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