diff --git a/app/Console/Commands/CheckData.php b/app/Console/Commands/CheckData.php index 1aabd733b1c5..fdef16cfcbb7 100644 --- a/app/Console/Commands/CheckData.php +++ b/app/Console/Commands/CheckData.php @@ -69,7 +69,7 @@ class CheckData extends Command /** * @var string */ - protected $signature = 'ninja:check-data {--database=} {--fix=} {--client_id=} {--paid_to_date=}'; + protected $signature = 'ninja:check-data {--database=} {--fix=} {--client_id=} {--paid_to_date=} {--client_balance=}'; /** * @var string @@ -506,6 +506,7 @@ class CheckData extends Command $this->logMessage($client->present()->name.' - '.$client->id." - calculated client balances do not match Invoice Balances = {$invoice_balance} - Client Balance = ".rtrim($client->balance, '0'). " Ledger balance = {$ledger->balance}"); $this->isValid = false; + } } @@ -535,6 +536,20 @@ class CheckData extends Command $this->logMessage("# {$client->id} " . $client->present()->name.' - '.$client->number." - Balance Failure - Invoice Balances = {$invoice_balance} Client Balance = {$client->balance} Ledger Balance = {$ledger->balance}"); $this->isValid = false; + + + if($this->option('client_balance')){ + + $this->logMessage("# {$client->id} " . $client->present()->name.' - '.$client->number." Fixing {$client->balance} to {$invoice_balance}"); + $client->balance = $invoice_balance; + $client->save(); + + $ledger->adjustment = $invoice_balance; + $ledger->balance = $invoice_balance; + $ledger->notes = 'Ledger Adjustment'; + $ledger->save(); + } + } }