From 0b4e3a9341e450ada73353a3f11fd32fc7ddc347 Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 18 Oct 2022 10:23:11 +1100 Subject: [PATCH] Dont save payments with a zero alloc amount, delete payments with a zero alloc amount, fix javascript calculating payment balance --- app/Http/Controllers/AdminController.php | 9 +++++++-- resources/views/email/user/invoice.blade.php | 2 ++ .../theme/backend/adminlte/a/payment/addedit.blade.php | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index bc90bae..4982a74 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -126,8 +126,7 @@ class AdminController extends Controller if ($items->count() == 1) { $oo = $items->pop(); - - if (! $amount['id']) { + if ($amount['id'] == 0) { $oo->delete(); continue; } @@ -138,7 +137,13 @@ class AdminController extends Controller } $oo->amount = ($oo->invoice->due >= 0) && ($oo->invoice->due-$amount['id'] >= 0) ? $amount['id'] : 0; + + // If the amount is empty, ignore it. + if (! $oo->amount) + continue; + $oo->site_id = config('site')->site_id; + $oo->active = TRUE; $o->items()->save($oo); } diff --git a/resources/views/email/user/invoice.blade.php b/resources/views/email/user/invoice.blade.php index e953c46..f68fe17 100644 --- a/resources/views/email/user/invoice.blade.php +++ b/resources/views/email/user/invoice.blade.php @@ -12,6 +12,8 @@ A new invoice has been generated on your account. A summary of that invoice is b ||| Sub Total | ${{ number_format($invoice->sub_total,2) }} | ||| Tax | ${{ number_format($invoice->tax_total,2) }} | ||| Total | ${{ number_format($invoice->total,2) }} | +||| Payments | ${{ number_format($invoice->paid,2) }} | +||| Still Due | ${{ number_format($invoice->due,2) }} | @endcomponent If you would like a PDF copy of that invoice, please click on the link below: diff --git a/resources/views/theme/backend/adminlte/a/payment/addedit.blade.php b/resources/views/theme/backend/adminlte/a/payment/addedit.blade.php index d25c70a..714651f 100644 --- a/resources/views/theme/backend/adminlte/a/payment/addedit.blade.php +++ b/resources/views/theme/backend/adminlte/a/payment/addedit.blade.php @@ -219,7 +219,7 @@ var alloc = 0; $('.invoice').each(function() { - alloc += $(this).val(); + alloc += parseFloat($(this).val()); }) $('#balance').val(($('#total_amt').val()-alloc).toFixed(2))