S:D:Invoice->new_from: Auftragsdatum aus Auftrag bei Erzeugen aus Lieferschein
[kivitendo-erp.git] / SL / DB / Invoice.pm
index 44b81df..0e27f8a 100644 (file)
@@ -60,6 +60,12 @@ __PACKAGE__->meta->add_relationship(
       sort_by      => 'acc_trans_id ASC',
     },
   },
+  dunnings       => {
+    type         => 'one to many',
+    class        => 'SL::DB::Dunning',
+    column_map   => { id => 'trans_id' },
+    manager_args => { with_objects => [ 'dunnings' ] }
+  },
 );
 
 __PACKAGE__->meta->initialize;
@@ -178,9 +184,16 @@ sub new_from {
 
   $args{payment_id} = ( $terms ? $terms->id : $source->payment_id);
 
-  if ($source->type =~ /_order$/) {
+  if ($source->type =~ /_delivery_order$/) {
+    $args{deliverydate} = $source->reqdate;
+    if (my $order = SL::DB::Manager::Order->find_by(ordnumber => $source->ordnumber)) {
+      $args{orddate}    = $order->transdate;
+    }
+
+  } elsif ($source->type =~ /_order$/) {
     $args{deliverydate} = $source->reqdate;
     $args{orddate}      = $source->transdate;
+
   } else {
     $args{quodate}      = $source->transdate;
   }
@@ -578,8 +591,8 @@ sub link {
   my ($self) = @_;
 
   my $html;
-  $html   = SL::Presenter->get->sales_invoice($self, display => 'inline') if $self->invoice;
-  $html   = SL::Presenter->get->ar_transaction($self, display => 'inline') if !$self->invoice;
+  $html   = $self->presenter->sales_invoice(display => 'inline') if $self->invoice;
+  $html   = $self->presenter->ar_transaction(display => 'inline') if !$self->invoice;
 
   return $html;
 }
@@ -714,7 +727,7 @@ See L<SL::DB::Object::basic_info>.
 =item C<closed>
 
 Returns 1 or 0, depending on whether the invoice is closed or not. Currently
-invoices that are overpaid also count as closed.
+invoices that are overpaid also count as closed and credit notes in general.
 
 =item C<recalculate_amounts %params>