Lines 53-58
use Koha::Patron::Debarments;
Link Here
|
53 |
use Koha::Database; |
53 |
use Koha::Database; |
54 |
use Koha::Libraries; |
54 |
use Koha::Libraries; |
55 |
use Koha::Holds; |
55 |
use Koha::Holds; |
|
|
56 |
use Koha::Issues; |
57 |
use Koha::OldIssues; |
56 |
use Carp; |
58 |
use Carp; |
57 |
use List::MoreUtils qw( uniq ); |
59 |
use List::MoreUtils qw( uniq ); |
58 |
use Scalar::Util qw( looks_like_number ); |
60 |
use Scalar::Util qw( looks_like_number ); |
Lines 1920-1940
sub AddReturn {
Link Here
|
1920 |
} |
1922 |
} |
1921 |
|
1923 |
|
1922 |
if ($borrowernumber) { |
1924 |
if ($borrowernumber) { |
1923 |
if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) { |
|
|
1924 |
_CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } ); |
1925 |
} |
1926 |
|
1927 |
eval { |
1925 |
eval { |
1928 |
MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, |
1926 |
MarkIssueReturned( $borrowernumber, $item->{'itemnumber'}, |
1929 |
$circControlBranch, $return_date, $borrower->{'privacy'} ); |
1927 |
$circControlBranch, $return_date, $borrower->{'privacy'} ); |
1930 |
}; |
1928 |
}; |
1931 |
if ( $@ ) { |
1929 |
unless ( $@ ) { |
1932 |
$messages->{'Wrongbranch'} = { |
1930 |
if ( ( C4::Context->preference('CalculateFinesOnReturn') && $issue->{'overdue'} ) || $return_date ) { |
1933 |
Wrongbranch => $branch, |
1931 |
_CalculateAndUpdateFine( { issue => $issue, item => $item, borrower => $borrower, return_date => $return_date } ); |
1934 |
Rightbranch => $message |
1932 |
} |
1935 |
}; |
1933 |
} else { |
1936 |
carp $@; |
1934 |
carp "The checkin for the following issue failed, Please go to the about page, section 'data corrupted' to know how to fix this problem ($@)" . Dumper( $issue ); |
1937 |
return ( 0, { WasReturned => 0 }, $issue, $borrower ); |
1935 |
|
|
|
1936 |
return ( 0, { WasReturned => 0, DataCorrupted => 1 }, $issue, $borrower ); |
1938 |
} |
1937 |
} |
1939 |
|
1938 |
|
1940 |
# FIXME is the "= 1" right? This could be the borrower hash. |
1939 |
# FIXME is the "= 1" right? This could be the borrower hash. |
Lines 2147-2167
sub MarkIssueReturned {
Link Here
|
2147 |
|
2146 |
|
2148 |
# FIXME Improve the return value and handle it from callers |
2147 |
# FIXME Improve the return value and handle it from callers |
2149 |
$schema->txn_do(sub { |
2148 |
$schema->txn_do(sub { |
|
|
2149 |
|
2150 |
# Update the returndate |
2150 |
$dbh->do( $query, undef, @bind ); |
2151 |
$dbh->do( $query, undef, @bind ); |
2151 |
|
2152 |
|
2152 |
my $id_already_exists = $dbh->selectrow_array( |
2153 |
# Retrieve the issue |
2153 |
q|SELECT COUNT(*) FROM old_issues WHERE issue_id = ?|, |
2154 |
my $issue = Koha::Issues->find( $issue_id ); # FIXME should be fetched earlier |
2154 |
undef, $issue_id |
|
|
2155 |
); |
2156 |
|
2155 |
|
2157 |
if ( $id_already_exists ) { |
2156 |
# Create the old_issues entry |
2158 |
my $new_issue_id = $dbh->selectrow_array(q|SELECT MAX(issue_id)+1 FROM old_issues|); |
2157 |
my $old_checkout = Koha::OldIssue->new($issue->unblessed)->store; |
2159 |
$dbh->do( |
|
|
2160 |
q|UPDATE issues SET issue_id = ? WHERE issue_id = ?|, |
2161 |
undef, $new_issue_id, $issue_id |
2162 |
); |
2163 |
$issue_id = $new_issue_id; |
2164 |
} |
2165 |
|
2158 |
|
2166 |
$dbh->do(q|INSERT INTO old_issues SELECT * FROM issues WHERE issue_id = ?|, undef, $issue_id); |
2159 |
$dbh->do(q|INSERT INTO old_issues SELECT * FROM issues WHERE issue_id = ?|, undef, $issue_id); |
2167 |
|
2160 |
|
Lines 2170-2176
sub MarkIssueReturned {
Link Here
|
2170 |
$dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $issue_id); |
2163 |
$dbh->do(q|UPDATE old_issues SET borrowernumber=? WHERE issue_id = ?|, undef, $anonymouspatron, $issue_id); |
2171 |
} |
2164 |
} |
2172 |
|
2165 |
|
2173 |
$dbh->do(q|DELETE FROM issues WHERE issue_id = ?|, undef, $issue_id); |
2166 |
# And finally delete the issue |
|
|
2167 |
$issue->delete; |
2174 |
|
2168 |
|
2175 |
ModItem( { 'onloan' => undef }, undef, $itemnumber ); |
2169 |
ModItem( { 'onloan' => undef }, undef, $itemnumber ); |
2176 |
|
2170 |
|