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

33 lines
886 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(2) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
DETERMINISTIC
BEGIN
/**
* Obtiene la serie 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
*/
2024-08-16 08:08:58 +00:00
DECLARE vTaxArea VARCHAR(25) COLLATE utf8mb3_general_ci;
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 ;