refactor: refs #8106 Optimized ticket_getTax #3122

Merged
guillermo merged 2 commits from 8106-negativeBasesOptimize into dev 2024-10-18 08:27:09 +00:00
1 changed files with 15 additions and 20 deletions
Showing only changes of commit 865da7bba2 - Show all commits

View File

@ -36,8 +36,7 @@ BEGIN
(PRIMARY KEY (ticketFk, code, rate))
ENGINE = MEMORY
WITH sales AS (
SELECT s.id,
s.ticketFk,
SELECT s.ticketFk,
guillermo marked this conversation as resolved Outdated

los campos s.id y s.ticketFk no son necesarios en la primera SELECT

los campos s.id y s.ticketFk no son necesarios en la primera SELECT

El s.id ok, pero el s.ticketFk sí es necesario, ya que se utiliza en el GROUP BY

El s.id ok, pero el s.ticketFk sí es necesario, ya que se utiliza en el GROUP BY
s.itemFk,
s.quantity * s.price * (100 - s.discount) / 100 total,
t.companyFk,
@ -54,25 +53,21 @@ BEGIN
JOIN vn.itemTaxCountry itc ON itc.itemFk = s.itemFk
AND itc.countryFk = su.countryFk
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 *
FROM ticketTax
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
ORDER BY priority;
CREATE OR REPLACE TEMPORARY TABLE tmp.ticketServiceTax