Bugzilla – Attachment 11843 Details for
Bug 7684
inventory : datatable fix actions etc.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7684: multiple fixes for inventory
Bug-7684-multiple-fixes-for-inventory.patch (text/plain), 32.47 KB, created by
Matthias Meusburger
on 2012-08-27 13:45:03 UTC
(
hide
)
Description:
Bug 7684: multiple fixes for inventory
Filename:
MIME Type:
Creator:
Matthias Meusburger
Created:
2012-08-27 13:45:03 UTC
Size:
32.47 KB
patch
obsolete
>From 3b00e7026b7b6f8877de8ba89480150a6a5385df Mon Sep 17 00:00:00 2001 >From: Matthias Meusburger <matthias.meusburger@biblibre.com> >Date: Thu, 23 Aug 2012 16:02:52 +0200 >Subject: [PATCH] Bug 7684: multiple fixes for inventory > >* when a file was uploaded and the comparison with catalogue range > requested, the comparison was wrong: the logic was wrong >* items that were not supposed to be scanned (ie: supposed to be on another shelf) > didn't had the author and title, it was hard to retrieve them on the shelved >* some useful fields were missing, like homebranch, location, status >* the CSV export contained all the item information. It should contain the same > informations as the screen > >Behaviour now: > * scan a list of barcode & select a range of location > * if a barcode has been scanned and should not be (mis placed item), the information is displayed > * if you choose "compare barcodes list to result option", the resulting list contains all items that have been scanned and those that were supposed to be. Any item not in both list appears with a specific message on the last column >--- > C4/Auth.pm | 2 +- > C4/Items.pm | 41 ++- > .../prog/en/modules/tools/inventory.tmpl | 296 ++++++++++++++++++++ > tools/ajax-inventory.pl | 43 +++ > tools/inventory.pl | 243 +++++++++++----- > 5 files changed, 536 insertions(+), 89 deletions(-) > create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tmpl > create mode 100755 tools/ajax-inventory.pl > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index f9b15ef..459260e 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -1091,7 +1091,7 @@ sub check_api_auth { > unless ($query->param('userid')) { > $sessionID = $query->cookie("CGISESSID"); > } >- if ($sessionID && not ($cas && $query->param('PT')) ) { >+ if ( $sessionID && not ($cas && $query->param('PT')) ) { > my $session = get_session($sessionID); > C4::Context->_new_userenv($sessionID); > if ($session) { >diff --git a/C4/Items.pm b/C4/Items.pm >index a9c0a16..0ffc2f9 100644 >--- a/C4/Items.pm >+++ b/C4/Items.pm >@@ -968,9 +968,11 @@ sub GetLostItems { > > =head2 GetItemsForInventory > >- $itemlist = GetItemsForInventory($minlocation, $maxlocation, >- $location, $itemtype $datelastseen, $branch, >- $offset, $size, $statushash); >+=over 4 >+ >+($itemlist, $iTotalRecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $offset, $size, $statushash); >+ >+=back > > Retrieve a list of title/authors/barcode/callnumber, for biblio inventory. > >@@ -983,6 +985,8 @@ the datelastseen can be used to specify that you want to see items not seen sinc > offset & size can be used to retrieve only a part of the whole listing (defaut behaviour) > $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. > >+$iTotalRecords is the number of rows that would have been returned without the $offset, $size limit clause >+ > =cut > > sub GetItemsForInventory { >@@ -991,7 +995,7 @@ sub GetItemsForInventory { > my ( @bind_params, @where_strings ); > > my $query = <<'END_SQL'; >-SELECT items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, datelastseen >+SELECT SQL_CALC_FOUND_ROWS items.itemnumber, barcode, itemcallnumber, title, author, biblio.biblionumber, biblio.frameworkcode, datelastseen, homebranch, location, notforloan, damaged, itemlost, stocknumber > FROM items > LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber > LEFT JOIN biblioitems on items.biblionumber = biblioitems.biblionumber >@@ -1050,20 +1054,33 @@ END_SQL > $query .= join ' AND ', @where_strings; > } > $query .= ' ORDER BY items.cn_sort, itemcallnumber, title'; >+ $query .= " LIMIT $offset, $size" if ($offset and $size); > my $sth = $dbh->prepare($query); > $sth->execute( @bind_params ); > > my @results; >- $size--; >- while ( my $row = $sth->fetchrow_hashref ) { >- $offset-- if ($offset); >- $row->{datelastseen}=format_date($row->{datelastseen}); >- if ( ( !$offset ) && $size ) { >- push @results, $row; >- $size--; >+ my $tmpresults = $sth->fetchall_arrayref({}); >+ $sth = $dbh->prepare("SELECT FOUND_ROWS()"); >+ $sth->execute(); >+ my ($iTotalRecords) = $sth->fetchrow_array(); >+ >+ foreach my $row (@$tmpresults) { >+ $row->{datelastseen} = format_date( $row->{datelastseen} ); >+ >+ # Auth values >+ foreach (keys %$row) { >+ # If the koha field is mapped to a marc field >+ my ($f, $sf) = GetMarcFromKohaField("items.$_", $row->{'frameworkcode'}); >+ if ($f and $sf) { >+ # We replace the code with it's description >+ my $authvals = C4::Koha::GetKohaAuthorisedValuesFromField($f, $sf, $row->{'frameworkcode'}); >+ $row->{$_} = $authvals->{$row->{$_}} if $authvals->{$row->{$_}}; >+ } > } >+ push @results, $row; > } >- return \@results; >+ >+ return (\@results, $iTotalRecords); > } > > =head2 GetItemsCount >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tmpl >new file mode 100644 >index 0000000..e5ecbf7 >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/inventory.tmpl >@@ -0,0 +1,296 @@ >+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" --> >+<title>Koha › Tools › Inventory</title> >+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" --> >+<link rel="stylesheet" type="text/css" href="<!-- TMPL_VAR NAME="themelang" -->/css/datatables.css" /> >+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.dataTables.min.js"></script> >+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/js/datatables.js"></script> >+<!-- TMPL_INCLUDE NAME="calendar.inc" --> >+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.checkboxes.min.js"></script> >+<script type="text/javascript"> >+//<![CDATA[ >+$(document).ready(function(){ >+ >+ inventorydt = $('#inventoryt').dataTable({ >+ 'sPaginationType': 'full_numbers', >+ "aoColumnDefs": [ { "bSortable": false, "aTargets": [ 0 ] } ] >+ } ); >+ >+ >+ $("#continuewithoutmarkingbutton").click(function(){ >+ inventorydt.fnPageChange( 'next' ); >+ return false; >+ }); >+ >+ $("#markseenandcontinuebutton").click(function(){ >+ var param = ''; >+ $("input:checked").each(function() { >+ param += "|" + $(this).attr('name'); >+ }); >+ $.post('/cgi-bin/koha/tools/ajax-inventory.pl', { seen: param }); >+ inventorydt.fnDraw(); >+ inventorydt.fnPageChange( 'next' ); >+ return false; >+ }); >+ >+ $("#markseenandquit").click(function(){ >+ var param = ''; >+ $("input:checked").each(function() { >+ param += "|" + $(this).attr('name'); >+ }); >+ $.ajax({ >+ type: 'POST', >+ url: '/cgi-bin/koha/tools/ajax-inventory.pl', >+ data: { seen: param}, >+ async: false >+ }); >+ document.location.href = '/cgi-bin/koha/tools/inventory.pl'; >+ return false; >+ }); >+ >+ >+ >+ $(".checkall").click(function(){ >+ $(".checkboxed").checkCheckboxes(); >+ return false; >+ }); >+ $(".clearall").click(function(){ >+ $(".checkboxed").unCheckCheckboxes(); >+ return false; >+ }); >+ $("#markback").click(function(){ >+ $(".checkboxed").find("input").filter("[name=offset]").attr("value","<!-- TMPL_VAR NAME="prevoffset" -->"); >+ return true; >+ }); >+ $("#marknext").click(function(){ >+ $(".checkboxed").find("input").filter("[name=offset]").attr("value","<!-- TMPL_VAR NAME="nextoffset" -->"); >+ return true; >+ }); >+ }); >+//]]> >+</script> >+</head> >+<body> >+<!-- TMPL_INCLUDE NAME="header.inc" --> >+<!-- TMPL_INCLUDE NAME="cat-search.inc"--> >+ >+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/tools/tools-home.pl">Tools</a> › <!-- TMPL_IF NAME="loop" --><a href="/cgi-bin/koha/tools/inventory.pl">Inventory</a> › Results<!-- TMPL_ELSE -->Inventory<!-- /TMPL_IF --></div> >+ >+<div id="doc3" class="yui-t2"> >+ >+ <div id="bd"> >+ <div id="yui-main"> >+ <div class="yui-b"> >+ <h1>Inventory/Stocktaking</h1> >+ <!--TMPL_IF Name="moddatecount" --><div class="dialog message"><!--TMPL_VAR Name="moddatecount"--> items modified : datelastseen set to <!--TMPL_VAR Name="date"--></div><!-- /TMPL_IF--> >+ <!--TMPL_IF Name="errorfile" --><div class="dialog alert"><!--TMPL_VAR Name="errorfile"--> can't be opened</div><!-- /TMPL_IF--> >+ <!--TMPL_LOOP Name="errorloop"--> >+ <div class="dialog alert"> >+ <!--TMPL_VAR Name="barcode"--> >+ <!--TMPL_IF Name="ERR_BARCODE"-->: barcode not found<!--/TMPL_IF--> >+ <!--TMPL_IF Name="ERR_WTHDRAWN"-->: item withdrawn<!--/TMPL_IF--> >+ <!--TMPL_IF Name="ERR_ONLOAN_RET"-->: item was on loan. It was returned before marked as seen<!--/TMPL_IF--> >+ <!--TMPL_IF Name="ERR_ONLOAN_NOT_RET"-->: item was on loan. couldn't be returned.<!--/TMPL_IF--> >+ </div> >+ <!-- /TMPL_LOOP--> >+ <!-- TMPL_UNLESS name="op" --> >+ <div class="yui-g"> >+ <form method="post" action="/cgi-bin/koha/tools/inventory.pl" enctype="multipart/form-data"> >+ <fieldset class="rows"> >+ <legend>Use a barcode file</legend> >+ <ol> >+ <li><label for="uploadbarcodes">Barcode file: </label> <input type="file" id="uploadbarcodes" name="uploadbarcodes" /></li> >+ <li><label for="setdate">Set inventory date to:</label> <input type="text" id="setdate" name="setdate" value="<!-- TMPL_VAR name="today" -->" /> >+ <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="setdate_button" alt="Show Calendar" /> >+ <script type="text/javascript"> >+ Calendar.setup( >+ { >+ inputField : "setdate", >+ ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->", >+ button : "setdate_button" >+ } >+ ); >+ </script> >+ <div class="hint"><!-- TMPL_INCLUDE NAME="date-format.inc" --></div> >+ </li> >+ </ol> >+ </fieldset> >+ <fieldset class="rows"> >+ <legend>Select items you want to check</legend> >+ <ol><li> >+ <label for="branch">Branch</label> >+ <input type="radio" name="branch" value="homebranch">Home Branch</input> >+ <input type="radio" name="branch" value="holdingbranch">Holding Branch</input> >+ </li><li> >+ <label for="branchloop">Library</label><select id="branchloop" name="branchcode" style="width:12em;"> >+ <option value="">All Locations</option> >+ <!-- TMPL_LOOP NAME="branchloop" --> >+ <!-- TMPL_IF name="selected" --> >+ <option value="<!-- TMPL_VAR NAME="value" -->" selected="selected"><!-- TMPL_VAR NAME="branchname" --></option> >+ <!-- TMPL_ELSE --> >+ <option value="<!-- TMPL_VAR NAME="value" -->"><!-- TMPL_VAR NAME="branchname" --></option> >+ <!-- /TMPL_IF --> >+ <!-- /TMPL_LOOP --> >+ </select> >+ </li> >+ <!-- TMPL_IF NAME="authorised_values" --> >+ <li> >+ <label for="locationloop">Item Location (items.location) is</label> >+ <select id="locationloop" name="location"> >+ <option value="">Filter location</option> >+ <!-- TMPL_LOOP NAME="authorised_values" --> >+ <!-- TMPL_IF name="selected" --> >+ <option value="<!-- TMPL_VAR NAME="authorised_value" -->" selected="selected"><!-- TMPL_VAR NAME="lib" --></option> >+ <!-- TMPL_ELSE --> >+ <option value="<!-- TMPL_VAR NAME="authorised_value" -->"><!-- TMPL_VAR NAME="lib" --></option> >+ <!-- /TMPL_IF --> >+ <!-- /TMPL_LOOP --> >+ </select> </li> >+ <!-- /TMPL_IF --> >+ <li> >+ <label for="minlocation">Item callnumber between: </label> >+ <input type="text" name="minlocation" id="minlocation" value="<!-- TMPL_VAR NAME="minlocation" -->" /> (items.itemcallnumber) </li> >+ <li><label for="maxlocation">...and: </label> >+ <input type="text" name="maxlocation" id="maxlocation" value="<!-- TMPL_VAR NAME="maxlocation" -->" /> >+ </li> >+ <!-- TMPL_IF name="statuses" --> >+ </ol> >+ </fieldset> >+ <fieldset class="rows"> >+ <legend>Item statuses:</legend> >+ <div name="statuses" style="display: block;"> >+ <!-- TMPL_LOOP name="statuses" --> >+ <!-- TMPL_IF name="values" --> >+ <fieldset style="float: left; padding: 5px; margin: 5px;text-align:right"> >+ <legend><!-- TMPL_VAR name="fieldname" --></legend> >+ <ul id="statuses-<!-- TMPL_VAR name="fieldname" -->" style="display: inline;"> >+ <!-- TMPL_LOOP name="values" --> >+ <!-- TMPL_IF NAME="lib" --><li> >+ <label for="<!-- TMPL_VAR name="id" -->"> >+ <!-- TMPL_VAR name="lib" --> >+ </label> >+ <input type="checkbox" name="status-<!-- TMPL_VAR name="fieldname" -->-<!-- TMPL_VAR name="authorised_value" -->" id="<!-- TMPL_VAR name="authorised_value" -->" /> >+ </li><!-- /TMPL_IF --> >+ <!-- /TMPL_LOOP --> >+ </ul> >+ </fieldset> >+ <!-- /TMPL_IF --> >+ <!-- /TMPL_LOOP --> >+ </div> >+ </fieldset> >+ <fieldset class="rows"> >+ <ol> >+ <!-- /TMPL_IF --> >+ >+ <li><label for="datelastseen">Inventory date:</label> >+ <input type="text" id="datelastseen" name="datelastseen" value="<!-- TMPL_VAR NAME="datelastseen" -->" /> >+ <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="datelastseen_button" alt="Show Calendar" /> >+ <script type="text/javascript"> >+ Calendar.setup( >+ { >+ inputField : "datelastseen", >+ ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->", >+ button : "datelastseen_button" >+ } >+ ); >+ </script> >+ <div class="hint"><!-- TMPL_INCLUDE NAME="date-format.inc" --></div> >+ </li> >+ <li><label for="ignoreissued">Skip copies on loan: </label> >+ <!-- TMPL_IF NAME="ignoreissued" --> >+ <input type="checkbox" id="ignoreissued" name="ignoreissued" checked="checked" /></li> >+ <!-- TMPL_ELSE --> >+ <input type="checkbox" id="ignoreissued" name="ignoreissued" /></li> >+ <!-- /TMPL_IF --> >+ <li> >+ <label for="CSVexport">Export to csv file</label> >+ <input type="checkbox" name="CSVexport" id="CSVexport" /> >+ </li> >+ <li> >+ <label for="compareinv2barcd">Compare barcodes list to results</label> >+ <input type="checkbox" name="compareinv2barcd" id="compareinv2barcd" /> >+ </li> >+ </ol> >+ </fieldset> >+ <input type="hidden" name="op" value="do_it" /> >+ <fieldset class="action"><input type="submit" value="Submit" class="button" /></fieldset> >+ </form> >+ </div> >+ </div> >+ <!--/TMPL_UNLESS--> >+ <!-- TMPL_IF NAME="op" --> >+ <form method="post" action="/cgi-bin/koha/tools/inventory.pl" class="checkboxed"> >+ <input type="hidden" name="markseen" value="1" /> >+ <input type="hidden" name="minlocation" value="<!-- TMPL_VAR NAME="minlocation" -->" /> >+ <input type="hidden" name="maxlocation" value="<!-- TMPL_VAR NAME="maxlocation" -->" /> >+ <input type="hidden" name="location" value="<!-- TMPL_VAR NAME="location" -->" /> >+ <input type="hidden" name="branchcode" value="<!-- TMPL_VAR NAME="branchcode" -->" /> >+ <input type="hidden" name="datelastseen" value="<!-- TMPL_VAR NAME="datelastseen" -->" /> >+ <input type="hidden" name="pagesize" value="<!-- TMPL_VAR NAME="pagesize" -->" /> >+ <input type="hidden" name="offset" value="<!-- TMPL_VAR NAME="offset" -->" /> >+ <div style="padding : .3em 0"><a href="#" class="checkall">[Select All]</a> <a href="#" class="clearall">[Clear All]</a></div> >+ <table id="inventoryt" class="display"> >+ <thead> >+ <tr> >+ <th>Seen</th> >+ <th>Barcode</th> >+ <th>Location</th> >+ <th>Title</th> >+ <th>Status</th> >+ <th>Lost</th> >+ <th>Damaged</th> >+ <th>Unseen since</th> >+ <th>Problems</th> >+ </tr> >+ </thead> >+ <tbody> >+ <!-- TMPL_LOOP NAME="loop" --> >+ <tr> >+ <td> >+ <input type="checkbox" name="SEEN-<!-- TMPL_VAR NAME="itemnumber" -->" value="1" /> >+ </td> >+ <td> >+ <!-- TMPL_VAR NAME="barcode" ESCAPE="html" --> >+ </td> >+ <td> >+ <!-- TMPL_VAR NAME="homebranch" ESCAPE="html" --> <!-- TMPL_VAR name="location" ESCAPE="HTML" --> [<!-- TMPL_VAR NAME="itemcallnumber" ESCAPE="HTML" -->] >+ </td> >+ <td> >+ <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> >+ </td> >+ <td> >+ <!-- TMPL_VAR NAME="notforloan" ESCAPE="html" --> >+ </td> >+ <td> >+ <!-- TMPL_VAR NAME="itemlost" ESCAPE="html" --> >+ </td> >+ <td> >+ <!-- TMPL_VAR NAME="damaged" ESCAPE="html" --> >+ </td> >+ <td> >+ <!-- TMPL_VAR NAME="datelastseen" ESCAPE="html" --> >+ </td> >+ <td> >+ <!-- 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 --> >+ </td> >+ </tr> >+ <!-- /TMPL_LOOP --> >+ </tbody> >+ </table> >+ <div class="spacer"></div> >+ <p style="display:block;"><span class="exportSelected"></span></p> >+ <div style="padding : .3em 0"><a href="#" class="checkall">[Select All]</a> <a href="#" class="clearall">[Clear All]</a></div> >+ <input type="submit" id="markseenandquit" value="Mark seen and quit" /> >+ <input type="submit" value="Mark Seen and Continue >>" id="markseenandcontinuebutton" /> >+ <input type="submit" value="Continue without Marking >>" id="continuewithoutmarkingbutton" class="submit" /> >+ </form> >+ >+ </div> >+ >+ <!-- /TMPL_IF --> >+ <!-- /TMPL_IF --> >+</div> >+<div class="yui-b"> >+<!-- TMPL_INCLUDE NAME="tools-menu.inc" --> >+</div> >+</div> >+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" --> >diff --git a/tools/ajax-inventory.pl b/tools/ajax-inventory.pl >new file mode 100755 >index 0000000..24739b9 >--- /dev/null >+++ b/tools/ajax-inventory.pl >@@ -0,0 +1,43 @@ >+#!/usr/bin/perl >+# >+ >+use Modern::Perl; >+ >+use CGI; >+use JSON; >+ >+use C4::Auth; >+use C4::Circulation qw/CanBookBeRenewed/; >+use C4::Context; >+use C4::Koha qw/getitemtypeimagelocation/; >+use C4::Reserves qw/CheckReserves/; >+use C4::Utils::DataTables; >+use C4::Output; >+use C4::Biblio; >+use C4::Items; >+use C4::Dates qw/format_date format_date_in_iso/; >+use C4::Koha; >+use C4::Branch; # GetBranches >+use C4::Reports::Guided; #_get_column_defs >+use C4::Charset; >+use List::MoreUtils qw /none/; >+ >+ >+my $input = new CGI; >+ >+# Authentication >+my ($status, $cookie, $sessionId) = C4::Auth::check_api_auth($input, { tools => 'inventory' }); >+exit unless ($status eq "ok"); >+ >+ >+my $seen = $input->param('seen'); >+my @seent = split(/\|/, $seen); >+ >+# mark seen if applicable (ie: coming form mark seen checkboxes) >+foreach ( @seent ) { >+ /SEEN-(.+)/ and &ModDateLastSeen($1); >+} >+ >+ >+print $input->header('application/json'); >+ >diff --git a/tools/inventory.pl b/tools/inventory.pl >index 5e7b198..d3b4250 100755 >--- a/tools/inventory.pl >+++ b/tools/inventory.pl >@@ -35,6 +35,9 @@ use C4::Dates qw/format_date format_date_in_iso/; > use C4::Koha; > use C4::Branch; # GetBranches > use C4::Circulation; >+use C4::Reports::Guided; #_get_column_defs >+use C4::Charset; >+ > > my $minlocation=$input->param('minlocation') || ''; > my $maxlocation=$input->param('maxlocation'); >@@ -50,19 +53,20 @@ my $pagesize = $input->param('pagesize'); > $pagesize=50 unless $pagesize; > my $branchcode = $input->param('branchcode') || ''; > my $branch = $input->param('branch'); >-my $op = $input->param('op'); >-my $res; #contains the results loop >-# warn "uploadbarcodes : ".$uploadbarcodes; >-# use Data::Dumper; warn Dumper($input); >- >-my ($template, $borrowernumber, $cookie) >- = get_template_and_user({template_name => "tools/inventory.tmpl", >- query => $input, >- type => "intranet", >- authnotrequired => 0, >- flagsrequired => {tools => 'inventory'}, >- debug => 1, >- }); >+my $op = $input->param('op'); >+my $compareinv2barcd = $input->param('compareinv2barcd'); >+my $res; #contains the results loop >+ >+my ( $template, $borrowernumber, $cookie ) = get_template_and_user( >+ { template_name => "tools/inventory.tmpl", >+ query => $input, >+ type => "intranet", >+ authnotrequired => 0, >+ flagsrequired => { tools => 'inventory' }, >+ debug => 1, >+ } >+); >+ > > my $branches = GetBranches(); > my @branch_loop; >@@ -114,48 +118,63 @@ for my $authvfield (@$statuses) { > } > } > >+my $notforloanlist; > my $statussth = ''; > for my $authvfield (@$statuses) { > if ( scalar @{$staton->{$authvfield->{fieldname}}} > 0 ){ > my $joinedvals = join ',', @{$staton->{$authvfield->{fieldname}}}; > $statussth .= "$authvfield->{fieldname} in ($joinedvals) and "; >+ $notforloanlist = $joinedvals if ($authvfield->{fieldname} eq "items.notforloan"); > } > } > $statussth =~ s, and $,,g; >- >-$template->param(branchloop => \@branch_loop, >- authorised_values=>\@authorised_value_list, >- DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), >- today => C4::Dates->today(), >- minlocation => $minlocation, >- maxlocation => $maxlocation, >- location=>$location, >- ignoreissued=>$ignoreissued, >- branchcode=>$branchcode, >- branch => $branch, >- offset => $offset, >- pagesize => $pagesize, >- datelastseen => $datelastseen, >- ); >+$template->param( >+ branchloop => \@branch_loop, >+ authorised_values => \@authorised_value_list, >+ DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), >+ today => C4::Dates->today(), >+ minlocation => $minlocation, >+ maxlocation => $maxlocation, >+ location => $location, >+ ignoreissued => $ignoreissued, >+ branchcode => $branchcode, >+ branch => $branch, >+ offset => $offset, >+ pagesize => $pagesize, >+ datelastseen => $datelastseen, >+ compareinv2barcd => $compareinv2barcd, >+ notforloanlist => $notforloanlist >+); >+ >+my @notforloans; >+if (defined $notforloanlist) { >+ @notforloans = split(/,/, $notforloanlist); >+} >+ >+ >+ > my @brcditems; >-if ($uploadbarcodes && length($uploadbarcodes)>0){ >- my $dbh=C4::Context->dbh; >- my $date = format_date_in_iso($input->param('setdate')) || C4::Dates->today('iso'); >-# warn "$date"; >- my $strsth="select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?"; >+my $barcodelist; >+my @errorloop; >+if ( $uploadbarcodes && length($uploadbarcodes) > 0 ) { >+ my $dbh = C4::Context->dbh; >+ my $date = format_date_in_iso( $input->param('setdate') ) || C4::Dates->today('iso'); >+ >+ my $strsth = "select * from issues, items where items.itemnumber=issues.itemnumber and items.barcode =?"; > my $qonloan = $dbh->prepare($strsth); > $strsth="select * from items where items.barcode =? and items.wthdrawn = 1"; > my $qwthdrawn = $dbh->prepare($strsth); >- my @errorloop; >- my $count=0; >- while (my $barcode=<$uploadbarcodes>){ >+ my $count = 0; >+ >+ while ( my $barcode = <$uploadbarcodes> ) { > $barcode =~ s/\r?\n$//; >- if ($qwthdrawn->execute($barcode) &&$qwthdrawn->rows){ >- push @errorloop, {'barcode'=>$barcode,'ERR_WTHDRAWN'=>1}; >- }else{ >- my $item = GetItem('', $barcode); >- if (defined $item && $item->{'itemnumber'}){ >- ModItem({ datelastseen => $date }, undef, $item->{'itemnumber'}); >+ $barcodelist .= ($barcodelist) ? '|' . $barcode : $barcode; >+ if ( $qwthdrawn->execute($barcode) && $qwthdrawn->rows ) { >+ push @errorloop, { 'barcode' => $barcode, 'ERR_WTHDRAWN' => 1 }; >+ } else { >+ my $item = GetItem( '', $barcode ); >+ if ( defined $item && $item->{'itemnumber'} ) { >+ ModItem( { datelastseen => $date }, undef, $item->{'itemnumber'} ); > push @brcditems, $item; > $count++; > $qonloan->execute($barcode); >@@ -172,48 +191,83 @@ if ($uploadbarcodes && length($uploadbarcodes)>0){ > push @errorloop, {'barcode'=>$barcode,'ERR_BARCODE'=>1}; > } > } >+ > } > $qonloan->finish; > $qwthdrawn->finish; >- $template->param(date=>format_date($date),Number=>$count); >-# $template->param(errorfile=>$errorfile) if ($errorfile); >- $template->param(errorloop=>\@errorloop) if (@errorloop); >+ $template->param( date => format_date($date), Number => $count ); >+ $template->param( errorloop => \@errorloop ) if (@errorloop); >+ >+ >+} >+$template->param(barcodelist => $barcodelist); >+ >+# now build the result list: inventoried items if requested, and mis-placed items -always- >+my $inventorylist; >+if ( $markseen or $op ) { >+ # retrieve all items in this range. >+ my $totalrecords; >+ ($inventorylist, $totalrecords) = GetItemsForInventory($minlocation, $maxlocation, $location, $itemtype, $ignoreissued, '', $branchcode, $branch, 0, undef , $staton); >+ >+ $res = $inventorylist ; > } >-#if we want to compare the results to a list of barcodes, or we have no barcode file >-if ( ! ($uploadbarcodes && length($uploadbarcodes)>0 ) || ( $input->param('compareinv2barcd') eq 'on' && length($uploadbarcodes)>0) ) { >- if ($markseen) { >- foreach ($input->param) { >- /SEEN-(.+)/ and &ModDateLastSeen($1); >+ >+# set "missing" flags for all items with a datelastseen before the choosen datelastseen >+foreach (@$res) {$_->{missingitem}=1 if C4::Dates->new($_->{datelastseen})->output('iso') lt C4::Dates->new($datelastseen)->output('iso')} >+ >+# removing missing items from loop if "Compare barcodes list to results" has not been checked >+@$res = grep {!$_->{missingitem} == 1 } @$res if (!$input->param('compareinv2barcd')); >+ >+# insert "wrongplace" to all scanned items that are not supposed to be in this range >+# note this list is always displayed, whatever the librarian has choosen for comparison >+foreach my $temp (@brcditems) { >+ next if $temp->{onloan}; # skip checked out items >+ >+ # If we have scanned items with a non-matching notforloan value >+ if (none { $temp->{'notforloan'} eq $_ } @notforloans) { >+ $temp->{'changestatus'} = 1; >+ if ($input->param('CSVexport') eq 'on') { >+ my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); >+ $temp->{title} = $biblio->{title}; >+ $temp->{author} = $biblio->{author}; >+ $temp->{datelastseen} = format_date($temp->{datelastseen}); > } >+ push @$res, $temp; >+ > } >- if ($markseen or $op) { >- $res = GetItemsForInventory( $minlocation, $maxlocation, $location, $itemtype, $ignoreissued, $datelastseen, $branchcode, $branch, $offset, $pagesize, $staton ); >- $template->param(loop =>$res, >- nextoffset => ($offset+$pagesize), >- prevoffset => ($offset?$offset-$pagesize:0), >- ); >- } >- if ( defined $input->param('compareinv2barcd') && ( ( $input->param('compareinv2barcd') eq 'on' ) && ( scalar @brcditems != scalar @$res ) ) && length($uploadbarcodes) > 0 ){ >- if ( scalar @brcditems > scalar @$res ){ >- for my $brcditem (@brcditems) { >- if (! grep( $_->{barcode} =~ /$brcditem->{barcode}/ , @$res) ){ >- $brcditem->{notfoundkoha} = 1; >- push @$res, $brcditem; >- } >- } >- } else { >- my @notfound; >- for my $item (@$res) { >- if ( ! grep( $_->{barcode} =~ /$item->{barcode}/ , @brcditems) ){ >- $item->{notfoundbarcode} = 1; >- push @notfound, $item; >- } >- } >- $res = [@$res, @notfound]; >+ >+ if (none { $temp->{barcode} eq $_->{barcode} && !$_->{onloan} } @$inventorylist) { >+ $temp->{wrongplace}=1; >+ if ($input->param('CSVexport') eq 'on') { >+ my $biblio = C4::Biblio::GetBiblioData($temp->{biblionumber}); >+ $temp->{title} = $biblio->{title}; >+ $temp->{author} = $biblio->{author}; >+ $temp->{datelastseen} = format_date($temp->{datelastseen}); > } >+ push @$res, $temp; >+ } >+} >+ >+# Finally, modifying datelastseen for remaining items >+my $moddatecount = 0; >+foreach (@$res) { >+ unless ($_->{'missingitem'}) { >+ ModDateLastSeen($_->{'itemnumber'}); >+ $moddatecount++; > } > } > >+# Removing items that don't have any problems from loop >+@$res = grep { $_->{missingitem} || $_->{wrongplace} || $_->{changestatus} } @$res; >+ >+$template->param( >+ moddatecount => $moddatecount, >+ loop => $res, >+ nextoffset => ( $offset + $pagesize ), >+ prevoffset => ( $offset ? $offset - $pagesize : 0 ), >+ op => $op >+); >+ > if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ > eval {use Text::CSV}; > my $csv = Text::CSV->new or >@@ -222,14 +276,51 @@ if (defined $input->param('CSVexport') && $input->param('CSVexport') eq 'on'){ > -type => 'text/csv', > -attachment => 'inventory.csv', > ); >- for my $re (@$res){ >+ >+ my $columns_def_hashref = C4::Reports::Guided::_get_column_defs(); >+ foreach my $key ( keys %$columns_def_hashref ) { >+ my $initkey = $key; >+ $key =~ s/[^\.]*\.//; >+ $columns_def_hashref->{$initkey}=NormalizeString($columns_def_hashref->{$initkey}); >+ $columns_def_hashref->{$key} = $columns_def_hashref->{$initkey}; >+ } >+ >+ my @translated_keys; >+ for my $key (qw / biblioitems.title biblio.author >+ items.barcode items.itemnumber >+ items.homebranch items.location >+ items.itemcallnumber items.notforloan >+ items.itemlost items.damaged >+ items.stocknumber >+ / ) { >+ push @translated_keys, $columns_def_hashref->{$key}; >+ } >+ >+ $csv->combine(@translated_keys); >+ print $csv->string, "\n"; >+ >+ my @keys = qw / title author barcode itemnumber homebranch location itemcallnumber notforloan lost damaged stocknumber /; >+ for my $re (@$res) { > my @line; >- for my $key (keys %$re) { >+ for my $key (@keys) { > push @line, $re->{$key}; > } >+ push @line, "wrong place" if $re->{wrongplace}; >+ push @line, "missing item" if $re->{missingitem}; >+ push @line, "change item status" if $re->{changestatus}; > $csv->combine(@line); > print $csv->string, "\n"; > } >+ # Adding not found barcodes >+ foreach my $error (@errorloop) { >+ my @line; >+ if ($error->{'ERR_BARCODE'}) { >+ push @line, map { $_ eq 'barcode' ? $error->{'barcode'} : ''} @keys; >+ push @line, "barcode not found"; >+ $csv->combine(@line); >+ print $csv->string, "\n"; >+ } >+ } > exit; > } > >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7684
:
9412
|
10413
|
11793
|
11843
|
12387
|
13097
|
16212
|
16483
|
16484
|
16524
|
16541
|
16594
|
16598
|
17841
|
17844
|
18705
|
18706
|
19215
|
20467
|
20468
|
21112
|
21113
|
21206
|
21331
|
21332
|
21440
|
21441
|
21968
|
21970
|
21971
|
21972
|
22208
|
22209
|
22210