fix(dm): energizer forecast to correct the date and qty push over
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
|
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) => {
|
||||||
/**
|
/**
|
||||||
@@ -55,23 +56,29 @@ export const energizerForecast = async (data: any, user: any) => {
|
|||||||
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);
|
||||||
|
|
||||||
|
console.log(isNaN(requirementDate), requirementDate, date);
|
||||||
posting.push({
|
posting.push({
|
||||||
customerArticleNo: material,
|
customerArticleNo: material,
|
||||||
quantity: qty,
|
quantity: qty,
|
||||||
requirementDate: new Date(requirementDate),
|
requirementDate: date,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//console.log(posting);
|
||||||
|
|
||||||
// the predefined data that will never change
|
// the predefined data that will never change
|
||||||
const predefinedObject = {
|
const predefinedObject = {
|
||||||
receivingPlantId: plantToken[0].value,
|
receivingPlantId: plantToken[0].value,
|
||||||
documentName: `ForecastFromLST-${new Date(Date.now()).toLocaleString(
|
documentName: `ForecastFromLST-${new Date(Date.now()).toLocaleString(
|
||||||
"en-US"
|
"en-US",
|
||||||
)}`,
|
)}`,
|
||||||
sender: user.username || "lst-system",
|
sender: user.username || "lst-system",
|
||||||
customerId: customerId,
|
customerId: customerId,
|
||||||
|
|||||||
Reference in New Issue
Block a user