From f151c5015237907d6cdac9a12b04b20ea8f65b66 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Sun, 10 Mar 2019 22:47:02 +0000 Subject: [PATCH] Bug 22188: (follow-up) Introducing dateformat field and other fixes To test with this patch, please update the database and update the schema. With this patch, you can now choose the dateformat of the date pattern by editing the subscription. This information is now saved in the DB subscription table. This patch also fixes previous problems with receiving and generating the next serial. Sponsored-by: Brimbank Libraries Australia --- C4/Serials.pm | 63 +++++++++++++++------- Koha/Schema/Result/Subscription.pm | 12 ++++- ...8_-_add_pubdatepatternformat_column_serial.perl | 8 +++ .../prog/en/modules/serials/subscription-add.tt | 37 ++++++++++++- .../prog/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 + 10 files changed, 148 insertions(+), 34 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_22188_-_add_pubdatepatternformat_column_serial.perl diff --git a/C4/Serials.pm b/C4/Serials.pm index fb44048..560ee8b 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -861,8 +861,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}; } @@ -1156,26 +1165,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=? @@ -1323,7 +1325,7 @@ sub ModSubscription { $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq, - $itemtype, $previousitemtype, $mana_id + $itemtype, $previousitemtype, $mana_id, $dateformat ) = @_; my $dbh = C4::Context->dbh; @@ -1336,9 +1338,9 @@ sub ModSubscription { callnumber=?, notes=?, letter=?, manualhistory=?, internalnotes=?, serialsadditems=?, staffdisplaycount=?, opacdisplaycount=?, graceperiod=?, location = ?, enddate=?, - skip_serialseq=?, itemtype=?, previousitemtype=?, mana_id=? + skip_serialseq=?, itemtype=?, previousitemtype=?, mana_id=?, + pubdatepatternformat=? WHERE subscriptionid = ?"; - my $sth = $dbh->prepare($query); $sth->execute( $auser, $branchcode, $aqbooksellerid, $cost, @@ -1350,7 +1352,7 @@ sub ModSubscription { $letter, ($manualhistory ? $manualhistory : 0), $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, - $itemtype, $previousitemtype, $mana_id, + $itemtype, $previousitemtype, $mana_id, $dateformat, $subscriptionid ); my $rows = $sth->rows; @@ -1367,7 +1369,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. @@ -1384,7 +1386,8 @@ sub NewSubscription { $innerloop3, $status, $notes, $letter, $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, - $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id + $location, $enddate, $skip_serialseq, $itemtype, $previousitemtype, $mana_id, + $dateformat ) = @_; my $dbh = C4::Context->dbh; @@ -1427,6 +1430,7 @@ sub NewSubscription { itemtype => $itemtype, previousitemtype => $previousitemtype, mana_id => $mana_id, + pubdatepatternformat => $dateformat, } )->store; $subscription->discard_changes; @@ -1459,8 +1463,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( @@ -1573,6 +1586,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'); + } + } + my $serial = Koha::Serial->new( { serialseq => $serialseq, @@ -2353,7 +2379,6 @@ sub GetNextDate { return unless $subscription and $publisheddate; - if ($freqdata->{'unit'}) { my ( $year, $month, $day ) = split /-/, $publisheddate; diff --git a/Koha/Schema/Result/Subscription.pm b/Koha/Schema/Result/Subscription.pm index 88b4325..ff887c5 100644 --- a/Koha/Schema/Result/Subscription.pm +++ b/Koha/Schema/Result/Subscription.pm @@ -276,6 +276,12 @@ __PACKAGE__->table("subscription"); data_type: 'integer' is_nullable: 1 +=head2 pubdatepatternformat + + data_type: 'varchar' + is_nullable: 1 + size: 3 + =cut __PACKAGE__->add_columns( @@ -365,6 +371,8 @@ __PACKAGE__->add_columns( { data_type => "varchar", is_nullable => 1, size => 10 }, "mana_id", { data_type => "integer", is_nullable => 1 }, + "pubdatepatternformat", + { data_type => "varchar", is_nullable => 1, size => 3 }, ); =head1 PRIMARY KEY @@ -452,8 +460,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2019-01-23 12:56:39 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:dTb/JOO3KQ3NZGypFbRiEw +# Created by DBIx::Class::Schema::Loader v0.07042 @ 2019-02-28 22:06:40 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:xfL68dHECH0R31U1uCTJtA __PACKAGE__->has_many( "additional_field_values", diff --git a/installer/data/mysql/atomicupdate/bug_22188_-_add_pubdatepatternformat_column_serial.perl b/installer/data/mysql/atomicupdate/bug_22188_-_add_pubdatepatternformat_column_serial.perl new file mode 100644 index 0000000..b636193 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_22188_-_add_pubdatepatternformat_column_serial.perl @@ -0,0 +1,8 @@ +$DBversion = 'XXX'; +if( CheckVersion( $DBversion ) ) { + unless( column_exists( 'subscription', 'pubdatepatternformat' ) ) { + $dbh->do(q|ALTER TABLE subscription ADD pubdatepatternformat varchar(3) default NULL AFTER mana_id|); + } + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 22188: Add column subscription.pubdatepatternformat)\n"; +} 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 3db8384..96e4157 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 @@ -306,9 +306,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 41e7746..55a01d5 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 @@ -169,7 +169,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 bf096ce..607f486 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js +++ b/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js @@ -323,7 +323,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]; @@ -548,6 +548,7 @@ function hidePredcitionPatternTest(){ } function usedatepattern() { + $("#date_format").show(); $("#more_options").hide(); clearAdvancedPattern(); if ($("#advancedpredictionpattern").is(":visible")){ @@ -568,6 +569,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) { @@ -588,11 +595,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 795950f..d3b6b68 100755 --- a/serials/serials-collection.pl +++ b/serials/serials-collection.pl @@ -32,7 +32,6 @@ use Koha::DateUtils qw( dt_from_string ); use List::MoreUtils qw/uniq/; - my $query = new CGI; my $op = $query->param('op') || q{}; my $nbissues=$query->param('nbissues'); @@ -69,6 +68,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}, @@ -82,10 +82,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 @@ -134,7 +143,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 3b3e492..4aaf9af 100755 --- a/serials/showpredictionpattern.pl +++ b/serials/showpredictionpattern.pl @@ -127,8 +127,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, { @@ -179,7 +189,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 82c8c8d..3e62187 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -170,6 +170,7 @@ $template->param( typeloop => \@typearg, previoustypeloop => \@previoustypearg, locations_loop=>$locations_loop, + pubdatepatternformat => $subs->{pubdatepatternformat}, ); # prepare template variables common to all $op conditions: @@ -371,6 +372,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, @@ -380,7 +382,7 @@ sub redirect_add_subscription { join(";",@irregularity), $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, - $skip_serialseq, $itemtype, $previousitemtype, $mana_id + $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $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'); @@ -498,6 +500,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, @@ -507,7 +510,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 + $skip_serialseq, $itemtype, $previousitemtype, $mana_id, $dateformat ); my @additional_fields; diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index b7137bd..634da33 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -127,6 +127,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}; my $default_bib_view = get_default_view(); @@ -165,6 +166,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.1.4