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

(-)a/C4/Items.pm (-10 / +14 lines)
Lines 996-1007 sub GetItemsForInventory { Link Here
996
    my $dbh = C4::Context->dbh;
996
    my $dbh = C4::Context->dbh;
997
    my ( @bind_params, @where_strings );
997
    my ( @bind_params, @where_strings );
998
998
999
    my $query = <<'END_SQL';
999
    my $select_columns = q{
1000
SELECT SQL_CALC_FOUND_ROWS items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, biblio.frameworkcode, datelastseen, homebranch, location, notforloan, damaged, itemlost, stocknumber
1000
        SELECT items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, biblio.frameworkcode, datelastseen, homebranch, location, notforloan, damaged, itemlost, stocknumber
1001
FROM items
1001
    };
1002
  LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
1002
    my $select_count = q{SELECT COUNT(*)};
1003
  LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber
1003
    my $query = q{
1004
END_SQL
1004
        FROM items
1005
        LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber
1006
        LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber
1007
    };
1005
    if ($statushash){
1008
    if ($statushash){
1006
        for my $authvfield (keys %$statushash){
1009
        for my $authvfield (keys %$statushash){
1007
            if ( scalar @{$statushash->{$authvfield}} > 0 ){
1010
            if ( scalar @{$statushash->{$authvfield}} > 0 ){
Lines 1056-1073 END_SQL Link Here
1056
        $query .= join ' AND ', @where_strings;
1059
        $query .= join ' AND ', @where_strings;
1057
    }
1060
    }
1058
    $query .= ' ORDER BY items.cn_sort, itemcallnumber, title';
1061
    $query .= ' ORDER BY items.cn_sort, itemcallnumber, title';
1062
    my $count_query = $select_count . $query;
1059
    $query .= " LIMIT $offset, $size" if ($offset and $size);
1063
    $query .= " LIMIT $offset, $size" if ($offset and $size);
1064
    $query = $select_columns . $query;
1060
    my $sth = $dbh->prepare($query);
1065
    my $sth = $dbh->prepare($query);
1061
    $sth->execute( @bind_params );
1066
    $sth->execute( @bind_params );
1062
1067
1063
    my @results;
1068
    my @results = ();
1064
    my $tmpresults = $sth->fetchall_arrayref({});
1069
    my $tmpresults = $sth->fetchall_arrayref({});
1065
    $sth = $dbh->prepare("SELECT FOUND_ROWS()");
1070
    $sth = $dbh->prepare( $count_query );
1066
    $sth->execute();
1071
    $sth->execute( @bind_params );
1067
    my ($iTotalRecords) = $sth->fetchrow_array();
1072
    my ($iTotalRecords) = $sth->fetchrow_array();
1068
1073
1069
    foreach my $row (@$tmpresults) {
1074
    foreach my $row (@$tmpresults) {
1070
        $row->{datelastseen} = format_date( $row->{datelastseen} );
1071
1075
1072
        # Auth values
1076
        # Auth values
1073
        foreach (keys %$row) {
1077
        foreach (keys %$row) {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tt (-34 / +41 lines)
Lines 1-3 Link Here
1
[% USE KohaDates %]
1
[% INCLUDE 'doc-head-open.inc' %]
2
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Tools &rsaquo; Inventory</title>
3
<title>Koha &rsaquo; Tools &rsaquo; Inventory</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
[% INCLUDE 'doc-head-close.inc' %]
Lines 12-23 $(document).ready(function(){ Link Here
12
13
13
        inventorydt = $('#inventoryt').dataTable($.extend(true, {}, dataTablesDefaults, {
14
        inventorydt = $('#inventoryt').dataTable($.extend(true, {}, dataTablesDefaults, {
14
            'sPaginationType': 'full_numbers',
15
            'sPaginationType': 'full_numbers',
15
            "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0 ] } ]
16
            [% IF compareinv2barcd %]
17
                "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 1 ] } ]
18
            [% ELSE %]
19
                "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0 ] } ]
20
            [% END %]
16
        } ));
21
        } ));
17
22
18
23
19
    $("#continuewithoutmarkingbutton").click(function(){
24
        $("#continuewithoutmarkingbutton").click(function(){
20
                inventorydt.fnPageChange( 'next' );
25
            inventorydt.fnPageChange( 'next' );
21
            return false;
26
            return false;
22
        });
27
        });
23
28
Lines 47-53 $(document).ready(function(){ Link Here
47
        });
52
        });
48
53
49
54
50
51
    $(".checkall").click(function(){
55
    $(".checkall").click(function(){
52
            $(".checkboxed").checkCheckboxes();
56
            $(".checkboxed").checkCheckboxes();
53
            return false;
57
            return false;
Lines 56-71 $(document).ready(function(){ Link Here
56
            $(".checkboxed").unCheckCheckboxes();
60
            $(".checkboxed").unCheckCheckboxes();
57
            return false;
61
            return false;
58
        });
62
        });
59
[% IF ( offset ) %]$("#markseen").before("<input type=\"submit\" value=\"&lt;&lt; " + _("Mark seen and continue") + "\" id=\"markback\" /> ");[% END %]
60
[% IF ( nextoffset ) %]$("#markseen").after(" <input type=\"submit\" id=\"marknext\" value=\"" + _("Mark seen and continue") + " &gt;&gt;\" />");[% END %]
61
    $("#markback").click(function(){
62
        $(".checkboxed").find("input").filter("[name=offset]").attr("value","[% prevoffset %]");
63
        return true;
64
    });
65
    $("#marknext").click(function(){
66
        $(".checkboxed").find("input").filter("[name=offset]").attr("value","[% nextoffset %]");
67
        return true;
68
    });
69
    });
63
    });
70
//]]>
64
//]]>
71
</script>
65
</script>
Lines 82-88 $(document).ready(function(){ Link Here
82
    <div id="yui-main">
76
    <div id="yui-main">
83
    <div class="yui-b">
77
    <div class="yui-b">
84
    <h1>Inventory/Stocktaking</h1>
78
    <h1>Inventory/Stocktaking</h1>
85
    [% IF (moddatecount) %]<div class="dialog message">[% moddatecount %] items modified : datelastseen set to [% date %]</div>[% END %]
79
    [% IF (moddatecount) %]<div class="dialog message">[% moddatecount %] items modified : datelastseen set to [% date | $KohaDates %]</div>[% END %]
86
    [% IF (errorfile) %]<div class="dialog alert">[% errorfile %] can't be opened</div>[% END %]
80
    [% IF (errorfile) %]<div class="dialog alert">[% errorfile %] can't be opened</div>[% END %]
87
    [% FOREACH error IN errorloop %]
81
    [% FOREACH error IN errorloop %]
88
        <div class="dialog alert">
82
        <div class="dialog alert">
Lines 100-106 $(document).ready(function(){ Link Here
100
            <legend>Use a barcode file</legend>
94
            <legend>Use a barcode file</legend>
101
     <ol>
95
     <ol>
102
            <li><label for="uploadbarcodes">Barcode file: </label> <input type="file" id="uploadbarcodes" name="uploadbarcodes" /></li>
96
            <li><label for="uploadbarcodes">Barcode file: </label> <input type="file" id="uploadbarcodes" name="uploadbarcodes" /></li>
103
            <li><label for="setdate">Set inventory date to:</label> <input type="text" id="setdate" name="setdate" value="[% today %]" class="datepickerfrom" />
97
            <li><label for="setdate">Set inventory date to:</label> <input type="text" id="setdate" name="setdate" value="[% today | $KohaDates %]" class="datepickerfrom" />
104
            </li>
98
            </li>
105
          </ol>
99
          </ol>
106
        </fieldset>
100
        </fieldset>
Lines 109-118 $(document).ready(function(){ Link Here
109
        <ol><li>
103
        <ol><li>
110
        <label for="branch">Library: </label>
104
        <label for="branch">Library: </label>
111
            <input type="radio" name="branch" value="homebranch"> Home library</input>
105
            <input type="radio" name="branch" value="homebranch"> Home library</input>
112
            <input type="radio" name="branch" value="holdingbranch"> Current location</input>
106
            <input type="radio" name="branch" value="holdingbranch"> Current library</input>
113
        </li><li>
107
        </li><li>
114
        <label for="branchloop">Library: </label><select id="branchloop" name="branchcode" style="width:12em;">
108
        <label for="branchloop">Library: </label><select id="branchloop" name="branchcode" style="width:12em;">
115
            <option value="">All locations</option>
109
            <option value="">All libraries</option>
116
        [% FOREACH branchloo IN branchloop %]
110
        [% FOREACH branchloo IN branchloop %]
117
            [% IF ( branchloo.selected ) %]
111
            [% IF ( branchloo.selected ) %]
118
                <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
112
                <option value="[% branchloo.value %]" selected="selected">[% branchloo.branchname %]</option>
Lines 172-178 $(document).ready(function(){ Link Here
172
        [% END %]
166
        [% END %]
173
167
174
        <li><label for="datelastseen">Inventory date:</label>
168
        <li><label for="datelastseen">Inventory date:</label>
175
            <input type="text" id="datelastseen" name="datelastseen" value="[% datelastseen %]" class="datepickerfrom" />
169
            <input type="text" id="datelastseen" name="datelastseen" value="[% datelastseen | $KohaDates %]" class="datepickerfrom" />
176
        </li>
170
        </li>
177
        <li><label for="ignoreissued">Skip copies on loan: </label>
171
        <li><label for="ignoreissued">Skip copies on loan: </label>
178
            [% IF (ignoreissued) %]
172
            [% IF (ignoreissued) %]
Lines 204-218 $(document).ready(function(){ Link Here
204
    <input type="hidden" name="location" value="[% location %]" />
198
    <input type="hidden" name="location" value="[% location %]" />
205
    <input type="hidden" name="branchcode" value="[% branchcode %]" />
199
    <input type="hidden" name="branchcode" value="[% branchcode %]" />
206
    <input type="hidden" name="datelastseen" value="[% datelastseen %]" />
200
    <input type="hidden" name="datelastseen" value="[% datelastseen %]" />
207
    <input type="hidden" name="pagesize" value="[% pagesize %]" />
201
208
    <input type="hidden" name="offset" value="[% offset %]" />
202
    [% UNLESS compareinv2barcd %]
209
    <div><a href="#" class="checkall">[Select All]</a> <a href="#" class="clearall">[Clear All]</a></div>
203
      <div><a href="#" class="checkall">[Select all]</a> <a href="#" class="clearall">[Clear all]</a></div>
204
    [% END %]
205
210
    <table id="inventoryt">
206
    <table id="inventoryt">
211
    <thead>
207
    <thead>
212
        <tr>
208
        <tr>
213
            <th>Seen</th>
209
            [% UNLESS compareinv2barcd %]<th>Seen</th>[% END %]
214
            <th>Barcode</th>
210
            <th>Barcode</th>
215
            <th>Location</th>
211
            <th>Library</th>
216
            <th>Title</th>
212
            <th>Title</th>
217
            <th>Status</th>
213
            <th>Status</th>
218
            <th>Lost</th>
214
            <th>Lost</th>
Lines 224-232 $(document).ready(function(){ Link Here
224
    <tbody>
220
    <tbody>
225
    [% FOREACH result IN loop %]
221
    [% FOREACH result IN loop %]
226
        <tr>
222
        <tr>
227
            <td>
223
            [% UNLESS compareinv2barcd %]
228
            <input type="checkbox" name="SEEN-[% result.itemnumber %]" value="1" />
224
              <td>
229
            </td>
225
                <input type="checkbox" name="SEEN-[% result.itemnumber %]" value="1" />
226
              </td>
227
            [% END %]
230
            <td>
228
            <td>
231
            [% result.barcode | html %]
229
            [% result.barcode | html %]
232
            </td>
230
            </td>
Lines 246-266 $(document).ready(function(){ Link Here
246
            [% result.damaged | html %]
244
            [% result.damaged | html %]
247
            </td>
245
            </td>
248
            <td>
246
            <td>
249
            [% result.datelastseen | html %]
247
            [% result.datelastseen | html | $KohaDates%]
250
            </td>
248
            </td>
251
            <td>
249
            <td>
252
            [% IF (result.wrongplace) %]<p>Item should not have been scanned</p>[% ELSIF (result.missingitem) %]<p>Item missing</p>[% ELSIF (result.changestatus) %]<p>Change item status</p>[% END %]
250
            [% IF result.problem == 'wrongplace' %]
251
                <p>Item should not have been scanned</p>
252
            [% ELSIF result.problem == 'missingitem' %]
253
                <p>Item missing</p>
254
            [% ELSIF result.problem == 'changestatus' %]
255
                <p>Change item status</p>
256
            [% ELSIF result.problem == 'not_scanned' %]
257
                <p>Item should have been scanned</p>
258
            [% END %]
253
            </td>
259
            </td>
254
        </tr>
260
        </tr>
255
    [% END %]
261
    [% END %]
256
    </tbody>
262
    </tbody>
257
    </table>
263
    </table>
258
    <div class="spacer"></div>
264
    <div class="spacer"></div>
259
      <p style="display:block;"><span class="exportSelected"></span></p>
265
    [% UNLESS compareinv2barcd %]
260
    <div style="padding : .3em 0"><a href="#" class="checkall">[Select All]</a> <a href="#" class="clearall">[Clear All]</a></div>
266
      <div style="padding : .3em 0"><a href="#" class="checkall">[Select all]</a> <a href="#" class="clearall">[Clear all]</a></div>
261
     <input type="submit" id="markseenandquit" value="Mark seen and quit" />
267
      <input type="submit" id="markseenandquit" value="Mark seen and quit" />
262
     <input type="submit" value="Mark Seen and Continue &gt;&gt;" id="markseenandcontinuebutton" />
268
      <input type="submit" value="Mark Seen and Continue &gt;&gt;" id="markseenandcontinuebutton" />
263
     <input type="submit" value="Continue without Marking &gt;&gt;" id="continuewithoutmarkingbutton" class="submit" />
269
      <input type="submit" value="Continue without Marking &gt;&gt;" id="continuewithoutmarkingbutton" class="submit" />
270
    [% END %]
264
    </form>
271
    </form>
265
272
266
    </div>
273
    </div>
(-)a/tools/ajax-inventory.pl (-21 / +1 lines)
Lines 1-27 Link Here
1
#!/usr/bin/perl
1
#!/usr/bin/perl
2
#
3
2
4
use Modern::Perl;
3
use Modern::Perl;
5
6
use CGI;
4
use CGI;
7
use JSON;
8
9
use C4::Auth;
5
use C4::Auth;
10
use C4::Circulation qw/CanBookBeRenewed/;
6
use C4::Items qw( ModDateLastSeen );
11
use C4::Context;
12
use C4::Koha qw/getitemtypeimagelocation/;
13
use C4::Reserves qw/CheckReserves/;
14
use C4::Utils::DataTables;
15
use C4::Output;
16
use C4::Biblio;
17
use C4::Items;
18
use C4::Dates qw/format_date format_date_in_iso/;
19
use C4::Koha;
20
use C4::Branch;    # GetBranches
21
use C4::Reports::Guided;    #_get_column_defs
22
use C4::Charset;
23
use List::MoreUtils qw /none/;
24
25
7
26
my $input = new CGI;
8
my $input = new CGI;
27
9
Lines 38-43 foreach ( @seent ) { Link Here
38
    /SEEN-(.+)/ and &ModDateLastSeen($1);
20
    /SEEN-(.+)/ and &ModDateLastSeen($1);
39
}
21
}
40
22
41
42
print $input->header('application/json');
23
print $input->header('application/json');
43
(-)a/tools/inventory.pl (-79 / +88 lines)
Lines 31-43 use C4::Context; Link Here
31
use C4::Output;
31
use C4::Output;
32
use C4::Biblio;
32
use C4::Biblio;
33
use C4::Items;
33
use C4::Items;
34
use C4::Dates qw/format_date format_date_in_iso/;
35
use C4::Koha;
34
use C4::Koha;
36
use C4::Branch; # GetBranches
35
use C4::Branch; # GetBranches
37
use C4::Circulation;
36
use C4::Circulation;
38
use C4::Reports::Guided;    #_get_column_defs
37
use C4::Reports::Guided;    #_get_column_defs
39
use C4::Charset;
38
use C4::Charset;
40
use List::MoreUtils qw/none/;
39
use Koha::DateUtils;
40
use List::MoreUtils qw( none );
41
41
42
42
43
my $minlocation=$input->param('minlocation') || '';
43
my $minlocation=$input->param('minlocation') || '';
Lines 47-65 my $location=$input->param('location') || ''; Link Here
47
my $itemtype=$input->param('itemtype'); # FIXME note, template does not currently supply this
47
my $itemtype=$input->param('itemtype'); # FIXME note, template does not currently supply this
48
my $ignoreissued=$input->param('ignoreissued');
48
my $ignoreissued=$input->param('ignoreissued');
49
my $datelastseen = $input->param('datelastseen');
49
my $datelastseen = $input->param('datelastseen');
50
my $offset = $input->param('offset');
51
my $markseen = $input->param('markseen');
50
my $markseen = $input->param('markseen');
52
$offset=0 unless $offset;
53
my $pagesize = $input->param('pagesize');
54
$pagesize=50 unless $pagesize;
55
my $branchcode = $input->param('branchcode') || '';
51
my $branchcode = $input->param('branchcode') || '';
56
my $branch     = $input->param('branch');
52
my $branch     = $input->param('branch');
57
my $op         = $input->param('op');
53
my $op         = $input->param('op');
58
my $compareinv2barcd = $input->param('compareinv2barcd');
54
my $compareinv2barcd = $input->param('compareinv2barcd');
59
my $res;                                            #contains the results loop
60
55
61
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
56
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
62
    {   template_name   => "tools/inventory.tmpl",
57
    {   template_name   => "tools/inventory.tt",
63
        query           => $input,
58
        query           => $input,
64
        type            => "intranet",
59
        type            => "intranet",
65
        authnotrequired => 0,
60
        authnotrequired => 0,
Lines 134-148 $statussth =~ s, and $,,g; Link Here
134
$template->param(
129
$template->param(
135
    branchloop               => \@branch_loop,
130
    branchloop               => \@branch_loop,
136
    authorised_values        => \@authorised_value_list,
131
    authorised_values        => \@authorised_value_list,
137
    today                    => C4::Dates->today(),
132
    today                    => dt_from_string,
138
    minlocation              => $minlocation,
133
    minlocation              => $minlocation,
139
    maxlocation              => $maxlocation,
134
    maxlocation              => $maxlocation,
140
    location                 => $location,
135
    location                 => $location,
141
    ignoreissued             => $ignoreissued,
136
    ignoreissued             => $ignoreissued,
142
    branchcode               => $branchcode,
137
    branchcode               => $branchcode,
143
    branch                   => $branch,
138
    branch                   => $branch,
144
    offset                   => $offset,
145
    pagesize                 => $pagesize,
146
    datelastseen             => $datelastseen,
139
    datelastseen             => $datelastseen,
147
    compareinv2barcd         => $compareinv2barcd,
140
    compareinv2barcd         => $compareinv2barcd,
148
    notforloanlist           => $notforloanlist
141
    notforloanlist           => $notforloanlist
Lines 153-166 if (defined $notforloanlist) { Link Here
153
    @notforloans = split(/,/, $notforloanlist);
146
    @notforloans = split(/,/, $notforloanlist);
154
}
147
}
155
148
156
149
my @scanned_items;
157
158
my @brcditems;
159
my $barcodelist;
160
my @errorloop;
150
my @errorloop;
161
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
151
if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) {
162
    my $dbh = C4::Context->dbh;
152
    my $dbh = C4::Context->dbh;
163
    my $date = format_date_in_iso( $input->param('setdate') ) || C4::Dates->today('iso');
153
    my $date = dt_from_string( $input->param('setdate') );
154
    $date = output_pref( $date, 'iso' );
164
155
165
    my $strsth  = "select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?";
156
    my $strsth  = "select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?";
166
    my $qonloan = $dbh->prepare($strsth);
157
    my $qonloan = $dbh->prepare($strsth);
Lines 174-187 if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { Link Here
174
165
175
    for my $barcode ( @barcodes ){
166
    for my $barcode ( @barcodes ){
176
        $barcode =~ s/\r?\n$//;
167
        $barcode =~ s/\r?\n$//;
177
        $barcodelist .= ($barcodelist) ? '|' . $barcode : $barcode;
168
        next unless $barcode;
178
        if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) {
169
        if ( $qwithdrawn->execute($barcode) && $qwithdrawn->rows ) {
179
            push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
170
            push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 };
180
        } else {
171
        } else {
181
            my $item = GetItem( '', $barcode );
172
            my $item = GetItem( '', $barcode );
182
            if ( defined $item && $item->{'itemnumber'} ) {
173
            if ( defined $item && $item->{'itemnumber'} ) {
183
                ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} );
174
                ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} );
184
                push @brcditems, $item;
175
                push @scanned_items, $item;
185
                $count++;
176
                $count++;
186
                $qonloan->execute($barcode);
177
                $qonloan->execute($barcode);
187
                if ($qonloan->rows){
178
                if ($qonloan->rows){
Lines 199-294 if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { Link Here
199
        }
190
        }
200
191
201
    }
192
    }
193
<<<<<<< HEAD
202
    $qonloan->finish;
194
    $qonloan->finish;
203
    $qwithdrawn->finish;
195
    $qwithdrawn->finish;
204
    $template->param( date => format_date($date), Number => $count );
196
    $template->param( date => format_date($date), Number => $count );
205
    $template->param( errorloop => \@errorloop ) if (@errorloop);
197
    $template->param( errorloop => \@errorloop ) if (@errorloop);
206
198
199
=======
200
    $template->param( date => $date, Number => $count );
201
    $template->param( errorloop => \@errorloop ) if (@errorloop);
202
>>>>>>> Bug 7684: QA Followup and bugfixes
207
}
203
}
208
$template->param(barcodelist => $barcodelist);
209
204
210
# now build the result list: inventoried items if requested, and mis-placed items -always-
205
# now build the result list: inventoried items if requested, and mis-placed items -always-
211
my $inventorylist;
206
my $inventorylist;
207
my @items_with_problems;
212
if ( $markseen or $op ) {
208
if ( $markseen or $op ) {
213
    # retrieve all items in this range.
209
    # retrieve all items in this range.
214
    my $totalrecords;
210
    my $totalrecords;
215
    ($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton);
211
    ($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton);
212
}
216
213
217
    # Real copy
214
# If "compare barcodes list to results" has been checked, we want to alert for missing items
218
    my @res_copy;
215
if ( $compareinv2barcd ) {
219
    foreach (@$inventorylist) {
216
    # set "missing" flags for all items with a datelastseen (dls) before the choosen datelastseen (cdls)
220
        push @res_copy, $_;
217
    my $dls = output_pref( dt_from_string( $datelastseen ), 'iso' );
218
    foreach my $item ( @$inventorylist ) {
219
        my $cdls = output_pref( dt_from_string( $_->{datelastseen} ), 'iso' );
220
        if ( $cdls lt $dls ) {
221
            $item->{problem} = 'missingitem';
222
            # We have to push a copy of the item, not the reference
223
            push @items_with_problems, { %$item };
224
        }
221
    }
225
    }
222
    $res = \@res_copy;
223
}
226
}
224
227
225
# set "missing" flags for all items with a datelastseen before the choosen datelastseen
226
foreach (@$res) { $_->{missingitem}=1 if C4::Dates->new($_->{datelastseen})->output('iso') lt C4::Dates->new($datelastseen)->output('iso'); }
227
228
228
# removing missing items from loop if "Compare barcodes list to results" has not been checked
229
@$res = grep {!$_->{missingitem} == 1 } @$res if (!$input->param('compareinv2barcd'));
230
229
231
# insert "wrongplace" to all scanned items that are not supposed to be in this range
230
# insert "wrongplace" to all scanned items that are not supposed to be in this range
232
# note this list is always displayed, whatever the librarian has choosen for comparison
231
# note this list is always displayed, whatever the librarian has choosen for comparison
233
foreach my $temp (@brcditems) {
232
my $moddatecount = 0;
233
foreach my $item ( @scanned_items ) {
234
234
235
  # Saving notforloan code before it's replaced by it's authorised value for later comparison
235
  # Saving notforloan code before it's replaced by it's authorised value for later comparison
236
  $temp->{'notforloancode'} = $temp->{'notforloan'};
236
  $item->{notforloancode} = $item->{notforloan};
237
237
238
  # Populating with authorised values
238
  # Populating with authorised values
239
  foreach (keys %$temp) {
239
  foreach my $field ( keys %$item ) {
240
        # If the koha field is mapped to a marc field
240
        # If the koha field is mapped to a marc field
241
        my $fc = $temp->{'frameworkcode'} || '';
241
        my $fc = $item->{'frameworkcode'} || '';
242
        my ($f, $sf) = GetMarcFromKohaField("items.$_", $fc);
242
        my ($f, $sf) = GetMarcFromKohaField("items.$field", $fc);
243
        if ($f and $sf) {
243
        if ($f and $sf) {
244
            # We replace the code with it's description
244
            # We replace the code with it's description
245
            my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $fc);
245
            my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $fc);
246
            if ($authvals and defined $temp->{$_} and defined $authvals->{$temp->{$_}}) {
246
            if ($authvals and defined $item->{$field} and defined $authvals->{$item->{$field}}) {
247
              $temp->{$_} = $authvals->{$temp->{$_}};
247
              $item->{$field} = $authvals->{$item->{$field}};
248
            }
248
            }
249
        }
249
        }
250
    }
250
    }
251
251
252
    next if $temp->{onloan}; # skip checked out items
252
    next if $item->{onloan}; # skip checked out items
253
253
254
    # If we have scanned items with a non-matching notforloan value
254
    # If we have scanned items with a non-matching notforloan value
255
    if (none { $temp->{'notforloancode'} eq $_ } @notforloans) {
255
    if (none { $item->{'notforloancode'} eq $_ } @notforloans) {
256
        $temp->{'changestatus'} = 1;
256
        $item->{problem} = 'changestatus';
257
        my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber});
257
        push @items_with_problems, { %$item };
258
        $temp->{title} = $biblio->{title};
259
        $temp->{author} = $biblio->{author};
260
        $temp->{datelastseen} = format_date($temp->{datelastseen});
261
        push @$res, $temp;
262
263
    }
258
    }
264
    if (none { $temp->{barcode} eq $_->{barcode} && !$_->{'onloan'} } @$inventorylist) {
259
    if (none { $item->{barcode} eq $_->{barcode} && !$_->{'onloan'} } @$inventorylist) {
265
        my $temp2 = { %$temp };
260
        $item->{problem} = 'wrongplace';
266
        $temp2->{wrongplace}=1;
261
        push @items_with_problems, { %$item };
267
        my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber});
268
        $temp2->{title} = $biblio->{title};
269
        $temp2->{author} = $biblio->{author};
270
        $temp2->{datelastseen} = format_date($temp->{datelastseen});
271
        push @$res, $temp2;
272
    }
262
    }
263
264
    # Modify date last seen for scanned items
265
    ModDateLastSeen($_->{'itemnumber'});
266
    $moddatecount++;
273
}
267
}
274
268
275
# Finally, modifying datelastseen for remaining items
269
if ( $compareinv2barcd ) {
276
my $moddatecount = 0;
270
    my @scanned_barcodes = map {$_->{barcode}} @scanned_items;
277
foreach (@$res) {
271
    for my $should_be_scanned ( @$inventorylist ) {
278
    unless ($_->{'missingitem'}) {
272
        my $barcode = $should_be_scanned->{barcode};
279
        ModDateLastSeen($_->{'itemnumber'});
273
        unless ( grep /^$barcode$/, @scanned_barcodes ) {
280
        $moddatecount++;
274
            $should_be_scanned->{problem} = 'not_scanned';
275
            push @items_with_problems, { %$should_be_scanned };
276
        }
281
    }
277
    }
282
}
278
}
283
279
284
# Removing items that don't have any problems from loop
280
for my $item ( @items_with_problems ) {
285
@$res = grep { $_->{missingitem} || $_->{wrongplace} || $_->{changestatus} } @$res;
281
    my $biblio = C4::Biblio::GetBiblioData($item->{biblionumber});
282
    $item->{title} = $biblio->{title};
283
    $item->{author} = $biblio->{author};
284
}
285
286
# If a barcode file is given, we want to show problems, else all items
287
my @results;
288
@results = $uploadbarcodes
289
            ? @items_with_problems
290
            : $op
291
                ? @$inventorylist
292
                : ();
286
293
287
$template->param(
294
$template->param(
288
    moddatecount => $moddatecount,
295
    moddatecount => $moddatecount,
289
    loop       => $res,
296
    loop       => \@results,
290
    nextoffset => ( $offset + $pagesize ),
291
    prevoffset => ( $offset ? $offset - $pagesize : 0 ),
292
    op         => $op
297
    op         => $op
293
);
298
);
294
299
Lines 319-353 if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ Link Here
319
                      / ) {
324
                      / ) {
320
       push @translated_keys, $columns_def_hashref->{$key};
325
       push @translated_keys, $columns_def_hashref->{$key};
321
    }
326
    }
327
    push @translated_keys, 'problem' if $uploadbarcodes;
322
328
323
    $csv->combine(@translated_keys);
329
    $csv->combine(@translated_keys);
324
    print $csv->string, "\n";
330
    print $csv->string, "\n";
325
331
326
    my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged stocknumber /;
332
    my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged stocknumber /;
327
    for my $re (@$res) {
333
    for my $item ( @results ) {
328
        my @line;
334
        my @line;
329
        for my $key (@keys) {
335
        for my $key (@keys) {
330
            push @line, $re->{$key};
336
            push @line, $item->{$key};
331
        }
337
        }
332
        if ($re->{wrongplace}) {
338
        if ( defined $item->{problem} ) {
333
            push @line, "wrong place";
339
            if ( $item->{problem} eq 'wrongplace' ) {
334
        } elsif ($re->{missingitem}) {
340
                push @line, "wrong place";
335
            push @line, "missing item";
341
            } elsif ( $item->{problem} eq 'missingitem' ) {
336
        } elsif ($re->{changestatus}) {
342
                push @line, "missing item";
337
            push @line, "change item status";
343
            } elsif ( $item->{problem} eq 'changestatus' ) {
344
                push @line, "change item status";
345
            } elsif ($item->{problem} eq 'not_scanned' ) {
346
                push @line, "item not scanned";
347
            }
338
        }
348
        }
339
        $csv->combine(@line);
349
        $csv->combine(@line);
340
        print $csv->string, "\n";
350
        print $csv->string, "\n";
341
    }
351
    }
342
    # Adding not found barcodes
352
    # Adding not found barcodes
343
    foreach my $error (@errorloop) {
353
    foreach my $error (@errorloop) {
344
    my @line;
354
        my @line;
345
    if ($error->{'ERR_BARCODE'}) {
355
        if ($error->{'ERR_BARCODE'}) {
346
        push @line, map { $_ eq 'barcode' ? $error->{'barcode'} : ''} @keys;
356
            push @line, map { $_ eq 'barcode' ? $error->{'barcode'} : ''} @keys;
347
        push @line, "barcode not found";
357
            push @line, "barcode not found";
348
        $csv->combine(@line);
358
            $csv->combine(@line);
349
        print $csv->string, "\n";
359
            print $csv->string, "\n";
350
    }
360
        }
351
    }
361
    }
352
    exit;
362
    exit;
353
}
363
}
354
- 

Return to bug 7684