summaryrefslogtreecommitdiff
path: root/httemplate/browse/part_pkg.cgi
blob: 7b9436cee46abdf3ee558d15faf60186c2caf86e (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!-- mason kludge -->
<%

my %search;
if ( $cgi->param('showdisabled') ) {
  %search = ();
} else {
  %search = ( 'disabled' => '' );
}

my @part_pkg = qsearch('part_pkg', \%search );
my $total = scalar(@part_pkg);

my $sortby;
my %num_active_cust_pkg;
if ( $cgi->param('active') ) {
  my $active_sth = dbh->prepare(
    'SELECT COUNT(*) FROM cust_pkg WHERE pkgpart = ?'.
    ' AND ( cancel IS NULL OR cancel = 0 )'.
    ' AND ( susp IS NULL OR susp = 0 )'
  ) or die dbh->errstr;
  foreach my $part_pkg ( @part_pkg ) {
    $active_sth->execute($part_pkg->pkgpart) or die $active_sth->errstr;
    $num_active_cust_pkg{$part_pkg->pkgpart} =
      $active_sth->fetchrow_arrayref->[0];
  }
  $sortby = \*active_cust_pkg_sort;
} else {
  $sortby = \*pkgpart_sort;
}

%>
<%= header("Package Definition Listing",menubar( 'Main Menu' => $p )) %>
<% unless ( $cgi->param('active') ) { %>
  One or more service definitions are grouped together into a package 
  definition and given pricing information.  Customers purchase packages
  rather than purchase services directly.<BR><BR>
  <A HREF="<%= $p %>edit/part_pkg.cgi"><I>Add a new package definition</I></A>
  <BR><BR>
<% } %>

<%= $total %> package definitions
<%
if ( $cgi->param('showdisabled') ) {
  $cgi->param('showdisabled', 0);
  print qq!( <a href="!. $cgi->self_url. qq!">hide disabled packages</a> )!;
} else {
  $cgi->param('showdisabled', 1);
  print qq!( <a href="!. $cgi->self_url. qq!">show disabled packages</a> )!;
}

my $colspan = $cgi->param('showdisabled') ? 2 : 3;
print &table(), <<END;
      <TR>
        <TH COLSPAN=$colspan>Package</TH>
        <TH>Comment</TH>
END
print '        <TH><FONT SIZE=-1>Customer<BR>packages</FONT></TH>'
  if $cgi->param('active');
print <<END;
        <TH><FONT SIZE=-1>Freq.</FONT></TH>
        <TH><FONT SIZE=-1>Plan</FONT></TH>
        <TH><FONT SIZE=-1>Data</FONT></TH>
        <TH>Service</TH>
        <TH><FONT SIZE=-1>Quan.</FONT></TH>
      </TR>
END

foreach my $part_pkg ( sort $sortby @part_pkg ) {
  my($hashref)=$part_pkg->hashref;
  my(@pkg_svc)=grep $_->getfield('quantity'),
    qsearch('pkg_svc',{'pkgpart'=> $hashref->{pkgpart} });
  my($rowspan)=scalar(@pkg_svc);
  my $plandata;
  if ( $hashref->{plan} ) {
    $plandata = $hashref->{plandata};
    $plandata =~ s/^(\w+)=/$1&nbsp;/mg;
    $plandata =~ s/\n/<BR>/g;
  } else {
    $hashref->{plan} = "(legacy)";
    $plandata = "Setup&nbsp;". $hashref->{setup}.
                "<BR>Recur&nbsp;". $hashref->{recur};
  }
  print <<END;
      <TR>
        <TD ROWSPAN=$rowspan><A HREF="${p}edit/part_pkg.cgi?$hashref->{pkgpart}">$hashref->{pkgpart}</A></TD>
END

  unless ( $cgi->param('showdisabled') ) {
    print "<TD ROWSPAN=$rowspan>";
    print "DISABLED" if $hashref->{disabled};
    print '</TD>';
  }

  print <<END;
        <TD ROWSPAN=$rowspan><A HREF="${p}edit/part_pkg.cgi?$hashref->{pkgpart}">$hashref->{pkg}</A></TD>
        <TD ROWSPAN=$rowspan>$hashref->{comment}</TD>
END
  if ( $cgi->param('active') ) {
    print "        <TD ROWSPAN=$rowspan>";
    print '<FONT COLOR="#00CC00"><B>'.
          $num_active_cust_pkg{$hashref->{'pkgpart'}}.
          qq!</B></FONT>&nbsp;<A HREF="${p}search/cust_pkg.cgi?magic=active;pkgpart=$hashref->{pkgpart}">active</A>!;
    # suspended/cancelled
    print '</TD>';
  }
  print <<END;
        <TD ROWSPAN=$rowspan>$hashref->{freq}</TD>
        <TD ROWSPAN=$rowspan>$hashref->{plan}</TD>
        <TD ROWSPAN=$rowspan>$plandata</TD>
END

  my($pkg_svc);
  my($n)="";
  foreach $pkg_svc ( @pkg_svc ) {
    my($svcpart)=$pkg_svc->getfield('svcpart');
    my($part_svc) = qsearchs('part_svc',{'svcpart'=> $svcpart });
    print $n,qq!<TD><A HREF="${p}edit/part_svc.cgi?$svcpart">!,
          $part_svc->getfield('svc'),"</A></TD><TD>",
          $pkg_svc->getfield('quantity'),"</TD></TR>\n";
    $n="<TR>";
  }

  print "</TR>";
}

$colspan = $cgi->param('showdisabled') ? 8 : 9;
print <<END;

    </TABLE>
  </BODY>
</HTML>
END


sub pkgpart_sort {
  $a->pkgpart <=> $b->pkgpart;
}

sub active_cust_pkg_sort {
  $num_active_cust_pkg{$b->pkgpart} <=> $num_active_cust_pkg{$a->pkgpart};
}

%>