From 7325a66c4749006471a95e558dc228f5f6a2de56 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 8 Nov 2023 15:43:08 +1100 Subject: [PATCH] Working on ledger balances --- app/Repositories/BaseRepository.php | 2 +- app/Services/Ledger/LedgerService.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Repositories/BaseRepository.php b/app/Repositories/BaseRepository.php index 44ddd501aab6..40519498019d 100644 --- a/app/Repositories/BaseRepository.php +++ b/app/Repositories/BaseRepository.php @@ -290,7 +290,7 @@ class BaseRepository /* Perform model specific tasks */ if ($model instanceof Invoice) { - if ($model->status_id != Invoice::STATUS_DRAFT && ($state['starting_amount'] != $state['finished_amount'])) { + if ($model->status_id != Invoice::STATUS_DRAFT) { $model->service()->updateStatus()->save(); $model->client->service()->calculateBalance(); $model->ledger()->updateInvoiceBalance(($state['finished_amount'] - $state['starting_amount']), "Update adjustment for invoice {$model->number}"); diff --git a/app/Services/Ledger/LedgerService.php b/app/Services/Ledger/LedgerService.php index 97715350a2c9..9d2b3fa6795d 100644 --- a/app/Services/Ledger/LedgerService.php +++ b/app/Services/Ledger/LedgerService.php @@ -36,7 +36,9 @@ class LedgerService // $hash = sha1($adjustment.$notes.$this->entity->status_id.$this->entity->client_id.$this->entity->amount.$this->entity->balance.$this->entity->company_id.Activity::UPDATE_INVOICE); // $hash = sha1($hash); // $hash = sha1("{$this->entity->amount}.{$this->entity->balance}"); - $hash = "{$this->entity->amount}.{$this->entity->balance}"; + $hash = "{$adjustment}.{$this->entity->amount}.{$this->entity->balance}"; + + usleep(10000000); $exists = CompanyLedger::query() ->where('client_id', $this->entity->client_id) @@ -49,6 +51,7 @@ class LedgerService ->exists(); if($exists) { + nlog("Collision {$adjustment} {$notes}"); return $this; }