feat(lstv2 move): moved lstv2 into this app to keep them combined and easier to maintain

This commit is contained in:
2025-09-19 22:22:05 -05:00
parent caf2315191
commit e4477402ad
847 changed files with 165801 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
export const blockQuery = `
SELECT TOP(1)
'Alert! new blocking order: #' + cast(HumanReadableId as varchar) + ' - ' + ArticleVariantDescription as subject,
cast([HumanReadableId] as varchar) as blockingNumber,
[ArticleVariantDescription] as article,
cast([CustomerHumanReadableId] as varchar) + ' - ' + [CustomerDescription] as customer,
convert(varchar(10), [test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockingOrder].[BlockingDate], 101) + ' - ' + convert(varchar(5), [test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockingOrder].[BlockingDate], 108) as blockingDate,
cast(ArticleVariantHumanReadableId as varchar) + ' - ' + ArticleVariantDescription as av,
case when [test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockingOrder].Remark = '' or [test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockingOrder].Remark is NULL then 'Please reach out to quality for the reason this was placed on hold as a remark was not entered during the blocking processs' else [test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockingOrder].Remark end as remark,
cast(FORMAT(TotalAmountOfPieces, '###,###') as varchar) + ' / ' + cast(LoadingUnit as varchar) as peicesAndLoadingUnits,
[test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockingOrder].ProductionLotHumanReadableId as lotNumber,
cast(IdGlobalBlockingDefectsGroup as varchar) + ' - ' + BD.Description as mainDefectGroup,
cast(IdGlobalBlockingDefect as varchar) + ' - ' + MD.Description as mainDefect,
sent=0,
lot.MachineLocation as line,
HumanReadableId
FROM [test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockingOrder] (nolock)
/*** Join 1.0 table to get correct id info to link ***/
join
[AlplaPROD_test1].[dbo].[T_BlockingOrders] (nolock) AS BO
on [HumanReadableId] = BO.[IdBlockingOrder]
/*** Get the main defect info ***/
Inner join
[AlplaPROD_test1].[dbo].[T_BlockingDefectsGroups] (nolock) as BD
ON BO.IdMainDefectGroup = BD.IdBlockingDefectsGroup
INNER join
[AlplaPROD_test1].[dbo].[T_BlockingDefects] as MD
ON BO.IdMainDefect = MD.IdBlockingDefect
/*** get lot info ***/
left join
(SELECT [MachineLocation]
,[MachineDescription]
,[ProductionLotHumanReadableId]
FROM [test1_AlplaPROD2.0_Reporting].[reporting_productionControlling].[ProducedLot]) as lot
on [test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockingOrder].ProductionLotHumanReadableId = lot.ProductionLotHumanReadableId
where [test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockingOrder].[BlockingDate] between getdate() - 1 and getdate() + 1
and [test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockingOrder].BlockingTrigger = 1
--and HumanReadableId NOT IN ([sentBlockingOrders])
and HumanReadableId > [lastBlocking]
`;

View File

@@ -0,0 +1,9 @@
export const bow2incoming = `
select LKWNummer as truckNumber
,LKWBezeichnung as carrier
,Add_Date
from [AlplaPROD_test1].[dbo].[V_WareneingangAuftraege]
where Add_Date > DATEADD(MINUTE, -[time], getdate())
`;

View File

