payment and credit applications have separate "apply to refund" choices now, and...
[freeside.git] / httemplate / edit / process / elements / ApplicationCommon.html
1 <%doc>
2
3 Examples:
4
5   #cust_bill_pay
6   include('elements/ApplicationCommon.html',
7     'error_redirect' => 'cust_bill_pay.cgi',
8     'src_table'      => 'cust_pay',
9     'src_thing'      => 'payment',
10     'link_table'     => 'cust_bill_pay',
11   )
12
13   #cust_credit_bill
14   include('elements/ApplicationCommon.html',
15     'error_redirect' => 'cust_credit_bill.cgi',
16     'src_table'      => 'cust_credit',
17     'src_thing'      => 'credit',
18     'link_table'     => 'cust_credit_bill',
19   )
20
21 </%doc>
22 %if ( $error ) {
23 %  $cgi->param('error', $error);
24 <% $cgi->redirect(popurl(2). $opt{error_redirect}. '?'. $cgi->query_string ) %>
25 %} else {
26 <% header("$src_thing application$to sucessful") %>
27   <SCRIPT TYPE="text/javascript">
28     window.top.location.reload();
29   </SCRIPT>
30   </BODY>
31   </HTML>
32 % } 
33 <%init>
34
35 my %opt = @_;
36
37 my $src_thing = ucfirst($opt{'src_thing'});
38 my $src_table = $opt{'src_table'};
39 my $src_pkey = dbdef->table($src_table)->primary_key;
40
41 my $to = $opt{'link_table'} =~  /refund/ ? ' to Refund' : '';
42
43 $cgi->param($src_pkey) =~ /^(\d+)$/ or die "Illegal $src_pkey!";
44 my $src_pkeyvalue = $1;
45
46 my $src = qsearchs($src_table, { $src_pkey => $src_pkeyvalue } )
47   or die "No such $src_pkey: $src_pkeyvalue";
48
49 my $cust_main = qsearchs('cust_main', { 'custnum' => $src->custnum } )
50   or die "Bogus $src_thing: not attached to customer";
51
52 my $custnum = $cust_main->custnum;
53
54 my $new;
55 #  $new = new FS::cust_refund ( {
56 #    'reason'  => 'Refunding payment', #enter reason in UI
57 #    'refund'  => $cgi->param('amount'),
58 #    'payby'   => 'BILL',
59 #    #'_date'   => $cgi->param('_date'),
60 #    'payinfo' => 'Cash', #enter payinfo in UI
61 #    'paynum' => $paynum,
62 #  } );
63 #} else {
64
65   my $class = 'FS::'. $opt{link_table};
66
67   $new = $class->new( {
68     map {
69       $_ => scalar($cgi->param($_));
70     } fields($opt{link_table})
71   } );
72
73 #}
74
75 my $error = $new->insert;
76
77 </%init>