|
Lines 25-30
use strict;
Link Here
|
| 25 |
use C4::Context; |
25 |
use C4::Context; |
| 26 |
use C4::Dates qw(format_date_in_iso format_date); |
26 |
use C4::Dates qw(format_date_in_iso format_date); |
| 27 |
use String::Random qw( random_string ); |
27 |
use String::Random qw( random_string ); |
|
|
28 |
use Clone qw(clone); |
| 28 |
use Date::Calc qw/Today Add_Delta_YM check_date Date_to_Days/; |
29 |
use Date::Calc qw/Today Add_Delta_YM check_date Date_to_Days/; |
| 29 |
use C4::Log; # logaction |
30 |
use C4::Log; # logaction |
| 30 |
use C4::Overdues; |
31 |
use C4::Overdues; |
|
Lines 41-47
use Koha::DateUtils;
Link Here
|
| 41 |
use Koha::Borrower::Debarments qw(IsDebarred); |
42 |
use Koha::Borrower::Debarments qw(IsDebarred); |
| 42 |
use Text::Unaccent qw( unac_string ); |
43 |
use Text::Unaccent qw( unac_string ); |
| 43 |
use Koha::AuthUtils qw(hash_password); |
44 |
use Koha::AuthUtils qw(hash_password); |
| 44 |
|
45 |
use C4::Branch qw( GetIndependentGroupModificationRights ); |
| 45 |
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug); |
46 |
our ($VERSION,@ISA,@EXPORT,@EXPORT_OK,$debug); |
| 46 |
|
47 |
|
| 47 |
BEGIN { |
48 |
BEGIN { |
|
Lines 257-281
sub Search {
Link Here
|
| 257 |
# $showallbranches was not used at the time SearchMember() was mainstreamed into Search(). |
258 |
# $showallbranches was not used at the time SearchMember() was mainstreamed into Search(). |
| 258 |
# Mentioning for the reference |
259 |
# Mentioning for the reference |
| 259 |
|
260 |
|
| 260 |
if ( C4::Context->preference("IndependentBranches") ) { # && !$showallbranches){ |
261 |
if ( C4::Context->preference("IndependentBranches") ) { |
| 261 |
if ( my $userenv = C4::Context->userenv ) { |
262 |
unless ( C4::Context->IsSuperLibrarian() ) { |
| 262 |
my $branch = $userenv->{'branch'}; |
263 |
$filter = clone($filter); # Modify a copy only |
| 263 |
if ( !C4::Context->IsSuperLibrarian() && $branch ){ |
264 |
my @branches = GetIndependentGroupModificationRights(); |
| 264 |
if (my $fr = ref $filter) { |
265 |
if ( my $fr = ref $filter ) { |
| 265 |
if ( $fr eq "HASH" ) { |
266 |
if ( $fr eq "HASH" ) { |
| 266 |
$filter->{branchcode} = $branch; |
267 |
$filter->{branchcode} = \@branches; |
| 267 |
} |
|
|
| 268 |
else { |
| 269 |
foreach (@$filter) { |
| 270 |
$_ = { '' => $_ } unless ref $_; |
| 271 |
$_->{branchcode} = $branch; |
| 272 |
} |
| 273 |
} |
| 274 |
} |
268 |
} |
| 275 |
else { |
269 |
else { |
| 276 |
$filter = { '' => $filter, branchcode => $branch }; |
270 |
foreach (@$filter) { |
|
|
271 |
$_ = { '' => $_ } unless ref $_; |
| 272 |
$_->{branchcode} = \@branches; |
| 273 |
} |
| 277 |
} |
274 |
} |
| 278 |
} |
275 |
} |
|
|
276 |
else { |
| 277 |
$filter = { '' => $filter, branchcode => \@branches }; |
| 278 |
} |
| 279 |
} |
279 |
} |
| 280 |
} |
280 |
} |
| 281 |
|
281 |
|
|
Lines 1313-1318
sub checkuniquemember {
Link Here
|
| 1313 |
($dateofbirth) ? |
1313 |
($dateofbirth) ? |
| 1314 |
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=? and dateofbirth=?" : |
1314 |
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=? and dateofbirth=?" : |
| 1315 |
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?"; |
1315 |
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?"; |
|
|
1316 |
|
| 1317 |
if ( C4::Context->preference('IndependentBranches') ) { |
| 1318 |
my $branches = GetIndependentGroupModificationRights( { stringify => 1 } ); |
| 1319 |
$request .= " AND branchcode IN ( $branches )"; |
| 1320 |
} |
| 1321 |
|
| 1316 |
my $sth = $dbh->prepare($request); |
1322 |
my $sth = $dbh->prepare($request); |
| 1317 |
if ($collectivity) { |
1323 |
if ($collectivity) { |
| 1318 |
$sth->execute( uc($surname) ); |
1324 |
$sth->execute( uc($surname) ); |
|
Lines 1976-1988
sub GetBorrowersToExpunge {
Link Here
|
| 1976 |
my $filterdate = $params->{'not_borrowered_since'}; |
1982 |
my $filterdate = $params->{'not_borrowered_since'}; |
| 1977 |
my $filterexpiry = $params->{'expired_before'}; |
1983 |
my $filterexpiry = $params->{'expired_before'}; |
| 1978 |
my $filtercategory = $params->{'category_code'}; |
1984 |
my $filtercategory = $params->{'category_code'}; |
| 1979 |
my $filterbranch = $params->{'branchcode'} || |
1985 |
my $filterbranch = $params->{'branchcode'}; |
| 1980 |
((C4::Context->preference('IndependentBranches') |
1986 |
my @filterbranches = |
| 1981 |
&& C4::Context->userenv |
1987 |
( C4::Context->preference('IndependentBranches') |
| 1982 |
&& !C4::Context->IsSuperLibrarian() |
1988 |
&& C4::Context->userenv |
| 1983 |
&& C4::Context->userenv->{branch}) |
1989 |
&& !C4::Context->IsSuperLibrarian() |
| 1984 |
? C4::Context->userenv->{branch} |
1990 |
&& C4::Context->userenv->{branch} ) |
| 1985 |
: ""); |
1991 |
? GetIndependentGroupModificationRights() |
|
|
1992 |
: ($filterbranch); |
| 1986 |
|
1993 |
|
| 1987 |
my $dbh = C4::Context->dbh; |
1994 |
my $dbh = C4::Context->dbh; |
| 1988 |
my $query = " |
1995 |
my $query = " |
|
Lines 1997-2005
sub GetBorrowersToExpunge {
Link Here
|
| 1997 |
AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0) |
2004 |
AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0) |
| 1998 |
"; |
2005 |
"; |
| 1999 |
my @query_params; |
2006 |
my @query_params; |
| 2000 |
if ( $filterbranch && $filterbranch ne "" ) { |
2007 |
if ( @filterbranches ) { |
| 2001 |
$query.= " AND borrowers.branchcode = ? "; |
2008 |
my $placeholders = join( ',', ('?') x @filterbranches ); |
| 2002 |
push( @query_params, $filterbranch ); |
2009 |
$query.= " AND borrowers.branchcode IN ( $placeholders )"; |
|
|
2010 |
push( @query_params, @filterbranches ); |
| 2003 |
} |
2011 |
} |
| 2004 |
if ( $filterexpiry ) { |
2012 |
if ( $filterexpiry ) { |
| 2005 |
$query .= " AND dateexpiry < ? "; |
2013 |
$query .= " AND dateexpiry < ? "; |
|
Lines 2042-2054
I<$result> is a ref to an array which all elements are a hasref.
Link Here
|
| 2042 |
=cut |
2050 |
=cut |
| 2043 |
|
2051 |
|
| 2044 |
sub GetBorrowersWhoHaveNeverBorrowed { |
2052 |
sub GetBorrowersWhoHaveNeverBorrowed { |
| 2045 |
my $filterbranch = shift || |
2053 |
my $filterbranch = shift; |
| 2046 |
((C4::Context->preference('IndependentBranches') |
2054 |
|
| 2047 |
&& C4::Context->userenv |
2055 |
my @filterbranches = |
| 2048 |
&& !C4::Context->IsSuperLibrarian() |
2056 |
( C4::Context->preference('IndependentBranches') |
| 2049 |
&& C4::Context->userenv->{branch}) |
2057 |
&& C4::Context->userenv |
| 2050 |
? C4::Context->userenv->{branch} |
2058 |
&& !C4::Context->IsSuperLibrarian() |
| 2051 |
: ""); |
2059 |
&& C4::Context->userenv->{branch} ) |
|
|
2060 |
? GetIndependentGroupModificationRights() |
| 2061 |
: ($filterbranch); |
| 2062 |
|
| 2052 |
my $dbh = C4::Context->dbh; |
2063 |
my $dbh = C4::Context->dbh; |
| 2053 |
my $query = " |
2064 |
my $query = " |
| 2054 |
SELECT borrowers.borrowernumber,max(timestamp) as latestissue |
2065 |
SELECT borrowers.borrowernumber,max(timestamp) as latestissue |
|
Lines 2056-2065
sub GetBorrowersWhoHaveNeverBorrowed {
Link Here
|
| 2056 |
LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber |
2067 |
LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber |
| 2057 |
WHERE issues.borrowernumber IS NULL |
2068 |
WHERE issues.borrowernumber IS NULL |
| 2058 |
"; |
2069 |
"; |
|
|
2070 |
|
| 2059 |
my @query_params; |
2071 |
my @query_params; |
| 2060 |
if ($filterbranch && $filterbranch ne ""){ |
2072 |
if (@filterbranches) { |
| 2061 |
$query.=" AND borrowers.branchcode= ?"; |
2073 |
my $placeholders = join( ',', ('?') x @filterbranches ); |
| 2062 |
push @query_params,$filterbranch; |
2074 |
$query .= " AND borrowers.branchcode IN ( $placeholders ) "; |
|
|
2075 |
push( @query_params, @filterbranches ); |
| 2063 |
} |
2076 |
} |
| 2064 |
warn $query if $debug; |
2077 |
warn $query if $debug; |
| 2065 |
|
2078 |
|
|
Lines 2092-2116
This hashref is containt the number of time this borrowers has borrowed before I
Link Here
|
| 2092 |
sub GetBorrowersWithIssuesHistoryOlderThan { |
2105 |
sub GetBorrowersWithIssuesHistoryOlderThan { |
| 2093 |
my $dbh = C4::Context->dbh; |
2106 |
my $dbh = C4::Context->dbh; |
| 2094 |
my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime()); |
2107 |
my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime()); |
| 2095 |
my $filterbranch = shift || |
2108 |
my $filterbranch = shift; |
| 2096 |
((C4::Context->preference('IndependentBranches') |
2109 |
|
| 2097 |
&& C4::Context->userenv |
2110 |
my @filterbranches = |
| 2098 |
&& !C4::Context->IsSuperLibrarian() |
2111 |
( C4::Context->preference('IndependentBranches') |
| 2099 |
&& C4::Context->userenv->{branch}) |
2112 |
&& C4::Context->userenv |
| 2100 |
? C4::Context->userenv->{branch} |
2113 |
&& !C4::Context->IsSuperLibrarian() |
| 2101 |
: ""); |
2114 |
&& C4::Context->userenv->{branch} ) |
|
|
2115 |
? GetIndependentGroupModificationRights() |
| 2116 |
: ($filterbranch); |
| 2117 |
|
| 2102 |
my $query = " |
2118 |
my $query = " |
| 2103 |
SELECT count(borrowernumber) as n,borrowernumber |
2119 |
SELECT count(borrowernumber) as n,borrowernumber |
| 2104 |
FROM old_issues |
2120 |
FROM old_issues |
| 2105 |
WHERE returndate < ? |
2121 |
WHERE returndate < ? |
| 2106 |
AND borrowernumber IS NOT NULL |
2122 |
AND borrowernumber IS NOT NULL |
| 2107 |
"; |
2123 |
"; |
|
|
2124 |
|
| 2108 |
my @query_params; |
2125 |
my @query_params; |
| 2109 |
push @query_params, $date; |
2126 |
push( @query_params, $date ); |
| 2110 |
if ($filterbranch){ |
2127 |
|
| 2111 |
$query.=" AND branchcode = ?"; |
2128 |
if (@filterbranches) { |
| 2112 |
push @query_params, $filterbranch; |
2129 |
my $placeholders = join( ',', ('?') x @filterbranches ); |
| 2113 |
} |
2130 |
$query .= " AND branchcode IN ( $placeholders ) "; |
|
|
2131 |
push( @query_params, @filterbranches ); |
| 2132 |
} |
| 2133 |
|
| 2114 |
$query.=" GROUP BY borrowernumber "; |
2134 |
$query.=" GROUP BY borrowernumber "; |
| 2115 |
warn $query if $debug; |
2135 |
warn $query if $debug; |
| 2116 |
my $sth = $dbh->prepare($query); |
2136 |
my $sth = $dbh->prepare($query); |