mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-31 01:57:30 -04:00 
			
		
		
		
	Fixes for migrating V4 data - pushing credits off leger
This commit is contained in:
		
							parent
							
								
									81e17d9cdc
								
							
						
					
					
						commit
						a5372b1cf3
					
				| @ -205,6 +205,8 @@ class Import implements ShouldQueue | |||||||
| 
 | 
 | ||||||
|         $this->setInitialCompanyLedgerBalances(); |         $this->setInitialCompanyLedgerBalances(); | ||||||
|          |          | ||||||
|  |         $this->fixClientBalances(); | ||||||
|  | 
 | ||||||
|         Mail::to($this->user) |         Mail::to($this->user) | ||||||
|             ->send(new MigrationCompleted($this->company)); |             ->send(new MigrationCompleted($this->company)); | ||||||
| 
 | 
 | ||||||
| @ -789,6 +791,7 @@ class Import implements ShouldQueue | |||||||
|         /*Improve memory handling by setting everything to null when we have finished*/ |         /*Improve memory handling by setting everything to null when we have finished*/ | ||||||
|         $data = null; |         $data = null; | ||||||
|         $credit_repository = null; |         $credit_repository = null; | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private function processQuotes(array $data): void |     private function processQuotes(array $data): void | ||||||
| @ -1425,4 +1428,23 @@ class Import implements ShouldQueue | |||||||
|         return $response->getBody(); |         return $response->getBody(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |     /* 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() | ||||||
|  |     { | ||||||
|  |         | ||||||
|  |         Client::cursor()->each(function ($client) { | ||||||
|  | 
 | ||||||
|  |             $credit_balance = $client->credits->where('is_deleted', false)->sum('balance'); | ||||||
|  | 
 | ||||||
|  |             if($credit_balance > 0){ | ||||||
|  |                 $client->balance += $credit_balance; | ||||||
|  |                 $client->save(); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user