1 <& /elements/header-popup.html, 'Credit line items' &>
3 <FORM ACTION="process/credit-cust_bill_pkg.html" METHOD="POST">
4 <INPUT TYPE="hidden" NAME="crednum" VALUE="">
5 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum |h %>">
6 <INPUT TYPE="hidden" NAME="paybatch" VALUE="">
7 <INPUT TYPE="hidden" NAME="_date" VALUE="<% time %>">
11 %# foreach my $cust_bill_pkg ( @cust_bill_pkg ) {
12 % foreach my $item ( @items ) {
13 % my( $setuprecur, $cust_bill_pkg ) = @$item;
15 % my $method = $setuprecur eq 'setup' ? 'setup' : 'recur';
16 % my $amount = $cust_bill_pkg->$method();
17 % my $credited = $cust_bill_pkg->credited('', '', 'setuprecur'=>$method);
18 % $amount -= $credited;
19 % $amount = sprintf('%.2f', $amount);
20 % next unless $amount > 0;
22 % if ( $cust_bill_pkg->invnum ne $old_invnum ) {
23 <TR><TD COLSPAN=3 BGCOLOR="#f8f8f8"> </TD></TR>
24 <TR><TH COLSPAN=3 BGCOLOR="#f8f8f8" ALIGN="left">Invoice #<% $cust_bill_pkg->invnum %> - <% time2str($date_format, $cust_bill_pkg->cust_bill->_date) %></TD></TR>
25 % $old_invnum = $cust_bill_pkg->invnum;
30 <INPUT TYPE = "checkbox"
31 NAME = "billpkgnum<% $cust_bill_pkg->billpkgnum.'-'. $setuprecur %>"
32 VALUE = "<% $amount %>"
33 onClick = "calc_total(this)"
34 data-amount = "<% $amount %>"
35 data-billpkgnum = "<% $cust_bill_pkg->billpkgnum %>"
36 data-setuprecur = "<% $setuprecur %>"
39 <TD BGCOLOR="#ffffff"><% $cust_bill_pkg->desc |h %></TD>
40 %# show one-time/setup vs recur vs usage?
41 <TD BGCOLOR="#ffffff" ALIGN="right"><% $money_char. $amount %></TD>
46 <TR><TD COLSPAN=3 BGCOLOR="#f8f8f8"> </TD></TR>
49 <TD ALIGN="right">Subtotal: </TD>
50 <TD ALIGN="right" ID="subtotal_td"><% $money_char %><% sprintf('%.2f', 0) %></TD>
54 <TD ALIGN="right">Taxes: </TD>
55 <TD ALIGN="right" ID="taxtotal_td"><% $money_char %><% sprintf('%.2f', 0) %></TD>
59 <TH ALIGN="right">Total credit amount: </TD>
60 <TH ALIGN="right" ID="total_td"><% $money_char %><% sprintf('%.2f', 0) %></TD>
62 <INPUT TYPE="hidden" NAME="amount" ID="total_el" VALUE="0.00">
68 <& /elements/tr-select-reason.html,
69 'field' => 'reasonnum',
70 'reason_class' => 'R',
71 #XXX reconcile both this and show_taxes wanteding to enable this
72 'id' => 'select_reason',
73 'control_button' => "document.getElementById('credit_button')",
78 <TD ALIGN="right"><% mt('Additional info') |h %></TD>
80 <INPUT TYPE="text" NAME="addlinfo" VALUE="<% $cgi->param('addlinfo') |h %>">
87 <INPUT TYPE="submit" ID="credit_button" VALUE="Credit" DISABLED>
91 <% include( '/elements/xmlhttp.html',
92 'url' => $p.'misc/xmlhttp-cust_bill_pkg-calculate_taxes.html',
93 'subs' => [ 'calculate_taxes' ],
96 <SCRIPT TYPE="text/javascript">
98 document.getElementById('select_reason').disabled = true;
99 // start it disabled because no line items are selected yet
100 function show_taxes(arg) {
101 var argsHash = eval('(' + arg + ')');
103 //XXX add an 'ErrorMessage' section to the HTML and re-enable
104 //var error = argsHash['error'];
106 //var paragraph = document.getElementById('ErrorMessage');
108 // paragraph.innerHTML = 'Error: ' + error;
109 // paragraph.style.color = '#ff0000';
111 // paragraph.innerHTML = '';
114 var taxlines = argsHash['taxlines'];
116 //XXX display the tax lines? just a total will do for now
118 // var table = document.getElementById('ApplicationTable');
120 // var aFoundRow = 0;
121 // for (i = 0; taxlines[i]; i++) {
122 // var itemdesc = taxlines[i][0];
123 // var locnum = taxlines[i][2];
124 // if (taxlines[i][3]) {
125 // locnum = taxlines[i][3];
129 // for (var row = 2; table.rows[row]; row++) {
130 // var inputs = table.rows[row].getElementsByTagName('input');
131 // if (! inputs.length) {
132 // while ( table.rows[row] ) {
133 // table.deleteRow(row);
137 // if ( inputs.item(4).value == itemdesc && inputs.item(2).value == locnum )
139 // inputs.item(0).value = taxlines[i][1];
140 // aFoundRow = found = row;
145 // var row = table.insertRow(table.rows.length);
146 // var warning_cell = document.createElement('TD');
147 // warning_cell.style.color = '#ff0000';
148 // warning_cell.colSpan = 2;
149 // warning_cell.innerHTML = 'Calculated Tax - ' + itemdesc + ' - ' +
150 // taxlines[i][1] + ' will not be applied';
151 // row.appendChild(warning_cell);
156 // sub_changed(table.rows[aFoundRow].getElementsByTagName('input').item(0));
159 var subtotal = parseFloat( argsHash['subtotal'] );
161 var taxtotal = parseFloat( argsHash['taxtotal'] );
162 document.getElementById('taxtotal_td').innerHTML =
163 '<% $money_char %>' + taxtotal.toFixed(2);
165 var total = subtotal + taxtotal;
166 document.getElementById('total_td').innerHTML =
167 '<% $money_char %>' + total.toFixed(2);
168 document.getElementById('total_el').value = total.toFixed(2);
170 //XXX reconcile both this and the reason selector wanteding to enable this
172 //document.getElementById('credit_button').disabled = false;
173 document.getElementById('select_reason').disabled = false;
178 function calc_total(what) {
180 //document.getElementById('credit_button').disabled = true;
181 document.getElementById('select_reason').disabled = true;
184 // bah, a pain, just using an attribute var re = /^billpkgnum(\d+)$/;
186 var el = what.form.elements;
187 var billpkgnums = [];
188 var setuprecurs = [];
190 for (var i=0; i<el.length; i++) {
191 if ( el[i].type == 'checkbox' && el[i].checked ) {
192 subtotal += parseFloat( el[i].getAttribute('data-amount') );
193 amounts.push( el[i].getAttribute('data-amount') );
194 billpkgnums.push( el[i].getAttribute('data-billpkgnum') );
195 setuprecurs.push( el[i].getAttribute('data-setuprecur') );
199 document.getElementById('subtotal_td').innerHTML =
200 '<% $money_char %>' + subtotal.toFixed(2);
202 var args = new Array(
203 'custnum', '<% $custnum %>',
204 'subtotal', subtotal,
205 'billpkgnums', billpkgnums.join(),
206 'setuprecurs', setuprecurs.join(),
207 'amounts', amounts.join()
210 calculate_taxes( args, show_taxes );
217 my $curuser = $FS::CurrentUser::CurrentUser;
218 die "access denied" unless $curuser->access_right('Post credit');
220 #a tiny bit of false laziness w/search/cust_bill_pkg.cgi, but we're pretty
221 # specialized and a piece of UI, not a report
222 #slightly more false laziness w/httemplate/edit/elements/ApplicationCommon.html
223 # show_taxes & calc_total here/do_calculate_tax there
225 my $conf = new FS::Conf;
226 my $money_char = $conf->config('money_char') || '$';
227 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
229 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
232 my $cust_main = qsearchs({
233 'table' => 'cust_main',
234 'hashref' => { 'custnum' => $custnum },
235 'extra_sql' => ' AND '. $curuser->agentnums_sql,
236 }) or die 'unknown customer';
238 my @cust_bill_pkg = qsearch({
239 'select' => 'cust_bill_pkg.*',
240 'table' => 'cust_bill_pkg',
241 'addl_from' => 'LEFT JOIN cust_bill USING (invnum)',
242 'extra_sql' => "WHERE custnum = $custnum AND pkgnum != 0",
243 'order_by' => 'ORDER BY invnum ASC, billpkgnum ASC',
246 my @items = map { my %hash = $_->disintegrate;
247 map [ $_, $hash{$_} ],
252 #omit line items which have been previously credited? would be nice