Initial import into CVS
[freeside.git] / htdocs / edit / process / cust_credit.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # process/cust_credit.cgi: Add a credit (process form)
4 #
5 # Usage: post form to:
6 #        http://server.name/path/cust_credit.cgi
7 #
8 # Note: Should be run setuid root as user nobody.
9 #
10 # ivan@voicenet.com 96-dec-05 -> 96-dec-08
11 #
12 # post a refund if $new_paybatch
13 # ivan@voicenet.com 96-dec-08
14 #
15 # refunds are no longer applied against a specific payment (paybatch)
16 # paybatch field removed
17 # ivan@voicenet.com 97-apr-22
18 #
19 # rewrite ivan@sisd.com 98-mar-16
20 #
21 # Changes to allow page to work at a relative position in server
22 #       bmccane@maxbaud.net     98-apr-3
23
24 use strict;
25 use CGI::Request;
26 use FS::UID qw(cgisuidsetup getotaker);
27 use FS::cust_credit;
28
29 my($req)=new CGI::Request; # create form object
30 cgisuidsetup($req->cgi);
31
32 $req->param('custnum') =~ /^(\d*)$/ or die "Illegal custnum!";
33 my($custnum)=$1;
34
35 $req->param('otaker',getotaker);
36
37 my($new) = create FS::cust_credit ( {
38   map {
39     $_, $req->param($_);
40   } qw(custnum _date amount otaker reason)
41 } );
42
43 my($error);
44 $error=$new->insert;
45 &idiot($error) if $error;
46
47 #no errors, no refund, so view our credit.
48 $req->cgi->redirect("../../view/cust_main.cgi?$custnum#history");
49
50 sub idiot {
51   my($error)=@_;
52   CGI::Base::SendHeaders(); # one guess
53   print <<END;
54 <HTML>
55   <HEAD>
56     <TITLE>Error posting credit/refund</TITLE>
57   </HEAD>
58   <BODY>
59     <CENTER>
60     <H4>Error posting credit/refund</H4>
61     </CENTER>
62     Your update did not occur because of the following error:
63     <P><B>$error</B>
64     <P>Hit the <I>Back</I> button in your web browser, correct this mistake, and press the <I>Post</I> button again.
65   </BODY>
66 </HTML>
67 END
68
69 }
70