C4::Debug - Centralized debug switches module, test and proof conversion (in Dates.pm)
[koha.git] / C4 / Accounts.pm
old mode 100755 (executable)
new mode 100644 (file)
index c03a0cd..e46e39d
@@ -17,21 +17,27 @@ package C4::Accounts;
 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
 # Suite 330, Boston, MA  02111-1307 USA
 
-# $Id$
 
 use strict;
-require Exporter;
 use C4::Context;
 use C4::Stats;
 use C4::Members;
+use C4::Items;
 
 #use C4::Circulation;
 use vars qw($VERSION @ISA @EXPORT);
 
-# set the version for version checking
-$VERSION = do { my @v = '$Revision$' =~ /\d+/g;
-    shift(@v) . "." . join( "_", map { sprintf "%03d", $_ } @v );
-};
+BEGIN {
+       # set the version for version checking
+       $VERSION = 3.02;
+       require Exporter;
+       @ISA    = qw(Exporter);
+       @EXPORT = qw(
+               &recordpayment &fixaccounts &makepayment &manualinvoice
+               &getnextacctno &reconcileaccount &getcharges &getcredits
+               &getrefunds
+       );
+}
 
 =head1 NAME
 
@@ -49,12 +55,6 @@ patron.
 
 =head1 FUNCTIONS
 
-=cut
-
-@ISA    = qw(Exporter);
-@EXPORT = qw(&recordpayment &fixaccounts &makepayment &manualinvoice
-  &getnextacctno &reconcileaccount);
-
 =head2 recordpayment
 
   &recordpayment($borrowernumber, $payment);
@@ -127,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;
 }
 
@@ -282,9 +282,7 @@ sub returnlost {
       ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
     my $bor =
 "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
-    $sth = $dbh->prepare("UPDATE items SET paidfor=? WHERE itemnumber=?");
-    $sth->execute( "Paid for by $bor $date", $itemnum );
-    $sth->finish;
+    ModItem({ paidfor =>  "Paid for by $bor $date" }, undef, $itemnum);
 }
 
 =head2 manualinvoice
@@ -538,12 +536,69 @@ 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;
 __END__
 
-
 =head1 SEE ALSO
 
 DBI(3)