Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SET ANSI_NULLS ON
- GO
- SET QUOTED_IDENTIFIER ON
- GO
- CREATE TRIGGER [dbo].[USD_SAFACT]
- ON [dbo].[SAFACT]
- AFTER INSERT AS
- BEGIN
- SET NOCOUNT ON
- DECLARE @Factor DECIMAL(28, 4)
- DECLARE @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),
- @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 FACTOR FROM dbo.SACONF);
- SELECT @NUMEROFAC=Inserted.NumeroD, @TipoF=Inserted.TipoFac FROM INSERTED
- SELECT @TipoCxC=@TipoCxC FROM dbo.SAACXC WHERE CodClie=@CODCLIE AND NumeroD=@NUMEROFAC
- 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, C.Saldo, C.SaldoOrg, C.SaldoAct
- FROM dbo.SAITEMFAC AS I
- JOIN dbo.SAFACT AS F ON F.NumeroD=I.NumeroD
- JOIN dbo.SAACXC AS C ON C.TipoCxc=10 AND C.NumeroD=F.NumeroD
- WHERE F.NumeroD=@NUMEROFAC AND F.TipoFac=@TipoF AND C.TipoCxc IN ('10','20') AND I.TipoFac = @TipoF
- 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, @SALDO, @SALDOORG, @SaldoAnt
- WHILE @@fetch_status = 0
- BEGIN
- IF EXISTS (SELECT * FROM dbo.SAFACT WHERE NumeroD = @NUMEROFAC AND FactorMex=0)
- BEGIN
- UPDATE dbo.SAFACT SET FactorMex=@FACTORM, MontoMEx=@MONTO*@FACTORM, MtoTotalMex=@MTOTOTAL*@FACTORM, ContadoMex=@CONTADO*@FACTORM, CreditoMex=@CREDITO*@FACTORM, TotalPrdMex=@TOTALPRD*@FACTORM,
- TGravableMex=@TGRAVABLE*@FACTORM, MtoTaxMEx=@MTOTAX*@FACTORM, CancelIMex=@CANCELI*@FACTORM, CancelAMex=@CANCELA*@FACTORM, CancelEMex=@CANCELE*@FACTORM,
- CancelCMex=@CANCELC*@FACTORM, CancelTMex=@CANCELT*@FACTORM, CancelGMex=@CANCELG*@FACTORM
- WHERE (CODSUCU='00000') AND (TIPOFAC=@TipoF) AND (NUMEROD=@NUMEROFAC);
- SET @NUMERRORS=@NUMERRORS+@@ERROR;
- UPDATE dbo.SATAXVTA SET TGravableMex=@TGRAVABLE*@FACTORM,MontoMex=@MONTO*@FACTORM WHERE (CODSUCU='00000') AND (TIPOFAC=@TipoF) AND (NUMEROD=@NUMEROFAC);
- SET @NUMERRORS=@NUMERRORS+@@ERROR;
- UPDATE dbo.SAITEMFAC SET FactorMex=@FACTORM,TotalItemMex=@TOTALITEM*@FACTORM,PrecioMex=@PRECIO*@FACTORM, CostoMex=@COSTO*@FACTORM, MtoTaxMex=@MTOTAXI*@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;
- UPDATE dbo.SAACXC SET SaldoMEx=@SALDO*@FACTORM, SaldoOrgMex=@SaldoOrg*@FACTORM, SaldoActMex=@SaldoAnt*@FACTORM, MtoTaxMex=@MTOTAX*@FACTORM, MontoMEx=@MONTO*@FACTORM, BaseImpoMex=@TGRAVABLE*@FACTORM,
- CreditosMex=@CREDITO*@FACTORM, CancelIMex=@CANCELI*@FACTORM, CancelAMex=@CANCELA*@FACTORM, CancelEMex=@CANCELE*@FACTORM, CancelCMex=@CANCELC*@FACTORM,
- CancelTMex=@CANCELT*@FACTORM, CancelGMex=@CANCELG*@FACTORM
- WHERE (CODSUCU='00000') AND (TipoCxc=@TipoCxC) AND (NUMEROD=@NUMEROFAC);
- 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, @SALDO, @SALDOORG, @SaldoAnt
- END
- close Fact_UPDATE_Mex
- deallocate Fact_UPDATE_Mex
- END
- GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement