From 620ce3f50e47a8ac3ef89e0095cb97abeab7796f Mon Sep 17 00:00:00 2001 From: hdl Date: Tue, 7 Feb 2006 15:33:35 +0000 Subject: [PATCH] Adding a new system preference : serialsadditem Adding two functions in Biblio.pm : getitemlocation and getitemstatus (helpful to get location list and status list, status is supposed to be in relation with items.notforloan) Adding a new function in Bull.pm : serialsitemize which take serial id and item information and creates the item Modifying statecollection to add a new line (used for data input) --- C4/Biblio.pm | 133 ++++++++++++++++++ C4/Bull.pm | 99 ++++++++++++- C4/Koha.pm | 2 +- bull/statecollection.pl | 87 ++++++++++-- .../default/en/bull/statecollection.tmpl | 82 ++++++++++- updater/updatedatabase | 17 +++ 6 files changed, 408 insertions(+), 12 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index bb79925d9f..9e02deb892 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -72,6 +72,8 @@ $VERSION = 0.01; &FindDuplicate &DisplayISBN + &getitemstatus + &getitemlocation ); # @@ -2778,6 +2780,129 @@ sub DisplayISBN { return "$seg1-$seg2-$seg3-$seg4"; } +=head2 getitemstatus + + $itemstatushash = &getitemstatus($fwkcode); + returns information about status. + Can be MARC dependant. + fwkcode is optional. + But basically could be can be loan or not + Create a status selector with the following code + +=head3 in PERL SCRIPT + +my $itemstatushash = getitemstatus; +my @itemstatusloop; +foreach my $thisstatus (keys %$itemstatushash) { + my %row =(value => $thisstatus, + statusname => $itemstatushash->{$thisstatus}->{'statusname'}, + ); + push @itemstatusloop, \%row; +} +$template->param(statusloop=>\@itemstatusloop); + + +=head3 in TEMPLATE + + +=cut +sub getitemstatus { +# returns a reference to a hash of references to status... + my ($fwk)=@_; + my %itemstatus; + my $dbh = C4::Context->dbh; + my $sth; + $fwk='' unless ($fwk); + my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.notforloan",$fwk); + if ($tag and $subfield){ + my $sth = $dbh->prepare("select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"); + $sth->execute($tag,$subfield,$fwk); + if (my ($authorisedvaluecat)=$sth->fetchrow){ + my $authvalsth=$dbh->prepare("select authorised_value, lib from authorised_values where category=? order by lib"); + $authvalsth->execute($authorisedvaluecat); + while (my ($authorisedvalue, $lib)=$authvalsth->fetchrow){ + $itemstatus{$authorisedvalue}=$lib; + } + $authvalsth->finish; + return \%itemstatus; + exit 1; + } else{ + #No authvalue list + # build default + } + $sth->finish; + } + #No authvalue list + #build default + $itemstatus{"1"}="Not For Loan"; + return \%itemstatus; +} +=head2 getitemlocation + + $itemlochash = &getitemlocation($fwk); + returns informations about location. + where fwk stands for an optional framework code. + Create a location selector with the following code + +=head3 in PERL SCRIPT + +my $itemlochash = getitemlocation; +my @itemlocloop; +foreach my $thisloc (keys %$itemlochash) { + my $selected = 1 if $thisbranch eq $branch; + my %row =(locval => $thisloc, + selected => $selected, + locname => $itemlochash->{$thisloc}, + ); + push @itemlocloop, \%row; +} +$template->param(itemlocationloop => \@itemlocloop); + +=head3 in TEMPLATE + + +=cut +sub getitemlocation { +# returns a reference to a hash of references to location... + my ($fwk)=@_; + my %itemlocation; + my $dbh = C4::Context->dbh; + my $sth; + $fwk='' unless ($fwk); + my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.location",$fwk); + if ($tag and $subfield){ + my $sth = $dbh->prepare("select authorised_value from marc_subfield_structure where tagfield=? and tagsubfield=? and frameworkcode=?"); + $sth->execute($tag,$subfield,$fwk); + if (my ($authorisedvaluecat)=$sth->fetchrow){ + my $authvalsth=$dbh->prepare("select authorised_value, lib from authorised_values where category=? order by lib"); + $authvalsth->execute($authorisedvaluecat); + while (my ($authorisedvalue, $lib)=$authvalsth->fetchrow){ + $itemlocation{$authorisedvalue}=$lib; + } + $authvalsth->finish; + return \%itemlocation; + exit 1; + } else{ + #No authvalue list + # build default + } + $sth->finish; + } + #No authvalue list + #build default + $itemlocation{"1"}="Not For Loan"; + return \%itemlocation; +} END { } # module clean-up code here (global destructor) @@ -2793,6 +2918,14 @@ Paul POULAIN paul.poulain@free.fr # $Id$ # $Log$ +# Revision 1.115.2.29 2006/02/07 15:33:35 hdl +# Adding a new system preference : serialsadditem +# +# Adding two functions in Biblio.pm : getitemlocation and getitemstatus (helpful to get location list and status list, status is supposed to be in relation with items.notforloan) +# +# Adding a new function in Bull.pm : serialsitemize which take serial id and item information and creates the item +# Modifying statecollection to add a new line (used for data input) +# # Revision 1.115.2.28 2006/01/30 16:06:26 hdl # BugFix : leader management was annoying for MARCadditem. Changing. Avoiding fields which tag is under 100. (Could be a simple different from 000) But in UNIMARC, fields under 100 donot have subfields. # diff --git a/C4/Bull.pm b/C4/Bull.pm index db49451fe6..9bbe792f1b 100755 --- a/C4/Bull.pm +++ b/C4/Bull.pm @@ -22,6 +22,8 @@ use strict; use C4::Date; use Date::Manip; use C4::Suggestions; +use C4::Biblio; +use C4::Search; require Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); @@ -47,7 +49,7 @@ Give all XYZ functions @EXPORT = qw(&newsubscription &modsubscription &delsubscription &getsubscriptions &getsubscription &getsubscriptionfrombiblionumber &get_subscription_list_from_biblionumber &get_full_subscription_list_from_biblionumber - &modsubscriptionhistory &newissue + &modsubscriptionhistory &newissue &serialsitemize &getserials &getlatestserials &serialchangestatus &Find_Next_Date, &Get_Next_Seq &hassubscriptionexpired &subscriptionexpirationdate &subscriptionrenew @@ -450,6 +452,100 @@ sub newissue { $sth->execute($recievedlist,$missinglist,$subscriptionid); } +=head2 serialsitemize + + serialitemize($serialid, $info); + $info is a hashref containing barcode branch, itemcallnumber, status, location + $serialid the serialid +=cut +sub serialsitemize { + my ($serialid, $info) =@_; + + my $dbh= C4::Context->dbh; + my $sth=$dbh->prepare("SELECT * from serial WHERE serialid=?"); + $sth->execute($serialid); + my $data=$sth->fetchrow_hashref; + my $bibid=MARCfind_MARCbibid_from_oldbiblionumber($dbh,$data->{biblionumber}); + my $fwk=MARCfind_frameworkcode($dbh,$bibid); + if ($info->{barcode}){ + my @errors; + my $exists = itemdata($info->{'barcode'}); + push @errors,"barcode_not_unique" if($exists); + unless ($exists){ + my $marcrecord = MARC::Record->new(); + my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.barcode",$fwk); + warn "items.barcode : $tag , $subfield"; + my $newField = MARC::Field->new( + "$tag",'','', + "$subfield" => $info->{barcode} + ); + $marcrecord->insert_fields_ordered($newField); + if ($info->{branch}){ + my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.homebranch",$fwk); + warn "items.homebranch : $tag , $subfield"; + if ($marcrecord->field($tag)) { + $marcrecord->field($tag)->add_subfields("$subfield" => $info->{branch}) + }else { + my $newField = MARC::Field->new( + "$tag",'','', + "$subfield" => $info->{branch} + ); + $marcrecord->insert_fields_ordered($newField); + } + my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.holdingbranch",$fwk); + if ($marcrecord->field($tag)) { + $marcrecord->field($tag)->add_subfields("$subfield" => $info->{branch}) + }else { + my $newField = MARC::Field->new( + "$tag",'','', + "$subfield" => $info->{branch} + ); + $marcrecord->insert_fields_ordered($newField); + } + } + if ($info->{notes}){ + my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.itemnotes",$fwk); + if ($marcrecord->field($tag)) { + $marcrecord->field($tag)->add_subfields("$subfield" => $info->{notes}) + }else { + my $newField = MARC::Field->new( + "$tag",'','', + "$subfield" => $info->{notes} + ); + $marcrecord->insert_fields_ordered($newField); + } + } + if ($info->{location}){ + my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.location",$fwk); + if ($marcrecord->field($tag)) { + $marcrecord->field($tag)->add_subfields("$subfield" => $info->{location}) + }else { + my $newField = MARC::Field->new( + "$tag",'','', + "$subfield" => $info->{location} + ); + $marcrecord->insert_fields_ordered($newField); + } + } + if ($info->{status}){ + my ($tag,$subfield)=MARCfind_marc_from_kohafield($dbh,"items.notforloan",$fwk); + if ($marcrecord->field($tag)) { + $marcrecord->field($tag)->add_subfields("$subfield" => $info->{status}) + }else { + my $newField = MARC::Field->new( + "$tag",'','', + "$subfield" => $info->{status} + ); + $marcrecord->insert_fields_ordered($newField); + } + } + NEWnewitem($dbh,$marcrecord,$bibid); + return 1; + } + return (0,@errors); + } +} + sub delissue { my ($serialseq,$subscriptionid) = @_; my $dbh = C4::Context->dbh; @@ -457,6 +553,7 @@ sub delissue { $sth->execute($serialseq,$subscriptionid); } + sub Get_Next_Date(@) { my ($planneddate,$subscription) = @_; my $resultdate; diff --git a/C4/Koha.pm b/C4/Koha.pm index 2a6e6db828..30946f0c27 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -61,7 +61,7 @@ Koha.pm provides many functions for Koha scripts. &getframeworks &getframeworkinfo &getauthtypes &getauthtype &getallthemes &getalllanguages - &getallbranches + &getallbranches $DEBUG); use vars qw(); diff --git a/bull/statecollection.pl b/bull/statecollection.pl index 8fc0aa113a..a43c1c27f7 100755 --- a/bull/statecollection.pl +++ b/bull/statecollection.pl @@ -4,6 +4,8 @@ use strict; use CGI; use C4::Auth; use C4::Date; +use C4::Biblio; +use C4::Koha; use C4::Output; use C4::Interface::CGI::Output; use C4::Context; @@ -26,8 +28,15 @@ my @serialseqs = $query->param('serialseq'); my @planneddates = $query->param('planneddate'); my @status = $query->param('status'); my @notes = $query->param('notes'); +my @barcodes = $query->param('barcode'); +my @itemcallnumbers = $query->param('itemcallnumber'); +my @locations = $query->param('location'); +my @itemstatus = $query->param('itemstatus'); +my @homebranches = $query->param('branch'); my $hassubscriptionexpired = hassubscriptionexpired($subscriptionid); my $subscription=getsubscription($subscriptionid); + + if ($op eq 'modsubscriptionhistory') { modsubscriptionhistory($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote); } @@ -36,23 +45,39 @@ if ($op eq 'serialchangestatus') { my $sth = $dbh->prepare("select status from serial where serialid=?"); for (my $i=0;$i<=$#serialids;$i++) { $sth->execute($serialids[$i]); + my ($oldstatus) = $sth->fetchrow; if ($serialids[$i]) { serialchangestatus($serialids[$i],$serialseqs[$i],format_date_in_iso($planneddates[$i]),$status[$i],$notes[$i]) unless ($hassubscriptionexpired && $oldstatus == 1); + if (($status[$i]==2) && C4::Context->preference("serialsadditems")){ + my %info; + $info{branch}=$homebranches[$i]; + $info{barcode}=$barcodes[$i]; + $info{itemcallnumber}=$itemcallnumbers[$i]; + $info{location}=$locations[$i]; + $info{status}=$itemstatus[$i]; + $info{notes}=$serialseqs[$i]; + my ($status, @errors)= serialsitemize($serialids[$i],\%info); + } } else { # add a special issue if ($serialseqs[$i]) { newissue($serialseqs[$i],$subscriptionid,$subscription->{biblionumber},$status[$i], format_date_in_iso($planneddates[$i])); } + if (($status[$i]==2) && C4::Context->preference("serialsadditems")){ + my %info; + $info{branch}=$homebranches[$i]; + $info{barcode}=$barcodes[$i]; + $info{itemcallnumber}=$itemcallnumbers[$i]; + $info{location}=$locations[$i]; + $info{status}=$itemstatus[$i]; + $info{notes}=$serialseqs[$i]; + my ($status, @errors)= serialsitemize($serialids[$i],\%info); + } + } } } -my $subs = &getsubscription($subscriptionid); -my ($totalissues,@serialslist) = getserials($subscriptionid); - -my $sth=$dbh->prepare("select * from subscriptionhistory where subscriptionid = ?"); -$sth->execute($subscriptionid); -my $solhistory = $sth->fetchrow_hashref; my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "bull/statecollection.tmpl", query => $query, @@ -62,7 +87,51 @@ my ($template, $loggedinuser, $cookie) debug => 1, }); - $template->param( +my $subs = &getsubscription($subscriptionid); +my ($totalissues,@serialslist) = getserials($subscriptionid); +my $branches = getbranches; +my @branchloop; +foreach my $thisbranch (keys %$branches) { + my %row =(value => $thisbranch, + branchname => $branches->{$thisbranch}->{'branchname'}, + ); + push @branchloop, \%row; +} + +my $itemstatushash = getitemstatus; +my @itemstatusloop; +foreach my $thisitemstatus (keys %$itemstatushash) { + my %row =(itemval => $thisitemstatus, + itemlib => $itemstatushash->{$thisitemstatus}, + ); + warn "".$row{'itemval'}.", ". $row{"itemlib"}; + push @itemstatusloop, \%row; +} + +my $itemlocationhash = getitemlocation; +my @itemlocationloop; +foreach my $thisitemlocation (keys %$itemlocationhash) { + my %row =(value => $thisitemlocation, + itemlocationname => $itemlocationhash->{$thisitemlocation}, + ); + push @itemlocationloop, \%row; +} + +foreach my $data (@serialslist){ + $data->{"itemstatusloop"}=\@itemstatusloop if ((C4::Context->preference("serialsadditems")) && scalar(@itemstatusloop)); + $data->{"itemlocationloop"}=\@itemlocationloop if ((C4::Context->preference("serialsadditems")) && scalar(@itemlocationloop)); + $data->{"branchloop"}=\@branchloop; + } +my $sth=$dbh->prepare("select * from subscriptionhistory where subscriptionid = ?"); +$sth->execute($subscriptionid); +my $solhistory = $sth->fetchrow_hashref; + +$template->param(serialadditems =>C4::Context->preference("serialsadditems"), + branchloop => \@branchloop, + ) if (C4::Context->preference("serialsadditems")); +$template->param(itemstatus=>1,itemstatusloop=>\@itemstatusloop) if ((C4::Context->preference("serialsadditems")) && scalar(@itemstatusloop)); +$template->param(itemlocation=>1,itemlocationloop=>\@itemlocationloop) if ((C4::Context->preference("serialsadditems")) && scalar(@itemlocationloop)); +$template->param( serialslist => \@serialslist, biblionumber => $subscription->{biblionumber}, histstartdate => format_date($solhistory->{'histstartdate'}), @@ -76,7 +145,7 @@ my ($template, $loggedinuser, $cookie) biblionumber => $subs->{biblionumber}, hassubscriptionexpired =>$hassubscriptionexpired, intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), - intranetstylesheet => C4::Context->preference("intranetstylesheet"), - IntranetNav => C4::Context->preference("IntranetNav"), + intranetstylesheet => C4::Context->preference("intranetstylesheet"), + IntranetNav => C4::Context->preference("IntranetNav"), ); output_html_with_http_headers $query, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/default/en/bull/statecollection.tmpl b/koha-tmpl/intranet-tmpl/default/en/bull/statecollection.tmpl index e53f1b13eb..d784b79c6b 100644 --- a/koha-tmpl/intranet-tmpl/default/en/bull/statecollection.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/bull/statecollection.tmpl @@ -32,7 +32,7 @@ - " size=50 maxlength=100> + Issue " size=50 maxlength=100> " size=10 maxlength=15> @@ -74,6 +74,46 @@ " size=20 maxlength=255> + + + + Callnumber + Barcode + + + + + + + + +   + + + + + + +   + + + + @@ -92,6 +132,46 @@ + + + + Callnumber + Barcode + + + + + + + + +   + + + + + + +   + + + + diff --git a/updater/updatedatabase b/updater/updatedatabase index 4d0830c624..38dbb7ad9b 100755 --- a/updater/updatedatabase +++ b/updater/updatedatabase @@ -1023,6 +1023,15 @@ my %tabledata = ( explanation => 'Put any HTML Credits at the bottom of the OPAC page', type => 'free', }, + { + uniquefieldrequired => 'variable', + variable => 'serialsadditems', + value => '1', + forceupdate => { 'explanation' => 1, ' + type' => 1}, + explanation => 'If set, a new item will be automatically added when receiving an issue', + type => 'YesNo', + }, ], ); @@ -1650,6 +1659,14 @@ $sth->finish; exit; # $Log$ +# Revision 1.100.2.23 2006/02/07 15:33:35 hdl +# Adding a new system preference : serialsadditem +# +# Adding two functions in Biblio.pm : getitemlocation and getitemstatus (helpful to get location list and status list, status is supposed to be in relation with items.notforloan) +# +# Adding a new function in Bull.pm : serialsitemize which take serial id and item information and creates the item +# Modifying statecollection to add a new line (used for data input) +# # Revision 1.100.2.22 2006/02/05 21:53:54 kados # Adds database support for IntranetNav systempref -- used to add HTML # tags to left-hand navigation menu on Intranet. -- 2.39.5