summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2010-05-21 23:35:47 +0000
committerivan <ivan>2010-05-21 23:35:47 +0000
commit42ed7ef03700fb17467bfeedead3639da9efc4a4 (patch)
treeac9ac209fee11c0a0fd4b122b8554e4d58c15037
parent4eae5a24723dd6cbac93bb646284a4fdf1553e73 (diff)
reporting on agent inventory, RT#7010
-rw-r--r--FS/FS/inventory_class.pm100
-rw-r--r--httemplate/browse/inventory_class.html70
-rw-r--r--httemplate/elements/menu.html7
-rw-r--r--httemplate/search/agent_inventory.html40
-rw-r--r--httemplate/search/inventory_item.html6
-rw-r--r--httemplate/search/report_agent_inventory.html26
6 files changed, 179 insertions, 70 deletions
diff --git a/FS/FS/inventory_class.pm b/FS/FS/inventory_class.pm
index 3d7f0499d..4747241d7 100644
--- a/FS/FS/inventory_class.pm
+++ b/FS/FS/inventory_class.pm
@@ -115,7 +115,10 @@ class (see L<FS::inventory_item>).
=cut
sub num_avail {
- shift->num_sql('( svcnum IS NULL OR svcnum = 0 )');
+ my( $self, $sql ) = @_;
+ $sql .= ' AND ' if length($sql);
+ $sql .= '( svcnum IS NULL OR svcnum = 0 )';
+ $self->num_sql($sql);
}
sub num_sql {
@@ -142,7 +145,10 @@ L<FS::inventory_class>).
=cut
sub num_used {
- shift->num_sql("svcnum IS NOT NULL AND svcnum > 0 ");
+ my( $self, $sql ) = @_;
+ $sql .= ' AND ' if length($sql);
+ $sql .= 'svcnum IS NOT NULL AND svcnum > 0 ';
+ $self->num_sql($sql);
}
=item num_total
@@ -153,7 +159,95 @@ L<FS::inventory_class>).
=cut
sub num_total {
- shift->num_sql('');
+ my( $self, $sql ) = @_;
+ $self->num_sql($sql);
+}
+
+=back
+
+=head1 CLASS METHODS
+
+=over 4
+
+=item searchcell_factory
+
+=cut
+
+sub countcell_factory {
+ my($class, %opt) = @_;
+
+ my $p = $opt{p};
+
+ my $sql = $opt{'agentnum'} ? 'agentnum = '.$opt{'agentnum'} : '';
+
+ use Tie::IxHash;
+ tie my %labels, 'Tie::IxHash',
+ 'num_avail' => 'Available', # <FONT SIZE="-1"><A HREF="eventually">(upload batch)</A></FONT>',
+ 'num_used' => 'In use', #'Used', #'Allocated',
+ 'num_total' => 'Total',
+ ;
+
+ my %link = (
+ 'num_avail' => ';avail=1',
+ 'num_used' => ';used=1',
+ 'num_total' => '',
+ );
+
+ my %inv_action_link = (
+ 'num_avail' => [ 'upload batch',
+ $p.'misc/inventory_item-import.html?classnum=',
+ 'classnum'
+ ],
+ );
+
+ sub {
+ my $inventory_class = shift;
+
+ my $link =
+ $p. 'search/inventory_item.html?'.
+ 'classnum='. $inventory_class->classnum;
+ $link .= ';agentnum='.$opt{'agentnum'} if $opt{'agentnum'};
+
+ my %actioncol = ();
+ foreach ( keys %inv_action_link ) {
+ my($label, $baseurl, $method) =
+ @{ $inv_action_link{$_} };
+ my $url = $baseurl. $inventory_class->$method();
+ $actioncol{$_} =
+ '<FONT SIZE="-1">'.
+ '('.
+ '<A HREF="'.$url.'">'.
+ $label.
+ '</A>'.
+ ')'.
+ '</FONT>';
+ }
+
+ my %num = map {
+ $_ => $inventory_class->$_($sql);
+ } keys %labels;
+
+ [ map {
+ [
+ {
+ 'data' => '<B>'. $num{$_}. '</B>',
+ 'align' => 'right',
+ },
+ {
+ 'data' => $labels{$_},
+ 'align' => 'left',
+ 'link' => ( $num{$_}
+ ? $link.$link{$_}
+ : ''
+ ),
+ },
+ { 'data' => $actioncol{$_},
+ 'align' => 'left',
+ },
+ ]
+ } keys %labels
+ ];
+ };
}
=back
diff --git a/httemplate/browse/inventory_class.html b/httemplate/browse/inventory_class.html
index 4ad72a2ea..2d85f1234 100644
--- a/httemplate/browse/inventory_class.html
+++ b/httemplate/browse/inventory_class.html
@@ -7,54 +7,9 @@
'header' => [ '#', 'Inventory class', 'Inventory' ],
'fields' => [ 'classnum',
'classname',
- sub {
- #my $inventory_class = shift;
- my $i_c = shift;
-
- my $link =
- $p. 'search/inventory_item.html?'.
- 'classnum='. $i_c->classnum;
-
- my %actioncol = ();
- foreach ( keys %inv_action_link ) {
- my($label, $baseurl, $method) =
- @{ $inv_action_link{$_} };
- my $url = $baseurl. $i_c->$method();
- $actioncol{$_} =
- '<FONT SIZE="-1">'.
- '('.
- '<A HREF="'.$url.'">'.
- $label.
- '</A>'.
- ')'.
- '</FONT>';
- }
-
- my %num = map {
- $_ => $i_c->$_();
- } keys %labels;
-
- [ map {
- [
- {
- 'data' => '<B>'. $num{$_}. '</B>',
- 'align' => 'right',
- },
- {
- 'data' => $labels{$_},
- 'align' => 'left',
- 'link' => ( $num{$_}
- ? $link.$link{$_}
- : ''
- ),
- },
- { 'data' => $actioncol{$_},
- 'align' => 'left',
- },
- ]
- } keys %labels
- ];
- },
+ FS::inventory_class->countcell_factory(
+ 'p'=>$p,
+ ),
],
'links' => [ $link,
$link,
@@ -71,25 +26,6 @@ die "access denied"
|| $curuser->access_right('Edit global inventory')
|| $curuser->access_right('Configuration');
-tie my %labels, 'Tie::IxHash',
- 'num_avail' => 'Available', # <FONT SIZE="-1"><A HREF="eventually">(upload batch)</A></FONT>',
- 'num_used' => 'In use', #'Used', #'Allocated',
- 'num_total' => 'Total',
-;
-
-my %link = (
- 'num_avail' => ';avail=1',
- 'num_used' => ';used=1',
- 'num_total' => '',
-);
-
-my %inv_action_link = (
- 'num_avail' => [ 'upload batch',
- $p.'misc/inventory_item-import.html?classnum=',
- 'classnum'
- ],
-);
-
my $menubar = $curuser->access_right('Configuration')
? [ 'Add a new inventory class' =>
$p.'edit/inventory_class.html',
diff --git a/httemplate/elements/menu.html b/httemplate/elements/menu.html
index fc5498f84..2d28e49d4 100644
--- a/httemplate/elements/menu.html
+++ b/httemplate/elements/menu.html
@@ -213,6 +213,11 @@ $report_packages{'FCC Form 477 packages'} = [ $fsurl.'search/report_477.html',
if $conf->exists('cust_main-require_censustract');
$report_packages{'Advanced package reports'} = [ $fsurl.'search/report_cust_pkg.html', 'by agent, date range, status, package definition' ];
+tie my %report_inventory, 'Tie::IxHash',
+ 'Inventory by agent' => [ $fsurl.'search/report_agent_inventory.html', '' ],
+ #'Inventory activity' => [ $fsurl.'search/report_h_inventory_item.html', '' ],
+;
+
tie my %report_rating, 'Tie::IxHash',
'RADIUS sessions' => [ $fsurl.'search/sqlradius.html', '' ],
'Call Detail Records (CDRs)' => [ $fsurl.'search/report_cdr.html', '' ],
@@ -295,6 +300,8 @@ $report_menu{'Packages'} = [ \%report_packages, 'Package reports' ]
if $curuser->access_right('List packages');
$report_menu{'Services'} = [ \%report_services, 'Services reports' ]
if $curuser->access_right('List services');
+$report_menu{'Inventory'} = [ \%report_inventory, 'Inventory reports' ]
+ if $curuser->access_right('Configuration'); #XXX List inventory?
$report_menu{'Usage'} = [ \%report_rating, 'Usage reports' ]
if $curuser->access_right('List rating data');
$report_menu{'Tickets'} = [ \%report_ticketing, 'Ticket reports' ]
diff --git a/httemplate/search/agent_inventory.html b/httemplate/search/agent_inventory.html
new file mode 100644
index 000000000..ac65371ca
--- /dev/null
+++ b/httemplate/search/agent_inventory.html
@@ -0,0 +1,40 @@
+<% include('elements/search.html',
+ 'title' => 'Inventory summary per agent',
+ 'name_singular' => 'agent',
+ 'query' => { 'table' => 'agent',
+ 'hashref' => { 'disabled' => '' },
+ 'extra_sql' => "AND $agentnums_sql",
+ },
+ 'count_query' => "SELECT COUNT(*) FROM agent".
+ " WHERE disabled = '' OR disabled IS NULL".
+ " AND $agentnums_sql",
+ 'header' => \@header,
+ 'fields' => \@fields,
+ )
+%>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+#XXX List inventory
+
+my $agentnums_sql = $FS::CurrentUser::CurrentUser->agentnums_sql;
+
+my @header = ('Agent');
+my @fields = ('agent');
+
+ #{ 'disabled' => '' }
+foreach my $inventory_class ( qsearch('inventory_class', {}) ) {
+ push @header, $inventory_class->classname;
+ push @fields, sub {
+ my $agent = shift;
+ my $sub = FS::inventory_class->countcell_factory(
+ 'p' => $p, 'agentnum' => $agent->agentnum,
+ );
+ &{$sub}($inventory_class);
+ };
+}
+
+#XXX show global inventory too
+
+</%init>
diff --git a/httemplate/search/inventory_item.html b/httemplate/search/inventory_item.html
index 681e5dbac..37914e0a7 100644
--- a/httemplate/search/inventory_item.html
+++ b/httemplate/search/inventory_item.html
@@ -103,6 +103,12 @@ my $inventory_class = qsearchs( {
my $title = $inventory_class->classname. ' Inventory';
+if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+ $extra_sql .= " AND inventory_item.agentnum = $1 ";
+ my $agent = qsearchs('agent', { 'agentnum' => $1 }) or die "unknown agentnum";
+ $title = $agent->agent. " $title";
+}
+
#little false laziness with SQL fragments in inventory_class.pm
if ( $cgi->param('avail') ) {
$extra_sql .= ' AND ( svcnum IS NULL OR svcnum = 0 )';
diff --git a/httemplate/search/report_agent_inventory.html b/httemplate/search/report_agent_inventory.html
new file mode 100644
index 000000000..af66043a6
--- /dev/null
+++ b/httemplate/search/report_agent_inventory.html
@@ -0,0 +1,26 @@
+<% include('/elements/header.html', 'Inventory summary per agent' ) %>
+
+<FORM ACTION="agent_inventory.html" METHOD="GET">
+
+<TABLE BGCOLOR="#cccccc" CELLSPACING=0>
+
+%# select agents
+
+%# select inventory classes
+
+</TABLE>
+
+<BR>
+<INPUT TYPE="submit" VALUE="Search">
+
+</FORM>
+
+<% include('/elements/footer.html') %>
+<%init>
+
+die "access denied"
+ unless $FS::CurrentUser::CurrentUser->access_right('Configuration');
+#XXX List inventory
+
+</%init>
+