53 lines
1.7 KiB
MySQL
53 lines
1.7 KiB
MySQL
|
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,
|
||
|
ibwg.ediBotanic,
|
||
|
ppa.denomination,
|
||
|
pp.number passportNumber,
|
||
|
be.isProtectedZone, c.code AS countryCode,
|
||
|
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
|
||
|
LEFT JOIN itemTaxCountry itc ON itc.itemFk = i.id
|
||
|
AND itc.countryFk = sp.countryFk
|
||
|
LEFT JOIN taxClass tcl ON tcl.id = itc.taxClassFk
|
||
|
LEFT JOIN plantpassport pp ON pp.producerFk = i.producerFk
|
||
|
LEFT JOIN plantpassportAuthority ppa ON ppa.id = pp.plantpassportAuthorityFk
|
||
|
LEFT JOIN itemBotanicalWithGenus ibwg ON ibwg.itemFk = i.id
|
||
|
LEFT JOIN botanicExport be ON be.restriction = 'pasaporte fitosanitario'
|
||
|
LEFT JOIN ediGenus eg ON eg.id = be.ediGenusFk
|
||
|
LEFT JOIN ediSpecie es ON es.id = be.ediSpecieFk
|
||
|
AND ibwg.ediBotanic LIKE CONCAT(
|
||
|
IFNULL(eg.latinGenusName, ''),
|
||
|
IF(es.latinSpeciesName > '',
|
||
|
CONCAT(' ', es.latinSpeciesName), ''),
|
||
|
'%')
|
||
|
WHERE s.ticketFk = ?
|
||
|
GROUP BY s.id
|
||
|
ORDER BY (it.isPackaging), s.concept, s.itemFk
|