[Koha-patches] [PATCH] bug 6039: Cancel All waiting holds button

Srdjan Jankovic srdjan at catalyst.net.nz
Mon Jan 23 01:49:26 CET 2012


TransferWhenCancelAllWaitingHolds syspref
---
 circ/waitingreserves.pl                            |  102 +++++++++++++-------
 installer/data/mysql/sysprefs.sql                  |    1 +
 installer/data/mysql/updatedatabase.pl             |    7 ++
 .../en/modules/admin/preferences/circulation.pref  |    6 +
 .../prog/en/modules/circ/waitingreserves.tt        |   20 +++-
 5 files changed, 99 insertions(+), 37 deletions(-)

diff --git a/circ/waitingreserves.pl b/circ/waitingreserves.pl
index 128d1eb..17b7be6 100755
--- a/circ/waitingreserves.pl
+++ b/circ/waitingreserves.pl
@@ -46,6 +46,7 @@ my $borrowernumber = $input->param('borrowernumber');
 my $fbr            = $input->param('fbr') || '';
 my $tbr            = $input->param('tbr') || '';
 my $all_branches   = $input->param('allbranches') || '';
+my $cancelall      = $input->param('cancelall');
 
 my $cancel;
 
@@ -62,42 +63,23 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 
 my $default = C4::Context->userenv->{'branch'};
 
+my $transfer_when_cancel_all = C4::Context->preference('TransferWhenCancelAllWaitingHolds');
+$template->param( TransferWhenCancelAllWaitingHolds => 1 ) if $transfer_when_cancel_all;
+
+my @cancel_result;
 # if we have a return from the form we launch the subroutine CancelReserve
 if ($item) {
-    my ( $messages, $nextreservinfo ) = ModReserveCancelAll( $item, $borrowernumber );
-    # if we have a result
-    if ($nextreservinfo) {
-        my $borrowerinfo = GetMemberDetails( $nextreservinfo );
-        my $iteminfo = GetBiblioFromItemNumber($item);
-        if ( $messages->{'transfert'} ) {
-            $template->param(
-                messagetransfert => $messages->{'transfert'},
-                branchname       => GetBranchName($messages->{'transfert'}),
-            );
-        }
-
-        $template->param(
-            message             => 1,
-            nextreservnumber    => $nextreservinfo,
-            nextreservsurname   => $borrowerinfo->{'surname'},
-            nextreservfirstname => $borrowerinfo->{'firstname'},
-            nextreservitem      => $item,
-            nextreservtitle     => $iteminfo->{'title'},
-            waiting             => ($messages->{'waiting'}) ? 1 : 0,
-        );
-    }
-
-# 	if the document is not in his homebranch location and there is not reservation after, we transfer it
-    if ($fbr ne $tbr  and not $nextreservinfo) {
-        ModItemTransfer( $item, $fbr, $tbr );
-    }
+    my $res = cancel( $item, $borrowernumber, $fbr, $tbr );
+    push @cancel_result, $res if $res;
 }
+
 if ( C4::Context->preference('IndependantBranches') ) {
     undef $all_branches;
 } else {
-    $template->param( all_branches_link => $input->url . '?allbranches=1&' . $input->query_string )
+    $template->param( all_branches_link => $input->url . '?allbranches=1' )
       unless $all_branches;
 }
+$template->param( all_branches => 1 ) if $all_branches;
 
 my (@reservloop, @overloop);
 my ($reservcount, $overcount);
