From ee77993006b1050b2d616dc65f0b52f2ce1b6a11 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 7 Oct 2020 22:06:00 +1100 Subject: [PATCH] Working on applying credits to payments prior to billing via gateway --- app/Services/Invoice/AutoBillInvoice.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 5a927c3daf3b..10230eeb5bc0 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -117,6 +117,10 @@ class AutoBillInvoice extends AbstractService $available_credits->each(function($credit) use($is_partial_amount){ + //todo need to iterate until the partial or balance is completely consumed + //by the credit, any remaining balance is then dealt with by + //the gateway + //each time a credit is applied SAVE the invoice // if($credit->balance >= $amount){ // //current credit covers the total amount @@ -141,6 +145,10 @@ class AutoBillInvoice extends AbstractService $credit->id => ['amount' => $amount] ]); + $this->payment->invoice()->attach([ + $this->invoice->id => ['amount' => $amount] + ]); + $this->applyPaymentToCredit($credit, $amount); } } @@ -150,7 +158,7 @@ class AutoBillInvoice extends AbstractService private function applyPaymentToCredit($credit, $amount) { - + $credit_item = new InvoiceItem; $credit_item->type_id = '1'; $credit_item->product_key = ctrans('texts.credit');