3 Commits

Author SHA1 Message Date
2ebf695526 fix(builds): fixed non used variables
All checks were successful
Build and Push LST Docker Image / docker (push) Successful in 1m32s
2026-06-15 17:16:29 -05:00
24af3ca403 fix(datamart): somereason it stopped working.. and added download types
there was a weird issue with the req.query that cause nothing to pull and make the excel files
lag..... now excel macros are using the csv pull from here and added in the xlsx to download to bc
why not makes it easier for later  and can have bbuttons for every thing in lst too :D
2026-06-15 17:16:00 -05:00
6fbe3a9eed chore(format): formatting changes 2026-06-15 17:14:05 -05:00
6 changed files with 87 additions and 103 deletions

View File

@@ -37,6 +37,7 @@ const lstDbRun = async (data: Data) => {
if (data.options) {
if (data.name === "psiInventory") {
const ids = data.options.articles.split(",").map((id: any) => id.trim());
const whse = data.options.whseToInclude
? data.options.whseToInclude
.split(",")

View File

@@ -1,4 +1,5 @@
import { Router } from "express";
import * as XLSX from "xlsx";
import { apiReturn } from "../utils/returnHelper.utils.js";
import { runDatamartQuery } from "./datamart.controller.js";
@@ -7,13 +8,73 @@ const r = Router();
type Options = {
name: string;
value: string;
format: string;
};
r.get("/:name", async (req, res) => {
const { name } = req.params;
const options = req.query as Options;
const options = { ...req.query } as Options;
const dataRan = await runDatamartQuery({ name, options });
if (!dataRan.success) {
return apiReturn(res, {
success: false,
level: "error",
module: "datamart",
subModule: "query",
message: dataRan.message,
status: 500,
});
}
// XLSX Export
if (options.format?.toLowerCase() === "xlsx") {
const wb = XLSX.utils.book_new();
const ws = XLSX.utils.json_to_sheet(dataRan.data);
XLSX.utils.book_append_sheet(wb, ws, name);
const buffer = XLSX.write(wb, {
type: "buffer",
bookType: "xlsx",
});
res.setHeader(
"Content-Type",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
);
res.setHeader("Content-Disposition", `attachment; filename="${name}.xlsx"`);
return res.send(buffer);
}
// CSV Export
if (options.format?.toLowerCase() === "csv") {
const rows = dataRan.data as any;
if (!rows.length) {
return res.status(200).send("");
}
const headers = Object.keys(rows[0]);
const csv = [
headers.join(","),
...rows.map((row: any) =>
headers
.map((h) => `"${String(row[h] ?? "").replace(/"/g, '""')}"`)
.join(","),
),
].join("\r\n");
res.setHeader("Content-Type", "text/csv");
res.setHeader("Content-Disposition", `attachment; filename="${name}.csv"`);
return res.send(csv);
}
return apiReturn(res, {
success: dataRan.success,
level: "info",

View File

@@ -6,7 +6,7 @@ import {
sqlQuerySelector,
} from "../prodSql/prodSqlQuerySelector.utils.js";
import { returnFunc } from "../utils/returnHelper.utils.js";
import { sendEmail } from "../utils/sendEmail.utils.js";
//import { sendEmail } from "../utils/sendEmail.utils.js";
import { tryCatch } from "../utils/trycatch.utils.js";
import { postData } from "./logistics.dm.postData.js";
@@ -83,7 +83,7 @@ export const lorealForecast = async (data: any, user: any) => {
const article: any = a?.data;
console.log(article);
//console.log(article);
// process the ebm forcast
for (let i = 0; i < ebmForeCastData.length; i++) {
@@ -127,31 +127,6 @@ export const lorealForecast = async (data: any, user: any) => {
//console.log(ebmForeCastData.length);
}
// petForeCastData.forEach((item: any, index: any) => {
// //console.log(`Processing item ${index + 1} of ${forecastData.length}`);
// // Extract the customer code
// const customerCode = item["SOUTH PET BOTTLES"];
// // Process each date in the current object
// for (const [date, qty] of Object.entries(item)) {
// // Skip metadata fields
// if (petMetadataFields.includes(date)) continue;
// if (qty === 0) continue;
// // Create your transformed record
// const record = {
// customerArticleNo: customerCode,
// requirementDate: excelDateStuff(parseInt(date)),
// quantity: qty,
// };
// // Do something with this record
// petForecastData.push(record);
// }
// });
// pet forecast
for (let i = 0; i < petForeCastData.length; i++) {
// bottle code
@@ -200,25 +175,25 @@ export const lorealForecast = async (data: any, user: any) => {
//console.log(comForecast);
// email the for the missing ones
const missedGrouped = Object.values(
missingSku.reduce((acc: any, item: any) => {
const key = item.customerArticleNo;
// const missedGrouped = Object.values(
// missingSku.reduce((acc: any, item: any) => {
// const key = item.customerArticleNo;
if (!acc[key]) {
// first time we see this customer
acc[key] = item;
} else {
// compare dates and keep the earliest
if (
new Date(item.requirementDate) < new Date(acc[key].requirementDate)
) {
acc[key] = item;
}
}
// if (!acc[key]) {
// // first time we see this customer
// acc[key] = item;
// } else {
// // compare dates and keep the earliest
// if (
// new Date(item.requirementDate) < new Date(acc[key].requirementDate)
// ) {
// acc[key] = item;
// }
// }
return acc;
}, {}),
);
// return acc;
// }, {}),
// );
// TODO: change this to a flagged notification so that he users can subscribe or leave it. this removes the hardcody shit.
// const emailSetup = {
@@ -248,19 +223,7 @@ export const lorealForecast = async (data: any, user: any) => {
const updatedPredefinedObject = {
...predefinedObject,
positions: [
...predefinedObject.positions,
...ebmForecastData,
// ...ebmForecastData.filter(
// (q: any) =>
// q.customerArticleNo != "" && q.customerArticleNo != "Total"
// ),
// ...petForecastData.filter(
// (q: any) =>
// q.customerArticleNo != "" && q.customerArticleNo != "Total"
// ),
],
positions: [...predefinedObject.positions, ...ebmForecastData],
};
// console.log(updatedPredefinedObject);

View File

@@ -113,8 +113,8 @@ export const pNgForecast = async (data: any, user: any) => {
// }
return {
customerArticleNo: parseInt(o["Customer Item No."]),
requirementDate: excelDateStuff(parseInt(o["Request Date"])),
customerArticleNo: parseInt(o["Customer Item No."] ?? "0", 10),
requirementDate: excelDateStuff(parseInt(o["Request Date"] ?? "0", 10)),
quantity: o["Remaining Qty to be Shipped"],
};
});

View File

@@ -19,13 +19,13 @@ import { setupUtilsRoutes } from "./utils/utils.routes.js";
export const setupRoutes = (baseUrl: string, app: Express) => {
//routes that are on by default
setupDatamartRoutes(baseUrl, app);
setupMobileRoutes(baseUrl, app);
setupSystemRoutes(baseUrl, app);
setupAdminRoutes(baseUrl, app);
setupApiDocsRoutes(baseUrl, app);
setupProdSqlRoutes(baseUrl, app);
setupGPSqlRoutes(baseUrl, app);
setupDatamartRoutes(baseUrl, app);
setupAuthRoutes(baseUrl, app);
setupUtilsRoutes(baseUrl, app);
setupOpendockRoutes(baseUrl, app);

View File

@@ -1,41 +0,0 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "nodenext",
"strict": true,
"verbatimModuleSyntax": true,
"types": ["node", "better-auth"],
"jsx": "react-jsx",
"outDir": "./dist",
"removeComments": true,
"allowJs": false,
"rootDir": "./backend",
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"exactOptionalPropertyTypes": true,
"baseUrl": ".",
"paths": {
"@/*": ["backend/*"],
"@features/*": ["backend/features/*"],
"@shared/*": ["backend/shared/*"],
"@config/*": ["backend/config/*"]
},
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
//"allowImportingTsExtensions": true,
"noEmit": false
},
"include": ["backend/**/*"],
"exclude": [
"node_modules",
"frontend",
"dist",
"lstDocs",
"database/testFiles",
"scripts"
]}