3 # $Id: cust_main.cgi,v 1.7 1998-12-30 23:03:34 ivan Exp $
5 # Usage: cust_main.cgi custnum
6 # http://server.name/path/cust_main.cgi?custnum
8 # Note: Should be run setuid freeside as user nobody.
10 # the payment history section could use some work, see below
12 # ivan@voicenet.com 96-nov-29 -> 96-dec-11
14 # added navigation bar (go to main menu ;)
15 # ivan@voicenet.com 97-jan-30
17 # changes to the way credits/payments are applied (the links are here).
18 # ivan@voicenet.com 97-apr-21
20 # added debugging code to diagnose CPU sucking problem.
21 # ivan@voicenet.com 97-may-19
23 # CPU sucking problem was in comment code? fixed?
24 # ivan@voicenet.com 97-may-22
27 # ivan@voicenet.com 97-jul-22
29 # Changes to allow page to work at a relative position in server
30 # Changed 'day' to 'daytime' because Pg6.3 reserves the day word
31 # bmccane@maxbaud.net 98-apr-3
33 # lose background, FS::CGI ivan@sisd.com 98-sep-2
35 # $Log: cust_main.cgi,v $
36 # Revision 1.7 1998-12-30 23:03:34 ivan
37 # bugfixes; fields isn't exported by derived classes
39 # Revision 1.6 1998/12/23 02:42:33 ivan
40 # remove double '/' in link urls
42 # Revision 1.5 1998/12/23 02:36:28 ivan
43 # use FS::cust_refund; to eliminate warning
45 # Revision 1.4 1998/12/17 09:57:21 ivan
46 # s/CGI::(Base|Request)/CGI.pm/;
48 # Revision 1.3 1998/11/15 13:14:20 ivan
49 # first pass as per-customer custom pricing
51 # Revision 1.2 1998/11/13 11:28:08 ivan
52 # s/CGI-modules/CGI.pm/;, relative URL's with popurl
57 use CGI::Carp qw(fatalsToBrowser);
59 use FS::UID qw(cgisuidsetup);
60 use FS::Record qw(qsearchs qsearch);
61 use FS::CGI qw(header menubar popurl table);
67 use FS::part_referral;
75 print $cgi->header, header("Customer View", menubar(
76 'Main Menu' => popurl(2)
81 die "No customer specified (bad URL)!" unless $cgi->keywords;
82 my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
85 my($cust_main)=qsearchs('cust_main',{'custnum'=>$custnum});
86 die "Customer not found!" unless $cust_main;
87 my($hashref)=$cust_main->hashref;
90 print "<FONT SIZE=+1><CENTER>Customer #<B>$custnum</B></CENTER></FONT>",
91 qq!<CENTER><A HREF="#cust_main">Customer Information</A> | !,
92 qq!<A HREF="#cust_comments">Comments</A> | !,
93 qq!<A HREF="#cust_pkg">Packages</A> | !,
94 qq!<A HREF="#history">Payment History</A> </CENTER>!;
97 print qq!<HR><CENTER><A HREF="!, popurl(2), qq!/misc/bill.cgi?$custnum">!,
98 qq!Bill this customer now</A></CENTER>!;
101 print qq!<HR><A NAME="cust_main"><CENTER><FONT SIZE=+1>Customer Information!,
103 qq!<BR><A HREF="!, popurl(2), qq!/edit/cust_main.cgi?$custnum!,
104 qq!">Edit this information</A></CENTER><FONT SIZE=-1>!;
107 my($agent)=qsearchs('agent',{
108 'agentnum' => $cust_main->getfield('agentnum')
110 die "Agent not found!" unless $agent;
111 print "<BR>Agent #<B>" , $agent->getfield('agentnum') , ": " ,
112 $agent->getfield('agent') , "</B>";
115 my($referral)=qsearchs('part_referral',{'refnum' => $cust_main->refnum});
116 die "Referral not found!" unless $referral;
117 print "<BR>Referral #<B>", $referral->refnum, ": ",
118 $referral->referral, "<\B>";
121 print "<P><B>", $hashref->{'last'}, ", ", $hashref->{first}, "</B>";
124 print " (SS# <B>", $hashref->{ss}, "</B>)" if $hashref->{ss};
127 print "<BR><B>", $hashref->{company}, "</B>" if $hashref->{company};
130 print "<BR><B>", $hashref->{address1}, "</B>";
133 print "<BR><B>", $hashref->{address2}, "</B>" if $hashref->{address2};
136 print "<BR><B>", $hashref->{city}, "</B>";
139 print " (<B>", $hashref->{county}, "</B> county)" if $hashref->{county};
142 print ",<B>", $hashref->{state}, "</B>";
145 print " <B>", $hashref->{zip}, "</B>";
148 print "<BR><B>", $hashref->{country}, "</B>"
149 unless $hashref->{country} eq "US";
152 print "<P><B>", $hashref->{daytime}, "</B>" if $hashref->{daytime};
153 print " (Day)" if $hashref->{daytime} && $hashref->{night};
156 print "<BR><B>", $hashref->{night}, "</B>" if $hashref->{night};
157 print " (Night)" if $hashref->{daytime} && $hashref->{night};
160 print "<BR><B>", $hashref->{fax}, "</B> (Fax)" if $hashref->{fax};
162 #payby/payinfo/paydate/payname
163 if ($hashref->{payby} eq "CARD") {
164 print "<P>Card #<B>", $hashref->{payinfo}, "</B> Exp. <B>",
165 $hashref->{paydate}, "</B>";
166 print " (<B>", $hashref->{payname}, "</B>)" if $hashref->{payname};
167 } elsif ($hashref->{payby} eq "BILL") {
169 print " on P.O. #<B>", $hashref->{payinfo}, "</B>"
170 if $hashref->{payinfo};
171 print " until <B>", $hashref->{paydate}, "</B>"
172 if $hashref->{paydate};
173 print " to <B>", $hashref->{payname}, "</B> at above address"
174 if $hashref->{payname};
175 } elsif ($hashref->{payby} eq "COMP") {
176 print "<P>Access complimentary";
177 print " courtesy of <B>", $hashref->{payinfo}, "</B>"
178 if $hashref->{payinfo};
179 print " until <B>", $hashref->{paydate}, "</B>"
180 if $hashref->{paydate};
182 print "Unknown payment type ", $hashref->{payby}, "!";
186 print "<BR>(Tax exempt)" if $hashref->{tax};
189 print "<P>Order taken by <B>", $hashref->{otaker}, "</B>";
192 print qq!<HR><FONT SIZE=+1><A NAME="cust_pkg"><CENTER>Packages</A></FONT>!,
193 qq!<BR>Click on package number to view/edit package.!,
194 qq!<BR><A HREF="!, popurl(2), qq!/edit/cust_pkg.cgi?$custnum">Add/Edit packages</A>!,
200 print qq!<CENTER>!, table, "\n",
201 qq!<TR><TH ROWSPAN=2>#</TH><TH ROWSPAN=2>Package</TH><TH COLSPAN=5>!,
202 qq!Dates</TH></TR>\n!,
203 qq!<TR><TH><FONT SIZE=-1>Setup</FONT></TH><TH>!,
204 qq!<FONT SIZE=-1>Next bill</FONT>!,
205 qq!</TH><TH><FONT SIZE=-1>Susp.</FONT></TH><TH><FONT SIZE=-1>Expire!,
207 qq!<TH><FONT SIZE=-1>Cancel</FONT></TH>!,
211 my(@packages)=qsearch('cust_pkg',{'custnum'=>$custnum});
213 foreach $package (@packages) {
214 my($pref)=$package->hashref;
215 my($part_pkg)=qsearchs('part_pkg',{
216 'pkgpart' => $pref->{pkgpart}
218 print qq!<TR><TD><FONT SIZE=-1><A HREF="!, popurl(2), qq!view/cust_pkg.cgi?!,
219 $pref->{pkgnum}, qq!">!,
220 $pref->{pkgnum}, qq!</A></FONT></TD>!,
221 "<TD><FONT SIZE=-1>", $part_pkg->getfield('pkg'), " - ",
222 $part_pkg->getfield('comment'),
223 qq!<FORM ACTION="!, popurl(2), qq!edit/part_pkg.cgi" METHOD=POST>!,
224 qq!<INPUT TYPE="hidden" NAME="clone" VALUE="!, $part_pkg->pkgpart, qq!">!,
225 qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="!, $package->pkgnum, qq!">!,
226 qq!<INPUT TYPE="submit" VALUE="Customize Pricing">!,
227 "</FORM></FONT></TD>",
228 "<TD><FONT SIZE=-1>",
229 $pref->{setup} ? time2str("%D",$pref->{setup} ) : "" ,
231 "<TD><FONT SIZE=-1>",
232 $pref->{bill} ? time2str("%D",$pref->{bill} ) : "" ,
234 "<TD><FONT SIZE=-1>",
235 $pref->{susp} ? time2str("%D",$pref->{susp} ) : "" ,
237 "<TD><FONT SIZE=-1>",
238 $pref->{expire} ? time2str("%D",$pref->{expire} ) : "" ,
240 "<TD><FONT SIZE=-1>",
241 $pref->{cancel} ? time2str("%D",$pref->{cancel} ) : "" ,
247 print "</TABLE></CENTER>";
250 print qq!<CENTER><HR><A NAME="history"><FONT SIZE=+1>Payment History!,
252 qq!Click on invoice to view invoice/enter payment.<BR>!,
253 qq!<A HREF="!, popurl(2), qq!edit/cust_credit.cgi?$custnum">!,
254 qq!Post Credit / Refund</A></CENTER><BR>!;
258 # major problem: this whole thing is way too sloppy.
259 # minor problem: the description lines need better formatting.
263 my(@bills)=qsearch('cust_bill',{'custnum'=>$custnum});
265 foreach $bill (@bills) {
266 my($bref)=$bill->hashref;
268 $bref->{_date} . qq!\t<A HREF="!. popurl(2). qq!view/cust_bill.cgi?! .
269 $bref->{invnum} . qq!">Invoice #! . $bref->{invnum} .
270 qq! (Balance \$! . $bref->{owed} . qq!)</A>\t! .
271 $bref->{charged} . qq!\t\t\t!;
273 my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } );
275 foreach $payment (@payments) {
276 # my($pref)=$payment->hashref;
277 my($date,$invnum,$payby,$payinfo,$paid)=($payment->getfield('_date'),
278 $payment->getfield('invnum'),
279 $payment->getfield('payby'),
280 $payment->getfield('payinfo'),
281 $payment->getfield('paid'),
284 "$date\tPayment, Invoice #$invnum ($payby $payinfo)\t\t$paid\t\t";
288 my(@credits)=qsearch('cust_credit',{'custnum'=>$custnum});
290 foreach $credit (@credits) {
291 my($cref)=$credit->hashref;
293 $cref->{_date} . "\tCredit #" . $cref->{crednum} . ", (Balance \$" .
294 $cref->{credited} . ") by " . $cref->{otaker} . " - " .
295 $cref->{reason} . "\t\t\t" . $cref->{amount} . "\t";
297 my(@refunds)=qsearch('cust_refund',{'crednum'=> $cref->{crednum} } );
299 foreach $refund (@refunds) {
300 my($rref)=$refund->hashref;
302 $rref->{_date} . "\tRefund, Credit #" . $rref->{crednum} . " (" .
303 $rref->{payby} . " " . $rref->{payinfo} . ") by " .
304 $rref->{otaker} . " - ". $rref->{reason} . "\t\t\t\t" .
310 print "<CENTER>", table, <<END;
314 <TH><FONT SIZE=-1>Charge</FONT></TH>
315 <TH><FONT SIZE=-1>Payment</FONT></TH>
316 <TH><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
317 <TH><FONT SIZE=-1>Refund</FONT></TH>
318 <TH><FONT SIZE=-1>Balance</FONT></TH>
322 #display payment history
326 foreach $item (sort keyfield_numerically @history) {
327 my($date,$desc,$charge,$payment,$credit,$refund)=split(/\t/,$item);
332 $balance += $charge - $payment;
333 $balance -= $credit - $refund;
335 print "<TR><TD><FONT SIZE=-1>",time2str("%D",$date),"</FONT></TD>",
336 "<TD><FONT SIZE=-1>$desc</FONT></TD>",
337 "<TD><FONT SIZE=-1>",
338 ( $charge ? "\$".sprintf("%.2f",$charge) : '' ),
340 "<TD><FONT SIZE=-1>",
341 ( $payment ? "- \$".sprintf("%.2f",$payment) : '' ),
343 "<TD><FONT SIZE=-1>",
344 ( $credit ? "- \$".sprintf("%.2f",$credit) : '' ),
346 "<TD><FONT SIZE=-1>",
347 ( $refund ? "\$".sprintf("%.2f",$refund) : '' ),
349 "<TD><FONT SIZE=-1>\$" . sprintf("%.2f",$balance),
355 print "</TABLE></CENTER>";
367 sub keyfield_numerically { (split(/\t/,$a))[0] <=> (split(/\t/,$b))[0] ; }