View | Details | Raw Unified | Return to bug 4530
Collapse All | Expand All

(-)a/C4/Circulation.pm (-214 / +104 lines)
Lines 75-81 BEGIN { Link Here
75
		&GetItemIssue
75
		&GetItemIssue
76
		&GetItemIssues
76
		&GetItemIssues
77
		&GetIssuingCharges
77
		&GetIssuingCharges
78
		&GetIssuingRule
79
        &GetBranchBorrowerCircRule
78
        &GetBranchBorrowerCircRule
80
        &GetBranchItemRule
79
        &GetBranchItemRule
81
		&GetBiblioIssues
80
		&GetBiblioIssues
Lines 357-368 sub TooMany { Link Here
357
 
356
 
358
    # given branch, patron category, and item type, determine
357
    # given branch, patron category, and item type, determine
359
    # applicable issuing rule
358
    # applicable issuing rule
360
    my $issuing_rule = GetIssuingRule($cat_borrower, $type, $branch);
359
    my $issuing_rule = GetIssuingRuleRecord($cat_borrower, $type, $branch, 'maxissueqty');
361
360
362
    # if a rule is found and has a loan limit set, count
361
    # if a rule is found and has a loan limit set, count
363
    # how many loans the patron already has that meet that
362
    # how many loans the patron already has that meet that
364
    # rule
363
    # rule
365
    if (defined($issuing_rule) and defined($issuing_rule->{'maxissueqty'})) {
364
    if ( $issuing_rule ) {
366
        my @bind_params;
365
        my @bind_params;
367
        my $count_query = "SELECT COUNT(*) FROM issues
366
        my $count_query = "SELECT COUNT(*) FROM issues
368
                           JOIN items USING (itemnumber) ";
367
                           JOIN items USING (itemnumber) ";
Lines 1094-1149 Get loan length for an itemtype, a borrower type and a branch Link Here
1094
1093
1095
sub GetLoanLength {
1094
sub GetLoanLength {
1096
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1095
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1097
    my $dbh = C4::Context->dbh;
1098
    my $sth =
1099
      $dbh->prepare(
1100
"select issuelength from issuingrules where categorycode=? and itemtype=? and branchcode=? and issuelength is not null"
1101
      );
1102
# warn "in get loan lenght $borrowertype $itemtype $branchcode ";
1103
# try to find issuelength & return the 1st available.
1104
# check with borrowertype, itemtype and branchcode, then without one of those parameters
1105
    $sth->execute( $borrowertype, $itemtype, $branchcode );
1106
    my $loanlength = $sth->fetchrow_hashref;
1107
    return $loanlength->{issuelength}
1108
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1109
1110
    $sth->execute( $borrowertype, "*", $branchcode );
1111
    $loanlength = $sth->fetchrow_hashref;
1112
    return $loanlength->{issuelength}
1113
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1114
1115
    $sth->execute( "*", $itemtype, $branchcode );
1116
    $loanlength = $sth->fetchrow_hashref;
1117
    return $loanlength->{issuelength}
1118
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1119
1120
    $sth->execute( "*", "*", $branchcode );
1121
    $loanlength = $sth->fetchrow_hashref;
1122
    return $loanlength->{issuelength}
1123
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1124
1125
    $sth->execute( $borrowertype, $itemtype, "*" );
1126
    $loanlength = $sth->fetchrow_hashref;
1127
    return $loanlength->{issuelength}
1128
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1129
1130
    $sth->execute( $borrowertype, "*", "*" );
1131
    $loanlength = $sth->fetchrow_hashref;
1132
    return $loanlength->{issuelength}
1133
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1134
1135
    $sth->execute( "*", $itemtype, "*" );
1136
    $loanlength = $sth->fetchrow_hashref;
1137
    return $loanlength->{issuelength}
1138
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1139
1140
    $sth->execute( "*", "*", "*" );
1141
    $loanlength = $sth->fetchrow_hashref;
1142
    return $loanlength->{issuelength}
1143
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1144
1145
    # if no rule is set => 21 days (hardcoded)
1096
    # if no rule is set => 21 days (hardcoded)
1146
    return 21;
1097
    return GetIssuingRuleValue( $borrowertype, $itemtype, $branchcode, 'issuelength' ) || 21;
1147
}
1098
}
1148
1099
1149
1100
Lines 1157-1264 Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a Link Here
1157
1108
1158
sub GetHardDueDate {
1109
sub GetHardDueDate {
1159
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1110
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1160
    my $dbh = C4::Context->dbh;
1111
    my $issuing_rule = GetIssuingRuleRecord($borrowertype, $itemtype, $branchcode, 'hardduedate')
1161
    my $sth =
1112
      or return;
1162
      $dbh->prepare(
1113
    return (C4::Dates->new($issuing_rule->{hardduedate}, 'iso'),$issuing_rule->{hardduedatecompare});
1163
"select hardduedate, hardduedatecompare from issuingrules where categorycode=? and itemtype=? and branchcode=?"
1164
      );
1165
    $sth->execute( $borrowertype, $itemtype, $branchcode );
1166
    my $results = $sth->fetchrow_hashref;
1167
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1168
      if defined($results) && $results->{hardduedate} ne 'NULL';
1169
1170
    $sth->execute( $borrowertype, "*", $branchcode );
1171
    $results = $sth->fetchrow_hashref;
1172
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1173
      if defined($results) && $results->{hardduedate} ne 'NULL';
1174
1175
    $sth->execute( "*", $itemtype, $branchcode );
1176
    $results = $sth->fetchrow_hashref;
1177
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1178
      if defined($results) && $results->{hardduedate} ne 'NULL';
1179
1180
    $sth->execute( "*", "*", $branchcode );
1181
    $results = $sth->fetchrow_hashref;
1182
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1183
      if defined($results) && $results->{hardduedate} ne 'NULL';
1184
1185
    $sth->execute( $borrowertype, $itemtype, "*" );
1186
    $results = $sth->fetchrow_hashref;
1187
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1188
      if defined($results) && $results->{hardduedate} ne 'NULL';
1189
1190
    $sth->execute( $borrowertype, "*", "*" );
1191
    $results = $sth->fetchrow_hashref;
1192
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1193
      if defined($results) && $results->{hardduedate} ne 'NULL';
1194
1195
    $sth->execute( "*", $itemtype, "*" );
1196
    $results = $sth->fetchrow_hashref;
1197
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1198
      if defined($results) && $results->{hardduedate} ne 'NULL';
1199
1200
    $sth->execute( "*", "*", "*" );
1201
    $results = $sth->fetchrow_hashref;
1202
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1203
      if defined($results) && $results->{hardduedate} ne 'NULL';
1204
1205
    # if no rule is set => return undefined
1206
    return (undef, undef);
1207
}
1114
}
1115
   
1116
1117
=head2 GetIssuingRuleValue
1118
1119
  my $irule = &GetIssuingRuleValue($borrowertype,$itemtype,$branchcode, $rule_name)
1120
1121
Get the most specific non-null value issuing rule for an itemtype, a borrower type and a branch
1208
1122
1209
=head2 GetIssuingRule
1123
=cut
1124
1125
sub GetIssuingRuleValue {
1126
    my ( $borrowertype, $itemtype, $branchcode, $rule ) = @_;
1127
    my $irule = GetIssuingRuleRecord( $borrowertype, $itemtype, $branchcode, $rule )
1128
      or return;
1129
    return $irule->{$rule};
1130
}
1210
1131
1211
  my $irule = &GetIssuingRule($borrowertype,$itemtype,branchcode)
1132
=head2 GetIssuingRuleRecord
1212
1133
1213
FIXME - This is a copy-paste of GetLoanLength
1134
  my $irule = &GetIssuingRuleRecord($borrowertype,$itemtype,$branchcode, $rule_name)
1214
as a stop-gap.  Do not wish to change API for GetLoanLength 
1215
this close to release, however, Overdues::GetIssuingRules is broken.
1216
1135
1217
Get the issuing rule for an itemtype, a borrower type and a branch
1136
Get the most specific non-null value issuing rule for an itemtype, a borrower type and a branch
1218
Returns a hashref from the issuingrules table.
1137
If $rule_name is specified, only records with $rule_name not null are taken in account
1138
1139
Order of preference is $branchcode, $borrowertype, $itemtype
1219
1140
1220
=cut
1141
=cut
1221
1142
1222
sub GetIssuingRule {
1143
sub GetIssuingRuleRecord {
1223
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1144
    my ( $borrowertype, $itemtype, $branchcode, $rule ) = @_;
1224
    my $dbh = C4::Context->dbh;
1225
    my $sth =  $dbh->prepare( "select * from issuingrules where categorycode=? and itemtype=? and branchcode=? and issuelength is not null"  );
1226
    my $irule;
1227
1145
1228
	$sth->execute( $borrowertype, $itemtype, $branchcode );
1146
    my $irules = GetIssuingRules($borrowertype,$itemtype,$branchcode)
1229
    $irule = $sth->fetchrow_hashref;
1147
      or return;
1230
    return $irule if defined($irule) ;
1231
1148
1232
    $sth->execute( $borrowertype, "*", $branchcode );
1149
    return unless @$irules;
1233
    $irule = $sth->fetchrow_hashref;
1234
    return $irule if defined($irule) ;
1235
1150
1236
    $sth->execute( "*", $itemtype, $branchcode );
1151
    return $irules->[0] unless $rule;
1237
    $irule = $sth->fetchrow_hashref;
1238
    return $irule if defined($irule) ;
1239
1152
1240
    $sth->execute( "*", "*", $branchcode );
1153
    die qq{Invalid rule (field) "$rule"} unless exists $irules->[0]->{$rule};
1241
    $irule = $sth->fetchrow_hashref;
1242
    return $irule if defined($irule) ;
1243
1154
1244
    $sth->execute( $borrowertype, $itemtype, "*" );
1155
    foreach (@$irules) {
1245
    $irule = $sth->fetchrow_hashref;
1156
        return $_ if $_->{$rule}; # XXX defined $_->{$rule}
1246
    return $irule if defined($irule) ;
1157
    }
1158
1159
    return;
1160
}
1247
1161
1248
    $sth->execute( $borrowertype, "*", "*" );
1162
=head2 GetIssuingRules
1249
    $irule = $sth->fetchrow_hashref;
1250
    return $irule if defined($irule) ;
1251
1163
1252
    $sth->execute( "*", $itemtype, "*" );
1164
  my $irules = &GetIssuingRules($borrowertype,$itemtype,$branchcode)
1253
    $irule = $sth->fetchrow_hashref;
1165
1254
    return $irule if defined($irule) ;
1166
Get issuing all rule records for an itemtype, a borrower type and a branch
1167
in order of preference
1168
1169
Order of preference is $branchcode, $borrowertype, $itemtype
1170
1171
=cut
1172
1173
sub GetIssuingRules {
1174
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1255
1175
1256
    $sth->execute( "*", "*", "*" );
1176
    my (@where, @params);
1257
    $irule = $sth->fetchrow_hashref;
1258
    return $irule if defined($irule) ;
1259
1177
1260
    # if no rule matches,
1178
    if ( $borrowertype ) {
1261
    return undef;
1179
        push @where, "categorycode=? OR categorycode='*'";
1180
        push @params, $borrowertype;
1181
    } else {
1182
        push @where, "categorycode='*'";
1183
    }
1184
1185
    if ( $itemtype ) {
1186
        push @where, "itemtype=? OR itemtype='*'";
1187
        push @params, $itemtype;
1188
    } else {
1189
        push @where, "itemtype='*'";
1190
    }
1191
1192
    if ( $branchcode ) {
1193
        push @where, "branchcode=? OR branchcode='*'";
1194
        push @params, $branchcode;
1195
    } else {
1196
        push @where, "branchcode='*'";
1197
    }
1198
1199
    my $qry = "select * from issuingrules where "
1200
            .join( ' AND ', map "($_)", @where )
1201
            ." order by branchcode desc, categorycode desc, itemtype desc";
1202
1203
    my $dbh = C4::Context->dbh;
1204
    return  $dbh->selectall_arrayref($qry, { Slice => {} }, @params);
1262
}
1205
}
1263
1206
1264
=head2 GetBranchBorrowerCircRule
1207
=head2 GetBranchBorrowerCircRule
Lines 1758-1775 sub _FixFineDaysOnReturn { Link Here
1758
    }
1701
    }
1759
1702
1760
    my $branchcode = _GetCircControlBranch( $item, $borrower );
1703
    my $branchcode = _GetCircControlBranch( $item, $borrower );
1704
1705
    my $finedays = GetIssuingRuleValue( $borrower->{categorycode}, $item->{itype}, $branchcode, 'finedays' )
1706
      or return;
1707
    my $grace = GetIssuingRuleValue( $borrower->{categorycode}, $item->{itype}, $branchcode, 'firstremind' );
1708
1761
    my $calendar = C4::Calendar->new( branchcode => $branchcode );
1709
    my $calendar = C4::Calendar->new( branchcode => $branchcode );
1762
    my $today = C4::Dates->new();
1710
    my $today = C4::Dates->new();
1763
1711
    my $deltadays = $calendar->daysBetween( $datedue, $today );
1764
    my $deltadays = $calendar->daysBetween( $datedue, C4::Dates->new() );
1765
1712
1766
    my $circcontrol = C4::Context::preference('CircControl');
1713
    my $circcontrol = C4::Context::preference('CircControl');
1767
    my $issuingrule = GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
1768
    my $finedays    = $issuingrule->{finedays};
1769
1770
    # exit if no finedays defined
1771
    return unless $finedays;
1772
    my $grace = $issuingrule->{firstremind};
1773
1714
1774
    if ( $deltadays - $grace > 0 ) {
1715
    if ( $deltadays - $grace > 0 ) {
1775
        my @newdate = Add_Delta_Days( Today(), $deltadays * $finedays );
1716
        my @newdate = Add_Delta_Days( Today(), $deltadays * $finedays );
Lines 2200-2226 sub CanBookBeRenewed { Link Here
2200
    
2141
    
2201
    my $sthcount = $dbh->prepare("
2142
    my $sthcount = $dbh->prepare("
2202
                   SELECT 
2143
                   SELECT 
2203
                    borrowers.categorycode, biblioitems.itemtype, issues.renewals, renewalsallowed, $controlbranch
2144
                    borrowers.categorycode, biblioitems.itemtype, issues.renewals, $controlbranch
2204
                   FROM  issuingrules, 
2145
                   FROM issues 
2205
                   issues 
2206
                   LEFT JOIN items USING (itemnumber) 
2146
                   LEFT JOIN items USING (itemnumber) 
2207
                   LEFT JOIN borrowers USING (borrowernumber) 
2147
                   LEFT JOIN borrowers USING (borrowernumber) 
2208
                   LEFT JOIN biblioitems USING (biblioitemnumber)
2148
                   LEFT JOIN biblioitems USING (biblioitemnumber)
2209
                   
2149
                   
2210
                   WHERE
2150
                   WHERE
2211
                    (issuingrules.categorycode = borrowers.categorycode OR issuingrules.categorycode = '*')
2212
                   AND
2213
                    (issuingrules.itemtype = $itype OR issuingrules.itemtype = '*')
2214
                   AND
2215
                    (issuingrules.branchcode = $controlbranch OR issuingrules.branchcode = '*') 
2216
                   AND 
2217
                    borrowernumber = ? 
2151
                    borrowernumber = ? 
2218
                   AND
2152
                   AND
2219
                    itemnumber = ?
2153
                    itemnumber = ?
2220
                   ORDER BY
2221
                    issuingrules.categorycode desc,
2222
                    issuingrules.itemtype desc,
2223
                    issuingrules.branchcode desc
2224
                   LIMIT 1;
2154
                   LIMIT 1;
2225
                  ");
2155
                  ");
2226
2156
Lines 2239-2246 sub CanBookBeRenewed { Link Here
2239
            $renewokay = 0;
2169
            $renewokay = 0;
2240
			$error="on_reserve"
2170
			$error="on_reserve"
2241
        }
2171
        }
2172
        elsif ( $override_limit ) {
2173
            $renewokay = 1;
2174
        }
2175
        elsif ( my $renewalsallowed = GetIssuingRuleValue($data1->{categorycode}, $itype, $data1->{$controlbranch}, 'renewalsallowed') ) {
2176
            if ( $renewalsallowed > $data1->{renewals} || $override_limit ) {
2177
                $renewokay = 1;
2178
            }
2179
        }
2180
	    $error="too_many" unless $renewokay;
2181
	}
2242
2182
2243
    }
2244
    return ($renewokay,$error);
2183
    return ($renewokay,$error);
2245
}
2184
}
2246
2185
Lines 2347-2354 sub GetRenewCount { Link Here
2347
    my ( $bornum, $itemno ) = @_;
2286
    my ( $bornum, $itemno ) = @_;
2348
    my $dbh           = C4::Context->dbh;
2287
    my $dbh           = C4::Context->dbh;
2349
    my $renewcount    = 0;
2288
    my $renewcount    = 0;
2350
    my $renewsallowed = 0;
2351
    my $renewsleft    = 0;
2352
2289
2353
    my $borrower = C4::Members::GetMember( borrowernumber => $bornum);
2290
    my $borrower = C4::Members::GetMember( borrowernumber => $bornum);
2354
    my $item     = GetItem($itemno); 
2291
    my $item     = GetItem($itemno); 
Lines 2369-2378 sub GetRenewCount { Link Here
2369
    # $item and $borrower should be calculated
2306
    # $item and $borrower should be calculated
2370
    my $branchcode = _GetCircControlBranch($item, $borrower);
2307
    my $branchcode = _GetCircControlBranch($item, $borrower);
2371
    
2308
    
2372
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2309
    my $renewsallowed = GetIssuingRuleValue($borrower->{categorycode}, $item->{itype}, $branchcode, 'renewalsallowed') || 0;
2373
    
2310
    my $renewsleft    = $renewsallowed - $renewcount;
2374
    $renewsallowed = $issuingrule->{'renewalsallowed'};
2375
    $renewsleft    = $renewsallowed - $renewcount;
2376
    if($renewsleft < 0){ $renewsleft = 0; }
2311
    if($renewsleft < 0){ $renewsleft = 0; }
2377
    return ( $renewcount, $renewsallowed, $renewsleft );
2312
    return ( $renewcount, $renewsallowed, $renewsleft );
2378
}
2313
}
Lines 2417-2435 sub GetIssuingCharges { Link Here
2417
        $item_type = $item_data->{itemtype};
2352
        $item_type = $item_data->{itemtype};
2418
        $charge    = $item_data->{rentalcharge};
2353
        $charge    = $item_data->{rentalcharge};
2419
        my $branch = C4::Branch::mybranch();
2354
        my $branch = C4::Branch::mybranch();
2420
        my $discount_query = q|SELECT rentaldiscount,
2355
        my $borr_query = q|SELECT borrowers.categorycode
2421
            issuingrules.itemtype, issuingrules.branchcode
2422
            FROM borrowers
2356
            FROM borrowers
2423
            LEFT JOIN issuingrules ON borrowers.categorycode = issuingrules.categorycode
2357
            WHERE borrowers.borrowernumber = ?|;
2424
            WHERE borrowers.borrowernumber = ?
2358
        my $borr_cat = $dbh->selectrow_array($borr_query, undef, $borrowernumber);
2425
            AND (issuingrules.itemtype = ? OR issuingrules.itemtype = '*')
2359
        if ( my $discount = GetIssuingRuleValue($borr_cat, $item_type, $branch, 'rentaldiscount') ) {
2426
            AND (issuingrules.branchcode = ? OR issuingrules.branchcode = '*')|;
2427
        my $discount_sth = $dbh->prepare($discount_query);
2428
        $discount_sth->execute( $borrowernumber, $item_type, $branch );
2429
        my $discount_rules = $discount_sth->fetchall_arrayref({});
2430
        if (@{$discount_rules}) {
2431
            # We may have multiple rules so get the most specific
2432
            my $discount = _get_discount_from_rule($discount_rules, $branch, $item_type);
2433
            $charge = ( $charge * ( 100 - $discount ) ) / 100;
2360
            $charge = ( $charge * ( 100 - $discount ) ) / 100;
2434
        }
2361
        }
2435
    }
2362
    }
Lines 2438-2480 sub GetIssuingCharges { Link Here
2438
    return ( $charge, $item_type );
2365
    return ( $charge, $item_type );
2439
}
2366
}
2440
2367
2441
# Select most appropriate discount rule from those returned
2442
sub _get_discount_from_rule {
2443
    my ($rules_ref, $branch, $itemtype) = @_;
2444
    my $discount;
2445
2446
    if (@{$rules_ref} == 1) { # only 1 applicable rule use it
2447
        $discount = $rules_ref->[0]->{rentaldiscount};
2448
        return (defined $discount) ? $discount : 0;
2449
    }
2450
    # could have up to 4 does one match $branch and $itemtype
2451
    my @d = grep { $_->{branchcode} eq $branch && $_->{itemtype} eq $itemtype } @{$rules_ref};
2452
    if (@d) {
2453
        $discount = $d[0]->{rentaldiscount};
2454
        return (defined $discount) ? $discount : 0;
2455
    }
2456
    # do we have item type + all branches
2457
    @d = grep { $_->{branchcode} eq q{*} && $_->{itemtype} eq $itemtype } @{$rules_ref};
2458
    if (@d) {
2459
        $discount = $d[0]->{rentaldiscount};
2460
        return (defined $discount) ? $discount : 0;
2461
    }
2462
    # do we all item types + this branch
2463
    @d = grep { $_->{branchcode} eq $branch && $_->{itemtype} eq q{*} } @{$rules_ref};
2464
    if (@d) {
2465
        $discount = $d[0]->{rentaldiscount};
2466
        return (defined $discount) ? $discount : 0;
2467
    }
2468
    # so all and all (surely we wont get here)
2469
    @d = grep { $_->{branchcode} eq q{*} && $_->{itemtype} eq q{*} } @{$rules_ref};
2470
    if (@d) {
2471
        $discount = $d[0]->{rentaldiscount};
2472
        return (defined $discount) ? $discount : 0;
2473
    }
2474
    # none of the above
2475
    return 0;
2476
}
2477
2478
=head2 AddIssuingCharge
2368
=head2 AddIssuingCharge
2479
2369
2480
  &AddIssuingCharge( $itemno, $borrowernumber, $charge )
2370
  &AddIssuingCharge( $itemno, $borrowernumber, $charge )
(-)a/C4/Members.pm (-1 lines)
Lines 626-632 sub IsMemberBlocked { Link Here
626
    my $dbh            = C4::Context->dbh;
626
    my $dbh            = C4::Context->dbh;
627
627
628
    my $blockeddate = CheckBorrowerDebarred($borrowernumber);
628
    my $blockeddate = CheckBorrowerDebarred($borrowernumber);
629
630
    return ( 1, $blockeddate ) if $blockeddate;
629
    return ( 1, $blockeddate ) if $blockeddate;
631
630
632
    # if he have late issues
631
    # if he have late issues
(-)a/C4/Overdues.pm (-41 / +1 lines)
Lines 72-80 BEGIN { Link Here
72
	push @EXPORT, qw(
72
	push @EXPORT, qw(
73
        &GetIssuesIteminfo
73
        &GetIssuesIteminfo
74
	);
74
	);
75
    #
76
	# &GetIssuingRules - delete.
77
	# use C4::Circulation::GetIssuingRule instead.
78
	
75
	
79
	# subs to move to Members.pm
76
	# subs to move to Members.pm
80
	push @EXPORT, qw(
77
	push @EXPORT, qw(
Lines 272-280 sub CalcFine { Link Here
272
    my $dbh = C4::Context->dbh;
269
    my $dbh = C4::Context->dbh;
273
    my $amount = 0;
270
    my $amount = 0;
274
	my $daystocharge;
271
	my $daystocharge;
275
	# get issuingrules (fines part will be used)
276
    $debug and warn sprintf("CalcFine calling GetIssuingRule(%s, %s, %s)", $bortype, $item->{'itemtype'}, $branchcode);
277
    my $data = C4::Circulation::GetIssuingRule($bortype, $item->{'itemtype'}, $branchcode);
278
	if($difference) {
272
	if($difference) {
279
		# if $difference is supplied, the difference has already been calculated, but we still need to adjust for the calendar.
273
		# if $difference is supplied, the difference has already been calculated, but we still need to adjust for the calendar.
280
    	# use copy-pasted functions from calendar module.  (deprecated -- these functions will be removed from C4::Overdues ).
274
    	# use copy-pasted functions from calendar module.  (deprecated -- these functions will be removed from C4::Overdues ).
Lines 292-297 sub CalcFine { Link Here
292
		}
286
		}
293
	}
287
	}
294
	# correct for grace period.
288
	# correct for grace period.
289
    my $data = C4::Circulation::GetIssuingRuleRecord($bortype, $item->{'itemtype'}, $branchcode);
295
	my $days_minus_grace = $daystocharge - $data->{'firstremind'};
290
	my $days_minus_grace = $daystocharge - $data->{'firstremind'};
296
    if ($data->{'chargeperiod'} > 0 && $days_minus_grace > 0 ) { 
291
    if ($data->{'chargeperiod'} > 0 && $days_minus_grace > 0 ) { 
297
        $amount = int($daystocharge / $data->{'chargeperiod'}) * $data->{'fine'};
292
        $amount = int($daystocharge / $data->{'chargeperiod'}) * $data->{'fine'};
Lines 655-695 sub GetFine { Link Here
655
    return 0;
650
    return 0;
656
}
651
}
657
652
658
659
=head2 GetIssuingRules
660
661
FIXME - This sub should be deprecated and removed.
662
It ignores branch and defaults.
663
664
    $data = &GetIssuingRules($itemtype,$categorycode);
665
666
Looks up for all issuingrules an item info 
667
668
C<$itemnumber> is a reference-to-hash whose keys are all of the fields
669
from the borrowers and categories tables of the Koha database. Thus,
670
671
C<$categorycode> contains  information about borrowers category 
672
673
C<$data> contains all information about both the borrower and
674
category he or she belongs to.
675
=cut 
676
677
sub GetIssuingRules {
678
	warn "GetIssuingRules is deprecated: use GetIssuingRule from C4::Circulation instead.";
679
   my ($itemtype,$categorycode)=@_;
680
   my $dbh   = C4::Context->dbh();    
681
   my $query=qq|SELECT *
682
        FROM issuingrules
683
        WHERE issuingrules.itemtype=?
684
            AND issuingrules.categorycode=?
685
        |;
686
    my $sth = $dbh->prepare($query);
687
    #  print $query;
688
    $sth->execute($itemtype,$categorycode);
689
    return $sth->fetchrow_hashref;
690
}
691
692
693
sub ReplacementCost2 {
653
sub ReplacementCost2 {
694
    my ( $itemnum, $borrowernumber ) = @_;
654
    my ( $itemnum, $borrowernumber ) = @_;
695
    my $dbh   = C4::Context->dbh();
655
    my $dbh   = C4::Context->dbh();
(-)a/C4/Reserves.pm (-14 / +1 lines)
Lines 418-435 sub CanItemBeReserved{ Link Here
418
    my $item     = GetItem($itemnumber);
418
    my $item     = GetItem($itemnumber);
419
    my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber);     
419
    my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber);     
420
    
420
    
421
    # we retrieve user rights on this itemtype and branchcode
422
    my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed 
423
                             FROM issuingrules 
424
                             WHERE (categorycode in (?,'*') ) 
425
                             AND (itemtype IN (?,'*')) 
426
                             AND (branchcode IN (?,'*')) 
427
                             ORDER BY 
428
                               categorycode DESC, 
429
                               itemtype     DESC, 
430
                               branchcode   DESC;"
431
                           );
432
                           
433
    my $querycount ="SELECT 
421
    my $querycount ="SELECT 
434
                            count(*) as count
422
                            count(*) as count
435
                            FROM reserves
423
                            FROM reserves
Lines 454-461 sub CanItemBeReserved{ Link Here
454
    }
442
    }
455
    
443
    
456
    # we retrieve rights 
444
    # we retrieve rights 
457
    $sth->execute($categorycode, $itemtype, $branchcode);
445
    if(my $rights = C4::Circulation::GetIssuingRuleRecord($categorycode, $itemtype, $branchcode, 'reservesallowed')){
458
    if(my $rights = $sth->fetchrow_hashref()){
459
        $itemtype        = $rights->{itemtype};
446
        $itemtype        = $rights->{itemtype};
460
        $allowedreserves = $rights->{reservesallowed}; 
447
        $allowedreserves = $rights->{reservesallowed}; 
461
    }else{
448
    }else{
(-)a/t/db_dependent/lib/KohaTest/Circulation.pm (-1 / +3 lines)
Lines 20-26 sub methods : Test( 1 ) { Link Here
20
                      CanBookBeIssued 
20
                      CanBookBeIssued 
21
                      AddIssue 
21
                      AddIssue 
22
                      GetLoanLength 
22
                      GetLoanLength 
23
                      GetIssuingRule 
23
                      GetIssuingRules
24
                      GetIssuingRuleRecord
25
                      GetIssuingRuleValue
24
                      GetBranchBorrowerCircRule
26
                      GetBranchBorrowerCircRule
25
                      AddReturn 
27
                      AddReturn 
26
                      MarkIssueReturned 
28
                      MarkIssueReturned 
(-)a/t/db_dependent/lib/KohaTest/Overdues.pm (-2 lines)
Lines 23-29 sub methods : Test( 1 ) { Link Here
23
                       BorType 
23
                       BorType 
24
                       ReplacementCost 
24
                       ReplacementCost 
25
                       GetFine 
25
                       GetFine 
26
                       GetIssuingRules 
27
                       ReplacementCost2 
26
                       ReplacementCost2 
28
                       GetNextIdNotify 
27
                       GetNextIdNotify 
29
                       NumberNotifyId
28
                       NumberNotifyId
30
- 

Return to bug 4530