mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-25 22:52:53 -04:00 
			
		
		
		
	Refactor payments
This commit is contained in:
		
							parent
							
								
									979916adb5
								
							
						
					
					
						commit
						1c55b529a0
					
				| @ -90,31 +90,38 @@ class PaymentController extends Controller | ||||
|                             //     ->where('company_id', auth('contact')->user()->company->id)
 | ||||
|                             //     ->get();
 | ||||
| 
 | ||||
|          | ||||
|         $invoices = Invoice::whereIn('id', $this->transformKeys(array_column($request()->invoices, 'invoice_id')))->get(); | ||||
|         /*find invoices*/ | ||||
|         $invoices = Invoice::whereIn('id', $this->transformKeys(array_column(request()->invoices, 'invoice_id')))->get(); | ||||
| 
 | ||||
|                             //old
 | ||||
|                             // $amount = $invoices->sum('balance');
 | ||||
| 
 | ||||
|         /*filter only payable invoices*/ | ||||
|         $invoices = $invoices->filter(function ($invoice) { | ||||
|             return $invoice->isPayable(); | ||||
|         }); | ||||
| 
 | ||||
| 
 | ||||
|         /*return early if no invoices*/ | ||||
|         if ($invoices->count() == 0) { | ||||
|             return redirect() | ||||
|                 ->route('client.invoices.index') | ||||
|                 ->with(['warning' => 'No payable invoices selected.']); | ||||
|         } | ||||
| 
 | ||||
|         /*iterate through invoices and add gateway fees*/ | ||||
|         foreach(request()->invoices as $payable_invoice) | ||||
|         { | ||||
|             $invoice = Invoice::find($this->decodePrimaryKey($payable_invoice['invoice_id'])); | ||||
|             $invoice = $invoices->first(function ($inv) use($payable_invoice) { | ||||
|                             return $payable_invoice['invoice_id'] == $inv->hashed_id; | ||||
|                         }); | ||||
| 
 | ||||
|             if($invoice) | ||||
|                 $invoice->service()->addGatewayFee($payable_invoice['amount']); | ||||
|         } | ||||
| 
 | ||||
| 
 | ||||
|         $invoices->map(function ($invoice) { | ||||
|         /*Format invoices*/ | ||||
|         $invoices->fresh()->map(function ($invoice) { | ||||
|             $invoice->balance = Number::formatMoney($invoice->balance, $invoice->client); | ||||
|             $invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format()); | ||||
|              | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user