feat: refs#6493 modificaciones solicitadas.
This commit is contained in:
parent
4767b98442
commit
c74aea74bc
|
@ -22,7 +22,6 @@ proc: BEGIN
|
||||||
|
|
||||||
CALL item_getStock (vWarehouseLanding, vDated, NULL);
|
CALL item_getStock (vWarehouseLanding, vDated, NULL);
|
||||||
|
|
||||||
|
|
||||||
-- Calcula algunos parámetros necesarios
|
-- Calcula algunos parámetros necesarios
|
||||||
SET vDatedFrom = TIMESTAMP(vDated, '00:00:00');
|
SET vDatedFrom = TIMESTAMP(vDated, '00:00:00');
|
||||||
SET vDatedTo = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDated), '23:59:59');
|
SET vDatedTo = TIMESTAMP(TIMESTAMPADD(DAY, 4, vDated), '23:59:59');
|
||||||
|
@ -62,7 +61,7 @@ proc: BEGIN
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tItemRangeLive
|
CREATE OR REPLACE TEMPORARY TABLE tItemRangeLive
|
||||||
(PRIMARY KEY (itemFk))
|
(PRIMARY KEY (itemFk))
|
||||||
ENGINE = MEMORY
|
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
|
FROM tItemRange ir
|
||||||
JOIN item i ON i.id = ir.itemFk
|
JOIN item i ON i.id = ir.itemFk
|
||||||
JOIN itemType it ON it.id = i.typeFk
|
JOIN itemType it ON it.id = i.typeFk
|
||||||
|
@ -73,8 +72,8 @@ proc: BEGIN
|
||||||
(INDEX (itemFk,warehouseFk))
|
(INDEX (itemFk,warehouseFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT i.itemFk, vWarehouseLanding warehouseFk, i.shipped dated, i.quantity
|
SELECT i.itemFk, vWarehouseLanding warehouseFk, i.shipped dated, i.quantity
|
||||||
FROM vn.itemTicketOut i
|
FROM itemTicketOut i
|
||||||
JOIN tItemRangeLive ir ON ir.itemFK = i.item_id
|
JOIN tItemRangeLive ir ON ir.itemFK = i.itemFk
|
||||||
WHERE i.shipped >= vDatedFrom
|
WHERE i.shipped >= vDatedFrom
|
||||||
AND (ir.dated IS NULL OR i.shipped <= ir.dated)
|
AND (ir.dated IS NULL OR i.shipped <= ir.dated)
|
||||||
AND i.warehouseFk = vWarehouseLanding
|
AND i.warehouseFk = vWarehouseLanding
|
||||||
|
@ -92,7 +91,7 @@ proc: BEGIN
|
||||||
AND (ir.dated IS NULL OR t.landed <= ir.dated)
|
AND (ir.dated IS NULL OR t.landed <= ir.dated)
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT i.itemFk, vWarehouseLanding, i.shipped, i.quantity
|
SELECT i.itemFk, vWarehouseLanding, i.shipped, i.quantity
|
||||||
FROM vn.itemEntryOut i
|
FROM itemEntryOut i
|
||||||
JOIN tItemRangeLive ir ON ir.itemFk = i.itemFk
|
JOIN tItemRangeLive ir ON ir.itemFk = i.itemFk
|
||||||
WHERE i.shipped >= vDatedFrom
|
WHERE i.shipped >= vDatedFrom
|
||||||
AND (ir.dated IS NULL OR i.shipped <= ir.dated)
|
AND (ir.dated IS NULL OR i.shipped <= ir.dated)
|
||||||
|
|
|
@ -58,39 +58,39 @@ BEGIN
|
||||||
WHERE id = vCompany;
|
WHERE id = vCompany;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tCompanyReceiving
|
CREATE OR REPLACE TEMPORARY TABLE tCompanyReceiving
|
||||||
SELECT id companyId
|
SELECT id companyFk
|
||||||
FROM company
|
FROM company
|
||||||
WHERE id = vCompany
|
WHERE id = vCompany
|
||||||
OR companyGroupFk = IF(vIsConsolidated, vConsolidatedGroup, NULL);
|
OR companyGroupFk = IF(vIsConsolidated, vConsolidatedGroup, NULL);
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tCompanyIssuing
|
CREATE OR REPLACE TEMPORARY TABLE tCompanyIssuing
|
||||||
SELECT id companyId
|
SELECT id companyFk
|
||||||
FROM supplier p;
|
FROM supplier p;
|
||||||
|
|
||||||
IF vInterGroupSalesIncluded = FALSE THEN
|
IF vInterGroupSalesIncluded = FALSE THEN
|
||||||
|
|
||||||
DELETE ci.*
|
DELETE ci.*
|
||||||
FROM tCompanyIssuing ci
|
FROM tCompanyIssuing ci
|
||||||
JOIN company e on e.id = ci.companyId
|
JOIN company e on e.id = ci.companyFk
|
||||||
WHERE e.companyGroupFk = vConsolidatedGroup;
|
WHERE e.companyGroupFk = vConsolidatedGroup;
|
||||||
|
|
||||||
END IF;
|
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
|
CREATE OR REPLACE TEMPORARY TABLE tmp.balanceDetail
|
||||||
SELECT cr.companyId receivingId,
|
SELECT cr.companyFk receivingId,
|
||||||
ci.companyId issuingId,
|
ci.companyFk issuingId,
|
||||||
YEAR(IFNULL(r.bookEntried,IFNULL(r.booked, r.issued))) `year`,
|
YEAR(IFNULL(r.bookEntried,IFNULL(r.booked, r.issued))) `year`,
|
||||||
MONTH(IFNULL(r.bookEntried,IFNULL(r.booked, r.issued))) `month`,
|
MONTH(IFNULL(r.bookEntried,IFNULL(r.booked, r.issued))) `month`,
|
||||||
expenseFk,
|
expenseFk,
|
||||||
SUM(taxableBase) amount
|
SUM(taxableBase) amount
|
||||||
FROM invoiceIn r
|
FROM invoiceIn r
|
||||||
JOIN invoiceInTax ri on ri.invoiceInFk = r.id
|
JOIN invoiceInTax ri on ri.invoiceInFk = r.id
|
||||||
JOIN tCompanyReceiving cr on cr.companyId = r.companyFk
|
JOIN tCompanyReceiving cr on cr.companyFk = r.companyFk
|
||||||
JOIN tCompanyIssuing ci ON ci.companyId = r.supplierFk
|
JOIN tCompanyIssuing ci ON ci.companyFk = r.supplierFk
|
||||||
WHERE IFNULL(r.bookEntried,IFNULL(r.booked, r.issued)) >= vStartingDate
|
WHERE COALESCE(r.bookEntried, r.booked, r.issued) >= vStartingDate
|
||||||
AND r.isBooked
|
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(
|
INSERT INTO tmp.balanceDetail(
|
||||||
receivingId,
|
receivingId,
|
||||||
|
@ -104,9 +104,9 @@ BEGIN
|
||||||
year,
|
year,
|
||||||
month,
|
month,
|
||||||
expenseFk,
|
expenseFk,
|
||||||
SUM(amount)
|
SUM(em.amount)
|
||||||
FROM expenseManual em
|
FROM expenseManual em
|
||||||
JOIN tCompanyReceiving er on em.companyFk = em.companyFk
|
JOIN tCompanyReceiving er ON er.companyFk = em.companyFk
|
||||||
WHERE year >= vStartingYear
|
WHERE year >= vStartingYear
|
||||||
AND month BETWEEN vStartingMonth AND vEndingMonth
|
AND month BETWEEN vStartingMonth AND vEndingMonth
|
||||||
GROUP BY expenseFk, year, month, em.companyFk;
|
GROUP BY expenseFk, year, month, em.companyFk;
|
||||||
|
@ -138,7 +138,7 @@ BEGIN
|
||||||
SET vQuery = CONCAT(
|
SET vQuery = CONCAT(
|
||||||
'UPDATE tmp.balance b
|
'UPDATE tmp.balance b
|
||||||
JOIN
|
JOIN
|
||||||
(SELECT expenseFk, SUM(amount)
|
(SELECT expenseFk, SUM(amount) amount
|
||||||
FROM tmp.balanceDetail
|
FROM tmp.balanceDetail
|
||||||
WHERE year = ?
|
WHERE year = ?
|
||||||
GROUP BY expenseFk
|
GROUP BY expenseFk
|
||||||
|
@ -160,7 +160,7 @@ BEGIN
|
||||||
SUM(IF(year = ?, venta, 0)) y0,
|
SUM(IF(year = ?, venta, 0)) y0,
|
||||||
c.Gasto
|
c.Gasto
|
||||||
FROM bs.ventas_contables c
|
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 ?
|
WHERE month BETWEEN ? AND ?
|
||||||
GROUP BY c.Gasto
|
GROUP BY c.Gasto
|
||||||
) sub ON sub.gasto = b.expenseFk COLLATE utf8_general_ci
|
) sub ON sub.gasto = b.expenseFk COLLATE utf8_general_ci
|
||||||
|
@ -205,7 +205,7 @@ BEGIN
|
||||||
b.', vOneYearAgo, ' = oneYearAgo,
|
b.', vOneYearAgo, ' = oneYearAgo,
|
||||||
b.', vTwoYearsAgo, ' = twoYearsAgo');
|
b.', vTwoYearsAgo, ' = twoYearsAgo');
|
||||||
|
|
||||||
SELECT *, CONCAT('',ifnull(expenseFk,'')) newgasto
|
SELECT *, CONCAT('',IFNULL(expenseFk,'')) newgasto
|
||||||
FROM tmp.balance;
|
FROM tmp.balance;
|
||||||
|
|
||||||
DROP TEMPORARY TABLE IF EXISTS tCompanyReceiving;
|
DROP TEMPORARY TABLE IF EXISTS tCompanyReceiving;
|
||||||
|
|
Loading…
Reference in New Issue