laravel 8

This commit is contained in:
Denis Duliçi
2020-10-14 17:07:59 +03:00
parent b4e044b199
commit 1ba8835a2d
134 changed files with 3515 additions and 1952 deletions

View File

@ -1,53 +1,64 @@
<?php
use App\Models\Auth\User;
namespace Database\Factories;
use App\Abstracts\Factory;
use App\Models\Banking\Account;
use App\Models\Banking\Transaction;
use App\Models\Banking\Transfer;
use App\Models\Banking\Transfer as Model;
use App\Models\Setting\Category;
use Faker\Generator as Faker;
$user = User::first();
$company = $user->companies()->first();
class Transfer extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Model::class;
$factory->define(Transfer::class, function (Faker $faker) use ($company) {
session(['company_id' => $company->id]);
setting()->setExtraColumns(['company_id' => $company->id]);
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
$accounts = Account::enabled()->get();
$accounts = Account::enabled()->get();
if ($accounts->count() >= 2) {
$random = $accounts->random(2);
if ($accounts->count() >= 2) {
$random = $accounts->random(2);
$expense_account = $random->first();
$income_account = $random->last();
} else {
$expense_account = $accounts->first();
$expense_account = $random->first();
$income_account = $random->last();
} else {
$expense_account = $accounts->first();
$income_account = Account::factory()->enabled()->default_currency()->create();
}
$income_account = factory(Account::class)->states('enabled', 'default_currency')->create();
$request = [
'amount' => $this->faker->randomFloat(2, 1, 1000),
'paid_at' => $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'),
'category_id' => Category::transfer(),
'description' => $this->faker->text(20),
'reference' => $this->faker->text(20),
];
$expense_transaction = Transaction::factory()->create(array_merge($request, [
'type' => 'expense',
'account_id' => $expense_account->id,
]));
$income_transaction = Transaction::factory()->create(array_merge($request, [
'type' => 'income',
'account_id' => $income_account->id,
]));
return [
'company_id' => $this->company->id,
'expense_transaction_id' => $expense_transaction->id,
'income_transaction_id' => $income_transaction->id,
];
}
$request = [
'amount' => $faker->randomFloat(2, 1, 1000),
'paid_at' => $faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'),
'category_id' => Category::transfer(),
'description' => $faker->text(20),
'reference' => $faker->text(20),
];
$expense_transaction = factory(Transaction::class)->create(array_merge($request, [
'type' => 'expense',
'account_id' => $expense_account->id,
]));
$income_transaction = factory(Transaction::class)->create(array_merge($request, [
'type' => 'income',
'account_id' => $income_account->id,
]));
return [
'company_id' => $company->id,
'expense_transaction_id' => $expense_transaction->id,
'income_transaction_id' => $income_transaction->id,
];
});
}