refs #6498 procRefactor6 #2134
|
@ -0,0 +1,99 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`(
|
||||
vIdArticle INT, vWarehouse INT, vDate DATETIME)
|
||||
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula y proporciona un historial de inventario absoluto
|
||||
* para un artículo específico en un almacén dado
|
||||
* hasta una fecha determinada.
|
||||
*
|
||||
* @param vIdArticle Id de artículo
|
||||
* @param vWarehouse Almacén
|
||||
guillermo marked this conversation as resolved
guillermo
commented
Cambiar nombre de variable a vWarehouseFk y comentario a Cambiar nombre de variable a vWarehouseFk y comentario a `Id de almacén`
|
||||
* @param vDate Fecha
|
||||
*/
|
||||
DECLARE vCalculatedInventory INT;
|
||||
DECLARE vToday DATETIME;
|
||||
guillermo marked this conversation as resolved
guillermo
commented
```
DECLARE vToday DATETIME DEFAULT util.VN_CURDATE();
```
|
||||
|
||||
SET vToday = util.VN_CURDATE();
|
||||
guillermo marked this conversation as resolved
guillermo
commented
Quitar linea Quitar linea
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE historicalPast
|
||||
ENGINE = MEMORY
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT tr.landed Fecha,
|
||||
b.quantity Entrada,
|
||||
NULL Salida,
|
||||
(tr.isReceived != FALSE) OK,
|
||||
guillermo marked this conversation as resolved
guillermo
commented
```
tr.isReceived ok,
```
|
||||
s.name Alias,
|
||||
e.invoiceNumber Referencia,
|
||||
e.id id,
|
||||
tr.isDelivered F5
|
||||
FROM buy b
|
||||
JOIN entry e ON e.id = b.entryFk
|
||||
JOIN travel tr ON tr.id = e.travelFk
|
||||
JOIN supplier s ON s.id = e.supplierFk
|
||||
WHERE tr.landed >= '2001-01-01'
|
||||
AND s.id <> 4
|
||||
guillermo
commented
No poner números a pelo en el código, para ello:
No poner números a pelo en el código, para ello:
```
AND s.id <> (SELECT supplierFk FROM inventoryConfig)
```
|
||||
AND vWarehouse IN (tr.warehouseInFk, 0)
|
||||
AND b.itemFk = vIdArticle
|
||||
AND e.isExcludedFromAvailable = 0
|
||||
AND e.isRaid = 0
|
||||
UNION ALL
|
||||
SELECT tr.shipped Fecha,
|
||||
NULL Entrada,
|
||||
b.quantity Salida,
|
||||
tr.isDelivered OK,
|
||||
s.name Alias,
|
||||
e.invoiceNumber Referencia,
|
||||
e.id id,
|
||||
tr.isDelivered F5
|
||||
FROM buy b
|
||||
JOIN entry e ON e.id = b.entryFk
|
||||
JOIN travel tr ON tr.id = e.travelFk
|
||||
JOIN supplier s ON s.id = e.supplierFk
|
||||
WHERE tr.shipped >= '2001-01-01'
|
||||
AND vWarehouse = tr.warehouseOutFk
|
||||
AND s.id <> 4
|
||||
AND b.itemFk = vIdArticle
|
||||
AND e.isExcludedFromAvailable = 0
|
||||
AND e.isRaid = 0
|
||||
UNION ALL
|
||||
SELECT t.shipped Fecha,
|
||||
NULL Entrada,
|
||||
m.quantity Salida,
|
||||
(m.isPicked <> 0 OR t.isLabeled <> 0 OR t.refFk IS NOT NULL) OK,
|
||||
guillermo
commented
```
(m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL)
```
|
||||
t.nickname Alias,
|
||||
t.refFk Referencia,
|
||||
t.id,
|
||||
t.isPrinted
|
||||
FROM sale m
|
||||
JOIN Tickets T USING (Id_Ticket)
|
||||
JOIN Clientes C ON C.Id_Cliente = T.Id_Cliente
|
||||
WHERE T.Fecha >= '2001-01-01'
|
||||
guillermo
commented
'2001-01-01' repetido en el código, crear variable con DEFAULT '2001-01-01' '2001-01-01' repetido en el código, crear variable con DEFAULT '2001-01-01'
|
||||
AND M.Id_Article = vIdArticle
|
||||
AND vWarehouse IN (T.warehouse_id , 0)
|
||||
) t1
|
||||
ORDER BY Fecha, Entrada DESC, OK DESC;
|
||||
|
||||
SELECT sum(Entrada) - sum(Salida) INTO vCalculatedInventory
|
||||
guillermo
commented
sum en mayuscula sum en mayuscula
|
||||
FROM historicalPast
|
||||
WHERE Fecha < vDate;
|
||||
|
||||
SELECT p1.*, NULL v_virtual
|
||||
FROM(
|
||||
guillermo marked this conversation as resolved
guillermo
commented
Espacio entre el FROM y el ( Espacio entre el FROM y el (
|
||||
SELECT vDate Fecha,
|
||||
vCalculatedInventory Entrada,
|
||||
NULL Salida,
|
||||
1 OK,
|
||||
'Inventario calculado' Alias,
|
||||
'' Referencia, 0 id,
|
||||
1 F5
|
||||
UNION ALL
|
||||
SELECT *
|
||||
FROM historicalPast
|
||||
WHERE Fecha >= vDate
|
||||
) p1;
|
||||
|
||||
DROP TEMPORARY TABLE historicalPast;
|
||||
END$$
|
||||
DELIMITER ;
|
Loading…
Reference in New Issue
Esto separalo, tipo: