]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/Invoice.pm
SL::DB::Invoice: Verknüpfung auf die Buchungsobjekte
[mfinanz.git] / SL / DB / Invoice.pm
index 3f94795ee97a16c4b41d9a48492892a0d39b132f..502654ba262168fed42635a5b0581f6052757150 100644 (file)
@@ -130,7 +130,10 @@ sub new_from {
 
   require SL::DB::Employee;
 
-  my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_terms->terms_netto : 0;
+  my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_terms
+            : $source->customer_id                              ? $source ->customer->payment_terms
+            :                                                     undef;
+
   my (@columns, @item_columns, $item_parent_id_column, $item_parent_column);
 
   if (ref($source) eq 'SL::DB::Order') {
@@ -151,7 +154,8 @@ sub new_from {
                                                 cp_id language_id taxzone_id shipto_id globalproject_id transaction_description currency_id delivery_term_id), @columns),
                transdate   => DateTime->today_local,
                gldate      => DateTime->today_local,
-               duedate     => DateTime->today_local->add(days => $terms * 1),
+               duedate     => DateTime->today_local->add(days => ($terms ? $terms->terms_netto * 1 : 1)),
+               payment_id  => $terms ? $terms->id : undef,
                invoice     => 1,
                type        => 'invoice',
                storno      => 0,
@@ -316,6 +320,15 @@ sub date {
   goto &transdate;
 }
 
+sub transactions {
+  my ($self) = @_;
+
+  return unless $self->id;
+
+  require SL::DB::AccTransaction;
+  SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $self->id ]);
+}
+
 1;
 
 __END__