X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=Koha%2FPatron.pm;h=eeaf0e4dc27680db524a1f0516bdebfacc28ffb7;hb=a23577cefae2312efe4f91709dccdf39370504d9;hp=aadb714307189ec804804dc150401c4cd9b85969;hpb=03ea0f0b37acdd6eab2374bebc845fcbe1c8eb13;p=koha_ffzg diff --git a/Koha/Patron.pm b/Koha/Patron.pm index aadb714307..eeaf0e4dc2 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -21,11 +21,10 @@ package Koha::Patron; use Modern::Perl; use Carp; -use List::MoreUtils qw( uniq ); +use List::MoreUtils qw( any uniq ); use JSON qw( to_json ); use Text::Unaccent qw( unac_string ); -use C4::Accounts; use C4::Context; use C4::Log; use Koha::AuthUtils; @@ -85,8 +84,6 @@ Koha::Patron - Koha Patron Object class =head2 Class Methods -=cut - =head3 new =cut @@ -192,29 +189,6 @@ sub store { $self->trim_whitespaces; - # We don't want invalid dates in the db (mysql has a bad habit of inserting 0000-00-00) - $self->dateofbirth(undef) unless $self->dateofbirth; - $self->debarred(undef) unless $self->debarred; - $self->date_renewed(undef) unless $self->date_renewed; - $self->lastseen(undef) unless $self->lastseen; - - if ( defined $self->updated_on and not $self->updated_on ) { - $self->updated_on(undef); - } - - # Set default values if not set - $self->sms_provider_id(undef) unless $self->sms_provider_id; - $self->guarantorid(undef) unless $self->guarantorid; - - # If flags == 0 or flags == '' => no permission - $self->flags(undef) unless $self->flags; - - # tinyint or int - $self->gonenoaddress(0) unless $self->gonenoaddress; - $self->login_attempts(0) unless $self->login_attempts; - $self->privacy_guarantor_checkouts(0) unless $self->privacy_guarantor_checkouts; - $self->lost(0) unless $self->lost; - unless ( $self->in_storage ) { #AddMember # Generate a valid userid/login if needed @@ -240,9 +214,6 @@ sub store { : undef; $self->privacy($default_privacy); - unless ( defined $self->privacy_guarantor_checkouts ) { - $self->privacy_guarantor_checkouts(0); - } # Make a copy of the plain text password for later use $self->plain_text_password( $self->password ); @@ -263,11 +234,6 @@ sub store { } else { #ModMember - # Come from ModMember, but should not be possible (?) - $self->dateenrolled(undef) unless $self->dateenrolled; - $self->dateexpiry(undef) unless $self->dateexpiry; - - my $self_from_storage = $self->get_from_storage; # FIXME We should not deal with that here, callers have to do this job # Moved from ModMember to prevent regressions @@ -286,33 +252,50 @@ sub store { $self->add_enrolment_fee_if_needed; } - my $borrowers_log = C4::Context->preference("BorrowersLog"); - my $previous_cardnumber = $self_from_storage->cardnumber; - if ($borrowers_log - && ( !defined $previous_cardnumber - || $previous_cardnumber ne $self->cardnumber ) - ) - { - logaction( - "MEMBERS", - "MODIFY", - $self->borrowernumber, - to_json( - { - cardnumber_replaced => { - previous_cardnumber => $previous_cardnumber, - new_cardnumber => $self->cardnumber, - } - }, - { utf8 => 1, pretty => 1 } - ) - ); - } + # Actionlogs + if ( C4::Context->preference("BorrowersLog") ) { + my $info; + my $from_storage = $self_from_storage->unblessed; + my $from_object = $self->unblessed; + my @skip_fields = (qw/lastseen/); + for my $key ( keys %{$from_storage} ) { + next if any { /$key/ } @skip_fields; + if ( + ( + !defined( $from_storage->{$key} ) + && defined( $from_object->{$key} ) + ) + || ( defined( $from_storage->{$key} ) + && !defined( $from_object->{$key} ) ) + || ( + defined( $from_storage->{$key} ) + && defined( $from_object->{$key} ) + && ( $from_storage->{$key} ne + $from_object->{$key} ) + ) + ) + { + $info->{$key} = { + before => $from_storage->{$key}, + after => $from_object->{$key} + }; + } + } - logaction( "MEMBERS", "MODIFY", $self->borrowernumber, - "UPDATE (executed w/ arg: " . $self->borrowernumber . ")" ) - if $borrowers_log; + if ( defined($info) ) { + logaction( + "MEMBERS", + "MODIFY", + $self->borrowernumber, + to_json( + $info, + { utf8 => 1, pretty => 1, canonical => 1 } + ) + ); + } + } + # Final store $self = $self->SUPER::store; } } @@ -863,8 +846,14 @@ sub add_enrolment_fee_if_needed { my ($self) = @_; my $enrolment_fee = $self->category->enrolmentfee; if ( $enrolment_fee && $enrolment_fee > 0 ) { - # insert fee in patron debts - C4::Accounts::manualinvoice( $self->borrowernumber, '', '', 'A', $enrolment_fee ); + $self->account->add_debit( + { + amount => $enrolment_fee, + user_id => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0, + library_id => C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef, + type => 'account' + } + ); } return $enrolment_fee || 0; } @@ -893,7 +882,6 @@ It has been introduced to replaced the C4::Members::GetPendingIssues subroutine It should not be used directly, prefer to access fields you need instead of retrieving all these fields in one go. - =cut sub pending_checkouts { @@ -1123,6 +1111,7 @@ Return true if the patron (usually the logged in user) can see the patron's info sub can_see_patron_infos { my ( $self, $patron ) = @_; + return unless $patron; return $self->can_see_patrons_from( $patron->library->branchcode ); } @@ -1229,6 +1218,7 @@ my $is_child = $patron->is_child Return true if the patron has a category with a type Child (C) =cut + sub is_child { my( $self ) = @_; return $self->category->category_type eq 'C' ? 1 : 0; @@ -1310,10 +1300,11 @@ sub _type { return 'Borrower'; } -=head1 AUTHOR +=head1 AUTHORS Kyle M Hall Alex Sassmannshausen +Martin Renvoize =cut