feat: refs #7438 Added volume to item_valuateInventory #2505
|
@ -1,5 +1,7 @@
|
||||||
DELIMITER $$
|
DELIMITER $$
|
||||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_ValuateInventory`(vDated DATE, vIsDetailed BOOLEAN)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_valuateInventory`(
|
||||||
|
vDated DATE
|
||||||
|
)
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE vInventoried DATE;
|
DECLARE vInventoried DATE;
|
||||||
DECLARE vHasNotInventory BOOLEAN DEFAULT FALSE;
|
DECLARE vHasNotInventory BOOLEAN DEFAULT FALSE;
|
||||||
|
@ -15,8 +17,7 @@ BEGIN
|
||||||
SELECT tr.landed INTO vInventoried
|
SELECT tr.landed INTO vInventoried
|
||||||
FROM travel tr
|
FROM travel tr
|
||||||
JOIN `entry` e ON e.travelFk = tr.id
|
JOIN `entry` e ON e.travelFk = tr.id
|
||||||
JOIN entryConfig ec
|
WHERE tr.landed <= vDateDayEnd
|
||||||
WHERE landed <= vDateDayEnd
|
|
||||||
AND e.supplierFk = vInventorySupplierFk
|
AND e.supplierFk = vInventorySupplierFk
|
||||||
ORDER BY tr.landed DESC
|
ORDER BY tr.landed DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
@ -27,8 +28,7 @@ BEGIN
|
||||||
SELECT landed INTO vInventoryClone
|
SELECT landed INTO vInventoryClone
|
||||||
FROM travel tr
|
FROM travel tr
|
||||||
JOIN `entry` e ON e.travelFk = tr.id
|
JOIN `entry` e ON e.travelFk = tr.id
|
||||||
JOIN entryConfig ec
|
WHERE tr.landed >= vDated
|
||||||
WHERE landed >= vDated
|
|
||||||
AND e.supplierFk = vInventorySupplierFk
|
AND e.supplierFk = vInventorySupplierFk
|
||||||
ORDER BY landed ASC
|
ORDER BY landed ASC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
@ -38,13 +38,14 @@ BEGIN
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tInventory(
|
CREATE OR REPLACE TEMPORARY TABLE tInventory(
|
||||||
warehouseFk SMALLINT,
|
warehouseFk SMALLINT,
|
||||||
itemFk BIGINT,
|
itemFk BIGINT,
|
||||||
quantity INT,
|
quantity INT,
|
||||||
cost DOUBLE DEFAULT 0,
|
volume DECIMAL(10,2),
|
||||||
total DOUBLE DEFAULT 0,
|
cost DOUBLE DEFAULT 0,
|
||||||
warehouseInventory VARCHAR(20),
|
total DOUBLE DEFAULT 0,
|
||||||
PRIMARY KEY (warehouseInventory, itemFk) USING HASH
|
warehouseInventory VARCHAR(20),
|
||||||
|
PRIMARY KEY (warehouseInventory, itemFk) USING HASH
|
||||||
)
|
)
|
||||||
ENGINE = MEMORY;
|
ENGINE = MEMORY;
|
||||||
|
|
||||||
|
@ -60,9 +61,8 @@ BEGIN
|
||||||
JOIN `entry` e ON e.id = b.entryFk
|
JOIN `entry` e ON e.id = b.entryFk
|
||||||
JOIN travel tr ON tr.id = e.travelFk
|
JOIN travel tr ON tr.id = e.travelFk
|
||||||
JOIN itemType t ON t.id = i.typeFk
|
JOIN itemType t ON t.id = i.typeFk
|
||||||
JOIN warehouse w ON w.id = warehouseInFk
|
JOIN warehouse w ON w.id = tr.warehouseInFk
|
||||||
JOIN entryConfig ec
|
WHERE tr.landed = vDateDayEnd
|
||||||
WHERE landed = vDateDayEnd
|
|
||||||
AND e.supplierFk = vInventorySupplierFk
|
AND e.supplierFk = vInventorySupplierFk
|
||||||
AND w.valuatedInventory
|
AND w.valuatedInventory
|
||||||
AND t.isInventory
|
AND t.isInventory
|
||||||
|
@ -78,9 +78,8 @@ BEGIN
|
||||||
JOIN `entry` e ON e.id = b.entryFk
|
JOIN `entry` e ON e.id = b.entryFk
|
||||||
JOIN travel tr ON tr.id = e.travelFk
|
JOIN travel tr ON tr.id = e.travelFk
|
||||||
JOIN itemType t ON t.id = i.typeFk
|
JOIN itemType t ON t.id = i.typeFk
|
||||||
JOIN warehouse w ON w.id = warehouseInFk
|
JOIN warehouse w ON w.id = tr.warehouseInFk
|
||||||
JOIN entryConfig ec
|
WHERE tr.landed = vInventoried
|
||||||
WHERE landed = vInventoried
|
|
||||||
AND e.supplierFk = vInventorySupplierFk
|
AND e.supplierFk = vInventorySupplierFk
|
||||||
AND w.valuatedInventory
|
AND w.valuatedInventory
|
||||||
AND t.isInventory
|
AND t.isInventory
|
||||||
|
@ -99,7 +98,6 @@ BEGIN
|
||||||
JOIN travel tr ON tr.id = e.travelFk
|
JOIN travel tr ON tr.id = e.travelFk
|
||||||
JOIN itemType t ON t.id = i.typeFk
|
JOIN itemType t ON t.id = i.typeFk
|
||||||
JOIN warehouse w ON w.id = tr.warehouseInFk
|
JOIN warehouse w ON w.id = tr.warehouseInFk
|
||||||
JOIN entryConfig ec
|
|
||||||
WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd
|
WHERE tr.landed BETWEEN vInventoried AND vDateDayEnd
|
||||||
AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, TRUE)
|
AND IF(tr.landed = util.VN_CURDATE(), tr.isReceived, TRUE)
|
||||||
AND NOT e.isRaid
|
AND NOT e.isRaid
|
||||||
|
@ -183,52 +181,37 @@ BEGIN
|
||||||
AND e.isConfirmed
|
AND e.isConfirmed
|
||||||
ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity);
|
ON DUPLICATE KEY UPDATE tInventory.quantity = tInventory.quantity + (b.quantity);
|
||||||
|
|
||||||
CALL vn.buyUltimate(NULL, vDateDayEnd);
|
CALL buyUltimate(NULL, vDateDayEnd);
|
||||||
|
|
||||||
|
DELETE FROM tInventory WHERE quantity IS NULL OR NOT quantity;
|
||||||
|
|
||||||
UPDATE tInventory i
|
UPDATE tInventory i
|
||||||
JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.itemFk = bu.itemFk
|
JOIN tmp.buyUltimate bu ON i.warehouseFk = bu.warehouseFk AND i.itemFk = bu.itemFk
|
||||||
JOIN buy b ON b.id = bu.buyFk
|
JOIN buy b ON b.id = bu.buyFk
|
||||||
SET total = i.quantity * (IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0)),
|
LEFT JOIN itemCost ic ON ic.itemFk = i.itemFk
|
||||||
cost = IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0)
|
AND ic.warehouseFk = i.warehouseFk
|
||||||
WHERE i.quantity;
|
SET i.total = i.quantity * (IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0)),
|
||||||
|
i.cost = IFNULL(b.buyingValue, 0) + IFNULL(b.packageValue, 0) + IFNULL(b.freightValue, 0) + IFNULL(b.comissionValue, 0),
|
||||||
|
i.volume = i.quantity * ic.cm3delivery / 1000000;
|
||||||
|
|
||||||
DELETE FROM tInventory
|
SELECT ti.warehouseFk,
|
||||||
WHERE quantity IS NULL OR NOT quantity;
|
i.id,
|
||||||
|
i.longName,
|
||||||
IF vIsDetailed THEN
|
i.size,
|
||||||
SELECT ti.warehouseFk,
|
ti.quantity,
|
||||||
i.id itemFk,
|
ti.volume,
|
||||||
i.longName,
|
tp.name itemTypeName,
|
||||||
i.size,
|
ic.name itemCategoryName,
|
||||||
ti.quantity,
|
ti.cost,
|
||||||
tp.name Tipo,
|
ti.total,
|
||||||
ic.name Reino,
|
ti.warehouseInventory
|
||||||
ti.cost,
|
FROM tInventory ti
|
||||||
CAST(ti.total AS DECIMAL(10, 2)) total,
|
JOIN warehouse w ON w.id = warehouseFk
|
||||||
ti.warehouseInventory almacen
|
JOIN item i ON i.id = ti.itemFk
|
||||||
FROM tInventory ti
|
JOIN itemType tp ON tp.id = i.typeFk
|
||||||
JOIN warehouse w ON w.id = warehouseFk
|
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
||||||
JOIN item i ON i.id = ti.itemFk
|
WHERE w.valuatedInventory
|
||||||
JOIN itemType tp ON tp.id = i.typeFk
|
AND ti.total > 0;
|
||||||
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
|
||||||
WHERE w.valuatedInventory
|
|
||||||
AND ti.total > 0
|
|
||||||
ORDER BY ti.total DESC;
|
|
||||||
ELSE
|
|
||||||
SELECT i.warehouseInventory Almacen,
|
|
||||||
ic.name Reino,
|
|
||||||
CAST(i.total AS DECIMAL(10, 2)) Euros,
|
|
||||||
w.code Comprador,
|
|
||||||
it.id
|
|
||||||
FROM tInventory i
|
|
||||||
JOIN warehouse wh ON wh.id = warehouseFk
|
|
||||||
JOIN item it ON it.id = i.itemFk
|
|
||||||
JOIN itemType itp ON itp.id = it.typeFk
|
|
||||||
LEFT JOIN worker w ON w.id = itp.workerFk
|
|
||||||
JOIN itemCategory ic ON ic.id = itp.categoryFk
|
|
||||||
WHERE wh.valuatedInventory
|
|
||||||
AND i.total > 0;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
DROP TEMPORARY TABLE
|
DROP TEMPORARY TABLE
|
||||||
tmp.buyUltimate,
|
tmp.buyUltimate,
|
Loading…
Reference in New Issue