diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 5d58d1656a67..3dc5dd475176 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -272,62 +272,60 @@ class InvoiceController extends BaseController $recurringDueDateHelp = ''; $recurringDueDates = []; - if ($invoice->is_recurring) { - foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_help')) as $line) { - $parts = explode('=>', $line); - if (count($parts) > 1) { - $line = $parts[0].' => '.Utils::processVariables($parts[0]); - $recurringHelp .= '
  • '.strip_tags($line).'
  • '; - } else { - $recurringHelp .= $line; - } + foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_help')) as $line) { + $parts = explode('=>', $line); + if (count($parts) > 1) { + $line = $parts[0].' => '.Utils::processVariables($parts[0]); + $recurringHelp .= '
  • '.strip_tags($line).'
  • '; + } else { + $recurringHelp .= $line; } + } - foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_due_date_help')) as $line) { - $parts = explode('=>', $line); - if (count($parts) > 1) { - $line = $parts[0].' => '.Utils::processVariables($parts[0]); - $recurringDueDateHelp .= '
  • '.strip_tags($line).'
  • '; - } else { - $recurringDueDateHelp .= $line; - } + foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_due_date_help')) as $line) { + $parts = explode('=>', $line); + if (count($parts) > 1) { + $line = $parts[0].' => '.Utils::processVariables($parts[0]); + $recurringDueDateHelp .= '
  • '.strip_tags($line).'
  • '; + } else { + $recurringDueDateHelp .= $line; } + } - // Create due date options - $recurringDueDates = [ - trans('texts.use_client_terms') => ['value' => '', 'class' => 'monthly weekly'], - ]; + // Create due date options + $recurringDueDates = [ + trans('texts.use_client_terms') => ['value' => '', 'class' => 'monthly weekly'], + ]; - $ends = ['th','st','nd','rd','th','th','th','th','th','th']; - for($i = 1; $i < 31; $i++){ - if ($i >= 11 && $i <= 13) $ordinal = $i. 'th'; - else $ordinal = $i . $ends[$i % 10]; + $ends = ['th','st','nd','rd','th','th','th','th','th','th']; + for($i = 1; $i < 31; $i++){ + if ($i >= 11 && $i <= 13) $ordinal = $i. 'th'; + else $ordinal = $i . $ends[$i % 10]; - $dayStr = str_pad($i, 2, '0', STR_PAD_LEFT); - $str = trans('texts.day_of_month', ['ordinal'=>$ordinal]); + $dayStr = str_pad($i, 2, '0', STR_PAD_LEFT); + $str = trans('texts.day_of_month', ['ordinal'=>$ordinal]); - $recurringDueDates[$str] = ['value' => "1998-01-$dayStr", 'data-num' => $i, 'class' => 'monthly']; - } - $recurringDueDates[trans('texts.last_day_of_month')] = ['value' => '1998-01-31', 'data-num' => 31, 'class' => 'monthly']; + $recurringDueDates[$str] = ['value' => "1998-01-$dayStr", 'data-num' => $i, 'class' => 'monthly']; + } + $recurringDueDates[trans('texts.last_day_of_month')] = ['value' => '1998-01-31', 'data-num' => 31, 'class' => 'monthly']; - $daysOfWeek = [ - trans('texts.sunday'), - trans('texts.monday'), - trans('texts.tuesday'), - trans('texts.wednesday'), - trans('texts.thursday'), - trans('texts.friday'), - trans('texts.saturday'), - ]; - foreach(['1st','2nd','3rd','4th'] as $i=>$ordinal){ - foreach($daysOfWeek as $j=>$dayOfWeek){ - $str = trans('texts.day_of_week_after', ['ordinal' => $ordinal, 'day' => $dayOfWeek]); + $daysOfWeek = [ + trans('texts.sunday'), + trans('texts.monday'), + trans('texts.tuesday'), + trans('texts.wednesday'), + trans('texts.thursday'), + trans('texts.friday'), + trans('texts.saturday'), + ]; + foreach(['1st','2nd','3rd','4th'] as $i=>$ordinal){ + foreach($daysOfWeek as $j=>$dayOfWeek){ + $str = trans('texts.day_of_week_after', ['ordinal' => $ordinal, 'day' => $dayOfWeek]); - $day = $i * 7 + $j + 1; - $dayStr = str_pad($day, 2, '0', STR_PAD_LEFT); - $recurringDueDates[$str] = ['value' => "1998-02-$dayStr", 'data-num' => $day, 'class' => 'weekly']; - } + $day = $i * 7 + $j + 1; + $dayStr = str_pad($day, 2, '0', STR_PAD_LEFT); + $recurringDueDates[$str] = ['value' => "1998-02-$dayStr", 'data-num' => $day, 'class' => 'weekly']; } } diff --git a/app/Ninja/Datatables/RecurringInvoiceDatatable.php b/app/Ninja/Datatables/RecurringInvoiceDatatable.php index 64a5bc3307d8..a04bcfe5918d 100644 --- a/app/Ninja/Datatables/RecurringInvoiceDatatable.php +++ b/app/Ninja/Datatables/RecurringInvoiceDatatable.php @@ -58,7 +58,17 @@ class RecurringInvoiceDatatable extends EntityDatatable function ($model) { return Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]); } - ] + ], + [ + trans("texts.clone_invoice"), + function ($model) { + return URL::to("invoices/{$model->public_id}/clone"); + }, + function ($model) { + return Auth::user()->can('create', ENTITY_INVOICE); + } + ], + ]; } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index b0dd5446fb74..e737a1aed197 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2139,6 +2139,8 @@ $LANG = array( 'restore_product' => 'Restore Product', 'blank' => 'Blank', 'invoice_error' => 'There was an error saving your invoice.', + 'enable_recurring' => 'Enable Recurring', + 'disable_recurring' => 'Disable Recurring', ); diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 1292627c199b..6fec4bbc98dc 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -550,6 +550,8 @@ {!! DropdownButton::normal(trans('texts.more_actions')) ->withContents($actions) ->dropup() !!} + @elseif ( ! $invoice->isQuote() && Request::is('*/clone')) + {!! Button::normal(trans($invoice->is_recurring ? 'texts.disable_recurring' : 'texts.enable_recurring'))->withAttributes(['id' => 'recurrButton', 'onclick' => 'onRecurrClick()'])->appendIcon(Icon::create('repeat')) !!} @endif @endif @endif @@ -1212,6 +1214,19 @@ doc.save(type +'-' + $('#invoice_number').val() + '.pdf'); } + function onRecurrClick() { + var invoice = model.invoice(); + if (invoice.is_recurring()) { + var recurring = false; + var label = "{{ trans('texts.enable_recurring')}}"; + } else { + var recurring = true; + var label = "{{ trans('texts.disable_recurring')}}"; + } + invoice.is_recurring(recurring); + $('#recurrButton').html(label + ""); + } + function onEmailClick() { if (!NINJA.isRegistered) { swal("{!! trans('texts.registration_required') !!}");