2024-01-15 11:31:03 +00:00
|
|
|
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))
|
2024-01-15 11:31:03 +00:00
|
|
|
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
|
2024-01-15 11:31:03 +00:00
|
|
|
* dependiendo del area del cliente.
|
2024-07-22 08:26:40 +00:00
|
|
|
*
|
2024-01-15 11:31:03 +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-01-15 11:31:03 +00:00
|
|
|
*/
|
|
|
|
DECLARE vTaxArea VARCHAR(25);
|
2024-07-22 08:26:40 +00:00
|
|
|
DECLARE vSerie CHAR(2);
|
2024-01-15 11:31:03 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
RETURN vSerie;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|