Merge branch 'dev' into 7906-notDeleteZone
gitea/salix/pipeline/pr-dev This commit looks good
Details
gitea/salix/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
commit
ed69604767
|
@ -1,5 +1,7 @@
|
||||||
DELIMITER $$
|
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
|
BEGIN
|
||||||
/**
|
/**
|
||||||
* Calcula la base imponible, el IVA y el recargo de equivalencia para
|
* Calcula la base imponible, el IVA y el recargo de equivalencia para
|
||||||
|
@ -33,30 +35,39 @@ BEGIN
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketTax
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketTax
|
||||||
(PRIMARY KEY (ticketFk, code, rate))
|
(PRIMARY KEY (ticketFk, code, rate))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT * FROM (
|
WITH sales AS (
|
||||||
SELECT tmpTicket.ticketFk,
|
SELECT s.ticketFk,
|
||||||
bp.pgcFk,
|
s.itemFk,
|
||||||
SUM(s.quantity * s.price * (100 - s.discount) / 100 ) taxableBase,
|
s.quantity * s.price * (100 - s.discount) / 100 total,
|
||||||
pgc.rate,
|
t.companyFk,
|
||||||
tc.code,
|
t.addressFk,
|
||||||
bp.priority
|
su.countryFk,
|
||||||
FROM tmp.ticket tmpTicket
|
ata.areaFk,
|
||||||
JOIN sale s ON s.ticketFk = tmpTicket.ticketFk
|
itc.taxClassFk
|
||||||
JOIN item i ON i.id = s.itemFk
|
FROM vn.sale s
|
||||||
JOIN ticket t ON t.id = tmpTicket.ticketFk
|
JOIN tmp.ticket tmp ON tmp.ticketFk = s.ticketFk
|
||||||
JOIN supplier su ON su.id = t.companyFk
|
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
|
JOIN tmp.addressTaxArea ata ON ata.addressFk = t.addressFk
|
||||||
AND ata.companyFk = t.companyFk
|
AND ata.companyFk = t.companyFk
|
||||||
JOIN itemTaxCountry itc ON itc.itemFk = i.id
|
JOIN vn.itemTaxCountry itc ON itc.itemFk = s.itemFk
|
||||||
AND itc.countryFk = su.countryFk
|
AND itc.countryFk = su.countryFk
|
||||||
JOIN bookingPlanner bp ON bp.countryFk = su.countryFk
|
HAVING total
|
||||||
AND bp.taxAreaFk = ata.areaFk
|
)
|
||||||
AND bp.taxClassFk = itc.taxClassFk
|
SELECT s.ticketFk,
|
||||||
JOIN pgc ON pgc.code = bp.pgcFk
|
bp.pgcFk,
|
||||||
JOIN taxClass tc ON tc.id = bp.taxClassFk
|
SUM(s.total) taxableBase,
|
||||||
GROUP BY tmpTicket.ticketFk, pgc.code, pgc.rate
|
pgc.rate,
|
||||||
HAVING taxableBase
|
tc.code,
|
||||||
) t3
|
bp.priority
|
||||||
|
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
|
||||||
ORDER BY priority;
|
ORDER BY priority;
|
||||||
|
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketServiceTax
|
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketServiceTax
|
||||||
|
|
|
@ -48,13 +48,13 @@ module.exports = Self => {
|
||||||
let stmt;
|
let stmt;
|
||||||
stmts.push(new ParameterizedSQL(
|
stmts.push(new ParameterizedSQL(
|
||||||
`CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
`CREATE OR REPLACE TEMPORARY TABLE tmp.ticket
|
||||||
(KEY (ticketFk))
|
(INDEX (ticketFk))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
SELECT id ticketFk
|
SELECT id ticketFk
|
||||||
FROM ticket t
|
FROM ticket
|
||||||
WHERE shipped BETWEEN ? AND util.dayEnd(?)
|
WHERE shipped BETWEEN ? AND util.dayEnd(?)
|
||||||
AND refFk IS NULL`, [args.from, args.to]));
|
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(
|
stmts.push(new ParameterizedSQL(
|
||||||
`CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
`CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
|
@ -71,12 +71,12 @@ module.exports = Self => {
|
||||||
c.isTaxDataChecked,
|
c.isTaxDataChecked,
|
||||||
w.id comercialId,
|
w.id comercialId,
|
||||||
u.name workerName
|
u.name workerName
|
||||||
FROM vn.ticket t
|
FROM ticket t
|
||||||
JOIN vn.company co ON co.id = t.companyFk
|
JOIN company co ON co.id = t.companyFk
|
||||||
JOIN vn.sale s ON s.ticketFk = t.id
|
JOIN sale s ON s.ticketFk = t.id
|
||||||
JOIN vn.client c ON c.id = t.clientFk
|
JOIN client c ON c.id = t.clientFk
|
||||||
JOIN vn.country cou ON cou.id = c.countryFk
|
JOIN country cou ON cou.id = c.countryFk
|
||||||
LEFT JOIN vn.worker w ON w.id = c.salesPersonFk
|
LEFT JOIN 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 (
|
LEFT JOIN (
|
||||||
SELECT ticketFk, taxableBase
|
SELECT ticketFk, taxableBase
|
||||||
|
|
|
@ -228,52 +228,57 @@ module.exports = Self => {
|
||||||
stmt = new ParameterizedSQL(`
|
stmt = new ParameterizedSQL(`
|
||||||
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
CREATE OR REPLACE TEMPORARY TABLE tmp.filter
|
||||||
(INDEX (id))
|
(INDEX (id))
|
||||||
ENGINE = MEMORY
|
ENGINE = InnoDB
|
||||||
SELECT t.id,
|
SELECT t.id,
|
||||||
t.shipped,
|
t.shipped,
|
||||||
CAST(DATE(t.shipped) AS CHAR) shippedDate,
|
CAST(DATE(t.shipped) AS CHAR) shippedDate,
|
||||||
HOUR(t.shipped) shippedHour,
|
HOUR(t.shipped) shippedHour,
|
||||||
t.nickname,
|
t.nickname,
|
||||||
t.refFk,
|
t.refFk,
|
||||||
t.routeFk,
|
t.routeFk,
|
||||||
t.warehouseFk,
|
t.warehouseFk,
|
||||||
t.clientFk,
|
t.clientFk,
|
||||||
t.totalWithoutVat,
|
t.totalWithoutVat,
|
||||||
t.totalWithVat,
|
t.totalWithVat,
|
||||||
io.id invoiceOutId,
|
io.id invoiceOutId,
|
||||||
a.provinceFk,
|
a.provinceFk,
|
||||||
p.name province,
|
p.name province,
|
||||||
w.name warehouse,
|
w.name warehouse,
|
||||||
am.name agencyMode,
|
am.name agencyMode,
|
||||||
am.id agencyModeFk,
|
am.id agencyModeFk,
|
||||||
st.name state,
|
st.name state,
|
||||||
st.classColor,
|
st.classColor,
|
||||||
wk.lastName salesPerson,
|
wk.lastName salesPerson,
|
||||||
ts.stateFk stateFk,
|
ts.stateFk stateFk,
|
||||||
ts.alertLevel alertLevel,
|
ts.alertLevel alertLevel,
|
||||||
ts.code alertLevelCode,
|
ts.code alertLevelCode,
|
||||||
u.name userName,
|
u.name userName,
|
||||||
c.salesPersonFk,
|
c.salesPersonFk,
|
||||||
z.hour zoneLanding,
|
z.hour zoneLanding,
|
||||||
HOUR(z.hour) zoneHour,
|
HOUR(z.hour) zoneHour,
|
||||||
MINUTE(z.hour) zoneMinute,
|
MINUTE(z.hour) zoneMinute,
|
||||||
z.name zoneName,
|
z.name zoneName,
|
||||||
z.id zoneFk,
|
z.id zoneFk,
|
||||||
CAST(z.hour AS CHAR) hour,
|
CAST(z.hour AS CHAR) hour,
|
||||||
a.nickname addressNickname
|
a.nickname addressNickname,
|
||||||
FROM ticket t
|
(SELECT GROUP_CONCAT(DISTINCT i2.itemPackingTypeFk ORDER BY i2.itemPackingTypeFk SEPARATOR ',')
|
||||||
LEFT JOIN invoiceOut io ON t.refFk = io.ref
|
FROM sale s2
|
||||||
LEFT JOIN zone z ON z.id = t.zoneFk
|
JOIN item i2 ON i2.id = s2.itemFk
|
||||||
LEFT JOIN address a ON a.id = t.addressFk
|
WHERE s2.ticketFk = t.id
|
||||||
LEFT JOIN province p ON p.id = a.provinceFk
|
) AS packing
|
||||||
LEFT JOIN warehouse w ON w.id = t.warehouseFk
|
FROM ticket t
|
||||||
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
|
LEFT JOIN invoiceOut io ON t.refFk = io.ref
|
||||||
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
LEFT JOIN zone z ON z.id = t.zoneFk
|
||||||
LEFT JOIN state st ON st.id = ts.stateFk
|
LEFT JOIN address a ON a.id = t.addressFk
|
||||||
LEFT JOIN client c ON c.id = t.clientFk
|
LEFT JOIN province p ON p.id = a.provinceFk
|
||||||
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
LEFT JOIN warehouse w ON w.id = t.warehouseFk
|
||||||
LEFT JOIN account.user u ON u.id = wk.id
|
LEFT JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||||
LEFT JOIN route r ON r.id = t.routeFk
|
LEFT JOIN ticketState ts ON ts.ticketFk = t.id
|
||||||
|
LEFT JOIN state st ON st.id = ts.stateFk
|
||||||
|
LEFT JOIN client c ON c.id = t.clientFk
|
||||||
|
LEFT JOIN worker wk ON wk.id = c.salesPersonFk
|
||||||
|
LEFT JOIN account.user u ON u.id = wk.id
|
||||||
|
LEFT JOIN route r ON r.id = t.routeFk
|
||||||
`);
|
`);
|
||||||
|
|
||||||
if (args.orderFk) {
|
if (args.orderFk) {
|
||||||
|
@ -292,6 +297,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt.merge(conn.makeWhere(filter.where));
|
stmt.merge(conn.makeWhere(filter.where));
|
||||||
|
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(`
|
stmt = new ParameterizedSQL(`
|
||||||
|
|
Loading…
Reference in New Issue