Refactoring client payments

This commit is contained in:
David Bomba 2020-08-26 10:53:11 +10:00
parent 79e0fa56e2
commit d57f0f9236
2 changed files with 7 additions and 11 deletions

View File

@ -103,19 +103,21 @@ class PaymentController extends Controller
foreach($payable_invoices as $key => $payable_invoice)
{
$payable_invoice[$key]['amount'] = Number::parseFloat($payable_invoice[$key]['amount']);
$payable_invoice[$key]['amount'] = Number::parseFloat($payable_invoice['amount']);
$payable_invoice['amount'] = $payable_invoice[$key]['amount'];
$invoice = $invoices->first(function ($inv) use($payable_invoice) {
return $payable_invoice[$key]['invoice_id'] == $inv->hashed_id;
return $payable_invoice['invoice_id'] == $inv->hashed_id;
});
if($invoice)
$invoice->service()->addGatewayFee($gateway, $payable_invoice[$key]['amount'])->save();
$invoice->service()->addGatewayFee($gateway, $payable_invoice['amount'])->save();
/*Update the payable amount to include the fee*/
$gateway_fee = $gateway->calcGatewayFee($payable_invoice[$key]['amount']);
$gateway_fee = $gateway->calcGatewayFee($payable_invoice['amount']);
$payable_invoice[$key]['amount_with_fee'] += $gateway_fee;
$payable_invoice[$key]['amount_with_fee'] = $payable_invoice['amount'] + $gateway_fee;
$payable_invoice[$key]['fee'] = $gateway_fee;
$payable_invoice[$key]['due_date'] = $this->formatDate($invoice->due_date, $invoice->client->date_format());
$payable_invoice[$key]['invoice_number'] = $invoice->number;

View File

@ -42,14 +42,8 @@ class NumberTest extends TestCase
$formatted_amount = Number::formatValue($amount, $currency);
info($formatted_amount);
$float_amount = Number::parseFloat($formatted_amount);
info($float_amount);
info($currency->id);
info($currency->code);
if($currency->precision == 0){
$this->assertEquals(123456789, $float_amount);
}