added partial payment to factories
This commit is contained in:
parent
f81279ac37
commit
b5db0d20a1
@ -31,7 +31,7 @@ $factory->define(Bill::class, function (Faker $faker) use ($company) {
|
|||||||
$contact = factory(Contact::class)->states('vendor')->create();
|
$contact = factory(Contact::class)->states('vendor')->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
$statuses = ['draft', 'received', 'paid'];
|
$statuses = ['draft', 'received', 'partial', 'paid'];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
@ -43,8 +43,8 @@ $factory->define(Bill::class, function (Faker $faker) use ($company) {
|
|||||||
'notes' => $faker->text(5),
|
'notes' => $faker->text(5),
|
||||||
'category_id' => $company->categories()->type('expense')->get()->random(1)->pluck('id')->first(),
|
'category_id' => $company->categories()->type('expense')->get()->random(1)->pluck('id')->first(),
|
||||||
'contact_id' => $contact->id,
|
'contact_id' => $contact->id,
|
||||||
'contact_name' => $contact->name,
|
'contact_name' => $contact->name,
|
||||||
'contact_email' =>$contact->email,
|
'contact_email' => $contact->email,
|
||||||
'contact_tax_number' => $contact->tax_number,
|
'contact_tax_number' => $contact->tax_number,
|
||||||
'contact_phone' => $contact->phone,
|
'contact_phone' => $contact->phone,
|
||||||
'contact_address' => $contact->address,
|
'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, 'received', ['status' => 'received']);
|
||||||
|
|
||||||
|
$factory->state(Bill::class, 'partial', ['status' => 'partial']);
|
||||||
|
|
||||||
$factory->state(Bill::class, 'paid', ['status' => 'paid']);
|
$factory->state(Bill::class, 'paid', ['status' => 'paid']);
|
||||||
|
|
||||||
$factory->state(Bill::class, 'recurring', function (Faker $faker) {
|
$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));
|
$updated_bill = dispatch_now(new UpdateBill($bill, $request));
|
||||||
|
|
||||||
if ($bill->status == 'paid') {
|
if (in_array($bill->status, ['partial', 'paid'])) {
|
||||||
$transaction = dispatch_now(new CreateDocumentTransaction($updated_bill, []));
|
$payment_request = [];
|
||||||
|
|
||||||
|
if ($bill->status == 'partial') {
|
||||||
|
$payment_request['amount'] = (double) $amount / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
$transaction = dispatch_now(new CreateDocumentTransaction($updated_bill, $payment_request));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -31,7 +31,7 @@ $factory->define(Invoice::class, function (Faker $faker) use ($company) {
|
|||||||
$contact = factory(Contact::class)->states('customer')->create();
|
$contact = factory(Contact::class)->states('customer')->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
$statuses = ['draft', 'sent', 'paid'];
|
$statuses = ['draft', 'sent', 'partial', 'paid'];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'company_id' => $company->id,
|
'company_id' => $company->id,
|
||||||
@ -43,8 +43,8 @@ $factory->define(Invoice::class, function (Faker $faker) use ($company) {
|
|||||||
'notes' => $faker->text(5),
|
'notes' => $faker->text(5),
|
||||||
'category_id' => $company->categories()->type('income')->get()->random(1)->pluck('id')->first(),
|
'category_id' => $company->categories()->type('income')->get()->random(1)->pluck('id')->first(),
|
||||||
'contact_id' => $contact->id,
|
'contact_id' => $contact->id,
|
||||||
'contact_name' => $contact->name,
|
'contact_name' => $contact->name,
|
||||||
'contact_email' =>$contact->email,
|
'contact_email' => $contact->email,
|
||||||
'contact_tax_number' => $contact->tax_number,
|
'contact_tax_number' => $contact->tax_number,
|
||||||
'contact_phone' => $contact->phone,
|
'contact_phone' => $contact->phone,
|
||||||
'contact_address' => $contact->address,
|
'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, 'sent', ['status' => 'sent']);
|
||||||
|
|
||||||
|
$factory->state(Invoice::class, 'partial', ['status' => 'partial']);
|
||||||
|
|
||||||
$factory->state(Invoice::class, 'paid', ['status' => 'paid']);
|
$factory->state(Invoice::class, 'paid', ['status' => 'paid']);
|
||||||
|
|
||||||
$factory->state(Invoice::class, 'recurring', function (Faker $faker) {
|
$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));
|
$updated_invoice = dispatch_now(new UpdateInvoice($invoice, $request));
|
||||||
|
|
||||||
if ($invoice->status == 'paid') {
|
if (in_array($invoice->status, ['partial', 'paid'])) {
|
||||||
event(new PaymentReceived($updated_invoice));
|
$payment_request = [];
|
||||||
|
|
||||||
|
if ($invoice->status == 'partial') {
|
||||||
|
$payment_request['amount'] = (double) $amount / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
event(new PaymentReceived($updated_invoice, $payment_request));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user