mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 13:24:29 -04:00
Support using variables in the invoice
This commit is contained in:
parent
2e74ec7d62
commit
a4215a6fbe
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -328,7 +328,7 @@ NINJA.decodeJavascript = function(invoice, javascript)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// search/replace values
|
// search/replace values
|
||||||
var regExp = new RegExp('"\\$[a-z][\\\w\\\.]*?[Value]?"', 'g');
|
var regExp = new RegExp('\\$[a-zA-Z\\.]*[Value]?', 'g');
|
||||||
var matches = javascript.match(regExp);
|
var matches = javascript.match(regExp);
|
||||||
|
|
||||||
if (matches) {
|
if (matches) {
|
||||||
@ -337,13 +337,13 @@ NINJA.decodeJavascript = function(invoice, javascript)
|
|||||||
|
|
||||||
// reserved words
|
// reserved words
|
||||||
if ([
|
if ([
|
||||||
'"$none"',
|
'$none',
|
||||||
'"$firstAndLast"',
|
'$firstAndLast',
|
||||||
'"$notFirstAndLastColumn"',
|
'$notFirstAndLastColumn',
|
||||||
'"$notFirst"',
|
'$notFirst',
|
||||||
'"$amount"',
|
'$amount',
|
||||||
'"$primaryColor"',
|
'$primaryColor',
|
||||||
'"$secondaryColor"',
|
'$secondaryColor',
|
||||||
].indexOf(match) >= 0) {
|
].indexOf(match) >= 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -351,11 +351,16 @@ NINJA.decodeJavascript = function(invoice, javascript)
|
|||||||
field = match.replace('$invoice.', '$');
|
field = match.replace('$invoice.', '$');
|
||||||
|
|
||||||
// legacy style had 'Value' at the end
|
// legacy style had 'Value' at the end
|
||||||
if (endsWith(field, 'Value"')) {
|
if (endsWith(field, 'Value')) {
|
||||||
field = field.substring(2, field.indexOf('Value'));
|
field = field.substring(1, field.indexOf('Value'));
|
||||||
} else {
|
} else {
|
||||||
field = field.substring(2, field.length - 1);
|
field = field.substring(1, field.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! field) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
field = toSnakeCase(field);
|
field = toSnakeCase(field);
|
||||||
|
|
||||||
if (field == 'footer') {
|
if (field == 'footer') {
|
||||||
@ -374,7 +379,9 @@ NINJA.decodeJavascript = function(invoice, javascript)
|
|||||||
value = formatMoneyInvoice(value, invoice);
|
value = formatMoneyInvoice(value, invoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
javascript = javascript.replace(match, '"'+value+'"');
|
if ($.trim(value)) {
|
||||||
|
javascript = javascript.replace(match, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user