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,55 @@
export const lotQuery = `
select IdMaschinen_ProdPlanung as LabelOnlineID,
IdMaschine as machineID,
MaschinenStandort as MachineLocation,
MaschinenBez as MachineDescription,
IdProdPlanung as lot,
prolink.lot as ProlinkLot,
IdArtikelvarianten as AV,
ArtikelVariantenBez as Alias,
convert(varchar, add_date, 20) as Add_Date,
Add_user,
idEtikettenDrucker as printerID,
b.name as PrinterName,
CAST(TotalPlannedLoadingUnits as float) as PlannedQTY,
CAST(TotalProducedLoadingUnits as float) as Produced,
ROUND(CAST(TotalPlannedLoadingUnits as float) - CAST(TotalProducedLoadingUnits as float),2) as Remaining,
case
-- checks if someone changed the criteria to something else to trigger the over run
when x.ProzentReserveAnzahlPaletten > 0 then 'yes'
-- if the lot has a decimal in it to allow over running with no intervention
when CAST(TotalPlannedLoadingUnits as float) - floor(CAST(TotalPlannedLoadingUnits as float)) > 0 then 'yes'
else 'no' end as overPrinting,
CustomerHumanReadableId as CustomerId,
CustomerName as CustomerName,
idMaschine as MachineID,
prolink.lastProlinkUpdate as lastProlinkUpdate,
IdEtikettenLayoutPalette as palletLabel,
AnzahlKopienPalette as pallerCopies,
IdEtikettenLayoutKarton as cartonLabel,
AnzahlKopienKarton as cartonCopies,
IsTechnicallyReleased
--*
from AlplaPROD_test1.dbo.V_Maschinen_ProdPlanungen x (nolock)
join
[test1_AlplaPROD2.0_Read].[productionControlling].[ProducedLot] on
x.IdProdPlanung =
[test1_AlplaPROD2.0_Read].[productionControlling].[ProducedLot].ProductionLotHumanReadableId
left join
[test1_AlplaPROD2.0_Read].masterData.Printer as b on
x.IdEtikettenDrucker = b.HumanReadableId
-- adding in prolink lot
left join
(SELECT * from (SELECT IdMaschine as prolinkMachineId,
Produktionslos as lot,
Upd_Date as lastProlinkUpdate,
ROW_NUMBER() OVER (PARTITION BY IdMaschine ORDER BY Upd_Date DESC) RN_Prolink
FROM AlplaPROD_test1.dbo.T_HistoryProduktionsdaten (nolock)
WHERE Upd_Date BETWEEN DATEADD(DD, - 300, getdate()) AND DATEADD(DD, 1, getdate())) p
WHERE RN_Prolink = 1
) as prolink on
x.idMaschine = prolink.prolinkMachineId
where IsTechnicallyReleased = 1
`;

View File

@@ -0,0 +1,9 @@
export const machineCheck = `
SELECT [HumanReadableId]
,[Name]
,[Location]
,[Active]
,[ImportSource]
,[StagingMainMaterialMandatory]
FROM [test1_AlplaPROD2.0_Read].[masterData].[Machine] (nolock)
where Active = 1 and [Location] = [loc]`;

View File

