| 
      
            Lines 226-253
          or "Final Notice".  But CalcFine never defined any value.
      
      
        Link Here
      
     | 
  
        
          | 226 | 
          sub CalcFine { | 
          226 | 
          sub CalcFine { | 
        
        
          | 227 | 
              my ( $item, $bortype, $branchcode, $due_dt, $end_date  ) = @_;  | 
          227 | 
              my ( $item, $bortype, $branchcode, $due_dt, $end_date  ) = @_;  | 
        
        
          | 228 | 
              my $start_date = $due_dt->clone();  | 
          228 | 
              my $start_date = $due_dt->clone();  | 
        
            
              | 229 | 
                  my $dbh = C4::Context->dbh;  | 
               | 
               | 
            
            
              | 230 | 
                  my $amount = 0;  | 
            
            
              | 231 | 
                  my $charge_duration;  | 
            
        
          | 232 | 
              # get issuingrules (fines part will be used)  | 
          229 | 
              # get issuingrules (fines part will be used)  | 
        
        
          | 233 | 
              my $data = C4::Circulation::GetIssuingRule($bortype, $item->{itemtype}, $branchcode); | 
          230 | 
              my $data = C4::Circulation::GetIssuingRule($bortype, $item->{itemtype}, $branchcode); | 
        
            
              | 234 | 
                  if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { | 
               | 
               | 
            
            
              | 235 | 
                      my $calendar = Koha::Calendar->new( branchcode => $branchcode );  | 
            
            
              | 236 | 
                      $charge_duration = $calendar->days_between( $start_date, $end_date );  | 
            
            
              | 237 | 
                  } else { | 
            
            
              | 238 | 
                      $charge_duration = $end_date - $start_date;  | 
            
            
              | 239 | 
                  }  | 
            
            
              | 240 | 
                  # correct for grace period.  | 
            
        
          | 241 | 
              my $fine_unit = $data->{lengthunit}; | 
          231 | 
              my $fine_unit = $data->{lengthunit}; | 
        
        
          | 242 | 
              $fine_unit ||= 'days';  | 
          232 | 
              $fine_unit ||= 'days';  | 
        
          
            
              | 243 | 
                  my $chargeable_units;  | 
              233 | 
               | 
            
            
              | 244 | 
                  if ($fine_unit eq 'hours') { | 
              234 | 
                  my $chargeable_units = _get_chargeable_units($fine_unit, $start_date, $end_date, $branchcode);  | 
            
            
              | 245 | 
                      $chargeable_units = $charge_duration->hours(); # TODO closed times???  | 
               | 
               | 
            
            
              | 246 | 
                  }  | 
            
            
              | 247 | 
                  else { | 
            
            
              | 248 | 
                      $chargeable_units = $charge_duration->days;  | 
            
            
              | 249 | 
                  }  | 
            
        
          | 250 | 
              my $days_minus_grace = $chargeable_units - $data->{firstremind}; | 
          235 | 
              my $days_minus_grace = $chargeable_units - $data->{firstremind}; | 
        
            
               | 
               | 
              236 | 
                  my $amount = 0;  | 
            
        
          | 251 | 
              if ($data->{'chargeperiod'}  && $days_minus_grace  ) {  | 
          237 | 
              if ($data->{'chargeperiod'}  && $days_minus_grace  ) {  | 
        
        
          | 252 | 
                  $amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents | 
          238 | 
                  $amount = int($chargeable_units / $data->{'chargeperiod'}) * $data->{'fine'};# TODO fine calc should be in cents | 
        
        
          | 253 | 
              } else { | 
          239 | 
              } else { | 
        
  
    | 
      
            Lines 260-265
          sub CalcFine {
      
      
        Link Here
      
     | 
  
        
          | 260 | 
              # FIXME: chargename is NEVER populated anywhere.  | 
          246 | 
              # FIXME: chargename is NEVER populated anywhere.  | 
        
        
          | 261 | 
          }  | 
          247 | 
          }  | 
        
        
          | 262 | 
           | 
          248 | 
           | 
        
            
               | 
               | 
              249 | 
              sub _get_chargeable_units { | 
            
            
              | 250 | 
                  my ($unit, $dt1, $dt2, $branchcode) = @_;  | 
            
            
              | 251 | 
                  my $charge_units = 0;  | 
            
            
              | 252 | 
                  my $charge_duration;  | 
            
            
              | 253 | 
                  if ($unit eq 'hours') { | 
            
            
              | 254 | 
                      if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { | 
            
            
              | 255 | 
                          my $calendar = Koha::Calendar->new( branchcode => $branchcode );  | 
            
            
              | 256 | 
                          $charge_duration = $calendar->hours_between( $dt1, $dt2 );  | 
            
            
              | 257 | 
                      } else { | 
            
            
              | 258 | 
                          $charge_duration = $dt2->delta_ms( $dt1 );  | 
            
            
              | 259 | 
                      }  | 
            
            
              | 260 | 
                      return $charge_duration->in_units('hours'); | 
            
            
              | 261 | 
                  }  | 
            
            
              | 262 | 
                  else { # days | 
            
            
              | 263 | 
                      if(C4::Context->preference('finesCalendar') eq 'noFinesWhenClosed') { | 
            
            
              | 264 | 
                          my $calendar = Koha::Calendar->new( branchcode => $branchcode );  | 
            
            
              | 265 | 
                          $charge_duration = $calendar->days_between( $dt1, $dt2 );  | 
            
            
              | 266 | 
                      } else { | 
            
            
              | 267 | 
                          $charge_duration = $dt2->delta_days( $dt1 );  | 
            
            
              | 268 | 
                      }  | 
            
            
              | 269 | 
                      return $charge_duration->in_units('days'); | 
            
            
              | 270 | 
                  }  | 
            
            
              | 271 | 
              }  | 
            
            
              | 272 | 
               | 
            
        
          | 263 | 
           | 
          273 | 
           | 
        
        
          | 264 | 
          =head2 GetSpecialHolidays  | 
          274 | 
          =head2 GetSpecialHolidays  | 
        
        
          | 265 | 
           | 
          275 | 
           |