refs #6915 test_master24_8 #2067
|
@ -46,15 +46,6 @@ module.exports = Self => {
|
||||||
|
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
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(
|
stmts.push(new ParameterizedSQL(
|
||||||
`CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
`CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
|
@ -64,8 +55,8 @@ module.exports = Self => {
|
||||||
c.socialName clientSocialName,
|
c.socialName clientSocialName,
|
||||||
u.nickname workerSocialName,
|
u.nickname workerSocialName,
|
||||||
SUM(s.quantity * s.price * ( 100 - s.discount ) / 100) amount,
|
SUM(s.quantity * s.price * ( 100 - s.discount ) / 100) amount,
|
||||||
negativeBase.taxableBase,
|
t.totalWithoutVat taxableBase,
|
||||||
negativeBase.ticketFk,
|
s.ticketFk,
|
||||||
c.isActive,
|
c.isActive,
|
||||||
c.hasToInvoice,
|
c.hasToInvoice,
|
||||||
c.isTaxDataChecked,
|
c.isTaxDataChecked,
|
||||||
|
@ -78,16 +69,10 @@ module.exports = Self => {
|
||||||
JOIN vn.country cou ON cou.id = c.countryFk
|
JOIN vn.country cou ON cou.id = c.countryFk
|
||||||
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
||||||
JOIN account.user u ON u.id = w.id
|
JOIN account.user u ON u.id = w.id
|
||||||
LEFT JOIN (
|
WHERE t.shipped BETWEEN ? AND util.dayEnd(?)
|
||||||
SELECT ticketFk, taxableBase
|
|
||||||
FROM tmp.ticketAmount
|
|
||||||
GROUP BY ticketFk
|
|
||||||
HAVING taxableBase < 0
|
|
||||||
) negativeBase ON negativeBase.ticketFk = t.id
|
|
||||||
WHERE t.shipped BETWEEN ? AND ?
|
|
||||||
AND t.refFk IS NULL
|
AND t.refFk IS NULL
|
||||||
AND c.typeFk IN ('normal','trust')
|
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]));
|
HAVING amount < 0`, [args.from, args.to]));
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(`SELECT * FROM tmp.filter`);
|
stmt = new ParameterizedSQL(`SELECT * FROM tmp.filter`);
|
||||||
|
@ -100,10 +85,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
const negativeBasesIndex = stmts.push(stmt) - 1;
|
const negativeBasesIndex = stmts.push(stmt) - 1;
|
||||||
|
|
||||||
stmts.push(`DROP TEMPORARY TABLE tmp.filter,
|
stmts.push(`DROP TEMPORARY TABLE tmp.filter`);
|
||||||
tmp.ticket,
|
|
||||||
tmp.ticketTax,
|
|
||||||
tmp.ticketAmount`);
|
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
const result = await conn.executeStmt(sql);
|
const result = await conn.executeStmt(sql);
|
||||||
|
|
Loading…
Reference in New Issue