Files
lst/lstV2/server/services/sqlServer/querys/ocp/lots.ts

72 lines
2.8 KiB
TypeScript

export const lotQuery = `
select IdMaschinen_ProdPlanung as LabelOnlineID,
x.IdMaschine as machineID,
MaschinenStandort as MachineLocation,
MaschinenBez as MachineDescription,
x.IdProdPlanung as lot,
prolink.lot as ProlinkLot,
x.IdArtikelvarianten as AV,
x.ArtikelVariantenBez as Alias,
convert(varchar, x.add_date, 20) as Add_Date,
x.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,
x.idMaschine as MachineID,
prolink.lastProlinkUpdate as lastProlinkUpdate,
IdEtikettenLayoutPalette as palletLabel,
AnzahlKopienPalette as pallerCopies,
IdEtikettenLayoutKarton as cartonLabel,
AnzahlKopienKarton as cartonCopies,
IsTechnicallyReleased,
DruckStatus as allowPrinting,
p.MaschZyklus as cycleTime,
x.StueckzahlJePalette,
p.WerkzeugKavität,
(((x.StueckzahlJePalette /p.WerkzeugKavität) * p.MaschZyklus) * (p.MaschAuslastung/100)) * .70 as timeTOmakeInSeconds
--*
from AlplaPROD_test1.dbo.V_Maschinen_ProdPlanungen x (nolock)
join
[test1_AlplaPROD2.0_Read].[productionControlling].[ProducedLot](nolock) on
x.IdProdPlanung =
[test1_AlplaPROD2.0_Read].[productionControlling].[ProducedLot].ProductionLotHumanReadableId
left join
[test1_AlplaPROD2.0_Read].masterData.Printer (nolock) 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
----packagin info
--left join
--[test1_AlplaPROD2.0_Read].[masterData].[PackagingInstruction] (nolock) pkg on
--pkg.HumanReadableId = x.IdVpkVorschrift
-- cycle time info
left join
AlplaPROD_test1.dbo.V_ProdPlanung (nolock) as p on
p.IdProdPlanung = x.IdProdPlanung
where IsTechnicallyReleased = 1 and DruckStatus = 1
`;