From 3a01b224874ffc914d4dd650eb709f790dc565e7 Mon Sep 17 00:00:00 2001
From: Kyle M Hall <kyle@bywatersolutions.com>
Date: Wed, 11 Dec 2013 11:04:21 -0500
Subject: [PATCH] Bug 6427 [Part 7] - Update cron scripts

---
 misc/cronjobs/create_koc_db.pl |   41 +---------------------------------------
 misc/cronjobs/fines.pl         |   10 ++++++--
 2 files changed, 8 insertions(+), 43 deletions(-)

diff --git a/misc/cronjobs/create_koc_db.pl b/misc/cronjobs/create_koc_db.pl
index ccc4a5b..f49519e 100755
--- a/misc/cronjobs/create_koc_db.pl
+++ b/misc/cronjobs/create_koc_db.pl
@@ -256,10 +256,8 @@ SELECT borrowernumber,
        city,
        phone,
        dateofbirth,
-       sum( accountlines.amountoutstanding ) as total_fines
+       account_balance as total_fines
 FROM borrowers
-LEFT JOIN accountlines USING (borrowernumber)
-GROUP BY borrowernumber;
 END_SQL
 
     my $fields_count = $sth_mysql->execute();
@@ -278,43 +276,6 @@ END_SQL
     }
     $dbh_sqlite->commit();
     print "inserted $count borrowers\n" if $verbose;
-    # add_fines_to_borrowers_table();
-}
-
-=head2 add_fines_to_borrowers_table
-
-Import the fines from koha.accountlines into the sqlite db
-
-=cut
-
-sub add_fines_to_borrowers_table {
-
-    print "preparing to update borrowers\n" if $verbose;
-    my $sth_mysql = $dbh_mysql->prepare(
-        "SELECT DISTINCT borrowernumber, SUM( amountoutstanding ) AS total_fines
-                                    FROM accountlines
-                                    GROUP BY borrowernumber"
-    );
-    $sth_mysql->execute();
-    my $count;
-    while ( my $result = $sth_mysql->fetchrow_hashref() ) {
-        $count++;
-        if ( $verbose ) {
-            print '.' unless ( $count % 10 );
-            print "$count\n" unless ( $count % 1000 );
-        }
-
-        my $borrowernumber = $result->{'borrowernumber'};
-        my $total_fines    = $result->{'total_fines'};
-
-        # warn "Fines for Borrower # $borrowernumber are \$ $total_fines \n" if $verbose;
-        my $sql = "UPDATE borrowers SET total_fines = ? WHERE borrowernumber = ?";
-
-        my $sth_sqlite = $dbh_sqlite->prepare($sql);
-        $sth_sqlite->execute( $total_fines, $borrowernumber );
-        $sth_sqlite->finish();
-    }
-    print "updated $count borrowers\n" if ( $verbose && $count );
 }
 
 =head2 create_issue_table
diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl
index 02bde14..f85b898 100755
--- a/misc/cronjobs/fines.pl
+++ b/misc/cronjobs/fines.pl
@@ -127,9 +127,13 @@ for my $overdue ( @{$overdues} ) {
     if ( $mode eq 'production' && !$is_holiday{$branchcode} ) {
         if ( $amount > 0 ) {
             UpdateFine(
-                $overdue->{itemnumber},
-                $overdue->{borrowernumber},
-                $amount, $type, output_pref($datedue)
+                {
+                    itemnumber     => $overdue->{itemnumber},
+                    borrowernumber => $overdue->{borrowernumber},
+                    amount         => $amount,
+                    due            => output_pref($datedue),
+                    issue_id       => $overdue->{issue_id}
+                }
             );
         }
     }
-- 
1.7.2.5