From b5db0d20a1b8ce48c62e4bad0a5b8c098356c363 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Wed, 22 Jan 2020 16:35:22 +0300 Subject: [PATCH] added partial payment to factories --- database/factories/Bill.php | 18 +++++++++++++----- database/factories/Invoice.php | 18 +++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/database/factories/Bill.php b/database/factories/Bill.php index 1141bdc1b..0fed8eedb 100644 --- a/database/factories/Bill.php +++ b/database/factories/Bill.php @@ -31,7 +31,7 @@ $factory->define(Bill::class, function (Faker $faker) use ($company) { $contact = factory(Contact::class)->states('vendor')->create(); } - $statuses = ['draft', 'received', 'paid']; + $statuses = ['draft', 'received', 'partial', 'paid']; return [ 'company_id' => $company->id, @@ -43,8 +43,8 @@ $factory->define(Bill::class, function (Faker $faker) use ($company) { 'notes' => $faker->text(5), 'category_id' => $company->categories()->type('expense')->get()->random(1)->pluck('id')->first(), 'contact_id' => $contact->id, - 'contact_name' => $contact->name, - 'contact_email' =>$contact->email, + 'contact_name' => $contact->name, + 'contact_email' => $contact->email, 'contact_tax_number' => $contact->tax_number, 'contact_phone' => $contact->phone, 'contact_address' => $contact->address, @@ -57,6 +57,8 @@ $factory->state(Bill::class, 'draft', ['status' => 'draft']); $factory->state(Bill::class, 'received', ['status' => 'received']); +$factory->state(Bill::class, 'partial', ['status' => 'partial']); + $factory->state(Bill::class, 'paid', ['status' => 'paid']); $factory->state(Bill::class, 'recurring', function (Faker $faker) { @@ -129,7 +131,13 @@ $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, [])); + if (in_array($bill->status, ['partial', 'paid'])) { + $payment_request = []; + + if ($bill->status == 'partial') { + $payment_request['amount'] = (double) $amount / 2; + } + + $transaction = dispatch_now(new CreateDocumentTransaction($updated_bill, $payment_request)); } }); diff --git a/database/factories/Invoice.php b/database/factories/Invoice.php index 0f3c7b0bc..3da448e5c 100644 --- a/database/factories/Invoice.php +++ b/database/factories/Invoice.php @@ -31,7 +31,7 @@ $factory->define(Invoice::class, function (Faker $faker) use ($company) { $contact = factory(Contact::class)->states('customer')->create(); } - $statuses = ['draft', 'sent', 'paid']; + $statuses = ['draft', 'sent', 'partial', 'paid']; return [ 'company_id' => $company->id, @@ -43,8 +43,8 @@ $factory->define(Invoice::class, function (Faker $faker) use ($company) { 'notes' => $faker->text(5), 'category_id' => $company->categories()->type('income')->get()->random(1)->pluck('id')->first(), 'contact_id' => $contact->id, - 'contact_name' => $contact->name, - 'contact_email' =>$contact->email, + 'contact_name' => $contact->name, + 'contact_email' => $contact->email, 'contact_tax_number' => $contact->tax_number, 'contact_phone' => $contact->phone, 'contact_address' => $contact->address, @@ -57,6 +57,8 @@ $factory->state(Invoice::class, 'draft', ['status' => 'draft']); $factory->state(Invoice::class, 'sent', ['status' => 'sent']); +$factory->state(Invoice::class, 'partial', ['status' => 'partial']); + $factory->state(Invoice::class, 'paid', ['status' => 'paid']); $factory->state(Invoice::class, 'recurring', function (Faker $faker) { @@ -126,7 +128,13 @@ $factory->afterCreating(Invoice::class, function ($invoice, $faker) use ($compan $updated_invoice = dispatch_now(new UpdateInvoice($invoice, $request)); - if ($invoice->status == 'paid') { - event(new PaymentReceived($updated_invoice)); + if (in_array($invoice->status, ['partial', 'paid'])) { + $payment_request = []; + + if ($invoice->status == 'partial') { + $payment_request['amount'] = (double) $amount / 2; + } + + event(new PaymentReceived($updated_invoice, $payment_request)); } });