Added QBXML Creation and posting to localhost. BOD-83
This commit is contained in:
116
server/accounting/qbxml/qbxml-receivables.js
Normal file
116
server/accounting/qbxml/qbxml-receivables.js
Normal file
@@ -0,0 +1,116 @@
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const path = require("path");
|
||||
var QuickBooks = require("node-quickbooks");
|
||||
var builder = require("xmlbuilder");
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
const queries = require("../../graphql-client/queries");
|
||||
const Dinero = require("dinero.js");
|
||||
|
||||
exports.default = async (req, res) => {
|
||||
const BearerToken = req.headers.authorization;
|
||||
const { jobId } = req.body;
|
||||
|
||||
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
Authorization: BearerToken,
|
||||
},
|
||||
});
|
||||
|
||||
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;
|
||||
//Build the XML file.
|
||||
|
||||
var requestXML = builder
|
||||
.create(foo, { version: "1.30", encoding: "UTF-8", headless: true })
|
||||
.end({ pretty: true });
|
||||
|
||||
const ret = `<?xml version="1.0" encoding="utf-8"?>
|
||||
<?qbxml version="CA13.0"?>
|
||||
${requestXML}
|
||||
`;
|
||||
|
||||
console.log(ret);
|
||||
//Prep the response and send it.
|
||||
// res.setHeader("Content-type", "application/octet-stream");
|
||||
// res.setHeader("Content-disposition", "attachment; filename=file.txt");
|
||||
// res.setHeader("filename", `${jobs_by_pk.ro_number}-RECEIVABLES.xml`);
|
||||
//res.send(response.join("\n"));
|
||||
res.status(200).send(ret);
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
res.status(400).send(JSON.stringify(error));
|
||||
}
|
||||
};
|
||||
const foo = {
|
||||
QBXML: {
|
||||
QBXMLMsgsRq: {
|
||||
"@onError": "stopOnError",
|
||||
InvoiceAddRq: {
|
||||
InvoiceAdd: {
|
||||
CustomerRef: {
|
||||
FullName: "Full Name",
|
||||
},
|
||||
TxnDate: new Date(),
|
||||
RefNumber: "RefNumber",
|
||||
BillAddress: {
|
||||
Addr1: "Address1",
|
||||
Addr2: "Address2",
|
||||
Addr3: "Address3",
|
||||
Addr4: "Address4",
|
||||
Addr5: "Address5",
|
||||
City: "City",
|
||||
State: "State",
|
||||
PostalCode: "PostalCode",
|
||||
Country: "Country",
|
||||
Note: "Note",
|
||||
},
|
||||
PONumber: "Ponumber",
|
||||
IsTaxIncluded: true,
|
||||
// InvoiceLineAddList: {
|
||||
InvoiceLineAdd: [
|
||||
{
|
||||
ItemRef: { FullName: "ItemRef FullName" },
|
||||
Desc: "Description",
|
||||
Quantity: 1,
|
||||
//Rate: 100,
|
||||
Amount: 100,
|
||||
},
|
||||
{
|
||||
ItemRef: { FullName: "ItemRef FullName" },
|
||||
Desc: "Description",
|
||||
Quantity: 1,
|
||||
//Rate: 100,
|
||||
Amount: 100,
|
||||
},
|
||||
{
|
||||
ItemRef: { FullName: "ItemRef FullName" },
|
||||
Desc: "Description",
|
||||
Quantity: 1,
|
||||
//Rate: 100,
|
||||
Amount: 100,
|
||||
},
|
||||
{
|
||||
ItemRef: { FullName: "ItemRef FullName" },
|
||||
Desc: "Description",
|
||||
Quantity: 1,
|
||||
//Rate: 100,
|
||||
Amount: 100,
|
||||
},
|
||||
],
|
||||
// },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
1
server/accounting/qbxml/qbxml.js
Normal file
1
server/accounting/qbxml/qbxml.js
Normal file
@@ -0,0 +1 @@
|
||||
exports.receivables = require("./qbxml-receivables").default
|
||||
Reference in New Issue
Block a user