From 901c7479abaf3a28ffa1baa492d6e5ca61bb2db7 Mon Sep 17 00:00:00 2001
From: Aleisha Amohia <aleishaamohia@hotmail.com>
Date: Fri, 27 Oct 2017 03:04:58 +0000
Subject: [PATCH] Bug 19532: Circulation rules

Adding 3 new rules and columns to issuingrules
- recall_due_date_interval
- recall_overdue_fine
- recall_shelf_time
---
 Koha/Schema/Result/Issuingrule.pm                  | 26 ++++++++++++++++++++--
 admin/smart-rules.pl                               |  8 ++++++-
 .../bug_19532_-_adding_recalls_circ_rules.perl     | 15 +++++++++++++
 .../prog/en/modules/admin/smart-rules.tt           | 14 +++++++++++-
 4 files changed, 59 insertions(+), 4 deletions(-)
 create mode 100644 installer/data/mysql/atomicupdate/bug_19532_-_adding_recalls_circ_rules.perl

diff --git a/Koha/Schema/Result/Issuingrule.pm b/Koha/Schema/Result/Issuingrule.pm
index 0ea74ca..a6320b4 100644
--- a/Koha/Schema/Result/Issuingrule.pm
+++ b/Koha/Schema/Result/Issuingrule.pm
@@ -215,6 +215,22 @@ __PACKAGE__->table("issuingrules");
   extra: {list => ["no","yes","bib_only","item_only"]}
   is_nullable: 0
 
+=head2 recall_due_date_interval
+
+  data_type: 'integer'
+  is_nullable: 1
+
+=head2 recall_overdue_fine
+
+  data_type: 'decimal'
+  is_nullable: 1
+  size: [28,6]
+
+=head2 recall_shelf_time
+
+  data_type: 'integer'
+  is_nullable: 1
+
 =cut
 
 __PACKAGE__->add_columns(
@@ -294,6 +310,12 @@ __PACKAGE__->add_columns(
     extra => { list => ["no", "yes", "bib_only", "item_only"] },
     is_nullable => 0,
   },
+  "recall_due_date_interval",
+  { data_type => "integer", is_nullable => 1 },
+  "recall_overdue_fine",
+  { data_type => "decimal", is_nullable => 1, size => [28, 6] },
+  "recall_shelf_time",
+  { data_type => "integer", is_nullable => 1 },
 );
 
 =head1 PRIMARY KEY
