BOD-62 WIP total calculations. PST rates is still missing.

This commit is contained in:
Patrick Fic
2020-04-07 17:06:34 -07:00
parent 6bf9ba5be0
commit ed9b2a57fb
18 changed files with 366 additions and 71 deletions

View File

@@ -1,4 +1,4 @@
<babeledit_project be_version="2.6.1" version="1.2">
<babeledit_project version="1.2" be_version="2.6.1">
<!--
BabelEdit project file
@@ -8609,6 +8609,32 @@
</translation>
</translations>
</concept_node>
<folder_node>
<name>ratetotals</name>
<children>
<concept_node>
<name>lab</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>
</children>
</folder_node>
<concept_node>
<name>vehicle_info</name>
<definition_loaded>false</definition_loaded>

View File

@@ -3,13 +3,11 @@ import { List } from "antd";
import Icon from "@ant-design/icons";
import { FaArrowRight } from "react-icons/fa";
export default function AuditTrailValuesComponent({ oldV, newV }) {
console.log("(!oldV & !newV)", !oldV && !newV);
console.log("(!oldV & newV)", !oldV && newV);
if (!oldV && !newV) return <div></div>;
if (!oldV && newV)
return (
<List style={{ width: "800px" }} bordered size="small">
<List style={{ width: "800px" }} bordered size='small'>
{Object.keys(newV).map((key, idx) => (
<List.Item key={idx} value={key}>
{key}: {JSON.stringify(newV[key])}
@@ -19,7 +17,7 @@ export default function AuditTrailValuesComponent({ oldV, newV }) {
);
return (
<List style={{ width: "800px" }} bordered size="small">
<List style={{ width: "800px" }} bordered size='small'>
{Object.keys(oldV).map((key, idx) => (
<List.Item key={idx}>
{key}: {oldV[key]} <Icon component={FaArrowRight} />

View File

@@ -1,9 +1,54 @@
import React from "react";
import { List, Row, Col } from "antd";
import { useTranslation } from "react-i18next";
export default function JobsTotalsTableComponent({ totals }) {
const { t } = useTranslation();
if (!!!totals) return null;
return (
<div>
<div>{JSON.stringify(totals, null, 2)}</div>
</div>
<Row>
<Col span={8}>
<strong>Rates</strong>
<List size='small'>
<List.Item>{`rate_laa - ${totals.rates.rate_laa.total} (${totals.rates.rate_laa.hours} @ ${totals.rates.rate_laa.rate})`}</List.Item>
<List.Item>{`LAB - ${totals.rates.rate_lab.total} (${totals.rates.rate_lab.hours} @ ${totals.rates.rate_lab.rate})`}</List.Item>
<List.Item>{`rate_lad - ${totals.rates.rate_lad.total} (${totals.rates.rate_lad.hours} @ ${totals.rates.rate_lad.rate})`}</List.Item>
<List.Item>{`rate_lae - ${totals.rates.rate_lae.total} (${totals.rates.rate_lae.hours} @ ${totals.rates.rate_lae.rate})`}</List.Item>
<List.Item>{`rate_laf - ${totals.rates.rate_laf.total} (${totals.rates.rate_laf.hours} @ ${totals.rates.rate_laf.rate})`}</List.Item>
<List.Item>{`rate_lag - ${totals.rates.rate_lag.total} (${totals.rates.rate_lag.hours} @ ${totals.rates.rate_lag.rate})`}</List.Item>
<List.Item>{`rate_lam - ${totals.rates.rate_lam.total} (${totals.rates.rate_lam.hours} @ ${totals.rates.rate_lam.rate})`}</List.Item>
<List.Item>{`rate_lar - ${totals.rates.rate_lar.total} (${totals.rates.rate_lar.hours} @ ${totals.rates.rate_lar.rate})`}</List.Item>
<List.Item>{`rate_las - ${totals.rates.rate_las.total} (${totals.rates.rate_las.hours} @ ${totals.rates.rate_las.rate})`}</List.Item>
<List.Item>{`rate_lau - ${totals.rates.rate_lau.total} (${totals.rates.rate_lau.hours} @ ${totals.rates.rate_lau.rate})`}</List.Item>
<List.Item>{`LA1 - ${totals.rates.rate_la1.total} (${totals.rates.rate_la1.hours} @ ${totals.rates.rate_la1.rate})`}</List.Item>
<List.Item>{`LA2 - ${totals.rates.rate_la2.total} (${totals.rates.rate_la2.hours} @ ${totals.rates.rate_la2.rate})`}</List.Item>
<List.Item>{`LA3 - ${totals.rates.rate_la3.total} (${totals.rates.rate_la3.hours} @ ${totals.rates.rate_la3.rate})`}</List.Item>
<List.Item>{`rate_la4 - ${totals.rates.rate_la4.total} (${totals.rates.rate_la4.hours} @ ${totals.rates.rate_la4.rate})`}</List.Item>
<List.Item>{`paint_mat - ${totals.rates.paint_mat.total} (${totals.rates.paint_mat.hours} @ ${totals.rates.paint_mat.rate})`}</List.Item>
<List.Item>{`shop_mat - ${totals.rates.shop_mat.total} (${totals.rates.shop_mat.hours} @ ${totals.rates.shop_mat.rate})`}</List.Item>
<List.Item>{`rate_atp - ${totals.rates.rate_atp.total} (${totals.rates.rate_atp.hours} @ ${totals.rates.rate_atp.rate})`}</List.Item>
</List>
{`Subtotal: ${totals.rates.subtotal}`}
</Col>
<Col span={8}>
<strong>Parts & Sublet</strong>
<List size='small'>
<List.Item>{`Parts - ${totals.parts.parts.total} (${totals.parts.parts.subtotal} +- ${totals.parts.parts.adjustments})`}</List.Item>
<List.Item>{`Sublet - ${totals.parts.sublets.total} (${totals.parts.sublets.subtotal} +- ${totals.parts.sublets.adjustments})`}</List.Item>
</List>
</Col>
<Col span={8}>
<strong>Totals</strong>
<List size='small'>
<List.Item>{`Subtotal - ${totals.totals.subtotal}`}</List.Item>
<List.Item>{`GST - ${totals.totals.federal_tax}`}</List.Item>
<List.Item>{`PST - ${totals.totals.state_tax}`}</List.Item>
<List.Item>{`Local - ${totals.totals.local_tax}`}</List.Item>
<List.Item>{`Total Payable - ${totals.totals.total_repairs}`}</List.Item>
<List.Item>{`Net Repairs - ${totals.totals.net_repairs}`}</List.Item>
</List>
</Col>
</Row>
);
}

View File

@@ -4,30 +4,27 @@ import { QUERY_JOB_FINANCIALS } from "../../graphql/jobs.queries";
import AlertComponent from "../alert/alert.component";
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
import JobTotalsTableComponent from "./job-totals-table.component";
import {
CalculateRatesTotals,
CalculatePartsTotals,
CalculateCustPayable
} from "./job-totals.utility";
import { CalculateJob } from "./job-totals.utility";
export default function JobTotalsTableContainer({ jobId }) {
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { selectBodyshop } from "../../redux/user/user.selectors";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop
});
export function JobTotalsTableContainer({ jobId, bodyshop }) {
const { loading, error, data } = useQuery(QUERY_JOB_FINANCIALS, {
variables: { jobId: jobId }
});
const [totals, setTotals] = useState({});
const [totals, setTotals] = useState(null);
useEffect(() => {
if (!!data) {
setTotals({
parts: CalculatePartsTotals(data.jobs_by_pk.joblines),
rates: CalculateRatesTotals(data.jobs_by_pk),
custPayable: CalculateCustPayable(data.jobs_by_pk)
});
setTotals(CalculateJob(data.jobs_by_pk, bodyshop.shoprates));
}
}, [data]);
console.log("totals", totals);
}, [data, setTotals, bodyshop.shoprates]);
if (loading) return <LoadingSpinner />;
if (error) return <AlertComponent message={error.message} type='error' />;
@@ -35,22 +32,8 @@ export default function JobTotalsTableContainer({ jobId }) {
return (
<div>
<JobTotalsTableComponent totals={totals} />
<div>
<div>STL Data</div>
<div>
{data
? JSON.stringify(data.jobs_by_pk.cieca_stl.data, null, 2)
: null}
</div>
</div>
<div>
<div>ttl Data</div>
<div>
{data
? JSON.stringify(data.jobs_by_pk.cieca_ttl.data, null, 2)
: null}
</div>
</div>
</div>
);
}
export default connect(mapStateToProps, null)(JobTotalsTableContainer);

View File

@@ -1,19 +1,48 @@
export function CalculateRatesTotals(ratesList) {
export function CalculateJob(job, shoprates) {
let ret = {
parts: CalculatePartsTotals(job.joblines),
rates: CalculateRatesTotals(job, shoprates),
custPayable: CalculateCustPayable(job)
};
ret.totals = CalculateTaxesTotals(job, ret);
return ret;
}
function CalculateTaxesTotals(job, otherTotals) {
const subtotal =
otherTotals.parts.parts.subtotal +
otherTotals.parts.sublets.subtotal +
otherTotals.rates.subtotal;
let ret = {
subtotal: subtotal,
federal_tax: subtotal * job.federal_tax_rate || 0,
state_tax: subtotal * job.state_tax_rate || 0,
local_tax: subtotal * job.local_tax_rate || 0
};
ret.total_repairs =
ret.subtotal + ret.federal_tax + ret.state_tax + ret.local_tax;
ret.net_repairs = ret.total_repairs - otherTotals.custPayable.total;
return ret;
}
function CalculateRatesTotals(ratesList, shoprates) {
const jobLines = ratesList.joblines;
let ret = {
rate_la1: {
hours: jobLines
.filter(item => item.mod_lbr_ty === "LA1")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
rate: ratesList.rate_la1
},
rate_la2: {
hours: jobLines
.filter(item => item.mod_lbr_ty === "LA2")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2),
.reduce((acc, value) => acc + value.mod_lb_hrs, 0),
rate: ratesList.rate_la2
},
rate_la3: {
@@ -21,97 +50,113 @@ export function CalculateRatesTotals(ratesList) {
hours: jobLines
.filter(item => item.mod_lbr_ty === "LA3")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_la4: {
rate: ratesList.rate_la4,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LA4")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_laa: {
rate: ratesList.rate_laa,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAA")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_lab: {
rate: ratesList.rate_lab,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAB")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_lad: {
rate: ratesList.rate_lad,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAD")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_lae: {
rate: ratesList.rate_lae,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAE")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_laf: {
rate: ratesList.rate_laf,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAF")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_lag: {
rate: ratesList.rate_lag,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAG")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_lam: {
rate: ratesList.rate_lam,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAM")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_lar: {
rate: ratesList.rate_lar,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAR")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_las: {
rate: ratesList.rate_las,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAS")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_lau: {
rate: ratesList.rate_lau,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAU")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
.toFixed(2)
},
rate_atp: {
rate: shoprates.rate_atp || 0,
hours: jobLines
.filter(
item =>
item.mod_lbr_ty !== "LA1" &&
item.mod_lbr_ty !== "LA2" &&
item.mod_lbr_ty !== "LA3" &&
item.mod_lbr_ty !== "LA4" &&
item.mod_lbr_ty !== "LAU" &&
item.mod_lbr_ty !== "LAG" &&
item.mod_lbr_ty !== "LAS" &&
item.mod_lbr_ty !== "LAA"
)
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
},
paint_mat: {
rate: ratesList.rate_mapa,
hours: jobLines
.filter(item => item.mod_lbr_ty === "LAR")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
},
shop_mat: {
rate: ratesList.rate_mash,
hours: jobLines
.filter(item => item.mod_lbr_ty !== "LAR")
.reduce((acc, value) => acc + value.mod_lb_hrs, 0)
}
};
let subtotal = 0;
for (const property in ret) {
ret[property].total = (ret[property].hours * ret[property].rate).toFixed(2);
ret[property].total = ret[property].hours * ret[property].rate;
subtotal = subtotal + ret[property].hours * ret[property].rate;
}
ret.subtotal = subtotal.toFixed(2);
ret.subtotal = subtotal;
return ret;
}
export function CalculatePartsTotals(jobLines) {
function CalculatePartsTotals(jobLines) {
const ret = jobLines.reduce(
(acc, value) => {
switch (value.part_type) {
@@ -121,8 +166,6 @@ export function CalculatePartsTotals(jobLines) {
case "PAL":
case "PAM":
case "PAN":
case "PAND":
case "PANF":
case "PAO":
case "PAP":
case "PAR":
@@ -163,7 +206,7 @@ export function CalculatePartsTotals(jobLines) {
};
}
export function CalculateCustPayable(job) {
function CalculateCustPayable(job) {
return {
deductible: job.ded_amt || 0,
federal_tax: job.federal_tax_payable || 0,

View File

@@ -48,7 +48,6 @@ export default function JobsDetailFinancials({ job }) {
<InputNumber />
</Form.Item>
<Divider />
Totals Table
<Form.Item
label={t("jobs.fields.labor_rate_desc")}
name='labor_rate_desc'>
@@ -125,7 +124,7 @@ export default function JobsDetailFinancials({ job }) {
<InputNumber />
</Form.Item>
</Col>
<Col offset={2} span={10}>
<Col offset={1} span={12}>
<JobTotalsTableContainer jobId={job.id} />
</Col>
</Row>

View File

@@ -97,8 +97,8 @@ export default function JobsFindModalComponent({
width: "8%",
ellipsis: true,
render: (text, record) => {
return record.vehicle.plate_no ? (
<span>{record.vehicle.plate_no}</span>
return record.plate_no ? (
<span>{record.plate_no}</span>
) : (
t("general.labels.unknown")
);
@@ -134,10 +134,10 @@ export default function JobsFindModalComponent({
<div>
<Table
title={() => t("jobs.labels.existing_jobs")}
size="small"
size='small'
pagination={{ position: "bottom" }}
columns={columns.map(item => ({ ...item }))}
rowKey="id"
rowKey='id'
loading={jobsListLoading}
dataSource={jobsList}
rowSelection={{
@@ -163,8 +163,7 @@ export default function JobsFindModalComponent({
...importOptions,
overrideHeaders: e.target.checked
})
}
>
}>
{t("jobs.labels.override_header")}
</Checkbox>
</div>

View File

@@ -20,6 +20,7 @@ export const QUERY_BODYSHOP = gql`
state_tax_id
updated_at
zip_post
shoprates
region_config
md_responsibility_centers
messagingservicesid

View File

@@ -396,6 +396,12 @@ export const QUERY_JOB_FINANCIALS = gql`
depreciation_taxes
federal_tax_payable
other_amount_payable
adjustment_bottom_line
towing_payable
storage_payable
federal_tax_rate
state_tax_rate
local_tax_rate
rate_atp
rate_la1
rate_la2

View File

@@ -550,6 +550,9 @@
"override_header": "Override estimate header on import?",
"parts": "Parts",
"rates": "Rates",
"ratetotals": {
"lab": "Body Total"
},
"vehicle_info": "Vehicle"
},
"successes": {

View File

@@ -550,6 +550,9 @@
"override_header": "¿Anular encabezado estimado al importar?",
"parts": "Partes",
"rates": "Tarifas",
"ratetotals": {
"lab": ""
},
"vehicle_info": "Vehículo"
},
"successes": {

View File

@@ -550,6 +550,9 @@
"override_header": "Remplacer l'en-tête d'estimation à l'importation?",
"parts": "les pièces",
"rates": "Les taux",
"ratetotals": {
"lab": ""
},
"vehicle_info": "Véhicule"
},
"successes": {

View File

@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."bodyshops" DROP COLUMN "shoprates";
type: run_sql

View File

@@ -0,0 +1,5 @@
- args:
cascade: false
read_only: false
sql: ALTER TABLE "public"."bodyshops" ADD COLUMN "shoprates" jsonb NULL;
type: run_sql

View File

@@ -0,0 +1,43 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_select_permission
- args:
permission:
allow_aggregations: false
columns:
- id
- shopname
- created_at
- updated_at
- address1
- address2
- city
- state
- zip_post
- country
- email
- federal_tax_id
- insurance_vendor_id
- state_tax_id
- logo_img_path
- md_ro_statuses
- region_config
- md_order_statuses
- md_responsibility_centers
- messagingservicesid
computed_fields: []
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
role: user
table:
name: bodyshops
schema: public
type: create_select_permission

View File

@@ -0,0 +1,44 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_select_permission
- args:
permission:
allow_aggregations: false
columns:
- address1
- address2
- city
- country
- created_at
- email
- federal_tax_id
- id
- insurance_vendor_id
- logo_img_path
- md_order_statuses
- md_responsibility_centers
- md_ro_statuses
- messagingservicesid
- region_config
- shopname
- shoprates
- state
- state_tax_id
- updated_at
- zip_post
computed_fields: []
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
role: user
table:
name: bodyshops
schema: public
type: create_select_permission

View File

@@ -0,0 +1,44 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_update_permission
- args:
permission:
columns:
- md_order_statuses
- md_responsibility_centers
- md_ro_statuses
- address1
- address2
- city
- country
- email
- federal_tax_id
- insurance_vendor_id
- logo_img_path
- region_config
- shopname
- state
- state_tax_id
- zip_post
- created_at
- updated_at
- id
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
localPresets:
- key: ""
value: ""
set: {}
role: user
table:
name: bodyshops
schema: public
type: create_update_permission

View File

@@ -0,0 +1,45 @@
- args:
role: user
table:
name: bodyshops
schema: public
type: drop_update_permission
- args:
permission:
columns:
- address1
- address2
- city
- country
- created_at
- email
- federal_tax_id
- id
- insurance_vendor_id
- logo_img_path
- md_order_statuses
- md_responsibility_centers
- md_ro_statuses
- region_config
- shopname
- shoprates
- state
- state_tax_id
- updated_at
- zip_post
filter:
associations:
bodyshop:
associations:
user:
authid:
_eq: X-Hasura-User-Id
localPresets:
- key: ""
value: ""
set: {}
role: user
table:
name: bodyshops
schema: public
type: create_update_permission