more granular ACLs for posting check vs. cash payments, processing credit card vs...
[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 %  }
12 %  if ( $link eq 'popup' ) {
13 %    
14 <% header('Payment entered') %>
15     <SCRIPT TYPE="text/javascript">
16       window.top.location.reload();
17     </SCRIPT>
18
19     </BODY></HTML>
20 %
21 %  } elsif ( $link eq 'custnum' ) {
22 <% $cgi->redirect(popurl(3). "view/cust_main.cgi?$linknum") %>
23 %  } else {
24 %    die "unknown link $link";
25 %  }
26 %
27 %}
28 <%init>
29
30 $cgi->param('linknum') =~ /^(\d+)$/
31   or die "Illegal linknum: ". $cgi->param('linknum');
32 my $linknum = $1;
33
34 $cgi->param('link') =~ /^(custnum|invnum|popup)$/
35   or die "Illegal link: ". $cgi->param('link');
36 my $field = my $link = $1;
37 $field = 'custnum' if $field eq 'popup';
38
39 my $_date = parse_datetime($cgi->param('_date'));
40
41 my $new = new FS::cust_pay ( {
42   $field => $linknum,
43   _date  => $_date,
44   map {
45     $_, scalar($cgi->param($_));
46   } qw( paid payby payinfo paybatch
47         pkgnum discount_term
48       )
49   #} fields('cust_pay')
50 } );
51
52 my @rights = ('Post payment');
53 push @rights, 'Post check payment' if $cust_pay->payby eq 'BILL';
54 push @rights, 'Post cash payment'  if $cust_pay->payby eq 'CASH';
55
56 die "access denied"
57   unless $FS::CurrentUser::CurrentUser->access_right(\@rights);
58
59 my $error = $new->insert( 'manual' => 1 );
60
61 </%init>