[HEAD](bug #3318) Granular renew permissions
authorNahuel ANGELINETTI <nahuel.angelinetti@biblibre.com>
Wed, 10 Jun 2009 12:18:20 +0000 (14:18 +0200)
committerHenri-Damien LAURENT <henridamien.laurent@biblibre.com>
Mon, 13 Jul 2009 10:38:16 +0000 (12:38 +0200)
This patch move the renewals allowed permissions to issuing rules.
It permit to define renewals right using CircControl and branchcode/itemtype/categorycode, and allow librarian to define more granular rules.
It drop contraints on issuingrules table to allow librarian to have "defaults" rules(for the moment a bug exist because of use "*").

C4/Circulation.pm
admin/itemtypes.pl
admin/smart-rules.pl
installer/data/mysql/kohastructure.sql
installer/data/mysql/updatedatabase.pl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tmpl
koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tmpl

index 6c2814e..7ed516f 100644 (file)
@@ -2037,40 +2037,50 @@ sub CanBookBeRenewed {
 
     # Look in the issues table for this item, lent to this borrower,
     # and not yet returned.
-
-    # FIXME - I think this function could be redone to use only one SQL call.
-    my $sth1 = $dbh->prepare(
-        "SELECT * FROM issues
-            WHERE borrowernumber = ?
-            AND itemnumber = ?"
-    );
-    $sth1->execute( $borrowernumber, $itemnumber );
-    if ( my $data1 = $sth1->fetchrow_hashref ) {
-
-        # Found a matching item
-
-        # See if this item may be renewed. This query is convoluted
-        # because it's a bit messy: given the item number, we need to find
-        # the biblioitem, which gives us the itemtype, which tells us
-        # whether it may be renewed.
-        my $query = "SELECT renewalsallowed FROM items ";
-        $query .= (C4::Context->preference('item-level_itypes'))
-                    ? "LEFT JOIN itemtypes ON items.itype = itemtypes.itemtype "
-                    : "LEFT JOIN biblioitems on items.biblioitemnumber = biblioitems.biblioitemnumber
-                       LEFT JOIN itemtypes ON biblioitems.itemtype = itemtypes.itemtype ";
-        $query .= "WHERE items.itemnumber = ?";
-        my $sth2 = $dbh->prepare($query);
-        $sth2->execute($itemnumber);
-        if ( my $data2 = $sth2->fetchrow_hashref ) {
-            $renews = $data2->{'renewalsallowed'};
-        }
-        if ( ( $renews && $renews > $data1->{'renewals'} ) || $override_limit ) {
+    my %branch = (
+            'ItemHomeLibrary' => 'items.homebranch',
+            'PickupLibrary'   => 'items.holdingbranch',
+            'PatronLibrary'   => 'borrowers.branchcode'
+            );
+    my $controlbranch = $branch{C4::Context->preference('CircControl')};
+    my $itype         = C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype';
+    
+    my $sthcount = $dbh->prepare("
+                   SELECT 
+                    borrowers.categorycode, biblioitems.itemtype, issues.renewals, renewalsallowed, $controlbranch
+                   FROM  issuingrules, 
+                   issues 
+                   LEFT JOIN items USING (itemnumber) 
+                   LEFT JOIN borrowers USING (borrowernumber) 
+                   LEFT JOIN biblioitems USING (biblioitemnumber)
+                   
+                   WHERE
+                    issuingrules.categorycode = borrowers.categorycode
+                   AND
+                    issuingrules.itemtype = $itype
+                   AND
+                    (issuingrules.branchcode = $controlbranch OR issuingrules.branchcode = '*') 
+                   AND 
+                    borrowernumber = ? 
+                   AND
+                    itemnumber = ?
+                   ORDER BY
+                    issuingrules.categorycode desc,
+                    issuingrules.itemtype desc,
+                    issuingrules.branchcode desc
+                   LIMIT 1;
+                  ");
+
+    $sthcount->execute( $borrowernumber, $itemnumber );
+    if ( my $data1 = $sthcount->fetchrow_hashref ) {
+        
+        if ( ( $data1->{renewalsallowed} && $data1->{renewalsallowed} > $data1->{renewals} ) || $override_limit ) {
             $renewokay = 1;
         }
         else {
                        $error="too_many";
                }
-        $sth2->finish;
+               
         my ( $resfound, $resrec ) = C4::Reserves::CheckReserves($itemnumber);
         if ($resfound) {
             $renewokay = 0;
@@ -2078,7 +2088,7 @@ sub CanBookBeRenewed {
         }
 
     }
-    $sth1->finish;
+    $sthcount->finish;
     return ($renewokay,$error);
 }
 
index 9f0395c..2c31a18 100755 (executable)
@@ -112,7 +112,6 @@ if ( $op eq 'add_form' ) {
     $template->param(
         itemtype        => $itemtype,
         description     => $data->{'description'},
-        renewalsallowed => $data->{'renewalsallowed'},
         rentalcharge    => sprintf( "%.2f", $data->{'rentalcharge'} ),
         notforloan      => $data->{'notforloan'},
         imageurl        => $data->{'imageurl'},
@@ -138,7 +137,6 @@ elsif ( $op eq 'add_validate' ) {
         my $query2 = '
             UPDATE itemtypes
             SET    description = ?
-                 , renewalsallowed = ?
                  , rentalcharge = ?
                  , notforloan = ?
                  , imageurl = ?
@@ -148,7 +146,6 @@ elsif ( $op eq 'add_validate' ) {
         $sth = $dbh->prepare($query2);
         $sth->execute(
             $input->param('description'),
-            $input->param('renewalsallowed'),
             $input->param('rentalcharge'),
             ( $input->param('notforloan') ? 1 : 0 ),
             (
@@ -165,7 +162,7 @@ elsif ( $op eq 'add_validate' ) {
     else {    # add a new itemtype & not modif an old
         my $query = "
             INSERT INTO itemtypes
-                (itemtype,description,renewalsallowed,rentalcharge, notforloan, imageurl,summary)
+                (itemtype,description,rentalcharge, notforloan, imageurl,summary)
             VALUES
                 (?,?,?,?,?,?,?);
             ";
@@ -174,7 +171,6 @@ elsif ( $op eq 'add_validate' ) {
         $sth->execute(
             $input->param('itemtype'),
             $input->param('description'),
-            $input->param('renewalsallowed'),
             $input->param('rentalcharge'),
             $input->param('notforloan') ? 1 : 0,
             $image eq 'removeImage' ?           ''                 :
@@ -204,14 +200,13 @@ elsif ( $op eq 'delete_confirm' ) {
 
     my $sth =
       $dbh->prepare(
-"select itemtype,description,renewalsallowed,rentalcharge from itemtypes where itemtype=?"
+"select itemtype,description,rentalcharge from itemtypes where itemtype=?"
       );
     $sth->execute($itemtype);
     my $data = $sth->fetchrow_hashref;
     $template->param(
         itemtype        => $itemtype,
         description     => $data->{description},
-        renewalsallowed => $data->{renewalsallowed},
         rentalcharge    => sprintf( "%.2f", $data->{rentalcharge} ),
         imageurl        => $data->{imageurl},
         total           => $total
index a3cdff9..db5bca9 100755 (executable)
@@ -99,8 +99,8 @@ elsif ($op eq 'delete-branch-item') {
 # save the values entered
 elsif ($op eq 'add') {
     my $sth_search = $dbh->prepare("SELECT COUNT(*) AS total FROM issuingrules WHERE branchcode=? AND categorycode=? AND itemtype=?");
-    my $sth_insert = $dbh->prepare("INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, issuelength, fine, finedays, firstremind, chargeperiod) VALUES(?,?,?,?,?,?,?,?,?)");
-    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, issuelength=? WHERE branchcode=? AND categorycode=? AND itemtype=?");
+    my $sth_insert = $dbh->prepare("INSERT INTO issuingrules (branchcode, categorycode, itemtype, maxissueqty, renewalsallowed, issuelength, fine, finedays, firstremind, chargeperiod) VALUES(?,?,?,?,?,?,?,?,?)");
+    my $sth_update=$dbh->prepare("UPDATE issuingrules SET fine=?, finedays=?, firstremind=?, chargeperiod=?, maxissueqty=?, renewalsallowed=?, issuelength=? WHERE branchcode=? AND categorycode=? AND itemtype=?");
     
     my $br = $branch; # branch
     my $bor  = $input->param('categorycode'); # borrower category
@@ -110,6 +110,7 @@ elsif ($op eq 'add') {
     my $firstremind  = $input->param('firstremind');
     my $chargeperiod = $input->param('chargeperiod');
     my $maxissueqty  = $input->param('maxissueqty');
+    my $renewalsallowed  = $input->param('renewalsallowed');
     $maxissueqty =~ s/\s//g;
     $maxissueqty = undef if $maxissueqty !~ /^\d+/;
     my $issuelength  = $input->param('issuelength');
@@ -118,9 +119,9 @@ elsif ($op eq 'add') {
     $sth_search->execute($br,$bor,$cat);
     my $res = $sth_search->fetchrow_hashref();
     if ($res->{total}) {
-        $sth_update->execute($fine, $finedays, $firstremind, $chargeperiod, $maxissueqty,$issuelength,$br,$bor,$cat);
+        $sth_update->execute($fine, $finedays, $firstremind, $chargeperiod, $maxissueqty,$renewalsallowed,$issuelength,$br,$bor,$cat);
     } else {
-        $sth_insert->execute($br,$bor,$cat,$maxissueqty,$issuelength,$fine,$finedays,$firstremind,$chargeperiod);
+        $sth_insert->execute($br,$bor,$cat,$maxissueqty,$renewalsallowed,$issuelength,$fine, $finedays,$firstremind,$chargeperiod);
     }
 } 
 elsif ($op eq "set-branch-defaults") {
index 434cfb1..e2b62af 100644 (file)
@@ -1142,6 +1142,7 @@ CREATE TABLE `issuingrules` (
   `chargename` varchar(100) default NULL,
   `maxissueqty` int(4) default NULL,
   `issuelength` int(4) default NULL,
+  `renewalsallowed` smallint(6) NOT NULL default "0",
   `branchcode` varchar(10) NOT NULL default '',
   PRIMARY KEY  (`branchcode`,`categorycode`,`itemtype`),
   KEY `categorycode` (`categorycode`),
@@ -1210,7 +1211,6 @@ DROP TABLE IF EXISTS `itemtypes`;
 CREATE TABLE `itemtypes` (
   `itemtype` varchar(10) NOT NULL default '',
   `description` mediumtext,
-  `renewalsallowed` smallint(6) default NULL,
   `rentalcharge` double(16,4) default NULL,
   `notforloan` smallint(6) default NULL,
   `imageurl` varchar(200) default NULL,
index 893de15..dd0cf7d 100755 (executable)
@@ -1966,6 +1966,232 @@ if (C4::Context->preference("Version") =~/3\.00/) {
                print STDERR "cannot read file $ENV{'PERL5LIB'}/installer/data/mysql/updatedatabase30.pl : $@ \n" if ($@);
        }
 }
+
+$DBversion = "3.01.00.016";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('Babeltheque',0,'Turn ON Babeltheque content  - See babeltheque.com to subscribe to this service','','YesNo')");
+    print "Upgrade to $DBversion done (Added Babeltheque syspref)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.017";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `subscription` ADD `staffdisplaycount` VARCHAR(10) NULL;");
+    $dbh->do("ALTER TABLE `subscription` ADD `opacdisplaycount` VARCHAR(10) NULL;");
+    $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
+    VALUES (
+    'StaffSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the Staff client', 'Integer'
+    );");
+       $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` )
+    VALUES (
+    'OPACSerialIssueDisplayCount', '3', '', 'Number of serial issues to display per subscription in the OPAC', 'Integer'
+    );");
+
+    print "Upgrade to $DBversion done ( Updated table for Serials Display)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.018";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE deletedborrowers ADD `smsalertnumber` varchar(50) default NULL");
+    print "Upgrade to $DBversion done (added deletedborrowers.smsalertnumber, missed in 3.00.00.091)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.019";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+        $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OPACShowCheckoutName','0','Displays in the OPAC the name of patron who has checked out the material. WARNING: Most sites should leave this off. It is intended for corporate or special sites which need to track who has the item.','','YesNo')");
+    print "Upgrade to $DBversion done (adding OPACShowCheckoutName systempref)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.020";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesID','','See:http://librarything.com/forlibraries/','','free')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesEnabled','0','Enable or Disable Library Thing for Libraries Features','','YesNo')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('LibraryThingForLibrariesTabbedView','0','Put LibraryThingForLibraries Content in Tabs.','','YesNo')");
+    print "Upgrade to $DBversion done (adding LibraryThing for Libraries sysprefs)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.021";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    my $enable_reviews = C4::Context->preference('OPACAmazonEnabled') ? '1' : '0';
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OPACAmazonReviews', '$enable_reviews', 'Display Amazon readers reviews on OPAC','','YesNo')");
+    print "Upgrade to $DBversion done (adding OPACAmazonReviews syspref)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.022';
+if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE `labels_conf` MODIFY COLUMN `formatstring` mediumtext DEFAULT NULL");
+    print "Upgrade to $DBversion done (bug 2945: increase size of labels_conf.formatstring)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.023';
+if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE biblioitems        MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
+    $dbh->do("ALTER TABLE deletedbiblioitems MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
+    $dbh->do("ALTER TABLE import_biblios     MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
+    $dbh->do("ALTER TABLE suggestions        MODIFY COLUMN isbn VARCHAR(30) DEFAULT NULL");
+    print "Upgrade to $DBversion done (bug 2765: increase width of isbn column in several tables)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.024";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE labels MODIFY COLUMN batch_id int(10) NOT NULL default 1;");
+    print "Upgrade to $DBversion done (change labels.batch_id from varchar to int)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.025';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'ceilingDueDate', '', '', 'If set, date due will not be past this date.  Enter date according to the dateformat System Preference', 'free')");
+
+    print "Upgrade to $DBversion done (added ceilingDueDate system preference)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.026';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'numReturnedItemsToShow', '20', '', 'Number of returned items to show on the check-in page', 'Integer')");
+
+    print "Upgrade to $DBversion done (added numReturnedItemsToShow system preference)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.027';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE zebraqueue CHANGE `biblio_auth_number` `biblio_auth_number` bigint(20) unsigned NOT NULL default 0");
+    print "Upgrade to $DBversion done (Increased size of zebraqueue biblio_auth_number to address bug 3148.)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.028';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    my $enable_reviews = C4::Context->preference('AmazonEnabled') ? '1' : '0';
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('AmazonReviews', '$enable_reviews', 'Display Amazon reviews on staff interface','','YesNo')");
+    print "Upgrade to $DBversion done (added AmazonReviews)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.029';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do(q( UPDATE language_rfc4646_to_iso639
+                SET iso639_2_code = 'spa'
+                WHERE rfc4646_subtag = 'es'
+                AND   iso639_2_code = 'rus' )
+            );
+    print "Upgrade to $DBversion done (fixed bug 2599: using Spanish search limit retrieves Russian results)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.030";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` ( `variable` , `value` , `options` , `explanation` , `type` ) VALUES ( 'AllowNotForLoanOverride', '0', '', 'If ON, Koha will allow the librarian to loan a not for loan item.', 'YesNo')");
+    print "Upgrade to $DBversion done (added AllowNotForLoanOverride system preference)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.031";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE branch_transfer_limits
+              MODIFY toBranch   varchar(10) NOT NULL,
+              MODIFY fromBranch varchar(10) NOT NULL,
+              MODIFY itemtype   varchar(10) NULL");
+    print "Upgrade to $DBversion done (fix column widths in branch_transfer_limits)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.032";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do(<<ENDOFRENEWAL);
+INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('RenewalPeriodBase', 'now', 'Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','date_due|now','Choice');
+ENDOFRENEWAL
+    print "Upgrade to $DBversion done (Change the field)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.033";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do(q/
+        ALTER TABLE borrower_message_preferences
+        MODIFY borrowernumber int(11) default NULL,
+        ADD    categorycode varchar(10) default NULL AFTER borrowernumber,
+        ADD KEY `categorycode` (`categorycode`),
+        ADD CONSTRAINT `borrower_message_preferences_ibfk_3` 
+                       FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) 
+                       ON DELETE CASCADE ON UPDATE CASCADE
+    /);
+    print "Upgrade to $DBversion done (DB changes to allow patron category defaults for messaging preferences)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = "3.01.00.034";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `subscription` ADD COLUMN `graceperiod` INT(11) NOT NULL default '0';");
+    print "Upgrade to $DBversion done (Adding graceperiod column to subscription table)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.035';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do(q{ ALTER TABLE `subscription` ADD location varchar(80) NULL DEFAULT '' AFTER callnumber; });
+   print "Upgrade to $DBversion done (Adding location to subscription table)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.036';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("UPDATE systempreferences SET explanation = 'Choose the default detail view in the staff interface; choose between normal, labeled_marc, marc or isbd'
+              WHERE variable = 'IntranetBiblioDefaultView'
+              AND   explanation = 'IntranetBiblioDefaultView'");
+    $dbh->do("UPDATE systempreferences SET type = 'Choice', options = 'normal|marc|isbd|labeled_marc'
+              WHERE variable = 'IntranetBiblioDefaultView'");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewISBD','1','Allow display of ISBD view of bibiographic records','','YesNo')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewLabeledMARC','0','Allow display of labeled MARC view of bibiographic records','','YesNo')");
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('viewMARC','1','Allow display of MARC view of bibiographic records','','YesNo')");
+    print "Upgrade to $DBversion done (new viewISBD, viewLabeledMARC, viewMARC sysprefs and tweak IntranetBiblioDefaultView)\n";
+    SetVersion ($DBversion);
+}
+
+$DBversion = '3.01.00.037';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do('ALTER TABLE authorised_values ADD KEY `lib` (`lib`)');
+    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type)VALUES('FilterBeforeOverdueReport','0','Do not run overdue report until filter selected','','YesNo')");
+    SetVersion ($DBversion);
+    print "Upgrade to $DBversion done (added FilterBeforeOverdueReport syspref and new index on authorised_values)\n";
+}
+
+$DBversion = '3.01.00.038';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do('ALTER TABLE issuingrules DROP FOREIGN KEY issuingrules_ibfk_1');
+    $dbh->do('ALTER TABLE issuingrules DROP FOREIGN KEY issuingrules_ibfk_2');
+    SetVersion ($DBversion);
+    print "Upgrade to $DBversion done (deleting contraints in issuingrules)\n";
+}
+
+$DBversion = '3.01.00.039';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do('ALTER TABLE issuingrules ADD COLUMN `renewalsallowed` smallint(6) NOT NULL default "0" AFTER `issuelength`;');
+    $dbh->do('ALTER TABLE issuingrules ADD COLUMN `finedays` smallint(6) NOT NULL default "0" AFTER `fine`;');
+    $sth = $dbh->prepare("SELECT itemtype, renewalsallowed FROM itemtypes");
+    $sth->execute();
+
+    my $sthupd = $dbh->prepare("UPDATE issuingrules SET renewalsallowed = ? WHERE itemtype = ?");
+    
+    while(my $row = $sth->fetchrow_hashref){
+        $sthupd->execute($row->{renewalsallowed}, $row->{itemtype});
+    }
+    
+    $dbh->do('ALTER TABLE itemtypes DROP COLUMN `renewalsallowed`;');
+    
+    SetVersion ($DBversion);
+    print "Upgrade to $DBversion done (Moving allowed renewals from itemtypes to issuingrule)\n";
+}
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table
index a519c0e..fbdb62c 100644 (file)
@@ -285,7 +285,6 @@ Item Types Administration
     <th>Code</th>
     <th>Description</th>
     <th>Not for loan</th>
-    <th>Renewable</th>
     <th>Charge</th>
     <th>Actions</th>
   </tr>
@@ -304,13 +303,6 @@ Item Types Administration
     <td><!-- TMPL_VAR name="description" --></td>
     <td><!-- TMPL_IF NAME="notforloan" -->Yes<!-- TMPL_ELSE -->&nbsp;<!-- /TMPL_IF --></td>
     <td>
-    <!-- TMPL_IF NAME="renewalsallowed" -->
-      <!-- TMPL_VAR name="renewalsallowed" --> times
-    <!-- TMPL_ELSE -->
-      No
-    <!-- /TMPL_IF -->
-    </td>
-    <td>
     <!-- TMPL_UNLESS name="notforloan" -->
       <!-- TMPL_VAR NAME="rentalcharge" -->
     <!-- /TMPL_UNLESS -->
index ca7ed31..4f9aa99 100644 (file)
@@ -69,6 +69,7 @@ $(document).ready(function() {
                 <th>Fine Grace Period</th>
                 <th>Fine Charging Interval</th>
                 <th>Current Checkouts Allowed</th>
+                <th>Renewals Allowed</th>
                 <th>Loan Period</th><th>&nbsp;</th>
             </tr>
             <!-- TMPL_LOOP NAME="rules" -->
@@ -103,6 +104,7 @@ $(document).ready(function() {
                             <!-- TMPL_VAR NAME="maxissueqty" -->
                         <!-- /TMPL_IF -->
                     </td>
+                                       <td><!-- TMPL_IF NAME="renewalsallowed" --><!-- TMPL_VAR NAME="renewalsallowed" --> time(s)<!-- /TMPL_IF --></td>
                     <td><!-- TMPL_IF NAME="issuelength" --><!-- TMPL_VAR NAME="issuelength" --> day(s)<!-- /TMPL_IF --></td>
                     <td>
                         <a class="button" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&amp;itemtype=<!-- TMPL_VAR NAME="itemtype" -->&amp;categorycode=<!-- TMPL_VAR NAME="categorycode" -->&amp;branch=<!-- TMPL_VAR NAME="branch" -->">Delete</a>
@@ -131,6 +133,7 @@ $(document).ready(function() {
                     <td><input name="firstremind" size="2" /> day(s)</td>
                     <td><input name="chargeperiod" size="2" /> day(s)</td>
                     <td><input name="maxissueqty" size="3" /></td>
+                    <td><input name="renewalsallowed" size="3" /></td>
                     <td><input name="issuelength" size="3" /> day(s)</td>
                     <td><input type="hidden" name="branch" value="<!-- TMPL_VAR NAME="branch" -->"/><input type="submit" value="Add" class="submit" /></td>
                 </tr>