[Koha-patches] [PATCH] Fines sytem updates

Kyle M Hall kyle.m.hall at gmail.com
Wed Oct 7 15:35:18 CEST 2009


This is the first step in the massive upgrade to the accounts system work discussed in the RFC on the koha-devel list.

Updated the accountlines table.
Make accountno the key, upgraded to int(11), auto_increment.
Added accountno_paid field.
Modified makepayment to store accountno for fine being paid in accountno_paid for the payment made.

Added accountnumbers and accountnumbers paid to boraccount.
---
 C4/Accounts.pm                                     |   28 +++++++++++++-
 C4/Items.pm                                        |   40 ++++++++++++++++++++
 installer/data/mysql/kohastructure.sql             |    4 +-
 installer/data/mysql/updatedatabase.pl             |    9 ++++
 .../prog/en/modules/members/boraccount.tmpl        |   10 +++-
 members/boraccount.pl                              |   38 ++++++++++++-------
 6 files changed, 109 insertions(+), 20 deletions(-)

diff --git a/C4/Accounts.pm b/C4/Accounts.pm
index e137587..71a836f 100644
--- a/C4/Accounts.pm
+++ b/C4/Accounts.pm
@@ -37,6 +37,7 @@ BEGIN {
 		&getnextacctno &reconcileaccount &getcharges &getcredits
 		&getrefunds &chargelostitem
 		&ReversePayment
+		&GetItemByAccountNumber
 	); # removed &fixaccounts
 }
 