@@ -0,0 +1,45 @@
export const downTimeCheck = `
SELECT
[IdHistoryStillstandsereignis] as downTimeId
,DATEDIFF(MINUTE,b.[Startzeit], case when b.[Endzeit] = '1900-01-01' then getdate() else b.[Endzeit] end ) as totalDuration
--, b.[IdMaschine]
,x.[Bezeichnung] as machineAlias
--,b.[IdStillstandsGrund],
, c.CTO_Code
,c.Downtime_Description
--,b.[IdFehlermerkmal],
,case when g.DT_Group_Desc is null then 'Not assigned yet' else g.DT_Group_Desc end as groupDesc
,b.[Bemerkung] as remark
,CONVERT(VARCHAR, CAST(b.[Startzeit] AS DATETIME), 100) dtStart
,CONVERT(VARCHAR, CAST(b.[Endzeit] AS DATETIME), 100) dtEnd
,b.Upd_Date
FROM Alplaprod_test1.[dbo].[T_HistoryStillstandsereignis] (nolock)b
--get the machine info
left join
Alplaprod_test1.[dbo].[T_Maschine] (nolock)x
on b.IdMaschine = x.IdMaschine
-- add in the cto codes
left join
Alplaprod_test1.[dbo].[V_MES_Downtime_Reasons] (nolock)c
on b.IdStillstandsGrund = c.Local_Downtime_ID
left join
Alplaprod_test1.[dbo].[V_MES_Downtime_Characteristics] (nolock)g
on b.IdFehlermerkmal = g.Local_DT_Characteristic_Id
where DATEDIFF(MINUTE,b.[Startzeit],case when b.[Endzeit] = '1900-01-01' then getdate() else b.[Endzeit] end) > [dtDuration]
and b.[Startzeit] > DATEADD(day, -[daysInPast], getDate())
and b.[Endzeit] = '1900-01-01'
--adding this date check in so we dont get everything possible
and c.CTO_Code not like 'a%'
and c.CTO_Code not like 'b%'
and c.CTO_Code not like 'c%'
and c.CTO_Code not like 'd%'
and c.CTO_Code not like 'e%'
and c.CTO_Code not like 'f%'
and c.CTO_Code not like 'y%'
order by IdHistoryStillstandsereignis desc
`;

View File

@@ -0,0 +1,10 @@
export const currentInv = `
SELECT Produktionslos as lot
,Lfdnr as runningNr
,IdArtikelVarianten as av
,Barcode
,ProduktionsDatumMin as prodDate
FROM [AlplaPROD_test1].[dbo].V_LagerPositionenBarcodes t
where GesperrtAktivSum = 0 and t.IdArtikelTyp in (1)
order by ProduktionsDatumMin
`;

View File

@@ -0,0 +1,32 @@
export const shippedPallets = `
SELECT
--[IdJournalLieferPosition]
--,[IdJournalPosition]
--,[IdLadePlanung]
[Beleg] as lot
,[LfdNrJeArtikelKunde] as runningNr
,l.IdArtikelvarianten as av
,x.[Barcode]
,[ProduktionsDatum] as prodDate
--,x.[Add_User]
--,x.[Add_Date]
--,x.[Upd_User]
--,x.[Upd_Date]
--,[IdJournalWarenPosition]
--,[LieferMenge]
--,x.[SSCC_ReserveZiffer]
--,[EAN_BasisNr]
--,[Guid]
--,[LieferEinheit]
--,x.[Bestrahlungsnummer]
FROM [AlplaPROD_test1].[dbo].[T_EAIJournalLieferPosition] x
--where Barcode = '1000000000000000000000000000000001144380'
left join
[AlplaPROD_test1].[dbo].[T_EtikettenGedruckt] l on
x.LfdNrJeArtikelKunde = l.LfdNr
where x.Add_Date between dateadd(hour, -1, getDate()) and getDate() -- this is looking only in the last hour
order by [ProduktionsDatum]
`;

View File

@@ -0,0 +1,17 @@
export const palletsRemovedAswaste = `
select * from (select IdArtikelVarianten as av
,ArtikelVariantenAlias as alias
,Lfdnr as runningnumber
,case when GesperrtAktivSum = 1 then 'Blocked' else 'Released' end as palletStatus
,BewegungsDatumMax as lastMovingDate
--,*
from AlplaPROD_test1.dbo.V_LagerPositionenBarcodes (nolock) )x
where runningnumber in (
SELECT
[HumanReadableId]
FROM [test1_AlplaPROD2.0_Reporting].[reporting_blocking].[BlockedItem] (nolock)
where state = 4
) and palletStatus = 'Released'
`;

View File

