From a6fc1d244184abc52c97d50c7472015b295ea687 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 | 70 +++++++++++++++------- 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, 151 insertions(+), 38 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 78a0c5a..f80405d 100644 --- a/C4/Serials.pm +++ b/C4/Serials.pm @@ -872,8 +872,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}; } @@ -1168,26 +1177,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=? @@ -1336,7 +1338,7 @@ sub ModSubscription { $biblionumber, $callnumber, $notes, $letter, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $subscriptionid, $skip_serialseq, - $itemtype, $previousitemtype + $itemtype, $previousitemtype, $mana_id, $dateformat ) = @_; my $dbh = C4::Context->dbh; @@ -1349,9 +1351,9 @@ sub ModSubscription { callnumber=?, notes=?, letter=?, manualhistory=?, internalnotes=?, serialsadditems=?, staffdisplaycount=?, opacdisplaycount=?, graceperiod=?, location = ?, enddate=?, - skip_serialseq=?, itemtype=?, previousitemtype=? + skip_serialseq=?, itemtype=?, previousitemtype=?, mana_id=?, + pubdatepatternformat=? WHERE subscriptionid = ?"; - my $sth = $dbh->prepare($query); $sth->execute( $auser, $branchcode, $aqbooksellerid, $cost, @@ -1363,7 +1365,7 @@ sub ModSubscription { $letter, ($manualhistory ? $manualhistory : 0), $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, - $itemtype, $previousitemtype, + $itemtype, $previousitemtype, $mana_id, $dateformat, $subscriptionid ); my $rows = $sth->rows; @@ -1380,7 +1382,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. @@ -1397,7 +1399,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; @@ -1411,8 +1414,8 @@ sub NewSubscription { irregularity, numberpattern, locale, callnumber, manualhistory, internalnotes, serialsadditems, staffdisplaycount, opacdisplaycount, graceperiod, location, enddate, skip_serialseq, - itemtype, previousitemtype, mana_id) - VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?, ?) + itemtype, previousitemtype, mana_id, pubdatepatternformat) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) |; my $sth = $dbh->prepare($query); $sth->execute( @@ -1423,7 +1426,7 @@ sub NewSubscription { $firstacquidate, $irregularity, $numberpattern, $locale, $callnumber, $manualhistory, $internalnotes, $serialsadditems, $staffdisplaycount, $opacdisplaycount, $graceperiod, $location, $enddate, $skip_serialseq, - $itemtype, $previousitemtype, $mana_id + $itemtype, $previousitemtype, $mana_id, $dateformat ); my $subscriptionid = $dbh->{'mysql_insertid'}; @@ -1454,8 +1457,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( @@ -1549,7 +1561,7 @@ sub ReNewSubscription { =head2 NewIssue -NewIssue($serialseq,$subscriptionid,$biblionumber,$status, $planneddate, $publisheddate, $notes) +NewIssue($serialseq,$subscriptionid,$biblionumber,$status, $planneddate, $publisheddate, $notes) Create a new issue stored on the database. Note : we have to update the recievedlist and missinglist on subscriptionhistory for this subscription. @@ -1568,6 +1580,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, @@ -2349,7 +2374,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 3666dd6..a4dbf95 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 # You can replace this text with custom content, and it will be preserved on regeneration 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 e9416c7..e7af094 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 @@ -298,9 +298,15 @@ fieldset.rows li.radio { width: 100%; } /* override staff-global.css */
  • +
  • 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 c6c0751..70e7df9 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 @@ -177,7 +177,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 9dc9ac3..2c15aee 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]; @@ -525,6 +525,7 @@ function mana_use(mana_id){ } function usedatepattern() { + $("#date_format").show(); $("#more_options").hide(); clearAdvancedPattern(); if ($("#advancedpredictionpattern").is(":visible")){ @@ -539,6 +540,12 @@ $(document).ready(function() { } $("#displayexample").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) { e.preventDefault(); @@ -558,11 +565,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 1b677ca..6a336e7 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 @@ -137,7 +146,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 7324058..b69a729 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 eb797aa..b78a071 100755 --- a/serials/subscription-add.pl +++ b/serials/subscription-add.pl @@ -165,6 +165,7 @@ $template->param( typeloop => \@typearg, previoustypeloop => \@previoustypearg, locations_loop=>$locations_loop, + dateformat => $subs->{pubdatepatternformat}, ); # prepare template variables common to all $op conditions: @@ -366,6 +367,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, @@ -375,7 +377,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')) and ( grep { $_ eq "subscription" } split(/,/, C4::Context->preference('AutoShareWithMana'))) ){ my $result = Koha::SharedContent::send_entity( $query->param('mana_language') || '', $loggedinuser, $subscriptionid, 'subscription'); @@ -477,6 +479,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, @@ -486,7 +489,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 = Koha::AdditionalField->all( { tablename => 'subscription' } ); diff --git a/serials/subscription-detail.pl b/serials/subscription-detail.pl index 451e5a6..4bbbcbf 100755 --- a/serials/subscription-detail.pl +++ b/serials/subscription-detail.pl @@ -125,6 +125,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(); @@ -162,6 +163,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