@@ -, +, @@ fixes --- 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 --- a/C4/Serials.pm +++ a/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=? @@ -1322,7 +1324,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; @@ -1335,9 +1337,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, @@ -1349,7 +1351,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; @@ -1366,7 +1368,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. @@ -1383,7 +1385,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; @@ -1426,6 +1429,7 @@ sub NewSubscription { itemtype => $itemtype, previousitemtype => $previousitemtype, mana_id => $mana_id, + pubdatepatternformat => $dateformat, } )->store; $subscription->discard_changes; @@ -1458,8 +1462,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( @@ -1572,6 +1585,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, @@ -2352,7 +2378,6 @@ sub GetNextDate { return unless $subscription and $publisheddate; - if ($freqdata->{'unit'}) { my ( $year, $month, $day ) = split /-/, $publisheddate; --- a/Koha/Schema/Result/Subscription.pm +++ a/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", --- a/installer/data/mysql/atomicupdate/bug_22188_-_add_pubdatepatternformat_column_serial.perl +++ a/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"; +} --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-add.tt @@ -306,9 +306,15 @@ fieldset.rows table { clear: none; margin: 0; }
  • + Required
  • --- a/koha-tmpl/intranet-tmpl/prog/en/modules/serials/subscription-detail.tt +++ a/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 ) %] --- a/koha-tmpl/intranet-tmpl/prog/js/subscription-add.js +++ a/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(){ --- a/serials/serials-collection.pl +++ a/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); --- a/serials/showpredictionpattern.pl +++ a/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]){ --- a/serials/subscription-add.pl +++ a/serials/subscription-add.pl @@ -170,6 +170,7 @@ $template->param( typeloop => \@typearg, previoustypeloop => \@previoustypearg, locations_loop=>$locations_loop, + dateformat => $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; --- a/serials/subscription-detail.pl +++ a/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, --