From b494bb24fd205bafcbf2553cc31e4b4b0db90f1b Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 Sep 2013 15:33:35 +0200 Subject: [PATCH] Bug 11169: Display acquition details at the OPAC This patch adds a new tab 'Acquisition detail' on the OPAC detail page. A syspref (OPACAcquisitionDetails) permits to turn on this feature. Test plan: - switch on the OPACAcquisitionDetails pref. - set the AcqCreateItems pref to 'receiving'. - create some orders on 1 or more items. - go to the opac detail page and verify the "acquitision details" tab contains the right number of items which is in order. - receive the items. - verify the number of items has decreased. - set the AcqCreateItems pref to 'ordering'. - create some orders on 1 or more items. - go to the opac detail page and verify the "acquitision details" tab contains the list of items which is in order. - receive the items. - verify the received items don't appear anymore in the table. Signed-off-by: Broust --- C4/Acquisition.pm | 5 + installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 13 ++ .../prog/en/modules/admin/preferences/opac.pref | 8 +- .../opac-tmpl/prog/en/includes/item-status.inc | 2 + koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt | 21 +++- opac/opac-detail.pl | 129 ++++++++++++------- 7 files changed, 129 insertions(+), 50 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 33aa8e3..312d04a 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1659,6 +1659,7 @@ sub SearchOrders { my $owner = $params->{owner}; my $pending = $params->{pending}; my $ordered = $params->{ordered}; + my $biblionumber = $params->{biblionumber}; my $dbh = C4::Context->dbh; my @args = (); @@ -1710,6 +1711,10 @@ sub SearchOrders { $query .= ' AND (aqorders.ordernumber=?)'; push @args, $ordernumber; } + if ( $biblionumber ) { + $query .= 'AND aqorders.biblionumber = ?'; + push @args, $biblionumber; + } if( $search ) { $query .= ' AND (biblio.title LIKE ? OR biblio.author LIKE ? OR biblioitems.isbn LIKE ?)'; push @args, ("%$search%","%$search%","%$search%"); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 661910b..611436b 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -202,6 +202,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('OAI-PMH:ConfFile','',NULL,'If empty, Koha OAI Server operates in normal mode, otherwise it operates in extended mode.','File'), ('OAI-PMH:MaxCount','50',NULL,'OAI-PMH maximum number of records by answer to ListRecords and ListIdentifiers queries','Integer'), ('OCLCAffiliateID','','','Use with FRBRizeEditions and XISBN. You can sign up for an AffiliateID here: http://www.worldcat.org/wcpa/do/AffiliateUserServices?method=initSelfRegister','free'), +('OPACAcquisitionDetails','0','','Show the acquisition details at the OPAC','YesNo'), ('OpacAddMastheadLibraryPulldown','0','','Adds a pulldown menu to select the library to search on the opac masthead.','YesNo'), ('OPACAllowHoldDateInFuture','0','','If set, along with the AllowHoldDateInFuture system preference, OPAC users can set the date of a hold to be in the future.','YesNo'), ('OpacAllowPublicListCreation','1',NULL,'If set, allows opac users to create public lists','YesNo'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 78ba6ca..310e8ad 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8065,6 +8065,19 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } + +$DBversion = "3.15.00.XXX"; +if ( CheckVersion($DBversion) ) { + $dbh->do(q| + INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES('OPACAcquisitionDetails','0', '','Show the acquisition details at the OPAC','YesNo') + |); + print "Upgrade to $DBversion done (MT12445 - Add OPACAcquisitionDetails syspref)\n"; + SetVersion($DBversion); +} + + + + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index d541440..166a2b8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -436,7 +436,13 @@ OPAC: yes: Allow no: Do not allow - users to add a note when placing a hold. - + - + - pref: OPACAcquisitionDetails + default: 0 + choices: + yes: Display + no: Don't display + - the acquisition details on OPAC detail pages. Policy: - - pref: singleBranchMode diff --git a/koha-tmpl/opac-tmpl/prog/en/includes/item-status.inc b/koha-tmpl/opac-tmpl/prog/en/includes/item-status.inc index 21bde2c..b014caa 100644 --- a/koha-tmpl/opac-tmpl/prog/en/includes/item-status.inc +++ b/koha-tmpl/opac-tmpl/prog/en/includes/item-status.inc @@ -46,6 +46,8 @@ not use an API to fetch items that populates item.datedue. [% ELSE %] Item damaged [% END %] +[% ELSIF item.on_order %] + On order [% ELSE %] Available [% IF ( item.restrictedopac ) %]([% item.restrictedopac %])[% END %] [% END %] diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt index fce873c..8b6441f 100644 --- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt +++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-detail.tt @@ -985,6 +985,9 @@ YAHOO.util.Event.onContentReady("furtherm", function () { Subscriptions [% END %] +[% IF Koha.Preference('OPACAcquisitionDetails') and acquisition_details.orders.size > 0 %] +
  • Acquisition details
  • +[% END %] [% IF ( Koha.Preference( 'reviewson' ) == 1 ) %]
  • Comments ( [% reviews.size || 0 %] )
  • [% END %] @@ -1238,6 +1241,22 @@ YAHOO.util.Event.onContentReady("furtherm", function () { [% END %] + +[% IF Koha.Preference('OPACAcquisitionDetails') and acquisition_details.orders.size > 0 %] +
    +

    Acquisition details

    + [% IF Koha.Preference('AcqCreateItem') == 'ordering' %] + The following items are on order. + [% INCLUDE items_table items=acquisition_details.items tab="acquisition_details" noshelfbrowser=1 %] + [% ELSE %] + [% acquisition_details.total_quantity %] items are on order. + [% END %] +
    +[% END %] + + + + [% IF ( LibraryThingForLibrariesID ) %] [% IF ( LibraryThingForLibrariesTabbedView ) %] @@ -1558,7 +1577,7 @@ YAHOO.util.Event.onContentReady("furtherm", function () { [% IF ( ITEM_RESULT.itemcallnumber ) %] [% ITEM_RESULT.itemcallnumber %] - [% IF ( OPACShelfBrowser ) %] + [% IF ( OPACShelfBrowser and not noshelfbrowser ) %] [% IF ( ITEM_RESULT.itemnumber == starting_itemnumber ) %] (Browse shelf) [% ELSE %] diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 46f76fb..17e6ce3 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -25,6 +25,7 @@ use warnings; use CGI; use C4::Auth qw(:DEFAULT get_session); +use C4::Acquisition qw( SearchOrders ); use C4::Branch; use C4::Koha; use C4::Serials; #uses getsubscriptionfrom biblionumber @@ -487,16 +488,16 @@ if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) { my $dat = &GetBiblioData($biblionumber); -my $itemtypes = GetItemTypes(); +our $itemtypes = GetItemTypes(); # imageurl: my $itemtype = $dat->{'itemtype'}; if ( $itemtype ) { $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} ); $dat->{'description'} = $itemtypes->{$itemtype}->{'description'}; } -my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac'); -my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac'); -my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac'); +our $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac'); +our $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac'); +our $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac'); #coping with subscriptions my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); @@ -532,7 +533,7 @@ $dat->{'count'} = scalar(@items); my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) ); -my (%item_reserves, %priority); +our (%item_reserves, %priority); my ($show_holds_count, $show_priority); for ( C4::Context->preference("OPACShowHoldQueueDetails") ) { m/holds/o and $show_holds_count = 1; @@ -562,6 +563,7 @@ if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) { $template->param(SeparateHoldings => 1); } my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch'); + my $viewallitems = $query->param('viewallitems'); my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50; if ( not $viewallitems and @items > $max_items_to_display ) { @@ -571,50 +573,8 @@ if ( not $viewallitems and @items > $max_items_to_display ) { ); } else { for my $itm (@items) { - $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} }; - $itm->{priority} = $priority{ $itm->{itemnumber} }; - $norequests = 0 - if ( (not $itm->{'withdrawn'} ) - && (not $itm->{'itemlost'} ) - && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} ) - && (not $itemtypes->{$itm->{'itype'}}->{notforloan} ) - && ($itm->{'itemnumber'} ) ); + $itm = _get_items_infos( $itm ); - # get collection code description, too - my $ccode = $itm->{'ccode'}; - $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} ); - my $copynumber = $itm->{'copynumber'}; - $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) ); - if ( defined $itm->{'location'} ) { - $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} }; - } - if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) { - $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} ); - $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'}; - } - foreach (qw(ccode enumchron copynumber itemnotes uri)) { - $itemfields{$_} = 1 if ($itm->{$_}); - } - - # walk through the item-level authorised values and populate some images - my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) ); - # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) ); - - if ( $itm->{'itemlost'} ) { - my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images; - $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' }; - $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' }; - } - my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber}); - if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; } - if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; } - - my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber}); - if ( defined( $transfertwhen ) && $transfertwhen ne '' ) { - $itm->{transfertwhen} = $transfertwhen; - $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname}; - $itm->{transfertto} = $branches->{$transfertto}{branchname}; - } my $itembranch = $itm->{$separatebranch}; if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) { if ($itembranch and $itembranch eq $currentbranch) { @@ -1068,4 +1028,77 @@ if ( C4::Context->preference('UseCourseReserves') ) { } } +if ( C4::Context->preference('OPACAcquisitionDetails') ) { + my $orders = C4::Acquisition::SearchOrders({ + biblionumber => $biblionumber, + pending => 1, + }); + + my @items; + my $total_quantity; + for my $order ( @$orders ) { + if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) { + for my $itemnumber ( C4::Acquisition::GetItemnumbersFromOrder( $order->{ordernumber} ) ) { + my $item = C4::Items::GetItem( $itemnumber ); + $item->{on_order} = 1; + push @items, _get_items_infos( $item ); + } + } + $total_quantity += $order->{quantity}; + } + $template->{VARS}->{acquisition_details} = { + orders => $orders, + items => \@items, + total_quantity => $total_quantity, + }; +} + output_html_with_http_headers $query, $cookie, $template->output; + +sub _get_items_infos { + my ( $itm ) = @_; + $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} }; + $itm->{priority} = $priority{ $itm->{itemnumber} }; + $norequests = 0 + if ( (not $itm->{'withdrawn'} ) + && (not $itm->{'itemlost'} ) + && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} ) + && (not $itemtypes->{$itm->{'itype'}}->{notforloan} ) + && ($itm->{'itemnumber'} ) ); + + # get collection code description, too + my $ccode = $itm->{'ccode'}; + $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) ); + my $copynumber = $itm->{'copynumber'}; + $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) ); + if ( defined $itm->{'location'} ) { + $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} }; + } + if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) { + $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} ); + $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'}; + } + foreach (qw(ccode enumchron copynumber itemnotes uri)) { + $itemfields{$_} = 1 if ($itm->{$_}); + } + + # walk through the item-level authorised values and populate some images + my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) ); + + if ( $itm->{'itemlost'} ) { + my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images; + $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' }; + $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' }; + } + my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber}); + if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; } + if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; } + + my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber}); + if ( defined( $transfertwhen ) && $transfertwhen ne '' ) { + $itm->{transfertwhen} = $transfertwhen; + $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname}; + $itm->{transfertto} = $branches->{$transfertto}{branchname}; + } + return $itm; +} -- 1.7.2.5