fix(dm): abbott truck time corrections
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { addDays, addHours, isAfter, parse } from "date-fns";
|
import { addDays, addHours, isAfter, parse } from "date-fns";
|
||||||
|
import { format } from "date-fns-tz";
|
||||||
import XLSX from "xlsx";
|
import XLSX from "xlsx";
|
||||||
import { db } from "../../../../../../../database/dbclient.js";
|
import { db } from "../../../../../../../database/dbclient.js";
|
||||||
import { settings } from "../../../../../../../database/schema/settings.js";
|
import { settings } from "../../../../../../../database/schema/settings.js";
|
||||||
@@ -92,7 +93,7 @@ export const abbottOrders = async (data: any, user: any) => {
|
|||||||
orders: [],
|
orders: [],
|
||||||
};
|
};
|
||||||
const oOrders: any = openOrders;
|
const oOrders: any = openOrders;
|
||||||
|
//console.log(orderData);
|
||||||
let correctedOrders: any = orderData
|
let correctedOrders: any = orderData
|
||||||
.filter(
|
.filter(
|
||||||
(o: any) =>
|
(o: any) =>
|
||||||
@@ -147,6 +148,7 @@ export const abbottOrders = async (data: any, user: any) => {
|
|||||||
|
|
||||||
// Map Excel data to predefinedObject format
|
// Map Excel data to predefinedObject format
|
||||||
const orders = filterOrders.map((o: any) => {
|
const orders = filterOrders.map((o: any) => {
|
||||||
|
//console.log(o.po, " ", o.date, format(o.date, "M/d/yyyy HH:mm"));
|
||||||
return {
|
return {
|
||||||
customerId: customerID,
|
customerId: customerID,
|
||||||
invoiceAddressId: invoiceID,
|
invoiceAddressId: invoiceID,
|
||||||
@@ -157,7 +159,7 @@ export const abbottOrders = async (data: any, user: any) => {
|
|||||||
deliveryAddressId: 8,
|
deliveryAddressId: 8,
|
||||||
customerArticleNo: o.customerArticlenumber,
|
customerArticleNo: o.customerArticlenumber,
|
||||||
quantity: o.qty,
|
quantity: o.qty,
|
||||||
deliveryDate: 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: 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
|
customerLineItemNo: 1, // this is how it is currently sent over from abbott
|
||||||
customerReleaseNo: 1, // same as above
|
customerReleaseNo: 1, // same as above
|
||||||
},
|
},
|
||||||
@@ -165,6 +167,7 @@ export const abbottOrders = async (data: any, user: any) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//console.log(orders);
|
||||||
// combine it all together.
|
// combine it all together.
|
||||||
const updatedPredefinedObject = {
|
const updatedPredefinedObject = {
|
||||||
...predefinedObject,
|
...predefinedObject,
|
||||||
|
|||||||
@@ -1,34 +1,60 @@
|
|||||||
import { getJsDateFromExcel } from "excel-date-to-js";
|
import { getJsDateFromExcel } from "excel-date-to-js";
|
||||||
|
|
||||||
export const excelDateStuff = (serial: number, time: any = 0) => {
|
// export const excelDateStuff = (serial: number, time?: any) => {
|
||||||
// console.log(serial);
|
// // add 5 hours or the offset to utc
|
||||||
// add 5 hours or the offset to utc
|
|
||||||
|
|
||||||
// get the local timezone
|
// // get the local timezone
|
||||||
const localoffset = new Date().getTimezoneOffset() / 60; // then divide by 60 to get the true number;
|
// const localoffset = new Date().getTimezoneOffset() / 60; // then divide by 60 to get the true number;
|
||||||
|
|
||||||
if (serial % 1 === 0) {
|
// if (!time) {
|
||||||
time = 800;
|
// time = 800;
|
||||||
}
|
// }
|
||||||
|
|
||||||
const addHours = serial + localoffset / 24;
|
// const addHours = serial + localoffset / 24;
|
||||||
//console.log(getJsDateFromExcel(addHours));
|
// //console.log(getJsDateFromExcel(addHours));
|
||||||
|
// if (typeof serial !== "number" || serial <= 0) {
|
||||||
|
// return "invalid Date";
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const date = getJsDateFromExcel(addHours); // base date from Excel serial
|
||||||
|
|
||||||
|
// if (time != 0) {
|
||||||
|
// // convert the time over to hour and min
|
||||||
|
// const hours = Math.floor(time / 100);
|
||||||
|
// const minutes = time % 100;
|
||||||
|
// date.setHours(hours);
|
||||||
|
// date.setMinutes(minutes);
|
||||||
|
// }
|
||||||
|
// //console.log(date.toLocaleString("en-US"), getJsDateFromExcel(addHours));
|
||||||
|
|
||||||
|
// //console.log(serial);
|
||||||
|
// console.log(date.toISOString(), serial, time);
|
||||||
|
// return date.toISOString(); //.toLocaleString("en-US"); // or .toISOString() if preferred
|
||||||
|
// };
|
||||||
|
|
||||||
|
export const excelDateStuff = (serial: number, time?: any) => {
|
||||||
if (typeof serial !== "number" || serial <= 0) {
|
if (typeof serial !== "number" || serial <= 0) {
|
||||||
return "invalid Date";
|
return "invalid Date";
|
||||||
}
|
}
|
||||||
|
|
||||||
const date = getJsDateFromExcel(addHours); // base date from Excel serial
|
// Default time to 8:00 AM if not provided
|
||||||
|
if (!time) {
|
||||||
|
time = 800;
|
||||||
|
}
|
||||||
|
|
||||||
if (time != 0) {
|
// Get base date from Excel serial (this gives you UTC midnight)
|
||||||
// convert the time over to hour and min
|
const date = getJsDateFromExcel(serial);
|
||||||
|
|
||||||
|
const localOffset = new Date().getTimezoneOffset() / 60;
|
||||||
const hours = Math.floor(time / 100);
|
const hours = Math.floor(time / 100);
|
||||||
const minutes = time % 100;
|
const minutes = time % 100;
|
||||||
date.setHours(hours);
|
|
||||||
date.setMinutes(minutes);
|
|
||||||
}
|
|
||||||
//console.log(date.toLocaleString("en-US"), getJsDateFromExcel(addHours));
|
|
||||||
|
|
||||||
//console.log(serial);
|
// Set the time in UTC
|
||||||
//console.log(date.toISOString());
|
date.setUTCHours(hours + localOffset);
|
||||||
return date.toISOString(); //.toLocaleString("en-US"); // or .toISOString() if preferred
|
date.setUTCMinutes(minutes);
|
||||||
|
date.setUTCSeconds(0);
|
||||||
|
date.setUTCMilliseconds(0);
|
||||||
|
|
||||||
|
//console.log(date.toISOString(), serial, time);
|
||||||
|
return date.toISOString();
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user