From 5f998b0ea8a952a72f34d9aa4ecc71b19066a133 Mon Sep 17 00:00:00 2001 From: Francisco Ferreira Date: Thu, 18 Jul 2019 07:26:59 +0100 Subject: [PATCH] Fixes recurring invoices end date parsing (port of #2905 to master) (#2906) * Invoice edit view: fix date parsing View gets the date already formatted and Carbon isn't always able to parse that format automatically, so convert it back to SQL format * RecurringInvoiceDatatable: fix status label --- app/Ninja/Datatables/RecurringInvoiceDatatable.php | 3 +++ resources/views/invoices/edit.blade.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/Ninja/Datatables/RecurringInvoiceDatatable.php b/app/Ninja/Datatables/RecurringInvoiceDatatable.php index a4e976ef0a..341eff8017 100644 --- a/app/Ninja/Datatables/RecurringInvoiceDatatable.php +++ b/app/Ninja/Datatables/RecurringInvoiceDatatable.php @@ -3,6 +3,7 @@ namespace App\Ninja\Datatables; use Auth; +use Carbon; use URL; use Utils; use App\Models\Invoice; @@ -84,6 +85,8 @@ class RecurringInvoiceDatatable extends EntityDatatable if ($model->invoice_status_id == INVOICE_STATUS_SENT) { if (! $model->last_sent_date_sql || $model->last_sent_date_sql == '0000-00-00') { $label = trans('texts.pending'); + } elseif ($model->end_date_sql && Carbon::parse($model->end_date_sql)->isPast()) { + $label = trans('texts.status_completed'); } else { $label = trans('texts.active'); } diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index eb6bc962cd..41d10259c9 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -76,7 +76,7 @@ @if ($invoice->is_recurring && $invoice->isSent()) @if (! $invoice->last_sent_date || $invoice->last_sent_date == '0000-00-00') {!! $invoice->present()->statusLabel(trans('texts.pending')) !!} - @elseif ($invoice->end_date && Carbon::parse($invoice->end_date)->isPast()) + @elseif ($invoice->end_date && Carbon::parse(Utils::toSqlDate($invoice->end_date))->isPast()) {!! $invoice->present()->statusLabel(trans('texts.status_completed')) !!} @else {!! $invoice->present()->statusLabel(trans('texts.active')) !!}