select i.organization_id, i.invoice_id as invoice_rev_id
from iv_invoices i, cr_items ii
where ii.latest_revision = i.invoice_id
and ii.item_id = :invoice_id
and i.status = 'paid'
update iv_invoices
set status = 'paid',
paid_currency = currency,
paid_amount = total_amount
where invoice_id = (select latest_revision
from cr_items
where item_id = :inv_id)