Compare commits

...

6 Commits

7 changed files with 229 additions and 247 deletions

View File

@@ -207,7 +207,7 @@ export default function TransferToNextLot() {
<span>"EOM Transfer"</span> <span>"EOM Transfer"</span>
<Tooltip> <Tooltip>
<TooltipTrigger> <TooltipTrigger>
<Info className="h-[16px] w-[16px]" /> <Info className="h-4 w-4" />
</TooltipTrigger> </TooltipTrigger>
<TooltipContent> <TooltipContent>
<p> <p>
@@ -223,7 +223,7 @@ export default function TransferToNextLot() {
<span>"Lot Transfer"</span> <span>"Lot Transfer"</span>
<Tooltip> <Tooltip>
<TooltipTrigger> <TooltipTrigger>
<Info className="h-[16px] w-[16px]" /> <Info className="h-4 w-4" />
</TooltipTrigger> </TooltipTrigger>
<TooltipContent> <TooltipContent>
<p> <p>

View File

@@ -0,0 +1 @@
export const abbottForecast = async () => {};

View File

@@ -1,95 +1,102 @@
import { addDays } from "date-fns";
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";
import { tryCatch } from "../../../../../../globalUtils/tryCatch.js"; import { tryCatch } from "../../../../../../globalUtils/tryCatch.js";
import XLSX from "xlsx"; import { createLog } from "../../../../../logger/logger.js";
import { postForecast } from "../postForecast.js"; import { sendEmail } from "../../../../../notifications/controller/sendMail.js";
import { query } from "../../../../../sqlServer/prodSqlServer.js"; import { query } from "../../../../../sqlServer/prodSqlServer.js";
import { activeArticle } from "../../../../../sqlServer/querys/dataMart/article.js"; import { activeArticle } from "../../../../../sqlServer/querys/dataMart/article.js";
import { addDays } from "date-fns"; import { excelDateStuff } from "../../../../utils/excelDateStuff.js";
import { sendEmail } from "../../../../../notifications/controller/sendMail.js"; import { postForecast } from "../postForecast.js";
import { createLog } from "../../../../../logger/logger.js";
export const energizerForecast = async (data: any, user: any) => { export const energizerForecast = async (data: any, user: any) => {
/** /**
* Post a standard forecast based on the standard template. * Post a standard forecast based on the standard template.
*/ */
const { data: s, error: e } = await tryCatch(db.select().from(settings)); const { data: s, error: e } = await tryCatch(db.select().from(settings));
if (e) { if (e) {
return { return {
success: false, success: false,
message: `Error getting settings`, message: `Error getting settings`,
data: e, data: e,
}; };
} }
const plantToken = s.filter((s) => s.name === "plantToken"); const plantToken = s.filter((s) => s.name === "plantToken");
const arrayBuffer = await data.arrayBuffer(); const arrayBuffer = await data.arrayBuffer();
const buffer = Buffer.from(arrayBuffer); const buffer = Buffer.from(arrayBuffer);
const workbook = XLSX.read(buffer, { type: "buffer" }); const workbook = XLSX.read(buffer, { type: "buffer" });
const sheet: any = workbook.Sheets["Sheet1"]; const sheet: any = workbook.Sheets["Sheet1"];
const range = XLSX.utils.decode_range(sheet["!ref"]); const range = XLSX.utils.decode_range(sheet["!ref"]);
const headers = [ const headers = [
"CustomerArticleNumber", "CustomerArticleNumber",
"Quantity", "Quantity",
"RequirementDate", "RequirementDate",
"CustomerID", "CustomerID",
]; ];
// formatting the data // formatting the data
const rows = XLSX.utils.sheet_to_json(sheet, { header: 1 }) as any; const rows = XLSX.utils.sheet_to_json(sheet, { header: 1 }) as any;
const posting: any = []; const posting: any = [];
const customerId = 44; const customerId = 44;
for (let i = 1; i < rows.length; i++) { for (let i = 1; i < rows.length; i++) {
const row: any = rows[i]; const row: any = rows[i];
const material = row[0]; const material = row[0];
if (material == undefined) continue; if (material == undefined) continue;
for (let j = 1; j < row.length; j++) { for (let j = 1; j < row.length; j++) {
const qty = row[j]; const qty = row[j];
if (qty && qty !== 0) { if (qty && qty > 0) {
const requirementDate = rows[0][j]; // first row is dates const requirementDate = rows[0][j]; // first row is dates
const date = isNaN(requirementDate)
? new Date(requirementDate)
: excelDateStuff(requirementDate);
posting.push({ console.log(isNaN(requirementDate), requirementDate, date);
customerArticleNo: material, posting.push({
quantity: qty, customerArticleNo: material,
requirementDate: new Date(requirementDate), quantity: qty,
}); requirementDate: date,
} });
} }
} }
}
// the predefined data that will never change //console.log(posting);
const predefinedObject = {
receivingPlantId: plantToken[0].value,
documentName: `ForecastFromLST-${new Date(Date.now()).toLocaleString(
"en-US"
)}`,
sender: user.username || "lst-system",
customerId: customerId,
positions: [],
};
// add the new forecast to the predefined data // the predefined data that will never change
let updatedPredefinedObject = { const predefinedObject = {
...predefinedObject, receivingPlantId: plantToken[0].value,
positions: [...predefinedObject.positions, ...posting], documentName: `ForecastFromLST-${new Date(Date.now()).toLocaleString(
}; "en-US",
)}`,
sender: user.username || "lst-system",
customerId: customerId,
positions: [],
};
//post it // add the new forecast to the predefined data
const forecastData: any = await postForecast(updatedPredefinedObject, user); let updatedPredefinedObject = {
...predefinedObject,
positions: [...predefinedObject.positions, ...posting],
};
return { //post it
success: forecastData.success, const forecastData: any = await postForecast(updatedPredefinedObject, user);
message: forecastData.message,
data: forecastData.data, return {
}; success: forecastData.success,
message: forecastData.message,
data: forecastData.data,
};
}; };

View File

@@ -1,172 +1,172 @@
import XLSX from "xlsx"; import XLSX from "xlsx";
import { tryCatch } from "../../../../../../globalUtils/tryCatch.js";
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";
import { tryCatch } from "../../../../../../globalUtils/tryCatch.js";
import { query } from "../../../../../sqlServer/prodSqlServer.js"; import { query } from "../../../../../sqlServer/prodSqlServer.js";
import { invoiceAddress } from "../../../../../sqlServer/querys/dm/invoiceAddress.js";
import { orderState } from "../../../../../sqlServer/querys/dm/orderState.js"; import { orderState } from "../../../../../sqlServer/querys/dm/orderState.js";
import { excelDateStuff } from "../../../../utils/excelDateStuff.js"; import { excelDateStuff } from "../../../../utils/excelDateStuff.js";
import { invoiceAddress } from "../../../../../sqlServer/querys/dm/invoiceAddress.js";
import { postOrders } from "../postOrders.js"; import { postOrders } from "../postOrders.js";
export const energizerOrders = async (data: any, user: any) => { export const energizerOrders = async (data: any, user: any) => {
/** /**
* Standard orders meaning that we get the standard file exported and fill it out and uplaod to lst. * Standard orders meaning that we get the standard file exported and fill it out and uplaod to lst.
*/ */
const { data: s, error: e } = await tryCatch(db.select().from(settings)); const { data: s, error: e } = await tryCatch(db.select().from(settings));
if (e) { if (e) {
return { return {
sucess: false, sucess: false,
message: `Error getting settings`, message: `Error getting settings`,
data: e, data: e,
}; };
} }
// order state // order state
const { data: o, error: oe } = await tryCatch( const { data: o, error: oe } = await tryCatch(
query(orderState, "Gets the next 500 orders that have not been started") query(orderState, "Gets the next 500 orders that have not been started"),
); );
const openOrders: any = o?.data; const openOrders: any = o?.data;
if (oe) { if (oe) {
return { return {
sucess: false, sucess: false,
message: `Error getting article data`, message: `Error getting article data`,
data: oe, data: oe,
}; };
} }
// order state // order state
const { data: invoice, error: ie } = await tryCatch( const { data: invoice, error: ie } = await tryCatch(
query(invoiceAddress, "Gets invoices addresses") query(invoiceAddress, "Gets invoices addresses"),
); );
const i: any = invoice?.data; const i: any = invoice?.data;
if (ie) { if (ie) {
return { return {
sucess: false, sucess: false,
message: `Error getting invoice address data`, message: `Error getting invoice address data`,
data: ie, data: ie,
}; };
} }
const plantToken = s.filter((s) => s.name === "plantToken"); const plantToken = s.filter((s) => s.name === "plantToken");
const arrayBuffer = await data.arrayBuffer(); const arrayBuffer = await data.arrayBuffer();
const buffer = Buffer.from(arrayBuffer); const buffer = Buffer.from(arrayBuffer);
const workbook = XLSX.read(buffer, { type: "buffer" }); const workbook = XLSX.read(buffer, { type: "buffer" });
const sheetName = workbook.SheetNames[0]; const sheetName = workbook.SheetNames[0];
const sheet = workbook.Sheets[sheetName]; const sheet = workbook.Sheets[sheetName];
// define custom headers // define custom headers
const headers = [ const headers = [
"ITEM", "ITEM",
"PO", "PO",
"ReleaseNo", "ReleaseNo",
"QTY", "QTY",
"DELDATE", "DELDATE",
"COMMENTS", "COMMENTS",
"What changed", "What changed",
"CUSTOMERID", "CUSTOMERID",
"Remark", "Remark",
]; ];
const orderData = XLSX.utils.sheet_to_json(sheet, { const orderData = XLSX.utils.sheet_to_json(sheet, {
defval: "", defval: "",
header: headers, header: headers,
range: 1, range: 1,
}); });
// the base of the import // the base of the import
const predefinedObject = { const predefinedObject = {
receivingPlantId: plantToken[0].value, receivingPlantId: plantToken[0].value,
documentName: `OrdersFromLST-${new Date(Date.now()).toLocaleString( documentName: `OrdersFromLST-${new Date(Date.now()).toLocaleString(
"en-US" "en-US",
)}`, )}`,
sender: user.username || "lst-system", sender: user.username || "lst-system",
externalRefNo: `OrdersFromLST-${new Date(Date.now()).toLocaleString( externalRefNo: `OrdersFromLST-${new Date(Date.now()).toLocaleString(
"en-US" "en-US",
)}`, )}`,
orders: [], orders: [],
}; };
let newOrders: any = orderData; let newOrders: any = orderData;
// filter out the orders that have already been started just to reduce the risk of errors. // filter out the orders that have already been started just to reduce the risk of errors.
newOrders.filter((oo: any) => newOrders.filter((oo: any) =>
openOrders.some( openOrders.some(
(o: any) => o.CustomerOrderNumber === oo.CustomerOrderNumber (o: any) => o.CustomerOrderNumber === oo.CustomerOrderNumber,
) ),
); );
// filter out the blanks // filter out the blanks
newOrders = newOrders.filter((z: any) => z.ITEM !== ""); newOrders = newOrders.filter((z: any) => z.ITEM !== "");
// let postedOrders: any = []; // let postedOrders: any = [];
// for (const [customerID, orders] of Object.entries(orderData)) { // for (const [customerID, orders] of Object.entries(orderData)) {
// // console.log(`Running for Customer ID: ${customerID}`); // // console.log(`Running for Customer ID: ${customerID}`);
// const newOrders: any = orderData; // const newOrders: any = orderData;
// // filter out the orders that have already been started just to reduce the risk of errors. // // filter out the orders that have already been started just to reduce the risk of errors.
// newOrders.filter((oo: any) => // newOrders.filter((oo: any) =>
// openOrders.some( // openOrders.some(
// (o: any) => o.CustomerOrderNumber === oo.CustomerOrderNumber // (o: any) => o.CustomerOrderNumber === oo.CustomerOrderNumber
// ) // )
// ); // );
// // map everything out for each order // // map everything out for each order
const nOrder = newOrders.map((o: any) => { const nOrder = newOrders.map((o: any) => {
const invoice = i.filter( const invoice = i.filter(
(i: any) => i.deliveryAddress === parseInt(o.CUSTOMERID) (i: any) => i.deliveryAddress === parseInt(o.CUSTOMERID),
); );
if (!invoice) { if (!invoice) {
return; return;
} }
return { return {
customerId: parseInt(o.CUSTOMERID), customerId: parseInt(o.CUSTOMERID),
invoiceAddressId: invoice[0].invoiceAddress, // matched to the default invoice address invoiceAddressId: invoice[0].invoiceAddress, // matched to the default invoice address
customerOrderNo: o.PO, customerOrderNo: o.PO,
orderDate: new Date(Date.now()).toLocaleString("en-US"), orderDate: new Date(Date.now()).toLocaleString("en-US"),
positions: [ positions: [
{ {
deliveryAddressId: parseInt(o.CUSTOMERID), deliveryAddressId: parseInt(o.CUSTOMERID),
customerArticleNo: o.ITEM, customerArticleNo: o.ITEM,
quantity: parseInt(o.QTY), quantity: parseInt(o.QTY),
deliveryDate: o.DELDATE, //excelDateStuff(o.DELDATE), deliveryDate: o.DELDATE, //excelDateStuff(o.DELDATE),
customerLineItemNo: o.ReleaseNo, // this is how it is currently sent over from abbott customerLineItemNo: o.ReleaseNo, // this is how it is currently sent over from abbott
customerReleaseNo: o.ReleaseNo, // same as above customerReleaseNo: o.ReleaseNo, // same as above
remark: o.remark === "" ? null : o.remark, remark: o.COMMENTS === "" ? null : o.COMMENTS,
}, },
], ],
}; };
}); });
// // do that fun combining thing // // do that fun combining thing
const updatedPredefinedObject = { const updatedPredefinedObject = {
...predefinedObject, ...predefinedObject,
orders: [...predefinedObject.orders, ...nOrder], orders: [...predefinedObject.orders, ...nOrder],
}; };
// //console.log(updatedPredefinedObject); // //console.log(updatedPredefinedObject);
// // post the orders to the server // // post the orders to the server
const posting: any = await postOrders(updatedPredefinedObject, user); const posting: any = await postOrders(updatedPredefinedObject, user);
return { return {
customer: nOrder[0].CUSTOMERID, customer: nOrder[0].CUSTOMERID,
//totalOrders: orders?.length(), //totalOrders: orders?.length(),
success: posting.success, success: posting.success,
message: posting.message, message: posting.message,
data: posting.data, data: posting.data,
}; };
// } // }
// return { // return {
// success: true, // success: true,
// message: // message:
// "Standard Template was just processed successfully, please check AlplaProd 2.0 to confirm no errors. ", // "Standard Template was just processed successfully, please check AlplaProd 2.0 to confirm no errors. ",
// data: nOrder, // data: nOrder,
// }; // };
}; };

View File

@@ -47,7 +47,7 @@ export const printerDelayByLot = async (lot: any) => {
}) })
.where( .where(
and( and(
eq(printerData.humanReadableId, lot[i].printerID), eq(printerData.humanReadableId, lot[i]?.printerID),
eq(printerData.printDelayOverride, false), eq(printerData.printDelayOverride, false),
), ),
), ),

