1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00

Show warning when changing recurring invoice start date

This commit is contained in:
Hillel Coren 2016-05-22 19:51:09 +03:00
parent bb2fa9a18e
commit ac09d86f68
3 changed files with 46 additions and 27 deletions

View File

@ -1305,6 +1305,11 @@ $LANG = array(
'canada' => 'Canada',
'accept_debit_cards' => 'Accept Debit Cards',
'debit_cards' => 'Debit Cards',
'warn_start_date_changed' => 'The next invoice will be sent on the new start date.',
'original_start_date' => 'Original start date',
'new_start_date' => 'New start date',
);
return $LANG;

View File

@ -530,7 +530,7 @@
@if ( ! $invoice->is_recurring)
{!! Button::primary(trans('texts.download_pdf'))->withAttributes(array('onclick' => 'onDownloadClick()'))->appendIcon(Icon::create('download-alt')) !!}
@endif
@if ($invoice->isClientTrashed())
<!-- do nothing -->
@elseif ($invoice->trashed())
@ -809,6 +809,7 @@
var invoice = {!! $invoice !!};
ko.mapping.fromJS(invoice, model.invoice().mapping, model.invoice);
model.invoice().is_recurring({{ $invoice->is_recurring ? '1' : '0' }});
model.invoice().start_date_orig(model.invoice().start_date());
@if ($invoice->id)
var invitationContactIds = {!! json_encode($invitationContactIds) !!};
@ -1192,14 +1193,26 @@
}
function onSaveClick() {
if (model.invoice().is_recurring() && {{ $invoice ? 'false' : 'true' }}) {
if (confirm("{!! trans("texts.confirm_recurring_email_$entityType") !!}" + '\n\n' + getSendToEmails() + '\n' + "{!! trans("texts.confirm_recurring_timing") !!}")) {
submitAction('');
}
} else {
preparePdfData('');
}
}
if (model.invoice().is_recurring()) {
// warn invoice will be emailed when saving new recurring invoice
if ({{ $invoice->exists() ? 'false' : 'true' }}) {
if (confirm("{!! trans("texts.confirm_recurring_email_$entityType") !!}" + '\n\n' + getSendToEmails() + '\n' + "{!! trans("texts.confirm_recurring_timing") !!}")) {
submitAction('');
}
return;
// warn invoice will be emailed again if start date is changed
} else if (model.invoice().start_date() != model.invoice().start_date_orig()) {
if (confirm("{!! trans("texts.warn_start_date_changed") !!}" + '\n\n'
+ "{!! trans("texts.original_start_date") !!}: " + model.invoice().start_date_orig() + '\n'
+ "{!! trans("texts.new_start_date") !!}: " + model.invoice().start_date())) {
submitAction('');
}
return;
}
}
preparePdfData('');
}
function getSendToEmails() {
var client = model.invoice().client();

View File

@ -55,7 +55,7 @@ function ViewModel(data) {
if (self.invoice().tax_name1() || self.invoice().tax_name2()) {
return true;
}
return self.invoice_taxes() && {{ count($taxRateOptions) ? 'true' : 'false' }};
});
@ -100,11 +100,11 @@ function ViewModel(data) {
$('input.client-email').each(function(item, value) {
var $email = $(value);
var email = $(value).val();
// Trim whitespace
email = (email || '').trim();
$email.val(email);
if (!firstName && (!email || !isValidEmailAddress(email))) {
isValid = false;
}
@ -180,6 +180,7 @@ function InvoiceModel(data) {
self.due_date = ko.observable('');
self.recurring_due_date = ko.observable('');
self.start_date = ko.observable('');
self.start_date_orig = ko.observable('');
self.end_date = ko.observable('');
self.last_sent_date = ko.observable('');
self.tax_name1 = ko.observable();
@ -240,13 +241,13 @@ function InvoiceModel(data) {
applyComboboxListeners();
return itemModel;
}
self.addDocument = function() {
var documentModel = new DocumentModel();
self.documents.push(documentModel);
return documentModel;
}
self.removeDocument = function(doc) {
var public_id = doc.public_id?doc.public_id():doc;
self.documents.remove(function(document) {
@ -291,7 +292,7 @@ function InvoiceModel(data) {
self.tax_rate2(rate);
}
})
self.wrapped_terms = ko.computed({
read: function() {
return this.terms();
@ -386,7 +387,7 @@ function InvoiceModel(data) {
var taxRate2 = parseFloat(self.tax_rate2());
var tax2 = roundToTwo(total * (taxRate2/100));
return self.formatMoney(tax1 + tax2);
});
@ -403,7 +404,7 @@ function InvoiceModel(data) {
lineTotal -= roundToTwo(lineTotal * (self.discount()/100));
}
}
var taxAmount = roundToTwo(lineTotal * item.tax_rate1() / 100);
if (taxAmount) {
var key = item.tax_name1() + item.tax_rate1();
@ -664,12 +665,12 @@ function ContactModel(data) {
return str;
});
self.info_color = ko.computed(function() {
if (self.invitation_viewed()) {
return '#57D172';
} else if (self.invitation_openend()) {
return '#FFCC00';
return '#FFCC00';
} else {
return '#B1B5BA';
}
@ -780,7 +781,7 @@ function ItemModel(data) {
this.onSelect = function() {}
}
function DocumentModel(data) {
var self = this;
self.public_id = ko.observable(0);
@ -788,16 +789,16 @@ function DocumentModel(data) {
self.name = ko.observable('');
self.type = ko.observable('');
self.url = ko.observable('');
self.update = function(data){
ko.mapping.fromJS(data, {}, this);
}
if (data) {
self.update(data);
}
}
}
var ExpenseModel = function(data) {
var self = this;
@ -808,7 +809,7 @@ var ExpenseModel = function(data) {
}
}
}
self.description = ko.observable('');
self.qty = ko.observable(0);
self.public_id = ko.observable(0);
@ -825,7 +826,7 @@ ko.bindingHandlers.typeahead = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
var $element = $(element);
var allBindings = allBindingsAccessor();
$element.typeahead({
highlight: true,
minLength: 0,
@ -875,4 +876,4 @@ ko.bindingHandlers.typeahead = {
}
};
</script>
</script>