Code Cleaning Members.
authorhdl <hdl>
Mon, 23 Apr 2007 13:10:07 +0000 (13:10 +0000)
committerhdl <hdl>
Mon, 23 Apr 2007 13:10:07 +0000 (13:10 +0000)
- checkaccount and getborraccountno => GetBorrowerAcctRecord

Many changes in names,
some changes in function signature.
Will be detailed in a mail to kohadevel.

33 files changed:
C4/Accounts.pm
C4/Circulation.pm
C4/Members.pm
acqui/acqui-home.pl
acqui/neworderempty.pl
circ/circulation.pl
koha-tmpl/intranet-tmpl/prog/en/installer/step3.tmpl
koha-tmpl/intranet-tmpl/prog/en/members/moremember.tmpl
members/boraccount.pl
members/borrowers_details.pl
members/deletemem.pl
members/guarantor_search.pl
members/mancredit.pl
members/maninvoice.pl
members/member.pl
members/memberentry.pl
members/moremember.pl
members/pay.pl
members/readingrec.pl
misc/notifys/fines.pl
opac/opac-ISBDdetail.pl
opac/opac-account.pl
opac/opac-detail.pl
opac/opac-main.pl
opac/opac-readingrecord.pl
opac/opac-user.pl
reserve/placerequest.pl
reserve/request.pl
reviews/reviewswaiting.pl
serials/member-search.pl
serials/routing-preview.pl
serials/routing.pl
tools/cleanborrowers.pl

index 8eb99b9..5147568 100755 (executable)
@@ -50,51 +50,9 @@ patron.
 =cut
 
 @ISA = qw(Exporter);
