refs #6493 refactorizar-procedimientos-vn2008-parte_2 #2235
|
@ -22,7 +22,6 @@ proc: BEGIN
|
|||
|
||||
CALL item_getStock (vWarehouseLanding, vDated, NULL);
|
||||
|
||||
jbreso marked this conversation as resolved
|
||||
|
||||
-- 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
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
No utilizar hacer uso de TIMESTAMP(ir.dated + INTERVAL it.life DAY, '23:59:59') , tenemos una función que hace eso util.dayEnd No utilizar hacer uso de TIMESTAMP(ir.dated + INTERVAL it.life DAY, '23:59:59') , tenemos una función que hace eso util.dayEnd
|
||||
FROM tItemRange ir
|
||||
jbreso marked this conversation as resolved
carlosap
commented
TIMESTAMPADD substituir por INTERVAL TIMESTAMPADD substituir por INTERVAL
|
||||
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
|
||||
jbreso marked this conversation as resolved
Outdated
guillermo
commented
Sobrepasa los carácteres máximos x linea, tabular Sobrepasa los carácteres máximos x linea, tabular
|
||||
FROM vn.itemTicketOut i
|
||||
JOIN tItemRangeLive ir ON ir.itemFK = i.item_id
|
||||
FROM itemTicketOut i
|
||||
JOIN tItemRangeLive ir ON ir.itemFK = i.itemFk
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
eliminar esquema vn, no es necesario eliminar esquema vn, no es necesario
|
||||
WHERE i.shipped >= vDatedFrom
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
porque se ha cambiado a item_id? porque se ha cambiado a item_id?
|
||||
AND (ir.dated IS NULL OR i.shipped <= ir.dated)
|
||||
jbreso marked this conversation as resolved
Outdated
guillermo
commented
Tab Tab
|
||||
AND i.warehouseFk = vWarehouseLanding
|
||||
|
@ -92,7 +91,7 @@ proc: BEGIN
|
|||
AND (ir.dated IS NULL OR t.landed <= ir.dated)
|
||||
UNION ALL
|
||||
jbreso marked this conversation as resolved
Outdated
guillermo
commented
Tab Tab
|
||||
SELECT i.itemFk, vWarehouseLanding, i.shipped, i.quantity
|
||||
FROM vn.itemEntryOut i
|
||||
FROM itemEntryOut i
|
||||
JOIN tItemRangeLive ir ON ir.itemFk = i.itemFk
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
eliminar esquema innecesario eliminar esquema innecesario
|
||||
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 companyId
|
||||
SELECT id companyFk
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
companyFk 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.*
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
NOT NOT
|
||||
FROM tCompanyIssuing ci
|
||||
JOIN company e on e.id = ci.companyId
|
||||
JOIN company e on e.id = ci.companyFk
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
companyFk companyFk
carlosap
commented
'*' no es necesario '*' no es necesario
|
||||
WHERE e.companyGroupFk = vConsolidatedGroup;
|
||||
|
||||
END IF;
|
||||
|
||||
-- Se calculan las facturas que intervienen, para luego poder servir el desglose desde aqui
|
||||
jbreso marked this conversation as resolved
guillermo
commented
Sobrepasa los caracteres máximos x linea Sobrepasa los caracteres máximos x linea
|
||||
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
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
companyFk companyFk
|
||||
JOIN tCompanyIssuing ci ON ci.companyFk = r.supplierFk
|
||||
WHERE COALESCE(r.bookEntried, r.booked, r.issued) >= vStartingDate
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
utilizar en este casi COALESCE utilizar en este casi COALESCE
|
||||
AND r.isBooked
|
||||
GROUP BY expenseFk, year, month, ci.companyId, cr.companyId;
|
||||
GROUP BY expenseFk, year, month, ci.companyFk, cr.companyFk;
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
companyFk 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
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
ON en mayúsculas ON en mayúsculas
el JOIN está mal em.companyFk = em.companyFk enlazará todos los registros
|
||||
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');
|
||||
jbreso marked this conversation as resolved
Outdated
guillermo
commented
(Tab) GROUP BY b1.id) (Tab) GROUP BY b1.id)
sub ON sub.id = b.id
|
||||
|
||||
SELECT *, CONCAT('',ifnull(expenseFk,'')) newgasto
|
||||
SELECT *, CONCAT('',IFNULL(expenseFk,'')) newgasto
|
||||
jbreso marked this conversation as resolved
Outdated
carlosap
commented
funciones en mayúsculas funciones en mayúsculas
|
||||
FROM tmp.balance;
|
||||
|
||||
DROP TEMPORARY TABLE IF EXISTS tCompanyReceiving;
|
||||
jbreso marked this conversation as resolved
Outdated
guillermo
commented
Utilizar un solo DROP para dropear las 2 tablas. Utilizar un solo DROP para dropear las 2 tablas.
|
||||
|
|
Loading…
Reference in New Issue
Salto de línea innecesario