|
Lines 30-36
use C4::Items;
Link Here
|
| 30 |
use C4::Members; |
30 |
use C4::Members; |
| 31 |
use C4::Dates; |
31 |
use C4::Dates; |
| 32 |
use C4::Dates qw(format_date); |
32 |
use C4::Dates qw(format_date); |
| 33 |
use C4::Accounts; |
33 |
use Koha::Accounts; |
| 34 |
use C4::ItemCirculationAlertPreference; |
34 |
use C4::ItemCirculationAlertPreference; |
| 35 |
use C4::Message; |
35 |
use C4::Message; |
| 36 |
use C4::Debug; |
36 |
use C4::Debug; |
|
Lines 48-53
use Data::Dumper;
Link Here
|
| 48 |
use Koha::DateUtils; |
48 |
use Koha::DateUtils; |
| 49 |
use Koha::Calendar; |
49 |
use Koha::Calendar; |
| 50 |
use Koha::Borrower::Debarments; |
50 |
use Koha::Borrower::Debarments; |
|
|
51 |
use Koha::Database; |
| 51 |
use Carp; |
52 |
use Carp; |
| 52 |
use Date::Calc qw( |
53 |
use Date::Calc qw( |
| 53 |
Today |
54 |
Today |
|
Lines 1273-1279
sub AddIssue {
Link Here
|
| 1273 |
## If item was lost, it has now been found, reverse any list item charges if neccessary. |
1274 |
## If item was lost, it has now been found, reverse any list item charges if neccessary. |
| 1274 |
if ( $item->{'itemlost'} ) { |
1275 |
if ( $item->{'itemlost'} ) { |
| 1275 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1276 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
| 1276 |
_FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, $item->{'barcode'} ); |
1277 |
_FixAccountForLostAndReturned( $item->{'itemnumber'} ); |
| 1277 |
} |
1278 |
} |
| 1278 |
} |
1279 |
} |
| 1279 |
|
1280 |
|
|
Lines 1834-1854
sub AddReturn {
Link Here
|
| 1834 |
|
1835 |
|
| 1835 |
$type ||= q{}; |
1836 |
$type ||= q{}; |
| 1836 |
|
1837 |
|
| 1837 |
if ( C4::Context->preference('finesMode') eq 'production' ) { |
1838 |
if ( $amount > 0 |
| 1838 |
if ( $amount > 0 ) { |
1839 |
&& C4::Context->preference('finesMode') eq 'production' ) |
| 1839 |
C4::Overdues::UpdateFine( $issue->{itemnumber}, |
1840 |
{ |
| 1840 |
$issue->{borrowernumber}, |
1841 |
C4::Overdues::UpdateFine( |
| 1841 |
$amount, $type, output_pref($datedue) ); |
1842 |
{ |
| 1842 |
} |
1843 |
itemnumber => $issue->{itemnumber}, |
| 1843 |
elsif ($return_date) { |
1844 |
borrowernumber => $issue->{borrowernumber}, |
| 1844 |
|
1845 |
amount => $amount, |
| 1845 |
# Backdated returns may have fines that shouldn't exist, |
1846 |
due => output_pref($datedue), |
| 1846 |
# so in this case, we need to drop those fines to 0 |
1847 |
issue_id => $issue->{issue_id} |
| 1847 |
|
1848 |
} |
| 1848 |
C4::Overdues::UpdateFine( $issue->{itemnumber}, |
1849 |
); |
| 1849 |
$issue->{borrowernumber}, |
1850 |
} |
| 1850 |
0, $type, output_pref($datedue) ); |
1851 |
elsif ($return_date) { |
| 1851 |
} |
1852 |
|
|
|
1853 |
# Backdated returns may have fines that shouldn't exist, |
| 1854 |
# so in this case, we need to drop those fines to 0 |
| 1855 |
C4::Overdues::UpdateFine( |
| 1856 |
{ |
| 1857 |
itemnumber => $issue->{itemnumber}, |
| 1858 |
borrowernumber => $issue->{borrowernumber}, |
| 1859 |
amount => 0, |
| 1860 |
due => output_pref($datedue), |
| 1861 |
issue_id => $issue->{issue_id} |
| 1862 |
} |
| 1863 |
); |
| 1852 |
} |
1864 |
} |
| 1853 |
} |
1865 |
} |
| 1854 |
|
1866 |
|
|
Lines 1898-1912
sub AddReturn {
Link Here
|
| 1898 |
$messages->{'WasLost'} = 1; |
1910 |
$messages->{'WasLost'} = 1; |
| 1899 |
|
1911 |
|
| 1900 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1912 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
| 1901 |
_FixAccountForLostAndReturned($item->{'itemnumber'}, $borrowernumber, $barcode); # can tolerate undef $borrowernumber |
1913 |
_FixAccountForLostAndReturned( $item->{'itemnumber'} ); |
| 1902 |
$messages->{'LostItemFeeRefunded'} = 1; |
1914 |
$messages->{'LostItemFeeRefunded'} = 1; |
| 1903 |
} |
1915 |
} |
| 1904 |
} |
1916 |
} |
| 1905 |
|
1917 |
|
| 1906 |
# fix up the overdues in accounts... |
1918 |
# fix up the overdues in accounts... |
| 1907 |
if ($borrowernumber) { |
1919 |
if ($borrowernumber) { |
| 1908 |
my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox); |
1920 |
_FixOverduesOnReturn( |
| 1909 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!"; # zero is OK, check defined |
1921 |
{ |
|
|
1922 |
exempt_fine => $exemptfine, |
| 1923 |
dropbox => $dropbox, |
| 1924 |
issue => $issue, |
| 1925 |
} |
| 1926 |
); |
| 1910 |
|
1927 |
|
| 1911 |
if ( $issue->{overdue} && $issue->{date_due} ) { |
1928 |
if ( $issue->{overdue} && $issue->{date_due} ) { |
| 1912 |
# fix fine days |
1929 |
# fix fine days |
|
Lines 2152-2290
Internal function, called only by AddReturn
Link Here
|
| 2152 |
=cut |
2169 |
=cut |
| 2153 |
|
2170 |
|
| 2154 |
sub _FixOverduesOnReturn { |
2171 |
sub _FixOverduesOnReturn { |
| 2155 |
my ($borrowernumber, $item); |
2172 |
my ( $params ) = @_; |
| 2156 |
unless ($borrowernumber = shift) { |
2173 |
|
| 2157 |
warn "_FixOverduesOnReturn() not supplied valid borrowernumber"; |
2174 |
my $exemptfine = $params->{exempt_fine}; |
| 2158 |
return; |
2175 |
my $dropbox = $params->{dropbox}; |
| 2159 |
} |
2176 |
my $issue = $params->{issue}; |
| 2160 |
unless ($item = shift) { |
2177 |
|
| 2161 |
warn "_FixOverduesOnReturn() not supplied valid itemnumber"; |
|
|
| 2162 |
return; |
| 2163 |
} |
| 2164 |
my ($exemptfine, $dropbox) = @_; |
| 2165 |
my $dbh = C4::Context->dbh; |
2178 |
my $dbh = C4::Context->dbh; |
| 2166 |
|
2179 |
|
| 2167 |
# check for overdue fine |
2180 |
my $schema = Koha::Database->new()->schema; |
| 2168 |
my $sth = $dbh->prepare( |
2181 |
my $fine = |
| 2169 |
"SELECT * FROM accountlines WHERE (borrowernumber = ?) AND (itemnumber = ?) AND (accounttype='FU' OR accounttype='O')" |
2182 |
$schema->resultset('AccountDebit') |
| 2170 |
); |
2183 |
->single( { issue_id => $issue->{issue_id}, type => Koha::Accounts::DebitTypes::Fine() } ); |
| 2171 |
$sth->execute( $borrowernumber, $item ); |
|
|
| 2172 |
|
2184 |
|
| 2173 |
# alter fine to show that the book has been returned |
2185 |
return unless ( $fine ); |
| 2174 |
my $data = $sth->fetchrow_hashref; |
2186 |
|
| 2175 |
return 0 unless $data; # no warning, there's just nothing to fix |
2187 |
$fine->accruing(0); |
| 2176 |
|
2188 |
|
| 2177 |
my $uquery; |
|
|
| 2178 |
my @bind = ($data->{'accountlines_id'}); |
| 2179 |
if ($exemptfine) { |
2189 |
if ($exemptfine) { |
| 2180 |
$uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0"; |
2190 |
AddCredit( |
| 2181 |
if (C4::Context->preference("FinesLog")) { |
2191 |
{ |
| 2182 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2192 |
borrower => $fine->borrowernumber(), |
| 2183 |
} |
2193 |
amount => $fine->amount_original(), |
| 2184 |
} elsif ($dropbox && $data->{lastincrement}) { |
2194 |
debit_id => $fine->debit_id(), |
| 2185 |
my $outstanding = $data->{amountoutstanding} - $data->{lastincrement} ; |
2195 |
type => Koha::Accounts::CreditTypes::Forgiven(), |
| 2186 |
my $amt = $data->{amount} - $data->{lastincrement} ; |
2196 |
} |
|
|
2197 |
); |
| 2187 |
if (C4::Context->preference("FinesLog")) { |
2198 |
if (C4::Context->preference("FinesLog")) { |
| 2188 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Dropbox adjustment $amt, item $item"); |
2199 |
&logaction( |
| 2189 |
} |
2200 |
"FINES", 'MODIFY', |
| 2190 |
$uquery = "update accountlines set accounttype='F' "; |
2201 |
$issue->{borrowernumber}, |
| 2191 |
if($outstanding >= 0 && $amt >=0) { |
2202 |
"Overdue forgiven: item " . $issue->{itemnumber} |
| 2192 |
$uquery .= ", amount = ? , amountoutstanding=? "; |
2203 |
); |
| 2193 |
unshift @bind, ($amt, $outstanding) ; |
|
|
| 2194 |
} |
2204 |
} |
| 2195 |
} else { |
2205 |
} elsif ($dropbox && $fine->amount_last_increment() != $fine->amount_original() ) { |
| 2196 |
$uquery = "update accountlines set accounttype='F' "; |
2206 |
if ( C4::Context->preference("FinesLog") ) { |
|
|
2207 |
&logaction( "FINES", 'MODIFY', $issue->{borrowernumber}, |
| 2208 |
"Dropbox adjustment " |
| 2209 |
. $fine->amount_last_increment() |
| 2210 |
. ", item " . $issue->{itemnumber} ); |
| 2211 |
} |
| 2212 |
$fine->amount_original( |
| 2213 |
$fine->amount_original() - $fine->amount_last_increment() ); |
| 2214 |
$fine->amount_outstanding( |
| 2215 |
$fine->amount_outstanding - $fine->amount_last_increment() ); |
| 2216 |
$schema->resultset('AccountOffset')->create( |
| 2217 |
{ |
| 2218 |
debit_id => $fine->debit_id(), |
| 2219 |
type => Koha::Accounts::OffsetTypes::Dropbox(), |
| 2220 |
amount => $fine->amount_last_increment() * -1, |
| 2221 |
} |
| 2222 |
); |
| 2197 |
} |
2223 |
} |
| 2198 |
$uquery .= " where (accountlines_id = ?)"; |
2224 |
|
| 2199 |
my $usth = $dbh->prepare($uquery); |
2225 |
return $fine->update(); |
| 2200 |
return $usth->execute(@bind); |
|
|
| 2201 |
} |
2226 |
} |
| 2202 |
|
2227 |
|
| 2203 |
=head2 _FixAccountForLostAndReturned |
2228 |
=head2 _FixAccountForLostAndReturned |
| 2204 |
|
2229 |
|
| 2205 |
&_FixAccountForLostAndReturned($itemnumber, [$borrowernumber, $barcode]); |
2230 |
&_FixAccountForLostAndReturned($itemnumber); |
| 2206 |
|
2231 |
|
| 2207 |
Calculates the charge for a book lost and returned. |
2232 |
Refunds a lost item fee in necessary |
| 2208 |
|
|
|
| 2209 |
Internal function, not exported, called only by AddReturn. |
| 2210 |
|
| 2211 |
FIXME: This function reflects how inscrutable fines logic is. Fix both. |
| 2212 |
FIXME: Give a positive return value on success. It might be the $borrowernumber who received credit, or the amount forgiven. |
| 2213 |
|
2233 |
|
| 2214 |
=cut |
2234 |
=cut |
| 2215 |
|
2235 |
|
| 2216 |
sub _FixAccountForLostAndReturned { |
2236 |
sub _FixAccountForLostAndReturned { |
| 2217 |
my $itemnumber = shift or return; |
2237 |
my ( $itemnumber ) = @_; |
| 2218 |
my $borrowernumber = @_ ? shift : undef; |
2238 |
|
| 2219 |
my $item_id = @_ ? shift : $itemnumber; # Send the barcode if you want that logged in the description |
2239 |
my $schema = Koha::Database->new()->schema; |
| 2220 |
my $dbh = C4::Context->dbh; |
2240 |
|
| 2221 |
# check for charge made for lost book |
2241 |
# Find the last issue for this item |
| 2222 |
my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE itemnumber = ? AND accounttype IN ('L', 'Rep', 'W') ORDER BY date DESC, accountno DESC"); |
2242 |
my $issue = |
| 2223 |
$sth->execute($itemnumber); |
2243 |
$schema->resultset('Issue')->single( { itemnumber => $itemnumber } ); |
| 2224 |
my $data = $sth->fetchrow_hashref; |
2244 |
$issue ||= |
| 2225 |
$data or return; # bail if there is nothing to do |
2245 |
$schema->resultset('OldIssue')->single( { itemnumber => $itemnumber } ); |
| 2226 |
$data->{accounttype} eq 'W' and return; # Written off |
2246 |
|
| 2227 |
|
2247 |
return unless $issue; |
| 2228 |
# writeoff this amount |
2248 |
|
| 2229 |
my $offset; |
2249 |
# Find a lost fee for this issue |
| 2230 |
my $amount = $data->{'amount'}; |
2250 |
my $debit = $schema->resultset('AccountDebit')->single( |
| 2231 |
my $acctno = $data->{'accountno'}; |
2251 |
{ |
| 2232 |
my $amountleft; # Starts off undef/zero. |
2252 |
issue_id => $issue->issue_id(), |
| 2233 |
if ($data->{'amountoutstanding'} == $amount) { |
2253 |
type => Koha::Accounts::DebitTypes::Lost() |
| 2234 |
$offset = $data->{'amount'}; |
2254 |
} |
| 2235 |
$amountleft = 0; # Hey, it's zero here, too. |
2255 |
); |
| 2236 |
} else { |
2256 |
|
| 2237 |
$offset = $amount - $data->{'amountoutstanding'}; # Um, isn't this the same as ZERO? We just tested those two things are == |
2257 |
return unless $debit; |
| 2238 |
$amountleft = $data->{'amountoutstanding'} - $amount; # Um, isn't this the same as ZERO? We just tested those two things are == |
2258 |
|
| 2239 |
} |
2259 |
# Check for an existing found credit for this debit, if there is one, the fee has already been refunded and we do nothing |
| 2240 |
my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0' |
2260 |
my @credits = $debit->account_offsets->search_related('credit', { 'credit.type' => Koha::Accounts::CreditTypes::Found() }); |
| 2241 |
WHERE (accountlines_id = ?)"); |
2261 |
|
| 2242 |
$usth->execute($data->{'accountlines_id'}); # We might be adjusting an account for some OTHER borrowernumber now. Not the one we passed in. |
2262 |
return if @credits; |
| 2243 |
#check if any credit is left if so writeoff other accounts |
2263 |
|
| 2244 |
my $nextaccntno = getnextacctno($data->{'borrowernumber'}); |
2264 |
# Ok, so we know we have an unrefunded lost item fee, let's refund it |
| 2245 |
$amountleft *= -1 if ($amountleft < 0); |
2265 |
CreditLostItem( |
| 2246 |
if ($amountleft > 0) { |
2266 |
{ |
| 2247 |
my $msth = $dbh->prepare("SELECT * FROM accountlines WHERE (borrowernumber = ?) |
2267 |
borrower => $issue->borrower(), |
| 2248 |
AND (amountoutstanding >0) ORDER BY date"); # might want to order by amountoustanding ASC (pay smallest first) |
2268 |
debit => $debit |
| 2249 |
$msth->execute($data->{'borrowernumber'}); |
2269 |
} |
| 2250 |
# offset transactions |
2270 |
); |
| 2251 |
my $newamtos; |
2271 |
|
| 2252 |
my $accdata; |
|
|
| 2253 |
while (($accdata=$msth->fetchrow_hashref) and ($amountleft>0)){ |
| 2254 |
if ($accdata->{'amountoutstanding'} < $amountleft) { |
| 2255 |
$newamtos = 0; |
| 2256 |
$amountleft -= $accdata->{'amountoutstanding'}; |
| 2257 |
} else { |
| 2258 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 2259 |
$amountleft = 0; |
| 2260 |
} |
| 2261 |
my $thisacct = $accdata->{'accountlines_id'}; |
| 2262 |
# FIXME: move prepares outside while loop! |
| 2263 |
my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ? |
| 2264 |
WHERE (accountlines_id = ?)"); |
| 2265 |
$usth->execute($newamtos,$thisacct); |
| 2266 |
$usth = $dbh->prepare("INSERT INTO accountoffsets |
| 2267 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
| 2268 |
VALUES |
| 2269 |
(?,?,?,?)"); |
| 2270 |
$usth->execute($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos); |
| 2271 |
} |
| 2272 |
} |
| 2273 |
$amountleft *= -1 if ($amountleft > 0); |
| 2274 |
my $desc = "Item Returned " . $item_id; |
| 2275 |
$usth = $dbh->prepare("INSERT INTO accountlines |
| 2276 |
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) |
| 2277 |
VALUES (?,?,now(),?,?,'CR',?)"); |
| 2278 |
$usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft); |
| 2279 |
if ($borrowernumber) { |
| 2280 |
# FIXME: same as query above. use 1 sth for both |
| 2281 |
$usth = $dbh->prepare("INSERT INTO accountoffsets |
| 2282 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
| 2283 |
VALUES (?,?,?,?)"); |
| 2284 |
$usth->execute($borrowernumber, $data->{'accountno'}, $nextaccntno, $offset); |
| 2285 |
} |
| 2286 |
ModItem({ paidfor => '' }, undef, $itemnumber); |
2272 |
ModItem({ paidfor => '' }, undef, $itemnumber); |
| 2287 |
return; |
|
|
| 2288 |
} |
2273 |
} |
| 2289 |
|
2274 |
|
| 2290 |
=head2 _GetCircControlBranch |
2275 |
=head2 _GetCircControlBranch |
|
Lines 2728-2746
sub AddRenewal {
Link Here
|
| 2728 |
# Charge a new rental fee, if applicable? |
2713 |
# Charge a new rental fee, if applicable? |
| 2729 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
2714 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
| 2730 |
if ( $charge > 0 ) { |
2715 |
if ( $charge > 0 ) { |
| 2731 |
my $accountno = getnextacctno( $borrowernumber ); |
|
|
| 2732 |
my $item = GetBiblioFromItemNumber($itemnumber); |
2716 |
my $item = GetBiblioFromItemNumber($itemnumber); |
| 2733 |
my $manager_id = 0; |
2717 |
|
| 2734 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
2718 |
my $borrower = |
| 2735 |
$sth = $dbh->prepare( |
2719 |
Koha::Database->new()->schema->resultset('Borrower') |
| 2736 |
"INSERT INTO accountlines |
2720 |
->find($borrowernumber); |
| 2737 |
(date, borrowernumber, accountno, amount, manager_id, |
2721 |
|
| 2738 |
description,accounttype, amountoutstanding, itemnumber) |
2722 |
AddDebit( |
| 2739 |
VALUES (now(),?,?,?,?,?,?,?,?)" |
2723 |
{ |
|
|
2724 |
borrower => $borrower, |
| 2725 |
itemnumber => $itemnumber, |
| 2726 |
amount => $charge, |
| 2727 |
type => Koha::Accounts::DebitTypes::Rental(), |
| 2728 |
description => |
| 2729 |
"Renewal of Rental Item $item->{'title'} $item->{'barcode'}" |
| 2730 |
} |
| 2740 |
); |
2731 |
); |
| 2741 |
$sth->execute( $borrowernumber, $accountno, $charge, $manager_id, |
|
|
| 2742 |
"Renewal of Rental Item $item->{'title'} $item->{'barcode'}", |
| 2743 |
'Rent', $charge, $itemnumber ); |
| 2744 |
} |
2732 |
} |
| 2745 |
|
2733 |
|
| 2746 |
# Send a renewal slip according to checkout alert preferencei |
2734 |
# Send a renewal slip according to checkout alert preferencei |
|
Lines 2959-2983
sub _get_discount_from_rule {
Link Here
|
| 2959 |
|
2947 |
|
| 2960 |
=head2 AddIssuingCharge |
2948 |
=head2 AddIssuingCharge |
| 2961 |
|
2949 |
|
| 2962 |
&AddIssuingCharge( $itemno, $borrowernumber, $charge ) |
2950 |
&AddIssuingCharge( $itemnumber, $borrowernumber, $amount ) |
| 2963 |
|
2951 |
|
| 2964 |
=cut |
2952 |
=cut |
| 2965 |
|
2953 |
|
| 2966 |
sub AddIssuingCharge { |
2954 |
sub AddIssuingCharge { |
| 2967 |
my ( $itemnumber, $borrowernumber, $charge ) = @_; |
2955 |
my ( $itemnumber, $borrowernumber, $amount ) = @_; |
| 2968 |
my $dbh = C4::Context->dbh; |
2956 |
|
| 2969 |
my $nextaccntno = getnextacctno( $borrowernumber ); |
2957 |
return AddDebit( |
| 2970 |
my $manager_id = 0; |
2958 |
{ |
| 2971 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
2959 |
borrower => Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber), |
| 2972 |
my $query =" |
2960 |
itemnumber => $itemnumber, |
| 2973 |
INSERT INTO accountlines |
2961 |
amount => $amount, |
| 2974 |
(borrowernumber, itemnumber, accountno, |
2962 |
type => Koha::Accounts::DebitTypes::Rental(), |
| 2975 |
date, amount, description, accounttype, |
2963 |
} |
| 2976 |
amountoutstanding, manager_id) |
2964 |
); |
| 2977 |
VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?) |
|
|
| 2978 |
"; |
| 2979 |
my $sth = $dbh->prepare($query); |
| 2980 |
$sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id ); |
| 2981 |
} |
2965 |
} |
| 2982 |
|
2966 |
|
| 2983 |
=head2 GetTransfers |
2967 |
=head2 GetTransfers |
|
Lines 3496-3525
sub ReturnLostItem{
Link Here
|
| 3496 |
sub LostItem{ |
3480 |
sub LostItem{ |
| 3497 |
my ($itemnumber, $mark_returned) = @_; |
3481 |
my ($itemnumber, $mark_returned) = @_; |
| 3498 |
|
3482 |
|
| 3499 |
my $dbh = C4::Context->dbh(); |
3483 |
my $schema = Koha::Database->new()->schema; |
| 3500 |
my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title |
|
|
| 3501 |
FROM issues |
| 3502 |
JOIN items USING (itemnumber) |
| 3503 |
JOIN biblio USING (biblionumber) |
| 3504 |
WHERE issues.itemnumber=?"); |
| 3505 |
$sth->execute($itemnumber); |
| 3506 |
my $issues=$sth->fetchrow_hashref(); |
| 3507 |
|
3484 |
|
| 3508 |
# If a borrower lost the item, add a replacement cost to the their record |
3485 |
my $issue = |
| 3509 |
if ( my $borrowernumber = $issues->{borrowernumber} ){ |
3486 |
$schema->resultset('Issue')->single( { itemnumber => $itemnumber } ); |
| 3510 |
my $borrower = C4::Members::GetMemberDetails( $borrowernumber ); |
3487 |
|
|
|
3488 |
my ( $borrower, $item ); |
| 3489 |
|
| 3490 |
if ( $issue ) { |
| 3491 |
$borrower = $issue->borrower(); |
| 3492 |
$item = $issue->item(); |
| 3493 |
} |
| 3511 |
|
3494 |
|
|
|
3495 |
# If a borrower lost the item, add a replacement cost to the their record |
| 3496 |
if ( $borrower ){ |
| 3512 |
if (C4::Context->preference('WhenLostForgiveFine')){ |
3497 |
if (C4::Context->preference('WhenLostForgiveFine')){ |
| 3513 |
my $fix = _FixOverduesOnReturn($borrowernumber, $itemnumber, 1, 0); # 1, 0 = exemptfine, no-dropbox |
3498 |
_FixOverduesOnReturn( |
| 3514 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!"; # zero is OK, check defined |
3499 |
{ |
|
|
3500 |
exempt_fine => 1, |
| 3501 |
dropbox => 0, |
| 3502 |
issue => $issue, |
| 3503 |
} |
| 3504 |
); |
| 3515 |
} |
3505 |
} |
| 3516 |
if (C4::Context->preference('WhenLostChargeReplacementFee')){ |
3506 |
if ( C4::Context->preference('WhenLostChargeReplacementFee') ) { |
| 3517 |
C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}"); |
3507 |
DebitLostItem( { borrower => $borrower, issue => $issue } ); |
| 3518 |
#FIXME : Should probably have a way to distinguish this from an item that really was returned. |
|
|
| 3519 |
#warn " $issues->{'borrowernumber'} / $itemnumber "; |
| 3520 |
} |
3508 |
} |
| 3521 |
|
3509 |
|
| 3522 |
MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$borrower->{'privacy'}) if $mark_returned; |
3510 |
MarkIssueReturned( $borrower->borrowernumber(), $item->itemnumber(), undef, undef, $borrower->privacy() ) if $mark_returned; |
| 3523 |
} |
3511 |
} |
| 3524 |
} |
3512 |
} |
| 3525 |
|
3513 |
|