]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/Invoice.pm
Artikel-Reihenfolge beibehalten beim Erzeugen und autom. Drucken wiederkehrender...
[mfinanz.git] / SL / DB / Invoice.pm
index 09c7f86e7d11aa4f75e215c5f44087beac4faa8b..2382c6e126275d817f0a3e9d384483a1571210be 100644 (file)
@@ -47,6 +47,13 @@ __PACKAGE__->meta->initialize;
 
 sub items { goto &invoiceitems; }
 
+sub items_sorted {
+  my ($self) = @_;
+
+  my @sorted =  sort {$a->id <=> $b->id } @{ $self->items };
+  return wantarray ? @sorted : \@sorted;
+}
+
 sub is_sales {
   # For compatibility with Order, DeliveryOrder
   croak 'not an accessor' if @_ > 1;
@@ -98,9 +105,9 @@ sub new_from {
 
   my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_terms->terms_netto : 0;
 
-  my %args = ( map({ ( $_ => $source->$_ ) } qw(customer_id taxincluded shippingpoint shipvia notes intnotes curr salesman_id cusordnumber ordnumber quonumber
+  my %args = ( map({ ( $_ => $source->$_ ) } qw(customer_id taxincluded shippingpoint shipvia notes intnotes salesman_id cusordnumber ordnumber quonumber
                                                 department_id cp_id language_id payment_id delivery_customer_id delivery_vendor_id taxzone_id shipto_id
-                                                globalproject_id transaction_description)),
+                                                globalproject_id transaction_description currency_id)),
                transdate   => DateTime->today_local,
                gldate      => DateTime->today_local,
                duedate     => DateTime->today_local->add(days => $terms * 1),
@@ -128,7 +135,7 @@ sub new_from {
                                     base_qty subtotal longdescription lastcost price_factor_id)),
                             deliverydate => $source_item->reqdate,
                             fxsellprice  => $source_item->sellprice,);
-  } @{ $source->items };
+  } @{ $source->items_sorted };
 
   $invoice->invoiceitems(\@items);