+
+ # deal with fxtransaction
+ if ( $self->currency_id != $::instance_conf->get_currency_id ) {
+ my $fxamount = _round($amount - ($amount * $exchangerate));
+ $new_acc_trans = SL::DB::AccTransaction->new(trans_id => $self->id,
+ chart_id => $account_bank->id,
+ chart_link => $account_bank->link,
+ amount => $fxamount * -1,
+ transdate => $transdate_obj,
+ source => $source,
+ memo => $memo,
+ taxkey => 0,
+ fx_transaction => 1,
+ tax_id => SL::DB::Manager::Tax->find_by(taxkey => 0)->id);
+ $new_acc_trans->save;
+ # if invoice exchangerate differs from exchangerate of payment
+ # deal with fxloss and fxamount
+ if ($self->exchangerate and $self->exchangerate != 1 and $self->exchangerate != $exchangerate) {
+ my $fxgain_chart = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_fxgain_accno_id) || die "Can't determine fxgain chart";
+ my $fxloss_chart = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_fxloss_accno_id) || die "Can't determine fxloss chart";
+ my $gain_loss_amount = _round($amount * ($exchangerate - $self->exchangerate ) * -1,2);
+ my $gain_loss_chart = $gain_loss_amount > 0 ? $fxgain_chart : $fxloss_chart;
+ $fx_gain_loss_amount = $gain_loss_amount;
+
+ $new_acc_trans = SL::DB::AccTransaction->new(trans_id => $self->id,
+ chart_id => $gain_loss_chart->id,
+ chart_link => $gain_loss_chart->link,
+ amount => $gain_loss_amount,
+ transdate => $transdate_obj,
+ source => $source,
+ memo => $memo,
+ taxkey => 0,
+ fx_transaction => 0,
+ tax_id => SL::DB::Manager::Tax->find_by(taxkey => 0)->id);
+ $new_acc_trans->save;
+
+ };
+ };