View | Details | Raw Unified | Return to bug 7684
Collapse All | Expand All

(-)a/C4/Auth.pm (-1 / +1 lines)
Lines 1091-1097 sub check_api_auth { Link Here
1091
    unless ($query->param('userid')) {
1091
    unless ($query->param('userid')) {
1092
        $sessionID = $query->cookie("CGISESSID");
1092
        $sessionID = $query->cookie("CGISESSID");
1093
    }
1093
    }
1094
    if ($sessionID && not ($cas && $query->param('PT')) ) {
1094
    if ( $sessionID && not ($cas && $query->param('PT')) ) {
1095
        my $session = get_session($sessionID);
1095
        my $session = get_session($sessionID);
1096
        C4::Context->_new_userenv($sessionID);
1096
        C4::Context->_new_userenv($sessionID);
1097
        if ($session) {
1097
        if ($session) {
(-)a/C4/Items.pm (-12 / +29 lines)
Lines 968-976 sub GetLostItems { Link Here
968
968
969
=head2 GetItemsForInventory
969
=head2 GetItemsForInventory
970
970
971
  $itemlist = GetItemsForInventory($minlocation, $maxlocation, 
971
=over 4
972
                 $location, $itemtype $datelastseen, $branch, 
972
973
                 $offset, $size, $statushash);
973
($itemlist, $iTotalRecords)  = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $offset, $size, $statushash);
974
975
=back
974
976
975
Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.
977
Retrieve a list of title/authors/barcode/callnumber, for biblio inventory.
976
978
Lines 983-988 the datelastseen can be used to specify that you want to see items not seen sinc Link Here
983
offset & size can be used to retrieve only a part of the whole listing (defaut behaviour)
985
offset & size can be used to retrieve only a part of the whole listing (defaut behaviour)
984
$statushash requires a hashref that has the authorized values fieldname (intems.notforloan, etc...) as keys, and an arrayref of statuscodes we are searching for as values.
986
$statushash requires a hashref that has the authorized values fieldname (intems.notforloan, etc...) as keys, and an arrayref of statuscodes we are searching for as values.
985
987
988
$iTotalRecords is the number of rows that would have been returned without the $offset, $size limit clause
989
986
=cut
990
=cut
987
991
988
sub GetItemsForInventory {
992
sub GetItemsForInventory {
Lines 991-997 sub GetItemsForInventory { Link Here
991
    my ( @bind_params, @where_strings );
995
    my ( @bind_params, @where_strings );
992
996
993
    my $query = <<'END_SQL';
997
    my $query = <<'END_SQL';
994
SELECT items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, datelastseen
998
SELECT SQL_CALC_FOUND_ROWS items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, biblio.frameworkcode, datelastseen, homebranch, location, notforloan, damaged, itemlost, stocknumber
995
FROM items
999
FROM items
996
  LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
1000
  LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
997
  LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber
1001
  LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber
Lines 1050-1069 END_SQL Link Here
1050
        $query .= join ' AND ', @where_strings;
1054
        $query .= join ' AND ', @where_strings;
1051
    }
1055
    }
1052
    $query .= ' ORDER BY items.cn_sort, itemcallnumber, title';
1056
    $query .= ' ORDER BY items.cn_sort, itemcallnumber, title';
1057
    $query .= " LIMIT $offset, $size" if ($offset and $size);
1053
    my $sth = $dbh->prepare($query);
1058
    my $sth = $dbh->prepare($query);
1054
    $sth->execute( @bind_params );
1059
    $sth->execute( @bind_params );
1055
1060
1056
    my @results;
1061
    my @results;
1057
    $size--;
1062
    my $tmpresults = $sth->fetchall_arrayref({});
1058
    while ( my $row = $sth->fetchrow_hashref ) {
1063
    $sth = $dbh->prepare("SELECT FOUND_ROWS()");
1059
        $offset-- if ($offset);
1064
    $sth->execute();
1060
        $row->{datelastseen}=format_date($row->{datelastseen});
1065
    my ($iTotalRecords) = $sth->fetchrow_array();
1061
        if ( ( !$offset ) && $size ) {
1066
 
1062
            push @results, $row;
1067
    foreach my $row (@$tmpresults) {
1063
            $size--;
1068
        $row->{datelastseen} = format_date( $row->{datelastseen} );
1069
1070
        # Auth values
1071
        foreach (keys %$row) {
1072
            # If the koha field is mapped to a marc field
1073
            my ($f, $sf) = GetMarcFromKohaField("items.$_", $row->{'frameworkcode'});
1074
            if ($f and $sf) {
1075
                # We replace the code with it's description
1076
                my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $row->{'frameworkcode'});
1077
                $row->{$_} = $authvals->{$row->{$_}} if $authvals->{$row->{$_}};
1078
            }
1064
        }
1079
        }
1080
        push @results, $row;
1065
    }
1081
    }
1066
    return \@results;
1082
   
1083
    return (\@results, $iTotalRecords);
1067
}
1084
}
1068
1085
1069
=head2 GetItemsCount
1086
=head2 GetItemsCount
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tmpl (+296 lines)
Line 0 Link Here
1
<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
2
<title>Koha &rsaquo; Tools &rsaquo; Inventory</title>
3
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
4
<link rel="stylesheet" type="text/css" href="<!-- TMPL_VAR NAME="themelang" -->/css/datatables.css" />
5
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.dataTables.min.js"></script>
6
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/js/datatables.js"></script>
7
<!-- TMPL_INCLUDE NAME="calendar.inc" -->
8
<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.checkboxes.min.js"></script>
9
<script type="text/javascript">
10
//<![CDATA[
11
$(document).ready(function(){
12
13
        inventorydt = $('#inventoryt').dataTable({
14
            'sPaginationType': 'full_numbers',
15
            "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0 ] } ] 
16
        } );
17
18
19
	$("#continuewithoutmarkingbutton").click(function(){
20
                inventorydt.fnPageChange( 'next' );
21
	        return false;
22
        });
23
24
        $("#markseenandcontinuebutton").click(function(){
25
            var param = '';
26
            $("input:checked").each(function() {
27
                param += "|" + $(this).attr('name');
28
            });
29
            $.post('/cgi-bin/koha/tools/ajax-inventory.pl', { seen: param });
30
            inventorydt.fnDraw();
31
            inventorydt.fnPageChange( 'next' );
32
            return false;
33
        });
34
35
        $("#markseenandquit").click(function(){
36
            var param = '';
37
            $("input:checked").each(function() {
38
                param += "|" + $(this).attr('name');
39
            });
40
            $.ajax({
41
              type: 'POST',
42
              url: '/cgi-bin/koha/tools/ajax-inventory.pl',
43
              data: { seen: param},
44
              async: false
45
            });
46
            document.location.href = '/cgi-bin/koha/tools/inventory.pl';
47
            return false;
48
        });
49
50
51
52
	$(".checkall").click(function(){
53
	        $(".checkboxed").checkCheckboxes();
54
	        return false;
55
		});
56
	$(".clearall").click(function(){
57
	        $(".checkboxed").unCheckCheckboxes();
58
	        return false;
59
	    });
60
	$("#markback").click(function(){
61
		$(".checkboxed").find("input").filter("[name=offset]").attr("value","<!-- TMPL_VAR NAME="prevoffset" -->");
62
		return true;
63
	});
64
	$("#marknext").click(function(){
65
		$(".checkboxed").find("input").filter("[name=offset]").attr("value","<!-- TMPL_VAR NAME="nextoffset" -->");
66
		return true;
67
	});
68
	});
69
//]]>
70
</script>
71
</head>
72
<body>
73
<!-- TMPL_INCLUDE NAME="header.inc" -->
74
<!-- TMPL_INCLUDE NAME="cat-search.inc"-->
75
76
<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> &rsaquo; <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> &rsaquo; <!-- TMPL_IF NAME="loop" --><a href="/cgi-bin/koha/tools/inventory.pl">Inventory</a> &rsaquo; Results<!-- TMPL_ELSE -->Inventory<!-- /TMPL_IF --></div>
77
78
<div id="doc3" class="yui-t2">
79
   
80
   <div id="bd">
81
	<div id="yui-main">
82
	<div class="yui-b">
83
    <h1>Inventory/Stocktaking</h1>
84
    <!--TMPL_IF Name="moddatecount" --><div class="dialog message"><!--TMPL_VAR Name="moddatecount"--> items modified : datelastseen set to <!--TMPL_VAR Name="date"--></div><!-- /TMPL_IF-->
85
    <!--TMPL_IF Name="errorfile" --><div class="dialog alert"><!--TMPL_VAR Name="errorfile"--> can't be opened</div><!-- /TMPL_IF-->
86
    <!--TMPL_LOOP Name="errorloop"-->
87
        <div class="dialog alert">
88
            <!--TMPL_VAR Name="barcode"-->
89
            <!--TMPL_IF Name="ERR_BARCODE"-->: barcode not found<!--/TMPL_IF-->
90
            <!--TMPL_IF Name="ERR_WTHDRAWN"-->: item withdrawn<!--/TMPL_IF-->
91
            <!--TMPL_IF Name="ERR_ONLOAN_RET"-->: item was on loan. It was returned before marked as seen<!--/TMPL_IF-->
92
            <!--TMPL_IF Name="ERR_ONLOAN_NOT_RET"-->: item was on loan. couldn't be returned.<!--/TMPL_IF-->
93
        </div>
94
    <!-- /TMPL_LOOP-->
95
       <!-- TMPL_UNLESS name="op" -->
96
	<div class="yui-g">
97
    <form method="post" action="/cgi-bin/koha/tools/inventory.pl" enctype="multipart/form-data">
98
        <fieldset class="rows">
99
            <legend>Use a barcode file</legend>
100
	 <ol>
101
            <li><label for="uploadbarcodes">Barcode file: </label> <input type="file" id="uploadbarcodes" name="uploadbarcodes" /></li>
102
            <li><label for="setdate">Set inventory date to:</label> <input type="text" id="setdate" name="setdate" value="<!-- TMPL_VAR name="today" -->" />
103
             <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="setdate_button" alt="Show Calendar" />
104
            <script type="text/javascript">
105
            Calendar.setup(
106
            {
107
            inputField : "setdate",
108
            ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
109
            button : "setdate_button"
110
            }
111
            );
112
            </script>
113
			<div class="hint"><!-- TMPL_INCLUDE NAME="date-format.inc" --></div>
114
            </li>
115
          </ol>
116
        </fieldset>
117
        <fieldset class="rows">
118
        <legend>Select items you want to check</legend>
119
        <ol><li>
120
        <label for="branch">Branch</label>
121
            <input type="radio" name="branch" value="homebranch">Home Branch</input>
122
            <input type="radio" name="branch" value="holdingbranch">Holding Branch</input>
123
        </li><li>
124
        <label for="branchloop">Library</label><select id="branchloop" name="branchcode" style="width:12em;">
125
            <option value="">All Locations</option>
126
        <!-- TMPL_LOOP NAME="branchloop" -->
127
            <!-- TMPL_IF name="selected" -->
128
                <option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="branchname" --></option>
129
            <!-- TMPL_ELSE -->
130
                <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="branchname" --></option>
131
            <!-- /TMPL_IF -->
132
        <!-- /TMPL_LOOP -->
133
        </select>
134
        </li>
135
        <!-- TMPL_IF NAME="authorised_values" -->
136
        <li>
137
            <label for="locationloop">Item Location (items.location) is</label> 
138
        <select id="locationloop" name="location">
139
                <option value="">Filter location</option>
140
        <!-- TMPL_LOOP NAME="authorised_values" -->
141
            <!-- TMPL_IF name="selected" -->
142
                <option value="<!-- TMPL_VAR NAME="authorised_value" -->" selected="selected"><!-- TMPL_VAR NAME="lib" --></option>
143
            <!-- TMPL_ELSE -->
144
                <option value="<!-- TMPL_VAR NAME="authorised_value" -->"><!-- TMPL_VAR NAME="lib" --></option>
145
            <!-- /TMPL_IF -->
146
        <!-- /TMPL_LOOP -->
147
        </select>        </li>
148
        <!-- /TMPL_IF -->
149
        <li>
150
            <label for="minlocation">Item callnumber between: </label>
151
                <input type="text" name="minlocation" id="minlocation" value="<!-- TMPL_VAR NAME="minlocation" -->" /> (items.itemcallnumber)  </li>
152
           <li><label for="maxlocation">...and: </label>
153
                <input type="text" name="maxlocation" id="maxlocation" value="<!-- TMPL_VAR NAME="maxlocation" -->" />
154
        </li>
155
        <!-- TMPL_IF name="statuses" -->
156
	</ol>
157
	</fieldset>
158
            <fieldset class="rows">
159
            <legend>Item statuses:</legend>
160
            <div name="statuses" style="display: block;">
161
                  <!-- TMPL_LOOP name="statuses" -->
162
                      <!-- TMPL_IF name="values" -->
163
                          <fieldset style="float: left; padding: 5px; margin: 5px;text-align:right">
164
                              <legend><!-- TMPL_VAR name="fieldname" --></legend>
165
                              <ul id="statuses-<!-- TMPL_VAR name="fieldname" -->" style="display: inline;">
166
                              <!-- TMPL_LOOP name="values" -->
167
                                  <!-- TMPL_IF NAME="lib" --><li>
168
                                    <label for="<!-- TMPL_VAR name="id" -->">
169
                                      <!-- TMPL_VAR name="lib" -->
170
                                    </label>
171
                                    <input type="checkbox" name="status-<!-- TMPL_VAR name="fieldname" -->-<!-- TMPL_VAR name="authorised_value" -->" id="<!-- TMPL_VAR name="authorised_value" -->" />
172
                                  </li><!-- /TMPL_IF -->
173
                              <!-- /TMPL_LOOP -->
174
                              </ul>
175
                          </fieldset>
176
                      <!-- /TMPL_IF -->
177
                  <!-- /TMPL_LOOP -->
178
                </div>
179
            </fieldset>
180
		<fieldset class="rows">
181
          <ol>
182
        <!-- /TMPL_IF -->
183
184
        <li><label for="datelastseen">Inventory date:</label>
185
            <input type="text" id="datelastseen" name="datelastseen" value="<!-- TMPL_VAR NAME="datelastseen" -->" />
186
            <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="datelastseen_button" alt="Show Calendar" />
187
            <script type="text/javascript">
188
            Calendar.setup(
189
            {
190
            inputField : "datelastseen",
191
            ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
192
            button : "datelastseen_button"
193
            }
194
            );
195
            </script>
196
			<div class="hint"><!-- TMPL_INCLUDE NAME="date-format.inc" --></div>
197
        </li>
198
        <li><label for="ignoreissued">Skip copies on loan: </label>
199
            <!-- TMPL_IF NAME="ignoreissued" -->
200
            <input type="checkbox" id="ignoreissued" name="ignoreissued" checked="checked" /></li>
201
            <!-- TMPL_ELSE -->
202
            <input type="checkbox" id="ignoreissued" name="ignoreissued" /></li>
203
            <!-- /TMPL_IF -->
204
        <li>
205
           <label for="CSVexport">Export to csv file</label>
206
           <input type="checkbox" name="CSVexport" id="CSVexport" />
207
        </li>
208
        <li>
209
            <label for="compareinv2barcd">Compare barcodes list to results</label>
210
            <input type="checkbox" name="compareinv2barcd" id="compareinv2barcd" />
211
        </li>
212
        </ol>
213
  </fieldset>
214
            <input type="hidden" name="op" value="do_it" />
215
            <fieldset class="action"><input type="submit" value="Submit" class="button" /></fieldset>
216
    </form>
217
	</div>
218
	</div>
219
	<!--/TMPL_UNLESS-->
220
    <!-- TMPL_IF NAME="op" -->
221
    <form method="post" action="/cgi-bin/koha/tools/inventory.pl" class="checkboxed">
222
    <input type="hidden" name="markseen" value="1" />
223
    <input type="hidden" name="minlocation" value="<!-- TMPL_VAR NAME="minlocation" -->" />
224
    <input type="hidden" name="maxlocation" value="<!-- TMPL_VAR NAME="maxlocation" -->" />
225
    <input type="hidden" name="location" value="<!-- TMPL_VAR NAME="location" -->" />
226
    <input type="hidden" name="branchcode" value="<!-- TMPL_VAR NAME="branchcode" -->" />
227
    <input type="hidden" name="datelastseen" value="<!-- TMPL_VAR NAME="datelastseen" -->" />
228
    <input type="hidden" name="pagesize" value="<!-- TMPL_VAR NAME="pagesize" -->" />
229
    <input type="hidden" name="offset" value="<!-- TMPL_VAR NAME="offset" -->" />
230
	<div style="padding : .3em 0"><a href="#" class="checkall">[Select All]</a> <a href="#" class="clearall">[Clear All]</a></div>
231
    <table id="inventoryt" class="display">
232
    <thead>
233
        <tr>
234
            <th>Seen</th>
235
            <th>Barcode</th>
236
            <th>Location</th>
237
            <th>Title</th>
238
            <th>Status</th>
239
            <th>Lost</th>
240
            <th>Damaged</th>
241
            <th>Unseen since</th>
242
            <th>Problems</th>
243
        </tr>
244
    </thead>
245
    <tbody>
246
    <!-- TMPL_LOOP NAME="loop" -->
247
        <tr>
248
            <td>
249
            <input type="checkbox" name="SEEN-<!-- TMPL_VAR NAME="itemnumber" -->" value="1" />
250
            </td>
251
            <td>
252
            <!-- TMPL_VAR NAME="barcode" ESCAPE="html" -->
253
            </td>
254
            <td>
255
            <!-- TMPL_VAR NAME="homebranch" ESCAPE="html" --> <!-- TMPL_VAR name="location" ESCAPE="HTML" --> [<!-- TMPL_VAR NAME="itemcallnumber" ESCAPE="HTML" -->]
256
            </td>
257
            <td>
258
            <p><a href="#" onclick="window.open('/cgi-bin/koha/catalogue/MARCdetail.pl?biblionumber=<!--TMPL_VAR Name="biblionumber"-->','marcview','width=800,height=600,toolbar=0,scrollbars=1');"><!-- TMPL_VAR NAME="title" ESCAPE="HTML" --></a></p><p><!-- TMPL_VAR NAME="author" ESCAPE="HTML" --></p>
259
            </td>
260
            <td>
261
            <!-- TMPL_VAR NAME="notforloan" ESCAPE="html" -->
262
            </td>
263
            <td>
264
            <!-- TMPL_VAR NAME="itemlost" ESCAPE="html" -->
265
            </td>
266
            <td>
267
            <!-- TMPL_VAR NAME="damaged" ESCAPE="html" -->
268
            </td>
269
            <td>
270
            <!-- TMPL_VAR NAME="datelastseen" ESCAPE="html" -->
271
            </td>
272
            <td>
273
            <!-- TMPL_IF name="wrongplace" --><p>Item should not have been scanned</p><!-- TMPL_ELSIF name="missingitem" --><p>Item missing</p><!-- TMPL_ELSIF name="changestatus" --><p>Change item status</p><!-- /TMPL_IF -->
274
            </td>
275
        </tr>
276
    <!-- /TMPL_LOOP -->
277
    </tbody>
278
    </table>
279
    <div class="spacer"></div>
280
      <p style="display:block;"><span class="exportSelected"></span></p>
281
	<div style="padding : .3em 0"><a href="#" class="checkall">[Select All]</a> <a href="#" class="clearall">[Clear All]</a></div>
282
     <input type="submit" id="markseenandquit" value="Mark seen and quit" />
283
     <input type="submit" value="Mark Seen and Continue &gt;&gt;" id="markseenandcontinuebutton" />
284
     <input type="submit" value="Continue without Marking &gt;&gt;" id="continuewithoutmarkingbutton" class="submit" />
285
    </form>
286
287
    </div>
288
289
    <!-- /TMPL_IF -->
290
    <!-- /TMPL_IF -->
291
</div>
292
<div class="yui-b">
293
<!-- TMPL_INCLUDE NAME="tools-menu.inc" -->
294
</div>
295
</div>
296
<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
(-)a/tools/inventory.pl (-77 / +167 lines)
Lines 35-40 use C4::Dates qw/format_date format_date_in_iso/; Link Here
35
use C4::Koha;
35
use C4::Koha;
36
use C4::Branch; # GetBranches
36
use C4::Branch; # GetBranches
37
use C4::Circulation;
37
use C4::Circulation;
38
use C4::Reports::Guided;    #_get_column_defs
39
use C4::Charset;
40
38
41
39
my $minlocation=$input->param('minlocation') || '';
42
my $minlocation=$input->param('minlocation') || '';
40
my $maxlocation=$input->param('maxlocation');
43
my $maxlocation=$input->param('maxlocation');
Lines 50-68 my $pagesize = $input->param('pagesize'); Link Here
50
$pagesize=50 unless $pagesize;
53
$pagesize=50 unless $pagesize;
51
my $branchcode = $input->param('branchcode') || '';
54
my $branchcode = $input->param('branchcode') || '';
52
my $branch     = $input->param('branch');
55
my $branch     = $input->param('branch');
53
my $op = $input->param('op');
56
my $op         = $input->param('op');
54
my $res;    #contains the results loop
57
my $compareinv2barcd = $input->param('compareinv2barcd');
55
# warn "uploadbarcodes : ".$uploadbarcodes;
58
my $res;                                            #contains the results loop
56
# use Data::Dumper; warn Dumper($input);
59
57
60
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
58
my ($template, $borrowernumber, $cookie)
61
    {   template_name   => "tools/inventory.tmpl",
59
    = get_template_and_user({template_name => "tools/inventory.tmpl",
62
        query           => $input,
60
                query => $input,
63
        type            => "intranet",
61
                type => "intranet",
64
        authnotrequired => 0,
62
                authnotrequired => 0,
65
        flagsrequired   => { tools => 'inventory' },
63
                flagsrequired => {tools => 'inventory'},
66
        debug           => 1,
64
                debug => 1,
67
    }
65
                });
68
);
69
66
70
67
my $branches = GetBranches();
71
my $branches = GetBranches();
68
my @branch_loop;
72
my @branch_loop;
Lines 114-161 for my $authvfield (@$statuses) { Link Here
114
    }
118
    }
115
}
119
}
116
120
121
my $notforloanlist;
117
my $statussth = '';
122
my $statussth = '';
118
for my $authvfield (@$statuses) {
123
for my $authvfield (@$statuses) {
119
    if ( scalar @{$staton->{$authvfield->{fieldname}}} > 0 ){
124
    if ( scalar @{$staton->{$authvfield->{fieldname}}} > 0 ){
120
        my $joinedvals = join ',', @{$staton->{$authvfield->{fieldname}}};
125
        my $joinedvals = join ',', @{$staton->{$authvfield->{fieldname}}};
121
        $statussth .= "$authvfield->{fieldname} in ($joinedvals) and ";
126
        $statussth .= "$authvfield->{fieldname} in ($joinedvals) and ";
127
        $notforloanlist = $joinedvals if ($authvfield->{fieldname} eq "items.notforloan");
122
    }
128
    }
123
}
129
}
124
$statussth =~ s, and $,,g;
130
$statussth =~ s, and $,,g;
125
 
