]> wagnertech.de Git - kivitendo-erp.git/blobdiff - SL/IC.pm
Regex korrekt escapen und Debugmeldungen.
[kivitendo-erp.git] / SL / IC.pm
index c9511b4db52a461718adf4aa95af673948b2874d..eaa932c00768ad3d9123917dfc8743f07a260222 100644 (file)
--- a/SL/IC.pm
+++ b/SL/IC.pm
@@ -829,8 +829,8 @@ sub all_parts {
     #  column name,   prefix,  joins_needed
     [ 'description',  'ioi.',  'invoice_oi'  ],
     [ 'deliverydate', 'ioi.',  'invoice_oi'  ],
-    [ 'transdate' ,   'apoe.', 'apoe'  ],
-    [ 'unit' ,        'ioi.',  'invoice_oi'  ],
+    [ 'transdate',    'apoe.', 'apoe'        ],
+    [ 'unit'        'ioi.',  'invoice_oi'  ],
   );
 
   # careful with renames. these are HARD, and any filters done on the original column will break
@@ -846,18 +846,18 @@ sub all_parts {
   my $make_token_builder = sub {
     my $joins_needed = shift;
     sub {
-      my ($col, $group) = @_;
+      my ($col, $alias) = @_;
       my @coalesce_tokens =
         map  { ($_->[1] || 'p.') . $_->[0] }
         grep { !$_->[2] || $joins_needed->{$_->[2]} }
-        grep { $_->[0] eq $col }
+        grep {  $_->[0] eq $col }
         @column_override, [ $col, $table_prefix{$col} ];
 
       my $coalesce = scalar @coalesce_tokens > 1;
       return ($coalesce
         ? sprintf 'COALESCE(%s)', join ', ', @coalesce_tokens
         : shift                              @coalesce_tokens)
-        . ($group && ($coalesce || $renamed_columns{$col})
+        . ($alias && ($coalesce || $renamed_columns{$col})
         ?  " AS " . ($renamed_columns{$col} || $col)
         : '');
     }
@@ -944,9 +944,6 @@ sub all_parts {
   push @bsooqr_tokens, q|module = 'oe' AND     quotation AND cv = 'vendor'|   if $form->{rfq};
   push @where_tokens, join ' OR ', map { "($_)" } @bsooqr_tokens              if $bsooqr;
 
-  $renamed_columns{onhand} = 'onhand_before_bsooqr';
-  $renamed_columns{qty}    = 'onhand';
-
   $joins_needed{partsgroup}  = 1;
   $joins_needed{pfac}        = 1;
   $joins_needed{makemodel}   = 1 if grep { $form->{$_} || $form->{"l_$_"} } @makemodel_filters;
@@ -954,6 +951,12 @@ sub all_parts {
   $joins_needed{apoe}        = 1 if $joins_needed{cv}   || grep { $form->{$_} || $form->{"l_$_"} } @apoe_filters;
   $joins_needed{invoice_oi}  = 1 if $joins_needed{apoe} || grep { $form->{$_} || $form->{"l_$_"} } @invoice_oi_filters;
 
+  # in bsoorq, use qtys instead of onhand
+  if ($joins_needed{invoice_oi}) {
+    $renamed_columns{onhand} = 'onhand_before_bsooqr';
+    $renamed_columns{qty}    = 'onhand';
+  }
+
   # special case for description search.
   # up in the simple filter section the description filter got interpreted as something like: WHERE description ILIKE '%$form->{description}%'
   # now we'd like to search also for the masked description entered in orderitems and invoice, so...