(MT823) add the possibility to have enrolment end date
authorNahuel ANGELINETTI <nahuel.angelinetti@biblibre.com>
Fri, 15 Jan 2010 11:40:48 +0000 (12:40 +0100)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Thu, 28 Jan 2010 14:11:55 +0000 (15:11 +0100)
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
admin/categorie.pl
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/categorie.tmpl

index c7220d5..f9c2050 100644 (file)
@@ -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)
index 57e30d9..cb3cd7b 100755 (executable)
@@ -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'});
index f418f4c..d2890d4 100755 (executable)
@@ -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
index 720463f..faacf1b 100644 (file)
@@ -4,6 +4,7 @@
 <!-- TMPL_IF NAME="delete_confirm" --><!-- TMPL_IF NAME="totalgtzero" -->Cannot Delete: Category <!-- TMPL_VAR NAME="categorycode" escape="html" --> in Use<!-- TMPL_ELSE -->Confirm Deletion of Category '<!-- TMPL_VAR NAME="categorycode" escape="html" -->'<!-- /TMPL_IF --><!-- /TMPL_IF -->
 <!-- TMPL_IF NAME="delete_confirmed" -->Category Deleted<!-- /TMPL_IF --></title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<!-- TMPL_INCLUDE NAME="calendar.inc" -->
 <script type="text/javascript">
 //<![CDATA[
        //
                        _alertString += "- upperagelimit is not a number\n";
                                
                }
+               if(ff.enrolmentperioddate.value && ff.enrolmentperiod.value){
+                       document.getElementById('enrolmentmessage').className = "error";
+                       return false;
+               }
                
                if (ok) { // if there is a problem
                        alert(_alertString);
        <li><label for="categorycode">Category code: </label> &nbsp; <input type="text" name="categorycode" id="categorycode" size="10" maxlength="10" onblur="toUC(this)" /></li>
        <!-- /TMPL_IF -->
        <li><label for="description">Description: </label> &nbsp; <input type="text" name="description" id="description" size="40" maxlength="80" value="<!-- TMPL_VAR NAME="description" escape="html" -->" /></li>
-       <li><label for="enrolmentperiod">Enrollment period: </label> &nbsp; <input type="text" name="enrolmentperiod" id="enrolmentperiod" size="3" maxlength="3" value="<!-- TMPL_VAR NAME="enrolmentperiod" -->" /> months</li>
+       <li><label for="enrolmentperiod">Enrollment period: </label> &nbsp; 
+               <input type="text" name="enrolmentperiod" id="enrolmentperiod" size="3" maxlength="3" value="<!-- TMPL_IF NAME="enrolmentperiod" --><!-- TMPL_VAR NAME="enrolmentperiod" --><!-- /TMPL_IF -->" /> months <br />
+               <label for="enrolmentperioddate">Until date: </label> &nbsp;
+               <input type="text" name="enrolmentperioddate" id="enrolmentperioddate" value="<!-- TMPL_VAR NAME="enrolmentperioddate" -->" /> <img src="<!-- TMPL_VAR Name="themelang" -->/lib/calendar/cal.gif" id="enrolmentperioddate_button" alt="Show Calendar" />
+               <script type="text/javascript">
+            //<![CDATA[
+               Calendar.setup({
+                    inputField : "enrolmentperioddate",
+                    ifFormat : "<!-- TMPL_VAR NAME="DHTMLcalendar_dateformat" -->",
+                       button : "enrolmentperioddate_button"
+               });
+               //]]>
+        </script>
+               <div id="enrolmentmessage" class="hint">Cannot have "months" and "until date" at the same time</div>
+       </li>
        <li><label for="dateofbirthrequired">Age required: </label> &nbsp; <input type="text" name="dateofbirthrequired" id="dateofbirthrequired" value="<!-- TMPL_VAR NAME="dateofbirthrequired" -->" size="3" maxlength="3" /> years</li>
        <li><label for="upperagelimit">Upperage limit: </label> &nbsp; <input type="text" name="upperagelimit" id="upperagelimit" size="3" maxlength="3" value="<!-- TMPL_VAR NAME="upperagelimit" -->" /> years</li>
        <li><label for="enrolmentfee">Enrollment fee: </label><input type="text" name="enrolmentfee" id="enrolmentfee" size="6" value="<!-- TMPL_VAR NAME="enrolmentfee" -->" /></li>
@@ -164,7 +183,15 @@ Confirm Deletion of Category <!-- TMPL_VAR NAME="categorycode" escape="html" -->
        <table>
        <tr><th scope="row">Category code: </th><td><!-- TMPL_VAR NAME="categorycode" escape="html" --></td></tr>
        <tr><th scope="row">Description: </th><td><!-- TMPL_VAR NAME="description" escape="html" --></td></tr>
-       <tr><th scope="row">Enrollment period: </th><td><!-- TMPL_VAR NAME="enrolmentperiod" --> months</td></tr>
+       <tr><th scope="row">Enrollment period: </th>
+               <td>
+                       <!-- TMPL_IF NAME="enrolmentperiod" -->
+                               <!-- TMPL_VAR NAME="enrolmentperiod" --> months
+                       <!-- TMPL_ELSE -->
+                               until <!-- TMPL_VAR NAME="enrolmentperioddate" -->
+                       <!-- /TMPL_IF -->
+               </td>
+       </tr>
        <tr><th scope="row">Age required: </th><td><!-- TMPL_VAR NAME="dateofbirthrequired" --> years</td></tr>
        <tr><th scope="row">Upperage limit: </th><td><!-- TMPL_VAR NAME="upperagelimit" --> years</td></tr>
        <tr><th scope="row">Enrollment fee: </th><td><!-- TMPL_VAR NAME="enrolmentfee" --></td></tr>
@@ -250,7 +277,14 @@ Confirm Deletion of Category <!-- TMPL_VAR NAME="categorycode" escape="html" -->
                             <!-- TMPL_IF NAME="type_S" -->Staff<!-- /TMPL_IF -->
                             <!-- TMPL_IF NAME="type_X" -->Statistical<!-- /TMPL_IF -->
                         </td>
-                        <td><!-- TMPL_VAR NAME="enrolmentperiod" --> months</td>
+                        <td>
+                               <!-- TMPL_IF NAME="enrolmentperiod" -->
+                                       <!-- TMPL_VAR NAME="enrolmentperiod" --> months
+                               <!-- TMPL_ELSE -->
+                                       until <!-- TMPL_VAR NAME="enrolmentperioddate" -->
+                               <!-- /TMPL_IF -->
+                        
+                        </td>
                         <td><!-- TMPL_VAR NAME="dateofbirthrequired" --> years</td>
                        <td><!-- TMPL_VAR NAME="upperagelimit" --> years</td>
                         <td><!-- TMPL_VAR NAME="enrolmentfee" --></td>