diff --git a/lstV2/server/services/notifications/controller/notifications/platToPlantEdi.ts b/lstV2/server/services/notifications/controller/notifications/platToPlantEdi.ts index c34fda1..9d684dc 100644 --- a/lstV2/server/services/notifications/controller/notifications/platToPlantEdi.ts +++ b/lstV2/server/services/notifications/controller/notifications/platToPlantEdi.ts @@ -7,15 +7,27 @@ import { query } from "../../../sqlServer/prodSqlServer.js"; import { sqlQuerySelector } from "../../../sqlServer/utils/querySelector.utils.js"; import { sendEmail } from "../sendMail.js"; +let running = false; export default async function platToPlantEdi(notifyData: any) { - createLog("info", "blocking", "notify", `monitoring ${notifyData.name}`); + createLog("info", "plantToPlant", "notify", `monitoring ${notifyData.name}`); + if (running) { + createLog( + "info", + "plantToPlant", + "notify", + `Notifcation ${notifyData.name} is already running skipping`, + ); + return; + } - const { data: noti, error: notiError } = await tryCatch( + running = true; + + const { data: noti, error: notiError } = (await tryCatch( db .select() .from(notifications) .where(eq(notifications.name, notifyData.name)), - ); + )) as any; if (notiError) { createLog( @@ -27,7 +39,7 @@ export default async function platToPlantEdi(notifyData: any) { } // get the default emails they can be blank if as we will only add these to the end of the email from the full flow - let emails = notifyData.email ?? ""; + let emails = noti[0]?.email ?? ""; const checkBol = sqlQuerySelector("checkBol.query"); @@ -41,14 +53,21 @@ export default async function platToPlantEdi(notifyData: any) { createLog("error", "edi", "notify", "Error in getting the bol query data"); } - let ignoreBols: string[] = notifyData?.notifiySettings?.processedBol ?? []; + let ignoreBols: string[] = noti[0]?.notifiySettings?.processedBol ?? []; const joinBols = ignoreBols.join(","); + let updateQuery = noti[0]?.notifiySettings?.includeAll + ? checkBol?.query?.replace( + "and a.bezeichnung like '%Alpla%'", + "--and a.bezeichnung like '%Alpla%'", + ) + : checkBol?.query; + const { data: b, error: bError } = (await tryCatch( query( - checkBol?.query - ?.replace("[timeCheck]", notifyData.checkInterval ?? "30") + updateQuery + ?.replace("[timeCheck]", noti[0]?.checkInterval ?? "30") .replace("[ignoreBols]", joinBols ?? 500) ?? "", "Check bol", ), @@ -99,7 +118,6 @@ export default async function platToPlantEdi(notifyData: any) { // console.log("Address: ", b.data[0].addressId ?? "0"); - // if theres no email then just stop. if (b.data[0].addressId === "") return; ignoreBols.push(bolNumber); @@ -120,9 +138,10 @@ export default async function platToPlantEdi(notifyData: any) { ), )) as any; + if (noti[0]?.emails === "") return; // no default emails // setup the email to be sent :D const emailSetup = { - email: address.data[0].email, + email: `${noti[0]?.emails};${address.data[0].email ?? ""}`, subject: `New EDI transfer Created for BOL: ${bolNumber}`, template: "plantToPlantEdi", context: { @@ -140,18 +159,22 @@ export default async function platToPlantEdi(notifyData: any) { .update(notifications) .set({ lastRan: sql`NOW()`, - notifiySettings: { processedBol: ignoreBols }, + notifiySettings: { + ...noti[0]?.notifiySettings, + processedBol: ignoreBols, + }, }) .where(eq(notifications.name, notifyData.name)); } + running = false; return { success: true, message: "All bols have been processed", data: [ignoreBols], }; } - + running = false; return { success: true, message: "No new bols have been created", diff --git a/lstV2/server/services/notifications/utils/masterNotifications.ts b/lstV2/server/services/notifications/utils/masterNotifications.ts index c304934..d709da6 100644 --- a/lstV2/server/services/notifications/utils/masterNotifications.ts +++ b/lstV2/server/services/notifications/utils/masterNotifications.ts @@ -170,9 +170,9 @@ export const note: any = [ "This is the plant to plant edi that will send an edi to the email once it ships, the emails will be for the receiving plants", checkInterval: 15, timeType: "min", - emails: "", + emails: "blake.matthes@alpla.com;Maritza.Hernandez@alpla.com", active: false, - notifiySettings: { processedBol: [500] }, + notifiySettings: { processedBol: [500], includeAll: false }, }, ]; diff --git a/lstV2/server/services/notifications/utils/notificationSqlCleanup.ts b/lstV2/server/services/notifications/utils/notificationSqlCleanup.ts index 0f2e98e..b77691f 100644 --- a/lstV2/server/services/notifications/utils/notificationSqlCleanup.ts +++ b/lstV2/server/services/notifications/utils/notificationSqlCleanup.ts @@ -58,6 +58,7 @@ const jobNames: string[] = [ "invenotry check", // spelling error one of my stupids "monitor_hold_monitor", "Monitor_Silo_adjustments", + "monitor_qualityLocMonitor", // validating with lima this is still needed ]; export const sqlJobCleanUp = async () => { diff --git a/lstV2/server/services/notifications/utils/views/plantToPlantEdi.hbs b/lstV2/server/services/notifications/utils/views/plantToPlantEdi.hbs index 4823f1d..6f5f206 100644 --- a/lstV2/server/services/notifications/utils/views/plantToPlantEdi.hbs +++ b/lstV2/server/services/notifications/utils/views/plantToPlantEdi.hbs @@ -9,9 +9,9 @@

All,

BOL: {{bol}} was created with the below pallets.

-

Please head to stock and import the pallets via the normal incoming goods process.

+

Please head to stock and import the pallets via the normal incoming goods process (now/immediately).

When encountering a discrepancy in pallets/cages received, please correct this after the pallets have been imported.

-

This due to these being plant to plant the only way to correct this is bring them in then undo the incoming goods process.

+

Due to these being plant to plant shipments, the only way to correct this is to bring them in then undo the incoming goods process.



diff --git a/lstV2/server/services/sqlServer/querys/newQueries/addressInfo.query.sql b/lstV2/server/services/sqlServer/querys/newQueries/addressInfo.query.sql index e272f58..2fabc97 100644 --- a/lstV2/server/services/sqlServer/querys/newQueries/addressInfo.query.sql +++ b/lstV2/server/services/sqlServer/querys/newQueries/addressInfo.query.sql @@ -1,4 +1,4 @@ -use [test3_AlplaPROD2.0_Read] +use [test1_AlplaPROD2.0_Read] select humanreadableId as addressId diff --git a/lstV2/server/services/sqlServer/querys/newQueries/checkBol.query.sql b/lstV2/server/services/sqlServer/querys/newQueries/checkBol.query.sql index e298d47..b43dfd4 100644 --- a/lstV2/server/services/sqlServer/querys/newQueries/checkBol.query.sql +++ b/lstV2/server/services/sqlServer/querys/newQueries/checkBol.query.sql @@ -36,8 +36,8 @@ x.idjournal = e.idjournal where idjournalStatus = 62 --and idadressen = 270 - --and a.bezeichnung like '%Alpla%' -- we only want to monitor for addresses that are linked to alpla. + and a.bezeichnung like '%Alpla%' -- we only want to monitor for addresses that are linked to alpla. and JournalDatum > DATEADD(MINUTE, -[timeCheck], GETDATE()) - and e.idjournal not in ([ignoreBols]) + and e.journalNummer not in ([ignoreBols]) and idauftrag > 1 -- this will ignore all incoming goodsv as we are really only looking for outbound deliveries order by JournalDatum desc \ No newline at end of file diff --git a/lstV2/server/services/sqlServer/querys/newQueries/palletsLinkedToBol.query.sql b/lstV2/server/services/sqlServer/querys/newQueries/palletsLinkedToBol.query.sql index 3a23db3..c8ee7b6 100644 --- a/lstV2/server/services/sqlServer/querys/newQueries/palletsLinkedToBol.query.sql +++ b/lstV2/server/services/sqlServer/querys/newQueries/palletsLinkedToBol.query.sql @@ -17,7 +17,7 @@ use AlplaPROD_test1 ,av.articlehumanreadableid as article ,av.ArticleDescription as alias --,[SSCC_ReserveZiffer] - ,ROW_NUMBER() OVER (PARTITION BY p.[LfdNrJeArtikelKunde] ORDER BY p.upd_date DESC) AS RowNum + --,ROW_NUMBER() OVER (PARTITION BY p.[LfdNrJeArtikelKunde] ORDER BY p.upd_date DESC) AS RowNum --,* FROM [dbo].[T_EAIJournalLieferPosition] as p (nolock) @@ -27,10 +27,11 @@ use AlplaPROD_test1 -- l.IdProdPlanung = p.Beleg left join -[test3_AlplaPROD2.0_Read].labelling.InternalLabel as av on +[test1_AlplaPROD2.0_Read].labelling.InternalLabel as av on av.RunningNumber = p.[LfdNrJeArtikelKunde] ) as a -where idladeplanung in ([palLinkedToBol]) and RowNum = 1 +where idladeplanung in ([palLinkedToBol]) +--and RowNum = 1 order by runningNr