Skip to content

Commit

Permalink
four digit for unit cost in stock value report
Browse files Browse the repository at this point in the history
  • Loading branch information
mbayopanda committed Jul 20, 2021
1 parent 7885f23 commit 007d59a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
<tr>
<td style="width:50%">{{inventory_name}}</td>
<td class="text-right">{{stockQtt}}</td>
<td class="text-right">{{currency stockUnitCost ../currency_id}}</td>
<td class="text-right">{{currency stockValue ../currency_id}}</td>
<td class="text-right">{{currencyWithPosition stockUnitCost ../currency_id 4}}</td>
<td class="text-right">{{currencyWithPosition stockValue ../currency_id 4}}</td>
</tr>
{{else}}
{{> emptyTable columns=4}}
Expand Down
21 changes: 21 additions & 0 deletions server/lib/template/helpers/finance.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ function currency(value = 0, currencyId) {
return new Handlebars.SafeString(accountingjs.formatMoney(value, fmt));
}

/**
* @function currencyWithPosition
* @desc format value with a given decimal position
* @todo merge this function with the currency function, since actually
* setting a position as third param in the currency function cause 0 decimal
* when nothing is defined as position we are using this currencyWithPosition
* @param {*} value
* @param {*} currencyId
* @param {*} precision
* @returns
*/
function currencyWithPosition(value = 0, currencyId, precision) {
const fmtNum = Number(currencyId);
// if currencyId is not defined, defaults to USD.
const fmt = fmtNum > 0 ? FORMATS[fmtNum] : USD_FMT;
const format = JSON.parse(JSON.stringify(fmt));
format.precision = precision;
return new Handlebars.SafeString(accountingjs.formatMoney(value, format));
}

/**
* @function currencyWithoutSymbol
*
Expand Down Expand Up @@ -107,6 +127,7 @@ function lessZero(value = 0) {

exports.debcred = debcred;
exports.currency = currency;
exports.currencyWithPosition = currencyWithPosition;
exports.indentAccount = indentAccount;
exports.numberToText = numberToText;
exports.percentage = percentage;
Expand Down
1 change: 1 addition & 0 deletions server/lib/template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const hbs = exphbs.create({
add : math.add,
substract : math.substract,
currency : finance.currency,
currencyWithPosition : finance.currencyWithPosition,
numberToText : finance.numberToText,
indentAccount : finance.indentAccount,
percentage : finance.percentage,
Expand Down

0 comments on commit 007d59a

Please sign in to comment.