refs #6493 refactorizar-procedimientos-vn2008-parte_2 #2235

Merged
jbreso merged 39 commits from 6493-refactorizar-procedimientos-vn2008-parte_2 into dev 2024-04-24 05:18:59 +00:00
2 changed files with 18 additions and 19 deletions
Showing only changes of commit c74aea74bc - Show all commits

View File

@ -22,7 +22,6 @@ proc: BEGIN
CALL item_getStock (vWarehouseLanding, vDated, NULL); CALL item_getStock (vWarehouseLanding, vDated, NULL);
jbreso marked this conversation as resolved
Review

Salto de línea innecesario

Salto de línea innecesario
-- 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
jbreso marked this conversation as resolved Outdated

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 FROM tItemRange ir
jbreso marked this conversation as resolved
Review

TIMESTAMPADD substituir por INTERVAL

TIMESTAMPADD substituir por INTERVAL
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
jbreso marked this conversation as resolved Outdated

Sobrepasa los carácteres máximos x linea, tabular

Sobrepasa los carácteres máximos x linea, tabular
FROM vn.itemTicketOut i FROM itemTicketOut i
JOIN tItemRangeLive ir ON ir.itemFK = i.item_id JOIN tItemRangeLive ir ON ir.itemFK = i.itemFk
jbreso marked this conversation as resolved Outdated

eliminar esquema vn, no es necesario

eliminar esquema vn, no es necesario
WHERE i.shipped >= vDatedFrom WHERE i.shipped >= vDatedFrom
jbreso marked this conversation as resolved Outdated

porque se ha cambiado a item_id?

porque se ha cambiado a item_id?
AND (ir.dated IS NULL OR i.shipped <= ir.dated) AND (ir.dated IS NULL OR i.shipped <= ir.dated)
jbreso marked this conversation as resolved Outdated

Tab

Tab
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
jbreso marked this conversation as resolved Outdated

Tab

Tab
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
jbreso marked this conversation as resolved Outdated

eliminar esquema innecesario

eliminar esquema innecesario
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)

View File

@ -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
jbreso marked this conversation as resolved Outdated

companyFk

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.*
jbreso marked this conversation as resolved Outdated

NOT

NOT
FROM tCompanyIssuing ci 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

companyFk

companyFk

'*' no es necesario

'*' no es necesario
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
jbreso marked this conversation as resolved
Review

Sobrepasa los caracteres máximos x linea

Sobrepasa los caracteres máximos x linea
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
jbreso marked this conversation as resolved Outdated

companyFk

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
jbreso marked this conversation as resolved Outdated

utilizar en este casi COALESCE

utilizar en este casi COALESCE
AND r.isBooked 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

companyFk

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
jbreso marked this conversation as resolved Outdated

ON en mayúsculas
el JOIN está mal em.companyFk = em.companyFk enlazará todos los registros

ON en mayúsculas el JOIN está mal em.companyFk = em.companyFk enlazará todos los registros
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');
jbreso marked this conversation as resolved Outdated

(Tab) GROUP BY b1.id)
sub ON sub.id = b.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

funciones en mayúsculas

funciones en mayúsculas
FROM tmp.balance; FROM tmp.balance;
DROP TEMPORARY TABLE IF EXISTS tCompanyReceiving; DROP TEMPORARY TABLE IF EXISTS tCompanyReceiving;
jbreso marked this conversation as resolved Outdated

Utilizar un solo DROP para dropear las 2 tablas.

Utilizar un solo DROP para dropear las 2 tablas.