This commit was generated by cvs2svn to compensate for changes in r11022,
[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                        'first_svc' => \@first_svc,
18                        %opt,
19                        # map { $_ => $opt{$_} } qw( pkgpart_svcpart saved_domsvc )
20                     )
21           %>
22
23 % } 
24 <%init>
25
26 my( $cust_main, %opt ) = @_;
27
28 # pry the wrong place for this logic.  also pretty expensive
29
30 #false laziness, copied from FS::cust_pkg::order
31 my $pkgpart;
32 my $agentnum = '';
33 my @agents = $FS::CurrentUser::CurrentUser->agents;
34 if ( scalar(@agents) == 1 ) {
35   # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
36   $pkgpart = $agents[0]->pkgpart_hashref;
37   $agentnum = $agents[0]->agentnum;
38 } elsif ( $cgi->param('lock_agentnum') =~ /^(\d+)$/
39             && $FS::CurrentUser::CurrentUser->agentnum($1) ) {
40   $agentnum = $1;
41   my $agent = (grep { $_->agentnum == $agentnum } @agents)[0];
42   $pkgpart = $agent->pkgpart_hashref;
43 } else {
44   #can't know (agent not chosen), so, allow all
45   $agentnum = 'all';
46   my %typenum;
47   foreach my $agent ( @agents ) {
48     next if $typenum{$agent->typenum}++;
49     $pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
50   }
51 }
52 #eslaf
53
54 my @part_pkg = ();
55 if ( $cgi->param('lock_pkgpart') =~ /^([\d, ]+)$/ ) {
56
57   my $lock_pkgpart = $1;
58
59   @part_pkg = qsearch({
60                         'table'     => 'part_pkg',
61                         'hashref'   => { 'disabled' => '' },
62                         'extra_sql' => "AND pkgpart IN ($lock_pkgpart)",
63                         'order_by'  => 'ORDER BY pkg', # case?
64                      });
65
66 } else {
67
68   @part_pkg =
69     qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
70
71 }
72
73 my @first_svc = ( 'svc_acct', 'svc_phone', 'svc_dsl' );
74
75 @part_pkg =
76   grep { $_->svcpart(\@first_svc)
77          && ( $pkgpart->{ $_->pkgpart } 
78               || $agentnum eq 'all'
79               || ( $agentnum ne 'all' && $agentnum && $_->agentnum
80                    && $_->agentnum == $agentnum
81                  )
82             )
83        }
84   @part_pkg;
85
86 </%init>