2023-04-26 11:49:08 +00:00
|
|
|
SELECT io.issued,
|
|
|
|
c.socialName,
|
|
|
|
c.street postalAddress,
|
2023-11-08 09:01:02 +00:00
|
|
|
c.fi,
|
2021-03-01 10:25:37 +00:00
|
|
|
io.clientFk,
|
2023-04-26 11:49:08 +00:00
|
|
|
c.postcode,
|
|
|
|
c.city,
|
2021-03-01 10:25:37 +00:00
|
|
|
io.companyFk,
|
|
|
|
io.ref,
|
2023-04-26 11:49:08 +00:00
|
|
|
tc.code,
|
|
|
|
s.concept,
|
|
|
|
s.quantity,
|
|
|
|
s.price,
|
|
|
|
s.discount,
|
|
|
|
s.ticketFk,
|
2021-03-01 10:25:37 +00:00
|
|
|
t.shipped,
|
2023-04-26 11:49:08 +00:00
|
|
|
t.refFk,
|
|
|
|
a.nickname,
|
2021-03-01 10:25:37 +00:00
|
|
|
s.itemFk,
|
|
|
|
s.id saleFk,
|
|
|
|
pm.name AS pmname,
|
|
|
|
sa.iban,
|
2023-04-26 11:49:08 +00:00
|
|
|
c.phone,
|
2021-03-01 10:25:37 +00:00
|
|
|
MAX(t.packages) packages,
|
|
|
|
a.incotermsFk,
|
|
|
|
ic.name incotermsName ,
|
2023-04-26 11:49:08 +00:00
|
|
|
t.weight,
|
|
|
|
t.observations,
|
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,
|
2021-03-01 10:25:37 +00:00
|
|
|
CAST(sub2.volume AS DECIMAL (10,2)) volume,
|
|
|
|
sub3.intrastat
|
|
|
|
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
|
|
|
|
LEFT JOIN vn.incoterms ic ON ic.code = a.incotermsFk
|
|
|
|
LEFT JOIN vn.customsAgent ca ON ca.id = a.customsAgentFk
|
|
|
|
JOIN vn.sale s ON s.ticketFk = t.id
|
|
|
|
JOIN (SELECT SUM(volume) volume
|
2023-04-26 11:49:08 +00:00
|
|
|
FROM vn.invoiceOut io
|
2021-03-01 10:25:37 +00:00
|
|
|
JOIN vn.ticket t ON t.refFk = io.ref
|
2023-04-26 11:49:08 +00:00
|
|
|
JOIN vn.saleVolume sv ON sv.ticketFk = t.id
|
2022-07-21 08:05:37 +00:00
|
|
|
WHERE t.refFk = ?
|
2023-04-26 11:49:08 +00:00
|
|
|
) sub2 ON TRUE
|
2021-03-01 10:25:37 +00:00
|
|
|
JOIN vn.itemTaxCountry itc ON itc.countryFk = su.countryFk AND itc.itemFk = s.itemFk
|
|
|
|
JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
|
2023-11-08 09:01:02 +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
|
|
|
|
LEFT JOIN (SELECT GROUP_CONCAT(DISTINCT ir.description ORDER BY ir.description SEPARATOR '. ' ) as intrastat
|
2023-04-26 11:49:08 +00:00
|
|
|
FROM vn.ticket t
|
2021-03-01 10:25:37 +00:00
|
|
|
JOIN vn.invoiceOut io ON io.ref = t.refFk
|
|
|
|
JOIN vn.sale s ON t.id = s.ticketFk
|
2023-04-26 11:49:08 +00:00
|
|
|
JOIN vn.item i ON i.id = s.itemFk
|
|
|
|
JOIN vn.intrastat ir ON ir.id = i.intrastatFk
|
2022-07-21 08:05:37 +00:00
|
|
|
WHERE t.refFk = ?
|
2021-03-01 10:25:37 +00:00
|
|
|
)sub3 ON TRUE
|
2022-07-21 08:05:37 +00:00
|
|
|
WHERE t.refFk = ?
|
|
|
|
|