131
$template->param(
126
$template->param(branchloop => \@branch_loop,
132
    branchloop               => \@branch_loop,
127
                authorised_values=>\@authorised_value_list,   
133
    authorised_values        => \@authorised_value_list,
128
                DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
134
    DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
129
                today			=>	C4::Dates->today(),
135
    today                    => C4::Dates->today(),
130
                minlocation => $minlocation,
136
    minlocation              => $minlocation,
131
                maxlocation => $maxlocation,
137
    maxlocation              => $maxlocation,
132
                location=>$location,
138
    location                 => $location,
133
                ignoreissued=>$ignoreissued,
139
    ignoreissued             => $ignoreissued,
134
                branchcode=>$branchcode,      
140
    branchcode               => $branchcode,
135
                branch    => $branch,
141
    branch                   => $branch,
136
                offset => $offset,
142
    offset                   => $offset,
137
                pagesize => $pagesize,
143
    pagesize                 => $pagesize,
138
                datelastseen => $datelastseen,
144
    datelastseen             => $datelastseen,
139
                );
145
    compareinv2barcd         => $compareinv2barcd,
146
    notforloanlist           => $notforloanlist
147
);
148
149
my @notforloans;
150
if (defined $notforloanlist) {
151
    @notforloans = split(/,/, $notforloanlist);
152
}
153
154
155
140
my @brcditems;
156
my @brcditems;
141
if ($uploadbarcodes && length($uploadbarcodes)>0){
157
my $barcodelist;
142
    my $dbh=C4::Context->dbh;
158
my @errorloop;
143
    my $date = format_date_in_iso($input->param('setdate')) || C4::Dates->today('iso');
159
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
144
# 	warn "$date";
160
     my $dbh = C4::Context->dbh;
145
    my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?";
161
    my $date = format_date_in_iso( $input->param('setdate') ) || C4::Dates->today('iso');
162
163
    my $strsth  = "select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?";
146
    my $qonloan = $dbh->prepare($strsth);
164
    my $qonloan = $dbh->prepare($strsth);
147
    $strsth="select * from items where items.barcode =? and items.wthdrawn = 1";
165
    $strsth="select * from items where items.barcode =? and items.wthdrawn = 1";
148
    my $qwthdrawn = $dbh->prepare($strsth);
166
    my $qwthdrawn = $dbh->prepare($strsth);
149
    my @errorloop;
167
    my $count = 0;
150
    my $count=0;
168
  
151
    while (my $barcode=<$uploadbarcodes>){
169
    while ( my $barcode = <$uploadbarcodes> ) {
152
        $barcode =~ s/\r?\n$//;
170
        $barcode =~ s/\r?\n$//;
153
        if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){
171
        $barcodelist .= ($barcodelist) ? '|' . $barcode : $barcode;
154
            push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1};
172
        if ( $qwthdrawn->execute($barcode) && $qwthdrawn->rows ) {
155
        }else{
173
            push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
156
            my $item = GetItem('', $barcode);
174
        } else {
157
            if (defined $item && $item->{'itemnumber'}){
175
            my $item = GetItem( '', $barcode );
158
                ModItem({ datelastseen => $date }, undef, $item->{'itemnumber'});
176
            if ( defined $item && $item->{'itemnumber'} ) {
177
                ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} );
159
                push @brcditems, $item;
178
                push @brcditems, $item;
160
                $count++;
179
                $count++;
161
                $qonloan->execute($barcode);
180
                $qonloan->execute($barcode);
Lines 172-219 if ($uploadbarcodes && length($uploadbarcodes)>0){ Link Here
172
                push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1};
191
                push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1};
173
            }
192
            }
