DELIMITER $$ CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`payment_add`( vDated DATE, vSupplierFk INT, vAmount DOUBLE, vCurrencyFk INT, vForeignValue DOUBLE, vBankFk INT, vPayMethodFk INT, vExpenseFk DOUBLE, vConcept VARCHAR(40), vCompanyFk INT) BEGIN /** * Registra un pago realizado a un proveedor y * su correspondiente registro en caja. * * @param vDated Fecha del pago * @param vSupplierFk Id del proveedor * @param vAmount Cantidad a pagar * @param vCurrencyFk Id de la moneda * @param vForeignValue 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 * @return paymentFk Id de pago insertado */ 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 vForeignValue, NULL, vForeignValue), vBankFk, vPayMethodFk, vExpenseFk, vConcept, vCompanyFk ); SELECT LAST_INSERT_ID() paymentFk; END$$ DELIMITER ;