From 63de5df95eae0c0301d112a910cdb2207fbc9a35 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 6 Oct 2023 13:25:46 +1100 Subject: [PATCH] Additional tests --- app/Filters/QuoteFilters.php | 6 ++++++ app/Services/Invoice/ApplyPayment.php | 16 ---------------- tests/Feature/RefundTest.php | 13 +++++++++++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/app/Filters/QuoteFilters.php b/app/Filters/QuoteFilters.php index 26a6b3f0ae2e..0a8c549af609 100644 --- a/app/Filters/QuoteFilters.php +++ b/app/Filters/QuoteFilters.php @@ -112,6 +112,12 @@ class QuoteFilters extends QueryFilters ->orderBy('due_date', 'DESC'); }); } + + if(in_array('convert', $status_parameters)) { + $query->orWhere(function ($q) { + $q->whereNotNull('invoice_id'); + }); + } }); return $this->builder; diff --git a/app/Services/Invoice/ApplyPayment.php b/app/Services/Invoice/ApplyPayment.php index 580e6f1cc9ef..058d9949c597 100644 --- a/app/Services/Invoice/ApplyPayment.php +++ b/app/Services/Invoice/ApplyPayment.php @@ -69,32 +69,16 @@ class ApplyPayment extends AbstractService } } - nlog($this->invoice->id. " " . $this->invoice->paid_to_date); $this->payment ->ledger() ->updatePaymentBalance($amount_paid); - // nlog("updating client balance by amount {$amount_paid}"); - $this->invoice ->client ->service() ->updateBalance($amount_paid) ->save(); - // /* Update Pivot Record amount */ - // $this->payment->invoices->each(function ($inv) use ($amount_paid) { - // if ($inv->id == $this->invoice->id) { - // // $inv->pivot->amount = ($amount_paid * -1); - // // $inv->pivot->save(); - // //25-06-2023 - // nlog($inv); - // nlog($amount_paid); - // $inv->paid_to_date += floatval($amount_paid * -1); - // $inv->save(); - // } - // }); - $this->invoice ->service() ->applyNumber() diff --git a/tests/Feature/RefundTest.php b/tests/Feature/RefundTest.php index 07a423d56ddb..a187fe49cb5d 100644 --- a/tests/Feature/RefundTest.php +++ b/tests/Feature/RefundTest.php @@ -135,6 +135,7 @@ class RefundTest extends TestCase $this->assertEquals(50, $arr['data']['refunded']); $this->assertEquals(Payment::STATUS_REFUNDED, $arr['data']['status_id']); + } /** @@ -289,6 +290,12 @@ class RefundTest extends TestCase $this->assertNotNull($payment->invoices()); $this->assertEquals(1, $payment->invoices()->count()); + + $i = $this->invoice->fresh(); + + $this->assertEquals(0, $i->balance); + $this->assertEquals(round($this->invoice->amount,2), round($i->paid_to_date,2)); + $data = [ 'id' => $this->encodePrimaryKey($payment->id), 'amount' => 50, @@ -309,6 +316,12 @@ class RefundTest extends TestCase ])->post('/api/v1/payments/refund', $data); $response->assertStatus(200); + + $i = $this->invoice->fresh(); + + $this->assertEquals($i->amount, $i->balance); + $this->assertEquals(0, round($i->paid_to_date, 2)); + } /**