| 
      
            Line 0
          
      
      
        Link Here
      
     | 
  
            
               | 
               | 
              1 | 
              use Modern::Perl;  | 
            
            
              | 2 | 
              use Koha::Installer::Output qw(say_warning say_success say_info);  | 
            
            
              | 3 | 
               | 
            
            
              | 4 | 
              return { | 
            
            
              | 5 | 
                  bug_number  => "36506",  | 
            
            
              | 6 | 
                  description => "Move itemtype processing fees to the circulation rules",  | 
            
            
              | 7 | 
                  up          => sub { | 
            
            
              | 8 | 
                      my ($args) = @_;  | 
            
            
              | 9 | 
                      my ( $dbh, $out ) = @$args{qw(dbh out)}; | 
            
            
              | 10 | 
               | 
            
            
              | 11 | 
                      if ( column_exists( 'itemtypes', 'processfee' ) ) { | 
            
            
              | 12 | 
                          my $existing_fees = $dbh->selectall_arrayref(  | 
            
            
              | 13 | 
                              q|SELECT itemtype, processfee FROM itemtypes WHERE processfee IS NOT NULL|,  | 
            
            
              | 14 | 
                              { Slice => {} } | 
            
            
              | 15 | 
                          );  | 
            
            
              | 16 | 
                          foreach my $existing_fee ( @{$existing_fees} ) { | 
            
            
              | 17 | 
                              my $itemtype      = $existing_fee->{itemtype}; | 
            
            
              | 18 | 
                              my $fee           = $existing_fee->{processfee}; | 
            
            
              | 19 | 
                              my $existing_rule = $dbh->selectall_arrayref(  | 
            
            
              | 20 | 
                                  q|SELECT * FROM circulation_rules WHERE branchcode IS NULL AND categorycode IS NULL  | 
            
            
              | 21 | 
                                  AND rule_name = "lost_item_processing_fee" AND itemtype = ?|, undef, $itemtype  | 
            
            
              | 22 | 
                              );  | 
            
            
              | 23 | 
                              if ( @{$existing_rule} ) { | 
            
            
              | 24 | 
                                  say_warning( $out, "Existing default rule for $itemtype found, not moving value from itemtypes" );  | 
            
            
              | 25 | 
                                  next;  | 
            
            
              | 26 | 
                              }  | 
            
            
              | 27 | 
                              $dbh->do(  | 
            
            
              | 28 | 
                                  q{ | 
            
            
              | 29 | 
                                  INSERT INTO circulation_rules (branchcode, categorycode, itemtype, rule_name, rule_value )  | 
            
            
              | 30 | 
                                  VALUES ( NULL, NULL, ?, "lost_item_processing_fee", ? )  | 
            
            
              | 31 | 
                              }, undef, $itemtype, $fee  | 
            
            
              | 32 | 
                              );  | 
            
            
              | 33 | 
                          }  | 
            
            
              | 34 | 
                          say $out "Moved existing processing fees from itemtypes to circulation rules";  | 
            
            
              | 35 | 
               | 
            
            
              | 36 | 
                          $dbh->do('ALTER TABLE itemtypes DROP COLUMN processfee'); | 
            
            
              | 37 | 
                          say $out "Removed existing processfee column from itemtypes";  | 
            
            
              | 38 | 
                      }  | 
            
            
              | 39 | 
               | 
            
            
              | 40 | 
                  },  | 
            
            
              | 41 | 
              };  |