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

44 lines
1.1 KiB
MySQL
Raw Permalink Normal View History

DELIMITER $$
CREATE OR REPLACE DEFINER=`vn`@`localhost` FUNCTION `vn`.`invoiceSerial`(
2024-09-04 12:09:31 +00:00
vClientFk INT,
vCompanyFk INT,
vType CHAR(15)
)
RETURNS char(2) CHARSET utf8mb3 COLLATE utf8mb3_general_ci
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);
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
RETURN vSerie;
END$$
DELIMITER ;