@@ -188,9 +189,9 @@ sub makepayment {
     my $payment = 0 - $amount;
     $dbh->do( "
         INSERT INTO     accountlines
-                        (borrowernumber, accountno, date, amount,
+                        (borrowernumber, accountno, accountno_paid, date, amount,
                          description, accounttype, amountoutstanding)
-        VALUES          ($borrowernumber, $nextaccntno, now(), $payment,
+        VALUES          ($borrowernumber, $nextaccntno, $accountno, now(), $payment,
                         'Payment,thanks - $user', 'Pay', 0)
         " );
 
@@ -662,6 +663,29 @@ sub ReversePayment {
   }
 }
 
+=head2 GetItemByAccountNumber
+
+ $item = GetItemNumberByAccountNumber( $accountno );
+
+=cut
+
+sub GetItemByAccountNumber {
+  my ( $accountno ) = @_;
+  
+  return unless $accountno;
+  
+  my $dbh = C4::Context->dbh;
+  my $sth = $dbh->prepare('SELECT itemnumber FROM accountlines WHERE accountno = ?');
+  $sth->execute( $accountno );
+  my $accountline = $sth->fetchrow_hashref();
+  my $itemnumber = $accountline->{'itemnumber'};
+  
+  return unless $itemnumber;
+
+  my $item = GetItemWithBiblio( $itemnumber );
+  return $item;
+}
+
 END { }    # module clean-up code here (global destructor)
 
 1;
diff --git a/C4/Items.pm b/C4/Items.pm
index 3f550ef..15e96ae 100644
--- a/C4/Items.pm
+++ b/C4/Items.pm
@@ -42,6 +42,7 @@ BEGIN {
     # function exports
     @EXPORT = qw(
         GetItem
+        GetItemWithBiblio
         AddItemFromMarc
         AddItem
         AddItemBatchFromMarc
@@ -156,6 +157,45 @@ sub GetItem {
     return $data;
 }    # sub GetItem
 
+=head2 GetItemWithBiblio
+
+=over 4
+
+$item = GetItemWithBiblio( $itemnumber, $barcode );
+
+=back
+
+Return item information, for a given itemnumber or barcode.
+The return value is a hashref mapping item column
+names to values.
+
+=cut
+
+sub GetItemWithBiblio {
+    my ( $itemnumber, $barcode ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth;
+
+    return unless ( $itemnumber || $barcode );
+
+    my $sql = "SELECT * FROM biblio, biblioitems, items 
+              WHERE items.biblionumber = biblio.biblionumber 
+              AND items.biblioitemnumber = biblioitems.biblioitemnumber
+              AND ";
+	
+    if ($itemnumber) {
+      $sql .= "itemnumber = ?";
+      $sth = $dbh->prepare( $sql );
+      $sth->execute( $itemnumber );
+    } else {
+      $sql .= "barcode = ?";
+      $sth = $dbh->prepare( $sql );
+      $sth->execute( $barcode );
+    }
+
+    return $sth->fetchrow_hashref();
+}
+
 =head2 CartToShelf
 
 =over 4
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index eaf47e0..d8f8f43 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -22,7 +22,8 @@
 DROP TABLE IF EXISTS `accountlines`;
 CREATE TABLE `accountlines` (
   `borrowernumber` int(11) NOT NULL default 0,
-  `accountno` smallint(6) NOT NULL default 0,
+  `accountno` int(11) NOT NULL auto_increment,
+  `accountno_paid` int(11) default NULL,
   `itemnumber` int(11) default NULL,
   `date` date default NULL,
   `amount` decimal(28,6) default NULL,
@@ -34,6 +35,7 @@ CREATE TABLE `accountlines` (
   `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
   `notify_id` int(11) NOT NULL default 0,
   `notify_level` int(2) NOT NULL default 0,
+  PRIMARY KEY (`accountno`),
   KEY `acctsborridx` (`borrowernumber`),
   KEY `timeidx` (`timestamp`),
   KEY `itemnumber` (`itemnumber`),
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 10c3451..218d633 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -2675,6 +2675,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
+$DBversion = '3.01.00.062';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("ALTER TABLE `accountlines` ADD PRIMARY KEY(`accountno`)");
+    $dbh->do("ALTER TABLE `accountlines` CHANGE `accountno` `accountno` INT( 11 ) NOT NULL AUTO_INCREMENT");
+    $dbh->do("ALTER TABLE `accountlines` ADD `accountno_paid` INT( 11 ) NULL AFTER `accountno`");
+	print "Upgrade to $DBversion done ( Updates to fines system )\n";
+    SetVersion ($DBversion);
+}
+
 =item DropAllForeignKeys($table)
 
   Drop all foreign keys of the table $table
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl
index 8f649ad..802139e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl
@@ -28,8 +28,10 @@
 <!-- The table with the account items -->
 <table>
   <tr>
-  	<th>Date</th>
+    <th>Account<br/>Number</th>
+    <th>Date</th>
     <th>Description of charges</th>
+    <th>Account<br/>Paid</th>
     <th>Amount</th>
     <th>Outstanding</th>
     <th>&nbsp;</th>
@@ -39,8 +41,10 @@
   <!-- TMPL_LOOP NAME="accounts" -->
 
    <!-- TMPL_IF NAME="toggle" --> <tr><!-- TMPL_ELSE --><tr class="highlight"><!-- /TMPL_IF -->
+      <td><!-- TMPL_VAR NAME="accountno" --></td>
       <td><!-- TMPL_VAR NAME="date" --></td>
-      <td><!-- TMPL_VAR NAME="description" -->&nbsp;<!-- TMPL_IF NAME="itemnumber" --><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->">View item</a>&nbsp;<!-- /TMPL_IF --><!-- TMPL_IF NAME="printtitle" --> <!-- TMPL_VAR NAME="title" escape="html" --><!-- /TMPL_IF --></td>
+      <td><!-- TMPL_VAR NAME="description" -->&nbsp;<!-- TMPL_IF NAME="itemnumber" --><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&amp;itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->"><!-- TMPL_IF NAME="printtitle" --><!-- TMPL_VAR NAME="title" escape="html" --><!-- TMPL_ELSE -->View Item<!-- /TMPL_IF --></a>&nbsp;<!-- /TMPL_IF --></td>
+      <td><!-- TMPL_VAR NAME="accountno_paid"-->&nbsp;</td>
       <!-- TMPL_IF NAME="amountcredit" --><td class="credit"><!-- TMPL_ELSE --><td class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="amount" --></td>
       <!-- TMPL_IF NAME="amountoutstandingcredit" --><td class="credit"><!-- TMPL_ELSE --><td class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="amountoutstanding" --></td>
       <td>
@@ -55,7 +59,7 @@
   <!-- /TMPL_LOOP -->
 <tfoot>
   <tr>
-    <td colspan="3">Total due</td>
+    <td colspan="5">Total due</td>
     <!-- TMPL_IF NAME="totalcredit" --><td colspan="2" class="credit"><!-- TMPL_ELSE --><td colspan="2" class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="total" --></td>
   </tr>
   </tfoot>
diff --git a/members/boraccount.pl b/members/boraccount.pl
index 9417ab9..a1b59a2 100755
--- a/members/boraccount.pl
+++ b/members/boraccount.pl
@@ -86,25 +86,35 @@ for (my $i=0;$i<$numaccts;$i++){
     if($accts->[$i]{'amountoutstanding'} <= 0){
         $accts->[$i]{'amountoutstandingcredit'} = 1;
     }
-    my %row = ( 'date'              => format_date($accts->[$i]{'date'}),
-                'amountcredit' => $accts->[$i]{'amountcredit'},
-                'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
-                'toggle' => $accts->[$i]{'toggle'},
-                'description'       => $accts->[$i]{'description'},
-				'itemnumber'       => $accts->[$i]{'itemnumber'},
-				'biblionumber'       => $accts->[$i]{'biblionumber'},
-                'amount'            => sprintf("%.2f",$accts->[$i]{'amount'}),
-                'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
-                'accountno' => $accts->[$i]{'accountno'},
-                'payment' => ( $accts->[$i]{'accounttype'} eq 'Pay' ),
-                
-                );
     
+    my %row = ( 'date'				=> format_date($accts->[$i]{'date'}),
+                'amountcredit' 			=> $accts->[$i]{'amountcredit'},
+                'amountoutstandingcredit' 	=> $accts->[$i]{'amountoutstandingcredit'},
+                'toggle' 			=> $accts->[$i]{'toggle'},
+                'description'       		=> $accts->[$i]{'description'},
+                'title' 			=> $accts->[$i]{'title'},
+		'itemnumber'       		=> $accts->[$i]{'itemnumber'},
+		'biblionumber'       		=> $accts->[$i]{'biblionumber'},
+                'amount'            		=> sprintf("%.2f",$accts->[$i]{'amount'}),
+                'amountoutstanding' 		=> sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
+                'accountno' 			=> $accts->[$i]{'accountno'},
+                'payment' 			=> ( $accts->[$i]{'accounttype'} eq 'Pay' ),
+                'accountno_paid' 		=> $accts->[$i]{'accountno_paid'},
+                );
+
     if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
         $row{'printtitle'}=1;
         $row{'title'} = $accts->[$i]{'title'};
     }
-    
+
+    my $item_paid = GetItemByAccountNumber( $accts->[$i]{'accountno_paid'} );
+    if ( $item_paid ) {
+      $row{'biblionumber'} = $item_paid->{'biblionumber'};
+      $row{'itemnumber'} = $item_paid->{'itemnumber'};
+      $row{'title'} = $item_paid->{'title'};
+      $row{'printtitle'} = 1;
+    }
+        
     push(@accountrows, \%row);
 }
 
-- 
1.5.6.5




More information about the Koha-patches mailing list