1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

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 = '';
$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 .= '<li>'.strip_tags($line).'</li>';
} 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 .= '<li>'.strip_tags($line).'</li>';
} 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 .= '<li>'.strip_tags($line).'</li>';
} 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 .= '<li>'.strip_tags($line).'</li>';
} 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'];
}
}

View File

@ -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);
}
],
];
}

View File

@ -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',
);

View File

@ -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 + "<span class='glyphicon glyphicon-repeat'></span>");
}
function onEmailClick() {
if (!NINJA.isRegistered) {
swal("{!! trans('texts.registration_required') !!}");