mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 03:17:35 -05:00 
			
		
		
		
	update invoice PDF when a payment is applied
This commit is contained in:
		
							parent
							
								
									2c74b5a3ba
								
							
						
					
					
						commit
						6b45317bf3
					
				@ -12,11 +12,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
namespace App\Services\Payment;
 | 
					namespace App\Services\Payment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App\Events\Invoice\InvoiceWasUpdated;
 | 
				
			||||||
use App\Helpers\Email\PaymentEmail;
 | 
					use App\Helpers\Email\PaymentEmail;
 | 
				
			||||||
use App\Jobs\Payment\EmailPayment;
 | 
					use App\Jobs\Payment\EmailPayment;
 | 
				
			||||||
use App\Jobs\Util\SystemLogger;
 | 
					use App\Jobs\Util\SystemLogger;
 | 
				
			||||||
use App\Models\Invoice;
 | 
					use App\Models\Invoice;
 | 
				
			||||||
use App\Models\SystemLog;
 | 
					use App\Models\SystemLog;
 | 
				
			||||||
 | 
					use App\Utils\Ninja;
 | 
				
			||||||
use App\Utils\Traits\MakesHash;
 | 
					use App\Utils\Traits\MakesHash;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class UpdateInvoicePayment
 | 
					class UpdateInvoicePayment
 | 
				
			||||||
@ -38,7 +40,9 @@ class UpdateInvoicePayment
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $paid_invoices = $this->payment_hash->invoices();
 | 
					        $paid_invoices = $this->payment_hash->invoices();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->get();
 | 
					        $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->get();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        collect($paid_invoices)->each(function ($paid_invoice) use($invoices) {
 | 
					        collect($paid_invoices)->each(function ($paid_invoice) use($invoices) {
 | 
				
			||||||
@ -71,12 +75,13 @@ class UpdateInvoicePayment
 | 
				
			|||||||
            $pivot_invoice->pivot->amount = $paid_amount;
 | 
					            $pivot_invoice->pivot->amount = $paid_amount;
 | 
				
			||||||
            $pivot_invoice->save();
 | 
					            $pivot_invoice->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
            $invoice->service() //caution what if we amount paid was less than partial - we wipe it! 
 | 
					            $invoice->service() //caution what if we amount paid was less than partial - we wipe it! 
 | 
				
			||||||
                ->clearPartial()
 | 
					                ->clearPartial()
 | 
				
			||||||
                ->updateBalance($paid_amount*-1)
 | 
					                ->updateBalance($paid_amount*-1)
 | 
				
			||||||
                ->save();
 | 
					                ->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            event(new InvoiceWasUpdated($invoice, $invoice->company, Ninja::eventVars()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // } else {
 | 
					            // } else {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user