From dc9991d9b48665af60038e4a65ee0b0293ab2bf7 Mon Sep 17 00:00:00 2001 From: Nahuel ANGELINETTI Date: Fri, 15 Jan 2010 12:40:48 +0100 Subject: [PATCH] (MT823) add the possibility to have enrolment end date this patch add the possibility to have an end date of enrolment, instead of a period. Like for a user category, all this category can have the same expiry date. The librarian can configure one of both, but not both. --- C4/Members.pm | 14 ++++-- admin/categorie.pl | 46 ++++++++++++------- installer/data/mysql/updatedatabase.pl | 7 +++ .../prog/en/modules/admin/categorie.tmpl | 40 ++++++++++++++-- 4 files changed, 82 insertions(+), 25 deletions(-) diff --git a/C4/Members.pm b/C4/Members.pm index c7220d5214..f9c2050d55 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -1269,16 +1269,20 @@ Return date is also in ISO format. sub GetExpiryDate { my ( $categorycode, $dateenrolled ) = @_; - my $enrolmentperiod = 12; # reasonable default + my $enrolments; if ($categorycode) { my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("select enrolmentperiod from categories where categorycode=?"); + my $sth = $dbh->prepare("SELECT enrolmentperiod,enrolmentperioddate FROM categories WHERE categorycode=?"); $sth->execute($categorycode); - $enrolmentperiod = $sth->fetchrow; + $enrolments = $sth->fetchrow_hashref; } # die "GetExpiryDate: for enrollmentperiod $enrolmentperiod (category '$categorycode') starting $dateenrolled.\n"; - my @date = split /-/,$dateenrolled; - return sprintf("%04d-%02d-%02d", Add_Delta_YM(@date,0,$enrolmentperiod)); + my @date = split (/-/,$dateenrolled); + if($enrolments->{enrolmentperiod}){ + return sprintf("%04d-%02d-%02d", Add_Delta_YM(@date,0,$enrolments->{enrolmentperiod})); + }else{ + return $enrolments->{enrolmentperioddate}; + } } =head2 checkuserpassword (OUEST-PROVENCE) diff --git a/admin/categorie.pl b/admin/categorie.pl index 57e30d9be3..cb3cd7b446 100755 --- a/admin/categorie.pl +++ b/admin/categorie.pl @@ -41,6 +41,7 @@ use CGI; use C4::Context; use C4::Auth; use C4::Output; +use C4::Dates; use C4::Form::MessagingPreferences; sub StringSearch { @@ -90,14 +91,17 @@ if ($op eq 'add_form') { my $data; if ($categorycode) { my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,category_type from categories where categorycode=?"); + my $sth=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,category_type from categories where categorycode=?"); $sth->execute($categorycode); $data=$sth->fetchrow_hashref; $sth->finish; } + $data->{'enrolmentperioddate'} = undef if ($data->{'enrolmentperioddate'} eq '0000-00-00'); + $template->param(description => $data->{'description'}, enrolmentperiod => $data->{'enrolmentperiod'}, + enrolmentperioddate => C4::Dates::format_date($data->{'enrolmentperioddate'}), upperagelimit => $data->{'upperagelimit'}, dateofbirthrequired => $data->{'dateofbirthrequired'}, enrolmentfee => sprintf("%.2f",$data->{'enrolmentfee'}), @@ -105,6 +109,7 @@ if ($op eq 'add_form') { issuelimit => $data->{'issuelimit'}, reservefee => sprintf("%.2f",$data->{'reservefee'}), category_type => $data->{'category_type'}, + DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), "type_".$data->{'category_type'} => 1, ); if (C4::Context->preference('EnhancedMessagingPreferences')) { @@ -117,13 +122,17 @@ if ($op eq 'add_form') { $template->param(add_validate => 1); my $is_a_modif = $input->param("is_a_modif"); my $dbh = C4::Context->dbh; + if($input->param('enrolmentperioddate')){ + $input->param('enrolmentperioddate' => C4::Dates::format_date_in_iso($input->param('enrolmentperioddate')) ); + } + if ($is_a_modif) { - my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"); - $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired','category_type','categorycode')); + my $sth=$dbh->prepare("UPDATE categories SET description=?,enrolmentperiod=?, enrolmentperioddate=?,upperagelimit=?,dateofbirthrequired=?,enrolmentfee=?,reservefee=?,overduenoticerequired=?,category_type=? WHERE categorycode=?"); + $sth->execute(map { $input->param($_) } ('description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired','category_type','categorycode')); $sth->finish; } else { - my $sth=$dbh->prepare("INSERT INTO categories (categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?)"); - $sth->execute(map { $input->param($_) } ('categorycode','description','enrolmentperiod','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired','category_type')); + my $sth=$dbh->prepare("INSERT INTO categories (categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,reservefee,overduenoticerequired,category_type) values (?,?,?,?,?,?,?,?,?,?)"); + $sth->execute(map { $input->param($_) } ('categorycode','description','enrolmentperiod','enrolmentperioddate','upperagelimit','dateofbirthrequired','enrolmentfee','reservefee','overduenoticerequired','category_type')); $sth->finish; } if (C4::Context->preference('EnhancedMessagingPreferences')) { @@ -146,7 +155,7 @@ if ($op eq 'add_form') { $sth->finish; $template->param(total => $total->{'total'}); - my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,category_type from categories where categorycode=?"); + my $sth2=$dbh->prepare("select categorycode,description,enrolmentperiod,enrolmentperioddate,upperagelimit,dateofbirthrequired,enrolmentfee,issuelimit,reservefee,overduenoticerequired,category_type from categories where categorycode=?"); $sth2->execute($categorycode); my $data=$sth2->fetchrow_hashref; $sth2->finish; @@ -154,8 +163,9 @@ if ($op eq 'add_form') { $template->param(totalgtzero => 1); } - $template->param(description => $data->{'description'}, + $template->param( description => $data->{'description'}, enrolmentperiod => $data->{'enrolmentperiod'}, + enrolmentperioddate => C4::Dates::format_date($data->{'enrolmentperioddate'}), upperagelimit => $data->{'upperagelimit'}, dateofbirthrequired => $data->{'dateofbirthrequired'}, enrolmentfee => sprintf("%.2f",$data->{'enrolmentfee'}), @@ -183,16 +193,18 @@ if ($op eq 'add_form') { my @loop; my ($count,$results)=StringSearch($searchfield,'web'); for (my $i=0; $i < $count; $i++){ - my %row = (categorycode => $results->[$i]{'categorycode'}, - description => $results->[$i]{'description'}, - enrolmentperiod => $results->[$i]{'enrolmentperiod'}, - upperagelimit => $results->[$i]{'upperagelimit'}, - dateofbirthrequired => $results->[$i]{'dateofbirthrequired'}, - enrolmentfee => sprintf("%.2f",$results->[$i]{'enrolmentfee'}), - overduenoticerequired => $results->[$i]{'overduenoticerequired'}, - issuelimit => $results->[$i]{'issuelimit'}, - reservefee => sprintf("%.2f",$results->[$i]{'reservefee'}), - category_type => $results->[$i]{'category_type'}, + my %row = ( + categorycode => $results->[$i]{'categorycode'}, + description => $results->[$i]{'description'}, + enrolmentperiod => $results->[$i]{'enrolmentperiod'}, + enrolmentperioddate => C4::Dates::format_date($results->[$i]{'enrolmentperioddate'}), + upperagelimit => $results->[$i]{'upperagelimit'}, + dateofbirthrequired => $results->[$i]{'dateofbirthrequired'}, + enrolmentfee => sprintf("%.2f",$results->[$i]{'enrolmentfee'}), + overduenoticerequired => $results->[$i]{'overduenoticerequired'}, + issuelimit => $results->[$i]{'issuelimit'}, + reservefee => sprintf("%.2f",$results->[$i]{'reservefee'}), + category_type => $results->[$i]{'category_type'}, "type_".$results->[$i]{'category_type'} => 1); if (C4::Context->preference('EnhancedMessagingPreferences')) { my $brief_prefs = _get_brief_messaging_prefs($results->[$i]{'categorycode'}); diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index f418f4c275..d2890d4bba 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -3378,6 +3378,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { SetVersion ($DBversion); } +$DBversion = '3.02.00.015'; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do('ALTER TABLE `categories` ADD COLUMN `enrolmentperioddate` DATE NULL DEFAULT NULL AFTER `enrolmentperiod`'); + print "Upgrade done (Add enrolment period date support)\n"; + SetVersion ($DBversion); +} + =item DropAllForeignKeys($table) Drop all foreign keys of the table $table diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tmpl index 720463f0c8..faacf1b509 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tmpl @@ -4,6 +4,7 @@ Cannot Delete: Category in UseConfirm Deletion of Category '' Category Deleted + +
Cannot have "months" and "until date" at the same time
+
  •   " size="3" maxlength="3" /> years
  •   " /> years
  • " />
  • @@ -164,7 +183,15 @@ Confirm Deletion of Category - + + + @@ -250,7 +277,14 @@ Confirm Deletion of Category StaffStatistical - + -- 2.20.1
    Category code:
    Description:
    Enrollment period: months
    Enrollment period: + + months + + until + +
    Age required: years
    Upperage limit: years
    Enrollment fee:
    months + + months + + until + + + years years