diff --git a/server/services/logistics/controller/dm/forecast/mappings/loralForecast.ts b/server/services/logistics/controller/dm/forecast/mappings/loralForecast.ts index 683dc65..cff06f7 100644 --- a/server/services/logistics/controller/dm/forecast/mappings/loralForecast.ts +++ b/server/services/logistics/controller/dm/forecast/mappings/loralForecast.ts @@ -7,6 +7,8 @@ import { postForecast } from "../postForecast.js"; import { query } from "../../../../../sqlServer/prodSqlServer.js"; import { activeArticle } from "../../../../../sqlServer/querys/dataMart/article.js"; import { addDays } from "date-fns"; +import { sendEmail } from "../../../../../notifications/controller/sendMail.js"; +import { createLog } from "../../../../../logger/logger.js"; let customerID = 4; export const lorealForecast = async (data: any, user: any) => { @@ -111,6 +113,9 @@ export const lorealForecast = async (data: any, user: any) => { ); if (activeAV.length === 0) { + if (typeof forcast.customerArticleNo === "number") { + missingSku.push(forcast); + } continue; } @@ -181,6 +186,9 @@ export const lorealForecast = async (data: any, user: any) => { ); if (activeAV.length === 0) { + if (typeof forcast.customerArticleNo === "number") { + missingSku.push(forcast); + } continue; } @@ -190,6 +198,56 @@ 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; + + 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; + }, {}) + ); + + const emailSetup = { + email: "Blake.matthes@alpla.com; Stuart.Gladney@alpla.com; Harold.Mccalister@alpla.com; Jenn.Osbourn@alpla.com", + subject: + missedGrouped.length > 0 + ? `Alert! There are ${missedGrouped.length}, missing skus.` + : `Alert! There is a missing SKU.`, + template: "missingLorealSkus", + context: { + items: missedGrouped, + }, + }; + + const { data: sentEmail, error: sendEmailError } = await tryCatch( + sendEmail(emailSetup) + ); + if (sendEmailError) { + createLog( + "error", + "blocking", + "notify", + "Failed to send email, will try again on next interval" + ); + return { + success: false, + message: "Failed to send email, will try again on next interval", + }; + } + // if the customerarticle number is not matching just ignore it const predefinedObject = { receivingPlantId: plantToken[0].value, diff --git a/server/services/notifications/utils/views/missingLorealSkus.hbs b/server/services/notifications/utils/views/missingLorealSkus.hbs new file mode 100644 index 0000000..4dfb4d4 --- /dev/null +++ b/server/services/notifications/utils/views/missingLorealSkus.hbs @@ -0,0 +1,41 @@ + + +
+ + + {{!-- --}} + {{> styles}} + + +All,
+The below SKU's do not currently have an av and will be ignored in the forcast import.
+The date and qty are the first time needed showing from teh vmi report
+| Customer Article Number | +First Date Needed | +Quantity | +
|---|---|---|
| {{customerArticleNo}} | +{{requirementDate}} | +{{quantity}} | +
Thank you,
+LST Team
+