Merge pull request '6444-MigrateVn2008.intrastat_netoFunctionToVn' (!1972) from 6444-MigrateVn2008.intrastat_netoFunctionToVn into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1972 Reviewed-by: Guillermo Bonet <guillermo@verdnatura.es>
This commit is contained in:
commit
4592429b3d
|
@ -0,0 +1,32 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn`.`intrastat_estimateNet`(
|
||||
vSelf INT,
|
||||
vStems 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 vStems Número de unidades
|
||||
* @return vNet
|
||||
*/
|
||||
DECLARE vNet DOUBLE;
|
||||
|
||||
SELECT ROUND(vStems / (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 ;
|
|
@ -1,20 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` FUNCTION `vn2008`.`intrastat_neto`(intINSTRASTAT INTEGER,intUNIDADES INTEGER)
|
||||
RETURNS double
|
||||
DETERMINISTIC
|
||||
BEGIN
|
||||
|
||||
DECLARE n DOUBLE;
|
||||
|
||||
SELECT ROUND(intUNIDADES / (SUM(MEDIA) / COUNT(media)), 2) INTO n FROM
|
||||
(SELECT *, unidades / neto MEDIA
|
||||
FROM intrastat_data
|
||||
WHERE intrastat_id = intINSTRASTAT AND neto
|
||||
AND unidades > 0
|
||||
ORDER BY odbc_date DESC
|
||||
LIMIT 20) t;
|
||||
-- JGF 01/06 per a evitar Kg en negatiu
|
||||
RETURN n/2;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue