Bug 5811: Add sysprefs to control overriding fines
[koha.git] / C4 / Members.pm
index cddbf41..a292054 100644 (file)
@@ -93,6 +93,7 @@ BEGIN {
        push @EXPORT, qw(
                &ModMember
                &changepassword
+         &ModPrivacy
        );
 
        #Delete data
@@ -443,7 +444,7 @@ sub patronflags {
         my $noissuescharge = C4::Context->preference("noissuescharge") || 5;
         $flaginfo{'message'} = sprintf "Patron owes \$%.02f", $amount;
         $flaginfo{'amount'}  = sprintf "%.02f", $amount;
-        if ( $amount > $noissuescharge ) {
+        if ( $amount > $noissuescharge && !C4::Context->preference("AllowFineOverride") ) {
             $flaginfo{'noissues'} = 1;
         }
         $flags{'CHARGES'} = \%flaginfo;
@@ -484,7 +485,7 @@ sub patronflags {
         $flags{'NOTES'}      = \%flaginfo;
     }
     my ( $odues, $itemsoverdue ) = checkoverdues($patroninformation->{'borrowernumber'});
-    if ( $odues > 0 ) {
+    if ( $odues && $odues > 0 ) {
         my %flaginfo;
         $flaginfo{'message'}  = "Yes";
         $flaginfo{'itemlist'} = $itemsoverdue;
@@ -937,22 +938,16 @@ with the modified information
 
 #'
 sub UpdateGuarantees {
-    my (%data) = @_;
+    my %data = shift;
     my $dbh = C4::Context->dbh;
     my ( $count, $guarantees ) = GetGuarantees( $data{'borrowernumber'} );
-    for ( my $i = 0 ; $i < $count ; $i++ ) {
-
-        # FIXME
-        # It looks like the $i is only being returned to handle walking through
-        # the array, which is probably better done as a foreach loop.
-        #
+    foreach my $guarantee (@$guarantees){
         my $guaquery = qq|UPDATE borrowers 
-              SET address='$data{'address'}',fax='$data{'fax'}',
-                  B_city='$data{'B_city'}',mobile='$data{'mobile'}',city='$data{'city'}',phone='$data{'phone'}'
-              WHERE borrowernumber='$guarantees->[$i]->{'borrowernumber'}'
+              SET address=?,fax=?,B_city=?,mobile=?,city=?,phone=?
+              WHERE borrowernumber=?
         |;
-        my $sth3 = $dbh->prepare($guaquery);
-        $sth3->execute;
+        my $sth = $dbh->prepare($guaquery);
+        $sth->execute($data{'address'},$data{'fax'},$data{'B_city'},$data{'mobile'},$data{'city'},$data{'phone'},$guarantee->{'borrowernumber'});
     }
 }
 =head2 GetPendingIssues
@@ -2028,6 +2023,31 @@ sub DebarMember {
     
 }
 
+=head2 ModPrivacy
+
+=over 4
+
+my $success = ModPrivacy( $borrowernumber, $privacy );
+
+Update the privacy of a patron.
+
+return :
+true on success, false on failure
+
+=back
+
+=cut
+
+sub ModPrivacy {
+    my $borrowernumber = shift;
+    my $privacy = shift;
+    return unless defined $borrowernumber;
+    return unless $borrowernumber =~ /^\d+$/;
+
+    return ModMember( borrowernumber => $borrowernumber,
+                      privacy        => $privacy );
+}
+
 =head2 AddMessage
 
   AddMessage( $borrowernumber, $message_type, $message, $branchcode );
@@ -2079,7 +2099,7 @@ sub GetMessages {
     my $query = "SELECT
                   branches.branchname,
                   messages.*,
-                  DATE_FORMAT( message_date, '%m/%d/%Y' ) AS message_date_formatted,
+                  message_date,
                   messages.branchcode LIKE '$branchcode' AS can_delete
                   FROM messages, branches
                   WHERE borrowernumber = ?
@@ -2091,6 +2111,8 @@ sub GetMessages {
     my @results;
 
     while ( my $data = $sth->fetchrow_hashref ) {
+        my $d = C4::Dates->new( $data->{message_date}, 'iso' );
+        $data->{message_date_formatted} = $d->output;
         push @results, $data;
     }
     return \@results;