summaryrefslogtreecommitdiff
path: root/httemplate/edit/cust_main/first_pkg.html
blob: 7c131eadcb9f962e455c9aee4859d411aae4db86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
% if ( $cgi->param('lock_pkgpart') =~ /^([\d, ]+)$/ ) {

    <INPUT TYPE="hidden" NAME="lock_pkgpart" VALUE="<% $1 %>">

% }
%
% if ( @part_pkg ) {

    <BR><BR>
    <FONT SIZE="+1"><B>First package</B></FONT>
    <% ntable("#cccccc") %>

      <TR>
        <TD COLSPAN=2>
          <% include('first_pkg/select-part_pkg.html',
                       'part_pkg' => \@part_pkg,
                       %opt,
                       # map { $_ => $opt{$_} } qw( pkgpart_svcpart saved_domsvc )
                    )
          %>

% } 
<%init>

my( $cust_main, %opt ) = @_;

# pry the wrong place for this logic.  also pretty expensive

#false laziness, copied from FS::cust_pkg::order
my $pkgpart;
my $agentnum = '';
my @agents = $FS::CurrentUser::CurrentUser->agents;
if ( scalar(@agents) == 1 ) {
  # $pkgpart->{PKGPART} is true iff $custnum may purchase PKGPART
  $pkgpart = $agents[0]->pkgpart_hashref;
  $agentnum = $agents[0]->agentnum;
} elsif ( $cgi->param('lock_agentnum') =~ /^(\d+)$/
            && $FS::CurrentUser::CurrentUser->agentnum($1) ) {
  $agentnum = $1;
  my $agent = (grep { $_->agentnum == $agentnum } @agents)[0];
  $pkgpart = $agent->pkgpart_hashref;
} else {
  #can't know (agent not chosen), so, allow all
  $agentnum = 'all';
  my %typenum;
  foreach my $agent ( @agents ) {
    next if $typenum{$agent->typenum}++;
    $pkgpart->{$_}++ foreach keys %{ $agent->pkgpart_hashref }
  }
}
#eslaf

my @part_pkg = ();
if ( $cgi->param('lock_pkgpart') =~ /^([\d, ]+)$/ ) {

  my $lock_pkgpart = $1;

  @part_pkg = qsearch({
                        'table'     => 'part_pkg',
                        'hashref'   => { 'disabled' => '' },
                        'extra_sql' => "AND pkgpart IN ($lock_pkgpart)",
                        'order_by'  => 'ORDER BY pkg', # case?
                     });

} else {

  @part_pkg =
    qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?

}

my @first_svc = ( 'svc_acct', 'svc_phone' );

@part_pkg =
  grep { $_->svcpart(\@first_svc)
         && ( $pkgpart->{ $_->pkgpart } 
              || $agentnum eq 'all'
              || ( $agentnum ne 'all' && $agentnum && $_->agentnum
                   && $_->agentnum == $agentnum
                 )
            )
       }
  @part_pkg;

</%init>