update structure db cau 9939
gitea/salix/dev This commit looks good
Details
gitea/salix/dev This commit looks good
Details
This commit is contained in:
parent
45527a43da
commit
6e23b5bcc0
|
@ -1,18 +0,0 @@
|
|||
USE `vn`;
|
||||
CREATE
|
||||
OR REPLACE ALGORITHM = UNDEFINED
|
||||
DEFINER = `root`@`%`
|
||||
SQL SECURITY DEFINER
|
||||
VIEW `vn`.`workerDepartment` AS
|
||||
SELECT
|
||||
`p`.`id_trabajador` AS `workerFk`,
|
||||
`d`.`id` AS `departmentFk`
|
||||
FROM
|
||||
(((`postgresql`.`person` `p`
|
||||
JOIN `postgresql`.`profile` `pr` ON ((`pr`.`person_id` = `p`.`person_id`)))
|
||||
LEFT JOIN (`postgresql`.`business` `b`
|
||||
LEFT JOIN `postgresql`.`business_labour` `bl` ON ((`b`.`business_id` = `bl`.`business_id`))) ON ((`pr`.`profile_id` = `b`.`client_id`)))
|
||||
JOIN `vn`.`department` `d` ON ((`d`.`id` = `bl`.`department_id`)))
|
||||
WHERE
|
||||
(ISNULL(`b`.`date_end`)
|
||||
OR (`b`.`date_end` > CURDATE()));
|
|
@ -1,108 +0,0 @@
|
|||
USE `hedera`;
|
||||
DROP procedure IF EXISTS `orderAddItem`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `hedera`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `orderAddItem`(IN `vOrder` INT, IN `vWarehouse` INT, IN `vItem` INT, IN `vAmount` INT)
|
||||
BEGIN
|
||||
DECLARE vRow INT;
|
||||
DECLARE vAdd INT;
|
||||
DECLARE vAvailable INT;
|
||||
DECLARE vDone BOOL;
|
||||
DECLARE vGrouping INT;
|
||||
DECLARE vRate INT;
|
||||
DECLARE vShipment DATE;
|
||||
DECLARE vPrice DECIMAL(10,2);
|
||||
DECLARE vDate DATE;
|
||||
DECLARE vAddress INT;
|
||||
DECLARE vAgencyMode INT;
|
||||
DECLARE cur CURSOR FOR
|
||||
SELECT grouping, price, rate
|
||||
FROM tmp.bionic_price
|
||||
WHERE warehouse_id = vWarehouse
|
||||
AND item_id = vItem
|
||||
ORDER BY grouping DESC;
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND
|
||||
SET vDone = TRUE;
|
||||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
SELECT date_send, address_id, agency_id
|
||||
INTO vDate, vAddress, vAgencyMode
|
||||
FROM `order`
|
||||
WHERE id = vOrder;
|
||||
|
||||
CALL vn2008.bionic_from_item(vDate, vAddress, vAgencyMode, vItem);
|
||||
|
||||
START TRANSACTION;
|
||||
|
||||
SELECT shipped INTO vShipment
|
||||
FROM tmp.travel_tree
|
||||
WHERE warehouseFk = vWarehouse;
|
||||
|
||||
SELECT available INTO vAvailable
|
||||
FROM tmp.bionic_lot
|
||||
WHERE warehouse_id = vWarehouse
|
||||
AND item_id = vItem;
|
||||
|
||||
IF vAmount > IFNULL(vAvailable, 0)
|
||||
THEN
|
||||
CALL util.throw ('ORDER_ROW_UNAVAILABLE');
|
||||
END IF;
|
||||
|
||||
OPEN cur;
|
||||
|
||||
l: LOOP
|
||||
SET vDone = FALSE;
|
||||
FETCH cur INTO vGrouping, vPrice, vRate;
|
||||
|
||||
IF vDone THEN
|
||||
LEAVE l;
|
||||
END IF;
|
||||
|
||||
SET vAdd = vAmount - MOD(vAmount, vGrouping);
|
||||
SET vAmount = vAmount - vAdd;
|
||||
|
||||
IF vAdd = 0 THEN
|
||||
ITERATE l;
|
||||
END IF;
|
||||
|
||||
INSERT INTO order_row SET
|
||||
order_id = vOrder,
|
||||
item_id = vItem,
|
||||
warehouse_id = vWarehouse,
|
||||
shipment = vShipment,
|
||||
rate = vRate,
|
||||
amount = vAdd,
|
||||
price = vPrice;
|
||||
|
||||
SET vRow = LAST_INSERT_ID();
|
||||
|
||||
INSERT INTO order_component (order_row_id, component_id, price)
|
||||
SELECT vRow, c.component_id, c.cost
|
||||
FROM tmp.bionic_component c
|
||||
JOIN bi.tarifa_componentes t
|
||||
ON t.Id_Componente = c.component_id
|
||||
AND (t.tarifa_class IS NULL OR t.tarifa_class = vRate)
|
||||
WHERE c.warehouse_id = vWarehouse
|
||||
AND c.item_id = vItem;
|
||||
END LOOP;
|
||||
|
||||
CLOSE cur;
|
||||
|
||||
IF vAmount > 0
|
||||
THEN
|
||||
CALL util.throw ('AMOUNT_NOT_MATCH_GROUPING');
|
||||
END IF;
|
||||
|
||||
COMMIT;
|
||||
CALL vn2008.bionic_free ();
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
|
@ -1 +0,0 @@
|
|||
INSERT INTO salix.ACL(id,model, property, accessType, permission, principalType, principalId)VALUES(147,'UserConfigView', '*', '*', 'ALLOW', 'ROLE', 'employee');
|
|
@ -1,99 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketGetTax`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetTax`()
|
||||
READS SQL DATA
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula la base imponible, el IVA y el recargo de equivalencia para
|
||||
* un conjunto de tickets.
|
||||
*
|
||||
* @table tmp.ticket(ticketFk) Identificadores de los tickets a calcular
|
||||
* @return tmp.ticketAmount
|
||||
* @return tmp.ticketTax Impuesto desglosado para cada ticket.
|
||||
|
||||
*/
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany;
|
||||
CREATE TEMPORARY TABLE tmp.addressCompany
|
||||
(INDEX (addressFk, companyFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT DISTINCT t.addressFk, t.companyFk
|
||||
FROM tmp.ticket tmpTicket
|
||||
JOIN ticket t ON t.id = tmpTicket.ticketFk;
|
||||
|
||||
CALL addressTaxArea ();
|
||||
|
||||
|
||||
/** Solo se calcula la base imponible (taxableBase) y el impuesto se calculará posteriormente
|
||||
* No se debería cambiar el sistema por problemas con los decimales
|
||||
*/
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketTax;
|
||||
CREATE TEMPORARY TABLE tmp.ticketTax
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT tmpTicket.ticketFk,
|
||||
bp.pgcFk,
|
||||
SUM(s.quantity * s.price * (100 - s.discount)/100 ) AS taxableBase,
|
||||
pgc.rate,
|
||||
tc.code
|
||||
FROM tmp.ticket tmpTicket
|
||||
JOIN sale s ON s.ticketFk = tmpTicket.ticketFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN ticket t ON t.id = tmpTicket.ticketFk
|
||||
JOIN supplier su ON su.id = t.companyFk
|
||||
JOIN tmp.addressTaxArea ata
|
||||
ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk
|
||||
JOIN itemTaxCountry itc
|
||||
ON itc.itemFk = i.id AND itc.countryFk = su.countryFk
|
||||
JOIN bookingPlanner bp
|
||||
ON bp.countryFk = su.countryFk
|
||||
AND bp.taxAreaFk = ata.areaFk
|
||||
AND bp.taxClassFk = itc.taxClassFk
|
||||
JOIN pgc ON pgc.code = bp.pgcFk
|
||||
JOIN taxClass tc ON tc.id = bp.taxClassFk
|
||||
GROUP BY tmpTicket.ticketFk, pgc.code,pgc.rate
|
||||
HAVING taxableBase != 0;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketServiceTax;
|
||||
CREATE TEMPORARY TABLE tmp.ticketServiceTax
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT tt.ticketFk,
|
||||
SUM(ts.quantity * ts.price) AS taxableBase,
|
||||
pgc.rate,
|
||||
tc.code
|
||||
FROM tmp.ticketTax tt
|
||||
JOIN ticketService ts ON ts.ticketFk = tt.ticketFk
|
||||
JOIN ticket t ON t.id = tt.ticketFk
|
||||
JOIN supplier su ON su.id = t.companyFk
|
||||
JOIN tmp.addressTaxArea ata
|
||||
ON ata.addressFk = t.addressFk AND ata.companyFk = t.companyFk
|
||||
JOIN bookingPlanner bp
|
||||
ON bp.countryFk = su.countryFk
|
||||
AND bp.taxAreaFk = ata.areaFk
|
||||
AND bp.taxClassFk = ts.taxClassFk
|
||||
JOIN pgc ON pgc.code = bp.pgcFk AND pgc.rate = tt.rate
|
||||
JOIN taxClass tc ON tc.id = bp.taxClassFk
|
||||
GROUP BY tt.ticketFk, tt.code,tt.rate
|
||||
HAVING taxableBase != 0;
|
||||
|
||||
UPDATE tmp.ticketTax tt
|
||||
JOIN tmp.ticketServiceTax ts ON tt.ticketFk = ts.ticketFk AND tt.code = ts.code AND tt.rate = ts.rate
|
||||
SET tt.taxableBase = tt.taxableBase + ts.taxableBase;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketAmount;
|
||||
CREATE TEMPORARY TABLE tmp.ticketAmount
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT ticketFk, taxableBase, SUM(CAST(taxableBase * rate / 100 AS DECIMAL(10, 2))) tax,code
|
||||
FROM tmp.ticketTax
|
||||
GROUP BY ticketFk, code;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.addressCompany;
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.addressTaxArea;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
|
@ -1,34 +0,0 @@
|
|||
DROP PROCEDURE IF EXISTS vn.ticketGetTaxAdd;
|
||||
|
||||
DELIMITER $$
|
||||
$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`ticketGetTaxAdd`(vTicketFk INT)
|
||||
BEGIN
|
||||
/**
|
||||
* Añade un ticket a la tabla tmp.ticket para calcular
|
||||
* el IVA y el recargo de equivalencia y devuelve el resultado.
|
||||
*/
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticket;
|
||||
CREATE TEMPORARY TABLE tmp.ticket
|
||||
ENGINE = MEMORY
|
||||
SELECT vTicketFk ticketFk;
|
||||
|
||||
CALL vn.ticketGetTax();
|
||||
|
||||
SELECT
|
||||
tt.ticketFk,
|
||||
CAST(tt.taxableBase AS DECIMAL(10, 2)) AS taxableBase,
|
||||
CAST(tt.rate * tt.taxableBase / 100 AS DECIMAL(10, 2)) AS tax,
|
||||
pgc.*,
|
||||
CAST(IF(pe.equFk IS NULL, taxableBase, 0) AS DECIMAL(10, 2)) AS Base,
|
||||
pgc.rate / 100 as vatPercent
|
||||
FROM tmp.ticketTax tt
|
||||
JOIN vn.pgc ON pgc.code = tt.pgcFk
|
||||
LEFT JOIN vn.pgcEqu pe ON pe.equFk = pgc.code;
|
||||
|
||||
DROP TEMPORARY TABLE tmp.ticket;
|
||||
DROP TEMPORARY TABLE tmp.ticketTax;
|
||||
DROP TEMPORARY TABLE tmp.ticketAmount;
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -1,147 +0,0 @@
|
|||
USE `vn`;
|
||||
DROP procedure IF EXISTS `ticketGetProblems`;
|
||||
|
||||
DELIMITER $$
|
||||
USE `vn`$$
|
||||
CREATE DEFINER=`root`@`%` PROCEDURE `ticketGetProblems`()
|
||||
BEGIN
|
||||
|
||||
DECLARE vWarehouse INT;
|
||||
DECLARE vDate DATE;
|
||||
DECLARE vAvailableCache INT;
|
||||
DECLARE vVisibleCache INT;
|
||||
DECLARE vDone INT DEFAULT 0;
|
||||
|
||||
DECLARE vCursor CURSOR FOR
|
||||
SELECT DISTINCT tt.warehouseFk, date(tt.shipped)
|
||||
FROM tmp.ticketGetProblems tt
|
||||
WHERE DATE(tt.shipped) BETWEEN CURDATE()
|
||||
AND TIMESTAMPADD(DAY, 1.9, CURDATE());
|
||||
|
||||
DECLARE CONTINUE HANDLER FOR NOT FOUND SET vDone = 1;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketProblems;
|
||||
CREATE TEMPORARY TABLE tmp.ticketProblems (
|
||||
ticketFk INT(11) PRIMARY KEY,
|
||||
problem VARCHAR(50)
|
||||
) ENGINE = MEMORY;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.ticketList;
|
||||
CREATE TEMPORARY TABLE tmp.ticketList
|
||||
(PRIMARY KEY (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT tp.ticketFk, c.id clientFk
|
||||
FROM tmp.ticketGetProblems tp
|
||||
JOIN vn.client c ON c.id = tp.clientFk;
|
||||
|
||||
INSERT INTO tmp.ticketProblems(ticketFk, problem)
|
||||
SELECT DISTINCT tl.ticketFk, 'Freezed'
|
||||
FROM tmp.ticketList tl
|
||||
JOIN vn.client c ON c.id = tl.clientFk
|
||||
WHERE c.isFreezed;
|
||||
|
||||
DELETE tl FROM tmp.ticketList tl
|
||||
JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tmp.clientGetDebt;
|
||||
CREATE TEMPORARY TABLE tmp.clientGetDebt
|
||||
(PRIMARY KEY (clientFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT DISTINCT clientFk
|
||||
FROM tmp.ticketList;
|
||||
|
||||
CALL clientGetDebt(CURDATE());
|
||||
|
||||
INSERT INTO tmp.ticketProblems(ticketFk, problem)
|
||||
SELECT DISTINCT tl.ticketFk, 'Risk'
|
||||
FROM tmp.ticketList tl
|
||||
JOIN vn.ticket t ON t.id = tl.ticketFk
|
||||
JOIN vn.agencyMode a ON t.agencyModeFk = a.id
|
||||
JOIN tmp.risk r ON r.clientFk = t.clientFk
|
||||
JOIN vn.client c ON c.id = t.clientFk
|
||||
WHERE r.risk > c.credit + 10
|
||||
AND a.deliveryMethodFk != 3;
|
||||
|
||||
|
||||
DELETE tl FROM tmp.ticketList tl
|
||||
JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk;
|
||||
|
||||
|
||||
INSERT INTO tmp.ticketProblems(ticketFk, problem)
|
||||
SELECT DISTINCT tl.ticketFk, 'Code 100'
|
||||
FROM tmp.ticketList tl
|
||||
JOIN vn.ticketRequest tr on tr.ticketFk = tl.ticketFk;
|
||||
|
||||
DELETE tl FROM tmp.ticketList tl
|
||||
JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk;
|
||||
|
||||
OPEN vCursor;
|
||||
|
||||
WHILE NOT vDone
|
||||
DO
|
||||
FETCH vCursor INTO vWarehouse, vDate;
|
||||
|
||||
CALL cache.visible_refresh(vVisibleCache, FALSE, vWarehouse);
|
||||
CALL cache.available_refresh(vAvailableCache, FALSE, vWarehouse, vDate);
|
||||
|
||||
|
||||
INSERT INTO tmp.ticketProblems(ticketFk, problem)
|
||||
SELECT tl.ticketFk, i.name
|
||||
FROM tmp.ticketList tl
|
||||
JOIN vn.ticket t ON t.id = tl.ticketFk
|
||||
LEFT JOIN vn.sale s ON s.ticketFk = t.id
|
||||
JOIN vn.item i ON i.id = s.itemFk
|
||||
JOIN vn.itemType it on it.id = i.typeFk
|
||||
LEFT JOIN cache.visible v ON i.id = v.item_id
|
||||
AND v.calc_id = vVisibleCache
|
||||
LEFT JOIN cache.available av ON av.item_id = i.id
|
||||
AND av.calc_id = vAvailableCache
|
||||
WHERE date(t.shipped) = vDate
|
||||
AND categoryFk != 6
|
||||
AND s.quantity > IFNULL(v.visible, 0)
|
||||
AND IFNULL(av.available, 0) < 0
|
||||
AND s.isPicked = FALSE
|
||||
AND NOT i.generic
|
||||
AND vWarehouse = t.warehouseFk
|
||||
GROUP BY tl.ticketFk;
|
||||
|
||||
|
||||
DELETE tl FROM tmp.ticketList tl
|
||||
JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk;
|
||||
|
||||
|
||||
INSERT INTO tmp.ticketProblems(ticketFk, problem)
|
||||
SELECT tl.ticketFk, CONCAT('Delay', i.name)
|
||||
FROM tmp.ticketList tl
|
||||
JOIN vn.ticket t ON t.id = tl.ticketFk
|
||||
LEFT JOIN vn.sale s ON s.ticketFk = t.id
|
||||
JOIN vn.item i ON i.id = s.itemFk
|
||||
JOIN vn.itemType it on it.id = i.typeFk
|
||||
LEFT JOIN cache.visible v ON i.id = v.item_id AND v.calc_id = vVisibleCache
|
||||
LEFT JOIN cache.available av ON av.item_id = i.id AND av.calc_id = vAvailableCache
|
||||
WHERE IFNULL(av.available, 0) >= 0
|
||||
AND s.quantity > IFNULL(v.visible, 0)
|
||||
AND s.isPicked = FALSE
|
||||
AND s.reserved = FALSE
|
||||
AND it.categoryFk != 6
|
||||
AND date(t.shipped) = vDate
|
||||
AND NOT i.generic
|
||||
AND CURDATE() = vDate
|
||||
AND t.warehouseFk = vWarehouse
|
||||
GROUP BY tl.ticketFk;
|
||||
|
||||
|
||||
DELETE tl FROM tmp.ticketList tl
|
||||
JOIN tmp.ticketProblems tp ON tl.ticketFk = tp.ticketFk;
|
||||
|
||||
END WHILE;
|
||||
|
||||
CLOSE vCursor;
|
||||
|
||||
DROP TEMPORARY TABLE
|
||||
tmp.clientGetDebt,
|
||||
tmp.ticketList;
|
||||
END$$
|
||||
|
||||
DELIMITER ;
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue