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

(-)a/C4/Circulation.pm (-214 / +98 lines)
Lines 74-80 BEGIN { Link Here
74
		&GetItemIssues
74
		&GetItemIssues
75
		&GetBorrowerIssues
75
		&GetBorrowerIssues
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 1119-1174 Get loan length for an itemtype, a borrower type and a branch Link Here
1119
1118
1120
sub GetLoanLength {
1119
sub GetLoanLength {
1121
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1120
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1122
    my $dbh = C4::Context->dbh;
1123
    my $sth =
1124
      $dbh->prepare(
1125
"select issuelength from issuingrules where categorycode=? and itemtype=? and branchcode=? and issuelength is not null"
1126
      );
1127
# warn "in get loan lenght $borrowertype $itemtype $branchcode ";
1128
# try to find issuelength & return the 1st available.
1129
# check with borrowertype, itemtype and branchcode, then without one of those parameters
1130
    $sth->execute( $borrowertype, $itemtype, $branchcode );
1131
    my $loanlength = $sth->fetchrow_hashref;
1132
    return $loanlength->{issuelength}
1133
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1134
1135
    $sth->execute( $borrowertype, "*", $branchcode );
1136
    $loanlength = $sth->fetchrow_hashref;
1137
    return $loanlength->{issuelength}
1138
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1139
1140
    $sth->execute( "*", $itemtype, $branchcode );
1141
    $loanlength = $sth->fetchrow_hashref;
1142
    return $loanlength->{issuelength}
1143
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1144
1145
    $sth->execute( "*", "*", $branchcode );
1146
    $loanlength = $sth->fetchrow_hashref;
1147
    return $loanlength->{issuelength}
1148
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1149
1150
    $sth->execute( $borrowertype, $itemtype, "*" );
1151
    $loanlength = $sth->fetchrow_hashref;
1152
    return $loanlength->{issuelength}
1153
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1154
1155
    $sth->execute( $borrowertype, "*", "*" );
1156
    $loanlength = $sth->fetchrow_hashref;
1157
    return $loanlength->{issuelength}
1158
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1159
1160
    $sth->execute( "*", $itemtype, "*" );
1161
    $loanlength = $sth->fetchrow_hashref;
1162
    return $loanlength->{issuelength}
1163
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1164
1165
    $sth->execute( "*", "*", "*" );
1166
    $loanlength = $sth->fetchrow_hashref;
1167
    return $loanlength->{issuelength}
1168
      if defined($loanlength) && $loanlength->{issuelength} ne 'NULL';
1169
1170
    # if no rule is set => 21 days (hardcoded)
1121
    # if no rule is set => 21 days (hardcoded)
1171
    return 21;
1122
    return GetIssuingRuleValue( $borrowertype, $itemtype, $branchcode, 'issuelength' ) || 21;
1172
}
1123
}
1173
1124
1174
1125
Lines 1182-1289 Get the Hard Due Date and it's comparison for an itemtype, a borrower type and a Link Here
1182
1133
1183
sub GetHardDueDate {
1134
sub GetHardDueDate {
1184
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1135
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1185
    my $dbh = C4::Context->dbh;
1136
    my $issuing_rule = GetIssuingRuleRecord($borrowertype, $itemtype, $branchcode, 'hardduedate')
1186
    my $sth =
1137
      or return;
1187
      $dbh->prepare(
1138
    return (C4::Dates->new($issuing_rule->{hardduedate}, 'iso'),$issuing_rule->{hardduedatecompare});
1188
"select hardduedate, hardduedatecompare from issuingrules where categorycode=? and itemtype=? and branchcode=?"
1139
}
1189
      );
1140
   
1190
    $sth->execute( $borrowertype, $itemtype, $branchcode );
1141
1191
    my $results = $sth->fetchrow_hashref;
1142
=head2 GetIssuingRuleValue
1192
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1143
1193
      if defined($results) && $results->{hardduedate} ne 'NULL';
1144
  my $irule = &GetIssuingRuleValue($borrowertype,$itemtype,$branchcode, $rule_name)
1194
1145
1195
    $sth->execute( $borrowertype, "*", $branchcode );
1146
Get the most specific non-null value issuing rule for an itemtype, a borrower type and a branch
1196
    $results = $sth->fetchrow_hashref;
1147
1197
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1148
=cut
1198
      if defined($results) && $results->{hardduedate} ne 'NULL';
1149
1199
1150
sub GetIssuingRuleValue {
1200
    $sth->execute( "*", $itemtype, $branchcode );
1151
    my ( $borrowertype, $itemtype, $branchcode, $rule ) = @_;
1201
    $results = $sth->fetchrow_hashref;
1152
    my $irule = GetIssuingRuleRecord( $borrowertype, $itemtype, $branchcode, $rule )
1202
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1153
      or return;
1203
      if defined($results) && $results->{hardduedate} ne 'NULL';
1154
    return $irule->{$rule};
1204
1205
    $sth->execute( "*", "*", $branchcode );
1206
    $results = $sth->fetchrow_hashref;
1207
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1208
      if defined($results) && $results->{hardduedate} ne 'NULL';
1209
1210
    $sth->execute( $borrowertype, $itemtype, "*" );
1211
    $results = $sth->fetchrow_hashref;
1212
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1213
      if defined($results) && $results->{hardduedate} ne 'NULL';
1214
1215
    $sth->execute( $borrowertype, "*", "*" );
1216
    $results = $sth->fetchrow_hashref;
1217
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1218
      if defined($results) && $results->{hardduedate} ne 'NULL';
1219
1220
    $sth->execute( "*", $itemtype, "*" );
1221
    $results = $sth->fetchrow_hashref;
1222
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1223
      if defined($results) && $results->{hardduedate} ne 'NULL';
1224
1225
    $sth->execute( "*", "*", "*" );
1226
    $results = $sth->fetchrow_hashref;
1227
    return (C4::Dates->new($results->{hardduedate}, 'iso'),$results->{hardduedatecompare})
1228
      if defined($results) && $results->{hardduedate} ne 'NULL';
1229
1230
    # if no rule is set => return undefined
1231
    return (undef, undef);
1232
}
1155
}
1233
1156
1234
=head2 GetIssuingRule
1157
=head2 GetIssuingRuleRecord
1235
1158
1236
  my $irule = &GetIssuingRule($borrowertype,$itemtype,branchcode)
1159
  my $irule = &GetIssuingRuleRecord($borrowertype,$itemtype,$branchcode, $rule_name)
1237
1160
1238
FIXME - This is a copy-paste of GetLoanLength
1161
Get the most specific non-null value issuing rule for an itemtype, a borrower type and a branch
1239
as a stop-gap.  Do not wish to change API for GetLoanLength 
1162
If $rule_name is specified, only records with $rule_name not null are taken in account
1240
this close to release, however, Overdues::GetIssuingRules is broken.
1241
1163
1242
Get the issuing rule for an itemtype, a borrower type and a branch
1164
Order of preference is $branchcode, $borrowertype, $itemtype
1243
Returns a hashref from the issuingrules table.
1244
1165
1245
=cut
1166
=cut
1246
1167
1247
sub GetIssuingRule {
1168
sub GetIssuingRuleRecord {
1248
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1169
    my ( $borrowertype, $itemtype, $branchcode, $rule ) = @_;
1249
    my $dbh = C4::Context->dbh;
1170
1250
    my $sth =  $dbh->prepare( "select * from issuingrules where categorycode=? and itemtype=? and branchcode=? and issuelength is not null"  );
1171
    my $irules = GetIssuingRules($borrowertype,$itemtype,$branchcode)
1251
    my $irule;
1172
      or return;
1173
1174
    return unless @$irules;
1175
1176
    return $irules->[0] unless $rule;
1177
1178
    die qq{Invalid rule (field) "$rule"} unless exists $irules->[0]->{$rule};
1252
1179
1253
	$sth->execute( $borrowertype, $itemtype, $branchcode );
1180
    foreach (@$irules) {
1254
    $irule = $sth->fetchrow_hashref;
1181
        return $_ if $_->{$rule}; # XXX defined $_->{$rule}
1255
    return $irule if defined($irule) ;
1182
    }
1256
1183
1257
    $sth->execute( $borrowertype, "*", $branchcode );
1184
    return;
1258
    $irule = $sth->fetchrow_hashref;
1185
}
1259
    return $irule if defined($irule) ;
1260
1186
1261
    $sth->execute( "*", $itemtype, $branchcode );
1187
=head2 GetIssuingRules
1262
    $irule = $sth->fetchrow_hashref;
1263
    return $irule if defined($irule) ;
1264
1188
1265
    $sth->execute( "*", "*", $branchcode );
1189
  my $irules = &GetIssuingRules($borrowertype,$itemtype,$branchcode)
1266
    $irule = $sth->fetchrow_hashref;
1267
    return $irule if defined($irule) ;
1268
1190
1269
    $sth->execute( $borrowertype, $itemtype, "*" );
1191
Get issuing all rule records for an itemtype, a borrower type and a branch
1270
    $irule = $sth->fetchrow_hashref;
1192
in order of preference
1271
    return $irule if defined($irule) ;
1272
1193
1273
    $sth->execute( $borrowertype, "*", "*" );
1194
Order of preference is $branchcode, $borrowertype, $itemtype
1274
    $irule = $sth->fetchrow_hashref;
1275
    return $irule if defined($irule) ;
1276
1195
1277
    $sth->execute( "*", $itemtype, "*" );
1196
=cut
1278
    $irule = $sth->fetchrow_hashref;
1279
    return $irule if defined($irule) ;
1280
1197
1281
    $sth->execute( "*", "*", "*" );
1198
sub GetIssuingRules {
1282
    $irule = $sth->fetchrow_hashref;
1199
    my ( $borrowertype, $itemtype, $branchcode ) = @_;
1283
    return $irule if defined($irule) ;
1200
1201
    my (@where, @params);
1284
1202
1285
    # if no rule matches,
1203
    if ( $borrowertype ) {
1286
    return undef;
1204
        push @where, "categorycode=? OR categorycode='*'";
1205
        push @params, $borrowertype;
1206
    } else {
1207
        push @where, "categorycode='*'";
1208
    }
1209
1210
    if ( $itemtype ) {
1211
        push @where, "itemtype=? OR itemtype='*'";
1212
        push @params, $itemtype;
1213
    } else {
1214
        push @where, "itemtype='*'";
1215
    }
1216
1217
    if ( $branchcode ) {
1218
        push @where, "branchcode=? OR branchcode='*'";
1219
        push @params, $branchcode;
1220
    } else {
1221
        push @where, "branchcode='*'";
1222
    }
1223
1224
    my $qry = "select * from issuingrules where "
1225
            .join( ' AND ', map "($_)", @where )
1226
            ." order by branchcode desc, categorycode desc, itemtype desc";
1227
1228
    my $dbh = C4::Context->dbh;
1229
    return  $dbh->selectall_arrayref($qry, { Slice => {} }, @params);
1287
}
1230
}
1288
1231
1289
=head2 GetBranchBorrowerCircRule
1232
=head2 GetBranchBorrowerCircRule
Lines 2159-2205 sub CanBookBeRenewed { Link Here
2159
    
2102
    
2160
    my $sthcount = $dbh->prepare("
2103
    my $sthcount = $dbh->prepare("
2161
                   SELECT 
2104
                   SELECT 
2162
                    borrowers.categorycode, biblioitems.itemtype, issues.renewals, renewalsallowed, $controlbranch
2105
                    borrowers.categorycode, biblioitems.itemtype, issues.renewals, $controlbranch
2163
                   FROM  issuingrules, 
2106
                   FROM issues 
2164
                   issues 
2165
                   LEFT JOIN items USING (itemnumber) 
2107
                   LEFT JOIN items USING (itemnumber) 
2166
                   LEFT JOIN borrowers USING (borrowernumber) 
2108
                   LEFT JOIN borrowers USING (borrowernumber) 
2167
                   LEFT JOIN biblioitems USING (biblioitemnumber)
2109
                   LEFT JOIN biblioitems USING (biblioitemnumber)
2168
                   
2110
                   
2169
                   WHERE
2111
                   WHERE
2170
                    (issuingrules.categorycode = borrowers.categorycode OR issuingrules.categorycode = '*')
2171
                   AND
2172
                    (issuingrules.itemtype = $itype OR issuingrules.itemtype = '*')
2173
                   AND
2174
                    (issuingrules.branchcode = $controlbranch OR issuingrules.branchcode = '*') 
2175
                   AND 
2176
                    borrowernumber = ? 
2112
                    borrowernumber = ? 
2177
                   AND
2113
                   AND
2178
                    itemnumber = ?
2114
                    itemnumber = ?
2179
                   ORDER BY
2180
                    issuingrules.categorycode desc,
2181
                    issuingrules.itemtype desc,
2182
                    issuingrules.branchcode desc
2183
                   LIMIT 1;
2115
                   LIMIT 1;
2184
                  ");
2116
                  ");
2185
2117
2186
    $sthcount->execute( $borrowernumber, $itemnumber );
2118
    $sthcount->execute( $borrowernumber, $itemnumber );
2187
    if ( my $data1 = $sthcount->fetchrow_hashref ) {
2119
    if ( my $data1 = $sthcount->fetchrow_hashref ) {
2188
        
2189
        if ( ( $data1->{renewalsallowed} && $data1->{renewalsallowed} > $data1->{renewals} ) || $override_limit ) {
2190
            $renewokay = 1;
2191
        }
2192
        else {
2193
			$error="too_many";
2194
		}
2195
		
2196
        my ( $resfound, $resrec ) = C4::Reserves::CheckReserves($itemnumber);
2120
        my ( $resfound, $resrec ) = C4::Reserves::CheckReserves($itemnumber);
2197
        if ($resfound) {
2121
        if ($resfound) {
2198
            $renewokay = 0;
2122
            $renewokay = 0;
2199
			$error="on_reserve"
2123
			$error="on_reserve"
2200
        }
2124
        }
2125
        elsif ( $override_limit ) {
2126
            $renewokay = 1;
2127
        }
2128
        elsif ( my $renewalsallowed = GetIssuingRuleValue($data1->{categorycode}, $itype, $data1->{$controlbranch}, 'renewalsallowed') ) {
2129
            if ( $renewalsallowed > $data1->{renewals} || $override_limit ) {
2130
                $renewokay = 1;
2131
            }
2132
        }
2133
	    $error="too_many" unless $renewokay;
2134
	}
2201
2135
2202
    }
2203
    return ($renewokay,$error);
2136
    return ($renewokay,$error);
2204
}
2137
}
2205
2138
Lines 2306-2313 sub GetRenewCount { Link Here
2306
    my ( $bornum, $itemno ) = @_;
2239
    my ( $bornum, $itemno ) = @_;
2307
    my $dbh           = C4::Context->dbh;
2240
    my $dbh           = C4::Context->dbh;
2308
    my $renewcount    = 0;
2241
    my $renewcount    = 0;
2309
    my $renewsallowed = 0;
2310
    my $renewsleft    = 0;
2311
2242
2312
    my $borrower = C4::Members::GetMemberDetails($bornum);
2243
    my $borrower = C4::Members::GetMemberDetails($bornum);
2313
    my $item     = GetItem($itemno); 
2244
    my $item     = GetItem($itemno); 
Lines 2328-2337 sub GetRenewCount { Link Here
2328
    # $item and $borrower should be calculated
2259
    # $item and $borrower should be calculated
2329
    my $branchcode = _GetCircControlBranch($item, $borrower);
2260
    my $branchcode = _GetCircControlBranch($item, $borrower);
2330
    
2261
    
2331
    my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode);
2262
    my $renewsallowed = GetIssuingRuleValue($borrower->{categorycode}, $item->{itype}, $branchcode, 'renewalsallowed') || 0;
2332
    
2263
    my $renewsleft    = $renewsallowed - $renewcount;
2333
    $renewsallowed = $issuingrule->{'renewalsallowed'};
2334
    $renewsleft    = $renewsallowed - $renewcount;
2335
    if($renewsleft < 0){ $renewsleft = 0; }
2264
    if($renewsleft < 0){ $renewsleft = 0; }
2336
    return ( $renewcount, $renewsallowed, $renewsleft );
2265
    return ( $renewcount, $renewsallowed, $renewsleft );
2337
}
2266
}
Lines 2376-2394 sub GetIssuingCharges { Link Here
2376
        $item_type = $item_data->{itemtype};
2305
        $item_type = $item_data->{itemtype};
2377
        $charge    = $item_data->{rentalcharge};
2306
        $charge    = $item_data->{rentalcharge};
2378
        my $branch = C4::Branch::mybranch();
2307
        my $branch = C4::Branch::mybranch();
2379
        my $discount_query = q|SELECT rentaldiscount,
2308
        my $borr_query = q|SELECT borrowers.categorycode
2380
            issuingrules.itemtype, issuingrules.branchcode
2381
            FROM borrowers
2309
            FROM borrowers
2382
            LEFT JOIN issuingrules ON borrowers.categorycode = issuingrules.categorycode
2310
            WHERE borrowers.borrowernumber = ?|;
2383
            WHERE borrowers.borrowernumber = ?
2311
        my $borr_cat = $dbh->selectrow_array($borr_query, undef, $borrowernumber);
2384
            AND (issuingrules.itemtype = ? OR issuingrules.itemtype = '*')
2312
        if ( my $discount = GetIssuingRuleValue($borr_cat, $item_type, $branch, 'rentaldiscount') ) {
2385
            AND (issuingrules.branchcode = ? OR issuingrules.branchcode = '*')|;
2386
        my $discount_sth = $dbh->prepare($discount_query);
2387
        $discount_sth->execute( $borrowernumber, $item_type, $branch );
2388
        my $discount_rules = $discount_sth->fetchall_arrayref({});
2389
        if (@{$discount_rules}) {
2390
            # We may have multiple rules so get the most specific
2391
            my $discount = _get_discount_from_rule($discount_rules, $branch, $item_type);
2392
            $charge = ( $charge * ( 100 - $discount ) ) / 100;
2313
            $charge = ( $charge * ( 100 - $discount ) ) / 100;
2393
        }
2314
        }
2394
    }
2315
    }
