aesthetic update
[freeside.git] / htdocs / view / cust_pkg.cgi
1 #!/usr/bin/perl -Tw
2 #
3 # $Id: cust_pkg.cgi,v 1.9 1999-04-08 12:00:19 ivan Exp $
4 #
5 # Usage: cust_pkg.cgi pkgnum
6 #        http://server.name/path/cust_pkg.cgi?pkgnum
7 #
8 # ivan@voicenet.com 96-dec-15
9 #
10 # services section needs to be cleaned up, needs to display extraneous
11 # entries in cust_pkg!
12 # ivan@voicenet.com 96-dec-31
13 #
14 # added navigation bar
15 # ivan@voicenet.com 97-jan-30
16 #
17 # changed and fixed up suspension and cancel stuff, now you can't add
18 # services to a cancelled package
19 # ivan@voicenet.com 97-feb-27
20 #
21 # rewrote for new API, still needs to be cleaned up!
22 # ivan@voicenet.com 97-jul-29
23 #
24 # no FS::Search ivan@sisd.com 98-mar-7
25
26 # $Log: cust_pkg.cgi,v $
27 # Revision 1.9  1999-04-08 12:00:19  ivan
28 # aesthetic update
29 #
30 # Revision 1.8  1999/02/28 00:04:01  ivan
31 # removed misleading comments
32 #
33 # Revision 1.7  1999/01/19 05:14:20  ivan
34 # for mod_perl: no more top-level my() variables; use vars instead
35 # also the last s/create/new/;
36 #
37 # Revision 1.6  1999/01/18 09:41:44  ivan
38 # all $cgi->header calls now include ( '-expires' => 'now' ) for mod_perl
39 # (good idea anyway)
40 #
41 # Revision 1.5  1998/12/23 03:11:40  ivan
42 # *** empty log message ***
43 #
44 # Revision 1.3  1998/12/17 09:57:22  ivan
45 # s/CGI::(Base|Request)/CGI.pm/;
46 #
47 # Revision 1.2  1998/11/13 09:56:49  ivan
48 # change configuration file layout to support multiple distinct databases (with
49 # own set of config files, export, etc.)
50 #
51
52 use strict;
53 use vars qw ( $cgi %uiview %uiadd $part_svc $query $pkgnum $cust_pkg $part_pkg
54               $custnum $susp $cancel $expire $pkg $comment $setup $bill
55               $otaker );
56 use Date::Format;
57 use CGI;
58 use CGI::Carp qw(fatalsToBrowser);
59 use FS::UID qw(cgisuidsetup);
60 use FS::CGI qw(popurl header menubar ntable table);
61 use FS::Record qw(qsearch qsearchs);
62 use FS::part_svc;
63 use FS::cust_pkg;
64 use FS::part_pkg;
65 use FS::pkg_svc;
66 use FS::cust_svc;
67
68 $cgi = new CGI;
69 cgisuidsetup($cgi);
70
71 foreach $part_svc ( qsearch('part_svc',{}) ) {
72   $uiview{$part_svc->svcpart} = popurl(2). "view/". $part_svc->svcdb . ".cgi";
73   $uiadd{$part_svc->svcpart}= popurl(2). "edit/". $part_svc->svcdb . ".cgi";
74 }
75
76 ($query) = $cgi->keywords;
77 $query =~ /^(\d+)$/;
78 $pkgnum = $1;
79
80 #get package record
81 $cust_pkg = qsearchs('cust_pkg',{'pkgnum'=>$pkgnum});
82 die "No package!" unless $cust_pkg;
83 $part_pkg = qsearchs('part_pkg',{'pkgpart'=>$cust_pkg->getfield('pkgpart')});
84
85 $custnum = $cust_pkg->getfield('custnum');
86 print $cgi->header( '-expires' => 'now' ), header('Package View', menubar(
87   "View this customer (#$custnum)" => popurl(2). "view/cust_main.cgi?$custnum",
88   'Main Menu' => popurl(2)
89 ));
90
91 #print info
92 ($susp,$cancel,$expire)=(
93   $cust_pkg->getfield('susp'),
94   $cust_pkg->getfield('cancel'),
95   $cust_pkg->getfield('expire'),
96 );
97 ($pkg,$comment)=($part_pkg->getfield('pkg'),$part_pkg->getfield('comment'));
98 ($setup,$bill)=($cust_pkg->getfield('setup'),$cust_pkg->getfield('bill'));
99 $otaker = $cust_pkg->getfield('otaker');
100
101 print "Package information";
102 print ' (<A HREF="'. popurl(2). 'misc/unsusp_pkg.cgi?'. $pkgnum.
103       '">unsuspend</A>)' if ( $susp && ! $cancel );
104 print ' (<A HREF="'. popurl(2). 'misc/susp_pkg.cgi?'. $pkgnum.
105       '">suspend</A>)' unless ( $susp || $cancel );
106 print ' (<A HREF="'. popurl(2). 'misc/cancel_pkg.cgi?'. $pkgnum.
107       '">cancel</A>)' unless $cancel;
108
109 print ntable("#c0c0c0"), '<TR><TD>', ntable("#c0c0c0",2),
110       '<TR><TD ALIGN="right">Package number</TD><TD BGCOLOR="#ffffff">',
111       $pkgnum, '</TD></TR>',
112       '<TR><TD ALIGN="right">Package</TD><TD BGCOLOR="#ffffff">',
113       $pkg,  '</TD></TR>',
114       '<TR><TD ALIGN="right">Comment</TD><TD BGCOLOR="#ffffff">',
115       $comment,  '</TD></TR>',
116       '<TR><TD ALIGN="right">Setup date</TD><TD BGCOLOR="#ffffff">',
117       ( $setup ? time2str("%D",$setup) : "(Not setup)" ), '</TD></TR>',
118       '<TR><TD ALIGN="right">Next bill date</TD><TD BGCOLOR="#ffffff">',
119       ( $bill ? time2str("%D",$bill) : "&nbsp;" ), '</TD></TR>',
120 ;
121 print '<TR><TD ALIGN="right">Suspension date</TD><TD BGCOLOR="#ffffff">',
122        time2str("%D",$susp), '</TD></TR>' if $susp;
123 print '<TR><TD ALIGN="right">Expiration date</TD><TD BGCOLOR="#ffffff">',
124        time2str("%D",$expire), '</TD></TR>' if $expire;
125 print '<TR><TD ALIGN="right">Cancellation date</TD><TD BGCOLOR="#ffffff">',
126        time2str("%D",$cancel), '</TD></TR>' if $cancel;
127 print  '<TR><TD ALIGN="right">Order taker</TD><TD BGCOLOR="#ffffff">',
128       $otaker,  '</TD></TR>',
129       '</TABLE></TD></TR></TABLE>'
130 ;
131
132 #  print <<END;
133 #<FORM ACTION="../misc/expire_pkg.cgi" METHOD="post">
134 #<INPUT TYPE="hidden" NAME="pkgnum" VALUE="$pkgnum">
135 #Expire (date): <INPUT TYPE="text" NAME="date" VALUE="" >
136 #<INPUT TYPE="submit" VALUE="Cancel later">
137 #END
138
139 unless ($cancel) {
140
141   #services
142   print '<BR>Service Information', table,
143   ;
144
145   #list of services this pkgpart includes
146   my $pkg_svc;
147   my %pkg_svc = ();
148   foreach $pkg_svc ( qsearch('pkg_svc',{'pkgpart'=> $cust_pkg->pkgpart }) ) {
149     $pkg_svc{$pkg_svc->svcpart} = $pkg_svc->quantity if $pkg_svc->quantity;
150   }
151
152   #list of records from cust_svc
153   my $svcpart;
154   foreach $svcpart (sort {$a <=> $b} keys %pkg_svc) {
155
156     my($svc)=qsearchs('part_svc',{'svcpart'=>$svcpart})->getfield('svc');
157
158     my(@cust_svc)=qsearch('cust_svc',{'pkgnum'=>$pkgnum, 
159                                       'svcpart'=>$svcpart,
160                                      });
161
162     my($enum);
163     for $enum ( 1 .. $pkg_svc{$svcpart} ) {
164
165       my($cust_svc);
166       if ( $cust_svc=shift @cust_svc ) {
167         my($svcnum)=$cust_svc->svcnum;
168         my($label, $value, $svcdb) = $cust_svc->label;
169         print <<END;
170 <TR><TD><A HREF="$uiview{$svcpart}?$svcnum">(View) $svc: $value<A></TD></TR>
171 END
172       } else {
173         print <<END;
174 <TR>
175   <TD><A HREF="$uiadd{$svcpart}?pkgnum$pkgnum-svcpart$svcpart">
176       (Add) $svc</A>
177    or <A HREF="../misc/link.cgi?pkgnum$pkgnum-svcpart$svcpart">
178       (Link to existing) $svc</A>
179   </TD>
180 </TR>
181 END
182       }
183
184     }
185     warn "WARNING: Leftover services pkgnum $pkgnum!" if @cust_svc;; 
186   }
187
188   print "</TABLE><FONT SIZE=-1>",
189         "Choose (View) to view or edit an existing service<BR>",
190         "Choose (Add) to setup a new service<BR>",
191         "Choose (Link to existing) to link to a legacy (pre-Freeside) service",
192         "</FONT>"
193   ;
194 }
195
196 #formatting
197 print <<END;
198   </BODY>
199 </HTML>
200 END
201