(bug #3819) still fixing holds policies

This patch backports more code from 3.2 to make hold policies working.
This commit is contained in:
Nahuel ANGELINETTI 2009-12-02 17:30:58 +01:00 committed by Henri-Damien LAURENT
parent 20d18c347b
commit 32e13e325a
7 changed files with 133 additions and 37 deletions

View File

@ -235,8 +235,8 @@ if ($borrowernumber) {
# Warningdate is the date that the warning starts appearing
my ( $today_year, $today_month, $today_day) = Today();
my ($warning_year, $warning_month, $warning_day) = split /-/, $borrower->{'dateexpiry'};
my ( $enrol_year, $enrol_month, $enrol_day) = split /-/, $borrower->{'dateenrolled'};
my ($warning_year, $warning_month, $warning_day) = split (/-/, $borrower->{'dateexpiry'});
my ( $enrol_year, $enrol_month, $enrol_day) = split (/-/, $borrower->{'dateenrolled'});
# Renew day is calculated by adding the enrolment period to today
my ( $renew_year, $renew_month, $renew_day) =
Add_Delta_YM( $enrol_year, $enrol_month, $enrol_day,

View File

@ -2,7 +2,16 @@
<title>Koha &rsaquo; Circulation &rsaquo; Holds &rsaquo; Place a hold on <!-- TMPL_VAR NAME="title" escape="html" --></title>
<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
<script type="text/javascript">
// <![CDATA[
// <![CDATA[
var patron_homebranch = "<!-- TMPL_VAR NAME="borrower_branchname" ESCAPE="JS" -->";
var override_items = {<!-- TMPL_LOOP NAME="bibitemloop" --><!-- TMPL_LOOP NAME="itemloop" --><!-- TMPL_IF NAME="override" -->
<!-- TMPL_VAR NAME="itemnumber" -->: {
homebranch: "<!-- TMPL_VAR NAME="homebranchname" ESCAPE="JS" -->",
holdallowed: <!-- TMPL_VAR NAME="holdallowed" -->
},
<!-- /TMPL_IF --><!-- /TMPL_LOOP --><!-- /TMPL_LOOP -->
};
function check() {
var msg = "";
var count_reserv = 0;
@ -50,6 +59,22 @@ if (alreadyreserved > "0"){
}
$(document).ready(function() {
$("input.needsoverride").click(function() { // This must be before the radio button/checkbox switch logic
var itemnumber = this.value;
var msg;
switch (override_items[itemnumber].holdallowed) {
case 0: msg = _( 'This item normally cannot be put on hold.' ); break;
case 1: msg = _( 'This item normally cannot be put on hold except for patrons from ' ) + override_items[itemnumber].homebranch + '.'; break;
}
msg += "\n\n" + _( 'Place hold on this item?' );
return confirm(msg);
});
$("input.warning").click(function() {
return confirm( _( 'None of these items can normally be put on hold for this patron.' ) + "\n\n" + _( 'Place hold?' ) );
});
$("#requestany").click(function() {
if(this.checked){
$("input[name=checkitem]").each(function() {
@ -136,6 +161,11 @@ if (alreadyreserved > "0"){
<!-- TMPL_IF NAME="alreadyreserved" -->
<li><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->"><!-- TMPL_VAR NAME="borrowerfirstname" --> <!-- TMPL_VAR NAME="borrowersurname" --></a> <strong>already has a hold</strong> on this item </li>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="none_available" -->
<li> <strong>No copies are available</strong> to be placed on hold</li>
<!-- /TMPL_IF -->
</ul></div>
<!-- /TMPL_IF -->
@ -192,9 +222,15 @@ if (alreadyreserved > "0"){
</ol>
<fieldset class="action">
<!-- TMPL_IF NAME="cardnumber"-->
<input type="submit" value="Place Hold" />
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="cardnumber"-->
<!-- TMPL_IF NAME="override_required" -->
<input type="submit" class="warning" value="Place Hold" />
<!-- TMPL_ELSIF NAME="none_available" -->
<input type="submit" disabled="disabled" value="Place Hold" />
<!-- TMPL_ELSE -->
<input type="submit" value="Place Hold" />
<!-- /TMPL_IF -->
<!-- /TMPL_IF -->
</fieldset>
<!-- TMPL_LOOP name="bibitemloop" -->
<ol>
@ -223,8 +259,12 @@ if (alreadyreserved > "0"){
<td>
<!-- TMPL_IF NAME="available" -->
<input type="radio" name="checkitem" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
<!-- TMPL_ELSIF NAME="override" -->
<input type="radio" name="checkitem" class="needsoverride" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
<img src="/intranet-tmpl/<!-- TMPL_VAR NAME="theme" -->/img/famfamfam/silk/error.png" alt="Requires override of hold policy" />
<!-- TMPL_ELSE -->
<input disabled="disabled" type="radio" name="checkitem" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
<img src="/intranet-tmpl/<!-- TMPL_VAR NAME="theme" -->/img/famfamfam/silk/cross.png" alt="Cannot be put on hold" />
<!-- /TMPL_IF -->
</td>
<!-- TMPL_IF NAME="item-level_itypes" -->
@ -284,9 +324,15 @@ if (alreadyreserved > "0"){
<!-- /TMPL_LOOP --> <!-- bibitemloop -->
<fieldset class="action">
<!-- TMPL_IF NAME="cardnumber"-->
<input type="submit" value="Place Hold" />
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="cardnumber"-->
<!-- TMPL_IF NAME="override_required" -->
<input type="submit" class="warning" value="Place Hold" />
<!-- TMPL_ELSIF NAME="none_available" -->
<input type="submit" disabled="disabled" value="Place Hold" />
<!-- TMPL_ELSE -->
<input type="submit" value="Place Hold" />
<!-- /TMPL_IF -->
<!-- /TMPL_IF -->
</fieldset>
</fieldset>
</form>

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

View File

@ -87,6 +87,11 @@
<!-- TMPL_IF NAME="bad_biblionumber" -->
<div class="dialog alert">ERROR: No biblio record found for biblionumber <!-- TMPL_VAR NAME="bad_biblionumber" -->.</div>
<!-- /TMPL_IF -->
<!-- TMPL_IF NAME="none_available" -->
<div class="dialog alert">
<strong>Sorry</strong>, none of these items can be placed on hold.
</div>
<!-- /TMPL_IF -->
</div>
<!-- /TMPL_IF -->
@ -135,7 +140,11 @@
<fieldset class="action"> <input type="hidden" name="biblioitem" value="<!-- TMPL_VAR NAME="biblioitemnumber" -->" />
<!-- TMPL_IF NAME="none_available" -->
<input type="submit" disabled="disabled" value="Place Hold" />
<!-- TMPL_ELSE -->
<input type="submit" value="Place Hold" />
<!-- /TMPL_IF -->
<input type="hidden" name="all" value="1" />
<input type="hidden" name="place_reserve" value="1" /></fieldset>
<!-- /TMPL_IF -->
@ -164,6 +173,7 @@
<input type="radio" name="checkitem" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
<!-- TMPL_ELSE -->
<input disabled="disabled" type="radio" name="checkitem" value="<!-- TMPL_VAR NAME="itemnumber" -->" />
<img src="/intranet-tmpl/<!-- TMPL_VAR NAME="theme" -->/img/famfamfam/silk/cross.png" alt="Cannot be put on hold" />
<!-- /TMPL_IF -->
</td>
<!-- TMPL_IF NAME="item-level_itypes" -->
@ -206,7 +216,11 @@
<!-- /TMPL_LOOP --> <!-- itemloop -->
</table>
<!-- /TMPL_LOOP --> <!-- bibitemloop -->
<input type="submit" value="Place Hold" />
<!-- TMPL_IF NAME="none_available" -->
<input type="submit" disabled="disabled" value="Place Hold" />
<!-- TMPL_ELSE -->
<input type="submit" value="Place Hold" />
<!-- /TMPL_IF -->
</form><!-- /TMPL_IF -->
<!-- end of the first form -->
<!-- /TMPL_IF -->

View File

@ -250,6 +250,7 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
}
my @bibitemloop;
my $num_available = 0;
foreach my $biblioitemnumber (@biblioitemnumbers) {
my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
@ -330,12 +331,17 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
# If there is no loan, return and transfer, we show a checkbox.
$item->{notforloan} = $item->{notforloan} || 0;
my $branchitemrule = C4::Context->preference("RequestOnOpac");
my $branchitemrule = GetBranchItemRule( $borr->{'branchcode'}, $itemInfo->{'itype'} );
my $policy_holdallowed = 1;
if ( $branchitemrule->{'holdallowed'} == 0 ||
( $branchitemrule->{'holdallowed'} == 1 && $borr->{'branchcode'} ne $itemInfo->{'homebranch'} ) ) {
$policy_holdallowed = 0;
}
if (IsAvailableForItemLevelRequest($itemnumber) and $policy_holdallowed) {
$item->{available} = 1;
$num_available++;
}
# FIXME: move this to a pm
@ -352,6 +358,10 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
push @bibitemloop, $biblioitem;
}
if ( $num_available == 0 ) {
$template->param( none_available => 1, message => 1 );
}
# display infos
$template->param(
forloan => $forloan,

View File

@ -115,7 +115,7 @@ if ($cardnumber) {
my $expiry_date = $borrowerinfo->{dateexpiry};
my $expiry = 0; # flag set if patron account has expired
if ($expiry_date and $expiry_date ne '0000-00-00' and
Date_to_Days(split /-/,$date) > Date_to_Days(split /-/,$expiry_date)) {
Date_to_Days(split (/-/,$date)) > Date_to_Days(split (/-/,$expiry_date))) {
$messages = $expiry = 1;
}else{
$expiry = 0;
@ -251,12 +251,13 @@ my @bibitemloop;
foreach my $biblioitemnumber (@biblioitemnumbers) {
my $biblioitem = $biblioiteminfos_of->{$biblioitemnumber};
my $num_available;
my $num_override;
$biblioitem->{description} =
$itemtypes->{ $biblioitem->{itemtype} }{description};
foreach
my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } )
{
foreach my $itemnumber ( @{ $itemnumbers_of_biblioitem{$biblioitemnumber} } ){
my $item = $iteminfos_of->{$itemnumber};
unless (C4::Context->preference('item-level_itypes')) {
$item->{itype} = $biblioitem->{itemtype};
@ -273,8 +274,8 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
$branches->{ $item->{holdingbranch} }{branchname};
}
# add information
$item->{itemcallnumber} = $item->{itemcallnumber};
# add information
$item->{itemcallnumber} = $item->{itemcallnumber};
# if the item is currently on loan, we display its return date and
# change the background color
@ -331,31 +332,56 @@ foreach my $biblioitemnumber (@biblioitemnumbers) {
# If there is no loan, return and transfer, we show a checkbox.
$item->{notforloan} = $item->{notforloan} || 0;
# if independent branches is on we need to check if the person can reserve
# for branches they arent logged in to
if ( C4::Context->preference("IndependantBranches") ) {
if (! C4::Context->preference("canreservefromotherbranches")){
# cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
my $userenv = C4::Context->userenv;
if ( ($userenv) && ( $userenv->{flags} %2 != 1 ) ) {
$item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
}
# if independent branches is on we need to check if the person can reserve
# for branches they arent logged in to
if ( C4::Context->preference("IndependantBranches") ) {
if (! C4::Context->preference("canreservefromotherbranches")){
# cant reserve items so need to check if item homebranch and userenv branch match if not we cant reserve
my $userenv = C4::Context->userenv;
if ( ($userenv) && ( $userenv->{flags} %2 != 1 ) ) {
$item->{cantreserve} = 1 if ( $item->{homebranch} ne $userenv->{branch} );
}
}
}
}
if (IsAvailableForItemLevelRequest($itemnumber) and not $item->{cantreserve}) {
$item->{available} = 1;
}
# FIXME: move this to a pm
my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
$sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
while (my $wait_hashref = $sth2->fetchrow_hashref) {
$item->{waitingdate} = format_date($wait_hashref->{waitingdate});
}
my $branchitemrule = GetBranchItemRule( $item->{'homebranch'}, $item->{'itype'} );
my $policy_holdallowed = 1;
$item->{'holdallowed'} = $branchitemrule->{'holdallowed'};
if ( $branchitemrule->{'holdallowed'} == 0 ||
( $branchitemrule->{'holdallowed'} == 1 && $borrowerinfo->{'branchcode'} ne $item->{'homebranch'} ) ) {
$policy_holdallowed = 0;
}
if (IsAvailableForItemLevelRequest($itemnumber) and not $item->{cantreserve}) {
if ( not $policy_holdallowed and C4::Context->preference( 'AllowHoldPolicyOverride' ) ) {
$item->{override} = 1;
$num_override++;
} elsif ( $policy_holdallowed ) {
$item->{available} = 1;
$num_available++;
}
}
# If none of the conditions hold true, then neither override nor available is set and the item cannot be checked
# FIXME: move this to a pm
my $sth2 = $dbh->prepare("SELECT * FROM reserves WHERE borrowernumber=? AND itemnumber=? AND found='W'");
$sth2->execute($item->{ReservedForBorrowernumber},$item->{itemnumber});
while (my $wait_hashref = $sth2->fetchrow_hashref) {
$item->{waitingdate} = format_date($wait_hashref->{waitingdate});
}
push @{ $biblioitem->{itemloop} }, $item;
}
if ( $num_override == scalar( @{ $biblioitem->{itemloop} } ) ) { # That is, if all items require an override
$template->param( override_required => 1 );
} elsif ( $num_available == 0 ) {
$template->param( none_available => 1 );
$template->param( warnings => 1 );
}
push @bibitemloop, $biblioitem;
}