From e1593c898f6c8951cba8fb5ce9da3aef9c249ce3 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Fri, 22 Mar 2013 09:53:51 +0000 Subject: [PATCH] Bug 7688: (follow-up) set firstacquidate in updatedatabase if it's not set firstacquidate is now a mandatory field, so it must be set. The updatedatabase process set firstacquidate value to one of: - the planned date of the first serial for this subscription, or if not found, - the subscription start date. + auto-select the numbering pattern when modifying a subscription. Signed-off-by: Bernardo Gonzalez Kriegel Signed-off-by: Galen Charlton --- installer/data/mysql/updatedatabase.pl | 32 +++++++++++++++++++ .../en/modules/serials/subscription-add.tt | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index f2f1aabb53..6289520f54 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7547,6 +7547,38 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { ADD CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE |); + # Set firstacquidate if not already set (firstacquidate is now mandatory) + my $get_first_planneddate_sth = $dbh->prepare(qq| + SELECT planneddate + FROM serial + WHERE subscriptionid = ? + ORDER BY serialid + LIMIT 1 + |); + my $update_firstacquidate_sth = $dbh->prepare(qq| + UPDATE subscription + SET firstacquidate = ? + WHERE subscriptionid = ? + |); + my $get_subscriptions_sth = $dbh->prepare(qq| + SELECT subscriptionid, startdate + FROM subscription + WHERE firstacquidate IS NULL + OR firstacquidate = '0000-00-00' + |); + $get_subscriptions_sth->execute; + while ( my ($subscriptionid, $startdate) = $get_subscriptions_sth->fetchrow ) { + # Try to get the planned date of the first serial + $get_first_planneddate_sth->execute($subscriptionid); + my ($first_planneddate) = $get_first_planneddate_sth->fetchrow; + if ($first_planneddate and $first_planneddate =~ /^\d{4}-\d{2}-\d{2}$/) { + $update_firstacquidate_sth->execute($first_planneddate, $subscriptionid); + } else { + # Defaults to subscription start date + $update_firstacquidate_sth->execute($startdate, $subscriptionid); + } + } + print "Upgrade to $DBversion done (Add subscription_frequencies and subscription_numberpatterns tables)\n"; SetVersion($DBversion); } 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 d98f0b640c..b0d84eecf6 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 @@ -693,7 +693,7 @@ $(document).ready(function() { [% FOREACH numberpattern IN numberpatterns %] [% IF (numberpattern.selected) %] -