added partial payment to factories

This commit is contained in:
denisdulici 2020-01-22 16:35:22 +03:00
parent f81279ac37
commit b5db0d20a1
2 changed files with 26 additions and 10 deletions

View File

@ -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));
}
});

View File

@ -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));
}
});