Kontoauszug verbuchen - Punktesystem sichtbar machen
[kivitendo-erp.git] / SL / PE.pm
index 31a8bd5..2eb7201 100644 (file)
--- a/SL/PE.pm
+++ b/SL/PE.pm
@@ -52,13 +52,16 @@ sub partsgroups {
 
   if ($form->{partsgroup}) {
     $where .= qq| AND partsgroup ILIKE ?|;
-    push(@values, '%' . $form->{partsgroup} . '%');
+    push(@values, like($form->{partsgroup}));
   }
 
   if ($form->{status} eq 'orphaned') {
     $where .=
       qq| AND id NOT IN | .
       qq|  (SELECT DISTINCT partsgroup_id FROM parts | .
+      qq|   WHERE NOT partsgroup_id ISNULL | .
+      qq| UNION | .
+      qq|   SELECT DISTINCT partsgroup_id FROM custom_variable_config_partsgroups | .
       qq|   WHERE NOT partsgroup_id ISNULL) |;
   }
 
@@ -96,7 +99,7 @@ sub save_partsgroup {
 
   if ($form->{id}) {
     $query = qq|UPDATE partsgroup SET partsgroup = ? WHERE id = ?|;
-               push(@values, $form->{id});
+    push(@values, $form->{id});
   } else {
     $query = qq|INSERT INTO partsgroup (partsgroup) VALUES (?)|;
   }
@@ -129,6 +132,12 @@ sub get_partsgroup {
 
   $dbh->disconnect;
 
+  # also not orphaned if partsgroup is selected for a cvar filter
+  if ($form->{orphaned}) {
+    my $cvar_count = scalar( @{ SL::DB::PartsGroup->new(id => $form->{id})->custom_variable_configs } );
+    $form->{orphaned} = !$cvar_count;
+  }
+
   $main::lxdebug->leave_sub();
 }
 
@@ -165,14 +174,14 @@ sub pricegroups {
 
   if ($form->{pricegroup}) {
     $where .= qq| AND pricegroup ILIKE ?|;
-    push(@values, '%' . $form->{pricegroup} . '%');
+    push(@values, like($form->{pricegroup}));
   }
 
   if ($form->{status} eq 'orphaned') {
     my $first = 1;
 
     $where .= qq| AND id NOT IN (|;
-    foreach my $table (qw(invoice orderitems prices rmaitems)) {
+    foreach my $table (qw(invoice orderitems prices)) {
       $where .= "UNION " unless ($first);
       $first = 0;
       $where .=
@@ -219,7 +228,7 @@ sub save_pricegroup {
 
   if ($form->{id}) {
     $query = qq|UPDATE pricegroup SET pricegroup = ? WHERE id = ? |;
-               push(@values, $form->{id});
+    push(@values, $form->{id});
   } else {
     $query = qq|INSERT INTO pricegroup (pricegroup) VALUES (?)|;
   }
@@ -253,7 +262,7 @@ sub get_pricegroup {
 
   my @values = ();
   $query = qq|SELECT |;
-  foreach my $table (qw(invoice orderitems prices rmaitems)) {
+  foreach my $table (qw(invoice orderitems prices)) {
     $query .= " + " unless ($first);
     $first = 0;
     $query .= qq|(SELECT COUNT(*) FROM $table WHERE pricegroup_id = ?) |;