salix/print/templates/reports/cmr/sql/data.sql

52 lines
1.5 KiB
SQL

SELECT c.id cmrFk,
t.id ticketFk,
c.truckPlate,
c.observations,
c.senderInstruccions,
c.paymentInstruccions,
c.specialAgreements,
c.created,
c.packagesList,
c.merchandiseDetail,
c.ead,
s.name carrierName,
s.nif carrierCif,
s.street carrierStreet,
s.postCode carrierPostCode,
s.city carrierCity,
cou.name carrierCountry,
s2.name senderName,
s2.street senderStreet,
s2.postCode senderPostCode,
s2.city senderCity,
cou2.name senderCountry,
a.street deliveryStreet,
a.id deliveryAddressFk,
a.postalCode deliveryPostalCode,
a.city deliveryCity,
a.nickname deliveryName,
a.phone deliveryPhone,
a.mobile deliveryMobile,
cou3.name deliveryCountry,
cl.phone clientPhone,
a2.street loadStreet,
a2.postalCode loadPostalCode,
a2.city loadCity,
cou4.name loadCountry,
co.stamp senderStamp,
s.stamp deliveryStamp
FROM cmr c
LEFT JOIN supplier s ON s.id = c.supplierFk
LEFT JOIN country cou ON cou.id = s.countryFk
LEFT JOIN company co ON co.id = c.companyFk
LEFT JOIN supplier s2 ON s2.id = c.companyFk
LEFT JOIN country cou2 ON cou2.id = s2.countryFk
LEFT JOIN `address` a ON a.id = c.addressToFk
LEFT JOIN province p ON p.id = a.provinceFk
LEFT JOIN country cou3 ON cou3.id = p.countryFk
LEFT JOIN client cl ON cl.id = a.clientFk
LEFT JOIN `address` a2 ON a2.id = c.addressFromFk
LEFT JOIN province p2 ON p2.id = a2.provinceFk
LEFT JOIN country cou4 ON cou4.id = p2.countryFk
LEFT JOIN ticket t ON t.cmrFk = c.id
WHERE c.id = ?