This commit is contained in:
parent
28e957fecd
commit
865da7bba2
|
@ -36,8 +36,7 @@ BEGIN
|
||||||
(PRIMARY KEY (ticketFk, code, rate))
|
(PRIMARY KEY (ticketFk, code, rate))
|
||||||
ENGINE = MEMORY
|
ENGINE = MEMORY
|
||||||
WITH sales AS (
|
WITH sales AS (
|
||||||
SELECT s.id,
|
SELECT s.ticketFk,
|
||||||
s.ticketFk,
|
|
||||||
s.itemFk,
|
s.itemFk,
|
||||||
s.quantity * s.price * (100 - s.discount) / 100 total,
|
s.quantity * s.price * (100 - s.discount) / 100 total,
|
||||||
t.companyFk,
|
t.companyFk,
|
||||||
|
@ -54,25 +53,21 @@ BEGIN
|
||||||
JOIN vn.itemTaxCountry itc ON itc.itemFk = s.itemFk
|
JOIN vn.itemTaxCountry itc ON itc.itemFk = s.itemFk
|
||||||
AND itc.countryFk = su.countryFk
|
AND itc.countryFk = su.countryFk
|
||||||
HAVING total
|
HAVING total
|
||||||
),
|
|
||||||
ticketTax AS (
|
|
||||||
SELECT s.ticketFk,
|
|
||||||
bp.pgcFk,
|
|
||||||
SUM(s.total) taxableBase,
|
|
||||||
pgc.rate,
|
|
||||||
tc.code,
|
|
||||||
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
|
|
||||||
)
|
)
|
||||||
SELECT *
|
SELECT s.ticketFk,
|
||||||
FROM ticketTax
|
bp.pgcFk,
|
||||||
|
SUM(s.total) taxableBase,
|
||||||
|
pgc.rate,
|
||||||
|
tc.code,
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue