refs #6444 change code accord to conventions
gitea/salix/pipeline/pr-dev This commit looks good Details

This commit is contained in:
Ivan Mas 2024-02-05 08:32:45 +01:00
parent 7b1a0e1957
commit 1a869766b9
1 changed files with 22 additions and 11 deletions

View File

@ -1,21 +1,32 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`intrastat_estimateNet`(vIntrastat INT, vUnidades INT)
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`intrastat_estimateNet`(
vSelf INT,
vUnits INT
)
RETURNS double
DETERMINISTIC
BEGIN
/**
* Calcula un valor neto estimado en función de
* datos históricos de facturas intrastat.
*
* @param vSelf Id de intrastat
* @param vUnits Número de unidades
* @return vNet
*/
DECLARE vNet DOUBLE;
SELECT ROUND(vUnidades / (SUM(media) / COUNT(media)), 2) INTO vNet
FROM (SELECT *, unidades / neto media
FROM vn2008.intrastat_data
WHERE intrastat_id = vIntrastat
AND neto
AND unidades > 0
ORDER BY odbc_date DESC
LIMIT 20) t;
SELECT ROUND(vUnits / (SUM(average) / COUNT(average)), 2) INTO vNet
FROM (
SELECT *, stems / net average
FROM invoiceInIntrastat
WHERE intrastatFk = vSelf
AND net
AND stems > 0
ORDER BY dated DESC
LIMIT 20
) sub;
RETURN vNet/2;
END$$
DELIMITER ;