@@ -313,8 +335,8 @@ __PACKAGE__->add_columns(
 __PACKAGE__->set_primary_key("branchcode", "categorycode", "itemtype");
 
 
-# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-04-27 19:15:48
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:D1443VWPcoIXN3+lIkckIQ
+# Created by DBIx::Class::Schema::Loader v0.07042 @ 2017-10-27 03:00:06
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1EXjmhkG47JNAOshMjdRqg
 
 
 # You can replace this text with custom code or comments, and it will be preserved on regeneration
diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl
index 6a55b7b..ccb86c8 100755
--- a/admin/smart-rules.pl
+++ b/admin/smart-rules.pl
@@ -152,7 +152,7 @@ elsif ($op eq 'add') {
     $issuelength = $issuelength eq q{} ? undef : $issuelength;
     my $lengthunit  = $input->param('lengthunit');
     my $hardduedate = $input->param('hardduedate') || undef;
-    $hardduedate = eval { dt_from_string( $input->param('hardduedate') ) } if ( $hardduedate );
+    $hardduedate = eval { dt_from_string( scalar $input->param('hardduedate') ) } if ( $hardduedate );
     $hardduedate = output_pref( { dt => $hardduedate, dateonly => 1, dateformat => 'iso' } ) if ( $hardduedate );
     my $hardduedatecompare = $input->param('hardduedatecompare');
     my $rentaldiscount = $input->param('rentaldiscount');
@@ -160,6 +160,9 @@ elsif ($op eq 'add') {
     my $article_requests = $input->param('article_requests') || 'no';
     my $overduefinescap = $input->param('overduefinescap') || undef;
     my $cap_fine_to_replacement_price = $input->param('cap_fine_to_replacement_price') eq 'on';
+    my $recall_due_date_interval = $input->param('recall_due_date_interval');
+    my $recall_overdue_fine = $input->param('recall_overdue_fine');
+    my $recall_shelf_time = $input->param('recall_shelf_time');
     $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
 
     my $params = {
@@ -192,6 +195,9 @@ elsif ($op eq 'add') {
         overduefinescap               => $overduefinescap,
         cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
         article_requests              => $article_requests,
+        recall_due_date_interval      => $recall_due_date_interval,
+        recall_overdue_fine           => $recall_overdue_fine,
+        recall_shelf_time             => $recall_shelf_time,
     };
 
     my $issuingrule = Koha::IssuingRules->find({categorycode => $bor, itemtype => $itemtype, branchcode => $br});
diff --git a/installer/data/mysql/atomicupdate/bug_19532_-_adding_recalls_circ_rules.perl b/installer/data/mysql/atomicupdate/bug_19532_-_adding_recalls_circ_rules.perl
new file mode 100644
index 0000000..3cf6a20
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_19532_-_adding_recalls_circ_rules.perl
@@ -0,0 +1,15 @@
+$DBversion = 'XXX';
+if( CheckVersion( $DBversion ) ) {
+    unless( column_exists( 'issuingrules', 'recall_due_date_interval' ) ) {
+        $dbh->do(q|ALTER TABLE issuingrules ADD recall_due_date_interval int(11) default NULL AFTER note|);
+    }
+    unless( column_exists( 'issuingrules', 'recall_overdue_fine' ) ) {
+        $dbh->do(q|ALTER TABLE issuingrules ADD recall_overdue_fine decimal(28,6) default NULL AFTER recall_due_date_interval|);
+    }
+    unless( column_exists( 'issuingrules', 'recall_shelf_time' ) ) {
+        $dbh->do(q|ALTER TABLE issuingrules ADD recall_shelf_time int(11) default NULL AFTER recall_overdue_fine|);
+    }
+
+    SetVersion( $DBversion );
+    print "Upgrade to $DBversion done (Bug 19532: Add columns issuingrules.recall_due_date_interval, issuingrules.recall_overdue_fine and issuingrules.recall_shelf_time)\n";
+}
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
index 99c03d3..685d876 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
@@ -208,6 +208,9 @@ $(document).ready(function() {
                 <th>Holds per record (count)</th>
                 <th>On shelf holds allowed</th>
                 <th>Item level holds</th>
+                <th>Recall due date interval (days)</th>
+                <th>Recall overdue fine amount</th>
+                <th>Recall pickup period (days)</th>
                 <th>Article requests</th>
                 <th>Rental discount (%)</th>
                 <th>Actions</th>
@@ -302,6 +305,9 @@ $(document).ready(function() {
                                                                 If any unavailable
                                                             [% END %]</td>
                                                         <td>[% IF rule.opacitemholds == 'F'%]Force[% ELSIF rule.opacitemholds == 'Y'%]Allow[% ELSE %]Don't allow[% END %]</td>
+                                                        <td>[% rule.recall_due_date_interval %]</td>
+                                                        <td>[% rule.recall_overdue_fine FILTER format("%.2f") %]</td>
+                                                        <td>[% rule.recall_shelf_time %]</td>
                                                         <td>
                                                             [% IF rule.article_requests == 'no' %]
                                                                 No
@@ -404,6 +410,9 @@ $(document).ready(function() {
                             <option value="F">Force</option>
                         </select>
                     </td>
+                    <td><input type="text" name="recall_due_date_interval" id="recall_due_date_interval" size="3"></td>
+                    <td><input type="text" name="recall_overdue_fine" id="recall_overdue_fine" size="6"></td>
+                    <td><input type="text" name="recall_shelf_time" id="recall_shelf_time" size="3"></td>
                     <td>
                         <select id="article_requests" name="article_requests">
                             <option value="no">No</option>
@@ -442,11 +451,14 @@ $(document).ready(function() {
                       <th>No renewal before</th>
                       <th>Automatic renewal</th>
                       <th>No automatic renewal after</th>
-                       <th>No automatic renewal after (hard limit)</th>
+                      <th>No automatic renewal after (hard limit)</th>
                       <th>Holds allowed (count)</th>
                       <th>Holds per record (count)</th>
                       <th>On shelf holds allowed</th>
                       <th>Item level holds</th>
+                      <th>Recall due date interval (days)</th>
+                      <th>Recall overdue fine amount</th>
+                      <th>Recall pickup period (days)</th>
                       <th>Article requests</th>
                       <th>Rental discount (%)</th>
                       <th>&nbsp;</th>
-- 
2.1.4