Revision 74ddad54
Von Jan Büren vor etwa 2 Jahren hinzugefügt
SL/Controller/BankTransaction.pm | ||
---|---|---|
689 | 689 |
# sign is simply the sign of amount in bank_transactions: positive for increase and negative for decrease |
690 | 690 |
# $amount_for_booking *= $sign; |
691 | 691 |
|
692 |
# check exchangerate and if fx_loss calculate new booking_amount for this invoice |
|
693 |
if ($fx_rate > 0) { |
|
694 |
die "Exchangerate without currency" unless $currency_id; |
|
695 |
die "Invoice currency differs from user input currency" unless $currency_id == $invoice->currency->id; |
|
696 |
|
|
697 |
# 1 set daily default or custom record exchange rate |
|
698 |
my $default_rate = $invoice->get_exchangerate_for_bank_transaction($bank_transaction->id); |
|
699 |
if (!$default_rate) { # set new daily default |
|
700 |
# helper |
|
701 |
my $buysell = $invoice->is_sales ? 'buy' : 'sell'; |
|
702 |
my $ex = SL::DB::Manager::Exchangerate->find_by(currency_id => $currency_id, |
|
703 |
transdate => $bank_transaction->valutadate) |
|
704 |
|| SL::DB::Exchangerate->new(currency_id => $currency_id, |
|
705 |
transdate => $bank_transaction->valutadate); |
|
706 |
$ex->update_attributes($buysell => $fx_rate); |
|
707 |
} elsif ($default_rate != $fx_rate) { # set record (banktransaction) exchangerate |
|
708 |
$bank_transaction->exchangerate($fx_rate); # custom rate, will be displayed in ap, ir, is |
|
709 |
} elsif ($default_rate == $fx_rate) { |
|
710 |
# should be last valid state -> do nothing |
|
711 |
} else { die "Invalid exchange rate state:" . $default_rate . " " . $fx_rate; } |
|
712 |
|
|
713 |
# 2 if fx_loss, we probably need a higher amount to pay the original amount of the ap invoice |
|
714 |
if ($invoice->get_exchangerate < $fx_rate) { |
|
715 |
# set whole bank_transaction amount -> pay_invoice will try to calculate losses and bank fees |
|
716 |
my $not_assigned_amount = abs($bank_transaction->not_assigned_amount); |
|
717 |
$amount_for_payment = $not_assigned_amount; |
|
718 |
$amount_for_payment *= -1 if $invoice->amount < 0; |
|
719 |
} elsif ($invoice->get_exchangerate > $fx_rate) { |
|
720 |
# if fx_gain do nothing, because gain |
|
721 |
# bla bla |
|
722 |
} else { |
|
723 |
die "Invalid exchange rate state for record:" . $invoice->get_exchangerate . " " . $fx_rate; |
|
724 |
} |
|
725 |
} |
|
692 | 726 |
# ... and then pay the invoice |
693 | 727 |
my @acc_ids = $invoice->pay_invoice(chart_id => $bank_transaction->local_bank_account->chart_id, |
694 | 728 |
trans_id => $invoice->id, |
Auch abrufbar als: Unified diff
wip: REMOVE Wechselkursberechungen geändert in Payment-Helper