diff --git a/app/Services/Invoice/AutoBillInvoice.php b/app/Services/Invoice/AutoBillInvoice.php index 549efee15b..50ce340e88 100644 --- a/app/Services/Invoice/AutoBillInvoice.php +++ b/app/Services/Invoice/AutoBillInvoice.php @@ -68,17 +68,17 @@ class AutoBillInvoice extends AbstractService $this->applyCreditPayment(); } - nlog($this->client->getSetting('use_unapplied_payment')); if($this->client->getSetting('use_unapplied_payment') != 'off') { - nlog("meeeeeeerp"); $this->applyUnappliedPayment(); } //If this returns true, it means a partial invoice amount was paid as a credit and there is no further balance payable - if ($this->is_partial_amount && $this->invoice->partial == 0) { + if (($this->is_partial_amount && $this->invoice->partial == 0) || (int)$this->invoice->balance == 0) { return; } + nlog($this->invoice->toArray()); + $amount = 0; $invoice_total = 0; @@ -262,11 +262,13 @@ class AutoBillInvoice extends AbstractService ->where('client_id', $this->client->id) ->where('status_id', Payment::STATUS_COMPLETED) ->where('is_deleted', false) - ->where('amount', '>', 'applied') + ->whereColumn('amount', '>', 'applied') ->where('amount', '>', 0) ->orderBy('created_at') ->get(); + nlog($unapplied_payments->pluck("id")); + $available_unapplied_balance = $unapplied_payments->sum('amount') - $unapplied_payments->sum('applied'); nlog("available unapplied balance = {$available_unapplied_balance}"); diff --git a/tests/TestCase.php b/tests/TestCase.php index 2932d4a69d..ffa0f237e1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,9 +2,19 @@ namespace Tests; +use App\Utils\Traits\AppSetup; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { use CreatesApplication; + use AppSetup; + + protected function setUp() :void + { + parent::setUp(); + + $this->buildCache(true); + + } }