@@ -, +, @@ receiving. received serial's itemtype is set as defined in the subscription. (Please note that the item-level_itypes syspref must be set to specific item.) It is also made available. --- C4/Items.pm | 9 ++++ C4/Serials.pm | 53 +++++++++++++++++++--- installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 29 ++++++++++++ .../prog/en/modules/admin/preferences/serials.pref | 6 +++ .../prog/en/modules/serials/serials-edit.tt | 6 +++ .../prog/en/modules/serials/subscription-add.tt | 28 ++++++++++++ serials/serials-edit.pl | 24 ++++++++++ serials/subscription-add.pl | 29 +++++++++++- 10 files changed, 179 insertions(+), 8 deletions(-) --- a/C4/Items.pm +++ a/C4/Items.pm @@ -2781,6 +2781,9 @@ sub PrepareItemrecordDisplay { while ( my ( $itemtype, $description ) = $sth->fetchrow_array ) { push @authorised_values, $itemtype; $authorised_lib{$itemtype} = $description; + + # If we have default value named itemtype or itemtypes, we use it + $defaultvalue = $itemtype if ($defaultvalues and ($defaultvalues->{'itemtypes'} eq $itemtype or $defaultvalues->{'itemtype'} eq $itemtype)); } #---- class_sources } elsif ( $tagslib->{$tag}->{$subfield}->{authorised_value} eq "cn_source" ) { @@ -2809,6 +2812,12 @@ sub PrepareItemrecordDisplay { while ( my ( $value, $lib ) = $authorised_values_sth->fetchrow_array ) { push @authorised_values, $value; $authorised_lib{$value} = $lib; + + # If we have a default value that has the same name as the authorised value category of the field, + # we use it + $defaultvalue = $value if ($defaultvalues and $defaultvalues->{$tagslib->{$tag}->{$subfield}->{authorised_value}} and $defaultvalues->{$tagslib->{$tag}->{$subfield}->{authorised_value}} eq $value); + + } } $subfield_data{marc_value} = CGI::scrolling_list( --- a/C4/Serials.pm +++ a/C4/Serials.pm @@ -50,6 +50,7 @@ BEGIN { &ReNewSubscription &GetLateIssues &GetLateOrMissingIssues &GetSerialInformation &AddItem2Serial &PrepareSerialsData &GetNextExpected &ModNextExpected + &GetPreviousSerialid &UpdateClaimdateIssues &GetSuppliersWithLateIssues &getsupplierbyserialid @@ -895,6 +896,39 @@ sub GetLatestSerials { return \@serials; } +=head2 GetPreviousSerialid + +$serialid = GetPreviousSerialid($subscriptionid, $nth) +get the $nth's previous serial for the given subscriptionid +return : +the serialid + +=cut + +sub GetPreviousSerialid { + my ( $subscriptionid, $nth ) = @_; + $nth ||= 1; + my $dbh = C4::Context->dbh; + my $return = undef; + + # Status 2: Arrived + my $strsth = "SELECT serialid + FROM serial + WHERE subscriptionid = ? + AND status = 2 + ORDER BY serialid DESC LIMIT $nth,1 + "; + my $sth = $dbh->prepare($strsth); + $sth->execute($subscriptionid); + my @serials; + my $line = $sth->fetchrow_hashref; + $return = $line->{'serialid'} if ($line); + + return $return; +} + + + =head2 GetDistributedTo $distributedto=GetDistributedTo($subscriptionid) @@ -1415,7 +1449,8 @@ sub ModSubscription { $lastvalue2, $innerloop2, $lastvalue3, $innerloop3, $status, $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, - $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq + $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq, + $itemtype, $previousitemtype ) = @_; my $dbh = C4::Context->dbh; @@ -1428,7 +1463,7 @@ sub ModSubscription { callnumber=?, notes=?, letter=?, manualhistory=?, internalnotes=?, serialsadditems=?, staffdisplaycount=?, opacdisplaycount=?, graceperiod=?, location = ?, enddate=?, - skip_serialseq=? + skip_serialseq=?, itemtype=?, previousitemtype=? WHERE subscriptionid = ?"; my $sth = $dbh->prepare($query); @@ -1442,6 +1477,7 @@ sub ModSubscription { $letter, ($manualhistory ? $manualhistory : 0), $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, + $itemtype, $previousitemtype, $subscriptionid ); my $rows = $sth->rows; @@ -1457,7 +1493,8 @@ $subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbu $lastvalue1,$innerloop1,$lastvalue2,$innerloop2,$lastvalue3,$innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, - $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq); + $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, + $skip_serialseq, $itemtype, $previousitemtype); Create a new subscription with value given on input args. @@ -1474,7 +1511,7 @@ sub NewSubscription { $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, - $location, $enddate, $skip_serialseq + $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype ) = @_; my $dbh = C4::Context->dbh; @@ -1487,8 +1524,9 @@ sub NewSubscription { lastvalue3, innerloop3, status, notes, letter, firstacquidate, irregularity, numberpattern, locale, callnumber, manualhistory, internalnotes, serialsadditems, staffdisplaycount, - opacdisplaycount, graceperiod, location, enddate, skip_serialseq) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) + opacdisplaycount, graceperiod, location, enddate, skip_serialseq, + itemtype, previousitemtype) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |; my $sth = $dbh->prepare($query); $sth->execute( @@ -1498,7 +1536,8 @@ sub NewSubscription { $lastvalue3, $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, - $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq + $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, + $itemtype, $previousitemtype ); my $subscriptionid = $dbh->{'mysql_insertid'}; --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -2097,6 +2097,8 @@ CREATE TABLE `subscription` ( `enddate` date default NULL, `closed` INT(1) NOT NULL DEFAULT 0, `reneweddate` date default NULL, + `itemtype` VARCHAR( 10 ) NULL, + `previousitemtype` VARCHAR( 10 ) NULL, PRIMARY KEY (`subscriptionid`), CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE, CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE --- a/installer/data/mysql/sysprefs.sql +++ a/installer/data/mysql/sysprefs.sql @@ -173,6 +173,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('LinkerOptions','','','A pipe-separated list of options for the linker.','free'), ('LinkerRelink','1',NULL,'If ON the authority linker will relink headings that have previously been linked every time it runs.','YesNo'), ('LocalCoverImages','0','1','Display local cover images on intranet details pages.','YesNo'), +('makePreviousSerialAvailable','0','','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','YesNo'), ('ManInvInNoissuesCharge','1',NULL,'MANUAL_INV charges block checkouts (added to noissuescharge).','YesNo'), ('MARCAuthorityControlField008','|| aca||aabn | a|a d',NULL,NULL,'Textarea'), ('MARCOrgCode','OSt','','Define MARC Organization Code - http://www.loc.gov/marc/organizations/orgshome.html','free'), --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -7912,6 +7912,35 @@ if ( CheckVersion($DBversion) ) { SetVersion($DBversion); } + + + + + + +$DBversion = "3.13.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(q{ + ALTER TABLE `subscription` ADD `itemtype` VARCHAR( 10 ) NULL, + ADD `previousitemtype` VARCHAR( 10 ) NULL + }); + print "Upgrade to $DBversion done (Bug 7677: Adds fields to subscription table)\n"; + SetVersion($DBversion); +} + +$DBversion = "3.13.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do( + "INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) VALUES ('makePreviousSerialAvailable','0','make previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item.','','YesNo');" + ); + + print "Upgrade to $DBversion done (Add makePreviousSerialAvailable syspref)\n"; + SetVersion($DBversion); +} + + + + =head1 FUNCTIONS =head2 TableExists($table) --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref @@ -50,3 +50,9 @@ Serials: - - List of fields which must not be rewritten when a subscription is duplicated (Separated by pipe |) - pref: SubscriptionDuplicateDroppedInput + - + - pref: makePreviousSerialAvailable + choices: + yes: Make + no: Do not make + - previous serial automatically available when collecting a new serial. Please note that the item-level_itypes syspref must be set to specific item. --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt @@ -59,6 +59,12 @@ function unHideItems(index,labelindex, serialId) { // Setting text field $(subfield_div).children("input[type='text'][name='field_value']").val($("#serialseq" + serialId).val()); + // Also prefilling copynumber + // Getting subfield with copynumber mapping + subfield_div = $(item_div).find("input[name='kohafield'][value='items.copynumber']").parent(); + // Setting text field + $(subfield_div).children("input[type='text'][name='field_value']").val($("#serialseq" + serialId).val()); + } function HideItems(index,labelindex) { subfield = document.getElementById(index); --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -608,6 +608,34 @@ $(document).ready(function() {
  • + + +
  • + [%IF makePreviousSerialAvailable %] +
  • + + +
  • + [% END %] +
  • day(s)
  • --- a/serials/serials-edit.pl +++ a/serials/serials-edit.pl @@ -90,6 +90,7 @@ if ( scalar(@subscriptionids) == 1 && index( $subscriptionids[0], q|,| ) > 0 ) { } my @errors; my @errseq; +my $dbh = C4::Context->dbh; # If user comes from subscription details unless (@serialids) { @@ -242,6 +243,29 @@ if ( $op and $op eq 'serialchangestatus' ) { $notes[$i] ); } + my $makePreviousSerialAvailable = C4::Context->preference('makePreviousSerialAvailable'); + if ($makePreviousSerialAvailable && $serialids[$i] ne "NEW") { + # We already have created the new expected serial at this point, so we get the second previous serial + my $previous = GetPreviousSerialid($subscriptionids[$i]); + if ($previous) { + + # Getting the itemnumber matching the serialid + my $query = "SELECT itemnumber FROM serialitems WHERE serialid=?"; + my $sth = $dbh->prepare($query); + $sth->execute($previous); + my @row = $sth->fetchrow_array; + if ($row[0]) { + my $itemnumber = $row[0]; + + # Getting the itemtype to set from the database + my $subscriptioninfos = GetSubscription($subscriptionids[$i]); + + # Changing the status to "available" and the itemtype according to the previousitemtype db field + ModItem({notforloan => 0, itype => $subscriptioninfos->{'previousitemtype'} }, undef, $itemnumber); + } + } + } + } my @moditems = $query->param('moditem'); if ( scalar(@moditems) ) { --- a/serials/subscription-add.pl +++ a/serials/subscription-add.pl @@ -151,6 +151,29 @@ $template->param(branchloop => $branchloop, locations_loop=>$locations_loop, ); # prepare template variables common to all $op conditions: +my $shelflocations = GetKohaAuthorisedValues( 'items.location', '' ); + +my @locationarg = + map { { code => $_, value => $shelflocations->{$_}, selected => ( ( $subs->{location} and $_ eq $subs->{location} ) ? "selected=\"selected\"" : "" ), } } sort keys %{$shelflocations}; + +my $typeloop = GetItemTypes(); + +my @typearg = + map { { code => $_, value => $typeloop->{$_}{'description'}, selected => ( ( $subs->{itemtype} and $_ eq $subs->{itemtype} ) ? "selected=\"selected\"" : "" ), } } sort keys %{$typeloop}; +my @previoustypearg = + map { { code => $_, value => $typeloop->{$_}{'description'}, selected => ( ( $subs->{previousitemtype} and $_ eq $subs->{previousitemtype} ) ? "selected=\"selected\"" : "" ), } } sort keys %{$typeloop}; + +$template->param( shelflocations => \@locationarg ); + +$template->param( + branchloop => $branchloop, + typeloop => \@typearg, + previoustypeloop => \@previoustypearg, + locations_loop=>$locations_loop, +); +# prepare template variables common to all $op conditions: +$template->param('makePreviousSerialAvailable' => 1) if (C4::Context->preference('makePreviousSerialAvailable')); + if ($op!~/^mod/) { letter_loop(q{}, $template); } @@ -313,6 +336,8 @@ sub redirect_add_subscription { my $staffdisplaycount = $query->param('staffdisplaycount'); my $opacdisplaycount = $query->param('opacdisplaycount'); my $location = $query->param('location'); + my $itemtype = $query->param('itemtype'); + my $previousitemtype = $query->param('previousitemtype'); my $skip_serialseq = $query->param('skip_serialseq'); my $startdate = format_date_in_iso( $query->param('startdate') ); my $enddate = format_date_in_iso( $query->param('enddate') ); @@ -381,6 +406,8 @@ sub redirect_mod_subscription { my $opacdisplaycount = $query->param('opacdisplaycount'); my $graceperiod = $query->param('graceperiod') || 0; my $location = $query->param('location'); + my $itemtype = $query->param('itemtype'); + my $previousitemtype = $query->param('previousitemtype'); my $skip_serialseq = $query->param('skip_serialseq'); # Guess end date @@ -408,7 +435,7 @@ sub redirect_mod_subscription { $status, $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, - $skip_serialseq + $skip_serialseq, $itemtype, $previousitemtype ); print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid"); --