This commit is contained in:
Patrick Fic
2021-04-12 13:39:02 -07:00
parent 84959209e6
commit 8f7c45976c
4 changed files with 105 additions and 63 deletions

View File

@@ -143,33 +143,35 @@ export function BillsListPage({
<Link to={`/manage/bills?billid=${record.id}`}>
<Button>{t("bills.actions.edit")}</Button>
</Link>
<Button
disabled={record.is_credit_memo}
onClick={() =>
setPartsOrderContext({
actions: {},
context: {
jobId: record.jobid,
vendorId: record.vendorid,
returnFromBill: record.id,
invoiceNumber: record.invoice_number,
linesToOrder: record.billlines.map((i) => {
return {
line_desc: i.line_desc,
// db_price: i.actual_price,
act_price: i.actual_price,
cost: i.actual_cost,
quantity: i.quantity,
joblineid: i.joblineid,
};
}),
isReturn: true,
},
})
}
>
{t("bills.actions.return")}
</Button>
{
// <Button
// disabled={record.is_credit_memo}
// onClick={() =>
// setPartsOrderContext({
// actions: {},
// context: {
// jobId: record.jobid,
// vendorId: record.vendorid,
// returnFromBill: record.id,
// invoiceNumber: record.invoice_number,
// linesToOrder: record.billlines.map((i) => {
// return {
// line_desc: i.line_desc,
// // db_price: i.actual_price,
// act_price: i.actual_price,
// cost: i.actual_cost,
// quantity: i.quantity,
// joblineid: i.joblineid,
// };
// }),
// isReturn: true,
// },
// })
// }
// >
// {t("bills.actions.return")}
// </Button>
}
<BillDeleteButton bill={record} />
{record.isinhouse && (
<PrintWrapperComponent

View File

@@ -1283,7 +1283,7 @@
"reconciliationheader": "Parts & Sublet Reconciliation",
"rosaletotal": "Total RO Sale",
"sale_labor": "Sales - Labor",
"sale_parts": "Sales - Parts",
"sale_parts": "Sales - Parts & Sublet",
"sales": "Sales",
"scheduledinchange": "The scheduled in is based off the latest appointment. To change this date, please schedule or reschedule the job. ",
"state_tax_amt": "State/Provincial Taxes",

View File

@@ -649,6 +649,8 @@ exports.QUERY_JOB_COSTING_DETAILS = ` query QUERY_JOB_COSTING_DETAILS($id: uuid!
lbr_op
lbr_amt
op_code_desc
profitcenter_part
profitcenter_labor
}
bills {
id
@@ -746,6 +748,8 @@ exports.QUERY_JOB_COSTING_DETAILS_MULTI = ` query QUERY_JOB_COSTING_DETAILS_MULT
lbr_op
lbr_amt
op_code_desc
profitcenter_part
profitcenter_labor
}
bills {
id

View File

@@ -3,6 +3,7 @@ const queries = require("../graphql-client/queries");
//const client = require("../graphql-client/graphql-client").client;
const _ = require("lodash");
const GraphQLClient = require("graphql-request").GraphQLClient;
const { json } = require("body-parser");
// Dinero.defaultCurrency = "USD";
// Dinero.globalLocale = "en-CA";
@@ -56,8 +57,6 @@ async function JobCostingMulti(req, res) {
ids: jobids,
});
//for Each!***************
const multiSummary = {
costCenterData: [],
summaryData: {
@@ -199,42 +198,80 @@ function GenerateCostingData(job) {
job &&
job.joblines.reduce(
(acc, val) => {
const laborProfitCenter = defaultProfits[val.mod_lbr_ty] || "?";
if (val.mod_lbr_ty) {
const laborProfitCenter =
val.profitcenter_labor || defaultProfits[val.mod_lbr_ty] || "?";
const rateName = `rate_${(val.mod_lbr_ty || "").toLowerCase()}`;
const laborAmount = Dinero({
amount: Math.round((job[rateName] || 0) * 100),
}).multiply(val.mod_lb_hrs || 0);
if (!acc.labor[laborProfitCenter])
acc.labor[laborProfitCenter] = Dinero();
acc.labor[laborProfitCenter] = acc.labor[laborProfitCenter].add(
laborAmount
);
if (laborProfitCenter === "?")
console.log("Unknown type", val.mod_lbr_ty);
const partsProfitCenter = defaultProfits[val.part_type] || "?";
if (!partsProfitCenter)
console.log(
"Unknown cost/profit center mapping for parts.",
val.part_type
const rateName = `rate_${(val.mod_lbr_ty || "").toLowerCase()}`;
const laborAmount = Dinero({
amount: Math.round((job[rateName] || 0) * 100),
}).multiply(val.mod_lb_hrs || 0);
if (!acc.labor[laborProfitCenter])
acc.labor[laborProfitCenter] = Dinero();
acc.labor[laborProfitCenter] = acc.labor[laborProfitCenter].add(
laborAmount
);
const partsAmount = Dinero({
amount: Math.round((val.act_price || 0) * 100),
}).multiply(val.part_qty || 1);
if (!acc.parts[partsProfitCenter])
acc.parts[partsProfitCenter] = Dinero();
acc.parts[partsProfitCenter] = acc.parts[partsProfitCenter].add(
partsAmount
);
if (val.mod_lbr_ty === "LAR") {
if (!acc.labor[defaultProfits["MAPA"]])
acc.labor[defaultProfits["MAPA"]] = Dinero();
acc.labor[defaultProfits["MAPA"]] = acc.labor[
defaultProfits["MAPA"]
].add(
Dinero({
amount: Math.round((job.rate_mapa || 0) * 100),
}).multiply(val.mod_lb_hrs || 0)
);
}
if (!acc.labor[defaultProfits["MASH"]])
acc.labor[defaultProfits["MASH"]] = Dinero();
if (val.mod_lbr_ty !== "LAR") {
acc.labor[defaultProfits["MASH"]] = acc.labor[
defaultProfits["MASH"]
].add(
Dinero({
amount: Math.round((job.rate_mash || 0) * 100),
}).multiply(val.mod_lb_hrs || 0)
);
}
//If labor line, add to paint and shop materials.
}
if (val.part_type && val.part_type !== "PAE") {
const partsProfitCenter =
val.profitcenter_part || defaultProfits[val.part_type] || "?";
if (partsProfitCenter === "?")
console.log("Unknown type", val.part_type);
if (!partsProfitCenter)
console.log(
"Unknown cost/profit center mapping for parts.",
val.part_type
);
const partsAmount = Dinero({
amount: Math.round((val.act_price || 0) * 100),
}).multiply(val.part_qty || 1);
if (!acc.parts[partsProfitCenter])
acc.parts[partsProfitCenter] = Dinero();
acc.parts[partsProfitCenter] = acc.parts[partsProfitCenter].add(
partsAmount
);
}
return acc;
},
{ parts: {}, labor: {} }
);
const billTotalsByProfitCenter = job.bills.reduce((bill_acc, bill_val) => {
//At the invoice level.
const billTotalsByCostCenters = job.bills.reduce((bill_acc, bill_val) => {
//At the bill level.
bill_val.billlines.map((line_val) => {
//At the invoice line level.
//At the bill line level.
//console.log("JobCostingPartsTable -> line_val", line_val);
if (!bill_acc[line_val.cost_center])
bill_acc[line_val.cost_center] = Dinero();
@@ -252,7 +289,7 @@ function GenerateCostingData(job) {
return bill_acc;
}, {});
const ticketTotalsByProfitCenter = job.timetickets.reduce(
const ticketTotalsByCostCenter = job.timetickets.reduce(
(ticket_acc, ticket_val) => {
//At the invoice level.
if (!ticket_acc[ticket_val.cost_center])
@@ -290,13 +327,12 @@ function GenerateCostingData(job) {
const sale_parts =
jobLineTotalsByProfitCenter.parts[ccVal] || Dinero({ amount: 0 });
const cost_labor =
ticketTotalsByProfitCenter[ccVal] || Dinero({ amount: 0 });
const cost_parts = billTotalsByProfitCenter[ccVal] || Dinero({ amount: 0 });
const cost_labor = ticketTotalsByCostCenter[ccVal] || Dinero({ amount: 0 });
const cost_parts = billTotalsByCostCenters[ccVal] || Dinero({ amount: 0 });
const costs = (
billTotalsByProfitCenter[ccVal] || Dinero({ amount: 0 })
).add(ticketTotalsByProfitCenter[ccVal] || Dinero({ amount: 0 }));
const costs = (billTotalsByCostCenters[ccVal] || Dinero({ amount: 0 })).add(
ticketTotalsByCostCenter[ccVal] || Dinero({ amount: 0 })
);
const totalSales = sale_labor.add(sale_parts);
const gpdollars = totalSales.subtract(costs);
const gppercent = (