1 <% include('/elements/header.html', "$classname Inventory Activity Report") %>
2 <% include('/elements/table-grid.html') %>
4 % my $TH = 'TH CLASS="grid" BGCOLOR="#cccccc" ROWSPAN=1';
5 <<%$TH%> WIDTH="10%" ALIGN="left">Day (<% time2str("%B %Y", $sdate) %>)</TH>
6 % foreach my $day (0..$numdays-1) {
7 <<%$TH%> WIDTH="2%" ALIGN="right"><% $day+1 %></TH>
10 % for (my $r=0; $r < scalar(@rows); $r++) {
12 % my $TD = 'TD CLASS="grid" BGCOLOR="'.($r % 2 ? '#ffffff' : '#eeeeee').'"';
13 <<%$TD%>><% $labels[$r] %></TD>
14 % for my $day (0..$numdays-1) {
15 <<%$TD%> ALIGN="right"><% $rows[$r][$day] %></TD>
22 use Date::Parse 'str2time';
23 use Date::Format 'time2str';
24 #use Data::Dumper::HTML 'dumper_html';
26 my ($classnum, $month, $year, $sdate, $edate);
27 $classnum = $cgi->param('classnum'); # may be empty
30 my $class = qsearchs('inventory_class', { classnum => $classnum });
31 die "classnum $classnum not found!" if !$class;
32 $classname = $class->classname . ' ';
35 $month = $cgi->param('_month') || time2str('%m', time);
36 $year = $cgi->param('_year') || time2str('%Y', time);
38 $sdate = str2time("$year-$month-01");
39 $edate = str2time($year + ($month == 12 ? 1 : 0) .
41 (($month + 1) % 12 || 12) .
43 my $numdays = sprintf("%.0f",($edate-$sdate)/86400);
44 my @days = (0..$numdays - 1);
45 # Initialize each row with zeroes.
53 my @rows = ( map {[ (0) x $numdays ]} @labels);
55 foreach my $day (0..$numdays-1) {
56 $rows[0][$day] = $rows[4][$day-1] if($day > 0);
59 foreach my $action (qw(insert replace_new replace_old)) {
62 'table' => 'h_inventory_item',
63 'hashref' => { $classnum ? ('classnum' => $classnum) : (),
64 'history_action' => $action },
65 'order_by' => 'ORDER BY itemnum, history_date',
67 ' AND history_date >= '.($sdate + 86400*$day).
68 ' AND history_date < ' .($sdate + 86400*($day+1)),
72 # Incoming items: simple, just count the inserts
73 $rows[1][$day] = scalar(@{ $history{'insert'} });
75 # Other item changes: trickier.
76 # Notice the order_by parameter above.
77 # Both lists are sorted by itemnum, then by date, so unless some villain has
78 # been rapidly replacing the same record several times per second, the
79 # replace_old and replace_new from the same operation will be in the same
81 while(my $h_new = shift @{ $history{'replace_new'} }) {
82 my $h_old = shift @{ $history{'replace_old'} };
83 die "history error" if !defined($h_old)
84 or $h_old->itemnum != $h_new->itemnum;
85 if(!$h_old->svcnum and $h_new->svcnum) {
86 # item was put into service.
89 elsif($h_old->svcnum and !$h_new->svcnum) {
90 # item was taken out of service.
93 # Add other cases here.
96 $rows[4][$day] = $rows[0][$day]