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 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; |
1252 |
|
1175 |
|
1253 |
$sth->execute( $borrowertype, $itemtype, $branchcode ); |
1176 |
return $irules->[0] unless $rule; |
1254 |
$irule = $sth->fetchrow_hashref; |
|
|
1255 |
return $irule if defined($irule) ; |
1256 |
|
1177 |
|
1257 |
$sth->execute( $borrowertype, "*", $branchcode ); |
1178 |
die qq{Invalid rule (field) "$rule"} unless exists $irules->[0]->{$rule}; |
1258 |
$irule = $sth->fetchrow_hashref; |
|
|
1259 |
return $irule if defined($irule) ; |
1260 |
|
1179 |
|
1261 |
$sth->execute( "*", $itemtype, $branchcode ); |
1180 |
foreach (@$irules) { |
1262 |
$irule = $sth->fetchrow_hashref; |
1181 |
return $_ if $_->{$rule}; # XXX defined $_->{$rule} |
1263 |
return $irule if defined($irule) ; |
1182 |
} |
|
|
1183 |
|
1184 |
return; |
1185 |
} |
1264 |
|
1186 |
|
1265 |
$sth->execute( "*", "*", $branchcode ); |
1187 |
=head2 GetIssuingRules |
1266 |
$irule = $sth->fetchrow_hashref; |
|
|
1267 |
return $irule if defined($irule) ; |
1268 |
|
1188 |
|
1269 |
$sth->execute( $borrowertype, $itemtype, "*" ); |
1189 |
my $irules = &GetIssuingRules($borrowertype,$itemtype,$branchcode) |
1270 |
$irule = $sth->fetchrow_hashref; |
|
|
1271 |
return $irule if defined($irule) ; |
1272 |
|
1190 |
|
1273 |
$sth->execute( $borrowertype, "*", "*" ); |
1191 |
Get issuing all rule records for an itemtype, a borrower type and a branch |
1274 |
$irule = $sth->fetchrow_hashref; |
1192 |
in order of preference |
1275 |
return $irule if defined($irule) ; |
|
|
1276 |
|
1193 |
|
1277 |
$sth->execute( "*", $itemtype, "*" ); |
1194 |
Order of preference is $branchcode, $borrowertype, $itemtype |
1278 |
$irule = $sth->fetchrow_hashref; |
|
|
1279 |
return $irule if defined($irule) ; |
1280 |
|
1195 |
|
1281 |
$sth->execute( "*", "*", "*" ); |
1196 |
=cut |
1282 |
$irule = $sth->fetchrow_hashref; |
1197 |
|
1283 |
return $irule if defined($irule) ; |
1198 |
sub GetIssuingRules { |
|
|
1199 |
my ( $borrowertype, $itemtype, $branchcode ) = @_; |
1200 |
|
1201 |
my (@where, @params); |
1202 |
|
1203 |
if ( $borrowertype ) { |
1204 |
push @where, "categorycode=? OR categorycode='*'"; |
1205 |
push @params, $borrowertype; |
1206 |
} else { |
1207 |
push @where, "categorycode='*'"; |
1208 |
} |
1284 |
|
1209 |
|
1285 |
# if no rule matches, |
1210 |
if ( $itemtype ) { |
1286 |
return undef; |
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 1783-1800
sub _FixFineDaysOnReturn {
Link Here
|
1783 |
} |
1726 |
} |
1784 |
|
1727 |
|
1785 |
my $branchcode = _GetCircControlBranch( $item, $borrower ); |
1728 |
my $branchcode = _GetCircControlBranch( $item, $borrower ); |
|
|
1729 |
|
1730 |
my $finedays = GetIssuingRuleValue( $borrower->{categorycode}, $item->{itype}, $branchcode, 'finedays' ) |
1731 |
or return; |
1732 |
my $grace = GetIssuingRuleValue( $borrower->{categorycode}, $item->{itype}, $branchcode, 'firstremind' ); |
1733 |
|
1786 |
my $calendar = C4::Calendar->new( branchcode => $branchcode ); |
1734 |
my $calendar = C4::Calendar->new( branchcode => $branchcode ); |
1787 |
my $today = C4::Dates->new(); |
1735 |
my $today = C4::Dates->new(); |
1788 |
|
1736 |
my $deltadays = $calendar->daysBetween( $datedue, $today ); |
1789 |
my $deltadays = $calendar->daysBetween( $datedue, C4::Dates->new() ); |
|
|
1790 |
|
1737 |
|
1791 |
my $circcontrol = C4::Context::preference('CircControl'); |
1738 |
my $circcontrol = C4::Context::preference('CircControl'); |
1792 |
my $issuingrule = GetIssuingRule( $borrower->{categorycode}, $item->{itype}, $branchcode ); |
|
|
1793 |
my $finedays = $issuingrule->{finedays}; |
1794 |
|
1795 |
# exit if no finedays defined |
1796 |
return unless $finedays; |
1797 |
my $grace = $issuingrule->{firstremind}; |
1798 |
|
1739 |
|
1799 |
if ( $deltadays - $grace > 0 ) { |
1740 |
if ( $deltadays - $grace > 0 ) { |
1800 |
my @newdate = Add_Delta_Days( Today(), $deltadays * $finedays ); |
1741 |
my @newdate = Add_Delta_Days( Today(), $deltadays * $finedays ); |
Lines 2224-2270
sub CanBookBeRenewed {
Link Here
|
2224 |
|
2165 |
|
2225 |
my $sthcount = $dbh->prepare(" |
2166 |
my $sthcount = $dbh->prepare(" |
2226 |
SELECT |
2167 |
SELECT |
2227 |
borrowers.categorycode, biblioitems.itemtype, issues.renewals, renewalsallowed, $controlbranch |
2168 |
borrowers.categorycode, biblioitems.itemtype, issues.renewals, $controlbranch |
2228 |
FROM issuingrules, |
2169 |
FROM issues |
2229 |
issues |
|
|
2230 |
LEFT JOIN items USING (itemnumber) |
2170 |
LEFT JOIN items USING (itemnumber) |
2231 |
LEFT JOIN borrowers USING (borrowernumber) |
2171 |
LEFT JOIN borrowers USING (borrowernumber) |
2232 |
LEFT JOIN biblioitems USING (biblioitemnumber) |
2172 |
LEFT JOIN biblioitems USING (biblioitemnumber) |
2233 |
|
2173 |
|
2234 |
WHERE |
2174 |
WHERE |
2235 |
(issuingrules.categorycode = borrowers.categorycode OR issuingrules.categorycode = '*') |
|
|
2236 |
AND |
2237 |
(issuingrules.itemtype = $itype OR issuingrules.itemtype = '*') |
2238 |
AND |
2239 |
(issuingrules.branchcode = $controlbranch OR issuingrules.branchcode = '*') |
2240 |
AND |
2241 |
borrowernumber = ? |
2175 |
borrowernumber = ? |
2242 |
AND |
2176 |
AND |
2243 |
itemnumber = ? |
2177 |
itemnumber = ? |
2244 |
ORDER BY |
|
|
2245 |
issuingrules.categorycode desc, |
2246 |
issuingrules.itemtype desc, |
2247 |
issuingrules.branchcode desc |
2248 |
LIMIT 1; |
2178 |
LIMIT 1; |
2249 |
"); |
2179 |
"); |
2250 |
|
2180 |
|
2251 |
$sthcount->execute( $borrowernumber, $itemnumber ); |
2181 |
$sthcount->execute( $borrowernumber, $itemnumber ); |
2252 |
if ( my $data1 = $sthcount->fetchrow_hashref ) { |
2182 |
if ( my $data1 = $sthcount->fetchrow_hashref ) { |
2253 |
|
|
|
2254 |
if ( ( $data1->{renewalsallowed} && $data1->{renewalsallowed} > $data1->{renewals} ) || $override_limit ) { |
2255 |
$renewokay = 1; |
2256 |
} |
2257 |
else { |
2258 |
$error="too_many"; |
2259 |
} |
2260 |
|
2261 |
my ( $resfound, $resrec ) = C4::Reserves::CheckReserves($itemnumber); |
2183 |
my ( $resfound, $resrec ) = C4::Reserves::CheckReserves($itemnumber); |
2262 |
if ($resfound) { |
2184 |
if ($resfound) { |
2263 |
$renewokay = 0; |
2185 |
$renewokay = 0; |
2264 |
$error="on_reserve" |
2186 |
$error="on_reserve" |
2265 |
} |
2187 |
} |
|
|
2188 |
elsif ( $override_limit ) { |
2189 |
$renewokay = 1; |
2190 |
} |
2191 |
elsif ( my $renewalsallowed = GetIssuingRuleValue($data1->{categorycode}, $itype, $data1->{$controlbranch}, 'renewalsallowed') ) { |
2192 |
if ( $renewalsallowed > $data1->{renewals} || $override_limit ) { |
2193 |
$renewokay = 1; |
2194 |
} |
2195 |
} |
2196 |
$error="too_many" unless $renewokay; |
2197 |
} |
2266 |
|
2198 |
|
2267 |
} |
|
|
2268 |
return ($renewokay,$error); |
2199 |
return ($renewokay,$error); |
2269 |
} |
2200 |
} |
2270 |
|
2201 |
|
Lines 2371-2378
sub GetRenewCount {
Link Here
|
2371 |
my ( $bornum, $itemno ) = @_; |
2302 |
my ( $bornum, $itemno ) = @_; |
2372 |
my $dbh = C4::Context->dbh; |
2303 |
my $dbh = C4::Context->dbh; |
2373 |
my $renewcount = 0; |
2304 |
my $renewcount = 0; |
2374 |
my $renewsallowed = 0; |
|
|
2375 |
my $renewsleft = 0; |
2376 |
|
2305 |
|
2377 |
my $borrower = C4::Members::GetMember( borrowernumber => $bornum); |
2306 |
my $borrower = C4::Members::GetMember( borrowernumber => $bornum); |
2378 |
my $item = GetItem($itemno); |
2307 |
my $item = GetItem($itemno); |
Lines 2393-2402
sub GetRenewCount {
Link Here
|
2393 |
# $item and $borrower should be calculated |
2322 |
# $item and $borrower should be calculated |
2394 |
my $branchcode = _GetCircControlBranch($item, $borrower); |
2323 |
my $branchcode = _GetCircControlBranch($item, $borrower); |
2395 |
|
2324 |
|
2396 |
my $issuingrule = GetIssuingRule($borrower->{categorycode}, $item->{itype}, $branchcode); |
2325 |
my $renewsallowed = GetIssuingRuleValue($borrower->{categorycode}, $item->{itype}, $branchcode, 'renewalsallowed') || 0; |
2397 |
|
2326 |
my $renewsleft = $renewsallowed - $renewcount; |
2398 |
$renewsallowed = $issuingrule->{'renewalsallowed'}; |
|
|
2399 |
$renewsleft = $renewsallowed - $renewcount; |
2400 |
if($renewsleft < 0){ $renewsleft = 0; } |
2327 |
if($renewsleft < 0){ $renewsleft = 0; } |
2401 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
2328 |
return ( $renewcount, $renewsallowed, $renewsleft ); |
2402 |
} |
2329 |
} |
Lines 2441-2459
sub GetIssuingCharges {
Link Here
|
2441 |
$item_type = $item_data->{itemtype}; |
2368 |
$item_type = $item_data->{itemtype}; |
2442 |
$charge = $item_data->{rentalcharge}; |
2369 |
$charge = $item_data->{rentalcharge}; |
2443 |
my $branch = C4::Branch::mybranch(); |
2370 |
my $branch = C4::Branch::mybranch(); |
2444 |
my $discount_query = q|SELECT rentaldiscount, |
2371 |
my $borr_query = q|SELECT borrowers.categorycode |
2445 |
issuingrules.itemtype, issuingrules.branchcode |
|
|
2446 |
FROM borrowers |
2372 |
FROM borrowers |
2447 |
LEFT JOIN issuingrules ON borrowers.categorycode = issuingrules.categorycode |
2373 |
WHERE borrowers.borrowernumber = ?|; |
2448 |
WHERE borrowers.borrowernumber = ? |
2374 |
my $borr_cat = $dbh->selectrow_array($borr_query, undef, $borrowernumber); |
2449 |
AND (issuingrules.itemtype = ? OR issuingrules.itemtype = '*') |
2375 |
if ( my $discount = GetIssuingRuleValue($borr_cat, $item_type, $branch, 'rentaldiscount') ) { |
2450 |
AND (issuingrules.branchcode = ? OR issuingrules.branchcode = '*')|; |
|
|
2451 |
my $discount_sth = $dbh->prepare($discount_query); |
2452 |
$discount_sth->execute( $borrowernumber, $item_type, $branch ); |
2453 |
my $discount_rules = $discount_sth->fetchall_arrayref({}); |
2454 |
if (@{$discount_rules}) { |
2455 |
# We may have multiple rules so get the most specific |
2456 |
my $discount = _get_discount_from_rule($discount_rules, $branch, $item_type); |
2457 |
$charge = ( $charge * ( 100 - $discount ) ) / 100; |
2376 |
$charge = ( $charge * ( 100 - $discount ) ) / 100; |
2458 |
} |
2377 |
} |
2459 |
} |
2378 |
} |
Lines 2462-2504
sub GetIssuingCharges {
Link Here
|
2462 |
return ( $charge, $item_type ); |
2381 |
return ( $charge, $item_type ); |
2463 |
} |
2382 |
} |
2464 |
|
2383 |
|
2465 |
# Select most appropriate discount rule from those returned |
|
|
2466 |
sub _get_discount_from_rule { |
2467 |
my ($rules_ref, $branch, $itemtype) = @_; |
2468 |
my $discount; |
2469 |
|
2470 |
if (@{$rules_ref} == 1) { # only 1 applicable rule use it |
2471 |
$discount = $rules_ref->[0]->{rentaldiscount}; |
2472 |
return (defined $discount) ? $discount : 0; |
2473 |
} |
2474 |
# could have up to 4 does one match $branch and $itemtype |
2475 |
my @d = grep { $_->{branchcode} eq $branch && $_->{itemtype} eq $itemtype } @{$rules_ref}; |
2476 |
if (@d) { |
2477 |
$discount = $d[0]->{rentaldiscount}; |
2478 |
return (defined $discount) ? $discount : 0; |
2479 |
} |
2480 |
# do we have item type + all branches |
2481 |
@d = grep { $_->{branchcode} eq q{*} && $_->{itemtype} eq $itemtype } @{$rules_ref}; |
2482 |
if (@d) { |
2483 |
$discount = $d[0]->{rentaldiscount}; |
2484 |
return (defined $discount) ? $discount : 0; |
2485 |
} |
2486 |
# do we all item types + this branch |
2487 |
@d = grep { $_->{branchcode} eq $branch && $_->{itemtype} eq q{*} } @{$rules_ref}; |
2488 |
if (@d) { |
2489 |
$discount = $d[0]->{rentaldiscount}; |
2490 |
return (defined $discount) ? $discount : 0; |
2491 |
} |
2492 |
# so all and all (surely we wont get here) |
2493 |
@d = grep { $_->{branchcode} eq q{*} && $_->{itemtype} eq q{*} } @{$rules_ref}; |
2494 |
if (@d) { |
2495 |
$discount = $d[0]->{rentaldiscount}; |
2496 |
return (defined $discount) ? $discount : 0; |
2497 |
} |
2498 |
# none of the above |
2499 |
return 0; |
2500 |
} |
2501 |
|
2502 |
=head2 AddIssuingCharge |
2384 |
=head2 AddIssuingCharge |
2503 |
|
2385 |
|
2504 |
&AddIssuingCharge( $itemno, $borrowernumber, $charge ) |
2386 |
&AddIssuingCharge( $itemno, $borrowernumber, $charge ) |