fix(psi): correcrtions to account for the tiem offset in the psi

This commit is contained in:
2026-01-02 11:07:45 -06:00
parent 56934216f7
commit 1b59cdd3a4
7 changed files with 203 additions and 157 deletions

View File

@@ -1,4 +1,4 @@
import { addDays, addHours, isAfter, parse } from "date-fns";
import { addDays, addHours, isAfter, parse, subDays } from "date-fns";
import { format } from "date-fns-tz";
import XLSX from "xlsx";
import { db } from "../../../../../../../database/dbclient.js";
@@ -94,6 +94,10 @@ export const abbottOrders = async (data: any, user: any) => {
};
const oOrders: any = openOrders;
//console.log(orderData);
function trimAll(str: string) {
return str.replace(/\s+/g, "");
}
let correctedOrders: any = orderData
.filter(
(o: any) =>
@@ -103,9 +107,9 @@ export const abbottOrders = async (data: any, user: any) => {
.map((o: any) => ({
date: excelDateStuff(o.date, o.time),
po:
o.newton8oz.replace(/\s+/g, "") !== ""
? o.newton8oz.replace(/\s+/g, "")
: o.newton10oz.replace(/\s+/g, ""),
trimAll(o.newton8oz) !== ""
? trimAll(o.newton8oz)
: o.newton10oz.replace(/[\s\u00A0]+/g, ""),
customerArticlenumber:
o.newton8oz != ""
? a.filter((a: any) => a.av === 118)[0].CustomerArticleNumber
@@ -116,24 +120,29 @@ export const abbottOrders = async (data: any, user: any) => {
: a.filter((a: any) => a.av === 120)[0].totalTruckLoad,
}));
//console.log(correctedOrders);
// now we want to make sure we only correct orders that or after now
correctedOrders = correctedOrders.filter((o: any) => {
const parsedDate = parse(o.date, "M/d/yyyy, h:mm:ss a", new Date());
return isAfter(o.date, new Date().toISOString());
return isAfter(new Date(o.date), new Date().toISOString());
});
//console.log(correctedOrders);
// last map to remove orders that have already been started
// correctedOrders = correctedOrders.filter((oo: any) =>
// oOrders.some((o: any) => o.CustomerOrderNumber === oo.po)
// );
let postedOrders: any = [];
const filterOrders: any = correctedOrders;
//console.log(filterOrders);
filterOrders.forEach((oo: any) => {
const isMatch = openOrders.some(
(o: any) => String(o.po).trim() === String(oo.po).trim(),
);
//console.log(isMatch, oo.po);
if (!isMatch) {
//console.log(`ok to update: ${oo.po}`);
console.log(`ok to update: ${oo.po}`);
// oo = {
// ...oo,
@@ -141,7 +150,7 @@ export const abbottOrders = async (data: any, user: any) => {
// };
postedOrders.push(oo);
} else {
// console.log(`Not valid order to update: ${oo.po}`);
//console.log(`Not valid order to update: ${oo.po}`);
//console.log(oo)
}
});
@@ -159,7 +168,7 @@ export const abbottOrders = async (data: any, user: any) => {
deliveryAddressId: 8,
customerArticleNo: o.customerArticlenumber,
quantity: o.qty,
deliveryDate: addHours(format(o.date, "M/d/yyyy HH:mm"), 1), //addHours(addDays(o.date, 1), 1), // adding this in so we can over come the constant 1 day behind thing as a work around
deliveryDate: format(o.date, "M/d/yyyy HH:mm"), // addHours(format(o.date, "M/d/yyyy HH:mm"), 1), //addHours(addDays(o.date, 1), 1), // adding this in so we can over come the constant 1 day behind thing as a work around
customerLineItemNo: 1, // this is how it is currently sent over from abbott
customerReleaseNo: 1, // same as above
},