From 2c567a0d95202c91757fdc37a6361f2e14e3b286 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 7 Nov 2023 20:04:56 +1100 Subject: [PATCH] Minor fixeS --- app/Jobs/Ledger/UpdateLedger.php | 11 +++++++++-- app/Services/Invoice/MarkSent.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Jobs/Ledger/UpdateLedger.php b/app/Jobs/Ledger/UpdateLedger.php index 68eefe13afa1..a86ad994da62 100644 --- a/app/Jobs/Ledger/UpdateLedger.php +++ b/app/Jobs/Ledger/UpdateLedger.php @@ -40,18 +40,25 @@ class UpdateLedger implements ShouldQueue */ public function handle() :void { - // nlog("Updating company ledger for client ". $this->company_ledger_id); + nlog("Updating company ledger for client ". $this->company_ledger_id); MultiDB::setDb($this->db); $cl = CompanyLedger::find($this->company_ledger_id); + $ledger_item = CompanyLedger::query() + ->where('company_id', $cl->company_id) + ->where('client_id', $cl->client_id) + ->where('company_ledgerable_id', $cl->company_ledgerable_id) + ->where('company_ledgerable_type', $cl->company_ledgerable_type) + ->exists(); + if(!$cl) return; $entity = $cl->company_ledgerable; $balance = $entity->calc()->getBalance(); - $cl->adjustment = $balance - $this->start_amount; + $cl->adjustment = $ledger_item ? $balance - $this->start_amount : $balance; $parent_ledger = CompanyLedger::query() ->where('id', '<', $cl->id) diff --git a/app/Services/Invoice/MarkSent.php b/app/Services/Invoice/MarkSent.php index f73e3fe65e3d..954e8e90d2d1 100644 --- a/app/Services/Invoice/MarkSent.php +++ b/app/Services/Invoice/MarkSent.php @@ -46,7 +46,7 @@ class MarkSent extends AbstractService // ->updateInvoiceBalance($adjustment, "Invoice {$this->invoice->number} marked as sent."); -$this->invoice->ledger()->mutateInvoiceBalance($this->invoice->amount, "Invoice {$this->invoice->number} marked as sent."); +$this->invoice->ledger()->mutateInvoiceBalance($this->invoice->amount, "Invoice {$this->invoice->number} marked as sent => {$this->invoice->amount}"); $this->invoice->client->service()->calculateBalance();