diff --git a/database/factories/Bill.php b/database/factories/Bill.php index 717c52aa9..47d3dc425 100644 --- a/database/factories/Bill.php +++ b/database/factories/Bill.php @@ -1,6 +1,7 @@ define(Bill::class, function (Faker $faker) use ($company) { $contact = factory(Contact::class)->states('vendor')->create(); } - $statuses = ['draft', 'received']; + $statuses = ['draft', 'received', 'paid']; return [ 'company_id' => $company->id, @@ -54,6 +55,8 @@ $factory->state(Bill::class, 'draft', ['status' => 'draft']); $factory->state(Bill::class, 'received', ['status' => 'received']); +$factory->state(Bill::class, 'paid', ['status' => 'paid']); + $factory->state(Bill::class, 'recurring', function (Faker $faker) { $frequencies = ['monthly', 'weekly']; @@ -91,8 +94,13 @@ $factory->afterCreating(Bill::class, function ($bill, $faker) use ($company) { session(['company_id' => $company->id]); setting()->setExtraColumns(['company_id' => $company->id]); + $status = $bill->status; + $bill->status = 'draft'; + event(new BillCreated($bill)); + $bill->status = $status; + if ($bill->status == 'received') { $bill->status = 'received'; $bill->save(); @@ -118,4 +126,8 @@ $factory->afterCreating(Bill::class, function ($bill, $faker) use ($company) { ]; $updated_bill = dispatch_now(new UpdateBill($bill, $request)); + + if ($bill->status == 'paid') { + $transaction = dispatch_now(new CreateDocumentTransaction($updated_bill, [])); + } });