From 9448b4053392a52df4040cf1ccb89c5122516ed5 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 2 Feb 2024 14:53:48 +0100 Subject: [PATCH 01/20] refs #6386 feat: add extension when return file --- back/methods/image/download.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/methods/image/download.js b/back/methods/image/download.js index c4037b809..2b1a4b546 100644 --- a/back/methods/image/download.js +++ b/back/methods/image/download.js @@ -87,6 +87,6 @@ module.exports = Self => { await fs.access(file.path); const stream = fs.createReadStream(file.path); - return [stream, file.contentType, `filename="${file.name}"`]; + return [stream, file.contentType, `filename="${fileName}"`]; }; }; From 53a367f4b3064747a6160e7008af40ace0de55e8 Mon Sep 17 00:00:00 2001 From: robert Date: Thu, 8 Feb 2024 13:04:06 +0100 Subject: [PATCH 02/20] feat: refs #6371 cleanTablesFix --- db/routines/vn/views/agencyWarehouse.sql | 7 ------- db/routines/vn/views/clientDefaultCompany.sql | 9 -------- db/routines/vn/views/coolerPath.sql | 6 ------ db/routines/vn/views/grantGroup.sql | 7 ------- db/routines/vn2008/procedures/clean.sql | 8 ------- .../10876-goldenRoebelini/00-firstScript.sql | 21 +++++++++++++++++++ 6 files changed, 21 insertions(+), 37 deletions(-) delete mode 100644 db/routines/vn/views/agencyWarehouse.sql delete mode 100644 db/routines/vn/views/clientDefaultCompany.sql delete mode 100644 db/routines/vn/views/coolerPath.sql delete mode 100644 db/routines/vn/views/grantGroup.sql create mode 100644 db/versions/10876-goldenRoebelini/00-firstScript.sql diff --git a/db/routines/vn/views/agencyWarehouse.sql b/db/routines/vn/views/agencyWarehouse.sql deleted file mode 100644 index 6cb174544..000000000 --- a/db/routines/vn/views/agencyWarehouse.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`agencyWarehouse` -AS SELECT `a`.`agency_id` AS `agencyFk`, - `a`.`warehouse_id` AS `warehouseFk`, - `a`.`Vista` AS `agencyType` -FROM `vn2008`.`agency_warehouse` `a` diff --git a/db/routines/vn/views/clientDefaultCompany.sql b/db/routines/vn/views/clientDefaultCompany.sql deleted file mode 100644 index 6af418a1a..000000000 --- a/db/routines/vn/views/clientDefaultCompany.sql +++ /dev/null @@ -1,9 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`clientDefaultCompany` -AS SELECT `t`.`Id_Clientes_empresa` AS `id`, - `t`.`Id_Cliente` AS `clientFk`, - `t`.`empresa_id` AS `companyFk`, - `t`.`fecha_ini` AS `started`, - `t`.`fecha_fin` AS `finished` -FROM `vn2008`.`Clientes_empresa` `t` diff --git a/db/routines/vn/views/coolerPath.sql b/db/routines/vn/views/coolerPath.sql deleted file mode 100644 index 6be11e557..000000000 --- a/db/routines/vn/views/coolerPath.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`coolerPath` -AS SELECT `c`.`cooler_path_id` AS `id`, - `c`.`description` AS `description` -FROM `vn2008`.`cooler_path` `c` diff --git a/db/routines/vn/views/grantGroup.sql b/db/routines/vn/views/grantGroup.sql deleted file mode 100644 index 267c3154e..000000000 --- a/db/routines/vn/views/grantGroup.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE OR REPLACE DEFINER=`root`@`localhost` - SQL SECURITY DEFINER - VIEW `vn`.`grantGroup` -AS SELECT `vn2008`.`Grupos`.`id` AS `id`, - `vn2008`.`Grupos`.`Grupo` AS `description`, - `vn2008`.`Grupos`.`observation_type_id` AS `observationTypeFk` -FROM `vn2008`.`Grupos` diff --git a/db/routines/vn2008/procedures/clean.sql b/db/routines/vn2008/procedures/clean.sql index bd8a324c6..8c36cced8 100644 --- a/db/routines/vn2008/procedures/clean.sql +++ b/db/routines/vn2008/procedures/clean.sql @@ -21,18 +21,10 @@ proc: BEGIN SET vRangeDeleteTicket = 60; DELETE FROM cdr WHERE calldate < vDate18; - DELETE FROM Monitoring WHERE ODBC_TIME < vDate; - DELETE FROM Conteo WHERE Fecha < vDate; DELETE FROM mail WHERE DATE_ODBC < vDate; - DELETE FROM expeditions_deleted WHERE odbc_date < vDate26; DELETE FROM Movimientos_mark WHERE odbc_date < vDate; DELETE FROM Splits WHERE Fecha < vDate18; - DELETE ts - FROM Tickets_stack ts - JOIN Tickets t ON ts.Id_Ticket = t.Id_Ticket - WHERE t.Fecha < vDate; - DELETE tobs FROM ticket_observation tobs JOIN Tickets t ON tobs.Id_Ticket = t.Id_Ticket diff --git a/db/versions/10876-goldenRoebelini/00-firstScript.sql b/db/versions/10876-goldenRoebelini/00-firstScript.sql new file mode 100644 index 000000000..361f3c7c8 --- /dev/null +++ b/db/versions/10876-goldenRoebelini/00-firstScript.sql @@ -0,0 +1,21 @@ +ALTER TABLE IF EXISTS vn2008.Compres_ok__ RENAME vn2008.Compres_ok; +ALTER TABLE IF EXISTS vn2008.Compres_ok COMMENT=''; + + +-- Para la tabla Monitoring +ALTER TABLE IF EXISTS vn2008.Monitoring RENAME vn2008.Monitoring__; +ALTER TABLE IF EXISTS vn2008.Monitoring__ COMMENT='refs #6371 deprecated 2024-01-11'; + +-- Para la tabla Movimientos_avisar +ALTER TABLE IF EXISTS vn2008.Movimientos_avisar RENAME vn2008.Movimientos_avisar__; +ALTER TABLE IF EXISTS vn2008.Movimientos_avisar__ COMMENT='refs #6371 deprecated 2024-01-11'; + + +-- Para la tabla Movimientos_revisar +ALTER TABLE IF EXISTS vn2008.Movimientos_revisar RENAME vn2008.Movimientos_revisar__; +ALTER TABLE IF EXISTS vn2008.Movimientos_revisar__ COMMENT='refs #6371 deprecated 2024-01-11'; + + +-- Para la tabla Proveedores_escritos +ALTER TABLE IF EXISTS vn2008.Proveedores_escritos RENAME vn2008.Proveedores_escritos__; +ALTER TABLE IF EXISTS vn2008.Proveedores_escritos__ COMMENT='refs #6371 deprecated 2024-01-11'; \ No newline at end of file From cc863a65f65038f1e5f6c225983bef0598c999c2 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 9 Feb 2024 11:40:20 +0100 Subject: [PATCH 03/20] refactor: refs #6501 Migrated procs from vn2008 to vn --- .../vn/procedures/XDiario_reconciliation.sql | 41 ++++ .../vn/procedures/entry_getTransfer.sql | 203 ++++++++++++++++++ .../vn/procedures/supplier_statement.sql | 139 ++++++++++++ db/routines/vn/procedures/travel_detail.sql | 103 +++++++++ .../vn2008/procedures/XDiario_Quadrator.sql | 34 --- .../vn2008/procedures/supplierStatement.sql | 117 ---------- db/routines/vn2008/procedures/traslado.sql | 182 ---------------- .../vn2008/procedures/travelDetail.sql | 119 ---------- .../10878-blueSalal/00-firstScript.sql | 4 + 9 files changed, 490 insertions(+), 452 deletions(-) create mode 100644 db/routines/vn/procedures/XDiario_reconciliation.sql create mode 100644 db/routines/vn/procedures/entry_getTransfer.sql create mode 100644 db/routines/vn/procedures/supplier_statement.sql create mode 100644 db/routines/vn/procedures/travel_detail.sql delete mode 100644 db/routines/vn2008/procedures/XDiario_Quadrator.sql delete mode 100644 db/routines/vn2008/procedures/supplierStatement.sql delete mode 100644 db/routines/vn2008/procedures/traslado.sql delete mode 100644 db/routines/vn2008/procedures/travelDetail.sql create mode 100644 db/versions/10878-blueSalal/00-firstScript.sql diff --git a/db/routines/vn/procedures/XDiario_reconciliation.sql b/db/routines/vn/procedures/XDiario_reconciliation.sql new file mode 100644 index 000000000..c4724849d --- /dev/null +++ b/db/routines/vn/procedures/XDiario_reconciliation.sql @@ -0,0 +1,41 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_reconciliation`() +BEGIN +/** + * Realiza la conciliación diaria de los asientos contables, + * identificando y notificando los asientos descuadrados + * y ajustando los saldos en caso necesario. + */ + INSERT INTO mail (receiver, subject, body) + SELECT 'cau@verdnatura.es', + 'Asientos descuadrados', + GROUP_CONCAT(CONCAT(' Asiento: ', ASIEN, ' - Importe:', recon) SEPARATOR ' | \n') + FROM ( + SELECT ASIEN, + SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon + FROM XDiario + WHERE NOT enlazado + GROUP BY ASIEN + HAVING ABS(SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0))) > 0.01 + ) sub + HAVING COUNT(*); + + UPDATE XDiario xd + JOIN ( + SELECT xd.id, SUBCTA, recon + FROM XDiario xd + JOIN ( + SELECT ASIEN, + SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon + FROM XDiario + WHERE NOT enlazado + GROUP BY ASIEN + HAVING recon + ) sub ON sub.ASIEN = xd.ASIEN + WHERE xd.SUBCTA > '5999999999' + GROUP BY xd.ASIEN + ) sub ON sub.id = xd.id + SET xd.Eurohaber = IF(IFNULL(xd.Eurohaber, 0) = 0, xd.Eurohaber, xd.Eurohaber + sub.recon), + xd.Eurodebe = IF(IFNULL(xd.Eurodebe, 0) = 0, xd.Eurodebe, xd.Eurodebe - sub.recon); +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql new file mode 100644 index 000000000..2c9fe8577 --- /dev/null +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -0,0 +1,203 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_getTransfer`( + vSelf INT +) +BEGIN +/** + * Gestiona el traslado de productos a partir de una entrada específica. + * + * @param vSelf Id de entrada + */ + DECLARE vDateShipped DATE; + DECLARE vDateLanded DATE; + DECLARE vWarehouseIn INT; + DECLARE vWarehouseOut INT; + DECLARE vCalcVisible INT; + DECLARE vInventoryDate DATE DEFAULT vn.getInventoryDate(); + + SELECT shipped, landed, warehouseInFk, warehouseOutFk + INTO vDateShipped, vDateLanded, vWarehouseIn, vWarehouseOut + FROM vn.travel t + JOIN vn.entry e ON e.travelFk = t.id + WHERE e.id = vSelf; + + CALL vn.rate_getPrices(vDateShipped, vWarehouseIn); + + -- Traslado en almacen origen + CREATE OR REPLACE TEMPORARY TABLE tBuy + (PRIMARY KEY (itemFk), INDEX(buyFk)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT b.itemFk, b.id buyFk + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vInventoryDate AND vDateShipped + AND NOT b.isIgnored + AND b.price2 >= 0 + ORDER BY (vWarehouseOut = t.warehouseInFk) DESC, t.landed DESC + LIMIT 10000000000000000000 + ) sub + GROUP BY itemFk; + + IF vDateShipped >= util.VN_CURDATE() THEN + CALL `cache`.visible_refresh(vCalcVisible, TRUE, vWarehouseOut); + + CREATE OR REPLACE TEMPORARY TABLE tItem ( + `itemFk` int(10) unsigned NOT NULL, + `visible` int(11) NOT NULL DEFAULT 0, + `available` int(11) NOT NULL DEFAULT 0, + `visibleLanding` int(11) NOT NULL DEFAULT 0, + `availableLanding` int(11) NOT NULL DEFAULT 0, + UNIQUE INDEX i USING HASH (itemFk) + ) ENGINE = MEMORY; + + INSERT INTO tItem(itemFk, visible) + SELECT item_id itemFk, visible + FROM `cache`.visible + WHERE calc_id = vCalcVisible + AND visible; + + CALL `cache`.visible_refresh(vCalcVisible, TRUE, vWarehouseIn); + + INSERT INTO tItem(itemFk, visibleLanding) + SELECT item_id, `visible` + FROM `cache`.`visible` v + WHERE v.calc_id = vCalcVisible + AND v.`visible` + ON DUPLICATE KEY UPDATE visibleLanding = v.`visible`; + + CALL vn2008.availableTraslate(vWarehouseOut, vDateShipped, NULL); + + INSERT INTO tItem(itemFk, available) + SELECT a.item_id, a.available + FROM vn2008.availableTraslate a + WHERE a.available + ON DUPLICATE KEY UPDATE available = a.available; + + CALL vn2008.availableTraslate(vWarehouseIn, vDateLanded, vWarehouseOut); + + INSERT INTO tItem(itemFk, availableLanding) + SELECT a.item_id, a.available + FROM vn2008.availableTraslate a + WHERE a.available + ON DUPLICATE KEY UPDATE availableLanding = a.available; + ELSE + CALL vn.item_getStock(vWarehouseOut, vDateShipped, NULL); + + CREATE OR REPLACE TEMPORARY TABLE tItem + (UNIQUE INDEX i USING HASH (itemFk)) + ENGINE = MEMORY + SELECT itemFk, + `visible`, + available, + 0 visibleLanding, + 0 availableLanding + FROM tmp.itemList; + END IF; + + CALL vn.buyUltimateFromInterval(vWarehouseIn,vInventoryDate, vDateLanded); + + CREATE OR REPLACE TEMPORARY TABLE tTransfer + ENGINE = MEMORY + SELECT it.categoryFk, + i.typeFk, + i.id itemFk, + i.name item, + i.`size`, + i.category, + i.inkFk, + o.code originCode, + b2.quantity, + i.stems, + CAST(ti.visible AS DECIMAL(10,0)) vis1, + CAST(ti.available AS DECIMAL(10,0)) ava1, + CAST(ti.visibleLanding AS DECIMAL(10,0)) vis2, + CAST(ti.availableLanding AS DECIMAL(10,0)) ava, + COALESCE(b2.`grouping`, b.`grouping`) `grouping`, + COALESCE(b2.packing, b.packing) packing, + COALESCE(b3.groupingMode, b2.groupingMode, b.groupingMode) package, + IFNULL(p.name, s.nickname) productor, + b.packagingFk, + b2.id buyFk, + b2.stickers, + b.ektFk, + it.workerFk, + pa.volume, + IFNULL(pa.width, 0) width, + IFNULL(pa.`depth`, 0) `depth`, + IFNULL(pa.height, 0) height, + IFNULL(b.buyingValue, 0) buyingValue, + IFNULL(b.comissionValue, 0) comissionValue, + IFNULL(b.freightValue, 0) freightValue, + am.m3, + e.commission, + pa.isPackageReturnable, + IFNULL(pa2.value, pa.value) `value`, + r.rate3, + r.rate2, + it.promo, + b.`grouping` groupingOrigin, + b.packing packingOrigin, + b.id buyFkOrigin, + pa.returnCost, + b.weight + FROM vn.item i + JOIN tItem ti ON ti.itemFk = i.id + LEFT JOIN vn.producer p ON p.id = i.producerFk + LEFT JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN vn.origin o ON o.id = i.originFk + LEFT JOIN tBuy lb ON lb.itemFk = i.id + LEFT JOIN vn.buy b ON b.id = lb.buyFk + LEFT JOIN vn.packaging pa ON pa.id = b.packagingFk + LEFT JOIN vn.entry e2 ON e2.id = b.entryFk + LEFT JOIN vn.supplier s ON s.id = e2.supplierFk + LEFT JOIN vn.entry e ON e.id = vSelf + LEFT JOIN vn.travel tr ON tr.id = e.travelFk + LEFT JOIN vn.agencyMode am ON am.id = tr.agencyModeFk + LEFT JOIN vn.buy b2 ON b2.itemFk = i.id + AND b2.entryFk = vSelf + LEFT JOIN vn.packaging pa2 ON pa2.id = b.packagingFk + LEFT JOIN tmp.rate r ON TRUE + LEFT JOIN tmp.buyUltimateFromInterval bufi ON bufi.itemFk = i.id + LEFT JOIN vn.buy b3 ON b3.id = bufi.buyFk + WHERE ic.display + AND NOT e.isRaid + AND (ti.visible != 0 OR ti.available != 0) + ORDER BY i.typeFk, i.name, i.id, i.size, i.category, o.name; + + CREATE INDEX tIndex USING HASH ON tTransfer (itemFk); + + SET @carriage := 0; + SET @comission := 0; + SET @packaging := 0; + SET @rate3 := 0; + SET @cost := 0; + SELECT *, + quantity - MOD(quantity , `grouping`) subQuantity, + MOD(quantity, `grouping`) soll, + ROUND((IF(volume > 0,volume, width * `depth` * IF(height = 0, `size` + 10, height))) / packing, 0) cm3, + buyingValue + comissionValue + freightValue Cost, + @carriage := ROUND((IF(volume > 0, volume, width * `depth` * IF(height = 0, `size` + 10, height))) * m3 / 1000000 / Packing, 3) carriage, + @comission := ROUND((buyingValue + comissionValue + freightValue) * commission / 100, 3) commission, + ROUND(@packaging := (returnCost + IF(isPackageReturnable != 0, 0, value)) / packing, 3) packaging, + @cost := IFNULL((buyingValue + comissionValue + freightValue), 0) + + IFNULL(@packaging, 0) + + IFNULL(@carriage, 0) + + IFNULL(@comission, 0) cost, + @rate3 := ROUND(@cost / ( (100 - rate3 - promo) / 100), 2) rate3, + ROUND(@rate3 * (1 + ((rate2 - rate3)/100)), 2) rate2, + FALSE selected + FROM tTransfer; + + DROP TEMPORARY TABLE IF EXISTS + tTransfer, + tItem, + tBuy, + tmp.buyUltimateFromInterval, + tmp.rate, + tmp.itemList; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/supplier_statement.sql b/db/routines/vn/procedures/supplier_statement.sql new file mode 100644 index 000000000..406286e9d --- /dev/null +++ b/db/routines/vn/procedures/supplier_statement.sql @@ -0,0 +1,139 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplier_statement`( + vSupplierFk INT, + vCurrencyFk INT, + vCompanyFk INT, + vOrderBy VARCHAR(15), + vIsConciliated BOOL +) +BEGIN +/** + * Crea un estado de cuenta de proveedores calculando + * los saldos en euros y en la moneda especificada. + * + * @param vSupplierFk Id del proveedor + * @param vCurrencyFk Id de la moneda + * @param vCompanyFk Id de la empresa + * @param vOrderBy Criterio de ordenación + * @param vIsConciliated Indica si está conciliado o no + * @return tmp.supplierStatement + */ + SET @euroBalance:= 0; + SET @currencyBalance:= 0; + + CREATE OR REPLACE TEMPORARY TABLE tmp.supplierStatement + ENGINE = MEMORY + SELECT *, + @euroBalance:= ROUND( + @euroBalance + IFNULL(paymentEuros, 0) - + IFNULL(invoiceEuros, 0), 2 + ) euroBalance, + @currencyBalance:= ROUND( + @currencyBalance + IFNULL(paymentCurrency, 0) - + IFNULL(invoiceCurrency, 0), 2 + ) currencyBalance + FROM ( + SELECT * FROM + ( + SELECT NULL bankFk, + ii.companyFk, + ii.serial, + ii.id, + CASE + WHEN vOrderBy = 'issued' THEN ii.issued + WHEN vOrderBy = 'bookEntried' THEN ii.bookEntried + WHEN vOrderBy = 'booked' THEN ii.booked + WHEN vOrderBy = 'dueDate' THEN iid.dueDated + END dated, + CONCAT('S/Fra ', ii.supplierRef) sref, + IF(ii.currencyFk > 1, + ROUND(SUM(iid.foreignValue) / SUM(iid.amount), 3), + NULL + ) changeValue, + CAST(SUM(iid.amount) AS DECIMAL(10,2)) invoiceEuros, + CAST(SUM(iid.foreignValue) AS DECIMAL(10,2)) invoiceCurrency, + NULL paymentEuros, + NULL paymentCurrency, + ii.currencyFk, + ii.isBooked, + c.code, + 'invoiceIn' statementType + FROM invoiceIn ii + JOIN invoiceInDueDay iid ON iid.invoiceInFk = ii.id + JOIN currency c ON c.id = ii.currencyFk + WHERE ii.issued > '2014-12-31' + AND ii.supplierFk = vSupplierFk + AND vCurrencyFk IN (ii.currencyFk, 0) + AND vCompanyFk IN (ii.companyFk, 0) + AND (vIsConciliated = ii.isBooked OR NOT vIsConciliated) + GROUP BY iid.id + UNION ALL + SELECT p.bankFk, + p.companyFk, + NULL, + p.id, + CASE + WHEN vOrderBy = 'issued' THEN p.received + WHEN vOrderBy = 'bookEntried' THEN p.received + WHEN vOrderBy = 'booked' THEN p.received + WHEN vOrderBy = 'dueDate' THEN p.dueDated + END, + CONCAT(IFNULL(pm.name, ''), + IF(pn.concept <> '', + CONCAT(' : ', pn.concept), + '') + ), + IF(p.currencyFk > 1, p.divisa / p.amount, NULL), + NULL, + NULL, + p.amount, + p.divisa, + p.currencyFk, + p.isConciliated, + c.code, + 'payment' + FROM payment p + LEFT JOIN currency c ON c.id = p.currencyFk + LEFT JOIN bank b ON b.id = p.bankFk + LEFT JOIN payMethod pm ON pm.id = p.payMethodFk + LEFT JOIN promissoryNote pn ON pn.paymentFk = p.id + WHERE p.received > '2014-12-31' + AND p.supplierFk = vSupplierFk + AND vCurrencyFk IN (p.currencyFk, 0) + AND vCompanyFk IN (p.companyFk, 0) + AND (vIsConciliated = p.isConciliated OR NOT vIsConciliated) + UNION ALL + SELECT NULL, + companyFk, + NULL, + se.id, + CASE + WHEN vOrderBy = 'issued' THEN se.dated + WHEN vOrderBy = 'bookEntried' THEN se.dated + WHEN vOrderBy = 'booked' THEN se.dated + WHEN vOrderBy = 'dueDate' THEN se.dueDated + END, + se.description, + 1, + amount, + NULL, + NULL, + NULL, + currencyFk, + isConciliated, + c.`code`, + 'expense' + FROM supplierExpense se + JOIN currency c ON c.id = se.currencyFk + WHERE se.supplierFk = vSupplierFk + AND vCurrencyFk IN (se.currencyFk,0) + AND vCompanyFk IN (se.companyFk,0) + AND (vIsConciliated = se.isConciliated OR NOT vIsConciliated) + ) sub + ORDER BY (dated IS NULL AND NOT isBooked), + dated, + IF(vOrderBy = 'dueDate', id, NULL) + LIMIT 10000000000000000000 + ) t; +END$$ +DELIMITER ; diff --git a/db/routines/vn/procedures/travel_detail.sql b/db/routines/vn/procedures/travel_detail.sql new file mode 100644 index 000000000..d805f0ca9 --- /dev/null +++ b/db/routines/vn/procedures/travel_detail.sql @@ -0,0 +1,103 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_detail`() +BEGIN +/** + * Devuelve los detalles de los vuelos que tienen + * un almacén de salida en Ecuador o Colombia. + */ + DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK; + SELECT IFNULL(CONCAT(" ", entryFk), travelFk) travelAndEntry, + sub.* + FROM ( + SELECT tr.id travelFk, + NULL entryFk, + TRUE isTravel, + am.name agency, + tr.ref, + tr.shipped, + wOut.name originBoxes, + tr.landed, + wIn.name destination, + SUM(b.stickers) stickers, + NULL evaNotes, + tr.kg, + CAST(SUM(b.weight * b.stickers) AS INT) loadedkg, + CAST( + SUM(vc.aerealVolumetricDensity * + b.stickers * + IF(p.volume, + p.volume, + p.width * p.depth * p.height + ) / 1000000 + ) AS INT + ) volumeKg, + NULL loadPriority, + NULL invoiceAmount, + s.nickname freighter, + NULL reference + FROM travel tr + LEFT JOIN supplier s ON s.id = tr.cargoSupplierFk + LEFT JOIN entry e ON e.travelFk = tr.id + LEFT JOIN buy b ON b.entryFk = e.id + LEFT JOIN packaging p ON p.id = b.packagingFk + LEFT JOIN item i ON i.id = b.itemFk + LEFT JOIN itemType it ON it.id = i.typeFk + JOIN warehouse wIn ON wIn.id = tr.warehouseInFk + JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk + JOIN agencyMode am ON am.id = tr.agencyModeFk + JOIN volumeConfig vc + WHERE tr.landed >= vDateFrom + AND (wOut.code = "col" OR wOut.code = "ecu") + GROUP BY tr.id + UNION ALL + SELECT e.travelFk, + e.id, + FALSE, + s.name, + e.invoiceNumber, + tr.shipped, + wOut.name, + tr.landed, + wIn.name, + SUM(b.stickers), + e.evaNotes, + NULL, + CAST(SUM(b.weight * b.stickers) AS INT), + CAST( + SUM(vc.aerealVolumetricDensity * + b.stickers * + IF(p.volume, + p.volume, + p.width * p.depth * p.height + ) / 1000000 + ) AS INT + ), + loadPriority, + e.invoiceAmount, + s2.nickname, + e.reference + FROM entry e + JOIN buy b ON b.entryFk = e.id + JOIN packaging p ON p.id = b.packagingFk + JOIN item i ON i.id = b.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN supplier s ON s.id = e.supplierFk + JOIN travel tr ON tr.id = e.travelFk + LEFT JOIN supplier s2 ON s2.id = tr.cargoSupplierFk + JOIN warehouse wIn ON wIn.id = tr.warehouseInFk + JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk + JOIN volumeConfig vc + WHERE tr.landed >= vDateFrom + AND (wOut.code = "col" OR wOut.code = "ecu") + GROUP BY e.id + ) sub + ORDER BY landed ASC, + shipped ASC, + travelFk, + isTravel DESC, + (loadPriority > 0) DESC, + loadPriority, + agency, + evaNotes; +END$$ +DELIMITER ; \ No newline at end of file diff --git a/db/routines/vn2008/procedures/XDiario_Quadrator.sql b/db/routines/vn2008/procedures/XDiario_Quadrator.sql deleted file mode 100644 index 93ddc231d..000000000 --- a/db/routines/vn2008/procedures/XDiario_Quadrator.sql +++ /dev/null @@ -1,34 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`XDiario_Quadrator`() -BEGIN - INSERT INTO vn.mail (receiver, subject, body) - SELECT 'cau@verdnatura.es', - 'asientos descuadrados', - group_concat(CONCAT(' Asiento: ', ASIEN, '- importe:', quadre) SEPARATOR ' \r\n ') - FROM ( - SELECT ASIEN, SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) quadre - FROM vn.XDiario - WHERE enlazado = FALSE - GROUP BY ASIEN - HAVING ABS(SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0))) > 0.01 - ) t - HAVING count(*) > 0; - - UPDATE vn.XDiario XD - INNER JOIN( - SELECT XD.id, SUBCTA, Quadre FROM vn.XDiario XD - INNER JOIN ( - SELECT ASIEN, SUM(IFNULL(ROUND(Eurodebe,2),0))- SUM(IFNULL(ROUND(EUROHABER,2),0)) as Quadre - FROM vn.XDiario - WHERE enlazado = FALSE - GROUP BY ASIEN - HAVING Quadre != 0 - ) sub USING(ASIEN) - WHERE SUBCTA > '5999999999' - GROUP BY ASIEN - ) sub2 USING(id) - SET Eurohaber = IF(IFNULL(Eurohaber,0) = 0, Eurohaber, Eurohaber + Quadre), - Eurodebe = IF(IFNULL(Eurodebe,0) = 0, Eurodebe, Eurodebe - Quadre); - -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/supplierStatement.sql b/db/routines/vn2008/procedures/supplierStatement.sql deleted file mode 100644 index 4701e3e21..000000000 --- a/db/routines/vn2008/procedures/supplierStatement.sql +++ /dev/null @@ -1,117 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`supplierStatement`(vSupplierFk INT, vCurrencyFk INT, vCompanyFk INT, vOrderBy VARCHAR(15), vOnlyConciliated BIT) -BEGIN - SET @saldo_eur:= 0; - SET @saldo_div:= 0; -select vOnlyConciliated; - DROP TEMPORARY TABLE IF EXISTS tmp.supplierStatement; - - CREATE TEMPORARY TABLE tmp.supplierStatement ENGINE = MEMORY - SELECT - *, - @saldo_eur:= round(@saldo_eur + IFNULL(Pago_Euros, 0) - IFNULL(Fac_Euros, 0) ,2 ) AS saldo_eur, - @saldo_div:= round(@saldo_div + IFNULL(Pago_Divisas, 0) - IFNULL(Fac_Divisas, 0) ,2 ) AS saldo_div - FROM - (SELECT * FROM - (SELECT - NULL as banco_id, - r.empresa_id, - r.serie, - r.id, - CASE - WHEN vOrderBy = 'issued' THEN r.fecha - WHEN vOrderBy = 'bookEntried' THEN r.bookEntried - WHEN vOrderBy = 'booked' THEN r.dateBooking - WHEN vOrderBy = 'dueDate' THEN rv.fecha - END AS fecha, - CONCAT('S/Fra ', r.sref) sref, - if(r.moneda_id > 1,round(sum(divisa) / sum(cantidad),3),NULL) val_cambio, - CAST(sum(cantidad) as DECIMAL(10,2)) as Fac_Euros, - CAST(sum(divisa) as DECIMAL(10,2)) as Fac_Divisas, - NULL AS Pago_Euros, - NULL AS Pago_Divisas, - r.moneda_id, - r.contabilizada, - Moneda, - NULL as pago_sdc_id, - 'invoiceIn' statementType - FROM - recibida r - JOIN recibida_vencimiento rv on rv.recibida_id = r.id - JOIN Monedas m on m.Id_Moneda = r.moneda_id - WHERE - r.fecha > '2014-12-31' - AND r.proveedor_id = vSupplierFk - AND vCurrencyFk IN (r.moneda_id, 0) - AND vCompanyFk IN (r.empresa_id,0) - AND (vOnlyConciliated = r.contabilizada OR NOT vOnlyConciliated) - GROUP BY rv.id - - UNION ALL - SELECT - p.id_banco, - p.empresa_id, - NULL, - p.id, - CASE - WHEN vOrderBy = 'issued' THEN p.Fecha - WHEN vOrderBy = 'bookEntried' THEN p.Fecha - WHEN vOrderBy = 'booked' THEN p.Fecha - WHEN vOrderBy = 'dueDate' THEN p.dueDated - END AS fecha, - CONCAT(IFNULL(name, ''), IF(pre.concepto <> '', CONCAT(' : ', pre.concepto), '')), - if(p.id_moneda > 1, p.divisa / importe, NULL) tip_cambio, - NULL, - NULL, - p.importe, - p.divisa, - p.id_moneda, - p.conciliado, - Moneda, - NULL as pago_sdc_id, - 'payment' statementType - FROM - pago p - LEFT JOIN Monedas ON Monedas.Id_Moneda = p.id_moneda - LEFT JOIN Bancos ON p.id_banco = Bancos.Id_banco - LEFT JOIN pay_met pm ON p.pay_met_id = pm.id - LEFT JOIN Pagares pre ON pre.pago_id = p.id - WHERE - Fecha > '2014-12-31' - AND p.Id_Proveedor = vSupplierFk - AND vCurrencyFk IN (p.id_moneda,0) - AND vCompanyFk IN (p.empresa_id,0) - AND (vOnlyConciliated = p.conciliado OR NOT vOnlyConciliated) - UNION ALL - SELECT - NULL, - companyFk, - NULL, - se.id, - CASE - WHEN vOrderBy = 'issued' THEN se.dated - WHEN vOrderBy = 'bookEntried' THEN se.dated - WHEN vOrderBy = 'booked' THEN se.dated - WHEN vOrderBy = 'dueDate' THEN se.dueDated - END AS fecha, - se.description, - 1 tip_cambio, - amount, - NULL, - NULL, - NULL, - currencyFk, - isConciliated, - c.`code`, - NULL, - 'expense' statementType - FROM vn.supplierExpense se - JOIN vn.currency c on c.id= se.currencyFk - WHERE se.supplierFk = vSupplierFk - AND vCurrencyFk IN (se.currencyFk,0) - AND vCompanyFk IN (se.companyFk,0) - AND (vOnlyConciliated = se.isConciliated OR NOT vOnlyConciliated) - ) AS SUB - ORDER BY (fecha is null and NOT contabilizada),fecha, IF(vOrderBy = 'dueDate', id, NULL) LIMIT 10000000000000000000) t; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/traslado.sql b/db/routines/vn2008/procedures/traslado.sql deleted file mode 100644 index 9c1e5efe7..000000000 --- a/db/routines/vn2008/procedures/traslado.sql +++ /dev/null @@ -1,182 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`traslado`(IN i_entrada INTEGER) -BEGIN - DECLARE dateShipment DATE; - DECLARE dateLanding DATE; - DECLARE warehouseShipment INTEGER; - DECLARE warehouseLanding INTEGER; - DECLARE v_calc_visible INTEGER; - DECLARE vInventoryDate DATE; - - SET vInventoryDate := vn.getInventoryDate(); - SELECT shipment, landing, warehouse_id_out, warehouse_id - INTO dateShipment, dateLanding, warehouseShipment, warehouseLanding - FROM travel t JOIN Entradas e ON t.id = e.travel_id - WHERE Id_Entrada = i_entrada; - - CALL vn.rate_getPrices(dateShipment, warehouseLanding); - - -- Traslado en almacen origen - - DROP TEMPORARY TABLE IF EXISTS buy_edi_temp; - CREATE TEMPORARY TABLE buy_edi_temp - (KEY (Id_Article), INDEX(Id_Compra)) ENGINE = MEMORY - SELECT * - FROM (SELECT c.Id_Article, c.Id_Compra - FROM Compres c INNER JOIN Entradas e USING(Id_Entrada) - INNER JOIN travel t ON t.id = e.travel_id - WHERE t.landing BETWEEN vInventoryDate AND dateShipment - AND c.Novincular = FALSE - AND c.Tarifa2 >= 0 - ORDER BY (warehouseShipment = t.warehouse_id) DESC, t.landing DESC - LIMIT 10000000000000000000) t - GROUP BY Id_Article; - - IF dateShipment >= util.VN_CURDATE() THEN - CALL `cache`.visible_refresh(v_calc_visible, TRUE, warehouseShipment); - - DROP TEMPORARY TABLE IF EXISTS tmp.item; - - CREATE TEMPORARY TABLE tmp.item ( - `itemFk` int(10) unsigned NOT NULL, - `visible` int(11) NOT NULL DEFAULT 0, - `available` int(11) NOT NULL DEFAULT 0, - `visibleLanding` int(11) NOT NULL DEFAULT 0, - `availableLanding` int(11) NOT NULL DEFAULT 0, - UNIQUE INDEX i USING HASH (itemFk) - ) ENGINE = MEMORY; - - INSERT INTO tmp.item(itemFk, visible) - SELECT item_id itemFk, visible - FROM `cache`.visible - WHERE calc_id = v_calc_visible - AND visible; - - CALL `cache`.visible_refresh(v_calc_visible, TRUE, warehouseLanding); - - INSERT INTO tmp.item(itemFk, visibleLanding) - SELECT item_id, `visible` - FROM `cache`.`visible` v - WHERE v.calc_id = v_calc_visible - AND v.`visible` - ON DUPLICATE KEY UPDATE visibleLanding = v.`visible`; - - CALL availableTraslate(warehouseShipment, dateShipment, NULL); - - INSERT INTO tmp.item(itemFk, available) - SELECT a.item_id, a.available - FROM availableTraslate a - WHERE a.available - ON DUPLICATE KEY UPDATE available = a.available; - - CALL availableTraslate(warehouseLanding, dateLanding, warehouseShipment); - - INSERT INTO tmp.item(itemFk, availableLanding) - SELECT a.item_id, a.available - FROM availableTraslate a - WHERE a.available - ON DUPLICATE KEY UPDATE availableLanding = a.available; - ELSE - CALL vn.item_getStock(warehouseShipment, dateShipment, NULL); - - DROP TEMPORARY TABLE IF EXISTS tmp.item; - CREATE TEMPORARY TABLE tmp.item (UNIQUE INDEX i USING HASH (itemFk)) ENGINE = MEMORY - SELECT itemFk, `visible`, available , 0 visibleLanding, 0 availableLanding - FROM tmp.itemList; - - DROP TEMPORARY TABLE tmp.itemList; - END IF; - - CALL vn.buyUltimateFromInterval(warehouseLanding,vInventoryDate, dateLanding); - - DROP TEMPORARY TABLE IF EXISTS Traslados; - CREATE TEMPORARY TABLE Traslados ENGINE = MEMORY - SELECT tp.Id_Tipo AS Tipo, - tp.reino_id, - ar.tipo_id, - ar.Id_Article AS article_id, - ar.Article, - ar.Medida, - ar.Categoria, - ar.Color, - Origen.abreviatura as Origen, - CE.Cantidad, - ar.Tallos, - CAST(AIM.visible AS DECIMAL(10,0)) as vis1, - CAST(AIM.available AS DECIMAL(10,0)) as dis1, - CAST(AIM.visibleLanding AS DECIMAL(10,0)) as vis2, - CAST(AIM.availableLanding AS DECIMAL(10,0)) as dis2, - COALESCE(CE.`grouping`, C.`grouping`) as `grouping`, - COALESCE(CE.Packing, C.Packing) as Packing, - COALESCE(cl.caja, CE.caja, C.caja) as caja, - IFNULL(p.name, P2.Alias) AS Productor, - C.Id_Cubo, - 1 Tinta, - CE.Id_Compra, - CE.Etiquetas, - C.buy_edi_id, - tp.Id_Trabajador, - CB.Volumen, - IFNULL(CB.x,0) x, - IFNULL(CB.y,0) y, - IFNULL(CB.z,0) z, - IFNULL(C.Costefijo,0) Costefijo, - IFNULL(C.Comisionfija,0) Comisionfija, - IFNULL(C.Portefijo,0) Portefijo, - A.m3, - E.comision, - CB.Retornable, - IFNULL(CEB.Valor,CB.Valor) Valor, - r.rate3 t3, r.rate2 t2, tp.promo, - C.`grouping` groupingOrigin, - C.Packing PackingOrigin, - C.Id_Compra CompraOrigin, - CB.costeRetorno, - C.weight - FROM Articles ar - JOIN tmp.item AIM ON AIM.itemFk = ar.Id_Article - LEFT JOIN producer p ON p.producer_id = ar.producer_id - LEFT JOIN Tipos tp ON tp.tipo_id = ar.tipo_id - JOIN vn.itemCategory ic ON ic.id = tp.reino_id - LEFT JOIN Origen ON Origen.id = ar.id_origen - LEFT JOIN buy_edi_temp lb ON lb.Id_Article = ar.Id_Article - LEFT JOIN Compres C ON C.Id_Compra = lb.Id_Compra - LEFT JOIN Cubos CB ON CB.Id_Cubo = C.Id_Cubo - LEFT JOIN Entradas E2 ON E2.Id_Entrada = C.Id_Entrada - LEFT JOIN Proveedores P2 ON P2.Id_Proveedor = E2.Id_Proveedor - LEFT JOIN Entradas E ON E.Id_Entrada = i_entrada - LEFT JOIN travel TR ON TR.id = E.travel_id - LEFT JOIN Agencias A ON A.Id_Agencia = TR.agency_id - LEFT JOIN Compres CE ON CE.Id_Article = ar.Id_Article AND CE.Id_Entrada = i_entrada - LEFT JOIN Cubos CEB ON CEB.Id_Cubo = CE.Id_Cubo - LEFT JOIN tmp.rate r ON TRUE - LEFT JOIN tmp.buyUltimateFromInterval bufi ON bufi.itemFk = ar.Id_Article - LEFT JOIN Compres cl ON cl.Id_Compra = bufi.buyFk - WHERE ic.display - AND E.Redada = FALSE - AND (AIM.visible != 0 OR AIM.available != 0) - ORDER BY tipo_id, Article, article_id, Medida, Categoria, Origen; - - CREATE INDEX tindex USING HASH ON Traslados (article_id); - - SELECT t.*, - Cantidad - MOD(Cantidad , `grouping`) as Subcantidad, - MOD(Cantidad , `grouping`) as Soll, - ROUND((IF(Volumen > 0,Volumen,x * y * IF(z = 0, Medida + 10, z))) / Packing,0) as cm3, - Costefijo + Comisionfija + Portefijo AS Cost, - @porte := ROUND((IF(Volumen > 0,Volumen,x * y * IF(z = 0, Medida + 10, z))) * m3 / 1000000 / Packing ,3) AS Porte, - @comision := ROUND((Costefijo + Comisionfija + Portefijo) * comision / 100 ,3) AS Comision, - ROUND(@embalaje := (costeRetorno + IF(Retornable != 0, 0, Valor)) / packing ,3) AS Embalaje, - @coste := IFNULL((Costefijo + Comisionfija + Portefijo),0) + IFNULL(@embalaje,0) + IFNULL(@porte,0) + IFNULL(@comision,0) AS Coste, - @t3 := ROUND(@coste / ( (100 - t3 - t.promo)/100),2) AS Tarifa3, - ROUND(@t3 * (1 + ((t2 - t3)/100)),2) AS Tarifa2, - 0 selected - FROM Traslados t; - - DROP TEMPORARY TABLE Traslados; - DROP TEMPORARY TABLE tmp.item; - DROP TEMPORARY TABLE buy_edi_temp; - DROP TEMPORARY TABLE tmp.buyUltimateFromInterval; - DROP TEMPORARY TABLE tmp.rate; -END$$ -DELIMITER ; diff --git a/db/routines/vn2008/procedures/travelDetail.sql b/db/routines/vn2008/procedures/travelDetail.sql deleted file mode 100644 index 39ed4f7b8..000000000 --- a/db/routines/vn2008/procedures/travelDetail.sql +++ /dev/null @@ -1,119 +0,0 @@ -DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn2008`.`travelDetail`() -BEGIN -/** - * Returns the details of the travels that have a departure warehouse in Ecuador or Colombia. - */ - DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK; - SELECT IFNULL(CONCAT(" ",Entrada),travel) travelAndEntry, - travel, - Entrada, - IsTravel, - Agencia, - ref, - shipment, - OrigenCajas, - landing, - Destino, - Etiquetas, - Notas_Eva, - kg, - loadedKg, - volumeKg, - loadPriority, - invoiceAmount, - Carguera, - reference - FROM - (SELECT TRUE IsTravel, - tr.id travel, - NULL Entrada, - ag.Agencia, - tr.ref, - tr.shipment, - wo.name OrigenCajas, - tr.landing, - w.name Destino, - SUM(c.Etiquetas) Etiquetas, - NULL Notas_Eva, - tr.kg, - CAST(SUM(c.weight * c.Etiquetas) AS INT) loadedkg, - CAST( - SUM(vc.aerealVolumetricDensity * - c.Etiquetas * - IF(cb.Volumen, - cb.Volumen, - cb.X * cb.Y * cb.Z - ) / 1000000 - ) AS INT - ) volumeKg, - NULL loadPriority, - NULL invoiceAmount, - pc.Alias Carguera, - NULL reference - FROM travel tr - LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk - LEFT JOIN Entradas e ON e.travel_id = tr.id - LEFT JOIN Compres c ON c.Id_Entrada = e.Id_Entrada - LEFT JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo - LEFT JOIN Articles a ON a.Id_Article = c.Id_Article - LEFT JOIN Tipos tp ON tp.tipo_id = a.tipo_id - JOIN warehouse w ON w.id = tr.warehouse_id - JOIN warehouse wo ON wo.id = tr.warehouse_id_out - JOIN Agencias ag ON ag.Id_Agencia = tr.agency_id - JOIN vn.volumeConfig vc - WHERE tr.landing >= vDateFrom - AND (wo.name="Colombia" OR wo.name="Ecuador") - GROUP BY tr.id - UNION ALL - SELECT 0 IsTravel, - e.travel_id travel, - e.Id_Entrada, - p.Proveedor, - e.Referencia, - tr.shipment, - wo.name OrigenCajas, - tr.landing, - w.name Destino, - SUM(Etiquetas) Etiquetas, - e.Notas_Eva, - NULL kg, - CAST(SUM(c.weight * c.Etiquetas) AS INT) loadedkg, - CAST( - SUM(vc.aerealVolumetricDensity * - c.Etiquetas * - IF(cb.Volumen, - cb.Volumen, - cb.X * cb.Y * cb.Z - ) / 1000000 - ) AS INT - ) volumeKg, - loadPriority, - e.invoiceAmount, - pc.Alias carguera, - e.reference - FROM Entradas e - JOIN Compres c ON c.Id_Entrada = e.Id_Entrada - JOIN Cubos cb ON cb.Id_Cubo = c.Id_Cubo - JOIN Articles a ON a.Id_Article = c.Id_Article - JOIN Tipos tp ON tp.tipo_id = a.tipo_id - JOIN Proveedores p ON p.Id_Proveedor = e.Id_Proveedor - JOIN travel tr ON tr.id = e.travel_id - LEFT JOIN Proveedores pc ON pc.Id_Proveedor = tr.cargoSupplierFk - JOIN warehouse w ON w.id = tr.warehouse_id - JOIN warehouse wo ON wo.id = tr.warehouse_id_out - JOIN vn.volumeConfig vc - WHERE tr.landing >= vDateFrom - AND (wo.name="Colombia" OR wo.name="Ecuador") - GROUP BY e.Id_Entrada - ) sub - ORDER BY landing ASC, - shipment ASC, - travel, - IsTravel DESC, - (loadPriority > 0) DESC, - loadPriority, - Agencia, - Notas_Eva; -END$$ -DELIMITER ; diff --git a/db/versions/10878-blueSalal/00-firstScript.sql b/db/versions/10878-blueSalal/00-firstScript.sql new file mode 100644 index 000000000..49511166b --- /dev/null +++ b/db/versions/10878-blueSalal/00-firstScript.sql @@ -0,0 +1,4 @@ +GRANT EXECUTE ON PROCEDURE vn.supplier_statement TO administrative, buyer, hrBoss; +GRANT EXECUTE ON PROCEDURE vn.XDiario_reconciliation TO adminBoss; +GRANT EXECUTE ON PROCEDURE vn.travel_detail TO buyer; +GRANT EXECUTE ON PROCEDURE vn.entry_transfer TO claimManager, buyer; From 22e6f547faad8a0a2e2918d42c659902100c7c18 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 9 Feb 2024 11:41:23 +0100 Subject: [PATCH 04/20] refactor: refs #6501 Migrated procs from vn2008 to vn --- db/versions/10878-blueSalal/00-firstScript.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/versions/10878-blueSalal/00-firstScript.sql b/db/versions/10878-blueSalal/00-firstScript.sql index 49511166b..1c1894c0e 100644 --- a/db/versions/10878-blueSalal/00-firstScript.sql +++ b/db/versions/10878-blueSalal/00-firstScript.sql @@ -1,4 +1,4 @@ GRANT EXECUTE ON PROCEDURE vn.supplier_statement TO administrative, buyer, hrBoss; GRANT EXECUTE ON PROCEDURE vn.XDiario_reconciliation TO adminBoss; GRANT EXECUTE ON PROCEDURE vn.travel_detail TO buyer; -GRANT EXECUTE ON PROCEDURE vn.entry_transfer TO claimManager, buyer; +GRANT EXECUTE ON PROCEDURE vn.entry_getTransfer TO claimManager, buyer; From dbe63ad11b675ed22794fd32a0f1e298de5a7209 Mon Sep 17 00:00:00 2001 From: guillermo Date: Fri, 9 Feb 2024 11:45:31 +0100 Subject: [PATCH 05/20] refactor: refs #6501 Fix grant errors --- .../10878-blueSalal/00-firstScript.sql | 495 +++++++++++++++++- 1 file changed, 494 insertions(+), 1 deletion(-) diff --git a/db/versions/10878-blueSalal/00-firstScript.sql b/db/versions/10878-blueSalal/00-firstScript.sql index 1c1894c0e..7ef168c6b 100644 --- a/db/versions/10878-blueSalal/00-firstScript.sql +++ b/db/versions/10878-blueSalal/00-firstScript.sql @@ -1,4 +1,497 @@ +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplier_statement`( + vSupplierFk INT, + vCurrencyFk INT, + vCompanyFk INT, + vOrderBy VARCHAR(15), + vIsConciliated BOOL +) +BEGIN +/** + * Crea un estado de cuenta de proveedores calculando + * los saldos en euros y en la moneda especificada. + * + * @param vSupplierFk Id del proveedor + * @param vCurrencyFk Id de la moneda + * @param vCompanyFk Id de la empresa + * @param vOrderBy Criterio de ordenación + * @param vIsConciliated Indica si está conciliado o no + * @return tmp.supplierStatement + */ + SET @euroBalance:= 0; + SET @currencyBalance:= 0; + + CREATE OR REPLACE TEMPORARY TABLE tmp.supplierStatement + ENGINE = MEMORY + SELECT *, + @euroBalance:= ROUND( + @euroBalance + IFNULL(paymentEuros, 0) - + IFNULL(invoiceEuros, 0), 2 + ) euroBalance, + @currencyBalance:= ROUND( + @currencyBalance + IFNULL(paymentCurrency, 0) - + IFNULL(invoiceCurrency, 0), 2 + ) currencyBalance + FROM ( + SELECT * FROM + ( + SELECT NULL bankFk, + ii.companyFk, + ii.serial, + ii.id, + CASE + WHEN vOrderBy = 'issued' THEN ii.issued + WHEN vOrderBy = 'bookEntried' THEN ii.bookEntried + WHEN vOrderBy = 'booked' THEN ii.booked + WHEN vOrderBy = 'dueDate' THEN iid.dueDated + END dated, + CONCAT('S/Fra ', ii.supplierRef) sref, + IF(ii.currencyFk > 1, + ROUND(SUM(iid.foreignValue) / SUM(iid.amount), 3), + NULL + ) changeValue, + CAST(SUM(iid.amount) AS DECIMAL(10,2)) invoiceEuros, + CAST(SUM(iid.foreignValue) AS DECIMAL(10,2)) invoiceCurrency, + NULL paymentEuros, + NULL paymentCurrency, + ii.currencyFk, + ii.isBooked, + c.code, + 'invoiceIn' statementType + FROM invoiceIn ii + JOIN invoiceInDueDay iid ON iid.invoiceInFk = ii.id + JOIN currency c ON c.id = ii.currencyFk + WHERE ii.issued > '2014-12-31' + AND ii.supplierFk = vSupplierFk + AND vCurrencyFk IN (ii.currencyFk, 0) + AND vCompanyFk IN (ii.companyFk, 0) + AND (vIsConciliated = ii.isBooked OR NOT vIsConciliated) + GROUP BY iid.id + UNION ALL + SELECT p.bankFk, + p.companyFk, + NULL, + p.id, + CASE + WHEN vOrderBy = 'issued' THEN p.received + WHEN vOrderBy = 'bookEntried' THEN p.received + WHEN vOrderBy = 'booked' THEN p.received + WHEN vOrderBy = 'dueDate' THEN p.dueDated + END, + CONCAT(IFNULL(pm.name, ''), + IF(pn.concept <> '', + CONCAT(' : ', pn.concept), + '') + ), + IF(p.currencyFk > 1, p.divisa / p.amount, NULL), + NULL, + NULL, + p.amount, + p.divisa, + p.currencyFk, + p.isConciliated, + c.code, + 'payment' + FROM payment p + LEFT JOIN currency c ON c.id = p.currencyFk + LEFT JOIN bank b ON b.id = p.bankFk + LEFT JOIN payMethod pm ON pm.id = p.payMethodFk + LEFT JOIN promissoryNote pn ON pn.paymentFk = p.id + WHERE p.received > '2014-12-31' + AND p.supplierFk = vSupplierFk + AND vCurrencyFk IN (p.currencyFk, 0) + AND vCompanyFk IN (p.companyFk, 0) + AND (vIsConciliated = p.isConciliated OR NOT vIsConciliated) + UNION ALL + SELECT NULL, + companyFk, + NULL, + se.id, + CASE + WHEN vOrderBy = 'issued' THEN se.dated + WHEN vOrderBy = 'bookEntried' THEN se.dated + WHEN vOrderBy = 'booked' THEN se.dated + WHEN vOrderBy = 'dueDate' THEN se.dueDated + END, + se.description, + 1, + amount, + NULL, + NULL, + NULL, + currencyFk, + isConciliated, + c.`code`, + 'expense' + FROM supplierExpense se + JOIN currency c ON c.id = se.currencyFk + WHERE se.supplierFk = vSupplierFk + AND vCurrencyFk IN (se.currencyFk,0) + AND vCompanyFk IN (se.companyFk,0) + AND (vIsConciliated = se.isConciliated OR NOT vIsConciliated) + ) sub + ORDER BY (dated IS NULL AND NOT isBooked), + dated, + IF(vOrderBy = 'dueDate', id, NULL) + LIMIT 10000000000000000000 + ) t; +END$$ +DELIMITER ; + GRANT EXECUTE ON PROCEDURE vn.supplier_statement TO administrative, buyer, hrBoss; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_reconciliation`() +BEGIN +/** + * Realiza la conciliación diaria de los asientos contables, + * identificando y notificando los asientos descuadrados + * y ajustando los saldos en caso necesario. + */ + INSERT INTO mail (receiver, subject, body) + SELECT 'cau@verdnatura.es', + 'Asientos descuadrados', + GROUP_CONCAT(CONCAT(' Asiento: ', ASIEN, ' - Importe:', recon) SEPARATOR ' | \n') + FROM ( + SELECT ASIEN, + SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon + FROM XDiario + WHERE NOT enlazado + GROUP BY ASIEN + HAVING ABS(SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0))) > 0.01 + ) sub + HAVING COUNT(*); + + UPDATE XDiario xd + JOIN ( + SELECT xd.id, SUBCTA, recon + FROM XDiario xd + JOIN ( + SELECT ASIEN, + SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon + FROM XDiario + WHERE NOT enlazado + GROUP BY ASIEN + HAVING recon + ) sub ON sub.ASIEN = xd.ASIEN + WHERE xd.SUBCTA > '5999999999' + GROUP BY xd.ASIEN + ) sub ON sub.id = xd.id + SET xd.Eurohaber = IF(IFNULL(xd.Eurohaber, 0) = 0, xd.Eurohaber, xd.Eurohaber + sub.recon), + xd.Eurodebe = IF(IFNULL(xd.Eurodebe, 0) = 0, xd.Eurodebe, xd.Eurodebe - sub.recon); +END$$ +DELIMITER ; + GRANT EXECUTE ON PROCEDURE vn.XDiario_reconciliation TO adminBoss; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_detail`() +BEGIN +/** + * Devuelve los detalles de los vuelos que tienen + * un almacén de salida en Ecuador o Colombia. + */ + DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK; + SELECT IFNULL(CONCAT(" ", entryFk), travelFk) travelAndEntry, + sub.* + FROM ( + SELECT tr.id travelFk, + NULL entryFk, + TRUE isTravel, + am.name agency, + tr.ref, + tr.shipped, + wOut.name originBoxes, + tr.landed, + wIn.name destination, + SUM(b.stickers) stickers, + NULL evaNotes, + tr.kg, + CAST(SUM(b.weight * b.stickers) AS INT) loadedkg, + CAST( + SUM(vc.aerealVolumetricDensity * + b.stickers * + IF(p.volume, + p.volume, + p.width * p.depth * p.height + ) / 1000000 + ) AS INT + ) volumeKg, + NULL loadPriority, + NULL invoiceAmount, + s.nickname freighter, + NULL reference + FROM travel tr + LEFT JOIN supplier s ON s.id = tr.cargoSupplierFk + LEFT JOIN entry e ON e.travelFk = tr.id + LEFT JOIN buy b ON b.entryFk = e.id + LEFT JOIN packaging p ON p.id = b.packagingFk + LEFT JOIN item i ON i.id = b.itemFk + LEFT JOIN itemType it ON it.id = i.typeFk + JOIN warehouse wIn ON wIn.id = tr.warehouseInFk + JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk + JOIN agencyMode am ON am.id = tr.agencyModeFk + JOIN volumeConfig vc + WHERE tr.landed >= vDateFrom + AND (wOut.code = "col" OR wOut.code = "ecu") + GROUP BY tr.id + UNION ALL + SELECT e.travelFk, + e.id, + FALSE, + s.name, + e.invoiceNumber, + tr.shipped, + wOut.name, + tr.landed, + wIn.name, + SUM(b.stickers), + e.evaNotes, + NULL, + CAST(SUM(b.weight * b.stickers) AS INT), + CAST( + SUM(vc.aerealVolumetricDensity * + b.stickers * + IF(p.volume, + p.volume, + p.width * p.depth * p.height + ) / 1000000 + ) AS INT + ), + loadPriority, + e.invoiceAmount, + s2.nickname, + e.reference + FROM entry e + JOIN buy b ON b.entryFk = e.id + JOIN packaging p ON p.id = b.packagingFk + JOIN item i ON i.id = b.itemFk + JOIN itemType it ON it.id = i.typeFk + JOIN supplier s ON s.id = e.supplierFk + JOIN travel tr ON tr.id = e.travelFk + LEFT JOIN supplier s2 ON s2.id = tr.cargoSupplierFk + JOIN warehouse wIn ON wIn.id = tr.warehouseInFk + JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk + JOIN volumeConfig vc + WHERE tr.landed >= vDateFrom + AND (wOut.code = "col" OR wOut.code = "ecu") + GROUP BY e.id + ) sub + ORDER BY landed ASC, + shipped ASC, + travelFk, + isTravel DESC, + (loadPriority > 0) DESC, + loadPriority, + agency, + evaNotes; +END$$ +DELIMITER ; + GRANT EXECUTE ON PROCEDURE vn.travel_detail TO buyer; -GRANT EXECUTE ON PROCEDURE vn.entry_getTransfer TO claimManager, buyer; + +DELIMITER $$ +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_getTransfer`( + vSelf INT +) +BEGIN +/** + * Gestiona el traslado de productos a partir de una entrada específica. + * + * @param vSelf Id de entrada + */ + DECLARE vDateShipped DATE; + DECLARE vDateLanded DATE; + DECLARE vWarehouseIn INT; + DECLARE vWarehouseOut INT; + DECLARE vCalcVisible INT; + DECLARE vInventoryDate DATE DEFAULT vn.getInventoryDate(); + + SELECT shipped, landed, warehouseInFk, warehouseOutFk + INTO vDateShipped, vDateLanded, vWarehouseIn, vWarehouseOut + FROM vn.travel t + JOIN vn.entry e ON e.travelFk = t.id + WHERE e.id = vSelf; + + CALL vn.rate_getPrices(vDateShipped, vWarehouseIn); + + -- Traslado en almacen origen + CREATE OR REPLACE TEMPORARY TABLE tBuy + (PRIMARY KEY (itemFk), INDEX(buyFk)) + ENGINE = MEMORY + SELECT * + FROM ( + SELECT b.itemFk, b.id buyFk + FROM buy b + JOIN entry e ON e.id = b.entryFk + JOIN travel t ON t.id = e.travelFk + WHERE t.landed BETWEEN vInventoryDate AND vDateShipped + AND NOT b.isIgnored + AND b.price2 >= 0 + ORDER BY (vWarehouseOut = t.warehouseInFk) DESC, t.landed DESC + LIMIT 10000000000000000000 + ) sub + GROUP BY itemFk; + + IF vDateShipped >= util.VN_CURDATE() THEN + CALL `cache`.visible_refresh(vCalcVisible, TRUE, vWarehouseOut); + + CREATE OR REPLACE TEMPORARY TABLE tItem ( + `itemFk` int(10) unsigned NOT NULL, + `visible` int(11) NOT NULL DEFAULT 0, + `available` int(11) NOT NULL DEFAULT 0, + `visibleLanding` int(11) NOT NULL DEFAULT 0, + `availableLanding` int(11) NOT NULL DEFAULT 0, + UNIQUE INDEX i USING HASH (itemFk) + ) ENGINE = MEMORY; + + INSERT INTO tItem(itemFk, visible) + SELECT item_id itemFk, visible + FROM `cache`.visible + WHERE calc_id = vCalcVisible + AND visible; + + CALL `cache`.visible_refresh(vCalcVisible, TRUE, vWarehouseIn); + + INSERT INTO tItem(itemFk, visibleLanding) + SELECT item_id, `visible` + FROM `cache`.`visible` v + WHERE v.calc_id = vCalcVisible + AND v.`visible` + ON DUPLICATE KEY UPDATE visibleLanding = v.`visible`; + + CALL vn2008.availableTraslate(vWarehouseOut, vDateShipped, NULL); + + INSERT INTO tItem(itemFk, available) + SELECT a.item_id, a.available + FROM vn2008.availableTraslate a + WHERE a.available + ON DUPLICATE KEY UPDATE available = a.available; + + CALL vn2008.availableTraslate(vWarehouseIn, vDateLanded, vWarehouseOut); + + INSERT INTO tItem(itemFk, availableLanding) + SELECT a.item_id, a.available + FROM vn2008.availableTraslate a + WHERE a.available + ON DUPLICATE KEY UPDATE availableLanding = a.available; + ELSE + CALL vn.item_getStock(vWarehouseOut, vDateShipped, NULL); + + CREATE OR REPLACE TEMPORARY TABLE tItem + (UNIQUE INDEX i USING HASH (itemFk)) + ENGINE = MEMORY + SELECT itemFk, + `visible`, + available, + 0 visibleLanding, + 0 availableLanding + FROM tmp.itemList; + END IF; + + CALL vn.buyUltimateFromInterval(vWarehouseIn,vInventoryDate, vDateLanded); + + CREATE OR REPLACE TEMPORARY TABLE tTransfer + ENGINE = MEMORY + SELECT it.categoryFk, + i.typeFk, + i.id itemFk, + i.name item, + i.`size`, + i.category, + i.inkFk, + o.code originCode, + b2.quantity, + i.stems, + CAST(ti.visible AS DECIMAL(10,0)) vis1, + CAST(ti.available AS DECIMAL(10,0)) ava1, + CAST(ti.visibleLanding AS DECIMAL(10,0)) vis2, + CAST(ti.availableLanding AS DECIMAL(10,0)) ava, + COALESCE(b2.`grouping`, b.`grouping`) `grouping`, + COALESCE(b2.packing, b.packing) packing, + COALESCE(b3.groupingMode, b2.groupingMode, b.groupingMode) package, + IFNULL(p.name, s.nickname) productor, + b.packagingFk, + b2.id buyFk, + b2.stickers, + b.ektFk, + it.workerFk, + pa.volume, + IFNULL(pa.width, 0) width, + IFNULL(pa.`depth`, 0) `depth`, + IFNULL(pa.height, 0) height, + IFNULL(b.buyingValue, 0) buyingValue, + IFNULL(b.comissionValue, 0) comissionValue, + IFNULL(b.freightValue, 0) freightValue, + am.m3, + e.commission, + pa.isPackageReturnable, + IFNULL(pa2.value, pa.value) `value`, + r.rate3, + r.rate2, + it.promo, + b.`grouping` groupingOrigin, + b.packing packingOrigin, + b.id buyFkOrigin, + pa.returnCost, + b.weight + FROM vn.item i + JOIN tItem ti ON ti.itemFk = i.id + LEFT JOIN vn.producer p ON p.id = i.producerFk + LEFT JOIN vn.itemType it ON it.id = i.typeFk + JOIN vn.itemCategory ic ON ic.id = it.categoryFk + LEFT JOIN vn.origin o ON o.id = i.originFk + LEFT JOIN tBuy lb ON lb.itemFk = i.id + LEFT JOIN vn.buy b ON b.id = lb.buyFk + LEFT JOIN vn.packaging pa ON pa.id = b.packagingFk + LEFT JOIN vn.entry e2 ON e2.id = b.entryFk + LEFT JOIN vn.supplier s ON s.id = e2.supplierFk + LEFT JOIN vn.entry e ON e.id = vSelf + LEFT JOIN vn.travel tr ON tr.id = e.travelFk + LEFT JOIN vn.agencyMode am ON am.id = tr.agencyModeFk + LEFT JOIN vn.buy b2 ON b2.itemFk = i.id + AND b2.entryFk = vSelf + LEFT JOIN vn.packaging pa2 ON pa2.id = b.packagingFk + LEFT JOIN tmp.rate r ON TRUE + LEFT JOIN tmp.buyUltimateFromInterval bufi ON bufi.itemFk = i.id + LEFT JOIN vn.buy b3 ON b3.id = bufi.buyFk + WHERE ic.display + AND NOT e.isRaid + AND (ti.visible != 0 OR ti.available != 0) + ORDER BY i.typeFk, i.name, i.id, i.size, i.category, o.name; + + CREATE INDEX tIndex USING HASH ON tTransfer (itemFk); + + SET @carriage := 0; + SET @comission := 0; + SET @packaging := 0; + SET @rate3 := 0; + SET @cost := 0; + SELECT *, + quantity - MOD(quantity , `grouping`) subQuantity, + MOD(quantity, `grouping`) soll, + ROUND((IF(volume > 0,volume, width * `depth` * IF(height = 0, `size` + 10, height))) / packing, 0) cm3, + buyingValue + comissionValue + freightValue Cost, + @carriage := ROUND((IF(volume > 0, volume, width * `depth` * IF(height = 0, `size` + 10, height))) * m3 / 1000000 / Packing, 3) carriage, + @comission := ROUND((buyingValue + comissionValue + freightValue) * commission / 100, 3) commission, + ROUND(@packaging := (returnCost + IF(isPackageReturnable != 0, 0, value)) / packing, 3) packaging, + @cost := IFNULL((buyingValue + comissionValue + freightValue), 0) + + IFNULL(@packaging, 0) + + IFNULL(@carriage, 0) + + IFNULL(@comission, 0) cost, + @rate3 := ROUND(@cost / ( (100 - rate3 - promo) / 100), 2) rate3, + ROUND(@rate3 * (1 + ((rate2 - rate3)/100)), 2) rate2, + FALSE selected + FROM tTransfer; + + DROP TEMPORARY TABLE IF EXISTS + tTransfer, + tItem, + tBuy, + tmp.buyUltimateFromInterval, + tmp.rate, + tmp.itemList; +END$$ +DELIMITER ; + +GRANT EXECUTE ON PROCEDURE vn.entry_getTransfer TO claimManager, buyer; \ No newline at end of file From 212bf5893277ef45012cc60034dbf9c5e05a5c82 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 12 Feb 2024 10:08:56 +0100 Subject: [PATCH 06/20] refactor: refs #6501 Minor change --- db/routines/vn/procedures/entry_getTransfer.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql index 2c9fe8577..414f62429 100644 --- a/db/routines/vn/procedures/entry_getTransfer.sql +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -179,14 +179,14 @@ BEGIN quantity - MOD(quantity , `grouping`) subQuantity, MOD(quantity, `grouping`) soll, ROUND((IF(volume > 0,volume, width * `depth` * IF(height = 0, `size` + 10, height))) / packing, 0) cm3, - buyingValue + comissionValue + freightValue Cost, + buyingValue + comissionValue + freightValue cost, @carriage := ROUND((IF(volume > 0, volume, width * `depth` * IF(height = 0, `size` + 10, height))) * m3 / 1000000 / Packing, 3) carriage, @comission := ROUND((buyingValue + comissionValue + freightValue) * commission / 100, 3) commission, ROUND(@packaging := (returnCost + IF(isPackageReturnable != 0, 0, value)) / packing, 3) packaging, @cost := IFNULL((buyingValue + comissionValue + freightValue), 0) + IFNULL(@packaging, 0) + IFNULL(@carriage, 0) + - IFNULL(@comission, 0) cost, + IFNULL(@comission, 0) expense, @rate3 := ROUND(@cost / ( (100 - rate3 - promo) / 100), 2) rate3, ROUND(@rate3 * (1 + ((rate2 - rate3)/100)), 2) rate2, FALSE selected From f89ae0aad9f9fe670abea57e9383ea20454a010e Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 12 Feb 2024 10:18:31 +0100 Subject: [PATCH 07/20] refactor: refs #6501 Minor change --- db/routines/vn/procedures/entry_getTransfer.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql index 414f62429..58e22c031 100644 --- a/db/routines/vn/procedures/entry_getTransfer.sql +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -114,7 +114,7 @@ BEGIN CAST(ti.visible AS DECIMAL(10,0)) vis1, CAST(ti.available AS DECIMAL(10,0)) ava1, CAST(ti.visibleLanding AS DECIMAL(10,0)) vis2, - CAST(ti.availableLanding AS DECIMAL(10,0)) ava, + CAST(ti.availableLanding AS DECIMAL(10,0)) ava2, COALESCE(b2.`grouping`, b.`grouping`) `grouping`, COALESCE(b2.packing, b.packing) packing, COALESCE(b3.groupingMode, b2.groupingMode, b.groupingMode) package, From 23bf9b2750d8b4cb1f5e4ffbe6f7662e112ffe4e Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 12 Feb 2024 10:28:25 +0100 Subject: [PATCH 08/20] refactor: refs #6501 Minor change --- db/routines/vn/procedures/entry_getTransfer.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql index 58e22c031..426619463 100644 --- a/db/routines/vn/procedures/entry_getTransfer.sql +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -101,7 +101,8 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tTransfer ENGINE = MEMORY - SELECT it.categoryFk, + SELECT it.code `type`, + it.categoryFk, i.typeFk, i.id itemFk, i.name item, From 4b5802202ddb0b20a2dc93f4b3bfc8769a864849 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 12 Feb 2024 10:36:09 +0100 Subject: [PATCH 09/20] refactor: refs #6501 Minor change --- .../vn/procedures/entry_getTransfer.sql | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql index 426619463..10f14c681 100644 --- a/db/routines/vn/procedures/entry_getTransfer.sql +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -120,6 +120,7 @@ BEGIN COALESCE(b2.packing, b.packing) packing, COALESCE(b3.groupingMode, b2.groupingMode, b.groupingMode) package, IFNULL(p.name, s.nickname) productor, + TRUE tinta, b.packagingFk, b2.id buyFk, b2.stickers, @@ -136,8 +137,8 @@ BEGIN e.commission, pa.isPackageReturnable, IFNULL(pa2.value, pa.value) `value`, - r.rate3, - r.rate2, + r.r3, + r.r2, it.promo, b.`grouping` groupingOrigin, b.packing packingOrigin, @@ -179,11 +180,17 @@ BEGIN SELECT *, quantity - MOD(quantity , `grouping`) subQuantity, MOD(quantity, `grouping`) soll, - ROUND((IF(volume > 0,volume, width * `depth` * IF(height = 0, `size` + 10, height))) / packing, 0) cm3, + ROUND((IF(volume > 0,volume, width * `depth` * + IF(height = 0, `size` + 10, height))) / + packing, 0) cm3, buyingValue + comissionValue + freightValue cost, - @carriage := ROUND((IF(volume > 0, volume, width * `depth` * IF(height = 0, `size` + 10, height))) * m3 / 1000000 / Packing, 3) carriage, - @comission := ROUND((buyingValue + comissionValue + freightValue) * commission / 100, 3) commission, - ROUND(@packaging := (returnCost + IF(isPackageReturnable != 0, 0, value)) / packing, 3) packaging, + @carriage := ROUND((IF(volume > 0, volume, width * `depth` * + IF(height = 0, `size` + 10, height))) * + m3 / 1000000 / Packing, 3) carriage, + @comission := ROUND((buyingValue + comissionValue + freightValue) * + commission / 100, 3) commission, + ROUND(@packaging := (returnCost + IF(isPackageReturnable != 0, 0, value)) + / packing, 3) packaging, @cost := IFNULL((buyingValue + comissionValue + freightValue), 0) + IFNULL(@packaging, 0) + IFNULL(@carriage, 0) + From fb763816245eb281f6025004242e2baf3150d9ef Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 12 Feb 2024 11:02:24 +0100 Subject: [PATCH 10/20] refactor: refs #6501 Minor change --- db/routines/vn/procedures/entry_getTransfer.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql index 10f14c681..986612a26 100644 --- a/db/routines/vn/procedures/entry_getTransfer.sql +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -137,8 +137,8 @@ BEGIN e.commission, pa.isPackageReturnable, IFNULL(pa2.value, pa.value) `value`, - r.r3, - r.r2, + r.rate3 r3, + r.rate2 r2, it.promo, b.`grouping` groupingOrigin, b.packing packingOrigin, From 8a7441be57a1acef083159f6bbe7dc5491117db8 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 12 Feb 2024 11:14:17 +0100 Subject: [PATCH 11/20] feat: refs #6371 --- db/routines/vn2008/procedures/clean.sql | 7 ------- db/versions/10876-goldenRoebelini/00-firstScript.sql | 4 ---- 2 files changed, 11 deletions(-) diff --git a/db/routines/vn2008/procedures/clean.sql b/db/routines/vn2008/procedures/clean.sql index 8c36cced8..0ff185c46 100644 --- a/db/routines/vn2008/procedures/clean.sql +++ b/db/routines/vn2008/procedures/clean.sql @@ -56,13 +56,6 @@ proc: BEGIN JOIN travel t ON t.id = e.travel_id WHERE t.landing <= vDate; - DELETE co - FROM Compres_ok co JOIN Compres c ON c.Id_Compra = co.Id_Compra - JOIN Entradas e ON e.Id_Entrada = c.Id_Entrada - JOIN travel t ON t.id = e.travel_id - WHERE t.landing <= vDate; - DELETE FROM scan WHERE odbc_date < vDate6 AND id <> 1; - IF v_full THEN CREATE OR REPLACE TEMPORARY TABLE tTicketDelete SELECT DISTINCT tl.originFk ticketFk diff --git a/db/versions/10876-goldenRoebelini/00-firstScript.sql b/db/versions/10876-goldenRoebelini/00-firstScript.sql index 361f3c7c8..c089f8950 100644 --- a/db/versions/10876-goldenRoebelini/00-firstScript.sql +++ b/db/versions/10876-goldenRoebelini/00-firstScript.sql @@ -1,7 +1,3 @@ -ALTER TABLE IF EXISTS vn2008.Compres_ok__ RENAME vn2008.Compres_ok; -ALTER TABLE IF EXISTS vn2008.Compres_ok COMMENT=''; - - -- Para la tabla Monitoring ALTER TABLE IF EXISTS vn2008.Monitoring RENAME vn2008.Monitoring__; ALTER TABLE IF EXISTS vn2008.Monitoring__ COMMENT='refs #6371 deprecated 2024-01-11'; From ee67a02bf0cad8944b0fb82c2a1ae3f3948b3f77 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 12 Feb 2024 11:28:54 +0100 Subject: [PATCH 12/20] refactor: refs #6501 Minor change --- db/routines/vn/procedures/entry_getTransfer.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql index 986612a26..2939fbf9e 100644 --- a/db/routines/vn/procedures/entry_getTransfer.sql +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -195,8 +195,8 @@ BEGIN IFNULL(@packaging, 0) + IFNULL(@carriage, 0) + IFNULL(@comission, 0) expense, - @rate3 := ROUND(@cost / ( (100 - rate3 - promo) / 100), 2) rate3, - ROUND(@rate3 * (1 + ((rate2 - rate3)/100)), 2) rate2, + @rate3 := ROUND(@cost / ( (100 - r3 - promo) / 100), 2) rate3, + ROUND(@rate3 * (1 + ((rate2 - r3)/100)), 2) rate2, FALSE selected FROM tTransfer; From 96d6637a3f689d59f460a22a14cfb9f525d0f8a8 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 12 Feb 2024 11:32:07 +0100 Subject: [PATCH 13/20] refactor: refs #6501 Minor change --- db/routines/vn/procedures/entry_getTransfer.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql index 2939fbf9e..f2cec654e 100644 --- a/db/routines/vn/procedures/entry_getTransfer.sql +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -196,7 +196,7 @@ BEGIN IFNULL(@carriage, 0) + IFNULL(@comission, 0) expense, @rate3 := ROUND(@cost / ( (100 - r3 - promo) / 100), 2) rate3, - ROUND(@rate3 * (1 + ((rate2 - r3)/100)), 2) rate2, + ROUND(@rate3 * (1 + ((r2 - r3)/100)), 2) rate2, FALSE selected FROM tTransfer; From fb84fe4b973be62faf9cb6079c17e825d9ca1bb1 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 13 Feb 2024 07:16:32 +0100 Subject: [PATCH 14/20] refactor: refs #6501 Requested changes --- .../{XDiario_reconciliation.sql => XDiario_verify.sql} | 4 ++-- db/routines/vn/procedures/entry_getTransfer.sql | 6 +++--- .../{travel_detail.sql => travel_detailAmerica.sql} | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename db/routines/vn/procedures/{XDiario_reconciliation.sql => XDiario_verify.sql} (93%) rename db/routines/vn/procedures/{travel_detail.sql => travel_detailAmerica.sql} (98%) diff --git a/db/routines/vn/procedures/XDiario_reconciliation.sql b/db/routines/vn/procedures/XDiario_verify.sql similarity index 93% rename from db/routines/vn/procedures/XDiario_reconciliation.sql rename to db/routines/vn/procedures/XDiario_verify.sql index c4724849d..0f898638a 100644 --- a/db/routines/vn/procedures/XDiario_reconciliation.sql +++ b/db/routines/vn/procedures/XDiario_verify.sql @@ -1,8 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_reconciliation`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_verify`() BEGIN /** - * Realiza la conciliación diaria de los asientos contables, + * Realiza la verificación diaria de los asientos contables, * identificando y notificando los asientos descuadrados * y ajustando los saldos en caso necesario. */ diff --git a/db/routines/vn/procedures/entry_getTransfer.sql b/db/routines/vn/procedures/entry_getTransfer.sql index f2cec654e..151bebd4d 100644 --- a/db/routines/vn/procedures/entry_getTransfer.sql +++ b/db/routines/vn/procedures/entry_getTransfer.sql @@ -4,7 +4,7 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_getTransfer`( ) BEGIN /** - * Gestiona el traslado de productos a partir de una entrada específica. + * Retorna los artículos trasladables a partir de una entrada. * * @param vSelf Id de entrada */ @@ -167,7 +167,7 @@ BEGIN LEFT JOIN vn.buy b3 ON b3.id = bufi.buyFk WHERE ic.display AND NOT e.isRaid - AND (ti.visible != 0 OR ti.available != 0) + AND (ti.visible OR ti.available) ORDER BY i.typeFk, i.name, i.id, i.size, i.category, o.name; CREATE INDEX tIndex USING HASH ON tTransfer (itemFk); @@ -189,7 +189,7 @@ BEGIN m3 / 1000000 / Packing, 3) carriage, @comission := ROUND((buyingValue + comissionValue + freightValue) * commission / 100, 3) commission, - ROUND(@packaging := (returnCost + IF(isPackageReturnable != 0, 0, value)) + ROUND(@packaging := (returnCost + IF(isPackageReturnable, 0, value)) / packing, 3) packaging, @cost := IFNULL((buyingValue + comissionValue + freightValue), 0) + IFNULL(@packaging, 0) + diff --git a/db/routines/vn/procedures/travel_detail.sql b/db/routines/vn/procedures/travel_detailAmerica.sql similarity index 98% rename from db/routines/vn/procedures/travel_detail.sql rename to db/routines/vn/procedures/travel_detailAmerica.sql index d805f0ca9..ecd24cd5c 100644 --- a/db/routines/vn/procedures/travel_detail.sql +++ b/db/routines/vn/procedures/travel_detailAmerica.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_detail`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_detailAmerica`() BEGIN /** * Devuelve los detalles de los vuelos que tienen From 185cc4f17fdf3209ded8586c954b110dc2b87fab Mon Sep 17 00:00:00 2001 From: Jbreso Date: Tue, 13 Feb 2024 09:50:07 +0100 Subject: [PATCH 15/20] feat: refs #6693 revisar triggers --- ...udgetNotes_BeforeInsert.sql => budgetNotes_beforeInsert.sql} | 2 +- ...lientCredit_AfterInsert.sql => clientCredit_afterInsert.sql} | 0 .../triggers/{client_AfterInsert.sql => client_afterInsert.sql} | 0 ...ionState_AfterInsert.sql => expeditionState_afterInsert.sql} | 0 ...nState_BeforeInsert.sql => expeditionState_beforeInsert.sql} | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename db/routines/vn/triggers/{budgetNotes_BeforeInsert.sql => budgetNotes_beforeInsert.sql} (91%) rename db/routines/vn/triggers/{clientCredit_AfterInsert.sql => clientCredit_afterInsert.sql} (100%) rename db/routines/vn/triggers/{client_AfterInsert.sql => client_afterInsert.sql} (100%) rename db/routines/vn/triggers/{expeditionState_AfterInsert.sql => expeditionState_afterInsert.sql} (100%) rename db/routines/vn/triggers/{expeditionState_BeforeInsert.sql => expeditionState_beforeInsert.sql} (100%) diff --git a/db/routines/vn/triggers/budgetNotes_BeforeInsert.sql b/db/routines/vn/triggers/budgetNotes_beforeInsert.sql similarity index 91% rename from db/routines/vn/triggers/budgetNotes_BeforeInsert.sql rename to db/routines/vn/triggers/budgetNotes_beforeInsert.sql index f75b7a01e..6ea5ad5eb 100644 --- a/db/routines/vn/triggers/budgetNotes_BeforeInsert.sql +++ b/db/routines/vn/triggers/budgetNotes_beforeInsert.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`budgetNotes_BeforeInsert` +CREATE OR REPLACE DEFINER=`root`@`localhost` TRIGGER `vn`.`budgetNotes_beforeInsert` BEFORE INSERT ON `budgetNotes` FOR EACH ROW BEGIN diff --git a/db/routines/vn/triggers/clientCredit_AfterInsert.sql b/db/routines/vn/triggers/clientCredit_afterInsert.sql similarity index 100% rename from db/routines/vn/triggers/clientCredit_AfterInsert.sql rename to db/routines/vn/triggers/clientCredit_afterInsert.sql diff --git a/db/routines/vn/triggers/client_AfterInsert.sql b/db/routines/vn/triggers/client_afterInsert.sql similarity index 100% rename from db/routines/vn/triggers/client_AfterInsert.sql rename to db/routines/vn/triggers/client_afterInsert.sql diff --git a/db/routines/vn/triggers/expeditionState_AfterInsert.sql b/db/routines/vn/triggers/expeditionState_afterInsert.sql similarity index 100% rename from db/routines/vn/triggers/expeditionState_AfterInsert.sql rename to db/routines/vn/triggers/expeditionState_afterInsert.sql diff --git a/db/routines/vn/triggers/expeditionState_BeforeInsert.sql b/db/routines/vn/triggers/expeditionState_beforeInsert.sql similarity index 100% rename from db/routines/vn/triggers/expeditionState_BeforeInsert.sql rename to db/routines/vn/triggers/expeditionState_beforeInsert.sql From ed67b1168f71f457c0210a5c13b5fa8a5b3267a6 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 13 Feb 2024 11:14:35 +0100 Subject: [PATCH 16/20] refactor: refs #6501 Requested changes --- ...ilAmerica.sql => continent_getTravelDetail.sql} | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) rename db/routines/vn/procedures/{travel_detailAmerica.sql => continent_getTravelDetail.sql} (87%) diff --git a/db/routines/vn/procedures/travel_detailAmerica.sql b/db/routines/vn/procedures/continent_getTravelDetail.sql similarity index 87% rename from db/routines/vn/procedures/travel_detailAmerica.sql rename to db/routines/vn/procedures/continent_getTravelDetail.sql index ecd24cd5c..8049f9e65 100644 --- a/db/routines/vn/procedures/travel_detailAmerica.sql +++ b/db/routines/vn/procedures/continent_getTravelDetail.sql @@ -1,9 +1,13 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_detailAmerica`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`continent_getTravelDetail`( + vSelf INT +) BEGIN /** * Devuelve los detalles de los vuelos que tienen - * un almacén de salida en Ecuador o Colombia. + * un almacén de salida de un continente. + * + * @param vSelf Id de continente */ DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK; SELECT IFNULL(CONCAT(" ", entryFk), travelFk) travelAndEntry, @@ -44,10 +48,11 @@ BEGIN LEFT JOIN itemType it ON it.id = i.typeFk JOIN warehouse wIn ON wIn.id = tr.warehouseInFk JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk + JOIN country co ON co.id = wOut.countryFk JOIN agencyMode am ON am.id = tr.agencyModeFk JOIN volumeConfig vc WHERE tr.landed >= vDateFrom - AND (wOut.code = "col" OR wOut.code = "ecu") + AND co.continentFk = vSelf GROUP BY tr.id UNION ALL SELECT e.travelFk, @@ -86,9 +91,10 @@ BEGIN LEFT JOIN supplier s2 ON s2.id = tr.cargoSupplierFk JOIN warehouse wIn ON wIn.id = tr.warehouseInFk JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk + JOIN country co ON co.id = wOut.countryFk JOIN volumeConfig vc WHERE tr.landed >= vDateFrom - AND (wOut.code = "col" OR wOut.code = "ecu") + AND co.continentFk = vSelf GROUP BY e.id ) sub ORDER BY landed ASC, From c2dadc09a22de4c648806f890f65ed5a875bb4e6 Mon Sep 17 00:00:00 2001 From: Jbreso Date: Wed, 14 Feb 2024 07:36:38 +0100 Subject: [PATCH 17/20] feat: refs #6693 comprobar triggers --- ...rojectNotes_BeforeInsert.sql => projectNotes_beforeInsert.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/routines/vn/triggers/{projectNotes_BeforeInsert.sql => projectNotes_beforeInsert.sql} (100%) diff --git a/db/routines/vn/triggers/projectNotes_BeforeInsert.sql b/db/routines/vn/triggers/projectNotes_beforeInsert.sql similarity index 100% rename from db/routines/vn/triggers/projectNotes_BeforeInsert.sql rename to db/routines/vn/triggers/projectNotes_beforeInsert.sql From 874f77649806f1d79a3a883be8ec4a70d6befaf4 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 14 Feb 2024 11:05:16 +0100 Subject: [PATCH 18/20] refactor: refs #6501 Requested changes --- .../vn/procedures/{XDiario_verify.sql => XDiario_check.sql} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename db/routines/vn/procedures/{XDiario_verify.sql => XDiario_check.sql} (94%) diff --git a/db/routines/vn/procedures/XDiario_verify.sql b/db/routines/vn/procedures/XDiario_check.sql similarity index 94% rename from db/routines/vn/procedures/XDiario_verify.sql rename to db/routines/vn/procedures/XDiario_check.sql index 0f898638a..0fb1c410d 100644 --- a/db/routines/vn/procedures/XDiario_verify.sql +++ b/db/routines/vn/procedures/XDiario_check.sql @@ -1,8 +1,8 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_verify`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_check`() BEGIN /** - * Realiza la verificación diaria de los asientos contables, + * Realiza la revisión diaria de los asientos contables, * identificando y notificando los asientos descuadrados * y ajustando los saldos en caso necesario. */ From b64637254b267cccbc624c62106232bb016947e1 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 14 Feb 2024 11:16:52 +0100 Subject: [PATCH 19/20] refactor: refs #6501 Requested changes --- ...velDetail.sql => travel_getDetailFromContinent.sql} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename db/routines/vn/procedures/{continent_getTravelDetail.sql => travel_getDetailFromContinent.sql} (91%) diff --git a/db/routines/vn/procedures/continent_getTravelDetail.sql b/db/routines/vn/procedures/travel_getDetailFromContinent.sql similarity index 91% rename from db/routines/vn/procedures/continent_getTravelDetail.sql rename to db/routines/vn/procedures/travel_getDetailFromContinent.sql index 8049f9e65..e81e648b3 100644 --- a/db/routines/vn/procedures/continent_getTravelDetail.sql +++ b/db/routines/vn/procedures/travel_getDetailFromContinent.sql @@ -1,13 +1,13 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`continent_getTravelDetail`( - vSelf INT +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_getDetailFromContinent`( + vContinentFk INT ) BEGIN /** * Devuelve los detalles de los vuelos que tienen * un almacén de salida de un continente. * - * @param vSelf Id de continente + * @param vContinentFk Id de continente */ DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK; SELECT IFNULL(CONCAT(" ", entryFk), travelFk) travelAndEntry, @@ -52,7 +52,7 @@ BEGIN JOIN agencyMode am ON am.id = tr.agencyModeFk JOIN volumeConfig vc WHERE tr.landed >= vDateFrom - AND co.continentFk = vSelf + AND co.continentFk = vContinentFk GROUP BY tr.id UNION ALL SELECT e.travelFk, @@ -94,7 +94,7 @@ BEGIN JOIN country co ON co.id = wOut.countryFk JOIN volumeConfig vc WHERE tr.landed >= vDateFrom - AND co.continentFk = vSelf + AND co.continentFk = vContinentFk GROUP BY e.id ) sub ORDER BY landed ASC, From b46087b75c6eeaa16870968c557312f77f70811e Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 14 Feb 2024 11:21:22 +0100 Subject: [PATCH 20/20] refactor: refs #6501 Requested changes --- .../10878-blueSalal/00-firstScript.sql | 482 +----------------- 1 file changed, 10 insertions(+), 472 deletions(-) diff --git a/db/versions/10878-blueSalal/00-firstScript.sql b/db/versions/10878-blueSalal/00-firstScript.sql index 7ef168c6b..64506fa61 100644 --- a/db/versions/10878-blueSalal/00-firstScript.sql +++ b/db/versions/10878-blueSalal/00-firstScript.sql @@ -1,496 +1,34 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplier_statement`( - vSupplierFk INT, - vCurrencyFk INT, - vCompanyFk INT, - vOrderBy VARCHAR(15), - vIsConciliated BOOL -) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`supplier_statement`() BEGIN -/** - * Crea un estado de cuenta de proveedores calculando - * los saldos en euros y en la moneda especificada. - * - * @param vSupplierFk Id del proveedor - * @param vCurrencyFk Id de la moneda - * @param vCompanyFk Id de la empresa - * @param vOrderBy Criterio de ordenación - * @param vIsConciliated Indica si está conciliado o no - * @return tmp.supplierStatement - */ - SET @euroBalance:= 0; - SET @currencyBalance:= 0; - - CREATE OR REPLACE TEMPORARY TABLE tmp.supplierStatement - ENGINE = MEMORY - SELECT *, - @euroBalance:= ROUND( - @euroBalance + IFNULL(paymentEuros, 0) - - IFNULL(invoiceEuros, 0), 2 - ) euroBalance, - @currencyBalance:= ROUND( - @currencyBalance + IFNULL(paymentCurrency, 0) - - IFNULL(invoiceCurrency, 0), 2 - ) currencyBalance - FROM ( - SELECT * FROM - ( - SELECT NULL bankFk, - ii.companyFk, - ii.serial, - ii.id, - CASE - WHEN vOrderBy = 'issued' THEN ii.issued - WHEN vOrderBy = 'bookEntried' THEN ii.bookEntried - WHEN vOrderBy = 'booked' THEN ii.booked - WHEN vOrderBy = 'dueDate' THEN iid.dueDated - END dated, - CONCAT('S/Fra ', ii.supplierRef) sref, - IF(ii.currencyFk > 1, - ROUND(SUM(iid.foreignValue) / SUM(iid.amount), 3), - NULL - ) changeValue, - CAST(SUM(iid.amount) AS DECIMAL(10,2)) invoiceEuros, - CAST(SUM(iid.foreignValue) AS DECIMAL(10,2)) invoiceCurrency, - NULL paymentEuros, - NULL paymentCurrency, - ii.currencyFk, - ii.isBooked, - c.code, - 'invoiceIn' statementType - FROM invoiceIn ii - JOIN invoiceInDueDay iid ON iid.invoiceInFk = ii.id - JOIN currency c ON c.id = ii.currencyFk - WHERE ii.issued > '2014-12-31' - AND ii.supplierFk = vSupplierFk - AND vCurrencyFk IN (ii.currencyFk, 0) - AND vCompanyFk IN (ii.companyFk, 0) - AND (vIsConciliated = ii.isBooked OR NOT vIsConciliated) - GROUP BY iid.id - UNION ALL - SELECT p.bankFk, - p.companyFk, - NULL, - p.id, - CASE - WHEN vOrderBy = 'issued' THEN p.received - WHEN vOrderBy = 'bookEntried' THEN p.received - WHEN vOrderBy = 'booked' THEN p.received - WHEN vOrderBy = 'dueDate' THEN p.dueDated - END, - CONCAT(IFNULL(pm.name, ''), - IF(pn.concept <> '', - CONCAT(' : ', pn.concept), - '') - ), - IF(p.currencyFk > 1, p.divisa / p.amount, NULL), - NULL, - NULL, - p.amount, - p.divisa, - p.currencyFk, - p.isConciliated, - c.code, - 'payment' - FROM payment p - LEFT JOIN currency c ON c.id = p.currencyFk - LEFT JOIN bank b ON b.id = p.bankFk - LEFT JOIN payMethod pm ON pm.id = p.payMethodFk - LEFT JOIN promissoryNote pn ON pn.paymentFk = p.id - WHERE p.received > '2014-12-31' - AND p.supplierFk = vSupplierFk - AND vCurrencyFk IN (p.currencyFk, 0) - AND vCompanyFk IN (p.companyFk, 0) - AND (vIsConciliated = p.isConciliated OR NOT vIsConciliated) - UNION ALL - SELECT NULL, - companyFk, - NULL, - se.id, - CASE - WHEN vOrderBy = 'issued' THEN se.dated - WHEN vOrderBy = 'bookEntried' THEN se.dated - WHEN vOrderBy = 'booked' THEN se.dated - WHEN vOrderBy = 'dueDate' THEN se.dueDated - END, - se.description, - 1, - amount, - NULL, - NULL, - NULL, - currencyFk, - isConciliated, - c.`code`, - 'expense' - FROM supplierExpense se - JOIN currency c ON c.id = se.currencyFk - WHERE se.supplierFk = vSupplierFk - AND vCurrencyFk IN (se.currencyFk,0) - AND vCompanyFk IN (se.companyFk,0) - AND (vIsConciliated = se.isConciliated OR NOT vIsConciliated) - ) sub - ORDER BY (dated IS NULL AND NOT isBooked), - dated, - IF(vOrderBy = 'dueDate', id, NULL) - LIMIT 10000000000000000000 - ) t; + SELECT 1; END$$ DELIMITER ; GRANT EXECUTE ON PROCEDURE vn.supplier_statement TO administrative, buyer, hrBoss; DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_reconciliation`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`XDiario_check`() BEGIN -/** - * Realiza la conciliación diaria de los asientos contables, - * identificando y notificando los asientos descuadrados - * y ajustando los saldos en caso necesario. - */ - INSERT INTO mail (receiver, subject, body) - SELECT 'cau@verdnatura.es', - 'Asientos descuadrados', - GROUP_CONCAT(CONCAT(' Asiento: ', ASIEN, ' - Importe:', recon) SEPARATOR ' | \n') - FROM ( - SELECT ASIEN, - SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon - FROM XDiario - WHERE NOT enlazado - GROUP BY ASIEN - HAVING ABS(SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0))) > 0.01 - ) sub - HAVING COUNT(*); - - UPDATE XDiario xd - JOIN ( - SELECT xd.id, SUBCTA, recon - FROM XDiario xd - JOIN ( - SELECT ASIEN, - SUM(IFNULL(ROUND(Eurodebe, 2), 0)) - SUM(IFNULL(ROUND(EUROHABER, 2), 0)) recon - FROM XDiario - WHERE NOT enlazado - GROUP BY ASIEN - HAVING recon - ) sub ON sub.ASIEN = xd.ASIEN - WHERE xd.SUBCTA > '5999999999' - GROUP BY xd.ASIEN - ) sub ON sub.id = xd.id - SET xd.Eurohaber = IF(IFNULL(xd.Eurohaber, 0) = 0, xd.Eurohaber, xd.Eurohaber + sub.recon), - xd.Eurodebe = IF(IFNULL(xd.Eurodebe, 0) = 0, xd.Eurodebe, xd.Eurodebe - sub.recon); + SELECT 1; END$$ DELIMITER ; -GRANT EXECUTE ON PROCEDURE vn.XDiario_reconciliation TO adminBoss; +GRANT EXECUTE ON PROCEDURE vn.XDiario_check TO adminBoss; DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_detail`() +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`travel_getDetailFromContinent`() BEGIN -/** - * Devuelve los detalles de los vuelos que tienen - * un almacén de salida en Ecuador o Colombia. - */ - DECLARE vDateFrom DATE DEFAULT util.VN_CURDATE() - INTERVAL 12 WEEK; - SELECT IFNULL(CONCAT(" ", entryFk), travelFk) travelAndEntry, - sub.* - FROM ( - SELECT tr.id travelFk, - NULL entryFk, - TRUE isTravel, - am.name agency, - tr.ref, - tr.shipped, - wOut.name originBoxes, - tr.landed, - wIn.name destination, - SUM(b.stickers) stickers, - NULL evaNotes, - tr.kg, - CAST(SUM(b.weight * b.stickers) AS INT) loadedkg, - CAST( - SUM(vc.aerealVolumetricDensity * - b.stickers * - IF(p.volume, - p.volume, - p.width * p.depth * p.height - ) / 1000000 - ) AS INT - ) volumeKg, - NULL loadPriority, - NULL invoiceAmount, - s.nickname freighter, - NULL reference - FROM travel tr - LEFT JOIN supplier s ON s.id = tr.cargoSupplierFk - LEFT JOIN entry e ON e.travelFk = tr.id - LEFT JOIN buy b ON b.entryFk = e.id - LEFT JOIN packaging p ON p.id = b.packagingFk - LEFT JOIN item i ON i.id = b.itemFk - LEFT JOIN itemType it ON it.id = i.typeFk - JOIN warehouse wIn ON wIn.id = tr.warehouseInFk - JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk - JOIN agencyMode am ON am.id = tr.agencyModeFk - JOIN volumeConfig vc - WHERE tr.landed >= vDateFrom - AND (wOut.code = "col" OR wOut.code = "ecu") - GROUP BY tr.id - UNION ALL - SELECT e.travelFk, - e.id, - FALSE, - s.name, - e.invoiceNumber, - tr.shipped, - wOut.name, - tr.landed, - wIn.name, - SUM(b.stickers), - e.evaNotes, - NULL, - CAST(SUM(b.weight * b.stickers) AS INT), - CAST( - SUM(vc.aerealVolumetricDensity * - b.stickers * - IF(p.volume, - p.volume, - p.width * p.depth * p.height - ) / 1000000 - ) AS INT - ), - loadPriority, - e.invoiceAmount, - s2.nickname, - e.reference - FROM entry e - JOIN buy b ON b.entryFk = e.id - JOIN packaging p ON p.id = b.packagingFk - JOIN item i ON i.id = b.itemFk - JOIN itemType it ON it.id = i.typeFk - JOIN supplier s ON s.id = e.supplierFk - JOIN travel tr ON tr.id = e.travelFk - LEFT JOIN supplier s2 ON s2.id = tr.cargoSupplierFk - JOIN warehouse wIn ON wIn.id = tr.warehouseInFk - JOIN warehouse wOut ON wOut.id = tr.warehouseOutFk - JOIN volumeConfig vc - WHERE tr.landed >= vDateFrom - AND (wOut.code = "col" OR wOut.code = "ecu") - GROUP BY e.id - ) sub - ORDER BY landed ASC, - shipped ASC, - travelFk, - isTravel DESC, - (loadPriority > 0) DESC, - loadPriority, - agency, - evaNotes; + SELECT 1; END$$ DELIMITER ; -GRANT EXECUTE ON PROCEDURE vn.travel_detail TO buyer; +GRANT EXECUTE ON PROCEDURE vn.travel_getDetailFromContinent TO buyer; DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_getTransfer`( - vSelf INT -) +CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_getTransfer`() BEGIN -/** - * Gestiona el traslado de productos a partir de una entrada específica. - * - * @param vSelf Id de entrada - */ - DECLARE vDateShipped DATE; - DECLARE vDateLanded DATE; - DECLARE vWarehouseIn INT; - DECLARE vWarehouseOut INT; - DECLARE vCalcVisible INT; - DECLARE vInventoryDate DATE DEFAULT vn.getInventoryDate(); - - SELECT shipped, landed, warehouseInFk, warehouseOutFk - INTO vDateShipped, vDateLanded, vWarehouseIn, vWarehouseOut - FROM vn.travel t - JOIN vn.entry e ON e.travelFk = t.id - WHERE e.id = vSelf; - - CALL vn.rate_getPrices(vDateShipped, vWarehouseIn); - - -- Traslado en almacen origen - CREATE OR REPLACE TEMPORARY TABLE tBuy - (PRIMARY KEY (itemFk), INDEX(buyFk)) - ENGINE = MEMORY - SELECT * - FROM ( - SELECT b.itemFk, b.id buyFk - FROM buy b - JOIN entry e ON e.id = b.entryFk - JOIN travel t ON t.id = e.travelFk - WHERE t.landed BETWEEN vInventoryDate AND vDateShipped - AND NOT b.isIgnored - AND b.price2 >= 0 - ORDER BY (vWarehouseOut = t.warehouseInFk) DESC, t.landed DESC - LIMIT 10000000000000000000 - ) sub - GROUP BY itemFk; - - IF vDateShipped >= util.VN_CURDATE() THEN - CALL `cache`.visible_refresh(vCalcVisible, TRUE, vWarehouseOut); - - CREATE OR REPLACE TEMPORARY TABLE tItem ( - `itemFk` int(10) unsigned NOT NULL, - `visible` int(11) NOT NULL DEFAULT 0, - `available` int(11) NOT NULL DEFAULT 0, - `visibleLanding` int(11) NOT NULL DEFAULT 0, - `availableLanding` int(11) NOT NULL DEFAULT 0, - UNIQUE INDEX i USING HASH (itemFk) - ) ENGINE = MEMORY; - - INSERT INTO tItem(itemFk, visible) - SELECT item_id itemFk, visible - FROM `cache`.visible - WHERE calc_id = vCalcVisible - AND visible; - - CALL `cache`.visible_refresh(vCalcVisible, TRUE, vWarehouseIn); - - INSERT INTO tItem(itemFk, visibleLanding) - SELECT item_id, `visible` - FROM `cache`.`visible` v - WHERE v.calc_id = vCalcVisible - AND v.`visible` - ON DUPLICATE KEY UPDATE visibleLanding = v.`visible`; - - CALL vn2008.availableTraslate(vWarehouseOut, vDateShipped, NULL); - - INSERT INTO tItem(itemFk, available) - SELECT a.item_id, a.available - FROM vn2008.availableTraslate a - WHERE a.available - ON DUPLICATE KEY UPDATE available = a.available; - - CALL vn2008.availableTraslate(vWarehouseIn, vDateLanded, vWarehouseOut); - - INSERT INTO tItem(itemFk, availableLanding) - SELECT a.item_id, a.available - FROM vn2008.availableTraslate a - WHERE a.available - ON DUPLICATE KEY UPDATE availableLanding = a.available; - ELSE - CALL vn.item_getStock(vWarehouseOut, vDateShipped, NULL); - - CREATE OR REPLACE TEMPORARY TABLE tItem - (UNIQUE INDEX i USING HASH (itemFk)) - ENGINE = MEMORY - SELECT itemFk, - `visible`, - available, - 0 visibleLanding, - 0 availableLanding - FROM tmp.itemList; - END IF; - - CALL vn.buyUltimateFromInterval(vWarehouseIn,vInventoryDate, vDateLanded); - - CREATE OR REPLACE TEMPORARY TABLE tTransfer - ENGINE = MEMORY - SELECT it.categoryFk, - i.typeFk, - i.id itemFk, - i.name item, - i.`size`, - i.category, - i.inkFk, - o.code originCode, - b2.quantity, - i.stems, - CAST(ti.visible AS DECIMAL(10,0)) vis1, - CAST(ti.available AS DECIMAL(10,0)) ava1, - CAST(ti.visibleLanding AS DECIMAL(10,0)) vis2, - CAST(ti.availableLanding AS DECIMAL(10,0)) ava, - COALESCE(b2.`grouping`, b.`grouping`) `grouping`, - COALESCE(b2.packing, b.packing) packing, - COALESCE(b3.groupingMode, b2.groupingMode, b.groupingMode) package, - IFNULL(p.name, s.nickname) productor, - b.packagingFk, - b2.id buyFk, - b2.stickers, - b.ektFk, - it.workerFk, - pa.volume, - IFNULL(pa.width, 0) width, - IFNULL(pa.`depth`, 0) `depth`, - IFNULL(pa.height, 0) height, - IFNULL(b.buyingValue, 0) buyingValue, - IFNULL(b.comissionValue, 0) comissionValue, - IFNULL(b.freightValue, 0) freightValue, - am.m3, - e.commission, - pa.isPackageReturnable, - IFNULL(pa2.value, pa.value) `value`, - r.rate3, - r.rate2, - it.promo, - b.`grouping` groupingOrigin, - b.packing packingOrigin, - b.id buyFkOrigin, - pa.returnCost, - b.weight - FROM vn.item i - JOIN tItem ti ON ti.itemFk = i.id - LEFT JOIN vn.producer p ON p.id = i.producerFk - LEFT JOIN vn.itemType it ON it.id = i.typeFk - JOIN vn.itemCategory ic ON ic.id = it.categoryFk - LEFT JOIN vn.origin o ON o.id = i.originFk - LEFT JOIN tBuy lb ON lb.itemFk = i.id - LEFT JOIN vn.buy b ON b.id = lb.buyFk - LEFT JOIN vn.packaging pa ON pa.id = b.packagingFk - LEFT JOIN vn.entry e2 ON e2.id = b.entryFk - LEFT JOIN vn.supplier s ON s.id = e2.supplierFk - LEFT JOIN vn.entry e ON e.id = vSelf - LEFT JOIN vn.travel tr ON tr.id = e.travelFk - LEFT JOIN vn.agencyMode am ON am.id = tr.agencyModeFk - LEFT JOIN vn.buy b2 ON b2.itemFk = i.id - AND b2.entryFk = vSelf - LEFT JOIN vn.packaging pa2 ON pa2.id = b.packagingFk - LEFT JOIN tmp.rate r ON TRUE - LEFT JOIN tmp.buyUltimateFromInterval bufi ON bufi.itemFk = i.id - LEFT JOIN vn.buy b3 ON b3.id = bufi.buyFk - WHERE ic.display - AND NOT e.isRaid - AND (ti.visible != 0 OR ti.available != 0) - ORDER BY i.typeFk, i.name, i.id, i.size, i.category, o.name; - - CREATE INDEX tIndex USING HASH ON tTransfer (itemFk); - - SET @carriage := 0; - SET @comission := 0; - SET @packaging := 0; - SET @rate3 := 0; - SET @cost := 0; - SELECT *, - quantity - MOD(quantity , `grouping`) subQuantity, - MOD(quantity, `grouping`) soll, - ROUND((IF(volume > 0,volume, width * `depth` * IF(height = 0, `size` + 10, height))) / packing, 0) cm3, - buyingValue + comissionValue + freightValue Cost, - @carriage := ROUND((IF(volume > 0, volume, width * `depth` * IF(height = 0, `size` + 10, height))) * m3 / 1000000 / Packing, 3) carriage, - @comission := ROUND((buyingValue + comissionValue + freightValue) * commission / 100, 3) commission, - ROUND(@packaging := (returnCost + IF(isPackageReturnable != 0, 0, value)) / packing, 3) packaging, - @cost := IFNULL((buyingValue + comissionValue + freightValue), 0) + - IFNULL(@packaging, 0) + - IFNULL(@carriage, 0) + - IFNULL(@comission, 0) cost, - @rate3 := ROUND(@cost / ( (100 - rate3 - promo) / 100), 2) rate3, - ROUND(@rate3 * (1 + ((rate2 - rate3)/100)), 2) rate2, - FALSE selected - FROM tTransfer; - - DROP TEMPORARY TABLE IF EXISTS - tTransfer, - tItem, - tBuy, - tmp.buyUltimateFromInterval, - tmp.rate, - tmp.itemList; + SELECT 1; END$$ DELIMITER ;