fix: refs #7906 remake method #3109
|
@ -1,5 +1,7 @@
|
|||
DELIMITER $$
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getTax`(IN vTaxArea VARCHAR(25))
|
||||
CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`ticket_getTax`(
|
||||
vTaxArea VARCHAR(25)
|
||||
)
|
||||
BEGIN
|
||||
/**
|
||||
* Calcula la base imponible, el IVA y el recargo de equivalencia para
|
||||
|
@ -33,30 +35,39 @@ BEGIN
|
|||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketTax
|
||||
(PRIMARY KEY (ticketFk, code, rate))
|
||||
ENGINE = MEMORY
|
||||
SELECT * FROM (
|
||||
SELECT tmpTicket.ticketFk,
|
||||
WITH sales AS (
|
||||
SELECT s.ticketFk,
|
||||
s.itemFk,
|
||||
s.quantity * s.price * (100 - s.discount) / 100 total,
|
||||
t.companyFk,
|
||||
t.addressFk,
|
||||
su.countryFk,
|
||||
ata.areaFk,
|
||||
itc.taxClassFk
|
||||
FROM vn.sale s
|
||||
JOIN tmp.ticket tmp ON tmp.ticketFk = s.ticketFk
|
||||
JOIN vn.ticket t ON t.id = s.ticketFk
|
||||
JOIN vn.supplier su ON su.id = t.companyFk
|
||||
JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk
|
||||
AND ata.companyFk = t.companyFk
|
||||
JOIN vn.itemTaxCountry itc ON itc.itemFk = s.itemFk
|
||||
AND itc.countryFk = su.countryFk
|
||||
HAVING total
|
||||
)
|
||||
SELECT s.ticketFk,
|
||||
bp.pgcFk,
|
||||
SUM(s.quantity * s.price * (100 - s.discount) / 100 ) taxableBase,
|
||||
SUM(s.total) taxableBase,
|
||||
pgc.rate,
|
||||
tc.code,
|
||||
bp.priority
|
||||
FROM tmp.ticket tmpTicket
|
||||
JOIN sale s ON s.ticketFk = tmpTicket.ticketFk
|
||||
JOIN item i ON i.id = s.itemFk
|
||||
JOIN ticket t ON t.id = tmpTicket.ticketFk
|
||||
JOIN supplier su ON su.id = t.companyFk
|
||||
JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk
|
||||
AND ata.companyFk = t.companyFk
|
||||
JOIN itemTaxCountry itc ON itc.itemFk = i.id
|
||||
AND itc.countryFk = su.countryFk
|
||||
JOIN bookingPlanner bp ON bp.countryFk = su.countryFk
|
||||
AND bp.taxAreaFk = ata.areaFk
|
||||
AND bp.taxClassFk = itc.taxClassFk
|
||||
JOIN pgc ON pgc.code = bp.pgcFk
|
||||
JOIN taxClass tc ON tc.id = bp.taxClassFk
|
||||
GROUP BY tmpTicket.ticketFk, pgc.code, pgc.rate
|
||||
FROM sales s
|
||||
JOIN vn.bookingPlanner bp ON bp.countryFk = s.countryFk
|
||||
AND bp.taxAreaFk = s.areaFk
|
||||
AND bp.taxClassFk = s.taxClassFk
|
||||
JOIN vn.pgc ON pgc.code = bp.pgcFk
|
||||
JOIN vn.taxClass tc ON tc.id = bp.taxClassFk
|
||||
GROUP BY s.ticketFk, pgc.code, pgc.rate
|
||||
HAVING taxableBase
|
||||
) t3
|
||||
ORDER BY priority;
|
||||
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketServiceTax
|
||||
|
|
|
@ -48,13 +48,13 @@ module.exports = Self => {
|
|||
let stmt;
|
||||
stmts.push(new ParameterizedSQL(
|
||||
`CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||
(KEY (ticketFk))
|
||||
(INDEX (ticketFk))
|
||||
ENGINE = MEMORY
|
||||
SELECT id ticketFk
|
||||
FROM ticket t
|
||||
FROM ticket
|
||||
WHERE shipped BETWEEN ? AND util.dayEnd(?)
|
||||
AND refFk IS NULL`, [args.from, args.to]));
|
||||
stmts.push(`CALL vn.ticket_getTax(NULL)`);
|
||||
stmts.push(`CALL ticket_getTax(NULL)`);
|
||||
stmts.push(new ParameterizedSQL(
|
||||
`CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||
ENGINE = MEMORY
|
||||
|
@ -71,12 +71,12 @@ module.exports = Self => {
|
|||
c.isTaxDataChecked,
|
||||
w.id comercialId,
|
||||
u.name workerName
|
||||
FROM vn.ticket t
|
||||
JOIN vn.company co ON co.id = t.companyFk
|
||||
JOIN vn.sale s ON s.ticketFk = t.id
|
||||
JOIN vn.client c ON c.id = t.clientFk
|
||||
JOIN vn.country cou ON cou.id = c.countryFk
|
||||
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
||||
FROM ticket t
|
||||
JOIN company co ON co.id = t.companyFk
|
||||
JOIN sale s ON s.ticketFk = t.id
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN country cou ON cou.id = c.countryFk
|
||||
LEFT JOIN worker w ON w.id = c.salesPersonFk
|
||||
JOIN account.user u ON u.id = w.id
|
||||
LEFT JOIN (
|
||||
SELECT ticketFk, taxableBase
|
||||
|
|
|
@ -228,7 +228,7 @@ module.exports = Self => {
|
|||
stmt = new ParameterizedSQL(`
|
||||
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||
(INDEX (id))
|
||||
ENGINE = MEMORY
|
||||
ENGINE = InnoDB
|
||||
SELECT t.id,
|
||||
t.shipped,
|
||||
CAST(DATE(t.shipped) AS CHAR) shippedDate,
|
||||
|
@ -260,7 +260,12 @@ module.exports = Self => {
|
|||
z.name zoneName,
|
||||
z.id zoneFk,
|
||||
CAST(z.hour AS CHAR) hour,
|
||||
a.nickname addressNickname
|
||||
a.nickname addressNickname,
|
||||
(SELECT GROUP_CONCAT(DISTINCT i2.itemPackingTypeFk ORDER BY i2.itemPackingTypeFk SEPARATOR ',')
|
||||
FROM sale s2
|
||||
JOIN item i2 ON i2.id = s2.itemFk
|
||||
WHERE s2.ticketFk = t.id
|
||||
) AS packing
|
||||
FROM ticket t
|
||||
LEFT JOIN invoiceOut io ON t.refFk = io.ref
|
||||
LEFT JOIN zone z ON z.id = t.zoneFk
|
||||
|
@ -292,6 +297,7 @@ module.exports = Self => {
|
|||
}
|
||||
|
||||
stmt.merge(conn.makeWhere(filter.where));
|
||||
|
||||
stmts.push(stmt);
|
||||
|
||||
stmt = new ParameterizedSQL(`
|
||||
|
|
Loading…
Reference in New Issue