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 259-283
sub Search {
Link Here
|
259 |
# $showallbranches was not used at the time SearchMember() was mainstreamed into Search(). |
260 |
# $showallbranches was not used at the time SearchMember() was mainstreamed into Search(). |
260 |
# Mentioning for the reference |
261 |
# Mentioning for the reference |
261 |
|
262 |
|
262 |
if ( C4::Context->preference("IndependentBranches") ) { # && !$showallbranches){ |
263 |
if ( C4::Context->preference("IndependentBranches") ) { |
263 |
if ( my $userenv = C4::Context->userenv ) { |
264 |
unless ( C4::Context->IsSuperLibrarian() ) { |
264 |
my $branch = $userenv->{'branch'}; |
265 |
$filter = clone($filter); # Modify a copy only |
265 |
if ( !C4::Context->IsSuperLibrarian() && $branch ){ |
266 |
my @branches = GetIndependentGroupModificationRights(); |
266 |
if (my $fr = ref $filter) { |
267 |
if ( my $fr = ref $filter ) { |
267 |
if ( $fr eq "HASH" ) { |
268 |
if ( $fr eq "HASH" ) { |
268 |
$filter->{branchcode} = $branch; |
269 |
$filter->{branchcode} = \@branches; |
269 |
} |
|
|
270 |
else { |
271 |
foreach (@$filter) { |
272 |
$_ = { '' => $_ } unless ref $_; |
273 |
$_->{branchcode} = $branch; |
274 |
} |
275 |
} |
276 |
} |
270 |
} |
277 |
else { |
271 |
else { |
278 |
$filter = { '' => $filter, branchcode => $branch }; |
272 |
foreach (@$filter) { |
|
|
273 |
$_ = { '' => $_ } unless ref $_; |
274 |
$_->{branchcode} = \@branches; |
275 |
} |
279 |
} |
276 |
} |
280 |
} |
277 |
} |
|
|
278 |
else { |
279 |
$filter = { '' => $filter, branchcode => \@branches }; |
280 |
} |
281 |
} |
281 |
} |
282 |
} |
282 |
} |
283 |
|
283 |
|
Lines 1315-1320
sub checkuniquemember {
Link Here
|
1315 |
($dateofbirth) ? |
1315 |
($dateofbirth) ? |
1316 |
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=? and dateofbirth=?" : |
1316 |
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=? and dateofbirth=?" : |
1317 |
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?"; |
1317 |
"SELECT borrowernumber,categorycode FROM borrowers WHERE surname=? and firstname=?"; |
|
|
1318 |
|
1319 |
if ( C4::Context->preference('IndependentBranches') ) { |
1320 |
my $branches = GetIndependentGroupModificationRights( { stringify => 1 } ); |
1321 |
$request .= " AND branchcode IN ( $branches )"; |
1322 |
} |
1323 |
|
1318 |
my $sth = $dbh->prepare($request); |
1324 |
my $sth = $dbh->prepare($request); |
1319 |
if ($collectivity) { |
1325 |
if ($collectivity) { |
1320 |
$sth->execute( uc($surname) ); |
1326 |
$sth->execute( uc($surname) ); |
Lines 2043-2055
sub GetBorrowersToExpunge {
Link Here
|
2043 |
my $filterdate = $params->{'not_borrowered_since'}; |
2049 |
my $filterdate = $params->{'not_borrowered_since'}; |
2044 |
my $filterexpiry = $params->{'expired_before'}; |
2050 |
my $filterexpiry = $params->{'expired_before'}; |
2045 |
my $filtercategory = $params->{'category_code'}; |
2051 |
my $filtercategory = $params->{'category_code'}; |
2046 |
my $filterbranch = $params->{'branchcode'} || |
2052 |
my $filterbranch = $params->{'branchcode'}; |
2047 |
((C4::Context->preference('IndependentBranches') |
2053 |
my @filterbranches = |
2048 |
&& C4::Context->userenv |
2054 |
( C4::Context->preference('IndependentBranches') |
2049 |
&& !C4::Context->IsSuperLibrarian() |
2055 |
&& C4::Context->userenv |
2050 |
&& C4::Context->userenv->{branch}) |
2056 |
&& !C4::Context->IsSuperLibrarian() |
2051 |
? C4::Context->userenv->{branch} |
2057 |
&& C4::Context->userenv->{branch} ) |
2052 |
: ""); |
2058 |
? GetIndependentGroupModificationRights() |
|
|
2059 |
: ($filterbranch); |
2053 |
|
2060 |
|
2054 |
my $dbh = C4::Context->dbh; |
2061 |
my $dbh = C4::Context->dbh; |
2055 |
my $query = " |
2062 |
my $query = " |
Lines 2064-2072
sub GetBorrowersToExpunge {
Link Here
|
2064 |
AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0) |
2071 |
AND borrowernumber NOT IN (SELECT guarantorid FROM borrowers WHERE guarantorid IS NOT NULL AND guarantorid <> 0) |
2065 |
"; |
2072 |
"; |
2066 |
my @query_params; |
2073 |
my @query_params; |
2067 |
if ( $filterbranch && $filterbranch ne "" ) { |
2074 |
if ( @filterbranches ) { |
2068 |
$query.= " AND borrowers.branchcode = ? "; |
2075 |
my $placeholders = join( ',', ('?') x @filterbranches ); |
2069 |
push( @query_params, $filterbranch ); |
2076 |
$query.= " AND borrowers.branchcode IN ( $placeholders )"; |
|
|
2077 |
push( @query_params, @filterbranches ); |
2070 |
} |
2078 |
} |
2071 |
if ( $filterexpiry ) { |
2079 |
if ( $filterexpiry ) { |
2072 |
$query .= " AND dateexpiry < ? "; |
2080 |
$query .= " AND dateexpiry < ? "; |
Lines 2109-2121
I<$result> is a ref to an array which all elements are a hasref.
Link Here
|
2109 |
=cut |
2117 |
=cut |
2110 |
|
2118 |
|
2111 |
sub GetBorrowersWhoHaveNeverBorrowed { |
2119 |
sub GetBorrowersWhoHaveNeverBorrowed { |
2112 |
my $filterbranch = shift || |
2120 |
my $filterbranch = shift; |
2113 |
((C4::Context->preference('IndependentBranches') |
2121 |
|
2114 |
&& C4::Context->userenv |
2122 |
my @filterbranches = |
2115 |
&& !C4::Context->IsSuperLibrarian() |
2123 |
( C4::Context->preference('IndependentBranches') |
2116 |
&& C4::Context->userenv->{branch}) |
2124 |
&& C4::Context->userenv |
2117 |
? C4::Context->userenv->{branch} |
2125 |
&& !C4::Context->IsSuperLibrarian() |
2118 |
: ""); |
2126 |
&& C4::Context->userenv->{branch} ) |
|
|
2127 |
? GetIndependentGroupModificationRights() |
2128 |
: ($filterbranch); |
2129 |
|
2119 |
my $dbh = C4::Context->dbh; |
2130 |
my $dbh = C4::Context->dbh; |
2120 |
my $query = " |
2131 |
my $query = " |
2121 |
SELECT borrowers.borrowernumber,max(timestamp) as latestissue |
2132 |
SELECT borrowers.borrowernumber,max(timestamp) as latestissue |
Lines 2123-2132
sub GetBorrowersWhoHaveNeverBorrowed {
Link Here
|
2123 |
LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber |
2134 |
LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber |
2124 |
WHERE issues.borrowernumber IS NULL |
2135 |
WHERE issues.borrowernumber IS NULL |
2125 |
"; |
2136 |
"; |
|
|
2137 |
|
2126 |
my @query_params; |
2138 |
my @query_params; |
2127 |
if ($filterbranch && $filterbranch ne ""){ |
2139 |
if (@filterbranches) { |
2128 |
$query.=" AND borrowers.branchcode= ?"; |
2140 |
my $placeholders = join( ',', ('?') x @filterbranches ); |
2129 |
push @query_params,$filterbranch; |
2141 |
$query .= " AND borrowers.branchcode IN ( $placeholders ) "; |
|
|
2142 |
push( @query_params, @filterbranches ); |
2130 |
} |
2143 |
} |
2131 |
warn $query if $debug; |
2144 |
warn $query if $debug; |
2132 |
|
2145 |
|
Lines 2159-2183
This hashref is containt the number of time this borrowers has borrowed before I
Link Here
|
2159 |
sub GetBorrowersWithIssuesHistoryOlderThan { |
2172 |
sub GetBorrowersWithIssuesHistoryOlderThan { |
2160 |
my $dbh = C4::Context->dbh; |
2173 |
my $dbh = C4::Context->dbh; |
2161 |
my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime()); |
2174 |
my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime()); |
2162 |
my $filterbranch = shift || |
2175 |
my $filterbranch = shift; |
2163 |
((C4::Context->preference('IndependentBranches') |
2176 |
|
2164 |
&& C4::Context->userenv |
2177 |
my @filterbranches = |
2165 |
&& !C4::Context->IsSuperLibrarian() |
2178 |
( C4::Context->preference('IndependentBranches') |
2166 |
&& C4::Context->userenv->{branch}) |
2179 |
&& C4::Context->userenv |
2167 |
? C4::Context->userenv->{branch} |
2180 |
&& !C4::Context->IsSuperLibrarian() |
2168 |
: ""); |
2181 |
&& C4::Context->userenv->{branch} ) |
|
|
2182 |
? GetIndependentGroupModificationRights() |
2183 |
: ($filterbranch); |
2184 |
|
2169 |
my $query = " |
2185 |
my $query = " |
2170 |
SELECT count(borrowernumber) as n,borrowernumber |
2186 |
SELECT count(borrowernumber) as n,borrowernumber |
2171 |
FROM old_issues |
2187 |
FROM old_issues |
2172 |
WHERE returndate < ? |
2188 |
WHERE returndate < ? |
2173 |
AND borrowernumber IS NOT NULL |
2189 |
AND borrowernumber IS NOT NULL |
2174 |
"; |
2190 |
"; |
|
|
2191 |
|
2175 |
my @query_params; |
2192 |
my @query_params; |
2176 |
push @query_params, $date; |
2193 |
push( @query_params, $date ); |
2177 |
if ($filterbranch){ |
2194 |
|
2178 |
$query.=" AND branchcode = ?"; |
2195 |
if (@filterbranches) { |
2179 |
push @query_params, $filterbranch; |
2196 |
my $placeholders = join( ',', ('?') x @filterbranches ); |
2180 |
} |
2197 |
$query .= " AND branchcode IN ( $placeholders ) "; |
|
|
2198 |
push( @query_params, @filterbranches ); |
2199 |
} |
2200 |
|
2181 |
$query.=" GROUP BY borrowernumber "; |
2201 |
$query.=" GROUP BY borrowernumber "; |
2182 |
warn $query if $debug; |
2202 |
warn $query if $debug; |
2183 |
my $sth = $dbh->prepare($query); |
2203 |
my $sth = $dbh->prepare($query); |