Updates for client paid to date and negative payments

This commit is contained in:
David Bomba 2025-03-26 16:33:52 +11:00
parent 41dbbf284e
commit d33e4ba1da
2 changed files with 13 additions and 18 deletions

View File

@ -110,7 +110,7 @@ class DeletePayment
$this->payment
->client
->service()
->updatePaidToDate(abs($net_deletable) * -1)
->updatePaidToDate(($net_deletable * -1) > 0 ? 0 : ($net_deletable * -1))
->save();
if ($is_trashed) {
@ -133,7 +133,7 @@ class DeletePayment
$this->payment
->client
->service()
->updateBalanceAndPaidToDate($net_deletable, $net_deletable * -1)
->updateBalanceAndPaidToDate($net_deletable, ($net_deletable * -1) > 0 ? 0 : ($net_deletable * -1)) // if negative, set to 0, the paid to date will be reduced further down.
->save();
if ($paymentable_invoice->balance == $paymentable_invoice->amount) {
@ -155,16 +155,16 @@ class DeletePayment
}
//sometimes the payment is NOT created properly, this catches the payment and prevents the paid to date reducing inappropriately.
// if ($this->update_client_paid_to_date) {
if ($this->update_client_paid_to_date) {
// $reduced_paid_to_date = $this->payment->amount < 0 ? $this->payment->amount * -1 : min(0, ($this->payment->amount - $this->payment->refunded - $this->_paid_to_date_deleted) * -1);
$reduced_paid_to_date = $this->payment->amount < 0 ? $this->payment->amount * -1 : min(0, ($this->payment->amount - $this->payment->refunded - $this->_paid_to_date_deleted) * -1);
// $this->payment
// ->client
// ->service()
// ->updatePaidToDate($reduced_paid_to_date)
// ->save();
// }
$this->payment
->client
->service()
->updatePaidToDate($reduced_paid_to_date)
->save();
}
return $this;
}

View File

@ -166,7 +166,7 @@ class CompanyGatewayTest extends TestCase
$balance = $this->invoice->balance;
$this->invoice = $this->invoice->service()->addGatewayFee($cg, GatewayType::CREDIT_CARD, $this->invoice->balance)->save();
$this->invoice = $this->invoice->service()->addGatewayFee($cg, GatewayType::CREDIT_CARD, $this->invoice->balance, '12321')->save();
$this->invoice = $this->invoice->calc()->getInvoice();
$items = $this->invoice->line_items;
@ -206,18 +206,13 @@ class CompanyGatewayTest extends TestCase
$balance = $this->invoice->balance;
$wiped_balance = $balance;
$this->invoice = $this->invoice->service()->addGatewayFee($cg, GatewayType::CREDIT_CARD, $this->invoice->balance)->save();
$this->invoice = $this->invoice->service()->addGatewayFee($cg, GatewayType::CREDIT_CARD, $this->invoice->balance, '123212')->save();
$this->invoice = $this->invoice->calc()->getInvoice();
$items = $this->invoice->line_items;
$this->assertEquals(($balance + 1), $this->invoice->balance);
(new CheckGatewayFee($this->invoice->id, $this->company->db))->handle();
$i = Invoice::withTrashed()->find($this->invoice->id);
$this->assertEquals($wiped_balance, $i->balance);
}
public function testMarkPaidAdjustsGatewayFeeAppropriately()
@ -252,7 +247,7 @@ class CompanyGatewayTest extends TestCase
$balance = $this->invoice->balance;
$wiped_balance = $balance;
$this->invoice = $this->invoice->service()->addGatewayFee($cg, GatewayType::CREDIT_CARD, $this->invoice->balance)->save();
$this->invoice = $this->invoice->service()->addGatewayFee($cg, GatewayType::CREDIT_CARD, $this->invoice->balance, '123213')->save();
$this->invoice = $this->invoice->calc()->getInvoice();
$items = $this->invoice->line_items;