customer view work:
[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     %><%= header('Payment entered') %>
39     <SCRIPT TYPE="text/javascript">
40       window.top.location.reload();
41     </SCRIPT>
42
43     </BODY></HTML>
44     <%
45
46   } elsif ( $link eq 'custnum' ) {
47     print $cgi->redirect(popurl(3). "view/cust_main.cgi?$linknum");
48   } else {
49     die "unknown link $link";
50   }
51
52 }
53
54 %>