From 22895e677554535107243e8fe9334eeee8907e48 Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@theke.io>
Date: Wed, 1 Sep 2021 18:00:59 -0300
Subject: [PATCH] Bug 28529: Add BiblioHoldItemTypeUseForRules system
 preference

---
 .../mysql/atomicupdate/bug_28529_itype_holds.pl | 17 +++++++++++++++++
 installer/data/mysql/mandatory/sysprefs.sql     |  1 +
 .../modules/admin/preferences/circulation.pref  |  5 +++++
 3 files changed, 23 insertions(+)
 create mode 100755 installer/data/mysql/atomicupdate/bug_28529_itype_holds.pl

diff --git a/installer/data/mysql/atomicupdate/bug_28529_itype_holds.pl b/installer/data/mysql/atomicupdate/bug_28529_itype_holds.pl
new file mode 100755
index 0000000000..2aecd0ac29
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug_28529_itype_holds.pl
@@ -0,0 +1,17 @@
+use Modern::Perl;
+
+return {
+    bug_number => "28529",
+    description => "Add BiblioHoldItemTypeUseForRules system preference",
+    up => sub {
+        my ($args) = @_;
+        my ($dbh) = @$args{qw(dbh)};
+
+        $dbh->do(q{
+            INSERT IGNORE INTO systempreferences
+                (variable,value,options,explanation,type)
+            VALUES
+                ('BiblioHoldItemTypeUseForRules','0','','If enabled, biblio-level holds with item type selected will honour circulation rules for item types','YesNo')
+        });
+    },
+}
diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql
index 0e53f66078..6902989495 100644
--- a/installer/data/mysql/mandatory/sysprefs.sql
+++ b/installer/data/mysql/mandatory/sysprefs.sql
@@ -103,6 +103,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('BiblioAddsAuthorities','0',NULL,'If ON, adding a new biblio will check for an existing authority record and create one on the fly if one doesn\'t exist','YesNo'),
 ('BiblioDefaultView','normal','normal|marc|isbd','Choose the default detail view in the catalog; choose between normal, marc or isbd','Choice'),
 ('BiblioItemtypeInfo','0','0','Control which itemtype info displays for biblio level itemtypes','YesNo'),
+('BiblioHoldItemTypeUseForRules','1','','If enabled, biblio-level holds with item type selected will honour circulation rules for item types','YesNo'),
 ('BibtexExportAdditionalFields',  '', NULL ,  'Define additional BibTex tags to export from MARC records in YAML format as an associative array with either a marc tag/subfield combination as the value, or a list of tag/subfield combinations.',  'textarea'),
 ('BlockExpiredPatronOpacActions','1',NULL,'Set whether an expired patron can perform opac actions such as placing holds or renew books, can be overridden on a per patron-type basis','YesNo'),
 ('BlockReturnOfLostItems','0','0','If enabled, items that are marked as lost cannot be returned.','YesNo'),
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
index 750e731832..817dc37f26 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref
@@ -687,6 +687,11 @@ Circulation:
                   1: Allow
                   0: "Don't allow"
             - hold fulfillment to be limited by item type.
+            - pref: BiblioHoldItemTypeUseForRules
+              choices:
+                  1: Consider
+                  0: "Don't consider"
+            - biblio-level hold item type when checking holdability.
         -
             - pref: AllowRenewalIfOtherItemsAvailable
               choices:
-- 
2.36.1