Fixes for tests

This commit is contained in:
David Bomba 2020-06-01 14:18:33 +10:00
parent 90e4534fef
commit 3abd0e0b17
2 changed files with 41 additions and 2 deletions

View File

@ -46,6 +46,7 @@ class RefundPayment
->buildCreditLineItems() //generate the credit note items
->updateCreditables() //return the credits first
->updatePaymentables() //update the paymentable items
->adjustInvoices()
->createActivity() // create the refund activity
->processGatewayRefund() //process the gateway refund if needed
->save();
@ -242,6 +243,46 @@ class RefundPayment
return $this;
}
private function adjustInvoices()
{
$adjustment_amount = 0;
if(isset($this->refund_data['invoices']) && count($this->refund_data['invoices']) > 0)
{
foreach ($this->refund_data['invoices'] as $refunded_invoice) {
$invoice = Invoice::find($refunded_invoice['invoice_id']);
$invoice->service()->updateBalance($refunded_invoice['amount'])->save();
if ($invoice->amount == $invoice->balance) {
$invoice->service()->setStatus(Invoice::STATUS_SENT);
} else {
$invoice->service()->setStatus(Invoice::STATUS_PARTIAL);
}
$client = $invoice->client;
$adjustment_amount += $refunded_invoice['amount'];
$client->balance += $refunded_invoice['amount'];
$client->save();
//todo adjust ledger balance here? or after and reference the credit and its total
}
$ledger_string = ''; //todo
$this->credit_note->ledger()->updateCreditBalance($adjustment_amount, $ledger_string);
$this->payment->client->paid_to_date -= $this->refund_data['amount'];
$this->payment->client->save();
}
return $this;
}
private function save()
{
$this->payment->save();

View File

@ -125,8 +125,6 @@ class RefundTest extends TestCase
$response->assertStatus(200);
info($arr);
$this->assertEquals(50, $arr['data']['refunded']);
$this->assertEquals(Payment::STATUS_REFUNDED, $arr['data']['status_id']);
}