update consulte sql
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2022-03-17 15:05:13 +01:00
parent c660786e45
commit 894f95cb1f
1 changed files with 7 additions and 7 deletions

View File

@ -42,20 +42,20 @@ module.exports = Self => {
SUM(t.packages) packages,
r.m3,
r.kmEnd - r.kmStart kmTotal,
CAST(IFNULL(ate.routePrice,
(ate.kmPrice * (GREATEST(r.kmEnd - r.kmStart , ate.minimumKm))
+ GREATEST(r.m3 , ate.minimumM3) * ate.m3Price)
+ ate.packagePrice * SUM(t.packages) )
CAST(IFNULL(sat.routePrice,
(sat.kmPrice * (GREATEST(r.kmEnd - r.kmStart , sat.minimumKm))
+ GREATEST(r.m3 , sat.minimumM3) * sat.m3Price)
+ sat.packagePrice * SUM(t.packages) )
AS DECIMAL(10,2)) price,
r.invoiceInFk,
a.supplierFk,
sat.supplierFk,
s.name supplierName
FROM vn.route r
LEFT JOIN vn.agencyMode am ON r.agencyModeFk = am.id
LEFT JOIN vn.agency a ON am.agencyFk = a.id
LEFT JOIN vn.ticket t ON t.routeFk = r.id
LEFT JOIN vn.agencyTerm ate ON ate.agencyFk = a.id
LEFT JOIN vn.supplier s ON s.id = a.supplierFk
LEFT JOIN vn.supplierAgencyTerm sat ON sat.agencyFk = a.id
LEFT JOIN vn.supplier s ON s.id = sat.supplierFk
WHERE r.created > DATE_ADD(CURDATE(), INTERVAL -2 MONTH) AND a.supplierFk IS NOT NULL
GROUP BY r.id
) a`