salix/db/routines/vn/functions/invoiceSerial.sql

33 lines
862 B
MySQL
Raw Normal View History

DELIMITER $$
2024-07-22 08:26:40 +00:00
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`invoiceSerial`(vClientFk INT, vCompanyFk INT, vType CHAR(15))
RETURNS char(1) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
DETERMINISTIC
BEGIN
/**
2024-07-22 08:26:40 +00:00
* Obtiene la serie de de una factura
* dependiendo del area del cliente.
2024-07-22 08:26:40 +00:00
*
* @param vClientFk Id del cliente
* @param vCompanyFk Id de la empresa
2024-07-22 08:26:40 +00:00
* @param vType Tipo de factura ['global','multiple','quick']
* @return vSerie de la factura
*/
DECLARE vTaxArea VARCHAR(25);
2024-07-22 08:26:40 +00:00
DECLARE vSerie CHAR(2);
IF (SELECT hasInvoiceSimplified FROM client WHERE id = vClientFk) THEN
RETURN 'S';
END IF;
2024-07-22 08:26:40 +00:00
SELECT addressTaxArea(defaultAddressFk, vCompanyFk) INTO vTaxArea
FROM client
WHERE id = vClientFk;
SELECT code INTO vSerie
FROM invoiceOutSerial
WHERE `type` = vType AND taxAreaFk = vTaxArea;
RETURN vSerie;
END$$
DELIMITER ;