174
        }
193
        }
194
175
    }
195
    }
176
    $qonloan->finish;
196
    $qonloan->finish;
177
    $qwthdrawn->finish;
197
    $qwthdrawn->finish;
178
    $template->param(date=>format_date($date),Number=>$count);
198
    $template->param( date => format_date($date), Number => $count );
179
# 	$template->param(errorfile=>$errorfile) if ($errorfile);
199
    $template->param( errorloop => \@errorloop ) if (@errorloop);
180
    $template->param(errorloop=>\@errorloop) if (@errorloop);
200
201
202
}
203
$template->param(barcodelist => $barcodelist);
204
205
# now build the result list: inventoried items if requested, and mis-placed items -always-
206
my $inventorylist;
207
if ( $markseen or $op ) {
208
    # retrieve all items in this range.
209
    my $totalrecords;
210
        ($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton);
211
212
    $res = $inventorylist ;
181
}
213
}
182
#if we want to compare the results to a list of barcodes, or we have no barcode file
214
183
if ( ! ($uploadbarcodes && length($uploadbarcodes)>0 ) || ( $input->param('compareinv2barcd') eq 'on' && length($uploadbarcodes)>0) ) {
215
# set "missing" flags for all items with a datelastseen before the choosen datelastseen
184
    if ($markseen) {
216
foreach (@$res) {$_->{missingitem}=1 if C4::Dates->new($_->{datelastseen})->output('iso') lt C4::Dates->new($datelastseen)->output('iso')}
185
        foreach ($input->param) {
217
186
            /SEEN-(.+)/ and &ModDateLastSeen($1);
218
# removing missing items from loop if "Compare barcodes list to results" has not been checked
219
@$res = grep {!$_->{missingitem} == 1 } @$res if (!$input->param('compareinv2barcd'));
220
221
# insert "wrongplace" to all scanned items that are not supposed to be in this range
222
# note this list is always displayed, whatever the librarian has choosen for comparison
223
foreach my $temp (@brcditems) {
224
    next if $temp->{onloan}; # skip checked out items
225
226
    # If we have scanned items with a non-matching notforloan value
227
    if (none { $temp->{'notforloan'} eq $_ } @notforloans) {
228
        $temp->{'changestatus'} = 1;
229
        if ($input->param('CSVexport') eq 'on') {
230
            my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber});
231
            $temp->{title} = $biblio->{title};
232
            $temp->{author} = $biblio->{author};
233
            $temp->{datelastseen} = format_date($temp->{datelastseen});
187
        }
234
        }
235
        push @$res, $temp;
236
188
    }
237
    }
