The query below
SELECT
<output name="c.name" title="Name" />,
<output name="c.reference" title="Reference No." />,
<output name="i.idinvoice" title="Invoice ID" />,
<output replace="(SUM(v.quantity * s.charges))/COUNT(i.idinvoice)" />As Invoice
<output replace="p.amount" />AS Amount,
<output replace="p.idpayment" title="Payment ID" />,
<output replace="p.cheque_no title="Cheque No" />,
<output replace="p.pdatetime" title="Processed Time" />,
<output replace="p.user" title="Processed By" type="user" attribute="username" />
FROM inv i
LEFT JOIN invitem v ON v.idinvoice = i.idinvoice
LEFT JOIN service s ON s.idservice = v.idservice
LEFT JOIN payment p ON p.idinvoice = i.idinvoice
LEFT JOIN address a ON a.idaddress = i.idaddress
LEFT JOIN client c ON c.idclient = a.idclient
WHERE a.idaddress = '<input name="idaddress" />'
GROUP BY i.idinvoice, p.amount, p.idpayment, p.cheque_no, p.pdatetime, p.user
ORDER BY i.idinvoice DESC