Lines 2397-2439 sub GetIssuingCharges { Link Here
2397
    return ( $charge, $item_type );
2318
    return ( $charge, $item_type );
2398
}
2319
}
2399
2320
2400
# Select most appropriate discount rule from those returned
2401
sub _get_discount_from_rule {
2402
    my ($rules_ref, $branch, $itemtype) = @_;
2403
    my $discount;
2404
2405
    if (@{$rules_ref} == 1) { # only 1 applicable rule use it
2406
        $discount = $rules_ref->[0]->{rentaldiscount};
2407
        return (defined $discount) ? $discount : 0;
2408
    }
2409
    # could have up to 4 does one match $branch and $itemtype
2410
    my @d = grep { $_->{branchcode} eq $branch && $_->{itemtype} eq $itemtype } @{$rules_ref};
2411
    if (@d) {
2412
        $discount = $d[0]->{rentaldiscount};
2413
        return (defined $discount) ? $discount : 0;
2414
    }
2415
    # do we have item type + all branches
2416
    @d = grep { $_->{branchcode} eq q{*} && $_->{itemtype} eq $itemtype } @{$rules_ref};
2417
    if (@d) {
2418
        $discount = $d[0]->{rentaldiscount};
2419
        return (defined $discount) ? $discount : 0;
2420
    }
2421
    # do we all item types + this branch
2422
    @d = grep { $_->{branchcode} eq $branch && $_->{itemtype} eq q{*} } @{$rules_ref};
2423
    if (@d) {
2424
        $discount = $d[0]->{rentaldiscount};
2425
        return (defined $discount) ? $discount : 0;
2426
    }
2427
    # so all and all (surely we wont get here)
2428
    @d = grep { $_->{branchcode} eq q{*} && $_->{itemtype} eq q{*} } @{$rules_ref};
2429
    if (@d) {
2430
        $discount = $d[0]->{rentaldiscount};
2431
        return (defined $discount) ? $discount : 0;
2432
    }
2433
    # none of the above
2434
    return 0;
2435
}
2436
2437
=head2 AddIssuingCharge
2321
=head2 AddIssuingCharge
2438
2322
2439
  &AddIssuingCharge( $itemno, $borrowernumber, $charge )
