2023-02-23 08:25:23 +00:00
|
|
|
DELIMITER $$
|
2024-01-15 11:31:03 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceOut_getMaxIssued`(vSerial VARCHAR(2),
|
2023-02-23 08:25:23 +00:00
|
|
|
vCompanyFk INT,
|
|
|
|
vYear INT
|
2024-01-15 11:31:03 +00:00
|
|
|
)
|
|
|
|
RETURNS date
|
|
|
|
NOT DETERMINISTIC
|
|
|
|
READS SQL DATA
|
2023-02-23 08:25:23 +00:00
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Retorna la fecha a partir de la cual es válido emitir una factura
|
|
|
|
*
|
|
|
|
* @param vSerial Serie de facturación
|
|
|
|
* @param vCompanyFk Empresa factura emitida
|
|
|
|
* @param vYear Año contable
|
|
|
|
* @return vInvoiceOutIssued fecha factura válida
|
|
|
|
*/
|
|
|
|
DECLARE vInvoiceOutIssued DATE;
|
|
|
|
DECLARE vFirstDayOfYear DATE;
|
|
|
|
|
|
|
|
SET vFirstDayOfYear := MAKEDATE(vYear, 1);
|
|
|
|
|
|
|
|
SELECT IFNULL(MAX(io.issued), vFirstDayOfYear) INTO vInvoiceOutIssued
|
|
|
|
FROM invoiceOut io
|
|
|
|
WHERE io.serial = vSerial
|
|
|
|
AND io.companyFk = vCompanyFk
|
|
|
|
AND io.issued BETWEEN vFirstDayOfYear
|
|
|
|
AND util.lastDayOfYear(vFirstDayOfYear);
|
|
|
|
|
|
|
|
RETURN vInvoiceOutIssued;
|
|
|
|
END$$
|
2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER ;
|