CVar validity ausgelagert in eine Massenfunktion.
[kivitendo-erp.git] / bin / mozilla / io.pl
index ce7ce78..6a0d2fc 100644 (file)
@@ -210,8 +210,8 @@ sub display_row {
     my %column_data = ();
 
     # undo formatting
-    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } 
-      qw(qty discount sellprice lastcost price_new price_old) 
+    map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) }
+      qw(qty discount sellprice lastcost price_new price_old)
         unless ($form->{simple_save});
 
 # unit begin
@@ -343,8 +343,8 @@ sub display_row {
     map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(marge_absolut marge_percent);
 
     push @ROW2, { value => sprintf qq|
-         <font %s><b>%s</b> %s &nbsp;%s%% </font> 
-        &nbsp;<b>%s</b> %s 
+         <font %s><b>%s</b> %s &nbsp;%s%% </font>
+        &nbsp;<b>%s</b> %s
         &nbsp;<b>%s</b> <input size="5" name="lastcost_$i" value="%s">|,
                    $marge_color, $locale->text('Ertrag'),$form->{"marge_absolut_$i"}, $form->{"marge_percent_$i"},
                    $locale->text('LP'), $form->format_amount(\%myconfig, $form->{"listprice_$i"}, 2),
@@ -675,7 +675,7 @@ sub item_selected {
   map {
     $form->{"${_}_$i"} =
       $form->format_amount(\%myconfig, $form->{"${_}_$i"}, $decimalplaces)
-  } qw(sellprice listprice) if $form->{item} ne 'assembly';
+  } qw(sellprice listprice lastcost) if $form->{item} ne 'assembly';
 
   # get pricegroups for parts
   IS->get_pricegroups_for_parts(\%myconfig, \%$form);
@@ -882,7 +882,7 @@ sub validate_items {
   # check if items are valid
   if ($form->{rowcount} == 1) {
     &update;
-    exit;
+    ::end_of_request();
   }
 
   for my $i (1 .. $form->{rowcount} - 1) {
@@ -1184,7 +1184,9 @@ sub print_options {
     (!$options{no_html}) ?
       opthash("html", $form->{DF}{html}, "HTML") : undef,
     ($main::opendocument_templates && !$options{no_opendocument}) ?
-      opthash("opendocument",        $form->{DF}{opendocument},        $locale->text("OpenDocument/OASIS")) : undef;
+      opthash("opendocument",        $form->{DF}{opendocument},        $locale->text("OpenDocument/OASIS")) : undef,
+    ($main::excel_templates && !$options{no_excel}) ?
+      opthash("excel",               $form->{DF}{excel},               $locale->text("Excel")) : undef;
 
   push @LANGUAGE_ID,
     map { opthash($_->{id}, ($_->{id} eq $form->{language_id} ? 'selected' : ''), $_->{description}) } +{}, @{ $form->{languages} }
@@ -1263,7 +1265,7 @@ sub print {
     &save();
     $form->{formname} = $formname;
     &edit();
-    exit;
+    ::end_of_request();
   }
 
   &print_form($old_form);
@@ -1427,10 +1429,10 @@ sub print_form {
       if(!exists $form->{addition}) {
         $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
         $form->{addition} = "PRINTED";
-        $form->save_history($form->dbconnect(\%myconfig));
+        $form->save_history;
       }
       # /saving the history
-      exit;
+      ::end_of_request();
     }
   }
 
@@ -1592,6 +1594,9 @@ sub print_form {
   } elsif ($form->{"format"} =~ /opendocument/) {
     $form->{opendocument} = 1;
     $extension            = 'odt';
+  } elsif ($form->{"format"} =~ /excel/) {
+    $form->{excel} = 1;
+    $extension            = 'xls';
   }
 
   my $email_extension = '_email' if (($form->{media} eq 'email') && (-f "$myconfig{templates}/$form->{formname}_email$form->{language}${printer_code}.${extension}"));
@@ -1655,7 +1660,7 @@ sub print_form {
     elsif($form->{media} =~ /screen/) {
       $form->{addition} = "SCREENED";
     }
-    $form->save_history($form->dbconnect(\%myconfig));
+    $form->save_history;
   }
   # /saving the history
 
@@ -1700,7 +1705,7 @@ sub print_form {
       }
 
       call_sub($display_form);
-      exit;
+      ::end_of_request();
     }
 
     my $msg =
@@ -1711,7 +1716,7 @@ sub print_form {
   }
   if ($form->{printing}) {
    call_sub($display_form);
-   exit;
+   ::end_of_request();
   }
 
   $main::lxdebug->leave_sub();
@@ -1947,13 +1952,11 @@ sub new_license {
 
   $form->{script} = "licenses.pl";
 
-  our $name;
-
   map { $form->{$_} = $form->{"old_$_"} } qw(partnumber description);
   map { $form->{$_} = $form->escape($form->{$_}, 1) }
     qw(partnumber description);
   $form->{callback} =
-    qq|$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$name&type=$form->{type}&customer=$customer&partnumber=$form->{partnumber}&description=$form->{description}&previousform="$previousform"&initial=1|;
+    qq|$form->{script}?action=add&vc=$form->{db}&$form->{db}_id=$form->{id}&$form->{db}=$form->{name}&type=$form->{type}&customer=$customer&partnumber=$form->{partnumber}&description=$form->{description}&previousform="$previousform"&initial=1|;
   $form->redirect;
 
   $main::lxdebug->leave_sub();
@@ -2074,7 +2077,7 @@ sub _update_custom_variables {
   my $form     = $main::form;
 
   $form->{CVAR_CONFIGS}       ||= { };
-  $form->{CVAR_CONFIGS}->{IC}   = CVar->get_configs(module => 'IC');
+  $form->{CVAR_CONFIGS}->{IC} ||= CVar->get_configs(module => 'IC');
 
   $main::lxdebug->leave_sub();
 }
@@ -2091,30 +2094,31 @@ sub _render_custom_variables_inputs {
     return;
   }
 
-  foreach my $cvar (@{ $form->{CVAR_CONFIGS}->{IC} }) {
-    $cvar->{valid} = $params{part_id}
-      ? CVar->get_custom_variables_validity(config_id => $cvar->{id}, trans_id => $params{part_id})
-      : 0;
-
-    $cvar->{value} = $form->{"ic_cvar_" . $cvar->{name} . "_$params{row}"};
-  }
-
-  CVar->render_inputs(hide_non_editable => 1,
-                      variables         => $form->{CVAR_CONFIGS}->{IC},
-                      name_prefix       => 'ic_',
-                      name_postfix      => "_$params{row}");
+  my $valid = CVar->custom_variables_validity_by_trans_id(trans_id => $params{part_id});
 
   my $num_visible_cvars = 0;
   foreach my $cvar (@{ $form->{CVAR_CONFIGS}->{IC} }) {
+    $cvar->{valid} = $params{part_id} && $valid->($cvar->{id});
+
     my $description = '';
     if ($cvar->{flag_editable} && $cvar->{valid}) {
       $num_visible_cvars++;
       $description = $cvar->{description} . ' ';
     }
 
-    push @{ $params{ROW2} }, { line_break => $num_visible_cvars == 1,
-                               value      => $description . $cvar->{HTML_CODE},
-                             };
+    push @{ $params{ROW2} }, {
+      line_break     => $num_visible_cvars == 1,
+      description    => $description,
+      cvar           => 1,
+      render_options => {
+         hide_non_editable => 1,
+         var               => $cvar,
+         name_prefix       => 'ic_',
+         name_postfix      => "_$params{row}",
+         valid             => $cvar->{valid},
+         value             => $form->{"ic_cvar_" . $cvar->{name} . "_$params{row}"},
+      }
+    };
   }
 
   $main::lxdebug->leave_sub(2);