refactor: refs #5586 Optimized SQL negativeBases #2007
|
@ -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
|
||||
|
||||
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
jgallego
commented
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
guillermo
commented
@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
jgallego
commented
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
guillermo
commented
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
jgallego
commented
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);
|
||||
|
|
Loading…
Reference in New Issue
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