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 $this->payment
->client ->client
->service() ->service()
->updatePaidToDate(abs($net_deletable) * -1) ->updatePaidToDate(($net_deletable * -1) > 0 ? 0 : ($net_deletable * -1))
->save(); ->save();
if ($is_trashed) { if ($is_trashed) {
@ -133,7 +133,7 @@ class DeletePayment
$this->payment $this->payment
->client ->client
->service() ->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(); ->save();
if ($paymentable_invoice->balance == $paymentable_invoice->amount) { 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. //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 $this->payment
// ->client ->client
// ->service() ->service()
// ->updatePaidToDate($reduced_paid_to_date) ->updatePaidToDate($reduced_paid_to_date)
// ->save(); ->save();
// } }
return $this; return $this;
} }

View File

@ -166,7 +166,7 @@ class CompanyGatewayTest extends TestCase
$balance = $this->invoice->balance; $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(); $this->invoice = $this->invoice->calc()->getInvoice();
$items = $this->invoice->line_items; $items = $this->invoice->line_items;
@ -206,18 +206,13 @@ class CompanyGatewayTest extends TestCase
$balance = $this->invoice->balance; $balance = $this->invoice->balance;
$wiped_balance = $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(); $this->invoice = $this->invoice->calc()->getInvoice();
$items = $this->invoice->line_items; $items = $this->invoice->line_items;
$this->assertEquals(($balance + 1), $this->invoice->balance); $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() public function testMarkPaidAdjustsGatewayFeeAppropriately()
@ -252,7 +247,7 @@ class CompanyGatewayTest extends TestCase
$balance = $this->invoice->balance; $balance = $this->invoice->balance;
$wiped_balance = $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(); $this->invoice = $this->invoice->calc()->getInvoice();
$items = $this->invoice->line_items; $items = $this->invoice->line_items;