From bb8a00b2b248d77139ed7706e1572d8b1aed897c 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 | 34 +++++++++++++++---- .../prog/en/modules/serials/subscription-add.tt | 1 + .../prog/en/modules/serials/subscription-detail.tt | 8 ++++- .../intranet-tmpl/prog/js/subscription-add.js | 38 ++++++++++++++++++++-- serials/serials-collection.pl | 15 +++++++-- serials/showpredictionpattern.pl | 9 +++++ serials/subscription-add.pl | 8 +++++ 7 files changed, 100 insertions(+), 13 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 91498ee..89feea3 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -862,8 +862,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}; @@ -943,6 +948,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}; @@ -1150,15 +1159,22 @@ sub ModSerialStatus { my $subscription = GetSubscription($subscriptionid); my $pattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subscription->{numberpattern}); + 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, - $newinnerloop1, $newinnerloop2, $newinnerloop3 - ) - = GetNextSeq( $subscription, $pattern, $publisheddate ); # next date (calculated from actual date & frequency parameters) - my $nextpublisheddate = GetNextDate($subscription, $publisheddate, 1); my $nextpubdate = $nextpublisheddate; $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? WHERE subscriptionid = ?"; @@ -1424,6 +1440,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 edab9b3..5cee0c5 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 @@ -302,6 +302,7 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */ [% numberpattern.label | html %] [% END %] +
  • 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 9f14fbb..ca1a6dd 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 @@ -168,8 +168,13 @@ [% END %]
  • Number pattern: - [% numberpattern.label | html %] + [% IF ( numberpattern ) %] + [% numberpattern.label | html %] + [% ELSE %] + Uses publication date + [% END %]
  • + [% IF ( numberpattern ) %]
  • @@ -196,6 +201,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 c995751..88a4e13 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js +++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js @@ -198,6 +198,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); @@ -362,6 +380,15 @@ function show_page_2() { displaymoreoptions(); } +function usedatepattern() { + $("#more_options").hide(); + clearAdvancedPattern(); + if ($("#advancedpredictionpattern").is(":visible")){ + $("#advancedpredictionpattern").toggle(); + $(".toggle_advanced_pattern").toggle(); + } +} + $(document).ready(function() { $("#aqbooksellerid").on('keypress', function(e) { @@ -383,7 +410,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(''); @@ -432,7 +464,7 @@ $(document).ready(function() { if($("#frequency").val() != ""){ frequencyload(); } - if($("#numberpattern").val() != ""){ + if($("#numberpattern").val() != "0" && $("#numberpattern").val() != ""){ numberpatternload(); } @@ -496,4 +528,4 @@ $(document).ready(function() { e.preventDefault(); testPredictionPattern(); }); -}); \ No newline at end of file +}); diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl index e8735b3..193b055 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -83,6 +83,10 @@ if($op eq 'gennext' && @subscriptionid){ $newinnerloop1, $newinnerloop2, $newinnerloop3 ) = GetNextSeq($subscription, $pattern, $expected->{publisheddate}); + if (!defined $pattern && !defined $newserialseq){ + $newserialseq = $expected->{publisheddate}; + } + ## We generate the next publication date my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, 1); my $planneddate = $date_received_today ? dt_from_string : $nextpublisheddate; @@ -128,8 +132,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; @@ -148,7 +155,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 6986b5e..3ced01b 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; @@ -112,6 +113,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, @@ -159,6 +165,9 @@ while( $i < 1000 ) { ($calculated, $subscription{'lastvalue1'}, $subscription{'lastvalue2'}, $subscription{'lastvalue3'}, $subscription{'innerloop1'}, $subscription{'innerloop2'}, $subscription{'innerloop3'}) = GetNextSeq(\%subscription, \%pattern); $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 fb7e797..bd520d2 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -338,6 +338,10 @@ sub redirect_add_subscription { } } + if ($numberpattern == "0"){ # using publication date as numbering pattern + $numberpattern = undef; + } + my $subscriptionid = NewSubscription( $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, $startdate, $periodicity, $numberlength, $weeklength, @@ -422,6 +426,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