189
    if ($markseen or $op) {
238
190
        $res = GetItemsForInventory( $minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $branch, $offset, $pagesize, $staton );
239
    if (none { $temp->{barcode} eq $_->{barcode} && !$_->{onloan} } @$inventorylist) {
191
        $template->param(loop =>$res,
240
        $temp->{wrongplace}=1;
192
                        nextoffset => ($offset+$pagesize),
241
        if ($input->param('CSVexport') eq 'on') {
193
                        prevoffset => ($offset?$offset-$pagesize:0),
242
            my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber});
194
                        );
243
            $temp->{title} = $biblio->{title};
195
    }
244
            $temp->{author} = $biblio->{author};
196
    if ( defined $input->param('compareinv2barcd') && ( ( $input->param('compareinv2barcd') eq 'on' ) && ( scalar @brcditems != scalar @$res ) ) && length($uploadbarcodes) > 0 ){
245
            $temp->{datelastseen} = format_date($temp->{datelastseen});
197
        if ( scalar @brcditems > scalar @$res ){
198
            for my $brcditem (@brcditems) {
199
                if (! grep( $_->{barcode} =~ /$brcditem->{barcode}/ , @$res) ){
200
                    $brcditem->{notfoundkoha} = 1;
201
                    push @$res, $brcditem;
202
                }
203
            }
204
        } else {
205
            my @notfound;
206
            for my $item (@$res) {
207
                if ( ! grep( $_->{barcode} =~ /$item->{barcode}/ , @brcditems) ){
208
                    $item->{notfoundbarcode} = 1;
209
                    push @notfound, $item;
210
                }
211
            }
212
            $res = [@$res, @notfound];
213
        }
246
        }
