Merge pull request 'feat: refs #7438 Added volume to item_valuateInventory' (!2505) from 7438-item_ValuateInventory into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #2505 Reviewed-by: Carlos Andrés <carlosap@verdnatura.es>
This commit is contained in:
commit
2c87730dba
|
@ -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;
|
||||||
|
@ -41,6 +41,7 @@ BEGIN
|
||||||
warehouseFk SMALLINT,
|
warehouseFk SMALLINT,
|
||||||
itemFk BIGINT,
|
itemFk BIGINT,
|
||||||
quantity INT,
|
quantity INT,
|
||||||
|
volume DECIMAL(10,2),
|
||||||
cost DOUBLE DEFAULT 0,
|
cost DOUBLE DEFAULT 0,
|
||||||
total DOUBLE DEFAULT 0,
|
total DOUBLE DEFAULT 0,
|
||||||
warehouseInventory VARCHAR(20),
|
warehouseInventory VARCHAR(20),
|
||||||
|
@ -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
|
|
||||||
WHERE quantity IS NULL OR NOT quantity;
|
|
||||||
|
|
||||||
IF vIsDetailed THEN
|
|
||||||
SELECT ti.warehouseFk,
|
SELECT ti.warehouseFk,
|
||||||
i.id itemFk,
|
i.id,
|
||||||
i.longName,
|
i.longName,
|
||||||
i.size,
|
i.size,
|
||||||
ti.quantity,
|
ti.quantity,
|
||||||
tp.name Tipo,
|
ti.volume,
|
||||||
ic.name Reino,
|
tp.name itemTypeName,
|
||||||
|
ic.name itemCategoryName,
|
||||||
ti.cost,
|
ti.cost,
|
||||||
CAST(ti.total AS DECIMAL(10, 2)) total,
|
ti.total,
|
||||||
ti.warehouseInventory almacen
|
ti.warehouseInventory
|
||||||
FROM tInventory ti
|
FROM tInventory ti
|
||||||
JOIN warehouse w ON w.id = warehouseFk
|
JOIN warehouse w ON w.id = warehouseFk
|
||||||
JOIN item i ON i.id = ti.itemFk
|
JOIN item i ON i.id = ti.itemFk
|
||||||
JOIN itemType tp ON tp.id = i.typeFk
|
JOIN itemType tp ON tp.id = i.typeFk
|
||||||
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
JOIN itemCategory ic ON ic.id = tp.categoryFk
|
||||||
WHERE w.valuatedInventory
|
WHERE w.valuatedInventory
|
||||||
AND ti.total > 0
|
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