2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-07-22 09:52:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` FUNCTION `vn`.`invoiceSerial`(vClientFk INT, vCompanyFk INT, vType CHAR(1))
|
2024-01-15 11:31:03 +00:00
|
|
|
RETURNS char(1) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
|
|
|
|
DETERMINISTIC
|
|
|
|
BEGIN
|
|
|
|
/**
|
|
|
|
* Obtiene la serie de de una factura
|
|
|
|
* dependiendo del area del cliente.
|
|
|
|
*
|
|
|
|
* @param vClientFk Id del cliente
|
|
|
|
* @param vCompanyFk Id de la empresa
|
|
|
|
* @param vType Tipo de factura ["R", "M", "G"]
|
|
|
|
* @return Serie de la factura
|
|
|
|
*/
|
|
|
|
DECLARE vTaxArea VARCHAR(25);
|
|
|
|
DECLARE vSerie CHAR(1);
|
|
|
|
|
|
|
|
IF (SELECT hasInvoiceSimplified FROM client WHERE id = vClientFk) THEN
|
|
|
|
RETURN 'S';
|
|
|
|
END IF;
|
|
|
|
|
|
|
|
SELECT clientTaxArea(vClientFk, vCompanyFk) INTO vTaxArea;
|
|
|
|
SELECT invoiceSerialArea(vType,vTaxArea) INTO vSerie;
|
|
|
|
RETURN vSerie;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|