auch ids müssen in der Multibox escaped werden.
[kivitendo-erp.git] / bin / mozilla / io.pl
index b796a7b..07db7ea 100644 (file)
@@ -151,7 +151,7 @@ sub display_row {
     {  id => 'serialnr',      width => 10,    value => $locale->text('Serial No.'),           display => 0, },
     {  id => 'projectnr',     width => 10,    value => $locale->text('Project'),              display => 0, },
     {  id => 'sellprice',     width => 15,    value => $locale->text('Price'),                display => !$is_delivery_order, },
-    {  id => 'sellprice_pg',  width => 8,     value => $locale->text('Pricegroup'),           display => ($form->{type} =~ /^sales_/) && !$is_delivery_order,  },
+    {  id => 'sellprice_pg',  width => 8,     value => $locale->text('Pricegroup'),           display => ($form->{type} =~ /^(sales_|invoice)/) && !$is_delivery_order,  },
     {  id => 'discount',      width => 5,     value => $locale->text('Discount'),             display => !$is_delivery_order, },
     {  id => 'linetotal',     width => 10,    value => $locale->text('Extended'),             display => !$is_delivery_order, },
     {  id => 'bin',           width => 10,    value => $locale->text('Bin'),                  display => 0, },
@@ -245,8 +245,7 @@ sub display_row {
     $column_data{"unit"} = AM->unit_select_html($all_units, "unit_$i", $this_unit, $form->{"id_$i"} ? $form->{"unit_$i"} : undef);
 # / unit ending
 
-    $form->{"sellprice_$i"} =~ /\.(\d+)/;
-    my $decimalplaces = max 2, length $1;
+    my $decimalplaces = ($form->{"sellprice_$i"} =~ /\.(\d+)/) ? max 2, length $1 : 2;
 
     my $price_factor   = $price_factors{$form->{"price_factor_id_$i"}} || 1;
     my $discount       = $form->round_amount($form->{"qty_$i"} * $form->{"sellprice_$i"} *        $form->{"discount_$i"}  / 100 / $price_factor, 2);
@@ -260,8 +259,7 @@ sub display_row {
                                 : $cgi->textfield(-name => "description_$i",   -size => 30, -value => $form->{"description_$i"}))
                                 . $cgi->button(-value => $locale->text('L'), -onClick => "set_longdescription_window('longdescription_$i')");
 
-    $form->{"qty_$i"} =~ /\.(\d+)/;
-    my $qty_dec = length $1;
+    my $qty_dec = ($form->{"qty_$i"} =~ /\.(\d+)/) ? length $1 : 2;
 
     $column_data{qty}  = $cgi->textfield(-name => "qty_$i", -size => 5, -value => $form->format_amount(\%myconfig, $form->{"qty_$i"}, $qty_dec));
     $column_data{qty} .= $cgi->button(-onclick => "calculate_qty_selection_window('qty_$i','alu_$i', 'formel_$i', $i)", -value => $locale->text('*/'))
@@ -319,24 +317,24 @@ sub display_row {
                    $locale->text('Subtotal'), $form->{"subtotal_$i"} ? 'checked' : '' };
 
 # begin marge calculations
-    my $marge_color;
-    my $real_sellprice     = ($form->{"sellprice_$i"} - $discount) / $price_factor;
-    my $marge_price_factor = $form->{"marge_price_factor_$i"} * 1 || 1;
-
-    $form->{"lastcost_$i"} *= 1;
+    $form->{"lastcost_$i"}     *= 1;
     $form->{"marge_percent_$i"} = 0;
 
-    if ($real_sellprice && ($form->{"qty_$i"} * 1)) {
-      $form->{"marge_percent_$i"}     = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * 100 / $real_sellprice;
-      $myconfig{marge_percent_warn} ||= 15;
-      $marge_color                    = 'color="#ff0000"' if $form->{"id_$i"} && ($form->{"marge_percent_$i"} < (1 * $myconfig{marge_percent_warn}));
+    my $marge_color;
+    my $real_sellprice           = $linetotal;
+    my $real_lastcost            = $form->{"lastcost_$i"} * $form->{"qty_$i"} / ( $form->{"marge_price_factor_$i"} || 1 );
+    my $marge_percent_warn       = $myconfig{marge_percent_warn} * 1 || 15;
+    my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
+
+    if ($real_sellprice * 1 && ($form->{"qty_$i"} * 1)) {
+      $form->{"marge_percent_$i"} = ($real_sellprice - $real_lastcost) * 100 / $real_sellprice;
+      $marge_color                = 'color="#ff0000"' if $form->{"id_$i"} && $form->{"marge_percent_$i"} < $marge_percent_warn;
     }
 
-    my $marge_adjust_credit_note = $form->{type} eq 'credit_note' ? -1 : 1;
-    $form->{"marge_absolut_$i"}  = ($real_sellprice - $form->{"lastcost_$i"} / $marge_price_factor) * $form->{"qty_$i"} * $marge_adjust_credit_note;
+    $form->{"marge_absolut_$i"}  = ($real_sellprice - $real_lastcost) * $marge_adjust_credit_note;
     $form->{"marge_total"}      += $form->{"marge_absolut_$i"};
-    $form->{"lastcost_total"}   += $form->{"lastcost_$i"} * $form->{"qty_$i"} / $marge_price_factor;
-    $form->{"sellprice_total"}  += $real_sellprice * $form->{"qty_$i"};
+    $form->{"lastcost_total"}   += $real_lastcost;
+    $form->{"sellprice_total"}  += $real_sellprice;
 
     map { $form->{"${_}_$i"} = $form->format_amount(\%myconfig, $form->{"${_}_$i"}, 2) } qw(marge_absolut marge_percent);
 
@@ -752,7 +750,7 @@ sub check_form {
         #($form->{"sellprice_$i"},$form->{"$pricegroup_old_$i"}) = split /--/, $form->{"sellprice_$i"};
 
         # fuer assemblies auskommentiert. siehe oben
-       #    $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"} / ($form->{"price_factor_$i"} || 1));
+        #    $form->{sellprice} += ($form->{"qty_$i"} * $form->{"sellprice_$i"} / ($form->{"price_factor_$i"} || 1));
         $form->{weight}    += ($form->{"qty_$i"} * $form->{"weight_$i"} / ($form->{"price_factor_$i"} || 1));
         $count++;
       }
@@ -1210,7 +1208,7 @@ sub print_options {
     );
 
   my %template_vars = (
-    display_copies       => scalar @{ $form->{printers} } && $main::latex_templates && $form->{media} ne 'email',
+    display_copies       => scalar @{ $form->{printers} || [] } && $main::latex_templates && $form->{media} ne 'email',
     display_remove_draft => (!$form->{id} && $form->{draft_id}),
     display_groupitems   => !$dont_display_groupitems{$form->{type}},
     groupitems_checked   => $form->{groupitems} ? "checked" : '',
@@ -1423,10 +1421,10 @@ sub print_form {
 
       call_sub($display_form);
       # saving the history
-         if(!exists $form->{addition}) {
+      if(!exists $form->{addition}) {
         $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
-           $form->{addition} = "PRINTED";
-           $form->save_history($form->dbconnect(\%myconfig));
+        $form->{addition} = "PRINTED";
+        $form->save_history($form->dbconnect(\%myconfig));
       }
       # /saving the history
       exit;
@@ -1643,16 +1641,16 @@ sub print_form {
   if(!exists $form->{addition}) {
     $form->{snumbers} = qq|ordnumber_| . $form->{ordnumber};
     if($form->{media} =~ /printer/) {
-       $form->{addition} = "PRINTED";
+      $form->{addition} = "PRINTED";
     }
     elsif($form->{media} =~ /email/) {
-       $form->{addition} = "MAILED";
+      $form->{addition} = "MAILED";
     }
     elsif($form->{media} =~ /queue/) {
-       $form->{addition} = "QUEUED";
+      $form->{addition} = "QUEUED";
     }
     elsif($form->{media} =~ /screen/) {
-       $form->{addition} = "SCREENED";
+      $form->{addition} = "SCREENED";
     }
     $form->save_history($form->dbconnect(\%myconfig));
   }
@@ -1811,72 +1809,72 @@ sub ship_to {
   <tr>
     <td>
       <table>
-       <tr class="listheading">
-         <th class="listheading" colspan="2" width="50%">|
+        <tr class="listheading">
+          <th class="listheading" colspan="2" width="50%">|
     . $locale->text('Billing Address') . qq|</th>
-         <th class="listheading" width="50%">|
+          <th class="listheading" width="50%">|
     . $locale->text('Shipping Address') . qq|</th>
-       </tr>
-       <tr height="5"></tr>
-       <tr>
-         <th align="right" nowrap>$number</th>
-         <td>$form->{"$form->{vc}number"}</td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>| . $locale->text('Company Name') . qq|</th>
-         <td>$form->{name}</td>
-         <td><input name="shiptoname" size="35" value="$form->{shiptoname}"></td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
-         <td>$form->{department_1}</td>
-         <td><input name="shiptodepartment_1" size="35" value="$form->{shiptodepartment_1}"></td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>&nbsp;</th>
-         <td>$form->{department_2}</td>
-         <td><input name="shiptodepartment_2" size="35" value="$form->{shiptodepartment_2}"></td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>| . $locale->text('Street') . qq|</th>
-         <td>$form->{street}</td>
-         <td><input name="shiptostreet" size="35" value="$form->{shiptostreet}"></td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>| . $locale->text('Zipcode') . qq|</th>
-         <td>$form->{zipcode}</td>
-         <td><input name="shiptozipcode" size="35" value="$form->{shiptozipcode}"></td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>| . $locale->text('City') . qq|</th>
-         <td>$form->{city}</td>
-         <td><input name="shiptocity" size="35" value="$form->{shiptocity}"></td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>| . $locale->text('Country') . qq|</th>
-         <td>$form->{country}</td>
-         <td><input name="shiptocountry" size="35" value="$form->{shiptocountry}"></td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>| . $locale->text('Contact') . qq|</th>
-         <td>$form->{contact}</td>
-         <td><input name="shiptocontact" size="35" value="$form->{shiptocontact}"></td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>| . $locale->text('Phone') . qq|</th>
-         <td>$form->{phone}</td>
-         <td><input name="shiptophone" size="20" value="$form->{shiptophone}"></td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>| . $locale->text('Fax') . qq|</th>
-         <td>$form->{fax}</td>
-         <td><input name="shiptofax" size="20" value="$form->{shiptofax}"></td>
-       </tr>
-       <tr>
-         <th align="right" nowrap>| . $locale->text('E-mail') . qq|</th>
-         <td>$form->{email}</td>
-         <td><input name="shiptoemail" size="35" value="$form->{shiptoemail}"></td>
-       </tr>
+        </tr>
+        <tr height="5"></tr>
+        <tr>
+          <th align="right" nowrap>$number</th>
+          <td>$form->{"$form->{vc}number"}</td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>| . $locale->text('Company Name') . qq|</th>
+          <td>$form->{name}</td>
+          <td><input name="shiptoname" size="35" value="$form->{shiptoname}"></td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>| . $locale->text('Department') . qq|</th>
+          <td>$form->{department_1}</td>
+          <td><input name="shiptodepartment_1" size="35" value="$form->{shiptodepartment_1}"></td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>&nbsp;</th>
+          <td>$form->{department_2}</td>
+          <td><input name="shiptodepartment_2" size="35" value="$form->{shiptodepartment_2}"></td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>| . $locale->text('Street') . qq|</th>
+          <td>$form->{street}</td>
+          <td><input name="shiptostreet" size="35" value="$form->{shiptostreet}"></td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>| . $locale->text('Zipcode') . qq|</th>
+          <td>$form->{zipcode}</td>
+          <td><input name="shiptozipcode" size="35" value="$form->{shiptozipcode}"></td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>| . $locale->text('City') . qq|</th>
+          <td>$form->{city}</td>
+          <td><input name="shiptocity" size="35" value="$form->{shiptocity}"></td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>| . $locale->text('Country') . qq|</th>
+          <td>$form->{country}</td>
+          <td><input name="shiptocountry" size="35" value="$form->{shiptocountry}"></td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>| . $locale->text('Contact') . qq|</th>
+          <td>$form->{contact}</td>
+          <td><input name="shiptocontact" size="35" value="$form->{shiptocontact}"></td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>| . $locale->text('Phone') . qq|</th>
+          <td>$form->{phone}</td>
+          <td><input name="shiptophone" size="20" value="$form->{shiptophone}"></td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>| . $locale->text('Fax') . qq|</th>
+          <td>$form->{fax}</td>
+          <td><input name="shiptofax" size="20" value="$form->{shiptofax}"></td>
+        </tr>
+        <tr>
+          <th align="right" nowrap>| . $locale->text('E-mail') . qq|</th>
+          <td>$form->{email}</td>
+          <td><input name="shiptoemail" size="35" value="$form->{shiptoemail}"></td>
+        </tr>
       </table>
     </td>
   </tr>
@@ -2079,7 +2077,7 @@ sub _update_custom_variables {
 }
 
 sub _render_custom_variables_inputs {
-  $main::lxdebug->enter_sub();
+  $main::lxdebug->enter_sub(2);
 
   my $form     = $main::form;
 
@@ -2116,5 +2114,5 @@ sub _render_custom_variables_inputs {
                              };
   }
 
-  $main::lxdebug->leave_sub();
+  $main::lxdebug->leave_sub(2);
 }