Revision 8328e037
Von Jan Büren vor etwa 2 Jahren hinzugefügt
SL/DB/Helper/Payment.pm | ||
---|---|---|
103 | 103 |
$exchangerate = $params{exchangerate}; |
104 | 104 |
|
105 | 105 |
my $new_open_amount = ( $self->open_amount / $self->get_exchangerate ) * $exchangerate; |
106 |
# VORHER |
|
107 |
# my $gain_loss_amount = _round($amount * ($exchangerate - $self->get_exchangerate ) * -1,2); |
|
108 |
# $fx_gain_loss_amount = _round( $self->open_amount - $new_open_amount); |
|
109 |
# $fx_gain_loss_amount = _round($self->open_amount / $self->get_exchangerate - $new_open_amount / $exchangerate); |
|
110 |
# works for ap, but change sign for ar (todo credit notes and negative ap transactions |
|
111 |
# $fx_gain_loss_amount *= -1 if $self->is_sales; |
|
112 |
# if new open amount for payment booking is smaller than original amount use this |
|
113 |
# assume that the rest are fees, if the user selected this |
|
106 |
# caller wants to book fees and set a fee amount |
|
114 | 107 |
if ($params{fx_book} && $params{fx_fee_amount} > 0) { |
115 | 108 |
die "Bank Fees can only be added for AP transactions or Sales Credit Notes" |
116 | 109 |
unless $self->invoice_type =~ m/^purchase_invoice$|^ap_transaction$|^credit_note$/; |
110 |
|
|
117 | 111 |
$self->_add_bank_fx_fees(fee => _round($params{fx_fee_amount}), |
118 | 112 |
bt_id => $params{bt_id}, |
119 | 113 |
bank_chart_id => $params{chart_id}, |
... | ... | |
121 | 115 |
source => $params{source}, |
122 | 116 |
transdate_obj => $transdate_obj ); |
123 | 117 |
# invoice_amount add gl booking |
124 |
$main::lxdebug->message(0, 'fee ' . $params{fx_fee_amount}); |
|
125 | 118 |
$return_bank_amount += _round($params{fx_fee_amount}); # invoice_type needs negative bank_amount |
126 |
$main::lxdebug->message(0, 'bank_amount' . $return_bank_amount); |
|
127 |
#$fx_gain_loss_amount = _round($params{amount} - ($params{amount} / $self->get_exchangerate * $exchangerate) ); |
|
128 | 119 |
} |
129 | 120 |
} elsif (!$self->forex) { # invoices uses default currency. no exchangerate |
130 | 121 |
$exchangerate = 1; |
... | ... | |
189 | 180 |
tax_id => SL::DB::Manager::Tax->find_by(taxkey => 0)->id); |
190 | 181 |
$new_acc_trans->save; |
191 | 182 |
$return_bank_amount += $amount; |
192 |
$main::lxdebug->message(0, 'return 5 :' . $return_bank_amount); |
|
193 |
$main::lxdebug->message(0, 'paid amount hier 1 :' . $paid_amount); |
|
194 | 183 |
push @new_acc_ids, $new_acc_trans->acc_trans_id; |
195 | 184 |
# deal with fxtransaction ... |
196 | 185 |
# if invoice exchangerate differs from exchangerate of payment |
... | ... | |
198 | 187 |
if ($exchangerate != 1 && $self->get_exchangerate and $self->get_exchangerate != 1 and $self->get_exchangerate != $exchangerate) { |
199 | 188 |
my $fxgain_chart = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_fxgain_accno_id) || die "Can't determine fxgain chart"; |
200 | 189 |
my $fxloss_chart = SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_fxloss_accno_id) || die "Can't determine fxloss chart"; |
201 |
# AMOUNT == EUR / fx rate pay * (fx rate invoice - fx rate pa) |
|
202 |
# rate invoice = 2, fx rate paid = 1.75 |
|
203 |
# partial payment of 15000 EUR invtotal 20000 |
|
204 |
# 15000/1.75 * (2 - 1.75) = 2142. EUR gain if invoice is purchase # sql ledger (with fx amount): |
|
190 |
# |
|
191 |
# AMOUNT == EUR / fx rate payment * (fx rate invoice - fx rate payment) |
|
205 | 192 |
# AR.pm |
206 | 193 |
# $amount = $form->round_amount($form->{"paid_$i"} * ($form->{exchangerate} - $form->{"exchangerate_$i"}) * -1, 2); |
207 | 194 |
# AP.pm |
208 | 195 |
# exchangerate gain/loss |
209 | 196 |
# $amount = $form->round_amount($form->{"paid_$i"} * ($form->{exchangerate} - $form->{"exchangerate_$i"}), 2); |
210 |
# ==>
|
|
211 |
my $fx_gain_loss_sign = $is_sales ? -1 : 1; # multiplier for getting the right sign depending on ar/ap
|
|
197 |
# => |
|
198 |
my $fx_gain_loss_sign = $is_sales ? -1 : 1; # multiplier for getting the right sign depending on ar/ap |
|
212 | 199 |
|
213 |
$fx_gain_loss_amount = _round($params{amount} / $exchangerate * ( $self->get_exchangerate - $exchangerate)) * $fx_gain_loss_sign; |
|
200 |
$fx_gain_loss_amount = _round($params{amount} / $exchangerate * ( $self->get_exchangerate - $exchangerate)) * $fx_gain_loss_sign;
|
|
214 | 201 |
|
215 | 202 |
my $gain_loss_chart = $fx_gain_loss_amount > 0 ? $fxgain_chart : $fxloss_chart; |
216 |
# for sales add loss to ar.paid and subtract gain from ar.paid |
|
203 |
# for sales add loss to ar.paid and subtract gain from ar.paid |
|
204 |
$paid_amount += abs($fx_gain_loss_amount) if $fx_gain_loss_amount < 0 && $self->is_sales; # extract if we have fx_loss |
|
205 |
$paid_amount -= abs($fx_gain_loss_amount) if $fx_gain_loss_amount > 0 && $self->is_sales; # but add if to match original invoice amount (arap) |
|
217 | 206 |
# for purchase add gain to ap.paid and subtract loss from ap.paid |
218 |
$paid_amount += abs($fx_gain_loss_amount) if $fx_gain_loss_amount < 0 && $self->is_sales; # extract if we have fx_loss |
|
219 |
$paid_amount -= abs($fx_gain_loss_amount) if $fx_gain_loss_amount > 0 && $self->is_sales; # but add if to match original invoice amount (arap) |
|
220 | 207 |
$paid_amount += abs($fx_gain_loss_amount) if $fx_gain_loss_amount > 0 && !$self->is_sales; # but add if to match original invoice amount (arap) |
221 | 208 |
$paid_amount -= abs($fx_gain_loss_amount) if $fx_gain_loss_amount < 0 && !$self->is_sales; # extract if we have fx_loss |
222 |
# (self->amount - self->paid) / $self->exchangerate |
|
223 |
$main::lxdebug->message(0, 'paid dort 2 ' . $paid_amount); |
|
224 |
|
|
225 |
$main::lxdebug->message(0, 'return 1 ' . $return_bank_amount); |
|
226 |
$main::lxdebug->message(0, 'paid amount hier 2 ' . $paid_amount); |
|
227 |
# $return_bank_amount += $fx_gain_loss_amount if $fx_gain_loss_amount < 0; # only add if we have fx_loss |
|
228 |
|
|
229 |
$main::lxdebug->message(0, 'paid2chart ' . $fx_gain_loss_amount); |
|
230 |
$main::lxdebug->message(0, 'return 2 ' . $return_bank_amount); |
|
231 |
# $fx_gain_loss_amount = $gain_loss_amount; |
|
232 | 209 |
|
233 | 210 |
$new_acc_trans = SL::DB::AccTransaction->new(trans_id => $self->id, |
234 | 211 |
chart_id => $gain_loss_chart->id, |
... | ... | |
370 | 347 |
push @new_acc_ids, $tax_booking->acc_trans_id; |
371 | 348 |
} |
372 | 349 |
} |
373 |
# $fx_gain_loss_amount *= -1 if $self->is_sales; |
|
374 | 350 |
$self->paid($self->paid + _round($paid_amount)) if $paid_amount; |
375 | 351 |
$self->datepaid($transdate_obj); |
376 | 352 |
$self->save; |
... | ... | |
460 | 436 |
} |
461 | 437 |
|
462 | 438 |
sub open_amount_fx { |
463 |
# validate shift == $self |
|
464 | 439 |
validate_pos( |
465 | 440 |
@_, |
466 | 441 |
{ can => [ qw(forex get_exchangerate) ], |
... | ... | |
478 | 453 |
} |
479 | 454 |
|
480 | 455 |
sub amount_less_skonto_fx { |
481 |
# validate shift == $self |
|
482 | 456 |
validate_pos( |
483 | 457 |
@_, |
484 | 458 |
{ can => [ qw(forex get_exchangerate percent_skonto) ], |
... | ... | |
493 | 467 |
return ( $self->amount_less_skonto / $self->get_exchangerate ) * $fx_rate; |
494 | 468 |
} |
495 | 469 |
|
496 |
|
|
497 |
|
|
498 | 470 |
sub skonto_amount { |
499 | 471 |
my $self = shift; |
500 | 472 |
|
Auch abrufbar als: Unified diff
Payment-Helper: Debugs raus, Kosmetik