amount is an absolute value and the sign is stored as property of the i_o_type.
59 lines
2.1 KiB
PHP
59 lines
2.1 KiB
PHP
<?php
|
|
|
|
use Faker\Generator as Faker;
|
|
use Carbon\Carbon;
|
|
|
|
use App\Project;
|
|
use App\AccountType;
|
|
use App\PersonTarget;
|
|
use App\Booking;
|
|
|
|
$factory->define(App\SubBooking::class, function (Faker $faker) {
|
|
|
|
// Select randomly an existing target from the database
|
|
$randomPersonTarget = PersonTarget::all()->random();
|
|
$randomAccountType = null;
|
|
|
|
// Randomly decide, if the target is paid, underpaid or overpaid
|
|
if (rand_bool(20)) {
|
|
// Overpaid
|
|
if ($randomPersonTarget->ioType->name === 'Einnahme') {
|
|
$randomAccountType = AccountType::incomes()->random();
|
|
$amount = abs($randomPersonTarget->difference() + rand(1, 100));
|
|
} else {
|
|
$randomAccountType = AccountType::expeditures()->random();
|
|
$amount = abs($randomPersonTarget->difference() + rand(1, 100));
|
|
}
|
|
} else if (rand_bool(20)) {
|
|
// Underpaid
|
|
if ($randomPersonTarget->ioType->name === 'Einnahme') {
|
|
$randomAccountType = AccountType::incomes()->random();
|
|
$amount = abs($randomPersonTarget->difference() - rand(1, $randomPersonTarget->difference()));
|
|
} else {
|
|
$randomAccountType = AccountType::expeditures()->random();
|
|
$amount = abs($randomPersonTarget->difference() - rand(1, $randomPersonTarget->difference()));
|
|
}
|
|
} else {
|
|
if ($randomPersonTarget->ioType->name === 'Einnahme') {
|
|
$randomAccountType = AccountType::incomes()->random();
|
|
$amount = abs($randomPersonTarget->difference());
|
|
} else {
|
|
$randomAccountType = AccountType::expeditures()->random();
|
|
$amount = abs($randomPersonTarget->difference());
|
|
}
|
|
}
|
|
|
|
return [
|
|
'booking_id' => Booking::all('id')->random()->id,
|
|
'project_id' => Project::all('id')->random()->id,
|
|
'account_type_id' => $randomAccountType->id,
|
|
'person_target_id' => $randomPersonTarget->id,
|
|
|
|
'reference' => $faker->text(50),
|
|
'amount' => $amount,
|
|
|
|
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
|
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
|
|
];
|
|
});
|