@@ -0,0 +1,31 @@
export const shortageBookings = `
use AlplaPROD_test1
Declare @range int = [time] -- change this to be range in minutues you want to monitor, this shouldnt be more than the interval check so we do not see duplicates
declare @avType nvarchar(3) = '[type]' --change to blank or single to have specific ones if all the type is ignored
declare @avTypeID NVARCHAR(MAX) = '[avType]' -- this can only be 1 article now.
select
IdArtikelVarianten as materialAV
,IdArtikelTyp
,ArtikelTypBez
,ArtikelVariantenAlias as materialAlias
,CAST(Menge as varchar) as qtyShortpcs
,ProduktionsLos as productionlot
,LEFT(PARSE(Right(barcode, 39) as int), LEN(PARSE(Right(barcode, 39)as int)) - 1) as palletWithShortBookings
,m.Standort as machineNumber
,m.Bezeichnung ,m.Bezeichnung as machineAlias
,Buchungsdatum as bookingDate
from [dbo].[V_LagerBuchungen] (nolock) s
left join
dbo.T_Maschine (nolock) as m
on m.IdMaschine = s.IdMaschine
where beleg like '%$Sho%' and s.Add_Date > DATEADD(MINUTE, -@range, getdate())
and (@avType = 'all' or IdArtikelTyp in (@avTypeID))
order by ProduktionsLos
`;

View File

@@ -0,0 +1,27 @@
export let getHeaders = `
select AuftragsNummer as header,
IdAuftragsAbruf as releaseNumber,
AbrufLadeDatum AS LoadingDate,
AbrufLiefertermin as delDate
FROM alplaprod_test1.dbo.V_TrackerAuftragsAbrufe (nolock) b
left join
(
select IdAdressen addressID,
x.Bezeichnung as name,
c.Bezeichnung as deliveryCondition,
c.Kurzbezeichnung as Abbreviation
from AlplaPROD_test1.dbo.t_Adressen (nolock) x
left join
AlplaPROD_test1.[dbo].[T_Lieferkonditionen] (nolock) c
on x.IdLieferkondition = c.IdLieferkondition
) x
on b.IdAdresse = x.addressID
WHERE AbrufStatus = 1 and
--AbrufLiefertermin between DATEADD(HOUR, -[from], getdate()) and DATEADD(HOUR, [to], GETDATE()) -- this number will be grabbed from the db with a default of 24hours
AbrufLadeDatum between DATEADD(HOUR, -[from], getdate()) and DATEADD(HOUR, [to], GETDATE()) -- this number will be grabbed from the db with a default of 24hours
and x.Abbreviation not in ('exw')
and IdAuftragsAbruf not in ([exclude])
`;

View File

