IO-2054 RO Splitting for QBO

This commit is contained in:
Patrick Fic
2022-09-26 11:33:58 -07:00
parent 220e863482
commit acd3f545b3
6 changed files with 149 additions and 9 deletions

View File

@@ -26084,6 +26084,27 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>additionalpayeroverallocation</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>additionaltotal</name>
<definition_loaded>false</definition_loaded>
@@ -28062,6 +28083,27 @@
</translation>
</translations>
</concept_node>
<concept_node>
<name>multipayers</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>net_repairs</name>
<definition_loaded>false</definition_loaded>

View File

@@ -12,7 +12,9 @@ import {
Popconfirm,
Select,
Space,
Statistic,
Switch,
Typography,
} from "antd";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
@@ -33,7 +35,7 @@ import { generateJobLinesUpdatesForInvoicing } from "../../graphql/jobs-lines.qu
import { UPDATE_JOB } from "../../graphql/jobs.queries";
import { selectJobReadOnly } from "../../redux/application/application.selectors";
import { selectBodyshop } from "../../redux/user/user.selectors";
import Dinero from "dinero.js";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
jobRO: selectJobReadOnly,
@@ -325,9 +327,41 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
</Form.Item>
)}
</LayoutFormRow>
<Divider>{t("jobs.labels.multipayers")}</Divider>
{Qb_Multi_Ar.treatment === "on" && (
<>
<Form.List name={["qb_multiple_payers"]}>
<Space>
<Form.List
name={["qb_multiple_payers"]}
rules={[
({ getFieldValue }) => ({
validator(_, value) {
let totalAllocated = Dinero();
const payers = form.getFieldValue("qb_multiple_payers");
payers &&
payers.forEach((payer) => {
totalAllocated = totalAllocated.add(
Dinero({
amount: Math.round((payer?.amount || 0) * 100),
})
);
});
const discrep = job.job_totals
? Dinero(job.job_totals.totals.total_repairs).subtract(
totalAllocated
)
: Dinero();
return discrep.getAmount() > 0
? Promise.resolve()
: Promise.reject(
new Error(
t("jobs.labels.additionalpayeroverallocation")
)
);
},
}),
]}
>
{(fields, { add, remove }) => {
return (
<div>
@@ -382,7 +416,7 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
<Button
disabled={jobRO}
onClick={() => {
if (fields.length < 3) add();
add();
}}
style={{ width: "100%" }}
>
@@ -393,7 +427,50 @@ export function JobsCloseComponent({ job, bodyshop, jobRO }) {
);
}}
</Form.List>
</>
<Form.Item shouldUpdate>
{() => {
//Perform Calculation to determine discrepancy.
let totalAllocated = Dinero();
const payers = form.getFieldValue("qb_multiple_payers");
payers &&
payers.forEach((payer) => {
totalAllocated = totalAllocated.add(
Dinero({ amount: Math.round((payer?.amount || 0) * 100) })
);
});
const discrep = job.job_totals
? Dinero(job.job_totals.totals.total_repairs).subtract(
totalAllocated
)
: Dinero();
return (
<Space size="large" wrap align="center">
<Statistic
title={t("jobs.labels.total_repairs")}
value={(job.job_totals
? Dinero(job.job_totals.totals.total_repairs)
: Dinero()
).toFormat()}
/>
<Typography.Title>-</Typography.Title>
<Statistic
title={t("jobs.labels.dms.totalallocated")}
value={totalAllocated.toFormat()}
/>
<Typography.Title>=</Typography.Title>
<Statistic
title={t("jobs.labels.total_cust_payable")}
valueStyle={{
color: discrep.getAmount() > 0 ? "green" : "red",
}}
value={discrep.toFormat()}
/>
</Space>
);
}}
</Form.Item>
</Space>
)}
<Divider />
<JobsCloseLines job={job} />

View File

@@ -1546,6 +1546,7 @@
"actual_completion_inferred": "$t(jobs.fields.actual_completion) inferred using $t(jobs.fields.scheduled_completion).",
"actual_delivery_inferred": "$t(jobs.fields.actual_delivery) inferred using $t(jobs.fields.scheduled_delivery).",
"actual_in_inferred": "$t(jobs.fields.actual_in) inferred using $t(jobs.fields.scheduled_in).",
"additionalpayeroverallocation": "You have allocated more than the sale of the Job to additional payers.",
"additionaltotal": "Additional Total",
"adjustmentrate": "Adjustment Rate",
"adjustments": "Adjustments",
@@ -1649,6 +1650,7 @@
"mapa": "Paint Materials",
"markforreexport": "Mark for Re-export",
"mash": "Shop Materials",
"multipayers": "Additional Payers",
"net_repairs": "Net Repairs",
"notes": "Notes",
"othertotal": "Other Totals",

View File

@@ -1546,6 +1546,7 @@
"actual_completion_inferred": "",
"actual_delivery_inferred": "",
"actual_in_inferred": "",
"additionalpayeroverallocation": "",
"additionaltotal": "",
"adjustmentrate": "",
"adjustments": "",
@@ -1649,6 +1650,7 @@
"mapa": "",
"markforreexport": "",
"mash": "",
"multipayers": "",
"net_repairs": "",
"notes": "Notas",
"othertotal": "",

View File

@@ -1546,6 +1546,7 @@
"actual_completion_inferred": "",
"actual_delivery_inferred": "",
"actual_in_inferred": "",
"additionalpayeroverallocation": "",
"additionaltotal": "",
"adjustmentrate": "",
"adjustments": "",
@@ -1649,6 +1650,7 @@
"mapa": "",
"markforreexport": "",
"mash": "",
"multipayers": "",
"net_repairs": "",
"notes": "Remarques",
"othertotal": "",

View File

@@ -100,7 +100,9 @@ exports.default = async (req, res) => {
oauthClient,
qbo_realmId,
req,
job
job,
isThreeTier,
insCoCustomerTier
);
//Query for the owner itself.
if (!ownerCustomerTier) {
@@ -121,7 +123,11 @@ exports.default = async (req, res) => {
qbo_realmId,
req,
job,
isThreeTier ? ownerCustomerTier : null // ownerCustomerTier || insCoCustomerTier
isThreeTier
? ownerCustomerTier
: twoTierPref === "source"
? insCoCustomerTier
: ownerCustomerTier
);
// Need to validate that the job tier is associated to the right individual?
@@ -342,7 +348,14 @@ async function InsertInsuranceCo(oauthClient, qbo_realmId, req, job, bodyshop) {
}
exports.InsertInsuranceCo = InsertInsuranceCo;
async function QueryOwner(oauthClient, qbo_realmId, req, job) {
async function QueryOwner(
oauthClient,
qbo_realmId,
req,
job,
isThreeTier,
parentTierRef
) {
const ownerName = generateOwnerTier(job, true, null);
const result = await oauthClient.makeApiCall({
url: urlBuilder(
@@ -362,7 +375,9 @@ async function QueryOwner(oauthClient, qbo_realmId, req, job) {
result.json &&
result.json.QueryResponse &&
result.json.QueryResponse.Customer &&
result.json.QueryResponse.Customer[0]
result.json.QueryResponse.Customer.find(
(x) => x.ParentRef?.value === parentTierRef?.Id
)
);
}
exports.QueryOwner = QueryOwner;