- # Nur Kunden finden, bei denen ich selber der Verkäufer bin
- # Gilt nicht für Lieferanten
- if ($cv eq 'customer' && !$main::auth->assert('customer_vendor_all_edit', 1)) {
- $where .= qq| AND ct.salesman_id = (select em.id from employee em where em.login = ?)|;
- push(@values, $form->{login});
+ if ($form->{salesman_id}) {
+ $where .= qq| AND (ct.salesman_id = ?)|;
+ push(@values, conv_i($form->{salesman_id}));
+ }
+
+ if($form->{insertdatefrom}) {
+ $where .= qq| AND (ct.itime::DATE >= ?)|;
+ push@values, conv_date($form->{insertdatefrom});
+ }
+
+ if($form->{insertdateto}) {
+ $where .= qq| AND (ct.itime::DATE <= ?)|;
+ push @values, conv_date($form->{insertdateto});
+ }
+
+ if ($form->{all}) {
+ my @tokens = parse_line('\s+', 0, $form->{all});
+ $where .= qq| AND (
+ ct.${cv}number ILIKE ? OR
+ ct.name ILIKE ?
+ )| for @tokens;
+ push @values, ("%$_%")x2 for @tokens;
+ }
+
+ if (($form->{create_zugferd_invoices} // '') ne '') {
+ $where .= qq| AND (ct.create_zugferd_invoices = ?)|;
+ push @values, $form->{create_zugferd_invoices};
+ }
+
+ if ($form->{all_phonenumbers}) {
+ my $search_term = trim($form->{all_phonenumbers});
+ $search_term =~ s{\p{WSpace}+}{}g;
+ $search_term = join ' *', split(//, $search_term);
+
+ $where .= qq| AND (ct.phone ~* ? OR
+ ct.fax ~* ? OR
+ ct.id IN
+ (SELECT cp_cv_id FROM contacts
+ WHERE cp_phone1 ~* ? OR
+ cp_phone2 ~* ? OR
+ cp_fax ~* ? OR
+ cp_mobile1 ~* ? OR
+ cp_mobile2 ~* ? OR
+ cp_satphone ~* ? OR
+ cp_satfax ~* ? OR
+ cp_privatphone ~* ?
+ )
+ )|;
+ push @values, ($search_term)x10;