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

(-)a/C4/Circulation.pm (-214 / +104 lines)
Lines 74-80 BEGIN { Link Here
74
		&GetItemIssue
74
		&GetItemIssue
75
		&GetItemIssues
75
		&GetItemIssues
76
		&GetIssuingCharges
76
		&GetIssuingCharges
77
		&GetIssuingRule
78
        &GetBranchBorrowerCircRule
77
        &GetBranchBorrowerCircRule
79
        &GetBranchItemRule
78
        &GetBranchItemRule
80
		&GetBiblioIssues
79
		&GetBiblioIssues
Lines 356-367 sub TooMany { Link Here
356
 
355
 
357
    # given branch, patron category, and item type, determine
356
    # given branch, patron category, and item type, determine
358
    # applicable issuing rule
357
    # applicable issuing rule
359
    my $issuing_rule = GetIssuingRule($cat_borrower, $type, $branch);
358
    my $issuing_rule = GetIssuingRuleRecord($cat_borrower, $type, $branch, 'maxissueqty');
360
359
361
    # if a rule is found and has a loan limit set, count
360
    # if a rule is found and has a loan limit set, count
362
    # how many loans the patron already has that meet that
361
    # how many loans the patron already has that meet that
363
    # rule
362
    # rule
364
    if (defined($issuing_rule) and defined($issuing_rule->{'maxissueqty'})) {
363
    if ( $issuing_rule ) {
365
        my @bind_params;
364
        my @bind_params;
366
        my $count_query = "SELECT COUNT(*) FROM issues
365
        my $count_query = "SELECT COUNT(*) FROM issues
367
                           JOIN items USING (itemnumber) ";
366
                           JOIN items USING (itemnumber) ";
Lines 1087-1142 Get loan length for an itemtype, a borrower type and a branch Link Here
1087
1086
1088
sub GetLoanLength {
1087
sub GetLoanLength {
1089
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1088
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1090
    my $dbh = C4::Context->dbh;
1091
    my $sth =
1092
      $dbh->prepare(
1093
"select issuelength from issuingrules where categorycode=? and itemtype=? and branchcode=? and issuelength is not null"
1094
      );
1095
# warn "in get loan lenght $borrowertype $itemtype $branchcode ";
1096
# try to find issuelength & return the 1st available.
1097
# check with borrowertype, itemtype and branchcode, then without one of those parameters
1098
    $sth->execute( $borrowertype, $itemtype, $branchcode );
1099
    my $loanlength = $sth->fetchrow_hashref;
1100
    return $loanlength->{issuelength}
1101
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1102
1103
    $sth->execute( $borrowertype, "*", $branchcode );
1104
    $loanlength = $sth->fetchrow_hashref;
1105
    return $loanlength->{issuelength}
1106
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1107
1108
    $sth->execute( "*", $itemtype, $branchcode );
1109
    $loanlength = $sth->fetchrow_hashref;
1110
    return $loanlength->{issuelength}
1111
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1112
1113
    $sth->execute( "*", "*", $branchcode );
1114
    $loanlength = $sth->fetchrow_hashref;
1115
    return $loanlength->{issuelength}
1116
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1117
1118
    $sth->execute( $borrowertype, $itemtype, "*" );
1119
    $loanlength = $sth->fetchrow_hashref;
1120
    return $loanlength->{issuelength}
1121
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1122
1123
    $sth->execute( $borrowertype, "*", "*" );
1124
    $loanlength = $sth->fetchrow_hashref;
1125
    return $loanlength->{issuelength}
1126
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1127
1128
    $sth->execute( "*", $itemtype, "*" );
1129
    $loanlength = $sth->fetchrow_hashref;
1130
    return $loanlength->{issuelength}
1131
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1132
1133
    $sth->execute( "*", "*", "*" );
1134
    $loanlength = $sth->fetchrow_hashref;
1135
    return $loanlength->{issuelength}
1136
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1137
1138
    # if no rule is set => 21 days (hardcoded)
1089
    # if no rule is set => 21 days (hardcoded)
1139
    return 21;
1090
    return GetIssuingRuleValue( $borrowertype, $itemtype, $branchcode, 'issuelength' ) || 21;
1140
}
1091
}
1141
1092
1142
1093
Lines 1150-1257 Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a Link Here
1150
1101
1151
sub GetHardDueDate {
1102
sub GetHardDueDate {
1152
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1103
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1153
    my $dbh = C4::Context->dbh;
1104
    my $issuing_rule = GetIssuingRuleRecord($borrowertype, $itemtype, $branchcode, 'hardduedate')
1154
    my $sth =
1105
      or return;
1155
      $dbh->prepare(
1106
    return (C4::Dates->new($issuing_rule->{hardduedate}, 'iso'),$issuing_rule->{hardduedatecompare});
1156
"select hardduedate, hardduedatecompare from issuingrules where categorycode=? and itemtype=? and branchcode=?"
1157
      );
1158
    $sth->execute( $borrowertype, $itemtype, $branchcode );
1159
    my $results = $sth->fetchrow_hashref;
1160
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1161
      if defined($results) && $results->{hardduedate} ne 'NULL';
1162
1163
    $sth->execute( $borrowertype, "*", $branchcode );
1164
    $results = $sth->fetchrow_hashref;
1165
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1166
      if defined($results) && $results->{hardduedate} ne 'NULL';
1167
1168
    $sth->execute( "*", $itemtype, $branchcode );
1169
    $results = $sth->fetchrow_hashref;
1170
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1171
      if defined($results) && $results->{hardduedate} ne 'NULL';
1172
1173
    $sth->execute( "*", "*", $branchcode );
1174
    $results = $sth->fetchrow_hashref;
1175
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1176
      if defined($results) && $results->{hardduedate} ne 'NULL';
1177
1178
    $sth->execute( $borrowertype, $itemtype, "*" );
1179
    $results = $sth->fetchrow_hashref;
1180
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1181
      if defined($results) && $results->{hardduedate} ne 'NULL';
1182
1183
    $sth->execute( $borrowertype, "*", "*" );
1184
    $results = $sth->fetchrow_hashref;
1185
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1186
      if defined($results) && $results->{hardduedate} ne 'NULL';
1187
1188
    $sth->execute( "*", $itemtype, "*" );
1189
    $results = $sth->fetchrow_hashref;
1190
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1191
      if defined($results) && $results->{hardduedate} ne 'NULL';
1192
1193
    $sth->execute( "*", "*", "*" );
1194
    $results = $sth->fetchrow_hashref;
1195
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1196
      if defined($results) && $results->{hardduedate} ne 'NULL';
1197
1198
    # if no rule is set => return undefined
1199
    return (undef, undef);
1200
}
1107
}
1108
   
1109
1110
=head2 GetIssuingRuleValue
1111
1112
  my $irule = &GetIssuingRuleValue($borrowertype,$itemtype,$branchcode, $rule_name)
1113
1114
Get the most specific non-null value issuing rule for an itemtype, a borrower type and a branch
1201
1115
1202
=head2 GetIssuingRule
1116
=cut
1117
1118
sub GetIssuingRuleValue {
1119
    my ( $borrowertype, $itemtype, $branchcode, $rule ) = @_;
1120
    my $irule = GetIssuingRuleRecord( $borrowertype, $itemtype, $branchcode, $rule )
1121
      or return;
1122
    return $irule->{$rule};
1123
}
1203
1124
1204
  my $irule = &GetIssuingRule($borrowertype,$itemtype,branchcode)
1125
=head2 GetIssuingRuleRecord
1205
1126
1206
FIXME - This is a copy-paste of GetLoanLength
1127
  my $irule = &GetIssuingRuleRecord($borrowertype,$itemtype,$branchcode, $rule_name)
1207
as a stop-gap.  Do not wish to change API for GetLoanLength 
1208
this close to release, however, Overdues::GetIssuingRules is broken.
1209
1128
1210
Get the issuing rule for an itemtype, a borrower type and a branch
1129
Get the most specific non-null value issuing rule for an itemtype, a borrower type and a branch
1211
Returns a hashref from the issuingrules table.
1130
If $rule_name is specified, only records with $rule_name not null are taken in account
1131
1132
Order of preference is $branchcode, $borrowertype, $itemtype
1212
1133
1213
=cut
1134
=cut
1214
1135
1215
sub GetIssuingRule {
1136
sub GetIssuingRuleRecord {
1216
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1137
    my ( $borrowertype, $itemtype, $branchcode, $rule ) = @_;
1217
    my $dbh = C4::Context->dbh;
1218
    my $sth =  $dbh->prepare( "select * from issuingrules where categorycode=? and itemtype=? and branchcode=? and issuelength is not null"  );
1219
    my $irule;
1220
1138
1221
	$sth->execute( $borrowertype, $itemtype, $branchcode );
1139
    my $irules = GetIssuingRules($borrowertype,$itemtype,$branchcode)
1222
    $irule = $sth->fetchrow_hashref;
1140
      or return;
1223
    return $irule if defined($irule) ;
1224
1141
1225
    $sth->execute( $borrowertype, "*", $branchcode );
1142
    return unless @$irules;
1226
    $irule = $sth->fetchrow_hashref;
1227
    return $irule if defined($irule) ;
1228
1143
1229
    $sth->execute( "*", $itemtype, $branchcode );
1144
    return $irules->[0] unless $rule;
1230
    $irule = $sth->fetchrow_hashref;
1231
    return $irule if defined($irule) ;
1232
1145
1233
    $sth->execute( "*", "*", $branchcode );
1146
    die qq{Invalid rule (field) "$rule"} unless exists $irules->[0]->{$rule};
1234
    $irule = $sth->fetchrow_hashref;
1235
    return $irule if defined($irule) ;
1236
1147
1237
    $sth->execute( $borrowertype, $itemtype, "*" );
1148
    foreach (@$irules) {
1238
    $irule = $sth->fetchrow_hashref;
1149
        return $_ if $_->{$rule}; # XXX defined $_->{$rule}
1239
    return $irule if defined($irule) ;
1150
    }
1151
1152
    return;
1153
}
1240
1154
1241
    $sth->execute( $borrowertype, "*", "*" );
1155
=head2 GetIssuingRules
1242
    $irule = $sth->fetchrow_hashref;
1243
    return $irule if defined($irule) ;
1244
1156
1245
    $sth->execute( "*", $itemtype, "*" );
1157
  my $irules = &GetIssuingRules($borrowertype,$itemtype,$branchcode)
1246
    $irule = $sth->fetchrow_hashref;
1158
1247
    return $irule if defined($irule) ;
1159
Get issuing all rule records for an itemtype, a borrower type and a branch
1160
in order of preference
1161
1162
Order of preference is $branchcode, $borrowertype, $itemtype
1163
1164
=cut
1165
1166
sub GetIssuingRules {
1167
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1248
1168
1249
    $sth->execute( "*", "*", "*" );
1169
    my (@where, @params);
1250
    $irule = $sth->fetchrow_hashref;
1251
    return $irule if defined($irule) ;
1252
1170
1253
    # if no rule matches,
1171
    if ( $borrowertype ) {
1254
    return undef;
1172
        push @where, "categorycode=? OR categorycode='*'";
1173
        push @params, $borrowertype;
1174
    } else {
1175
        push @where, "categorycode='*'";
1176
    }
1177
1178
    if ( $itemtype ) {
1179
        push @where, "itemtype=? OR itemtype='*'";
1180
        push @params, $itemtype;
1181
    } else {
1182
        push @where, "itemtype='*'";
1183
    }
1184
1185
    if ( $branchcode ) {
1186
        push @where, "branchcode=? OR branchcode='*'";
1187
        push @params, $branchcode;
1188
    } else {
1189
        push @where, "branchcode='*'";
1190
    }
1191
1192
    my $qry = "select * from issuingrules where "
1193
            .join( ' AND ', map "($_)", @where )
1194
            ." order by branchcode desc, categorycode desc, itemtype desc";
1195
1196
    my $dbh = C4::Context->dbh;
1197
    return  $dbh->selectall_arrayref($qry, { Slice => {} }, @params);
1255
}
1198
}
1256
1199
1257
=head2 GetBranchBorrowerCircRule
1200
=head2 GetBranchBorrowerCircRule
Lines 1751-1768 sub _FixFineDaysOnReturn { Link Here
1751
    }
1694
    }
1752
1695
1753
    my $branchcode = _GetCircControlBranch( $item, $borrower );
1696
    my $branchcode = _GetCircControlBranch( $item, $borrower );
1697
1698
    my $finedays = GetIssuingRuleValue( $borrower->{categorycode}, $item->{itype}, $branchcode, 'finedays' )
1699
      or return;
1700
    my $grace = GetIssuingRuleValue( $borrower->{categorycode}, $item->{itype}, $branchcode, 'firstremind' );
1701
1754
    my $calendar = C4::Calendar->new( branchcode => $branchcode );
1702
    my $calendar = C4::Calendar->new( branchcode => $branchcode );
1755
    my $today = C4::Dates->new();
1703
    my $today = C4::Dates->new();
1756
1704
    my $deltadays = $calendar->daysBetween( $datedue, $today );
1757
    my $deltadays = $calendar->daysBetween( $datedue, C4::Dates->new() );
1758
1705
1759
    my $circcontrol = C4::Context::preference('CircControl');
1706
    my $circcontrol = C4::Context::preference('CircControl');
1760
    my $issuingrule = GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode );
1761
    my $finedays    = $issuingrule->{finedays};
1762
1763
    # exit if no finedays defined
1764
    return unless $finedays;
1765
    my $grace = $issuingrule->{firstremind};
1766
1707
1767
    if ( $deltadays - $grace > 0 ) {
1708
    if ( $deltadays - $grace > 0 ) {
1768
        my @newdate = Add_Delta_Days( Today(), $deltadays * $finedays );
1709
        my @newdate = Add_Delta_Days( Today(), $deltadays * $finedays );
Lines 2192-2218 sub CanBookBeRenewed { Link Here
2192
    
2133
    
2193
    my $sthcount = $dbh->prepare("
2134
    my $sthcount = $dbh->prepare("
2194
                   SELECT 
2135
                   SELECT 
2195
                    borrowers.categorycode, biblioitems.itemtype, issues.renewals, renewalsallowed, $controlbranch
2136
                    borrowers.categorycode, biblioitems.itemtype, issues.renewals, $controlbranch
2196
                   FROM  issuingrules, 
2137
                   FROM issues 
2197
                   issues 
2198
                   LEFT JOIN items USING (itemnumber) 
2138
                   LEFT JOIN items USING (itemnumber) 
2199
                   LEFT JOIN borrowers USING (borrowernumber) 
2139
                   LEFT JOIN borrowers USING (borrowernumber) 
2200
                   LEFT JOIN biblioitems USING (biblioitemnumber)
2140
                   LEFT JOIN biblioitems USING (biblioitemnumber)
2201
                   
2141
                   
2202
                   WHERE
2142
                   WHERE
2203
                    (issuingrules.categorycode = borrowers.categorycode OR issuingrules.categorycode = '*')
2204
                   AND
2205
                    (issuingrules.itemtype = $itype OR issuingrules.itemtype = '*')
2206
                   AND
2207
                    (issuingrules.branchcode = $controlbranch OR issuingrules.branchcode = '*') 
2208
                   AND 
2209
                    borrowernumber = ? 
2143
                    borrowernumber = ? 
2210
                   AND
2144
                   AND
2211
                    itemnumber = ?
2145
                    itemnumber = ?
2212
                   ORDER BY
2213
                    issuingrules.categorycode desc,
2214
                    issuingrules.itemtype desc,
2215
                    issuingrules.branchcode desc
2216
                   LIMIT 1;
2146
                   LIMIT 1;
2217
                  ");
2147
                  ");
2218
2148
Lines 2231-2238 sub CanBookBeRenewed { Link Here
2231
            $renewokay = 0;
2161
            $renewokay = 0;
2232
			$error="on_reserve"
2162
			$error="on_reserve"
2233
        }
2163
        }
2164
        elsif ( $override_limit ) {
2165
            $renewokay = 1;
2166
        }
2167
        elsif ( my $renewalsallowed = GetIssuingRuleValue($data1->{categorycode}, $itype, $data1->{$controlbranch}, 'renewalsallowed') ) {
2168
            if ( $renewalsallowed > $data1->{renewals} || $override_limit ) {
2169
                $renewokay = 1;
2170
            }
2171
        }
2172
	    $error="too_many" unless $renewokay;
2173
	}
2234
2174
2235
    }
2236
    return ($renewokay,$error);
2175
    return ($renewokay,$error);
2237
}
2176
}
2238
2177
Lines 2339-2346 sub GetRenewCount { Link Here
2339
    my ( $bornum, $itemno ) = @_;
2278
    my ( $bornum, $itemno ) = @_;
2340
    my $dbh           = C4::Context->dbh;
2279
    my $dbh           = C4::Context->dbh;
2341
    my $renewcount    = 0;
2280
    my $renewcount    = 0;
2342
    my $renewsallowed = 0;
2343
    my $renewsleft    = 0;
2344
2281
2345
    my $borrower = C4::Members::GetMember( borrowernumber => $bornum);
2282
    my $borrower = C4::Members::GetMember( borrowernumber => $bornum);
2346
    my $item     = GetItem($itemno); 
2283
    my $item     = GetItem($itemno); 
Lines 2361-2370 sub GetRenewCount { Link Here
2361
    # $item and $borrower should be calculated
2298
    # $item and $borrower should be calculated
2362
    my $branchcode = _GetCircControlBranch($item, $borrower);
2299
    my $branchcode = _GetCircControlBranch($item, $borrower);
2363
    
2300
    
2364
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2301
    my $renewsallowed = GetIssuingRuleValue($borrower->{categorycode}, $item->{itype}, $branchcode, 'renewalsallowed') || 0;
2365
    
2302
    my $renewsleft    = $renewsallowed - $renewcount;
2366
    $renewsallowed = $issuingrule->{'renewalsallowed'};
2367
    $renewsleft    = $renewsallowed - $renewcount;
2368
    if($renewsleft < 0){ $renewsleft = 0; }
2303
    if($renewsleft < 0){ $renewsleft = 0; }
2369
    return ( $renewcount, $renewsallowed, $renewsleft );
2304
    return ( $renewcount, $renewsallowed, $renewsleft );
2370
}
2305
}
Lines 2409-2427 sub GetIssuingCharges { Link Here
2409
        $item_type = $item_data->{itemtype};
2344
        $item_type = $item_data->{itemtype};
2410
        $charge    = $item_data->{rentalcharge};
2345
        $charge    = $item_data->{rentalcharge};
2411
        my $branch = C4::Branch::mybranch();
2346
        my $branch = C4::Branch::mybranch();
2412
        my $discount_query = q|SELECT rentaldiscount,
2347
        my $borr_query = q|SELECT borrowers.categorycode
2413
            issuingrules.itemtype, issuingrules.branchcode
2414
            FROM borrowers
2348
            FROM borrowers
2415
            LEFT JOIN issuingrules ON borrowers.categorycode = issuingrules.categorycode
2349
            WHERE borrowers.borrowernumber = ?|;
2416
            WHERE borrowers.borrowernumber = ?
2350
        my $borr_cat = $dbh->selectrow_array($borr_query, undef, $borrowernumber);
2417
            AND (issuingrules.itemtype = ? OR issuingrules.itemtype = '*')
2351
        if ( my $discount = GetIssuingRuleValue($borr_cat, $item_type, $branch, 'rentaldiscount') ) {
2418
            AND (issuingrules.branchcode = ? OR issuingrules.branchcode = '*')|;
2419
        my $discount_sth = $dbh->prepare($discount_query);
2420
        $discount_sth->execute( $borrowernumber, $item_type, $branch );
2421
        my $discount_rules = $discount_sth->fetchall_arrayref({});
2422
        if (@{$discount_rules}) {
2423
            # We may have multiple rules so get the most specific
2424
            my $discount = _get_discount_from_rule($discount_rules, $branch, $item_type);
2425
            $charge = ( $charge * ( 100 - $discount ) ) / 100;
2352
            $charge = ( $charge * ( 100 - $discount ) ) / 100;
2426
        }
2353
        }
2427
    }
2354
    }
Lines 2430-2472 sub GetIssuingCharges { Link Here
2430
    return ( $charge, $item_type );
2357
    return ( $charge, $item_type );
2431
}
2358
}
2432
2359
2433
# Select most appropriate discount rule from those returned
2434
sub _get_discount_from_rule {
2435
    my ($rules_ref, $branch, $itemtype) = @_;
2436
    my $discount;
2437
2438
    if (@{$rules_ref} == 1) { # only 1 applicable rule use it
2439
        $discount = $rules_ref->[0]->{rentaldiscount};
2440
        return (defined $discount) ? $discount : 0;
2441
    }
2442
    # could have up to 4 does one match $branch and $itemtype
2443
    my @d = grep { $_->{branchcode} eq $branch && $_->{itemtype} eq $itemtype } @{$rules_ref};
2444
    if (@d) {
2445
        $discount = $d[0]->{rentaldiscount};
2446
        return (defined $discount) ? $discount : 0;
2447
    }
2448
    # do we have item type + all branches
2449
    @d = grep { $_->{branchcode} eq q{*} && $_->{itemtype} eq $itemtype } @{$rules_ref};
2450
    if (@d) {
2451
        $discount = $d[0]->{rentaldiscount};
2452
        return (defined $discount) ? $discount : 0;
2453
    }
2454
    # do we all item types + this branch
2455
    @d = grep { $_->{branchcode} eq $branch && $_->{itemtype} eq q{*} } @{$rules_ref};
2456
    if (@d) {
2457
        $discount = $d[0]->{rentaldiscount};
2458
        return (defined $discount) ? $discount : 0;
2459
    }
2460
    # so all and all (surely we wont get here)
2461
    @d = grep { $_->{branchcode} eq q{*} && $_->{itemtype} eq q{*} } @{$rules_ref};
2462
    if (@d) {
2463
        $discount = $d[0]->{rentaldiscount};
2464
        return (defined $discount) ? $discount : 0;
2465
    }
2466
    # none of the above
2467
    return 0;
2468
}
2469
2470
=head2 AddIssuingCharge
2360
=head2 AddIssuingCharge
2471
2361
2472
  &AddIssuingCharge( $itemno, $borrowernumber, $charge )
2362
  &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