Bug 18327: Same change for serials-edit
[koha_ffzg] / serials / serials-collection.pl
index e9cb3fd..a4fd91d 100755 (executable)
@@ -19,8 +19,7 @@
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 
-use strict;
-use warnings;
+use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Koha;
@@ -29,12 +28,15 @@ use C4::Letters;
 use C4::Output;
 use C4::Context;
 
+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');
+my $date_received_today = $query->param('date_received_today') || 0;
 my $dbh = C4::Context->dbh;
 
 my ($template, $loggedinuser, $cookie)
@@ -67,8 +69,9 @@ 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},
-                    $issue->{planneddate}, $issue->{publisheddate},
+                    $planneddate, $issue->{publisheddate},
                     $issue->{publisheddatetext}, $status, "" );
         } else {
             require C4::Serials::Numberpattern;
@@ -82,9 +85,10 @@ if($op eq 'gennext' && @subscriptionid){
 
              ## We generate the next publication date
              my $nextpublisheddate = GetNextDate($subscription, $expected->{publisheddate}, 1);
+             my $planneddate = $date_received_today ? dt_from_string : $nextpublisheddate;
              ## Creating the new issue
              NewIssue( $newserialseq, $subscriptionid, $subscription->{'biblionumber'},
-                     1, $nextpublisheddate, $nextpublisheddate );
+                     1, $planneddate, $nextpublisheddate );
 
              ## Updating the subscription seq status
              my $squery = "UPDATE subscription SET lastvalue1=?, lastvalue2=?, lastvalue3=?, innerloop1=?, innerloop2=?, innerloop3=?