Bug 20504: Fix lang attribute in html tag on systempreferences page
[koha.git] / admin / smart-rules.pl
index 9b745b4..fe0c9c2 100755 (executable)
 # You should have received a copy of the GNU General Public License
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
-use strict;
-use warnings;
+use Modern::Perl;
 use CGI qw ( -utf8 );
 use C4::Context;
 use C4::Output;
 use C4::Auth;
 use C4::Koha;
 use C4::Debug;
-use C4::Branch;
 use Koha::DateUtils;
 use Koha::Database;
 use Koha::IssuingRule;
@@ -127,6 +125,7 @@ elsif ($op eq 'add') {
     my $finedays     = $input->param('finedays');
     my $maxsuspensiondays = $input->param('maxsuspensiondays');
     $maxsuspensiondays = undef if $maxsuspensiondays eq q||;
+    my $suspension_chargeperiod = $input->param('suspension_chargeperiod') || 1;
     my $firstremind  = $input->param('firstremind');
     my $chargeperiod = $input->param('chargeperiod');
     my $chargeperiod_charge_at = $input->param('chargeperiod_charge_at');
@@ -137,6 +136,11 @@ elsif ($op eq 'add') {
     my $norenewalbefore  = $input->param('norenewalbefore');
     $norenewalbefore = undef if $norenewalbefore =~ /^\s*$/;
     my $auto_renew = $input->param('auto_renew') eq 'yes' ? 1 : 0;
+    my $no_auto_renewal_after = $input->param('no_auto_renewal_after');
+    $no_auto_renewal_after = undef if $no_auto_renewal_after =~ /^\s*$/;
+    my $no_auto_renewal_after_hard_limit = $input->param('no_auto_renewal_after_hard_limit') || undef;
+    $no_auto_renewal_after_hard_limit = eval { dt_from_string( $input->param('no_auto_renewal_after_hard_limit') ) } if ( $no_auto_renewal_after_hard_limit );
+    $no_auto_renewal_after_hard_limit = output_pref( { dt => $no_auto_renewal_after_hard_limit, dateonly => 1, dateformat => 'iso' } ) if ( $no_auto_renewal_after_hard_limit );
     my $reservesallowed  = $input->param('reservesallowed');
     my $holds_per_record  = $input->param('holds_per_record');
     my $onshelfholds     = $input->param('onshelfholds') || 0;
@@ -153,6 +157,7 @@ elsif ($op eq 'add') {
     my $hardduedatecompare = $input->param('hardduedatecompare');
     my $rentaldiscount = $input->param('rentaldiscount');
     my $opacitemholds = $input->param('opacitemholds') || 0;
+    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';
     $debug and warn "Adding $br, $bor, $itemtype, $fine, $maxissueqty, $maxonsiteissueqty, $cap_fine_to_replacement_price";
@@ -164,6 +169,7 @@ elsif ($op eq 'add') {
         fine                          => $fine,
         finedays                      => $finedays,
         maxsuspensiondays             => $maxsuspensiondays,
+        suspension_chargeperiod       => $suspension_chargeperiod,
         firstremind                   => $firstremind,
         chargeperiod                  => $chargeperiod,
         chargeperiod_charge_at        => $chargeperiod_charge_at,
@@ -173,6 +179,8 @@ elsif ($op eq 'add') {
         renewalperiod                 => $renewalperiod,
         norenewalbefore               => $norenewalbefore,
         auto_renew                    => $auto_renew,
+        no_auto_renewal_after         => $no_auto_renewal_after,
+        no_auto_renewal_after_hard_limit => $no_auto_renewal_after_hard_limit,
         reservesallowed               => $reservesallowed,
         holds_per_record              => $holds_per_record,
         issuelength                   => $issuelength,
@@ -184,6 +192,7 @@ elsif ($op eq 'add') {
         opacitemholds                 => $opacitemholds,
         overduefinescap               => $overduefinescap,
         cap_fine_to_replacement_price => $cap_fine_to_replacement_price,
+        article_requests              => $article_requests,
     };
 
     my $issuingrule = Koha::IssuingRules->find({categorycode => $bor, itemtype => $itemtype, branchcode => $br});
@@ -289,7 +298,7 @@ elsif ($op eq "add-branch-cat") {
                     maxonsiteissueqty = ?
                 WHERE categorycode = ?
             |);
-            $sth_search->execute($branch);
+            $sth_search->execute($categorycode);
             my $res = $sth_search->fetchrow_hashref();
             if ($res->{total}) {
                 $sth_update->execute($maxissueqty, $maxonsiteissueqty, $categorycode);
@@ -464,8 +473,7 @@ $template->param(
 my $patron_categories = Koha::Patron::Categories->search({}, { order_by => ['description'] });
 
 my @row_loop;
-my @itemtypes = @{ GetItemTypes( style => 'array' ) };
-@itemtypes = sort { lc $a->{translated_description} cmp lc $b->{translated_description} } @itemtypes;
+my $itemtypes = Koha::ItemTypes->search_with_localization;
 
 my $sth2 = $dbh->prepare("
     SELECT  issuingrules.*,
@@ -500,6 +508,11 @@ while (my $row = $sth2->fetchrow_hashref) {
     } else {
        $row->{'hardduedate'} = 0;
     }
+    if ($row->{no_auto_renewal_after_hard_limit}) {
+       my $dt = eval { dt_from_string( $row->{no_auto_renewal_after_hard_limit} ) };
+       $row->{no_auto_renewal_after_hard_limit} = eval { output_pref( { dt => $dt, dateonly => 1 } ) } if $dt;
+    }
+
     push @row_loop, $row;
 }
 
@@ -612,7 +625,7 @@ $template->param(default_rules => ($defaults ? 1 : 0));
 
 $template->param(
     patron_categories => $patron_categories,
-                        itemtypeloop => \@itemtypes,
+                        itemtypeloop => $itemtypes,
                         rules => \@sorted_row_loop,
                         humanbranch => ($branch ne '*' ? $branch : ''),
                         current_branch => $branch,