Zahlungsbedingungen bei Lieferscheinen; veraltete Spalte »terms« entfernt
[kivitendo-erp.git] / SL / DB / Invoice.pm
index 065d2b3..82cf66b 100644 (file)
@@ -138,14 +138,10 @@ sub new_from {
 
   require SL::DB::Employee;
 
-  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') {
-    @columns      = qw(quonumber payment_id delivery_customer_id delivery_vendor_id);
+    @columns      = qw(quonumber delivery_customer_id delivery_vendor_id);
     @item_columns = qw(subtotal);
 
     $item_parent_id_column = 'trans_id';
@@ -158,12 +154,13 @@ sub new_from {
     $item_parent_column    = 'delivery_order';
   }
 
+  my $terms = $source->can('payment_id') ? $source->payment_terms : undef;
+
   my %args = ( map({ ( $_ => $source->$_ ) } qw(customer_id taxincluded shippingpoint shipvia notes intnotes salesman_id cusordnumber ordnumber department_id
-                                                cp_id language_id taxzone_id shipto_id globalproject_id transaction_description currency_id delivery_term_id), @columns),
+                                                cp_id language_id taxzone_id shipto_id globalproject_id transaction_description currency_id delivery_term_id payment_id), @columns),
                transdate   => DateTime->today_local,
                gldate      => DateTime->today_local,
-               duedate     => DateTime->today_local->add(days => ($terms ? $terms->terms_netto * 1 : 1)),
-               payment_id  => $terms ? $terms->id : undef,
+               duedate     => $terms ? $terms->calc_date(reference_date => DateTime->today_local) : DateTime->today_local,
                invoice     => 1,
                type        => 'invoice',
                storno      => 0,