2024-01-15 11:31:03 +00:00
|
|
|
DELIMITER $$
|
2024-09-05 07:40:42 +00:00
|
|
|
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`invoiceSerial`(
|
2024-09-04 12:09:31 +00:00
|
|
|
vClientFk INT,
|
|
|
|
vCompanyFk INT,
|
|
|
|
vType CHAR(15)
|
|
|
|
)
|
2024-08-20 08:11:42 +00:00
|
|
|
RETURNS char(2) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
|
2024-01-15 11:31:03 +00:00
|
|
|
DETERMINISTIC
|
|
|
|
BEGIN
|
2024-09-04 12:09:31 +00:00
|
|
|
/**
|
|
|
|
* Obtiene la serie de una factura
|
|
|
|
* dependiendo del area del cliente.
|
|
|
|
*
|
|
|
|
* @param vClientFk Id del cliente
|
|
|
|
* @param vCompanyFk Id de la empresa
|
|
|
|
* @param vType Tipo de factura (vn.invoiceOutSerial.type[ENUM])
|
|
|
|
* @return vSerie de la factura
|
|
|
|
*/
|
2024-08-16 08:08:58 +00:00
|
|
|
DECLARE vTaxArea VARCHAR(25) COLLATE utf8mb3_general_ci;
|
2024-09-04 12:09:31 +00:00
|
|
|
DECLARE vTransactionCode INT(2);
|
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;
|
|
|
|
|
2024-09-04 12:09:31 +00:00
|
|
|
SELECT CodigoTransaccion INTO vTransactionCode
|
|
|
|
FROM taxArea
|
|
|
|
WHERE code = vTaxArea;
|
|
|
|
|
|
|
|
SELECT ios.code INTO vSerie
|
|
|
|
FROM invoiceOutSerial ios
|
|
|
|
JOIN taxArea ta ON ta.code = ios.taxAreaFk
|
|
|
|
WHERE ios.`type` = vType
|
|
|
|
AND ta.CodigoTransaccion = vTransactionCode;
|
2024-07-22 08:26:40 +00:00
|
|
|
|
2024-01-15 11:31:03 +00:00
|
|
|
RETURN vSerie;
|
|
|
|
END$$
|
|
|
|
DELIMITER ;
|