From accbbcf67b8e0870965351410a4791e9a48e9b6b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 8 Oct 2019 12:03:40 +1000 Subject: [PATCH] Flash message --- .../ClientPortal/InvoiceController.php | 9 ++- app/Models/Invoice.php | 17 ++++- .../portal/default/flash-message.blade.php | 62 ++++++++++--------- .../portal/default/invoices/index.blade.php | 3 +- .../portal/default/layouts/master.blade.php | 4 +- 5 files changed, 56 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index c34ec5d21492..2e2e92ee7ab0 100644 --- a/app/Http/Controllers/ClientPortal/InvoiceController.php +++ b/app/Http/Controllers/ClientPortal/InvoiceController.php @@ -120,9 +120,14 @@ class InvoiceController extends Controller $total = $invoices->sum('balance'); - $invoices->filter(function ($invoice){ + $invoices = $invoices->filter(function ($invoice){ return $invoice->isPayable(); - })->map(function ($invoice){ + }); + + if($invoices->count() == 0) + return back()->with(['warning' => 'No payable invoices selected']); + + $invoices->map(function ($invoice){ $invoice->balance = Number::formatMoney($invoice->balance, $invoice->client); $invoice->due_date = $this->formatDate($invoice->due_date, $invoice->client->date_format()); return $invoice; diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index b6f87fa42967..202fdd587cf4 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -192,14 +192,25 @@ class Invoice extends BaseModel return strtotime($this->createClientDate(date(), $this->client->timezone()->name)) > (strtotime($due_date) + (60 * 60 * 24)); } - public function markViewed() + public function markViewed() :void { $this->last_viewed = Carbon::now()->format('Y-m-d H:i'); + $this->save(); } - public function isPayable() + public function isPayable() : bool { - return ($this->status === Invoice::STATUS_UNPAID || $this->status === Invoice::STATUS_OVERDUE); + + if($this->status_id == Invoice::STATUS_SENT && $this->due_date > Carbon::now()) + return true; + else if($this->status_id == Invoice::STATUS_PARTIAL && $this->partial_due_date > Carbon::now()) + return true; + else if($this->status_id == Invoice::STATUS_SENT && $this->due_date < Carbon::now()) + return true; + else if($this->status_id == Invoice::STATUS_PARTIAL && $this->partial_due_date < Carbon::now()) + return true; + else + return false; } public static function badgeForStatus(int $status) diff --git a/resources/views/portal/default/flash-message.blade.php b/resources/views/portal/default/flash-message.blade.php index 66445001ec3d..7ca9fb7c516f 100644 --- a/resources/views/portal/default/flash-message.blade.php +++ b/resources/views/portal/default/flash-message.blade.php @@ -1,38 +1,40 @@ -@if ($message = Session::get('success')) -
- - {{ $message }} -
-@endif +
+ @if ($message = Session::get('success')) +
+ + {{ $message }} +
+ @endif -@if ($message = Session::get('error')) -
- - {{ $message }} -
-@endif + @if ($message = Session::get('error')) +
+ + {{ $message }} +
+ @endif -@if ($message = Session::get('warning')) -
- - {{ $message }} -
-@endif + @if ($message = Session::get('warning')) +
+ + {{ $message }} +
+ @endif -@if ($message = Session::get('info')) -
- - {{ $message }} -
-@endif + @if ($message = Session::get('info')) +
+ + {{ $message }} +
+ @endif -@if ($errors->any()) -
- - Please check the form below for errors -
-@endif \ No newline at end of file + @if ($errors->any()) +
+ + Please check the form below for errors +
+ @endif +
\ No newline at end of file diff --git a/resources/views/portal/default/invoices/index.blade.php b/resources/views/portal/default/invoices/index.blade.php index 2d7b3e27742f..1b0da129fc22 100644 --- a/resources/views/portal/default/invoices/index.blade.php +++ b/resources/views/portal/default/invoices/index.blade.php @@ -21,7 +21,8 @@ {!! Former::close() !!}
- + @include('portal.default.flash-message') +
diff --git a/resources/views/portal/default/layouts/master.blade.php b/resources/views/portal/default/layouts/master.blade.php index 27c26c9a456d..c17e093ee864 100644 --- a/resources/views/portal/default/layouts/master.blade.php +++ b/resources/views/portal/default/layouts/master.blade.php @@ -46,12 +46,10 @@ .nav {min-height: calc(100% - 55px);} @stack('css') - - @yield('head') + @yield('head') @include('portal.default.header') @yield('header') -@include('portal.default.flash-message') @include('portal.default.sidebar') @yield('sidebar') @section('body')