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