Minor fixeS

This commit is contained in:
David Bomba 2023-11-07 20:04:56 +11:00
parent 7de0cd99f1
commit 2c567a0d95
2 changed files with 10 additions and 3 deletions

View File

@ -40,18 +40,25 @@ class UpdateLedger implements ShouldQueue
*/ */
public function handle() :void 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); MultiDB::setDb($this->db);
$cl = CompanyLedger::find($this->company_ledger_id); $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) if(!$cl)
return; return;
$entity = $cl->company_ledgerable; $entity = $cl->company_ledgerable;
$balance = $entity->calc()->getBalance(); $balance = $entity->calc()->getBalance();
$cl->adjustment = $balance - $this->start_amount; $cl->adjustment = $ledger_item ? $balance - $this->start_amount : $balance;
$parent_ledger = CompanyLedger::query() $parent_ledger = CompanyLedger::query()
->where('id', '<', $cl->id) ->where('id', '<', $cl->id)

View File

@ -46,7 +46,7 @@ class MarkSent extends AbstractService
// ->updateInvoiceBalance($adjustment, "Invoice {$this->invoice->number} marked as sent."); // ->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(); $this->invoice->client->service()->calculateBalance();