<%doc> Examples: #cust_bill_pay include('elements/ApplicationCommon.html', 'form_action' => 'process/cust_bill_pay.cgi', 'src_table' => 'cust_pay', 'src_thing' => 'payment', 'dst_table' => 'cust_bill', 'dst_thing' => 'invoice', ) #cust_credit_bill include('elements/ApplicationCommon.html', 'form_action' => 'process/cust_credit_bill.cgi', 'src_table' => 'cust_credit', 'src_thing' => 'credit', 'dst_table' => 'cust_bill', 'dst_thing' => 'invoice', ) #cust_pay_refund include('elements/ApplicationCommon.html', 'form_action' => 'process/cust_pay_refund.cgi', 'src_table' => 'cust_pay', 'src_thing' => 'payment', 'dst_table' => 'cust_refund', 'dst_thing' => 'refund', ) #cust_credit_refund include('elements/ApplicationCommon.html', 'form_action' => 'process/cust_credit_refund.cgi', 'src_table' => 'cust_credit', 'src_thing' => 'credit', 'dst_table' => 'cust_refund', 'dst_thing' => 'refund', ) <% include('/elements/header-popup.html', "Apply $src_thing$to", '', 'onLoad="myOnLoadFunction();"') %> <% include('/elements/error.html') %>

<% $src_thing %> #<% $src_pkeyvalue %>
% if ( $src_table eq 'cust_credit' ) { % }
Date: <% time2str($date_format, $src->_date) %>
Amount: <% $money_char %><% $src_amount %> % if ($use_sub_dst_thing && $can_change_credit) { % }
Unapplied amount: <% $money_char %><% $unapplied %>
Reason: <% $src->reason %>

Apply to: % if ($use_sub_dst_thing && $src_pkey eq 'crednum') {
<% include( '/elements/xmlhttp.html', 'url' => $p.'misc/xmlhttp-calculate_taxes.html', 'subs' => [ 'calculate_taxes' ], ) %> %} % if ($use_sub_dst_thing) { % }
<% $dst_thing %>:
Amount: <% $money_char %> STYLE="text-align:right;">

