invoice_sections_with_taxes per-agent, RT#79636
[freeside.git] / httemplate / edit / credit-cust_bill_pkg.html
index f5c4eef..85f7943 100644 (file)
   <TH ALIGN="right" COLSPAN=2>Total credit amount: </TD>
   <TH ALIGN="right" ID="total_td"><% $money_char %><% sprintf('%.2f', 0) %></TD>
 </TR>
-<INPUT TYPE="hidden" NAME="amount" ID="total_el" VALUE="0.00">
 
 </table>
 
+<INPUT TYPE="hidden" NAME="amount" ID="total_el" VALUE="0.00">
+
 <table>
 
 <& /elements/tr-select-reason.html,
               'field'          => 'reasonnum',
               'reason_class'   => 'R',
-              #XXX reconcile both this and show_taxes wanteding to enable this
-              'control_button' => "document.getElementById('credit_button')",
+              #XXX reconcile both this and show_taxes wanting to enable this
+              'id'             => 'select_reason',
+              'control_button' => 'credit_button',
               'cgi'            => $cgi,
 &>
 
   </TD>
 </TR>
 
+% if ( $conf->exists('credits-auto-apply-disable') ) {
+        <INPUT TYPE="HIDDEN" NAME="apply" VALUE="no">
+% } else {
+  <TR>
+    <TD ALIGN="right"><% mt('Apply to selected line items') |h %></TD>
+    <TD><SELECT NAME="apply"><OPTION VALUE="yes" SELECTED><% mt('yes') |h %><OPTION><% mt('no') |h %></SELECT></TD>
+  </TR>
+% }
+
 </table>
 
 <BR>
 %>
 <SCRIPT TYPE="text/javascript">
 
+document.getElementById('select_reason').disabled = true;
+  // start it disabled because no line items are selected yet
 function show_taxes(arg) {
   var argsHash = eval('(' + arg + ')');
 
@@ -177,14 +190,16 @@ function show_taxes(arg) {
 
   //XXX reconcile both this and the reason selector wanteding to enable this
   if ( total > 0 ) {
-    document.getElementById('credit_button').disabled = false;
+    //document.getElementById('credit_button').disabled = false;
+    document.getElementById('select_reason').disabled = false;
   }
     
 }
 
 function calc_total(what) {
 
-  document.getElementById('credit_button').disabled = true;
+  //document.getElementById('credit_button').disabled = true;
+  document.getElementById('select_reason').disabled = true;
 
   var subtotal = 0;
   // bah, a pain, just using an attribute var re = /^billpkgnum(\d+)$/;
@@ -230,7 +245,7 @@ function calc_total(what) {
 <%init>
 
 my $curuser = $FS::CurrentUser::CurrentUser;
-die "access denied" unless $curuser->access_right('Post credit');
+die "access denied" unless $curuser->access_right('Credit line items');
 
 #a tiny bit of false laziness w/search/cust_bill_pkg.cgi, but we're pretty
 # specialized and a piece of UI, not a report
@@ -254,7 +269,8 @@ my @cust_bill_pkg = qsearch({
   'select'    => 'cust_bill_pkg.*',
   'table'     => 'cust_bill_pkg',
   'addl_from' => 'LEFT JOIN cust_bill USING (invnum)',
-  'extra_sql' => "WHERE custnum = $custnum AND pkgnum != 0",
+  'extra_sql' => "WHERE custnum = $custnum ".
+                 "AND (pkgnum != 0 or feepart IS NOT NULL)",
   'order_by'  => 'ORDER BY invnum ASC, billpkgnum ASC',
 });