Merge branch 'dev' into 6952-fixProducerNameInvoice
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:
commit
ec356423bb
|
@ -1,13 +1,13 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `cache`.`visible_refresh`(OUT v_calc INT, v_refresh BOOL, v_warehouse INT)
|
||||
proc: BEGIN
|
||||
proc:BEGIN
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
CALL cache_calc_unlock (v_calc);
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse);
|
||||
CALL cache_calc_start (v_calc, v_refresh, 'visible', v_warehouse);
|
||||
|
||||
IF !v_refresh THEN
|
||||
LEAVE proc;
|
||||
|
@ -15,22 +15,23 @@ proc: BEGIN
|
|||
|
||||
-- Calculamos el stock hasta ayer
|
||||
|
||||
CALL `cache`.stock_refresh(false);
|
||||
CALL cache.stock_refresh(false);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.itemVisible
|
||||
(PRIMARY KEY (item_id))
|
||||
ENGINE = MEMORY
|
||||
SELECT item_id, amount stock, amount visible FROM `cache`.stock
|
||||
SELECT item_id, amount stock, amount visible
|
||||
FROM cache.stock
|
||||
WHERE warehouse_id = v_warehouse;
|
||||
|
||||
-- Calculamos los movimientos confirmados de hoy
|
||||
CALL vn.item_GetVisible(v_warehouse, NULL);
|
||||
CALL vn.item_calcVisible(NULL, v_warehouse);
|
||||
DELETE FROM visible WHERE calc_id = v_calc;
|
||||
|
||||
INSERT INTO visible (calc_id, item_id,visible)
|
||||
SELECT v_calc, item_id, visible FROM tmp.itemVisible;
|
||||
|
||||
CALL cache_calc_end (v_calc);
|
||||
CALL cache_calc_end (v_calc);
|
||||
|
||||
DROP TEMPORARY TABLE tmp.itemVisible;
|
||||
END$$
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` EVENT `vn`.`claim_changeState`
|
||||
ON SCHEDULE EVERY 1 DAY
|
||||
STARTS '2024-06-06 07:52:46.000'
|
||||
ON COMPLETION PRESERVE
|
||||
ENABLE
|
||||
DO BEGIN
|
||||
|
||||
DECLARE vClaimState INT;
|
||||
|
||||
SELECT id INTO vClaimState
|
||||
FROM claimState cs
|
||||
WHERE cs.code = 'canceled';
|
||||
|
||||
UPDATE claim c
|
||||
JOIN claimState cs ON cs.id = c.claimStateFk
|
||||
SET c.claimStateFk = vClaimState
|
||||
WHERE c.created < util.VN_CURDATE() - INTERVAL 2 MONTH
|
||||
AND cs.code IN('incomplete','coming','waiting','out');
|
||||
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -26,16 +26,16 @@ BEGIN
|
|||
vErrorNumber = MYSQL_ERRNO,
|
||||
vErrorMsg = MESSAGE_TEXT;
|
||||
|
||||
CALL util.debugAdd('collection_assign', JSON_OBJECT(
|
||||
'errorNumber', vErrorNumber,
|
||||
'errorMsg', vErrorMsg,
|
||||
'lockName', vLockName,
|
||||
'userFk', vUserFk
|
||||
)); -- Tmp
|
||||
|
||||
IF vLockName IS NOT NULL THEN
|
||||
DO RELEASE_LOCK(vLockName);
|
||||
CALL util.debugAdd('collection_assign', JSON_OBJECT(
|
||||
'errorNumber', vErrorNumber,
|
||||
'errorMsg', vErrorMsg,
|
||||
'lockName', vLockName,
|
||||
'userFk', vUserFk
|
||||
)); -- Tmp
|
||||
END IF;
|
||||
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
|
|
|
@ -53,17 +53,17 @@ BEGIN
|
|||
vErrorNumber = MYSQL_ERRNO,
|
||||
vErrorMsg = MESSAGE_TEXT;
|
||||
|
||||
CALL util.debugAdd('collection_new', JSON_OBJECT(
|
||||
'errorNumber', vErrorNumber,
|
||||
'errorMsg', vErrorMsg,
|
||||
'lockName', vLockName,
|
||||
'userFk', vUserFk,
|
||||
'ticketFk', vTicketFk
|
||||
)); -- Tmp
|
||||
|
||||
IF vLockName IS NOT NULL THEN
|
||||
DO RELEASE_LOCK(vLockName);
|
||||
CALL util.debugAdd('collection_new', JSON_OBJECT(
|
||||
'errorNumber', vErrorNumber,
|
||||
'errorMsg', vErrorMsg,
|
||||
'lockName', vLockName,
|
||||
'userFk', vUserFk,
|
||||
'ticketFk', vTicketFk
|
||||
)); -- Tmp
|
||||
END IF;
|
||||
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_GetVisible`(vWarehouse SMALLINT, vItem INT)
|
||||
BEGIN
|
||||
DECLARE vTomorrow DATETIME DEFAULT TIMESTAMPADD(DAY, 1, util.VN_CURDATE());
|
||||
|
||||
INSERT INTO tmp.itemVisible (item_id, visible)
|
||||
SELECT item_id, SUM(amount) amount
|
||||
FROM (
|
||||
SELECT i.itemFk AS item_id, quantity AS amount
|
||||
FROM itemTicketOut i
|
||||
LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk
|
||||
JOIN state s ON s.id = ts.stateFk
|
||||
LEFT JOIN (SELECT DISTINCT saleFk
|
||||
FROM saleTracking st
|
||||
JOIN state s ON s.id = st.stateFk
|
||||
WHERE st.created > util.VN_CURDATE()
|
||||
AND (s.isPicked OR st.isChecked)
|
||||
) stPrevious ON `stPrevious`.`saleFk` = i.saleFk
|
||||
WHERE i.warehouseFk = vWarehouse
|
||||
AND (vItem IS NULL OR i.itemFk = vItem)
|
||||
AND (s.isPicked OR i.reserved OR stPrevious.saleFk )
|
||||
AND i.shipped >= util.VN_CURDATE() AND i.shipped < vTomorrow
|
||||
UNION ALL
|
||||
SELECT iei.itemFk, quantity
|
||||
FROM itemEntryIn iei
|
||||
WHERE (iei.isReceived != FALSE /*OR ip.modificationDate > util.VN_CURDATE()*/)
|
||||
AND iei.landed >= util.VN_CURDATE() AND iei.landed < vTomorrow
|
||||
AND iei.warehouseInFk = vWarehouse
|
||||
AND (vItem IS NULL OR iei.itemFk = vItem)
|
||||
AND iei.isVirtualStock is FALSE
|
||||
UNION ALL
|
||||
SELECT itemFk, quantity
|
||||
FROM itemEntryOut
|
||||
WHERE isDelivered != FALSE
|
||||
AND shipped >= util.VN_CURDATE() AND shipped < vTomorrow
|
||||
AND warehouseOutFk = vWarehouse
|
||||
AND (vItem IS NULL OR itemFk = vItem)
|
||||
) t
|
||||
GROUP BY item_id
|
||||
ON DUPLICATE KEY UPDATE
|
||||
visible = IFNULL(stock,0) + VALUES(visible);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -0,0 +1,56 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`item_calcVisible`(
|
||||
vSelf INT,
|
||||
vWarehouseFk INT
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula el visible de un artículo o de todos.
|
||||
*
|
||||
* @param vWarehouse Warehouse id
|
||||
* @param vSelf Item id
|
||||
* @param tmp.itemVisible(item_id, stock, visible)
|
||||
*/
|
||||
DECLARE vDated DATE DEFAULT util.VN_CURDATE();
|
||||
DECLARE vTomorrow DATETIME DEFAULT util.tomorrow();
|
||||
|
||||
INSERT INTO tmp.itemVisible(item_id, visible)
|
||||
SELECT itemFk, SUM(quantity)
|
||||
FROM (
|
||||
SELECT i.itemFk, i.quantity
|
||||
FROM itemTicketOut i
|
||||
LEFT JOIN ticketState ts ON ts.ticketFk = i.ticketFk
|
||||
JOIN `state` s ON s.id = ts.stateFk
|
||||
LEFT JOIN (
|
||||
SELECT DISTINCT st.saleFk
|
||||
FROM saleTracking st
|
||||
JOIN state s ON s.id = st.stateFk
|
||||
WHERE st.created > vDated
|
||||
AND (s.isPicked OR st.isChecked)
|
||||
) stPrevious ON `stPrevious`.`saleFk` = i.saleFk
|
||||
WHERE IFNULL(vWarehouseFk, i.warehouseFk) = i.warehouseFk
|
||||
AND (vSelf IS NULL OR i.itemFk = vSelf)
|
||||
AND (s.isPicked OR i.reserved OR stPrevious.saleFk)
|
||||
AND i.shipped >= vDated AND i.shipped < vTomorrow
|
||||
UNION ALL
|
||||
SELECT itemFk, quantity
|
||||
FROM itemEntryIn
|
||||
WHERE isReceived
|
||||
AND landed >= vDated AND landed < vTomorrow
|
||||
AND IFNULL(vWarehouseFk, warehouseInFk) = warehouseInFk
|
||||
AND (vSelf IS NULL OR itemFk = vSelf)
|
||||
AND NOT isVirtualStock
|
||||
UNION ALL
|
||||
SELECT itemFk, quantity
|
||||
FROM itemEntryOut
|
||||
WHERE isDelivered
|
||||
AND shipped >= vDated
|
||||
AND shipped < vTomorrow
|
||||
AND IFNULL(vWarehouseFk, warehouseOutFk) = warehouseOutFk
|
||||
AND (vSelf IS NULL OR itemFk = vSelf)
|
||||
) t
|
||||
GROUP BY itemFk
|
||||
ON DUPLICATE KEY UPDATE
|
||||
visible = IFNULL(stock, 0) + VALUES(visible);
|
||||
END$$
|
||||
DELIMITER ;
|
|
@ -10,6 +10,7 @@ proc: BEGIN
|
|||
DECLARE vDateTo DATETIME;
|
||||
DECLARE vDateToTomorrow DATETIME;
|
||||
DECLARE vDefaultDayRange INT;
|
||||
DECLARE vCalcFk INT;
|
||||
|
||||
IF vDate < util.VN_CURDATE() THEN
|
||||
LEAVE proc;
|
||||
|
@ -82,50 +83,18 @@ proc: BEGIN
|
|||
ai.sd = iic.quantity;
|
||||
|
||||
-- Cálculo del visible
|
||||
CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc
|
||||
(PRIMARY KEY (itemFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT itemFk, SUM(quantity) visible
|
||||
FROM (
|
||||
SELECT s.itemFk, s.quantity
|
||||
FROM sale s
|
||||
JOIN ticket t ON t.id = s.ticketFk
|
||||
JOIN warehouse w ON w.id = t.warehouseFk
|
||||
WHERE t.shipped >= vDate
|
||||
AND t.shipped < vDateTomorrow
|
||||
AND (NOT isPicked AND NOT t.isLabeled AND t.refFk IS NULL)
|
||||
AND IFNULL(vWarehouseFk, t.warehouseFk) = t.warehouseFk
|
||||
AND w.isComparative
|
||||
UNION ALL
|
||||
SELECT b.itemFk, - b.quantity
|
||||
FROM buy b
|
||||
JOIN entry e ON e.id = b.entryFk
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
JOIN warehouse w ON w.id = t.warehouseInFk
|
||||
WHERE t.landed = vDate
|
||||
AND NOT t.isReceived
|
||||
AND NOT e.isExcludedFromAvailable
|
||||
AND NOT e.isRaid
|
||||
AND IFNULL(vWarehouseFk, t.warehouseInFk) = t.warehouseInFk
|
||||
AND w.isComparative
|
||||
UNION ALL
|
||||
SELECT b.itemFk, b.quantity
|
||||
FROM buy b
|
||||
JOIN entry e ON e.id = b.entryFk
|
||||
JOIN travel t ON t.id = e.travelFk
|
||||
JOIN warehouse w ON w.id = t.warehouseOutFk
|
||||
WHERE t.shipped = vDate
|
||||
AND NOT t.isReceived
|
||||
AND NOT e.isExcludedFromAvailable
|
||||
AND NOT e.isRaid
|
||||
AND IFNULL(vWarehouseFk, t.warehouseOutFk) = t.warehouseOutFk
|
||||
AND w.isComparative
|
||||
) sub2
|
||||
GROUP BY itemFk;
|
||||
CALL cache.visible_refresh(vCalcFk, FALSE, vWarehouseFk);
|
||||
|
||||
UPDATE tmp.itemInventory ai
|
||||
JOIN tItemVisibleCalc ivc ON ivc.itemFk = ai.id
|
||||
SET ai.visible = ai.visible + ivc.visible;
|
||||
CREATE OR REPLACE TEMPORARY TABLE tItemVisibleCalc
|
||||
(PRIMARY KEY (item_id))
|
||||
ENGINE = MEMORY
|
||||
SELECT item_id, visible
|
||||
FROM cache.visible
|
||||
WHERE calc_id = vCalcFk;
|
||||
|
||||
UPDATE tmp.itemInventory it
|
||||
JOIN tItemVisibleCalc ivc ON ivc.item_id = it.id
|
||||
SET it.visible = it.visible + ivc.visible;
|
||||
|
||||
-- Calculo del disponible
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc
|
||||
|
@ -196,8 +165,8 @@ proc: BEGIN
|
|||
DROP TEMPORARY TABLE
|
||||
tmp.itemTravel,
|
||||
tmp.itemCalc,
|
||||
tmp.itemAtp,
|
||||
tItemInventoryCalc,
|
||||
tItemVisibleCalc,
|
||||
tmp.itemAtp;
|
||||
tItemVisibleCalc;
|
||||
END$$
|
||||
DELIMITER ;
|
||||
|
|
|
@ -16,6 +16,9 @@ BEGIN
|
|||
DECLARE vNewTicketFk INT;
|
||||
DECLARE vPackingTypesToSplit INT;
|
||||
DECLARE vDone INT DEFAULT FALSE;
|
||||
DECLARE vErrorNumber INT;
|
||||
DECLARE vErrorMsg TEXT;
|
||||
|
||||
DECLARE vSaleGroup CURSOR FOR
|
||||
SELECT itemPackingTypeFk
|
||||
FROM tSaleGroup
|
||||
|
@ -26,6 +29,15 @@ BEGIN
|
|||
|
||||
DECLARE EXIT HANDLER FOR SQLEXCEPTION
|
||||
BEGIN
|
||||
GET DIAGNOSTICS CONDITION 1
|
||||
vErrorNumber = MYSQL_ERRNO,
|
||||
vErrorMsg = MESSAGE_TEXT;
|
||||
|
||||
CALL util.debugAdd('ticket_splitItemPackingType', JSON_OBJECT(
|
||||
'errorNumber', vErrorNumber,
|
||||
'errorMsg', vErrorMsg,
|
||||
'ticketFk', vSelf
|
||||
)); -- Tmp
|
||||
ROLLBACK;
|
||||
RESIGNAL;
|
||||
END;
|
||||
|
|
|
@ -5,4 +5,19 @@ CREATE TABLE IF NOT EXISTS `vn`.`agencyIncoming` (
|
|||
)
|
||||
ENGINE=InnoDB
|
||||
DEFAULT CHARSET=utf8mb3
|
||||
COLLATE=utf8mb3_unicode_ci COMMENT='Agencias de entrada de mercancias';;
|
||||
COLLATE=utf8mb3_unicode_ci COMMENT='Agencias de entrada de mercancias';
|
||||
|
||||
INSERT IGNORE INTO vn.agencyIncoming (agencyModeFk) VALUES
|
||||
(1343), (1002), (1282), (841), (1303), (714), (556), (1786), (1785), (1784),
|
||||
(1780), (1783), (1758), (1782), (1772), (1789), (1776), (1791), (1778), (1792),
|
||||
(1779), (1362), (681), (1765), (15), (1594), (1706), (1707), (907), (1260),
|
||||
(1715), (1371), (1372), (53), (689), (1375), (738), (742), (1307), (1700), (608),
|
||||
(1311), (1315), (1339), (1433), (1338), (1332), (1844), (842), (1382), (1466),
|
||||
(1719), (1723), (1725), (1720), (1732), (1736), (1728), (1724), (1726), (1727),
|
||||
(1767), (1734), (1730), (1845), (1729), (1746), (1699), (2), (671), (1379), (614),
|
||||
(1718), (1697), (62), (1529), (1392), (1378), (1438), (1796), (1688), (686),
|
||||
(1326), (1691), (1), (1560), (1695), (1696), (1558), (1648), (1649), (1598),
|
||||
(1680), (1694), (1600), (1601), (1602), (1712), (1603), (1604), (1641), (1692),
|
||||
(1693), (1650), (1683), (1682), (1681), (1713), (1826), (1768), (1769), (1770),
|
||||
(1593), (1443), (1244), (1679), (1006), (1361), (1102), (1655), (1744), (1225),
|
||||
(1007);
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE vn.vehicle DROP FOREIGN KEY provinceFk;
|
||||
ALTER TABLE vn.vehicle
|
||||
ADD CONSTRAINT vehicle_warehouse_FK FOREIGN KEY (warehouseFk) REFERENCES vn.warehouse(id) ON DELETE RESTRICT ON UPDATE CASCADE;
|
|
@ -0,0 +1,2 @@
|
|||
ALTER TABLE vn.payrollWorker CHANGE grupotarifa__ grupotarifa int(10) NOT NULL;
|
||||
ALTER TABLE vn.payrollWorker MODIFY COLUMN grupotarifa int(10) NOT NULL;
|
|
@ -347,6 +347,18 @@ module.exports = Self => {
|
|||
if (hasWhere)
|
||||
stmt.merge(conn.makeWhere(problems));
|
||||
|
||||
if (filter.order) {
|
||||
if (typeof filter.order == 'string') filter.order = [filter.order];
|
||||
const index = filter.order.findIndex(o => o.includes('stateFk'));
|
||||
if (index > -1) {
|
||||
filter.order = [
|
||||
...filter.order.slice(0, index),
|
||||
'refFk ' + filter.order[index].split(' ')[1],
|
||||
...filter.order.slice(index)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
stmt.merge(conn.makeOrderBy(filter.order));
|
||||
stmt.merge(conn.makeLimit(filter));
|
||||
const ticketsIndex = stmts.push(stmt) - 1;
|
||||
|
|
Loading…
Reference in New Issue