mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
fixes for credits
This commit is contained in:
parent
e918d8243e
commit
4c721e5027
@ -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();
|
||||
// }
|
||||
|
||||
// });
|
||||
|
||||
// }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user