[firebase-br] URGENTE!!! Poderiam analisar esta trigger ???
Anderson Sauthier
sauthier_fb em yahoo.com.br
Qua Fev 1 09:47:17 -03 2006
esta é a trigger do MOVFIN, cada lançamento feito ou deletado é atualizada a tabela de saldo do MOVFIN, SLDMOVCTAFIN
Desde já agradeço.
AS
DECLARE VARIABLE SLDANT NUMERIC(9,2);
DECLARE VARIABLE DATA_ANT DATE;
DECLARE VARIABLE DATA_ATU DATE;
DECLARE VARIABLE DEBCRE CHAR(1);
begin
IF (INSERTING) THEN
BEGIN
/* DEBITO OU CREDITO */
SELECT TIPO
FROM DEBCRE
WHERE EMPRESAID = NEW.EMPRESAID AND
DEBCREID = NEW.DEBCREID
INTO :DEBCRE;
/* VE SE JA ESTA CADADTRADO A DATA ATUAL NO SLDMOV */
SELECT DATA
FROM SLDMOVCTAFIN
WHERE EMPRESAID = NEW.EMPRESAID AND
CTAFINID = NEW.CTAFINID AND
DATA = NEW.DATA
INTO :DATA_ATU;
IF (:DATA_ATU IS NULL) THEN
BEGIN
/* SALDO ANTERIOR */
SELECT MAX(DATA)
FROM SLDMOVCTAFIN
WHERE EMPRESAID = NEW.EMPRESAID AND
CTAFINID = NEW.CTAFINID AND
DATA < NEW.DATA
INTO :DATA_ANT;
IF (:DATA_ANT IS NULL) THEN
SLDANT = 0.00;
ELSE
BEGIN
SELECT SLDATU
FROM SLDMOVCTAFIN
WHERE EMPRESAID = NEW.EMPRESAID AND
CTAFINID = NEW.CTAFINID AND
DATA = :DATA_ANT
INTO :SLDANT;
END
IF (:DEBCRE = 'C') THEN
BEGIN
INSERT INTO SLDMOVCTAFIN
VALUES (NEW.EMPRESAID, NEW.CTAFINID, NEW.DATA,
:SLDANT, NEW.VALORTOTAL, 0.00, :SLDANT +
NEW.VALORTOTAL);
END
ELSE
BEGIN
INSERT INTO SLDMOVCTAFIN
VALUES (NEW.EMPRESAID, NEW.CTAFINID, NEW.DATA,
:SLDANT, 0.00, NEW.VALORTOTAL, :SLDANT -
NEW.VALORTOTAL);
END
END
ELSE
BEGIN
IF (:DEBCRE = 'C') THEN
BEGIN
UPDATE SLDMOVCTAFIN
SET CREDITO = CREDITO + NEW.VALORTOTAL
WHERE EMPRESAID = NEW.EMPRESAID AND
CTAFINID = NEW.CTAFINID AND
DATA = NEW.DATA;
END
ELSE
BEGIN
UPDATE SLDMOVCTAFIN
SET DEBITO = DEBITO + NEW.VALORTOTAL
WHERE EMPRESAID = NEW.EMPRESAID AND
CTAFINID = NEW.CTAFINID AND
DATA = NEW.DATA;
END
UPDATE SLDMOVCTAFIN
SET SLDATU = SLDANT + CREDITO - DEBITO
WHERE EMPRESAID = NEW.EMPRESAID AND
CTAFINID = NEW.CTAFINID AND
DATA = NEW.DATA;
END
END
IF (DELETING) THEN
BEGIN
/* DEBITO OU CREDITO */
SELECT TIPO
FROM DEBCRE
WHERE EMPRESAID = OLD.EMPRESAID AND
DEBCREID = OLD.DEBCREID
INTO :DEBCRE;
IF (:DEBCRE = 'C') THEN
BEGIN
UPDATE SLDMOVCTAFIN
SET CREDITO = CREDITO - OLD.VALORTOTAL
WHERE EMPRESAID = OLD.EMPRESAID AND
CTAFINID = OLD.CTAFINID AND
DATA = OLD.DATA;
END
ELSE
BEGIN
UPDATE SLDMOVCTAFIN
SET DEBITO = DEBITO - OLD.VALORTOTAL
WHERE EMPRESAID = OLD.EMPRESAID AND
CTAFINID = OLD.CTAFINID AND
DATA = OLD.DATA;
END
UPDATE SLDMOVCTAFIN
SET SLDATU = SLDANT + CREDITO - DEBITO
WHERE EMPRESAID = OLD.EMPRESAID AND
CTAFINID = OLD.CTAFINID AND
DATA = OLD.DATA;
END
END
---------------------------------
Yahoo! doce lar. Faça do Yahoo! sua homepage.
Mais detalhes sobre a lista de discussão lista