SELECT invnumber, amount, paid, fxamount, fxpaid FROM ap WHERE amount=paid AND fxamount <> 
 fxpaid AND fxpaid <> 0 OR fxpaid is NULL;
 
 UPDATE ap SET fxamount = (SELECT SUM(0-amount) FROM acc_trans WHERE
 chart_id IN (SELECT id FROM chart WHERE link LIKE '%AP_amount%' OR
 link LIKE '%IC_expense%' OR link LIKE '%tax%') AND trans_id=ap.id and
 NOT fx_transaction);
 
 UPDATE ap SET fxpaid = paid WHERE fxpaid is NULL;
 
 UPDATE ar SET fxpaid = paid WHERE fxpaid is NULL;
 
 UPDATE ap SET fxamount = fxpaid WHERE amount = paid;
 
 UPDATE ar SET fxamount = fxpaid WHERE amount = paid;   
 

Ignore below

 
 
 UPDATE ap SET fxamount = amount WHERE fxamount = 0;
 UPDATE ap SET fxpaid = paid WHERE fxpaid = 0;
 
 UPDATE ap SET fxpaid = (SELECT SUM(amount) FROM acc_trans WHERE
 chart_id IN (SELECT id FROM chart WHERE link LIKE '%_paid%') AND
 trans_id=ap.id AND NOT fx_transaction);
 UPDATE ap SET fxamount=round(fxamount), fxpaid=ROUND(fxpaid);
 
 UPDATE ap SET fxamount = fxpaid WHERE amount = paid;