[Koha-cvs] koha/C4 Members.pm [rel_3_0]

Antoine Farnault antoine at koha-fr.org
Fri Nov 17 17:06:51 CET 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch:		rel_3_0
Changes by:	Antoine Farnault <toins>	06/11/17 16:06:51

Modified files:
	C4             : Members.pm 

Log message:
	3 news functions :
	-GetBorrowersWhoHaveNotBorrowedSince
	-GetBorrowersWhoHaveNeverBorrowed
	-GetBorrowersWithIssuesHistoryOlderThan

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Members.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.32.2.17&r2=1.32.2.18

Patches:
Index: Members.pm
===================================================================
RCS file: /sources/koha/koha/C4/Members.pm,v
retrieving revision 1.32.2.17
retrieving revision 1.32.2.18
diff -u -b -r1.32.2.17 -r1.32.2.18
--- Members.pm	17 Nov 2006 14:57:21 -0000	1.32.2.17
+++ Members.pm	17 Nov 2006 16:06:51 -0000	1.32.2.18
@@ -19,7 +19,7 @@
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id: Members.pm,v 1.32.2.17 2006/11/17 14:57:21 tipaul Exp $
+# $Id: Members.pm,v 1.32.2.18 2006/11/17 16:06:51 toins Exp $
 
 use strict;
 require Exporter;
@@ -31,7 +31,7 @@
 
 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
 
-$VERSION = do { my @v = '$Revision: 1.32.2.17 $' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
+$VERSION = do { my @v = '$Revision: 1.32.2.18 $' =~ /\d+/g; shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v ); };
 
 =head1 NAME
 
@@ -69,7 +69,9 @@
  &GetCities &GetRoadTypes &GetRoadTypeDetails &GetBorNotifyAcctRecord
  &GetMembeReregistration
  &GetSortDetails	
- 		
+ &GetBorrowersWhoHaveNotBorrowedSince
+ &GetBorrowersWhoHaveNeverBorrowed
+ &GetBorrowersWithIssuesHistoryOlderThan
 );
 
 
@@ -1502,14 +1504,13 @@
     return ($lib);		
 }
 
-=head2 delmember 
+=head2 DeleteBorrower 
 
-  () = &delmember($member);
+  () = &DeleteBorrower($member);
 
 delete all data fo borrowers and add record to deletedborrowers table
 C<&$member>this is the borrowernumber
 
-
 =cut
 
 sub DeleteBorrower{
@@ -1540,6 +1541,28 @@
   	$sth->finish;
 }
 
+=head2 DelBorrowerCompletly
+
+DelBorrowerCompletly($borrowernumber);
+
+This function remove directly a borrower whitout writing it on deleteborrower.
+
+=cut
+
+sub DelBorrowerCompletly {
+   my $dbh = C4::Context->dbh;
+   my $borrowernumber = shift;
+   return unless $borrowernumber; # date is mandatory.
+   my $query = "
+       DELETE *
+       FROM borrowers
+       WHERE borrowernumber = ?
+   ";
+   my $sth = $dbh->prepare($query);
+   $sth->execute($borrowernumber);
+   return $sth->rows;
+}
+
 =head2 member_reregistration (OUEST-PROVENCE)
 
 automatic reregistration in borrowers table 
@@ -1621,6 +1644,7 @@
 C<&$roadtypeid>this is the value of roadtype s
 
 =cut
+
 sub GetRoadTypeDetails {
     my ($roadtypeid)=@_;
     my $dbh = C4::Context->dbh;
@@ -1633,28 +1657,101 @@
     return ($roadtype);		
 }
 
+=head2 GetBorrowersWhoHaveNotBorrowedSince
 
+&GetBorrowersWhoHaveNotBorrowedSince($date)
 
-=head2 delmember 
-
-  () = &delmember($member);
+this function get all borrowers who haven't borrowed since the date given on input arg.
 
-delete all data fo borrowers and add record to deletedborrowers table
-C<&$member>this is the borrowernumber
+=cut
 
+sub GetBorrowersWhoHaveNotBorrowedSince {
+   my $date = shift;
+   return unless $date; # date is mandatory.
+   my $dbh = C4::Context->dbh;
+   my $query = "
+        SELECT borrowers.borrowernumber,max(timestamp)
+        FROM   borrowers
+          LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
+        WHERE issues.borrowernumber IS NOT NULL
+        GROUP BY borrowers.borrowernumber
+   ";
+   my $sth = $dbh->prepare($query);
+   $sth->execute;
+   my @results;
+   while(my $data = $sth->fetchrow_hashref){
+        push @results,$data;
+   }
+   return \@results;
+}
 
+=head2 GetBorrowersWhoHaveNeverBorrowed
 
+$results = &GetBorrowersWhoHaveNeverBorrowed
 
+this function get all borrowers who have never borrowed.
 
+I<$result> is a ref to an array which all elements are a hasref.
 
+=cut
 
+sub GetBorrowersWhoHaveNeverBorrowed {
+   my $dbh = C4::Context->dbh;
+   my $query = "
+        SELECT borrowers.borrowernumber,max(timestamp)
+        FROM   borrowers
+          LEFT JOIN issues ON borrowers.borrowernumber = issues.borrowernumber
+        WHERE issues.borrowernumber IS NULL
+   ";
+   my $sth = $dbh->prepare($query);
+   $sth->execute;
+   my @results;
+   while(my $data = $sth->fetchrow_hashref){
+        push @results,$data;
+   }
+   return \@results;
+}
 
+=head2 GetBorrowersWithIssuesHistoryOlderThan
 
+$results = &GetBorrowersWithIssuesHistoryOlderThan($date)
 
+this function get all borrowers who an issue history older than I<$date> given on input arg.
 
+I<$result> is a ref to an array which all elements are a hashref.
+This hashref is containt the number of time this borrowers has borrowed before I<$date> and the borrowernumber.
 
+=cut
 
+sub GetBorrowersWithIssuesHistoryOlderThan {
+   my $dbh = C4::Context->dbh;
+   my $date = shift;
+   return unless $date; # date is mandatory.
+   my $query = "
+       SELECT count(borrowernumber) as n,borrowernumber
+       FROM issues
+       WHERE timestamp < ? 
+       GROUP BY borrowernumber
+   ";
+   my $sth = $dbh->prepare($query);
+   $sth->execute($date);
+   my @results;
+   while(my $data = $sth->fetchrow_hashref){
+        push @results,$data;
+   }
+   return \@results;
+}
 
 END { }       # module clean-up code here (global destructor)
 
 1;
+
+__END__
+
+=back
+
+=head1 AUTHOR
+
+Koha Team
+
+=cut





More information about the Koha-cvs mailing list