Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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 my $conf = FS::Conf->new;
32
33 $cgi->param('linknum') =~ /^(\d+)$/
34   or die "Illegal linknum: ". $cgi->param('linknum');
35 my $linknum = $1;
36
37 $cgi->param('link') =~ /^(custnum|invnum|popup)$/
38   or die "Illegal link: ". $cgi->param('link');
39 my $field = my $link = $1;
40 $field = 'custnum' if $field eq 'popup';
41
42 my $_date;
43 if ( $FS::CurrentUser::CurrentUser->access_right('Backdate payment') ) {
44   $_date = parse_datetime($cgi->param('_date'));
45 }
46 else {
47   $_date = time;
48 }
49
50 my $new = new FS::cust_pay ( {
51   $field => $linknum,
52   _date  => $_date,
53   map {
54     $_, scalar($cgi->param($_));
55   } qw( paid payby payinfo paybatch
56         pkgnum discount_term
57         bank depositor account teller
58       )
59   #} fields('cust_pay')
60 } );
61
62 my @rights = ('Post payment');
63 push @rights, 'Post check payment' if $new->payby eq 'BILL';
64 push @rights, 'Post cash payment'  if $new->payby eq 'CASH';
65
66 die "access denied"
67   unless $FS::CurrentUser::CurrentUser->access_right(\@rights);
68
69 my $error ||= $new->insert( 'manual' => 1 );
70
71 </%init>