finish UI improvements wrt refunds: now you have to post a check or cash refund expli...
[freeside.git] / httemplate / edit / elements / ApplicationCommon.html
1 <%doc>
2
3 Examples:
4
5   #cust_bill_pay
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',
12   )
13
14   #cust_credit_bill
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',
21   )
22
23   #cust_pay_refund
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',
30   )
31
32   #cust_credit_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',
39   )
40
41 </%doc>
42 <% include('/elements/header-popup.html', "Apply $src_thing$to" ) %>
43
44 <% include('/elements/error.html') %>
45
46 <FORM ACTION="<% $p1. $opt{'form_action'} %>" NAME="ApplicationForm" ID="ApplicationForm" METHOD=POST>
47
48 <% $src_thing %> #<B><% $src_pkeyvalue %></B><BR>
49 <INPUT TYPE="hidden" NAME="<% $src_pkey %>" VALUE="<% $src_pkeyvalue %>">
50
51 <TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
52
53 <TR>
54   <TD ALIGN="right">Date: </TD>
55   <TD><B><% time2str("%D", $src->_date) %></B></TD>
56 </TR>
57
58 <TR>
59   <TD ALIGN="right">Amount: </TD>
60   <TD><B><% $money_char %><% $src->amount %></B></TD>
61 </TR>
62
63 <TR>
64   <TD ALIGN="right">Unapplied amount: </TD>
65   <TD><B><% $money_char %><% $unapplied %></B></TD>
66 </TR>
67
68 % if ( $src_table eq 'cust_credit' ) {
69     <TR>
70       <TD ALIGN="right">Reason: </TD>
71       <TD><B><% $src->reason %></B></TD>
72     </TR>
73 % }
74
75 </TABLE>
76 <BR>
77
78 <SCRIPT TYPE="text/javascript">
79 function changed(what) {
80   dst = what.options[what.selectedIndex].value;
81
82   if ( dst == '' ) {
83     what.form.submit.disabled=true;
84     return true;
85   }
86
87   what.form.submit.disabled=false;
88
89 % foreach my $dst ( @dst ) {
90
91     if ( dst == <% $dst->$dst_pkey %> ) {
92       what.form.amount.value = "<% min($dst->$dst_unapplied, $unapplied) %>";
93     }
94
95 % } 
96
97 }
98 </SCRIPT>
99
100 Apply to:
101
102 <TABLE BGCOLOR="#cccccc" BORDER=0 CELLSPACING=0>
103
104 <TR>
105   <TD ALIGN="right"><% $dst_thing %>: </TD>
106   <TD><SELECT NAME="<% $dst_pkey %>" SIZE=1 onChange="changed(this)">
107 <OPTION VALUE="">Select <% $dst_thing %>
108
109 % foreach my $dst ( @dst ) { 
110   <OPTION<% $dst->$dst_pkey eq $dst_pkeyvalue ? ' SELECTED' : '' %> VALUE="<% $dst->$dst_pkey %>">#<% $dst->$dst_pkey %> - <% time2str("%D", $dst->_date) %> - $<% $dst->$dst_unapplied %>
111 % } 
112
113 </SELECT>
114   </TD>
115 </TR>
116
117 <TR>
118   <TD ALIGN="right">Amount: </TD>
119   <TD><% $money_char %><INPUT TYPE="text" NAME="amount" VALUE="<% $amount %>" SIZE=8 MAXLENGTH=8></TD>
120 </TR>
121
122 </TABLE>
123
124 <BR>
125 <CENTER><INPUT TYPE="submit" VALUE="Apply" NAME="submit" ID="submit" DISABLED></CENTER>
126
127 </FORM>
128
129 <% include('/elements/footer.html') %>
130
131 <%init>
132
133 my %opt = @_;
134
135 my $conf = new FS::Conf;
136 my $money_char = $conf->config('money_char') || '$';
137
138 my $src_thing = ucfirst($opt{'src_thing'});
139 my $src_table = $opt{'src_table'};
140 my $src_pkey = dbdef->table($src_table)->primary_key;
141
142 my $dst_thing = ucfirst($opt{'dst_thing'});
143 my $dst_table = $opt{'dst_table'};
144 my $dst_pkey = dbdef->table($dst_table)->primary_key;
145 my $dst_unapplied = $dst_table eq 'cust_bill' ? 'owed' : 'unapplied';
146
147 my $to = $dst_table eq 'cust_refund' ? ' to Refund' : '';
148
149 my($src_pkeyvalue, $amount, $dst_pkeyvalue);
150 if ( $cgi->param('error') ) {
151   $src_pkeyvalue = $cgi->param($src_pkey);
152   $amount    = $cgi->param('amount');
153   $dst_pkeyvalue    = $cgi->param($dst_pkey);
154 } else {
155   my($query) = $cgi->keywords;
156   $query =~ /^(\d+)$/;
157   $src_pkeyvalue = $1;
158   $amount = '';
159   $dst_pkeyvalue = '';
160 }
161
162 my $otaker = getotaker;
163
164 my $p1 = popurl(1);
165
166 my $src = qsearchs($src_table, { $src_pkey => $src_pkeyvalue } );
167 die "$src_thing $src_pkeyvalue not found!" unless $src;
168
169 my $unapplied = $src->unapplied;
170
171 my @dst = sort {    $a->_date     <=> $b->_date
172                  or $a->$dst_pkey <=> $b->$dst_pkey
173                }
174           grep { $_->$dst_unapplied != 0 }
175           qsearch($dst_table, { 'custnum' => $src->custnum } );
176
177 </%init>