refactor: refs #6453 order_confirmWithUser
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
e64f56cff1
commit
460723bd7a
|
@ -28,11 +28,8 @@ BEGIN
|
||||||
DECLARE vClientId INT;
|
DECLARE vClientId INT;
|
||||||
DECLARE vCompanyId INT;
|
DECLARE vCompanyId INT;
|
||||||
DECLARE vAgencyModeId INT;
|
DECLARE vAgencyModeId INT;
|
||||||
DECLARE TICKET_FREE INT DEFAULT 2;
|
|
||||||
DECLARE vCalc INT;
|
DECLARE vCalc INT;
|
||||||
DECLARE vIsLogifloraItem BOOL;
|
DECLARE vIsLogifloraItem BOOL;
|
||||||
DECLARE vOldQuantity INT;
|
|
||||||
DECLARE vNewQuantity INT;
|
|
||||||
DECLARE vIsTaxDataChecked BOOL;
|
DECLARE vIsTaxDataChecked BOOL;
|
||||||
|
|
||||||
DECLARE cDates CURSOR FOR
|
DECLARE cDates CURSOR FOR
|
||||||
|
@ -40,14 +37,15 @@ BEGIN
|
||||||
FROM `order` o
|
FROM `order` o
|
||||||
JOIN order_row r ON r.order_id = o.id
|
JOIN order_row r ON r.order_id = o.id
|
||||||
LEFT JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = r.warehouse_id
|
LEFT JOIN tmp.zoneGetShipped zgs ON zgs.warehouseFk = r.warehouse_id
|
||||||
WHERE o.id = vSelf AND r.amount != 0
|
WHERE o.id = vSelf
|
||||||
|
AND r.amount
|
||||||
GROUP BY r.warehouse_id;
|
GROUP BY r.warehouse_id;
|
||||||
|
|
||||||
DECLARE cRows CURSOR FOR
|
DECLARE cRows CURSOR FOR
|
||||||
SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate, i.isFloramondo
|
SELECT r.id, r.item_id, i.name, r.amount, r.price, r.rate, i.isFloramondo
|
||||||
FROM order_row r
|
FROM order_row r
|
||||||
JOIN vn.item i ON i.id = r.item_id
|
JOIN vn.item i ON i.id = r.item_id
|
||||||
WHERE r.amount != 0
|
WHERE r.amount
|
||||||
AND r.warehouse_id = vWarehouse
|
AND r.warehouse_id = vWarehouse
|
||||||
AND r.order_id = vSelf
|
AND r.order_id = vSelf
|
||||||
ORDER BY r.rate DESC;
|
ORDER BY r.rate DESC;
|
||||||
|
@ -62,10 +60,20 @@ BEGIN
|
||||||
END;
|
END;
|
||||||
|
|
||||||
-- Carga los datos del pedido
|
-- Carga los datos del pedido
|
||||||
SELECT o.date_send, o.address_id, o.note, a.clientFk,
|
SELECT o.date_send,
|
||||||
o.company_id, o.agency_id, c.isTaxDataChecked
|
o.address_id,
|
||||||
INTO vDelivery, vAddress, vNotes, vClientId,
|
o.note,
|
||||||
vCompanyId, vAgencyModeId, vIsTaxDataChecked
|
a.clientFk,
|
||||||
|
o.company_id,
|
||||||
|
o.agency_id,
|
||||||
|
c.isTaxDataChecked
|
||||||
|
INTO vDelivery,
|
||||||
|
vAddress,
|
||||||
|
vNotes,
|
||||||
|
vClientId,
|
||||||
|
vCompanyId,
|
||||||
|
vAgencyModeId,
|
||||||
|
vIsTaxDataChecked
|
||||||
FROM hedera.`order` o
|
FROM hedera.`order` o
|
||||||
JOIN vn.address a ON a.id = o.address_id
|
JOIN vn.address a ON a.id = o.address_id
|
||||||
JOIN vn.client c ON c.id = a.clientFk
|
JOIN vn.client c ON c.id = a.clientFk
|
||||||
|
@ -73,11 +81,11 @@ BEGIN
|
||||||
|
|
||||||
-- Verifica si el cliente tiene los datos comprobados
|
-- Verifica si el cliente tiene los datos comprobados
|
||||||
IF NOT vIsTaxDataChecked THEN
|
IF NOT vIsTaxDataChecked THEN
|
||||||
CALL util.throw ('clientNotVerified');
|
CALL util.throw('clientNotVerified');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Carga las fechas de salida de cada almacen
|
-- Carga las fechas de salida de cada almacen
|
||||||
CALL vn.zone_getShipped (vDelivery, vAddress, vAgencyModeId, FALSE);
|
CALL vn.zone_getShipped(vDelivery, vAddress, vAgencyModeId, FALSE);
|
||||||
|
|
||||||
-- Trabajador que realiza la accion
|
-- Trabajador que realiza la accion
|
||||||
IF vUserId IS NULL THEN
|
IF vUserId IS NULL THEN
|
||||||
|
@ -94,7 +102,7 @@ BEGIN
|
||||||
FROM order_row WHERE order_id = vSelf AND amount > 0;
|
FROM order_row WHERE order_id = vSelf AND amount > 0;
|
||||||
|
|
||||||
IF NOT vOk THEN
|
IF NOT vOk THEN
|
||||||
CALL util.throw ('ORDER_EMPTY');
|
CALL util.throw('ORDER_EMPTY');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Crea los tickets del pedido
|
-- Crea los tickets del pedido
|
||||||
|
@ -112,8 +120,8 @@ BEGIN
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Busca un ticket existente que coincida con los parametros
|
-- Busca un ticket existente que coincida con los parametros
|
||||||
WITH tPrevia AS
|
WITH tPrevia AS (
|
||||||
(SELECT DISTINCT s.ticketFk
|
SELECT DISTINCT s.ticketFk
|
||||||
FROM vn.sale s
|
FROM vn.sale s
|
||||||
JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
|
JOIN vn.saleGroupDetail sgd ON sgd.saleFk = s.id
|
||||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||||
|
@ -124,8 +132,7 @@ BEGIN
|
||||||
JOIN vn.alertLevel al ON al.code = 'FREE'
|
JOIN vn.alertLevel al ON al.code = 'FREE'
|
||||||
LEFT JOIN tPrevia tp ON tp.ticketFk = t.id
|
LEFT JOIN tPrevia tp ON tp.ticketFk = t.id
|
||||||
LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id
|
LEFT JOIN vn.ticketState tls on tls.ticketFk = t.id
|
||||||
JOIN hedera.`order` o
|
JOIN hedera.`order` o ON o.address_id = t.addressFk
|
||||||
ON o.address_id = t.addressFk
|
|
||||||
AND vWarehouse = t.warehouseFk
|
AND vWarehouse = t.warehouseFk
|
||||||
AND o.date_send = t.landed
|
AND o.date_send = t.landed
|
||||||
AND DATE(t.shipped) = vShipment
|
AND DATE(t.shipped) = vShipment
|
||||||
|
@ -136,11 +143,8 @@ BEGIN
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
-- Crea el ticket en el caso de no existir uno adecuado
|
-- Crea el ticket en el caso de no existir uno adecuado
|
||||||
IF vTicket IS NULL
|
IF vTicket IS NULL THEN
|
||||||
THEN
|
|
||||||
|
|
||||||
SET vShipment = IFNULL(vShipment, util.VN_CURDATE());
|
SET vShipment = IFNULL(vShipment, util.VN_CURDATE());
|
||||||
|
|
||||||
CALL vn.ticket_add(
|
CALL vn.ticket_add(
|
||||||
vClientId,
|
vClientId,
|
||||||
vShipment,
|
vShipment,
|
||||||
|
@ -158,7 +162,7 @@ BEGIN
|
||||||
INSERT INTO vn.ticketTracking
|
INSERT INTO vn.ticketTracking
|
||||||
SET ticketFk = vTicket,
|
SET ticketFk = vTicket,
|
||||||
userFk = vUserId,
|
userFk = vUserId,
|
||||||
stateFk = TICKET_FREE;
|
stateFk = (SELECT id FROM vn.state WHERE code = 'FREE');
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
INSERT IGNORE INTO vn.orderTicket
|
INSERT IGNORE INTO vn.orderTicket
|
||||||
|
@ -166,21 +170,17 @@ BEGIN
|
||||||
ticketFk = vTicket;
|
ticketFk = vTicket;
|
||||||
|
|
||||||
-- Añade las notas
|
-- Añade las notas
|
||||||
|
IF vNotes IS NOT NULL AND vNotes <> '' THEN
|
||||||
IF vNotes IS NOT NULL AND vNotes != ''
|
|
||||||
THEN
|
|
||||||
INSERT INTO vn.ticketObservation SET
|
INSERT INTO vn.ticketObservation SET
|
||||||
ticketFk = vTicket,
|
ticketFk = vTicket,
|
||||||
observationTypeFk = 4 /* salesperson */ ,
|
observationTypeFk = (SELECT id FROM vn.observationType WHERE code = 'salesPerson'),
|
||||||
`description` = vNotes
|
`description` = vNotes
|
||||||
ON DUPLICATE KEY UPDATE
|
ON DUPLICATE KEY UPDATE
|
||||||
`description` = CONCAT(VALUES(`description`),'. ', `description`);
|
`description` = CONCAT(VALUES(`description`),'. ', `description`);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Añade los movimientos y sus componentes
|
-- Añade los movimientos y sus componentes
|
||||||
|
|
||||||
OPEN cRows;
|
OPEN cRows;
|
||||||
|
|
||||||
lRows: LOOP
|
lRows: LOOP
|
||||||
SET vDone = FALSE;
|
SET vDone = FALSE;
|
||||||
FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem;
|
FETCH cRows INTO vRowId, vItem, vConcept, vAmount, vPrice, vRate, vIsLogifloraItem;
|
||||||
|
@ -191,7 +191,7 @@ BEGIN
|
||||||
|
|
||||||
SET vSale = NULL;
|
SET vSale = NULL;
|
||||||
|
|
||||||
SELECT s.id, s.quantity INTO vSale, vOldQuantity
|
SELECT s.id INTO vSale
|
||||||
FROM vn.sale s
|
FROM vn.sale s
|
||||||
WHERE ticketFk = vTicket
|
WHERE ticketFk = vTicket
|
||||||
AND price = vPrice
|
AND price = vPrice
|
||||||
|
@ -204,10 +204,6 @@ BEGIN
|
||||||
SET quantity = quantity + vAmount,
|
SET quantity = quantity + vAmount,
|
||||||
originalQuantity = quantity
|
originalQuantity = quantity
|
||||||
WHERE id = vSale;
|
WHERE id = vSale;
|
||||||
|
|
||||||
SELECT s.quantity INTO vNewQuantity
|
|
||||||
FROM vn.sale s
|
|
||||||
WHERE id = vSale;
|
|
||||||
ELSE
|
ELSE
|
||||||
-- Obtiene el coste
|
-- Obtiene el coste
|
||||||
SELECT SUM(rc.`price`) valueSum INTO vPriceFixed
|
SELECT SUM(rc.`price`) valueSum INTO vPriceFixed
|
||||||
|
@ -236,7 +232,8 @@ BEGIN
|
||||||
GROUP BY vSale, rc.componentFk;
|
GROUP BY vSale, rc.componentFk;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
UPDATE order_row SET Id_Movimiento = vSale
|
UPDATE order_row
|
||||||
|
SET Id_Movimiento = vSale
|
||||||
WHERE id = vRowId;
|
WHERE id = vRowId;
|
||||||
|
|
||||||
-- Inserta en putOrder si la compra es de Floramondo
|
-- Inserta en putOrder si la compra es de Floramondo
|
||||||
|
@ -245,13 +242,13 @@ BEGIN
|
||||||
|
|
||||||
SET @available := 0;
|
SET @available := 0;
|
||||||
|
|
||||||
SELECT GREATEST(0,available) INTO @available
|
SELECT GREATEST(0, available) INTO @available
|
||||||
FROM cache.availableNoRaids
|
FROM cache.availableNoRaids
|
||||||
WHERE calc_id = vCalc
|
WHERE calc_id = vCalc
|
||||||
AND item_id = vItem;
|
AND item_id = vItem;
|
||||||
|
|
||||||
UPDATE cache.availableNoRaids
|
UPDATE cache.availableNoRaids
|
||||||
SET available = GREATEST(0,available - vAmount)
|
SET available = GREATEST(0, available - vAmount)
|
||||||
WHERE item_id = vItem
|
WHERE item_id = vItem
|
||||||
AND calc_id = vCalc;
|
AND calc_id = vCalc;
|
||||||
|
|
||||||
|
@ -283,13 +280,13 @@ BEGIN
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
END IF;
|
END IF;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
|
||||||
CLOSE cRows;
|
CLOSE cRows;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
|
|
||||||
CLOSE cDates;
|
CLOSE cDates;
|
||||||
|
|
||||||
UPDATE `order` SET confirmed = TRUE, confirm_date = util.VN_NOW()
|
UPDATE `order`
|
||||||
|
SET confirmed = TRUE,
|
||||||
|
confirm_date = util.VN_NOW()
|
||||||
WHERE id = vSelf;
|
WHERE id = vSelf;
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
|
|
Loading…
Reference in New Issue