X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/fcbb613d03379b265cb0df7ce0b553ee630d52f3..2def6461e70255e05432757a744188e84c767f79:/SL/CT.pm diff --git a/SL/CT.pm b/SL/CT.pm index 93c3fcea2..63b252d9e 100644 --- a/SL/CT.pm +++ b/SL/CT.pm @@ -551,8 +551,19 @@ sub _save_contact { my @columns = qw(cp_title cp_givenname cp_name cp_email cp_phone1 cp_phone2 cp_abteilung cp_fax cp_mobile1 cp_mobile2 cp_satphone cp_satfax cp_project cp_privatphone cp_privatemail cp_birthday cp_gender - cp_street cp_zipcode cp_city); - my @values = map { $_ eq 'cp_gender' ? ($form->{$_} eq 'f' ? 'f' : 'm') : $form->{$_} } @columns; + cp_street cp_zipcode cp_city cp_position); + my @values = map( + { + if ( $_ eq 'cp_gender' ) { + $form->{$_} eq 'f' ? 'f' : 'm'; + } elsif ( $_ eq 'cp_birthday' && $form->{cp_birthday} eq '' ) { + undef; + } else { + $form->{$_}; + } + } + @columns + ); my ($query, $cp_id); if ($form->{cp_id}) { @@ -606,7 +617,7 @@ sub search { my %allowed_sort_columns = map { $_, 1 } qw( id customernumber vendornumber name contact phone fax email street - taxnumber business invnumber ordnumber quonumber zipcode city + taxnumber business invnumber ordnumber quonumber zipcode city country salesman ); my $sortorder = $form->{sort} && $allowed_sort_columns{$form->{sort}} ? $form->{sort} : "name"; $form->{sort} = $sortorder; @@ -648,6 +659,19 @@ sub search { push @values, ('%' . $form->{addr_city} . '%') x 2; } + if ($form->{addr_country}) { + $where .= " AND ((lower(ct.country) LIKE lower(?)) + OR + (ct.id IN ( + SELECT trans_id + FROM shipto + WHERE (module = 'CT') + AND (lower(shiptocountry) LIKE lower(?)) + )) + )"; + push @values, ('%' . $form->{addr_country} . '%') x 2; + } + if ( $form->{status} eq 'orphaned' ) { $where .= qq| AND ct.id NOT IN | . @@ -665,7 +689,7 @@ sub search { qq| WHERE cv.id = a.vendor_id)|; } $form->{l_invnumber} = $form->{l_ordnumber} = $form->{l_quonumber} = ""; - } + }; if ($form->{obsolete} eq "Y") { $where .= qq| AND obsolete|; @@ -705,10 +729,11 @@ sub search { } my $query = - qq|SELECT ct.*, b.description AS business | . + qq|SELECT ct.*, b.description AS business, e.name as salesman | . (qq|, NULL AS invnumber, NULL AS ordnumber, NULL AS quonumber, NULL AS invid, NULL AS module, NULL AS formtype, NULL AS closed | x!! $join_records) . qq|FROM $cv ct | . qq|LEFT JOIN business b ON (ct.business_id = b.id) | . + qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | . qq|WHERE $where|; my @saved_values = @values; @@ -722,13 +747,14 @@ sub search { push(@values, @saved_values); $query .= qq| UNION | . - qq|SELECT ct.*, b.description AS business, | . + qq|SELECT ct.*, b.description AS business, e.name as salesman, | . qq| a.invnumber, a.ordnumber, a.quonumber, a.id AS invid, | . qq| '$module' AS module, 'invoice' AS formtype, | . qq| (a.amount = a.paid) AS closed | . qq|FROM $cv ct | . qq|JOIN $ar a ON (a.${cv}_id = ct.id) | . qq|LEFT JOIN business b ON (ct.business_id = b.id) | . + qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | . qq|WHERE $where AND (a.invoice = '1')|; } @@ -736,12 +762,13 @@ sub search { push(@values, @saved_values); $query .= qq| UNION | . - qq|SELECT ct.*, b.description AS business,| . + qq|SELECT ct.*, b.description AS business, e.name as salesman, | . qq| ' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid, | . qq| 'oe' AS module, 'order' AS formtype, o.closed | . qq|FROM $cv ct | . qq|JOIN oe o ON (o.${cv}_id = ct.id) | . qq|LEFT JOIN business b ON (ct.business_id = b.id) | . + qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | . qq|WHERE $where AND (o.quotation = '0')|; } @@ -749,12 +776,13 @@ sub search { push(@values, @saved_values); $query .= qq| UNION | . - qq|SELECT ct.*, b.description AS business, | . + qq|SELECT ct.*, b.description AS business, e.name as salesman, | . qq| ' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid, | . qq| 'oe' AS module, 'quotation' AS formtype, o.closed | . qq|FROM $cv ct | . qq|JOIN oe o ON (o.${cv}_id = ct.id) | . qq|LEFT JOIN business b ON (ct.business_id = b.id) | . + qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | . qq|WHERE $where AND (o.quotation = '1')|; } } @@ -1112,7 +1140,7 @@ sub search_contacts { 'vcnumber' => 'vcnumber, cp_name, cp_givenname', ); - my %sortcols = map { $_ => 1 } qw(cp_name cp_givenname cp_phone1 cp_phone2 cp_mobile1 cp_email cp_street cp_zipcode cp_city vcname vcnumber); + my %sortcols = map { $_ => 1 } qw(cp_name cp_givenname cp_phone1 cp_phone2 cp_mobile1 cp_email cp_street cp_zipcode cp_city cp_position vcname vcnumber); my $order_by = $sortcols{$::form->{sort}} ? $::form->{sort} : 'cp_name'; $::form->{sort} = $order_by;