Kosmetik.
[kivitendo-erp.git] / SL / IC.pm
index c710af9..0bf015f 100644 (file)
--- a/SL/IC.pm
+++ b/SL/IC.pm
@@ -41,6 +41,8 @@ use YAML;
 use SL::CVar;
 use SL::DBUtils;
 
+use strict;
+
 sub get_part {
   $main::lxdebug->enter_sub();
 
@@ -792,8 +794,8 @@ sub all_parts {
     pfac       => 'LEFT JOIN price_factors pfac ON (pfac.id     = p.price_factor_id)',
     invoice_oi =>
       q|LEFT JOIN (
-         SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty,          assemblyitem,         deliverydate, 'invoice'    AS ioi FROM invoice UNION
-         SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, FALSE AS assemblyitem, NULL AS deliverydate, 'orderitems' AS ioi FROM orderitems
+         SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty,          assemblyitem,         deliverydate, 'invoice'    AS ioi, id FROM invoice UNION
+         SELECT parts_id, description, serialnumber, trans_id, unit, sellprice, qty, FALSE AS assemblyitem, NULL AS deliverydate, 'orderitems' AS ioi, id FROM orderitems
        ) AS ioi ON ioi.parts_id = p.id|,
     apoe       =>
       q|LEFT JOIN (
@@ -824,6 +826,8 @@ sub all_parts {
      serialnumber => 'ioi.',
      quotation    => 'apoe.',
      cv           => 'cv.',
+     "ioi.id"     => ' ',
+     "ioi.ioi"    => ' ',
   );
 
   # if the join condition in these blocks are met, the column
@@ -835,12 +839,15 @@ sub all_parts {
     [ 'deliverydate', 'ioi.',  'invoice_oi'  ],
     [ 'transdate',    'apoe.', 'apoe'        ],
     [ 'unit',         'ioi.',  'invoice_oi'  ],
+    [ 'sellprice',    'ioi.',  'invoice_oi'  ],
   );
 
   # careful with renames. these are HARD, and any filters done on the original column will break
   my %renamed_columns = (
     'factor'       => 'price_factor',
     'SUM(ioi.qty)' => 'soldtotal',
+    'ioi.id'       => 'ioi_id',
+    'ioi.ioi'      => 'ioi',
   );
 
   if (($form->{searchitems} eq 'assembly') && $form->{l_lastcost}) {
@@ -937,7 +944,7 @@ sub all_parts {
   my $bsooqr        = any { $form->{$_} } @oe_flags;
   my @bsooqr_tokens = ();
 
-  push @select_tokens, @qsooqr_flags, 'quotation', 'cv'                       if $bsooqr;
+  push @select_tokens, @qsooqr_flags, 'quotation', 'cv', 'ioi.id', 'ioi.ioi'  if $bsooqr;
   push @select_tokens, @deliverydate_flags                                    if $bsooqr && $form->{l_deliverydate};
   push @select_tokens, $q_assembly_lastcost                                   if ($form->{searchitems} eq 'assembly') && $form->{l_lastcost};
   push @bsooqr_tokens, q|module = 'ir' AND NOT ioi.assemblyitem|              if $form->{bought};
@@ -1005,7 +1012,15 @@ sub all_parts {
     push @bind_vars, @cvar_values;
   }
 
-  my $query = qq|SELECT DISTINCT $select_clause FROM parts p $join_clause WHERE $where_clause $group_clause $order_clause $limit_clause|;
+  my $query = <<"  SQL";
+    SELECT DISTINCT $select_clause
+    FROM parts p
+    $join_clause
+    WHERE $where_clause
+    $group_clause
+    $order_clause
+    $limit_clause
+  SQL
 
   $form->{parts} = selectall_hashref_query($form, $dbh, $query, @bind_vars);