SELECT
invoice.invoiceid,
invoice.invoiceid,
clients.company_name,
invoice.`date`,
vat_settingsid,
format(sum((invoice_lines.qty*invoice_lines.selling_price_excluding_vat)),2),
invoice.processed_transaction as posted
FROM
invoice
Left Join clients ON clients.clientsid = invoice.clientsid
Left Join contact_person ON contact_person.contact_personid = invoice.contact_personid
Left Join invoice_lines ON invoice_lines.invoiceid = invoice.invoiceid
group by invoice.invoiceid