From 4f1ef515f6d387eeb18f559c13ebad911f5626f9 Mon Sep 17 00:00:00 2001 From: Matthias Meusburger Date: Thu, 9 Jan 2014 17:06:14 +0100 Subject: [PATCH] BZ7677: New areas in subscriptions and new functions when receiving. When enabling the makePreviousSerialAvailable syspref, the previously 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/Serials.pm | 53 +++++++++++++++++++--- installer/data/mysql/kohastructure.sql | 2 + installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 17 +++++++ .../prog/en/modules/admin/preferences/serials.pref | 6 +++ .../prog/en/modules/serials/serials-edit.tt | 1 - .../prog/en/modules/serials/subscription-add.tt | 28 ++++++++++++ serials/serials-edit.pl | 24 ++++++++++ serials/subscription-add.pl | 22 ++++++++- 9 files changed, 145 insertions(+), 9 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index d127066..44d57b8 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -51,6 +51,7 @@ BEGIN { &ReNewSubscription &GetLateIssues &GetLateOrMissingIssues &GetSerialInformation &AddItem2Serial &PrepareSerialsData &GetNextExpected &ModNextExpected + &GetPreviousSerialid &UpdateClaimdateIssues &GetSuppliersWithLateIssues &getsupplierbyserialid @@ -899,6 +900,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) @@ -1389,7 +1423,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; @@ -1402,7 +1437,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); @@ -1416,6 +1451,7 @@ sub ModSubscription { $letter, ($manualhistory ? $manualhistory : 0), $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, + $itemtype, $previousitemtype, $subscriptionid ); my $rows = $sth->rows; @@ -1431,7 +1467,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. @@ -1448,7 +1485,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; @@ -1461,8 +1498,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( @@ -1472,7 +1510,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'}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 4ffbbf2..f44aec8 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2131,6 +2131,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 diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index c3e308f..b772e9b 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -193,6 +193,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('LocalHoldsPriority', '0', NULL, 'Enables the LocalHoldsPriority feature', 'YesNo'), ('LocalHoldsPriorityItemControl', 'holdingbranch', 'holdingbranch|homebranch', 'decides if the feature operates using the item''s home or holding library.', 'Choice'), ('LocalHoldsPriorityPatronControl', 'PickupLibrary', 'HomeLibrary|PickupLibrary', 'decides if the feature operates using the library set as the patron''s home library, or the library set as the pickup library for the given hold.', 'Choice'), +('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,'Define the contents of MARC21 authority control field 008 position 06-39','Textarea'), ('MarcFieldsToOrder','',NULL,'Set the mapping values for a new order line created from a MARC record in a staged file. In a YAML format.','textarea'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index cf17e0b..3bdd9cb 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -9585,6 +9585,23 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } + + + +$DBversion = "3.19.00.XXX"; +if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { + $dbh->do(q{ + ALTER TABLE `subscription` ADD `itemtype` VARCHAR( 10 ) NULL AFTER reneweddate, + ADD `previousitemtype` VARCHAR( 10 ) NULL AFTER itemtype + }); + $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 (Bug 7677: Adds fields to subscription table and makePreviousSerialAvailable syspref)\n"; + SetVersion($DBversion); +} + + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref index db727b6..b898394 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/serials.pref +++ b/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. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt index 3877715..df02b84 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/serials-edit.tt @@ -59,7 +59,6 @@ function unHideItems(index,labelindex, serialId) { subfield_div = $(item_div).find("input[name='kohafield'][value='items.enumchron']").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); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt index e69649c..8972bee 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -594,6 +594,34 @@ $(document).ready(function() {
  • + + +
  • + [%IF makePreviousSerialAvailable %] +
  • + + +
  • + [% END %] +
  • day(s)
  • diff --git a/serials/serials-edit.pl b/serials/serials-edit.pl index 2eeed10..89c002e 100755 --- a/serials/serials-edit.pl +++ b/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) ) { diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index b17fc60..92279f6 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -153,7 +153,23 @@ my $locations_loop = GetAuthorisedValues("LOC",$subs->{'location'}); $template->param(branchloop => $branchloop, locations_loop=>$locations_loop, ); + +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( + 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/) { my $letters = get_letter_loop(); $template->param( letterloop => $letters ); @@ -318,6 +334,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') ); @@ -386,6 +404,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 @@ -413,7 +433,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"); -- 2.1.0