|
Lines 169-174
sub store {
Link Here
|
| 169 |
$self->permanent_location( $self->location ); |
169 |
$self->permanent_location( $self->location ); |
| 170 |
} |
170 |
} |
| 171 |
|
171 |
|
|
|
172 |
# If item was lost, it has now been found, reverse any list item charges if necessary. |
| 173 |
if ( exists $updated_columns{itemlost} |
| 174 |
and $self->itemlost != $updated_columns{itemlost} |
| 175 |
and $updated_columns{itemlost} >= 1 ) { |
| 176 |
$self->_set_found_trigger; |
| 177 |
$self->paidfor(''); |
| 178 |
} |
| 179 |
|
| 172 |
C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" ) |
180 |
C4::Biblio::ModZebra( $self->biblionumber, "specialUpdate", "biblioserver" ) |
| 173 |
unless $params->{skip_modzebra_update}; |
181 |
unless $params->{skip_modzebra_update}; |
| 174 |
|
182 |
|
|
Lines 763-772
sub renewal_branchcode {
Link Here
|
| 763 |
return $branchcode; |
771 |
return $branchcode; |
| 764 |
} |
772 |
} |
| 765 |
|
773 |
|
| 766 |
sub set_found { |
774 |
=head3 _set_found_trigger |
| 767 |
my ($self, $params) = @_; |
775 |
|
|
|
776 |
$self->_set_found_trigger |
| 777 |
|
| 778 |
Finds the most recent lost item charge for this item and refunds the patron |
| 779 |
appropriatly, taking into account any payments or writeoffs already applied |
| 780 |
against the charge. |
| 768 |
|
781 |
|
| 769 |
my $holdingbranch = $params->{holdingbranch} || $self->holdingbranch; |
782 |
Internal function, not exported, called only by Koha::Item->store. |
|
|
783 |
|
| 784 |
=cut |
| 785 |
|
| 786 |
sub _set_found_trigger { |
| 787 |
my ( $self, $params ) = @_; |
| 770 |
|
788 |
|
| 771 |
## If item was lost, it has now been found, reverse any list item charges if necessary. |
789 |
## If item was lost, it has now been found, reverse any list item charges if necessary. |
| 772 |
my $refund = 1; |
790 |
my $refund = 1; |
|
Lines 778-802
sub set_found {
Link Here
|
| 778 |
dt_from_string( $self->itemlost_on )->delta_days($today) |
796 |
dt_from_string( $self->itemlost_on )->delta_days($today) |
| 779 |
->in_units('days'); |
797 |
->in_units('days'); |
| 780 |
|
798 |
|
| 781 |
$refund = 0 unless ( $lost_age_in_days < $no_refund_after_days ); |
799 |
return $self unless $lost_age_in_days < $no_refund_after_days; |
|
|
800 |
} |
| 801 |
|
| 802 |
return $self |
| 803 |
unless Koha::CirculationRules->get_lostreturn_policy( |
| 804 |
{ |
| 805 |
current_branch => C4::Context->userenv->{branch}, |
| 806 |
item => $self, |
| 807 |
} |
| 808 |
); |
| 809 |
|
| 810 |
# check for charge made for lost book |
| 811 |
my $accountlines = Koha::Account::Lines->search( |
| 812 |
{ |
| 813 |
itemnumber => $self->itemnumber, |
| 814 |
debit_type_code => 'LOST', |
| 815 |
status => [ undef, { '<>' => 'FOUND' } ] |
| 816 |
}, |
| 817 |
{ |
| 818 |
order_by => { -desc => [ 'date', 'accountlines_id' ] } |
| 819 |
} |
| 820 |
); |
| 821 |
|
| 822 |
return $self unless $accountlines->count > 0; |
| 823 |
|
| 824 |
my $accountline = $accountlines->next; |
| 825 |
my $total_to_refund = 0; |
| 826 |
|
| 827 |
return $self unless $accountline->borrowernumber; |
| 828 |
|
| 829 |
my $patron = Koha::Patrons->find( $accountline->borrowernumber ); |
| 830 |
return $self |
| 831 |
unless $patron; # Patron has been deleted, nobody to credit the return to |
| 832 |
# FIXME Should not we notify this somehwere |
| 833 |
|
| 834 |
my $account = $patron->account; |
| 835 |
|
| 836 |
# Use cases |
| 837 |
if ( $accountline->amount > $accountline->amountoutstanding ) { |
| 838 |
|
| 839 |
# some amount has been cancelled. collect the offsets that are not writeoffs |
| 840 |
# this works because the only way to subtract from this kind of a debt is |
| 841 |
# using the UI buttons 'Pay' and 'Write off' |
| 842 |
my $credits_offsets = Koha::Account::Offsets->search( |
| 843 |
{ |
| 844 |
debit_id => $accountline->id, |
| 845 |
credit_id => { '!=' => undef }, # it is not the debit itself |
| 846 |
type => { '!=' => 'Writeoff' }, |
| 847 |
amount => { '<' => 0 } # credits are negative on the DB |
| 848 |
} |
| 849 |
); |
| 850 |
|
| 851 |
$total_to_refund = ( $credits_offsets->count > 0 ) |
| 852 |
? $credits_offsets->total * -1 # credits are negative on the DB |
| 853 |
: 0; |
| 782 |
} |
854 |
} |
| 783 |
|
855 |
|
| 784 |
my $refunded; |
856 |
my $credit_total = $accountline->amountoutstanding + $total_to_refund; |
| 785 |
if ( |
857 |
|
| 786 |
$refund |
858 |
my $credit; |
| 787 |
&& Koha::CirculationRules->get_lostreturn_policy( |
859 |
if ( $credit_total > 0 ) { |
|
|
860 |
my $branchcode = |
| 861 |
C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef; |
| 862 |
$credit = $account->add_credit( |
| 788 |
{ |
863 |
{ |
| 789 |
current_branch => C4::Context->userenv->{branch}, |
864 |
amount => $credit_total, |
| 790 |
item => $self, |
865 |
description => 'Item found ' . $item_id, |
|
|
866 |
type => 'LOST_FOUND', |
| 867 |
interface => C4::Context->interface, |
| 868 |
library_id => $branchcode, |
| 869 |
item_id => $itemnumber |
| 791 |
} |
870 |
} |
| 792 |
) |
871 |
); |
| 793 |
) |
872 |
|
| 794 |
{ |
873 |
$credit->apply( { debits => [$accountline] } ); |
| 795 |
C4::Circulation::_FixAccountForLostAndFound( $self->itemnumber, $self->barcode ); |
|
|
| 796 |
$refunded = 1; |
| 797 |
} |
874 |
} |
| 798 |
|
875 |
|
| 799 |
return $refunded; |
876 |
# Update the account status |
|
|
877 |
$accountline->discard_changes->status('FOUND') |
| 878 |
; # FIXME JD Why discard_changes? $accountline has not been modified since last fetch |
| 879 |
$accountline->store; |
| 880 |
|
| 881 |
if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) { |
| 882 |
$account->reconcile_balance; |
| 883 |
} |
| 884 |
|
| 885 |
return $self; |
| 800 |
} |
886 |
} |
| 801 |
|
887 |
|
| 802 |
=head3 to_api_mapping |
888 |
=head3 to_api_mapping |