6 include('elements/ApplicationCommon.html',
7 'form_action' => 'process/cust_bill_pay.cgi',
8 'src_table' => 'cust_pay',
9 'src_thing' => 'payment',
10 'dst_table' => 'cust_bill',
11 'dst_thing' => 'invoice',
15 include('elements/ApplicationCommon.html',
16 'form_action' => 'process/cust_credit_bill.cgi',
17 'src_table' => 'cust_credit',
18 'src_thing' => 'credit',
19 'dst_table' => 'cust_bill',
20 'dst_thing' => 'invoice',
24 include('elements/ApplicationCommon.html',
25 'form_action' => 'process/cust_pay_refund.cgi',
26 'src_table' => 'cust_pay',
27 'src_thing' => 'payment',
28 'dst_table' => 'cust_refund',
29 'dst_thing' => 'refund',
33 include('elements/ApplicationCommon.html',
34 'form_action' => 'process/cust_credit_refund.cgi',
35 'src_table' => 'cust_credit',
36 'src_thing' => 'credit',
37 'dst_table' => 'cust_refund',
38 'dst_thing' => 'refund',
42 <% include('/elements/header-popup.html', "Apply $src_thing$to" ) %>
44 <% include('/elements/error.html') %>
46 <FORM ACTION="<% $p1. $opt{'form_action'} %>" METHOD=POST>
48 <% $src_thing %> #<B><% $src_pkeyvalue %></B><BR>
49 <INPUT TYPE="hidden" NAME="<% $src_pkey %>" VALUE="<% $src_pkeyvalue %>">
51 <TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
54 <TD ALIGN="right">Date: </TD>
55 <TD><B><% time2str("%D", $src->_date) %></B></TD>
59 <TD ALIGN="right">Amount: </TD>
60 <TD><B><% $money_char %><% $src->amount %></B></TD>
64 <TD ALIGN="right">Unapplied amount: </TD>
65 <TD><B><% $money_char %><% $unapplied %></B></TD>
68 % if ( $src_table eq 'cust_credit' ) {
70 <TD ALIGN="right">Reason: </TD>
71 <TD><B><% $src->reason %></B></TD>
78 <SCRIPT TYPE="text/javascript">
79 function changed(what) {
80 dst = what.options[what.selectedIndex].value;
82 % foreach my $dst ( @dst ) {
84 if ( dst == <% $dst->$dst_pkey %> ) {
85 what.form.amount.value = "<% min($dst->$dst_unapplied, $unapplied) %>";
95 <TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
98 <TD ALIGN="right"><% $dst_thing %>: </TD>
99 <TD><SELECT NAME="<% $dst_pkey %>" SIZE=1 onChange="changed(this)">
102 % foreach my $dst ( @dst ) {
103 <OPTION<% $dst->$dst_pkey eq $dst_pkeyvalue ? ' SELECTED' : '' %> VALUE="<% $dst->$dst_pkey %>">#<% $dst->$dst_pkey %> - <% time2str("%D", $dst->_date) %> - $<% $dst->$dst_unapplied %>
111 <TD ALIGN="right">Amount: </TD>
112 <TD><% $money_char %><INPUT TYPE="text" NAME="amount" VALUE="<% $amount %>" SIZE=8 MAXLENGTH=8></TD>
118 <CENTER><INPUT TYPE="submit" VALUE="Apply"></CENTER>
122 <% include('/elements/footer.html') %>
128 my $conf = new FS::Conf;
129 my $money_char = $conf->config('money_char') || '$';
131 my $src_thing = ucfirst($opt{'src_thing'});
132 my $src_table = $opt{'src_table'};
133 my $src_pkey = dbdef->table($src_table)->primary_key;
135 my $dst_thing = ucfirst($opt{'dst_thing'});
136 my $dst_table = $opt{'dst_table'};
137 my $dst_pkey = dbdef->table($dst_table)->primary_key;
138 my $dst_unapplied = $dst_table eq 'cust_bill' ? 'owed' : 'unapplied';
140 my $to = $dst_table eq 'cust_refund' ? ' to Refund' : '';
142 my($src_pkeyvalue, $amount, $dst_pkeyvalue);
143 if ( $cgi->param('error') ) {
144 $src_pkeyvalue = $cgi->param($src_pkey);
145 $amount = $cgi->param('amount');
146 $dst_pkeyvalue = $cgi->param($dst_pkey);
148 my($query) = $cgi->keywords;
155 my $otaker = getotaker;
159 my $src = qsearchs($src_table, { $src_pkey => $src_pkeyvalue } );
160 die "$src_thing $src_pkeyvalue not found!" unless $src;
162 my $unapplied = $src->unapplied;
164 my @dst = sort { $a->_date <=> $b->_date
165 or $a->$dst_pkey <=> $b->$dst_pkey
167 grep { $_->$dst_unapplied != 0 }
168 qsearch($dst_table, { 'custnum' => $src->custnum } );