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