fixes for credits

This commit is contained in:
David Bomba 2021-02-05 07:47:16 +11:00
parent e918d8243e
commit 4c721e5027

View File

@ -205,7 +205,7 @@ class Import implements ShouldQueue
$this->setInitialCompanyLedgerBalances(); $this->setInitialCompanyLedgerBalances();
$this->fixClientBalances(); // $this->fixClientBalances();
Mail::to($this->user) Mail::to($this->user)
->send(new MigrationCompleted($this->company)); ->send(new MigrationCompleted($this->company));
@ -779,6 +779,14 @@ class Import implements ShouldQueue
CreditFactory::create($this->company->id, $modified['user_id']) 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']}"; $key = "credits_{$resource['id']}";
$this->ids['credits'][$key] = [ $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. /* 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 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){ // if($credit_balance > 0){
$client->balance += $credit_balance; // $client->balance += $credit_balance;
$client->save(); // $client->save();
} // }
}); // });
} // }
} }