Lieferanten/Kunden Namen richtig escapen
[kivitendo-erp.git] / bin / mozilla / io.pl
index f890cee..f3e92dc 100644 (file)
@@ -193,9 +193,11 @@ sub display_row {
 
   _update_part_information();
   _update_ship() if ($is_s_p_order);
+  _update_custom_variables();
 
   # rows
   for $i (1 .. $numrows) {
+    my %column_data = ();
 
     # undo formatting
     map { $form->{"${_}_$i"} = $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(qty discount sellprice price_new price_old) unless ($form->{simple_save});
@@ -260,7 +262,7 @@ sub display_row {
     if ($form->{"id_$i"}) {
       my $ship_qty        = $form->{"ship_$i"} * 1;
       $ship_qty          *= $all_units->{$form->{"partunit_$i"}}->{factor};
-      $ship_qty          /= $all_units->{$form->{"unit_$i"}}->{factor};
+      $ship_qty          /= ( $all_units->{$form->{"unit_$i"}}->{factor} || 1 );
 
       $column_data{ship}  = $form->format_amount(\%myconfig, $form->round_amount($ship_qty, 2) * 1) . ' ' . $form->{"unit_$i"};
     }
@@ -335,6 +337,19 @@ sub display_row {
       if $form->{"id_$i"} && ($form->{type} =~ /^sales_/ ||  $form->{type} =~ /invoice/) && !$is_delivery_order;
 # / marge calculations ending
 
+# calculate onhand
+    if ($form->{"id_$i"}) {
+      my $part         = IC->get_basic_part_info(id => $form->{"id_$i"});
+      my $onhand_color = 'color="#ff0000"' if  $part->{onhand} < $part->{rop};
+      push @ROW2, { value => sprintf "<b>%s</b> <font %s>%s %s</font>",
+                      $locale->text('On Hand'),
+                      $onhand_color,
+                      $form->format_amount(\%myconfig, $part->{onhand}, 2),
+                      $part->{unit}
+      };
+    }
+# / calculate onhand
+
     my @hidden_vars;
 
     if ($is_delivery_order) {
@@ -356,6 +371,9 @@ sub display_row {
 
     $form->{invsubtotal} += $linetotal;
 
+    # Benutzerdefinierte Variablen für Waren/Dienstleistungen/Erzeugnisse
+    _render_custom_variables_inputs(ROW2 => \@ROW2, row => $i, part_id => $form->{"id_$i"});
+
     push @ROWS, { ROW1 => \@ROW1, ROW2 => \@ROW2, HIDDENS => \@HIDDENS, colspan => $colspan, error => $form->{"row_error_$i"}, };
   }
 
@@ -441,6 +459,13 @@ sub select_item {
 
   print qq|</tr>|;
 
+  my @new_fields =
+    qw(bin listprice inventory_accno income_accno expense_accno unit weight
+       assembly taxaccounts partsgroup formel longdescription not_discountable
+       part_payment_id partnotes id lastcost price_factor_id price_factor);
+  push @new_fields, "lizenzen" if ($lizenzen);
+  push @new_fields, grep { m/^ic_cvar_/ } keys %{ $form->{item_list}->[0] };
+
   my $i = 0;
   foreach $ref (@{ $form->{item_list} }) {
     $checked = ($i++) ? "" : "checked";
@@ -494,12 +519,6 @@ sub select_item {
 
     print("</tr>\n");
 
-    my @new_fields =
-      qw(bin listprice inventory_accno income_accno expense_accno unit weight
-         assembly taxaccounts partsgroup formel longdescription not_discountable
-         part_payment_id partnotes id lastcost price_factor_id price_factor);
-    push(@new_fields, "lizenzen") if ($lizenzen);
-
     print join "\n", map { $cgi->hidden("-name" => "new_${_}_$i", "-value" => $ref->{$_}) } @new_fields;
     print "\n";
   }
@@ -562,6 +581,9 @@ sub item_selected {
        partsgroup formel longdescription not_discountable partnotes lastcost
        price_factor_id price_factor);
 
+  my $ic_cvar_configs = CVar->get_configs(module => 'IC');
+  push @new_fields, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs };
+
   map { $form->{"${_}_$i"} = $form->{"new_${_}_$j"} } @new_fields;
 
   $form->{"marge_price_factor_$i"} = $form->{"new_price_factor_$j"};
@@ -672,16 +694,6 @@ sub check_form {
   my @a     = ();
   my $count = 0;
 
-  my @flds = qw(id partnumber description qty ship sellprice unit
-                discount inventory_accno income_accno expense_accno listprice
-                taxaccounts bin assembly weight projectnumber project_id
-                oldprojectnumber runningnumber serialnumber partsgroup payment_id
-                not_discountable shop ve gv buchungsgruppen_id language_values
-                sellprice_pg pricegroup_old price_old price_new unit_old ordnumber
-                transdate longdescription basefactor marge_total marge_percent
-                marge_price_factor lastcost price_factor_id partnotes
-                stock_out stock_in);
-
   # remove any makes or model rows
   if ($form->{item} eq 'part') {
     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
@@ -695,8 +707,7 @@ sub check_form {
     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) }
       qw(listprice sellprice rop stock);
 
-    @flds =
-      qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup lastcost);
+    my @flds = qw(id qty unit bom partnumber description sellprice weight runningnumber partsgroup lastcost);
 
     for my $i (1 .. ($form->{assembly_rows} - 1)) {
       if ($form->{"qty_$i"}) {
@@ -725,6 +736,18 @@ sub check_form {
     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(listprice sellprice lastcost);
 
   } else {
+    my @flds = qw(id partnumber description qty ship sellprice unit
+                  discount inventory_accno income_accno expense_accno listprice
+                  taxaccounts bin assembly weight projectnumber project_id
+                  oldprojectnumber runningnumber serialnumber partsgroup payment_id
+                  not_discountable shop ve gv buchungsgruppen_id language_values
+                  sellprice_pg pricegroup_old price_old price_new unit_old ordnumber
+                  transdate longdescription basefactor marge_total marge_percent
+                  marge_price_factor lastcost price_factor_id partnotes
+                  stock_out stock_in has_sernumber);
+
+    my $ic_cvar_configs = CVar->get_configs(module => 'IC');
+    push @flds, map { "ic_cvar_$_->{name}" } @{ $ic_cvar_configs };
 
     # this section applies to invoices and orders
     # remove any empty numbers
@@ -872,7 +895,7 @@ sub order {
   $script =~ s|.pl$||;
   $locale = new Locale($language, $script);
 
-  map { $form->{"select$_"} = "" } ($form->{vc}, currency);
+  map { $form->{"select$_"} = "" } ($form->{vc}, "currency");
 
   $currency = $form->{currency};
 
@@ -1426,10 +1449,9 @@ sub print_form {
   }
 
   if ($form->{language} ne "") {
-    map({ $form->{"unit"}->[$_] =
-            AM->translate_units($form, $form->{"language"},
-                                $form->{"unit"}->[$_], $form->{"qty"}->[$_]); }
-        (0..scalar(@{$form->{"unit"}}) - 1));
+    my $template_arrays = $form->{TEMPLATE_ARRAYS} || $form;
+    map { $template_arrays->{unit}->[$_] = AM->translate_units($form, $form->{language}, $template_arrays->{unit}->[$_], $template_arrays->{qty}->[$_]); } (0..scalar(@{ $template_arrays->{unit} }) - 1);
+
     $form->{language} = "_" . $form->{language};
   }
 
@@ -1936,3 +1958,51 @@ sub _update_ship {
 
   $lxdebug->leave_sub();
 }
+
+sub _update_custom_variables {
+  $lxdebug->enter_sub();
+
+  $form->{CVAR_CONFIGS}       ||= { };
+  $form->{CVAR_CONFIGS}->{IC}   = CVar->get_configs(module => 'IC');
+
+  $lxdebug->leave_sub();
+}
+
+sub _render_custom_variables_inputs {
+  $lxdebug->enter_sub();
+
+  my %params = @_;
+
+  if (!$form->{CVAR_CONFIGS}->{IC}) {
+    $lxdebug->leave_sub();
+    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})
+      : 1;
+
+    $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 $num_visible_cvars = 0;
+  foreach my $cvar (@{ $form->{CVAR_CONFIGS}->{IC} }) {
+    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},
+                             };
+  }
+
+  $lxdebug->leave_sub();
+}