WIP Exporting Fixes

This commit is contained in:
Patrick Fic
2021-02-16 17:09:01 -08:00
parent 930d9fe7dc
commit 9533e7c4e0
13 changed files with 174 additions and 126 deletions

View File

@@ -61,7 +61,8 @@ const generateBill = (bill) => {
FullName: bill.vendor.name,
},
TxnDate: moment(bill.date).format("YYYY-MM-DD"),
DueDate: moment(bill.due_date).format("YYYY-MM-DD"),
DueDate:
bill.due_date && moment(bill.due_date).format("YYYY-MM-DD"),
RefNumber: bill.bill_number,
Memo: `RO ${bill.job.ro_number || ""} OWNER ${
bill.job.ownr_fn || ""

View File

@@ -6,6 +6,7 @@ const Dinero = require("dinero.js");
var builder = require("xmlbuilder");
const moment = require("moment");
const QbXmlUtils = require("./qbxml-utils");
const QbxmlReceivables = require("./qbxml-receivables");
require("dotenv").config({
path: path.resolve(
process.cwd(),
@@ -31,42 +32,49 @@ exports.default = async (req, res) => {
.request(queries.QUERY_PAYMENTS_FOR_EXPORT, {
payments: paymentsToQuery,
});
const { payments } = result;
const { payments, bodyshops } = result;
const bodyshop = bodyshops[0];
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.
});
}
QbXmlToExecute.push({
id: jobs_by_pk.id,
okStatusCodes: ["0", "3100"],
qbxml: generateJobQbxml(
jobs_by_pk,
bodyshop,
isThreeTier,
2,
twoTierPref
),
});
QbXmlToExecute.push({
id: jobs_by_pk.id,
okStatusCodes: ["0", "3100"],
qbxml: generateJobQbxml(
jobs_by_pk,
bodyshop,
isThreeTier,
3,
twoTierPref
),
});
const QbXmlToExecute = [];
payments.map((i) => {
if (isThreeTier) {
QbXmlToExecute.push({
id: i.id,
okStatusCodes: ["0", "3100"],
qbxml: QbxmlReceivables.generateSourceCustomerQbxml(i.job, bodyshop), // Create the source customer.
});
}
QbXmlToExecute.push({
id: i.id,
okStatusCodes: ["0", "3100"],
qbxml: QbxmlReceivables.generateJobQbxml(
i.job,
bodyshop,
isThreeTier,
2,
twoTierPref
),
});
QbXmlToExecute.push({
id: i.id,
okStatusCodes: ["0", "3100"],
qbxml: QbxmlReceivables.generateJobQbxml(
i.job,
bodyshop,
isThreeTier,
3,
twoTierPref
),
});
QbXmlToExecute.push({
id: i.id,
okStatusCodes: ["0"],

View File

@@ -29,8 +29,7 @@ exports.default = async (req, res) => {
const result = await client
.setHeaders({ Authorization: BearerToken })
.request(queries.QUERY_JOBS_FOR_RECEIVABLES_EXPORT, { ids: jobIds });
const { jobs } = result;
const { bodyshops } = result;
const { jobs, bodyshops } = result;
const QbXmlToExecute = [];
const bodyshop = bodyshops[0];
@@ -119,7 +118,7 @@ const generateSourceCustomerQbxml = (jobs_by_pk, bodyshop) => {
return customerQbxml_Full;
};
exports.generateSourceCustomerQbxml = generateSourceCustomerQbxml;
const generateJobQbxml = (
jobs_by_pk,
bodyshop,
@@ -170,7 +169,7 @@ const generateJobQbxml = (
console.log("jobQbxml_Full", jobQbxml_Full);
return jobQbxml_Full;
};
exports.generateJobQbxml = generateJobQbxml;
const generateInvoiceQbxml = (jobs_by_pk, bodyshop) => {
//Build the Invoice XML file.
const InvoiceLineAdd = [];

View File

@@ -146,7 +146,12 @@ query QUERY_BILLS_FOR_PAYABLES_EXPORT($bills: [uuid!]!) {
`;
exports.QUERY_PAYMENTS_FOR_EXPORT = `
query QUERY_PAYMENTS_FOR_EXPORT($payments: [uuid!]!) {
query QUERY_PAYMENTS_FOR_EXPORT($payments: [uuid!]!)
{ bodyshops(where: {associations: {active: {_eq: true}}}) {
id
md_responsibility_centers
accountingconfig
}
payments(where: {id: {_in: $payments}}) {
id
created_at