option to credit unused time on suspension as part of suspend reason, #31702
[freeside.git] / httemplate / edit / process / cust_credit.cgi
1 %if ( $error ) {
2 %  $cgi->param('error', $error);
3 %  $dbh->rollback if $oldAutoCommit;
4 %  
5 <% $cgi->redirect(popurl(2). "cust_credit.cgi?". $cgi->query_string ) %>
6 %
7 %} else {
8 %
9 %  if ( $cgi->param('apply') eq 'yes' ) {
10 %    my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum })
11 %      or die "unknown custnum $custnum";
12 %    $cust_main->apply_credits;
13 %  }
14 %
15 %  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
16 %  
17 <% header(emt('Credit successful')) %>
18   <SCRIPT TYPE="text/javascript">
19     window.top.location.reload();
20   </SCRIPT>
21
22   </BODY></HTML>
23 % } 
24 <%init>
25
26 die "access denied"
27   unless $FS::CurrentUser::CurrentUser->access_right('Post credit');
28
29 $cgi->param('custnum') =~ /^(\d+)$/ or die "Illegal custnum!";
30 my $custnum = $1;
31
32 $cgi->param('reasonnum') =~ /^(-?\d+)$/ or die "Illegal reasonnum";
33 my $reasonnum = $1;
34
35 my $oldAutoCommit = $FS::UID::AutoCommit;
36 local $FS::UID::AutoCommit = 0;
37 my $dbh = dbh;
38
39 my ($reasonnum, $error) = $m->comp('/misc/process/elements/reason');
40 if (!$reasonnum) {
41   $error ||= 'Reason required'
42 }
43 $cgi->param('reasonnum', $reasonnum) unless $error;
44
45 unless ($error) {
46   my $new = new FS::cust_credit ( {
47     map {
48       $_, scalar($cgi->param($_));
49     } fields('cust_credit')
50   } );
51   $error = $new->insert;
52 }
53
54 </%init>