]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/Helper/Payment.pm
Payment Helper exchangerate Methode verbessert
[mfinanz.git] / SL / DB / Helper / Payment.pm
index ed959718d32224a66800dc8d7159557f6c86d5c2..660794428aaac513e3445c050d692b55945550bf 100644 (file)
@@ -153,6 +153,7 @@ sub pay_invoice {
                                                    transdate  => $transdate_obj,
                                                    source     => $source,
                                                    memo       => $memo,
+                                                   project_id => $params{project_id} ? $params{project_id} : undef,
                                                    taxkey     => 0,
                                                    tax_id     => SL::DB::Manager::Tax->find_by(taxkey => 0)->id);
       $new_acc_trans->save;
@@ -656,11 +657,13 @@ sub exchangerate {
 
   return 1 if $self->currency_id == $::instance_conf->get_currency_id;
 
+  die "transdate isn't a DateTime object:" . ref($self->transdate) unless ref($self->transdate) eq 'DateTime';
   my $rate = SL::DB::Manager::Exchangerate->find_by(currency_id => $self->currency_id,
                                                     transdate   => $self->transdate,
                                                    );
   return undef unless $rate;
-  $self->is_sales ? return $rate->sell : return $rate->buy;
+
+  return $self->is_sales ? $rate->buy : $rate->sell; # also undef if not defined
 };
 
 sub get_payment_suggestions {
@@ -792,6 +795,7 @@ Example:
                    memo          => 'foobar',
                    source        => 'barfoo',
                    payment_type  => 'without_skonto',  # default if not specified
+                   project_id    => 25,
                   );
 
 or with skonto:
@@ -1104,8 +1108,12 @@ values for sales and purchases.
 
 =item C<exchangerate>
 
-Returns the exchangerate in database format for the invoice according to that invoice's transdate.
-Returns 'sell' for sales, 'buy' for purchases.
+Returns 1 immediately if the record uses the default currency.
+
+Returns the exchangerate in database format for the invoice according to that
+invoice's transdate, returning 'buy' for sales, 'sell' for purchases.
+
+If no exchangerate can be found for that day undef is returned.
 
 =back