diff --git a/app/Http/Controllers/ClientPortal/InvoiceController.php b/app/Http/Controllers/ClientPortal/InvoiceController.php index c34ec5d21..2e2e92ee7 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 b6f87fa42..202fdd587 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 66445001e..7ca9fb7c5 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')) -