diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 710bd09f12..aacec46b05 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -737,7 +737,7 @@ ORDER BY clients.id; $this->logMessage($client_object->present()->name.' - '.$client_object->id." - calculated client balances do not match Invoice Balances = {$invoice_balance} - Client Balance = ".rtrim($client['client_balance'], '0'). " Ledger balance = {$ledger->balance}"); - if($this->option('client_balance')){ + if($this->option('ledger_balance')){ $this->logMessage("# {$client_object->id} " . $client_object->present()->name.' - '.$client_object->number." Fixing {$client_object->balance} to {$invoice_balance}"); $client_object->balance = $invoice_balance; diff --git a/app/Services/Client/ClientService.php b/app/Services/Client/ClientService.php index 2f2152429f..aa310479d8 100644 --- a/app/Services/Client/ClientService.php +++ b/app/Services/Client/ClientService.php @@ -28,21 +28,27 @@ class ClientService public function updateBalance(float $amount) { - $this->client->balance += $amount; + // $this->client->balance += $amount; + + $this->client->increment('balance', $amount); return $this; } public function updatePaidToDate(float $amount) { - $this->client->paid_to_date += $amount; + // $this->client->paid_to_date += $amount; + + $this->client->increment('paid_to_date', $amount); return $this; } public function adjustCreditBalance(float $amount) { - $this->client->credit_balance += $amount; + // $this->client->credit_balance += $amount; + + $this->client->increment('credit_balance', $amount); return $this; } diff --git a/app/Services/Invoice/InvoiceService.php b/app/Services/Invoice/InvoiceService.php index 50e7249d0b..233644b207 100644 --- a/app/Services/Invoice/InvoiceService.php +++ b/app/Services/Invoice/InvoiceService.php @@ -145,8 +145,11 @@ class InvoiceService return $this; } - $this->invoice->balance += $balance_adjustment; + // $this->invoice->balance += $balance_adjustment; + $this->invoice->increment('balance', $balance_adjustment); + + if (round($this->invoice->balance,2) == 0 && !$is_draft) { $this->invoice->status_id = Invoice::STATUS_PAID; } @@ -160,7 +163,10 @@ class InvoiceService public function updatePaidToDate($adjustment) { - $this->invoice->paid_to_date += $adjustment; + // $this->invoice->paid_to_date += $adjustment; + + $this->invoice->increment('paid_to_date', $adjustment); + return $this; } @@ -381,7 +387,8 @@ class InvoiceService /*Update the partial amount of a invoice*/ public function updatePartial($amount) { - $this->invoice->partial += $amount; + // $this->invoice->partial += $amount; + $this->invoice->increment('partial', $amount); return $this; }