feat: refs #7950 Modified sql #3165
|
@ -86,39 +86,27 @@ module.exports = Self => {
|
|||
|
||||
let stmts = [];
|
||||
const stmt = new ParameterizedSQL(`
|
||||
SELECT *
|
||||
FROM (
|
||||
SELECT t.cmrFk,
|
||||
t.id ticketFk,
|
||||
t.routeFk,
|
||||
co.id countryFk,
|
||||
co.name countryName,
|
||||
t.clientFk,
|
||||
IF(sub.id, TRUE, FALSE) hasCmrDms,
|
||||
DATE(t.shipped) shipped,
|
||||
t.warehouseFk,
|
||||
w.name warehouseName
|
||||
FROM ticket t
|
||||
JOIN ticketState ts ON ts.ticketFk = t.id
|
||||
JOIN state s ON s.id = ts.stateFk
|
||||
JOIN alertLevel al ON al.id = s.alertLevel
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN address a ON a.id = t.addressFk
|
||||
JOIN province p ON p.id = a.provinceFk
|
||||
JOIN country co ON co.id = p.countryFk
|
||||
JOIN agencyMode am ON am.id = t.agencyModeFk
|
||||
JOIN warehouse w ON w.id = t.warehouseFk
|
||||
LEFT JOIN (
|
||||
SELECT td.ticketFk, d.id
|
||||
FROM ticketDms td
|
||||
JOIN dms d ON d.id = td.dmsFk
|
||||
JOIN dmsType dt ON dt.id = d.dmsTypeFk
|
||||
WHERE dt.name = 'cmr'
|
||||
) sub ON sub.ticketFk = t.id
|
||||
WHERE am.name <> 'ABONO'
|
||||
AND w.code = 'ALG'
|
||||
AND t.cmrFk
|
||||
) sub
|
||||
SELECT c.id,
|
||||
co.code sender,
|
||||
af.nickname loadingPlace,
|
||||
at.nickname deliveryPlace,
|
||||
s.name carrier,
|
||||
c.created loadingDate,
|
||||
c.ead landingDate,
|
||||
c.truckPlate,
|
||||
c.packagesList,
|
||||
c.senderInstruccions,
|
||||
c.merchandiseDetail,
|
||||
c.specialAgreements,
|
||||
c.paymentInstruccions,
|
||||
c.observations,
|
||||
t.id
|
||||
FROM cmr c
|
||||
JOIN address af ON af.id = c.addressFromFk
|
||||
JOIN address at ON at.id = c.addressToFk
|
||||
JOIN company co ON co.id = c.companyFk
|
||||
JOIN supplier s ON s.id = c.supplierFk
|
||||
LEFT JOIN ticket t ON t.cmrFk = c.id
|
||||
`);
|
||||
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
|
|
Loading…
Reference in New Issue