Import von Lieferadressen.
[kivitendo-erp.git] / bin / mozilla / is.pl
index b5e0927..2d833b6 100644 (file)
@@ -94,14 +94,6 @@ sub edit {
   $form->{javascript} = qq|<script type="text/javascript" src="js/show_history.js"></script>|;
   #/show hhistory button
 
-  if ($form->{type} eq "credit_note") {
-    $form->{title} = $locale->text('Edit Credit Note');
-    $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
-  } else {
-    $form->{title} = $locale->text('Edit Sales Invoice');
-    $form->{title} = $locale->text('Edit Storno Invoice')     if $form->{storno};
-  }
-
   my ($language_id, $printer_id);
   if ($form->{print_and_post}) {
     $form->{action}   = "print";
@@ -109,7 +101,16 @@ sub edit {
     $language_id = $form->{language_id};
     $printer_id = $form->{printer_id};
   }
+
   &invoice_links;
+  if ($form->{type} eq "credit_note") {
+    $form->{title} = $locale->text('Edit Credit Note');
+    $form->{title} = $locale->text('Edit Storno Credit Note') if $form->{storno};
+  } else {
+    $form->{title} = $locale->text('Edit Sales Invoice');
+    $form->{title} = $locale->text('Edit Storno Invoice')     if $form->{storno};
+  }
+
   &prepare_invoice;
   if ($form->{print_and_post}) {
     $form->{language_id} = $language_id;
@@ -132,8 +133,8 @@ sub invoice_links {
   $form->{vc} = 'customer';
 
   # create links
-  $form->{webdav}   = $main::webdav;
-  $form->{lizenzen} = $main::lizenzen;
+  $form->{webdav}   = $::lx_office_conf{features}->{webdav};
+  $form->{lizenzen} = $::lx_office_conf{features}->{lizenzen};
 
   $form->create_links("AR", \%myconfig, "customer");
 
@@ -155,14 +156,6 @@ sub invoice_links {
     $ref->{name} = $form->quote($ref->{name});
   }
 
-  # Load data for a specific order and update form fields
-  my $order_data = OE->get_order_data_by_ordnumber(%$form) if $form->{ordnumber};
-
-  # Copy the fields we need to %form
-  for my $key (qw(payment_id salesman_id orddate taxzone_id quonumber)) {
-    $form->{$key} = $order_data->{$key};
-  }
-
   $form->restore_vars(qw(id));
 
   IS->retrieve_invoice(\%myconfig, \%$form);
@@ -274,7 +267,13 @@ sub prepare_invoice {
 
     # get pricegroups for parts
     IS->get_pricegroups_for_parts(\%myconfig, \%$form);
-    set_pricegroup($_) for 1 .. $form->{rowcount};
+
+    # Problem: set_pricegroup resets the sellprice of old invoices to the price
+    # currently defined in the pricegroup, which is a problem if the price has
+    # changed, as the old invoice gets the new price
+    # set_pricegroup must never be called, when an old invoice is initially loaded
+
+    # set_pricegroup($_) for 1 .. $form->{rowcount};
   }
   $main::lxdebug->leave_sub();
 }
@@ -334,7 +333,7 @@ sub form_header {
   my @values = map { $_       } @{ $form->{ALL_CURRENCIES} };
   my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
   $form->{currency}            = $form->{defaultcurrency} unless $form->{currency};
-  $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
+  $form->{show_exchangerate}   = $form->{currency} ne $form->{defaultcurrency};
   $TMPL_VAR{currencies}        = NTI($::cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
                                                       '-values' => \@values, '-labels' => \%labels)) if scalar @values;
   push @custom_hiddens, "forex";
@@ -474,9 +473,9 @@ sub update {
 
   $main::auth->assert('invoice_edit');
 
-  my ($recursive_call) = shift;
+  my ($recursive_call) = @_;
 
-#  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining) unless $recursive_call;
+  $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}) unless $recursive_call;
 
   $form->{print_and_post} = 0         if $form->{second_run};
   my $taxincluded            = "checked" if $form->{taxincluded};
@@ -563,7 +562,7 @@ sub update {
 
         $form->{"qty_$i"} = $form->format_amount(\%myconfig, $form->{"qty_$i"});
 
-        if ($main::lizenzen) {
+        if ($::lx_office_conf{features}->{lizenzen}) {
           if ($form->{"inventory_accno_$i"} ne "") {
             $form->{"lizenzen_$i"} = qq|<option></option>|;
             foreach my $item (@{ $form->{LIZENZEN}{ $form->{"id_$i"} } }) {
@@ -639,7 +638,7 @@ sub post_payment {
   # Das Problem hierbei ist, dass in IS.pm post_invoice IMMER alle Zahlungseingänge aus $form
   # erneut gespeichert werden. Prinzipiell wäre es besser NUR die Änderungen des Rechnungs-
   # belegs (neue Zahlung aber nichts anderes) zu speichern ...
-  # Vielleicht könnte man ähnlich wie bei Rechnung löschen verfahren 
+  # Vielleicht könnte man ähnlich wie bei Rechnung löschen verfahren
   $form->error($locale->text('Cannot post payment for a closed period!'))
     if ($form->date_closed($form->{"datepaid_$form->{paidaccounts}"}, \%myconfig));
 
@@ -788,6 +787,11 @@ sub use_as_template {
   $form->{paidaccounts} = 1;
   $form->{rowcount}--;
   $form->{invdate} = $form->current_date(\%myconfig);
+
+  # remember pricegroups for "use as template"
+  IS->get_pricegroups_for_parts(\%myconfig, \%$form);
+  set_pricegroup($_) for 1 .. $form->{rowcount};
+
   &display_form;
 
   $main::lxdebug->leave_sub();
@@ -912,7 +916,8 @@ sub credit_note {
   $form->{title}  = $locale->text('Add Credit Note');
   $form->{script} = 'is.pl';
 
-
+  # Bei Gutschriften bezug zur Rechnungsnummer
+  $form->{invnumber_for_credit_note} = $form->{invnumber};
   # bo creates the id, reset it
   map { delete $form->{$_} }
     qw(id invnumber subject message cc bcc printed emailed queued);
@@ -961,7 +966,7 @@ sub yes {
 
   $main::auth->assert('invoice_edit');
 
-  if (IS->delete_invoice(\%myconfig, \%$form, $main::spool)) {
+  if (IS->delete_invoice(\%myconfig, \%$form)) {
     # saving the history
     if(!exists $form->{addition}) {
     $form->{snumbers} = qq|invnumber_| . $form->{invnumber};