&GetBorrowersWithIssuesHistoryOlderThan
&GetExpiryDate
+ &IsMemberBlocked
);
#Modify data
$query .= ($category_type ? " AND category_type = ".$dbh->quote($category_type) : "");
$query .= " WHERE (surname LIKE ? OR cardnumber like ?) ";
if (C4::Context->preference("IndependantBranches") && !$showallbranches){
- if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){
+ if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
$query.=" AND borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'}) unless (C4::Context->userenv->{'branch'} eq "insecure");
}
}
$count = @data;
$query .= " WHERE ";
if (C4::Context->preference("IndependantBranches") && !$showallbranches){
- if (C4::Context->userenv && C4::Context->userenv->{flags}!=1 && C4::Context->userenv->{'branch'}){
+ if (C4::Context->userenv && C4::Context->userenv->{flags} % 2 !=1 && C4::Context->userenv->{'branch'}){
$query.=" borrowers.branchcode =".$dbh->quote(C4::Context->userenv->{'branch'})." AND " unless (C4::Context->userenv->{'branch'} eq "insecure");
}
}
# Patron's card was reported lost
}
-Each flag has a C<message> key, giving a human-readable explanation of
-the flag. If the state of a flag means that the patron should not be
+If the state of a flag means that the patron should not be
allowed to borrow any more books, then it will have a C<noissues> key
with a true value.
-The possible flags are:
-
-=head3 CHARGES
-
-=over 4
-
-=item Shows the patron's credit or debt, if any.
-
-=back
-
-=head3 GNA
-
-=over 4
-
-=item (Gone, no address.) Set if the patron has left without giving a
-forwarding address.
-
-=back
-
-=head3 LOST
-
-=over 4
-
-=item Set if the patron's card has been reported as lost.
-
-=back
-
-=head3 DBARRED
-
-=over 4
-
-=item Set if the patron has been debarred.
-
-=back
-
-=head3 NOTES
-
-=over 4
-
-=item Any additional notes about the patron.
-
-=back
-
-=head3 ODUES
-
-=over 4
-
-=item Set if the patron has overdue items. This flag has several keys:
-
-C<$flags-E<gt>{ODUES}{itemlist}> is a reference-to-array listing the
-overdue items. Its elements are references-to-hash, each describing an
-overdue item. The keys are selected fields from the issues, biblio,
-biblioitems, and items tables of the Koha database.
-
-C<$flags-E<gt>{ODUES}{itemlist}> is a string giving a text listing of
-the overdue items, one per line.
-
-=back
-
-=head3 WAITING
-
-=over 4
-
-=item Set if any items that the patron has reserved are available.
-
-C<$flags-E<gt>{WAITING}{itemlist}> is a reference-to-array listing the
-available items. Each element is a reference-to-hash whose keys are
-fields from the reserves table of the Koha database.
-
-=back
+See patronflags for more details.
C<$borrower-E<gt>{authflags}> is a hash giving more detailed information
about the top-level permissions flags set for the borrower. For example,
=head2 patronflags
- Not exported
+ $flags = &patronflags($patron);
- NOTE!: If you change this function, be sure to update the POD for
- &GetMemberDetails.
+ This function is not exported.
- $flags = &patronflags($patron);
+ The following will be set where applicable:
+ $flags->{CHARGES}->{amount} Amount of debt
+ $flags->{CHARGES}->{noissues} Set if debt amount >$5.00 (or syspref noissuescharge)
+ $flags->{CHARGES}->{message} Message -- deprecated
+
+ $flags->{CREDITS}->{amount} Amount of credit
+ $flags->{CREDITS}->{message} Message -- deprecated
+
+ $flags->{ GNA } Patron has no valid address
+ $flags->{ GNA }->{noissues} Set for each GNA
+ $flags->{ GNA }->{message} "Borrower has no valid address" -- deprecated
+
+ $flags->{ LOST } Patron's card reported lost
+ $flags->{ LOST }->{noissues} Set for each LOST
+ $flags->{ LOST }->{message} Message -- deprecated
+
+ $flags->{DBARRED} Set if patron debarred, no access
+ $flags->{DBARRED}->{noissues} Set for each DBARRED
+ $flags->{DBARRED}->{message} Message -- deprecated
+
+ $flags->{ NOTES }
+ $flags->{ NOTES }->{message} The note itself. NOT deprecated
- $flags->{CHARGES}
- {message} Message showing patron's credit or debt
- {noissues} Set if patron owes >$5.00
- {GNA} Set if patron gone w/o address
- {message} "Borrower has no valid address"
- {noissues} Set.
- {LOST} Set if patron's card reported lost
- {message} Message to this effect
- {noissues} Set.
- {DBARRED} Set is patron is debarred
- {message} Message to this effect
- {noissues} Set.
- {NOTES} Set if patron has notes
- {message} Notes about patron
- {ODUES} Set if patron has overdue books
- {message} "Yes"
- {itemlist} ref-to-array: list of overdue books
- {itemlisttext} Text list of overdue items
- {WAITING} Set if there are items available that the
- patron reserved
- {message} Message to this effect
- {itemlist} ref-to-array: list of available items
+ $flags->{ ODUES } Set if patron has overdue books.
+ $flags->{ ODUES }->{message} "Yes" -- deprecated
+ $flags->{ ODUES }->{itemlist} ref-to-array: list of overdue books
+ $flags->{ ODUES }->{itemlisttext} Text list of overdue items -- deprecated
+
+ $flags->{WAITING} Set if any of patron's reserves are available
+ $flags->{WAITING}->{message} Message -- deprecated
+ $flags->{WAITING}->{itemlist} ref-to-array: list of available items
+
+=over 4
+
+C<$flags-E<gt>{ODUES}-E<gt>{itemlist}> is a reference-to-array listing the
+overdue items. Its elements are references-to-hash, each describing an
+overdue item. The keys are selected fields from the issues, biblio,
+biblioitems, and items tables of the Koha database.
+
+C<$flags-E<gt>{ODUES}-E<gt>{itemlisttext}> is a string giving a text listing of
+the overdue items, one per line. Deprecated.
+
+C<$flags-E<gt>{WAITING}-E<gt>{itemlist}> is a reference-to-array listing the
+available items. Each element is a reference-to-hash whose keys are
+fields from the reserves table of the Koha database.
+
+=back
+
+All the "message" fields that include language generated in this function are deprecated,
+because such strings belong properly in the display layer.
+
+The "message" field that comes from the DB is OK.
=cut
+
+# TODO: use {anonymous => hashes} instead of a dozen %flaginfo
# FIXME rename this function.
sub patronflags {
my %flags;
my ($amount) = GetMemberAccountRecords( $patroninformation->{'borrowernumber'});
if ( $amount > 0 ) {
my %flaginfo;
- my $noissuescharge = C4::Context->preference("noissuescharge");
+ my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
$flaginfo{'message'} = sprintf "Patron owes \$%.02f", $amount;
- $flaginfo{'amount'} = sprintf "%.02f",$amount;
+ $flaginfo{'amount'} = sprintf "%.02f", $amount;
if ( $amount > $noissuescharge ) {
$flaginfo{'noissues'} = 1;
}
elsif ( $amount < 0 ) {
my %flaginfo;
$flaginfo{'message'} = sprintf "Patron has credit of \$%.02f", -$amount;
+ $flaginfo{'amount'} = sprintf "%.02f", $amount;
$flags{'CREDITS'} = \%flaginfo;
}
if ( $patroninformation->{'gonenoaddress'}
&& $patroninformation->{'borrowernotes'} )
{
my %flaginfo;
- $flaginfo{'message'} = "$patroninformation->{'borrowernotes'}";
+ $flaginfo{'message'} = $patroninformation->{'borrowernotes'};
$flags{'NOTES'} = \%flaginfo;
}
- my ( $odues, $itemsoverdue ) =
- checkoverdues( $patroninformation->{'borrowernumber'}, $dbh );
+ my ( $odues, $itemsoverdue ) = checkoverdues($patroninformation->{'borrowernumber'});
if ( $odues > 0 ) {
my %flaginfo;
$flaginfo{'message'} = "Yes";
@$itemsoverdue )
{
$flaginfo{'itemlisttext'} .=
- "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n";
+ "$_->{'date_due'} $_->{'barcode'} $_->{'title'} \n"; # newline is display layer
}
$flags{'ODUES'} = \%flaginfo;
}
=head2 GetMember
- $borrower = &GetMember($information, $type);
+ $borrower = &GetMember(%information);
Looks up information about a patron (borrower) by either card number
,firstname, or borrower number, depending on $type value.
#'
sub GetMember {
- my ( $information, $type ) = @_;
+ my ( %information ) = @_;
my $dbh = C4::Context->dbh;
my $sth;
my $select = "
FROM borrowers
LEFT JOIN categories on borrowers.categorycode=categories.categorycode
";
- if (defined($type) and ( $type eq 'cardnumber' || $type eq 'firstname'|| $type eq 'userid'|| $type eq 'borrowernumber' ) ){
- $information = uc $information;
- $sth = $dbh->prepare("$select WHERE $type=?");
- } else {
- $sth = $dbh->prepare("$select WHERE borrowernumber=?");
- }
- $sth->execute($information);
- my $data = $sth->fetchrow_hashref;
- ($data) and return ($data);
-
- if (defined($type) and ($type eq 'cardnumber' || $type eq 'firstname')) { # otherwise, try with firstname
- $sth = $dbh->prepare("$select WHERE firstname like ?");
- $sth->execute($information);
- $data = $sth->fetchrow_hashref;
- ($data) and return ($data);
- }
- return undef;
+ $select.=" WHERE ".join(" AND ",map {"$_ = ?"}keys %information);
+ $select=~s/AND $//;
+ $debug && warn $select, " ",values %information;
+ $sth = $dbh->prepare("$select");
+ $sth->execute(values %information);
+ my $data = $sth->fetchall_arrayref({});
+ return undef if (scalar(@$data)==0);
+ if (scalar(@$data)==1) {return $$data[0];}
+ ($data) and return $data;
}
=head2 GetMemberIssuesAndFines
}
my @columns = &columns;
my %hashborrowerfields = (map {$_=>1} @columns);
- my $query = "UPDATE borrowers SET \n";
+ my $query = "UPDATE borrowers SET ";
my $sth;
my @parameters;
my $dbh = C4::Context->dbh;
$data{'userid'} = '' unless $data{'password'};
$data{'password'} = md5_base64( $data{'password'} ) if $data{'password'};
-
# WE SHOULD NEVER PASS THIS SUBROUTINE ANYTHING OTHER THAN ISO DATES
# IF YOU UNCOMMENT THESE LINES YOU BETTER HAVE A DARN COMPELLING REASON
# $data{'dateofbirth'} = format_date_in_iso( $data{'dateofbirth'} );
# $data{'dateenrolled'} = format_date_in_iso( $data{'dateenrolled'});
# $data{'dateexpiry'} = format_date_in_iso( $data{'dateexpiry'} );
- # This query should be rewritten to use "?" at execute.
+ my $iso_re = C4::Dates->new()->regexp('iso');
+ foreach (qw(dateofbirth dateexpiry dateenrolled)) {
+ if (my $tempdate = $data{$_}) { # assignment, not comparison
+ ($tempdate =~ /$iso_re/) and next; # Congatulations, you sent a valid ISO date.
+ warn "AddMember given $_ not in ISO format ($tempdate)";
+ my $tempdate2 = format_date_in_iso($tempdate);
+ if (!$tempdate2 or $tempdate2 eq '0000-00-00') {
+ warn "AddMember cannot convert '$tempdate' (from syspref to ISO)";
+ next;
+ }
+ $data{$_} = $tempdate2;
+ }
+ }
if (!$data{'dateofbirth'}){
undef ($data{'dateofbirth'});
}
+ my $elements=join "|",grep {!/borrowernumber/} C4::Members->columns;
+ my @param_values;
+ my @param_query;
+ foreach my $field (grep {/\b($elements)\b/} keys %data){
+ push @param_values, $data{$field};
+ push @param_query, " $field = ?";
+ }
my $query =
- "insert into borrowers set cardnumber=" . $dbh->quote( $data{'cardnumber'} )
- . ",surname=" . $dbh->quote( $data{'surname'} )
- . ",firstname=" . $dbh->quote( $data{'firstname'} )
- . ",title=" . $dbh->quote( $data{'title'} )
- . ",othernames=" . $dbh->quote( $data{'othernames'} )
- . ",initials=" . $dbh->quote( $data{'initials'} )
- . ",streetnumber=". $dbh->quote( $data{'streetnumber'} )
- . ",streettype=" . $dbh->quote( $data{'streettype'} )
- . ",address=" . $dbh->quote( $data{'address'} )
- . ",address2=" . $dbh->quote( $data{'address2'} )
- . ",zipcode=" . $dbh->quote( $data{'zipcode'} )
- . ",city=" . $dbh->quote( $data{'city'} )
- . ",phone=" . $dbh->quote( $data{'phone'} )
- . ",email=" . $dbh->quote( $data{'email'} )
- . ",mobile=" . $dbh->quote( $data{'mobile'} )
- . ",phonepro=" . $dbh->quote( $data{'phonepro'} )
- . ",opacnote=" . $dbh->quote( $data{'opacnote'} )
- . ",guarantorid=" . $dbh->quote( $data{'guarantorid'} )
- . ",dateofbirth=" . $dbh->quote( $data{'dateofbirth'} )
- . ",branchcode=" . $dbh->quote( $data{'branchcode'} )
- . ",categorycode=" . $dbh->quote( $data{'categorycode'} )
- . ",dateenrolled=" . $dbh->quote( $data{'dateenrolled'} )
- . ",contactname=" . $dbh->quote( $data{'contactname'} )
- . ",borrowernotes=" . $dbh->quote( $data{'borrowernotes'} )
- . ",dateexpiry=" . $dbh->quote( $data{'dateexpiry'} )
- . ",contactnote=" . $dbh->quote( $data{'contactnote'} )
- . ",B_address=" . $dbh->quote( $data{'B_address'} )
- . ",B_zipcode=" . $dbh->quote( $data{'B_zipcode'} )
- . ",B_city=" . $dbh->quote( $data{'B_city'} )
- . ",B_phone=" . $dbh->quote( $data{'B_phone'} )
- . ",B_email=" . $dbh->quote( $data{'B_email'} )
- . ",password=" . $dbh->quote( $data{'password'} )
- . ",userid=" . $dbh->quote( $data{'userid'} )
- . ",sort1=" . $dbh->quote( $data{'sort1'} )
- . ",sort2=" . $dbh->quote( $data{'sort2'} )
- . ",contacttitle=" . $dbh->quote( $data{'contacttitle'} )
- . ",emailpro=" . $dbh->quote( $data{'emailpro'} )
- . ",contactfirstname=" . $dbh->quote( $data{'contactfirstname'} )
- . ",sex=" . $dbh->quote( $data{'sex'} )
- . ",fax=" . $dbh->quote( $data{'fax'} )
- . ",relationship=" . $dbh->quote( $data{'relationship'} )
- . ",B_streetnumber=" . $dbh->quote( $data{'B_streetnumber'} )
- . ",B_streettype=" . $dbh->quote( $data{'B_streettype'} )
- . ",gonenoaddress=" . $dbh->quote( $data{'gonenoaddress'} )
- . ",lost=" . $dbh->quote( $data{'lost'} )
- . ",debarred=" . $dbh->quote( $data{'debarred'} )
- . ",ethnicity=" . $dbh->quote( $data{'ethnicity'} )
- . ",ethnotes=" . $dbh->quote( $data{'ethnotes'} )
- . ",altcontactsurname=" . $dbh->quote( $data{'altcontactsurname'} )
- . ",altcontactfirstname=" . $dbh->quote( $data{'altcontactfirstname'} )
- . ",altcontactaddress1=" . $dbh->quote( $data{'altcontactaddress1'} )
- . ",altcontactaddress2=" . $dbh->quote( $data{'altcontactaddress2'} )
- . ",altcontactaddress3=" . $dbh->quote( $data{'altcontactaddress3'} )
- . ",altcontactzipcode=" . $dbh->quote( $data{'altcontactzipcode'} )
- . ",altcontactphone=" . $dbh->quote( $data{'altcontactphone'} ) ;
+ q{ insert into borrowers set }
+ .join (",", @param_query) ;
$debug and print STDERR "AddMember SQL: ($query)\n";
my $sth = $dbh->prepare($query);
# print "Executing SQL: $query\n";
- $sth->execute();
+ $sth->execute(@param_values);
$sth->finish;
$data{'borrowernumber'} = $dbh->{'mysql_insertid'}; # unneeded w/ autoincrement ?
# mysql_insertid is probably bad. not necessarily accurate and mysql-specific at best.
-
logaction("MEMBERS", "CREATE", $data{'borrowernumber'}, "") if C4::Context->preference("BorrowersLog");
# check for enrollment fee & add it if needed
sub fixup_cardnumber ($) {
my ($cardnumber) = @_;
- my $autonumber_members = C4::Context->boolean_preference('autoMemberNum');
- $autonumber_members = 0 unless defined $autonumber_members;
+ my $autonumber_members = C4::Context->boolean_preference('autoMemberNum') || 0;
# Find out whether member numbers should be generated
# automatically. Should be either "1" or something else.
# Defaults to "0", which is interpreted as "no".
# if ($cardnumber !~ /\S/ && $autonumber_members) {
- if ($autonumber_members) {
- my $dbh = C4::Context->dbh;
- if ( C4::Context->preference('checkdigit') eq 'katipo' ) {
-
- # if checkdigit is selected, calculate katipo-style cardnumber.
- # otherwise, just use the max()
- # purpose: generate checksum'd member numbers.
- # We'll assume we just got the max value of digits 2-8 of member #'s
- # from the database and our job is to increment that by one,
- # determine the 1st and 9th digits and return the full string.
- my $sth =
- $dbh->prepare(
- "select max(substring(borrowers.cardnumber,2,7)) from borrowers"
- );
- $sth->execute;
-
- my $data = $sth->fetchrow_hashref;
- $cardnumber = $data->{'max(substring(borrowers.cardnumber,2,7))'};
- $sth->finish;
- if ( !$cardnumber ) { # If DB has no values,
- $cardnumber = 1000000; # start at 1000000
- }
- else {
- $cardnumber += 1;
- }
-
- my $sum = 0;
- for ( my $i = 0 ; $i < 8 ; $i += 1 ) {
+ ($autonumber_members) or return $cardnumber;
+ my $checkdigit = C4::Context->preference('checkdigit');
+ my $dbh = C4::Context->dbh;
+ if ( $checkdigit and $checkdigit eq 'katipo' ) {
+
+ # if checkdigit is selected, calculate katipo-style cardnumber.
+ # otherwise, just use the max()
+ # purpose: generate checksum'd member numbers.
+ # We'll assume we just got the max value of digits 2-8 of member #'s
+ # from the database and our job is to increment that by one,
+ # determine the 1st and 9th digits and return the full string.
+ my $sth = $dbh->prepare(
+ "select max(substring(borrowers.cardnumber,2,7)) as new_num from borrowers"
+ );
+ $sth->execute;
+ my $data = $sth->fetchrow_hashref;
+ $cardnumber = $data->{new_num};
+ if ( !$cardnumber ) { # If DB has no values,
+ $cardnumber = 1000000; # start at 1000000
+ } else {
+ $cardnumber += 1;
+ }
- # read weightings, left to right, 1 char at a time
- my $temp1 = $weightings[$i];
+ my $sum = 0;
+ for ( my $i = 0 ; $i < 8 ; $i += 1 ) {
+ # read weightings, left to right, 1 char at a time
+ my $temp1 = $weightings[$i];
- # sequence left to right, 1 char at a time
- my $temp2 = substr( $cardnumber, $i, 1 );
+ # sequence left to right, 1 char at a time
+ my $temp2 = substr( $cardnumber, $i, 1 );
- # mult each char 1-7 by its corresponding weighting
- $sum += $temp1 * $temp2;
- }
+ # mult each char 1-7 by its corresponding weighting
+ $sum += $temp1 * $temp2;
+ }
- my $rem = ( $sum % 11 );
- $rem = 'X' if $rem == 10;
+ my $rem = ( $sum % 11 );
+ $rem = 'X' if $rem == 10;
- $cardnumber = "V$cardnumber$rem";
- }
- else {
+ return "V$cardnumber$rem";
+ } else {
# MODIFIED BY JF: mysql4.1 allows casting as an integer, which is probably
# better. I'll leave the original in in case it needs to be changed for you
- my $sth =
- $dbh->prepare(
- "select max(cast(cardnumber as signed)) from borrowers");
-
- #my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers");
-
- $sth->execute;
-
- my ($result) = $sth->fetchrow;
- $sth->finish;
- $cardnumber = $result + 1;
- }
+ # my $sth=$dbh->prepare("select max(borrowers.cardnumber) from borrowers");
+ my $sth = $dbh->prepare(
+ "select max(cast(cardnumber as signed)) from borrowers"
+ );
+ $sth->execute;
+ my ($result) = $sth->fetchrow;
+ return $result + 1;
}
- return $cardnumber;
+ return $cardnumber; # just here as a fallback/reminder
}
=head2 GetGuarantees
&UpdateGuarantees($parent_borrno);
-C<&UpdateGuarantees> borrower data for an adulte and updates all the guarantees
+C<&UpdateGuarantees> borrower data for an adult and updates all the guarantees
with the modified information
=cut
while ( my $data = $sth->fetchrow_hashref ) {
my $biblio = GetBiblioFromItemNumber($data->{itemnumber}) if $data->{itemnumber};
$data->{biblionumber} = $biblio->{biblionumber};
+ $data->{title} = $biblio->{title};
$acctlines[$numlines] = $data;
$numlines++;
- $total += $data->{'amountoutstanding'};
+ $total += int(100 * $data->{'amountoutstanding'}); # convert float to integer to avoid round-off errors
}
+ $total /= 100;
$sth->finish;
return ( $total, \@acctlines,$numlines);
}
while ( my $data = $sth->fetchrow_hashref ) {
$acctlines[$numlines] = $data;
$numlines++;
- $total += $data->{'amountoutstanding'};
+ $total += int(100 * $data->{'amountoutstanding'});
}
+ $total /= 100;
$sth->finish;
return ( $total, \@acctlines, $numlines );
}
my $dbh = C4::Context->dbh;
my $request = ($collectivity) ?
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? " :
- "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
+ ($dateofbirth) ?
+ "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=? and dateofbirth=?" :
+ "SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?";
my $sth = $dbh->prepare($request);
if ($collectivity) {
$sth->execute( uc($surname) );
- } else {
- if($dateofbirth){
- $request .= " and dateofbirth=?";
- $sth->execute( uc($surname), ucfirst($firstname), $dateofbirth );
- }else{
- $sth->execute( uc($surname), ucfirst($firstname));
- }
+ } elsif($dateofbirth){
+ $sth->execute( uc($surname), ucfirst($firstname), $dateofbirth );
+ }else{
+ $sth->execute( uc($surname), ucfirst($firstname));
}
my @data = $sth->fetchrow;
$sth->finish;
return ($sortvalue) unless ($lib);
}
-=head2 DeleteBorrower
+=head2 MoveMemberToDeleted
- () = &DeleteBorrower($member);
+ $result = &MoveMemberToDeleted($borrowernumber);
-delete all data fo borrowers and add record to deletedborrowers table
-C<&$member>this is the borrowernumber
+Copy the record from borrowers to deletedborrowers table.
=cut
+# FIXME: should do it in one SQL statement w/ subquery
+# Otherwise, we should return the @data on success
+
sub MoveMemberToDeleted {
- my ($member) = @_;
+ my ($member) = shift or return;
my $dbh = C4::Context->dbh;
- my $query;
- $query = qq|SELECT *
+ my $query = qq|SELECT *
FROM borrowers
WHERE borrowernumber=?|;
my $sth = $dbh->prepare($query);
$sth->execute($member);
my @data = $sth->fetchrow_array;
- $sth->finish;
+ (@data) or return; # if we got a bad borrowernumber, there's nothing to insert
$sth =
$dbh->prepare( "INSERT INTO deletedborrowers VALUES ("
. ( "?," x ( scalar(@data) - 1 ) )
. "?)" );
$sth->execute(@data);
- $sth->finish;
}
=head2 DelMember
sub ExtendMemberSubscriptionTo {
my ( $borrowerid,$date) = @_;
my $dbh = C4::Context->dbh;
- my $borrower = GetMember($borrowerid,'borrowernumber');
+ my $borrower = GetMember(borrowernumber=>$borrowerid);
unless ($date){
$date=POSIX::strftime("%Y-%m-%d",localtime());
- my $borrower = GetMember($borrowerid,'borrowernumber');
$date = GetExpiryDate( $borrower->{'categorycode'}, $date );
}
my $sth = $dbh->do(<<EOF);
$sth = $dbh->prepare("SELECT enrolmentfee FROM categories WHERE categorycode=?");
$sth->execute($borrower->{'categorycode'});
my ($enrolmentfee) = $sth->fetchrow;
- if ($enrolmentfee) {
+ if ($enrolmentfee && $enrolmentfee > 0) {
# insert fee in patron debts
manualinvoice($borrower->{'borrowernumber'}, '', '', 'A', $enrolmentfee);
}
my $sth = $dbh->prepare($query);
$sth->execute($cardnumber);
my $imagedata = $sth->fetchrow_hashref;
- my $dberror = $sth->errstr;
warn "Database error!" if $sth->errstr;
- $sth->finish;
- return $imagedata, $dberror;
+ return $imagedata, $sth->errstr;
}
=head2 PutPatronImage
my $sth = $dbh->prepare($query);
$sth->execute($cardnumber,$mimetype,$imgfile,$imgfile);
warn "Error returned inserting $cardnumber.$mimetype." if $sth->errstr;
- my $dberror = $sth->errstr;
- $sth->finish;
- return $dberror;
+ return $sth->errstr;
}
=head2 RmPatronImage
$sth->execute($cardnumber);
my $dberror = $sth->errstr;
warn "Database error!" if $sth->errstr;
- $sth->finish;
return $dberror;
}
my $filterbranch = shift ||
((C4::Context->preference('IndependantBranches')
&& C4::Context->userenv
- && C4::Context->userenv->{flags}!=1
+ && C4::Context->userenv->{flags} % 2 !=1
&& C4::Context->userenv->{branch})
? C4::Context->userenv->{branch}
: "");
my $filterbranch = shift ||
((C4::Context->preference('IndependantBranches')
&& C4::Context->userenv
- && C4::Context->userenv->{flags}!=1
+ && C4::Context->userenv->{flags} % 2 !=1
&& C4::Context->userenv->{branch})
? C4::Context->userenv->{branch}
: "");
my $filterbranch = shift ||
((C4::Context->preference('IndependantBranches')
&& C4::Context->userenv
- && C4::Context->userenv->{flags}!=1
+ && C4::Context->userenv->{flags} % 2 !=1
&& C4::Context->userenv->{branch})
? C4::Context->userenv->{branch}
: "");
}
+=head2 IsMemberBlocked
+
+=over 4
+
+my $blocked = IsMemberBlocked( $borrowernumber );
+
+return the status, and the number of day or documents, depends his punishment
+
+return :
+-1 if the user have overdue returns
+1 if the user is punished X days
+0 if the user is authorised to loan
+
+=back
+
+=cut
+
+sub IsMemberBlocked {
+ my $borrowernumber = shift;
+ my $dbh = C4::Context->dbh;
+ # if he have late issues
+ my $sth = $dbh->prepare(
+ "SELECT COUNT(*) as latedocs
+ FROM issues
+ WHERE borrowernumber = ?
+ AND date_due < now()"
+ );
+ $sth->execute($borrowernumber);
+ my $latedocs = $sth->fetchrow_hashref->{'latedocs'};
+ $sth->finish();
+
+ return (-1, $latedocs) if $latedocs > 0;
+
+ # or if he must wait to loan
+ if(C4::Context->preference("item-level_itypes")){
+ $sth = $dbh->prepare(
+ "SELECT
+ ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due) ) AS blockingdate,
+ DATEDIFF(ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due)),NOW()) AS blockedcount
+ FROM old_issues
+ LEFT JOIN items ON (items.itemnumber=old_issues.itemnumber)
+ LEFT JOIN issuingrules ON (issuingrules.itemtype=items.itype)
+ WHERE finedays IS NOT NULL
+ AND date_due < returndate
+ AND borrowernumber = ?
+ ORDER BY blockingdate DESC
+ LIMIT 1"
+ );
+ }else{
+ $sth = $dbh->prepare(
+ "SELECT
+ ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due) ) AS blockingdate,
+ DATEDIFF(ADDDATE(returndate, finedays * DATEDIFF(returndate,date_due)),NOW()) AS blockedcount
+ FROM old_issues
+ LEFT JOIN items ON (items.itemnumber=old_issues.itemnumber)
+ LEFT JOIN biblioitems ON (biblioitems.biblioitemnumber=items.biblioitemnumber)
+ LEFT JOIN issuingrules ON (issuingrules.itemtype=biblioitems.itemtype)
+ WHERE finedays IS NOT NULL
+ AND date_due < returndate
+ AND borrowernumber = ?
+ ORDER BY blockingdate DESC
+ LIMIT 1"
+ );
+ }
+ $sth->execute($borrowernumber);
+ my $row = $sth->fetchrow_hashref;
+ my $blockeddate = $row->{'blockeddate'};
+ my $blockedcount = $row->{'blockedcount'};
+ $sth->finish();
+
+ return (1, $blockedcount) if $blockedcount > 0;
+
+ return 0
+}
+
END { } # module clean-up code here (global destructor)
1;