@@ -0,0 +1,150 @@
export let getOrderToSend = `
select * from (
Select IdAdresse as addressId,
LieferAdressBez as addressAlias,
LEFT(ArtikelVariantenAlias, charindex(' ', ArtikelVariantenAlias) - 1) item,
IdArtikelVarianten as article,
ArtikelVariantenAlias as articleAlias,
IdAuftragsAbruf as releaseNumber,
AuftragsNummer AS Header,
AuftragsNummer as CustomerLineItemNo,
AbrufNummer AS CustomerReleaseNumber,
AbrufMengeVPK AS Pallets,
AbrufMenge AS QTY,
IdAdresse AS CUSTOMERID,
AbrufLadeDatum AS LoadingDate,
AbrufLiefertermin AS DeliveryDate
,carrierAV
,singleTrip
,roundTrip
,countryAv
,zipCode
,streetAddress
,city -- split on here by ,
--,OrderStatus = 'loading'
,ac.costCenter -- also called pfc
,pkg.pkgHeight
,pkg.pkgLengh
,pkg.pkgWidth
,ROUND((ac.weight * pkg.palletCount / 1000) + pkg.totalPKGWeight,2)as pkgWeight
,AbrufStatus as status
,remark
,ac.artileType
--,*
FROM alplaprod_test1.dbo.V_TrackerAuftragsAbrufe (nolock) x
--av info
left join
(SELECT [IdArtikelvarianten] as article
,[FibuKontenKontoNr] as costCenter
,ArtikelGewicht as weight,
s.pkgId
,artikelvariantentypbez as artileType
FROM [AlplaPROD_test1].[dbo].[V_Artikelvarianten_BASIS] (nolock) x
left join
(
select * from (select
ROW_NUMBER() OVER(PARTITION BY [IdArtikelvarianten] ORDER BY gueltigabDatum DESC) AS rn
,[IdArtikelvarianten] as article
,IdVpkVorschrift as pkgId
from [AlplaPROD_test1].[dbo].[T_HistoryVK] (nolock)) a where rn = 1
) as s
on
x.[IdArtikelvarianten] = s.article
) as ac
on
x.IdArtikelVarianten = ac.article
-- transport part of query
left join
(SELECT [IdHistoryTransportkosten]
,[IdLieferadresse] as customerAddressAV
,[IdSpediteuradresse] as carrierAV
,[GueltigabDatum] as validDate
,[Einzelfahrtkosten] as singleTrip
,[Rundfahrtkosten] as roundTrip
,[EinzelfahrtkostenProKubikmeter] as singletripCostsperCubicMeter
,[RundfahrtkostenProKubikmeter] as roundSingletripCostsperCubicMeter
,[Standard] as standard
,[Aktiv] as active
--,[FWEinzelfahrtkosten]
--,[FWRundfahrtkosten]
--,[FWEinzelfahrtkostenProKubikmeter]
--,[FWRundfahrtkostenProKubikmeter]
FROM [AlplaPROD_test1].[dbo].[T_HistoryTransportkosten] (nolock)
where Standard = 1 and Aktiv = 1) as carrier
on x.IdAdresse = carrier.customerAddressAV
-- address stuff
left join
(SELECT [IdAdressen] as addressAV
,[IdAdressentyp] as addressType -- 1 customer,2 supplier, 4 transport
--,[IdZahlKond]
--,[IdMwst]
,[Bezeichnung] as addressName
,[IdStaaten] as countryAv
,[PLZ] as zipCode
,[Strasse] as streetAddress
,[PLZPostfach] as poBox
,[Postfach] as mailbox
,[Ort] as city
,[Tel] as customerPhone
,[DebNr] as debitorNr
,xy.[Bonus] as bonus
,[Bemerkung] as remark
,[Aktiv] as active
,Entfernung as distanceKM
,Transportzeit as transportTime
,IdLieferkondition as deliveryCondtionAV
,delc.deliveryContionAlias
,delc.deliveryContionAbv
--,ac.costCenter
FROM [AlplaPROD_test1].[dbo].[T_Adressen] (nolock) xy
--delivery condtion details
left join
(SELECT [IdLieferkondition] as deliveryCondtionAV
,[Bezeichnung] as deliveryContionAlias
,[Kurzbezeichnung] as deliveryContionAbv
,[Bemerkung] as deliveryContionRemark
,[Aktiv] as active
FROM [AlplaPROD_test1].[dbo].[T_Lieferkonditionen] (nolock)) as delC
on xy.IdLieferkondition = delC.deliveryCondtionAV
) as del
on
x.IdAdresse = del.addressAV
-- pkg info
left join
(
SELECT [IdVpkVorschrift] as pkgId
,[Aktiv] as active
,[Bezeichnung] as alias
,[AnzahlAVProVpk] as palletCount
,[AnzahlVpkProLKW] as totalTruck
,[AnzahlKistenProKarton]
,[BruttoGewicht] / 1000 as totalPKGWeight
--,[AnzahlAVProHE]
,[VpkDimensionenHoehe] as pkgHeight
,[VpkDimensionenBreite] as pkgWidth
,[VpkDimensionenTiefe] as pkgLengh
FROM [AlplaPROD_test1].[dbo].[V_Vpk_BASIS]
)as pkg
on
ac.pkgId = pkg.pkgId
WHERE AbrufStatus = 1
--and AbrufLiefertermin between DATEADD(HOUR, -[from], getdate()) and DATEADD(HOUR, [to], getdate())-- this number will be grabbed from the db with a default of 24hours
and AbrufLadeDatum between DATEADD(HOUR, -[from], getdate()) and DATEADD(HOUR, [to], getdate())-- this number will be grabbed from the db with a default of 24hours
and deliveryContionAbv not in ('EXW')
--ORDER BY AbrufLiefertermin)
) a
where releaseNumber = [releaseToProcess]
`;