2024-06-20 09:04:42 +00:00
|
|
|
SELECT calc.packages,
|
2021-03-01 10:25:37 +00:00
|
|
|
a.incotermsFk,
|
2024-01-11 09:09:35 +00:00
|
|
|
ic.name incotermsName,
|
2024-06-20 09:04:42 +00:00
|
|
|
calc.weight,
|
2021-03-01 10:25:37 +00:00
|
|
|
ca.fiscalName customsAgentName,
|
|
|
|
ca.street customsAgentStreet,
|
|
|
|
ca.nif customsAgentNif,
|
|
|
|
ca.phone customsAgentPhone,
|
2023-04-26 11:49:08 +00:00
|
|
|
ca.email customsAgentEmail,
|
2024-01-11 09:09:35 +00:00
|
|
|
CAST(vol.volume AS DECIMAL (10,2)) volume,
|
|
|
|
intr.intrastat
|
2021-03-01 10:25:37 +00:00
|
|
|
FROM vn.invoiceOut io
|
|
|
|
JOIN vn.supplier su ON su.id = io.companyFk
|
|
|
|
JOIN vn.client c ON c.id = io.clientFk
|
|
|
|
LEFT JOIN vn.province p ON p.id = c.provinceFk
|
|
|
|
JOIN vn.ticket t ON t.refFk = io.ref
|
|
|
|
JOIN vn.address a ON a.id = t.addressFk
|
2024-02-12 09:10:30 +00:00
|
|
|
JOIN vn.incoterms ic ON ic.code = a.incotermsFk
|
2021-03-01 10:25:37 +00:00
|
|
|
LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk
|
|
|
|
JOIN vn.sale s ON s.ticketFk = t.id
|
2024-01-11 09:09:35 +00:00
|
|
|
JOIN (
|
|
|
|
SELECT SUM(volume) volume, COUNT(*) packages
|
|
|
|
FROM vn.invoiceOut io
|
|
|
|
JOIN vn.ticket t ON t.refFk = io.ref
|
|
|
|
JOIN vn.saleVolume sv ON sv.ticketFk = t.id
|
|
|
|
WHERE t.refFk = ?
|
|
|
|
) vol
|
|
|
|
JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk
|
|
|
|
AND itc.itemFk = s.itemFk
|
2021-03-01 10:25:37 +00:00
|
|
|
JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
|
2024-01-11 09:09:35 +00:00
|
|
|
JOIN vn.invoiceOutSerial ios ON ios.code = io.serial
|
|
|
|
AND ios.taxAreaFk = 'WORLD'
|
2021-03-01 10:25:37 +00:00
|
|
|
JOIN vn.country cty ON cty.id = c.countryFk
|
|
|
|
JOIN vn.payMethod pm ON pm.id = c .payMethodFk
|
|
|
|
JOIN vn.company co ON co.id=io.companyFk
|
|
|
|
JOIN vn.supplierAccount sa ON sa.id=co.supplierAccountFk
|
2024-01-11 09:09:35 +00:00
|
|
|
JOIN (
|
|
|
|
SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR '. ' ) intrastat
|
|
|
|
FROM vn.ticket t
|
|
|
|
JOIN vn.invoiceOut io ON io.ref = t.refFk
|
|
|
|
JOIN vn.sale s ON t.id = s.ticketFk
|
|
|
|
JOIN vn.item i ON i.id = s.itemFk
|
|
|
|
JOIN vn.intrastat ir ON ir.id = i.intrastatFk
|
|
|
|
WHERE t.refFk = ?
|
|
|
|
) intr
|
|
|
|
JOIN (
|
2024-06-20 09:04:42 +00:00
|
|
|
SELECT SUM(packages) packages, SUM(weight) weight
|
2024-01-11 09:09:35 +00:00
|
|
|
FROM ticket
|
|
|
|
WHERE refFk = ?
|
2024-06-20 09:04:42 +00:00
|
|
|
) calc
|
2024-01-11 09:09:35 +00:00
|
|
|
WHERE t.refFk = ?
|
|
|
|
LIMIT 1
|