From 4ed8468195f81a3a32c5b46999153bf1bb670992 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 3 Apr 2017 22:06:09 +0300 Subject: [PATCH] Always show recurring invoices in client portal --- app/Http/Controllers/ClientPortalController.php | 10 ++++++++-- app/Models/Client.php | 10 +++++++++- app/Ninja/Repositories/InvoiceRepository.php | 8 ++++++-- resources/views/public_list.blade.php | 6 +++--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/ClientPortalController.php b/app/Http/Controllers/ClientPortalController.php index c583835fd49d..9800a1ed1651 100644 --- a/app/Http/Controllers/ClientPortalController.php +++ b/app/Http/Controllers/ClientPortalController.php @@ -326,14 +326,20 @@ class ClientPortalController extends BaseController } $color = $account->primary_color ? $account->primary_color : '#0b4d78'; + $columns = ['frequency', 'start_date', 'end_date', 'invoice_total']; + $client = $contact->client; + + if ($client->hasAutoBillConfigurableInvoices()) { + $columns[] = 'auto_bill'; + } $data = [ 'color' => $color, 'account' => $account, - 'client' => $contact->client, + 'client' => $client, 'title' => trans('texts.recurring_invoices'), 'entityType' => ENTITY_RECURRING_INVOICE, - 'columns' => Utils::trans(['frequency', 'start_date', 'end_date', 'invoice_total', 'auto_bill']), + 'columns' => Utils::trans($columns), ]; return response()->view('public_list', $data); diff --git a/app/Models/Client.php b/app/Models/Client.php index 5a42983d38ba..7f886fc96879 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -543,7 +543,15 @@ class Client extends EntityModel */ public function hasAutoBillConfigurableInvoices() { - return $this->invoices()->whereIn('auto_bill', [AUTO_BILL_OPT_IN, AUTO_BILL_OPT_OUT])->count() > 0; + return $this->invoices()->whereIsPublic(true)->whereIn('auto_bill', [AUTO_BILL_OPT_IN, AUTO_BILL_OPT_OUT])->count() > 0; + } + + /** + * @return bool + */ + public function hasRecurringInvoices() + { + return $this->invoices()->whereIsPublic(true)->whereIsRecurring(true)->count() > 0; } public function defaultDaysDue() diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index b52982841163..3daa8b3d89b4 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -211,7 +211,6 @@ class InvoiceRepository extends BaseRepository ->where('clients.deleted_at', '=', null) ->where('invoices.is_recurring', '=', true) ->where('invoices.is_public', '=', true) - ->whereIn('invoices.auto_bill', [AUTO_BILL_OPT_IN, AUTO_BILL_OPT_OUT]) //->where('invoices.start_date', '>=', date('Y-m-d H:i:s')) ->select( DB::raw('COALESCE(clients.currency_id, accounts.currency_id) currency_id'), @@ -225,6 +224,7 @@ class InvoiceRepository extends BaseRepository 'invoices.amount', 'invoices.start_date', 'invoices.end_date', + 'invoices.auto_bill', 'invoices.client_enable_auto_bill', 'frequencies.name as frequency' ); @@ -243,7 +243,11 @@ class InvoiceRepository extends BaseRepository return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id); }) ->addColumn('client_enable_auto_bill', function ($model) { - if ($model->client_enable_auto_bill) { + if ($model->auto_bill == AUTO_BILL_OFF) { + return trans('texts.disabled'); + } elseif ($model->auto_bill == AUTO_BILL_ALWAYS) { + return trans('texts.enabled'); + } elseif ($model->client_enable_auto_bill) { return trans('texts.enabled') . ' - '.trans('texts.disable').''; } else { return trans('texts.disabled') . ' - '.trans('texts.enable').''; diff --git a/resources/views/public_list.blade.php b/resources/views/public_list.blade.php index bc8e7d35839f..bd81eb30dadd 100644 --- a/resources/views/public_list.blade.php +++ b/resources/views/public_list.blade.php @@ -35,9 +35,9 @@ --> - @if($entityType == ENTITY_INVOICE && $account->getTokenGatewayId() && $client->hasAutoBillConfigurableInvoices()) + @if($entityType == ENTITY_INVOICE && $client->hasRecurringInvoices())
- {!! Button::info(trans("texts.manage_auto_bill"))->asLinkTo(URL::to('/client/invoices/recurring'))->appendIcon(Icon::create('repeat')) !!} + {!! Button::primary(trans("texts.recurring_invoices"))->asLinkTo(URL::to('/client/invoices/recurring')) !!}
@endif

{{ $title }}

@@ -49,7 +49,7 @@ ->render('datatable') !!} - @if($entityType == ENTITY_RECURRING_INVOICE) + @if ($entityType == ENTITY_RECURRING_INVOICE) {!! Former::open(URL::to('/client/invoices/auto_bill'))->id('auto_bill_form') !!}