fix unapplied payment report, RT#73048, fallout from #25944
[freeside.git] / httemplate / search / elements / report_cust_pay_or_refund.html
index 885457c..1cc77f7 100644 (file)
@@ -13,121 +13,160 @@ Examples:
          )
 
 </%doc>
-<% include('/elements/header.html', $title ) %>
+<& /elements/header.html, mt($title) &>
 
 <FORM ACTION="<% $table %>.html" METHOD="GET">
 <INPUT TYPE="hidden" NAME="magic" VALUE="_date">
+<INPUT TYPE="hidden" NAME="unapplied" VALUE="<% $unapplied %>">
 
 <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
 
   <TR>
     <TH CLASS="background" COLSPAN=2 ALIGN="left">
-      <FONT SIZE="+1">Search options</FONT>
+      <FONT SIZE="+1"><% mt('[_1] search options', ucfirst($name_singular)) |h %></FONT>
     </TH>
   </TR>
 
+  <& /elements/tr-select.html,
+    label     => ucfirst(PL($name_singular)) . ' of type:',
+    field     => 'payby',
+    options   => [ keys %payby ],
+    labels    => \%payby,
+    multiple  => 1,
+    size      => 18,
+  &>
+
   <TR>
-    <TD ALIGN="right"><% ucfirst(PL($name_singular)) %> of type: </TD>
+    <TD ALIGN="right"><% mt('Check #:') |h %> </TD>
     <TD>
-      <SELECT NAME="payby" onChange="payby_changed(this)">
-        <OPTION VALUE="">all</OPTION>
-        <OPTION VALUE="CARD">credit card (all)</OPTION>
-        <OPTION VALUE="CARD-VisaMC">credit card (Visa/MasterCard)</OPTION>
-        <OPTION VALUE="CARD-Amex">credit card (American Express)</OPTION>
-        <OPTION VALUE="CARD-Discover">credit card (Discover)</OPTION>
-        <OPTION VALUE="CARD-Maestro">credit card (Maestro/Switch/Solo)</OPTION>
-        <OPTION VALUE="CHEK">electronic check / ACH</OPTION>
-        <OPTION VALUE="BILL">check</OPTION>
-        <OPTION VALUE="PREP">prepaid card</OPTION>
-        <OPTION VALUE="CASH">cash</OPTION>
-        <OPTION VALUE="WEST">Western Union</OPTION>
-        <OPTION VALUE="MCRD">manual credit card</OPTION>
-      </SELECT>
+      <INPUT TYPE="text" ID="payinfo" NAME="payinfo">
     </TD>
   </TR>
-
-  <SCRIPT TYPE="text/javascript">
-  
-    function payby_changed(what) {
-      if ( what.options[what.selectedIndex].value == 'BILL' ) {
-       document.getElementById('checkno_caption').style.color = '#000000';
-        what.form.payinfo.disabled = false;
-       what.form.payinfo.style.backgroundColor = '#ffffff';
-      } else {
-       document.getElementById('checkno_caption').style.color = '#bbbbbb';
-        what.form.payinfo.disabled = true;
-       what.form.payinfo.style.backgroundColor = '#dddddd';
-      }
-    }
-
-  </SCRIPT>
-
   <TR>
-    <TD ALIGN="right"><FONT ID="checkno_caption" COLOR="#bbbbbb">Check #: </FONT></TD>
+    <TD ALIGN="right"><% mt('Transaction #:') |h %> </TD>
     <TD>
-      <INPUT TYPE="text" NAME="payinfo" DISABLED STYLE="background-color: #dddddd">
+      <INPUT TYPE="text" ID="ccpay" NAME="ccpay">
     </TD>
   </TR>
 
-  <% include( '/elements/tr-select-agent.html',
-                 'curr_value'    => scalar($cgi->param('agentnum')),
-                 'label'         => 'for agent: ',
-                 'disable_empty' => 0,
-             )
-  %>
-
-  <% include( '/elements/tr-select-user.html' ) %>
+  <& /elements/tr-select-user.html &>
+
+% if ( $has_reason ) {
+%   # limit to reasons that are in use for the table being reported on
+%   # (maybe order by count(*) desc?)
+  <& /elements/tr-select-table.html,
+    label       => emt('Reason'),
+    field       => 'reasonnum',
+    id          => 'reasonnum',
+    table       => 'reason',
+    name_col    => 'reason',
+    extra_sql   => " WHERE EXISTS(SELECT 1 FROM $table WHERE $table.reasonnum = reason.reasonnum) ",
+    empty_label => emt('any'),
+  &>
+% }
 
   <TR>
-    <TD ALIGN="right" VALIGN="center">Payment</TD>
+    <TD ALIGN="right" VALIGN="center"><% mt(ucfirst($name_singular). ' date') |h %></TD>
     <TD>
       <TABLE>
