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

85 lines
1.5 KiB
MySQL
Raw Normal View History

DELIMITER $$
2024-03-04 12:42:11 +00:00
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`payment_add`(
vDated DATE,
vSupplierFk INT,
vAmount DOUBLE,
vCurrencyFk INT,
2024-02-29 06:37:23 +00:00
vForeignValue DOUBLE,
vBankFk INT,
vPayMethodFk INT,
vExpenseFk DOUBLE,
vConcept VARCHAR(40),
vCompanyFk INT)
BEGIN
2024-02-28 07:39:49 +00:00
/**
2024-03-04 12:42:11 +00:00
* Registra un pago realizado a un proveedor y
* su correspondiente registro en caja.
2024-02-28 07:39:49 +00:00
*
* @param vDated Fecha del pago
* @param vSupplierFk Id del proveedor
* @param vAmount Cantidad a pagar
* @param vCurrencyFk Id de la moneda
2024-02-29 06:37:23 +00:00
* @param vForeignValue Tipo de cambio utilizado
2024-02-28 07:39:49 +00:00
* @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,
2024-02-29 06:37:23 +00:00
IF(NOT vForeignValue, NULL, vForeignValue),
vBankFk,
vPayMethodFk,
vExpenseFk,
vConcept,
vCompanyFk
);
2024-02-28 08:13:01 +00:00
SELECT LAST_INSERT_ID() paymentFk;
END$$
DELIMITER ;