update structure DB
This commit is contained in:
parent
7a5d8bdd03
commit
756614bd27
|
@ -1,17 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP function IF EXISTS `messageSend`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `messageSend`(vRecipient VARCHAR(255) CHARSET utf8, vMessage TEXT CHARSET utf8) RETURNS int(11)
|
||||
BEGIN
|
||||
DECLARE result INT;
|
||||
DECLARE vSenderFk INT;
|
||||
|
||||
SELECT id INTO vSenderFk
|
||||
FROM account.user WHERE `name` = account.userGetName();
|
||||
|
||||
RETURN (SELECT messageSendWithUser(vSenderFk, vRecipient, vMessage));
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,57 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP function IF EXISTS `messageSendWithUser`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` FUNCTION `messageSendWithUser`(vSenderFK INT, vRecipient VARCHAR(255) CHARSET utf8, vMessage TEXT CHARSET utf8) RETURNS int(11)
|
||||
BEGIN
|
||||
|
||||
DECLARE vCount INT;
|
||||
DECLARE vUuid VARCHAR(255);
|
||||
DECLARE vSendDate DATETIME DEFAULT NOW();
|
||||
DECLARE vSender VARCHAR(255) CHARSET utf8;
|
||||
|
||||
SELECT `name` INTO vSender
|
||||
FROM account.user WHERE id = vSenderFK;
|
||||
|
||||
SET vRecipient = LOWER(vRecipient);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tRecipients;
|
||||
CREATE TEMPORARY TABLE tRecipients
|
||||
SELECT u.name finalRecipient
|
||||
FROM account.mailAlias a
|
||||
JOIN account.mailAliasAccount aa ON aa.mailAlias = a.id
|
||||
JOIN account.user u ON u.id = aa.account
|
||||
WHERE a.alias = vRecipient COLLATE utf8_unicode_ci
|
||||
AND u.name != vSender
|
||||
AND u.active
|
||||
UNION
|
||||
SELECT u.name FROM account.user u
|
||||
WHERE u.name = vRecipient
|
||||
AND u.active;
|
||||
|
||||
SELECT COUNT(*) INTO vCount FROM tRecipients;
|
||||
|
||||
IF vCount = 0 THEN
|
||||
RETURN vCount;
|
||||
END IF;
|
||||
|
||||
SET vUuid = UUID();
|
||||
|
||||
INSERT INTO message
|
||||
SET uuid = vUuid,
|
||||
sender = vSender,
|
||||
recipient = vRecipient,
|
||||
message = vMessage,
|
||||
sendDate = vSendDate;
|
||||
|
||||
INSERT INTO messageInbox (uuid, sender, recipient, finalRecipient, message, sendDate)
|
||||
SELECT vUuid, vSender, vRecipient, finalRecipient, vMessage, vSendDate
|
||||
FROM tRecipients;
|
||||
|
||||
DROP TEMPORARY TABLE tRecipients;
|
||||
RETURN vCount;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `agencyHourOffer`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourOffer`(vDate DATE, vAddressFk INT, vAgencyFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve las posibles fechas de envío de un ticket
|
||||
*
|
||||
* @param vDate La fecha
|
||||
* @param vAddressFk Id del consignatario
|
||||
* @param vAgencyFk Id de la agencia
|
||||
* @return tmp.agencyHourOffer
|
||||
*/
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vWarehouseFk SMALLINT;
|
||||
|
||||
DECLARE vCur CURSOR FOR
|
||||
SELECT w.id warehouseFk
|
||||
FROM warehouse w
|
||||
WHERE w.hasAvailable;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = TRUE;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.agencyHourOffer;
|
||||
CREATE TEMPORARY TABLE tmp.agencyHourOffer
|
||||
(
|
||||
warehouseFk TINYINT NOT NULL PRIMARY KEY,
|
||||
shipped DATE NOT NULL,
|
||||
landed DATE NOT NULL
|
||||
)
|
||||
ENGINE = MEMORY;
|
||||
|
||||
OPEN vCur;
|
||||
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH vCur INTO vWarehouseFk;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
INSERT INTO tmp.agencyHourOffer (warehouseFk, shipped, landed)
|
||||
SELECT vWarehouseFk, shipping, vDate FROM (
|
||||
SELECT TIMESTAMPADD(DAY, -ah.substractDay, vDate) shipping, ah.maxHour
|
||||
FROM agencyHour ah
|
||||
LEFT JOIN address a ON a.id = vAddressFk
|
||||
WHERE ah.warehouseFk = vWarehouseFk
|
||||
AND (weekDay = WEEKDAY(vDate)
|
||||
OR weekDay IS NULL)
|
||||
AND (ah.agencyFk = vAgencyFk
|
||||
OR ah.agencyFk IS NULL)
|
||||
AND (ah.provinceFk = a.provinceFk
|
||||
OR ah.provinceFk IS NULL
|
||||
OR vAddressFk IS NULL)
|
||||
ORDER BY (
|
||||
(ah.weekDay IS NOT NULL) +
|
||||
(ah.agencyFk IS NOT NULL) +
|
||||
((ah.provinceFk IS NOT NULL) * 3)
|
||||
) DESC
|
||||
LIMIT 1
|
||||
) t
|
||||
WHERE t.shipping >= CURDATE()
|
||||
AND IF(t.shipping = CURDATE(), t.maxHour > HOUR(NOW()), TRUE);
|
||||
END LOOP;
|
||||
|
||||
CLOSE vCur;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `buyUltimateFromInterval`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `buyUltimateFromInterval`(vWarehouseFk SMALLINT, vStarted DATE, vEnded DATE)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula las últimas compras realizadas
|
||||
* desde un rango de fechas.
|
||||
*
|
||||
* @param vWarehouseFk Id del almacén
|
||||
* @param vStarted Fecha inicial
|
||||
* @param vEnded Fecha fin
|
||||
* @return tmp.buyUltimateFromInterval
|
||||
*/
|
||||
IF vEnded IS NULL THEN
|
||||
SET vEnded = vStarted;
|
||||
END IF;
|
||||
|
||||
IF vEnded < vStarted THEN
|
||||
SET vStarted = TIMESTAMPADD(MONTH, -1, vEnded);
|
||||
END IF;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimateFromInterval;
|
||||
CREATE TEMPORARY TABLE tmp.buyUltimateFromInterval
|
||||
ENGINE = MEMORY
|
||||
SELECT
|
||||
b.itemFk,
|
||||
t.warehouseInFk warehouseFk,
|
||||
MULTIMAX(t.landed, b.id) buyFk,
|
||||
MAX(t.landed) landed
|
||||
FROM buy b
|
||||
JOIN entry e ON e.id = b.entryFk
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
WHERE t.landed BETWEEN vStarted AND vEnded
|
||||
AND (vWarehouseFk IS NULL OR t.warehouseInFk = vWarehouseFk)
|
||||
AND b.price2 > 0
|
||||
AND NOT b.isIgnored
|
||||
GROUP BY itemFk, warehouseInFk;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,35 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `buyUltimate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `buyUltimate`(vWarehouseFk SMALLINT, vDate DATE)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula las últimas compras realizadas hasta una fecha
|
||||
*
|
||||
* @param vWarehouseFk Id del almacén
|
||||
* @param vDate Compras hasta fecha
|
||||
* @return tmp.buyUltimate
|
||||
*/
|
||||
CALL cache.last_buy_refresh (FALSE);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.buyUltimate;
|
||||
CREATE TEMPORARY TABLE tmp.buyUltimate
|
||||
(PRIMARY KEY (itemFk, warehouseFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT item_id itemFk, buy_id buyFk, warehouse_id warehouseFk
|
||||
FROM cache.last_buy
|
||||
WHERE warehouse_id = vWarehouseFk OR vWarehouseFk IS NULL;
|
||||
|
||||
CALL vn.buyUltimateFromInterval(vWarehouseFk, CURDATE(), vDate);
|
||||
|
||||
REPLACE INTO tmp.buyUltimate
|
||||
SELECT itemFk, buyFk, warehouseFk
|
||||
FROM tmp.buyUltimateFromInterval
|
||||
WHERE warehouseFk = vWarehouseFk OR vWarehouseFk IS NULL;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.buyUltimateFromInterval;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,294 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketComponentCalculate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentCalculate`(
|
||||
vAddressFk INT,
|
||||
vAgencyModeFk INT)
|
||||
proc: BEGIN
|
||||
/**
|
||||
* Calcula los componentes de un ticket
|
||||
*
|
||||
* @param vAddressFk Id del consignatario
|
||||
* @param vAgencyModeFk Id del modo de agencia
|
||||
* @return tmp.ticketComponent, tmp.ticketComponentPrice
|
||||
*/
|
||||
DECLARE vClientFk INT;
|
||||
DECLARE vGeneralInflationCoefficient INT DEFAULT 1.3;
|
||||
DECLARE vMinimumDensityWeight INT DEFAULT 167;
|
||||
DECLARE vBoxFreightItem INT DEFAULT 71;
|
||||
DECLARE vBoxVolume BIGINT DEFAULT 138000;
|
||||
DECLARE vSpecialPriceComponent INT DEFAULT 10;
|
||||
DECLARE vExtraFreightComponent INT DEFAULT 14;
|
||||
DECLARE vDeliveryComponent INT DEFAULT 15;
|
||||
DECLARE vRecoveryComponent INT DEFAULT 17;
|
||||
DECLARE vSellByPacketComponent INT DEFAULT 22;
|
||||
DECLARE vBuyValueComponent INT DEFAULT 28;
|
||||
DECLARE vMarginComponent INT DEFAULT 29;
|
||||
DECLARE vDiscountLastItemComponent INT DEFAULT 32;
|
||||
DECLARE vExtraBaggedComponent INT DEFAULT 38;
|
||||
DECLARE vManaAutoComponent INT DEFAULT 39;
|
||||
DECLARE vFreightBonusComponent INT DEFAULT 41;
|
||||
|
||||
SELECT clientFk INTO vClientFK
|
||||
FROM address
|
||||
WHERE id = vAddressFk;
|
||||
|
||||
SET @rate2 := 0;
|
||||
SET @rate3 := 0;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCalculate;
|
||||
CREATE TEMPORARY TABLE tmp.ticketComponentCalculate
|
||||
(PRIMARY KEY (itemFk, warehouseFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT
|
||||
tl.itemFk, tl.warehouseFk, tl.available,
|
||||
IF((@rate2 := IFNULL(pf.rate2, b.price2)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate2) * 1.0 rate2,
|
||||
IF((@rate3 := IFNULL(pf.rate3, b.price3)) < i.minPrice AND i.hasMinPrice, i.minPrice, @rate3) * 1.0 rate3,
|
||||
IFNULL(pf.rate3, 0) AS minPrice,
|
||||
IFNULL(pf.packing, b.packing) packing,
|
||||
IFNULL(pf.grouping, b.grouping) grouping,
|
||||
ABS(IFNULL(pf.box, b.groupingMode)) groupingMode,
|
||||
tl.buyFk, i.typeFk
|
||||
FROM tmp.ticketLot tl
|
||||
JOIN buy b ON b.id = tl.buyFk
|
||||
JOIN item i ON i.id = tl.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
|
||||
LEFT JOIN specialPrice sp ON sp.itemFk = i.id AND sp.clientFk = vClientFk
|
||||
LEFT JOIN (
|
||||
SELECT * FROM (
|
||||
SELECT pf.itemFk, pf.grouping, pf.packing, pf.box, pf.rate2, pf.rate3, aho.warehouseFk
|
||||
FROM priceFixed pf
|
||||
JOIN tmp.agencyHourOffer aho ON pf.warehouseFk = aho.warehouseFk OR pf.warehouseFk = 0
|
||||
WHERE aho.shipped BETWEEN pf.started AND pf.ended ORDER BY pf.itemFk, pf.warehouseFk DESC
|
||||
) tpf
|
||||
GROUP BY tpf.itemFk, tpf.warehouseFk
|
||||
) pf ON pf.itemFk = tl.itemFk AND pf.warehouseFk = tl.warehouseFk
|
||||
WHERE b.buyingValue + b.freightValue + b.packageValue + b.comissionValue > 0.01 AND ic.display <> 0;
|
||||
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponent;
|
||||
CREATE TEMPORARY TABLE tmp.ticketComponent (
|
||||
`warehouseFk` INT UNSIGNED NOT NULL,
|
||||
`itemFk` INT NOT NULL,
|
||||
`componentFk` INT UNSIGNED NOT NULL,
|
||||
`cost` DECIMAL(10,4) NOT NULL,
|
||||
INDEX `itemWarehouse` USING BTREE (`itemFk` ASC, `warehouseFk` ASC),
|
||||
UNIQUE INDEX `itemWarehouseComponent` (`itemFk` ASC, `warehouseFk` ASC, `componentFk` ASC));
|
||||
|
||||
|
||||
|
||||
INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
|
||||
SELECT
|
||||
tcc.warehouseFk,
|
||||
tcc.itemFk,
|
||||
vBuyValueComponent,
|
||||
tcc.rate3 - b.buyingValue - b.freightValue - b.packageValue - b.comissionValue
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN buy b ON b.id = tcc.buyFk;
|
||||
|
||||
INSERT INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
|
||||
SELECT
|
||||
tcc.warehouseFk,
|
||||
tcc.itemFk,
|
||||
vMarginComponent,
|
||||
tcc.rate3 - b.buyingValue - b.freightValue - b.packageValue - b.comissionValue
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN buy b ON b.id = tcc.buyFk;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentBase;
|
||||
CREATE TEMPORARY TABLE tmp.ticketComponentBase ENGINE = MEMORY
|
||||
SELECT tc.itemFk, ROUND(SUM(tc.cost), 4) AS base, tc.warehouseFk
|
||||
FROM tmp.ticketComponent tc
|
||||
GROUP BY tc.itemFk, warehouseFk;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcb.warehouseFk, tcb.itemFk, vRecoveryComponent, ROUND(tcb.base * LEAST(cr.recobro, 0.25), 3)
|
||||
FROM tmp.ticketComponentBase tcb
|
||||
JOIN bi.claims_ratio cr ON cr.Id_Cliente = vClientFk
|
||||
WHERE cr.recobro > 0.009;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcb.warehouseFk, tcb.itemFk, vManaAutoComponent, ROUND(base * (0.01 + prices_modifier_rate), 3) as manaAuto
|
||||
FROM tmp.ticketComponentBase tcb
|
||||
JOIN `client` c on c.id = vClientFk
|
||||
JOIN bs.mana_spellers ms ON c.salesPersonFk = ms.Id_Trabajador
|
||||
WHERE ms.prices_modifier_activated
|
||||
HAVING manaAuto <> 0;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT
|
||||
tcb.warehouseFk,
|
||||
tcb.itemFk,
|
||||
cr.id,
|
||||
GREATEST(IFNULL(ROUND(tcb.base * cr.tax, 4), 0), tcc.minPrice - tcc.rate3)
|
||||
FROM tmp.ticketComponentBase tcb
|
||||
JOIN componentRate cr
|
||||
JOIN tmp.ticketComponentCalculate tcc ON tcc.itemFk = tcb.itemFk AND tcc.warehouseFk = tcb.warehouseFk
|
||||
LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk
|
||||
WHERE cr.id = vDiscountLastItemComponent AND cr.tax <> 0 AND tcc.minPrice < tcc.rate3 AND sp.value IS NULL;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcc.warehouseFk, tcc.itemFk, vSellByPacketComponent, tcc.rate2 - tcc.rate3
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN buy b ON b.id = tcc.buyFk
|
||||
LEFT JOIN specialPrice sp ON sp.clientFk = vClientFk AND sp.itemFk = tcc.itemFk
|
||||
WHERE sp.value IS NULL;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT
|
||||
tcc.warehouseFK,
|
||||
tcc.itemFk,
|
||||
vDeliveryComponent,
|
||||
vGeneralInflationCoefficient
|
||||
* ROUND(
|
||||
r.cm3
|
||||
* IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1)
|
||||
* IFNULL(amz.price
|
||||
* amz.inflation, 50) / vBoxVolume, 4
|
||||
) cost
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN item i ON i.id = tcc.itemFk
|
||||
JOIN agencyMode am ON am.id = vAgencyModeFk
|
||||
JOIN `address` a ON a.id = vAddressFk
|
||||
JOIN agencyProvince ap ON ap.agencyFk = a.id
|
||||
AND ap.warehouseFk = tcc.warehouseFk AND ap.provinceFk = a.provinceFk
|
||||
JOIN agencyModeZone amz ON amz.agencyModeFk = vAgencyModeFk
|
||||
AND amz.zone = ap.zone AND amz.itemFk = 71 AND amz.warehouseFk = tcc.warehouseFk
|
||||
LEFT JOIN bi.rotacion r ON r.warehouse_id = tcc.warehouseFk
|
||||
AND r.Id_Article = tcc.itemFk
|
||||
HAVING cost <> 0;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT
|
||||
tcc.warehouseFk,
|
||||
tcc.itemFk,
|
||||
vFreightBonusComponent,
|
||||
vGeneralInflationCoefficient
|
||||
* ROUND(
|
||||
r.cm3
|
||||
* IF(am.deliveryMethodFk = 1, (GREATEST(i.density, vMinimumDensityWeight) / vMinimumDensityWeight), 1)
|
||||
* awb.bonus
|
||||
* amz.inflation / vBoxVolume, 4
|
||||
) cost
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN item i ON i.id = tcc.itemFk
|
||||
JOIN agencyMode am ON am.id = vAgencyModeFk
|
||||
JOIN `address` a ON a.id = vAddressFk
|
||||
JOIN agencyProvince ap ON ap.agencyFk = a.id
|
||||
AND ap.warehouseFk = tcc.warehouseFk AND ap.provinceFk = a.provinceFk
|
||||
JOIN agencyModeZone amz ON amz.agencyModeFk = vAgencyModeFk
|
||||
AND amz.zone = ap.zone AND amz.itemFk = vBoxFreightItem AND amz.warehouseFk = tcc.warehouseFk
|
||||
JOIN agencyWeekDayBonus awb ON awb.warehouseFk = amz.warehouseFk AND awb.zone = amz.zone AND am.id = awb.agencyFk
|
||||
LEFT JOIN bi.rotacion r ON r.warehouse_id = tcc.warehouseFk
|
||||
AND r.Id_Article = tcc.itemFk
|
||||
JOIN tmp.agencyHourOffer aho ON aho.warehouseFk = awb.warehouseFk
|
||||
AND WEEKDAY(aho.landed) = awb.weekDay
|
||||
HAVING cost <> 0
|
||||
LIMIT 1;
|
||||
|
||||
IF (SELECT COUNT(*) FROM vn.addressForPackaging WHERE addressFk = vAddressFk) THEN
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcc.warehouseFk, b.itemFk, vExtraBaggedComponent, ap.packagingValue cost
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN vn.addressForPackaging ap
|
||||
WHERE ap.addressFk = vAddressFk;
|
||||
END IF;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT tcb.warehouseFk, tcb.itemFk, vExtraFreightComponent, tcb.base * (IFNULL(pe.percentage,pp.percentage)/100)
|
||||
FROM tmp.ticketComponentBase tcb
|
||||
JOIN tmp.agencyHourOffer aho ON aho.warehouseFk = tcb.warehouseFk
|
||||
LEFT JOIN preparationPercentage pp ON pp.weekDay = WEEKDAY(aho.shipped)
|
||||
AND tcb.warehouseFk = IFNULL(pp.warehouseFk, tcb.warehouseFk)
|
||||
LEFT JOIN preparationException pe ON pe.exceptionDay = aho.shipped
|
||||
AND tcb.warehouseFk = IFNULL(pe.warehouseFk, tcb.warehouseFk)
|
||||
WHERE IFNULL(pe.percentage, pp.percentage);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentCopy;
|
||||
CREATE TEMPORARY TABLE tmp.ticketComponentCopy ENGINE = MEMORY
|
||||
SELECT * FROM tmp.ticketComponent;
|
||||
|
||||
INSERT INTO tmp.ticketComponent
|
||||
SELECT
|
||||
tcc.warehouseFk,
|
||||
tcc.itemFk,
|
||||
vSpecialPriceComponent,
|
||||
sp.value - SUM(tcc.cost) sumCost
|
||||
FROM tmp.ticketComponentCopy tcc
|
||||
JOIN componentRate cr ON cr.id = tcc.componentFk
|
||||
JOIN specialPrice sp ON sp.clientFk = vClientFK AND sp.itemFk = tcc.itemFk
|
||||
WHERE cr.classRate IS NULL
|
||||
GROUP BY tcc.itemFk, tcc.warehouseFk
|
||||
HAVING ABS(sumCost) > 0.001;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentSum;
|
||||
CREATE TEMPORARY TABLE tmp.ticketComponentSum
|
||||
(INDEX (itemFk, warehouseFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT SUM(cost) sumCost, tc.itemFk, tc.warehouseFk, cr.classRate
|
||||
FROM tmp.ticketComponent tc
|
||||
JOIN componentRate cr ON cr.id = tc.componentFk
|
||||
GROUP BY tc.itemFk, tc.warehouseFk, cr.classRate;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentRate;
|
||||
CREATE TEMPORARY TABLE tmp.ticketComponentRate ENGINE = MEMORY
|
||||
SELECT
|
||||
tcc.warehouseFk,
|
||||
tcc.itemFk,
|
||||
1 rate,
|
||||
IF(tcc.groupingMode = 1, tcc.grouping, 1) grouping,
|
||||
SUM(tcs.sumCost) price
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
|
||||
AND tcs.warehouseFk = tcc.warehouseFk
|
||||
WHERE IFNULL(tcs.classRate, 1) = 1
|
||||
AND tcc.groupingMode < 2 AND (tcc.packing > tcc.grouping or tcc.groupingMode = 0)
|
||||
GROUP BY tcs.warehouseFk, tcs.itemFk;
|
||||
|
||||
INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, grouping, price)
|
||||
SELECT
|
||||
tcc.warehouseFk,
|
||||
tcc.itemFk,
|
||||
2 rate,
|
||||
tcc.packing grouping,
|
||||
SUM(tcs.sumCost) price
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
|
||||
AND tcs.warehouseFk = tcc.warehouseFk
|
||||
WHERE tcc.available IS NULL OR (IFNULL(tcs.classRate, 2) = 2
|
||||
AND tcc.packing > 0 AND tcc.available >= tcc.packing)
|
||||
GROUP BY tcs.warehouseFk, tcs.itemFk;
|
||||
|
||||
INSERT INTO tmp.ticketComponentRate (warehouseFk, itemFk, rate, grouping, price)
|
||||
SELECT
|
||||
tcc.warehouseFk,
|
||||
tcc.itemFk,
|
||||
3 rate,
|
||||
tcc.available grouping,
|
||||
SUM(tcs.sumCost) price
|
||||
FROM tmp.ticketComponentCalculate tcc
|
||||
JOIN tmp.ticketComponentSum tcs ON tcs.itemFk = tcc.itemFk
|
||||
AND tcs.warehouseFk = tcc.warehouseFk
|
||||
WHERE IFNULL(tcs.classRate, 3) = 3
|
||||
GROUP BY tcs.warehouseFk, tcs.itemFk;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketComponentPrice;
|
||||
CREATE TEMPORARY TABLE tmp.ticketComponentPrice ENGINE = MEMORY
|
||||
SELECT * FROM (
|
||||
SELECT * FROM tmp.ticketComponentRate ORDER BY price
|
||||
) t
|
||||
GROUP BY itemFk, warehouseFk, grouping;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.ticketComponentCalculate,
|
||||
tmp.ticketComponentSum,
|
||||
tmp.ticketComponentBase,
|
||||
tmp.ticketComponentRate,
|
||||
tmp.ticketComponentCopy;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketComponentPreview`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPreview`(
|
||||
vDate DATE,
|
||||
vAddressFk INT,
|
||||
vAgencyModeFk INT,
|
||||
vTicketFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve un listado previo de
|
||||
* componentes para un ticket
|
||||
*
|
||||
* @param vDate Fecha de envío
|
||||
* @param vAddressFk Id del consignatario
|
||||
* @param vAgencyModeFk Id del modo de agencia
|
||||
* @param vTicketFk Id del ticket
|
||||
*/
|
||||
DECLARE vWarehouseFk SMALLINT;
|
||||
DECLARE vAgencyFk INT;
|
||||
DECLARE vShipped DATE;
|
||||
DECLARE vBuyOrderItem INT DEFAULT 100;
|
||||
|
||||
SELECT warehouseFk INTO vWarehouseFK
|
||||
FROM ticket
|
||||
WHERE id = vTicketFk;
|
||||
|
||||
SELECT agencyFk INTO vAgencyFk
|
||||
FROM agencyMode
|
||||
WHERE id = vAgencyModeFk;
|
||||
|
||||
CALL agencyHourOffer(vDate, vAddressFk, vAgencyFk);
|
||||
|
||||
SELECT shipped INTO vShipped
|
||||
FROM tmp.agencyHourOffer
|
||||
WHERE warehouseFk = vWarehouseFK;
|
||||
|
||||
CALL buyUltimate(vWarehouseFK, vShipped);
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketLot;
|
||||
CREATE TEMPORARY TABLE tmp.ticketLot ENGINE = MEMORY (
|
||||
SELECT
|
||||
vWarehouseFK AS warehouseFk,
|
||||
NULL AS available,
|
||||
s.itemFk,
|
||||
bu.buyFk
|
||||
FROM sale s
|
||||
LEFT JOIN tmp.buyUltimate bu ON bu.itemFk = s.itemFk
|
||||
WHERE s.ticketFk = vTicketFk
|
||||
AND s.itemFk != vBuyOrderItem
|
||||
GROUP BY bu.warehouseFk, bu.itemFk);
|
||||
|
||||
CALL ticketComponentCalculate(vAddressFk, vAgencyModeFk);
|
||||
|
||||
REPLACE INTO tmp.ticketComponent (warehouseFk, itemFk, componentFk, cost)
|
||||
SELECT t.warehouseFk, s.itemFk, sc.componentFk, sc.value
|
||||
FROM saleComponent sc
|
||||
JOIN sale s ON s.id = sc.saleFk
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN componentRate cr ON cr.id = sc.componentFk
|
||||
WHERE s.ticketFk = vTicketFk AND NOT cr.isRenewable;
|
||||
|
||||
SET @shipped = vShipped;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.agencyHourOffer,
|
||||
tmp.buyUltimate,
|
||||
tmp.ticketLot;
|
||||
|
||||
IF IFNULL(vShipped, CURDATE() - 1) < CURDATE() THEN
|
||||
CALL util.throw('NO_AGENCY_AVAILABLE');
|
||||
END IF;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,50 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketComponentPriceDifference`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentPriceDifference`(
|
||||
vDate DATE,
|
||||
vAddressFk INT,
|
||||
vAgencyModeFk INT,
|
||||
vTicketFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve las diferencias de precio
|
||||
* de los movimientos de un ticket.
|
||||
*
|
||||
* @param vTicketFk Id del ticket
|
||||
*/
|
||||
CALL vn.ticketComponentPreview(vDate, vAddressFk, vAgencyModeFk, vTicketFk);
|
||||
|
||||
SELECT
|
||||
s.itemFk,
|
||||
i.name,
|
||||
i.size,
|
||||
i.category,
|
||||
IFNULL(s.quantity, 0) AS quantity,
|
||||
IFNULL(s.price, 0) AS price,
|
||||
ROUND(SUM(tc.cost), 4) AS newPrice,
|
||||
s.quantity * (s.price - ROUND(SUM(cost), 4)) difference,
|
||||
s.id AS saleFk
|
||||
FROM sale s
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
LEFT JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk
|
||||
AND tc.warehouseFk = t.warehouseFk
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
AND sc.componentFk = tc.componentFk
|
||||
LEFT JOIN componentRate cr ON cr.id = tc.componentFk
|
||||
WHERE
|
||||
t.id = vTicketFk
|
||||
AND IF(sc.componentFk IS NULL
|
||||
AND cr.classRate IS NOT NULL, FALSE, TRUE)
|
||||
GROUP BY s.id ORDER BY s.id;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.ticketComponent,
|
||||
tmp.ticketComponentPrice;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketComponentUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdate`(
|
||||
vTicketFk INT,
|
||||
vAgencyModeFk INT,
|
||||
vAddressFk INT,
|
||||
vWarehouseFk INT,
|
||||
vShipped DATETIME,
|
||||
vLanded DATE,
|
||||
vOption INT)
|
||||
BEGIN
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
UPDATE ticket t
|
||||
SET
|
||||
t.agencyModeFk = vAgencyModeFk,
|
||||
t.addressFk = vAddressFk,
|
||||
t.warehouseFk = vWarehouseFk,
|
||||
t.landed = vLanded,
|
||||
t.shipped = vShipped
|
||||
WHERE
|
||||
t.id = vTicketFk;
|
||||
|
||||
IF vOption <> 8 THEN
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
CREATE TEMPORARY TABLE tmp.sale
|
||||
(PRIMARY KEY (saleFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT id AS saleFk, vWarehouseFk warehouseFk
|
||||
FROM sale s WHERE s.ticketFk = vTicketFk;
|
||||
|
||||
CALL ticketComponentUpdateSale (vOption);
|
||||
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
END IF;
|
||||
|
||||
COMMIT;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,153 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketComponentUpdateSale`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdateSale`(vOption INT)
|
||||
BEGIN
|
||||
/**
|
||||
* A partir de la tabla tmp.movement, crea los Movimientos_componentes
|
||||
* y modifica el campo Preu de la tabla Movimientos
|
||||
*
|
||||
* @param i_option integer tipo de actualizacion
|
||||
* @param table tmp.movement tabla memory con el campo Id_Movimiento, warehouse_id
|
||||
**/
|
||||
DECLARE vComponentFk INT;
|
||||
DECLARE vRenewComponents BOOLEAN;
|
||||
DECLARE vKeepPrices BOOLEAN;
|
||||
|
||||
CASE vOption
|
||||
WHEN 1 THEN
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = FALSE;
|
||||
WHEN 2 THEN
|
||||
SET vComponentFk = 17;
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
WHEN 3 THEN
|
||||
SET vComponentFk = 37;
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
WHEN 4 THEN
|
||||
SET vComponentFk = 34;
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
WHEN 5 THEN
|
||||
SET vComponentFk = 35;
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
WHEN 6 THEN
|
||||
SET vComponentFk = 36;
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
WHEN 7 THEN
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.8, 3)
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
AND sc.componentFk NOT IN (28, 29)
|
||||
GROUP BY s.id;
|
||||
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, 29, ROUND(((s.price * (100 - s.discount) / 100) - SUM(IFNULL(sc.value, 0))) * 0.2, 3)
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
AND sc.componentFk NOT IN (28, 29)
|
||||
GROUP BY s.id;
|
||||
|
||||
SET vRenewComponents = FALSE;
|
||||
SET vKeepPrices = FALSE;
|
||||
WHEN 8 THEN
|
||||
DELETE sc.*
|
||||
FROM tmp.sale tmps JOIN saleComponent sc ON sc.saleFk = tmps.saleFk;
|
||||
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, 28, ROUND(((s.price * (100 - s.discount) / 100)), 3)
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id;
|
||||
|
||||
SET vRenewComponents = FALSE;
|
||||
SET vKeepPrices = FALSE;
|
||||
WHEN 9 THEN
|
||||
SET vRenewComponents = TRUE;
|
||||
SET vKeepPrices = TRUE;
|
||||
END CASE;
|
||||
|
||||
IF vRenewComponents THEN
|
||||
DELETE sc.*
|
||||
FROM tmp.sale tmps
|
||||
JOIN saleComponent sc ON sc.saleFk = tmps.saleFk
|
||||
JOIN componentRate cr ON cr.id = sc.componentFk
|
||||
WHERE cr.isRenewable;
|
||||
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, tc.componentFk, tc.cost
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
JOIN tmp.ticketComponent tc ON tc.itemFk = s.itemFk AND tc.warehouseFk = tmps.warehouseFk
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
AND sc.componentFk = tc.componentFk
|
||||
LEFT JOIN componentRate cr ON cr.id = tc.componentFk
|
||||
WHERE IF(sc.componentFk IS NULL AND NOT cr.isRenewable, FALSE, TRUE);
|
||||
END IF;
|
||||
|
||||
IF vKeepPrices THEN
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, vComponentFk, ROUND((s.price * (100 - s.discount) / 100) - SUM(sc.value), 3) dif
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
WHERE sc.saleFk <> vComponentFk
|
||||
GROUP BY s.id
|
||||
HAVING dif <> 0;
|
||||
ELSE
|
||||
UPDATE sale s
|
||||
JOIN item i on i.id = s.id
|
||||
JOIN itemType it on it.id = i.typeFk
|
||||
JOIN (SELECT SUM(sc.value) sumValue, sc.saleFk
|
||||
FROM saleComponent sc
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
|
||||
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
|
||||
SET s.price = sumValue
|
||||
WHERE it.code != 'PRT';
|
||||
|
||||
REPLACE INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, 21, s.price * (100 - s.discount) / 100 - sum(sc.value) saleValue
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
||||
WHERE sc.saleFk != 21
|
||||
GROUP BY s.id
|
||||
HAVING ROUND(saleValue, 4) <> 0;
|
||||
END IF;
|
||||
|
||||
UPDATE sale s
|
||||
JOIN (
|
||||
SELECT SUM(sc.value) sumValue, sc.saleFk
|
||||
FROM saleComponent sc
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
|
||||
JOIN componentRate cr ON cr.id = sc.componentFk
|
||||
JOIN componentTypeRate ctr on ctr.id = cr.componentTypeRate AND ctr.base
|
||||
GROUP BY sc.saleFk) sc ON sc.saleFk = s.id
|
||||
SET s.priceFixed = sumValue, s.isPriceFixed = 1;
|
||||
|
||||
DELETE sc.*
|
||||
FROM saleComponent sc
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = sc.saleFk
|
||||
JOIN sale s on s.id = sc.saleFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE it.code = 'PRT';
|
||||
|
||||
INSERT INTO saleComponent(saleFk, componentFk, value)
|
||||
SELECT s.id, 15, s.price
|
||||
FROM sale s
|
||||
JOIN tmp.sale tmps ON tmps.saleFk = s.id
|
||||
JOIN item i ON i.id = s.itemFK
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE it.code = 'PRT' AND s.price > 0;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,31 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketComponentMakeUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE PROCEDURE `ticketComponentMakeUpdate` (
|
||||
vTicketFk INT,
|
||||
vAgencyModeFk INT,
|
||||
vAddressFk INT,
|
||||
vWarehouseFk INT,
|
||||
vShipped DATETIME,
|
||||
vLanded DATE,
|
||||
vOption INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve las diferencias de precio
|
||||
* de los movimientos de un ticket.
|
||||
*
|
||||
* @param vTicketFk Id del ticket
|
||||
*/
|
||||
|
||||
CALL vn.ticketComponentPreview (vLanded, vAddressFk, vAgencyModeFk, vTicketFk);
|
||||
CALL vn.ticketComponentUpdate (vTicketFk, vAgencyModeFk, vAddressFk, vWarehouseFk, vShipped, vLanded, vOption);
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.ticketComponent,
|
||||
tmp.ticketComponentPrice;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
ALTER TABLE `vn2008`.`Tickets`
|
||||
ADD COLUMN `isDeleted` TINYINT(2) NOT NULL DEFAULT '0' AFTER `boxed`;
|
|
@ -1,26 +0,0 @@
|
|||
USE `vn`;
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `ticket` AS
|
||||
SELECT
|
||||
`t`.`Id_Ticket` AS `id`,
|
||||
`t`.`Id_Cliente` AS `clientFk`,
|
||||
`t`.`warehouse_id` AS `warehouseFk`,
|
||||
`t`.`Fecha` AS `shipped`,
|
||||
`t`.`landing` AS `landed`,
|
||||
`t`.`Alias` AS `nickname`,
|
||||
`t`.`Factura` AS `refFk`,
|
||||
`t`.`Id_Consigna` AS `addressFk`,
|
||||
`t`.`Localizacion` AS `location`,
|
||||
`t`.`Solucion` AS `solution`,
|
||||
`t`.`Id_Ruta` AS `routeFk`,
|
||||
`t`.`empresa_id` AS `companyFk`,
|
||||
`t`.`Id_Agencia` AS `agencyModeFk`,
|
||||
`t`.`Prioridad` AS `priority`,
|
||||
`t`.`Bultos` AS `packages`,
|
||||
`t`.`isDeleted`,
|
||||
`t`.`odbc_date` AS `created`
|
||||
FROM
|
||||
`vn2008`.`Tickets` `t`;
|
|
@ -1,14 +0,0 @@
|
|||
UPDATE `salix`.`ACL` SET `accessType`='READ' WHERE `id`='20';
|
||||
UPDATE `salix`.`ACL` SET `principalId`='production' WHERE `id`='67';
|
||||
INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('78', 'TicketTracking', '*', 'WRITE', 'ALLOW', 'ROLE', 'production');
|
||||
INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `permission`, `principalType`, `principalId`) VALUES ('79', 'TicketTracking', 'changeState', 'ALLOW', 'ROLE', 'employe');
|
||||
|
||||
UPDATE `salix`.`ACL` SET `accessType`='READ' WHERE `id`='65';
|
||||
INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('80', 'Sale', 'removes', '*', 'ALLOW', 'ROLE', 'employee');
|
||||
INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('81', 'Sale', 'moveToTicket', '*', 'ALLOW', 'ROLE', 'employee');
|
||||
UPDATE `salix`.`ACL` SET `principalId`='employee' WHERE `id`='79';
|
||||
UPDATE `salix`.`ACL` SET `accessType`='*' WHERE `id`='79';
|
||||
|
||||
INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('82', 'Sale', 'updateQuantity', '*', 'ALLOW', 'ROLE', 'employee');
|
||||
INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('83', 'Sale', 'updatePrice', '*', 'ALLOW', 'ROLE', 'employee');
|
||||
INSERT INTO `salix`.`ACL` (`id`, `model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES ('84', 'Sale', 'updateDiscount', '*', 'ALLOW', 'ROLE', 'employee');
|
|
@ -1,22 +0,0 @@
|
|||
USE `vn`;
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `sale` AS
|
||||
SELECT
|
||||
`m`.`Id_Movimiento` AS `id`,
|
||||
`m`.`Id_Article` AS `itemFk`,
|
||||
`m`.`Id_Ticket` AS `ticketFk`,
|
||||
`m`.`Concepte` AS `concept`,
|
||||
`m`.`Cantidad` AS `quantity`,
|
||||
`m`.`Preu` AS `price`,
|
||||
`m`.`Descuento` AS `discount`,
|
||||
`m`.`Reservado` AS `reserved`,
|
||||
`m`.`OK` AS `isPicked`,
|
||||
`m`.`odbc_date` AS `created`,
|
||||
`m`.`CostFixat` AS `priceFixed`,
|
||||
`m`.`PrecioFijado` AS `isPriceFixed`
|
||||
|
||||
FROM
|
||||
`vn2008`.`Movimientos` `m`;
|
|
@ -1,12 +0,0 @@
|
|||
USE `vn`;
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`componentTypeRate` AS
|
||||
SELECT
|
||||
`t`.`tarifa_componentes_series_id` AS `id`,
|
||||
`t`.`Serie` AS `type`,
|
||||
`t`.`base` AS `base`
|
||||
FROM
|
||||
`bi`.`tarifa_componentes_series` `t`;
|
|
@ -1,27 +0,0 @@
|
|||
DROP VIEW `salix`.`Accounting`;
|
||||
DROP VIEW `salix`.`Address`;
|
||||
DROP VIEW `salix`.`Agency`;
|
||||
DROP VIEW `salix`.`AgencyMode`;
|
||||
DROP VIEW `salix`.`Bank`;
|
||||
DROP VIEW `salix`.`City`;
|
||||
DROP VIEW `salix`.`Client`;
|
||||
DROP VIEW `salix`.`ClientCredit`;
|
||||
DROP VIEW `salix`.`ClientCreditLimit`;
|
||||
DROP VIEW `salix`.`ClientObservation`;
|
||||
DROP VIEW `salix`.`ClientType`;
|
||||
DROP VIEW `salix`.`ContactChannel`;
|
||||
DROP VIEW `salix`.`Country`;
|
||||
DROP VIEW `salix`.`CreditClassification`;
|
||||
DROP VIEW `salix`.`Delivery`;
|
||||
DROP VIEW `salix`.`Employee`;
|
||||
DROP VIEW `salix`.`PayMethod`;
|
||||
DROP VIEW `salix`.`Province`;
|
||||
DROP VIEW `salix`.`Route`;
|
||||
DROP VIEW `salix`.`State`;
|
||||
DROP VIEW `salix`.`Ticket`;
|
||||
DROP VIEW `salix`.`TicketState`;
|
||||
DROP VIEW `salix`.`Vehicle`;
|
||||
DROP VIEW `salix`.`Warehouse`;
|
||||
DROP VIEW `salix`.`WarehouseAlias`;
|
||||
DROP VIEW `salix`.`Worker`;
|
||||
DROP VIEW `salix`.`Zone`;
|
|
@ -1,26 +0,0 @@
|
|||
DROP TRIGGER IF EXISTS `vn2008`.`Articles_AFTER_INSERT`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn2008`$$
|
||||
CREATE DEFINER=`root`@`%` TRIGGER `vn2008`.`Articles_AFTER_INSERT` AFTER INSERT ON `Articles` FOR EACH ROW
|
||||
BEGIN
|
||||
|
||||
CALL itemTagArrangedUpdate(NEW.Id_Article);
|
||||
|
||||
INSERT INTO vn.itemTaxCountry(itemFk, countryFk, taxClassFk)
|
||||
SELECT NEW.Id_Article, 1, NEW.iva_group_id;
|
||||
|
||||
INSERT INTO vn.itemTaxCountry(itemFk, countryFk, taxClassFk)
|
||||
SELECT NEW.Id_Article, 5, NEW.iva_group_id;
|
||||
|
||||
INSERT INTO vn.itemTaxCountry(itemFk, countryFk, taxClassFk)
|
||||
SELECT NEW.Id_Article, 30, NEW.iva_group_id;
|
||||
|
||||
IF NEW.tipo_id IS NOT NULL THEN
|
||||
INSERT INTO vn.itemTag (itemFk, tagFk, priority)
|
||||
SELECT NEW.Id_Article, tagFk, priority FROM vn.itemTypeTag
|
||||
WHERE itemTypeFk = NEW.tipo_id;
|
||||
END IF;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,23 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketListCreate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketListCreate`(
|
||||
vClientId INT
|
||||
,vShipped DATE
|
||||
,vWarehouseId INT
|
||||
,vCompanyFk INT
|
||||
,vAddressFk INT
|
||||
,vAgencyType INT
|
||||
,vRouteFk INT
|
||||
,vlanded DATE)
|
||||
BEGIN
|
||||
|
||||
DECLARE vNewTicket INT;
|
||||
CALL vn.ticketCreate(vClientId, vShipped, vWarehouseId, vCompanyFk, vAddressFk, vAgencyType, vRouteFk, vlanded,vNewTicket);
|
||||
SELECT vNewTicket;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,17 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `agencyHourListOffer`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `agencyHourListOffer`(vDate DATE, vAddressFk INT, vAgencyFk INT)
|
||||
BEGIN
|
||||
|
||||
CALL vn.agencyHourOffer(vDate, vAddressFk, vAgencyFk);
|
||||
|
||||
SELECT * FROM tmp.agencyHourOffer;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.agencyHourOffer;
|
||||
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,52 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketComponentUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketComponentUpdate`(
|
||||
vTicketFk INT,
|
||||
vAgencyModeFk INT,
|
||||
vAddressFk INT,
|
||||
vWarehouseFk INT,
|
||||
vShipped DATETIME,
|
||||
vLanded DATE,
|
||||
vIsDeleted BOOLEAN,
|
||||
vOption INT)
|
||||
BEGIN
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
UPDATE ticket t
|
||||
SET
|
||||
t.agencyModeFk = vAgencyModeFk,
|
||||
t.addressFk = vAddressFk,
|
||||
t.warehouseFk = vWarehouseFk,
|
||||
t.landed = vLanded,
|
||||
t.shipped = vShipped,
|
||||
t.isDeleted = vIsDeleted
|
||||
WHERE
|
||||
t.id = vTicketFk;
|
||||
|
||||
IF vOption <> 8 THEN
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.sale;
|
||||
CREATE TEMPORARY TABLE tmp.sale
|
||||
(PRIMARY KEY (saleFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT id AS saleFk, vWarehouseFk warehouseFk
|
||||
FROM sale s WHERE s.ticketFk = vTicketFk;
|
||||
|
||||
CALL ticketComponentUpdateSale (vOption);
|
||||
|
||||
DROP TEMPORARY TABLE tmp.sale;
|
||||
END IF;
|
||||
|
||||
COMMIT;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketComponentMakeUpdate`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `ticketComponentMakeUpdate`(
|
||||
vTicketFk INT,
|
||||
vAgencyModeFk INT,
|
||||
vAddressFk INT,
|
||||
vWarehouseFk INT,
|
||||
vShipped DATETIME,
|
||||
vLanded DATE,
|
||||
vIsDeleted BOOLEAN,
|
||||
vOption INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Devuelve las diferencias de precio
|
||||
* de los movimientos de un ticket.
|
||||
*
|
||||
* @param vTicketFk Id del ticket
|
||||
*/
|
||||
|
||||
CALL vn.ticketComponentPreview (vLanded, vAddressFk, vAgencyModeFk, vTicketFk);
|
||||
CALL vn.ticketComponentUpdate (
|
||||
vTicketFk,
|
||||
vAgencyModeFk,
|
||||
vAddressFk,
|
||||
vWarehouseFk,
|
||||
vShipped,
|
||||
vLanded,
|
||||
vIsDeleted,
|
||||
vOption
|
||||
);
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.ticketComponent,
|
||||
tmp.ticketComponentPrice;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue