This commit was generated by cvs2svn to compensate for changes in r12472,
[freeside.git] / httemplate / edit / process / cust_pay.cgi
1 %if ($error) {
2 %  $cgi->param('error', $error);
3 <% $cgi->redirect(popurl(2). 'cust_pay.cgi?'. $cgi->query_string ) %>
4 %} elsif ( $field eq 'invnum' ) {
5 <% $cgi->redirect(popurl(3). "view/cust_bill.cgi?$linknum") %>
6 %} elsif ( $field eq 'custnum' ) {
7 %  if ( $cgi->param('apply') eq 'yes' ) {
8 %    my $cust_main = qsearchs('cust_main', { 'custnum' => $linknum })
9 %      or die "unknown custnum $linknum";
10 %    $cust_main->apply_payments( 'manual' => 1,
11 %                                'backdate_application' => ($_date < time-86400) );
12 %  }
13 %  if ( $link eq 'popup' ) {
14 %    
15 <% header(emt('Payment entered')) %>
16     <SCRIPT TYPE="text/javascript">
17       window.top.location.reload();
18     </SCRIPT>
19
20     </BODY></HTML>
21 %
22 %  } elsif ( $link eq 'custnum' ) {
23 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?$linknum") %>
24 %  } else {
25 %    die "unknown link $link";
26 %  }
27 %
28 %}
29 <%init>
30
31 $cgi->param('linknum') =~ /^(\d+)$/
32   or die "Illegal linknum: ". $cgi->param('linknum');
33 my $linknum = $1;
34
35 $cgi->param('link') =~ /^(custnum|invnum|popup)$/
36   or die "Illegal link: ". $cgi->param('link');
37 my $field = my $link = $1;
38 $field = 'custnum' if $field eq 'popup';
39
40 my $_date = parse_datetime($cgi->param('_date'));
41
42 my $new = new FS::cust_pay ( {
43   $field => $linknum,
44   _date  => $_date,
45   map {
46     $_, scalar($cgi->param($_));
47   } qw( paid payby payinfo paybatch
48         pkgnum discount_term
49       )
50   #} fields('cust_pay')
51 } );
52
53 my @rights = ('Post payment');
54 push @rights, 'Post check payment' if $new->payby eq 'BILL';
55 push @rights, 'Post cash payment'  if $new->payby eq 'CASH';
56
57 die "access denied"
58   unless $FS::CurrentUser::CurrentUser->access_right(\@rights);
59
60 my $error = $new->insert( 'manual' => 1 );
61
62 </%init>