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)
This commit is contained in:
hdl 2006-02-07 15:33:35 +00:00
parent 527ef4efc9
commit 620ce3f50e
6 changed files with 408 additions and 12 deletions

View File

@ -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
<select name="statusloop">
<option value="">Default</option>
<!-- TMPL_LOOP name="statusloop" -->
<option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="statusname" --></option>
<!-- /TMPL_LOOP -->
</select>
=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
<select name="location">
<option value="">Default</option>
<!-- TMPL_LOOP name="itemlocationloop" -->
<option value="<!-- TMPL_VAR name="locval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="locname" --></option>
<!-- /TMPL_LOOP -->
</select>
=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.
#

View File

@ -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;

View File

@ -61,7 +61,7 @@ Koha.pm provides many functions for Koha scripts.
&getframeworks &getframeworkinfo
&getauthtypes &getauthtype
&getallthemes &getalllanguages
&getallbranches
&getallbranches
$DEBUG);
use vars qw();

View File

@ -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;

View File

@ -32,7 +32,7 @@
<!-- TMPL_LOOP name="serialslist" -->
<tr>
<td>
<input type="text" name="serialseq" value="<!-- TMPL_VAR name="serialseq" -->" size=50 maxlength=100>
Issue <input type="text" name="serialseq" value="<!-- TMPL_VAR name="serialseq" -->" size=50 maxlength=100>
</td>
<td>
<input type="text" name="planneddate" value="<!-- TMPL_VAR name="planneddate" -->" size=10 maxlength=15>
@ -74,6 +74,46 @@
<input type="text" name="notes" value="<!-- TMPL_VAR name="notes" -->" size=20 maxlength=255>
</td>
</tr>
<!--TMPL_IF Name="serialadditems" -->
<tr>
<td>
Callnumber <input type="text" name="itemcallnumber" value="" size=10 maxlength=15>
Barcode <input type="text" name="barcode" value="" size=20 maxlength=20>
</td>
<td>
<select name="branch" size="1">
<option value="">Branch</option>
<!-- TMPL_LOOP name="branchloop" -->
<option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="branchname" --></option>
<!-- /TMPL_LOOP -->
</select>
</td>
<td>
<!--TMPL_IF Name="itemstatus"-->
<select name="status" size="1">
<option value="">Item Status</option>
<!-- TMPL_LOOP name="itemstatusloop" -->
<option value="<!-- TMPL_VAR name="itemval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="itemlib" --></option>
<!-- /TMPL_LOOP -->
</select>
<!-- TMPL_ELSE -->
&nbsp;
<!--/TMPL_IF-->
</td>
<td>
<!--TMPL_IF Name="itemlocation"-->
<select name="location" size="1">
<option value="">Location</option>
<!-- TMPL_LOOP name="itemlocationloop" -->
<option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="itemlocationname" --></option>
<!-- /TMPL_LOOP -->
</select>
<!-- TMPL_ELSE -->
&nbsp;
<!--/TMPL_IF-->
</td>
</tr>
<!--/TMPL_IF-->
<!-- /TMPL_LOOP -->
<!-- TMPL_UNLESS name="hassubscriptionexpired" -->
<tr>
@ -92,6 +132,46 @@
</select>
</td>
</tr>
<!--TMPL_IF Name="serialadditems" -->
<tr>
<td>
Callnumber <input type="text" name="itemcallnumber" value="" size=10 maxlength=15>
Barcode <input type="text" name="barcode" value="" size=20 maxlength=20>
</td>
<td>
<select name="branch" size="1">
<option value="">Branch</option>
<!-- TMPL_LOOP name="branchloop" -->
<option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="branchname" --></option>
<!-- /TMPL_LOOP -->
</select>
</td>
<td>
<!-- TMPL_IF Name="itemstatus"-->
<select name="status" size="1">
<option value="">Item Status</option>
<!-- TMPL_LOOP name="itemstatusloop" -->
<option value="<!-- TMPL_VAR name="itemval" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="itemlib" --></option>
<!-- /TMPL_LOOP -->
</select>
<!-- TMPL_ELSE -->
&nbsp;
<!--/TMPL_IF -->
</td>
<td>
<!-- TMPL_IF Name="itemlocation"-->
<select name="location" size="1">
<option value="">Location</option>
<!-- TMPL_LOOP name="itemlocationloop" -->
<option value="<!-- TMPL_VAR name="value" -->" <!-- TMPL_IF name="selected" -->selected<!-- /TMPL_IF -->><!-- TMPL_VAR name="itemlocationname" --></option>
<!-- /TMPL_LOOP -->
</select>
<!-- TMPL_ELSE -->
&nbsp;
<!--/TMPL_IF -->
</td>
</tr>
<!--/TMPL_IF-->
<!-- /TMPL_UNLESS -->
</table>
<input type="submit" value="Save changes" accesskey="w" class="button bull">

View File

@ -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.