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

View File

@@ -1283,7 +1283,7 @@
"reconciliationheader": "Parts & Sublet Reconciliation", "reconciliationheader": "Parts & Sublet Reconciliation",
"rosaletotal": "Total RO Sale", "rosaletotal": "Total RO Sale",
"sale_labor": "Sales - Labor", "sale_labor": "Sales - Labor",
"sale_parts": "Sales - Parts", "sale_parts": "Sales - Parts & Sublet",
"sales": "Sales", "sales": "Sales",
"scheduledinchange": "The scheduled in is based off the latest appointment. To change this date, please schedule or reschedule the job. ", "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", "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_op
lbr_amt lbr_amt
op_code_desc op_code_desc
profitcenter_part
profitcenter_labor
} }
bills { bills {
id id
@@ -746,6 +748,8 @@ exports.QUERY_JOB_COSTING_DETAILS_MULTI = ` query QUERY_JOB_COSTING_DETAILS_MULT
lbr_op lbr_op
lbr_amt lbr_amt
op_code_desc op_code_desc
profitcenter_part
profitcenter_labor
} }
bills { bills {
id id

View File

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