trigger payment_beforeInsert sql
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
f4a07cab70
commit
7c17250919
|
@ -0,0 +1,61 @@
|
|||
DROP TRIGGER IF EXISTS vn.payment_beforeInsert;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `payment_beforeInsert` BEFORE INSERT ON `payment` FOR EACH ROW
|
||||
-- Edit trigger body code below this line. Do not edit lines above this one
|
||||
BEGIN
|
||||
DECLARE cuenta_banco,cuenta_proveedor DOUBLE;
|
||||
DECLARE vNewBookEntry INT;
|
||||
DECLARE bolCASH BOOLEAN;
|
||||
DECLARE isSupplierActive BOOLEAN;
|
||||
DECLARE vIsPayMethodChecked BOOLEAN;
|
||||
|
||||
-- PAK 10/02/15 No se asientan los pagos directamente, salvo en el caso de las cajas de CASH
|
||||
SELECT (at2.code = 'cash') INTO bolCASH FROM vn.bank b JOIN vn.accountingType at2 ON at2.id = b.cash WHERE b.id = NEW.bankFk ;
|
||||
|
||||
IF bolCASH THEN
|
||||
|
||||
SELECT account INTO cuenta_banco
|
||||
FROM bank
|
||||
WHERE id = NEW.bankFk;
|
||||
|
||||
SELECT account INTO cuenta_proveedor
|
||||
FROM supplier
|
||||
WHERE id = NEW.supplierFk;
|
||||
|
||||
CALL vn.ledger_next(vNewBookEntry);
|
||||
|
||||
INSERT INTO XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id)
|
||||
SELECT vNewBookEntry,NEW.received,SUBCTA,CONTRA,NEW.concept,EURODEBE,EUROHABER,NEW.companyFk
|
||||
FROM
|
||||
( SELECT cuenta_banco SUBCTA,cuenta_proveedor CONTRA,0 EURODEBE, NEW.amount + NEW.bankingFees EUROHABER
|
||||
UNION ALL
|
||||
SELECT cuenta_proveedor SUBCTA, cuenta_banco CONTRA,NEW.amount EURODEBE, 0 EUROHABER
|
||||
) gf;
|
||||
|
||||
IF NEW.bankingFees <> 0 THEN
|
||||
INSERT INTO XDiario (ASIEN,FECHA,SUBCTA,CONTRA,CONCEPTO,EURODEBE,EUROHABER,empresa_id)
|
||||
SELECT vNewBookEntry,NEW.received,IF(c.id = 1,6260000002,IF(CEE = 1,6260000003,6260000004)),cuenta_banco,NEW.concept,NEW.bankingFees,0,NEW.companyFk
|
||||
FROM supplier s
|
||||
JOIN country c ON s.countryFk = c.id
|
||||
WHERE s.id = NEW.supplierFk;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
SET NEW.dueDated = IFNULL(NEW.dueDated, NEW.received);
|
||||
|
||||
SELECT isActive, isPayMethodChecked INTO vIsSupplierActive, vIsPayMethodChecked
|
||||
FROM supplier
|
||||
WHERE id = NEW.supplierFk;
|
||||
|
||||
IF isSupplierActive = FALSE THEN
|
||||
CALL util.throw('SUPPLIER_INACTIVE');
|
||||
END IF;
|
||||
|
||||
IF vIsPayMethodChecked = FALSE THEN
|
||||
CALL util.throw('SUPPLIER_DOES_NOT_HAVE_PAYMETHODCHECKED');
|
||||
END IF;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue