]> wagnertech.de Git - mfinanz.git/blobdiff - SL/CT.pm
kivitendo 3.9.2-0.2
[mfinanz.git] / SL / CT.pm
index b52c8794acafa55317b3c4bb674b4eab08d223c9..f6d95484f1efa970892fa0ce91332b79ae8e0721 100644 (file)
--- a/SL/CT.pm
+++ b/SL/CT.pm
@@ -66,6 +66,8 @@ sub search {
       "customernumber"     => "ct.customernumber",
       "vendornumber"       => "ct.vendornumber",
       "name"               => "ct.name",
+      "department_1"       => "ct.department_1",
+      "department_2"       => "ct.department_2",
       "contact"            => "ct.contact",
       "phone"              => "ct.phone",
       "fax"                => "ct.fax",
@@ -84,10 +86,12 @@ sub search {
       "insertdate"         => "ct.itime",
       "salesman"           => "e.name",
       "payment"            => "pt.description",
+      "taxzone"            => "tz.description",
       "pricegroup"         => "pg.pricegroup",
       "ustid"              => "ct.ustid",
       "creditlimit"        => "ct.creditlimit",
       "commercial_court"   => "ct.commercial_court",
+      "dunning_lock"       => "ct.dunning_lock",
     );
 
   $form->{sort} ||= "name";
@@ -102,7 +106,7 @@ sub search {
   }
   my $sortdir   = !defined $form->{sortdir} ? 'ASC' : $form->{sortdir} ? 'ASC' : 'DESC';
 
-  if ($sortorder !~ /(business|creditlimit|id|discount|itime)/ && !$join_records) {
+  if ($sortorder !~ /(business|creditlimit|id|discount|itime|dunning_lock)/ && !$join_records) {
     $sortorder  = "lower($sortorder) ${sortdir}";
   } else {
     $sortorder .= " ${sortdir}";
@@ -113,8 +117,8 @@ sub search {
     push(@values, like($form->{"${cv}number"}));
   }
 
-  foreach my $key (qw(name contact email)) {
-    if ($form->{$key}) {
+  foreach my $key (qw(name department_1 department_2 contact email)) {
+    if ($form->{$key} ne '') {
       $where .= " AND ct.$key ILIKE ?";
       push(@values, like($form->{$key}));
     }
@@ -221,6 +225,16 @@ sub search {
     push(@values, conv_i($form->{salesman_id}));
   }
 
+  if ($form->{payment_id}) {
+    $where .= qq| AND (ct.payment_id = ?)|;
+    push(@values, $form->{payment_id});
+  }
+
+  if ($form->{taxzone_id}) {
+    $where .= qq| AND (ct.taxzone_id = ?)|;
+    push(@values, $form->{taxzone_id});
+  }
+
   if($form->{insertdatefrom}) {
     $where .= qq| AND (ct.itime::DATE >= ?)|;
     push@values, conv_date($form->{insertdatefrom});
@@ -231,6 +245,11 @@ sub search {
     push @values, conv_date($form->{insertdateto});
   }
 
+  if($form->{dunning_lock} ne '') {
+    $where .= qq| AND ct.dunning_lock = ?|;
+    push @values, $form->{dunning_lock};
+  }
+
   if ($form->{all}) {
     my @tokens = parse_line('\s+', 0, $form->{all});
       $where .= qq| AND (
@@ -287,7 +306,7 @@ sub search {
   }
   my $query =
     qq|SELECT ct.*, ct.itime::DATE AS insertdate, b.description AS business, e.name as salesman, | .
-    qq|  pt.description as payment | .
+    qq|  pt.description as payment, tz.description as taxzone | .
     $pg_select .
     $main_cp_select .
     (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) .
@@ -295,6 +314,7 @@ sub search {
     qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
     qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | .
     qq|LEFT JOIN payment_terms pt ON (ct.payment_id = pt.id) | .
+    qq|LEFT JOIN tax_zones tz ON (ct.taxzone_id = tz.id) | .
     $pg_join .
     qq|WHERE $where|;
 
@@ -310,7 +330,7 @@ sub search {
       $query .=
         qq| UNION | .
         qq|SELECT ct.*, ct.itime::DATE AS insertdate, b.description AS business, e.name as salesman, | .
-        qq|  pt.description as payment | .
+        qq|  pt.description as payment, tz.description as taxzone | .
         $pg_select .
         $main_cp_select .
         qq|, a.invnumber, a.ordnumber, a.quonumber, a.id AS invid, | .
@@ -321,6 +341,7 @@ sub search {
         qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
         qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | .
         qq|LEFT JOIN payment_terms pt ON (ct.payment_id = pt.id) | .
+        qq|LEFT JOIN tax_zones tz ON (ct.taxzone_id = tz.id) | .
         $pg_join .
         qq|WHERE $where AND (a.invoice = '1')|;
     }
@@ -330,7 +351,7 @@ sub search {
       $query .=
         qq| UNION | .
         qq|SELECT ct.*, ct.itime::DATE AS insertdate, b.description AS business, e.name as salesman, | .
-        qq|  pt.description as payment | .
+        qq|  pt.description as payment, tz.description as taxzone | .
         $pg_select .
         $main_cp_select .
         qq|, ' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid, | .
@@ -340,8 +361,9 @@ sub search {
         qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
         qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | .
         qq|LEFT JOIN payment_terms pt ON (ct.payment_id = pt.id) | .
+        qq|LEFT JOIN tax_zones tz ON (ct.taxzone_id = tz.id) | .
         $pg_join .
-        qq|WHERE $where AND (o.quotation = '0')|;
+        qq|WHERE $where AND ((o.record_type = 'sales_order') OR (o.record_type = 'purchase_order'))|;
     }
 
     if ( $form->{l_quonumber} ) {
@@ -349,7 +371,7 @@ sub search {
       $query .=
         qq| UNION | .
         qq|SELECT ct.*, ct.itime::DATE AS insertdate, b.description AS business, e.name as salesman, | .
-        qq|  pt.description as payment | .
+        qq|  pt.description as payment, tz.description as taxzone | .
         $pg_select .
         $main_cp_select .
         qq|, ' ' AS invnumber, o.ordnumber, o.quonumber, o.id AS invid, | .
@@ -359,8 +381,9 @@ sub search {
         qq|LEFT JOIN business b ON (ct.business_id = b.id) | .
         qq|LEFT JOIN employee e ON (ct.salesman_id = e.id) | .
         qq|LEFT JOIN payment_terms pt ON (ct.payment_id = pt.id) | .
+        qq|LEFT JOIN tax_zones tz ON (ct.taxzone_id = tz.id) | .
         $pg_join .
-        qq|WHERE $where AND (o.quotation = '1')|;
+        qq|WHERE $where AND ((o.record_type = 'sales_quotation') OR (o.record_type = 'request_quotation'))|;
     }
   }