mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 23:17:32 -05:00 
			
		
		
		
	Merge pull request #5826 from turbo124/v5-develop
Fixes for DB::rollBack
This commit is contained in:
		
						commit
						8fd9d2211f
					
				@ -57,13 +57,13 @@ class InvoiceBalanceSanity implements Rule
 | 
				
			|||||||
    private function checkIfInvoiceBalanceIsSane() : bool
 | 
					    private function checkIfInvoiceBalanceIsSane() : bool
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        DB::connection(config('database.default'))->beginTransaction();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $this->invoice = Invoice::on(config('database.default'))->find($this->invoice->id);
 | 
				
			||||||
        $this->invoice->line_items = $this->input['line_items'];
 | 
					        $this->invoice->line_items = $this->input['line_items'];
 | 
				
			||||||
 | 
					        $temp_invoice = $this->invoice->calc()->getTempEntity();
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
        DB::beginTransaction();
 | 
					        DB::connection(config('database.default'))->rollBack();
 | 
				
			||||||
 
 | 
					 | 
				
			||||||
            $temp_invoice = $this->invoice->calc()->getTempEntity();
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
        DB::rollBack();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if($temp_invoice->balance < 0){
 | 
					        if($temp_invoice->balance < 0){
 | 
				
			||||||
            $this->message = 'Invoice balance cannot go negative';
 | 
					            $this->message = 'Invoice balance cannot go negative';
 | 
				
			||||||
@ -71,7 +71,7 @@ class InvoiceBalanceSanity implements Rule
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return true;
 | 
					       return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -306,6 +306,10 @@ class BaseRepository
 | 
				
			|||||||
        /* Perform model specific tasks */
 | 
					        /* Perform model specific tasks */
 | 
				
			||||||
        if ($model instanceof Invoice) {
 | 
					        if ($model instanceof Invoice) {
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
 | 
					            nlog("Finished amount = " . $state['finished_amount']);
 | 
				
			||||||
 | 
					            nlog("Starting amount = " . $state['starting_amount']);
 | 
				
			||||||
 | 
					            nlog("Diff = " . ($state['finished_amount'] - $state['starting_amount']));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) {
 | 
					            if (($state['finished_amount'] != $state['starting_amount']) && ($model->status_id != Invoice::STATUS_DRAFT)) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $model->service()->updateStatus()->save();
 | 
					                $model->service()->updateStatus()->save();
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user