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