refactor: refs #5586 Optimized SQL negativeBases #2007

Merged
guillermo merged 12 commits from 5586-optimizeNegativeBases into dev 2024-02-20 06:28:05 +00:00
1 changed files with 5 additions and 23 deletions
Showing only changes of commit bdc6192a7c - Show all commits

View File

@ -46,15 +46,6 @@ module.exports = Self => {
const stmts = [];
let stmt;
stmts.push(new ParameterizedSQL(
`CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
(KEY (ticketFk))
ENGINE = MEMORY
SELECT id ticketFk
FROM ticket t
WHERE shipped BETWEEN ? AND util.dayEnd(?)
AND refFk IS NULL`, [args.from, args.to]));
stmts.push(`CALL vn.ticket_getTax(NULL)`);
stmts.push(new ParameterizedSQL(
`CREATE OR REPLACE TEMPORARY TABLE tmp.filter

si lleves esta cridà funciona igual? a mes ha canviat nom de taules de tickte a filter..

si lleves esta cridà funciona igual? a mes ha canviat nom de taules de tickte a filter..

Sí, he respetat el alias taxableBase, falta que arregle els test de back que he vist que fallen

Sí, he respetat el alias taxableBase, falta que arregle els test de back que he vist que fallen
ENGINE = MEMORY
@ -64,8 +55,8 @@ module.exports = Self => {
c.socialName clientSocialName,
u.nickname workerSocialName,
SUM(s.quantity * s.price * ( 100 - s.discount ) / 100) amount,
negativeBase.taxableBase,
negativeBase.ticketFk,
t.totalWithoutVat taxableBase,
s.ticketFk,
c.isActive,
c.hasToInvoice,
c.isTaxDataChecked,
@ -78,16 +69,10 @@ module.exports = Self => {
JOIN vn.country cou ON cou.id = c.countryFk
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
JOIN account.user u ON u.id = w.id
LEFT JOIN (
SELECT ticketFk, taxableBase
FROM tmp.ticketAmount
GROUP BY ticketFk
HAVING taxableBase < 0
) negativeBase ON negativeBase.ticketFk = t.id
guillermo marked this conversation as resolved Outdated

açò valida que ninguna de les bases imponibles siguen < 0 per separat es a dir si un ticket suma 100 y te una base imponible -20 y laltra 120 es un error, en el teu plantejament mos la colarien

açò valida que ninguna de les bases imponibles siguen < 0 **per separat** es a dir si un ticket suma 100 y te una base imponible -20 y laltra 120 es un error, en el teu plantejament mos la colarien
@carlosap
WHERE t.shipped BETWEEN ? AND ?
WHERE t.shipped BETWEEN ? AND util.dayEnd(?)
AND t.refFk IS NULL
AND c.typeFk IN ('normal','trust')
GROUP BY t.clientFk, negativeBase.taxableBase
GROUP BY t.clientFk, t.totalWithoutVat
HAVING amount < 0`, [args.from, args.to]));
stmt = new ParameterizedSQL(`SELECT * FROM tmp.filter`);
@ -100,10 +85,7 @@ module.exports = Self => {
const negativeBasesIndex = stmts.push(stmt) - 1;
guillermo marked this conversation as resolved
Review

posar una funcio en el where pot fer que no puga indexar, revisa be que vaja rapid

posar una funcio en el where pot fer que no puga indexar, revisa be que vaja rapid
Review

Funciona mes rapid que antes.

Funciona mes rapid que antes.
stmts.push(`DROP TEMPORARY TABLE tmp.filter,
tmp.ticket,
tmp.ticketTax,
tmp.ticketAmount`);
stmts.push(`DROP TEMPORARY TABLE tmp.filter`);
const sql = ParameterizedSQL.join(stmts, ';');
guillermo marked this conversation as resolved Outdated

un ticket que tinga 2 bases imponibles ha de tindre dos linies, amb este group by ho fusiona en una..

un ticket que tinga 2 bases imponibles ha de tindre dos linies, amb este group by ho fusiona en una..
const result = await conn.executeStmt(sql);