diff --git a/db/routines/vn/procedures/available_traslate.sql b/db/routines/vn/procedures/available_traslate.sql index 8ef452c6f..d5c6b6da0 100644 --- a/db/routines/vn/procedures/available_traslate.sql +++ b/db/routines/vn/procedures/available_traslate.sql @@ -5,11 +5,12 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`available_traslate` vWarehouseShipment INT) proc: BEGIN /** - * Calcular la disponibilidad dependiendo del almacen de origen y destino según la fecha + * Calcular la disponibilidad dependiendo del almacen + * de origen y destino según la fecha. * - * @param vWarehouseLanding almacén de llegada. - * @param vDated la fecha para la cual se está calculando la disponibilidad de articulos. - * @param vWarehouseShipment almacén de destino. + * @param vWarehouseLanding almacén de llegada + * @param vDated fecha del calculo para la disponibilidad de articulos + * @param vWarehouseShipment almacén de destino */ DECLARE vDatedFrom DATE; DECLARE vDatedTo DATETIME; @@ -44,7 +45,8 @@ proc: BEGIN AND NOT e.isRaid GROUP BY c.itemFk; - -- Tabla con el ultimo dia de last_buy para cada producto que hace un replace de la anterior + -- Tabla con el ultimo dia de last_buy para cada producto + -- que hace un replace de la anterior. CALL buyUltimate(vWarehouseShipment, util.VN_CURDATE()); INSERT INTO tItemRange @@ -56,7 +58,8 @@ proc: BEGIN LEFT JOIN tItemRange i ON t.itemFk = i.itemFk WHERE t.warehouseFk = vWarehouseShipment AND NOT e.isRaid - ON DUPLICATE KEY UPDATE tItemRange.dated = GREATEST(tItemRange.dated, tr.landed); + ON DUPLICATE KEY UPDATE tItemRange.dated = GREATEST(tItemRange.dated, + tr.landed); CREATE OR REPLACE TEMPORARY TABLE tItemRangeLive (PRIMARY KEY (itemFk)) @@ -67,18 +70,24 @@ proc: BEGIN JOIN itemType it ON it.id = i.typeFk HAVING dated >= vDatedFrom OR dated IS NULL; - -- Calcula el ATP + -- Calcula el ATP. CREATE OR REPLACE TEMPORARY TABLE tmp.itemCalc (INDEX (itemFk,warehouseFk)) ENGINE = MEMORY - SELECT i.itemFk, vWarehouseLanding warehouseFk, i.shipped dated, i.quantity + SELECT i.itemFk, + vWarehouseLanding warehouseFk, + i.shipped dated, + i.quantity FROM itemTicketOut i JOIN tItemRangeLive ir ON ir.itemFK = i.itemFk WHERE i.shipped >= vDatedFrom AND (ir.dated IS NULL OR i.shipped <= ir.dated) AND i.warehouseFk = vWarehouseLanding UNION ALL - SELECT b.itemFk, vWarehouseLanding, t.landed, b.quantity + SELECT b.itemFk, + vWarehouseLanding, + t.landed, + b.quantity FROM buy b JOIN entry e ON b.entryFk = e.id JOIN travel t ON t.id = e.travelFk diff --git a/db/routines/vn/procedures/balance_create.sql b/db/routines/vn/procedures/balance_create.sql index e02a26ca2..0124087cb 100644 --- a/db/routines/vn/procedures/balance_create.sql +++ b/db/routines/vn/procedures/balance_create.sql @@ -7,13 +7,14 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balance_create`( IN vInterGroupSalesIncluded BOOLEAN) BEGIN /** - * Crea un balance financiero para una empresa durante un período de tiempo determinado + * Crea un balance financiero para una empresa durante + * un período de tiempo determinado. * * @param vStartingMonth Mes de inicio del período * @param vEndingMonth Mes de finalización del período * @param vCompany Identificador de la empresa * @param vIsConsolidated Indica si se trata de un balance consolidado - * @param vInterGroupSalesIncluded Indica si se incluyen las ventas dentro del grupo + * @param vInterGroupSalesIncluded Indica si se incluyen las ventas del grupo */ DECLARE intGAP INT DEFAULT 7; DECLARE vYears INT DEFAULT 2; @@ -32,19 +33,20 @@ BEGIN SET vOneYearAgo = util.quoteIdentifier(vCurYear-1); SET vTwoYearsAgo = util.quoteIdentifier(vCurYear-2); - -- Solicitamos la tabla tmp.nest, como base para el balance + -- Solicitamos la tabla tmp.nest, como base para el balance. DROP TEMPORARY TABLE IF EXISTS tmp.nest; EXECUTE IMMEDIATE CONCAT( 'CREATE TEMPORARY TABLE tmp.nest SELECT node.id - ,CONCAT( REPEAT(REPEAT(" ",?), COUNT(parent.id) - 1), node.name) AS name - ,node.lft - ,node.rgt - ,COUNT(parent.id) - 1 as depth - ,cast((node.rgt - node.lft - 1) / 2 as DECIMAL) as sons - FROM ', vTable, ' AS node, - ', vTable, ' AS parent + ,CONCAT( REPEAT(REPEAT(" ",?), COUNT(parent.id) - 1), + node.name) name, + node.lft, + node.rgt, + COUNT(parent.id) - 1 depth, + CAST((node.rgt - node.lft - 1) / 2 AS DECIMAL) sons + FROM ', vTable, ' node, + ', vTable, ' parent WHERE node.lft BETWEEN parent.lft AND parent.rgt GROUP BY node.id ORDER BY node.lft') @@ -76,7 +78,8 @@ BEGIN END IF; - -- Se calculan las facturas que intervienen, para luego poder servir el desglose desde aqui + -- Se calculan las facturas que intervienen, + -- para luego poder servir el desglose desde aqui. CREATE OR REPLACE TEMPORARY TABLE tmp.balanceDetail SELECT cr.companyFk receivingId, ci.companyFk issuingId, @@ -90,30 +93,30 @@ BEGIN JOIN tCompanyIssuing ci ON ci.companyFk = r.supplierFk WHERE COALESCE(r.bookEntried, r.booked, r.issued) >= vStartingDate AND r.isBooked - GROUP BY expenseFk, year, month, ci.companyFk, cr.companyFk; + GROUP BY expenseFk, `year`, `month`, ci.companyFk, cr.companyFk; INSERT INTO tmp.balanceDetail( receivingId, issuingId, - year, - month, + `year`, + `month`, expenseFk, amount) SELECT em.companyFk, em.companyFk, - year, - month, + `year`, + `month`, expenseFk, SUM(em.amount) FROM expenseManual em JOIN tCompanyReceiving er ON er.companyFk = em.companyFk - WHERE year >= vStartingYear - AND month BETWEEN vStartingMonth AND vEndingMonth - GROUP BY expenseFk, year, month, em.companyFk; + WHERE `year` >= vStartingYear + AND `month` BETWEEN vStartingMonth AND vEndingMonth + GROUP BY expenseFk, `year`, `month`, em.companyFk; DELETE FROM tmp.balanceDetail - WHERE month < vStartingMonth - OR month > vEndingMonth; + WHERE `month` < vStartingMonth + OR `month` > vEndingMonth; -- Ahora el balance EXECUTE IMMEDIATE CONCAT( @@ -130,8 +133,8 @@ BEGIN JOIN (SELECT id, name FROM expense GROUP BY id) g ON g.id = bnt.expenseFk COLLATE utf8_general_ci - SET b.expenseFk = g.id COLLATE utf8_general_ci - , b.expenseName = g.id COLLATE utf8_general_ci ; + SET b.expenseFk = g.id COLLATE utf8_general_ci, + b.expenseName = g.id COLLATE utf8_general_ci ; -- Rellenamos los valores de primer nivel, los que corresponden a los gastos simples WHILE vYears >= 0 DO @@ -208,8 +211,7 @@ BEGIN SELECT *, CONCAT('',IFNULL(expenseFk,'')) newgasto FROM tmp.balance; - DROP TEMPORARY TABLE IF EXISTS tCompanyReceiving; - DROP TEMPORARY TABLE IF EXISTS tCompanyIssuing; + DROP TEMPORARY TABLE IF EXISTS tCompanyReceiving, tCompanyIssuing; END$$ DELIMITER ; \ No newline at end of file diff --git a/db/versions/10859-pinkGerbera/00-firstScript.sql b/db/versions/10859-pinkGerbera/00-firstScript.sql index 8fcadf605..a4683d93a 100644 --- a/db/versions/10859-pinkGerbera/00-firstScript.sql +++ b/db/versions/10859-pinkGerbera/00-firstScript.sql @@ -2,14 +2,8 @@ CREATE OR REPLACE PROCEDURE `vn`.`balance_create`() BEGIN END; CREATE OR REPLACE PROCEDURE `vn`.`buy_recalcPricesByEntry`() BEGIN END; CREATE OR REPLACE PROCEDURE `vn`.`buy_recalcPricesByBuy`() BEGIN END; -GRANT EXECUTE ON PROCEDURE vn.balance_create TO `financialBoss`; -GRANT EXECUTE ON PROCEDURE vn.balance_create TO `hrBoss`; +GRANT EXECUTE ON PROCEDURE vn.balance_create TO `financialBoss`, `hrBoss`; -GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByEntry TO `buyer`; -GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByEntry TO `claimManager`; -GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByEntry TO `employee`; +GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByEntry TO `buyer`, `claimManager`, `employee`; -GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByBuy TO `buyer`; -GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByBuy TO `entryEditor`; -GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByBuy TO `claimManager`; -GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByBuy TO `employee`; \ No newline at end of file +GRANT EXECUTE ON PROCEDURE vn.buy_recalcPricesByBuy TO `buyer`, `entryEditor`, `claimManager`, `employee`; \ No newline at end of file