From d31a244f80347a28e687c145eb3b689876db13e6 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Fri, 13 Oct 2023 01:51:15 +0000 Subject: [PATCH] Bug 22188: (follow-up) Introducing dateformat field and other fixes --- C4/Serials.pm | 57 +++++++++++++------ .../en/modules/serials/subscription-add.tt | 37 +++++++++++- .../en/modules/serials/subscription-detail.tt | 2 +- .../intranet-tmpl/prog/js/subscription-add.js | 12 +++- serials/serials-collection.pl | 17 ++++-- serials/showpredictionpattern.pl | 22 ++++++- serials/subscription-add.pl | 7 ++- serials/subscription-detail.pl | 2 + 8 files changed, 127 insertions(+), 29 deletions(-) diff --git a/C4/Serials.pm b/C4/Serials.pm index fcf0aaebe9a..b4de5a8baa7 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -842,8 +842,17 @@ sub GetNextSeq { my $calculated = ""; my $numberingmethod = ""; + my $dateformat = $subscription->{pubdatepatternformat}; if ($pattern eq "pubdate"){ - $calculated = dt_from_string( $planneddate )->strftime( '%Y %B %d' ); + if ( $dateformat eq 'dmy' ){ + $calculated = dt_from_string( $planneddate )->strftime( '%d %B %Y' ); + } elsif ( $dateformat eq 'mdy' ){ + $calculated = dt_from_string( $planneddate )->strftime( '%B %d %Y' ); + } elsif ( $dateformat eq 'ydm' ){ + $calculated = dt_from_string( $planneddate )->strftime( '%Y %d %B' ); + } else { + $calculated = dt_from_string( $planneddate )->strftime( '%Y %B %d' ); + } } else { $numberingmethod = $pattern->{numberingmethod}; } @@ -1135,26 +1144,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 $nextpublisheddate = GetNextDate($subscription, $publisheddate, $frequency); my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 ); + # next issue number if (!defined $pattern){ $pattern = "pubdate"; - ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, - $newinnerloop1, $newinnerloop2, $newinnerloop3 ) = GetNextSeq( $subscription, $pattern, $nextpublisheddate ); + $newserialseq = "pubdate"; } 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, $frequency, $publisheddate ); - # next date (calculated from actual date & frequency parameters) my $nextpubdate = $nextpublisheddate; $query = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=? @@ -1315,7 +1317,7 @@ sub ModSubscription { $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq, - $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template + $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template, $dateformat ) = @_; my $subscription = Koha::Subscriptions->find($subscriptionid); @@ -1360,6 +1362,7 @@ sub ModSubscription { mana_id => $mana_id, ccode => $ccode, published_on_template => $published_on_template, + pubdatepatternformat => $dateformat, } )->store; # FIXME Must be $subscription->serials @@ -1380,7 +1383,7 @@ $subscriptionid = &NewSubscription($auser,branchcode,$aqbooksellerid,$cost,$aqbu $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, - $skip_serialseq, $itemtype, $previousitemtype); + $skip_serialseq, $itemtype, $previousitemtype, $dateformat); Create a new subscription with value given on input args. @@ -1398,7 +1401,7 @@ sub NewSubscription { $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, - $published_on_template, + $published_on_template, $dateformat, ) = @_; my $dbh = C4::Context->dbh; @@ -1443,6 +1446,7 @@ sub NewSubscription { mana_id => $mana_id, ccode => $ccode, published_on_template => $published_on_template, + pubdatepatternformat => $dateformat, } )->store; $subscription->discard_changes; @@ -1475,8 +1479,17 @@ sub NewSubscription { # calculate issue number my $serialseq = GetSeq($subscription, $pattern) || q{}; + $dateformat //= ''; if ($serialseq eq "pubdate"){ - $serialseq = dt_from_string( $firstacquidate )->strftime('%Y %B %d'); + if ( $dateformat eq 'dmy' ){ + $serialseq = dt_from_string( $firstacquidate )->strftime('%d %B %Y'); + } elsif ( $dateformat eq 'mdy' ){ + $serialseq = dt_from_string( $firstacquidate )->strftime('%B %d %Y'); + } elsif ( $dateformat eq 'ydm' ){ + $serialseq = dt_from_string( $firstacquidate )->strftime('%Y %d %B'); + } else { + $serialseq = dt_from_string( $firstacquidate )->strftime('%Y %B %d'); + } } Koha::Serial->new( @@ -1622,6 +1635,19 @@ sub NewIssue { my $subscription = Koha::Subscriptions->find( $subscriptionid ); + my $dateformat = $subscription->pubdatepatternformat; + if ($serialseq eq "pubdate"){ + if ( $dateformat eq 'dmy' ){ + $serialseq = dt_from_string( $publisheddate )->strftime('%d %B %Y'); + } elsif ( $dateformat eq 'mdy' ){ + $serialseq = dt_from_string( $publisheddate )->strftime('%B %d %Y'); + } elsif ( $dateformat eq 'ydm' ){ + $serialseq = dt_from_string( $publisheddate )->strftime('%Y %d %B'); + } else { + $serialseq = dt_from_string( $publisheddate )->strftime('%Y %B %d'); + } + } + if ( my $template = $subscription->published_on_template ) { $publisheddatetext = process_tt( $template, @@ -2427,7 +2453,6 @@ sub GetNextDate { return unless $subscription and $publisheddate; - if ($freqdata->{'unit'}) { my ( $year, $month, $day ) = split /-/, $publisheddate; 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 753212df2a4..a8e079bf8cd 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 @@ -360,9 +360,15 @@ fieldset.rows table { clear: none; margin: 0; }
  • + 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 2b49ff75f37..3ef18927c0a 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 @@ -104,7 +104,7 @@ [% IF ( numberpattern ) %] [% numberpattern.label | html %] [% ELSE %] - Uses publication date + Uses publication date - [% dateformat %] format [% END %] [% IF ( numberpattern ) %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js index f2293aa33c8..4d46a4bf132 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js +++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js @@ -348,7 +348,7 @@ function testPredictionPattern() { 'every1', 'every2', 'every3', 'innerloop1', 'innerloop2', 'innerloop3', 'setto1', 'setto2', 'setto3', 'numbering1', 'numbering2', 'numbering3', 'whenmorethan1', 'whenmorethan2', 'whenmorethan3', 'locale', - 'sfdescription', 'unitsperissue', 'issuesperunit', 'unit' + 'sfdescription', 'unitsperissue', 'issuesperunit', 'unit', 'date_format' ]; for(i in ajaxParams) { var param = ajaxParams[i]; @@ -572,6 +572,7 @@ function hidePredcitionPatternTest(){ } function usedatepattern() { + $("#date_format").show(); $("#more_options").hide(); clearAdvancedPattern(); if ($("#advancedpredictionpattern").is(":visible")){ @@ -592,6 +593,12 @@ $(document).ready(function() { $("#new_mana_comment").hide(); $(".mana_comment_status").hide(); }); + $("#mana_search_result").modal("hide"); + + $("#date_format").hide(); + if ($("select#numberpattern").val() == "0"){ + $("#date_format").show(); + } $("#aqbooksellerid").on('keypress', function(e) { if (e.keyCode == 13) { @@ -612,11 +619,12 @@ $(document).ready(function() { }); $("select#numberpattern").change(function(){ patternneedtobetested = 1; - console.log($("select#numberpattern").val()); if ($("select#numberpattern").val() == "0"){ usedatepattern(); } else { numberpatternload(); + $("#date_format").hide(); + $("#date_format").val(""); } }); $("#subtype").change(function(){ diff --git a/serials/serials-collection.pl b/serials/serials-collection.pl index 9edbbf33200..78ba4e49489 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -31,7 +31,6 @@ use Koha::DateUtils qw( dt_from_string ); use List::MoreUtils qw( uniq ); - my $query = CGI->new; my $op = $query->param('op') || q{}; my $nbissues=$query->param('nbissues'); @@ -66,6 +65,7 @@ if($op eq 'gennext' && @subscriptionid){ $sth->execute($subscriptionid); # modify actual expected issue, to generate the next if ( my $issue = $sth->fetchrow_hashref ) { + my $planneddate = $date_received_today ? dt_from_string : $issue->{planneddate}; ModSerialStatus( $issue->{serialid}, $issue->{serialseq}, $planneddate, $issue->{publisheddate}, @@ -79,10 +79,19 @@ if($op eq 'gennext' && @subscriptionid){ my ( $newserialseq, $newlastvalue1, $newlastvalue2, $newlastvalue3, $newinnerloop1, $newinnerloop2, $newinnerloop3 - ) = GetNextSeq($subscription, $pattern, $frequency, $expected->{publisheddate}); + ) = GetNextSeq($subscription, $pattern, $frequency); if (!defined $pattern && !defined $newserialseq){ - $newserialseq = $expected->{publisheddate}; + my $dateformat = $subscription->{pubdatepatternformat}; + if ( $dateformat eq 'dmy' ){ + $newserialseq = dt_from_string( $expected->{publisheddate} )->strftime('%d %B %Y'); + } elsif ( $dateformat eq 'mdy' ){ + $newserialseq = dt_from_string( $expected->{publisheddate} )->strftime('%B %d %Y'); + } elsif ( $dateformat eq 'ydm' ){ + $newserialseq = dt_from_string( $expected->{publisheddate} )->strftime('%Y %d %B'); + } else { + $newserialseq = dt_from_string( $expected->{publisheddate} )->strftime('%Y %B %d'); + } } ## We generate the next publication date @@ -158,7 +167,7 @@ if (@subscriptionid){ $subs->{frequency} = $frequency; my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern}); if (!defined $numberpattern){ - $numberpattern->{label} = "Uses publication date"; + $numberpattern->{label} = "Uses publication date - $subs->{pubdatepatternformat} format"; } $subs->{numberpattern} = $numberpattern; $subs->{'hasRouting'} = check_routing($subscriptionid); diff --git a/serials/showpredictionpattern.pl b/serials/showpredictionpattern.pl index d0aae17b586..86fea33264b 100755 --- a/serials/showpredictionpattern.pl +++ b/serials/showpredictionpattern.pl @@ -121,8 +121,18 @@ if(defined $subscriptionid) { my @predictions_loop; my ($calculated) = GetSeq(\%subscription, \%pattern); +my $dateformat = scalar $input->param('date_format'); + if ($calculated eq "pubdate"){ - $calculated = dt_from_string( $date )->strftime('%Y %B %d'); + if ( $dateformat eq 'dmy' ){ + $calculated = dt_from_string( $date )->strftime('%d %B %Y'); + } elsif ( $dateformat eq 'mdy' ){ + $calculated = dt_from_string( $date )->strftime('%B %d %Y'); + } elsif ( $dateformat eq 'ydm' ){ + $calculated = dt_from_string( $date )->strftime('%Y %d %B'); + } else { + $calculated = dt_from_string( $date )->strftime('%Y %B %d'); + } } push @predictions_loop, { @@ -173,7 +183,15 @@ while( $i < 1000 ) { $issuenumber++; $line{'number'} = $calculated; if ($calculated eq ''){ - $line{'number'} = dt_from_string( $date )->strftime('%Y %B %d'); + if ( $dateformat eq 'dmy' ){ + $line{'number'} = dt_from_string( $date )->strftime('%d %B %Y'); + } elsif ( $dateformat eq 'mdy' ){ + $line{'number'} = dt_from_string( $date )->strftime('%B %d %Y'); + } elsif ( $dateformat eq 'ydm' ){ + $line{'number'} = dt_from_string( $date )->strftime('%Y %d %B'); + } else { + $line{'number'} = dt_from_string( $date )->strftime('%Y %B %d'); + } } $line{'issuenumber'} = $issuenumber; if(@irreg && $issuenumber == $irreg[0]){ diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl index ed4aa7b4bfd..7f2db497a9e 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -157,6 +157,7 @@ $template->param( typeloop => \@typearg, previoustypeloop => \@previoustypearg, locations_loop=>$locations_loop, + pubdatepatternformat => $subs->{pubdatepatternformat}, ); # prepare template variables common to all $op conditions: @@ -353,6 +354,7 @@ sub redirect_add_subscription { if ($numberpattern == "0"){ # using publication date as numbering pattern $numberpattern = undef; } + my $dateformat = $query->param('date_format'); my $subscriptionid = NewSubscription( $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $biblionumber, @@ -362,7 +364,7 @@ sub redirect_add_subscription { join(";",@irregularity), $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, - $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template + $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template, $dateformat ); if ( (C4::Context->preference('Mana') == 1) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){ my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription'); @@ -475,6 +477,7 @@ sub redirect_mod_subscription { if ($numberpattern == "0"){ # using publication date as numbering pattern $numberpattern = undef; } + my $dateformat = $query->param('date_format'); ModSubscription( $auser, $branchcode, $aqbooksellerid, $cost, $aqbudgetid, $startdate, @@ -484,7 +487,7 @@ sub redirect_mod_subscription { $status, $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, - $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template + $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $ccode, $published_on_template, $dateformat ); my @additional_fields; diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index 74a0ee8aabb..4c3c75a0772 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -124,6 +124,7 @@ my @irregular_issues = split /;/, $subs->{irregularity}; my $frequency = C4::Serials::Frequency::GetSubscriptionFrequency($subs->{periodicity}); my $numberpattern = C4::Serials::Numberpattern::GetSubscriptionNumberpattern($subs->{numberpattern}); +my $dateformat = $subs->{pubdatepatternformat}; $template->param( available_additional_fields => Koha::AdditionalFields->search( { tablename => 'subscription' } ), @@ -157,6 +158,7 @@ $template->param( cannotedit => (not C4::Serials::can_edit_subscription( $subs )), frequency => $frequency, numberpattern => $numberpattern, + dateformat => $dateformat, has_X => ($numberpattern->{'numberingmethod'} =~ /{X}/) ? 1 : 0, has_Y => ($numberpattern->{'numberingmethod'} =~ /{Y}/) ? 1 : 0, has_Z => ($numberpattern->{'numberingmethod'} =~ /{Z}/) ? 1 : 0, -- 2.30.2