Compare commits
13 Commits
cfd378dab6
...
57ac7a6b8d
| Author | SHA1 | Date | |
|---|---|---|---|
| 57ac7a6b8d | |||
| c88fedd75a | |||
| a5f1203a34 | |||
| b96a750e9e | |||
| fb603e74dc | |||
| 2559706510 | |||
| 89812d29a0 | |||
| 9148723607 | |||
| e2fcb09ff9 | |||
| 3ecad39440 | |||
| e9bcf2e21e | |||
| 54a4e008a2 | |||
| 522f313249 |
@@ -22,6 +22,7 @@ export default function DMButtons() {
|
|||||||
name={"Energizer Truck List"}
|
name={"Energizer Truck List"}
|
||||||
/>
|
/>
|
||||||
<ForecastImport fileType={"loreal"} name={"VMI Import"} />
|
<ForecastImport fileType={"loreal"} name={"VMI Import"} />
|
||||||
|
<ForecastImport fileType={"pg"} name={"P&G"} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{plantToken[0]?.value === "usday1" && (
|
{plantToken[0]?.value === "usday1" && (
|
||||||
@@ -44,6 +45,16 @@ export default function DMButtons() {
|
|||||||
{plantToken[0]?.value === "usstp1" && (
|
{plantToken[0]?.value === "usstp1" && (
|
||||||
<div className="flex flex-row gap-2"></div>
|
<div className="flex flex-row gap-2"></div>
|
||||||
)}
|
)}
|
||||||
|
{plantToken[0]?.value === "usiow1" && (
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<ForecastImport fileType={"pg"} name={"P&G"} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{plantToken[0]?.value === "usiow2" && (
|
||||||
|
<div className="flex flex-row gap-2">
|
||||||
|
<ForecastImport fileType={"pg"} name={"P&G"} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"admConfig": {
|
"admConfig": {
|
||||||
"build": 340,
|
"build": 348,
|
||||||
"oldBuild": "backend-0.1.3.zip"
|
"oldBuild": "backend-0.1.3.zip"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { lorealForecast } from "./mappings/loralForecast.js";
|
import { lorealForecast } from "./mappings/loralForecast.js";
|
||||||
|
import { pNgForecast } from "./mappings/pNgForecast.js";
|
||||||
import { standardForecast } from "./mappings/standardForcast.js";
|
import { standardForecast } from "./mappings/standardForcast.js";
|
||||||
|
|
||||||
export const forecastIn = async (data: any, user: any) => {
|
export const forecastIn = async (data: any, user: any) => {
|
||||||
@@ -32,7 +33,11 @@ export const forecastIn = async (data: any, user: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (data["fileType"] === "pg") {
|
if (data["fileType"] === "pg") {
|
||||||
// orders in
|
//run the standard forecast in
|
||||||
|
const pg = await pNgForecast(data["postForecast"], user);
|
||||||
|
success = pg.success ?? false;
|
||||||
|
message = pg.message ?? "Error posting standard forecast";
|
||||||
|
orderData = pg.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -0,0 +1,160 @@
|
|||||||
|
import { db } from "../../../../../../../database/dbclient.js";
|
||||||
|
import { settings } from "../../../../../../../database/schema/settings.js";
|
||||||
|
import { tryCatch } from "../../../../../../globalUtils/tryCatch.js";
|
||||||
|
import XLSX from "xlsx";
|
||||||
|
import { excelDateStuff } from "../../../../utils/excelDateStuff.js";
|
||||||
|
import { postForecast } from "../postForecast.js";
|
||||||
|
import { query } from "../../../../../sqlServer/prodSqlServer.js";
|
||||||
|
import { activeArticle } from "../../../../../sqlServer/querys/dataMart/article.js";
|
||||||
|
|
||||||
|
export const pNgForecast = async (data: any, user: any) => {
|
||||||
|
/**
|
||||||
|
* Post a standard forecast based on the standard template.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const { data: s, error: e } = await tryCatch(db.select().from(settings));
|
||||||
|
|
||||||
|
if (e) {
|
||||||
|
return {
|
||||||
|
sucess: false,
|
||||||
|
message: `Error getting settings`,
|
||||||
|
data: e,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: a, error: ae } = await tryCatch(
|
||||||
|
query(activeArticle, "p&g active av")
|
||||||
|
);
|
||||||
|
|
||||||
|
if (ae) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
message: "Error getting active av",
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const article: any = a?.data;
|
||||||
|
|
||||||
|
const plantToken = s.filter((s) => s.name === "plantToken");
|
||||||
|
|
||||||
|
const arrayBuffer = await data.arrayBuffer();
|
||||||
|
const buffer = Buffer.from(arrayBuffer);
|
||||||
|
|
||||||
|
const workbook = XLSX.read(buffer, { type: "buffer" });
|
||||||
|
|
||||||
|
const sheetName = workbook.SheetNames[0];
|
||||||
|
//const sheet: any = workbook.Sheets[sheetName];
|
||||||
|
const sheet: any = workbook.Sheets["SchedAgreementUIConfigSpreadshe"];
|
||||||
|
const range = XLSX.utils.decode_range(sheet["!ref"]);
|
||||||
|
|
||||||
|
const headers = [];
|
||||||
|
for (let C = range.s.c; C <= range.e.c; ++C) {
|
||||||
|
const cellAddress = XLSX.utils.encode_cell({ r: 0, c: C }); // row 0 = Excel row 1
|
||||||
|
const cell = sheet[cellAddress];
|
||||||
|
headers.push(cell ? cell.v : undefined);
|
||||||
|
}
|
||||||
|
|
||||||
|
//console.log(headers);
|
||||||
|
const forecastData: any = XLSX.utils.sheet_to_json(sheet, {
|
||||||
|
defval: "",
|
||||||
|
header: headers,
|
||||||
|
range: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
const groupedByCustomer: any = forecastData.reduce(
|
||||||
|
(acc: any, item: any) => {
|
||||||
|
const id = item.CustomerID;
|
||||||
|
if (!acc[id]) {
|
||||||
|
acc[id] = [];
|
||||||
|
}
|
||||||
|
acc[id].push(item);
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
const foreCastData: any = [];
|
||||||
|
|
||||||
|
for (const [customerID, forecast] of Object.entries(groupedByCustomer)) {
|
||||||
|
//console.log(`Running for Customer ID: ${customerID}`);
|
||||||
|
const newForecast: any = forecast;
|
||||||
|
|
||||||
|
const predefinedObject = {
|
||||||
|
receivingPlantId: plantToken[0].value,
|
||||||
|
documentName: `ForecastFromLST-${new Date(
|
||||||
|
Date.now()
|
||||||
|
).toLocaleString("en-US")}`,
|
||||||
|
sender: user.username || "lst-system",
|
||||||
|
customerId: 139,
|
||||||
|
positions: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
// map everything out for each order
|
||||||
|
const nForecast = newForecast.map((o: any) => {
|
||||||
|
// const invoice = i.filter(
|
||||||
|
// (i: any) => i.deliveryAddress === parseInt(customerID)
|
||||||
|
// );
|
||||||
|
// if (!invoice) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
|
return {
|
||||||
|
customerArticleNo: parseInt(o["Customer Item No."]),
|
||||||
|
requirementDate: excelDateStuff(parseInt(o["Request Date"])),
|
||||||
|
quantity: o["Remaining Qty to be Shipped"],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// check to make sure the av belongs in this plant.
|
||||||
|
const onlyNumbers = nForecast.filter((n: any) => n.quantity > 0);
|
||||||
|
const filteredForecast: any = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < nForecast.length; i++) {
|
||||||
|
//console.log(nForecast[i].customerArticleNo);
|
||||||
|
const activeAV = article.filter(
|
||||||
|
(c: any) =>
|
||||||
|
c?.CustomerArticleNumber ===
|
||||||
|
nForecast[i]?.customerArticleNo.toString()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (activeAV.length > 0) {
|
||||||
|
filteredForecast.push(onlyNumbers[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filteredForecast.length === 0) {
|
||||||
|
console.log("Nothing to post");
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "No forecast to be posted",
|
||||||
|
data: foreCastData,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// do that fun combining thing
|
||||||
|
let updatedPredefinedObject = {
|
||||||
|
...predefinedObject,
|
||||||
|
positions: [...predefinedObject.positions, ...filteredForecast],
|
||||||
|
};
|
||||||
|
|
||||||
|
//console.log(updatedPredefinedObject);
|
||||||
|
|
||||||
|
// post the orders to the server
|
||||||
|
const posting: any = await postForecast(updatedPredefinedObject, user);
|
||||||
|
|
||||||
|
foreCastData.push({
|
||||||
|
customer: customerID,
|
||||||
|
//totalOrders: orders?.length(),
|
||||||
|
success: posting.success,
|
||||||
|
message: posting.message,
|
||||||
|
data: posting.data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
message: "Forecast Posted",
|
||||||
|
data: foreCastData,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -118,7 +118,7 @@ export const abbottOrders = async (data: any, user: any) => {
|
|||||||
// now we want to make sure we only correct orders that or after now
|
// now we want to make sure we only correct orders that or after now
|
||||||
correctedOrders = correctedOrders.filter((o: any) => {
|
correctedOrders = correctedOrders.filter((o: any) => {
|
||||||
const parsedDate = parse(o.date, "M/d/yyyy, h:mm:ss a", new Date());
|
const parsedDate = parse(o.date, "M/d/yyyy, h:mm:ss a", new Date());
|
||||||
return isAfter(parsedDate, new Date());
|
return isAfter(o.date, new Date().toISOString());
|
||||||
});
|
});
|
||||||
|
|
||||||
// last map to remove orders that have already been started
|
// last map to remove orders that have already been started
|
||||||
@@ -132,7 +132,7 @@ export const abbottOrders = async (data: any, user: any) => {
|
|||||||
(o: any) => String(o.po).trim() === String(oo.po).trim()
|
(o: any) => String(o.po).trim() === String(oo.po).trim()
|
||||||
);
|
);
|
||||||
if (!isMatch) {
|
if (!isMatch) {
|
||||||
console.log(`ok to update: ${oo.po}`);
|
//console.log(`ok to update: ${oo.po}`);
|
||||||
|
|
||||||
// oo = {
|
// oo = {
|
||||||
// ...oo,
|
// ...oo,
|
||||||
@@ -140,7 +140,7 @@ export const abbottOrders = async (data: any, user: any) => {
|
|||||||
// };
|
// };
|
||||||
postedOrders.push(oo);
|
postedOrders.push(oo);
|
||||||
} else {
|
} else {
|
||||||
console.log(`Not valid order to update: ${oo.po}`);
|
// console.log(`Not valid order to update: ${oo.po}`);
|
||||||
//console.log(oo)
|
//console.log(oo)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -171,13 +171,14 @@ export const abbottOrders = async (data: any, user: any) => {
|
|||||||
orders: [...predefinedObject.orders, ...orders],
|
orders: [...predefinedObject.orders, ...orders],
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(updatedPredefinedObject);
|
//console.log(updatedPredefinedObject);
|
||||||
// post the orders to the server
|
// post the orders to the server
|
||||||
const posting = await postOrders(updatedPredefinedObject, user);
|
const posting = await postOrders(updatedPredefinedObject, user);
|
||||||
|
//console.log(posting);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: posting?.success,
|
success: posting?.success,
|
||||||
message: posting?.message,
|
message: posting?.message,
|
||||||
data: posting?.data,
|
data: posting,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ export const postOrders = async (data: any, user: any) => {
|
|||||||
data: data,
|
data: data,
|
||||||
});
|
});
|
||||||
|
|
||||||
//console.log(results.data);
|
|
||||||
//console.log(results.status);
|
//console.log(results.status);
|
||||||
if (results.data.errors) {
|
if (results.data.errors) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export const excelDateStuff = (serial: number, time: any = 0) => {
|
|||||||
date.setHours(hours);
|
date.setHours(hours);
|
||||||
date.setMinutes(minutes);
|
date.setMinutes(minutes);
|
||||||
}
|
}
|
||||||
|
//console.log(date.toLocaleString("en-US"), getJsDateFromExcel(addHours));
|
||||||
return date.toLocaleString("en-US"); // or .toISOString() if preferred
|
//console.log(date.toISOString());
|
||||||
|
return date.toISOString(); //.toLocaleString("en-US"); // or .toISOString() if preferred
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export const assignedPrinters = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (l.data.length === 0 && l.success) {
|
if (l.data.length === 0 && l.success) {
|
||||||
createLog("info", "lst", "ocp", `There are no lots assigned currently`);
|
//createLog("info", "lst", "ocp", `There are no lots assigned currently`);
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
message: "There are no lots assigned currenly.",
|
message: "There are no lots assigned currenly.",
|
||||||
|
|||||||
@@ -102,7 +102,7 @@
|
|||||||
"oldVersion": "D:\\LST\\lst_backend_2",
|
"oldVersion": "D:\\LST\\lst_backend_2",
|
||||||
"shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]",
|
"shippingHours": "[{\"early\": \"06:30\", \"late\": \"23:00\"}]",
|
||||||
"tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]",
|
"tiPostTime": "[{\"from\": \"24\", \"to\": \"24\"}]",
|
||||||
"otherSettings": [{ "specialInstructions": "" }]
|
"otherSettings": [{ "specialInstructions": "[header]" }]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"sName": "Kansas City",
|
"sName": "Kansas City",
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export let getHeaders = `
|
export let getHeaders = `
|
||||||
select AuftragsNummer as header,
|
select AuftragsNummer as header,
|
||||||
IdAuftragsAbruf as releaseNumber,
|
IdAuftragsAbruf as releaseNumber,
|
||||||
|
AbrufLadeDatum AS LoadingDate,
|
||||||
AbrufLiefertermin as delDate
|
AbrufLiefertermin as delDate
|
||||||
FROM alplaprod_test1.dbo.V_TrackerAuftragsAbrufe (nolock) b
|
FROM alplaprod_test1.dbo.V_TrackerAuftragsAbrufe (nolock) b
|
||||||
|
|
||||||
@@ -19,7 +20,8 @@ on x.IdLieferkondition = c.IdLieferkondition
|
|||||||
on b.IdAdresse = x.addressID
|
on b.IdAdresse = x.addressID
|
||||||
|
|
||||||
WHERE AbrufStatus = 1 and
|
WHERE AbrufStatus = 1 and
|
||||||
AbrufLiefertermin between DATEADD(HOUR, -[from], GETDATE()) and DATEADD(HOUR, [to], GETDATE()) -- this number will be grabbed from the db with a default of 24hours
|
--AbrufLiefertermin between DATEADD(HOUR, -15, GETDATE()) and DATEADD(HOUR, 36, GETDATE()) -- this number will be grabbed from the db with a default of 24hours
|
||||||
|
AbrufLadeDatum between DATEADD(HOUR, -15, GETDATE()) and DATEADD(HOUR, 36, GETDATE()) -- this number will be grabbed from the db with a default of 24hours
|
||||||
and x.Abbreviation not in ('exw')
|
and x.Abbreviation not in ('exw')
|
||||||
and IdAuftragsAbruf not in ([exclude])
|
and IdAuftragsAbruf not in ([exclude])
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -139,7 +139,8 @@ on
|
|||||||
ac.pkgId = pkg.pkgId
|
ac.pkgId = pkg.pkgId
|
||||||
|
|
||||||
WHERE AbrufStatus = 1
|
WHERE AbrufStatus = 1
|
||||||
and AbrufLiefertermin between DATEADD(HOUR, -[from], getdate()) and DATEADD(HOUR, [to], getdate())-- this number will be grabbed from the db with a default of 24hours
|
--and AbrufLiefertermin between DATEADD(HOUR, -[from], getdate()) and DATEADD(HOUR, [to], getdate())-- this number will be grabbed from the db with a default of 24hours
|
||||||
|
and AbrufLadeDatum between DATEADD(HOUR, -[from], getdate()) and DATEADD(HOUR, [to], getdate())-- this number will be grabbed from the db with a default of 24hours
|
||||||
and deliveryContionAbv not in ('EXW')
|
and deliveryContionAbv not in ('EXW')
|
||||||
|
|
||||||
--ORDER BY AbrufLiefertermin)
|
--ORDER BY AbrufLiefertermin)
|
||||||
|
|||||||
Reference in New Issue
Block a user