better UI for package report classes, #13057
[freeside.git] / httemplate / search / report_477.html
index c9d97c5..12918a1 100755 (executable)
                )
     %>
 
+    <& /elements/tr-td-label.html, 'label' => 'State' &>
+    <TD>
+      <SELECT NAME="state">
+%   foreach (@states) {
+        <OPTION VALUE="<% $_ %>"><% $_ %></OPTION>
+%   }
+      </SELECT>
+    </TD></TR>
+
     <% include( '/elements/tr-select-pkg_class.html',
                    'multiple'       => 1,
                    'empty_label' => '(empty class)',
                      'table'        => 'part_pkg_report_option',
                      'name_col'     => 'name',
                      'hashref'      => { 'disabled' => '' },
-                     'element_name' => 'partv_report_option',
+                     'element_name' => 'part5_report_option',
+                     'curr_value'   =>
+                            FS::Report::FCC_477::restore_fcc477map("part5_report_option"),
                  )
             %>
         </TD>
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('List packages');
 
+my @states = (
+  qsearch({
+    'table'   => 'cust_main',
+    'select'  => 'DISTINCT(state)',
+    'hashref' => { 'country' => 'US' }, # 477 report isn't relevant elsewhere
+  }),
+  qsearch({
+    'table'   => 'cust_main',
+    'select'  => 'DISTINCT(ship_state) AS state',
+    'hashref' => { 'country' => 'US' },
+  }),
+  qsearch({
+    'table'   => 'cust_location',
+    'select'  => 'DISTINCT(state)',
+    'hashref' => { 'country' => 'US' },
+  }),
+);
+
+{
+  my %seen = map {$_->get('state') => 1} @states;
+  @states = grep $_, sort keys(%seen);
+}
+
 </%init>