Enable recurring for a cloned invoice

This commit is contained in:
Hillel Coren 2016-09-26 09:54:59 +03:00
parent 394cb1ad7e
commit 078527443f
4 changed files with 72 additions and 47 deletions

View File

@ -272,62 +272,60 @@ class InvoiceController extends BaseController
$recurringDueDateHelp = ''; $recurringDueDateHelp = '';
$recurringDueDates = []; $recurringDueDates = [];
if ($invoice->is_recurring) { foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_help')) as $line) {
foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_help')) as $line) { $parts = explode('=>', $line);
$parts = explode('=>', $line); if (count($parts) > 1) {
if (count($parts) > 1) { $line = $parts[0].' => '.Utils::processVariables($parts[0]);
$line = $parts[0].' => '.Utils::processVariables($parts[0]); $recurringHelp .= '<li>'.strip_tags($line).'</li>';
$recurringHelp .= '<li>'.strip_tags($line).'</li>'; } else {
} else { $recurringHelp .= $line;
$recurringHelp .= $line;
}
} }
}
foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_due_date_help')) as $line) { foreach (preg_split("/((\r?\n)|(\r\n?))/", trans('texts.recurring_due_date_help')) as $line) {
$parts = explode('=>', $line); $parts = explode('=>', $line);
if (count($parts) > 1) { if (count($parts) > 1) {
$line = $parts[0].' => '.Utils::processVariables($parts[0]); $line = $parts[0].' => '.Utils::processVariables($parts[0]);
$recurringDueDateHelp .= '<li>'.strip_tags($line).'</li>'; $recurringDueDateHelp .= '<li>'.strip_tags($line).'</li>';
} else { } else {
$recurringDueDateHelp .= $line; $recurringDueDateHelp .= $line;
}
} }
}
// Create due date options // Create due date options
$recurringDueDates = [ $recurringDueDates = [
trans('texts.use_client_terms') => ['value' => '', 'class' => 'monthly weekly'], trans('texts.use_client_terms') => ['value' => '', 'class' => 'monthly weekly'],
]; ];
$ends = ['th','st','nd','rd','th','th','th','th','th','th']; $ends = ['th','st','nd','rd','th','th','th','th','th','th'];
for($i = 1; $i < 31; $i++){ for($i = 1; $i < 31; $i++){
if ($i >= 11 && $i <= 13) $ordinal = $i. 'th'; if ($i >= 11 && $i <= 13) $ordinal = $i. 'th';
else $ordinal = $i . $ends[$i % 10]; else $ordinal = $i . $ends[$i % 10];
$dayStr = str_pad($i, 2, '0', STR_PAD_LEFT); $dayStr = str_pad($i, 2, '0', STR_PAD_LEFT);
$str = trans('texts.day_of_month', ['ordinal'=>$ordinal]); $str = trans('texts.day_of_month', ['ordinal'=>$ordinal]);
$recurringDueDates[$str] = ['value' => "1998-01-$dayStr", 'data-num' => $i, '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']; $recurringDueDates[trans('texts.last_day_of_month')] = ['value' => '1998-01-31', 'data-num' => 31, 'class' => 'monthly'];
$daysOfWeek = [ $daysOfWeek = [
trans('texts.sunday'), trans('texts.sunday'),
trans('texts.monday'), trans('texts.monday'),
trans('texts.tuesday'), trans('texts.tuesday'),
trans('texts.wednesday'), trans('texts.wednesday'),
trans('texts.thursday'), trans('texts.thursday'),
trans('texts.friday'), trans('texts.friday'),
trans('texts.saturday'), trans('texts.saturday'),
]; ];
foreach(['1st','2nd','3rd','4th'] as $i=>$ordinal){ foreach(['1st','2nd','3rd','4th'] as $i=>$ordinal){
foreach($daysOfWeek as $j=>$dayOfWeek){ foreach($daysOfWeek as $j=>$dayOfWeek){
$str = trans('texts.day_of_week_after', ['ordinal' => $ordinal, 'day' => $dayOfWeek]); $str = trans('texts.day_of_week_after', ['ordinal' => $ordinal, 'day' => $dayOfWeek]);
$day = $i * 7 + $j + 1; $day = $i * 7 + $j + 1;
$dayStr = str_pad($day, 2, '0', STR_PAD_LEFT); $dayStr = str_pad($day, 2, '0', STR_PAD_LEFT);
$recurringDueDates[$str] = ['value' => "1998-02-$dayStr", 'data-num' => $day, 'class' => 'weekly']; $recurringDueDates[$str] = ['value' => "1998-02-$dayStr", 'data-num' => $day, 'class' => 'weekly'];
}
} }
} }

View File

@ -58,7 +58,17 @@ class RecurringInvoiceDatatable extends EntityDatatable
function ($model) { function ($model) {
return Auth::user()->can('editByOwner', [ENTITY_INVOICE, $model->user_id]); 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);
}
],
]; ];
} }

View File

@ -2139,6 +2139,8 @@ $LANG = array(
'restore_product' => 'Restore Product', 'restore_product' => 'Restore Product',
'blank' => 'Blank', 'blank' => 'Blank',
'invoice_error' => 'There was an error saving your invoice.', 'invoice_error' => 'There was an error saving your invoice.',
'enable_recurring' => 'Enable Recurring',
'disable_recurring' => 'Disable Recurring',
); );

View File

@ -550,6 +550,8 @@
{!! DropdownButton::normal(trans('texts.more_actions')) {!! DropdownButton::normal(trans('texts.more_actions'))
->withContents($actions) ->withContents($actions)
->dropup() !!} ->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 @endif
@endif @endif
@ -1212,6 +1214,19 @@
doc.save(type +'-' + $('#invoice_number').val() + '.pdf'); 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 + "<span class='glyphicon glyphicon-repeat'></span>");
}
function onEmailClick() { function onEmailClick() {
if (!NINJA.isRegistered) { if (!NINJA.isRegistered) {
swal("{!! trans('texts.registration_required') !!}"); swal("{!! trans('texts.registration_required') !!}");