&GetSortDetails
&GetTitles
- &GetPatronImage
- &PutPatronImage
- &RmPatronImage
+ &GetPatronImage
+ &PutPatronImage
+ &RmPatronImage
&GetMemberAccountRecords
&GetBorNotifyAcctRecord
&GetBorrowersWhoHaveNotBorrowedSince($date)
this function get all borrowers who haven't borrowed since the date given on input arg.
-
+
=cut
sub GetBorrowersWhoHaveNotBorrowedSince {
- my $date = shift;
- return unless $date; # date is mandatory.
+### TODO : It could be dangerous to delete Borrowers who have just been entered and who have not yet borrowed any book. May be good to add a dateexpiry or dateenrolled filter.
+
+ my $filterdate = shift||POSIX::strftime("%Y-%m-%d",localtime());
+ my $filterbranch = shift ||
+ ((C4::Context->preference('IndependantBranches')
+ && C4::Context->userenv
+ && C4::Context->userenv->{flags}!=1
+ && C4::Context->userenv->{branch})
+ ? C4::Context->userenv->{branch}
+ : "");
my $dbh = C4::Context->dbh;
my $query = "
- SELECT borrowers.borrowernumber,max(timestamp)
+ SELECT borrowers.borrowernumber,max(issues.timestamp) as latestissue
FROM borrowers
LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
- WHERE issues.borrowernumber IS NOT NULL
- GROUP BY borrowers.borrowernumber
";
+ my @query_params;
+ if ($filterbranch && $filterbranch ne ""){
+ $query.=" WHERE branchcode= ?";
+ push @query_params,$filterbranch;
+ }
+ $query.=" GROUP BY borrowers.borrowernumber";
+ if ($filterdate){
+ $query.=" HAVING latestissue <? OR latestissue IS NULL";
+ push @query_params,$filterdate;
+ }
+ warn $query;
my $sth = $dbh->prepare($query);
- $sth->execute;
+ if (scalar(@query_params)>0){
+ $sth->execute(@query_params);
+ }
+ else {
+ $sth->execute;
+ }
+
my @results;
-
while ( my $data = $sth->fetchrow_hashref ) {
push @results, $data;
}
=cut
sub GetBorrowersWhoHaveNeverBorrowed {
+ my $filterbranch = shift ||
+ ((C4::Context->preference('IndependantBranches')
+ && C4::Context->userenv
+ && C4::Context->userenv->{flags}!=1
+ && C4::Context->userenv->{branch})
+ ? C4::Context->userenv->{branch}
+ : "");
my $dbh = C4::Context->dbh;
my $query = "
- SELECT borrowers.borrowernumber,max(timestamp)
+ SELECT borrowers.borrowernumber,max(timestamp) as latestissue
FROM borrowers
LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
WHERE issues.borrowernumber IS NULL
";
+ my @query_params;
+ if ($filterbranch && $filterbranch ne ""){
+ $query.=" AND branchcode= ?";
+ push @query_params,$filterbranch;
+ }
+ warn $query;
+
my $sth = $dbh->prepare($query);
- $sth->execute;
+ if (scalar(@query_params)>0){
+ $sth->execute(@query_params);
+ }
+ else {
+ $sth->execute;
+ }
+
my @results;
while ( my $data = $sth->fetchrow_hashref ) {
push @results, $data;
sub GetBorrowersWithIssuesHistoryOlderThan {
my $dbh = C4::Context->dbh;
- my $date = shift;
- return unless $date; # date is mandatory.
+ my $date = shift ||POSIX::strftime("%Y-%m-%d",localtime());
+ my $filterbranch = shift ||
+ ((C4::Context->preference('IndependantBranches')
+ && C4::Context->userenv
+ && C4::Context->userenv->{flags}!=1
+ && C4::Context->userenv->{branch})
+ ? C4::Context->userenv->{branch}
+ : "");
my $query = "
SELECT count(borrowernumber) as n,borrowernumber
FROM old_issues
WHERE returndate < ?
AND borrowernumber IS NOT NULL
- GROUP BY borrowernumber
- ";
+ ";
+ if ($filterbranch){
+ $query.=" AND branchcode=\'$filterbranch\'";
+ }
+ $query.=" GROUP BY borrowernumber ";
+ warn $query;
my $sth = $dbh->prepare($query);
$sth->execute($date);
my @results;
return \@results;
}
+=head2 GetBorrowersNamesAndLatestIssue
+
+$results = &GetBorrowersNamesAndLatestIssueList(@borrowernumbers)
+
+this function get borrowers Names and surnames and Issue information.
+
+I<@borrowernumbers> is an array which all elements are borrowernumbers.
+This hashref is containt the number of time this borrowers has borrowed before I<$date> and the borrowernumber.
+
+=cut
+
+sub GetBorrowersNamesAndLatestIssue {
+ my $dbh = C4::Context->dbh;
+ my @borrowernumbers=@_;
+ my $query = "
+ SELECT surname,lastname, phone, email,max(timestamp)
+ FROM borrowers
+ LEFT JOIN issues ON borrowers.borrowernumber=issues.borrowernumber
+ GROUP BY borrowernumber
+ ";
+ my $sth = $dbh->prepare($query);
+ $sth->execute;
+ my $results = $sth->fetchall_arrayref({});
+ return $results;
+}
END { } # module clean-up code here (global destructor)
1;
my $checkbox = $params->{'checkbox'};
my $totalDel;
+ my $membersToDelete;
if ($checkbox eq "borrower") {
- my $membersToDelete = GetBorrowersWhoHaveNotBorrowedSince($filterdate1);
+ $membersToDelete = GetBorrowersWhoHaveNotBorrowedSince($filterdate1);
$totalDel = scalar @$membersToDelete;
+
}
-
my $totalAno;
+ my $membersToAnonymize;
if ($checkbox eq "issue") {
- my $membersToAnonymize =
+ $membersToAnonymize =
GetBorrowersWithIssuesHistoryOlderThan($filterdate2);
$totalAno = scalar @$membersToAnonymize;
}
step2 => 1,
totalToDelete => $totalDel,
totalToAnonymize => $totalAno,
+ memberstodelete_list => $membersToDelete,
+ memberstoanonymize_list => $membersToAnonymize,
filterdate1 => format_date($filterdate1),
filterdate2 => format_date($filterdate2),
);
-
+### TODO : Use GetBorrowersNamesAndLatestIssue function in order to get the borrowers to delete or anonymize.
+### Now, we are only using total, which is not enough imlo
#writing the template
output_html_with_http_headers $cgi, $cookie, $template->output;
exit;