From df06ce7e9b9ff81bb5528b40395aedaffda892af 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 ++- .../en/modules/serials/subscription-add.tt | 1 + .../en/modules/serials/subscription-detail.tt | 215 ++++++++++++++++++ .../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, 308 insertions(+), 6 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index 1eae56bc8d..fcf0aaebe9 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -840,8 +840,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}; @@ -922,6 +927,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}; @@ -1126,6 +1135,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, @@ -1134,7 +1156,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 = ?"; @@ -1454,6 +1475,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 19d53a1c33..753212df2a 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 @@ -370,6 +370,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 e596aba702..2b49ff75f3 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 @@ -82,6 +82,221 @@

[% END %] +
+
+
+
+
    +
  1. Beginning date: [% startdate | html %] +
  2. +
  3. Frequency: + [% frequency.description | html %] +
  4. +
  5. + Manual history: + [% IF ( manualhistory ) %] + Enabled Edit history + [% ELSE %] + Disabled + [% END %] +
  6. +
  7. Number pattern: + [% IF ( numberpattern ) %] + [% numberpattern.label | html %] + [% ELSE %] + Uses publication date + [% END %] +
  8. + [% IF ( numberpattern ) %] +
  9. + + + [% IF (has_X) %] + + [% END %] + [% IF (has_Y) %] + + [% END %] + [% IF (has_Z) %] + + [% END %] + + + + [% IF (has_X) %] + + [% END %] + [% IF (has_Y) %] + + [% END %] + [% IF (has_Z) %] + + [% END %] + +
    Starting with:[% lastvalue1 | html %][% lastvalue2 | html %][% lastvalue3 | html %]
    Rollover:[% numberpattern.whenmorethan1 | html %][% numberpattern.whenmorethan2 | html %][% numberpattern.whenmorethan3 | html %]
  10. + [% END %] + [% IF ( irregular_issues ) %] +
  11. Irregularity: [% irregular_issues | html %] issues +
  12. + [% END %] +
  13. First arrival: [% firstacquidate | html %] +
  14. + [% IF ( numberlength ) %]
  15. Number of issues: [% numberlength | html %]
  16. [% END %] + [% IF ( weeklength ) %]
  17. Number of weeks: [% weeklength | html %]
  18. [% END %] + [% IF ( monthlength ) %]
  19. Number of months: [% monthlength | html %]
  20. [% END %] +
+
+
+
+
+ +
+ + + + + + + + + [% FOREACH serialslis IN serialslist %] + + + + + + + + [% END %] +
Issue numberPlanned datePublished datePublished date (text)Status
+ [% serialslis.serialseq | html %] + + [% IF serialslis.planneddate %] + [% serialslis.planneddate | html %] + [% ELSE %] + Unknown + [% END %] + + [% IF serialslis.publisheddate %] + [% serialslis.publisheddate | html %] + [% ELSE %] + Unknown + [% END %] + + [% serialslis.publisheddatetext | html %] + + [% IF ( serialslis.status1 ) %]Expected[% END %] + [% IF ( serialslis.status2 ) %]Arrived[% END %] + [% IF ( serialslis.status3 ) %]Late[% END %] + [% IF ( serialslis.status4 ) %]Missing[% END %] + [% IF ( serialslis.status41 ) %]Missing (never received)[% END %] + [% IF ( serialslis.status42 ) %]Missing (sold out)[% END %] + [% IF ( serialslis.status43 ) %]Missing (damaged)[% END %] + [% IF ( serialslis.status44 ) %]Missing (lost)[% END %] + [% IF ( serialslis.status5 ) %]Not issued[% END %] + [% IF ( serialslis.status6 ) %]Delete[% END %] + [% IF ( serialslis.status7 ) %] + Claimed + [% IF ( serialslis.claimdate ) %] + [% serialslis.claimdate | html %] + [% END %] + [% END %] + [% IF ( serialslis.status8 ) %]Stopped[% END %] +
+
+
+
+
+
+
    +
  1. Start date: [% startdate | html %]
  2. +
  3. End date: [% enddate | html %]
  4. +
  5. History start date: [% histstartdate | html %]
  6. +
  7. History end date: [% histenddate | html %]
  8. +
  9. Received issues:[% recievedlist | html | html_line_break %]
  10. +
  11. Missing issues:[% missinglist | html | html_line_break %]
  12. +
  13. Nonpublic note:[% internalnotes | html | html_line_break %]
  14. +
  15. Public note:[% notes | html | html_line_break %]
  16. +
  17. History staff note:[% librariannote | html | html_line_break %]
  18. +
  19. History OPAC note:[% opacnote | html | html_line_break %]
  20. +
+
+
+
+
+ + [% IF orders_grouped.size %] +
+

Acquisition details

+ + [% WRAPPER tabs id= "subscription_description" %] [% WRAPPER tabs_nav %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js index ebf0977d47..f2293aa33c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js +++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js @@ -252,6 +252,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); @@ -553,6 +571,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(); @@ -585,7 +612,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(''); @@ -634,7 +666,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 2179b83069..9edbbf3320 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -81,6 +81,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 my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, $frequency, 1); my $planneddate = $date_received_today ? dt_from_string : $nextpublisheddate; @@ -151,8 +155,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; @@ -171,7 +178,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 9fc801102b..d0aae17b58 100755 --- a/serials/showpredictionpattern.pl +++ b/serials/showpredictionpattern.pl @@ -35,6 +35,7 @@ use Date::Calc qw( Add_Delta_Days Add_Delta_YM Day_of_Week Delta_Days ); use C4::Auth qw( get_template_and_user ); use C4::Output qw( output_html_with_http_headers ); use C4::Serials qw( GetSubscription GetFictiveIssueNumber GetSeq GetSubscriptionIrregularities GetNextDate GetNextSeq ); +use POSIX qw(strftime); use C4::Serials::Frequency; use Koha::DateUtils qw( dt_from_string ); @@ -119,6 +120,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, @@ -166,6 +172,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 f8cbc572f2..ed4aa7b4bf 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -349,6 +349,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, @@ -467,6 +472,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.30.2
+ + Hide already received orders + | Show all orders + | Expand all + | Collapse all + +