@@ -107,8 +89,24 @@ my @getreserves = $all_branches ? GetReservesForBranch() : GetReservesForBranch(
 my $today = Date_to_Days(&Today);
 foreach my $num (@getreserves) {
     next unless ($num->{'waitingdate'} && $num->{'waitingdate'} ne '0000-00-00');
-    my %getreserv;
-    my $gettitle     = GetBiblioFromItemNumber( $num->{'itemnumber'} );
+
+    my $itemnumber = $num->{'itemnumber'};
+    my $gettitle     = GetBiblioFromItemNumber( $itemnumber );
+    my $borrowernum = $num->{'borrowernumber'};
+    my $holdingbranch = $gettitle->{'holdingbranch'};
+    my $homebranch = $gettitle->{'homebranch'};
+
+    if ($cancelall) {
+        my $res = cancel( $itemnumber, $borrowernum, $holdingbranch, $homebranch, !$transfer_when_cancel_all );
+        push @cancel_result, $res if $res;
+        next;
+    }
+
+    my %getreserv = (
+        itemnumber => $itemnumber,
+        borrowernum => $borrowernum,
+    );
+
     # fix up item type for display
     $gettitle->{'itemtype'} = C4::Context->preference('item-level_itypes') ? $gettitle->{'itype'} : $gettitle->{'itemtype'};
     my $getborrower = GetMember(borrowernumber => $num->{'borrowernumber'});
@@ -122,17 +120,15 @@ foreach my $num (@getreserves) {
 
     $getreserv{'itemtype'}       = $itemtypeinfo->{'description'};
     $getreserv{'title'}          = $gettitle->{'title'};
-    $getreserv{'itemnumber'}     = $gettitle->{'itemnumber'};
     $getreserv{'biblionumber'}   = $gettitle->{'biblionumber'};
     $getreserv{'barcode'}        = $gettitle->{'barcode'};
     $getreserv{'branchname'}     = GetBranchName($gettitle->{'homebranch'});
     $getreserv{'homebranch'}     = $gettitle->{'homebranch'};
     $getreserv{'holdingbranch'}  = $gettitle->{'holdingbranch'};
     $getreserv{'itemcallnumber'} = $gettitle->{'itemcallnumber'};
-    if ( $gettitle->{'homebranch'} ne $gettitle->{'holdingbranch'} ) {
+    if ( $homebranch ne $holdingbranch ) {
         $getreserv{'dotransfer'} = 1;
     }
-    $getreserv{'borrowernum'}       = $getborrower->{'borrowernumber'};
     $getreserv{'borrowername'}      = $getborrower->{'surname'};
     $getreserv{'borrowerfirstname'} = $getborrower->{'firstname'};
     $getreserv{'borrowerphone'}     = $getborrower->{'phone'};
@@ -150,6 +146,7 @@ foreach my $num (@getreserves) {
     
 }
 
+$template->param(cancel_result => \@cancel_result) if @cancel_result;
 $template->param(
     reserveloop => \@reservloop,
     reservecount => $reservcount,
@@ -161,3 +158,42 @@ $template->param(
 );
 
 output_html_with_http_headers $input, $cookie, $template->output;
+
+exit;
+
+sub cancel {
+    my ($item, $borrowernumber, $fbr, $tbr, $skip_transfers ) = @_;
+
+    my $transfer = $fbr ne $tbr; # XXX && !$nextreservinfo;
+
+    return if $transfer && $skip_transfers;
+
+    my ( $messages, $nextreservinfo ) = ModReserveCancelAll( $item, $borrowernumber );
+
+# 	if the document is not in his homebranch location and there is not reservation after, we transfer it
+    if ($transfer && !$nextreservinfo) {
+        ModItemTransfer( $item, $fbr, $tbr );
+    }
+    # if we have a result
+    if ($nextreservinfo) {
+        my %res;
+        my $borrowerinfo = GetMemberDetails( $nextreservinfo );
+        my $iteminfo = GetBiblioFromItemNumber($item);
+        if ( $messages->{'transfert'} ) {
+            $res{messagetransfert} = $messages->{'transfert'};
+            $res{branchname}       = GetBranchName($messages->{'transfert'});
+        }
+
+        $res{message}             = 1;
+        $res{nextreservnumber}    = $nextreservinfo;
+        $res{nextreservsurname}   = $borrowerinfo->{'surname'};
+        $res{nextreservfirstname} = $borrowerinfo->{'firstname'};
+        $res{nextreservitem}      = $item;
+        $res{nextreservtitle}     = $iteminfo->{'title'};
+        $res{waiting}             = $messages->{'waiting'} ? 1 : 0;
+
+        return \%res;
+    }
+
+    return;
+}
diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql
index 918df5c..740e665 100755
--- a/installer/data/mysql/sysprefs.sql
+++ b/installer/data/mysql/sysprefs.sql
@@ -330,3 +330,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('EasyAnalyticalRecords','0','If on, display in the catalogue screens tools to easily setup analytical record relationships','','YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('OpacShowRecentComments',0,'If ON a link to recent comments will appear in the OPAC masthead',NULL,'YesNo');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('CircAutoPrintQuickSlip', '1', 'Choose what should happen when an empty barcode field is submitted in circulation: Display a print quick slip window or Clear the screen.',NULL,'YesNo');
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('TransferWhenCancelAllWaitingHolds','0','Transfer items when cancelling all waiting holds',NULL,'YesNo');
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index b12196c..4b9ae48 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -4626,6 +4626,13 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     SetVersion($DBversion);
 }
 
+$DBversion = "3.07.00.XXX";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('TransferWhenCancelAllWaitingHolds','0','Transfer items when cancelling all waiting holds',NULL,'YesNo')");
+    print "Upgrade to $DBversion done (Add sysprefs to control transfer when cancel all waiting holds)\n";
+    SetVersion ($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 DropAllForeignKeys($table)
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
index 30bcb9b..7d7d682 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
@@ -317,6 +317,12 @@ Circulation:
                   yes: Enable
                   no:  "Don't enable"
             - "the ability to place holds on multiple biblio from the search results"	    
+        -
+            - pref: TransferWhenCancelAllWaitingHolds
+              choices:
+                  yes: Transfer
+                  no: "Don't transfer"
+            - items when cancelling all waiting holds.
     Fines Policy:
         -
             - Calculate fines based on days overdue
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt
index 7ecc3a1..14b6906 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/waitingreserves.tt
@@ -44,7 +44,8 @@ $.tablesorter.addParser({
             View all branches</a></span>
             [% END %]
         </h2>
-        [% IF ( messagetransfert ) %]
+    [% IF ( cancel_result ) %]
+        [% IF ( cancel_result.messagetransfert ) %]
             <div>
                 <h2>Hold find for ([% nextreservtitle %]), must be transferred</h2>
                 <p>This hold placed by : <b> [% nextreservsurname %] [% nextreservfirstname %]</b> at the library : <b> [% branchname %] </b>, Please transfer this hold.
@@ -54,7 +55,7 @@ $.tablesorter.addParser({
                 </form>
             </div>
         [% END %]
-        [% IF ( waiting ) %]
+        [% IF ( cancel_result.waiting ) %]
             <div id="bloc25">
                 <h2>This hold is waiting</h2>
                 <p>This hold ([% nextreservtitle %]) was placed by <b> : [% nextreservsurname %] [% nextreservfirstname %]</b>,
@@ -65,7 +66,7 @@ $.tablesorter.addParser({
                 </form>
             </div>
         [% END %]
-        [% UNLESS ( message ) %]
+    [% ELSE %]
         <div id="resultlist" class="toptabs">
             <ul>
                 <li><a href="/cgi-bin/koha/circ/waitingreserves.pl#holdswaiting">[% reservecount %] Hold(s) waiting</a></li>
@@ -117,7 +118,18 @@ $.tablesorter.addParser({
         </div>
         <div id="holdsover">
                 <p>Holds listed here have been awaiting pickup for more than [% ReservesMaxPickUpDelay %] days.</p>
-                [% IF ( overloop ) %]
+               [% IF ( overloop ) %]
+               <p>
+               <form name="cancelAllReserve" action="waitingreserves.pl" method="post">
+                   <input type="hidden" name="cancelall" value="1" />
+                   <input type="hidden" name="allbranches" value="[% allbranches %] />
+                   <input type="submit" value="Cancel [% IF TransferWhenCancelAllWaitingHolds %]and Transfer [% END %]All" />
+               </form>
+               [% UNLESS TransferWhenCancelAllWaitingHolds %]
+               Only items that need not be transferred will be cancelled (TransferWhenCancelAllWaitingHolds sypref)
+               [% END %]
+               </p>
+               <br/>
                <table id="holdso">
                <thead><tr>
                     <th>Available since</th>
-- 
1.6.5



More information about the Koha-patches mailing list