akaunting/database/factories/Transaction.php

44 lines
1.4 KiB
PHP
Raw Normal View History

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-13 02:03:10 +03:00
$types = ['income', 'expense'];
$type = $faker->randomElement($types);
2020-01-07 01:28:05 +03:00
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'),
2020-01-13 17:15:51 +03:00
'amount' => $faker->randomFloat(2, 1, 1000),
2019-11-18 10:54:26 +03:00
'currency_code' => setting('default.currency'),
'currency_rate' => '1',
'description' => $faker->text(5),
2020-01-07 09:29:45 +03:00
'category_id' => $company->categories()->type($type)->get()->random(1)->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',
2020-05-03 11:15:56 +03:00
'category_id' => $company->categories()->income()->get()->random(1)->pluck('id')->first(),
2020-01-07 01:28:05 +03:00
];
});
2019-12-16 10:39:09 +03:00
$factory->state(Transaction::class, 'expense', function (Faker $faker) use ($company) {
return [
'type' => 'expense',
2020-05-03 11:15:56 +03:00
'category_id' => $company->categories()->expense()->get()->random(1)->pluck('id')->first(),
2019-12-16 10:39:09 +03:00
];
});