View File

@@ -46,9 +46,17 @@ app.openapi(
return c.json({ success: false, message: "missing data" }, 400); return c.json({ success: false, message: "missing data" }, 400);
} }
//console.log(`Tag: ${Buffer.from(body.idHex, "hex").toString("utf-8")}, ${body[key].data.idHex}`); //console.log(`Tag: ${Buffer.from(body.idHex, "hex").toString("utf-8")}, ${body[key].data.idHex}`);
createLog(
"info",
"rfid-tag",
"rfid",
`Tag Data from ${reader}: ${JSON.stringify(body)}`,
);
for (let i = 0; i < body.length; i++) { for (let i = 0; i < body.length; i++) {
const tag = Buffer.from(body[i].data.idHex, "hex").toString("utf-8"); const tag = Buffer.from(body[i].data.idHex, "hex")
.toString("utf-8")
.replace("\x00\x00", "");
// console.log( // console.log(
// "Raw value:", // "Raw value:",
// body[i].data.peakRssi, // body[i].data.peakRssi,

View File

@@ -1,34 +0,0 @@
export const planningNumbersByAVDate = `
use AlplaPROD_test1
declare @start_date nvarchar(30) = '[startDate]' --'2025-01-01'
declare @end_date nvarchar(30) = '[endDate]' --'2025-08-09'
/*
articles will need to be passed over as well as the date structure we want to see
*/
select x.IdArtikelvarianten As Article,
ProduktionAlias as Description,
standort as MachineId,
MaschinenBezeichnung as MachineName,
--MaschZyklus as PlanningCycleTime,
x.IdProdPlanung as LotNumber,
FORMAT(ProdTag, 'MM/dd/yyyy') as ProductionDay,
x.planMenge as TotalPlanned,
ProduktionMenge as QTYPerDay,
round(ProduktionMengeVPK, 2) PalDay,
Status as finished
--MaschStdAuslastung as nee
from dbo.V_ProdLosProduktionJeProdTag_PLANNING (nolock) as x
left join
dbo.V_ProdPlanung (nolock) as p on
x.IdProdPlanung = p.IdProdPlanung
where ProdTag between @start_date and @end_date
and p.IdArtikelvarianten in ([articles])
--and V_ProdLosProduktionJeProdTag_PLANNING.IdKunde = 10
--and IdProdPlanung = 18442
order by ProdTag desc
`;