2020-09-25 12:45:00 +00:00
|
|
|
SELECT
|
|
|
|
s.id,
|
|
|
|
s.itemFk,
|
|
|
|
s.concept,
|
|
|
|
s.quantity,
|
|
|
|
s.price,
|
|
|
|
s.price - SUM(IF(ctr.id = 6, sc.value, 0)) netPrice,
|
|
|
|
s.discount,
|
|
|
|
i.size,
|
|
|
|
i.stems,
|
|
|
|
i.category,
|
|
|
|
it.id itemTypeId,
|
|
|
|
o.code AS origin,
|
|
|
|
i.inkFk,
|
|
|
|
s.ticketFk,
|
|
|
|
tcl.code vatType,
|
2020-12-16 08:24:11 +00:00
|
|
|
ib.botanical,
|
|
|
|
eg.latinGenusName,
|
|
|
|
es.latinSpeciesName,
|
2020-09-25 12:45:00 +00:00
|
|
|
i.tag5,
|
|
|
|
i.value5,
|
|
|
|
i.tag6,
|
|
|
|
i.value6,
|
|
|
|
i.tag7,
|
|
|
|
i.value7
|
|
|
|
FROM vn.sale s
|
|
|
|
LEFT JOIN saleComponent sc ON sc.saleFk = s.id
|
|
|
|
LEFT JOIN component cr ON cr.id = sc.componentFk
|
|
|
|
LEFT JOIN componentType ctr ON ctr.id = cr.typeFk
|
|
|
|
LEFT JOIN item i ON i.id = s.itemFk
|
|
|
|
LEFT JOIN ticket t ON t.id = s.ticketFk
|
|
|
|
LEFT JOIN origin o ON o.id = i.originFk
|
|
|
|
LEFT JOIN country c ON c.id = o.countryFk
|
|
|
|
LEFT JOIN supplier sp ON sp.id = t.companyFk
|
|
|
|
LEFT JOIN itemType it ON it.id = i.typeFk
|
2020-12-16 08:24:11 +00:00
|
|
|
LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
|
2020-09-25 12:45:00 +00:00
|
|
|
LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id
|
|
|
|
AND itc.countryFk = sp.countryFk
|
|
|
|
LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk
|
2020-12-16 08:24:11 +00:00
|
|
|
LEFT JOIN itemBotanical ib ON ib.itemFk = i.id
|
|
|
|
AND ic.code = 'plant'
|
|
|
|
LEFT JOIN ediGenus eg ON eg.id = ib.genusFk
|
|
|
|
LEFT JOIN ediSpecie es ON es.id = ib.specieFk
|
2020-09-25 12:45:00 +00:00
|
|
|
WHERE s.ticketFk = ?
|
|
|
|
GROUP BY s.id
|
|
|
|
ORDER BY (it.isPackaging), s.concept, s.itemFk
|