Bug 25771: Allow the user to sort checkouts by the renew column in the OPAC
[koha-ffzg.git] / installer / onboarding.pl
index 77aa120..f3be391 100755 (executable)
@@ -30,7 +30,7 @@ use Koha::DateUtils;
 use Koha::Patrons;
 use Koha::Patron::Categories;
 use Koha::ItemTypes;
-use Koha::IssuingRules;
+use Koha::CirculationRules;
 
 #Setting variables
 my $input = new CGI;
@@ -144,8 +144,14 @@ if ( $step == 3 ) {
         my $secondpassword = $input->param('password2') || '';
         my $cardnumber     = $input->param('cardnumber');
         my $userid         = $input->param('userid');
+        my $categorycode = $input->param('categorycode_entry');
+        my $patron_category =
+          Koha::Patron::Categories->find( $categorycode );
+
+        my ( $is_valid, $passworderror ) =
+          Koha::AuthUtils::is_password_valid( $firstpassword,
+            $patron_category );
 
-        my ( $is_valid, $passworderror) = Koha::AuthUtils::is_password_valid( $firstpassword );
 
         if ( my $error_code = checkcardnumber($cardnumber) ) {
             if ( $error_code == 1 ) {
@@ -171,7 +177,7 @@ if ( $step == 3 ) {
                 firstname    => scalar $input->param('firstname'),
                 cardnumber   => scalar $input->param('cardnumber'),
                 branchcode   => scalar $input->param('libraries'),
-                categorycode => scalar $input->param('categorycode_entry'),
+                categorycode => $categorycode,
                 userid       => scalar $input->param('userid'),
                 privacy      => "default",
                 address      => "",
@@ -179,8 +185,6 @@ if ( $step == 3 ) {
                 flags        => 1,    # Will be superlibrarian
             };
 
-            my $patron_category =
-              Koha::Patron::Categories->find( $patron_data->{categorycode} );
             $patron_data->{dateexpiry} =
               $patron_category->get_expiry_date( $patron_data->{dateenrolled} );
 
@@ -242,6 +246,9 @@ if ( $step == 5 ) {
         my $lengthunit      = $input->param('lengthunit');
         my $renewalsallowed = $input->param('renewalsallowed');
         my $renewalperiod   = $input->param('renewalperiod');
+        my $reservesallowed = $input->param('reservesallowed');
+        my $holds_per_day   = $input->param('holds_per_day');
+        my $holds_per_record = $input->param('holds_per_record');
         my $onshelfholds    = $input->param('onshelfholds') || 0;
         $maxissueqty =~ s/\s//g;
         $maxissueqty = undef if $maxissueqty !~ /^\d+/;
@@ -251,43 +258,51 @@ if ( $step == 5 ) {
             branchcode      => $branchcode,
             categorycode    => $categorycode,
             itemtype        => $itemtype,
-            renewalsallowed => $renewalsallowed,
-            renewalperiod   => $renewalperiod,
-            issuelength     => $issuelength,
-            lengthunit      => $lengthunit,
-            onshelfholds    => $onshelfholds,
+            rules => {
+                renewalsallowed                  => $renewalsallowed,
+                renewalperiod                    => $renewalperiod,
+                issuelength                      => $issuelength,
+                lengthunit                       => $lengthunit,
+                onshelfholds                     => $onshelfholds,
+                article_requests                 => "no",
+                auto_renew                       => 0,
+                cap_fine_to_replacement_price    => 0,
+                chargeperiod                     => 0,
+                chargeperiod_charge_at           => 0,
+                fine                             => 0,
+                finedays                         => 0,
+                firstremind                      => 0,
+                hardduedate                      => "",
+                hardduedatecompare               => -1,
+                holds_per_day                    => $holds_per_day,
+                holds_per_record                 => $holds_per_record,
+                maxissueqty                      => $maxissueqty,
+                maxonsiteissueqty                => "",
+                maxsuspensiondays                => "",
+                no_auto_renewal_after            => "",
+                no_auto_renewal_after_hard_limit => "",
+                norenewalbefore                  => "",
+                opacitemholds                    => "N",
+                overduefinescap                  => "",
+                rentaldiscount                   => 0,
+                reservesallowed                  => $reservesallowed,
+                suspension_chargeperiod          => undef,
+              }
         };
 
-        my $issuingrule = Koha::IssuingRule->new($params);
-        eval { $issuingrule->store; };
+        eval {
+            Koha::CirculationRules->set_rules($params);
+        };
 
         if ($@) {
+            warn $@;
             push @messages, { code => 'error_on_insert_circ_rule' };
         } else {
-
-            eval {
-                Koha::CirculationRules->set_rules(
-                    {
-                        categorycode => $categorycode,
-                        itemtype     => $itemtype,
-                        branchcode   => $branchcode,
-                        rules        => {
-                            maxissueqty => $maxissueqty,
-                        }
-                    }
-                );
-            };
-
-            unless ($@) {
-                push @messages, { code => 'success_on_insert_circ_rule' };
-            }
-            else {
-                push @messages, { code => 'error_on_insert_circ_rule' };
-            }
+            push @messages, { code => 'success_on_insert_circ_rule' };
         }
     }
 
-    $step++ if Koha::IssuingRules->count;
+    $step++ if Koha::CirculationRules->count;
 }
 
 my $libraries = Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
@@ -305,7 +320,6 @@ my ( $template, $loggedinuser );
         template_name   => "onboarding/onboardingstep${step}.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
         debug           => 1,
     }
 );