salix/db/versions/.archive/10171-crimsonCarnation/01-itemWeight.sql

27 lines
965 B
MySQL
Raw Permalink Normal View History

ALTER TABLE vn.item ADD weightByPiece int unsigned NULL
COMMENT 'peso por defecto para un articulo por tallo/unidad';
/*
-- actualizamos con los valores del itemCost, o de la ultima compra, o de la densidad * volumen
UPDATE vn.itemCost ic
JOIN cache.last_buy lb ON lb.item_id = ic.itemFk and lb.warehouse_id = ic.warehouseFk
JOIN vn.buy b ON b.id = lb.buy_id
JOIN vn.item i ON i.id = ic.itemFk
SET ic.grams = COALESCE(
(b.weight * 1000) / b.packing,
i.density * (cm3delivery / 1000000) * 1000);
UPDATE vn.item i
JOIN vn.itemCost ic ON ic.itemFk = i.id and ic.warehouseFk = 60
SET i.weightByPiece = ic.grams
WHERE i.weightByPiece IS NULL;
UPDATE vn.item i
JOIN vn.itemCost ic ON ic.itemFk = i.id and ic.warehouseFk = 7
SET i.weightByPiece = ic.grams
WHERE weightByPiece IS NULL;
UPDATE vn.item i
JOIN vn.itemCost ic ON ic.itemFk = i.id
SET i.weightByPiece = ic.grams
WHERE i.weightByPiece IS NULL
AND ic.warehouseFk NOT IN (60,7);*/