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