ACLs
[freeside.git] / httemplate / edit / cust_pkg.cgi
1 <% include('/elements/header.html', "Add/Edit Packages", '') %>
2
3 <% include('/elements/error.html') %>
4
5 <FORM ACTION="<% $p1 %>process/cust_pkg.cgi" METHOD=POST>
6
7 <INPUT TYPE="hidden" NAME="custnum" VALUE="<% $custnum %>">
8 %
9 %#current packages
10 %my @cust_pkg = qsearch('cust_pkg', { 'custnum' => $custnum, 'cancel' => '' } );
11 %
12 %if (@cust_pkg) {
13 %
14
15
16   Current packages - select to remove (services are moved to a new package below)
17   <TABLE>
18     <TR STYLE="background-color: #cccccc;">
19       <TH COLSPAN="2">Pkg #</TH>
20       <TH>Package description</TH>
21     </TR>
22   <BR><BR>
23 %
24 %
25 %  foreach ( sort {     $all_pkg{ $a->getfield('pkgpart') }
26 %                   cmp $all_pkg{ $b->getfield('pkgpart') }
27 %                 }
28 %                 @cust_pkg
29 %          )
30 %  {
31 %    my($pkgnum,$pkgpart)=( $_->getfield('pkgnum'), $_->getfield('pkgpart') );
32 %    my $checked = $remove_pkg{$pkgnum} ? ' CHECKED' : '';
33 %
34 %  
35
36
37     <TR>
38       <TD><INPUT TYPE="checkbox" NAME="remove_pkg" VALUE="<% $pkgnum %>"<% $checked %>></TD>
39       <TD ALIGN="right"><% $pkgnum %>:</TD>
40       <TD><% $all_pkg{$pkgpart} %> - <% $all_comment{$pkgpart} %></TD>
41     </TR>
42 % } 
43
44
45   </TABLE>
46   <BR><BR>
47 % } 
48
49
50 Order new packages
51 <BR><BR>
52 %
53 %my $cust_main = qsearchs('cust_main',{'custnum'=>$custnum});
54 %my $agent = qsearchs('agent',{'agentnum'=> $cust_main->agentnum });
55 %
56 %my %agent_pkgs = map { ( $_->pkgpart , $all_pkg{$_->pkgpart} ) }
57 %                     qsearch('type_pkgs',{'typenum'=> $agent->typenum });
58 %
59 %my $count = 0;
60 %my $pkgparts = 0;
61 %
62
63
64 <TABLE>
65   <TR STYLE="background-color: #cccccc;">
66     <TH>Qty.</TH>
67     <TH COLSPAN="2">Package Description</TH>
68   </TR>
69 %
70 %#foreach my $type_pkgs ( qsearch('type_pkgs',{'typenum'=> $agent->typenum }) ) {
71 %foreach my $pkgpart ( sort { $agent_pkgs{$a} cmp $agent_pkgs{$b} }
72 %                             keys(%agent_pkgs) ) {
73 %  $pkgparts++;
74 %  next unless exists $pkg{$pkgpart}; #skip disabled ones
75 %  #print qq!<TR>! if ( $count == 0 );
76 %  my $value = $cgi->param("pkg$pkgpart") || 0;
77 %
78
79
80   <TR>
81     <TD>
82       <INPUT TYPE="text" NAME="<% "pkg$pkgpart" %>" VALUE="<% $value %>" SIZE="2" MAXLENGTH="2">
83     </TD>
84     <TD ALIGN="right"><% $pkgpart %>:</TD>
85     <TD><% $pkg{$pkgpart} %> - <% $comment{$pkgpart}%></TD>
86   </TR>
87 %
88 %  $count ++ ;
89 %  #if ( $count == 2 ) {
90 %  #  print qq!</TR>\n! ;
91 %  #  $count = 0;
92 %  #}
93 %}
94 %
95
96
97 </TABLE>
98 % unless ( $pkgparts ) {
99 %     my $p2 = popurl(2);
100 %     my $typenum = $agent->typenum;
101 %     my $agent_type = qsearchs( 'agent_type', { 'typenum' => $typenum } );
102 %     my $atype = $agent_type->atype;
103 %
104
105
106      (No <A HREF="<% $p2 %>browse/part_pkg.cgi">package definitions</A>,
107      or agent type
108      <A HREF="<% $p2 %>edit/agent_type.cgi?<% $typenum %>"><% $atype %></a>
109      is not allowed to purchase any packages.)
110 % } 
111
112
113 <P><INPUT TYPE="submit" VALUE="Order">
114
115 </FORM>
116
117 <% include('/elements/footer.html') %>
118
119 <%init>
120
121 die "access denied"
122   unless $FS::CurrentUser::CurrentUser->access_right('Bulk change customer packages');
123
124 my %pkg = ();
125 my %comment = ();
126 my %all_pkg = ();
127 my %all_comment = ();
128 #foreach (qsearch('part_pkg', { 'disabled' => '' })) {
129 #  $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg');
130 #  $comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment');
131 #}
132 foreach (qsearch('part_pkg', {} )) {
133   $all_pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg');
134   $all_comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment');
135   next if $_->disabled;
136   $pkg{ $_ -> getfield('pkgpart') } = $_->getfield('pkg');
137   $comment{ $_ -> getfield('pkgpart') } = $_->getfield('comment');
138 }
139
140 my($custnum, %remove_pkg);
141 if ( $cgi->param('error') ) {
142   $custnum = $cgi->param('custnum');
143   %remove_pkg = map { $_ => 1 } $cgi->param('remove_pkg');
144 } else {
145   my($query) = $cgi->keywords;
146   $query =~ /^(\d+)$/;
147   $custnum = $1;
148   %remove_pkg = ();
149 }
150
151 my $p1 = popurl(1);
152
153 </%init>
154