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