From 88dea78ecdb77761f71c5016ca97e53b2d55d9d3 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 1 Apr 2016 17:19:46 +0200 Subject: [PATCH] =?utf8?q?Einkaufs-/Verkaufssuchen:=20bei=20Textfeldern=20?= =?utf8?q?f=C3=BChrende/anh=C3=A4ngende=20Whitespaces=20entfernen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/AP.pm | 7 ++++--- SL/AR.pm | 15 ++++++++------- SL/CVar.pm | 9 +++++---- SL/DBUtils.pm | 6 +++++- SL/DN.pm | 7 ++++--- SL/DO.pm | 9 +++++---- SL/Form.pm | 13 ++----------- SL/OE.pm | 15 ++++++++------- 8 files changed, 41 insertions(+), 40 deletions(-) diff --git a/SL/AP.pm b/SL/AP.pm index bbddd6e8c..e3dc7b31d 100644 --- a/SL/AP.pm +++ b/SL/AP.pm @@ -39,6 +39,7 @@ use SL::DBUtils; use SL::IO; use SL::MoreCommon; use SL::DB::Default; +use SL::Util qw(trim); use Data::Dumper; use strict; @@ -457,7 +458,7 @@ sub ap_transactions { } if ($form->{"cp_name"}) { $where .= " AND (cp.cp_name ILIKE ? OR cp.cp_givenname ILIKE ?)"; - push(@values, ('%' . $form->{"cp_name"} . '%')x2); + push(@values, ('%' . trim($form->{"cp_name"}) . '%')x2); } if ($form->{department}) { # ähnlich wie commit 0bbfb33b6aa8e38bb6c81d1684ab7d08e5b5c5af abteilung @@ -493,11 +494,11 @@ sub ap_transactions { if ($form->{transdatefrom}) { $where .= " AND a.transdate >= ?"; - push(@values, $form->{transdatefrom}); + push(@values, trim($form->{transdatefrom})); } if ($form->{transdateto}) { $where .= " AND a.transdate <= ?"; - push(@values, $form->{transdateto}); + push(@values, trim($form->{transdateto})); } if ($form->{open} || $form->{closed}) { unless ($form->{open} && $form->{closed}) { diff --git a/SL/AR.pm b/SL/AR.pm index 405a7f2fc..a2cad1196 100644 --- a/SL/AR.pm +++ b/SL/AR.pm @@ -41,6 +41,7 @@ use SL::IO; use SL::MoreCommon; use SL::DB::Default; use SL::TransNumber; +use SL::Util qw(trim); use strict; @@ -499,7 +500,7 @@ sub ar_transactions { if ($form->{customernumber}) { $where .= " AND c.customernumber = ?"; - push(@values, $form->{customernumber}); + push(@values, trim($form->{customernumber})); } if ($form->{customer_id}) { $where .= " AND a.customer_id = ?"; @@ -510,7 +511,7 @@ sub ar_transactions { } if ($form->{"cp_name"}) { $where .= " AND (cp.cp_name ILIKE ? OR cp.cp_givenname ILIKE ?)"; - push(@values, ('%' . $form->{"cp_name"} . '%')x2); + push(@values, ('%' . trim($form->{"cp_name"}) . '%')x2); } if ($form->{business_id}) { my $business_id = $form->{business_id}; @@ -523,7 +524,7 @@ sub ar_transactions { push(@values, $department_id); } if ($form->{department}) { - my $department = "%" . $form->{department} . "%"; + my $department = "%" . trim($form->{department}) . "%"; $where .= " AND d.description ILIKE ?"; push(@values, $department); } @@ -547,19 +548,19 @@ sub ar_transactions { if ($form->{transdatefrom}) { $where .= " AND a.transdate >= ?"; - push(@values, $form->{transdatefrom}); + push(@values, trim($form->{transdatefrom})); } if ($form->{transdateto}) { $where .= " AND a.transdate <= ?"; - push(@values, $form->{transdateto}); + push(@values, trim($form->{transdateto})); } if ($form->{duedatefrom}) { $where .= " AND a.duedate >= ?"; - push(@values, $form->{duedatefrom}); + push(@values, trim($form->{duedatefrom})); } if ($form->{duedateto}) { $where .= " AND a.duedate <= ?"; - push(@values, $form->{duedateto}); + push(@values, trim($form->{duedateto})); } if ($form->{open} || $form->{closed}) { unless ($form->{open} && $form->{closed}) { diff --git a/SL/CVar.pm b/SL/CVar.pm index 8ee48f900..f13481207 100644 --- a/SL/CVar.pm +++ b/SL/CVar.pm @@ -9,6 +9,7 @@ use Data::Dumper; use SL::DBUtils; use SL::MoreCommon qw(listify); +use SL::Util qw(trim); sub get_configs { $main::lxdebug->enter_sub(); @@ -355,7 +356,7 @@ sub build_filter_query { next unless ($params{filter}->{$name}); push @sub_where, qq|cvar.text_value ILIKE ?|; - push @sub_values, '%' . $params{filter}->{$name} . '%' + push @sub_values, '%' . trim($params{filter}->{$name}) . '%' } elsif ($config->{type} eq 'select') { next unless ($params{filter}->{$name}); @@ -406,7 +407,7 @@ sub build_filter_query { } push @sub_where, qq|cvar.number_value $op ?|; - push @sub_values, $form->parse_amount($myconfig, $params{filter}->{$name}); + push @sub_values, $form->parse_amount($myconfig, trim($params{filter}->{$name})); } elsif ($config->{type} eq 'bool') { next unless ($params{filter}->{$name}); @@ -418,12 +419,12 @@ sub build_filter_query { my $table = $config->{type}; push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM $table WHERE name ILIKE ?)|; - push @sub_values, "%$params{filter}->{$name}%"; + push @sub_values, "%" . trim($params{filter}->{$name}) . "%"; } elsif ($config->{type} eq 'part') { next unless $params{filter}->{$name}; push @sub_where, qq|cvar.number_value * 1 IN (SELECT id FROM parts WHERE partnumber ILIKE ?)|; - push @sub_values, "%$params{filter}->{$name}%"; + push @sub_values, "%" . trim($params{filter}->{$name}) . "%"; } if (@sub_where) { diff --git a/SL/DBUtils.pm b/SL/DBUtils.pm index 89761443b..e8cd304ee 100644 --- a/SL/DBUtils.pm +++ b/SL/DBUtils.pm @@ -1,5 +1,7 @@ package SL::DBUtils; +use SL::Util qw(trim); + require Exporter; our @ISA = qw(Exporter); @@ -30,7 +32,9 @@ sub conv_b { sub conv_date { my ($value) = @_; - return (defined($value) && "$value" ne "") ? $value : undef; + return undef if !defined $value; + $value = trim($value); + return $value eq "" ? undef : $value; } sub conv_dateq { diff --git a/SL/DN.pm b/SL/DN.pm index 2bead22c7..e7959e0f1 100644 --- a/SL/DN.pm +++ b/SL/DN.pm @@ -45,6 +45,7 @@ use SL::Template; use SL::DB::Printer; use SL::DB::Language; use SL::TransNumber; +use SL::Util qw(trim); use strict; @@ -491,7 +492,7 @@ sub get_invoices { } elsif ($form->{customer}) { $where .= qq| AND (ct.name ILIKE ?)|; - push(@values, '%' . $form->{customer} . '%'); + push(@values, '%' . trim($form->{customer}) . '%'); } my %columns = ( @@ -503,7 +504,7 @@ sub get_invoices { foreach my $key (keys(%columns)) { next unless ($form->{$key}); $where .= qq| AND $columns{$key} ILIKE ?|; - push(@values, '%' . $form->{$key} . '%'); + push(@values, '%' . trim($form->{$key}) . '%'); } if ($form->{dunning_level}) { @@ -514,7 +515,7 @@ sub get_invoices { $form->{minamount} = $form->parse_amount($myconfig,$form->{minamount}); if ($form->{minamount}) { $where .= qq| AND ((a.amount - a.paid) > ?) |; - push(@values, $form->{minamount}); + push(@values, trim($form->{minamount})); } my $query = diff --git a/SL/DO.pm b/SL/DO.pm index 3ab2ffa6a..b098f71e0 100644 --- a/SL/DO.pm +++ b/SL/DO.pm @@ -46,6 +46,7 @@ use SL::HTML::Restrict; use SL::RecordLinks; use SL::IC; use SL::TransNumber; +use SL::Util qw(trim); use strict; @@ -110,12 +111,12 @@ sub transactions { } elsif ($form->{$vc}) { push @where, qq|ct.name ILIKE ?|; - push @values, '%' . $form->{$vc} . '%'; + push @values, '%' . trim($form->{$vc}) . '%'; } if ($form->{"cp_name"}) { push @where, "(cp.cp_name ILIKE ? OR cp.cp_givenname ILIKE ?)"; - push @values, ('%' . $form->{"cp_name"} . '%')x2; + push @values, ('%' . trim($form->{"cp_name"}) . '%')x2; } foreach my $item (qw(employee_id salesman_id)) { @@ -131,7 +132,7 @@ sub transactions { foreach my $item (qw(donumber ordnumber cusordnumber transaction_description)) { next unless ($form->{$item}); push @where, qq|dord.$item ILIKE ?|; - push @values, '%' . $form->{$item} . '%'; + push @values, '%' . trim($form->{$item}) . '%'; } if (($form->{open} || $form->{closed}) && @@ -146,7 +147,7 @@ sub transactions { if ($form->{serialnumber}) { push @where, 'dord.id IN (SELECT doi.delivery_order_id FROM delivery_order_items doi WHERE doi.serialnumber LIKE ?)'; - push @values, '%' . $form->{serialnumber} . '%'; + push @values, '%' . trim($form->{serialnumber}) . '%'; } if($form->{transdatefrom}) { diff --git a/SL/Form.pm b/SL/Form.pm index d2aa04927..98bb4dbe2 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -75,6 +75,7 @@ use SL::PrefixedNumber; use SL::Request; use SL::Template; use SL::User; +use SL::Util; use SL::X; use Template; use URI; @@ -3001,19 +3002,9 @@ sub current_date { } sub like { - $main::lxdebug->enter_sub(); - my ($self, $string) = @_; - if ($string !~ /%/) { - $string = "%$string%"; - } - - $string =~ s/\'/\'\'/g; - - $main::lxdebug->leave_sub(); - - return $string; + return "%" . SL::Util::trim($string // '') . "%"; } sub redo_rows { diff --git a/SL/OE.pm b/SL/OE.pm index 1c812e24f..079b14b13 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -50,6 +50,7 @@ use SL::DBUtils; use SL::HTML::Restrict; use SL::IC; use SL::TransNumber; +use SL::Util qw(trim); use Text::ParseWords; use strict; @@ -172,12 +173,12 @@ SQL } elsif ($form->{$vc}) { $query .= " AND ct.name ILIKE ?"; - push(@values, '%' . $form->{$vc} . '%'); + push(@values, '%' . trim($form->{$vc}) . '%'); } if ($form->{"cp_name"}) { $query .= " AND (cp.cp_name ILIKE ? OR cp.cp_givenname ILIKE ?)"; - push(@values, ('%' . $form->{"cp_name"} . '%')x2); + push(@values, ('%' . trim($form->{"cp_name"}) . '%')x2); } if (!$main::auth->assert('sales_all_edit', 1)) { @@ -208,12 +209,12 @@ SQL if ($form->{$ordnumber}) { $query .= qq| AND o.$ordnumber ILIKE ?|; - push(@values, '%' . $form->{$ordnumber} . '%'); + push(@values, '%' . trim($form->{$ordnumber}) . '%'); } if ($form->{cusordnumber}) { $query .= qq| AND o.cusordnumber ILIKE ?|; - push(@values, '%' . $form->{cusordnumber} . '%'); + push(@values, '%' . trim($form->{cusordnumber}) . '%'); } if($form->{transdatefrom}) { @@ -248,7 +249,7 @@ SQL if ($form->{shippingpoint}) { $query .= qq| AND o.shippingpoint ILIKE ?|; - push(@values, '%' . $form->{shippingpoint} . '%'); + push(@values, '%' . trim($form->{shippingpoint}) . '%'); } if ($form->{taxzone_id} ne '') { # taxzone_id could be 0 @@ -258,7 +259,7 @@ SQL if ($form->{transaction_description}) { $query .= qq| AND o.transaction_description ILIKE ?|; - push(@values, '%' . $form->{transaction_description} . '%'); + push(@values, '%' . trim($form->{transaction_description}) . '%'); } if ($form->{periodic_invoices_active} ne $form->{periodic_invoices_inactive}) { @@ -273,7 +274,7 @@ SQL if (($form->{order_probability_value} || '') ne '') { my $op = $form->{order_probability_value} eq 'le' ? '<=' : '>='; $query .= qq| AND (o.order_probability ${op} ?)|; - push @values, $form->{order_probability_value}; + push @values, trim($form->{order_probability_value}); } if ($form->{expected_billing_date_from}) { -- 2.20.1