mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-11 05:32:39 +01: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)
|
// ->where('company_id', auth('contact')->user()->company->id)
|
||||||
// ->get();
|
// ->get();
|
||||||
|
|
||||||
|
/*find invoices*/
|
||||||
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($request()->invoices, 'invoice_id')))->get();
|
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column(request()->invoices, 'invoice_id')))->get();
|
||||||
|
|
||||||
//old
|
//old
|
||||||
// $amount = $invoices->sum('balance');
|
// $amount = $invoices->sum('balance');
|
||||||
|
|
||||||
|
/*filter only payable invoices*/
|
||||||
$invoices = $invoices->filter(function ($invoice) {
|
$invoices = $invoices->filter(function ($invoice) {
|
||||||
return $invoice->isPayable();
|
return $invoice->isPayable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/*return early if no invoices*/
|
||||||
if ($invoices->count() == 0) {
|
if ($invoices->count() == 0) {
|
||||||
return redirect()
|
return redirect()
|
||||||
->route('client.invoices.index')
|
->route('client.invoices.index')
|
||||||
->with(['warning' => 'No payable invoices selected.']);
|
->with(['warning' => 'No payable invoices selected.']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*iterate through invoices and add gateway fees*/
|
||||||
foreach(request()->invoices as $payable_invoice)
|
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']);
|
$invoice->service()->addGatewayFee($payable_invoice['amount']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*Format invoices*/
|
||||||
$invoices->map(function ($invoice) {
|
$invoices->fresh()->map(function ($invoice) {
|
||||||
$invoice->balance = Number::formatMoney($invoice->balance, $invoice->client);
|
$invoice->balance = Number::formatMoney($invoice->balance, $invoice->client);
|
||||||
$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format());
|
$invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format());
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user