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

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

Return to bug 7684