IO-256 Add vendor credits.

This commit is contained in:
Patrick Fic
2021-10-12 16:54:28 -07:00
parent a02aa71a95
commit fff9073f9d

View File

@@ -72,6 +72,7 @@ exports.default = async (req, res) => {
bill, bill,
vendorRecord vendorRecord
); );
ret.push({ billid: bill.id, success: true }); ret.push({ billid: bill.id, success: true });
} catch (error) { } catch (error) {
ret.push({ ret.push({
@@ -112,7 +113,7 @@ async function QueryVendorRecord(oauthClient, req, bill) {
); );
} catch (error) { } catch (error) {
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, { logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
error, error: JSON.stringify(error),
method: "QueryVendorRecord", method: "QueryVendorRecord",
}); });
throw error; throw error;
@@ -135,7 +136,7 @@ async function InsertVendorRecord(oauthClient, req, bill) {
return result && result.Vendor; return result && result.Vendor;
} catch (error) { } catch (error) {
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, { logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
error, error: JSON.stringify(error),
method: "InsertVendorRecord", method: "InsertVendorRecord",
}); });
throw error; throw error;
@@ -150,7 +151,7 @@ async function InsertBill(oauthClient, req, bill, vendor) {
value: vendor.Id, value: vendor.Id,
}, },
TxnDate: moment(bill.date).format("YYYY-MM-DD"), TxnDate: moment(bill.date).format("YYYY-MM-DD"),
DueDate: bill.due_date && moment(bill.due_date).format("YYYY-MM-DD"), //DueDate: bill.due_date && moment(bill.due_date).format("YYYY-MM-DD"),
DocNumber: bill.invoice_number, DocNumber: bill.invoice_number,
...(bill.job.class ? { ClassRef: { Id: classes[bill.job.class] } } : {}), ...(bill.job.class ? { ClassRef: { Id: classes[bill.job.class] } } : {}),
@@ -170,7 +171,10 @@ async function InsertBill(oauthClient, req, bill, vendor) {
}; };
try { try {
const result = await oauthClient.makeApiCall({ const result = await oauthClient.makeApiCall({
url: urlBuilder(req.cookies.qbo_realmId, "bill"), url: urlBuilder(
req.cookies.qbo_realmId,
bill.is_credit_memo ? "vendorcredit" : "bill"
),
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
@@ -181,7 +185,7 @@ async function InsertBill(oauthClient, req, bill, vendor) {
return result && result.Bill; return result && result.Bill;
} catch (error) { } catch (error) {
logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, { logger.log("qbo-payables-error", "DEBUG", req.user.email, bill.id, {
error, error: JSON.stringify(error),
method: "InsertBill", method: "InsertBill",
}); });
throw error; throw error;
@@ -231,6 +235,7 @@ const generateBillLine = (
.toFormat(DineroQbFormat), .toFormat(DineroQbFormat),
}; };
}; };
async function QueryMetaData(oauthClient, req) { async function QueryMetaData(oauthClient, req) {
const accounts = await oauthClient.makeApiCall({ const accounts = await oauthClient.makeApiCall({
url: urlBuilder( url: urlBuilder(