internationalization/localization, RT12515
[freeside.git] / httemplate / edit / process / cust_credit.cgi
1 %if ( $error ) {
2 %  $cgi->param('reasonnum', $reasonnum);
3 %  $cgi->param('error', $error);
4 %  $dbh->rollback if $oldAutoCommit;
5 %  
6 <% $cgi->redirect(popurl(2). "cust_credit.cgi?". $cgi->query_string ) %>
7 %
8 %} else {
9 %
10 %  if ( $cgi->param('apply') eq 'yes' ) {
11 %    my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum })
12 %      or die "unknown custnum $custnum";
13 %    $cust_main->apply_credits;
14 %  }
15 %
16 %  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
17 %  
18 <% header(emt('Credit sucessful')) %>
19   <SCRIPT TYPE="text/javascript">
20     window.top.location.reload();
21   </SCRIPT>
22
23   </BODY></HTML>
24 % } 
25 <%init>
26
27 die "access denied"
28   unless $FS::CurrentUser::CurrentUser->access_right('Post credit');
29
30 $cgi->param('custnum') =~ /^(\d*)$/ or die "Illegal custnum!";
31 my $custnum = $1;
32
33 $cgi->param('reasonnum') =~ /^(-?\d+)$/ or die "Illegal reasonnum";
34 my $reasonnum = $1;
35
36 my $oldAutoCommit = $FS::UID::AutoCommit;
37 local $FS::UID::AutoCommit = 0;
38 my $dbh = dbh;
39
40 my $error = '';
41 if ($reasonnum == -1) {
42
43   $error = 'Enter a new reason (or select an existing one)'
44     unless $cgi->param('newreasonnum') !~ /^\s*$/;
45   my $reason = new FS::reason({ 'reason_type' => $cgi->param('newreasonnumT'),
46                                 'reason'      => $cgi->param('newreasonnum'),
47                               });
48   $error ||= $reason->insert;
49   $cgi->param('reasonnum', $reason->reasonnum)
50     unless $error;
51 }
52
53 unless ($error) {
54   my $new = new FS::cust_credit ( {
55     map {
56       $_, scalar($cgi->param($_));
57     } fields('cust_credit')
58   } );
59   $error = $new->insert;
60 }
61
62 </%init>