Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d73d1806

Von Jan Büren vor mehr als 1 Jahr hinzugefügt

  • ID d73d180697af7e55e2be1f6fb95b369e0ed7c04e
  • Vorgänger e9b48f2e
  • Nachfolger 077479e3

Payment-Helper: Warnungen, striktere regex, vorheriges Mult. Verfahren

Das Vorzeichen über is_sales für fx_gain_loss zu setzen ist doch
korrekt und liefert die richtigen Zuordnungen. Regex richtig setzen
und auf initialisierte Werte Prüfung, für tests

Unterschiede anzeigen:

SL/DB/Helper/Payment.pm
91 91

  
92 92
  # currency has to be passed and caller has to be sure to assign it for a forex invoice
93 93
  # dies if called for a invoice with the default currency (TODO: Params::Validate before)
94
  my ($exchangerate, $currency, $return_bank_amount , $fx_gain_loss_amount);
95
  $return_bank_amount = 0;
94
  my ($exchangerate, $currency);
95
  my $fx_gain_loss_amount    = 0;
96
  my $return_bank_amount     = 0;
96 97
  if ($params{currency} || $params{currency_id} && $self->forex) { # currency was specified
97 98
    $currency = SL::DB::Manager::Currency->find_by(name => $params{currency}) || SL::DB::Manager::Currency->find_by(id => $params{currency_id});
98 99

  
......
108 109
    # $fx_gain_loss_amount = _round($self->open_amount / $self->get_exchangerate - $new_open_amount / $exchangerate);
109 110
    # works for ap, but change sign for ar (todo credit notes and negative ap transactions
110 111
    # $fx_gain_loss_amount *= -1 if $self->is_sales;
111
    $main::lxdebug->message(0, 'h 1 ' . $new_open_amount . ' h 3 ' . $params{amount});
112 112
    # if new open amount for payment booking is smaller than original amount use this
113 113
    # assume that the rest are fees, if the user selected this
114 114
    if ($params{fx_book} && $params{fx_fee_amount} > 0) {
115 115
      die "Bank Fees can only be added for AP transactions or Sales Credit Notes"
116
        unless $self->invoice_type =~ m/purchase_invoice|ap_transaction|credit_note/;
117

  
116
        unless $self->invoice_type =~ m/^purchase_invoice$|^ap_transaction$|^credit_note$/;
118 117
      $self->_add_bank_fx_fees(fee           => _round($params{fx_fee_amount}),
119 118
                               bt_id         => $params{bt_id},
120 119
                               bank_chart_id => $params{chart_id},
......
209 208
        # exchangerate gain/loss
210 209
        # $amount = $form->round_amount($form->{"paid_$i"} * ($form->{exchangerate} - $form->{"exchangerate_$i"}), 2);
211 210
        # ==>
212
        # my $fx_gain_loss_sign   = $is_sales ? -1 : 1;  # multiplier for getting the right sign depending on ar/ap
213

  
214
        #my $fx_gain_loss_sign = $self->invoice_type =~ m/purchase_invoice|ap_transaction|credit_note/                             ?  1
215
        #                      : $self->invoice_type =~ m/invoice|ar_transaction|purchase_credit_note|invoice_for_advance_payment/ ? -1
216
        #                      : die "invalid state";
211
        my $fx_gain_loss_sign   = $is_sales ? -1 : 1;  # multiplier for getting the right sign depending on ar/ap
217 212

  
218
        $fx_gain_loss_amount = _round($params{amount} / $exchangerate * ( $self->get_exchangerate - $exchangerate)); # * $fx_gain_loss_sign;
213
        $fx_gain_loss_amount = _round($params{amount} / $exchangerate * ( $self->get_exchangerate - $exchangerate)) * $fx_gain_loss_sign;
219 214

  
220
        $main::lxdebug->message(0, 'was sagt gain loss 2 ' . $fx_gain_loss_amount);
221
        # die "huchz" . $fx_gain_loss_amount;
222 215
        my $gain_loss_chart  = $fx_gain_loss_amount > 0 ? $fxgain_chart : $fxloss_chart;
223
        # $paid_amount += abs($fx_gain_loss_amount); # if $fx_gain_loss_amount < 0; # only add if we have fx_loss
224
        $main::lxdebug->message(0, 'paid hier 1 ' . $paid_amount);
225 216
        # for sales add loss to ar.paid and subtract gain from ar.paid
226 217
        # for purchase add gain to ap.paid and subtract loss from ap.paid
227 218
        $paid_amount += abs($fx_gain_loss_amount) if $fx_gain_loss_amount < 0 && $self->is_sales; # extract if we have fx_loss
......
797 788
  return 1 if $self->currency_id == $::instance_conf->get_currency_id;
798 789

  
799 790
  # return record exchange rate if set
800
  return $self->exchangerate if $self->exchangerate > 0;
791
  return $self->exchangerate if $self->exchangerate && $self->exchangerate > 0;
801 792

  
802 793
  # none defined check daily exchangerate at records transdate
803 794
  die "transdate isn't a DateTime object:" . ref($self->transdate) unless ref($self->transdate) eq 'DateTime';

Auch abrufbar als: Unified diff