diff --git a/db/routines/vn/procedures/balance_create.sql b/db/routines/vn/procedures/balance_create.sql index 9fb8b614c..a3f498661 100644 --- a/db/routines/vn/procedures/balance_create.sql +++ b/db/routines/vn/procedures/balance_create.sql @@ -6,6 +6,15 @@ CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`balance_create`( IN vIsConsolidated BOOLEAN, IN vInterGroupSalesIncluded BOOLEAN) BEGIN +/** + * 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 + */ DECLARE intGAP INT DEFAULT 7; DECLARE vYears INT DEFAULT 2; DECLARE vYear TEXT; @@ -71,8 +80,8 @@ BEGIN CREATE OR REPLACE TEMPORARY TABLE tmp.balanceDetail SELECT cr.companyId receivingId, ci.companyId issuingId, - year(IFNULL(r.bookEntried,IFNULL(r.booked, r.issued))) `year`, - month(IFNULL(r.bookEntried,IFNULL(r.booked, r.issued))) `month`, + YEAR(IFNULL(r.bookEntried,IFNULL(r.booked, r.issued))) `year`, + MONTH(IFNULL(r.bookEntried,IFNULL(r.booked, r.issued))) `month`, expenseFk, SUM(taxableBase) amount FROM invoiceIn r @@ -129,7 +138,7 @@ BEGIN SET vQuery = CONCAT( 'UPDATE tmp.balance b JOIN - (SELECT expenseFk, SUM(amount) as amount + (SELECT expenseFk, SUM(amount) FROM tmp.balanceDetail WHERE year = ? GROUP BY expenseFk @@ -151,7 +160,7 @@ BEGIN SUM(IF(year = ?, venta, 0)) y0, c.Gasto FROM bs.ventas_contables c - JOIN tCompanyReceiving cr on cr.companyId = c.empresa_id + JOIN tCompanyReceiving cr ON cr.companyId = c.empresa_id WHERE month BETWEEN ? AND ? GROUP BY c.Gasto ) sub ON sub.gasto = b.expenseFk COLLATE utf8_general_ci