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
|
%
%
%my $classnum = $cgi->param('classnum');
%$classnum =~ /^(\d+)$/ or eidiot "illegal classnum $classnum";
%$classnum = $1;
%
%my $inventory_class = qsearchs( {
% 'table' => 'inventory_class',
% 'hashref' => { 'classnum' => $classnum },
%} );
%
%my $title = $inventory_class->classname. ' Inventory';
%
%#little false laziness with SQL fragments in inventory_class.pm
%my $extra_sql = '';
%if ( $cgi->param('avail') ) {
% $extra_sql = 'AND ( svcnum IS NULL OR svcnum = 0 )';
% $title .= ' - Available';
%} elsif ( $cgi->param('used') ) {
% $extra_sql = 'AND svcnum IS NOT NULL AND svcnum > 0';
% $title .= ' - In use';
%}
%
%my $count_query =
% "SELECT COUNT(*) FROM inventory_item WHERE classnum = $classnum $extra_sql";
%
%my $link = sub {
% my $inventory_item = shift;
% if ( $inventory_item->svcnum ) {
% [ "${p}view/svc_acct.cgi?", 'svcnum' ];
% } else {
% '';
% }
%};
%my $link_cust = sub {
% my $inventory_item = shift;
% if ( $inventory_item->custnum ) {
% [ "${p}view/cust_main.cgi?", 'custnum' ];
% } else {
% '';
% }
%};
%
%my $addl_from = ' LEFT JOIN cust_svc USING ( svcnum ) '.
% ' LEFT JOIN part_svc USING ( svcpart ) '.
% ' LEFT JOIN cust_pkg USING ( pkgnum ) '.
% ' LEFT JOIN cust_main USING ( custnum ) ';
%
%
<% include( 'elements/search.html',
'title' => $title,
#less lame to use Lingua:: something to pluralize
'name' => $inventory_class->classname. 's',
'query' => {
'table' => 'inventory_item',
'hashref' => { 'classnum' => $classnum },
'select' => join(', ',
'inventory_item.*',
'cust_main.custnum',
FS::UI::Web::cust_sql_fields(),
),
'extra_sql' => $extra_sql,
'addl_from' => $addl_from,
},
'count_query' => $count_query,
'header' => [
'#',
$inventory_class->classname,
'Service',
FS::UI::Web::cust_header(),
],
'fields' => [
'itemnum',
'item',
#'svcnum', #XXX proper full service customer link ala svc_acct
# "unallocated" ? "available" ?
sub {
#this could be way more efficient with a mixin
# like cust_main_Mixin that let us all all the methods
# on data we already have...
my $inventory_item = shift;
my $cust_svc = $inventory_item->cust_svc;
if ( $cust_svc ) {
my($label, $value) = $cust_svc->label;
"$label: $value";
} else {
'(available)';
}
},
\&FS::UI::Web::cust_fields,
],
'links' => [
'',
'',
$link,
( map { $link_cust } FS::UI::Web::cust_header() ),
],
)
%>
|