SELECT  
        it.ref,
        it.socialName,
        it.iban,     
        it.payMethod,  
        it.clientFk,
        it.shipped,
        it.nickname,
        s.ticketFk,
        s.itemFk,
        s.concept, 
        s.quantity, 
        s.price, 
        s.discount,
        i.tag5, 
        i.value5,
        i.tag6, 
        i.value6, 
        i.tag7, 
        i.value7,
		tc.code AS vatType,
        ib.ediBotanic botanical
	FROM tmp.invoiceTickets it
    JOIN vn.sale s ON s.ticketFk = it.ticketFk 
    JOIN item i ON i.id = s.itemFk
    LEFT JOIN itemType it ON it.id = i.typeFk
    LEFT JOIN itemCategory ic ON ic.id = it.categoryFk
    LEFT JOIN itemBotanicalWithGenus ib ON ib.itemFk = i.id
        AND ic.code = 'plant'
        AND ib.ediBotanic IS NOT NULL
    JOIN vn.itemTaxCountry itc ON itc.countryFk = it.supplierCountryFk 
        AND itc.itemFk = s.itemFk
    JOIN vn.taxClass tc ON tc.id = itc.taxClassFk
UNION ALL	
SELECT  
        it.ref,
        it.socialName,
        it.iban,        
        it.payMethod,  
        it.clientFk,
        it.shipped,
        it.nickname, 
        it.ticketFk, 
        '',
        ts.description concept, 
        ts.quantity, 
        ts.price, 
        0 discount, 
        NULL AS tag5,
        NULL AS value5,
        NULL AS tag6,
        NULL AS value6,
        NULL AS tag7,
        NULL AS value7,
        tc.code AS vatType,
        NULL AS botanical
	FROM tmp.invoiceTickets it
        JOIN vn.ticketService ts ON ts.ticketFk = it.ticketFk
        JOIN vn.taxClass tc ON tc.id = ts.taxClassFk