From 4c721e5027dbcc95b8e5d0701b0f087c82b918e4 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Fri, 5 Feb 2021 07:47:16 +1100 Subject: [PATCH] fixes for credits --- app/Jobs/Util/Import.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/app/Jobs/Util/Import.php b/app/Jobs/Util/Import.php index fdb5e32890f8..04bf3f62b2e8 100644 --- a/app/Jobs/Util/Import.php +++ b/app/Jobs/Util/Import.php @@ -205,7 +205,7 @@ class Import implements ShouldQueue $this->setInitialCompanyLedgerBalances(); - $this->fixClientBalances(); + // $this->fixClientBalances(); Mail::to($this->user) ->send(new MigrationCompleted($this->company)); @@ -779,6 +779,14 @@ class Import implements ShouldQueue CreditFactory::create($this->company->id, $modified['user_id']) ); + //remove credit balance from ledger + if($credit->balance > 0 && $credit->client->balance > 0){ + $client = $credit->client; + $client->balance -= $credit->balance; + $client->save(); + } + + $key = "credits_{$resource['id']}"; $this->ids['credits'][$key] = [ @@ -1434,19 +1442,19 @@ class Import implements ShouldQueue /* In V4 we use negative invoices (credits) and add then into the client balance. In V5, these sit off ledger and are applied later. This next section will check for credit balances and reduce the client balance so that the V5 balances are correct */ - private function fixClientBalances() - { + // private function fixClientBalances() + // { - Client::cursor()->each(function ($client) { + // Client::cursor()->each(function ($client) { - $credit_balance = $client->credits->where('is_deleted', false)->sum('balance'); + // $credit_balance = $client->credits->where('is_deleted', false)->sum('balance'); - if($credit_balance > 0){ - $client->balance += $credit_balance; - $client->save(); - } + // if($credit_balance > 0){ + // $client->balance += $credit_balance; + // $client->save(); + // } - }); + // }); - } + // } }