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 1292-1298
sub AddIssue {
Link Here
|
1292 |
## If item was lost, it has now been found, reverse any list item charges if neccessary. |
1294 |
## If item was lost, it has now been found, reverse any list item charges if neccessary. |
1293 |
if ( $item->{'itemlost'} ) { |
1295 |
if ( $item->{'itemlost'} ) { |
1294 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1296 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1295 |
_FixAccountForLostAndReturned( $item->{'itemnumber'}, undef, $item->{'barcode'} ); |
1297 |
_FixAccountForLostAndReturned( $item->{'itemnumber'} ); |
1296 |
} |
1298 |
} |
1297 |
} |
1299 |
} |
1298 |
|
1300 |
|
Lines 1839-1845
sub AddReturn {
Link Here
|
1839 |
} |
1841 |
} |
1840 |
|
1842 |
|
1841 |
if ($borrowernumber) { |
1843 |
if ($borrowernumber) { |
1842 |
if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) { |
1844 |
if ( |
|
|
1845 |
( !$item->{itemlost} ) # skip lost items |
1846 |
&& ( |
1847 |
( |
1848 |
C4::Context->preference('CalculateFinesOnReturn') |
1849 |
&& $issue->{'overdue'} |
1850 |
) |
1851 |
|| $return_date # force fine recalculation in case fine needs reduced |
1852 |
) |
1853 |
) |
1854 |
{ |
1843 |
# we only need to calculate and change the fines if we want to do that on return |
1855 |
# we only need to calculate and change the fines if we want to do that on return |
1844 |
# Should be on for hourly loans |
1856 |
# Should be on for hourly loans |
1845 |
my $control = C4::Context->preference('CircControl'); |
1857 |
my $control = C4::Context->preference('CircControl'); |
Lines 1857-1877
sub AddReturn {
Link Here
|
1857 |
|
1869 |
|
1858 |
$type ||= q{}; |
1870 |
$type ||= q{}; |
1859 |
|
1871 |
|
1860 |
if ( C4::Context->preference('finesMode') eq 'production' ) { |
1872 |
if ( $amount > 0 |
1861 |
if ( $amount > 0 ) { |
1873 |
&& C4::Context->preference('finesMode') eq 'production' ) |
1862 |
C4::Overdues::UpdateFine( $issue->{itemnumber}, |
1874 |
{ |
1863 |
$issue->{borrowernumber}, |
1875 |
C4::Overdues::UpdateFine( |
1864 |
$amount, $type, output_pref($datedue) ); |
1876 |
{ |
1865 |
} |
1877 |
itemnumber => $issue->{itemnumber}, |
1866 |
elsif ($return_date) { |
1878 |
borrowernumber => $issue->{borrowernumber}, |
1867 |
|
1879 |
amount => $amount, |
1868 |
# Backdated returns may have fines that shouldn't exist, |
1880 |
due => output_pref($datedue), |
1869 |
# so in this case, we need to drop those fines to 0 |
1881 |
issue_id => $issue->{issue_id} |
1870 |
|
1882 |
} |
1871 |
C4::Overdues::UpdateFine( $issue->{itemnumber}, |
1883 |
); |
1872 |
$issue->{borrowernumber}, |
1884 |
} |
1873 |
0, $type, output_pref($datedue) ); |
1885 |
elsif ($return_date) { |
1874 |
} |
1886 |
|
|
|
1887 |
# Backdated returns may have fines that shouldn't exist, |
1888 |
# so in this case, we need to drop those fines to 0 |
1889 |
C4::Overdues::UpdateFine( |
1890 |
{ |
1891 |
itemnumber => $issue->{itemnumber}, |
1892 |
borrowernumber => $issue->{borrowernumber}, |
1893 |
amount => 0, |
1894 |
due => output_pref($datedue), |
1895 |
issue_id => $issue->{issue_id} |
1896 |
} |
1897 |
); |
1875 |
} |
1898 |
} |
1876 |
} |
1899 |
} |
1877 |
|
1900 |
|
Lines 1921-1935
sub AddReturn {
Link Here
|
1921 |
$messages->{'WasLost'} = 1; |
1944 |
$messages->{'WasLost'} = 1; |
1922 |
|
1945 |
|
1923 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1946 |
if ( C4::Context->preference('RefundLostItemFeeOnReturn' ) ) { |
1924 |
_FixAccountForLostAndReturned($item->{'itemnumber'}, $borrowernumber, $barcode); # can tolerate undef $borrowernumber |
1947 |
_FixAccountForLostAndReturned( $item->{'itemnumber'} ); |
1925 |
$messages->{'LostItemFeeRefunded'} = 1; |
1948 |
$messages->{'LostItemFeeRefunded'} = 1; |
1926 |
} |
1949 |
} |
1927 |
} |
1950 |
} |
1928 |
|
1951 |
|
1929 |
# fix up the overdues in accounts... |
1952 |
# fix up the overdues in accounts... |
1930 |
if ($borrowernumber) { |
1953 |
if ($borrowernumber) { |
1931 |
my $fix = _FixOverduesOnReturn($borrowernumber, $item->{itemnumber}, $exemptfine, $dropbox); |
1954 |
_FinalizeFine( |
1932 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $item->{itemnumber}...) failed!"; # zero is OK, check defined |
1955 |
{ |
|
|
1956 |
exempt_fine => $exemptfine, |
1957 |
dropbox => $dropbox, |
1958 |
issue => Koha::Database->new()->schema->resultset('OldIssue')->find( $issue->{issue_id} ), |
1959 |
} |
1960 |
); |
1933 |
|
1961 |
|
1934 |
if ( $issue->{overdue} && $issue->{date_due} ) { |
1962 |
if ( $issue->{overdue} && $issue->{date_due} ) { |
1935 |
# fix fine days |
1963 |
# fix fine days |
Lines 2038-2047
of the return. It is ignored when a dropbox_branch is passed in.
Link Here
|
2038 |
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2, |
2066 |
C<$privacy> contains the privacy parameter. If the patron has set privacy to 2, |
2039 |
the old_issue is immediately anonymised |
2067 |
the old_issue is immediately anonymised |
2040 |
|
2068 |
|
2041 |
Ideally, this function would be internal to C<C4::Circulation>, |
|
|
2042 |
not exported, but it is currently needed by one |
2043 |
routine in C<C4::Accounts>. |
2044 |
|
2045 |
=cut |
2069 |
=cut |
2046 |
|
2070 |
|
2047 |
sub MarkIssueReturned { |
2071 |
sub MarkIssueReturned { |
Lines 2163-2317
sub _debar_user_on_return {
Link Here
|
2163 |
return; |
2187 |
return; |
2164 |
} |
2188 |
} |
2165 |
|
2189 |
|
2166 |
=head2 _FixOverduesOnReturn |
2190 |
=head2 _FinalizeFine |
2167 |
|
|
|
2168 |
&_FixOverduesOnReturn($brn,$itm, $exemptfine, $dropboxmode); |
2169 |
|
2170 |
C<$brn> borrowernumber |
2171 |
|
2191 |
|
2172 |
C<$itm> itemnumber |
2192 |
_FinalizeFine({ |
|
|
2193 |
exempt_fine => $exempt_fine, |
2194 |
dropbox => $dropbox, |
2195 |
issue => $issue, |
2196 |
}); |
2173 |
|
2197 |
|
2174 |
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. |
2198 |
C<$exemptfine> BOOL -- remove overdue charge associated with this issue. |
2175 |
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue. |
2199 |
C<$dropboxmode> BOOL -- remove lastincrement on overdue charge associated with this issue. |
|
|
2200 |
C<$issue> -- DBIx::Class::Row for the issue |
2176 |
|
2201 |
|
2177 |
Internal function, called only by AddReturn |
2202 |
This subrouting closes out the accuruing of a fine, and reduces if it exemptfine or |
|
|
2203 |
dropbox flags are passed in. |
2178 |
|
2204 |
|
2179 |
=cut |
2205 |
=cut |
2180 |
|
2206 |
|
2181 |
sub _FixOverduesOnReturn { |
2207 |
sub _FinalizeFine { |
2182 |
my ($borrowernumber, $item); |
2208 |
my ( $params ) = @_; |
2183 |
unless ($borrowernumber = shift) { |
2209 |
|
2184 |
warn "_FixOverduesOnReturn() not supplied valid borrowernumber"; |
2210 |
my $exemptfine = $params->{exempt_fine}; |
2185 |
return; |
2211 |
my $dropbox = $params->{dropbox}; |
2186 |
} |
2212 |
my $issue = $params->{issue}; |
2187 |
unless ($item = shift) { |
2213 |
|
2188 |
warn "_FixOverduesOnReturn() not supplied valid itemnumber"; |
|
|
2189 |
return; |
2190 |
} |
2191 |
my ($exemptfine, $dropbox) = @_; |
2192 |
my $dbh = C4::Context->dbh; |
2214 |
my $dbh = C4::Context->dbh; |
2193 |
|
2215 |
|
2194 |
# check for overdue fine |
2216 |
my $schema = Koha::Database->new()->schema; |
2195 |
my $sth = $dbh->prepare( |
2217 |
my $fine = $schema->resultset('AccountDebit')->single( |
2196 |
"SELECT * FROM accountlines WHERE (borrowernumber = ?) AND (itemnumber = ?) AND (accounttype='FU' OR accounttype='O')" |
2218 |
{ |
|
|
2219 |
issue_id => $issue->issue_id(), |
2220 |
type => Koha::Accounts::DebitTypes::Fine(), |
2221 |
accruing => 1, |
2222 |
} |
2197 |
); |
2223 |
); |
2198 |
$sth->execute( $borrowernumber, $item ); |
|
|
2199 |
|
2224 |
|
2200 |
# alter fine to show that the book has been returned |
2225 |
return unless ( $fine ); |
2201 |
my $data = $sth->fetchrow_hashref; |
2226 |
|
2202 |
return 0 unless $data; # no warning, there's just nothing to fix |
2227 |
$fine->accruing(0); |
2203 |
|
2228 |
|
2204 |
my $uquery; |
|
|
2205 |
my @bind = ($data->{'accountlines_id'}); |
2206 |
if ($exemptfine) { |
2229 |
if ($exemptfine) { |
2207 |
$uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0"; |
2230 |
AddCredit( |
2208 |
if (C4::Context->preference("FinesLog")) { |
2231 |
{ |
2209 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Overdue forgiven: item $item"); |
2232 |
borrower => $fine->borrowernumber(), |
2210 |
} |
2233 |
amount => $fine->amount_original(), |
2211 |
} elsif ($dropbox && $data->{lastincrement}) { |
2234 |
debit_id => $fine->debit_id(), |
2212 |
my $outstanding = $data->{amountoutstanding} - $data->{lastincrement} ; |
2235 |
type => Koha::Accounts::CreditTypes::Forgiven(), |
2213 |
my $amt = $data->{amount} - $data->{lastincrement} ; |
2236 |
} |
|
|
2237 |
); |
2214 |
if (C4::Context->preference("FinesLog")) { |
2238 |
if (C4::Context->preference("FinesLog")) { |
2215 |
&logaction("FINES", 'MODIFY',$borrowernumber,"Dropbox adjustment $amt, item $item"); |
2239 |
&logaction( |
2216 |
} |
2240 |
"FINES", 'MODIFY', |
2217 |
$uquery = "update accountlines set accounttype='F' "; |
2241 |
$issue->{borrowernumber}, |
2218 |
if($outstanding >= 0 && $amt >=0) { |
2242 |
"Overdue forgiven: item " . $issue->{itemnumber} |
2219 |
$uquery .= ", amount = ? , amountoutstanding=? "; |
2243 |
); |
2220 |
unshift @bind, ($amt, $outstanding) ; |
|
|
2221 |
} |
2244 |
} |
2222 |
} else { |
2245 |
} elsif ($dropbox && $fine->amount_last_increment() != $fine->amount_original() ) { |
2223 |
$uquery = "update accountlines set accounttype='F' "; |
2246 |
if ( C4::Context->preference("FinesLog") ) { |
|
|
2247 |
&logaction( "FINES", 'MODIFY', $issue->{borrowernumber}, |
2248 |
"Dropbox adjustment " |
2249 |
. $fine->amount_last_increment() |
2250 |
. ", item " . $issue->{itemnumber} ); |
2251 |
} |
2252 |
$fine->amount_original( |
2253 |
$fine->amount_original() - $fine->amount_last_increment() ); |
2254 |
$fine->amount_outstanding( |
2255 |
$fine->amount_outstanding - $fine->amount_last_increment() ); |
2256 |
$schema->resultset('AccountOffset')->create( |
2257 |
{ |
2258 |
debit_id => $fine->debit_id(), |
2259 |
type => Koha::Accounts::OffsetTypes::Dropbox(), |
2260 |
amount => $fine->amount_last_increment() * -1, |
2261 |
} |
2262 |
); |
2224 |
} |
2263 |
} |
2225 |
$uquery .= " where (accountlines_id = ?)"; |
2264 |
|
2226 |
my $usth = $dbh->prepare($uquery); |
2265 |
return $fine->update(); |
2227 |
return $usth->execute(@bind); |
|
|
2228 |
} |
2266 |
} |
2229 |
|
2267 |
|
2230 |
=head2 _FixAccountForLostAndReturned |
2268 |
=head2 _FixAccountForLostAndReturned |
2231 |
|
2269 |
|
2232 |
&_FixAccountForLostAndReturned($itemnumber, [$borrowernumber, $barcode]); |
2270 |
&_FixAccountForLostAndReturned($itemnumber); |
2233 |
|
|
|
2234 |
Calculates the charge for a book lost and returned. |
2235 |
|
2236 |
Internal function, not exported, called only by AddReturn. |
2237 |
|
2271 |
|
2238 |
FIXME: This function reflects how inscrutable fines logic is. Fix both. |
2272 |
Refunds a lost item fee in necessary |
2239 |
FIXME: Give a positive return value on success. It might be the $borrowernumber who received credit, or the amount forgiven. |
|
|
2240 |
|
2273 |
|
2241 |
=cut |
2274 |
=cut |
2242 |
|
2275 |
|
2243 |
sub _FixAccountForLostAndReturned { |
2276 |
sub _FixAccountForLostAndReturned { |
2244 |
my $itemnumber = shift or return; |
2277 |
my ( $itemnumber ) = @_; |
2245 |
my $borrowernumber = @_ ? shift : undef; |
2278 |
|
2246 |
my $item_id = @_ ? shift : $itemnumber; # Send the barcode if you want that logged in the description |
2279 |
my $schema = Koha::Database->new()->schema; |
2247 |
my $dbh = C4::Context->dbh; |
2280 |
|
2248 |
# check for charge made for lost book |
2281 |
# Find the last issue for this item |
2249 |
my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE itemnumber = ? AND accounttype IN ('L', 'Rep', 'W') ORDER BY date DESC, accountno DESC"); |
2282 |
my $issue = |
2250 |
$sth->execute($itemnumber); |
2283 |
$schema->resultset('Issue')->single( { itemnumber => $itemnumber } ); |
2251 |
my $data = $sth->fetchrow_hashref; |
2284 |
$issue ||= |
2252 |
$data or return; # bail if there is nothing to do |
2285 |
$schema->resultset('OldIssue')->single( { itemnumber => $itemnumber } ); |
2253 |
$data->{accounttype} eq 'W' and return; # Written off |
2286 |
|
2254 |
|
2287 |
return unless $issue; |
2255 |
# writeoff this amount |
2288 |
|
2256 |
my $offset; |
2289 |
# Find a lost fee for this issue |
2257 |
my $amount = $data->{'amount'}; |
2290 |
my $debit = $schema->resultset('AccountDebit')->single( |
2258 |
my $acctno = $data->{'accountno'}; |
2291 |
{ |
2259 |
my $amountleft; # Starts off undef/zero. |
2292 |
issue_id => $issue->issue_id(), |
2260 |
if ($data->{'amountoutstanding'} == $amount) { |
2293 |
type => Koha::Accounts::DebitTypes::Lost() |
2261 |
$offset = $data->{'amount'}; |
2294 |
} |
2262 |
$amountleft = 0; # Hey, it's zero here, too. |
2295 |
); |
2263 |
} else { |
2296 |
|
2264 |
$offset = $amount - $data->{'amountoutstanding'}; # Um, isn't this the same as ZERO? We just tested those two things are == |
2297 |
return unless $debit; |
2265 |
$amountleft = $data->{'amountoutstanding'} - $amount; # Um, isn't this the same as ZERO? We just tested those two things are == |
2298 |
|
2266 |
} |
2299 |
# Check for an existing found credit for this debit, if there is one, the fee has already been refunded and we do nothing |
2267 |
my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0' |
2300 |
my @credits = $debit->account_offsets->search_related('credit', { 'credit.type' => Koha::Accounts::CreditTypes::Found() }); |
2268 |
WHERE (accountlines_id = ?)"); |
2301 |
|
2269 |
$usth->execute($data->{'accountlines_id'}); # We might be adjusting an account for some OTHER borrowernumber now. Not the one we passed in. |
2302 |
return if @credits; |
2270 |
#check if any credit is left if so writeoff other accounts |
2303 |
|
2271 |
my $nextaccntno = getnextacctno($data->{'borrowernumber'}); |
2304 |
# Ok, so we know we have an unrefunded lost item fee, let's refund it |
2272 |
$amountleft *= -1 if ($amountleft < 0); |
2305 |
CreditLostItem( |
2273 |
if ($amountleft > 0) { |
2306 |
{ |
2274 |
my $msth = $dbh->prepare("SELECT * FROM accountlines WHERE (borrowernumber = ?) |
2307 |
borrower => $issue->borrower(), |
2275 |
AND (amountoutstanding >0) ORDER BY date"); # might want to order by amountoustanding ASC (pay smallest first) |
2308 |
debit => $debit |
2276 |
$msth->execute($data->{'borrowernumber'}); |
2309 |
} |
2277 |
# offset transactions |
2310 |
); |
2278 |
my $newamtos; |
2311 |
|
2279 |
my $accdata; |
|
|
2280 |
while (($accdata=$msth->fetchrow_hashref) and ($amountleft>0)){ |
2281 |
if ($accdata->{'amountoutstanding'} < $amountleft) { |
2282 |
$newamtos = 0; |
2283 |
$amountleft -= $accdata->{'amountoutstanding'}; |
2284 |
} else { |
2285 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
2286 |
$amountleft = 0; |
2287 |
} |
2288 |
my $thisacct = $accdata->{'accountlines_id'}; |
2289 |
# FIXME: move prepares outside while loop! |
2290 |
my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ? |
2291 |
WHERE (accountlines_id = ?)"); |
2292 |
$usth->execute($newamtos,$thisacct); |
2293 |
$usth = $dbh->prepare("INSERT INTO accountoffsets |
2294 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
2295 |
VALUES |
2296 |
(?,?,?,?)"); |
2297 |
$usth->execute($data->{'borrowernumber'},$accdata->{'accountno'},$nextaccntno,$newamtos); |
2298 |
} |
2299 |
} |
2300 |
$amountleft *= -1 if ($amountleft > 0); |
2301 |
my $desc = "Item Returned " . $item_id; |
2302 |
$usth = $dbh->prepare("INSERT INTO accountlines |
2303 |
(borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding) |
2304 |
VALUES (?,?,now(),?,?,'CR',?)"); |
2305 |
$usth->execute($data->{'borrowernumber'},$nextaccntno,0-$amount,$desc,$amountleft); |
2306 |
if ($borrowernumber) { |
2307 |
# FIXME: same as query above. use 1 sth for both |
2308 |
$usth = $dbh->prepare("INSERT INTO accountoffsets |
2309 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
2310 |
VALUES (?,?,?,?)"); |
2311 |
$usth->execute($borrowernumber, $data->{'accountno'}, $nextaccntno, $offset); |
2312 |
} |
2313 |
ModItem({ paidfor => '' }, undef, $itemnumber); |
2312 |
ModItem({ paidfor => '' }, undef, $itemnumber); |
2314 |
return; |
|
|
2315 |
} |
2313 |
} |
2316 |
|
2314 |
|
2317 |
=head2 _GetCircControlBranch |
2315 |
=head2 _GetCircControlBranch |
Lines 2704-2717
sub AddRenewal {
Link Here
|
2704 |
my $dbh = C4::Context->dbh; |
2702 |
my $dbh = C4::Context->dbh; |
2705 |
|
2703 |
|
2706 |
# Find the issues record for this book |
2704 |
# Find the issues record for this book |
2707 |
my $sth = |
2705 |
my $issue = Koha::Database->new()->schema->resultset('Issue')->single({ itemnumber => $itemnumber }); |
2708 |
$dbh->prepare("SELECT * FROM issues WHERE itemnumber = ?"); |
|
|
2709 |
$sth->execute( $itemnumber ); |
2710 |
my $issuedata = $sth->fetchrow_hashref; |
2711 |
|
2706 |
|
2712 |
return unless ( $issuedata ); |
2707 |
return unless ( $issue ); |
2713 |
|
2708 |
|
2714 |
$borrowernumber ||= $issuedata->{borrowernumber}; |
2709 |
$borrowernumber ||= $issue->get_column('borrowernumber'); |
2715 |
|
2710 |
|
2716 |
if ( defined $datedue && ref $datedue ne 'DateTime' ) { |
2711 |
if ( defined $datedue && ref $datedue ne 'DateTime' ) { |
2717 |
carp 'Invalid date passed to AddRenewal.'; |
2712 |
carp 'Invalid date passed to AddRenewal.'; |
Lines 2727-2767
sub AddRenewal {
Link Here
|
2727 |
my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
2722 |
my $itemtype = (C4::Context->preference('item-level_itypes')) ? $biblio->{'itype'} : $biblio->{'itemtype'}; |
2728 |
|
2723 |
|
2729 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
2724 |
$datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? |
2730 |
dt_from_string( $issuedata->{date_due} ) : |
2725 |
dt_from_string( $issue->get_column('date_due') ) : |
2731 |
DateTime->now( time_zone => C4::Context->tz()); |
2726 |
DateTime->now( time_zone => C4::Context->tz()); |
2732 |
$datedue = CalcDateDue($datedue, $itemtype, $issuedata->{'branchcode'}, $borrower, 'is a renewal'); |
2727 |
$datedue = CalcDateDue($datedue, $itemtype, $issue->get_column('branchcode'), $borrower, 'is a renewal'); |
2733 |
} |
2728 |
} |
2734 |
|
2729 |
|
2735 |
# Update the issues record to have the new due date, and a new count |
2730 |
# Update the issues record to have the new due date, and a new count |
2736 |
# of how many times it has been renewed. |
2731 |
# of how many times it has been renewed. |
2737 |
my $renews = $issuedata->{'renewals'} + 1; |
2732 |
$issue->update( |
2738 |
$sth = $dbh->prepare("UPDATE issues SET date_due = ?, renewals = ?, lastreneweddate = ? |
2733 |
{ |
2739 |
WHERE borrowernumber=? |
2734 |
date_due => $datedue->strftime('%Y-%m-%d %H:%M'), |
2740 |
AND itemnumber=?" |
2735 |
renewals => $issue->renewals() + 1, |
|
|
2736 |
lastreneweddate => $lastreneweddate, |
2737 |
} |
2741 |
); |
2738 |
); |
2742 |
|
2739 |
|
2743 |
$sth->execute( $datedue->strftime('%Y-%m-%d %H:%M'), $renews, $lastreneweddate, $borrowernumber, $itemnumber ); |
|
|
2744 |
|
2740 |
|
2745 |
# Update the renewal count on the item, and tell zebra to reindex |
2741 |
# Update the renewal count on the item, and tell zebra to reindex |
2746 |
$renews = $biblio->{'renewals'} + 1; |
2742 |
my $renews = $biblio->{'renewals'} + 1; |
2747 |
ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber); |
2743 |
ModItem({ renewals => $renews, onloan => $datedue->strftime('%Y-%m-%d %H:%M')}, $biblio->{'biblionumber'}, $itemnumber); |
2748 |
|
2744 |
|
2749 |
# Charge a new rental fee, if applicable? |
2745 |
# Charge a new rental fee, if applicable? |
2750 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
2746 |
my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber ); |
2751 |
if ( $charge > 0 ) { |
2747 |
if ( $charge > 0 ) { |
2752 |
my $accountno = getnextacctno( $borrowernumber ); |
|
|
2753 |
my $item = GetBiblioFromItemNumber($itemnumber); |
2748 |
my $item = GetBiblioFromItemNumber($itemnumber); |
2754 |
my $manager_id = 0; |
2749 |
|
2755 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
2750 |
my $borrower = |
2756 |
$sth = $dbh->prepare( |
2751 |
Koha::Database->new()->schema->resultset('Borrower') |
2757 |
"INSERT INTO accountlines |
2752 |
->find($borrowernumber); |
2758 |
(date, borrowernumber, accountno, amount, manager_id, |
2753 |
|
2759 |
description,accounttype, amountoutstanding, itemnumber) |
2754 |
AddDebit( |
2760 |
VALUES (now(),?,?,?,?,?,?,?,?)" |
2755 |
{ |
|
|
2756 |
borrower => $borrower, |
2757 |
itemnumber => $itemnumber, |
2758 |
amount => $charge, |
2759 |
type => Koha::Accounts::DebitTypes::Rental(), |
2760 |
description => |
2761 |
"Renewal of Rental Item $item->{'title'} $item->{'barcode'}" |
2762 |
} |
2761 |
); |
2763 |
); |
2762 |
$sth->execute( $borrowernumber, $accountno, $charge, $manager_id, |
|
|
2763 |
"Renewal of Rental Item $item->{'title'} $item->{'barcode'}", |
2764 |
'Rent', $charge, $itemnumber ); |
2765 |
} |
2764 |
} |
2766 |
|
2765 |
|
2767 |
# Send a renewal slip according to checkout alert preferencei |
2766 |
# Send a renewal slip according to checkout alert preferencei |
Lines 2803-2808
sub AddRenewal {
Link Here
|
2803 |
borrowernumber => $borrowernumber, |
2802 |
borrowernumber => $borrowernumber, |
2804 |
ccode => $item->{'ccode'}} |
2803 |
ccode => $item->{'ccode'}} |
2805 |
); |
2804 |
); |
|
|
2805 |
|
2806 |
_FinalizeFine( { issue => $issue } ); |
2807 |
|
2806 |
return $datedue; |
2808 |
return $datedue; |
2807 |
} |
2809 |
} |
2808 |
|
2810 |
|
Lines 2987-3011
sub _get_discount_from_rule {
Link Here
|
2987 |
|
2989 |
|
2988 |
=head2 AddIssuingCharge |
2990 |
=head2 AddIssuingCharge |
2989 |
|
2991 |
|
2990 |
&AddIssuingCharge( $itemno, $borrowernumber, $charge ) |
2992 |
&AddIssuingCharge( $itemnumber, $borrowernumber, $amount ) |
2991 |
|
2993 |
|
2992 |
=cut |
2994 |
=cut |
2993 |
|
2995 |
|
2994 |
sub AddIssuingCharge { |
2996 |
sub AddIssuingCharge { |
2995 |
my ( $itemnumber, $borrowernumber, $charge ) = @_; |
2997 |
my ( $itemnumber, $borrowernumber, $amount ) = @_; |
2996 |
my $dbh = C4::Context->dbh; |
2998 |
|
2997 |
my $nextaccntno = getnextacctno( $borrowernumber ); |
2999 |
return AddDebit( |
2998 |
my $manager_id = 0; |
3000 |
{ |
2999 |
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv; |
3001 |
borrower => Koha::Database->new()->schema->resultset('Borrower')->find($borrowernumber), |
3000 |
my $query =" |
3002 |
itemnumber => $itemnumber, |
3001 |
INSERT INTO accountlines |
3003 |
amount => $amount, |
3002 |
(borrowernumber, itemnumber, accountno, |
3004 |
type => Koha::Accounts::DebitTypes::Rental(), |
3003 |
date, amount, description, accounttype, |
3005 |
} |
3004 |
amountoutstanding, manager_id) |
3006 |
); |
3005 |
VALUES (?, ?, ?,now(), ?, 'Rental', 'Rent',?,?) |
|
|
3006 |
"; |
3007 |
my $sth = $dbh->prepare($query); |
3008 |
$sth->execute( $borrowernumber, $itemnumber, $nextaccntno, $charge, $charge, $manager_id ); |
3009 |
} |
3007 |
} |
3010 |
|
3008 |
|
3011 |
=head2 GetTransfers |
3009 |
=head2 GetTransfers |
Lines 3524-3553
sub ReturnLostItem{
Link Here
|
3524 |
sub LostItem{ |
3522 |
sub LostItem{ |
3525 |
my ($itemnumber, $mark_returned) = @_; |
3523 |
my ($itemnumber, $mark_returned) = @_; |
3526 |
|
3524 |
|
3527 |
my $dbh = C4::Context->dbh(); |
3525 |
my $schema = Koha::Database->new()->schema; |
3528 |
my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title |
|
|
3529 |
FROM issues |
3530 |
JOIN items USING (itemnumber) |
3531 |
JOIN biblio USING (biblionumber) |
3532 |
WHERE issues.itemnumber=?"); |
3533 |
$sth->execute($itemnumber); |
3534 |
my $issues=$sth->fetchrow_hashref(); |
3535 |
|
3526 |
|
3536 |
# If a borrower lost the item, add a replacement cost to the their record |
3527 |
my $issue = |
3537 |
if ( my $borrowernumber = $issues->{borrowernumber} ){ |
3528 |
$schema->resultset('Issue')->single( { itemnumber => $itemnumber } ); |
3538 |
my $borrower = C4::Members::GetMemberDetails( $borrowernumber ); |
|
|
3539 |
|
3529 |
|
|
|
3530 |
my ( $borrower, $item ); |
3531 |
|
3532 |
if ( $issue ) { |
3533 |
$borrower = $issue->borrower(); |
3534 |
$item = $issue->item(); |
3535 |
} |
3536 |
|
3537 |
# If a borrower lost the item, add a replacement cost to the their record |
3538 |
if ( $borrower ){ |
3540 |
if (C4::Context->preference('WhenLostForgiveFine')){ |
3539 |
if (C4::Context->preference('WhenLostForgiveFine')){ |
3541 |
my $fix = _FixOverduesOnReturn($borrowernumber, $itemnumber, 1, 0); # 1, 0 = exemptfine, no-dropbox |
3540 |
_FinalizeFine( |
3542 |
defined($fix) or warn "_FixOverduesOnReturn($borrowernumber, $itemnumber...) failed!"; # zero is OK, check defined |
3541 |
{ |
|
|
3542 |
exempt_fine => 1, |
3543 |
dropbox => 0, |
3544 |
issue => $issue, |
3545 |
} |
3546 |
); |
3543 |
} |
3547 |
} |
3544 |
if (C4::Context->preference('WhenLostChargeReplacementFee')){ |
3548 |
if ( C4::Context->preference('WhenLostChargeReplacementFee') ) { |
3545 |
C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}"); |
3549 |
DebitLostItem( { borrower => $borrower, issue => $issue } ); |
3546 |
#FIXME : Should probably have a way to distinguish this from an item that really was returned. |
|
|
3547 |
#warn " $issues->{'borrowernumber'} / $itemnumber "; |
3548 |
} |
3550 |
} |
3549 |
|
3551 |
|
3550 |
MarkIssueReturned($borrowernumber,$itemnumber,undef,undef,$borrower->{'privacy'}) if $mark_returned; |
3552 |
MarkIssueReturned( $borrower->borrowernumber(), $item->itemnumber(), undef, undef, $borrower->privacy() ) if $mark_returned; |
3551 |
} |
3553 |
} |
3552 |
} |
3554 |
} |
3553 |
|
3555 |
|
Lines 3665-3674
sub ProcessOfflineIssue {
Link Here
|
3665 |
sub ProcessOfflinePayment { |
3667 |
sub ProcessOfflinePayment { |
3666 |
my $operation = shift; |
3668 |
my $operation = shift; |
3667 |
|
3669 |
|
3668 |
my $borrower = C4::Members::GetMemberDetails( undef, $operation->{cardnumber} ); # Get borrower from operation cardnumber |
3670 |
AddCredit( |
3669 |
my $amount = $operation->{amount}; |
3671 |
{ |
3670 |
|
3672 |
borrower => Koha::Database->new()->schema->resultset('Borrower') |
3671 |
recordpayment( $borrower->{borrowernumber}, $amount ); |
3673 |
->single( { cardnumber => $operation->{cardnumber} } ), |
|
|
3674 |
amount => $operation->{amount}, |
3675 |
notes => 'via offline circulation', |
3676 |
type => Koha::Accounts::CreditTypes::Payment, |
3677 |
} |
3678 |
); |
3672 |
|
3679 |
|
3673 |
return "Success." |
3680 |
return "Success." |
3674 |
} |
3681 |
} |