2323
  &AddIssuingCharge( $itemno, $borrowernumber, $charge )
(-)a/C4/Members.pm (-20 / +23 lines)
Lines 660-687 sub IsMemberBlocked { Link Here
660
    my $dbh            = C4::Context->dbh;
660
    my $dbh            = C4::Context->dbh;
661
661
662
    # does patron have current fine days?
662
    # does patron have current fine days?
663
	my $strsth=qq{
663
	my $strsth=<<EOQ;
664
            SELECT
664
SELECT
665
            ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due) ) AS blockingdate,
665
issuingrules.itemtype,
666
            DATEDIFF(ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due)),NOW()) AS blockedcount
666
ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due) ) AS blockingdate,
667
            FROM old_issues
667
DATEDIFF(ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due)),NOW()) AS blockedcount
668
	};
668
FROM old_issues
669
LEFT JOIN items ON (items.itemnumber=old_issues.itemnumber)
670
EOQ
669
    if(C4::Context->preference("item-level_itypes")){
671
    if(C4::Context->preference("item-level_itypes")){
670
        $strsth.=
672
        $strsth.=<<EOQ;
671
		qq{ LEFT JOIN items ON (items.itemnumber=old_issues.itemnumber)
673
LEFT JOIN issuingrules ON (issuingrules.itemtype=items.itype OR issuingrules.itemtype='*')
672
            LEFT JOIN issuingrules ON (issuingrules.itemtype=items.itype)}
674
EOQ
673
    }else{
675
    }else{
674
        $strsth .= 
676
        $strsth.=<<EOQ;
675
		qq{ LEFT JOIN items ON (items.itemnumber=old_issues.itemnumber)
677
LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
676
            LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
678
LEFT JOIN issuingrules ON (issuingrules.itemtype=biblioitems.itemtype OR issuingrules.itemtype='*')
677
            LEFT JOIN issuingrules ON (issuingrules.itemtype=biblioitems.itemtype) };
679
EOQ
678
    }
680
    }
