]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/Invoice.pm
Merge branch 'master' of github.com:kivitendo/kivitendo-erp
[mfinanz.git] / SL / DB / Invoice.pm
index f75a6cd65b5013a0918ea7b3a07a622b76a9f9fa..77d6769a8c13cabdcc5cff81e83967099b3c94a0 100644 (file)
@@ -25,17 +25,21 @@ __PACKAGE__->meta->add_relationship(
     class        => 'SL::DB::InvoiceItem',
     column_map   => { id => 'trans_id' },
     manager_args => {
-      with_objects => [ 'parts' ]
+      with_objects => [ 'part' ]
     }
   },
+  storno_invoices => {
+    type          => 'one to many',
+    class         => 'SL::DB::Invoice',
+    column_map    => { id => 'storno_id' },
+  },
 );
 
 __PACKAGE__->meta->initialize;
 
 # methods
 
-sub items        { goto &invoiceitems; }
-sub payment_term { goto &payment;      }
+sub items { goto &invoiceitems; }
 
 sub is_sales {
   # For compatibility with Order, DeliveryOrder
@@ -165,14 +169,22 @@ sub post {
 sub _post_add_acctrans {
   my ($self, $entries) = @_;
 
+  my $default_tax_id = SL::DB::Manager::Tax->find_by(taxkey => 0)->id;
+  my $chart_link;
+
   while (my ($chart_id, $spec) = each %{ $entries }) {
-    $spec = { taxkey => 0, amount => $spec } unless ref $spec;
+    $spec = { taxkey => 0, tax_id => $default_tax_id, amount => $spec } unless ref $spec;
+    $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)->save;
+                                transdate  => $self->transdate,
+                                chart_link => $chart_link)->save;
   }
 }