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