Compare commits
No commits in common. "07b45748f0627cd53e9b5d1d933b67993f0edbfa" and "f316ca697405c53b06775a974899b521bd211857" have entirely different histories.
07b45748f0
...
f316ca6974
|
@ -22,6 +22,7 @@ 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');
|
||||
|
@ -61,7 +62,7 @@ proc: BEGIN
|
|||
CREATE OR REPLACE TEMPORARY TABLE tItemRangeLive
|
||||
(PRIMARY KEY (itemFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT ir.itemFk, TIMESTAMP(ir.dated + INTERVAL it.life DAY, '23:59:59') dated
|
||||
SELECT ir.itemFk, TIMESTAMP(TIMESTAMPADD(DAY, it.life, ir.dated), '23:59:59') dated
|
||||
FROM tItemRange ir
|
||||
JOIN item i ON i.id = ir.itemFk
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
|
@ -72,8 +73,8 @@ proc: BEGIN
|
|||
(INDEX (itemFk,warehouseFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT i.itemFk, vWarehouseLanding warehouseFk, i.shipped dated, i.quantity
|
||||
FROM itemTicketOut i
|
||||
JOIN tItemRangeLive ir ON ir.itemFK = i.itemFk
|
||||
FROM vn.itemTicketOut i
|
||||
JOIN tItemRangeLive ir ON ir.itemFK = i.item_id
|
||||
WHERE i.shipped >= vDatedFrom
|
||||
AND (ir.dated IS NULL OR i.shipped <= ir.dated)
|
||||
AND i.warehouseFk = vWarehouseLanding
|
||||
|
@ -91,7 +92,7 @@ proc: BEGIN
|
|||
AND (ir.dated IS NULL OR t.landed <= ir.dated)
|
||||
UNION ALL
|
||||
SELECT i.itemFk, vWarehouseLanding, i.shipped, i.quantity
|
||||
FROM itemEntryOut i
|
||||
FROM vn.itemEntryOut i
|
||||
JOIN tItemRangeLive ir ON ir.itemFk = i.itemFk
|
||||
WHERE i.shipped >= vDatedFrom
|
||||
AND (ir.dated IS NULL OR i.shipped <= ir.dated)
|
||||
|
|
|
@ -58,39 +58,39 @@ BEGIN
|
|||
WHERE id = vCompany;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tCompanyReceiving
|
||||
SELECT id companyFk
|
||||
SELECT id companyId
|
||||
FROM company
|
||||
WHERE id = vCompany
|
||||
OR companyGroupFk = IF(vIsConsolidated, vConsolidatedGroup, NULL);
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tCompanyIssuing
|
||||
SELECT id companyFk
|
||||
SELECT id companyId
|
||||
FROM supplier p;
|
||||
|
||||
IF vInterGroupSalesIncluded = FALSE THEN
|
||||
|
||||
DELETE ci.*
|
||||
FROM tCompanyIssuing ci
|
||||
JOIN company e on e.id = ci.companyFk
|
||||
JOIN company e on e.id = ci.companyId
|
||||
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.companyFk receivingId,
|
||||
ci.companyFk issuingId,
|
||||
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`,
|
||||
expenseFk,
|
||||
SUM(taxableBase) amount
|
||||
FROM invoiceIn r
|
||||
JOIN invoiceInTax ri on ri.invoiceInFk = r.id
|
||||
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
|
||||
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
|
||||
AND r.isBooked
|
||||
GROUP BY expenseFk, year, month, ci.companyFk, cr.companyFk;
|
||||
GROUP BY expenseFk, year, month, ci.companyId, cr.companyId;
|
||||
|
||||
INSERT INTO tmp.balanceDetail(
|
||||
receivingId,
|
||||
|
@ -104,9 +104,9 @@ BEGIN
|
|||
year,
|
||||
month,
|
||||
expenseFk,
|
||||
SUM(em.amount)
|
||||
SUM(amount)
|
||||
FROM expenseManual em
|
||||
JOIN tCompanyReceiving er ON er.companyFk = em.companyFk
|
||||
JOIN tCompanyReceiving er on em.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) amount
|
||||
(SELECT expenseFk, SUM(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.companyFk = 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
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue