diff --git a/app/Services/Payment/DeletePayment.php b/app/Services/Payment/DeletePayment.php index 82d24f67b7..68c86a2e0c 100644 --- a/app/Services/Payment/DeletePayment.php +++ b/app/Services/Payment/DeletePayment.php @@ -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; } diff --git a/tests/Feature/CompanyGatewayTest.php b/tests/Feature/CompanyGatewayTest.php index 5946b12615..40942fee47 100644 --- a/tests/Feature/CompanyGatewayTest.php +++ b/tests/Feature/CompanyGatewayTest.php @@ -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;