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 ) |