<& /elements/header-popup.html, 'Credit line items' &>
% my $old_invnum = 0; %# foreach my $cust_bill_pkg ( @cust_bill_pkg ) { % foreach my $item ( @items ) { % my( $setuprecur, $cust_bill_pkg ) = @$item; % my $method = $setuprecur eq 'setup' ? 'setup' : 'recur'; % my $amount = $cust_bill_pkg->$method(); % my $credited = $cust_bill_pkg->credited('', '', 'setuprecur'=>$method); % $amount -= $credited; % $amount = sprintf('%.2f', $amount); % next unless $amount > 0; % if ( $cust_bill_pkg->invnum ne $old_invnum ) { % $old_invnum = $cust_bill_pkg->invnum; % } % my $el_name = 'billpkgnum'. $cust_bill_pkg->billpkgnum. '-'. $setuprecur; %# show one-time/setup vs recur vs usage? % }
 
Invoice #<% $cust_bill_pkg->invnum %> - <% time2str($date_format, $cust_bill_pkg->cust_bill->_date) %>
<% $cust_bill_pkg->desc |h %><% $money_char. $amount %> <% $money_char %>
 
Subtotal: <% $money_char %><% sprintf('%.2f', 0) %>
Taxes: <% $money_char %><% sprintf('%.2f', 0) %>
Total credit amount: <% $money_char %><% sprintf('%.2f', 0) %>
<& /elements/tr-select-reason.html, 'field' => 'reasonnum', 'reason_class' => 'R', #XXX reconcile both this and show_taxes wanting to enable this 'id' => 'select_reason', 'control_button' => 'credit_button', 'cgi' => $cgi, &> % if ( $conf->exists('credits-auto-apply-disable') ) { % } else { % }
<% mt('Additional info') |h %>
<% mt('Apply to selected line items') |h %>

<% include( '/elements/xmlhttp.html', 'url' => $p.'misc/xmlhttp-cust_bill_pkg-calculate_taxes.html', 'subs' => [ 'calculate_taxes' ], ) %> <%init> my $curuser = $FS::CurrentUser::CurrentUser; 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 #slightly more false laziness w/httemplate/edit/elements/ApplicationCommon.html # show_taxes & calc_total here/do_calculate_tax there my $conf = new FS::Conf; my $money_char = $conf->config('money_char') || '$'; my $date_format = $conf->config('date_format') || '%m/%d/%Y'; $cgi->param('custnum') =~ /^(\d+)$/ or die 'illegal custnum'; my $custnum = $1; my $cust_main = qsearchs({ 'table' => 'cust_main', 'hashref' => { 'custnum' => $custnum }, 'extra_sql' => ' AND '. $curuser->agentnums_sql, }) or die 'unknown customer'; 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 or feepart IS NOT NULL)", 'order_by' => 'ORDER BY invnum ASC, billpkgnum ASC', }); my @items = map { my %hash = $_->disintegrate; map [ $_, $hash{$_} ], keys(%hash); } @cust_bill_pkg; #omit line items which have been previously credited? would be nice