I have deleted my previous post as it was not the correct reason for the problem. I will explain the problem and see if anyone else has this issue.
I process invoices with multiple lines with different VATs associated with different entries. So some entries may be 0VAT and some may be 20% VAT entries. These all appear in the trans_tax_details table for the particular invoice(debt) as multiple rows all with the correct respective net_amount and amount entries.
The Select statement
SELECT
'Output',
ca.amt gross_output,
(ca.amt/(ttd.net_amount+ttd.amount)) * ttd.net_amount * ex_rate net_output,
(ca.amt/(ttd.net_amount+ttd.amount)) * ttd.amount*ex_rate payable,
is performed to determine the correct amount if the invoice is not settled (allocated) in full. However, as I see it this only works if the invoice is summarised in one row with one VAT. That is, ca.amt is compared with each row and if this doesn't relate directly to the ttd.net_amount and ttd.amount in one row it doesn't work?
Am I reading this wrongly?
As I noted before I deleted my earlier post using
SELECT
'Output',
ca.amt gross_output,
ttd.net_amount * ex_rate net_output,
ttd.amount*ex_rate payable,
will work but technically only if the allocation is in full.
Can anyone please confirm if it's an error or if I am seeing this wrongly??
Many thanks