3 # $Id: cust_main.cgi,v 1.4 1998-12-17 09:57:21 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.4 1998-12-17 09:57:21 ivan
37 # s/CGI::(Base|Request)/CGI.pm/;
39 # Revision 1.3 1998/11/15 13:14:20 ivan
40 # first pass as per-customer custom pricing
42 # Revision 1.2 1998/11/13 11:28:08 ivan
43 # s/CGI-modules/CGI.pm/;, relative URL's with popurl
48 use CGI::Carp qw(fatalsToBrowser);
50 use FS::UID qw(cgisuidsetup);
51 use FS::Record qw(qsearchs qsearch);
52 use FS::CGI qw(header menubar popurl table);
58 use FS::part_referral;
65 print $cgi->header, header("Customer View", menubar(
66 'Main Menu' => popurl(2)
71 die "No customer specified (bad URL)!" unless $cgi->keywords;
72 my($query) = $cgi->keywords; # needs parens with my, ->keywords returns array
75 my($cust_main)=qsearchs('cust_main',{'custnum'=>$custnum});
76 die "Customer not found!" unless $cust_main;
77 my($hashref)=$cust_main->hashref;
80 print "<FONT SIZE=+1><CENTER>Customer #<B>$custnum</B></CENTER></FONT>",
81 qq!<CENTER><A HREF="#cust_main">Customer Information</A> | !,
82 qq!<A HREF="#cust_comments">Comments</A> | !,
83 qq!<A HREF="#cust_pkg">Packages</A> | !,
84 qq!<A HREF="#history">Payment History</A> </CENTER>!;
87 print qq!<HR><CENTER><A HREF="!, popurl(2), qq!/misc/bill.cgi?$custnum">!,
88 qq!Bill this customer now</A></CENTER>!;
91 print qq!<HR><A NAME="cust_main"><CENTER><FONT SIZE=+1>Customer Information!,
93 qq!<BR><A HREF="!, popurl(2), qq!/edit/cust_main.cgi?$custnum!,
94 qq!">Edit this information</A></CENTER><FONT SIZE=-1>!;
97 my($agent)=qsearchs('agent',{
98 'agentnum' => $cust_main->getfield('agentnum')
100 die "Agent not found!" unless $agent;
101 print "<BR>Agent #<B>" , $agent->getfield('agentnum') , ": " ,
102 $agent->getfield('agent') , "</B>";
105 my($referral)=qsearchs('part_referral',{'refnum' => $cust_main->refnum});
106 die "Referral not found!" unless $referral;
107 print "<BR>Referral #<B>", $referral->refnum, ": ",
108 $referral->referral, "<\B>";
111 print "<P><B>", $hashref->{'last'}, ", ", $hashref->{first}, "</B>";
114 print " (SS# <B>", $hashref->{ss}, "</B>)" if $hashref->{ss};
117 print "<BR><B>", $hashref->{company}, "</B>" if $hashref->{company};
120 print "<BR><B>", $hashref->{address1}, "</B>";
123 print "<BR><B>", $hashref->{address2}, "</B>" if $hashref->{address2};
126 print "<BR><B>", $hashref->{city}, "</B>";
129 print " (<B>", $hashref->{county}, "</B> county)" if $hashref->{county};
132 print ",<B>", $hashref->{state}, "</B>";
135 print " <B>", $hashref->{zip}, "</B>";
138 print "<BR><B>", $hashref->{country}, "</B>"
139 unless $hashref->{country} eq "US";
142 print "<P><B>", $hashref->{daytime}, "</B>" if $hashref->{daytime};
143 print " (Day)" if $hashref->{daytime} && $hashref->{night};
146 print "<BR><B>", $hashref->{night}, "</B>" if $hashref->{night};
147 print " (Night)" if $hashref->{daytime} && $hashref->{night};
150 print "<BR><B>", $hashref->{fax}, "</B> (Fax)" if $hashref->{fax};
152 #payby/payinfo/paydate/payname
153 if ($hashref->{payby} eq "CARD") {
154 print "<P>Card #<B>", $hashref->{payinfo}, "</B> Exp. <B>",
155 $hashref->{paydate}, "</B>";
156 print " (<B>", $hashref->{payname}, "</B>)" if $hashref->{payname};
157 } elsif ($hashref->{payby} eq "BILL") {
159 print " on P.O. #<B>", $hashref->{payinfo}, "</B>"
160 if $hashref->{payinfo};
161 print " until <B>", $hashref->{paydate}, "</B>"
162 if $hashref->{paydate};
163 print " to <B>", $hashref->{payname}, "</B> at above address"
164 if $hashref->{payname};
165 } elsif ($hashref->{payby} eq "COMP") {
166 print "<P>Access complimentary";
167 print " courtesy of <B>", $hashref->{payinfo}, "</B>"
168 if $hashref->{payinfo};
169 print " until <B>", $hashref->{paydate}, "</B>"
170 if $hashref->{paydate};
172 print "Unknown payment type ", $hashref->{payby}, "!";
176 print "<BR>(Tax exempt)" if $hashref->{tax};
179 print "<P>Order taken by <B>", $hashref->{otaker}, "</B>";
182 print qq!<HR><FONT SIZE=+1><A NAME="cust_pkg"><CENTER>Packages</A></FONT>!,
183 qq!<BR>Click on package number to view/edit package.!,
184 qq!<BR><A HREF="!, popurl(2), qq!/edit/cust_pkg.cgi?$custnum">Add/Edit packages</A>!,
190 print qq!<CENTER>!, table, "\n",
191 qq!<TR><TH ROWSPAN=2>#</TH><TH ROWSPAN=2>Package</TH><TH COLSPAN=5>!,
192 qq!Dates</TH></TR>\n!,
193 qq!<TR><TH><FONT SIZE=-1>Setup</FONT></TH><TH>!,
194 qq!<FONT SIZE=-1>Next bill</FONT>!,
195 qq!</TH><TH><FONT SIZE=-1>Susp.</FONT></TH><TH><FONT SIZE=-1>Expire!,
197 qq!<TH><FONT SIZE=-1>Cancel</FONT></TH>!,
201 my(@packages)=qsearch('cust_pkg',{'custnum'=>$custnum});
203 foreach $package (@packages) {
204 my($pref)=$package->hashref;
205 my($part_pkg)=qsearchs('part_pkg',{
206 'pkgpart' => $pref->{pkgpart}
208 print qq!<TR><TD><FONT SIZE=-1><A HREF="!, popurl(2), qq!/view/cust_pkg.cgi?!,
209 $pref->{pkgnum}, qq!">!,
210 $pref->{pkgnum}, qq!</A></FONT></TD>!,
211 "<TD><FONT SIZE=-1>", $part_pkg->getfield('pkg'), " - ",
212 $part_pkg->getfield('comment'),
213 qq!<FORM ACTION="!, popurl(2), qq!/edit/part_pkg.cgi" METHOD=POST>!,
214 qq!<INPUT TYPE="hidden" NAME="clone" VALUE="!, $part_pkg->pkgpart, qq!">!,
215 qq!<INPUT TYPE="hidden" NAME="pkgnum" VALUE="!, $package->pkgnum, qq!">!,
216 qq!<INPUT TYPE="submit" VALUE="Customize Pricing">!,
217 "</FORM></FONT></TD>",
218 "<TD><FONT SIZE=-1>",
219 $pref->{setup} ? time2str("%D",$pref->{setup} ) : "" ,
221 "<TD><FONT SIZE=-1>",
222 $pref->{bill} ? time2str("%D",$pref->{bill} ) : "" ,
224 "<TD><FONT SIZE=-1>",
225 $pref->{susp} ? time2str("%D",$pref->{susp} ) : "" ,
227 "<TD><FONT SIZE=-1>",
228 $pref->{expire} ? time2str("%D",$pref->{expire} ) : "" ,
230 "<TD><FONT SIZE=-1>",
231 $pref->{cancel} ? time2str("%D",$pref->{cancel} ) : "" ,
237 print "</TABLE></CENTER>";
240 print qq!<CENTER><HR><A NAME="history"><FONT SIZE=+1>Payment History!,
242 qq!Click on invoice to view invoice/enter payment.<BR>!,
243 qq!<A HREF="!, popurl(2), qq!/edit/cust_credit.cgi?$custnum">!,
244 qq!Post Credit / Refund</A></CENTER><BR>!;
248 # major problem: this whole thing is way too sloppy.
249 # minor problem: the description lines need better formatting.
253 my(@bills)=qsearch('cust_bill',{'custnum'=>$custnum});
255 foreach $bill (@bills) {
256 my($bref)=$bill->hashref;
258 $bref->{_date} . qq!\t<A HREF="!. popurl(2). qq!/view/cust_bill.cgi?! .
259 $bref->{invnum} . qq!">Invoice #! . $bref->{invnum} .
260 qq! (Balance \$! . $bref->{owed} . qq!)</A>\t! .
261 $bref->{charged} . qq!\t\t\t!;
263 my(@payments)=qsearch('cust_pay',{'invnum'=> $bref->{invnum} } );
265 foreach $payment (@payments) {
266 # my($pref)=$payment->hashref;
267 my($date,$invnum,$payby,$payinfo,$paid)=($payment->getfield('_date'),
268 $payment->getfield('invnum'),
269 $payment->getfield('payby'),
270 $payment->getfield('payinfo'),
271 $payment->getfield('paid'),
274 "$date\tPayment, Invoice #$invnum ($payby $payinfo)\t\t$paid\t\t";
278 my(@credits)=qsearch('cust_credit',{'custnum'=>$custnum});
280 foreach $credit (@credits) {
281 my($cref)=$credit->hashref;
283 $cref->{_date} . "\tCredit #" . $cref->{crednum} . ", (Balance \$" .
284 $cref->{credited} . ") by " . $cref->{otaker} . " - " .
285 $cref->{reason} . "\t\t\t" . $cref->{amount} . "\t";
287 my(@refunds)=qsearch('cust_refund',{'crednum'=> $cref->{crednum} } );
289 foreach $refund (@refunds) {
290 my($rref)=$refund->hashref;
292 $rref->{_date} . "\tRefund, Credit #" . $rref->{crednum} . " (" .
293 $rref->{payby} . " " . $rref->{payinfo} . ") by " .
294 $rref->{otaker} . " - ". $rref->{reason} . "\t\t\t\t" .
300 print "<CENTER>", table, <<END;
304 <TH><FONT SIZE=-1>Charge</FONT></TH>
305 <TH><FONT SIZE=-1>Payment</FONT></TH>
306 <TH><FONT SIZE=-1>In-house<BR>Credit</FONT></TH>
307 <TH><FONT SIZE=-1>Refund</FONT></TH>
308 <TH><FONT SIZE=-1>Balance</FONT></TH>
312 #display payment history
316 foreach $item (sort keyfield_numerically @history) {
317 my($date,$desc,$charge,$payment,$credit,$refund)=split(/\t/,$item);
322 $balance += $charge - $payment;
323 $balance -= $credit - $refund;
325 print "<TR><TD><FONT SIZE=-1>",time2str("%D",$date),"</FONT></TD>",
326 "<TD><FONT SIZE=-1>$desc</FONT></TD>",
327 "<TD><FONT SIZE=-1>",
328 ( $charge ? "\$".sprintf("%.2f",$charge) : '' ),
330 "<TD><FONT SIZE=-1>",
331 ( $payment ? "- \$".sprintf("%.2f",$payment) : '' ),
333 "<TD><FONT SIZE=-1>",
334 ( $credit ? "- \$".sprintf("%.2f",$credit) : '' ),
336 "<TD><FONT SIZE=-1>",
337 ( $refund ? "\$".sprintf("%.2f",$refund) : '' ),
339 "<TD><FONT SIZE=-1>\$" . sprintf("%.2f",$balance),
345 print "</TABLE></CENTER>";
357 sub keyfield_numerically { (split(/\t/,$a))[0] <=> (split(/\t/,$b))[0] ; }