IO-1822 Add manual ATS calculation.
This commit is contained in:
@@ -20355,6 +20355,27 @@
|
||||
</concept_node>
|
||||
</children>
|
||||
</folder_node>
|
||||
<concept_node>
|
||||
<name>auto_add_ats</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
<description></description>
|
||||
<comment></comment>
|
||||
<default_text></default_text>
|
||||
<translations>
|
||||
<translation>
|
||||
<language>en-US</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>es-MX</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>fr-CA</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
</translations>
|
||||
</concept_node>
|
||||
<concept_node>
|
||||
<name>ca_bc_pvrt</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
@@ -23257,6 +23278,27 @@
|
||||
</concept_node>
|
||||
</children>
|
||||
</folder_node>
|
||||
<concept_node>
|
||||
<name>rate_ats</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
<description></description>
|
||||
<comment></comment>
|
||||
<default_text></default_text>
|
||||
<translations>
|
||||
<translation>
|
||||
<language>en-US</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>es-MX</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
<translation>
|
||||
<language>fr-CA</language>
|
||||
<approved>false</approved>
|
||||
</translation>
|
||||
</translations>
|
||||
</concept_node>
|
||||
<concept_node>
|
||||
<name>rate_la1</name>
|
||||
<definition_loaded>false</definition_loaded>
|
||||
|
||||
@@ -88,6 +88,33 @@ export function JobsDetailRates({ jobRO, form, job, bodyshop }) {
|
||||
</Form.Item>
|
||||
<CABCpvrtCalculator form={form} disabled={jobRO} />
|
||||
</Space>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.auto_add_ats")}
|
||||
name="auto_add_ats"
|
||||
valuePropName="checked"
|
||||
>
|
||||
<Switch disabled={jobRO} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
nostyle
|
||||
shouldUpdate={(prev, cur) => prev.auto_add_ats !== cur.auto_add_ats}
|
||||
>
|
||||
{() => {
|
||||
if (form.getFieldValue("auto_add_ats"))
|
||||
return (
|
||||
<Form.Item
|
||||
label={t("jobs.fields.rate_ats")}
|
||||
name="rate_ats"
|
||||
initialValue={bodyshop.shoprates.rate_atp}
|
||||
>
|
||||
<CurrencyInput disabled={jobRO} />
|
||||
</Form.Item>
|
||||
);
|
||||
|
||||
return null;
|
||||
}}
|
||||
</Form.Item>
|
||||
</FormRow>
|
||||
<FormRow>
|
||||
<Form.Item
|
||||
@@ -100,7 +127,13 @@ export function JobsDetailRates({ jobRO, form, job, bodyshop }) {
|
||||
label={t("jobs.fields.state_tax_rate")}
|
||||
name="state_tax_rate"
|
||||
>
|
||||
<InputNumber min={0} max={1} precision={2} disabled={jobRO} autoComplete="new-password"/>
|
||||
<InputNumber
|
||||
min={0}
|
||||
max={1}
|
||||
precision={2}
|
||||
disabled={jobRO}
|
||||
autoComplete="new-password"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
label={t("jobs.fields.local_tax_rate")}
|
||||
|
||||
@@ -611,6 +611,8 @@ export const GET_JOB_BY_PK = gql`
|
||||
ownerid
|
||||
ded_note
|
||||
materials
|
||||
auto_add_ats
|
||||
rate_ats
|
||||
owner {
|
||||
id
|
||||
ownr_fn
|
||||
|
||||
@@ -1245,6 +1245,7 @@
|
||||
"08": "Left Rear Side",
|
||||
"09": "Left Side"
|
||||
},
|
||||
"auto_add_ats": "Automatically Add/Update ATS",
|
||||
"ca_bc_pvrt": "PVRT",
|
||||
"ca_customer_gst": "Customer Portion of GST",
|
||||
"ca_gst_registrant": "GST Registrant",
|
||||
@@ -1392,6 +1393,7 @@
|
||||
"production_vars": {
|
||||
"note": "Production Note"
|
||||
},
|
||||
"rate_ats": "ATS Rate",
|
||||
"rate_la1": "LA1",
|
||||
"rate_la2": "LA2",
|
||||
"rate_la3": "LA3",
|
||||
|
||||
@@ -1245,6 +1245,7 @@
|
||||
"08": "",
|
||||
"09": ""
|
||||
},
|
||||
"auto_add_ats": "",
|
||||
"ca_bc_pvrt": "",
|
||||
"ca_customer_gst": "",
|
||||
"ca_gst_registrant": "",
|
||||
@@ -1392,6 +1393,7 @@
|
||||
"production_vars": {
|
||||
"note": ""
|
||||
},
|
||||
"rate_ats": "",
|
||||
"rate_la1": "Tarifa LA1",
|
||||
"rate_la2": "Tarifa LA2",
|
||||
"rate_la3": "Tarifa LA3",
|
||||
|
||||
@@ -1245,6 +1245,7 @@
|
||||
"08": "",
|
||||
"09": ""
|
||||
},
|
||||
"auto_add_ats": "",
|
||||
"ca_bc_pvrt": "",
|
||||
"ca_customer_gst": "",
|
||||
"ca_gst_registrant": "",
|
||||
@@ -1392,6 +1393,7 @@
|
||||
"production_vars": {
|
||||
"note": ""
|
||||
},
|
||||
"rate_ats": "",
|
||||
"rate_la1": "Taux LA1",
|
||||
"rate_la2": "Taux LA2",
|
||||
"rate_la3": "Taux LA3",
|
||||
|
||||
@@ -20,6 +20,38 @@ mutation UNARCHIVE_CONVERSATION($id: uuid!) {
|
||||
}
|
||||
`;
|
||||
|
||||
exports.INSERT_NEW_JOB_LINE = `
|
||||
mutation INSERT_NEW_JOB_LINE($lineInput: [joblines_insert_input!]!) {
|
||||
insert_joblines(objects: $lineInput) {
|
||||
returning {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
exports.UPDATE_JOB_LINE = `
|
||||
mutation UPDATE_JOB_LINE($lineId: uuid!, $line: joblines_set_input!) {
|
||||
update_joblines(where: { id: { _eq: $lineId } }, _set: $line) {
|
||||
returning {
|
||||
id
|
||||
notes
|
||||
mod_lbr_ty
|
||||
part_qty
|
||||
db_price
|
||||
act_price
|
||||
line_desc
|
||||
line_no
|
||||
oem_partno
|
||||
notes
|
||||
location
|
||||
status
|
||||
removed
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
exports.RECEIVE_MESSAGE = `
|
||||
mutation RECEIVE_MESSAGE($msg: [messages_insert_input!]!) {
|
||||
insert_messages(objects: $msg) {
|
||||
@@ -970,6 +1002,8 @@ exports.GET_JOB_BY_PK = ` query GET_JOB_BY_PK($id: uuid!) {
|
||||
ca_bc_pvrt
|
||||
ca_customer_gst
|
||||
materials
|
||||
auto_add_ats
|
||||
rate_ats
|
||||
joblines(where: { removed: { _eq: false } }){
|
||||
id
|
||||
line_no
|
||||
|
||||
@@ -24,7 +24,7 @@ exports.totalsSsu = async function (req, res) {
|
||||
});
|
||||
|
||||
const newTotals = await TotalsServerSide(
|
||||
{ body: { job: job.jobs_by_pk } },
|
||||
{ body: { job: job.jobs_by_pk, client: client } },
|
||||
res,
|
||||
true
|
||||
);
|
||||
@@ -53,7 +53,9 @@ exports.totalsSsu = async function (req, res) {
|
||||
|
||||
//IMPORTANT*** These two functions MUST be mirrrored.
|
||||
async function TotalsServerSide(req, res) {
|
||||
const { job } = req.body;
|
||||
const { job, client } = req.body;
|
||||
await AutoAddAtsIfRequired({ job: job, client: client });
|
||||
|
||||
try {
|
||||
let ret = {
|
||||
parts: CalculatePartsTotals(job.joblines),
|
||||
@@ -78,6 +80,16 @@ async function Totals(req, res) {
|
||||
jobid: job.id,
|
||||
});
|
||||
|
||||
const BearerToken = req.headers.authorization;
|
||||
const { id } = req.body;
|
||||
logger.log("job-totals-ssu", "DEBUG", req.user.email, id, null);
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
Authorization: BearerToken,
|
||||
},
|
||||
});
|
||||
|
||||
await AutoAddAtsIfRequired({ job, client });
|
||||
try {
|
||||
let ret = {
|
||||
parts: CalculatePartsTotals(job.joblines),
|
||||
@@ -96,6 +108,83 @@ async function Totals(req, res) {
|
||||
}
|
||||
}
|
||||
|
||||
async function AutoAddAtsIfRequired({ job, client }) {
|
||||
//Check if ATS should be automatically added.
|
||||
if (job.auto_add_ats) {
|
||||
//Get the total sum of hours that should be the ATS amount.
|
||||
//Check to see if an ATS line exists.
|
||||
let atsLineIndex = null;
|
||||
const atsHours = job.joblines.reduce((acc, val, index) => {
|
||||
if (val.line_desc && val.line_desc.toLowerCase() === "ats amount") {
|
||||
atsLineIndex = index;
|
||||
}
|
||||
|
||||
if (
|
||||
val.mod_lbr_ty !== "LA1" &&
|
||||
val.mod_lbr_ty !== "LA2" &&
|
||||
val.mod_lbr_ty !== "LA3" &&
|
||||
val.mod_lbr_ty !== "LA4" &&
|
||||
val.mod_lbr_ty !== "LAU" &&
|
||||
val.mod_lbr_ty !== "LAG" &&
|
||||
val.mod_lbr_ty !== "LAS" &&
|
||||
val.mod_lbr_ty !== "LAA"
|
||||
) {
|
||||
acc = acc + val.mod_lb_hrs;
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, 0);
|
||||
|
||||
const atsAmount = atsHours * (job.rate_ats || 0);
|
||||
//If it does, update it in place, and make sure it is updated for local calculations.
|
||||
if (atsLineIndex === null) {
|
||||
const newAtsLine = {
|
||||
jobid: job.id,
|
||||
alt_partm: null,
|
||||
line_no: 35,
|
||||
unq_seq: 0,
|
||||
line_ind: "E",
|
||||
line_desc: "ATS Amount",
|
||||
line_ref: 0.0,
|
||||
part_type: null,
|
||||
oem_partno: null,
|
||||
db_price: 0.0,
|
||||
act_price: atsAmount,
|
||||
part_qty: 1,
|
||||
mod_lbr_ty: null,
|
||||
db_hrs: 0.0,
|
||||
mod_lb_hrs: 0.0,
|
||||
lbr_op: "OP13",
|
||||
lbr_amt: 0.0,
|
||||
op_code_desc: "ADDITIONAL COSTS",
|
||||
status: null,
|
||||
location: null,
|
||||
tax_part: true,
|
||||
db_ref: null,
|
||||
manual_line: true,
|
||||
prt_dsmk_p: 0.0,
|
||||
prt_dsmk_m: 0.0,
|
||||
};
|
||||
|
||||
const result = await client.request(queries.INSERT_NEW_JOB_LINE, {
|
||||
lineInput: [newAtsLine],
|
||||
});
|
||||
|
||||
job.joblines.push(newAtsLine);
|
||||
}
|
||||
//If it does not, create one for local calculations and insert it.
|
||||
else {
|
||||
const result = await client.request(queries.UPDATE_JOB_LINE, {
|
||||
line: { act_price: atsAmount },
|
||||
lineId: job.joblines[atsLineIndex].id,
|
||||
});
|
||||
job.joblines[atsLineIndex].act_price = atsAmount;
|
||||
}
|
||||
|
||||
console.log(job.jobLines);
|
||||
}
|
||||
}
|
||||
|
||||
function CalculateRatesTotals(ratesList) {
|
||||
const jobLines = ratesList.joblines.filter((jl) => !jl.removed);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user