@@ -0,0 +1,140 @@
// export const mmQuery = `
// SELECT lot.ProductionLotHumanReadableId,
// case when SourcingState in (1, 2) then 1
// when x.ProvidedAmount > 0 then 1
// when x.EffectiveConsumption > 0 then 1
// else 0 end as Staged,
// x.ProvidedAmount as Provided,
// x.EffectiveConsumption as consumption,
// x.TotalDemand as totalNeeded,
// /* remaining needed to complete the lot */
// x.TotalDemand - x.EffectiveConsumption as remainingNeeded,
// /* do we have enough staged or scanned to the lot? */
// case when (case when x.ProvidedAmount <> 0 then x.ProvidedAmount else x.EffectiveConsumption end) > x.TotalDemand then 'good' else 'bad' end as noShortage ,
// x.IsManualProcess as isManual,
// MaterialHumanReadableId
// FROM [test1_AlplaPROD2.0_Read].[issueMaterial].[MaterialDemand] x (nolock)
// left join
// [test1_AlplaPROD2.0_Read].[issueMaterial].[ProductionLot] as lot on
// x.ProductionLotId = lot.Id
// where lot.ProductionLotHumanReadableId = [lotNumber]
// and IsMainMaterial = 1
// `;
export const mmQuery = `
use [test1_AlplaPROD2.0_Read]
declare @lot as NVARCHAR(max) = [lotNumber]
/*
checks all needed material including pkg
we only want to monitor the manual materials and the mm materail to make sure they are good.
for auto consume materails this will be compared with another query.
*/
/*
Material demands for this lot
*/
select
MaterialHumanReadableId
,MaterialDescription
-- check box is staged so we could book in even if we used preprint.
,case when SourcingState in (1, 2) then 1
when x.ProvidedAmount > 0 then 1
when x.EffectiveConsumption > 0 then 1
else 0 end as Staged
,x.IsManualProcess as isManual
,IsMainMaterial
-- lot stuff
,lot.TotalPlannedLoadingUnits
,lot.TotalProducedLoadingUnits
,lot.TotalPlannedLoadingUnits - lot.TotalProducedLoadingUnits as remainingPallets
,x.ProvidedAmount as Provided -- this is what has been provided most of the time this is due to a silo attachment
,x.EffectiveConsumption as consumption -- this is how much was consummed via cmd 112
,x.TotalDemand as totalDemand -- the total demand needed to finish the lot out
,case when cp.Pieces >= 0.001 then (lot.TotalProducedLoadingUnits+1) * cp.Pieces else
(a.Weight *((case when cp.Percentage is null then 80 else cp.Percentage end) / 100) * ((lot.TotalProducedLoadingUnits+1) * p.LoadingUnitPieces)) / 1000 end totalNeeded
,case when IsMainMaterial = 1 then
case when (case when x.ProvidedAmount <> 0
then x.ProvidedAmount else x.EffectiveConsumption end) >
(case when cp.Pieces >= 0.001 then (lot.TotalProducedQuantity+1) * cp.Pieces else
(a.Weight *((case when cp.Percentage is null then 80 else cp.Percentage end) / 100) * ((lot.TotalProducedLoadingUnits+1) * p.LoadingUnitPieces)) / 1000 end)
then 'mmGood'
else 'noMM' end else null end as noMMShortage
-- pkg check auto
,case when pkg.QuantityPosition is null then null else
(case when l.qty > ((lot.TotalProducedLoadingUnits+1) * pkg.QuantityPosition) and IsManualProcess = 0 then 'pkgAutoGood' else 'noAutoPkg' end) end as noPKGAutoShortage
-- plg check manual
,case when pkg.QuantityPosition is null then null else
(case when x.EffectiveConsumption > ((lot.TotalProducedLoadingUnits+1) * pkg.QuantityPosition) and IsManualProcess = 1 then 'pkgManGood' else 'noManPkg' end) end as noPKGManualShortage
-- manualMateiral
,case when IsMainMaterial = 0 and IsManualProcess = 1 then
case when (case when x.ProvidedAmount <> 0
then x.ProvidedAmount else x.EffectiveConsumption end) >
(case when cp.Pieces >= 0.001 then (lot.TotalProducedQuantity+1) * cp.Pieces else
(a.Weight *((case when cp.Percentage is null then 80 else cp.Percentage end) / 100) * ((lot.TotalProducedLoadingUnits+1) * p.LoadingUnitPieces)) / 1000 end)
then 'manualGood'
else 'noOK' end else null end as noManualShortage
-- autoconsume
,case when cp.Percentage is null then
case when l.qty > ((lot.TotalProducedLoadingUnits +1) * pkg.QuantityPosition) then 'autoConsumeOk' else 'autoConsumeNOK' end else
(case when l.qty > (a.Weight *(cp.Percentage / 100) * ((lot.TotalProducedLoadingUnits+1) * p.LoadingUnitPieces)) / 1000 and IsManualProcess = 0
then 'autoConsumeOk' else 'autoConsumeNOK' end) end as autoConsumeCheck
-- stock amounts
,l.qty as invForAutoConsume
,case when cp.Percentage is null then 0 else cp.Percentage end as Percentage
,pkg.QuantityPosition
,(lot.TotalProducedQuantity+1) * cp.Pieces
from [issueMaterial].[MaterialDemand] x (nolock)
/* production lot info */
left join
[productionControlling].[ProducedLot] as lot on
lot.Id = x.ProductionLotId
/* packagaing */
left join
[masterData].[PackagingInstructionPosition] as pkg on
pkg.PackagingInstructionId = lot.PackagingId
and pkg.ArticleId = x.MaterialId
-- get the pkg stuff so we have the total amount per pallet.
left join
[masterData].[PackagingInstruction] as p on
p.id = lot.PackagingId
/* av data */
left join
[masterData].[Article] as a on
a.id = lot.ArticleId
/* compound*/
left join
[masterData].[CompoundPosition] as cp on
cp.CompoundId = a.CompoundId
and cp.ArticleId = x.MaterialId
/* current stock info for auto consumption*/
left join
(select
IdArtikelVarianten
,ArtikelVariantenBez
,sum(VerfuegbareMengeSum) as qty
from AlplaPROD_test1.dbo.V_LagerPositionenBarcodes as i (nolock)
left join
AlplaPROD_test1.dbo.V_LagerAbteilungen as l (nolock) on
l.IdLagerAbteilung = i.IdLagerAbteilung
where autoverbrauch = 1 and aktiv = 1
group by IdArtikelVarianten,ArtikelVariantenBez
) as l on
l.IdArtikelVarianten = MaterialHumanReadableId
where lot.ProductionLotHumanReadableId = @lot and MaterialDescription not like '%nopal%'
and MaterialDescription NOT LIKE '%bb%'
and MaterialDescription NOT LIKE '%mcg%'
`;

View File

@@ -0,0 +1,25 @@
export const prolinkQuery = `
select * from (
select *
From(select
V_Maschinen_ProdPlanungen.MaschinenStandort as Machine,
V_Maschinen_ProdPlanungen.IdProdPlanung as AlplaLabelOnline,
prolink.lot Prolink,
case when AlplaPROD_test1.dbo.V_Maschinen_ProdPlanungen.IdProdPlanung <> prolink.lot
Then 'IncorrectLot'
Else 'Good' end as LotCheck
from AlplaPROD_test1.dbo.V_Maschinen_ProdPlanungen (nolock)
left join
(
SELECT *
FROM (SELECT IdMaschine,
Produktionslos as lot,
Startzeit as StartTime,
Upd_Date,
ROW_NUMBER() OVER (PARTITION BY IdMaschine ORDER BY Upd_Date DESC) RN_Prolink
FROM AlplaPROD_test1.dbo.T_HistoryProduktionsdaten (nolock)
WHERE Upd_Date BETWEEN DATEADD(DD, - 10, getdate()) AND DATEADD(DD, 1, getdate())) a
WHERE RN_Prolink = 1
) as prolink on AlplaPROD_test1.dbo.V_Maschinen_ProdPlanungen.IdMaschine=prolink.IdMaschine) a
) a
`;