Will things ever be the same again?
[freeside.git] / httemplate / edit / process / cust_pay.cgi
1 %
2 %
3 %$cgi->param('linknum') =~ /^(\d+)$/
4 %  or die "Illegal linknum: ". $cgi->param('linknum');
5 %my $linknum = $1;
6 %
7 %$cgi->param('link') =~ /^(custnum|invnum|popup)$/
8 %  or die "Illegal link: ". $cgi->param('link');
9 %my $field = my $link = $1;
10 %$field = 'custnum' if $field eq 'popup';
11 %
12 %my $_date = str2time($cgi->param('_date'));
13 %
14 %my $new = new FS::cust_pay ( {
15 %  $field => $linknum,
16 %  _date  => $_date,
17 %  map {
18 %    $_, scalar($cgi->param($_));
19 %  } qw(paid payby payinfo paybatch)
20 %  #} fields('cust_pay')
21 %} );
22 %
23 %my $error = $new->insert;
24 %
25 %if ($error) {
26 %  $cgi->param('error', $error);
27 %  print $cgi->redirect(popurl(2). 'cust_pay.cgi?'. $cgi->query_string );
28 %} elsif ( $field eq 'invnum' ) {
29 %  print $cgi->redirect(popurl(3). "view/cust_bill.cgi?$linknum");
30 %} elsif ( $field eq 'custnum' ) {
31 %  if ( $cgi->param('apply') eq 'yes' ) {
32 %    my $cust_main = qsearchs('cust_main', { 'custnum' => $linknum })
33 %      or die "unknown custnum $linknum";
34 %    $cust_main->apply_payments;
35 %  }
36 %  if ( $link eq 'popup' ) {
37 %
38 %    
39 <% header('Payment entered') %>
40     <SCRIPT TYPE="text/javascript">
41       window.top.location.reload();
42     </SCRIPT>
43
44     </BODY></HTML>
45 %
46 %
47 %  } elsif ( $link eq 'custnum' ) {
48 %    print $cgi->redirect(popurl(3). "view/cust_main.cgi?$linknum");
49 %  } else {
50 %    die "unknown link $link";
51 %  }
52 %
53 %}
54 %
55 %
56