|
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 |
_FinalizeFine( |
| 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 => Koha::Database->new()->schema->resultset('OldIssue')->find( $issue->{issue_id} ), |
| 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 2151-2305
sub _debar_user_on_return {
Link Here
|
| 2151 |
return; |
2165 |
return; |
| 2152 |
} |
2166 |
} |
| 2153 |
|
2167 |
|
| 2154 |
=head2 _FixOverduesOnReturn |
2168 |
=head2 _FinalizeFine |
| 2155 |
|
|
|
| 2156 |
&_FixOverduesOnReturn($brn,$itm, $exemptfine, $dropboxmode); |
| 2157 |
|
| 2158 |
C<$brn> borrowernumber |
| 2159 |
|
2169 |
|
| 2160 |
C<$itm> itemnumber |
2170 |
_FinalizeFine({ |
|
|
2171 |
exempt_fine => $exempt_fine, |
| 2172 |
dropbox => $dropbox, |
| 2173 |
issue => $issue, |
| 2174 |
}); |
| 2161 |
|
2175 |
|
| 2162 |
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. |
2176 |
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. |
| 2163 |
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue. |
2177 |
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue. |
|
|
2178 |
C<$issue> -- DBIx::Class::Row for the issue |
| 2164 |
|
2179 |
|
| 2165 |
Internal function, called only by AddReturn |
2180 |
This subrouting closes out the accuruing of a fine, and reduces if it exemptfine or |
|
|
2181 |
dropbox flags are passed in. |
| 2166 |
|
2182 |
|
| 2167 |
=cut |
2183 |
=cut |
| 2168 |
|
2184 |
|
| 2169 |
sub _FixOverduesOnReturn { |
2185 |
sub _FinalizeFine { |
| 2170 |
my ($borrowernumber, $item); |
2186 |
my ( $params ) = @_; |
| 2171 |
unless ($borrowernumber = shift) { |
2187 |
|
| 2172 |
warn "_FixOverduesOnReturn() not supplied valid borrowernumber"; |
2188 |
my $exemptfine = $params->{exempt_fine}; |
| 2173 |
return; |
2189 |
my $dropbox = $params->{dropbox}; |
| 2174 |
} |
2190 |
my $issue = $params->{issue}; |
| 2175 |
unless ($item = shift) { |
2191 |
|
| 2176 |
warn "_FixOverduesOnReturn() not supplied valid itemnumber"; |
|
|
| 2177 |
return; |
| 2178 |
} |
| 2179 |
my ($exemptfine, $dropbox) = @_; |
| 2180 |
my $dbh = C4::Context->dbh; |
2192 |
my $dbh = C4::Context->dbh; |
| 2181 |
|
2193 |
|
| 2182 |
# check for overdue fine |
2194 |
my $schema = Koha::Database->new()->schema; |
| 2183 |
my $sth = $dbh->prepare( |
2195 |
my $fine = $schema->resultset('AccountDebit')->single( |
| 2184 |
"SELECT * FROM accountlines WHERE (borrowernumber = ?) AND (itemnumber = ?) AND (accounttype='FU' OR accounttype='O')" |
2196 |
{ |
|
|
2197 |
issue_id => $issue->issue_id(), |
| 2198 |
type => Koha::Accounts::DebitTypes::Fine(), |
| 2199 |
accruing => 1, |
| 2200 |
} |
| 2185 |
); |
2201 |
); |
| 2186 |
$sth->execute( $borrowernumber, $item ); |
|
|
| 2187 |
|
2202 |
|
| 2188 |
# alter fine to show that the book has been returned |
2203 |
return unless ( $fine ); |
| 2189 |
my $data = $sth->fetchrow_hashref; |
2204 |
|
| 2190 |
return 0 unless $data; # no warning, there's just nothing to fix |
2205 |
$fine->accruing(0); |
| 2191 |
|
2206 |
|
| 2192 |
my $uquery; |
|
|
| 2193 |
my @bind = ($data->{'accountlines_id'}); |
| 2194 |
if ($exemptfine) { |
2207 |
if ($exemptfine) { |
| 2195 |
$uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0"; |
2208 |
AddCredit( |
| 2196 |
if (C4::Context->preference("FinesLog")) { |
2209 |
{ |
| 2197 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2210 |
borrower => $fine->borrowernumber(), |
| 2198 |
} |
2211 |
amount => $fine->amount_original(), |
| 2199 |
} elsif ($dropbox && $data->{lastincrement}) { |
2212 |
debit_id => $fine->debit_id(), |
| 2200 |
my $outstanding = $data->{amountoutstanding} - $data->{lastincrement} ; |
2213 |
type => Koha::Accounts::CreditTypes::Forgiven(), |
| 2201 |
my $amt = $data->{amount} - $data->{lastincrement} ; |
2214 |
} |
|
|
2215 |
); |
| 2202 |
if (C4::Context->preference("FinesLog")) { |
2216 |
if (C4::Context->preference("FinesLog")) { |
| 2203 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Dropbox adjustment $amt, item $item"); |
2217 |
&logaction( |
| 2204 |
} |
2218 |
"FINES", 'MODIFY', |
| 2205 |
$uquery = "update accountlines set accounttype='F' "; |
2219 |
$issue->{borrowernumber}, |
| 2206 |
if($outstanding >= 0 && $amt >=0) { |
2220 |
"Overdue forgiven: item " . $issue->{itemnumber} |
| 2207 |
$uquery .= ", amount = ? , amountoutstanding=? "; |
2221 |
); |
| 2208 |
unshift @bind, ($amt, $outstanding) ; |
|
|
| 2209 |
} |
2222 |
} |
| 2210 |
} else { |
2223 |
} elsif ($dropbox && $fine->amount_last_increment() != $fine->amount_original() ) { |
| 2211 |
$uquery = "update accountlines set accounttype='F' "; |
2224 |
if ( C4::Context->preference("FinesLog") ) { |
|
|
2225 |
&logaction( "FINES", 'MODIFY', $issue->{borrowernumber}, |
| 2226 |
"Dropbox adjustment " |
| 2227 |
. $fine->amount_last_increment() |
| 2228 |
. ", item " . $issue->{itemnumber} ); |
| 2229 |
} |
| 2230 |
$fine->amount_original( |
| 2231 |
$fine->amount_original() - $fine->amount_last_increment() ); |
| 2232 |
$fine->amount_outstanding( |
| 2233 |
$fine->amount_outstanding - $fine->amount_last_increment() ); |
| 2234 |
$schema->resultset('AccountOffset')->create( |
| 2235 |
{ |
| 2236 |
debit_id => $fine->debit_id(), |
| 2237 |
type => Koha::Accounts::OffsetTypes::Dropbox(), |
| 2238 |
amount => $fine->amount_last_increment() * -1, |
| 2239 |
} |
| 2240 |
); |
| 2212 |
} |
2241 |
} |
| 2213 |
$uquery .= " where (accountlines_id = ?)"; |
2242 |
|
| 2214 |
my $usth = $dbh->prepare($uquery); |
2243 |
return $fine->update(); |
| 2215 |
return $usth->execute(@bind); |
|
|
| 2216 |
} |
2244 |
} |
| 2217 |
|
2245 |
|
| 2218 |
=head2 _FixAccountForLostAndReturned |
2246 |
=head2 _FixAccountForLostAndReturned |
| 2219 |
|
2247 |
|
| 2220 |
&_FixAccountForLostAndReturned($itemnumber, [$borrowernumber, $barcode]); |
2248 |
&_FixAccountForLostAndReturned($itemnumber); |
| 2221 |
|
|
|
| 2222 |
Calculates the charge for a book lost and returned. |
| 2223 |
|
| 2224 |
Internal function, not exported, called only by AddReturn. |
| 2225 |
|
2249 |
|
| 2226 |
FIXME: This function reflects how inscrutable fines logic is. Fix both. |
2250 |
Refunds a lost item fee in necessary |
| 2227 |
FIXME: Give a positive return value on success. It might be the $borrowernumber who received credit, or the amount forgiven. |
|
|
| 2228 |
|
2251 |
|
| 2229 |
=cut |
2252 |
=cut |
| 2230 |
|
2253 |
|
| 2231 |
sub _FixAccountForLostAndReturned { |
2254 |
sub _FixAccountForLostAndReturned { |
| 2232 |
my $itemnumber = shift or return; |
2255 |
my ( $itemnumber ) = @_; |
| 2233 |
my $borrowernumber = @_ ? shift : undef; |
2256 |
|
| 2234 |
my $item_id = @_ ? shift : $itemnumber; # Send the barcode if you want that logged in the description |
2257 |
my $schema = Koha::Database->new()->schema; |
| 2235 |
my $dbh = C4::Context->dbh; |
2258 |
|
| 2236 |
# check for charge made for lost book |
2259 |
# Find the last issue for this item |
| 2237 |
my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE itemnumber = ? AND accounttype IN ('L', 'Rep', 'W') ORDER BY date DESC, accountno DESC"); |
2260 |
my $issue = |
| 2238 |
$sth->execute($itemnumber); |
2261 |
$schema->resultset('Issue')->single( { itemnumber => $itemnumber } ); |
| 2239 |
my $data = $sth->fetchrow_hashref; |
2262 |
$issue ||= |
| 2240 |
$data or return; # bail if there is nothing to do |
2263 |
$schema->resultset('OldIssue')->single( { itemnumber => $itemnumber } ); |
| 2241 |
$data->{accounttype} eq 'W' and return; # Written off |
2264 |
|
| 2242 |
|
2265 |
return unless $issue; |
| 2243 |
# writeoff this amount |
2266 |
|
| 2244 |
my $offset; |
2267 |
# Find a lost fee for this issue |
| 2245 |
my $amount = $data->{'amount'}; |
2268 |
my $debit = $schema->resultset('AccountDebit')->single( |
| 2246 |
my $acctno = $data->{'accountno'}; |
2269 |
{ |
| 2247 |
my $amountleft; # Starts off undef/zero. |
2270 |
issue_id => $issue->issue_id(), |
| 2248 |
if ($data->{'amountoutstanding'} == $amount) { |
2271 |
type => Koha::Accounts::DebitTypes::Lost() |
| 2249 |
$offset = $data->{'amount'}; |
2272 |
} |
| 2250 |
$amountleft = 0; # Hey, it's zero here, too. |
2273 |
); |
| 2251 |
} else { |
2274 |
|
| 2252 |
$offset = $amount - $data->{'amountoutstanding'}; # Um, isn't this the same as ZERO? We just tested those two things are == |
2275 |
return unless $debit; |
| 2253 |
$amountleft = $data->{'amountoutstanding'} - $amount; # Um, isn't this the same as ZERO? We just tested those two things are == |
2276 |
|
| 2254 |
} |
2277 |
# Check for an existing found credit for this debit, if there is one, the fee has already been refunded and we do nothing |
| 2255 |
my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0' |
2278 |
my @credits = $debit->account_offsets->search_related('credit', { 'credit.type' => Koha::Accounts::CreditTypes::Found() }); |
| 2256 |
WHERE (accountlines_id = ?)"); |
2279 |
|
| 2257 |
$usth->execute($data->{'accountlines_id'}); # We might be adjusting an account for some OTHER borrowernumber now. Not the one we passed in. |
2280 |
return if @credits; |
| 2258 |
#check if any credit is left if so writeoff other accounts |
2281 |
|
| 2259 |
my $nextaccntno = getnextacctno($data->{'borrowernumber'}); |
2282 |
# Ok, so we know we have an unrefunded lost item fee, let's refund it |
| 2260 |
$amountleft *= -1 if ($amountleft < 0); |
2283 |
CreditLostItem( |
| 2261 |
if ($amountleft > 0) { |
2284 |
{ |
| 2262 |
my $msth = $dbh->prepare("SELECT * FROM accountlines WHERE (borrowernumber = ?) |
2285 |
borrower => $issue->borrower(), |
| 2263 |
AND (amountoutstanding >0) ORDER BY date"); # might want to order by amountoustanding ASC (pay smallest first) |
2286 |
debit => $debit |
| 2264 |
$msth->execute($data->{'borrowernumber'}); |
2287 |
} |
| 2265 |
# offset transactions |
2288 |
); |
| 2266 |
my $newamtos; |
2289 |
|
| 2267 |
my $accdata; |
|
|
| 2268 |
while (($accdata=$msth->fetchrow_hashref) and ($amountleft>0)){ |
| 2269 |
if ($accdata->{'amountoutstanding'} < $amountleft) { |
| 2270 |
$newamtos = 0; |
| 2271 |
$amountleft -= $accdata->{'amountoutstanding'}; |
| 2272 |
} else { |
| 2273 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 2274 |
$amountleft = 0; |
| 2275 |
} |
| 2276 |
my $thisacct = $accdata->{'accountlines_id'}; |
| 2277 |
# FIXME: move prepares outside while loop! |
| 2278 |
my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ? |
| 2279 |
WHERE (accountlines_id = ?)"); |
| 2280 |
$usth->execute($newamtos,$thisacct); |
| 2281 |
$usth = $dbh->prepare("INSERT INTO accountoffsets |
| 2282 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
| 2283 |
VALUES |
| 2284 |
(?,?,?,?)"); |
| 2285 |
$usth->execute($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos); |
| 2286 |
} |
| 2287 |
} |
| 2288 |
$amountleft *= -1 if ($amountleft > 0); |
| 2289 |
my $desc = "Item Returned " . $item_id; |
| 2290 |
$usth = $dbh->prepare("INSERT INTO accountlines |
| 2291 |
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) |
| 2292 |
VALUES (?,?,now(),?,?,'CR',?)"); |
| 2293 |
$usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft); |
| 2294 |
if ($borrowernumber) { |
| 2295 |
# FIXME: same as query above. use 1 sth for both |
| 2296 |
$usth = $dbh->prepare("INSERT INTO accountoffsets |
| 2297 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
| 2298 |
VALUES (?,?,?,?)"); |
| 2299 |
$usth->execute($borrowernumber, $data->{'accountno'}, $nextaccntno, $offset); |
| 2300 |
} |
| 2301 |
ModItem({ paidfor => '' }, undef, $itemnumber); |
2290 |
ModItem({ paidfor => '' }, undef, $itemnumber); |
| 2302 |
return; |
|
|
| 2303 |
} |
2291 |
} |
| 2304 |
|
2292 |
|
| 2305 |
=head2 _GetCircControlBranch |
2293 |
=head2 _GetCircControlBranch |
|
Lines 2698-2711
sub AddRenewal {
Link Here
|
| 2698 |
my $dbh = C4::Context->dbh; |
2686 |
my $dbh = C4::Context->dbh; |
| 2699 |
|
2687 |
|
| 2700 |
# Find the issues record for this book |
2688 |
# Find the issues record for this book |
| 2701 |
my $sth = |
2689 |
my $issue = Koha::Database->new()->schema->resultset('Issue')->single({ itemnumber => $itemnumber }); |
| 2702 |
$dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?"); |
|
|
| 2703 |
$sth->execute( $itemnumber ); |
| 2704 |
my $issuedata = $sth->fetchrow_hashref; |
| 2705 |
|
2690 |
|
| 2706 |
return unless ( $issuedata ); |
2691 |
return unless ( $issue ); |
| 2707 |
|
2692 |
|
| 2708 |
$borrowernumber ||= $issuedata->{borrowernumber}; |
2693 |
$borrowernumber ||= $issue->get_column('borrowernumber'); |
| 2709 |
|
2694 |
|
| 2710 |
if ( defined $datedue && ref $datedue ne 'DateTime' ) { |
2695 |
if ( defined $datedue && ref $datedue ne 'DateTime' ) { |
| 2711 |
carp 'Invalid date passed to AddRenewal.'; |
2696 |
carp 'Invalid date passed to AddRenewal.'; |
|
Lines 2721-2761
sub AddRenewal {
Link Here
|
| 2721 |
my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
2706 |
my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
| 2722 |
|
2707 |
|
| 2723 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
2708 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
| 2724 |
dt_from_string( $issuedata->{date_due} ) : |
2709 |
dt_from_string( $issue->get_column('date_due') ) : |
| 2725 |
DateTime->now( time_zone => C4::Context->tz()); |
2710 |
DateTime->now( time_zone => C4::Context->tz()); |
| 2726 |
$datedue = CalcDateDue($datedue, $itemtype, $issuedata->{'branchcode'}, $borrower, 'is a renewal'); |
2711 |
$datedue = CalcDateDue($datedue, $itemtype, $issue->get_column('branchcode'), $borrower, 'is a renewal'); |
| 2727 |
} |
2712 |
} |
| 2728 |
|
2713 |
|
| 2729 |
# Update the issues record to have the new due date, and a new count |
2714 |
# Update the issues record to have the new due date, and a new count |
| 2730 |
# of how many times it has been renewed. |
2715 |
# of how many times it has been renewed. |
| 2731 |
my $renews = $issuedata->{'renewals'} + 1; |
2716 |
$issue->update( |
| 2732 |
$sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
2717 |
{ |
| 2733 |
WHERE borrowernumber=? |
2718 |
date_due => $datedue->strftime('%Y-%m-%d %H:%M'), |
| 2734 |
AND itemnumber=?" |
2719 |
renewals => $issue->renewals() + 1, |
|
|
2720 |
lastreneweddate => $lastreneweddate, |
| 2721 |
} |
| 2735 |
); |
2722 |
); |
| 2736 |
|
2723 |
|
| 2737 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
|
|
| 2738 |
|
2724 |
|
| 2739 |
# Update the renewal count on the item, and tell zebra to reindex |
2725 |
# Update the renewal count on the item, and tell zebra to reindex |
| 2740 |
$renews = $biblio->{'renewals'} + 1; |
2726 |
my $renews = $biblio->{'renewals'} + 1; |
| 2741 |
ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber); |
2727 |
ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber); |
| 2742 |
|
2728 |
|
| 2743 |
# Charge a new rental fee, if applicable? |
2729 |
# Charge a new rental fee, if applicable? |
| 2744 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
2730 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
| 2745 |
if ( $charge > 0 ) { |
2731 |
if ( $charge > 0 ) { |
| 2746 |
my $accountno = getnextacctno( $borrowernumber ); |
|
|
| 2747 |
my $item = GetBiblioFromItemNumber($itemnumber); |
2732 |
my $item = GetBiblioFromItemNumber($itemnumber); |
| 2748 |
my $manager_id = 0; |
2733 |
|
| 2749 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
2734 |
my $borrower = |
| 2750 |
$sth = $dbh->prepare( |
2735 |
Koha::Database->new()->schema->resultset('Borrower') |
| 2751 |
"INSERT INTO accountlines |
2736 |
->find($borrowernumber); |
| 2752 |
(date, borrowernumber, accountno, amount, manager_id, |
2737 |
|
| 2753 |
description,accounttype, amountoutstanding, itemnumber) |
2738 |
AddDebit( |
| 2754 |
VALUES (now(),?,?,?,?,?,?,?,?)" |
2739 |
{ |
|
|
2740 |
borrower => $borrower, |
| 2741 |
itemnumber => $itemnumber, |
| 2742 |
amount => $charge, |
| 2743 |
type => Koha::Accounts::DebitTypes::Rental(), |
| 2744 |
description => |
| 2745 |
"Renewal of Rental Item $item->{'title'} $item->{'barcode'}" |
| 2746 |
} |
| 2755 |
); |
2747 |
); |
| 2756 |
$sth->execute( $borrowernumber, $accountno, $charge, $manager_id, |
|
|
| 2757 |
"Renewal of Rental Item $item->{'title'} $item->{'barcode'}", |
| 2758 |
'Rent', $charge, $itemnumber ); |
| 2759 |
} |
2748 |
} |
| 2760 |
|
2749 |
|
| 2761 |
# Send a renewal slip according to checkout alert preferencei |
2750 |
# Send a renewal slip according to checkout alert preferencei |
|
Lines 2797-2802
sub AddRenewal {
Link Here
|
| 2797 |
borrowernumber => $borrowernumber, |
2786 |
borrowernumber => $borrowernumber, |
| 2798 |
ccode => $item->{'ccode'}} |
2787 |
ccode => $item->{'ccode'}} |
| 2799 |
); |
2788 |
); |
|
|
2789 |
|
| 2790 |
_FinalizeFine( { issue => $issue } ); |
| 2791 |
|
| 2800 |
return $datedue; |
2792 |
return $datedue; |
| 2801 |
} |
2793 |
} |
| 2802 |
|
2794 |
|
|
Lines 2981-3005
sub _get_discount_from_rule {
Link Here
|
| 2981 |
|
2973 |
|
| 2982 |
=head2 AddIssuingCharge |
2974 |
=head2 AddIssuingCharge |
| 2983 |
|
2975 |
|
| 2984 |
&AddIssuingCharge( $itemno, $borrowernumber, $charge ) |
2976 |
&AddIssuingCharge( $itemnumber, $borrowernumber, $amount ) |
| 2985 |
|
2977 |
|
| 2986 |
=cut |
2978 |
=cut |
| 2987 |
|
2979 |
|
| 2988 |
sub AddIssuingCharge { |
2980 |
sub AddIssuingCharge { |
| 2989 |
my ( $itemnumber, $borrowernumber, $charge ) = @_; |
2981 |
my ( $itemnumber, $borrowernumber, $amount ) = @_; |
| 2990 |
my $dbh = C4::Context->dbh; |
2982 |
|
| 2991 |
my $nextaccntno = getnextacctno( $borrowernumber ); |
2983 |
return AddDebit( |
| 2992 |
my $manager_id = 0; |
2984 |
{ |
| 2993 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
2985 |
borrower => Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber), |
| 2994 |
my $query =" |
2986 |
itemnumber => $itemnumber, |
| 2995 |
INSERT INTO accountlines |
2987 |
amount => $amount, |
| 2996 |
(borrowernumber, itemnumber, accountno, |
2988 |
type => Koha::Accounts::DebitTypes::Rental(), |
| 2997 |
date, amount, description, accounttype, |
2989 |
} |
| 2998 |
amountoutstanding, manager_id) |
2990 |
); |
| 2999 |
VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?) |
|
|
| 3000 |
"; |
| 3001 |
my $sth = $dbh->prepare($query); |
| 3002 |
$sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id ); |
| 3003 |
} |
2991 |
} |
| 3004 |
|
2992 |
|
| 3005 |
=head2 GetTransfers |
2993 |
=head2 GetTransfers |
|
Lines 3518-3547
sub ReturnLostItem{
Link Here
|
| 3518 |
sub LostItem{ |
3506 |
sub LostItem{ |
| 3519 |
my ($itemnumber, $mark_returned) = @_; |
3507 |
my ($itemnumber, $mark_returned) = @_; |
| 3520 |
|
3508 |
|
| 3521 |
my $dbh = C4::Context->dbh(); |
3509 |
my $schema = Koha::Database->new()->schema; |
| 3522 |
my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title |
|
|
| 3523 |
FROM issues |
| 3524 |
JOIN items USING (itemnumber) |
| 3525 |
JOIN biblio USING (biblionumber) |
| 3526 |
WHERE issues.itemnumber=?"); |
| 3527 |
$sth->execute($itemnumber); |
| 3528 |
my $issues=$sth->fetchrow_hashref(); |
| 3529 |
|
3510 |
|
| 3530 |
# If a borrower lost the item, add a replacement cost to the their record |
3511 |
my $issue = |
| 3531 |
if ( my $borrowernumber = $issues->{borrowernumber} ){ |
3512 |
$schema->resultset('Issue')->single( { itemnumber => $itemnumber } ); |
| 3532 |
my $borrower = C4::Members::GetMemberDetails( $borrowernumber ); |
|
|
| 3533 |
|
3513 |
|
|
|
3514 |
my ( $borrower, $item ); |
| 3515 |
|
| 3516 |
if ( $issue ) { |
| 3517 |
$borrower = $issue->borrower(); |
| 3518 |
$item = $issue->item(); |
| 3519 |
} |
| 3520 |
|
| 3521 |
# If a borrower lost the item, add a replacement cost to the their record |
| 3522 |
if ( $borrower ){ |
| 3534 |
if (C4::Context->preference('WhenLostForgiveFine')){ |
3523 |
if (C4::Context->preference('WhenLostForgiveFine')){ |
| 3535 |
my $fix = _FixOverduesOnReturn($borrowernumber, $itemnumber, 1, 0); # 1, 0 = exemptfine, no-dropbox |
3524 |
_FinalizeFine( |
| 3536 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!"; # zero is OK, check defined |
3525 |
{ |
|
|
3526 |
exempt_fine => 1, |
| 3527 |
dropbox => 0, |
| 3528 |
issue => $issue, |
| 3529 |
} |
| 3530 |
); |
| 3537 |
} |
3531 |
} |
| 3538 |
if (C4::Context->preference('WhenLostChargeReplacementFee')){ |
3532 |
if ( C4::Context->preference('WhenLostChargeReplacementFee') ) { |
| 3539 |
C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}"); |
3533 |
DebitLostItem( { borrower => $borrower, issue => $issue } ); |
| 3540 |
#FIXME : Should probably have a way to distinguish this from an item that really was returned. |
|
|
| 3541 |
#warn " $issues->{'borrowernumber'} / $itemnumber "; |
| 3542 |
} |
3534 |
} |
| 3543 |
|
3535 |
|
| 3544 |
MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$borrower->{'privacy'}) if $mark_returned; |
3536 |
MarkIssueReturned( $borrower->borrowernumber(), $item->itemnumber(), undef, undef, $borrower->privacy() ) if $mark_returned; |
| 3545 |
} |
3537 |
} |
| 3546 |
} |
3538 |
} |
| 3547 |
|
3539 |
|
|
Lines 3659-3668
sub ProcessOfflineIssue {
Link Here
|
| 3659 |
sub ProcessOfflinePayment { |
3651 |
sub ProcessOfflinePayment { |
| 3660 |
my $operation = shift; |
3652 |
my $operation = shift; |
| 3661 |
|
3653 |
|
| 3662 |
my $borrower = C4::Members::GetMemberDetails( undef, $operation->{cardnumber} ); # Get borrower from operation cardnumber |
3654 |
AddCredit( |
| 3663 |
my $amount = $operation->{amount}; |
3655 |
{ |
| 3664 |
|
3656 |
borrower => Koha::Database->new()->schema->resultset('Borrower') |
| 3665 |
recordpayment( $borrower->{borrowernumber}, $amount ); |
3657 |
->single( { cardnumber => $operation->{cardnumber} } ), |
|
|
3658 |
amount => $operation->{amount}, |
| 3659 |
notes => 'via offline circulation', |
| 3660 |
type => Koha::Accounts::CreditTypes::Payment, |
| 3661 |
} |
| 3662 |
); |
| 3666 |
|
3663 |
|
| 3667 |
return "Success." |
3664 |
return "Success." |
| 3668 |
} |
3665 |
} |