Akaunting/database/factories/Transaction.php

44 lines
1.4 KiB
PHP
Raw Normal View History

2019-11-18 07:54:26 +00:00
<?php
use App\Models\Auth\User;
use App\Models\Banking\Transaction;
use Faker\Generator as Faker;
2019-12-16 07:39:09 +00:00
$user = User::first();
$company = $user->companies()->first();
2019-11-18 07:54:26 +00:00
2019-12-16 07:39:09 +00:00
$factory->define(Transaction::class, function (Faker $faker) use ($company) {
2019-11-22 14:35:46 +00:00
setting()->setExtraColumns(['company_id' => $company->id]);
2020-01-12 23:03:10 +00:00
$types = ['income', 'expense'];
$type = $faker->randomElement($types);
2020-01-06 22:28:05 +00:00
2019-11-18 07:54:26 +00:00
return [
'company_id' => $company->id,
2020-01-06 22:28:05 +00:00
'type' => $type,
2019-11-18 07:54:26 +00:00
'account_id' => setting('default.account'),
2020-07-25 14:22:50 +00:00
'paid_at' => $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d H:i:s'),
2020-01-13 14:15:51 +00:00
'amount' => $faker->randomFloat(2, 1, 1000),
2019-11-18 07:54:26 +00:00
'currency_code' => setting('default.currency'),
2020-07-25 14:22:50 +00:00
'currency_rate' => '1.0',
2019-11-18 07:54:26 +00:00
'description' => $faker->text(5),
2020-01-07 06:29:45 +00:00
'category_id' => $company->categories()->type($type)->get()->random(1)->pluck('id')->first(),
2019-11-18 07:54:26 +00:00
'reference' => $faker->text(5),
'payment_method' => setting('default.payment_method'),
];
});
2019-12-16 07:39:09 +00:00
2020-01-06 22:28:05 +00:00
$factory->state(Transaction::class, 'income', function (Faker $faker) use ($company) {
return [
'type' => 'income',
2020-05-03 08:15:56 +00:00
'category_id' => $company->categories()->income()->get()->random(1)->pluck('id')->first(),
2020-01-06 22:28:05 +00:00
];
});
2019-12-16 07:39:09 +00:00
$factory->state(Transaction::class, 'expense', function (Faker $faker) use ($company) {
return [
'type' => 'expense',
2020-05-03 08:15:56 +00:00
'category_id' => $company->categories()->expense()->get()->random(1)->pluck('id')->first(),
2019-12-16 07:39:09 +00:00
];
});