salix/db/routines/vn/procedures/pay.sql

84 lines
1.5 KiB
MySQL
Raw Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`pay`(
vDated DATE,
vSupplierFk INT,
vAmount DOUBLE,
vCurrencyFk INT,
vDivisa DOUBLE,
vBankFk INT,
vPayMethodFk INT,
vExpenseFk DOUBLE,
vConcept VARCHAR(40),
vCompanyFk INT)
BEGIN
2024-02-28 07:39:49 +00:00
/**
* Registra un pago realizado a un proveedor.
*
* @param vDated Fecha del pago
* @param vSupplierFk Id del proveedor
* @param vAmount Cantidad a pagar
* @param vCurrencyFk Id de la moneda
* @param vDivisa Tipo de cambio utilizado
* @param vBankFk Id del banco
* @param vPayMethodFk Id del método de pago
* @param vExpenseFk Id de gasto
* @param vConcept Concepto del pago
* @param vCompanyFk Id de la empresa
2024-02-28 08:13:01 +00:00
* @return paymentFk Id de pago insertado
2024-02-28 07:39:49 +00:00
*/
INSERT INTO till(
concept,
serie,
`number`,
`out`,
dated,
isAccountable,
bankFk,
workerFk,
companyFk,
isConciliate
)
SELECT CONCAT('n/pago a ', `name`),
'R',
vSupplierFk,
vAmount,
vDated,
1,
vBankFk,
account.myUser_getId(),
vCompanyFk,
1
FROM supplier
WHERE id = vSupplierFk;
INSERT INTO payment(
received,
dueDated,
supplierFk,
amount,
currencyFk,
divisa,
bankFk,
payMethodFk,
bankingFees,
concept,
companyFk
)
VALUES(
vDated,
vDated,
vSupplierFk,
vAmount,
vCurrencyFk,
IF(NOT vDivisa, NULL, vDivisa),
vBankFk,
vPayMethodFk,
vExpenseFk,
vConcept,
vCompanyFk
);
2024-02-28 08:13:01 +00:00
SELECT LAST_INSERT_ID() paymentFk;
END$$
DELIMITER ;