Basic IIF rendering with test component for BOD-83
This commit is contained in:
58
server/accounting/iif/iif-receivables.js
Normal file
58
server/accounting/iif/iif-receivables.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const path = require("path");
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
const queries = require("../../graphql-client/queries");
|
||||
|
||||
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 response = [];
|
||||
response.push(TRNS_HEADER);
|
||||
response.push(generateInvoiceHeader(result.jobs_by_pk));
|
||||
response.push(END_TRNS);
|
||||
|
||||
res.setHeader("Content-type", "application/octet-stream");
|
||||
res.setHeader("Content-disposition", "attachment; filename=file.txt");
|
||||
res.setHeader("filename", `${result.jobs_by_pk.ro_number}-RECEIVABLES.iif`);
|
||||
res.send(response.join("\n"));
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
res.status(400).send(JSON.stringify(error));
|
||||
}
|
||||
};
|
||||
|
||||
const TRNS_HEADER = `!TRNS TRNSID TRNSTYPE DATE ACCNT NAME CLASS AMOUNT DOCNUM MEMO CLEAR TOPRINT NAMEISTAXABLE ADDR1 ADDR2 ADDR3 ADDR4 DUEDATE TERMS OTHER1 PONUM
|
||||
!SPL SPLID TRNSTYPE DATE ACCNT NAME CLASS AMOUNT DOCNUM MEMO CLEAR QNTY PRICE INVITEM PAYMETH TAXABLE VALADJ SERVICEDATE OTHER2 EXTRA
|
||||
!ENDTRNS`;
|
||||
|
||||
const generateInvoiceHeader = (job) =>
|
||||
`TRNS INVOICE ${new Date(job.date_invoiced).getMonth() + 1}/${new Date(
|
||||
job.date_invoiced
|
||||
).getDate()}/${new Date(
|
||||
job.date_invoiced
|
||||
).getFullYear()} Accounts Receivable GUO DA Acct.# ${job.ownr_id}:${
|
||||
job.ro_number
|
||||
} 0100 ${job.clm_total} ${job.ro_number} N N Y GUO DA Acct.# ${job.ownr_id}:${
|
||||
job.ro_number
|
||||
} ${job.ownr_addr1} ${job.ownr_city} ${job.ownr_st} ${job.ownr_zip} `;
|
||||
const generateInvoiceLine = (line) =>
|
||||
`SPL INVOICE 05/21/2020 Sales:Total Labour:Sales, Body Shop Labour 0100 -572.60 114519 Labor Body N 572.60 Total Labour:4015 Y N `;
|
||||
|
||||
const END_TRNS = `ENDTRNS`;
|
||||
1
server/accounting/iif/iif.js
Normal file
1
server/accounting/iif/iif.js
Normal file
@@ -0,0 +1 @@
|
||||
exports.receivables = require("./iif-receivables").default
|
||||
@@ -1,10 +1,17 @@
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
const path = require("path");
|
||||
require("dotenv").config({ path: path.resolve(process.cwd(), `.env.${process.env.NODE_ENV || 'development'}`) });
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
|
||||
//TODO May need to use a different client that includes caching of resources.
|
||||
//TODO May need to use a different client that includes caching of resources.
|
||||
exports.client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
"x-hasura-admin-secret": process.env.HASURA_ADMIN_SECRET
|
||||
}
|
||||
"x-hasura-admin-secret": process.env.HASURA_ADMIN_SECRET,
|
||||
},
|
||||
});
|
||||
|
||||
exports.unauthclient = new GraphQLClient(process.env.GRAPHQL_ENDPOINT);
|
||||
|
||||
@@ -39,3 +39,27 @@ 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) {
|
||||
id
|
||||
job_totals
|
||||
date_invoiced
|
||||
ro_number
|
||||
clm_total
|
||||
invoice_allocation
|
||||
ownerid
|
||||
ownr_addr1
|
||||
ownr_addr2
|
||||
ownr_zip
|
||||
ownr_city
|
||||
ownr_st
|
||||
|
||||
}
|
||||
bodyshops{
|
||||
id
|
||||
md_responsibility_centers
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user