osb/database/factories/ServiceFactory.php
2020-02-12 21:57:44 +11:00

111 lines
4.3 KiB
PHP

<?php
use Faker\Generator as Faker;
$factory->define(App\Models\Service::class, function (Faker $faker) {
return [
'active'=>1,
];
});
$factory->afterMaking(App\Models\Service::class, function ($service,$faker) {
$product = factory(App\Models\Product::class)->make();
$service->setRelation('product',$product);
$service->product_id = $product->id;
$account = factory(App\Models\Account::class)->make();
$service->setRelation('account',$account);
$service->account_id = $account->id;
});
// Weekly
$factory->afterMakingState(App\Models\Service::class,'week',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('week')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 0;
});
$factory->afterMakingState(App\Models\Service::class,'week-mid',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('week-mid')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 0;
});
// Monthly
$factory->afterMakingState(App\Models\Service::class,'month',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('month')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 1;
});
$factory->afterMakingState(App\Models\Service::class,'month-mid',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('month-mid')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 1;
});
// Quarterly
$factory->afterMakingState(App\Models\Service::class,'quarter',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('quarter')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 2;
});
$factory->afterMakingState(App\Models\Service::class,'quarter-mid',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('quarter-mid')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 2;
});
// Half Yearly
$factory->afterMakingState(App\Models\Service::class,'half',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('half')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 3;
});
$factory->afterMakingState(App\Models\Service::class,'half-mid',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('half-mid')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 3;
});
// Yearly
$factory->afterMakingState(App\Models\Service::class,'year',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('year')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 4;
});
$factory->afterMakingState(App\Models\Service::class,'year-mid',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('year-mid')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 4;
});
// 2 Yearly
$factory->afterMakingState(App\Models\Service::class,'2year',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('2year')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 5;
});
// 3 Yearly
$factory->afterMakingState(App\Models\Service::class,'3year',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('3year')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 6;
});
// Last Month
$factory->afterMakingState(App\Models\Service::class,'next-invoice',function ($service,$faker) {
$invoice_items = factory(App\Models\InvoiceItem::class,1)->state('next-invoice')->make();
$service->setRelation('invoice_items',$invoice_items);
$service->recur_schedule = 1;
});
// New Connect
$factory->afterMakingState(App\Models\Service::class,'new-connect',function ($service,$faker) {
$service->recur_schedule = 1;
$service->date_next_invoice = \Carbon\Carbon::now()->subMonth()->startOfMonth()->addDays(\Carbon\Carbon::now()->subMonth()->daysInMonth/2);
});