From cb19ae8eb81cd847c17d18863d0cae023bb9a950 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Thu, 17 May 2012 21:06:48 -0400 Subject: [PATCH] Bug 6557: automatically increment totalissues Content-Type: text/plain; charset="UTF-8" Adds the ability to automatically increment biblioitems.totalissues whenever an item is issued. To test: 1) Choose a record with at least one item that can circulate 2) Check the value of 942$0 (you may need to look at the plain MARC view on the OPAC). Most likely there won't be any 942$0 at all 3) Enable UpdateTotalIssuesOnCirc 4) Check out the item you selected 5) Check the value of 942$0 (you may need to look at the plain MARC view on the OPAC). That value should now be one greater than before 6) Discharge the item 7) Disable UpdateTotalIssuesOnCirc 8) Check out the item you selected again 9) Check the value of 942$0 (you may need to look at the plain MARC view on the OPAC). That value should not have changed --- C4/Biblio.pm | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ C4/Circulation.pm | 3 +++ 2 files changed, 51 insertions(+), 0 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 5508cbe..42d445f 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -103,6 +103,7 @@ BEGIN { &ModBiblio &ModBiblioframework &ModZebra + &UpdateTotalIssues ); # To delete something @@ -3780,6 +3781,53 @@ sub prepare_host_field { return; } + +=head2 UpdateTotalIssues + + UpdateTotalIssues($biblionumber, $increase, [$value]) + +Update the total issue count for a particular bib record. + +=over 4 + +=item C<$biblionumber> is the biblionumber of the bib to update + +=item C<$increase> is the amount to increase (or decrease) the total issues count by + +=item C<$value> is the absolute value that total issues count should be set to. If provided, C<$increase> is ignored. + +=back + +=cut + +sub UpdateTotalIssues { + my ($biblionumber, $increase, $value) = @_; + my $totalissues; + + my $data = GetBiblioData($biblionumber); + + if (defined $value) { + $totalissues = $value; + } else { + $totalissues = $data->{'totalissues'} + $increase; + } + my ($totalissuestag, $totalissuessubfield) = GetMarcFromKohaField('biblioitems.totalissues', $data->{'frameworkcode'}); + + my $record = GetMarcBiblio($biblionumber); + + my $field = $record->field($totalissuestag); + if (defined $field) { + $field->update( $totalissuessubfield => $totalissues ); + } else { + $field = MARC::Field->new($totalissuestag, '0', '0', + $totalissuessubfield => $totalissues); + $record->insert_grouped_field($field); + } + + ModBiblio($record, $biblionumber, $data->{'frameworkcode'}); + return; +} + 1; diff --git a/C4/Circulation.pm b/C4/Circulation.pm index c26de76..b97cf6e 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -1059,6 +1059,9 @@ sub AddIssue { CartToShelf( $item->{'itemnumber'} ); } $item->{'issues'}++; + if ( C4::Context->preference('UpdateTotalIssuesOnCirc') ) { + UpdateTotalIssues($item->{'biblionumber'}, 1); + } ## If item was lost, it has now been found, reverse any list item charges if neccessary. if ( $item->{'itemlost'} ) { -- 1.7.2.5