-- dbo.ET_TabVyrCP_HDC_IU
CREATE TRIGGER dbo.ET_TabVyrCP_HDC_IU ON dbo.TabVyrCP
WITH EXECUTE AS CALLER
FOR INSERT, UPDATE
AS
BEGIN
 SET NOCOUNT ON

-- !! trigger neupravujte, bude stejne pregenerovan pri startu pluginu PluginHDCRTN !!

 DECLARE
  @id INT,
  @idPZ INT,
  @mnoz NUMERIC(19,6)


 DECLARE c CURSOR LOCAL FAST_FORWARD FOR
  SELECT i.ID, i.IDPolozkaDokladu, i.Mnozstvi
   FROM inserted i
 OPEN c
 WHILE (1=1)
  BEGIN
   FETCH NEXT FROM c INTO @id, @idPZ, @mnoz
   IF (@@FETCH_STATUS<>0) BREAK


-- sync informace pro reseni ASol/ProHolding/HDC
   IF OBJECT_ID(N'dbo._TabVyroba_Objednavky_Pol', N'U') IS NOT NULL
    BEGIN
     UPDATE dbo._TabVyroba_Objednavky_Pol SET Mnozstvi=@mnoz WHERE IDPohybOZ=@idPZ AND IDVyrCP=@id
    END


  END
 CLOSE c
 DEALLOCATE c


END
