Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USE [EnterpriseAdminDB]
- GO
- /****** Object: Trigger [dbo].[USD_SAFACT] Script Date: 19/06/2023 14:38:02 ******/
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- --DROP TRIGGER [dbo].[USD_SAFACT]
- --GO
- ALTER TRIGGER [dbo].[USD_SAFACT]
- ON [dbo].[SAITEMFAC]
- AFTER INSERT AS
- BEGIN
- SET NOCOUNT ON
- DECLARE
- @Factor DECIMAL(28, 4),
- @FACTORM DECIMAL(28,4),
- @MONTO DECIMAL(28,4),
- @CONTADO DECIMAL(28,4),
- @CREDITO DECIMAL(28,4),
- @CAMBIO DECIMAL(28,4),
- @CANCELA DECIMAL(28,4),
- @CANCELE DECIMAL(28,4),
- @CANCELI DECIMAL(28,4),
- @CANCELC DECIMAL(28,4),
- @CANCELT DECIMAL(28,4),
- @CANCELG DECIMAL(28,4),
- @DESCTO1 DECIMAL(28,4),
- @MTOTOTAL DECIMAL(28,4),
- @PRECIO DECIMAL(28,4),
- @COSTO DECIMAL(28,4),
- @TOTALITEM DECIMAL(28,4),
- @TOTALPRD DECIMAL(28,4),
- @COSTOPRD DECIMAL(28,4),
- @TOTALSRV DECIMAL(28,4),
- @COSTOSRV DECIMAL(28,4),
- @MONTOTAX DECIMAL(28,4),
- @MTOTAX DECIMAL(28,4),
- @MTOTAXI DECIMAL(28,4),
- @NOTAS VARCHAR(MAX),
- @TGRAVABLE DECIMAL(28,4),
- @NUMEROFAC VARCHAR(20),
- @NUMERODOC VARCHAR(20),
- @SALDO decimal(28,4),
- @SaldoAnt DECIMAL(28,4),
- @SaldoOrg DECIMAL(28,4),
- @TipoCxC VARCHAR(2),
- @TipoF VARCHAR(1),
- @CODCLIE VARCHAR(15),
- @CODITEM VARCHAR(15),
- @NROLINEA INT,
- @NUMERRORS INT;
- SET @NUMERRORS=0;
- SET @Factor = (SELECT FACTOR FROM dbo.SACONF);
- SET @FACTORM = (SELECT FactorM FROM dbo.SACONF);
- SELECT @NUMEROFAC=Inserted.NumeroD, @TipoF=Inserted.TipoFac, @NROLINEA=NroLinea FROM INSERTED
- declare Fact_UPDATE_Mex cursor FOR
- SELECT F.NumeroD, F.TipoFac, F.Monto, F.MtoTax, F.TGravable, F.CostoPrd, F.CostoSrv, F.MtoTotal, F.Contado, F.Credito, F.CancelI,
- F.CancelA, F.CancelE, F.CancelC, F.CancelT, F.CancelG, F.Cambio, F.Descto1, F.TotalPrd, F.TotalSrv,
- I. NroLinea, I.CodItem, I.TotalItem, I.Costo, I.Precio, I.MtoTax, F.Notas6
- FROM dbo.SAITEMFAC AS I
- JOIN dbo.SAFACT AS F ON F.NumeroD=I.NumeroD
- WHERE F.NumeroD=@NUMEROFAC AND F.TipoFac=@TipoF AND I.NroLinea=@NROLINEA
- open Fact_UPDATE_Mex
- fetch next from Fact_UPDATE_Mex into @NUMEROFAC, @TipoF, @MONTO, @MTOTAX, @TGRAVABLE, @COSTOPRD, @COSTOSRV, @MTOTOTAL, @CONTADO, @CREDITO, @CANCELI, @CANCELA, @CANCELE, @CANCELC, @CANCELT,
- @CANCELG, @CAMBIO, @DESCTO1, @TOTALPRD, @TOTALSRV, @NROLINEA, @CODITEM, @TOTALITEM, @COSTO, @PRECIO, @MTOTAXI, @NOTAS
- WHILE @@fetch_status = 0
- BEGIN
- IF EXISTS (SELECT * FROM dbo.SAFACT WHERE NumeroD = @NUMEROFAC AND TipoFac=@TipoF AND @TipoF='G')
- BEGIN
- IF EXISTS (SELECT * FROM dbo.SAFACT WHERE NumeroD = @NUMEROFAC AND TipoFac=@TipoF AND Notas10 IS NULL)
- BEGIN
- UPDATE dbo.SAFACT SET Monto=@MONTO*@FACTORM, MtoTotal=@MTOTOTAL*@FACTORM, MontoMEx=@MONTO,
- Contado=@CONTADO*@FACTORM, Credito=@CREDITO*@FACTORM,
- TGravable=@TGRAVABLE*@FACTORM, MtoTax=@MTOTAX*@FACTORM,
- CancelI=@CANCELI*@FACTORM, CancelA=@CANCELA*@FACTORM, CancelE=@CANCELE*@FACTORM,
- CancelC=@CANCELC*@FACTORM, CancelT=@CANCELT*@FACTORM, CancelG=@CANCELG*@FACTORM,
- Factor=@FACTORM, Notas10='UPDATED'
- WHERE (CODSUCU='00000') AND (TIPOFAC=@TipoF) AND (NUMEROD=@NUMEROFAC) AND @NOTAS LIKE '%$%';
- SET @NUMERRORS=@NUMERRORS+@@ERROR;
- UPDATE dbo.SATAXVTA SET TGravable=@TGRAVABLE*@FACTORM, Monto=@MONTO*@FACTORM WHERE (CODSUCU='00000') AND (TIPOFAC=@TipoF) AND (NUMEROD=@NUMEROFAC);
- SET @NUMERRORS=@NUMERRORS+@@ERROR;
- END
- UPDATE dbo.SAITEMFAC SET TotalItem=@TOTALITEM*@FACTORM, MtoTax=@MTOTAXI*@FACTORM,
- Precio=@PRECIO*@FACTORM, Costo=@COSTO*@FACTORM
- WHERE (CODSUCU='00000') AND (TIPOFAC=@TipoF) AND (NUMEROD=@NUMEROFAC) AND (NroLinea=@NROLINEA);
- SET @NUMERRORS=@NUMERRORS+@@ERROR;
- UPDATE dbo.SATAXITF SET TGravable=@TOTALITEM*@FACTORM,Monto=@MTOTAXI*@FACTORM
- WHERE (CodSucu='00000') AND (TIPOFAC=@TipoF) AND (NUMEROD=@NUMEROFAC) AND (NroLinea=@NROLINEA);
- SET @NUMERRORS=@NUMERRORS+@@ERROR;
- END
- FETCH NEXT FROM Fact_UPDATE_Mex INTO @NUMEROFAC, @TipoF, @MONTO, @MTOTAX, @TGRAVABLE, @COSTOPRD, @COSTOSRV, @MTOTOTAL, @CONTADO, @CREDITO, @CANCELI, @CANCELA, @CANCELE, @CANCELC, @CANCELT,
- @CANCELG, @CAMBIO, @DESCTO1, @TOTALPRD, @TOTALSRV, @NROLINEA, @CODITEM, @TOTALITEM, @COSTO, @PRECIO, @MTOTAXI, @NOTAS
- END
- close Fact_UPDATE_Mex
- deallocate Fact_UPDATE_Mex
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement