Comparing version 1.4.0 to 1.5.0
@@ -506,8 +506,7 @@ --- | ||
|------|------------|----------|---------| | ||
| item | An object in the data given to the liquid template | N | ticket | ||
| propName | The name of the property of the item that is a collection of objects | N | taxes | ||
| item.propName | An object in the data given to the liquid template | N | ticket.taxes | ||
| innerPropName | The name of the property in the objects in the collection | N | calculated | ||
```liquid | ||
"{% raw %} {%- money ticket fees subTotal -%} {% endraw %}" | ||
"{% raw %} {%- money ticket.fees subTotal -%} {% endraw %}" | ||
``` | ||
@@ -514,0 +513,0 @@ |
{ | ||
"name": "btrz-pdf", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Generates pdf documents based on a liquid template", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -22,6 +22,7 @@ const formatter = require("btrz-formatter"); | ||
function getCurrency(item, providerPreferences) { | ||
const baseCurrency = providerPreferences.preferences.supportedCurrencies[0]; | ||
if (providerPreferences.preferences.multiCurrency) { | ||
return item && item.displayCurrency && item.displayCurrency.isocode ? item.displayCurrency : baseCurrency; | ||
} | ||
return providerPreferences.preferences.supportedCurrencies[0]; | ||
return baseCurrency; | ||
} | ||
@@ -103,16 +104,13 @@ | ||
const args = tagToken.args.split(" "); | ||
this.item = args[0] || "ticket"; | ||
this.propName = args[1] || "taxes"; | ||
this.innerPropName = args[2] || "calculated"; | ||
this.item = args[0] || "ticket.taxes"; | ||
this.innerPropName = args[1] || "calculated"; | ||
}, | ||
render: async function(ctx) { | ||
const coll = await this.liquid.evalValue(this.item, ctx); | ||
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences && | ||
ctx.environments[this.item] && ctx.environments[this.item][this.propName]) { | ||
const coll = ctx.environments[this.item][this.propName]; | ||
if (Array.isArray(coll)) { | ||
const sum = coll.reduce((acc, item) => { | ||
return acc + getCurrencyValue(item, this.innerPropName, ctx.environments.providerPreferences, {prefix: "display"}); | ||
}, 0); | ||
return formatter.money(sum); | ||
} | ||
Array.isArray(coll)) { | ||
const sum = coll.reduce((acc, item) => { | ||
return acc + getCurrencyValue(item, this.innerPropName, ctx.environments.providerPreferences, {prefix: "display"}); | ||
}, 0); | ||
return formatter.money(sum); | ||
} | ||
@@ -128,9 +126,10 @@ return "PNA"; | ||
const args = tagToken.args.split(" "); | ||
this.item = args[0] || "ticket"; | ||
this.item = args[0] || "ticket.total"; | ||
this.propName = args[1] || "total"; | ||
}, | ||
render: async function(ctx) { | ||
const item = await this.liquid.evalValue(this.item, ctx); | ||
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences && | ||
ctx.environments[this.item] && ctx.environments[this.item][this.propName] !== undefined) { | ||
return formatter.money(getCurrencyValue(ctx.environments[this.item], this.propName, ctx.environments.providerPreferences, {prefix: "display"})); | ||
item && item[this.propName] !== undefined) { | ||
return formatter.money(getCurrencyValue(item, this.propName, ctx.environments.providerPreferences, {prefix: "display"})); | ||
} | ||
@@ -148,4 +147,5 @@ return "PNA"; | ||
render: async function(ctx) { | ||
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences && ctx.environments[this.item]) { | ||
const itemCurrency = getCurrency(ctx.environments[this.item], ctx.environments.providerPreferences); | ||
const item = await this.liquid.evalValue(this.item, ctx); | ||
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences && item) { | ||
const itemCurrency = getCurrency(item, ctx.environments.providerPreferences); | ||
return getCurrencySymbol((itemCurrency || {}).isocode || " "); | ||
@@ -164,4 +164,5 @@ } | ||
render: async function(ctx) { | ||
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences && ctx.environments[this.item]) { | ||
const itemCurrency = getCurrency(ctx.environments[this.item], ctx.environments.providerPreferences); | ||
const item = await this.liquid.evalValue(this.item, ctx); | ||
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences && item) { | ||
const itemCurrency = getCurrency(item, ctx.environments.providerPreferences); | ||
return (itemCurrency || {}).isocode || " "; | ||
@@ -168,0 +169,0 @@ } |
@@ -8,2 +8,48 @@ describe("index.js", () => { | ||
_id: "5c9f8f8f8f8f8f8f8f8f8f8", | ||
payments: [ | ||
{ | ||
provider: "inperson", | ||
type: "cash", | ||
displayName: "Cash", | ||
status: "success", | ||
amount: 3.86, | ||
rollbackPayload: null, | ||
acceptedCurrency: { | ||
isocode:"GTQ", | ||
symbol:"Q", | ||
buy:7.77, | ||
sell:7.57, | ||
channels:[] | ||
}, | ||
displayAmount: "30.00", | ||
displayCurrency: { | ||
isocode:"GTQ", | ||
symbol:"Q", | ||
buy:7.77, | ||
sell:7.57 | ||
}, | ||
acceptedCurrencyAmount: 30, | ||
exchangeDetails: { | ||
exchangeCurrency:{}, | ||
acceptedCurrencyAmount: 3000000, | ||
acceptedCurrencyAmountReceived: 3000000, | ||
acceptedCurrencyAmountReturned: 0, | ||
exchangeCurrencyAmount: 386100, | ||
exchangeCurrencyAmountReceived: 386100, | ||
exchangeCurrencyAmountReturned: 0 | ||
} | ||
}, | ||
{ | ||
amount: 20, | ||
displayCurrency: { | ||
isocode:"USD", | ||
symbol:"$", | ||
buy:7.77, | ||
sell:7.57 | ||
}, | ||
}, | ||
{ | ||
amount: 30 | ||
} | ||
] | ||
}, | ||
@@ -89,3 +135,2 @@ providerPreferences: { | ||
it("should return a default document definition", () => { | ||
@@ -145,6 +190,10 @@ const pdf = require("../src/index.js"); | ||
"content": [ | ||
{%for payment in transaction.payments %} | ||
"{%- curcySymbol payment -%}", | ||
"{%- curcyIso payment -%}", | ||
{% endfor %} | ||
"{%- money ticket total -%}", | ||
"{%- curcySymbol ticket -%}", | ||
"{%- curcyIso ticket -%}", | ||
"{%- moneyReduce ticket ssrs subTotal -%}" | ||
"{%- moneyReduce ticket.ssrs subTotal -%}" | ||
] | ||
@@ -157,2 +206,8 @@ }`; | ||
"content": [ | ||
"Q", | ||
"GTQ", | ||
"$", | ||
"USD", | ||
"$", | ||
"USD", | ||
"0.00", | ||
@@ -187,3 +242,3 @@ "$", | ||
"{%- curcyIso ticket -%}", | ||
"{%- moneyReduce ticket ssrs subTotal -%}", | ||
"{%- moneyReduce ticket.ssrs subTotal -%}", | ||
"{%- humanDateTime ticket createdAt %}", | ||
@@ -190,0 +245,0 @@ "{%- humanDate ticket createdAt %}", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51786
1040