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 Koha::Accounts::CreditTypes; |
34 |
use C4::ItemCirculationAlertPreference; |
35 |
use C4::ItemCirculationAlertPreference; |
35 |
use C4::Message; |
36 |
use C4::Message; |
36 |
use C4::Debug; |
37 |
use C4::Debug; |
Lines 48-53
use Data::Dumper;
Link Here
|
48 |
use Koha::DateUtils; |
49 |
use Koha::DateUtils; |
49 |
use Koha::Calendar; |
50 |
use Koha::Calendar; |
50 |
use Koha::Borrower::Debarments; |
51 |
use Koha::Borrower::Debarments; |
|
|
52 |
use Koha::Database; |
51 |
use Carp; |
53 |
use Carp; |
52 |
use Date::Calc qw( |
54 |
use Date::Calc qw( |
53 |
Today |
55 |
Today |
Lines 1280-1286
sub AddIssue {
Link Here
|
1280 |
## If item was lost, it has now been found, reverse any list item charges if neccessary. |
1282 |
## If item was lost, it has now been found, reverse any list item charges if neccessary. |
1281 |
if ( $item->{'itemlost'} ) { |
1283 |
if ( $item->{'itemlost'} ) { |
1282 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1284 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1283 |
_FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, $item->{'barcode'} ); |
1285 |
_FixAccountForLostAndReturned( $item->{'itemnumber'} ); |
1284 |
} |
1286 |
} |
1285 |
} |
1287 |
} |
1286 |
|
1288 |
|
Lines 1845-1865
sub AddReturn {
Link Here
|
1845 |
|
1847 |
|
1846 |
$type ||= q{}; |
1848 |
$type ||= q{}; |
1847 |
|
1849 |
|
1848 |
if ( C4::Context->preference('finesMode') eq 'production' ) { |
1850 |
if ( $amount > 0 |
1849 |
if ( $amount > 0 ) { |
1851 |
&& C4::Context->preference('finesMode') eq 'production' ) |
1850 |
C4::Overdues::UpdateFine( $issue->{itemnumber}, |
1852 |
{ |
1851 |
$issue->{borrowernumber}, |
1853 |
C4::Overdues::UpdateFine( |
1852 |
$amount, $type, output_pref($datedue) ); |
1854 |
{ |
1853 |
} |
1855 |
itemnumber => $issue->{itemnumber}, |
1854 |
elsif ($return_date) { |
1856 |
borrowernumber => $issue->{borrowernumber}, |
1855 |
|
1857 |
amount => $amount, |
1856 |
# Backdated returns may have fines that shouldn't exist, |
1858 |
due => output_pref($datedue), |
1857 |
# so in this case, we need to drop those fines to 0 |
1859 |
issue_id => $issue->{issue_id} |
1858 |
|
1860 |
} |
1859 |
C4::Overdues::UpdateFine( $issue->{itemnumber}, |
1861 |
); |
1860 |
$issue->{borrowernumber}, |
1862 |
} |
1861 |
0, $type, output_pref($datedue) ); |
1863 |
elsif ($return_date) { |
1862 |
} |
1864 |
|
|
|
1865 |
# Backdated returns may have fines that shouldn't exist, |
1866 |
# so in this case, we need to drop those fines to 0 |
1867 |
C4::Overdues::UpdateFine( |
1868 |
{ |
1869 |
itemnumber => $issue->{itemnumber}, |
1870 |
borrowernumber => $issue->{borrowernumber}, |
1871 |
amount => 0, |
1872 |
due => output_pref($datedue), |
1873 |
issue_id => $issue->{issue_id} |
1874 |
} |
1875 |
); |
1863 |
} |
1876 |
} |
1864 |
} |
1877 |
} |
1865 |
|
1878 |
|
Lines 1909-1923
sub AddReturn {
Link Here
|
1909 |
$messages->{'WasLost'} = 1; |
1922 |
$messages->{'WasLost'} = 1; |
1910 |
|
1923 |
|
1911 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1924 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1912 |
_FixAccountForLostAndReturned($item->{'itemnumber'}, $borrowernumber, $barcode); # can tolerate undef $borrowernumber |
1925 |
_FixAccountForLostAndReturned( $item->{'itemnumber'} ); |
1913 |
$messages->{'LostItemFeeRefunded'} = 1; |
1926 |
$messages->{'LostItemFeeRefunded'} = 1; |
1914 |
} |
1927 |
} |
1915 |
} |
1928 |
} |
1916 |
|
1929 |
|
1917 |
# fix up the overdues in accounts... |
1930 |
# fix up the overdues in accounts... |
1918 |
if ($borrowernumber) { |
1931 |
if ($borrowernumber) { |
1919 |
my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox); |
1932 |
_FixOverduesOnReturn( |
1920 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!"; # zero is OK, check defined |
1933 |
{ |
|
|
1934 |
exempt_fine => $exemptfine, |
1935 |
dropbox => $dropbox, |
1936 |
issue => $issue, |
1937 |
} |
1938 |
); |
1921 |
|
1939 |
|
1922 |
if ( $issue->{overdue} && $issue->{date_due} ) { |
1940 |
if ( $issue->{overdue} && $issue->{date_due} ) { |
1923 |
# fix fine days |
1941 |
# fix fine days |
Lines 2026-2035
of the return. It is ignored when a dropbox_branch is passed in.
Link Here
|
2026 |
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2, |
2044 |
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2, |
2027 |
the old_issue is immediately anonymised |
2045 |
the old_issue is immediately anonymised |
2028 |
|
2046 |
|
2029 |
Ideally, this function would be internal to C<C4::Circulation>, |
|
|
2030 |
not exported, but it is currently needed by one |
2031 |
routine in C<C4::Accounts>. |
2032 |
|
2033 |
=cut |
2047 |
=cut |
2034 |
|
2048 |
|
2035 |
sub MarkIssueReturned { |
2049 |
sub MarkIssueReturned { |
Lines 2165-2303
Internal function, called only by AddReturn
Link Here
|
2165 |
=cut |
2179 |
=cut |
2166 |
|
2180 |
|
2167 |
sub _FixOverduesOnReturn { |
2181 |
sub _FixOverduesOnReturn { |
2168 |
my ($borrowernumber, $item); |
2182 |
my ( $params ) = @_; |
2169 |
unless ($borrowernumber = shift) { |
2183 |
|
2170 |
warn "_FixOverduesOnReturn() not supplied valid borrowernumber"; |
2184 |
my $exemptfine = $params->{exempt_fine}; |
2171 |
return; |
2185 |
my $dropbox = $params->{dropbox}; |
2172 |
} |
2186 |
my $issue = $params->{issue}; |
2173 |
unless ($item = shift) { |
2187 |
|
2174 |
warn "_FixOverduesOnReturn() not supplied valid itemnumber"; |
|
|
2175 |
return; |
2176 |
} |
2177 |
my ($exemptfine, $dropbox) = @_; |
2178 |
my $dbh = C4::Context->dbh; |
2188 |
my $dbh = C4::Context->dbh; |
2179 |
|
2189 |
|
2180 |
# check for overdue fine |
2190 |
my $schema = Koha::Database->new()->schema; |
2181 |
my $sth = $dbh->prepare( |
2191 |
my $fine = |
2182 |
"SELECT * FROM accountlines WHERE (borrowernumber = ?) AND (itemnumber = ?) AND (accounttype='FU' OR accounttype='O')" |
2192 |
$schema->resultset('AccountDebit') |
2183 |
); |
2193 |
->single( { issue_id => $issue->issue_id(), type => Koha::Accounts::DebitTypes::Fine() } ); |
2184 |
$sth->execute( $borrowernumber, $item ); |
|
|
2185 |
|
2194 |
|
2186 |
# alter fine to show that the book has been returned |
2195 |
return unless ( $fine ); |
2187 |
my $data = $sth->fetchrow_hashref; |
2196 |
|
2188 |
return 0 unless $data; # no warning, there's just nothing to fix |
2197 |
$fine->accruing(0); |
2189 |
|
2198 |
|
2190 |
my $uquery; |
|
|
2191 |
my @bind = ($data->{'accountlines_id'}); |
2192 |
if ($exemptfine) { |
2199 |
if ($exemptfine) { |
2193 |
$uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0"; |
2200 |
AddCredit( |
2194 |
if (C4::Context->preference("FinesLog")) { |
2201 |
{ |
2195 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2202 |
borrower => $fine->borrowernumber(), |
2196 |
} |
2203 |
amount => $fine->amount_original(), |
2197 |
} elsif ($dropbox && $data->{lastincrement}) { |
2204 |
debit_id => $fine->debit_id(), |
2198 |
my $outstanding = $data->{amountoutstanding} - $data->{lastincrement} ; |
2205 |
type => Koha::Accounts::CreditTypes::Forgiven(), |
2199 |
my $amt = $data->{amount} - $data->{lastincrement} ; |
2206 |
} |
|
|
2207 |
); |
2200 |
if (C4::Context->preference("FinesLog")) { |
2208 |
if (C4::Context->preference("FinesLog")) { |
2201 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Dropbox adjustment $amt, item $item"); |
2209 |
&logaction( |
2202 |
} |
2210 |
"FINES", 'MODIFY', |
2203 |
$uquery = "update accountlines set accounttype='F' "; |
2211 |
$issue->{borrowernumber}, |
2204 |
if($outstanding >= 0 && $amt >=0) { |
2212 |
"Overdue forgiven: item " . $issue->{itemnumber} |
2205 |
$uquery .= ", amount = ? , amountoutstanding=? "; |
2213 |
); |
2206 |
unshift @bind, ($amt, $outstanding) ; |
|
|
2207 |
} |
2214 |
} |
2208 |
} else { |
2215 |
} elsif ($dropbox && $fine->amount_last_increment() != $fine->amount_original() ) { |
2209 |
$uquery = "update accountlines set accounttype='F' "; |
2216 |
if ( C4::Context->preference("FinesLog") ) { |
|
|
2217 |
&logaction( "FINES", 'MODIFY', $issue->{borrowernumber}, |
2218 |
"Dropbox adjustment " |
2219 |
. $fine->amount_last_increment() |
2220 |
. ", item " . $issue->{itemnumber} ); |
2221 |
} |
2222 |
$fine->amount_original( |
2223 |
$fine->amount_original() - $fine->amount_last_increment() ); |
2224 |
$fine->amount_outstanding( |
2225 |
$fine->amount_outstanding - $fine->amount_last_increment() ); |
2226 |
$schema->resultset('AccountOffset')->create( |
2227 |
{ |
2228 |
debit_id => $fine->debit_id(), |
2229 |
type => Koha::Accounts::OffsetTypes::Dropbox(), |
2230 |
amount => $fine->amount_last_increment() * -1, |
2231 |
} |
2232 |
); |
2210 |
} |
2233 |
} |
2211 |
$uquery .= " where (accountlines_id = ?)"; |
2234 |
|
2212 |
my $usth = $dbh->prepare($uquery); |
2235 |
return $fine->update(); |
2213 |
return $usth->execute(@bind); |
|
|
2214 |
} |
2236 |
} |
2215 |
|
2237 |
|
2216 |
=head2 _FixAccountForLostAndReturned |
2238 |
=head2 _FixAccountForLostAndReturned |
2217 |
|
2239 |
|
2218 |
&_FixAccountForLostAndReturned($itemnumber, [$borrowernumber, $barcode]); |
2240 |
&_FixAccountForLostAndReturned($itemnumber); |
2219 |
|
|
|
2220 |
Calculates the charge for a book lost and returned. |
2221 |
|
2222 |
Internal function, not exported, called only by AddReturn. |
2223 |
|
2241 |
|
2224 |
FIXME: This function reflects how inscrutable fines logic is. Fix both. |
2242 |
Refunds a lost item fee in necessary |
2225 |
FIXME: Give a positive return value on success. It might be the $borrowernumber who received credit, or the amount forgiven. |
|
|
2226 |
|
2243 |
|
2227 |
=cut |
2244 |
=cut |
2228 |
|
2245 |
|
2229 |
sub _FixAccountForLostAndReturned { |
2246 |
sub _FixAccountForLostAndReturned { |
2230 |
my $itemnumber = shift or return; |
2247 |
my ( $itemnumber ) = @_; |
2231 |
my $borrowernumber = @_ ? shift : undef; |
2248 |
|
2232 |
my $item_id = @_ ? shift : $itemnumber; # Send the barcode if you want that logged in the description |
2249 |
my $schema = Koha::Database->new()->schema; |
2233 |
my $dbh = C4::Context->dbh; |
2250 |
|
2234 |
# check for charge made for lost book |
2251 |
# Find the last issue for this item |
2235 |
my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE itemnumber = ? AND accounttype IN ('L', 'Rep', 'W') ORDER BY date DESC, accountno DESC"); |
2252 |
my $issue = |
2236 |
$sth->execute($itemnumber); |
2253 |
$schema->resultset('Issue')->single( { itemnumber => $itemnumber } ); |
2237 |
my $data = $sth->fetchrow_hashref; |
2254 |
$issue ||= |
2238 |
$data or return; # bail if there is nothing to do |
2255 |
$schema->resultset('OldIssue')->single( { itemnumber => $itemnumber } ); |
2239 |
$data->{accounttype} eq 'W' and return; # Written off |
2256 |
|
2240 |
|
2257 |
return unless $issue; |
2241 |
# writeoff this amount |
2258 |
|
2242 |
my $offset; |
2259 |
# Find a lost fee for this issue |
2243 |
my $amount = $data->{'amount'}; |
2260 |
my $debit = $schema->resultset('AccountDebit')->single( |
2244 |
my $acctno = $data->{'accountno'}; |
2261 |
{ |
2245 |
my $amountleft; # Starts off undef/zero. |
2262 |
issue_id => $issue->issue_id(), |
2246 |
if ($data->{'amountoutstanding'} == $amount) { |
2263 |
type => Koha::Accounts::DebitTypes::Lost() |
2247 |
$offset = $data->{'amount'}; |
2264 |
} |
2248 |
$amountleft = 0; # Hey, it's zero here, too. |
2265 |
); |
2249 |
} else { |
2266 |
|
2250 |
$offset = $amount - $data->{'amountoutstanding'}; # Um, isn't this the same as ZERO? We just tested those two things are == |
2267 |
return unless $debit; |
2251 |
$amountleft = $data->{'amountoutstanding'} - $amount; # Um, isn't this the same as ZERO? We just tested those two things are == |
2268 |
|
2252 |
} |
2269 |
# Check for an existing found credit for this debit, if there is one, the fee has already been refunded and we do nothing |
2253 |
my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0' |
2270 |
my @credits = $debit->account_offsets->search_related('credit', { 'credit.type' => Koha::Accounts::CreditTypes::Found() }); |
2254 |
WHERE (accountlines_id = ?)"); |
2271 |
|
2255 |
$usth->execute($data->{'accountlines_id'}); # We might be adjusting an account for some OTHER borrowernumber now. Not the one we passed in. |
2272 |
return if @credits; |
2256 |
#check if any credit is left if so writeoff other accounts |
2273 |
|
2257 |
my $nextaccntno = getnextacctno($data->{'borrowernumber'}); |
2274 |
# Ok, so we know we have an unrefunded lost item fee, let's refund it |
2258 |
$amountleft *= -1 if ($amountleft < 0); |
2275 |
CreditLostItem( |
2259 |
if ($amountleft > 0) { |
2276 |
{ |
2260 |
my $msth = $dbh->prepare("SELECT * FROM accountlines WHERE (borrowernumber = ?) |
2277 |
borrower => $issue->borrower(), |
2261 |
AND (amountoutstanding >0) ORDER BY date"); # might want to order by amountoustanding ASC (pay smallest first) |
2278 |
debit => $debit |
2262 |
$msth->execute($data->{'borrowernumber'}); |
2279 |
} |
2263 |
# offset transactions |
2280 |
); |
2264 |
my $newamtos; |
2281 |
|
2265 |
my $accdata; |
|
|
2266 |
while (($accdata=$msth->fetchrow_hashref) and ($amountleft>0)){ |
2267 |
if ($accdata->{'amountoutstanding'} < $amountleft) { |
2268 |
$newamtos = 0; |
2269 |
$amountleft -= $accdata->{'amountoutstanding'}; |
2270 |
} else { |
2271 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
2272 |
$amountleft = 0; |
2273 |
} |
2274 |
my $thisacct = $accdata->{'accountlines_id'}; |
2275 |
# FIXME: move prepares outside while loop! |
2276 |
my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ? |
2277 |
WHERE (accountlines_id = ?)"); |
2278 |
$usth->execute($newamtos,$thisacct); |
2279 |
$usth = $dbh->prepare("INSERT INTO accountoffsets |
2280 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
2281 |
VALUES |
2282 |
(?,?,?,?)"); |
2283 |
$usth->execute($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos); |
2284 |
} |
2285 |
} |
2286 |
$amountleft *= -1 if ($amountleft > 0); |
2287 |
my $desc = "Item Returned " . $item_id; |
2288 |
$usth = $dbh->prepare("INSERT INTO accountlines |
2289 |
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) |
2290 |
VALUES (?,?,now(),?,?,'CR',?)"); |
2291 |
$usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft); |
2292 |
if ($borrowernumber) { |
2293 |
# FIXME: same as query above. use 1 sth for both |
2294 |
$usth = $dbh->prepare("INSERT INTO accountoffsets |
2295 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
2296 |
VALUES (?,?,?,?)"); |
2297 |
$usth->execute($borrowernumber, $data->{'accountno'}, $nextaccntno, $offset); |
2298 |
} |
2299 |
ModItem({ paidfor => '' }, undef, $itemnumber); |
2282 |
ModItem({ paidfor => '' }, undef, $itemnumber); |
2300 |
return; |
|
|
2301 |
} |
2283 |
} |
2302 |
|
2284 |
|
2303 |
=head2 _GetCircControlBranch |
2285 |
=head2 _GetCircControlBranch |
Lines 2741-2759
sub AddRenewal {
Link Here
|
2741 |
# Charge a new rental fee, if applicable? |
2723 |
# Charge a new rental fee, if applicable? |
2742 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
2724 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
2743 |
if ( $charge > 0 ) { |
2725 |
if ( $charge > 0 ) { |
2744 |
my $accountno = getnextacctno( $borrowernumber ); |
|
|
2745 |
my $item = GetBiblioFromItemNumber($itemnumber); |
2726 |
my $item = GetBiblioFromItemNumber($itemnumber); |
2746 |
my $manager_id = 0; |
2727 |
|
2747 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
2728 |
my $borrower = |
2748 |
$sth = $dbh->prepare( |
2729 |
Koha::Database->new()->schema->resultset('Borrower') |
2749 |
"INSERT INTO accountlines |
2730 |
->find($borrowernumber); |
2750 |
(date, borrowernumber, accountno, amount, manager_id, |
2731 |
|
2751 |
description,accounttype, amountoutstanding, itemnumber) |
2732 |
AddDebit( |
2752 |
VALUES (now(),?,?,?,?,?,?,?,?)" |
2733 |
{ |
|
|
2734 |
borrower => $borrower, |
2735 |
itemnumber => $itemnumber, |
2736 |
amount => $charge, |
2737 |
type => Koha::Accounts::DebitTypes::Rental(), |
2738 |
description => |
2739 |
"Renewal of Rental Item $item->{'title'} $item->{'barcode'}" |
2740 |
} |
2753 |
); |
2741 |
); |
2754 |
$sth->execute( $borrowernumber, $accountno, $charge, $manager_id, |
|
|
2755 |
"Renewal of Rental Item $item->{'title'} $item->{'barcode'}", |
2756 |
'Rent', $charge, $itemnumber ); |
2757 |
} |
2742 |
} |
2758 |
|
2743 |
|
2759 |
# Send a renewal slip according to checkout alert preferencei |
2744 |
# Send a renewal slip according to checkout alert preferencei |
Lines 2979-3003
sub _get_discount_from_rule {
Link Here
|
2979 |
|
2964 |
|
2980 |
=head2 AddIssuingCharge |
2965 |
=head2 AddIssuingCharge |
2981 |
|
2966 |
|
2982 |
&AddIssuingCharge( $itemno, $borrowernumber, $charge ) |
2967 |
&AddIssuingCharge( $itemnumber, $borrowernumber, $amount ) |
2983 |
|
2968 |
|
2984 |
=cut |
2969 |
=cut |
2985 |
|
2970 |
|
2986 |
sub AddIssuingCharge { |
2971 |
sub AddIssuingCharge { |
2987 |
my ( $itemnumber, $borrowernumber, $charge ) = @_; |
2972 |
my ( $itemnumber, $borrowernumber, $amount ) = @_; |
2988 |
my $dbh = C4::Context->dbh; |
2973 |
|
2989 |
my $nextaccntno = getnextacctno( $borrowernumber ); |
2974 |
return AddDebit( |
2990 |
my $manager_id = 0; |
2975 |
{ |
2991 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
2976 |
borrower => Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber), |
2992 |
my $query =" |
2977 |
itemnumber => $itemnumber, |
2993 |
INSERT INTO accountlines |
2978 |
amount => $amount, |
2994 |
(borrowernumber, itemnumber, accountno, |
2979 |
type => Koha::Accounts::DebitTypes::Rental(), |
2995 |
date, amount, description, accounttype, |
2980 |
} |
2996 |
amountoutstanding, manager_id) |
2981 |
); |
2997 |
VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?) |
|
|
2998 |
"; |
2999 |
my $sth = $dbh->prepare($query); |
3000 |
$sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id ); |
3001 |
} |
2982 |
} |
3002 |
|
2983 |
|
3003 |
=head2 GetTransfers |
2984 |
=head2 GetTransfers |
Lines 3516-3545
sub ReturnLostItem{
Link Here
|
3516 |
sub LostItem{ |
3497 |
sub LostItem{ |
3517 |
my ($itemnumber, $mark_returned) = @_; |
3498 |
my ($itemnumber, $mark_returned) = @_; |
3518 |
|
3499 |
|
3519 |
my $dbh = C4::Context->dbh(); |
3500 |
my $schema = Koha::Database->new()->schema; |
3520 |
my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title |
|
|
3521 |
FROM issues |
3522 |
JOIN items USING (itemnumber) |
3523 |
JOIN biblio USING (biblionumber) |
3524 |
WHERE issues.itemnumber=?"); |
3525 |
$sth->execute($itemnumber); |
3526 |
my $issues=$sth->fetchrow_hashref(); |
3527 |
|
3501 |
|
3528 |
# If a borrower lost the item, add a replacement cost to the their record |
3502 |
my $issue = |
3529 |
if ( my $borrowernumber = $issues->{borrowernumber} ){ |
3503 |
$schema->resultset('Issue')->single( { itemnumber => $itemnumber } ); |
3530 |
my $borrower = C4::Members::GetMemberDetails( $borrowernumber ); |
3504 |
|
|
|
3505 |
my ( $borrower, $item ); |
3506 |
|
3507 |
if ( $issue ) { |
3508 |
$borrower = $issue->borrower(); |
3509 |
$item = $issue->item(); |
3510 |
} |
3531 |
|
3511 |
|
|
|
3512 |
# If a borrower lost the item, add a replacement cost to the their record |
3513 |
if ( $borrower ){ |
3532 |
if (C4::Context->preference('WhenLostForgiveFine')){ |
3514 |
if (C4::Context->preference('WhenLostForgiveFine')){ |
3533 |
my $fix = _FixOverduesOnReturn($borrowernumber, $itemnumber, 1, 0); # 1, 0 = exemptfine, no-dropbox |
3515 |
_FixOverduesOnReturn( |
3534 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!"; # zero is OK, check defined |
3516 |
{ |
|
|
3517 |
exempt_fine => 1, |
3518 |
dropbox => 0, |
3519 |
issue => $issue, |
3520 |
} |
3521 |
); |
3535 |
} |
3522 |
} |
3536 |
if (C4::Context->preference('WhenLostChargeReplacementFee')){ |
3523 |
if ( C4::Context->preference('WhenLostChargeReplacementFee') ) { |
3537 |
C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}"); |
3524 |
DebitLostItem( { borrower => $borrower, issue => $issue } ); |
3538 |
#FIXME : Should probably have a way to distinguish this from an item that really was returned. |
|
|
3539 |
#warn " $issues->{'borrowernumber'} / $itemnumber "; |
3540 |
} |
3525 |
} |
3541 |
|
3526 |
|
3542 |
MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$borrower->{'privacy'}) if $mark_returned; |
3527 |
MarkIssueReturned( $borrower->borrowernumber(), $item->itemnumber(), undef, undef, $borrower->privacy() ) if $mark_returned; |
3543 |
} |
3528 |
} |
3544 |
} |
3529 |
} |
3545 |
|
3530 |
|
Lines 3657-3666
sub ProcessOfflineIssue {
Link Here
|
3657 |
sub ProcessOfflinePayment { |
3642 |
sub ProcessOfflinePayment { |
3658 |
my $operation = shift; |
3643 |
my $operation = shift; |
3659 |
|
3644 |
|
3660 |
my $borrower = C4::Members::GetMemberDetails( undef, $operation->{cardnumber} ); # Get borrower from operation cardnumber |
3645 |
AddCredit( |
3661 |
my $amount = $operation->{amount}; |
3646 |
{ |
3662 |
|
3647 |
borrower => Koha::Database->new()->schema->resultset('Borrower') |
3663 |
recordpayment( $borrower->{borrowernumber}, $amount ); |
3648 |
->single( { cardnumber => $operation->{cardnumber} } ), |
|
|
3649 |
amount => $operation->{amount}, |
3650 |
notes => 'via offline circulation', |
3651 |
type => Koha::Accounts::CreditTypes::Payment, |
3652 |
} |
3653 |
); |
3664 |
|
3654 |
|
3665 |
return "Success." |
3655 |
return "Success." |
3666 |
} |
3656 |
} |