717 |
717 |
# sign is simply the sign of amount in bank_transactions: positive for increase and negative for decrease
|
718 |
718 |
$amount_for_booking *= $sign;
|
719 |
719 |
|
720 |
|
$main::lxdebug->message(0, 'amount for payment:' . $amount_for_payment);
|
721 |
|
# check exchangerate and if fx_loss calculate new booking_amount for this invoice
|
722 |
|
#if ($fx_rate > 0) {
|
723 |
|
# die "Exchangerate without currency" unless $currency_id;
|
724 |
|
# die "Invoice currency differs from user input currency" unless $currency_id == $invoice->currency->id;
|
725 |
|
|
726 |
|
|
727 |
|
# open_amount is open_amount for default currency
|
728 |
|
# TODO
|
729 |
|
# use helper to calc everything (even)
|
730 |
|
# 2 if fx_loss, we probably need a higher amount to pay the original amount of the ap invoice
|
731 |
|
# no, just calc new open_amount and check if user wants a fee booking
|
732 |
|
# my $open_amount_fx = $invoice->open_amount_fx($fx_rate);
|
733 |
|
# $amount_for_payment = $fx_book ? $not_assigned_amount : $invoice->open_amount_fx($fx_rate);
|
734 |
|
|
735 |
|
# die $open_amount_fx;
|
736 |
|
# if ($invoice->get_exchangerate < $fx_rate) {
|
737 |
|
# set whole bank_transaction amount -> pay_invoice will try to calculate losses and bank fees
|
738 |
|
# my $not_assigned_amount = abs($bank_transaction->not_assigned_amount);
|
739 |
|
# $amount_for_payment = $not_assigned_amount;
|
740 |
|
# $amount_for_payment *= -1 if $invoice->amount < 0;
|
741 |
|
# } elsif ($invoice->get_exchangerate >= $fx_rate) {
|
742 |
|
# if fx_gain do nothing, because gain
|
743 |
|
# bla bla
|
744 |
|
# TODO copy paste
|
745 |
|
# my $not_assigned_amount = abs($bank_transaction->not_assigned_amount);
|
746 |
|
# $amount_for_payment = $not_assigned_amount;
|
747 |
|
# $amount_for_payment *= -1 if $invoice->amount < 0;
|
748 |
|
# } else {
|
749 |
|
# die "Invalid exchange rate state for record:" . $invoice->get_exchangerate . " " . $fx_rate;
|
750 |
|
# }
|
751 |
|
#}
|
752 |
|
#$main::lxdebug->message(0, 'amount for payment2:' . $amount_for_payment);
|
753 |
720 |
# ... and then pay the invoice
|
754 |
721 |
my @acc_ids = $invoice->pay_invoice(chart_id => $bank_transaction->local_bank_account->chart_id,
|
755 |
722 |
trans_id => $invoice->id,
|
... | ... | |
766 |
733 |
transdate => $bank_transaction->valutadate->to_kivitendo);
|
767 |
734 |
# First element is the booked amount for accno bank
|
768 |
735 |
my $bank_amount = shift @acc_ids;
|
769 |
|
$main::lxdebug->message(0, 'a' . $bank_amount->{return_bank_amount});
|
770 |
|
$main::lxdebug->message(0, 'b' . $amount_for_booking);
|
|
736 |
|
771 |
737 |
if (!$invoice->forex) {
|
772 |
738 |
# die "Invalid state, calculated invoice_amount differs from expected invoice amount" unless (abs($bank_amount->{return_bank_amount}) - abs($amount_for_booking) < 0.001);
|
773 |
739 |
$bank_transaction->invoice_amount($bank_transaction->invoice_amount + $amount_for_booking);
|
Wechselkurs-Optimierung: Kosmetik weiter aufräumen