From 7da670b895b20279114439db5e80b4a378ace800 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 13 Dec 2018 03:12:30 +0000 Subject: [PATCH] Bug 22188: Use publication date as numbering pattern Brimbank were trying to make a numbering pattern that displays the publication date, but numbering patterns are calculated mathematically, and dates are not always consistent and don't work that way. I've written a feature that hardcodes an option to use the publication date instead of a numbering pattern, in a 'Y M D' format. To test: 1) Go to Serials 2) Click New subscription 3) Fill in the necessary details for the first page and click Next 4) Fill in the necessary details for the second page. Under numbering pattern, select Number. 5) Notice the advanced pattern table shows. Put some random data in these fields 6) Change numbering pattern to Use publication date. Confirm that selecting this option hides the advanced pattern table and clears its fields. 7) Click Test prediction pattern and confirm the prediction pattern shows as expected 8) Save subscription 9) You should now be on the subscription detail page for your new subscription. Go to the Planning tab and confirm that it says 'uses publication date' under Number pattern and that there is now table saying 'Starting with' and 'Rollover' 10) Go to the Issues tab and confirm the first serial is there with the correct issue number (publication date). 11) Click the Receive button 12) Confirm the publication date shows under the Numbered column, in the Issue text field and click Save 13) Click the Generate next button and confirm the alert box 14) Confirm the publication date shows under 'Number' 15) Find/make a subscription that uses a normal numbering pattern 16) Edit this subscription to now use the publication date as numbering pattern 17) Upon saving, confirm that previously received serials keep their old issue numbers 18) Click Receive and Generate next again and confirm that the next serial now has the publication date 19) Confirm that making a subscription with a normal numbering pattern works as expected. Upon saving, the table should show under the Planning tab with 'Starting with' and 'Rollover' and all other fields should be filled correctly. Sponsored-by: Brimbank Libraries Australia --- C4/Serials.pm | 29 +++++++++++++++-- .../prog/en/modules/serials/subscription-add.tt | 1 + .../prog/en/modules/serials/subscription-detail.tt | 8 ++++- .../intranet-tmpl/prog/js/subscription-add.js | 36 ++++++++++++++++++++-- serials/serials-collection.pl | 15 +++++++-- serials/showpredictionpattern.pl | 9 ++++++ serials/subscription-add.pl | 9 ++++++ 7 files changed, 100 insertions(+), 7 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index f2290f4..cbe4a99 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -859,8 +859,13 @@ sub GetNextSeq { } } - my $numberingmethod = $pattern->{numberingmethod}; my $calculated = ""; + my $numberingmethod = ""; + if ($pattern eq "pubdate"){ + $calculated = dt_from_string( $planneddate )->strftime( '%Y %B %d' ); + } else { + $numberingmethod = $pattern->{numberingmethod}; + } if ($numberingmethod) { $calculated = $numberingmethod; my $locale = $subscription->{locale}; @@ -940,6 +945,10 @@ the sequence in string format sub GetSeq { my ($subscription, $pattern) = @_; + if ($pattern->{numberingmethod} eq ''){ + return "pubdate"; + } + return unless ($subscription and $pattern); my $locale = $subscription->{locale}; @@ -1147,6 +1156,19 @@ sub ModSerialStatus { my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); + my $nextpublisheddate = GetNextDate($subscription, $publisheddate, 1); + my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, + $newinnerloop1, $newinnerloop2, $newinnerloop3 ); + + if (!defined $pattern){ + $pattern = "pubdate"; + ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, + $newinnerloop1, $newinnerloop2, $newinnerloop3 ) = GetNextSeq( $subscription, $pattern, $nextpublisheddate ); + } else { + ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, + $newinnerloop1, $newinnerloop2, $newinnerloop3 ) = GetNextSeq( $subscription, $pattern, $publisheddate ); + } + # next issue number my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, @@ -1155,7 +1177,6 @@ sub ModSerialStatus { = GetNextSeq( $subscription, $pattern, $frequency, $publisheddate ); # next date (calculated from actual date & frequency parameters) - my $nextpublisheddate = GetNextDate($subscription, $publisheddate, $frequency, 1); my $nextpubdate = $nextpublisheddate; $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? WHERE subscriptionid = ?"; @@ -1437,6 +1458,10 @@ sub NewSubscription { # calculate issue number my $serialseq = GetSeq($subscription, $pattern) || q{}; + if ($serialseq eq "pubdate"){ + $serialseq = dt_from_string( $firstacquidate )->strftime('%Y %B %d'); + } + Koha::Serial->new( { serialseq => $serialseq, 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 eff55ae..3db8384 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 @@ -316,6 +316,7 @@ fieldset.rows table { clear: none; margin: 0; } [% numberpattern.label | html %] [% END %] + Required diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt index 983a7a8..41e7746 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt @@ -166,8 +166,13 @@ [% END %]
  • Number pattern: - [% numberpattern.label | html %] + [% IF ( numberpattern ) %] + [% numberpattern.label | html %] + [% ELSE %] + Uses publication date + [% END %]
  • + [% IF ( numberpattern ) %]
  • @@ -194,6 +199,7 @@ [% END %]
    Starting with:
  • + [% END %] [% IF ( irregular_issues ) %]
  • Irregularity: [% irregular_issues | html %] issues
  • diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js index 4c6bf22..bf096ce 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js +++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js @@ -227,6 +227,24 @@ function modifyAdvancedPattern() { advancedpatternlocked = 0; } +function clearAdvancedPattern() { + $("#patternname").prop('readOnly', false).val(''); + $("#numberingmethod").prop('readOnly', false).val(''); + + $("#advancedpredictionpatternt input").each(function() { + $(this).prop('readOnly', false).val(''); + }); + $("#advancedpredictionpatternt select").each(function() { + $(this).prop('disabled', false).val(''); + }); + + $("#restoreadvancedpatternbutton").hide(); + $("#saveadvancedpatternbutton").hide(); + $("#modifyadvancedpatternbutton").hide(); + + advancedpatternlocked = 1; +} + function restoreAdvancedPattern() { $("#patternname").prop('readOnly', true).val(globalnumpatterndata.label); $("#numberingmethod").prop('readOnly', true).val(globalnumpatterndata.numberingmethod); @@ -529,6 +547,15 @@ function hidePredcitionPatternTest(){ $("#page_2 > div").attr("class","col-md-10 col-md-offset-1 col-lg-8 col-lg-offset-2"); } +function usedatepattern() { + $("#more_options").hide(); + clearAdvancedPattern(); + if ($("#advancedpredictionpattern").is(":visible")){ + $("#advancedpredictionpattern").toggle(); + $(".toggle_advanced_pattern").toggle(); + } +} + $(document).ready(function() { if ( mana_enabled == 1 ) { mana_search(); @@ -561,7 +588,12 @@ $(document).ready(function() { }); $("select#numberpattern").change(function(){ patternneedtobetested = 1; - numberpatternload(); + console.log($("select#numberpattern").val()); + if ($("select#numberpattern").val() == "0"){ + usedatepattern(); + } else { + numberpatternload(); + } }); $("#subtype").change(function(){ $("input[name='enddate']").val(''); @@ -610,7 +642,7 @@ $(document).ready(function() { if($("#frequency").val() != ""){ frequencyload(); } - if($("#numberpattern").val() != ""){ + if($("#numberpattern").val() != "0" && $("#numberpattern").val() != ""){ numberpatternload(); } diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl index d9ab11a..795950f 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -84,6 +84,10 @@ if($op eq 'gennext' && @subscriptionid){ $newinnerloop1, $newinnerloop2, $newinnerloop3 ) = GetNextSeq($subscription, $pattern, $frequency, $expected->{publisheddate}); + if (!defined $pattern && !defined $newserialseq){ + $newserialseq = $expected->{publisheddate}; + } + ## We generate the next publication date $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subscription->{periodicity}); my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, $frequency, 1); @@ -127,8 +131,11 @@ if (@subscriptionid){ $location = $subs->{'location'}; $callnumber = $subs->{callnumber}; my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subs->{periodicity}); - my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern}); $subs->{frequency} = $frequency; + my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern}); + if (!defined $numberpattern){ + $numberpattern->{label} = "Uses publication date"; + } $subs->{numberpattern} = $numberpattern; $subs->{'hasRouting'} = check_routing($subscriptionid); push @$subscriptiondescs,$subs; @@ -147,7 +154,11 @@ if (@subscriptionid){ my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($s->{periodicity}); my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($s->{numberpattern}); $s->{frequency} = $frequency; - $s->{numberpattern} = $numberpattern; + if (!defined $numberpattern){ + $numberpattern->{label} = "pubdate"; + } else { + $s->{numberpattern} = $numberpattern; + } } my $subscriptioninformation = GetFullSubscriptionsFromBiblionumber($biblionumber); $subscriptions=PrepareSerialsData($subscriptioninformation); diff --git a/serials/showpredictionpattern.pl b/serials/showpredictionpattern.pl index 4a3f7b2..3b3e492 100755 --- a/serials/showpredictionpattern.pl +++ b/serials/showpredictionpattern.pl @@ -31,6 +31,7 @@ publication date, based on frequency and first publication date. use Modern::Perl; use CGI qw ( -utf8 ); +use POSIX qw(strftime); use Date::Calc qw(Today Day_of_Year Week_of_Year Day_of_Week Days_in_Year Delta_Days Add_Delta_Days Add_Delta_YM); use C4::Auth; use C4::Output; @@ -125,6 +126,11 @@ if(defined $subscriptionid) { my @predictions_loop; my ($calculated) = GetSeq(\%subscription, \%pattern); + +if ($calculated eq "pubdate"){ + $calculated = dt_from_string( $date )->strftime('%Y %B %d'); +} + push @predictions_loop, { number => $calculated, publicationdate => $date, @@ -172,6 +178,9 @@ while( $i < 1000 ) { ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern, $frequency); $issuenumber++; $line{'number'} = $calculated; + if ($calculated eq ''){ + $line{'number'} = dt_from_string( $date )->strftime('%Y %B %d'); + } $line{'issuenumber'} = $issuenumber; if(@irreg && $issuenumber == $irreg[0]){ $line{'not_published'} = 1; diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index ebc19a0..82c8c8d 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -367,6 +367,11 @@ sub redirect_add_subscription { $enddate = _guess_enddate($startdate, $periodicity, $numberlength, $weeklength, $monthlength) } } + + if ($numberpattern == "0"){ # using publication date as numbering pattern + $numberpattern = undef; + } + my $subscriptionid = NewSubscription( $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, $startdate, $periodicity, $numberlength, $weeklength, @@ -490,6 +495,10 @@ sub redirect_mod_subscription { $firstissuedate = $nextacquidate if($nextexpected->{isfirstissue}); } + if ($numberpattern == "0"){ # using publication date as numbering pattern + $numberpattern = undef; + } + ModSubscription( $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, $periodicity, $firstacquidate, join(";",@irregularity), -- 2.1.4