refs #6915 test_master24_8 #2067

Merged
alexm merged 561 commits from test_master24_8 into master 2024-02-22 07:31:34 +00:00
1 changed files with 22 additions and 11 deletions
Showing only changes of commit 1a869766b9 - Show all commits

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 ;