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=4 BGCOLOR="#f8f8f8"> </TD></TR>
24 <TR><TH COLSPAN=4 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;
28 % my $el_name = 'billpkgnum'. $cust_bill_pkg->billpkgnum. '-'. $setuprecur;
31 <INPUT TYPE = "checkbox"
32 NAME = "<% $el_name %>"
34 onClick = "calc_total(this)"
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>
43 <% $money_char %><INPUT TYPE = "text"
44 NAME = "<% $el_name %>-amount"
45 ID = "<% $el_name %>-amount"
46 VALUE = "<% $amount %>"
48 onChange = "calc_total(this)"
49 STYLE = "text-align:right;"
57 <TR><TD COLSPAN=4 BGCOLOR="#f8f8f8"> </TD></TR>
60 <TD ALIGN="right" COLSPAN=2>Subtotal: </TD>
61 <TD ALIGN="right" ID="subtotal_td"><% $money_char %><% sprintf('%.2f', 0) %></TD>
65 <TD ALIGN="right" COLSPAN=2>Taxes: </TD>
66 <TD ALIGN="right" ID="taxtotal_td"><% $money_char %><% sprintf('%.2f', 0) %></TD>
70 <TH ALIGN="right" COLSPAN=2>Total credit amount: </TD>
71 <TH ALIGN="right" ID="total_td"><% $money_char %><% sprintf('%.2f', 0) %></TD>
73 <INPUT TYPE="hidden" NAME="amount" ID="total_el" VALUE="0.00">
79 <& /elements/tr-select-reason.html,
80 'field' => 'reasonnum',
81 'reason_class' => 'R',
82 #XXX reconcile both this and show_taxes wanteding to enable this
83 'control_button' => "document.getElementById('credit_button')",
88 <TD ALIGN="right"><% mt('Additional info') |h %></TD>
90 <INPUT TYPE="text" NAME="addlinfo" VALUE="<% $cgi->param('addlinfo') |h %>">
97 <INPUT TYPE="submit" ID="credit_button" VALUE="Credit" DISABLED>
101 <% include( '/elements/xmlhttp.html',
102 'url' => $p.'misc/xmlhttp-cust_bill_pkg-calculate_taxes.html',
103 'subs' => [ 'calculate_taxes' ],
106 <SCRIPT TYPE="text/javascript">
108 function show_taxes(arg) {
109 var argsHash = eval('(' + arg + ')');
111 //XXX add an 'ErrorMessage' section to the HTML and re-enable
112 //var error = argsHash['error'];
114 //var paragraph = document.getElementById('ErrorMessage');
116 // paragraph.innerHTML = 'Error: ' + error;
117 // paragraph.style.color = '#ff0000';
119 // paragraph.innerHTML = '';
122 var taxlines = argsHash['taxlines'];
124 //XXX display the tax lines? just a total will do for now
126 // var table = document.getElementById('ApplicationTable');
128 // var aFoundRow = 0;
129 // for (i = 0; taxlines[i]; i++) {
130 // var itemdesc = taxlines[i][0];
131 // var locnum = taxlines[i][2];
132 // if (taxlines[i][3]) {
133 // locnum = taxlines[i][3];
137 // for (var row = 2; table.rows[row]; row++) {
138 // var inputs = table.rows[row].getElementsByTagName('input');
139 // if (! inputs.length) {
140 // while ( table.rows[row] ) {
141 // table.deleteRow(row);
145 // if ( inputs.item(4).value == itemdesc && inputs.item(2).value == locnum )
147 // inputs.item(0).value = taxlines[i][1];
148 // aFoundRow = found = row;
153 // var row = table.insertRow(table.rows.length);
154 // var warning_cell = document.createElement('TD');
155 // warning_cell.style.color = '#ff0000';
156 // warning_cell.colSpan = 2;
157 // warning_cell.innerHTML = 'Calculated Tax - ' + itemdesc + ' - ' +
158 // taxlines[i][1] + ' will not be applied';
159 // row.appendChild(warning_cell);
164 // sub_changed(table.rows[aFoundRow].getElementsByTagName('input').item(0));
167 var subtotal = parseFloat( argsHash['subtotal'] );
169 var taxtotal = parseFloat( argsHash['taxtotal'] );
170 document.getElementById('taxtotal_td').innerHTML =
171 '<% $money_char %>' + taxtotal.toFixed(2);
173 var total = subtotal + taxtotal;
174 document.getElementById('total_td').innerHTML =
175 '<% $money_char %>' + total.toFixed(2);
176 document.getElementById('total_el').value = total.toFixed(2);
178 //XXX reconcile both this and the reason selector wanteding to enable this
180 document.getElementById('credit_button').disabled = false;
185 function calc_total(what) {
187 document.getElementById('credit_button').disabled = true;
190 // bah, a pain, just using an attribute var re = /^billpkgnum(\d+)$/;
192 var el = what.form.elements;
193 var billpkgnums = [];
194 var setuprecurs = [];
196 for (var i=0; i<el.length; i++) {
198 if ( el[i].type == 'checkbox' ) {
199 var amount_el = document.getElementById( el[i].id + '-amount' );
200 if ( el[i].checked ) {
201 amount_el.disabled = false;
202 var amount = amount_el.value;
203 subtotal += parseFloat( amount );
204 amounts.push( amount );
205 billpkgnums.push( el[i].getAttribute('data-billpkgnum') );
206 setuprecurs.push( el[i].getAttribute('data-setuprecur') );
208 amount_el.disabled = true;
214 document.getElementById('subtotal_td').innerHTML =
215 '<% $money_char %>' + subtotal.toFixed(2);
217 var args = new Array(
218 'custnum', '<% $custnum %>',
219 'subtotal', subtotal,
220 'billpkgnums', billpkgnums.join(),
221 'setuprecurs', setuprecurs.join(),
222 'amounts', amounts.join()
225 calculate_taxes( args, show_taxes );
232 my $curuser = $FS::CurrentUser::CurrentUser;
233 die "access denied" unless $curuser->access_right('Post credit');
235 #a tiny bit of false laziness w/search/cust_bill_pkg.cgi, but we're pretty
236 # specialized and a piece of UI, not a report
237 #slightly more false laziness w/httemplate/edit/elements/ApplicationCommon.html
238 # show_taxes & calc_total here/do_calculate_tax there
240 my $conf = new FS::Conf;
241 my $money_char = $conf->config('money_char') || '$';
242 my $date_format = $conf->config('date_format') || '%m/%d/%Y';
244 $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum';
247 my $cust_main = qsearchs({
248 'table' => 'cust_main',
249 'hashref' => { 'custnum' => $custnum },
250 'extra_sql' => ' AND '. $curuser->agentnums_sql,
251 }) or die 'unknown customer';
253 my @cust_bill_pkg = qsearch({
254 'select' => 'cust_bill_pkg.*',
255 'table' => 'cust_bill_pkg',
256 'addl_from' => 'LEFT JOIN cust_bill USING (invnum)',
257 'extra_sql' => "WHERE custnum = $custnum AND pkgnum != 0",
258 'order_by' => 'ORDER BY invnum ASC, billpkgnum ASC',
261 my @items = map { my %hash = $_->disintegrate;
262 map [ $_, $hash{$_} ],
267 #omit line items which have been previously credited? would be nice