summaryrefslogtreecommitdiff
path: root/httemplate/edit/process/cust_pay.cgi
blob: 82442ae00dba253fe3a4fdb2e4c473dffaba4673 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<%

$cgi->param('linknum') =~ /^(\d+)$/
  or die "Illegal linknum: ". $cgi->param('linknum');
my $linknum = $1;

$cgi->param('link') =~ /^(custnum|invnum)$/
  or die "Illegal link: ". $cgi->param('link');
my $link = $1;

my $new = new FS::cust_pay ( {
  $link => $linknum,
  map {
    $_, scalar($cgi->param($_));
  } qw(paid _date payby payinfo paybatch)
  #} fields('cust_pay')
} );

my $error = $new->insert;

if ($error) {
  $cgi->param('error', $error);
  print $cgi->redirect(popurl(2). 'cust_pay.cgi?'. $cgi->query_string );
} elsif ( $link eq 'invnum' ) {
  print $cgi->redirect(popurl(3). "view/cust_bill.cgi?$linknum");
} elsif ( $link eq 'custnum' ) {
  if ( $cgi->param('apply') eq 'yes' ) {
    my $cust_main = qsearchs('cust_main', { 'custnum' => $linknum })
      or die "unknown custnum $linknum";
    $cust_main->apply_payments;
  }
  if ( $cgi->param('quickpay') eq 'yes' ) {
    print $cgi->redirect(popurl(3). "search/cust_main-quickpay.html");
  } else {
    print $cgi->redirect(popurl(3). "view/cust_main.cgi?$linknum");
  }
}

%>