summaryrefslogtreecommitdiff
path: root/httemplate/search/inventory_item.html
blob: d8277341519b10ede05f628c7b8ef3deb0e89b7f (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<& elements/search.html,
                 'title'       => $title,

                 'menubar'     => [ 'View inventory classes' =>
                                      $p.'browse/inventory_class.html',
                                    'Upload '. PL($inventory_class->classname)=>
                                      $p.'misc/inventory_item-import.html?'.
                                      "classnum=$classnum"
                                  ],

                 'name'        => PL($inventory_class->classname),

                 'query'       => {
                                    'table'   => 'inventory_item',
                                    'hashref' => {},
                                    'select'  => join(', ',
                                        'inventory_item.*',
                                        'part_svc.svcdb',
                                        'cust_main.custnum',
                                        FS::UI::Web::cust_sql_fields(),
                                      ),
                                    'extra_sql' => $extra_sql,
                                    'addl_from' => $addl_from,
                                  },

                 'count_query' => $count_query,

                 'agent_virt' => 1,
                 'agent_null' => 1,
                 'agent_pos'  => 2,

                 'header'      => [
                   '#',
                   $inventory_class->classname,
                   'Service',
                   FS::UI::Web::cust_header(),
                   '', # checkbox column
                 ],

                 '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,
                   $sub_checkbox,

                 ],
                 'align'       => 'rll'.FS::UI::Web::cust_aligns(),
                 'links'       => [
                   '',
                   '',
                   $link,
                   ( map { $_ ne 'Cust. Status' ? $link_cust : '' }
                         FS::UI::Web::cust_header()
                   ),
                 ],
                 'color' => [ 
                              '',
                              '',
                              '',
                              FS::UI::Web::cust_colors(),
                            ],
                 'style' => [ 
                              '',
                              '',
                              '',
                              FS::UI::Web::cust_styles(),
                            ],
                  'html_init' => $html_form,
                  'html_foot' => $html_foot,
             
&>
<%init>

my $curuser = $FS::CurrentUser::CurrentUser;

die "access denied"
  unless $curuser->access_right('Edit inventory')
      || $curuser->access_right('Edit global inventory')
      || $curuser->access_right('Configuration');

my $classnum = $cgi->param('classnum');
$classnum =~ /^(\d+)$/ or errorpage("illegal classnum $classnum");
$classnum = $1;
my $extra_sql = "WHERE inventory_item.classnum = $classnum ";

my $inventory_class = qsearchs( {
  'table'     => 'inventory_class',
  'hashref'   => { 'classnum' => $classnum },
} );

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 )';
  $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 $extra_sql";

my $link = sub {
  my $inventory_item = shift;
  if ( $inventory_item->svcnum ) {

    #[ "${p}view/svc_acct.cgi?", 'svcnum' ];
    my $url = svc_url(
      'm'      => $m,
      'action' => 'view',
      #'svcdb'  => $inventory_item->cust_svc->part_svc->svcdb,
      'svcdb'  => $inventory_item->svcdb, #we have it from the joined search
      'query'  => '',
    );
    [ $url, '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  ) '.
                FS::UI::Web::join_cust_main('cust_pkg', 'cust_pkg');

my $sub_checkbox = sub {
  my $item = $_[0];
  my $itemnum = $item->itemnum;
  return '' if $item->svcnum;

  return qq!<INPUT NAME="itemnum" TYPE="checkbox" VALUE="$itemnum">!;
};

my $html_form = qq!
<FORM NAME="itemForm" ACTION="$p/misc/inventory_item-move.cgi" METHOD="POST">
<INPUT TYPE="hidden" NAME="classnum" VALUE="$classnum">
<INPUT TYPE="hidden" NAME="avail"    VALUE="! .$cgi->param('avail') . '">';
#'

my $html_foot = include('elements/checkbox-foot.html',
      actions => [
          { submit  => 'Delete',
            confirm => 'Delete the selected items?',
            name    => 'delete',
          },
          { submit  => 'Move to',
            name    => 'move',
          },
      ],
);

$html_foot =~ s[</DIV>][];
$html_foot .= 
  include('/elements/select-agent.html',
    'field'         => 'move_agentnum',
    'disable_empty' => 1,
  ) .
  '</DIV></FORM>';

</%init>