summaryrefslogtreecommitdiff
path: root/httemplate/edit/process/cust_credit_bill.cgi
blob: 17f9fcb35589a22dfb37afd6afe3e671424bafd2 (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
40
41
42
43
44
45
46
47
48
49
50
%if ( $error ) {
%  $cgi->param('error', $error);
<% $cgi->redirect(popurl(2). "cust_credit_bill.cgi?". $cgi->query_string ) %>
%} else {
<% header('Credit application sucessful') %>
  <SCRIPT TYPE="text/javascript">
    window.top.location.reload();
  </SCRIPT>
  </BODY>
  </HTML>
% } 
<%init>

die "access denied"
  unless $FS::CurrentUser::CurrentUser->access_right('Apply credit');

$cgi->param('crednum') =~ /^(\d*)$/ or die "Illegal crednum!";
my $crednum = $1;

my $cust_credit = qsearchs('cust_credit', { 'crednum' => $crednum } )
  or die "No such crednum";

my $cust_main = qsearchs('cust_main', { 'custnum' => $cust_credit->custnum } )
  or die "Bogus credit:  not attached to customer";

my $custnum = $cust_main->custnum;

my $new;
if ($cgi->param('invnum') =~ /^Refund$/) {
  $new = new FS::cust_refund ( {
    'reason'  => ( $cust_credit->reason || 'refund from credit' ),
    'refund'  => $cgi->param('amount'),
    'payby'   => 'BILL',
    #'_date'   => $cgi->param('_date'),
    #'payinfo' => 'Cash',
    'payinfo' => 'Refund',
    'crednum' => $crednum,
  } );
} else {
  $new = new FS::cust_credit_bill ( {
    map {
      $_, scalar($cgi->param($_));
    #} qw(custnum _date amount invnum)
    } fields('cust_credit_bill')
  } );
}

my $error = $new->insert;

</%init>