# system
#
-package ILS::Patron;
+package C4::SIP::ILS::Patron;
use strict;
use warnings;
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_hash);
+use C4::Auth qw(checkpw);
-our $VERSION = 3.07.00.049;
+use Koha::Libraries;
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;
$dexpiry and $dexpiry =~ s/-//g; # YYYYMMDD
my $fines_amount = $flags->{CHARGES}->{amount};
$fines_amount = ($fines_amount and $fines_amount > 0) ? $fines_amount : 0;
+ my $fee_limit = _fee_limit();
+ my $fine_blocked = $fines_amount > $fee_limit;
{
no warnings; # any of these $kp->{fields} being concat'd could be undef
%ilspatron = (
address => $adr,
home_phone => $kp->{phone},
email_addr => $kp->{email},
- charge_ok => ( !$debarred && !$expired ),
- renew_ok => ( !$debarred && !$expired ),
- recall_ok => ( !$debarred && !$expired ),
- hold_ok => ( !$debarred && !$expired ),
+ charge_ok => ( !$debarred && !$expired && !$fine_blocked),
+ renew_ok => ( !$debarred && !$expired && !$fine_blocked),
+ recall_ok => ( !$debarred && !$expired && !$fine_blocked),
+ hold_ok => ( !$debarred && !$expired && !$fine_blocked),
card_lost => ( $kp->{lost} || $kp->{gonenoaddress} || $flags->{LOST} ),
claims_returned => 0,
fines => $fines_amount, # GetMemberAccountRecords($kp->{borrowernumber})
unavail_holds => [],
inet => ( !$debarred && !$expired ),
expired => $expired,
+ fee_limit => $fee_limit,
+ userid => $kp->{userid},
);
}
$debug and warn "patron fines: $ilspatron{fines} ... amountoutstanding: $kp->{amountoutstanding} ... CHARGES->amount: $flags->{CHARGES}->{amount}";
card_lost => 0, # for patron_status[4]
recall_overdue => 0,
currency => 1,
-# fee_limit => 0,
+ fee_limit => 0,
screen_msg => 1,
print_line => 1,
too_many_charged => 0, # for patron_status[5]
}
sub check_password {
- my ($self, $pwd) = @_;
- defined $pwd or return 0; # you gotta give me something (at least ''), or no deal
+ my ( $self, $pwd ) = @_;
+
+ # you gotta give me something (at least ''), or no deal
+ return 0 unless defined $pwd;
- my $hashed_pwd = $self->{password};
- defined $hashed_pwd or return $pwd eq ''; # 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};
- # warn sprintf "check_password for %s: '%s' vs. '%s'",($self->{name}||''),($self->{password}||''),($pwd||'');
- return checkpw_hash($pwd, $hashed_pwd);
+ my $dbh = C4::Context->dbh;
+ my $ret = 0;
+ ($ret) = checkpw( $dbh, $self->{userid}, $pwd, undef, undef, 1 ); # dbh, userid, query, type, no_set_userenv
+ return $ret;
}
# A few special cases, not in AUTOLOADed %fields
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;
return $self->{inet} ? 'Y' : 'N';
}
-sub fee_limit {
- my $self = shift;
- return C4::Context->preference("noissuescharge") || 5;
+sub _fee_limit {
+ return C4::Context->preference('noissuescharge') || 5;
}
sub excessive_fees {
my $self = shift;
return ($self->fee_amount and $self->fee_amount > $self->fee_limit);
}
+
sub excessive_fines {
my $self = shift;
return $self->excessive_fees; # excessive_fines is the same thing as excessive_fees for Koha
}
+
+sub holds_blocked_by_excessive_fees {
+ my $self = shift;
+ return ( $self->fee_amount
+ && $self->fee_amount > C4::Context->preference("maxoutstanding") );
+}
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};
}
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($h->{biblionumber}) )->[0];
}
$h->{barcode} = GetBarcodeFromItemnumber($item);
}