Rearranged shop template page to better handle previews & template editor BOD-126

This commit is contained in:
Patrick Fic
2020-09-04 15:03:01 -07:00
parent 051be83303
commit af8e39da75
8 changed files with 129 additions and 88 deletions

View File

@@ -86,86 +86,86 @@ function CalculateRatesTotals(ratesList, shoprates) {
la1: {
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LA1")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
rate: ratesList.rate_la1 || 0,
},
la2: {
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LA2")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
rate: ratesList.rate_la2 || 0,
},
la3: {
rate: ratesList.rate_la3 || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LA3")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
la4: {
rate: ratesList.rate_la4 || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LA4")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
laa: {
rate: ratesList.rate_laa || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAA")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
lab: {
rate: ratesList.rate_lab || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAB")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
lad: {
rate: ratesList.rate_lad || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAD")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
lae: {
rate: ratesList.rate_lae || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAE")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
laf: {
rate: ratesList.rate_laf || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAF")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
lag: {
rate: ratesList.rate_lag || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAG")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
lam: {
rate: ratesList.rate_lam || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAM")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
lar: {
rate: ratesList.rate_lar || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAR")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
las: {
rate: ratesList.rate_las || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAS")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
lau: {
rate: ratesList.rate_lau || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAU")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
atp: {
rate: shoprates.rate_atp || 0,
@@ -184,29 +184,29 @@ function CalculateRatesTotals(ratesList, shoprates) {
item.mod_lbr_ty !== "LAS" &&
item.mod_lbr_ty !== "LAA"
)
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0)
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
: 0,
},
mapa: {
rate: ratesList.rate_mapa || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty === "LAR")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
mash: {
rate: ratesList.rate_mash || 0,
hours: jobLines
.filter((item) => item.mod_lbr_ty !== "LAR")
.reduce((acc, value) => acc + value.mod_lb_hrs * 10, 0),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
},
};
let subtotal = Dinero({ amount: 0 });
let rates_subtotal = Dinero({ amount: 0 });
for (const property in ret) {
ret[property].total = Dinero({ amount: ret[property].rate * 100 })
.multiply(ret[property].hours)
.divide(10);
ret[property].total = Dinero({ amount: ret[property].rate * 100 }).multiply(
ret[property].hours
);
subtotal = subtotal.add(ret[property].total);
if (
property !== "mapa" &&

View File

@@ -8,9 +8,42 @@ require("dotenv").config({
});
var _ = require("lodash");
const Handlebars = require("handlebars");
var Dinero = require("dinero.js");
Dinero.defaultCurrency = "CAD";
Dinero.globalLocale = "en-CA";
//Usage: {{moment appointments_by_pk.start format="dddd, DD MMMM YYYY"}}
Handlebars.registerHelper("dinerof", function (context, block) {
if (context && context.hash) {
block = _.cloneDeep(context);
context = undefined;
}
var amount = Dinero(context);
if (context) {
return amount.toFormat();
}
return "";
});
Handlebars.registerHelper("objectKeys", function (obj, block) {
var accum = "";
Object.keys(obj).map((key) => {
accum += block.fn({ key, value: obj[key] });
});
return accum;
});
Handlebars.registerHelper("dinero", function (context, block) {
if (context && context.hash) {
block = _.cloneDeep(context);
context = undefined;
}
var amount = Dinero({ amount: Math.round((context || 0) * 100) });
return amount.toFormat();
});
Handlebars.registerHelper("moment", function (context, block) {
if (context && context.hash) {
block = _.cloneDeep(context);