679
	$strsth.=
681
	$strsth.=<<EOQ;
680
        qq{ WHERE finedays IS NOT NULL
682
WHERE finedays IS NOT NULL
681
            AND  date_due < returndate
683
AND  date_due < returndate
682
            AND borrowernumber = ?
684
AND borrowernumber = ?
683
            ORDER BY blockingdate DESC, blockedcount DESC
685
ORDER BY issuingrules.itemtype DESC, blockingdate DESC, blockedcount DESC
684
            LIMIT 1};
686
LIMIT 1
687
EOQ
685
	my $sth=$dbh->prepare($strsth);
688
	my $sth=$dbh->prepare($strsth);
686
    $sth->execute($borrowernumber);
689
    $sth->execute($borrowernumber);
687
    my $row = $sth->fetchrow_hashref;
690
    my $row = $sth->fetchrow_hashref;
(-)a/C4/Overdues.pm (-39 / +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 246-252 sub CalcFine { Link Here
246
	my $daystocharge;
243
	my $daystocharge;
247
	# get issuingrules (fines part will be used)
244
	# get issuingrules (fines part will be used)
248
    $debug and warn sprintf("CalcFine calling GetIssuingRule(%s, %s, %s)", $bortype, $item->{'itemtype'}, $branchcode);
245
    $debug and warn sprintf("CalcFine calling GetIssuingRule(%s, %s, %s)", $bortype, $item->{'itemtype'}, $branchcode);
249
    my $data = C4::Circulation::GetIssuingRule($bortype, $item->{'itemtype'}, $branchcode);
250
	if($difference) {
246
	if($difference) {
251
		# if $difference is supplied, the difference has already been calculated, but we still need to adjust for the calendar.
247
		# if $difference is supplied, the difference has already been calculated, but we still need to adjust for the calendar.
252
    	# use copy-pasted functions from calendar module.  (deprecated -- these functions will be removed from C4::Overdues ).
248
    	# use copy-pasted functions from calendar module.  (deprecated -- these functions will be removed from C4::Overdues ).
Lines 264-269 sub CalcFine { Link Here
264
		}
260
		}
265
	}
261
	}
266
	# correct for grace period.
262
	# correct for grace period.
263
    my $data = C4::Circulation::GetIssuingRuleRecord($bortype, $item->{'itemtype'}, $branchcode);
267
	my $days_minus_grace = $daystocharge - $data->{'firstremind'};
264
	my $days_minus_grace = $daystocharge - $data->{'firstremind'};
268
    if ($data->{'chargeperiod'} > 0 && $days_minus_grace > 0 ) { 
265
    if ($data->{'chargeperiod'} > 0 && $days_minus_grace > 0 ) { 
269
        $amount = int($daystocharge / $data->{'chargeperiod'}) * $data->{'fine'};
266
        $amount = int($daystocharge / $data->{'chargeperiod'}) * $data->{'fine'};
Lines 624-664 sub GetFine { Link Here
624
    return ( $data->{'sum(amountoutstanding)'} );
621
    return ( $data->{'sum(amountoutstanding)'} );
625
}
622
}
626
623
627
628
=head2 GetIssuingRules
629
630
FIXME - This sub should be deprecated and removed.
631
It ignores branch and defaults.
632
633
    $data = &GetIssuingRules($itemtype,$categorycode);
634
635
Looks up for all issuingrules an item info 
636
637
C<$itemnumber> is a reference-to-hash whose keys are all of the fields
638
from the borrowers and categories tables of the Koha database. Thus,
639
640
C<$categorycode> contains  information about borrowers category 
641
642
C<$data> contains all information about both the borrower and
643
category he or she belongs to.
644
=cut 
645
646
sub GetIssuingRules {
647
	warn "GetIssuingRules is deprecated: use GetIssuingRule from C4::Circulation instead.";
648
   my ($itemtype,$categorycode)=@_;
649
   my $dbh   = C4::Context->dbh();    
650
   my $query=qq|SELECT *
651
        FROM issuingrules
652
        WHERE issuingrules.itemtype=?
653
            AND issuingrules.categorycode=?
654
        |;
655
    my $sth = $dbh->prepare($query);
656
    #  print $query;
657
    $sth->execute($itemtype,$categorycode);
658
    return $sth->fetchrow_hashref;
659
}
660
661
662
sub ReplacementCost2 {
624
sub ReplacementCost2 {
663
    my ( $itemnum, $borrowernumber ) = @_;
625
    my ( $itemnum, $borrowernumber ) = @_;
664
    my $dbh   = C4::Context->dbh();
626
    my $dbh   = C4::Context->dbh();
(-)a/C4/Reserves.pm (-14 / +1 lines)
Lines 410-427 sub CanItemBeReserved{ Link Here
410
    my $item     = GetItem($itemnumber);
410
    my $item     = GetItem($itemnumber);
411
    my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber);     
411
    my $borrower = C4::Members::GetMember('borrowernumber'=>$borrowernumber);     
412
    
412
    
413
    # we retrieve user rights on this itemtype and branchcode
414
    my $sth = $dbh->prepare("SELECT categorycode, itemtype, branchcode, reservesallowed 
415
                             FROM issuingrules 
416
                             WHERE (categorycode in (?,'*') ) 
417
                             AND (itemtype IN (?,'*')) 
418
                             AND (branchcode IN (?,'*')) 
419
                             ORDER BY 
420
                               categorycode DESC, 
421
                               itemtype     DESC, 
422
                               branchcode   DESC;"
423
                           );
424
                           
425
    my $querycount ="SELECT 
413
    my $querycount ="SELECT 
426
                            count(*) as count
414
                            count(*) as count
427
                            FROM reserves
415
                            FROM reserves
Lines 446-453 sub CanItemBeReserved{ Link Here
446
    }
434
    }
447
    
435
    
448
    # we retrieve rights 
436
    # we retrieve rights 
449
    $sth->execute($categorycode, $itemtype, $branchcode);
437
    if(my $rights = C4::Circulation::GetIssuingRuleRecord($categorycode, $itemtype, $branchcode, 'reservesallowed')){
450
    if(my $rights = $sth->fetchrow_hashref()){
451
        $itemtype        = $rights->{itemtype};
438
        $itemtype        = $rights->{itemtype};
452
        $allowedreserves = $rights->{reservesallowed}; 
439
        $allowedreserves = $rights->{reservesallowed}; 
453
    }else{
440
    }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