refs #6498 procRefactor6 #2134

Merged
ivanm merged 8 commits from 6499-procRefactor6 into dev 2024-03-21 11:03:33 +00:00
1 changed files with 99 additions and 0 deletions
Showing only changes of commit 1ccec1e0fb - Show all commits

View File

@ -0,0 +1,99 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`absoluteInventoryHistory`(
vIdArticle INT, vWarehouse INT, vDate DATETIME)

Esto separalo, tipo:

   vItemFk INT,
   vWarehouse INT,
   vDate DATETIME
)
Esto separalo, tipo: ``` vItemFk 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
Review

Cambiar nombre de variable a vWarehouseFk y comentario a Id de almacén

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
Review
DECLARE vToday DATETIME DEFAULT util.VN_CURDATE();
``` DECLARE vToday DATETIME DEFAULT util.VN_CURDATE(); ```
SET vToday = util.VN_CURDATE();
guillermo marked this conversation as resolved
Review

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
Review
tr.isReceived ok,
``` 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

No poner números a pelo en el código, para ello:

AND s.id <> (SELECT supplierFk FROM inventoryConfig)
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,
(m.isPicked OR t.isLabeled OR t.refFk IS NOT NULL)
``` (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'
Review

'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

sum en mayuscula

sum en mayuscula
FROM historicalPast
WHERE Fecha < vDate;
SELECT p1.*, NULL v_virtual
FROM(
guillermo marked this conversation as resolved
Review

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 ;