Ansprechpartner: cp_greeting durch cp_gender ersetzt
[kivitendo-erp.git] / SL / Common.pm
index bedb9e6..bdc4c5d 100644 (file)
@@ -29,6 +29,7 @@ use vars qw(@db_encodings %db_encoding_to_charset);
 );
 
 %db_encoding_to_charset = map { $_->{dbencoding}, $_->{charset} } @db_encodings;
+%charset_to_db_encoding = map { $_->{charset}, $_->{dbencoding} } @db_encodings;
 
 use constant DEFAULT_CHARSET => 'ISO-8859-15';
 
@@ -49,21 +50,32 @@ sub retrieve_parts {
   my $dbh = $form->dbconnect($myconfig);
 
   my (@filter_values, $filter);
-  if ($form->{"partnumber"}) {
-    $filter .= qq| AND (partnumber ILIKE ?)|;
-    push(@filter_values, '%' . $form->{"partnumber"} . '%');
+
+  foreach (qw(partnumber description ean)) {
+    next unless $form->{$_};
+
+    $filter .= qq| AND ($_ ILIKE ?)|;
+    push @filter_values, '%' . $form->{$_} . '%';
   }
-  if ($form->{"description"}) {
-    $filter .= qq| AND (description ILIKE ?)|;
-    push(@filter_values, '%' . $form->{"description"} . '%');
+
+  if ($form->{no_assemblies}) {
+    $filter .= qq| AND (NOT COALESCE(assembly, FALSE))|;
+  }
+  if ($form->{assemblies}) {
+    $filter .= qq| AND assembly=TRUE|;
   }
+
+  if ($form->{no_services}) {
+    $filter .= qq| AND (inventory_accno_id is not NULL or assembly=TRUE)|; # @mb hier nochmal optimieren ... nach kurzer ruecksprache alles i.o.
+  }
+
   substr($filter, 1, 3) = "WHERE" if ($filter);
 
   $order_by =~ s/[^a-zA-Z_]//g;
   $order_dir = $order_dir ? "ASC" : "DESC";
 
   my $query =
-    qq|SELECT id, partnumber, description | .
+    qq|SELECT id, partnumber, description, ean | .
     qq|FROM parts $filter | .
     qq|ORDER BY $order_by $order_dir|;
   my $sth = $dbh->prepare($query);
@@ -182,7 +194,7 @@ sub retrieve_customers_or_vendors {
     push(@queries, qq|SELECT
                         c.id, c.name, 0 AS customer_is_vendor,
                         c.street, c.zipcode, c.city,
-                        ct.cp_greeting, ct.cp_title, ct.cp_givenname, ct.cp_name
+                        ct.cp_gender, ct.cp_title, ct.cp_givenname, ct.cp_name
                       FROM customer c
                       LEFT JOIN contacts ct ON (c.id = ct.cp_cv_id)
                       $c_filter|);
@@ -195,7 +207,7 @@ sub retrieve_customers_or_vendors {
     push(@queries, qq|SELECT
                         v.id, v.name, 1 AS customer_is_vendor,
                         v.street, v.zipcode, v.city,
-                        ct.cp_greeting, ct.cp_title, ct.cp_givenname, ct.cp_name
+                        ct.cp_gender, ct.cp_title, ct.cp_givenname, ct.cp_name
                       FROM vendor v
                       LEFT JOIN contacts ct ON (v.id = ct.cp_cv_id)
                       $v_filter|);
@@ -354,8 +366,8 @@ sub webdav_folder {
     my $base_path = substr($ENV{'SCRIPT_NAME'}, 1);
     $base_path =~ s|[^/]+$||;
     $base_path =~ s|/$||;
-
-    if (opendir $dir, $path) {
+    # wo kommt der wert für dir her? es wird doch gar nichts übergeben? fix für strict my $dir jb 21.2.
+    if (opendir my $dir, $path) {
       foreach my $file (sort { lc $a cmp lc $b } readdir $dir) {
         next if (($file eq '.') || ($file eq '..'));
 
@@ -502,9 +514,23 @@ sub check_params {
   my $params = shift;
 
   foreach my $key (@_) {
-    if (!defined $params->{$key}) {
+    if ((ref $key eq '') && !defined $params->{$key}) {
       my $subroutine = (caller(1))[3];
       $main::form->error($main::locale->text("Missing parameter #1 in call to sub #2.", $key, $subroutine));
+
+    } elsif (ref $key eq 'ARRAY') {
+      my $found = 0;
+      foreach my $subkey (@{ $key }) {
+        if (defined $params->{$subkey}) {
+          $found = 1;
+          last;
+        }
+      }
+
+      if (!$found) {
+        my $subroutine = (caller(1))[3];
+        $main::form->error($main::locale->text("Missing parameter (at least one of #1) in call to sub #2.", join(', ', @{ $key }), $subroutine));
+      }
     }
   }
 }
@@ -513,9 +539,23 @@ sub check_params_x {
   my $params = shift;
 
   foreach my $key (@_) {
-    if (!exists $params->{$key}) {
+    if ((ref $key eq '') && !exists $params->{$key}) {
       my $subroutine = (caller(1))[3];
       $main::form->error($main::locale->text("Missing parameter #1 in call to sub #2.", $key, $subroutine));
+
+    } elsif (ref $key eq 'ARRAY') {
+      my $found = 0;
+      foreach my $subkey (@{ $key }) {
+        if (exists $params->{$subkey}) {
+          $found = 1;
+          last;
+        }
+      }
+
+      if (!$found) {
+        my $subroutine = (caller(1))[3];
+        $main::form->error($main::locale->text("Missing parameter (at least one of #1) in call to sub #2.", join(', ', @{ $key }), $subroutine));
+      }
     }
   }
 }