feat(dm): standard forecast and orders in

This commit is contained in:
2025-04-23 15:19:34 -05:00
parent 3c9e627021
commit 28b050859a
9 changed files with 172 additions and 19 deletions

View File

@@ -100,7 +100,27 @@ export const standardOrders = async (data: any, user: any) => {
let postedOrders: any = [];
for (const [customerID, orders] of Object.entries(groupedByCustomer)) {
// console.log(`Running for Customer ID: ${customerID}`);
const newOrders: any = orders;
const filterOrders: any = orders;
const newOrders: any = [];
//newOrders.filter((oo) => openOrders.some((o) => String(o.CustomerOrderNumber) === String(oo.CustomerOrderNumber)));
//console.log(newOrders)
filterOrders.forEach((oo: any) => {
const isMatch = openOrders.some(
(o: any) =>
String(o.CustomerOrderNumber).trim() ===
String(oo.CustomerOrderNumber).trim()
);
if (!isMatch) {
console.log(`ok to update: ${oo.CustomerOrderNumber}`);
newOrders.push(oo);
} else {
console.log(
`Not valid order to update: ${oo.CustomerOrderNumber}`
);
//console.log(oo)
}
});
// filter out the orders that have already been started just to reduce the risk of errors.
newOrders.filter((oo: any) =>
@@ -119,7 +139,7 @@ export const standardOrders = async (data: any, user: any) => {
}
return {
customerId: parseInt(customerID),
invoiceAddressId: invoice[0].invoiceAddress, // matched to the default invoice address
invoiceAddressId: invoice[0]?.invoiceAddress, // matched to the default invoice address
customerOrderNo: o.CustomerOrderNumber,
orderDate: new Date(Date.now()).toLocaleString("en-US"),
positions: [