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 1296-1302
sub AddIssue {
Link Here
|
1296 |
## If item was lost, it has now been found, reverse any list item charges if neccessary. |
1297 |
## If item was lost, it has now been found, reverse any list item charges if neccessary. |
1297 |
if ( $item->{'itemlost'} ) { |
1298 |
if ( $item->{'itemlost'} ) { |
1298 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1299 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1299 |
_FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, $item->{'barcode'} ); |
1300 |
_FixAccountForLostAndReturned( $item->{'itemnumber'} ); |
1300 |
} |
1301 |
} |
1301 |
} |
1302 |
} |
1302 |
|
1303 |
|
Lines 1855-1861
sub AddReturn {
Link Here
|
1855 |
} |
1856 |
} |
1856 |
|
1857 |
|
1857 |
if ($borrowernumber) { |
1858 |
if ($borrowernumber) { |
1858 |
if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) { |
1859 |
if ( |
|
|
1860 |
( !$item->{itemlost} ) # skip lost items |
1861 |
&& ( |
1862 |
( |
1863 |
C4::Context->preference('CalculateFinesOnReturn') |
1864 |
&& $issue->{'overdue'} |
1865 |
) |
1866 |
|| $return_date # force fine recalculation in case fine needs reduced |
1867 |
) |
1868 |
) |
1869 |
{ |
1859 |
# we only need to calculate and change the fines if we want to do that on return |
1870 |
# we only need to calculate and change the fines if we want to do that on return |
1860 |
# Should be on for hourly loans |
1871 |
# Should be on for hourly loans |
1861 |
my $control = C4::Context->preference('CircControl'); |
1872 |
my $control = C4::Context->preference('CircControl'); |
Lines 1873-1893
sub AddReturn {
Link Here
|
1873 |
|
1884 |
|
1874 |
$type ||= q{}; |
1885 |
$type ||= q{}; |
1875 |
|
1886 |
|
1876 |
if ( C4::Context->preference('finesMode') eq 'production' ) { |
1887 |
if ( $amount > 0 |
1877 |
if ( $amount > 0 ) { |
1888 |
&& C4::Context->preference('finesMode') eq 'production' ) |
1878 |
C4::Overdues::UpdateFine( $issue->{itemnumber}, |
1889 |
{ |
1879 |
$issue->{borrowernumber}, |
1890 |
C4::Overdues::UpdateFine( |
1880 |
$amount, $type, output_pref($datedue) ); |
1891 |
{ |
1881 |
} |
1892 |
itemnumber => $issue->{itemnumber}, |
1882 |
elsif ($return_date) { |
1893 |
borrowernumber => $issue->{borrowernumber}, |
1883 |
|
1894 |
amount => $amount, |
1884 |
# Backdated returns may have fines that shouldn't exist, |
1895 |
due => output_pref($datedue), |
1885 |
# so in this case, we need to drop those fines to 0 |
1896 |
issue_id => $issue->{issue_id} |
1886 |
|
1897 |
} |
1887 |
C4::Overdues::UpdateFine( $issue->{itemnumber}, |
1898 |
); |
1888 |
$issue->{borrowernumber}, |
1899 |
} |
1889 |
0, $type, output_pref($datedue) ); |
1900 |
elsif ($return_date) { |
1890 |
} |
1901 |
|
|
|
1902 |
# Backdated returns may have fines that shouldn't exist, |
1903 |
# so in this case, we need to drop those fines to 0 |
1904 |
C4::Overdues::UpdateFine( |
1905 |
{ |
1906 |
itemnumber => $issue->{itemnumber}, |
1907 |
borrowernumber => $issue->{borrowernumber}, |
1908 |
amount => 0, |
1909 |
due => output_pref($datedue), |
1910 |
issue_id => $issue->{issue_id} |
1911 |
} |
1912 |
); |
1891 |
} |
1913 |
} |
1892 |
} |
1914 |
} |
1893 |
|
1915 |
|
Lines 1938-1952
sub AddReturn {
Link Here
|
1938 |
$messages->{'WasLost'} = 1; |
1960 |
$messages->{'WasLost'} = 1; |
1939 |
|
1961 |
|
1940 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1962 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1941 |
_FixAccountForLostAndReturned($item->{'itemnumber'}, $borrowernumber, $barcode); # can tolerate undef $borrowernumber |
1963 |
_FixAccountForLostAndReturned( $item->{'itemnumber'} ); |
1942 |
$messages->{'LostItemFeeRefunded'} = 1; |
1964 |
$messages->{'LostItemFeeRefunded'} = 1; |
1943 |
} |
1965 |
} |
1944 |
} |
1966 |
} |
1945 |
|
1967 |
|
1946 |
# fix up the overdues in accounts... |
1968 |
# fix up the overdues in accounts... |
1947 |
if ($borrowernumber) { |
1969 |
if ($borrowernumber) { |
1948 |
my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox); |
1970 |
_FinalizeFine( |
1949 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!"; # zero is OK, check defined |
1971 |
{ |
|
|
1972 |
exempt_fine => $exemptfine, |
1973 |
dropbox => $dropbox, |
1974 |
issue => Koha::Database->new()->schema->resultset('OldIssue')->find( $issue->{issue_id} ), |
1975 |
} |
1976 |
); |
1950 |
|
1977 |
|
1951 |
if ( $issue->{overdue} && $issue->{date_due} ) { |
1978 |
if ( $issue->{overdue} && $issue->{date_due} ) { |
1952 |
# fix fine days |
1979 |
# fix fine days |
Lines 2060-2069
of the return. It is ignored when a dropbox_branch is passed in.
Link Here
|
2060 |
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2, |
2087 |
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2, |
2061 |
the old_issue is immediately anonymised |
2088 |
the old_issue is immediately anonymised |
2062 |
|
2089 |
|
2063 |
Ideally, this function would be internal to C<C4::Circulation>, |
|
|
2064 |
not exported, but it is currently needed by one |
2065 |
routine in C<C4::Accounts>. |
2066 |
|
2067 |
=cut |
2090 |
=cut |
2068 |
|
2091 |
|
2069 |
sub MarkIssueReturned { |
2092 |
sub MarkIssueReturned { |
Lines 2185-2339
sub _debar_user_on_return {
Link Here
|
2185 |
return; |
2208 |
return; |
2186 |
} |
2209 |
} |
2187 |
|
2210 |
|
2188 |
=head2 _FixOverduesOnReturn |
2211 |
=head2 _FinalizeFine |
2189 |
|
2212 |
|
2190 |
&_FixOverduesOnReturn($brn,$itm, $exemptfine, $dropboxmode); |
2213 |
_FinalizeFine({ |
2191 |
|
2214 |
exempt_fine => $exempt_fine, |
2192 |
C<$brn> borrowernumber |
2215 |
dropbox => $dropbox, |
2193 |
|
2216 |
issue => $issue, |
2194 |
C<$itm> itemnumber |
2217 |
}); |
2195 |
|
2218 |
|
2196 |
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. |
2219 |
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. |
2197 |
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue. |
2220 |
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue. |
|
|
2221 |
C<$issue> -- DBIx::Class::Row for the issue |
2198 |
|
2222 |
|
2199 |
Internal function, called only by AddReturn |
2223 |
This subrouting closes out the accuruing of a fine, and reduces if it exemptfine or |
|
|
2224 |
dropbox flags are passed in. |
2200 |
|
2225 |
|
2201 |
=cut |
2226 |
=cut |
2202 |
|
2227 |
|
2203 |
sub _FixOverduesOnReturn { |
2228 |
sub _FinalizeFine { |
2204 |
my ($borrowernumber, $item); |
2229 |
my ( $params ) = @_; |
2205 |
unless ($borrowernumber = shift) { |
2230 |
|
2206 |
warn "_FixOverduesOnReturn() not supplied valid borrowernumber"; |
2231 |
my $exemptfine = $params->{exempt_fine}; |
2207 |
return; |
2232 |
my $dropbox = $params->{dropbox}; |
2208 |
} |
2233 |
my $issue = $params->{issue}; |
2209 |
unless ($item = shift) { |
2234 |
|
2210 |
warn "_FixOverduesOnReturn() not supplied valid itemnumber"; |
|
|
2211 |
return; |
2212 |
} |
2213 |
my ($exemptfine, $dropbox) = @_; |
2214 |
my $dbh = C4::Context->dbh; |
2235 |
my $dbh = C4::Context->dbh; |
2215 |
|
2236 |
|
2216 |
# check for overdue fine |
2237 |
my $schema = Koha::Database->new()->schema; |
2217 |
my $sth = $dbh->prepare( |
2238 |
my $fine = $schema->resultset('AccountDebit')->single( |
2218 |
"SELECT * FROM accountlines WHERE (borrowernumber = ?) AND (itemnumber = ?) AND (accounttype='FU' OR accounttype='O')" |
2239 |
{ |
|
|
2240 |
issue_id => $issue->issue_id(), |
2241 |
type => Koha::Accounts::DebitTypes::Fine(), |
2242 |
accruing => 1, |
2243 |
} |
2219 |
); |
2244 |
); |
2220 |
$sth->execute( $borrowernumber, $item ); |
|
|
2221 |
|
2245 |
|
2222 |
# alter fine to show that the book has been returned |
2246 |
return unless ( $fine ); |
2223 |
my $data = $sth->fetchrow_hashref; |
2247 |
|
2224 |
return 0 unless $data; # no warning, there's just nothing to fix |
2248 |
$fine->accruing(0); |
2225 |
|
2249 |
|
2226 |
my $uquery; |
|
|
2227 |
my @bind = ($data->{'accountlines_id'}); |
2228 |
if ($exemptfine) { |
2250 |
if ($exemptfine) { |
2229 |
$uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0"; |
2251 |
AddCredit( |
2230 |
if (C4::Context->preference("FinesLog")) { |
2252 |
{ |
2231 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2253 |
borrower => $fine->borrowernumber(), |
2232 |
} |
2254 |
amount => $fine->amount_original(), |
2233 |
} elsif ($dropbox && $data->{lastincrement}) { |
2255 |
debit_id => $fine->debit_id(), |
2234 |
my $outstanding = $data->{amountoutstanding} - $data->{lastincrement} ; |
2256 |
type => Koha::Accounts::CreditTypes::Forgiven(), |
2235 |
my $amt = $data->{amount} - $data->{lastincrement} ; |
2257 |
} |
|
|
2258 |
); |
2236 |
if (C4::Context->preference("FinesLog")) { |
2259 |
if (C4::Context->preference("FinesLog")) { |
2237 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Dropbox adjustment $amt, item $item"); |
2260 |
&logaction( |
2238 |
} |
2261 |
"FINES", 'MODIFY', |
2239 |
$uquery = "update accountlines set accounttype='F' "; |
2262 |
$issue->{borrowernumber}, |
2240 |
if($outstanding >= 0 && $amt >=0) { |
2263 |
"Overdue forgiven: item " . $issue->{itemnumber} |
2241 |
$uquery .= ", amount = ? , amountoutstanding=? "; |
2264 |
); |
2242 |
unshift @bind, ($amt, $outstanding) ; |
|
|
2243 |
} |
2265 |
} |
2244 |
} else { |
2266 |
} elsif ($dropbox && $fine->amount_last_increment() != $fine->amount_original() ) { |
2245 |
$uquery = "update accountlines set accounttype='F' "; |
2267 |
if ( C4::Context->preference("FinesLog") ) { |
|
|
2268 |
&logaction( "FINES", 'MODIFY', $issue->{borrowernumber}, |
2269 |
"Dropbox adjustment " |
2270 |
. $fine->amount_last_increment() |
2271 |
. ", item " . $issue->{itemnumber} ); |
2272 |
} |
2273 |
$fine->amount_original( |
2274 |
$fine->amount_original() - $fine->amount_last_increment() ); |
2275 |
$fine->amount_outstanding( |
2276 |
$fine->amount_outstanding - $fine->amount_last_increment() ); |
2277 |
$schema->resultset('AccountOffset')->create( |
2278 |
{ |
2279 |
debit_id => $fine->debit_id(), |
2280 |
type => Koha::Accounts::OffsetTypes::Dropbox(), |
2281 |
amount => $fine->amount_last_increment() * -1, |
2282 |
} |
2283 |
); |
2246 |
} |
2284 |
} |
2247 |
$uquery .= " where (accountlines_id = ?)"; |
2285 |
|
2248 |
my $usth = $dbh->prepare($uquery); |
2286 |
return $fine->update(); |
2249 |
return $usth->execute(@bind); |
|
|
2250 |
} |
2287 |
} |
2251 |
|
2288 |
|
2252 |
=head2 _FixAccountForLostAndReturned |
2289 |
=head2 _FixAccountForLostAndReturned |
2253 |
|
2290 |
|
2254 |
&_FixAccountForLostAndReturned($itemnumber, [$borrowernumber, $barcode]); |
2291 |
&_FixAccountForLostAndReturned($itemnumber); |
2255 |
|
2292 |
|
2256 |
Calculates the charge for a book lost and returned. |
2293 |
Refunds a lost item fee in necessary |
2257 |
|
|
|
2258 |
Internal function, not exported, called only by AddReturn. |
2259 |
|
2260 |
FIXME: This function reflects how inscrutable fines logic is. Fix both. |
2261 |
FIXME: Give a positive return value on success. It might be the $borrowernumber who received credit, or the amount forgiven. |
2262 |
|
2294 |
|
2263 |
=cut |
2295 |
=cut |
2264 |
|
2296 |
|
2265 |
sub _FixAccountForLostAndReturned { |
2297 |
sub _FixAccountForLostAndReturned { |
2266 |
my $itemnumber = shift or return; |
2298 |
my ( $itemnumber ) = @_; |
2267 |
my $borrowernumber = @_ ? shift : undef; |
2299 |
|
2268 |
my $item_id = @_ ? shift : $itemnumber; # Send the barcode if you want that logged in the description |
2300 |
my $schema = Koha::Database->new()->schema; |
2269 |
my $dbh = C4::Context->dbh; |
2301 |
|
2270 |
# check for charge made for lost book |
2302 |
# Find the last issue for this item |
2271 |
my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE itemnumber = ? AND accounttype IN ('L', 'Rep', 'W') ORDER BY date DESC, accountno DESC"); |
2303 |
my $issue = |
2272 |
$sth->execute($itemnumber); |
2304 |
$schema->resultset('Issue')->single( { itemnumber => $itemnumber } ); |
2273 |
my $data = $sth->fetchrow_hashref; |
2305 |
$issue ||= |
2274 |
$data or return; # bail if there is nothing to do |
2306 |
$schema->resultset('OldIssue')->single( { itemnumber => $itemnumber } ); |
2275 |
$data->{accounttype} eq 'W' and return; # Written off |
2307 |
|
2276 |
|
2308 |
return unless $issue; |
2277 |
# writeoff this amount |
2309 |
|
2278 |
my $offset; |
2310 |
# Find a lost fee for this issue |
2279 |
my $amount = $data->{'amount'}; |
2311 |
my $debit = $schema->resultset('AccountDebit')->single( |
2280 |
my $acctno = $data->{'accountno'}; |
2312 |
{ |
2281 |
my $amountleft; # Starts off undef/zero. |
2313 |
issue_id => $issue->issue_id(), |
2282 |
if ($data->{'amountoutstanding'} == $amount) { |
2314 |
type => Koha::Accounts::DebitTypes::Lost() |
2283 |
$offset = $data->{'amount'}; |
2315 |
} |
2284 |
$amountleft = 0; # Hey, it's zero here, too. |
2316 |
); |
2285 |
} else { |
2317 |
|
2286 |
$offset = $amount - $data->{'amountoutstanding'}; # Um, isn't this the same as ZERO? We just tested those two things are == |
2318 |
return unless $debit; |
2287 |
$amountleft = $data->{'amountoutstanding'} - $amount; # Um, isn't this the same as ZERO? We just tested those two things are == |
2319 |
|
2288 |
} |
2320 |
# Check for an existing found credit for this debit, if there is one, the fee has already been refunded and we do nothing |
2289 |
my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0' |
2321 |
my @credits = $debit->account_offsets->search_related('credit', { 'credit.type' => Koha::Accounts::CreditTypes::Found() }); |
2290 |
WHERE (accountlines_id = ?)"); |
2322 |
|
2291 |
$usth->execute($data->{'accountlines_id'}); # We might be adjusting an account for some OTHER borrowernumber now. Not the one we passed in. |
2323 |
return if @credits; |
2292 |
#check if any credit is left if so writeoff other accounts |
2324 |
|
2293 |
my $nextaccntno = getnextacctno($data->{'borrowernumber'}); |
2325 |
# Ok, so we know we have an unrefunded lost item fee, let's refund it |
2294 |
$amountleft *= -1 if ($amountleft < 0); |
2326 |
CreditLostItem( |
2295 |
if ($amountleft > 0) { |
2327 |
{ |
2296 |
my $msth = $dbh->prepare("SELECT * FROM accountlines WHERE (borrowernumber = ?) |
2328 |
borrower => $issue->borrower(), |
2297 |
AND (amountoutstanding >0) ORDER BY date"); # might want to order by amountoustanding ASC (pay smallest first) |
2329 |
debit => $debit |
2298 |
$msth->execute($data->{'borrowernumber'}); |
2330 |
} |
2299 |
# offset transactions |
2331 |
); |
2300 |
my $newamtos; |
2332 |
|
2301 |
my $accdata; |
|
|
2302 |
while (($accdata=$msth->fetchrow_hashref) and ($amountleft>0)){ |
2303 |
if ($accdata->{'amountoutstanding'} < $amountleft) { |
2304 |
$newamtos = 0; |
2305 |
$amountleft -= $accdata->{'amountoutstanding'}; |
2306 |
} else { |
2307 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
2308 |
$amountleft = 0; |
2309 |
} |
2310 |
my $thisacct = $accdata->{'accountlines_id'}; |
2311 |
# FIXME: move prepares outside while loop! |
2312 |
my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ? |
2313 |
WHERE (accountlines_id = ?)"); |
2314 |
$usth->execute($newamtos,$thisacct); |
2315 |
$usth = $dbh->prepare("INSERT INTO accountoffsets |
2316 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
2317 |
VALUES |
2318 |
(?,?,?,?)"); |
2319 |
$usth->execute($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos); |
2320 |
} |
2321 |
} |
2322 |
$amountleft *= -1 if ($amountleft > 0); |
2323 |
my $desc = "Item Returned " . $item_id; |
2324 |
$usth = $dbh->prepare("INSERT INTO accountlines |
2325 |
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) |
2326 |
VALUES (?,?,now(),?,?,'CR',?)"); |
2327 |
$usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft); |
2328 |
if ($borrowernumber) { |
2329 |
# FIXME: same as query above. use 1 sth for both |
2330 |
$usth = $dbh->prepare("INSERT INTO accountoffsets |
2331 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
2332 |
VALUES (?,?,?,?)"); |
2333 |
$usth->execute($borrowernumber, $data->{'accountno'}, $nextaccntno, $offset); |
2334 |
} |
2335 |
ModItem({ paidfor => '' }, undef, $itemnumber); |
2333 |
ModItem({ paidfor => '' }, undef, $itemnumber); |
2336 |
return; |
|
|
2337 |
} |
2334 |
} |
2338 |
|
2335 |
|
2339 |
=head2 _GetCircControlBranch |
2336 |
=head2 _GetCircControlBranch |
Lines 2781-2794
sub AddRenewal {
Link Here
|
2781 |
my $dbh = C4::Context->dbh; |
2778 |
my $dbh = C4::Context->dbh; |
2782 |
|
2779 |
|
2783 |
# Find the issues record for this book |
2780 |
# Find the issues record for this book |
2784 |
my $sth = |
2781 |
my $issue = Koha::Database->new()->schema->resultset('Issue')->single({ itemnumber => $itemnumber }); |
2785 |
$dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?"); |
|
|
2786 |
$sth->execute( $itemnumber ); |
2787 |
my $issuedata = $sth->fetchrow_hashref; |
2788 |
|
2782 |
|
2789 |
return unless ( $issuedata ); |
2783 |
return unless ( $issue ); |
2790 |
|
2784 |
|
2791 |
$borrowernumber ||= $issuedata->{borrowernumber}; |
2785 |
$borrowernumber ||= $issue->get_column('borrowernumber'); |
2792 |
|
2786 |
|
2793 |
if ( defined $datedue && ref $datedue ne 'DateTime' ) { |
2787 |
if ( defined $datedue && ref $datedue ne 'DateTime' ) { |
2794 |
carp 'Invalid date passed to AddRenewal.'; |
2788 |
carp 'Invalid date passed to AddRenewal.'; |
Lines 2804-2844
sub AddRenewal {
Link Here
|
2804 |
my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
2798 |
my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
2805 |
|
2799 |
|
2806 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
2800 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
2807 |
dt_from_string( $issuedata->{date_due} ) : |
2801 |
dt_from_string( $issue->get_column('date_due') ) : |
2808 |
DateTime->now( time_zone => C4::Context->tz()); |
2802 |
DateTime->now( time_zone => C4::Context->tz()); |
2809 |
$datedue = CalcDateDue($datedue, $itemtype, $issuedata->{'branchcode'}, $borrower, 'is a renewal'); |
2803 |
$datedue = CalcDateDue($datedue, $itemtype, $issue->get_column('branchcode'), $borrower, 'is a renewal'); |
2810 |
} |
2804 |
} |
2811 |
|
2805 |
|
2812 |
# Update the issues record to have the new due date, and a new count |
2806 |
# Update the issues record to have the new due date, and a new count |
2813 |
# of how many times it has been renewed. |
2807 |
# of how many times it has been renewed. |
2814 |
my $renews = $issuedata->{'renewals'} + 1; |
2808 |
$issue->update( |
2815 |
$sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
2809 |
{ |
2816 |
WHERE borrowernumber=? |
2810 |
date_due => $datedue->strftime('%Y-%m-%d %H:%M'), |
2817 |
AND itemnumber=?" |
2811 |
renewals => $issue->renewals() + 1, |
|
|
2812 |
lastreneweddate => $lastreneweddate, |
2813 |
} |
2818 |
); |
2814 |
); |
2819 |
|
2815 |
|
2820 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
|
|
2821 |
|
2816 |
|
2822 |
# Update the renewal count on the item, and tell zebra to reindex |
2817 |
# Update the renewal count on the item, and tell zebra to reindex |
2823 |
$renews = $biblio->{'renewals'} + 1; |
2818 |
my $renews = $biblio->{'renewals'} + 1; |
2824 |
ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber); |
2819 |
ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber); |
2825 |
|
2820 |
|
2826 |
# Charge a new rental fee, if applicable? |
2821 |
# Charge a new rental fee, if applicable? |
2827 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
2822 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
2828 |
if ( $charge > 0 ) { |
2823 |
if ( $charge > 0 ) { |
2829 |
my $accountno = getnextacctno( $borrowernumber ); |
|
|
2830 |
my $item = GetBiblioFromItemNumber($itemnumber); |
2824 |
my $item = GetBiblioFromItemNumber($itemnumber); |
2831 |
my $manager_id = 0; |
2825 |
|
2832 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
2826 |
my $borrower = |
2833 |
$sth = $dbh->prepare( |
2827 |
Koha::Database->new()->schema->resultset('Borrower') |
2834 |
"INSERT INTO accountlines |
2828 |
->find($borrowernumber); |
2835 |
(date, borrowernumber, accountno, amount, manager_id, |
2829 |
|
2836 |
description,accounttype, amountoutstanding, itemnumber) |
2830 |
AddDebit( |
2837 |
VALUES (now(),?,?,?,?,?,?,?,?)" |
2831 |
{ |
|
|
2832 |
borrower => $borrower, |
2833 |
itemnumber => $itemnumber, |
2834 |
amount => $charge, |
2835 |
type => Koha::Accounts::DebitTypes::Rental(), |
2836 |
description => |
2837 |
"Renewal of Rental Item $item->{'title'} $item->{'barcode'}" |
2838 |
} |
2838 |
); |
2839 |
); |
2839 |
$sth->execute( $borrowernumber, $accountno, $charge, $manager_id, |
|
|
2840 |
"Renewal of Rental Item $item->{'title'} $item->{'barcode'}", |
2841 |
'Rent', $charge, $itemnumber ); |
2842 |
} |
2840 |
} |
2843 |
|
2841 |
|
2844 |
# Send a renewal slip according to checkout alert preferencei |
2842 |
# Send a renewal slip according to checkout alert preferencei |
Lines 2880-2885
sub AddRenewal {
Link Here
|
2880 |
borrowernumber => $borrowernumber, |
2878 |
borrowernumber => $borrowernumber, |
2881 |
ccode => $item->{'ccode'}} |
2879 |
ccode => $item->{'ccode'}} |
2882 |
); |
2880 |
); |
|
|
2881 |
|
2882 |
_FinalizeFine( { issue => $issue } ); |
2883 |
|
2883 |
return $datedue; |
2884 |
return $datedue; |
2884 |
} |
2885 |
} |
2885 |
|
2886 |
|
Lines 3064-3088
sub _get_discount_from_rule {
Link Here
|
3064 |
|
3065 |
|
3065 |
=head2 AddIssuingCharge |
3066 |
=head2 AddIssuingCharge |
3066 |
|
3067 |
|
3067 |
&AddIssuingCharge( $itemno, $borrowernumber, $charge ) |
3068 |
&AddIssuingCharge( $itemnumber, $borrowernumber, $amount ) |
3068 |
|
3069 |
|
3069 |
=cut |
3070 |
=cut |
3070 |
|
3071 |
|
3071 |
sub AddIssuingCharge { |
3072 |
sub AddIssuingCharge { |
3072 |
my ( $itemnumber, $borrowernumber, $charge ) = @_; |
3073 |
my ( $itemnumber, $borrowernumber, $amount ) = @_; |
3073 |
my $dbh = C4::Context->dbh; |
3074 |
|
3074 |
my $nextaccntno = getnextacctno( $borrowernumber ); |
3075 |
return AddDebit( |
3075 |
my $manager_id = 0; |
3076 |
{ |
3076 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
3077 |
borrower => Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber), |
3077 |
my $query =" |
3078 |
itemnumber => $itemnumber, |
3078 |
INSERT INTO accountlines |
3079 |
amount => $amount, |
3079 |
(borrowernumber, itemnumber, accountno, |
3080 |
type => Koha::Accounts::DebitTypes::Rental(), |
3080 |
date, amount, description, accounttype, |
3081 |
} |
3081 |
amountoutstanding, manager_id) |
3082 |
); |
3082 |
VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?) |
|
|
3083 |
"; |
3084 |
my $sth = $dbh->prepare($query); |
3085 |
$sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id ); |
3086 |
} |
3083 |
} |
3087 |
|
3084 |
|
3088 |
=head2 GetTransfers |
3085 |
=head2 GetTransfers |
Lines 3601-3630
sub ReturnLostItem{
Link Here
|
3601 |
sub LostItem{ |
3598 |
sub LostItem{ |
3602 |
my ($itemnumber, $mark_returned) = @_; |
3599 |
my ($itemnumber, $mark_returned) = @_; |
3603 |
|
3600 |
|
3604 |
my $dbh = C4::Context->dbh(); |
3601 |
my $schema = Koha::Database->new()->schema; |
3605 |
my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title |
|
|
3606 |
FROM issues |
3607 |
JOIN items USING (itemnumber) |
3608 |
JOIN biblio USING (biblionumber) |
3609 |
WHERE issues.itemnumber=?"); |
3610 |
$sth->execute($itemnumber); |
3611 |
my $issues=$sth->fetchrow_hashref(); |
3612 |
|
3602 |
|
3613 |
# If a borrower lost the item, add a replacement cost to the their record |
3603 |
my $issue = |
3614 |
if ( my $borrowernumber = $issues->{borrowernumber} ){ |
3604 |
$schema->resultset('Issue')->single( { itemnumber => $itemnumber } ); |
3615 |
my $borrower = C4::Members::GetMemberDetails( $borrowernumber ); |
3605 |
|
|
|
3606 |
my ( $borrower, $item ); |
3616 |
|
3607 |
|
|
|
3608 |
if ( $issue ) { |
3609 |
$borrower = $issue->borrower(); |
3610 |
$item = $issue->item(); |
3611 |
} |
3612 |
|
3613 |
# If a borrower lost the item, add a replacement cost to the their record |
3614 |
if ( $borrower ){ |
3617 |
if (C4::Context->preference('WhenLostForgiveFine')){ |
3615 |
if (C4::Context->preference('WhenLostForgiveFine')){ |
3618 |
my $fix = _FixOverduesOnReturn($borrowernumber, $itemnumber, 1, 0); # 1, 0 = exemptfine, no-dropbox |
3616 |
_FinalizeFine( |
3619 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!"; # zero is OK, check defined |
3617 |
{ |
|
|
3618 |
exempt_fine => 1, |
3619 |
dropbox => 0, |
3620 |
issue => $issue, |
3621 |
} |
3622 |
); |
3620 |
} |
3623 |
} |
3621 |
if (C4::Context->preference('WhenLostChargeReplacementFee')){ |
3624 |
if ( C4::Context->preference('WhenLostChargeReplacementFee') ) { |
3622 |
C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}"); |
3625 |
DebitLostItem( { borrower => $borrower, issue => $issue } ); |
3623 |
#FIXME : Should probably have a way to distinguish this from an item that really was returned. |
|
|
3624 |
#warn " $issues->{'borrowernumber'} / $itemnumber "; |
3625 |
} |
3626 |
} |
3626 |
|
3627 |
|
3627 |
MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$borrower->{'privacy'}) if $mark_returned; |
3628 |
MarkIssueReturned( $borrower->borrowernumber(), $item->itemnumber(), undef, undef, $borrower->privacy() ) if $mark_returned; |
3628 |
} |
3629 |
} |
3629 |
} |
3630 |
} |
3630 |
|
3631 |
|
Lines 3742-3751
sub ProcessOfflineIssue {
Link Here
|
3742 |
sub ProcessOfflinePayment { |
3743 |
sub ProcessOfflinePayment { |
3743 |
my $operation = shift; |
3744 |
my $operation = shift; |
3744 |
|
3745 |
|
3745 |
my $borrower = C4::Members::GetMemberDetails( undef, $operation->{cardnumber} ); # Get borrower from operation cardnumber |
3746 |
AddCredit( |
3746 |
my $amount = $operation->{amount}; |
3747 |
{ |
3747 |
|
3748 |
borrower => Koha::Database->new()->schema->resultset('Borrower') |
3748 |
recordpayment( $borrower->{borrowernumber}, $amount ); |
3749 |
->single( { cardnumber => $operation->{cardnumber} } ), |
|
|
3750 |
amount => $operation->{amount}, |
3751 |
notes => 'via offline circulation', |
3752 |
type => Koha::Accounts::CreditTypes::Payment, |
3753 |
} |
3754 |
); |
3749 |
|
3755 |
|
3750 |
return "Success." |
3756 |
return "Success." |
3751 |
} |
3757 |
} |