- # exchangerate gain/loss
- $amount = $form->round_amount($form->{"paid_$i"} * ($form->{exchangerate} - $form->{"exchangerate_$i"}), 2);
-
- if ($amount != 0) {
- $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno};
- $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
- transdate, fx_transaction, cleared)
- VALUES ($form->{id}, (SELECT id FROM chart
- WHERE accno = '$accno'),
- $amount, '$form->{"datepaid_$i"}', '1', '0')|;
- $dbh->do($query) || $form->dberror($query);
+
+ # exchangerate difference for payment
+ $amount = $form->round_amount($form->{"paid_$i"} * ($form->{"exchangerate_$i"} - 1) * -1, 2);
+
+ if ($amount != 0) {
+ $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
+ transdate, fx_transaction, cleared)
+ VALUES ($form->{id},
+ (SELECT id FROM chart
+ WHERE accno = '$form->{AR_amounts}{"paid_$i"}'),
+ $amount, '$form->{"datepaid_$i"}', '1', '0')|;
+ $dbh->do($query) || $form->dberror($query);
+ }
+
+ # exchangerate gain/loss
+ $amount = $form->round_amount($form->{"paid_$i"} * ($form->{exchangerate} - $form->{"exchangerate_$i"}) * -1, 2);
+
+ if ($amount != 0) {
+ $accno = ($amount > 0) ? $form->{fxgain_accno} : $form->{fxloss_accno};
+ $query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount,
+ transdate, fx_transaction, cleared)
+ VALUES ($form->{id}, (SELECT id FROM chart
+ WHERE accno = '$accno'),
+ $amount, '$form->{"datepaid_$i"}', '1', '0')|;
+ $dbh->do($query) || $form->dberror($query);
+ }