Added factory and seeder for sub-bookings.
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
<?php
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
use Carbon\Carbon;
|
||||
|
||||
$factory->define(App\Booking::class, function (Faker $faker) {
|
||||
return [
|
||||
'date'=> $faker->dateTimeBetween('2014-01-01'),
|
||||
'reference' => $faker->text(50),
|
||||
'person_or_company' => $faker->name,
|
||||
'note' => $faker->text(10)
|
||||
'note' => $faker->text(10),
|
||||
|
||||
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
||||
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
|
||||
];
|
||||
});
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonPeriod;
|
||||
|
||||
$factory->define(App\MemberState::class, function (Faker $faker) {
|
||||
return [
|
||||
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
||||
'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
||||
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
|
||||
];
|
||||
});
|
||||
|
||||
@@ -1,9 +1,58 @@
|
||||
<?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 = $randomPersonTarget->difference() + rand(1, 100);
|
||||
} else {
|
||||
$randomAccountType = AccountType::expeditures()->random();
|
||||
$amount = $randomPersonTarget->difference() + rand(1, 100);
|
||||
}
|
||||
} else if (rand_bool(20)) {
|
||||
// Underpaid
|
||||
if ($randomPersonTarget->ioType->name === 'Einnahme') {
|
||||
$randomAccountType = AccountType::incomes()->random();
|
||||
$amount = $randomPersonTarget->difference() - rand(1, $randomPersonTarget->difference());
|
||||
} else {
|
||||
$randomAccountType = AccountType::expeditures()->random();
|
||||
$amount = $randomPersonTarget->difference() - rand(1, $randomPersonTarget->difference());
|
||||
}
|
||||
} else {
|
||||
if ($randomPersonTarget->ioType->name === 'Einnahme') {
|
||||
$randomAccountType = AccountType::incomes()->random();
|
||||
$amount = $randomPersonTarget->difference();
|
||||
} else {
|
||||
$randomAccountType = AccountType::expeditures()->random();
|
||||
$amount = $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')
|
||||
];
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user