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