<% include('/elements/footer.html') %> <%init> my %opt = @_; my $conf = new FS::Conf; my $money_char = $conf->config('money_char') || '$'; my $date_format = $conf->config('date_format') || '%m/%d/%Y'; my $src_thing = ucfirst($opt{'src_thing'}); my $src_table = $opt{'src_table'}; my $src_pkey = dbdef->table($src_table)->primary_key; my $dst_thing = ucfirst($opt{'dst_thing'}); my $dst_table = $opt{'dst_table'}; my $dst_pkey = dbdef->table($dst_table)->primary_key; my $dst_unapplied = $dst_table eq 'cust_bill' ? 'owed' : 'unapplied'; $opt{form_action} =~ /^process\/(.*)\./ or die "bad form action"; my $link_table = $1; my $use_sub_dst_thing = 0; $use_sub_dst_thing = 1 if ( $dst_table eq 'cust_bill' && $conf->exists("${link_table}_pkg-manual") ); my $can_change_credit = 0; $can_change_credit = 1 if ( $src_table eq 'cust_credit' && $FS::CurrentUser::CurrentUser->access_right('Post credit') && $FS::CurrentUser::CurrentUser->access_right('Delete credit') ); my $to = $dst_table eq 'cust_refund' ? ' to Refund' : ''; my($src_pkeyvalue, $amount, $dst_pkeyvalue, $src_amount); if ( $cgi->param('error') ) { $src_pkeyvalue = $cgi->param($src_pkey); $amount = $cgi->param('amount'); $dst_pkeyvalue = $cgi->param($dst_pkey); $src_amount = $cgi->param('src_amount'); } else { my($query) = $cgi->keywords; $query =~ /^(\d+)$/; $src_pkeyvalue = $1; $amount = ''; $dst_pkeyvalue = ''; } my $otaker = getotaker; my $p1 = popurl(1); my $src = qsearchs($src_table, { $src_pkey => $src_pkeyvalue } ); die "$src_thing $src_pkeyvalue not found!" unless $src; $src_amount = $src->amount unless $cgi->param('error'); my $unapplied = $src->unapplied; my @dst = sort { $a->_date <=> $b->_date or $a->$dst_pkey <=> $b->$dst_pkey } grep { $_->$dst_unapplied != 0 } qsearch($dst_table, { 'custnum' => $src->custnum } ); my $row_generator = sub { my ($key, $cust_bill_pkg, $desc, $owed, $amount, $taxXnum) = @_; my ($num, $s_or_r, $taxlinenum) = split(':', $key); my $id = $cust_bill_pkg->pkgnum || 'Tax'; my $billpkgnum = $cust_bill_pkg->billpkgnum; my $s_or_r = $cust_bill_pkg->setup > 0 ? 'setup' : 'recur'; $amount = sprintf("%.2f", $amount); qq! var tablebody = document.getElementsByTagName('tbody').item(0); var row = table.insertRow(rownum+2); var pkg_cell = document.createElement('TD'); pkg_cell.style.textAlign = 'right'; pkg_cell.innerHTML = "$id - $desc - $owed:"; var amount_cell = document.createElement('TD'); amount_cell.innerHTML = "$money_char"; var amount_input = document.createElement('INPUT'); amount_input.setAttribute('name', 'subamount'+rownum); amount_input.setAttribute('id', 'subamount'+rownum); amount_input.style.textAlign = 'right'; amount_input.setAttribute('size', 8); amount_input.setAttribute('maxlength', 8); amount_input.setAttribute('rownum', rownum); amount_input.setAttribute('value', "$amount"); amount_input.setAttribute('onChange', "sub_changed(this);"); amount_cell.appendChild(amount_input); var subnum_input = document.createElement('INPUT'); subnum_input.setAttribute('name', 'subnum'+rownum); subnum_input.setAttribute('id', 'subnum'+rownum); subnum_input.setAttribute('type', 'hidden'); subnum_input.setAttribute('rownum', rownum); subnum_input.setAttribute('value', "$billpkgnum"); amount_cell.appendChild(subnum_input); var taxnum_input = document.createElement('INPUT'); taxnum_input.setAttribute('name', 'taxXlocationnum'+rownum); taxnum_input.setAttribute('id', 'taxXlocationnum'+rownum); taxnum_input.setAttribute('type', 'hidden'); taxnum_input.setAttribute('rownum', rownum); taxnum_input.setAttribute('value', "$taxXnum"); amount_cell.appendChild(taxnum_input); var s_or_r_input = document.createElement('INPUT'); s_or_r_input.setAttribute('name', 's_or_r'+rownum); s_or_r_input.setAttribute('id', 's_or_r'+rownum); s_or_r_input.setAttribute('type', 'hidden'); s_or_r_input.setAttribute('rownum', rownum); s_or_r_input.setAttribute('value', "$s_or_r"); amount_cell.appendChild(s_or_r_input); var itemdesc_input = document.createElement('INPUT'); itemdesc_input.setAttribute('name', 'itemdesc'+rownum); itemdesc_input.setAttribute('id', 'itemdesc'+rownum); itemdesc_input.setAttribute('type', 'hidden'); itemdesc_input.setAttribute('rownum', rownum); itemdesc_input.setAttribute('value', "$desc"); amount_cell.appendChild(itemdesc_input); row.appendChild(pkg_cell); row.appendChild(amount_cell); rownum++; !; }; my $key_generator = sub { my $listref = shift; my ($cust_bill_pkg, $amount, $hashref) = @$listref; my $setup_or_recur = $cust_bill_pkg->setup > 0 ? 'setup' : 'recur'; my $taxlinenum = $hashref->{billpkgtaxlocationnum} || $hashref->{billpkgtaxratelocationnum} || ''; join(':', $cust_bill_pkg->billpkgnum, $setup_or_recur, $taxlinenum); }; my $onload = 'return true;'; if ($cgi->param('error')) { my $set_sub_amounts = join(';', map { "myform.subamount$_.value = ". $cgi->param("subamount$_") } grep { /.+/ } map { /^subnum(\d+)$/ ? $1 : '' } $cgi->param ); $set_sub_amounts &&= "$set_sub_amounts;sub_changed(myform.subamount0)"; $onload = qq! var myform = document.getElementById('ApplicationForm'); changed(myform.elements['$dst_pkey']); $set_sub_amounts; return true; !; }