update jobs j
join invoices i on j.id = i.job_id
set j.closed = 1,
j.closed_date = i.payment_date
where j.closed = 0
and i.status = 'Paid';