fix A/R report
[freeside.git] / httemplate / search / report_tax.html
index 7bc35e3..f920adb 100755 (executable)
-<HTML>
-  <HEAD>
-    <TITLE>Tax Report Criteria</TITLE>
-    <LINK REL="stylesheet" TYPE="text/css" HREF="../elements/calendar-win2k-2.css" TITLE="win2k-2">
-    <SCRIPT TYPE="text/javascript" SRC="../elements/calendar_stripped.js"></SCRIPT>
-    <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-en.js"></SCRIPT>
-    <SCRIPT TYPE="text/javascript" SRC="../elements/calendar-setup.js"></SCRIPT>  </HEAD>
-  <BODY BGCOLOR="#e8e8e8">
-    <H1>Tax Report Criteria</H1>
-    <FORM ACTION="report_tax.cgi" METHOD="post">
-      Return <B>tax report</B> for period:
-    <TABLE>
-      <TR>
-        <TD ALIGN="right">From: </TD>
-        <TD><INPUT TYPE="text" NAME="beginning" ID="beginning_text" VALUE="" SIZE=11 MAXLENGTH=10> <IMG SRC="../images/calendar.png" ID="beginning_button" STYLE="cursor: pointer" TITLE="Select date"><BR><i>m/d/y</i></TD>
-<SCRIPT TYPE="text/javascript">
-  Calendar.setup({
-    inputField: "beginning_text",
-    ifFormat:   "%m/%d/%Y",
-    button:     "beginning_button",
-    align:      "BR"
-  });
-</SCRIPT>
-      </TR>
-        <TD ALIGN="right">To: </TD>
-        <TD><INPUT TYPE="text" NAME="ending" ID="ending_text" VALUE="" SIZE=11 MAXLENGTH=10> <IMG SRC="../images/calendar.png" ID="ending_button" STYLE="cursor: pointer" TITLE="Select date"><BR><i>m/d/y</i></TD>
-<SCRIPT TYPE="text/javascript">
-  Calendar.setup({
-    inputField: "ending_text",
-    ifFormat:   "%m/%d/%Y",
-    button:     "ending_button",
-    align:      "BR"
+<% include('/elements/header.html', 'Tax Report' ) %>
+
+<FORM ACTION="report_tax.cgi" METHOD="GET">
+
+<TABLE>
+
+  <& /elements/tr-select-agent.html, 'disable_empty'=>0 &>
+
+  <& /elements/tr-input-beginning_ending.html &>
+
+  <tr>
+    <td></td>
+    <td colspan=2 style="font-weight: bold">
+      <& /elements/radio.html,
+        'field' => 'all',
+        'value' => 1,
+        'curr_value' => 1,
+      &> All taxes
+      <& /elements/radio.html,
+        'field' => 'all',
+        'value' => 0,
+      &> A specific tax
+    </td>
+  </tr>
+  <& /elements/tr-select.html,
+    'label'         => 'Country',
+    'field'         => 'country',
+    'options'       => \@countries,
+    'curr_value'    => ($conf->config('countrydefault') || 'US'),
+  &>
+
+  <& /elements/tr-select.html,
+    'label'         => 'For tax named ',
+    'field'         => 'taxname',
+    'options'       => \@taxnames,
+    'disable_empty' => 1,
+  &>
+
+  <& /elements/tr-checkbox-multiple.html,
+    'label'         => 'Break down by ',
+    'field'         => 'breakdown',
+    'options'       => \@breakdown,
+    'option_labels' => {
+      taxclass  => 'Tax class',
+      pkgclass  => 'Package class',
+      city      => 'City',
+      district  => 'District',
+    },
+  &>
+  <TR>
+    <TD></TD>
+    <TD>Deduct credited tax if it was 
+      <SELECT NAME="credit_date">
+        <OPTION VALUE="cust_bill" SELECTED>invoiced in this period</OPTION>
+        <OPTION VALUE="cust_credit_bill">credited in this period</OPTION>
+      </SELECT>
+    </TD>
+  </TR>
+
+</TABLE>
+
+<BR><INPUT TYPE="submit" VALUE="Get Report">
+
+</FORM>
+
+<script>
+$(document).ready(function() {
+  $('[name=all]').on('change', function(ev) {
+    // disable country/taxname/breakdown if 'all' = 1
+    if (this.checked) {
+      var disabled = (this.value == 1);
+      $('[name=country').prop('disabled', disabled);
+      $('[name=taxname').prop('disabled', disabled);
+      $('[name=breakdown').prop('disabled', disabled);
+    }
   });
-</SCRIPT>
-      </TR>
-    </TABLE>
+  $('[name=all]').change();
+});
+</script>
+
+<% include('/elements/footer.html') %>
+<%init>
+
+die "access denied"
+  unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
+
+my $conf = new FS::Conf;
+
+my $sth = dbh->prepare('SELECT DISTINCT(COALESCE(taxname, \'Tax\')) FROM cust_main_county');
+$sth->execute or die $sth->errstr;
+my @taxnames = map { $_->[0] } @{ $sth->fetchall_arrayref };
 
-      <BR><INPUT TYPE="submit" VALUE="Get Report">
+$sth = dbh->prepare('SELECT DISTINCT(country) FROM cust_location');
+$sth->execute or die $sth->errstr;
+my @countries = map { $_->[0] } @{ $sth->fetchall_arrayref };
 
-    </FORM>
-  </BODY>
-</HTML>
+my @breakdown;
+if ( $conf->exists('enable_taxclasses') ) {
+  push @breakdown, 'taxclass';
+}
+if ( FS::pkg_class->count() > 0 ) {
+  push @breakdown, 'pkgclass';
+}
+if ( FS::cust_main_county->count("city is not null and city != ''") > 0 ) {
+  push @breakdown, 'city';
+}
+if ( FS::cust_main_county->count("district is not null") > 0 ) {
+  push @breakdown, 'district';
+}
 
+</%init>