Added untested changes for exporting all receivables BOD-240
This commit is contained in:
@@ -16,7 +16,7 @@ const { generateJobTier, generateOwnerTier, generateSourceTier } = QbXmlUtils;
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
const BearerToken = req.headers.authorization;
|
||||
const { jobId } = req.body;
|
||||
const { jobIds } = req.body;
|
||||
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
@@ -27,51 +27,56 @@ exports.default = async (req, res) => {
|
||||
try {
|
||||
const result = await client
|
||||
.setHeaders({ Authorization: BearerToken })
|
||||
.request(queries.QUERY_JOBS_FOR_RECEIVABLES_EXPORT, { id: jobId });
|
||||
const { jobs_by_pk } = result;
|
||||
const { bodyshop } = jobs_by_pk;
|
||||
.request(queries.QUERY_JOBS_FOR_RECEIVABLES_EXPORT, { ids: jobIds });
|
||||
console.log("result", result);
|
||||
const { jobs } = result;
|
||||
const { bodyshops } = result;
|
||||
const QbXmlToExecute = [];
|
||||
|
||||
//Is this a two tier, or 3 tier setup?
|
||||
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||
const twoTierPref = bodyshop.accountingconfig.twotierpref;
|
||||
const bodyshop = bodyshops[0];
|
||||
|
||||
jobs.map((jobs_by_pk) => {
|
||||
//Is this a two tier, or 3 tier setup?
|
||||
const isThreeTier = bodyshop.accountingconfig.tiers === 3;
|
||||
const twoTierPref = bodyshop.accountingconfig.twotierpref;
|
||||
|
||||
if (isThreeTier) {
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateSourceCustomerQbxml(jobs_by_pk, bodyshop), // Create the source customer.
|
||||
});
|
||||
}
|
||||
|
||||
if (isThreeTier) {
|
||||
QbXmlToExecute.push({
|
||||
id: jobId,
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateSourceCustomerQbxml(jobs_by_pk, bodyshop), // Create the source customer.
|
||||
qbxml: generateJobQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
2,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
QbXmlToExecute.push({
|
||||
id: jobId,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateJobQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
2,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
|
||||
QbXmlToExecute.push({
|
||||
id: jobId,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateJobQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
3,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
//Generate the actual invoice.
|
||||
QbXmlToExecute.push({
|
||||
id: jobId,
|
||||
okStatusCodes: ["0"],
|
||||
qbxml: generateInvoiceQbxml(jobs_by_pk, bodyshop),
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0", "3100"],
|
||||
qbxml: generateJobQbxml(
|
||||
jobs_by_pk,
|
||||
bodyshop,
|
||||
isThreeTier,
|
||||
3,
|
||||
twoTierPref
|
||||
),
|
||||
});
|
||||
//Generate the actual invoice.
|
||||
QbXmlToExecute.push({
|
||||
id: jobs_by_pk.id,
|
||||
okStatusCodes: ["0"],
|
||||
qbxml: generateInvoiceQbxml(jobs_by_pk, bodyshop),
|
||||
});
|
||||
});
|
||||
|
||||
res.status(200).json(QbXmlToExecute);
|
||||
|
||||
@@ -41,8 +41,8 @@ mutation UPDATE_MESSAGE($msid: String!, $fields: messages_set_input!) {
|
||||
`;
|
||||
|
||||
exports.QUERY_JOBS_FOR_RECEIVABLES_EXPORT = `
|
||||
query QUERY_JOBS_FOR_RECEIVABLES_EXPORT($id: uuid!) {
|
||||
jobs_by_pk(id: $id) {
|
||||
query QUERY_JOBS_FOR_RECEIVABLES_EXPORT($ids: [uuid!]!) {
|
||||
jobs(where: {id: {_in: $ids}}) {
|
||||
id
|
||||
job_totals
|
||||
date_invoiced
|
||||
@@ -59,14 +59,14 @@ query QUERY_JOBS_FOR_RECEIVABLES_EXPORT($id: uuid!) {
|
||||
ownr_city
|
||||
ownr_st
|
||||
ins_co_nm
|
||||
owner{
|
||||
owner {
|
||||
accountingid
|
||||
}
|
||||
bodyshop {
|
||||
id
|
||||
md_responsibility_centers
|
||||
accountingconfig
|
||||
}
|
||||
}
|
||||
bodyshops(where: {associations: {active: {_eq: true}}}) {
|
||||
id
|
||||
md_responsibility_centers
|
||||
accountingconfig
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user