247
        push @$res, $temp;
248
    }
249
}
250
251
# Finally, modifying datelastseen for remaining items
252
my $moddatecount = 0;
253
foreach (@$res) {
254
    unless ($_->{'missingitem'}) {
255
        ModDateLastSeen($_->{'itemnumber'}); 
256
        $moddatecount++;
214
    }
257
    }
215
}
258
}
216
259
260
# Removing items that don't have any problems from loop
261
@$res = grep { $_->{missingitem} || $_->{wrongplace} || $_->{changestatus} } @$res;
262
263
$template->param(
264
    moddatecount => $moddatecount,
265
    loop       => $res,
266
    nextoffset => ( $offset + $pagesize ),
267
    prevoffset => ( $offset ? $offset - $pagesize : 0 ),
268
    op         => $op
269
);
270
217
if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){
271
if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){
218
    eval {use Text::CSV};
272
    eval {use Text::CSV};
219
    my $csv = Text::CSV->new or
273
    my $csv = Text::CSV->new or
Lines 222-235 if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ Link Here
222
        -type       => 'text/csv',
276
        -type       => 'text/csv',
223
        -attachment => 'inventory.csv',
277
        -attachment => 'inventory.csv',
224
    );
278
    );
225
    for my $re (@$res){
279
280
    my $columns_def_hashref = C4::Reports::Guided::_get_column_defs();
281
    foreach my $key ( keys %$columns_def_hashref ) {
282
        my $initkey = $key;
283
        $key =~ s/[^\.]*\.//;
284
        $columns_def_hashref->{$initkey}=NormalizeString($columns_def_hashref->{$initkey});
285
        $columns_def_hashref->{$key} = $columns_def_hashref->{$initkey};
286
    }
287
288
    my @translated_keys;
289
    for my $key (qw / biblioitems.title    biblio.author 
290
                      items.barcode        items.itemnumber 
291
                      items.homebranch     items.location 
292
                      items.itemcallnumber items.notforloan 
293
                      items.itemlost       items.damaged
294
                      items.stocknumber
295
                      / ) {
296
       push @translated_keys, $columns_def_hashref->{$key};
297
    }
298
299
    $csv->combine(@translated_keys);
300
    print $csv->string, "\n";
301
302
    my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged stocknumber /; 
303
    for my $re (@$res) {
226
        my @line;
304
        my @line;
227
        for my $key (keys %$re) {
305
        for my $key (@keys) {
228
            push @line, $re->{$key};
306
            push @line, $re->{$key};
229
        }
307
        }
308
        push @line, "wrong place" if $re->{wrongplace};
309
        push @line, "missing item" if $re->{missingitem};
310
        push @line, "change item status" if $re->{changestatus};
230
        $csv->combine(@line);
311
        $csv->combine(@line);
231
        print $csv->string, "\n";
312
        print $csv->string, "\n";
232
    }
313
    }
314
    # Adding not found barcodes
315
    foreach my $error (@errorloop) {
316
	my @line;
317
	if ($error->{'ERR_BARCODE'}) {
318
		push @line, map { $_ eq 'barcode' ? $error->{'barcode'} : ''} @keys;
319
		push @line, "barcode not found";
320
		$csv->combine(@line);
321
		print $csv->string, "\n";
322
	}
323
    }
233
    exit;
324
    exit;
234
}
325
}
235
326
236
- 

Return to bug 7684