- my $query = qq|
- UPDATE subscription
- SET librarian=?, aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?,
- periodicity=?,dow=?,numberlength=?,weeklength=?,monthlength=?,
- add1=?,every1=?,whenmorethan1=?,setto1=?,lastvalue1=?,innerloop1=?,
- add2=?,every2=?,whenmorethan2=?,setto2=?,lastvalue2=?,innerloop2=?,
- add3=?,every3=?,whenmorethan3=?,setto3=?,lastvalue3=?,innerloop3=?,
- numberingmethod=?, status=?, biblionumber=?, notes=?, letter=?,irregularity=?,hemisphere=?,callnumber=?,numberpattern=? ,publisheddate=?
- WHERE subscriptionid = ?
- |;
- my $sth=$dbh->prepare($query);
- $sth->execute($auser,$aqbooksellerid,$cost,$aqbudgetid,$startdate,
- $periodicity,$dow,$numberlength,$weeklength,$monthlength,
- $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
- $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
- $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
- $numberingmethod, $status, $biblionumber, $notes, $letter, $irregularity,$hemisphere,$callnumber,$numberpattern,$publisheddate,$subscriptionid);
+ my $sth = $dbh->prepare('SELECT serialid, planneddate FROM serial WHERE subscriptionid=? AND status=?');
+ # Each subscription has only one 'expected' issue, with serial.status==1.
+ $sth->execute( $subscriptionid, 1 );
+ my ( $nextissue ) = $sth->fetchrow_hashref;
+ $nextissue->{planneddate} = C4::Dates->new($nextissue->{planneddate},'iso');
+ return $nextissue;
+}
+=head2 ModNextExpected
+
+=over 4
+
+ModNextExpected($subscriptionid,$date)
+
+Update the planneddate for the current expected issue of the subscription.
+This will modify all future prediction results.
+
+C<$date> is a C4::Dates object.
+
+=back
+
+=cut
+
+sub ModNextExpected($$) {
+ my ($subscriptionid,$date) = @_;
+ my $dbh = C4::Context->dbh;
+ #FIXME: Would expect to only set planneddate, but we set both on new issue creation, so updating it here
+ my $sth = $dbh->prepare('UPDATE serial SET planneddate=?,publisheddate=? WHERE subscriptionid=? AND status=?');
+ # Each subscription has only one 'expected' issue, with serial.status==1.
+ $sth->execute( $date->output('iso'),$date->output('iso'), $subscriptionid, 1);
+ return 0;
+
+}
+
+=head2 ModSubscription
+
+=over 4
+
+this function modify a subscription. Put all new values on input args.
+
+=back
+
+=cut
+
+sub ModSubscription {
+ my (
+ $auser, $branchcode, $aqbooksellerid, $cost,
+ $aqbudgetid, $startdate, $periodicity, $firstacquidate,
+ $dow, $irregularity, $numberpattern, $numberlength,
+ $weeklength, $monthlength, $add1, $every1,
+ $whenmorethan1, $setto1, $lastvalue1, $innerloop1,
+ $add2, $every2, $whenmorethan2, $setto2,
+ $lastvalue2, $innerloop2, $add3, $every3,
+ $whenmorethan3, $setto3, $lastvalue3, $innerloop3,
+ $numberingmethod, $status, $biblionumber, $callnumber,
+ $notes, $letter, $hemisphere, $manualhistory,
+ $internalnotes, $serialsadditems,
+ $subscriptionid
+ ) = @_;
+# warn $irregularity;
+ my $dbh = C4::Context->dbh;
+ my $query = "UPDATE subscription
+ SET librarian=?, branchcode=?,aqbooksellerid=?,cost=?,aqbudgetid=?,startdate=?,
+ periodicity=?,firstacquidate=?,dow=?,irregularity=?, numberpattern=?, numberlength=?,weeklength=?,monthlength=?,
+ add1=?,every1=?,whenmorethan1=?,setto1=?,lastvalue1=?,innerloop1=?,
+ add2=?,every2=?,whenmorethan2=?,setto2=?,lastvalue2=?,innerloop2=?,
+ add3=?,every3=?,whenmorethan3=?,setto3=?,lastvalue3=?,innerloop3=?,
+ numberingmethod=?, status=?, biblionumber=?, callnumber=?, notes=?, letter=?, hemisphere=?,manualhistory=?,internalnotes=?,serialsadditems=?
+ WHERE subscriptionid = ?";
+# warn "query :".$query;
+ my $sth = $dbh->prepare($query);
+ $sth->execute(
+ $auser, $branchcode, $aqbooksellerid, $cost,
+ $aqbudgetid, $startdate, $periodicity, $firstacquidate,
+ $dow, "$irregularity", $numberpattern, $numberlength,
+ $weeklength, $monthlength, $add1, $every1,
+ $whenmorethan1, $setto1, $lastvalue1, $innerloop1,
+ $add2, $every2, $whenmorethan2, $setto2,
+ $lastvalue2, $innerloop2, $add3, $every3,
+ $whenmorethan3, $setto3, $lastvalue3, $innerloop3,
+ $numberingmethod, $status, $biblionumber, $callnumber,
+ $notes, $letter, $hemisphere, ($manualhistory?$manualhistory:0),
+ $internalnotes, $serialsadditems,
+ $subscriptionid
+ );
+ my $rows=$sth->rows;