e?(-e<<1)+1:(e<<1)+0}function i(e){var t=1===(1&e),r=e>>1;return t?-r:r}var a=r(5),s=5,u=1<>>=s,n>0&&(t|=l),r+=a.encode(t);while(n>0);return r},t.decode=function(e,t){var r,n,o=0,u=e.length,f=0,p=0;do{if(o>=u)throw new Error("Expected more digits in base 64 VLQ value.");n=a.decode(e.charAt(o++)),r=!!(n&l),n&=c,f+=n<=200&&o.status<400)return t(o.responseText);n(new Error("Unable to retrieve "+e))}},o.send()}function o(e,t,r){for(var n,o,i,a=/function\s+([^(]*?)\s*\(([^)]*)\)/,s=/['"]?([$_A-Za-z][$_A-Za-z0-9]*)['"]?\s*[:=]\s*function\b/,u=/['"]?([$_A-Za-z][$_A-Za-z0-9]*)['"]?\s*[:=]\s*(?:eval|new Function)\b/,c=e.split("\n"),l="",f=Math.min(t,20),p=0;f>p;++p)if(n=c[t-p-1],i=n.indexOf("//"),i>=0&&(n=n.substr(0,i)),n){if(l=n+l,o=s.exec(l),o&&o[1])return o[1];if(o=a.exec(l),o&&o[1])return o[1];if(o=u.exec(l),o&&o[1])return o[1]}return void 0}function i(){if("function"!=typeof Object.defineProperty||"function"!=typeof Object.create)throw new Error("Unable to consume source maps in older browsers")}function a(e){if("object"!=typeof e)throw new TypeError("Given StackFrame is not an object");if("string"!=typeof e.fileName)throw new TypeError("Given file name is not a String");if("number"!=typeof e.lineNumber||e.lineNumber%1!==0||e.lineNumber<1)throw new TypeError("Given line number must be a positive integer");if("number"!=typeof e.columnNumber||e.columnNumber%1!==0||e.columnNumber<0)throw new TypeError("Given column number must be a non-negative integer");return!0}function s(e){var t=/\/\/[#@] ?sourceMappingURL=([^\s'"]+)$/.exec(e);if(t&&t[1])return t[1];throw new Error("sourceMappingURL not found")}function u(r,n,o,i){var a=new e.SourceMapConsumer(r).originalPositionFor({line:o,column:i});return new t(a.name,n,a.source,a.line,a.column)}return function c(e){return this instanceof c?(e=e||{},this.sourceCache=e.sourceCache||{},this.ajax=n,this._atob=function(e){if(window&&window.atob)return window.atob(e);if("undefined"!=typeof Buffer)return new Buffer(e,"base64").toString("utf-8");throw new Error("No base64 decoder available")},this._get=function(t){return new Promise(function(r,n){var o="data:"===t.substr(0,5);if(this.sourceCache[t])r(this.sourceCache[t]);else if(e.offline&&!o)n(new Error("Cannot make network requests in offline mode"));else if(o){var i="application/json;base64";if(t.substr(5,i.length)!==i)n(new Error("The encoding of the inline sourcemap is not supported"));else{var a="data:".length+i.length+",".length,s=t.substr(a),u=this._atob(s);this.sourceCache[t]=u,r(u)}}else this.ajax(t,function(e){this.sourceCache[t]=e,r(e)}.bind(this),n)}.bind(this))},this.pinpoint=function(e){return new Promise(function(t,r){this.getMappedLocation(e).then(function(e){function r(){t(e)}this.findFunctionName(e).then(t,r)["catch"](r)}.bind(this),r)}.bind(this))},this.findFunctionName=function(e){return new Promise(function(r,n){a(e),this._get(e.fileName).then(function(n){var i=o(n,e.lineNumber,e.columnNumber);r(new t(i,e.args,e.fileName,e.lineNumber,e.columnNumber))},n)}.bind(this))},void(this.getMappedLocation=function(e){return new Promise(function(t,r){i(),a(e);var n=e.fileName;this._get(n).then(function(o){var i=s(o);"/"!==i[0]&&(i=n.substring(0,n.lastIndexOf("/")+1)+i),this._get(i).then(function(r){var n=e.lineNumber,o=e.columnNumber;t(u(r,e.args,n,o))},r)["catch"](r)}.bind(this),r)["catch"](r)}.bind(this))})):new c(e)}}),function(e,t){"use strict";"function"==typeof define&&define.amd?define("stack-generator",["stackframe"],t):"object"==typeof exports?module.exports=t(require("stackframe")):e.StackGenerator=t(e.StackFrame)}(this,function(e){return{backtrace:function(t){var r=[],n=10;"object"==typeof t&&"number"==typeof t.maxStackSize&&(n=t.maxStackSize);for(var o=arguments.callee;o&&r.length-1&&e.message.split("\n").length>e.stacktrace.split("\n").length?this.parseOpera9(e):e.stack?this.parseOpera11(e):this.parseOpera10(e)},parseOpera9:function(t){for(var r=/Line (\d+).*script (?:in )?(\S+)/i,n=t.message.split("\n"),o=[],i=2,a=n.length;a>i;i+=2){var s=r.exec(n[i]);s&&o.push(new e(void 0,void 0,s[2],s[1],void 0,n[i]))}return o},parseOpera10:function(t){for(var r=/Line (\d+).*script (?:in )?(\S+)(?:: In function (\S+))?$/i,n=t.stacktrace.split("\n"),o=[],i=0,a=n.length;a>i;i+=2){var s=r.exec(n[i]);s&&o.push(new e(s[3]||void 0,void 0,s[2],s[1],void 0,n[i]))}return o},parseOpera11:function(r){return r.stack.split("\n").filter(function(e){return!!e.match(t)&&!e.match(/^Error created at/)},this).map(function(t){var r,n=t.split("@"),o=this.extractLocation(n.pop()),i=n.shift()||"",a=i.replace(//,"$2").replace(/\([^\)]*\)/g,"")||void 0;i.match(/\(([^\)]*)\)/)&&(r=i.replace(/^[^\(]+\(([^\)]*)\)$/,"$1"));var s=void 0===r||"[arguments not available]"===r?void 0:r.split(",");return new e(a,s,o[0],o[1],o[2],t)},this)}}}),function(e,t){"use strict";"function"==typeof define&&define.amd?define("stacktrace",["error-stack-parser","stack-generator","stacktrace-gps"],t):"object"==typeof exports?module.exports=t(require("error-stack-parser"),require("stack-generator"),require("stacktrace-gps")):e.StackTrace=t(e.ErrorStackParser,e.StackGenerator,e.StackTraceGPS)}(this,function(e,t,r){function n(e,t){var r={};return[e,t].forEach(function(e){for(var t in e)e.hasOwnProperty(t)&&(r[t]=e[t]);return r}),r}function o(e){return e.stack||e["opera#sourceloc"]}var i={filter:function(e){return-1===(e.functionName||"").indexOf("StackTrace$$")&&-1===(e.functionName||"").indexOf("ErrorStackParser$$")&&-1===(e.functionName||"").indexOf("StackTraceGPS$$")&&-1===(e.functionName||"").indexOf("StackGenerator$$")}};return{get:function(e){try{throw new Error}catch(t){return o(t)?this.fromError(t,e):this.generateArtificially(e)}},fromError:function(t,o){return o=n(i,o),new Promise(function(n){var i=e.parse(t);"function"==typeof o.filter&&(i=i.filter(o.filter)),n(Promise.all(i.map(function(e){return new Promise(function(t){function n(r){t(e)}new r(o).pinpoint(e).then(t,n)["catch"](n)})})))}.bind(this))},generateArtificially:function(e){e=n(i,e);var r=t.backtrace(e);return"function"==typeof e.filter&&(r=r.filter(e.filter)),Promise.resolve(r)},instrument:function(e,t,r,n){if("function"!=typeof e)throw new Error("Cannot instrument non-function object");if("function"==typeof e.__stacktraceOriginalFn)return e;var i=function(){try{this.get().then(t,r)["catch"](r),e.apply(n||this,arguments)}catch(i){throw o(i)&&this.fromError(i).then(t,r)["catch"](r),i}}.bind(this);return i.__stacktraceOriginalFn=e,i},deinstrument:function(e){if("function"!=typeof e)throw new Error("Cannot de-instrument non-function object");return"function"==typeof e.__stacktraceOriginalFn?e.__stacktraceOriginalFn:e},report:function(e,t){return new Promise(function(r,n){var o=new XMLHttpRequest;o.onerror=n,o.onreadystatechange=function(){4===o.readyState&&(o.status>=200&&o.status<400?r(o.responseText):n(new Error("POST to "+t+" failed with status: "+o.status)))},o.open("post",t),o.setRequestHeader("Content-Type","application/json"),o.send(JSON.stringify({stack:e}))})}}});
-//# sourceMappingURL=vendor/stacktrace-js/dist/stacktrace-with-polyfills.min.js.map
/**
* @license
* Fuse - Lightweight fuzzy-search
@@ -31251,13 +31248,13 @@ NINJA.notesAndTerms = function(invoice)
var data = [];
if (invoice.public_notes) {
- data.push({stack:[{text: invoice.public_notes, style: ['notes']}]});
+ data.push({stack:[{text: invoice.is_recurring ? processVariables(invoice.public_notes) : invoice.public_notes, style: ['notes']}]});
data.push({text:' '});
}
if (invoice.terms) {
data.push({text:invoiceLabels.terms, style: ['termsLabel']});
- data.push({stack:[{text: invoice.terms, style: ['terms']}]});
+ data.push({stack:[{text: invoice.is_recurring ? processVariables(invoice.terms) : invoice.terms, style: ['terms']}]});
}
return NINJA.prepareDataList(data, 'notesAndTerms');
@@ -31297,10 +31294,16 @@ NINJA.invoiceColumns = function(invoice)
NINJA.invoiceFooter = function(invoice)
{
+ var footer = invoice.invoice_footer;
+
+ if (invoice.is_recurring) {
+ footer = processVariables(footer);
+ }
+
if (!invoice.features.invoice_settings && invoice.invoice_design_id == 3) {
- return invoice.invoice_footer ? invoice.invoice_footer.substring(0, 200) : ' ';
+ return footer ? footer.substring(0, 200) : ' ';
} else {
- return invoice.invoice_footer || ' ';
+ return footer || ' ';
}
}
@@ -31591,13 +31594,13 @@ NINJA.invoiceDetails = function(invoice) {
if (invoice.custom_text_value1) {
data.push([
{text: invoice.account.custom_invoice_text_label1},
- {text: invoice.custom_text_value1}
+ {text: invoice.is_recurring ? processVariables(invoice.custom_text_value1) : invoice.custom_text_value1}
])
}
if (invoice.custom_text_value2) {
data.push([
{text: invoice.account.custom_invoice_text_label2},
- {text: invoice.custom_text_value2}
+ {text: invoice.is_recurring ? processVariables(invoice.custom_text_value2) : invoice.custom_text_value2}
])
}
diff --git a/public/js/pdf.pdfmake.js b/public/js/pdf.pdfmake.js
index ca728d4066..26d82f979c 100644
--- a/public/js/pdf.pdfmake.js
+++ b/public/js/pdf.pdfmake.js
@@ -247,13 +247,13 @@ NINJA.notesAndTerms = function(invoice)
var data = [];
if (invoice.public_notes) {
- data.push({stack:[{text: invoice.public_notes, style: ['notes']}]});
+ data.push({stack:[{text: invoice.is_recurring ? processVariables(invoice.public_notes) : invoice.public_notes, style: ['notes']}]});
data.push({text:' '});
}
if (invoice.terms) {
data.push({text:invoiceLabels.terms, style: ['termsLabel']});
- data.push({stack:[{text: invoice.terms, style: ['terms']}]});
+ data.push({stack:[{text: invoice.is_recurring ? processVariables(invoice.terms) : invoice.terms, style: ['terms']}]});
}
return NINJA.prepareDataList(data, 'notesAndTerms');
@@ -293,10 +293,16 @@ NINJA.invoiceColumns = function(invoice)
NINJA.invoiceFooter = function(invoice)
{
+ var footer = invoice.invoice_footer;
+
+ if (invoice.is_recurring) {
+ footer = processVariables(footer);
+ }
+
if (!invoice.features.invoice_settings && invoice.invoice_design_id == 3) {
- return invoice.invoice_footer ? invoice.invoice_footer.substring(0, 200) : ' ';
+ return footer ? footer.substring(0, 200) : ' ';
} else {
- return invoice.invoice_footer || ' ';
+ return footer || ' ';
}
}
@@ -587,13 +593,13 @@ NINJA.invoiceDetails = function(invoice) {
if (invoice.custom_text_value1) {
data.push([
{text: invoice.account.custom_invoice_text_label1},
- {text: invoice.custom_text_value1}
+ {text: invoice.is_recurring ? processVariables(invoice.custom_text_value1) : invoice.custom_text_value1}
])
}
if (invoice.custom_text_value2) {
data.push([
{text: invoice.account.custom_invoice_text_label2},
- {text: invoice.custom_text_value2}
+ {text: invoice.is_recurring ? processVariables(invoice.custom_text_value2) : invoice.custom_text_value2}
])
}
From 986156117e40d5f49996c93822a9c8ad290b4287 Mon Sep 17 00:00:00 2001
From: Raymond
Date: Sat, 7 May 2016 15:29:27 +0200
Subject: [PATCH 09/11] Copy custom values of invoice items
---
app/Ninja/Repositories/InvoiceRepository.php | 2 ++
public/built.js | 10 +++++++---
public/js/pdf.pdfmake.js | 10 +++++++---
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php
index 0596462e0c..91ffddfea1 100644
--- a/app/Ninja/Repositories/InvoiceRepository.php
+++ b/app/Ninja/Repositories/InvoiceRepository.php
@@ -743,6 +743,8 @@ class InvoiceRepository extends BaseRepository
$item->tax_rate1 = $recurItem->tax_rate1;
$item->tax_name2 = $recurItem->tax_name2;
$item->tax_rate2 = $recurItem->tax_rate2;
+ $item->custom_value1 = Utils::processVariables($recurItem->custom_value1);
+ $item->custom_value2 = Utils::processVariables($recurItem->custom_value2);
$invoice->invoice_items()->save($item);
}
diff --git a/public/built.js b/public/built.js
index 2ebcfe7e36..7be10bc1f8 100644
--- a/public/built.js
+++ b/public/built.js
@@ -31359,7 +31359,9 @@ NINJA.invoiceLines = function(invoice) {
var notes = item.notes;
var productKey = item.product_key;
var tax1 = '';
- var tax2 = '';
+ var tax2 = '';
+ var custom_value1 = item.custom_value1;
+ var custom_value2 = item.custom_value2;
if (showItemTaxes) {
if (item.tax_name1) {
@@ -31381,6 +31383,8 @@ NINJA.invoiceLines = function(invoice) {
if (invoice.is_recurring) {
notes = processVariables(notes);
productKey = processVariables(productKey);
+ custom_value1 = processVariables(item.custom_value1);
+ custom_value2 = processVariables(item.custom_value2);
}
var lineTotal = roundToTwo(NINJA.parseFloat(item.cost)) * roundToTwo(NINJA.parseFloat(item.qty));
@@ -31393,10 +31397,10 @@ NINJA.invoiceLines = function(invoice) {
}
row.push({style:["notes", rowStyle], stack:[{text:notes || ' '}]});
if (invoice.features.invoice_settings && account.custom_invoice_item_label1) {
- row.push({style:["customValue1", rowStyle], text:item.custom_value1 || ' '});
+ row.push({style:["customValue1", rowStyle], text:custom_value1 || ' '});
}
if (invoice.features.invoice_settings && account.custom_invoice_item_label2) {
- row.push({style:["customValue2", rowStyle], text:item.custom_value2 || ' '});
+ row.push({style:["customValue2", rowStyle], text:custom_value2 || ' '});
}
row.push({style:["cost", rowStyle], text:cost});
if (!hideQuantity) {
diff --git a/public/js/pdf.pdfmake.js b/public/js/pdf.pdfmake.js
index 26d82f979c..4ee0b306da 100644
--- a/public/js/pdf.pdfmake.js
+++ b/public/js/pdf.pdfmake.js
@@ -358,7 +358,9 @@ NINJA.invoiceLines = function(invoice) {
var notes = item.notes;
var productKey = item.product_key;
var tax1 = '';
- var tax2 = '';
+ var tax2 = '';
+ var custom_value1 = item.custom_value1;
+ var custom_value2 = item.custom_value2;
if (showItemTaxes) {
if (item.tax_name1) {
@@ -380,6 +382,8 @@ NINJA.invoiceLines = function(invoice) {
if (invoice.is_recurring) {
notes = processVariables(notes);
productKey = processVariables(productKey);
+ custom_value1 = processVariables(item.custom_value1);
+ custom_value2 = processVariables(item.custom_value2);
}
var lineTotal = roundToTwo(NINJA.parseFloat(item.cost)) * roundToTwo(NINJA.parseFloat(item.qty));
@@ -392,10 +396,10 @@ NINJA.invoiceLines = function(invoice) {
}
row.push({style:["notes", rowStyle], stack:[{text:notes || ' '}]});
if (invoice.features.invoice_settings && account.custom_invoice_item_label1) {
- row.push({style:["customValue1", rowStyle], text:item.custom_value1 || ' '});
+ row.push({style:["customValue1", rowStyle], text:custom_value1 || ' '});
}
if (invoice.features.invoice_settings && account.custom_invoice_item_label2) {
- row.push({style:["customValue2", rowStyle], text:item.custom_value2 || ' '});
+ row.push({style:["customValue2", rowStyle], text:custom_value2 || ' '});
}
row.push({style:["cost", rowStyle], text:cost});
if (!hideQuantity) {
From cf9dbae1d10f567f7e2084d4fca2108b3c6fd195 Mon Sep 17 00:00:00 2001
From: Hillel Coren
Date: Sun, 8 May 2016 09:33:19 +0300
Subject: [PATCH 10/11] Remove duplicate Auth include
---
app/Services/BaseService.php | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/Services/BaseService.php b/app/Services/BaseService.php
index c687038bac..6bbbc729b2 100644
--- a/app/Services/BaseService.php
+++ b/app/Services/BaseService.php
@@ -3,7 +3,6 @@
use Auth;
use Illuminate\Foundation\Bus\DispatchesJobs;
use App\Services\DatatableService;
-use Auth;
class BaseService
{
From 89b5d73615166dc9e018c86e6f898214291f850e Mon Sep 17 00:00:00 2001
From: Hillel Coren
Date: Sun, 8 May 2016 10:05:16 +0300
Subject: [PATCH 11/11] Fix for loading tokens
---
app/Models/Account.php | 4 ++--
app/Ninja/Repositories/AccountRepository.php | 2 +-
app/Ninja/Transformers/UserAccountTransformer.php | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 952dd97cec..6bceb23d8f 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -470,10 +470,10 @@ class Account extends Eloquent
return Document::getDirectFileUrl($this->logo, $this->getLogoDisk());
}
- public function getToken($name)
+ public function getToken($userId, $name)
{
foreach ($this->account_tokens as $token) {
- if ($token->name === $name) {
+ if ($token->user_id == $userId && $token->name === $name) {
return $token->token;
}
}
diff --git a/app/Ninja/Repositories/AccountRepository.php b/app/Ninja/Repositories/AccountRepository.php
index 3b3c36d3ec..f5d401619e 100644
--- a/app/Ninja/Repositories/AccountRepository.php
+++ b/app/Ninja/Repositories/AccountRepository.php
@@ -644,7 +644,7 @@ class AccountRepository
{
$name = trim($name) ?: 'TOKEN';
$users = $this->findUsers($user);
-
+
foreach ($users as $user) {
if ($token = AccountToken::whereUserId($user->id)->whereName($name)->first()) {
continue;
diff --git a/app/Ninja/Transformers/UserAccountTransformer.php b/app/Ninja/Transformers/UserAccountTransformer.php
index bc49a96c54..e914a25c66 100644
--- a/app/Ninja/Transformers/UserAccountTransformer.php
+++ b/app/Ninja/Transformers/UserAccountTransformer.php
@@ -32,7 +32,7 @@ class UserAccountTransformer extends EntityTransformer
return [
'account_key' => $user->account->account_key,
'name' => $user->account->present()->name,
- 'token' => $user->account->getToken($this->tokenName),
+ 'token' => $user->account->getToken($user->id, $this->tokenName),
'default_url' => SITE_URL
];
}