commit 429593d00b33a76a53e5ad6e96330e5fe5fe89ca
Author: Tamino Steinert <tamino.steinert@tamino.st>
Date:   Wed Apr 5 17:13:17 2023 +0200

    Kunden/Lieferanten-Bericht: nach Steuerrate filtern und anzeigen

diff --git a/SL/CT.pm b/SL/CT.pm
index ce7f7677f..a1698b2e1 100644
--- a/SL/CT.pm
+++ b/SL/CT.pm
@@ -86,6 +86,7 @@ sub search {
       "insertdate"         => "ct.itime",
       "salesman"           => "e.name",
       "payment"            => "pt.description",
+      "taxzone"            => "tz.description",
       "pricegroup"         => "pg.pricegroup",
       "ustid"              => "ct.ustid",
       "creditlimit"        => "ct.creditlimit",
@@ -229,6 +230,11 @@ sub search {
     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});
@@ -300,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) .
@@ -308,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|;
 
diff --git a/bin/mozilla/ct.pl b/bin/mozilla/ct.pl
index 630501cf7..24020809b 100644
--- a/bin/mozilla/ct.pl
+++ b/bin/mozilla/ct.pl
@@ -56,6 +56,7 @@ use SL::DB::Business;
 use SL::DB::Default;
 use SL::DB::DeliveryTerm;
 use SL::DB::Manager::PaymentTerm;
+use SL::DB::Manager::TaxZone;
 use SL::ReportGenerator;
 use SL::Locale::String qw(t8);
 use SL::MoreCommon qw(uri_encode);
@@ -85,6 +86,7 @@ sub search {
   $form->get_lists("business_types" => "ALL_BUSINESS_TYPES",
                    "salesmen"       => "ALL_SALESMEN");
   $form->{ALL_PAYMENT_TERMS} = SL::DB::Manager::PaymentTerm->get_all_sorted;
+  $form->{ALL_TAXZONES}      = SL::DB::Manager::TaxZone    ->get_all_sorted;
   $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0;
 
   $form->{CUSTOM_VARIABLES}                  = CVar->get_configs('module' => 'CT');
@@ -187,6 +189,13 @@ sub list_names {
     }
   }
 
+  if ($form->{taxzone_id}) {
+    my $tax_zone = SL::DB::Manager::TaxZone->find_by(id => $form->{taxzone_id});
+    if ($tax_zone) {
+      push @options, $locale->text('Tax rate') . " : " . $tax_zone->description;
+    }
+  }
+
   if ( $form->{insertdatefrom} or $form->{insertdateto} ) {
     push @options, $locale->text('Insert Date');
     push @options, $locale->text('From') . " " . $locale->date(\%myconfig, $form->{insertdatefrom}, 1) if $form->{insertdatefrom};
@@ -197,7 +206,7 @@ sub list_names {
     'id',        'name',    "$form->{db}number",   'contact', 'main_contact_person',
     'department_1',         'department_2',        'phone',   'discount',
     'fax',       'email',   'taxnumber',           'street',    'zipcode' , 'city',
-    'business',  'payment', 'invnumber', 'ordnumber',           'quonumber', 'salesman',
+    'business',  'payment', 'taxzone', 'invnumber', 'ordnumber',           'quonumber', 'salesman',
     'country',   'gln',     'insertdate',           'pricegroup', 'contact_origin', 'invoice_mail',
     'creditlimit', 'ustid', 'commercial_court', 'delivery_order_mail', 'dunning_lock'
   );
@@ -233,6 +242,7 @@ sub list_names {
     'salesman'          => { 'text' => $locale->text('Salesman'), },
     'discount'          => { 'text' => $locale->text('Discount'), },
     'payment'           => { 'text' => $locale->text('Payment Terms'), },
+    'taxzone'           => { 'text' => $locale->text('Tax rate'), },
     'insertdate'        => { 'text' => $locale->text('Insert Date'), },
     'pricegroup'        => { 'text' => $locale->text('Pricegroup'), },
     'invoice_mail'      => { 'text' => $locale->text('Email of the invoice recipient'), },
@@ -251,7 +261,7 @@ sub list_names {
   my @hidden_variables  = ( qw(
       db status obsolete name contact email cp_name addr_street addr_zipcode
       addr_city addr_country addr_gln business_id salesman_id insertdateto insertdatefrom all
-      all_phonenumbers dunning_lock department_1 department_2 payment_id
+      all_phonenumbers dunning_lock department_1 department_2 payment_id taxzone_id
     ), "$form->{db}number",
     map({ "cvar_$_->{name}" } @searchable_custom_variables),
     map({'cvar_'. $_->{name} .'_from'} grep({$_->{type} eq 'date'} @searchable_custom_variables)),
diff --git a/templates/design40_webpages/ct/search.html b/templates/design40_webpages/ct/search.html
index d789dfc6b..1b0f10db7 100644
--- a/templates/design40_webpages/ct/search.html
+++ b/templates/design40_webpages/ct/search.html
@@ -110,6 +110,10 @@
           <th>[% 'Payment Term' | $T8 %]</th>
           <td>[% L.select_tag('payment_id', ALL_PAYMENT_TERMS, with_empty=1, title_key='description', with_empty=1, class="wi-lightwide") %]</td>
         </tr>
+        <tr>
+          <th>[% 'Tax rate' | $T8 %]</th>
+          <td>[% L.select_tag('taxzone_id', ALL_TAXZONES, with_empty=1, title_key='description', class="wi-lightwide") %]</td>
+        </tr>
       [% CUSTOM_VARIABLES_FILTER_CODE %]
       <tr>
         <th>[% 'Scope' | $T8 %] </th>
@@ -277,6 +281,10 @@
       <input name="l_payment" id="l_payment" type="checkbox" value="Y">
       <label for="l_payment"> [% 'Payment Terms' | $T8 %] </label>
     </div>
+    <div>
+      <input name="l_taxzone" id="l_taxzone" type="checkbox" value="Y">
+      <label for="l_taxzone"> [% 'Tax rate' | $T8 %] </label>
+    </div>
   </div>
 
   <div class="list col">
diff --git a/templates/webpages/ct/search.html b/templates/webpages/ct/search.html
index ad4c5bd59..984c35bcb 100644
--- a/templates/webpages/ct/search.html
+++ b/templates/webpages/ct/search.html
@@ -79,6 +79,11 @@
      <td>[% L.select_tag('payment_id', ALL_PAYMENT_TERMS, with_empty=1, title_key='description', with_empty=1) %]</td>
    </tr>
 
+    <tr>
+     <th align="right">[% 'Tax rate' | $T8 %]</th>
+     <td>[% L.select_tag('taxzone_id', ALL_TAXZONES, with_empty=1, title_key='description') %]</td>
+    </tr>
+
 [% IF IS_CUSTOMER %]
    <tr>
      <th align="right" nowrap>[% LxERP.t8("Factur-X/ZUGFeRD settings") %]</th>
@@ -218,6 +223,10 @@
         <input name="l_payment" id="l_payment" type="checkbox" class="checkbox" value="Y">
         <label for="l_payment">[% 'Payment Terms' | $T8 %]</label>
        </td>
+       <td>
+        <input name="l_taxzone" id="l_taxzone" type="checkbox" class="checkbox" value="Y">
+        <label for="l_taxzone">[% 'Tax rate' | $T8 %]</label>
+       </td>
        <td>
         <input name="l_insertdate" id="l_insertdate" class="checkbox" type="checkbox" value="Y">
         <label for="l_insertdate">[% 'Insert Date' | $T8 %]</label>
