Auftrags-Controller: hash ref richtig dereferenzieren.
[kivitendo-erp.git] / bin / mozilla / ic.pl
index c9317ab..3328735 100644 (file)
@@ -288,12 +288,9 @@ sub update_prices {
 #  $form->header;
 #
 #  print qq|
+#  <h1>| . $locale->text('choice part') . qq|</h1>
 #  <form method=post action=ic.pl>
 #    <table width=100%>
-#     <tr>
-#      <th class=listtop colspan=6>| . $locale->text('choice part') . qq|</th>
-#     </tr>
-#        <tr height="5"></tr>
 #        <tr class=listheading>
 #          <th>&nbsp;</th>
 #          <th class=listheading>| . $locale->text('Part Number') . qq|</th>
@@ -722,11 +719,9 @@ sub addtop100 {
   my $colspan = $#column_index + 1;
 
   print qq|
+    <h1>$form->{title}</h1>
+
 <table width=100%>
-  <tr>
-    <th class=listtop colspan=$colspan>$form->{title}</th>
-  </tr>
-  <tr height="5"></tr>
 
   <tr><td colspan=$colspan>$option</td></tr>
 
@@ -1028,6 +1023,7 @@ sub generate_report {
     'drawing'            => { 'text' => $locale->text('Drawing'), },
     'ean'                => { 'text' => $locale->text('EAN'), },
     'image'              => { 'text' => $locale->text('Image'), },
+    'insertdate'         => { 'text' => $locale->text('Insert Date'), },
     'invnumber'          => { 'text' => $locale->text('Invoice Number'), },
     'lastcost'           => { 'text' => $locale->text('Last Cost'), },
     'linetotallastcost'  => { 'text' => $locale->text('Extended'), },
@@ -1046,9 +1042,11 @@ sub generate_report {
     'sellprice'          => { 'text' => $locale->text('Sell Price'), },
     'serialnumber'       => { 'text' => $locale->text('Serial Number'), },
     'soldtotal'          => { 'text' => $locale->text('Qty in Selected Records'), },
+    'name'               => { 'text' => $locale->text('Name in Selected Records'), },
     'transdate'          => { 'text' => $locale->text('Transdate'), },
     'unit'               => { 'text' => $locale->text('Unit'), },
     'weight'             => { 'text' => $locale->text('Weight'), },
+    'shop'               => { 'text' => $locale->text('Shopartikel'), },
     'projectnumber'      => { 'text' => $locale->text('Project Number'), },
     'projectdescription' => { 'text' => $locale->text('Project Description'), },
   );
@@ -1133,11 +1131,13 @@ sub generate_report {
     microfiche    => $locale->text('Microfiche')       . ": '$form->{microfiche}'",
     l_soldtotal   => $locale->text('Qty in Selected Records'),
     ean           => $locale->text('EAN')              . ": '$form->{ean}'",
+    insertdatefrom => $locale->text('Insert Date') . ": " . $locale->text('From')       . " " . $locale->date(\%myconfig, $form->{insertdatefrom}, 1),
+    insertdateto   => $locale->text('Insert Date') . ": " . $locale->text('To (time)')  . " " . $locale->date(\%myconfig, $form->{insertdateto}, 1),
   );
 
   my @itemstatus_keys = qw(active obsolete orphaned onhand short);
   my @callback_keys   = qw(onorder ordered rfq quoted bought sold partnumber partsgroup partsgroup_id serialnumber description make model
-                           drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto ean);
+                           drawing microfiche l_soldtotal l_deliverydate transdatefrom transdateto insertdatefrom insertdateto ean shop);
 
   # calculate dependencies
   for (@itemstatus_keys, @callback_keys) {
@@ -1211,7 +1211,11 @@ sub generate_report {
 
     flash('warning', $::locale->text('Soldtotal does not make sense without any bsooqr options'));
   }
+  if ($form->{l_name} && !$bsooqr_mode) {
+    delete $form->{l_name};
 
+    flash('warning', $::locale->text('Name does not make sense without any bsooqr options'));
+  }
   IC->all_parts(\%myconfig, \%$form);
 
   my @columns = qw(
@@ -1219,6 +1223,7 @@ sub generate_report {
     linetotallistprice sellprice linetotalsellprice lastcost linetotallastcost
     priceupdate weight image drawing microfiche invnumber ordnumber quonumber
     transdate name serialnumber deliverydate ean projectnumber projectdescription
+    insertdate shop
   );
 
   my $pricegroups = SL::DB::Manager::Pricegroup->get_all(sort => 'id');
@@ -1243,10 +1248,10 @@ sub generate_report {
 
   %column_defs = (%column_defs, %column_defs_cvars, %column_defs_pricegroups);
   map { $column_defs{$_}->{visible} ||= $form->{"l_$_"} ? 1 : 0 } @columns;
-  map { $column_defs{$_}->{align}   = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal), @pricegroup_columns;
+  map { $column_defs{$_}->{align}   = 'right' } qw(onhand sellprice listprice lastcost linetotalsellprice linetotallastcost linetotallistprice rop weight soldtotal shop), @pricegroup_columns;
 
   my @hidden_variables = (
-    qw(l_subtotal l_linetotal searchitems itemstatus bom l_pricegroups),
+    qw(l_subtotal l_linetotal searchitems itemstatus bom l_pricegroups insertdatefrom insertdateto),
     @itemstatus_keys,
     @callback_keys,
     map({ "cvar_$_->{name}" } @searchable_custom_variables),
@@ -1256,7 +1261,7 @@ sub generate_report {
 
   my $callback         = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
 
-  my @sort_full        = qw(partnumber description onhand soldtotal deliverydate);
+  my @sort_full        = qw(partnumber description onhand soldtotal deliverydate insertdate shop);
   my @sort_no_revers   = qw(partsgroup bin priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
 
   foreach my $col (@sort_full) {
@@ -1350,6 +1355,11 @@ sub generate_report {
 
     $row->{weight}->{data} .= ' ' . $defaults->{weightunit};
 
+    # 'yes' and 'no' for boolean value shop
+    if ($form->{l_shop}) {
+      $row->{shop}{data} = $row->{shop}{data}? $::locale->text('yes') : $::locale->text('no');
+    }
+
     if (!$ref->{assemblyitem}) {
       foreach my $col (@subtotal_columns) {
         $totals{$col}    += $soldtotal * $ref->{$col};
@@ -1633,7 +1643,8 @@ sub form_header {
   CVar->render_inputs('variables' => $form->{CUSTOM_VARIABLES}, show_disabled_message => 1, partsgroup_id => $partsgroup_id)
     if (scalar @{ $form->{CUSTOM_VARIABLES} });
 
-  $::request->layout->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery);
+  $::request->layout->use_javascript("${_}.js") for qw(ckeditor/ckeditor ckeditor/adapters/jquery kivi.PriceRule);
+  $::request->layout->add_javascripts_inline("\$(function(){kivi.PriceRule.load_price_rules_for_part(@{[ $::form->{id} * 1 ]})});") if $::form->{id};
   $form->header;
   #print $form->parse_html_template('ic/form_header', { ALL_PRICE_FACTORS => $form->{ALL_PRICE_FACTORS},
   #                                                     ALL_UNITS         => $form->{ALL_UNITS},
@@ -1641,7 +1652,7 @@ sub form_header {
   #                                                     payment_terms     => $form->{payment_terms},
   #                                                     all_partsgroup    => $form->{all_partsgroup}});
 
-  $form->{show_edit_buttons} = $main::auth->check_right($form->{login}, 'part_service_assembly_edit');
+  $form->{show_edit_buttons} = $main::auth->check_right($::myconfig{login}, 'part_service_assembly_edit');
 
   print $form->parse_html_template('ic/form_header');
   $lxdebug->leave_sub();
@@ -1787,9 +1798,20 @@ sub update {
 
   $auth->assert('part_service_assembly_edit');
 
+  # update checks whether pricegroups, makemodels or assembly items have been changed/added
+  # new items might have been added (and the original form might have been stored and restored)
+  # so at the end the ic form is run through check_form in io.pl
+  # The various combination of events can lead to problems with the order of parse_amount and format_amount
+  # Currently check_form parses some variables in assembly mode, but not in article or service mode
+  # This will only ever really be sanely resolved with a rewrite...
+
   # parse pricegroups. and no, don't rely on check_form for this...
   map { $form->{"price_$_"} = $form->parse_amount(\%myconfig, $form->{"price_$_"}) } 1 .. $form->{price_rows};
-  $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) for qw(sellprice listprice ve gv);
+
+  unless ($form->{item} eq 'assembly') {
+    # for assemblies check_form will parse sellprice and listprice, but not for parts or services
+    $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) for qw(sellprice listprice ve gv);
+  };
 
   if ($form->{item} eq 'part') {
     $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) for qw(weight rop);
@@ -1809,13 +1831,16 @@ sub update {
     if (   ($form->{"partnumber_$i"} eq "")
         && ($form->{"description_$i"} eq "")
         && ($form->{"partsgroup_$i"}  eq "")) {
+      # no new assembly item was added
 
       &check_form;
 
     } else {
-
+      # search db for newly added assemblyitems, via partnumber or description
       IC->assembly_item(\%myconfig, \%$form);
 
+      # form->{item_list} contains the possible matches, next check whether the
+      # match is unique or we need to call the page to select the item
       my $rows = scalar @{ $form->{item_list} };
 
       if ($rows) {
@@ -1823,7 +1848,7 @@ sub update {
 
         if ($rows > 1) {
           $form->{makemodel_rows}--;
-          select_item(mode => 'IC');
+          select_item(mode => 'IC', pre_entered_qty => $form->parse_amount(\%myconfig, $form->{"qty_$i"}));
           ::end_of_request();
         } else {
           map { $form->{item_list}[$i]{$_} =~ s/\"/&quot;/g }
@@ -1858,7 +1883,7 @@ sub save {
   $lxdebug->enter_sub();
 
   $auth->assert('part_service_assembly_edit');
-
+  $::form->mtime_ischanged('parts');
   my ($parts_id, %newform, $amount, $callback);
 
   # check if there is a part number - commented out, cause there is an automatic allocation of numbers
@@ -1890,8 +1915,9 @@ sub save {
   }
   # saving the history
   if(!exists $form->{addition}) {
-    $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
-    $form->{addition} = "SAVED";
+    $form->{snumbers}  = qq|partnumber_| . $form->{partnumber};
+    $form->{what_done} = "part";
+    $form->{addition}  = "SAVED";
     $form->save_history;
   }
   # /saving the history
@@ -2018,8 +2044,9 @@ sub save_as_new {
 
   # saving the history
   if(!exists $form->{addition}) {
-    $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
-    $form->{addition} = "SAVED AS NEW";
+    $form->{snumbers}  = qq|partnumber_| . $form->{partnumber};
+    $form->{addition}  = "SAVED AS NEW";
+    $form->{what_done} = "part";
     $form->save_history;
   }
   # /saving the history
@@ -2039,8 +2066,9 @@ sub delete {
 
   # saving the history
   if(!exists $form->{addition}) {
-    $form->{snumbers} = qq|partnumber_| . $form->{partnumber};
-    $form->{addition} = "DELETED";
+    $form->{snumbers}  = qq|partnumber_| . $form->{partnumber};
+    $form->{addition}  = "DELETED";
+    $form->{what_done} = "part";
     $form->save_history;
   }
   # /saving the history