Bug 7175: Allow to choose which items to receive

If AcqCreateItem=ordering, when you receive an order, you now have a
list of all created items and checkboxes that permit you to choose which
items you want to receive.
A 'Edit' link open additem.pl page in a popup to allow you edit the
items before receiving them (popup is automatically closed after
modification, and items table is automatically updated)
If quantity is set manually in the text box, the appropriate number of
checkbox are checked from top to bottom and a warning shows up if
quantity is greater than order quantity

Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
This commit is contained in:
Julian Maurice 2012-01-13 16:55:10 +01:00 committed by Paul Poulain
parent b156055ad2
commit 2338d02e9e
7 changed files with 283 additions and 14 deletions

View File

@ -57,7 +57,7 @@ BEGIN {
&ModReceiveOrder &ModOrderBiblioitemNumber
&GetCancelledOrders
&NewOrderItem &ModOrderItem
&NewOrderItem &ModOrderItem &ModItemOrder
&GetParcels &GetParcel
&GetContracts &GetContract
@ -1053,6 +1053,29 @@ sub ModOrderItem {
return 0;
}
=head3 ModItemOrder
ModItemOrder($itemnumber, $ordernumber);
Modifies the ordernumber of an item in aqorders_items.
=cut
sub ModItemOrder {
my ($itemnumber, $ordernumber) = @_;
return unless ($itemnumber and $ordernumber);
my $dbh = C4::Context->dbh;
my $query = qq{
UPDATE aqorders_items
SET ordernumber = ?
WHERE itemnumber = ?
};
my $sth = $dbh->prepare($query);
return $sth->execute($ordernumber, $itemnumber);
}
#------------------------------------------------------------#
@ -1138,7 +1161,7 @@ C<$ordernumber>.
sub ModReceiveOrder {
my (
$biblionumber, $ordernumber, $quantrec, $user, $cost,
$invoiceno, $freight, $rrp, $budget_id, $datereceived
$invoiceno, $freight, $rrp, $budget_id, $datereceived, $received_items
)
= @_;
my $dbh = C4::Context->dbh;
@ -1181,7 +1204,19 @@ sub ModReceiveOrder {
$order->{'quantity'} -= $quantrec;
$order->{'quantityreceived'} = 0;
my $newOrder = NewOrder($order);
} else {
# Change ordernumber in aqorders_items for items not received
my @orderitems = GetItemnumbersFromOrder( $order->{'ordernumber'} );
my $count = scalar @orderitems;
for (my $i=0; $i<$count; $i++){
foreach (@$received_items){
splice (@orderitems, $i, 1) if ($orderitems[$i] == $_);
}
}
foreach (@orderitems) {
ModItemOrder($_, $newOrder);
}
} else {
$sth=$dbh->prepare("update aqorders
set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
unitprice=?,freight=?,rrp=?

View File

@ -94,9 +94,14 @@ if ($quantityrec > $origquantityrec ) {
NewOrderItem($itemnumber, $ordernumber);
}
}
my @received_items = ();
if(C4::Context->preference('AcqCreateItem') eq 'ordering') {
@received_items = $input->param('items_to_receive');
}
# save the quantity received.
$datereceived = ModReceiveOrder($biblionumber,$ordernumber, $quantityrec ,$user,$unitprice,$invoiceno,$freight,$replacement,undef,$datereceived);
$datereceived = ModReceiveOrder($biblionumber,$ordernumber, $quantityrec ,$user,$unitprice,$invoiceno,$freight,$replacement,undef,$datereceived, \@received_items);
}
update_item( $_ ) foreach GetItemnumbersFromOrder( $ordernumber );

View File

@ -112,16 +112,51 @@ my $count = scalar @$results;
# prepare the form for receiving
if ( $count == 1 ) {
my $order = $results->[0];
if (C4::Context->preference('AcqCreateItem') eq 'receiving') {
# Check if ACQ framework exists
my $marc = GetMarcStructure(1, 'ACQ');
unless($marc) {
$template->param('NoACQframework' => 1);
}
# Check if ACQ framework exists
my $acq_fw = GetMarcStructure(1, 'ACQ');
unless($acq_fw) {
$template->param('NoACQframework' => 1);
}
my $AcqCreateItem = C4::Context->preference('AcqCreateItem');
if ($AcqCreateItem eq 'receiving') {
$template->param(
AcqCreateItemReceiving => 1,
UniqueItemFields => C4::Context->preference('UniqueItemFields'),
);
} elsif ($AcqCreateItem eq 'ordering') {
my $fw = ($acq_fw) ? 'ACQ' : '';
my @itemnumbers = GetItemnumbersFromOrder($order->{ordernumber});
my @items;
foreach (@itemnumbers) {
my $item = GetItem($_);
if($item->{homebranch}) {
$item->{homebranchname} = GetBranchName($item->{homebranch});
}
if($item->{holdingbranch}) {
$item->{holdingbranchname} = GetBranchName($item->{holdingbranch});
}
if(my $code = GetAuthValCode("items.notforloan", $fw)) {
$item->{notforloan} = GetKohaAuthorisedValueLib($code, $item->{notforloan});
}
if(my $code = GetAuthValCode("items.restricted", $fw)) {
$item->{restricted} = GetKohaAuthorisedValueLib($code, $item->{restricted});
}
if(my $code = GetAuthValCode("items.location", $fw)) {
$item->{location} = GetKohaAuthorisedValueLib($code, $item->{location});
}
if(my $code = GetAuthValCode("items.ccode", $fw)) {
$item->{collection} = GetKohaAuthorisedValueLib($code, $item->{ccode});
}
if(my $code = GetAuthValCode("items.materials", $fw)) {
$item->{materials} = GetKohaAuthorisedValueLib($code, $item->{materials});
}
my $itemtype = getitemtypeinfo($item->{itype});
$item->{itemtype} = $itemtype->{description};
push @items, $item;
}
$template->param(items => \@items);
}
if ( $order->{'unitprice'} == 0 ) {
@ -136,6 +171,7 @@ if ( $count == 1 ) {
my $budget = GetBudget( $order->{'budget_id'} );
$template->param(
AcqCreateItem => $AcqCreateItem,
count => 1,
biblionumber => $order->{'biblionumber'},
ordernumber => $order->{'ordernumber'},

73
catalogue/getitem-ajax.pl Executable file
View File

@ -0,0 +1,73 @@
#!/usr/bin/perl
# Copyright BibLibre 2012
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with Koha; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use Modern::Perl;
use CGI;
use JSON;
use C4::Biblio;
use C4::Branch;
use C4::Items;
use C4::Koha;
use C4::Output;
my $cgi = new CGI;
my $item = {};
my $itemnumber = $cgi->param('itemnumber');
if($itemnumber) {
my $acq_fw = GetMarcStructure(1, 'ACQ');
my $fw = ($acq_fw) ? 'ACQ' : '';
$item = GetItem($itemnumber);
if($item->{homebranch}) {
$item->{homebranchname} = GetBranchName($item->{homebranch});
}
if($item->{holdingbranch}) {
$item->{holdingbranchname} = GetBranchName($item->{holdingbranch});
}
if(my $code = GetAuthValCode("items.notforloan", $fw)) {
$item->{notforloan} = GetKohaAuthorisedValueLib($code, $item->{notforloan});
}
if(my $code = GetAuthValCode("items.restricted", $fw)) {
$item->{restricted} = GetKohaAuthorisedValueLib($code, $item->{restricted});
}
if(my $code = GetAuthValCode("items.location", $fw)) {
$item->{location} = GetKohaAuthorisedValueLib($code, $item->{location});
}
if(my $code = GetAuthValCode("items.ccode", $fw)) {
$item->{collection} = GetKohaAuthorisedValueLib($code, $item->{ccode});
}
if(my $code = GetAuthValCode("items.materials", $fw)) {
$item->{materials} = GetKohaAuthorisedValueLib($code, $item->{materials});
}
my $itemtype = getitemtypeinfo($item->{itype});
$item->{itemtype} = $itemtype->{description};
}
my $json_text = to_json( $item, { utf8 => 1 } );
output_with_http_headers $cgi, undef, $json_text, 'json';

View File

@ -724,6 +724,7 @@ $template->param(
itemtagsubfield => $itemtagsubfield,
op => $nextop,
opisadd => ($nextop eq "saveitem") ? 0 : 1,
popup => $input->param('popup') ? 1: 0,
C4::Search::enabled_staff_search_views,
);

View File

@ -32,9 +32,68 @@
return true;
}
[% IF (AcqCreateItem == 'ordering') %]
var items_columns = [null, null, 'barcode', 'homebranchname',
'holdingbranchname', 'notforloan', 'restricted', 'location',
'itemcallnumber', 'copynumber', 'stocknumber', 'collection',
'itemtype', 'materials', 'itemnotes'];
function PopupEditPage(biblionumber, itemnumber) {
var url = "/cgi-bin/koha/cataloguing/additem.pl?op=edititem&biblionumber="
+ biblionumber + "&itemnumber=" + itemnumber + "&popup=1#edititem";
var w = window.open(url);
var watchClose = setInterval(function() {
if (w.closed) {
clearTimeout(watchClose);
$.getJSON('/cgi-bin/koha/catalogue/getitem-ajax.pl',
{
'itemnumber': itemnumber
},
function(item) {
var tds = $("#item_"+itemnumber+" td");
for(var i=2; i<tds.length; i++) {
var column = items_columns[i];
$(tds[i]).text(item[column]);
}
}
);
}
}, 500);
}
function CalcQtyToReceive() {
var qty = $("input[name='items_to_receive']:checked").length;
$("#quantity").val(qty);
}
function CheckNItems(n) {
$("input[name='items_to_receive']").each(function() {
$(this).attr('checked', false);
});
$("input[name='items_to_receive']:lt("+n+")").each(function () {
$(this).attr('checked', true);
});
}
[% END %]
$(document).ready(function() {
[% IF (AcqCreateItemReceiving) %]
cloneItemBlock(0, '[% UniqueItemFields %]');
[% ELSIF (AcqCreateItem == 'ordering') %]
$("input[name='items_to_receive']").change(function() {
CalcQtyToReceive();
});
CalcQtyToReceive();
$("#quantity").keyup(function() {
var qty = parseInt($("#quantity").val());
var qtyto = parseInt($("#quantity_to_receive").val());
if(qty > qtyto) {
$("#qtyrecerror").show();
} else {
$("#qtyrecerror").hide();
}
CheckNItems($(this).val());
});
[% END %]
});
//]]>
@ -127,7 +186,55 @@
[% END %]
<div id="outeritemblock"></div>
</fieldset>
[% END %][%# IF (AcqCreateItemReceiving) %]
[% ELSIF (AcqCreateItem == 'ordering') %]
[% IF (items.size) %]
<h5>Items</h5>
<div style="width:100%;overflow:auto">
<table>
<thead>
<tr>
<th>Receive?</th>
<th>&nbsp;</th>
<th>Barcode</th>
<th>Home branch</th>
<th>Holding branch</th>
<th>Not for loan</th>
<th>Restricted</th>
<th>Location</th>
<th>Call number</th>
<th>Copy number</th>
<th>Stock number</th>
<th>Collection code</th>
<th>Item type</th>
<th>Materials</th>
<th>Notes</th>
</tr>
</thead>
<tbody>
[% FOREACH item IN items %]
<tr id="item_[% item.itemnumber %]">
<td style="text-align:center"><input type="checkbox" name="items_to_receive" value="[% item.itemnumber %]" /></td>
<td><a style="cursor:pointer" onclick="PopupEditPage([% item.biblionumber %],[% item.itemnumber %]);">Edit</a></td>
<td>[% item.barcode %]</td>
<td>[% item.homebranchname %]</td>
<td>[% item.holdingbranchname %]</td>
<td>[% item.notforloan %]</td>
<td>[% item.restricted %]</td>
<td>[% item.location %]</td>
<td>[% item.itemcallnumber %]</td>
<td>[% item.copynumber %]</td>
<td>[% item.stocknumber %]</td>
<td>[% item.collection %]</td>
<td>[% item.itemtype %]</td>
<td>[% item.materials %]</td>
<td>[% item.itemnotes %]</td>
</tr>
[% END %]
</tbody>
</table>
</div>
[% END %]
[% END %]
<input type="hidden" name="biblionumber" value="[% biblionumber %]" />
<input type="hidden" name="ordernumber" value="[% ordernumber %]" />
<input type="hidden" name="biblioitemnumber" value="[% biblioitemnumber %]" />
@ -143,7 +250,7 @@
<li><label for="datereceived">Date received: </label><span> [% datereceived %] </span></li>
<li><label for="bookfund">Budget: </label><span> [% bookfund %] </span></li>
<li><label for="creator">Created by: </label><span> [% IF ( memberfirstname and membersurname ) %][% IF ( memberfirstname ) %][% memberfirstname %][% END %] [% membersurname %][% ELSE %]No name[% END %]</span></li>
<li><label for="quantityto">Quantity to receive: </label><span class="label">
<li><label for="quantity_to_receive">Quantity to receive: </label><span class="label">
[% IF ( edit ) %]
<input type="text" id="quantity_to_receive" name="quantity" value="[% quantity %]" />
[% ELSE %]
@ -168,12 +275,16 @@
[% END %]
[% ELSE %]
[% IF ( items ) %]
<input READONLY type="text" id="quantity" size="20" name="quantityrec" value="1" />
<input type="text" id="quantity" size="20" name="quantityrec" value="1" />
[% ELSE %]
<input type="text" size="20" id="quantity" name="quantityrec" value="1" />
[% END %]
<input id="origquantityrec" READONLY type="hidden" name="origquantityrec" value="0" />
[% END %]
<div id="qtyrecerror" style="display:none">
<p class="error">Warning, you have entered more items than expected.
Items will not be created.</p>
</div>
[% END %][%# IF (AcqCreateItemReceiving) %]
</li>
<li><label for="rrp">Replacement cost: </label><input type="text" size="20" name="rrp" id="rrp" value="[% rrp %]" /></li>

View File

@ -4,6 +4,11 @@
<script type="text/javascript">
//<![CDATA[
$(document).ready(function(){
[% IF (popup) %]
[% IF (opisadd) %]
window.close();
[% END %]
[% END %]
$("fieldset.rows input").keydown(function(e){ return checkEnter(e); });
/* Inline edit/delete links */
var biblionumber = $("input[name='biblionumber']").attr("value");
@ -219,6 +224,9 @@ $(document).ready(function() {
<div id="cataloguing_additem_newitem">
<form method="post" action="/cgi-bin/koha/cataloguing/additem.pl" name="f">
<input type="hidden" name="op" value="[% op %]" />
[% IF (popup) %]
<input type="hidden" name="popup" value="1" />
[% END %]
<input type="hidden" name="biblionumber" value="[% biblionumber %]" />
[% IF ( opisadd ) %]
<h2 id="additema">Add item</h2>