-@EXPORT = qw(&checkaccount &recordpayment &fixaccounts &makepayment &manualinvoice
+@EXPORT = qw(&recordpayment &fixaccounts &makepayment &manualinvoice
 &getnextacctno &reconcileaccount);
 
-=head2 checkaccount
-
-  $owed = &checkaccount($borrowernumber, $dbh, $date);
-
-Looks up the total amount of money owed by a borrower (fines, etc.).
-
-C<$borrowernumber> specifies the borrower to look up.
-
-C<$dbh> is a DBI::db handle for the Koha database.
-
-=cut
-
-#'
-sub checkaccount  {
-  #take borrower number
-  #check accounts and list amounts owing
-    my ($borrowernumber,$dbh,$date)=@_;
-    my $select="SELECT SUM(amountoutstanding) AS total
-            FROM accountlines
-        WHERE borrowernumber = ?
-            AND amountoutstanding<>0";
-    my @bind = ($borrowernumber);
-    if ($date && $date ne ''){
-    $select.=" AND date < ?";
-    push(@bind,$date);
-    }
-    #  print $select;
-    my $sth=$dbh->prepare($select);
-    $sth->execute(@bind);
-    my $data=$sth->fetchrow_hashref;
-    my $total = $data->{'total'} || 0;
-    $sth->finish;
-    # output(1,2,"borrower owes $total");
-    #if ($total > 0){
-    #  # output(1,2,"borrower owes $total");
-    #  if ($total > 5){
-    #    reconcileaccount($dbh,$borrowernumber,$total);
-    #  }
-    #}
-    #  pause();
-    return($total);
-}
 
 =head2 recordpayment
 
@@ -286,7 +244,7 @@ EOT
 sub returnlost{
   my ($borrowernumber,$itemnum)=@_;
   my $dbh = C4::Context->dbh;
-  my $borrower=borrdata('',$borrowernumber);
+  my $borrower=GetMember($borrowernumber,'borrowernumber');
   my $sth=$dbh->prepare("Update issues set returndate=now() where
   borrowernumber=? and itemnumber=? and returndate is null");
   $sth->execute($borrowernumber,$itemnum);
index e794997..dff439f 100755 (executable)
@@ -26,7 +26,6 @@ use C4::Stats;
 use C4::Reserves2;
 use C4::Koha;
 use C4::Biblio;
-use C4::Accounts;
 use C4::Reserves2;
 use C4::Members;
 use C4::Date;
@@ -714,8 +713,8 @@ sub CanBookBeIssued {
     #
 
     # DEBTS
-    my $amount =
-      checkaccount( $borrower->{'borrowernumber'}, $dbh, $duedate );
+    my ($amount) =
+      GetBorrowerAcctRecord( $borrower->{'borrowernumber'}, $duedate );
     if ( C4::Context->preference("IssuingInProcess") ) {
         my $amountlimit = C4::Context->preference("noissuescharge");
         if ( $amount > $amountlimit && !$inprocess ) {
@@ -1661,7 +1660,7 @@ sub AddRenewal {
     my ( $charge, $type ) = GetIssuingCharges( $itemnumber, $borrowernumber );
     if ( $charge > 0 ) {
         my $accountno = getnextacctno( $borrowernumber );
-        my $item = GetBiblioFromItemNumbe(r$itemnumber);
+        my $item = GetBiblioFromItemNumber($itemnumber);
         $sth = $dbh->prepare(
                 "INSERT INTO accountlines
                     (borrowernumber,accountno,date,amount,
index 3c131b4..f3fe8b9 100644 (file)
@@ -26,7 +26,6 @@ use C4::Date;
 use Digest::MD5 qw(md5_base64);
 use Date::Calc qw/Today Add_Delta_YM/;
 use C4::Log; # logaction
-use C4::Accounts;
 use C4::Overdues;
 use C4::Reserves2;
 
@@ -54,32 +53,74 @@ This module contains routines for adding, modifying and deleting members/patrons
 
 @ISA = qw(Exporter);
 
-@EXPORT = qw(
-  &BornameSearch &GetMember &GetMemberDetails
-  &borrdata &borrdata2
-  &fixup_cardnumber &findguarantees &findguarantor &GuarantornameSearch
-  &modmember &newmember &changepassword &borrissues &allissues
-  &checkuniquemember &getzipnamecity &getidcity &getguarantordata &getcategorytype
-  &DeleteBorrower
-  &calcexpirydate &checkuserpassword
-  &getboracctrecord
-  &GetborCatFromCatType &getborrowercategory
-  &fixEthnicity
-  &ethnicitycategories &get_institutions add_member_orgs
-  &get_age &GetBorrowersFromSurname &GetBranchCodeFromBorrowers
-  &GetFlagsAndBranchFromBorrower
-  &GetCities &GetRoadTypes &GetRoadTypeDetails &GetBorNotifyAcctRecord
+#Get data
+push @EXPORT, qw(
+  &SearchBorrower 
+  &GetMemberDetails
+  &GetMember
+  
+  &GetGuarantees 
+  &findguarantor 
+  &GuarantornameSearch
+  
+  &GetBorrowerIssuesAndFines
+  &GetPendingIssues
+  &GetAllIssues
+  
+  &get_institutions 
+  &getzipnamecity 
+  &getidcity
+   
+  &GetAge 
+  &GetCities 
+  &GetRoadTypes 
+  &GetRoadTypeDetails 
+  
+  &GetBorrowerAcctRecord
+  
+  &GetborCatFromCatType 
+  &GetBorrowercategory
+  
+  &GetBorNotifyAcctRecord
   &GetMembeReregistration
   &GetSortDetails
+  
   &GetBorrowersTitles  
   &GetBorrowersWhoHaveNotBorrowedSince
   &GetBorrowersWhoHaveNeverBorrowed
   &GetBorrowersWithIssuesHistoryOlderThan
+  &GetBorrowersFromSurname 
+  
+  &GetExpiryDate
+);
+
+#Modify data
+push @EXPORT, qw(
+  &ModMember
+  &fixup_cardnumber
+  &changepassword
+);
+  
+#Delete data
+push @EXPORT, qw(
+  &DelMember
+);
+
+#Insert data
+push @EXPORT, qw(
+  &AddMember  
+  &checkuniquemember 
+  &checkuserpassword
+  &fixEthnicity
+  &ethnicitycategories 
+  &add_member_orgs
+  
+  &MoveMemberToDeleted
 );
 
-=item BornameSearch
+=item Searchborrower
 
-  ($count, $borrowers) = &BornameSearch($searchstring, $type);
+  ($count, $borrowers) = &SearchBorrower($searchstring, $type);
 
 Looks up patrons (borrowers) by name.
 
@@ -91,7 +132,7 @@ C<$searchstring> is a space-separated list of search terms. Each term
 must match the beginning a borrower's surname, first name, or other
 name.
 
-C<&BornameSearch> returns a two-element list. C<$borrowers> is a
+C<&SearchBorrower> returns a two-element list. C<$borrowers> is a
 reference-to-array; each element is a reference-to-hash, whose keys
 are the fields of the C<borrowers> table in the Koha database.
 C<$count> is the number of elements in C<$borrowers>.
@@ -101,8 +142,8 @@ C<$count> is the number of elements in C<$borrowers>.
 #'
 #used by member enquiries from the intranet
 #called by member.pl
-sub BornameSearch {
-    my ($searchstring, $orderby, $type ) = @_;
+sub SearchBorrower {
+    my ($searchstring, $orderby, $type,$category_type ) = @_;
     my $dbh   = C4::Context->dbh;
     my $query = "";
     my $count;
@@ -113,8 +154,9 @@ sub BornameSearch {
     {
         $query =
           "SELECT * FROM borrowers
-                  LEFT JOIN categories ON borrowers.categorycode=categories.categorycode
-                  WHERE surname LIKE ? ORDER BY $orderby";
+                  LEFT JOIN categories ON borrowers.categorycode=categories.categorycode ".
+                  ($category_type?" AND category_type = ".$dbh->quote($category_type):"").
+                  " WHERE surname LIKE ? ORDER BY $orderby";
         @bind = ("$searchstring%");
     }
     else    # advanced search looking in surname, firstname and othernames
@@ -126,7 +168,8 @@ sub BornameSearch {
                WHERE ((surname LIKE ? OR surname LIKE ?
                OR firstname  LIKE ? OR firstname LIKE ?
                OR othernames LIKE ? OR othernames LIKE ?)
-               ";
+               ".
+                  ($category_type?" AND category_type = ".$dbh->quote($category_type):"");
         @bind = (
             "$data[0]%", "% $data[0]%", "$data[0]%", "% $data[0]%",
             "$data[0]%", "% $data[0]%"
@@ -163,80 +206,6 @@ sub BornameSearch {
     return ( $cnt, \@results );
 }
 
-=head3 GetFlagsAndBranchFromBorrower
-
-=over 4
-
-($flags, $homebranch) = GetFlagsAndBranchFromBorrower($loggedinuser);
-
-this function read on the database to get flags and homebranch for a user
-given on input arg.
-
-return : 
-it returns the $flags & the homebranch in scalar context.
-
-=back
-
-=cut
-
-sub GetFlagsAndBranchFromBorrower {
-    my $loggedinuser = @_;
-    my $dbh          = C4::Context->dbh;
-    my $query        = "
-       SELECT flags, branchcode
-       FROM   borrowers
-       WHERE  borrowernumber = ? 
-    ";
-    my $sth = $dbh->prepare($query);
-    $sth->execute($loggedinuser);
-
-    return $sth->fetchrow;
-}
-
-=item GetMember
-
-  $borrower = &GetMember($cardnumber, $borrowernumber);
-
-Looks up information about a patron (borrower) by either card number
-or borrower number. If $borrowernumber is specified, C<&borrdata>
-searches by borrower number; otherwise, it searches by card number.
-
-C<&GetMember> returns a reference-to-hash whose keys are the fields of
-the C<borrowers> table in the Koha database.
-
-=cut
-
-sub GetMember {
-    my ( $cardnumber, $borrowernumber ) = @_;
-    $cardnumber = uc $cardnumber;
-    my $dbh = C4::Context->dbh;
-    my $sth;
-    if ( $borrowernumber eq '' ) {
-        $sth = $dbh->prepare("Select * from borrowers where cardnumber=?");
-        $sth->execute($cardnumber);
-    }
-    else {
-        $sth = $dbh->prepare("Select * from borrowers where borrowernumber=?");
-        $sth->execute($borrowernumber);
-    }
-    my $data = $sth->fetchrow_hashref;
-    $sth->finish;
-    if ($data) {
-        return ($data);
-    }
-    else {    # try with firstname
-        if ($cardnumber) {
-            my $sth =
-              $dbh->prepare("select * from borrowers where firstname=?");
-            $sth->execute($cardnumber);
-            my $data = $sth->fetchrow_hashref;
-            $sth->finish;
-            return ($data);
-        }
-    }
-    return undef;
-}
-
 =head2 GetMemberDetails
 
 ($borrower, $flags) = &GetMemberDetails($borrowernumber, $cardnumber);
@@ -350,7 +319,7 @@ sub GetMemberDetails {
         return undef;
     }
     my $borrower = $sth->fetchrow_hashref;
-    my $amount = C4::Accounts::checkaccount( $borrowernumber, $dbh );
+    my ($amount) = GetBorrowerAcctRecord( $borrowernumber);
     $borrower->{'amountoutstanding'} = $amount;
     my $flags = patronflags( $borrower, $dbh );
     my $accessflagshash;
@@ -412,9 +381,9 @@ sub GetMemberDetails {
 
 sub patronflags {
     my %flags;
-    my ( $patroninformation, $dbh ) = @_;
-    my $amount =
-      C4::Accounts::checkaccount( $patroninformation->{'borrowernumber'}, $dbh );
+    my ( $patroninformation) = @_;
+    my $dbh=C4::Context->dbh;
+    my ($amount) = GetBorrowerAcctRecord( $patroninformation->{'borrowernumber'});
     if ( $amount > 0 ) {
         my %flaginfo;
         my $noissuescharge = C4::Context->preference("noissuescharge");
@@ -485,38 +454,40 @@ sub patronflags {
 }
 
 
-=item borrdata
+=item GetMember
 
-  $borrower = &borrdata($cardnumber, $borrowernumber);
+  $borrower = &GetMember($information, $type);
 
 Looks up information about a patron (borrower) by either card number
-or borrower number. If $borrowernumber is specified, C<&borrdata>
-searches by borrower number; otherwise, it searches by card number.
+,firstname, or borrower number, depending on $type value.
+If C<$type> == 'cardnumber', C<&GetBorrower>
+searches by cardnumber then by firstname if not found in cardnumber; 
+otherwise, it searches by borrowernumber.
 
-C<&borrdata> returns a reference-to-hash whose keys are the fields of
+C<&GetBorrower> returns a reference-to-hash whose keys are the fields of
 the C<borrowers> table in the Koha database.
 
 =cut
 
 #'
-sub borrdata {
-    my ( $cardnumber, $borrowernumber ) = @_;
-    $cardnumber = uc $cardnumber;
+sub GetMember {
+    my ( $information, $type ) = @_;
     my $dbh = C4::Context->dbh;
     my $sth;
-    if ( $borrowernumber eq '' ) {
-        $sth =
+    if ($type eq 'cardnumber' || $type eq 'firstname'|| $type eq 'userid'|| $type eq 'borrowernumber'){
+      $information = uc $information;
+      $sth =
           $dbh->prepare(
-"Select borrowers.*,categories.category_type from borrowers left join categories on borrowers.categorycode=categories.categorycode where cardnumber=?"
+"Select borrowers.*,categories.category_type,categories.description  from borrowers left join categories on borrowers.categorycode=categories.categorycode where $type=?"
           );
-        $sth->execute($cardnumber);
+        $sth->execute($information);
     }
     else {
         $sth =
           $dbh->prepare(
-"Select borrowers.*,categories.category_type from borrowers left join categories on borrowers.categorycode=categories.categorycode where borrowernumber=?"
+"Select borrowers.*,categories.category_type, categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode where borrowernumber=?"
           );
-        $sth->execute($borrowernumber);
+        $sth->execute($information);
     }
     my $data = $sth->fetchrow_hashref;
 
@@ -524,12 +495,12 @@ sub borrdata {
     if ($data) {
         return ($data);
     }
-    elsif ($cardnumber) {    # try with firstname
+    elsif ($type eq 'cardnumber' ||$type eq 'firstname') {    # try with firstname
         my $sth =
               $dbh->prepare(
-"Select borrowers.*,categories.category_type from borrowers left join categories on borrowers.categorycode=categories.categorycode  where firstname=?"
+"Select borrowers.*,categories.category_type,categories.description from borrowers left join categories on borrowers.categorycode=categories.categorycode  where firstname like ?"
             );
-            $sth->execute($cardnumber);
+            $sth->execute($information);
             my $data = $sth->fetchrow_hashref;
             $sth->finish;
             return ($data);
@@ -539,14 +510,14 @@ sub borrdata {
     }
 }
 
-=item borrdata2
+=item GetBorrowerIssuesAndFines
 
-  ($borrowed, $due, $fine) = &borrdata2($borrowernumber);
+  ($borrowed, $due, $fine) = &GetBorrowerIssuesAndFines($borrowernumber);
 
 Returns aggregate data about items borrowed by the patron with the
 given borrowernumber.
 
-C<&borrdata2> returns a three-element array. C<$borrowed> is the
+C<&GetBorrowerIssuesAndFines> returns a three-element array. C<$borrowed> is the
 number of books the patron currently has borrowed. C<$due> is the
 number of overdue items the patron currently has borrowed. C<$fine> is
 the total fine currently due by the borrower.
@@ -554,7 +525,7 @@ the total fine currently due by the borrower.
 =cut
 
 #'
-sub borrdata2 {
+sub GetBorrowerIssuesAndFines {
     my ( $borrowernumber ) = @_;
     my $dbh   = C4::Context->dbh;
     my $query =
@@ -585,7 +556,18 @@ sub borrdata2 {
         $data3->{'sum(amountoutstanding)'} );
 }
 
-sub modmember {
+=head2
+
+=item ModMember
+
+  ($borrowed, $due, $fine) = &ModMember($borrowernumber);
+
+Modify borrower's data
+
+=cut
+
+#'
+sub ModMember {
     my (%data) = @_;
     my $dbh = C4::Context->dbh;
     $data{'dateofbirth'}  = format_date_in_iso( $data{'dateofbirth'} );
@@ -683,18 +665,28 @@ sub modmember {
 # ok if its an adult (type) it may have borrowers that depend on it as a guarantor
 # so when we update information for an adult we should check for guarantees and update the relevant part
 # of their records, ie addresses and phone numbers
-    my ( $category_type, undef ) = getcategorytype( $data{'category_type'} );
-    if ( $category_type eq 'A' ) {
-
+    my $borrowercategory= GetBorrowercategory( $data{'category_type'} );
+    if ( $borrowercategory->{'category_type'} eq 'A' ) {
         # is adult check guarantees;
-        updateguarantees(%data);
+        UpdateGuarantees(%data);
 
     }
     &logaction(C4::Context->userenv->{'number'},"MEMBERS","MODIFY",$data{'borrowernumber'},"") 
         if C4::Context->preference("BorrowersLog");
 }
 
-sub newmember {
+=head2
+
+=item AddMember
+
+  $borrowernumber = &ModMember(%borrower);
+
+insert new borrower into table
+
+=cut
+
+#'
+sub AddMember {
     my (%data) = @_;
     my $dbh = C4::Context->dbh;
     $data{'userid'} = '' unless $data{'password'};
@@ -836,18 +828,11 @@ sub changepassword {
         if C4::Context->preference("BorrowersLog");
 }
 
-sub getmemberfromuserid {
-    my ($userid) = @_;
-    my $dbh      = C4::Context->dbh;
-    my $sth      = $dbh->prepare("select * from borrowers where userid=?");
-    $sth->execute($userid);
-    return $sth->fetchrow_hashref;
-}
 
-sub updateguarantees {
+sub UpdateGuarantees {
     my (%data) = @_;
     my $dbh = C4::Context->dbh;
-    my ( $count, $guarantees ) = findguarantees( $data{'borrowernumber'} );
+    my ( $count, $guarantees ) = GetGuarantees( $data{'borrowernumber'} );
     for ( my $i = 0 ; $i < $count ; $i++ ) {
 
         # FIXME
@@ -949,24 +934,24 @@ sub fixup_cardnumber ($) {
     return $cardnumber;
 }
 
-=head2 findguarantees
+=head2 GetGuarantees
 
-  ($num_children, $children_arrayref) = &findguarantees($parent_borrno);
+  ($num_children, $children_arrayref) = &GetGuarantees($parent_borrno);
   $child0_cardno = $children_arrayref->[0]{"cardnumber"};
   $child0_borrno = $children_arrayref->[0]{"borrowernumber"};
 
-C<&findguarantees> takes a borrower number (e.g., that of a patron
+C<&GetGuarantees> takes a borrower number (e.g., that of a patron
 with children) and looks up the borrowers who are guaranteed by that
 borrower (i.e., the patron's children).
 
-C<&findguarantees> returns two values: an integer giving the number of
+C<&GetGuarantees> returns two values: an integer giving the number of
 borrowers guaranteed by C<$parent_borrno>, and a reference to an array
 of references to hash, which gives the actual results.
 
 =cut
 
 #'
-sub findguarantees {
+sub GetGuarantees {
     my ($borrowernumber) = @_;
     my $dbh              = C4::Context->dbh;
     my $sth              =
@@ -976,135 +961,18 @@ sub findguarantees {
     $sth->execute($borrowernumber);
 
     my @dat;
-    while ( my $data = $sth->fetchrow_hashref ) {
-        push @dat, $data;
-    }
-    $sth->finish;
-    return ( scalar(@dat), \@dat );
-}
-
-=head2 findguarantor
-
-  $guarantor = &findguarantor($borrower_no);
-  $guarantor_cardno = $guarantor->{"cardnumber"};
-  $guarantor_surname = $guarantor->{"surname"};
-  ...
-
-C<&findguarantor> takes a borrower number (presumably that of a child
-patron), finds the guarantor for C<$borrower_no> (the child's parent),
-and returns the record for the guarantor.
-
-C<&findguarantor> returns a reference-to-hash. Its keys are the fields
-from the C<borrowers> database table;
-
-=cut
-
-#'
-sub findguarantor {
-    my ($borrowernumber) = @_;
-    my $dbh              = C4::Context->dbh;
-    my $sth              =
-      $dbh->prepare("select guarantorid from borrowers where borrowernumber=?");
-    $sth->execute($borrowernumber);
-    my $data = $sth->fetchrow_hashref;
-    $sth->finish;
-    $sth = $dbh->prepare("Select * from borrowers where borrowernumber=?");
-    $sth->execute( $data->{'guarantorid'} );
-    $data = $sth->fetchrow_hashref;
-    $sth->finish;
-    return ($data);
-}
-
-=item GuarantornameSearch
-
-  ($count, $borrowers) = &GuarantornameSearch($searchstring, $type);
-
-Looks up guarantor  by name.
-
-BUGFIX 499: C<$type> is now used to determine type of search.
-if $type is "simple", search is performed on the first letter of the
-surname only.
-
-C<$searchstring> is a space-separated list of search terms. Each term
-must match the beginning a borrower's surname, first name, or other
-name.
-
-C<&GuarantornameSearch> returns a two-element list. C<$borrowers> is a
-reference-to-array; each element is a reference-to-hash, whose keys
-are the fields of the C<borrowers> table in the Koha database.
-C<$count> is the number of elements in C<$borrowers>.
-
-return all info from guarantor =>only category_type A
-
-=cut
-
-#'
-#used by member enquiries from the intranet
-#called by guarantor_search.pl
-sub GuarantornameSearch {
-    my ($searchstring, $orderby, $type ) = @_;
-    my $dbh   = C4::Context->dbh;
-    my $query = "";
-    my $count;
-    my @data;
-    my @bind = ();
-
-    if ( $type eq "simple" )    # simple search for one letter only
-    {
-        $query =
-"Select * from borrowers,categories  where borrowers.categorycode=categories.categorycode and category_type='A'  and  surname like ? order by $orderby";
-        @bind = ("$searchstring%");
-    }
-    else    # advanced search looking in surname, firstname and othernames
-    {
-        @data  = split( ' ', $searchstring );
-        $count = @data;
-        $query = "Select * from borrowers,categories
-               where ((surname like ? or surname like ?
-               or firstname  like ? or firstname like ?
-               or othernames like ? or othernames like ?) and borrowers.categorycode=categories.categorycode and category_type='A' 
-               ";
-        @bind = (
-            "$data[0]%", "% $data[0]%", "$data[0]%", "% $data[0]%",
-            "$data[0]%", "% $data[0]%"
-        );
-        for ( my $i = 1 ; $i < $count ; $i++ ) {
-            $query = $query . " and (" . " surname like ? or surname like ?
-                        or firstname  like ? or firstname like ?
-                       or othernames like ? or othernames like ?)";
-            push( @bind,
-                "$data[$i]%",   "% $data[$i]%", "$data[$i]%",
-                "% $data[$i]%", "$data[$i]%",   "% $data[$i]%" );
-
-            # FIXME - .= <<EOT;
-        }
-        $query = $query . ") or cardnumber like ?
-               order by $orderby";
-        push( @bind, $searchstring );
-
-        # FIXME - .= <<EOT;
-    }
-
-    my $sth = $dbh->prepare($query);
-    $sth->execute(@bind);
-    my @results;
-    my $cnt = $sth->rows;
-    while ( my $data = $sth->fetchrow_hashref ) {
-        push( @results, $data );
-    }
-
-    #  $sth->execute;
+    my $data = $sth->fetchall_arrayref({}); 
     $sth->finish;
-    return ( $cnt, \@results );
+    return ( scalar(@$data), $data );
 }
 
-=head2 borrissues
+=head2 GetPendingIssues
 
-  ($count, $issues) = &borrissues($borrowernumber);
+  ($count, $issues) = &GetPendingIssues($borrowernumber);
 
 Looks up what the patron with the given borrowernumber has borrowed.
 
-C<&borrissues> returns a two-element array. C<$issues> is a
+C<&GetPendingIssues> returns a two-element array. C<$issues> is a
 reference-to-array, where each element is a reference-to-hash; the
 keys are the fields from the C<issues>, C<biblio>, and C<items> tables
 in the Koha database. C<$count> is the number of elements in
@@ -1113,27 +981,23 @@ C<$issues>.
 =cut
 
 #'
-sub borrissues {
+sub GetPendingIssues {
     my ($borrowernumber) = @_;
     my $dbh              = C4::Context->dbh;
     my $sth              = $dbh->prepare(
         "Select * from issues,biblio,items where borrowernumber=?
-   and items.itemnumber=issues.itemnumber
+        and items.itemnumber=issues.itemnumber
        and items.biblionumber=biblio.biblionumber
        and issues.returndate is NULL order by date_due"
     );
     $sth->execute($borrowernumber);
-    my @result;
-    while ( my $data = $sth->fetchrow_hashref ) {
-        push @result, $data;
-    }
-    $sth->finish;
-    return ( scalar(@result), \@result );
+    my $data = $sth->fetchall_arrayref({});
+    return ( scalar(@$data), $data );
 }
 
-=head2 allissues
+=head2 GetAllIssues
 
-  ($count, $issues) = &allissues($borrowernumber, $sortkey, $limit);
+  ($count, $issues) = &GetAllIssues($borrowernumber, $sortkey, $limit);
 
 Looks up what the patron with the given borrowernumber has borrowed,
 and sorts the results.
@@ -1144,7 +1008,7 @@ C<biblioitems>, or C<items> table in the Koha database.
 
 C<$limit> is the maximum number of results to return.
 
-C<&allissues> returns a two-element array. C<$issues> is a
+C<&GetAllIssues> returns a two-element array. C<$issues> is a
 reference-to-array, where each element is a reference-to-hash; the
 keys are the fields from the C<issues>, C<biblio>, C<biblioitems>, and
 C<items> tables of the Koha database. C<$count> is the number of
@@ -1153,7 +1017,7 @@ elements in C<$issues>
 =cut
 
 #'
-sub allissues {
+sub GetAllIssues {
     my ( $borrowernumber, $order, $limit ) = @_;
 
     #FIXME: sanity-check order and limit
@@ -1209,15 +1073,14 @@ sub allissues {
     return ( $i, \@result );
 }
 
-=head2 getboracctrecord
 
-  ($count, $acctlines, $total) = &getboracctrecord($borrowernumber);
+=head2 GetBorrowerAcctRecord
 
-Looks up accounting data for the patron with the given borrowernumber.
+  ($total, $acctlines, $count) = &GetBorrowerAcctRecord($borrowernumber);
 
-(FIXME - I'm not at all sure what this is about.)
+Looks up accounting data for the patron with the given borrowernumber.
 
-C<&getboracctrecord> returns a three-element array. C<$acctlines> is a
+C<&GetBorrowerAcctRecord> returns a three-element array. C<$acctlines> is a
 reference-to-array, where each element is a reference-to-hash; the
 keys are the fields of the C<accountlines> table in the Koha database.
 C<$count> is the number of elements in C<$acctlines>. C<$total> is the
@@ -1226,36 +1089,32 @@ total amount outstanding for all of the account lines.
 =cut
 
 #'
-sub getboracctrecord {
-    my ($params ) = @_;
+sub GetBorrowerAcctRecord {
+    my ($borrowernumber,$date) = @_;
     my $dbh = C4::Context->dbh;
     my @acctlines;
     my $numlines = 0;
-    my $sth      = $dbh->prepare(
-        "Select * from accountlines where
-borrowernumber=? order by date desc,timestamp desc"
+    my $strsth      = qq(
+        Select * from accountlines where
+borrowernumber=? order by date desc,timestamp desc
     );
+    my @bind = ($borrowernumber);
+    if ($date && $date ne ''){
+    $strsth.=" AND date < ?";
+    push(@bind,$date);
+    }
 
-    $sth->execute( $params->{'borrowernumber'} );
+    my $sth= $dbh->prepare( $strsth );
+    $sth->execute( $borrowernumber);
     my $total = 0;
     while ( my $data = $sth->fetchrow_hashref ) {
 
-        #FIXME before reinstating: insecure?
-        #      if ($data->{'itemnumber'} ne ''){
-        #        $query="Select * from items,biblio where items.itemnumber=
-        #      '$data->{'itemnumber'}' and biblio.biblionumber=items.biblionumber";
-        #      my $sth2=$dbh->prepare($query);
-        #      $sth2->execute;
-        #      my $data2=$sth2->fetchrow_hashref;
-        #      $sth2->finish;
-        #      $data=$data2;
-        #     }
         $acctlines[$numlines] = $data;
         $numlines++;
         $total += $data->{'amountoutstanding'};
     }
     $sth->finish;
-    return ( $numlines, \@acctlines, $total );
+    return ( $total, \@acctlines,$numlines);
 }
 
 =head2 GetBorNotifyAcctRecord
@@ -1369,27 +1228,6 @@ sub getzipnamecity {
     return $data[0], $data[1];
 }
 
-=head2 updatechildguarantor (OUEST-PROVENCE)
-
-check for title,firstname,surname,adress,zip code and city  from guarantor to 
-guarantorchild
-
-=cut
-
-#'
-
-sub getguarantordata {
-    my ($borrowerid) = @_;
-    my $dbh          = C4::Context->dbh;
-    my $sth          =
-      $dbh->prepare(
-"Select title,firstname,surname,streetnumber,address,streettype,address2,zipcode,city,phone,phonepro,mobile,email,emailpro,fax  from borrowers where borrowernumber =? "
-      );
-    $sth->execute($borrowerid);
-    my $guarantor_data = $sth->fetchrow_hashref;
-    $sth->finish;
-    return $guarantor_data;
-}
 
 =head2 getdcity (OUEST-PROVENCE)
 
@@ -1406,26 +1244,14 @@ sub getidcity {
     return $data;
 }
 
-=head2 getcategorytype (OUEST-PROVENCE)
 
-check for the category_type with categorycode
-and return the category_type 
+=head2 GetExpiryDate 
 
-=cut
+  $expirydate = GetExpiryDate($categorycode, $dateenrolled);
+process expiry date given a date and a categorycode
 
-sub getcategorytype {
-    my ($categorycode) = @_;
-    my $dbh            = C4::Context->dbh;
-    my $sth            =
-      $dbh->prepare(
-"Select category_type,description from categories where categorycode=?  "
-      );
-    $sth->execute($categorycode);
-    my ( $category_type, $description ) = $sth->fetchrow;
-    return $category_type, $description;
-}
-
-sub calcexpirydate {
+=cut
+sub GetExpiryDate {
     my ( $categorycode, $dateenrolled ) = @_;
     my $dbh = C4::Context->dbh;
     my $sth =
@@ -1434,9 +1260,6 @@ sub calcexpirydate {
     $sth->execute($categorycode);
     my ($enrolmentperiod) = $sth->fetchrow;
     $enrolmentperiod = 12 unless ($enrolmentperiod);
-#     warn "Avant format_date_in_iso :".$dateenrolled;
-#     $dateenrolled=format_date_in_iso($dateenrolled);
-#     warn "Apres format_date_in_iso :".$dateenrolled;
     my @date=split /-/,format_date_in_iso($dateenrolled);
     @date=Add_Delta_YM($date[0],$date[1],$date[2],0,$enrolmentperiod);
     return sprintf("%04d-%02d-%02d",$date[0],$date[1],$date[2]);
@@ -1502,16 +1325,16 @@ sub GetborCatFromCatType {
     return ( \@codes, \%labels );
 }
 
-=head2 getborrowercategory
+=head2 GetBorrowercategory
 
-  $description,$dateofbirthrequired,$upperagelimit,$category_type = &getborrowercategory($categorycode);
+  $hashref = &GetBorrowercategory($categorycode);
 
 Given the borrower's category code, the function returns the corresponding
-description , dateofbirthrequired , upperagelimit and category type for a comprehensive information display.
+data hashref for a comprehensive information display.
 
 =cut
 
-sub getborrowercategory {
+sub GetBorrowercategory {
     my ($catcode) = @_;
     my $dbh       = C4::Context->dbh;
     my $sth       =
@@ -1519,11 +1342,10 @@ sub getborrowercategory {
 "SELECT description,dateofbirthrequired,upperagelimit,category_type FROM categories WHERE categorycode = ?"
       );
     $sth->execute($catcode);
-    my ( $description, $dateofbirthrequired, $upperagelimit, $category_type ) =
-      $sth->fetchrow();
+    my $data =
+      $sth->fetchrow_hashref;
     $sth->finish();
-    return ( $description, $dateofbirthrequired, $upperagelimit,
-        $category_type );
+    return $data;
 }    # sub getborrowercategory
 
 =head2 ethnicitycategories
@@ -1576,16 +1398,16 @@ sub fixEthnicity {
     return $data->{'name'};
 }    # sub fixEthnicity
 
-=head2 get_age
+=head2 GetAge
 
-  $dateofbirth,$date = &get_age($date);
+  $dateofbirth,$date = &GetAge($date);
 
 this function return the borrowers age with the value of dateofbirth
 
 =cut
 
 #'
-sub get_age {
+sub GetAge{
     my ( $date, $date_ref ) = @_;
 
     if ( not defined $date_ref ) {
@@ -1679,17 +1501,14 @@ sub GetBorrowersFromSurname {
     my @results;
     $count = 0;
 
-    while ( my $data = $sth->fetchrow_hashref ) {
-        push( @results, $data );
-        $count++;
-    }
+    my $data = $sth->fetchall_arrayref({});
     $sth->finish;
-    return ( $count, \@results );
+    return ( scalar(@$data), $data );
 }
 
-=head2 citycaracteristiques (OUEST-PROVENCE)
+=head2 GetCities (OUEST-PROVENCE)
 
-  ($id_cityarrayref, $city_hashref) = &citycaracteristic();
+  ($id_cityarrayref, $city_hashref) = &GetCities();
 
 Looks up the different city and zip in the database. Returns two
 elements: a reference-to-array, which lists the zip city
@@ -1765,7 +1584,7 @@ C<&$member>this is the borrowernumber
 
 =cut
 
-sub DeleteBorrower {
+sub MoveMemberToDeleted {
     my ($member) = @_;
     my $dbh = C4::Context->dbh;
     my $query;
@@ -1782,75 +1601,61 @@ sub DeleteBorrower {
           . "?)" );
     $sth->execute(@data);
     $sth->finish;
-    $query = qq|DELETE 
-                 FROM borrowers 
-                 WHERE borrowernumber=?|;
-    $sth = $dbh->prepare($query);
-    $sth->execute($member);
-    $sth->finish;
-    $query = qq|DELETE 
-                 FROM  reserves 
-                 WHERE borrowernumber=?|;
-    $sth = $dbh->prepare($query);
-    $sth->execute($member);
-    $sth->finish;
-    
-    # logging to action_log
-    &logaction(C4::Context->userenv->{'number'},"MEMBERS","DELETE",$member,"") 
-        if C4::Context->preference("BorrowersLog");
 }
 
-=head2 DelBorrowerCompletly
+=head2 DelMember
 
-DelBorrowerCompletly($borrowernumber);
+DelMember($borrowernumber);
 
 This function remove directly a borrower whitout writing it on deleteborrower.
++ Deletes reserves for the borrower
 
 =cut
 
-sub DelBorrowerCompletly {
+sub DelMember {
     my $dbh            = C4::Context->dbh;
     my $borrowernumber = shift;
-    return unless $borrowernumber;    # date is mandatory.
-    my $query = "
-       DELETE *
+    return unless $borrowernumber;    # borrowernumber is mandatory.
+
+    my $query = qq|DELETE 
+                 FROM  reserves 
+                 WHERE borrowernumber=?|;
+    my $sth = $dbh->prepare($query);
+    $sth->execute($borrowernumber);
+    $sth->finish;
+    $query = "
+       DELETE
        FROM borrowers
        WHERE borrowernumber = ?
    ";
     my $sth = $dbh->prepare($query);
-    $sth->execute($borrowernumber);
+    &logaction(C4::Context->userenv->{'number'},"MEMBERS","DELETE",$borrowernumber,"") 
+        if C4::Context->preference("BorrowersLog");
     return $sth->rows;
 }
 
-=head2 member_reregistration (OUEST-PROVENCE)
-
-automatic reregistration in borrowers table 
-with dateexpiry .
+=head2 ExtendMemberSubscriptionTo (OUEST-PROVENCE)
 
+$date= ExtendMemberSubscriptionTo($borrowerid, $date);
+Extending the subscription to a given date or to the expiry date calculated on local date.
+returns date 
 =cut
 
-sub GetMembeReregistration {
-    my ( $categorycode, $borrowerid ) = @_;
+sub ExtendMemberSubscriptionTo {
+    my ( $borrowerid,$date) = @_;
     my $dbh = C4::Context->dbh;
-    my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
-      localtime(time);
-    $mon++;
-    $year = $year + 1900;
-    if ( $mon < '10' ) {
-        $mon = "0" . $mon;
-    }
-    if ( $mday < '10' ) {
-        $mday = "0" . $mday;
-    }
-    my $today = sprintf("%04d-%02d-%02d",$year,$mon,$mday);
-    my $dateexpiry = calcexpirydate( $categorycode, $today );
-    my $query      = qq|   UPDATE borrowers 
-                       SET  dateexpiry='$dateexpiry' 
-                       WHERE borrowernumber='$borrowerid'|;
-    my $sth = $dbh->prepare($query);
-    $sth->execute;
-    $sth->finish;
-    return $dateexpiry;
+    unless ($date){
+      $date=POSIX::strftime("%Y-%m-%d",localtime(time));
+      my $borrower = GetBorrower($borrowerid,'borrowernumber');
+      $date = GetExpiryDate( $borrower->{'categorycode'}, $date );
+    }
+    my $sth = $dbh->do(<<EOF);
+UPDATE borrowers 
+SET  dateexpiry='$date' 
+WHERE borrowernumber='$borrowerid'
+EOF
+    return $date if ($sth);
+    return 0;
 }
 
 =head2 GetRoadTypes (OUEST-PROVENCE)
index 0f0d76c..030dd62 100755 (executable)
@@ -65,7 +65,8 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 );
 
 # budget
-my ( $flags, $homebranch ) = GetFlagsAndBranchFromBorrower($loggedinuser);
+my $borrower= GetBorrower($loggedinuser);
+my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
 
 my @results = GetBookFunds($homebranch);
 my $count = scalar @results;
index f606b8d..09c2f4f 100755 (executable)
@@ -185,7 +185,8 @@ foreach my $thisbranch ( sort keys %$branches ) {
 $template->param( branchloop => \@branchloop );
 
 # build bookfund list
-my ($flags, $homebranch) = GetFlagsAndBranchFromBorrower($loggedinuser);
+my $borrower= GetBorrower($loggedinuser);
+my ( $flags, $homebranch )= ($borrower->{'flags'},$borrower->{'branchcode'});
 
 my $count2;
 my @bookfund;
index d98bc4e..5d1474b 100755 (executable)
@@ -141,7 +141,7 @@ my $borrowerslist;
 my $message;
 if ($findborrower) {
     my ( $count, $borrowers ) =
-      BornameSearch($findborrower, 'cardnumber', 'web' );
+      SearchBorrower($findborrower, 'cardnumber', 'web' );
     my @borrowers = @$borrowers;
     if ( $#borrowers == -1 ) {
         $query->param( 'findborrower', '' );
@@ -163,7 +163,7 @@ my @lines;
 
 if ($borrowernumber) {
     $borrower = GetMemberDetails( $borrowernumber, 0 );
-    my ( $od, $issue, $fines ) = borrdata2( $borrowernumber );
+    my ( $od, $issue, $fines ) = GetBorrowerIssuesAndFines( $borrowernumber );
 
     # Warningdate is the date that the warning starts appearing
     my ( $today_year,   $today_month,   $today_day )   = Today();
@@ -248,7 +248,7 @@ if ($barcode) {
     }
     
 # FIXME If the issue is confirmed, we launch another time borrdata2, now display the issue count after issue 
-        my ( $od, $issue, $fines ) = borrdata2( $borrowernumber );
+        my ( $od, $issue, $fines ) = GetBorrowerIssuesAndFines( $borrowernumber );
         $template->param(
         issuecount   => $issue,
         );
index b2577ac..62fee3c 100644 (file)
@@ -1,4 +1,5 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" --><title>Koha &rsaquo; Web Installer &rsaquo; Step 3</title>
+<!--TMPL_IF Name="finish"--><meta http-equiv="refresh" content="10; url=/cgi-bin/koha/mainpage.pl"><!--/TMPL_IF-->
 <!-- TMPL_INCLUDE NAME="installer-doc-head-close.inc" -->
 <div>
 <h1 id="logo"><img alt="Koha" src="/intranet-tmpl/prog/en/images/koha.org-logo.gif" /></h1>
@@ -75,7 +76,10 @@ function Hide(link) {
 }
 </script>
 <!--/TMPL_IF-->
-
+<!--TMPL_IF Name="finish"-->
+  <h1>Congratulations, Installation complete</h1>
+  
+<!--/TMPL_IF-->
 <!--TMPL_IF Name="selectframeworks"-->
   <h2 align="center">Selecting Default Settings</h2>
   <form name="frameworkselection" method="post" action="install.pl">
@@ -98,7 +102,7 @@ function Hide(link) {
   <!--TMPL_LOOP Name="frameworks"-->
     <div style="border:1px;">
     <p>
-    <!--TMPL_IF Name="mandatory"--><input type="checkbox" Name="framework" value="<!--TMPL_VAR Name="fwkfile"-->" checked />
+    <!--TMPL_IF Name="checked"--><input type="checkbox" Name="framework" value="<!--TMPL_VAR Name="fwkfile"-->" checked />
     <!--TMPl_ELSE--><input type="checkbox" Name="framework" value="<!--TMPL_VAR Name="fwkfile"-->" />
     <!--/TMPL_IF-->
     <!--TMPL_VAR Name="fwkdescription"-->
@@ -187,6 +191,6 @@ Alternatively, if you are upgrading from a previous version of Koha, you can <a
 <a href="install.pl?step=3&amp;op=selectframeworks" class="button">Continue to Framework Selection</a>
   </div>
 <!--/TMPL_IF-->
-</div>
+
 </body>
 </html>
index 0360090..b1e75df 100644 (file)
 <fieldset>
     <legend>Library use</legend>
     <p><label>Borrower number:</label><!-- TMPL_VAR NAME="borrowernumber" --></p>
-    <p><label>Category:</label><!-- TMPL_VAR NAME="categorycode" --></p>
+    <p><label>Category:</label><!-- TMPL_VAR NAME="description" --></p>
     <p><label>Registration date:</label><!-- TMPL_VAR NAME="dateenrolled" --></p>
     <p><label>Relation:</label><!-- TMPL_VAR NAME="relationship" --></p>
     
index 46a266b..bd7a829 100755 (executable)
@@ -48,12 +48,10 @@ my ($template, $loggedinuser, $cookie)
 
 my $borrowernumber=$input->param('borrowernumber');
 #get borrower details
-my $data=borrdata('',$borrowernumber);
+my $data=GetMember($borrowernumber,'borrowernumber');
 
 #get account details
-my %bor;
-$bor{'borrowernumber'}=$borrowernumber;
-my ($numaccts,$accts,$total)=getboracctrecord('',\%bor);
+my ($numaccts,$accts,$total)=GetBorrowerAcctRecord($borrowernumber);
 my $totalcredit;
 if($total <= 0){
        $totalcredit = 1;
index a33bb2c..1d8e086 100644 (file)
@@ -59,10 +59,10 @@ my $category_type=$input->param('category_type');
 
  if ( $data{'surname'} eq '') 
        {
-               $data=borrdata('',$borrowernumber);
+               $data=GetMember($borrowernumber,'borrowernumber');
                %data=%$data;
        }
- my ($category_type,$description) = getcategorytype($data{'categorycode'});    
+ my $borrowercategory = GetBorrowercategory($data{'categorycode'});    
 
 $template->param(              borrowernumber  => $borrowernumber,#register number
                                #transform value  in capital or capital for first letter of the word
@@ -70,11 +70,11 @@ $template->param(           borrowernumber  => $borrowernumber,#register number
                                surname         => uc($data{'surname'}),
                                categorycode    => $data{'categorycode'},
                                title           => $data{'title'},
-                               category_type   => $category_type,
+                               category_type   => $borrowercategory ->{'category_type'},
        # #                     
                                "title_".$data{'title'}             => " SELECTED ",                    
                                dateofbirth     => format_date($data{'dateofbirth'}),
-                               description     =>$description
+                               description     => $borrowercategory->{'description'}
 #                              
                                );
        $template->param(Institution => 1) if ($category_type eq "I");
index be734da..6e762e5 100755 (executable)
@@ -107,7 +107,8 @@ $template->param(intranetcolorstylesheet => C4::Context->preference("intranetcol
 output_html_with_http_headers $input, $cookie, $template->output;
 
 } else {
-       DeleteBorrower($member);
+       MoveMemberToDeleted($member);
+       DelMember($member);
        print $input->redirect("/cgi-bin/koha/members/members-home.pl");
 }
 
index 78eaf07..2d2ba0a 100755 (executable)
@@ -65,15 +65,15 @@ my $background = 0;
 if ($member ne ''){
        if(length($member) == 1)
        {
-               ($count,$results)=GuarantornameSearch($member,$orderby,"simple");
+               ($count,$results)=SearchBorrower($member,$orderby,"simple",'A');
        }
        else
        {
-               ($count,$results)=GuarantornameSearch($member,$orderby,"advanced");
+               ($count,$results)=SearchBorrower($member,$orderby,"advanced",'A');
        }
        for (my $i=0; $i < $count; $i++){
        #find out stats
-       my ($od,$issue,$fines)=borrdata2($results->[$i]{'borrowerid'});
+       my ($od,$issue,$fines)=GetBorrowerIssuesAndFines($results->[$i]{'borrowerid'});
        my $guarantorinfo=uc($results->[$i]{'surname'})." , ".ucfirst($results->[$i]{'firstname'});
        my %row = (
                background => $background,
index 2b2b869..a03502f 100755 (executable)
@@ -34,7 +34,7 @@ my $input=new CGI;
 my $borrowernumber=$input->param('borrowernumber');
 
 #get borrower details
-my $data=borrdata('',$borrowernumber);
+my $data=GetMember($borrowernumber,'borrowernumber');
 my $add=$input->param('add');
 
 if ($add){
index 217cd00..e462c27 100755 (executable)
@@ -34,7 +34,7 @@ my $input=new CGI;
 my $borrowernumber=$input->param('borrowernumber');
 
 # get borrower details
-my $data=borrdata('',$borrowernumber);
+my $data=GetMember($borrowernumber,'borrowernumber');
 my $add=$input->param('add');
 
 if ($add){
index dcb6e91..2e2b81b 100755 (executable)
@@ -72,11 +72,11 @@ my ($count,$results);
 
 if(length($member) == 1)
 {
-    ($count,$results)=BornameSearch($member,$orderby,"simple");
+    ($count,$results)=SearchBorrower($member,$orderby,"simple");
 }
 else
 {
-    ($count,$results)=BornameSearch($member,$orderby,"advanced");
+    ($count,$results)=SearchBorrower($member,$orderby,"advanced");
 }
 
 
@@ -84,7 +84,7 @@ my @resultsdata;
 my $background = 0;
 for (my $i=0; $i < $count; $i++){
   #find out stats
-  my ($od,$issue,$fines)=borrdata2($results->[$i]{'borrowernumber'});
+  my ($od,$issue,$fines)=GetBorrowerIssuesAndFines($results->[$i]{'borrowernumber'});
 
   my %row = (
     background => $background,
index 593a5f6..d6711f6 100755 (executable)
@@ -47,9 +47,10 @@ my $dbh = C4::Context->dbh;
 my $categorycode=$input->param('categorycode');
 my $category_type;
 $category_type = $input->param('category_type');
-
-my $desc;
-($category_type,$desc) = getcategorytype($categorycode) unless ($category_type or !($categorycode));
+unless ($category_type or !($categorycode)){
+  my $borrowercategory= GetBorrowercategory($categorycode);
+  $category_type = $borrowercategory->{'category_type'};
+}
 
 die "NO CATEGORY TYPE !" unless $category_type; # FIXME we should display a error message instead of a 500 error !
 
@@ -91,7 +92,7 @@ $template->param( "mandatory$_" => 1);
 }
 $template->param("add"=>1) if ($op eq 'add');
 $template->param( "checked" => 1) if ($nodouble eq 1);
-($borrower_data=borrdata('',$borrowernumber)) if($op eq 'modify');
+($borrower_data=GetMember($borrowernumber,'borrowernumber')) if($op eq 'modify');
 
 # if a add or modify is requested => check validity of data.
 if ($step eq 0){
@@ -110,17 +111,19 @@ if ($op eq 'add' or $op eq 'modify') {
        # WARN : some tests must be done whatever the step, because the librarian can click on any tab.
        #############test for member being unique #############
        if ($op eq 'add'){
-               (my $category_type_send=$category_type ) if ($category_type eq 'I'); 
-               my $check_category; # recover the category code of the doublon suspect borrowers
-          ($check_member,$check_category)= checkuniquemember($category_type_send,$data{'surname'},$data{'firstname'},format_date_in_iso($data{'dateofbirth'}));
-       
-#      recover the category type if the borrowers is a doublon 
-       ($check_categorytype,undef)=getcategorytype($check_category);
+          my $category_type_send=$category_type if ($category_type eq 'I'); 
+          my $check_category; # recover the category code of the doublon suspect borrowers
+          ($check_member,$check_category)= checkuniquemember($category_type_send,$data{'surname'},$data{'firstname'},format_date_in_iso($data{'dateofbirth'}));
+          
+  #    recover the category type if the borrowers is a doublon 
+          my $tmpborrowercategory=GetBorrowercategory($check_category);
+          $check_categorytype=$tmpborrowercategory->{'category_type'};
+          
        }
 
 #recover all data from guarantor address phone ,fax... 
 if ($category_type eq 'C' and $guarantorid ne '' ){
-                       my $guarantordata=getguarantordata($guarantorid);
+                       my $guarantordata=GetMember($guarantorid);
                        $guarantorinfo=$guarantordata->{'surname'}." , ".$guarantordata->{'firstname'};
                        if (($data{'contactname'} eq '' or $data{'contactname'} ne $guarantordata->{'surname'})) {
                                $data{'contactfirstname'}=$guarantordata->{'firstname'};        
@@ -155,9 +158,9 @@ if ($category_type eq 'C' and $guarantorid ne '' ){
         my $dateofbirthmandatory=0;
         map {$dateofbirthmandatory=1 if $_ eq "dateofbirth"} @field_check;
         if ($category_type ne 'I' && $data{dateofbirth} && $dateofbirthmandatory) {
-          my $age = get_age(format_date_in_iso($data{dateofbirth}));
-          my (undef,$agelimitmin,$agelimitmax,undef)=getborrowercategory($data{'categorycode'});   
-          if (($age > $agelimitmax) or ($age < $agelimitmin)) {
+          my $age = GetAge(format_date_in_iso($data{dateofbirth}));
+          my $borrowercategory=GetBorrowercategory($data{'categorycode'});   
+          if (($age > $borrowercategory->{'upperagelimit'}) or ($age < $borrowercategory->{'dateofbirthrequired'})) {
             push @errors, 'ERROR_age_limitations';
             $nok = 1;
           }
@@ -166,27 +169,23 @@ if ($category_type eq 'C' and $guarantorid ne '' ){
 
 # STEP 2
        if ($step eq 2) {
-       
-       
-                       if ( ($data{'userid'} eq '')){
-                               my $onefirstnameletter=substr($data{'firstname'},0,1);
-                               my $fivesurnameletter=substr($data{'surname'},0,5);
-                               $data{'userid'}=lc($onefirstnameletter.$fivesurnameletter);
-                       }
-                       if ($op eq 'add' and $data{'dateenrolled'} eq ''){
-                               my $today= sprintf('%04d-%02d-%02d', Today());
-                               #insert ,in field "dateenrolled" , the current date
-                               $data{'dateenrolled'}=$today;
-                               #if date expiry is null u must calculate the value only in this case
-                               $data{'dateexpiry'} = calcexpirydate($data{'categorycode'},$today);
-                       }
-                       if ($op eq 'modify' ){
-                       my $today= sprintf('%04d-%02d-%02d', Today());
-#                      if date expiry is null u must calculate the value only in this case
-                       if ($data{'dateexpiry'} eq ''){
-                       $data{'dateexpiry'} = calcexpirydate($data{'categorycode'},$today);
-                       }
-               }
+            if ( ($data{'userid'} eq '')){
+              my $onefirstnameletter=substr($data{'firstname'},0,1);
+              my $fivesurnameletter=substr($data{'surname'},0,5);
+              $data{'userid'}=lc($onefirstnameletter.$fivesurnameletter);
+            }
+            if ($op eq 'add' and $data{'dateenrolled'} eq ''){
+              my $today= sprintf('%04d-%02d-%02d', Today());
+              #insert ,in field "dateenrolled" , the current date
+              $data{'dateenrolled'}=$today;
+              $data{'dateexpiry'} = GetExpiryDate($data{'categorycode'},$today);
+            }
+            if ($op eq 'modify' ){
+              unless ($data{'dateexpiry'}){
+                my $today= sprintf('%04d-%02d-%02d', Today());
+                $data{'dateexpiry'} = GetExpiryDate($data{'categorycode'},$today);
+              }
+            }
        }
 # STEP 3
        if ($step eq 3) {
@@ -196,7 +195,7 @@ if ($category_type eq 'C' and $guarantorid ne '' ){
                if ($op eq 'modify'){
                        # test to know if another user have the same password and same login            
                        if ($loginexist eq 0) {
-                               &modmember(%data);              
+                               &ModMember(%data);              
                        }
                        else {
                                push @errors, "ERROR_login_exist";
@@ -208,7 +207,7 @@ if ($category_type eq 'C' and $guarantorid ne '' ){
                                push @errors, "ERROR_login_exist";
                                $nok=1;
                        } else {
-                               $borrowernumber = &newmember(%data);
+                               $borrowernumber = &AddMember(%data);
                                if ($data{'organisations'}){                                
                                    # need to add the members organisations
                                    my @orgs=split(/\|/,$data{'organisations'});
@@ -245,7 +244,7 @@ if ($delete){
        my $data;
 # test to now if u add or modify a borrower (modify =>to take all carateristic of the borrowers)
        if (!$op and !$data{'surname'}) {
-               $data=borrdata('',$borrowernumber);
+               $data=GetMember($borrowernumber,'borrowernumber');
                %data=%$data;
        }
        if (C4::Context->preference("IndependantBranches")) {
index 5711268..b401b07 100755 (executable)
@@ -78,7 +78,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 my $borrowernumber = $input->param('borrowernumber');
 
 #start the page and read in includes
-my $data           = borrdata( '', $borrowernumber );
+my $data           = GetMember( $borrowernumber ,'borrowernumber');
 my $reregistration = $input->param('reregistration');
 
 if ( not defined $data ) {
@@ -96,9 +96,9 @@ if ( not defined $data ) {
         $borrowernumber, $data->{'dateenrolled'}
     )
 ) if ( $reregistration eq 'y' );
-my ( undef, undef, undef, $category_type ) =
-  getborrowercategory( $data->{'categorycode'} );
-  
+my $borrowercategory = GetBorrowercategory( $data->{'categorycode'} );
+my $category_type = $borrowercategory->{'category_type'};
+
 # in template <TMPL_IF name="I"> => instutitional (A for Adult& C for children) 
 $template->param( $data->{'categorycode'} => 1 ); 
 
@@ -120,7 +120,7 @@ $data->{'ethnicity'} = fixEthnicity( $data->{'ethnicity'} );
 $data->{ &expand_sex_into_predicate( $data->{'sex'} ) } = 1;
 
 if ( $category_type eq 'C' and $data->{'guarantorid'} ne '0' ) {
-    my $data2 = borrdata( '', $data->{'guarantorid'} );
+    my $data2 = GetMember( $data->{'guarantorid'} ,'borrowernumber');
     $data->{'address'}   = $data2->{'address'};
     $data->{'city'}      = $data2->{'city'};
     $data->{'B_address'} = $data2->{'B_address'};
@@ -140,7 +140,7 @@ if ( $category_type eq 'A' ) {
     # It looks like the $i is only being returned to handle walking through
     # the array, which is probably better done as a foreach loop.
     #
-    my ( $count, $guarantees ) = findguarantees( $data->{'borrowernumber'} );
+    my ( $count, $guarantees ) = GetGuarantees( $data->{'borrowernumber'} );
     my @guaranteedata;
     for ( my $i = 0 ; $i < $count ; $i++ ) {
         push(
@@ -158,16 +158,15 @@ if ( $category_type eq 'A' ) {
 
 }
 else {
-    my ($guarantorid) = findguarantor( $data->{'borrowernumber'} );
-    ( $template->param( guarantor => 1 ) )
-      if ( ( $data->{'guarantorid'} > '0' ) );
-    if ( $guarantorid->{'borrowernumber'} ) {
-        $template->param(
-            guarantorborrowernumber => $guarantorid->{'borrowernumber'},
-            guarantorcardnumber     => $guarantorid->{'cardnumber'},
-            guarantorfirstname      => $guarantorid->{'firstname'},
-            guarantorsurname        => $guarantorid->{'surname'}
-        );
+    if ($data->{'guarantorid'}){
+      my ($guarantor) = GetMember( $data->{'guarantorid'},'biblionumber');
+      $template->param( 
+              guarantor => 1,
+              guarantorborrowernumber => $guarantor->{'borrowernumber'},
+              guarantorcardnumber     => $guarantor->{'cardnumber'},
+              guarantorfirstname      => $guarantor->{'firstname'},
+              guarantorsurname        => $guarantor->{'surname'}
+          );
     }
 }
 
@@ -193,11 +192,8 @@ if ( C4::Context->preference("IndependantBranches") ) {
 $data->{'branchname'} =
   ( ( GetBranchDetail( $data->{'branchcode'} ) )->{'branchname'} );
 
-# Converts the categorycode to the description
-( $data->{'categorycode'}, undef, undef ) =
-  &getborrowercategory( $data->{'categorycode'} );
 
-my ( $numaccts, $accts, $total ) = getboracctrecord( '', \%bor );
+my ( $total, $accts, $numaccts) = GetBorrowerAcctRecord( $borrowernumber );
 my $lib1 = &GetSortDetails( "Bsort1", $data->{'sort1'} );
 my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
 ( $template->param( lib1 => $lib1 ) ) if ($lib1);
@@ -205,7 +201,7 @@ my $lib2 = &GetSortDetails( "Bsort2", $data->{'sort2'} );
 
 # current issues
 #
-my ( $count, $issue ) = borrissues($borrowernumber);
+my ( $count, $issue ) = GetPendingIssues($borrowernumber);
 my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
 my $today       = ParseDate('today');
 my @issuedata;
index b4883b5..4e4243d 100755 (executable)
@@ -46,12 +46,10 @@ if ( $borrowernumber eq '' ) {
 }
 
 # get borrower details
-my $data = borrdata( '', $borrowernumber );
+my $data = GetMember( $borrowernumber,'borrowernumber' );
 my $user = $input->remote_user;
 
 # get account details
-my %bor;
-$bor{'borrowernumber'} = $borrowernumber;
 my $branches = GetBranches();
 my $printers = GetPrinters();
 my $branch   = GetBranch( $input, $branches );
@@ -91,7 +89,7 @@ if ( $check == 0 ) {
         recordpayment( $borrowernumber, $total );
     }
 
-    my ( $numaccts, $accts, $total ) = getboracctrecord( '', \%bor );
+    my ( $total, $accts, $numaccts) = GetBorrowerAcctRecord( $borrowernumber );
 
 #       creation d'une fonction qui va nous retourner le notify_id dans un tableau
 
index 5a0446b..d41f2b9 100755 (executable)
@@ -33,7 +33,7 @@ my $input=new CGI;
 
 my $borrowernumber=$input->param('borrowernumber');
 #get borrower details
-my $data=borrdata('',$borrowernumber);
+my $data=GetMember($borrowernumber,'borrowernumber');
 my $order=$input->param('order');
 my $order2=$order;
 if ($order2 eq ''){
@@ -49,7 +49,7 @@ if ($limit){
 else {
   $limit=50;
 }
-my ($count,$issues)=allissues($borrowernumber,$order2,$limit);
+my ($count,$issues)=GetAllIssues($borrowernumber,$order2,$limit);
 
 my ($template, $loggedinuser, $cookie)
 = get_template_and_user({template_name => "members/readingrec.tmpl",
index 3548f61..09e76b4 100755 (executable)
@@ -315,7 +315,7 @@ my %actions;
                                 $template->param(BOOKDETAILS => \@bookdetails);
                                 my %params;
                                 %params->{'borrowernumber'} = $overdue->{'borrowernumber'};
-                                my ($count, $acctlines, $total) = &getboracctrecord(\%params);
+                                my ($total, $acctlines, $count) = &GetBorrowerAcctRecord($overdue->{'borrowernumber'});
                                             $template->param(FINES_TOTAL => $total_fines);
                             $template->param(OWING => $total);
                             my $name= "$borrower->{'firstname'} $borrower->{'surname'}";
index df7f45d..1fd8229 100755 (executable)
@@ -173,7 +173,7 @@ $res =~ s/\(\)//g;
 my $reviews = getreviews( $biblionumber, 1 );
 foreach ( @$reviews ) {
     my $borrower_number_review = $_->{borrowernumber};
-    my $borrowerData           = GetMember('',$borrower_number_review);
+    my $borrowerData           = GetMember($borrower_number_review,'borrowernumber');
     # setting some borrower info into this hash
     $_->{title}     = $borrowerData->{'title'};
     $_->{surname}   = $borrowerData->{'surname'};
index 3a2ffaa..6136735 100755 (executable)
@@ -41,7 +41,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
 );
 
 # get borrower information ....
-my ( $borr, $flags ) = GetMemberDetails( $borrowernumber );
+my $borr = GetMemberDetails( $borrowernumber );
 
 my @bordat;
 $bordat[0] = $borr;
@@ -49,7 +49,7 @@ $bordat[0] = $borr;
 $template->param( BORROWER_INFO => \@bordat );
 
 #get account details
-my ( $numaccts, $accts, $total ) = getboracctrecord( undef, $borr );
+my ( $total , $accts, $numaccts) = GetBorrowerAcctRecord( $borrowernumber );
 
 for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
     $accts->[$i]{'date'} = format_date( $accts->[$i]{'date'} );
index 2d03c31..68d5769 100755 (executable)
@@ -110,7 +110,7 @@ foreach ( keys %{$dat} ) {
 my $reviews = getreviews( $biblionumber, 1 );
 foreach ( @$reviews ) {
     my $borrower_number_review = $_->{borrowernumber};
-    my $borrowerData           = GetMember('',$borrower_number_review);
+    my $borrowerData           = GetMember($borrower_number_review,'borrowernumber');
     # setting some borrower info into this hash
     $_->{title}     = $borrowerData->{'title'};
     $_->{surname}   = $borrowerData->{'surname'};
index 6c1b59f..bec99cc 100755 (executable)
@@ -68,7 +68,7 @@ if($limit) {
     );
 }
 
-my $borrower = GetMember( '', $borrowernumber );
+my $borrower = GetMember( $borrowernumber,'borrowernumber' );
 my @languages;
 my $counter = 0;
 my $langavail = getTranslatedLanguages('opac');
index ef4408f..4c7cbda 100755 (executable)
@@ -69,7 +69,7 @@ if ( $limit eq 'full' ) {
 else {
     $limit = 50;
 }
-my ( $count, $issues ) = allissues( $borrowernumber, $order2, $limit );
+my ( $count, $issues ) = GetAllIssues( $borrowernumber, $order2, $limit );
 
 # add the row parity
 #my $num = 0;
index 1be5e6a..87d46b9 100755 (executable)
@@ -92,7 +92,7 @@ foreach my $issue ( @$issues ) {
         $issue->{'reserved'} = 1;
     }
     
-    my ( $numaccts, $accts, $total ) = getboracctrecord( undef, $borr );
+    my ( $total , $accts, $numaccts) = GetBorrowerAcctRecord( $borrowernumber );
     my $charges = 0;
     foreach my $ac (@$accts) {
         if ( $ac->{'itemnumber'} == $issue->{'itemnumber'} ) {
index 2d42d6e..5d9f367 100755 (executable)
@@ -41,7 +41,7 @@ my $branch=$input->param('pickup');
 my @rank=$input->param('rank-request');
 my $type=$input->param('type');
 my $title=$input->param('title');
-my $borrowernumber=borrdata($borrower,'');
+my $borrowernumber=GetMember($borrower,'cardnumber');
 my $checkitem=$input->param('checkitem');
 my $found;
 
index 1beb70c..b3411ae 100755 (executable)
@@ -69,7 +69,7 @@ my $date = sprintf( '%04d-%02d-%02d', Today() );
 
 if ($findborrower) {
     my ( $count, $borrowers ) =
-      BornameSearch($findborrower, 'cardnumber', 'web' );
+      SearchBorrower($findborrower, 'cardnumber', 'web' );
 
     my @borrowers = @$borrowers;
 
index 4d4e456..b4f4a0c 100755 (executable)
@@ -51,7 +51,7 @@ my $reviews = getallreviews(0);
 
 foreach ( @$reviews ) {
     my $borrowernumber = $_->{borrowernumber};
-    my $borrowerData   = GetMember('',$borrowernumber);
+    my $borrowerData   = GetMember($borrowernumber,'borrowernumber');
     my $biblioData     = GetBiblioData($_->{biblionumber});
     # setting some borrower info into this hash
     $_->{bibliotitle} = $biblioData->{'title'};
index 6571625..dcb9608 100755 (executable)
@@ -43,7 +43,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
 );
 
 if ($searchstring) {
-    my ( $count, $members ) = &BornameSearch( '', $searchstring, "surname" );
+    my ( $count, $members ) = &SearchBorrower( '', $searchstring, "surname" );
 
     $template->param(
         subscriptionid => $subscriptionid,
index 7d0bb64..39dd696 100755 (executable)
@@ -100,7 +100,7 @@ if($ok){
 my @results;
 my $data;
 for(my $i=0;$i<$routing;$i++){
-    $data=borrdata('',$routinglist[$i]->{'borrowernumber'});
+    $data=GetMember($routinglist[$i]->{'borrowernumber'},'borrowernumber');
     $data->{'location'}=$data->{'streetaddress'};
     $data->{'name'}="$data->{'firstname'} $data->{'surname'}";
     $data->{'routingid'}=$routinglist[$i]->{'routingid'};
index 37842d8..f4d5be7 100755 (executable)
@@ -105,7 +105,7 @@ my ($template, $loggedinuser, $cookie)
 my @results;
 my $data;
 for(my $i=0;$i<$routing;$i++){
-    $data=borrdata('',$routinglist[$i]->{'borrowernumber'});
+    $data=GetMember($routinglist[$i]->{'borrowernumber'},'borrowernumber');
     $data->{'location'}=$data->{'streetaddress'};
     $data->{'name'}="$data->{'firstname'} $data->{'surname'}";
     $data->{'routingid'}=$routinglist[$i]->{'routingid'};
index 5f71b13..0928e71 100755 (executable)
@@ -114,13 +114,14 @@ if ( $params->{'step3'} ) {
         if ( $radio eq 'trash' ) {
             my $i;
             for ( $i = 0 ; $i < $totalDel ; $i++ ) {
-                DeleteBorrower( $membersToDelete->[$i]->{'borrowernumber'} );
+                MoveMemberToDeleted( $membersToDelete->[$i]->{'borrowernumber'} );
+                DelMember( $membersToDelete->[$i]->{'borrowernumber'} );
             }
         }
         else {    # delete completly.
             my $i;
             for ( $i = 0 ; $i < $totalDel ; $i++ ) {
-               DelBorrowerCompletly($membersToDelete->[$i]->{'borrowernumber'});
+               DelMember($membersToDelete->[$i]->{'borrowernumber'});
             }
         }
         $template->param(