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