refs #6493 refactorizar-procedimientos-vn2008-parte_2 #2235
|
@ -8,9 +8,9 @@ proc: BEGIN
|
||||||
* Calcular la disponibilidad dependiendo del almacen
|
* Calcular la disponibilidad dependiendo del almacen
|
||||||
* de origen y destino según la fecha.
|
* de origen y destino según la fecha.
|
||||||
*
|
*
|
||||||
jbreso marked this conversation as resolved
|
|||||||
* @param vWarehouseLanding almacén de llegada
|
* @param vWarehouseLanding Almacén de llegada
|
||||||
* @param vDated fecha del calculo para la disponibilidad de articulos
|
* @param vDated Fecha del calculo para la disponibilidad de articulos
|
||||||
* @param vWarehouseShipment almacén de destino
|
* @param vWarehouseShipment Almacén de destino
|
||||||
*/
|
*/
|
||||||
DECLARE vDatedFrom DATE;
|
DECLARE vDatedFrom DATE;
|
||||||
DECLARE vDatedTo DATETIME;
|
DECLARE vDatedTo DATETIME;
|
||||||
|
@ -23,14 +23,14 @@ proc: BEGIN
|
||||||
|
|
||||||
CALL item_getStock (vWarehouseLanding, vDated, NULL);
|
CALL item_getStock (vWarehouseLanding, vDated, NULL);
|
||||||
jbreso marked this conversation as resolved
carlosap
commented
Salto de línea innecesario Salto de línea innecesario
|
|||||||
|
|
||||||
-- Calcula algunos parámetros necesarios
|
-- Calcula algunos parámetros necesarios.
|
||||||
SET vDatedFrom = TIMESTAMP(vDated, '00:00:00');
|
SET vDatedFrom = TIMESTAMP(vDated, '00:00:00');
|
||||||
SET vDatedTo = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDated), '23:59:59');
|
SET vDatedTo = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDated), '23:59:59');
|
||||||
SELECT FechaInventario INTO vDatedInventory FROM tblContadores;
|
SELECT FechaInventario INTO vDatedInventory FROM tblContadores;
|
||||||
SELECT SUBTIME(util.VN_NOW(), reserveTime) INTO vDatedReserve
|
SELECT SUBTIME(util.VN_NOW(), reserveTime) INTO vDatedReserve
|
||||||
FROM hedera.orderConfig;
|
FROM hedera.orderConfig;
|
||||||
|
|
||||||
-- Calcula el ultimo dia de vida para cada producto
|
-- Calcula el ultimo dia de vida para cada producto.
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tItemRange
|
CREATE OR REPLACE TEMPORARY TABLE tItemRange
|
||||||
(PRIMARY KEY (itemFk))
|
(PRIMARY KEY (itemFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
|
@ -89,15 +89,15 @@ proc: BEGIN
|
||||||
t.landed,
|
t.landed,
|
||||||
b.quantity
|
b.quantity
|
||||||
FROM buy b
|
FROM buy b
|
||||||
JOIN entry e ON b.entryFk = e.id
|
JOIN entry e ON b.entryFk = e.id
|
||||||
JOIN travel t ON t.id = e.travelFk
|
JOIN travel t ON t.id = e.travelFk
|
||||||
JOIN tItemRangeLive ir ON ir.itemFk = b.itemFk
|
JOIN tItemRangeLive ir ON ir.itemFk = b.itemFk
|
||||||
WHERE NOT e.isExcludedFromAvailable
|
WHERE NOT e.isExcludedFromAvailable
|
||||||
AND b.quantity <> 0
|
AND b.quantity <> 0
|
||||||
AND NOT e.isRaid
|
AND NOT e.isRaid
|
||||||
AND t.warehouseInFk = vWarehouseLanding
|
AND t.warehouseInFk = vWarehouseLanding
|
||||||
AND t.landed >= vDatedFrom
|
AND t.landed >= vDatedFrom
|
||||||
AND (ir.dated IS NULL OR t.landed <= ir.dated)
|
AND (ir.dated IS NULL OR t.landed <= ir.dated)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT i.itemFk, vWarehouseLanding, i.shipped, i.quantity
|
SELECT i.itemFk, vWarehouseLanding, i.shipped, i.quantity
|
||||||
FROM itemEntryOut i
|
FROM itemEntryOut i
|
||||||
|
|
|
@ -130,23 +130,26 @@ BEGIN
|
||||||
-- Añadimos los gastos, para facilitar el formulario
|
-- Añadimos los gastos, para facilitar el formulario
|
||||||
UPDATE tmp.balance b
|
UPDATE tmp.balance b
|
||||||
JOIN balanceNestTree bnt on bnt.id = b.id
|
JOIN balanceNestTree bnt on bnt.id = b.id
|
||||||
JOIN (SELECT id, name
|
JOIN (
|
||||||
|
SELECT id, name
|
||||||
FROM expense
|
FROM expense
|
||||||
GROUP BY id) g ON g.id = bnt.expenseFk COLLATE utf8_general_ci
|
GROUP BY id
|
||||||
|
) g ON g.id = bnt.expenseFk COLLATE utf8_general_ci
|
||||||
SET b.expenseFk = g.id COLLATE utf8_general_ci,
|
SET b.expenseFk = g.id COLLATE utf8_general_ci,
|
||||||
b.expenseName = g.id COLLATE utf8_general_ci ;
|
b.expenseName = g.id COLLATE utf8_general_ci ;
|
||||||
|
|
||||||
-- Rellenamos los valores de primer nivel, los que corresponden a los gastos simples
|
-- Rellenamos los valores de primer nivel, los que corresponden
|
||||||
|
-- a los gastos simples.
|
||||||
WHILE vYears >= 0 DO
|
WHILE vYears >= 0 DO
|
||||||
SET vQuery = CONCAT(
|
SET vQuery = CONCAT(
|
||||||
'UPDATE tmp.balance b
|
'UPDATE tmp.balance b
|
||||||
JOIN
|
JOIN (
|
||||||
(SELECT expenseFk, SUM(amount) amount
|
SELECT expenseFk, SUM(amount) amount
|
||||||
FROM tmp.balanceDetail
|
FROM tmp.balanceDetail
|
||||||
WHERE year = ?
|
WHERE year = ?
|
||||||
GROUP BY expenseFk
|
GROUP BY expenseFk
|
||||||
) sub on sub.expenseFk = b.expenseFk COLLATE utf8_general_ci
|
) sub on sub.expenseFk = b.expenseFk COLLATE utf8_general_ci
|
||||||
SET ', util.quoteIdentifier(vCurYear - vYears), ' = - amount');
|
SET ', util.quoteIdentifier(vCurYear - vYears), ' = - amount');
|
||||||
|
|
||||||
EXECUTE IMMEDIATE vQuery
|
EXECUTE IMMEDIATE vQuery
|
||||||
USING vCurYear - vYears;
|
USING vCurYear - vYears;
|
||||||
|
@ -154,7 +157,7 @@ BEGIN
|
||||||
SET vYears = vYears - 1;
|
SET vYears = vYears - 1;
|
||||||
END WHILE;
|
END WHILE;
|
||||||
|
|
||||||
-- Añadimos las ventas
|
-- Añadimos las ventas.
|
||||||
EXECUTE IMMEDIATE CONCAT(
|
EXECUTE IMMEDIATE CONCAT(
|
||||||
'UPDATE tmp.balance b
|
'UPDATE tmp.balance b
|
||||||
JOIN (
|
JOIN (
|
||||||
|
@ -164,7 +167,7 @@ BEGIN
|
||||||
c.Gasto
|
c.Gasto
|
||||||
jbreso marked this conversation as resolved
guillermo
commented
Sobra un espacio Sobra un espacio
|
|||||||
FROM bs.ventas_contables c
|
FROM bs.ventas_contables c
|
||||||
JOIN tCompanyReceiving cr ON cr.companyFk = c.empresa_id
|
JOIN tCompanyReceiving cr ON cr.companyFk = c.empresa_id
|
||||||
WHERE month BETWEEN ? AND ?
|
WHERE month BETWEEN ? AND ?
|
||||||
GROUP BY c.Gasto
|
GROUP BY c.Gasto
|
||||||
) sub ON sub.gasto = b.expenseFk COLLATE utf8_general_ci
|
) sub ON sub.gasto = b.expenseFk COLLATE utf8_general_ci
|
||||||
SET b.', vTwoYearsAgo, '= IFNULL(b.', vTwoYearsAgo, ', 0) + sub.y2,
|
SET b.', vTwoYearsAgo, '= IFNULL(b.', vTwoYearsAgo, ', 0) + sub.y2,
|
||||||
|
@ -176,7 +179,7 @@ BEGIN
|
||||||
vStartingMonth,
|
vStartingMonth,
|
||||||
vEndingMonth;
|
vEndingMonth;
|
||||||
|
|
||||||
-- Ventas intra grupo
|
-- Ventas intra grupo.
|
||||||
IF NOT vInterGroupSalesIncluded THEN
|
IF NOT vInterGroupSalesIncluded THEN
|
||||||
|
|
||||||
SELECT lft, rgt INTO @grupoLft, @grupoRgt
|
SELECT lft, rgt INTO @grupoLft, @grupoRgt
|
||||||
|
@ -189,7 +192,7 @@ BEGIN
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Rellenamos el valor de los padres con la suma de los hijos
|
-- Rellenamos el valor de los padres con la suma de los hijos.
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.balance_aux
|
CREATE OR REPLACE TEMPORARY TABLE tmp.balance_aux
|
||||||
SELECT * FROM tmp.balance;
|
SELECT * FROM tmp.balance;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,5 @@ CREATE OR REPLACE PROCEDURE `vn`.`buy_recalcPricesByEntry`() BEGIN END;
|
||||||
CREATE OR REPLACE PROCEDURE `vn`.`buy_recalcPricesByBuy`() BEGIN END;
|
CREATE OR REPLACE PROCEDURE `vn`.`buy_recalcPricesByBuy`() BEGIN END;
|
||||||
|
|
||||||
GRANT EXECUTE ON PROCEDURE vn.balance_create TO `financialBoss`, `hrBoss`;
|
GRANT EXECUTE ON PROCEDURE vn.balance_create TO `financialBoss`, `hrBoss`;
|
||||||
|
|
||||||
GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByEntry TO `buyer`, `claimManager`, `employee`;
|
GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByEntry TO `buyer`, `claimManager`, `employee`;
|
||||||
|
|
||||||
GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByBuy TO `buyer`, `entryEditor`, `claimManager`, `employee`;
|
GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByBuy TO `buyer`, `entryEditor`, `claimManager`, `employee`;
|
Loading…
Reference in New Issue
Falta poner un espacio entre vWarehouse y Landing.
Además de que cuando se ponen los params, ninguna descripción del param debe de tener punto (viendo otros procs se puede comprobar)
vWarehouseLanding no se porque quieres el espacio la variable se llama asi, si pongo el espacio en esa también tendía que ponerlo en vWarehouseShipment?
Vale no sorry, queria decir que la primera letra del comentario de la variable debe de estár en mayuscula, así en todos los del PR