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