-        <% include( '/elements/tr-input-beginning_ending.html',
-                      layout   => 'horiz',
-                  )
-        %>
+        <& /elements/tr-input-beginning_ending.html,
+                      layout     => 'horiz',
+                      input_time => $conf->exists('report-cust_pay-select_time'),
+        &>
       </TABLE>
     </TD>
   </TR>
 
 % if ( $void ) {
     <TR>
-      <TD ALIGN="right" VALIGN="center">Voided</TD>
+      <TD ALIGN="right" VALIGN="center"><% mt('Voided') |h %></TD>
       <TD>
         <TABLE>
-          <% include( '/elements/tr-input-beginning_ending.html',
+          <& /elements/tr-input-beginning_ending.html,
                         prefix => 'void',
                         layout => 'horiz',
-                    )
-          %>
+          &>
         </TABLE>
       </TD>
     </TR>
 % }
 
-  <% include( '/elements/tr-input-lessthan_greaterthan.html',
-                'label' => 'Amount',
-               'field' => 'paid',
-            )
-  %>
+% if ( $table eq 'cust_pay' ) {
+
+% # payment batch
+% #  <& /elements/tr-select-batchnum.html &>
+
+% #payment "entry" batch (should probably just all become the same thing)
+  <& /elements/tr-select-paybatch.html &>
+
+% }
+
+  <& /elements/tr-input-lessthan_greaterthan.html,
+                'label' => emt('Amount'),
+                'field' => 'paid',
+  &>
+
+
+</TABLE>
+<BR>
+
+
+<TABLE BGCOLOR="#cccccc" CELLSPACING=0>
+
+  <TR>
+    <TH CLASS="background" COLSPAN=2 ALIGN="left">
+      <FONT SIZE="+1"><% mt('Customer search options') |h %></FONT>
+    </TH>
+  </TR>
+
+  <& /elements/tr-select-agent.html,
+                 'curr_value'    => scalar($cgi->param('agentnum')),
+                 'label'         => emt('Agent'),
+                 'disable_empty' => 0,
+  &>
+
+  <& /elements/tr-select-cust_class.html,
+       'label'        => emt('Customer class'),
+       'field'        => 'cust_classnum',
+       'multiple'     => 1,
+       'pre_options'  => [ 0 => emt('(none)') ],
+  &>
+
+</TABLE>
 
 % if ( $table eq 'cust_pay' ) { 
-  <% include( '/elements/tr-checkbox.html',
-                'label' => 'Include tax names',
-               'field' => 'tax_names',
+
+  <BR>
+  <TABLE BGCOLOR="#cccccc" CELLSPACING=0>
+
+  <TR>
+    <TH CLASS="background" COLSPAN=2 ALIGN="left">
+      <FONT SIZE="+1"><% mt('Display options') |h %></FONT>
+    </TH>
+  </TR>
+
+  <& /elements/tr-checkbox.html,
+                'label' => emt('Include tax names'),
+                'field' => 'tax_names',
                 'value' => 1,
-            )
-  %>
-% }
+  &>
+
+  <& /elements/tr-checkbox.html,
+                'label' => emt('Include order number'),
+                'field' => 'show_order_number',
+                'value' => 1,
+  &>
 
 </TABLE>
 
+% }
+
 <BR>
-<INPUT TYPE="submit" VALUE="Get Report">
+<INPUT TYPE="submit" VALUE="<% mt('Get Report') |h %>">
 
 </FORM>
 
-<% include('/elements/footer.html') %>
+<& /elements/footer.html &>
 <%init>
 
 my %opt = @_;
@@ -137,9 +176,39 @@ my $name_singular = $opt{'name_singular'};
 die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
 
+my $conf = new FS::Conf;
+
 my $void = $cgi->param('void') ? 1 : 0;
+my $unapplied = $cgi->param('unapplied') ? 1 : 0;
 
-my $title = $void ? "Voided $name_singular report" : "\u$name_singular report";
+my $title = $void ? "Voided $name_singular report" :
+            $unapplied ? "Unapplied $name_singular report" :
+            "\u$name_singular report" ;
 $table .= '_void' if $void;
 
+my $has_reason = dbdef->table($table)->column('reasonnum');
+
+tie (my %payby, 'Tie::IxHash',
+  'CARD-VisaMC'    => 'credit card (Visa/MasterCard)',
+  'CARD-Amex'      => 'credit card (American Express)',
+  'CARD-Discover'  => 'credit card (Discover)',
+  'CARD-Maestro'   => 'credit card (Maestro/Switch/Solo)',
+  'CARD-Tokenized' => 'credit card (Tokenized)',
+
+  'CHEK'           => 'electronic check / ACH',
+  'BILL'           => 'check',
+  'CASH'           => 'cash',
+  'PPAL'           => 'Paypal',
+  'APPL'           => 'Apple Store',
+  'ANRD'           => 'Android Market',
+
+  'PREP'           => 'prepaid card',
+  'WIRE'           => 'wire transfer',
+  'WEST'           => 'Western Union',
+  'IDTP'           => 'IDT Payment Services',
+  'EDI'            => 'Electronic Debit (EDI)',
+  'MCRD'           => 'manual credit card',
+  'MCHK'           => 'manual electronic check',
+);
+
 </%init>