diff --git a/db/routines/vn/procedures/route_calcCommission.sql b/db/routines/vn/procedures/route_calcCommission.sql index 47a256994..1a5a9bdc2 100644 --- a/db/routines/vn/procedures/route_calcCommission.sql +++ b/db/routines/vn/procedures/route_calcCommission.sql @@ -23,14 +23,15 @@ BEGIN DELETE FROM routeCommission WHERE routeFk = vSelf; - SELECT w.isFreelance, v.isKmTruckRate, c.countryFk INTO vIsFreelance, vIsKmTruckRate, vCountryFk + SELECT w.isFreelance, v.isKmTruckRate, p.countryFk INTO vIsFreelance, vIsKmTruckRate, vCountryFk FROM route r JOIN worker w ON w.id = r.workerFk JOIN vehicle v ON v.id = r.vehicleFk LEFT JOIN ticket t ON t.routeFk = r.id - LEFT JOIN client c ON c.id = t.clientFk + LEFT JOIN address a ON a.id = t.addressFk + LEFT JOIN province p ON p.id = a.provinceFk WHERE r.id = vSelf - GROUP BY c.countryFk + GROUP BY p.countryFk ORDER BY COUNT(*) DESC LIMIT 1; @@ -90,7 +91,9 @@ BEGIN (r.kmEnd - r.kmStart) * IF(v.isKmTruckRate, rc.kmHeavy, rc.kmLight), IFNULL(r.m3, 0) * - IF(v.isKmTruckRate, rc.deliveryM3Cat5, rc.deliveryM3Cat4), + IF(v.isKmTruckRate, + IFNULL(wc.deliveryM3Cat5, rc.deliveryM3Cat5), + IFNULL(wc.deliveryM3Cat4, rc.deliveryM3Cat4)), (r.kmEnd - r.kmStart) * rc.kmYearly, IFNULL(r.m3, 0) * rc.m3Yearly, IFNULL(wc.distributionCat4M3, rc.distributionCat4M3) * IFNULL(r.m3, 0), diff --git a/db/versions/11363-silverCarnation/00-firstScript.sql b/db/versions/11363-silverCarnation/00-firstScript.sql new file mode 100644 index 000000000..b9595bab3 --- /dev/null +++ b/db/versions/11363-silverCarnation/00-firstScript.sql @@ -0,0 +1,7 @@ +ALTER TABLE vn.workCenterCommission ADD deliveryM3Cat4 DECIMAL(5,2) DEFAULT NULL NULL; +ALTER TABLE vn.workCenterCommission ADD deliveryM3Cat5 DECIMAL(5,2) DEFAULT NULL NULL; + +INSERT INTO vn.workCenterCommission (workCenterFk, deliveryM3Cat4, deliveryM3Cat5) + VALUES (5,8.0,8.0); + +