use C4::Koha;
use C4::Members;
use C4::Reserves;
-use C4::Branch qw(GetBranchName);
use C4::Items qw( GetBarcodeFromItemnumber GetItemnumbersForBiblio);
use C4::Auth qw(checkpw);
-our $VERSION = 3.07.00.049;
+use Koha::Libraries;
+use Koha::Patrons;
our $kp; # koha patron
syslog("LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id);
return;
}
- $kp = GetMemberDetails($kp->{borrowernumber});
- $debug and warn "new Patron (GetMemberDetails): " . Dumper($kp);
+ $kp = GetMember( borrowernumber => $kp->{borrowernumber});
+ $debug and warn "new Patron (GetMember): " . Dumper($kp);
my $pw = $kp->{password};
- my $flags = $kp->{flags}; # or warn "Warning: No flags from patron object for '$patron_id'";
- my $debarred = defined($kp->{flags}->{DBARRED});
- $debug and warn sprintf("Debarred = %s : ", ($debarred||'undef')) . Dumper(%{$kp->{flags}});
+ my $flags = C4::Members::patronflags( $kp );
+ my $debarred = defined($flags->{DBARRED});
+ $debug and warn sprintf("Debarred = %s : ", ($debarred||'undef')) . Dumper(%$flags);
my ($day, $month, $year) = (localtime)[3,4,5];
my $today = sprintf '%04d-%02d-%02d', $year+1900, $month+1, $day;
my $expired = ($today gt $kp->{dateexpiry}) ? 1 : 0;
}
}
+sub name {
+ my ( $self, $template ) = @_;
+
+ if ($template) {
+ require Template;
+ require Koha::Patrons;
+
+ my $tt = Template->new();
+
+ my $patron = Koha::Patrons->find( $self->{borrowernumber} );
+
+ my $output;
+ $tt->process( \$template, { patron => $patron }, \$output );
+ return $output;
+ }
+ else {
+ return $self->{name};
+ }
+}
+
sub check_password {
my ( $self, $pwd ) = @_;
- defined $pwd
- or return 0; # you gotta give me something (at least ''), or no deal
+ # you gotta give me something (at least ''), or no deal
+ return 0 unless defined $pwd;
- return 1
- if $pwd eq q{}; # if the record has a NULL password, accept '' as match
+ # If the record has a NULL password, accept '' as match
+ return $pwd eq q{} unless $self->{password};
my $dbh = C4::Context->dbh;
my $ret = 0;
- ($ret) = checkpw( $dbh, $self->{userid}, $pwd );
+ ($ret) = checkpw( $dbh, $self->{userid}, $pwd, undef, undef, 1 ); # dbh, userid, query, type, no_set_userenv
return $ret;
}
return $self->x_items('items', @_);
}
sub fine_items {
+ require Koha::Database;
+ require Template;
+
my $self = shift;
- return $self->x_items('fine_items', @_);
+ my $start = shift;
+ my $end = shift;
+ my $server = shift;
+
+ my @fees = Koha::Database->new()->schema()->resultset('Accountline')->search(
+ {
+ borrowernumber => $self->{borrowernumber},
+ amountoutstanding => { '>' => '0' },
+ }
+ );
+
+ $start = $start ? $start - 1 : 0;
+ $end = $end ? $end : scalar @fees - 1;
+
+ my $av_field_template = $server ? $server->{account}->{av_field_template} : undef;
+ $av_field_template ||= "[% accountline.description %] [% accountline.amountoutstanding | format('%.2f') %]";
+
+ my $tt = Template->new();
+
+ my @return_values;
+ for ( my $i = $start; $i <= $end; $i++ ) {
+ my $fee = $fees[$i];
+
+ my $output;
+ $tt->process( \$av_field_template, { accountline => $fee }, \$output );
+ push( @return_values, { barcode => $output } );
+ }
+
+ return \@return_values;
}
sub recall_items {
my $self = shift;
sub library_name {
my $self = shift;
unless ($self->{library_name}) {
- $self->{library_name} = GetBranchName($self->{branchcode});
+ my $library = Koha::Libraries->find( $self->{branchcode} );
+ $self->{library_name} = $library ? $library->branchname : '';
}
return $self->{library_name};
}
sub _get_outstanding_holds {
my $borrowernumber = shift;
- my @hold_array = grep { !defined $_->{found} || $_->{found} ne 'W'} GetReservesFromBorrowernumber($borrowernumber);
- foreach my $h (@hold_array) {
+
+ my $patron = Koha::Patrons->find( $borrowernumber );
+ my $holds = $patron->holds->search( { -or => [ { found => undef }, { found => { '!=' => 'W' } } ] } );
+ my @holds;
+ while ( my $hold = $holds->next ) {
my $item;
- if ($h->{itemnumber}) {
- $item = $h->{itemnumber};
+ if ($hold->itemnumber) {
+ $item = $hold->itemnumber;
}
else {
# We need to return a barcode for the biblio so the client
# can request the biblio info
- $item = ( GetItemnumbersForBiblio($h->{biblionumber}) )->[0];
+ $item = ( GetItemnumbersForBiblio($hold->biblionumber) )->[0];
}
- $h->{barcode} = GetBarcodeFromItemnumber($item);
+ my $unblessed_hold = $hold->unblessed;
+ $unblessed_hold->{barcode} = GetBarcodeFromItemnumber($item);
+ push @holds, $unblessed_hold;
}
- return \@hold_array;
+ return \@holds;
}
1;