7430_devToTest #2490

Merged
alexm merged 306 commits from 7430_devToTest into test 2024-05-21 09:15:04 +00:00
2 changed files with 48 additions and 53 deletions
Showing only changes of commit cc941de606 - Show all commits

View File

@ -8,7 +8,7 @@ BEGIN
*/
DROP TEMPORARY TABLE IF EXISTS tmp.buyRecalc;
CREATE TEMPORARY TABLE tmp.buyRecalc
CREATE TEMPORARY TABLE tmp.buyRecalc
SELECT vBuyFk id;
CALL buy_recalcPrices();

View File

@ -1,7 +1,7 @@
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_devalueA2`(
vSelf INT,
vShelvingFK VARCHAR(10),
vItemFk INT,
vBuyingValue DECIMAL(10,4),
vQuantity INT
)
@ -11,8 +11,8 @@ BEGIN
* Si no existe el item A2 lo crea y genera los movimientos de las entradas
* de almacén y shelvings correspondientes
*
* @param vSelf Id de artículo a devaluar
* @param vShelvingFK Ubicación actual del artículo
* @param vItemFk Id de artículo a devaluar
* @param vBuyingValue Nuevo precio de coste
*/
DECLARE vItemA2Fk INT;
@ -26,7 +26,7 @@ BEGIN
DECLARE vCacheFk INT;
DECLARE vLastEntryFk INT;
DECLARE vCurrentVisible INT;
DECLARE vInventoryTravelFk INT;
DECLARE vDevalueTravelFk INT;
DECLARE vCurdate DATE;
DECLARE CONTINUE HANDLER FOR SQLEXCEPTION
@ -35,7 +35,7 @@ BEGIN
RESIGNAL;
END;
IF (SELECT TRUE FROM item WHERE id = vItemFk AND (category <> 'A1' OR category IS NULL)) THEN
IF (SELECT TRUE FROM item WHERE id = vSelf AND (category <> 'A1' OR category IS NULL)) THEN
CALL util.throw('Item has not category A1');
END IF;
@ -47,11 +47,15 @@ BEGIN
CALL util.throw ('Operator has not a valid warehouse');
END IF;
IF vQuantity <= 0 OR vQuantity IS NULL THEN
CALL util.throw ('The quantity is incorrect');
END IF;
SELECT util.VN_CURDATE() INTO vCurdate;
SELECT t.id INTO vInventoryTravelFk
SELECT t.id INTO vDevalueTravelFk
FROM travel t
JOIN travelConfig tc
JOIN travelConfig tc
WHERE t.shipped = vCurdate
AND t.landed = vCurdate
AND t.warehouseInFk = vWarehouseFk
@ -59,7 +63,7 @@ BEGIN
AND t.agencyModeFk = tc.devalueAgencyModeFk
LIMIT 1;
IF NOT vInventoryTravelFk OR vInventoryTravelFk IS NULL THEN
IF NOT vDevalueTravelFk OR vDevalueTravelFk IS NULL THEN
INSERT INTO travel (
shipped,
landed,
@ -76,14 +80,14 @@ BEGIN
TRUE,
tc.devalueAgencyModeFk
FROM travelConfig tc;
SET vInventoryTravelFk = LAST_INSERT_ID();
SET vDevalueTravelFk = LAST_INSERT_ID();
END IF;
SELECT id, dated INTO vTargetEntryFk, vTargetEntryDate
SELECT id, DATE(dated) INTO vTargetEntryFk, vTargetEntryDate
FROM `entry` e
WHERE created = vCurdate
WHERE DATE(dated) = vCurdate
AND typeFk ='devaluation'
AND travelFk = vInventoryTravelFk
AND travelFk = vDevalueTravelFk
ORDER BY created DESC
LIMIT 1;
@ -92,23 +96,31 @@ BEGIN
SELECT b.entryFk, bu.buyFk INTO vLastEntryFk,vLastBuyFk
FROM tmp.buyUltimate bu
JOIN vn.buy b ON b.id =bu.buyFk
WHERE bu.itemFk = vItemFk
WHERE bu.itemFk = vSelf
AND bu.warehouseFk = vWarehouseFk;
SELECT id,visible INTO vTargetItemShelvingFk,vCurrentVisible
IF vLastEntryFk IS NULL OR vLastBuyFk IS NULL THEN
CALL util.throw ('The item has not a buy');
END IF;
SELECT id,visible INTO vTargetItemShelvingFk, vCurrentVisible
FROM itemShelving
WHERE shelvingFk = vShelvingFK COLLATE utf8mb3_general_ci
AND itemFk = vItemFk
AND itemFk = vSelf
LIMIT 1;
IF vQuantity >= vCurrentVisible THEN
IF vCurrentVisible IS NULL THEN
CALL util.throw ('The shelving has not a visible for this item');
END IF;
IF vQuantity > vCurrentVisible THEN
CALL util.throw('Quantity is greater than visible');
END IF;
START TRANSACTION;
IF NOT vTargetEntryFk OR vTargetEntryFk IS NULL
OR NOT vTargetEntryDate <=> vCurdate THEN
OR NOT vTargetEntryDate <=> vCurdate THEN
INSERT INTO entry(
travelFk,
supplierFk,
@ -119,7 +131,7 @@ BEGIN
clonedFrom,
typeFk
)
SELECT vInventoryTravelFk,
SELECT vDevalueTravelFk,
supplierFk,
vCurdate,
commission,
@ -149,7 +161,7 @@ BEGIN
i.EmbalageCode,
i.quality
FROM item i
WHERE i.id = vItemFk
WHERE i.id = vSelf
)i2 ON i2.name <=> i.name
AND i2.subname <=> i.subname
AND i2.value5 <=> i.value5
@ -193,18 +205,6 @@ BEGIN
isActive,
longName,
subName,
tag5,
value5,
tag6,
value6,
tag7,
value7,
tag8,
value8,
tag9,
value9,
tag10,
value10,
minimum,
upToDown,
supplyResponseFk,
@ -250,19 +250,7 @@ BEGIN
expenseFk,
isActive,
longName,
subName,
tag5,
value5,
tag6,
value6,
tag7,
value7,
tag8,
value8,
tag9,
value9,
tag10,
value10,
subName,
minimum,
upToDown,
supplyResponseFk,
@ -283,20 +271,25 @@ BEGIN
recycledPlastic,
nonRecycledPlastic
FROM item
WHERE id = vItemFk;
WHERE id = vSelf;
SET vItemA2Fk = LAST_INSERT_ID();
INSERT INTO itemTag (itemFk, tagFk, `value`, intValue, priority, editorFk)
SELECT vItemA2Fk, tagFk, `value`, intValue, priority, editorFk
FROM itemTag
WHERE id = vSelf;
UPDATE itemTaxCountry itc
JOIN itemTaxCountry itc2 ON itc2.itemFk = vItemFk
JOIN itemTaxCountry itc2 ON itc2.itemFk = vSelf
AND itc2.countryFk = itc.countryFk
SET itc2.taxClassFk = itc.taxClassFk
WHERE itc.id = vItemA2Fk;
INSERT INTO itemBotanical (itemFk, genusFk, specieFk)
SELECT vItemA2Fk, genusFk, specieFk
FROM itemBotanical
WHERE itemFk = vItemFk;
WHERE itemFk = vSelf;
END IF;
IF vQuantity = vCurrentVisible THEN
@ -334,7 +327,7 @@ BEGIN
SELECT vTargetEntryFk,
itemFk,
- LEAST(vQuantity, vCurrentVisible),
vBuyingValue,
buyingValue,
freightValue,
TRUE,
stickers,
@ -381,7 +374,7 @@ BEGIN
FROM vn.buy
WHERE id = vLastBuyFk;
INSERT INTO itemShelving (
INSERT IGNORE INTO itemShelving (
itemFk,
shelvingFk,
visible,
@ -392,15 +385,17 @@ BEGIN
isChecked)
SELECT vItemA2Fk,
shelvingFk,
vQuantity,
vQuantity ,
`grouping`,
packing,
packagingFk,
account.myUser_getId(),
isChecked
FROM itemShelving
WHERE itemFK = vItemFk
AND shelvingFk = vShelvingFK COLLATE utf8mb3_general_ci;
WHERE itemFK = vSelf
AND shelvingFk = vShelvingFK COLLATE utf8mb3_general_ci
ON DUPLICATE KEY UPDATE
visible = vQuantity + VALUES(visible);
COMMIT;
CALL cache.visible_refresh(vCacheFk, TRUE, vWarehouseFk);