salix/print/templates/reports/invoice-incoterms/sql/incoterms.sql

68 lines
2.5 KiB
MySQL
Raw Normal View History

SELECT io.issued,
c.socialName,
c.street postalAddress,
c.fi,
2021-03-01 10:25:37 +00:00
io.clientFk,
c.postcode,
c.city,
2021-03-01 10:25:37 +00:00
io.companyFk,
io.ref,
tc.code,
s.concept,
s.quantity,
s.price,
s.discount,
s.ticketFk,
2021-03-01 10:25:37 +00:00
t.shipped,
t.refFk,
a.nickname,
2021-03-01 10:25:37 +00:00
s.itemFk,
s.id saleFk,
pm.name AS pmname,
sa.iban,
c.phone,
2021-03-01 10:25:37 +00:00
MAX(t.packages) packages,
a.incotermsFk,
ic.name incotermsName ,
t.weight,
t.observations,
2021-03-01 10:25:37 +00:00
ca.fiscalName customsAgentName,
ca.street customsAgentStreet,
ca.nif customsAgentNif,
ca.phone customsAgentPhone,
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
FROM vn.invoiceOut io
2021-03-01 10:25:37 +00:00
JOIN vn.ticket t ON t.refFk = io.ref
JOIN vn.saleVolume sv ON sv.ticketFk = t.id
2022-07-21 08:05:37 +00:00
WHERE t.refFk = ?
) 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
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
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
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 = ?