feat: refs#6493 modificaciones solicitadas.

This commit is contained in:
Juanjo Breso 2024-04-05 12:58:31 +02:00
parent 4767b98442
commit c74aea74bc
2 changed files with 18 additions and 19 deletions

View File

@ -22,7 +22,6 @@ proc: BEGIN
CALL item_getStock (vWarehouseLanding, vDated, NULL);
-- Calcula algunos parámetros necesarios
SET vDatedFrom = TIMESTAMP(vDated, '00:00:00');
SET vDatedTo = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDated), '23:59:59');
@ -62,7 +61,7 @@ proc: BEGIN
CREATE OR REPLACE TEMPORARY TABLE tItemRangeLive
(PRIMARY KEY (itemFk))
ENGINE = MEMORY
SELECT ir.itemFk, TIMESTAMP(TIMESTAMPADD(DAY, it.life, ir.dated), '23:59:59') dated
SELECT ir.itemFk, TIMESTAMP(ir.dated + INTERVAL it.life DAY, '23:59:59') dated
FROM tItemRange ir
JOIN item i ON i.id = ir.itemFk
JOIN itemType it ON it.id = i.typeFk
@ -73,8 +72,8 @@ proc: BEGIN
(INDEX (itemFk,warehouseFk))
ENGINE = MEMORY
SELECT i.itemFk, vWarehouseLanding warehouseFk, i.shipped dated, i.quantity
FROM vn.itemTicketOut i
JOIN tItemRangeLive ir ON ir.itemFK = i.item_id
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
@ -92,7 +91,7 @@ proc: BEGIN
AND (ir.dated IS NULL OR t.landed <= ir.dated)
UNION ALL
SELECT i.itemFk, vWarehouseLanding, i.shipped, i.quantity
FROM vn.itemEntryOut i
FROM itemEntryOut i
JOIN tItemRangeLive ir ON ir.itemFk = i.itemFk
WHERE i.shipped >= vDatedFrom
AND (ir.dated IS NULL OR i.shipped <= ir.dated)

View File

@ -58,39 +58,39 @@ BEGIN
WHERE id = vCompany;
CREATE OR REPLACE TEMPORARY TABLE tCompanyReceiving
SELECT id companyId
SELECT id companyFk
FROM company
WHERE id = vCompany
OR companyGroupFk = IF(vIsConsolidated, vConsolidatedGroup, NULL);
CREATE OR REPLACE TEMPORARY TABLE tCompanyIssuing
SELECT id companyId
SELECT id companyFk
FROM supplier p;
IF vInterGroupSalesIncluded = FALSE THEN
DELETE ci.*
FROM tCompanyIssuing ci
JOIN company e on e.id = ci.companyId
JOIN company e on e.id = ci.companyFk
WHERE e.companyGroupFk = vConsolidatedGroup;
END IF;
-- Se calculan las facturas que intervienen, para luego poder servir el desglose desde aqui
CREATE OR REPLACE TEMPORARY TABLE tmp.balanceDetail
SELECT cr.companyId receivingId,
ci.companyId issuingId,
SELECT cr.companyFk receivingId,
ci.companyFk issuingId,
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
JOIN invoiceInTax ri on ri.invoiceInFk = r.id
JOIN tCompanyReceiving cr on cr.companyId = r.companyFk
JOIN tCompanyIssuing ci ON ci.companyId = r.supplierFk
WHERE IFNULL(r.bookEntried,IFNULL(r.booked, r.issued)) >= vStartingDate
JOIN tCompanyReceiving cr on cr.companyFk = r.companyFk
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.companyId, cr.companyId;
GROUP BY expenseFk, year, month, ci.companyFk, cr.companyFk;
INSERT INTO tmp.balanceDetail(
receivingId,
@ -104,9 +104,9 @@ BEGIN
year,
month,
expenseFk,
SUM(amount)
SUM(em.amount)
FROM expenseManual em
JOIN tCompanyReceiving er on em.companyFk = em.companyFk
JOIN tCompanyReceiving er ON er.companyFk = em.companyFk
WHERE year >= vStartingYear
AND month BETWEEN vStartingMonth AND vEndingMonth
GROUP BY expenseFk, year, month, em.companyFk;
@ -138,7 +138,7 @@ BEGIN
SET vQuery = CONCAT(
'UPDATE tmp.balance b
JOIN
(SELECT expenseFk, SUM(amount)
(SELECT expenseFk, SUM(amount) amount
FROM tmp.balanceDetail
WHERE year = ?
GROUP BY expenseFk
@ -160,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.companyFk = c.empresa_id
WHERE month BETWEEN ? AND ?
GROUP BY c.Gasto
) sub ON sub.gasto = b.expenseFk COLLATE utf8_general_ci
@ -205,7 +205,7 @@ BEGIN
b.', vOneYearAgo, ' = oneYearAgo,
b.', vTwoYearsAgo, ' = twoYearsAgo');
SELECT *, CONCAT('',ifnull(expenseFk,'')) newgasto
SELECT *, CONCAT('',IFNULL(expenseFk,'')) newgasto
FROM tmp.balance;
DROP TEMPORARY TABLE IF EXISTS tCompanyReceiving;