import torrus 1.0.9
[freeside.git] / httemplate / edit / cust_main / first_pkg.html
1 % if ( $cgi->param('lock_pkgpart') =~ /^([\d, ]+)$/ ) {
2
3     <INPUT TYPE="hidden" NAME="lock_pkgpart" VALUE="<% $1 %>">
4
5 % }
6 %
7 % if ( @part_pkg ) {
8
9     <BR><BR>
10     <FONT SIZE="+1"><B>First package</B></FONT>
11     <% ntable("#cccccc") %>
12
13       <TR>
14         <TD COLSPAN=2>
15           <% include('first_pkg/select-part_pkg.html',
16                        'part_pkg' => \@part_pkg,
17                        %opt,
18                        # map { $_ => $opt{$_} } qw( pkgpart_svcpart saved_domsvc )
19                     )
20           %>
21
22 % } 
23 <%init>
24
25 my( $cust_main, %opt ) = @_;
26
27 # pry the wrong place for this logic.  also pretty expensive
28
29 #false laziness, copied from FS::cust_pkg::order
30 my $pkgpart;
31 my $agentnum = '';
32 my @agents = $FS::CurrentUser::CurrentUser->agents;
33 if ( scalar(@agents) == 1 ) {
34   # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
35   $pkgpart = $agents[0]->pkgpart_hashref;
36   $agentnum = $agents[0]->agentnum;
37 } elsif ( $cgi->param('lock_agentnum') =~ /^(\d+)$/
38             && $FS::CurrentUser::CurrentUser->agentnum($1) ) {
39   $agentnum = $1;
40   my $agent = (grep { $_->agentnum == $agentnum } @agents)[0];
41   $pkgpart = $agent->pkgpart_hashref;
42 } else {
43   #can't know (agent not chosen), so, allow all
44   $agentnum = 'all';
45   my %typenum;
46   foreach my $agent ( @agents ) {
47     next if $typenum{$agent->typenum}++;
48     $pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
49   }
50 }
51 #eslaf
52
53 my @part_pkg = ();
54 if ( $cgi->param('lock_pkgpart') =~ /^([\d, ]+)$/ ) {
55
56   my $lock_pkgpart = $1;
57
58   @part_pkg = qsearch({
59                         'table'     => 'part_pkg',
60                         'hashref'   => { 'disabled' => '' },
61                         'extra_sql' => "AND pkgpart IN ($lock_pkgpart)",
62                         'order_by'  => 'ORDER BY pkg', # case?
63                      });
64
65 } else {
66
67   @part_pkg =
68     qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
69
70 }
71
72 my @first_svc = ( 'svc_acct', 'svc_phone' );
73
74 @part_pkg =
75   grep { $_->svcpart(\@first_svc)
76          && ( $pkgpart->{ $_->pkgpart } 
77               || $agentnum eq 'all'
78               || ( $agentnum ne 'all' && $agentnum && $_->agentnum
79                    && $_->agentnum == $agentnum
80                  )
81             )
82        }
83   @part_pkg;
84
85 </%init>