use Koha::List::Patron;
use Koha::Patrons;
use Koha::Patron::Categories;
+use Koha::Schema;
our (@ISA,@EXPORT,@EXPORT_OK,$debug);
@ISA = qw(Exporter);
#Get data
push @EXPORT, qw(
- &Search
&GetMemberDetails
&GetMember
&GetFirstValidEmailAddress
&GetNoticeEmailAddress
- &GetAge
- &GetTitles
-
- &GetHideLostItemsPreference
-
&GetMemberAccountRecords
&GetBorNotifyAcctRecord
- GetBorrowerCategorycode
-
&GetBorrowersToExpunge
&GetBorrowersWhoHaveNeverBorrowed
&GetBorrowersWithIssuesHistoryOlderThan
SELECT borrowers.*,
category_type,
categories.description,
- categories.BlockExpiredPatronOpacActions,
reservefee,
enrolmentperiod
FROM borrowers
SELECT borrowers.*,
category_type,
categories.description,
- categories.BlockExpiredPatronOpacActions,
reservefee,
enrolmentperiod
FROM borrowers
$borrower->{'flags'} = $flags;
$borrower->{'authflags'} = $accessflagshash;
- # Handle setting the true behavior for BlockExpiredPatronOpacActions
- $borrower->{'BlockExpiredPatronOpacActions'} =
- C4::Context->preference('BlockExpiredPatronOpacActions')
- if ( $borrower->{'BlockExpiredPatronOpacActions'} == -1 );
-
$borrower->{'is_expired'} = 0;
$borrower->{'is_expired'} = 1 if
defined($borrower->{dateexpiry}) &&
}
}
- my $old_categorycode = GetBorrowerCategorycode( $data{borrowernumber} );
+ my $old_categorycode = Koha::Patrons->find( $data{borrowernumber} )->categorycode;
# get only the columns of a borrower
my $schema = Koha::Database->new()->schema;
$new_borrower->{dateexpiry} ||= undef if exists $new_borrower->{dateexpiry};
$new_borrower->{debarred} ||= undef if exists $new_borrower->{debarred};
$new_borrower->{sms_provider_id} ||= undef if exists $new_borrower->{sms_provider_id};
+ $new_borrower->{guarantorid} ||= undef if exists $new_borrower->{guarantorid};
- my $rs = $schema->resultset('Borrower')->search({
- borrowernumber => $new_borrower->{borrowernumber},
- });
+ my $patron = Koha::Patrons->find( $new_borrower->{borrowernumber} );
delete $new_borrower->{userid} if exists $new_borrower->{userid} and not $new_borrower->{userid};
- my $execute_success = $rs->update($new_borrower);
- if ($execute_success ne '0E0') { # only proceed if the update was a success
+ my $execute_success = $patron->store if $patron->set($new_borrower);
+
+ if ($execute_success) { # only proceed if the update was a success
# If the patron changes to a category with enrollment fee, we add a fee
if ( $data{categorycode} and $data{categorycode} ne $old_categorycode ) {
if ( C4::Context->preference('FeeOnChangePatronCategory') ) {
- AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
+ $patron->add_enrolment_fee_if_needed;
}
}
});
}
- # mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best.
logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
- AddEnrolmentFeeIfNeeded( $data{categorycode}, $data{borrowernumber} );
+ $patron->add_enrolment_fee_if_needed;
return $data{borrowernumber};
}
}
}
+ my $borrower = Koha::Schema->resultset('Borrower');
+ my $field_size = $borrower->result_source->column_info('cardnumber')->{size};
+ $min = $field_size if $min > $field_size;
return ( $min, $max );
}
return $results;
}
-=head2 GetBorrowerCategorycode
-
- $categorycode = &GetBorrowerCategoryCode( $borrowernumber );
-
-Given the borrowernumber, the function returns the corresponding categorycode
-
-=cut
-
-sub GetBorrowerCategorycode {
- my ( $borrowernumber ) = @_;
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare( qq{
- SELECT categorycode
- FROM borrowers
- WHERE borrowernumber = ?
- } );
- $sth->execute( $borrowernumber );
- return $sth->fetchrow;
-}
-
-=head2 GetAge
-
- $dateofbirth,$date = &GetAge($date);
-
-this function return the borrowers age with the value of dateofbirth
-
-=cut
-
-#'
-sub GetAge{
- my ( $date, $date_ref ) = @_;
-
- if ( not defined $date_ref ) {
- $date_ref = sprintf( '%04d-%02d-%02d', Today() );
- }
-
- my ( $year1, $month1, $day1 ) = split /-/, $date;
- my ( $year2, $month2, $day2 ) = split /-/, $date_ref;
-
- my $age = $year2 - $year1;
- if ( $month1 . $day1 > $month2 . $day2 ) {
- $age--;
- }
-
- return $age;
-} # sub get_age
-
-=head2 SetAge
-
- $borrower = C4::Members::SetAge($borrower, $datetimeduration);
- $borrower = C4::Members::SetAge($borrower, '0015-12-10');
- $borrower = C4::Members::SetAge($borrower, $datetimeduration, $datetime_reference);
-
- eval { $borrower = C4::Members::SetAge($borrower, '015-1-10'); };
- if ($@) {print $@;} #Catch a bad ISO Date or kill your script!
-
-This function sets the borrower's dateofbirth to match the given age.
-Optionally relative to the given $datetime_reference.
-
-@PARAM1 koha.borrowers-object
-@PARAM2 DateTime::Duration-object as the desired age
- OR a ISO 8601 Date. (To make the API more pleasant)
-@PARAM3 DateTime-object as the relative date, defaults to now().
-RETURNS The given borrower reference @PARAM1.
-DIES If there was an error with the ISO Date handling.
-
-=cut
-
-#'
-sub SetAge{
- my ( $borrower, $datetimeduration, $datetime_ref ) = @_;
- $datetime_ref = DateTime->now() unless $datetime_ref;
-
- if ($datetimeduration && ref $datetimeduration ne 'DateTime::Duration') {
- if ($datetimeduration =~ /^(\d{4})-(\d{2})-(\d{2})/) {
- $datetimeduration = DateTime::Duration->new(years => $1, months => $2, days => $3);
- }
- else {
- die "C4::Members::SetAge($borrower, $datetimeduration), datetimeduration not a valid ISO 8601 Date!\n";
- }
- }
-
- my $new_datetime_ref = $datetime_ref->clone();
- $new_datetime_ref->subtract_duration( $datetimeduration );
-
- $borrower->{dateofbirth} = $new_datetime_ref->ymd();
-
- return $borrower;
-} # sub SetAge
-
-=head2 GetHideLostItemsPreference
-
- $hidelostitemspref = &GetHideLostItemsPreference($borrowernumber);
-
-Returns the HideLostItems preference for the patron category of the supplied borrowernumber
-C<&$hidelostitemspref>return value of function, 0 or 1
-
-=cut
-
-sub GetHideLostItemsPreference {
- my ($borrowernumber) = @_;
- my $dbh = C4::Context->dbh;
- my $query = "SELECT hidelostitems FROM borrowers,categories WHERE borrowers.categorycode = categories.categorycode AND borrowernumber = ?";
- my $sth = $dbh->prepare($query);
- $sth->execute($borrowernumber);
- my $hidelostitems = $sth->fetchrow;
- return $hidelostitems;
-}
-
=head2 GetBorrowersToExpunge
$borrowers = &GetBorrowersToExpunge(
return ( $borrowernumber, $borrower{'password'} );
}
-=head2 AddEnrolmentFeeIfNeeded
-
- AddEnrolmentFeeIfNeeded( $borrower->{categorycode}, $borrower->{borrowernumber} );
-
-Add enrolment fee for a patron if needed.
-
-=cut
-
-sub AddEnrolmentFeeIfNeeded {
- my ( $categorycode, $borrowernumber ) = @_;
- # check for enrollment fee & add it if needed
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare(q{
- SELECT enrolmentfee
- FROM categories
- WHERE categorycode=?
- });
- $sth->execute( $categorycode );
- if ( $sth->err ) {
- warn sprintf('Database returned the following error: %s', $sth->errstr);
- return;
- }
- my ($enrolmentfee) = $sth->fetchrow;
- if ($enrolmentfee && $enrolmentfee > 0) {
- # insert fee in patron debts
- C4::Accounts::manualinvoice( $borrowernumber, '', '', 'A', $enrolmentfee );
- }
-}
-
=head2 DeleteExpiredOpacRegistrations
Delete accounts that haven't been upgraded from the 'temporary' category