renamed CheckSpecificUserPermissions to GranularPermissions
[koha_gimpoz] / C4 / Accounts.pm
index a8db930..3a648e4 100644 (file)
@@ -23,18 +23,19 @@ use C4::Context;
 use C4::Stats;
 use C4::Members;
 use C4::Items;
+use C4::Circulation;
 
-#use C4::Circulation;
 use vars qw($VERSION @ISA @EXPORT);
 
 BEGIN {
        # set the version for version checking
-       $VERSION = 3.01;
+       $VERSION = 3.02;
        require Exporter;
        @ISA    = qw(Exporter);
        @EXPORT = qw(
                &recordpayment &fixaccounts &makepayment &manualinvoice
-               &getnextacctno &reconcileaccount
+               &getnextacctno &reconcileaccount &getcharges &getcredits
+               &getrefunds
        );
 }
 
@@ -126,7 +127,7 @@ sub recordpayment {
     );
     $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft );
     $usth->finish;
-    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber );
+    UpdateStats( $branch, 'payment', $data, '', '', '', $borrowernumber, $nextaccntno );
     $sth->finish;
 }
 
@@ -265,22 +266,13 @@ sub fixaccounts {
 EOT
 }
 
-# FIXME - Never used, but not exported, either.
 sub returnlost {
     my ( $borrowernumber, $itemnum ) = @_;
-    my $dbh      = C4::Context->dbh;
+    C4::Circulation::MarkIssueReturned( $borrowernumber, $itemnum );
     my $borrower = C4::Members::GetMember( $borrowernumber, 'borrowernumber' );
-    my $sth      = $dbh->prepare(
-        "UPDATE issues SET returndate=now() WHERE
-  borrowernumber=? AND itemnumber=? AND returndate IS NULL"
-    );
-    $sth->execute( $borrowernumber, $itemnum );
-    $sth->finish;
     my @datearr = localtime(time);
-    my $date =
-      ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
-    my $bor =
-"$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
+    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
+    my $bor = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
     ModItem({ paidfor =>  "Paid for by $bor $date" }, undef, $itemnum);
 }
 
@@ -535,6 +527,64 @@ sub refund {
     return ($amountleft);
 }
 
+sub getcharges {
+       my ( $borrowerno, $timestamp, $accountno ) = @_;
+       my $dbh        = C4::Context->dbh;
+       my $timestamp2 = $timestamp - 1;
+       my $query      = "";
+       my $sth = $dbh->prepare(
+                       "SELECT * FROM accountlines WHERE borrowernumber=? AND accountno = ?"
+          );
+       $sth->execute( $borrowerno, $accountno );
+       
+    my @results;
+    while ( my $data = $sth->fetchrow_hashref ) {
+               push @results,$data;
+       }
+    return (@results);
+}
+
+
+sub getcredits {
+       my ( $date, $date2 ) = @_;
+       my $dbh = C4::Context->dbh;
+       my $sth = $dbh->prepare(
+                               "SELECT * FROM accountlines,borrowers
+      WHERE amount < 0 AND accounttype <> 'Pay' AND accountlines.borrowernumber = borrowers.borrowernumber
+         AND timestamp >=TIMESTAMP(?) AND timestamp < TIMESTAMP(?)"
+      );  
+
+    $sth->execute( $date, $date2 );                                                                                                              
+    my @results;          
+    while ( my $data = $sth->fetchrow_hashref ) {
+               $data->{'date'} = $data->{'timestamp'};
+               push @results,$data;
+       }
+    return (@results);
+} 
+
+
+sub getrefunds {
+       my ( $date, $date2 ) = @_;
+       my $dbh = C4::Context->dbh;
+       
+       my $sth = $dbh->prepare(
+                               "SELECT *,timestamp AS datetime                                                                                      
+                  FROM accountlines,borrowers
+                  WHERE (accounttype = 'REF'
+                                         AND accountlines.borrowernumber = borrowers.borrowernumber
+                                                         AND date  >=?  AND date  <?)"
+    );
+
+    $sth->execute( $date, $date2 );
+
+    my @results;
+    while ( my $data = $sth->fetchrow_hashref ) {
+               push @results,$data;
+               
+       }
+    return (@results);
+}
 END { }    # module clean-up code here (global destructor)
 
 1;