default to a session cookie instead of setting an explicit timeout, weird timezone...
[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 <& /elements/header-popup.html, emt('Payment entered') &>
16     <SCRIPT TYPE="text/javascript">
17       topreload();
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   no_auto_apply => ($cgi->param('apply') eq 'never') ? 'Y' : '',
54   map {
55     $_, scalar($cgi->param($_));
56   } qw( paid payby payinfo paybatch
57         pkgnum discount_term
58         bank depositor account teller
59       )
60   #} fields('cust_pay')
61   # gatewaynum, processor, auth, order_number
62   # are for realtime payments only, and can't be entered manually
63 } );
64
65 my @rights = ('Post payment');
66 push @rights, 'Post check payment' if $new->payby eq 'BILL';
67 push @rights, 'Post cash payment'  if $new->payby eq 'CASH';
68
69 die "access denied"
70   unless $FS::CurrentUser::CurrentUser->access_right(\@rights);
71
72 my $error = $new->insert( 'manual' => 1 );
73
74 </%init>