S:D:Invoice: _post_add_acctrans: Keine Tranaktionen mit Summe == 0 speichern.
[kivitendo-erp.git] / SL / DB / Invoice.pm
index 4caafc0..6f8438f 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;
   }
@@ -290,14 +303,16 @@ sub _post_add_acctrans {
     $chart_link = SL::DB::Manager::Chart->find_by(id => $chart_id)->{'link'};
     $chart_link ||= '';
 
-    SL::DB::AccTransaction->new(trans_id   => $self->id,
-                                chart_id   => $chart_id,
-                                amount     => $spec->{amount},
-                                tax_id     => $spec->{tax_id},
-                                taxkey     => $spec->{taxkey},
-                                project_id => $self->globalproject_id,
-                                transdate  => $self->transdate,
-                                chart_link => $chart_link)->save;
+    if ($spec->{amount} != 0) {
+      SL::DB::AccTransaction->new(trans_id   => $self->id,
+                                  chart_id   => $chart_id,
+                                  amount     => $spec->{amount},
+                                  tax_id     => $spec->{tax_id},
+                                  taxkey     => $spec->{taxkey},
+                                  project_id => $self->globalproject_id,
+                                  transdate  => $self->transdate,
+                                  chart_link => $chart_link)->save;
+    }
   }
 }
 
@@ -349,6 +364,7 @@ sub add_ar_amount_row {
     chart_id   => $params{chart}->id,
     chart_link => $params{chart}->link,
     transdate  => $self->transdate,
+    gldate     => $self->gldate,
     taxkey     => $tax->taxkey,
     tax_id     => $tax->id,
     project_id => $params{project_id},
@@ -363,6 +379,7 @@ sub add_ar_amount_row {
        chart_id   => $tax->chart_id,
        chart_link => $tax->chart->link,
        transdate  => $self->transdate,
+       gldate     => $self->gldate,
        taxkey     => $tax->taxkey,
        tax_id     => $tax->id,
      );
@@ -558,7 +575,8 @@ sub abbreviation {
 sub oneline_summary {
   my $self = shift;
 
-  return sprintf("%s: %s %s (%s)", $self->abbreviation, $self->invnumber, $self->customer->name, $self->transdate->to_kivitendo);
+  return sprintf("%s: %s %s %s (%s)", $self->abbreviation, $self->invnumber, $self->customer->name,
+                                      $::form->format_amount(\%::myconfig, $self->amount,2), $self->transdate->to_kivitendo);
 }
 
 sub date {
@@ -577,8 +595,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;
 }
@@ -713,7 +731,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>