[Koha-patches] [PATCH 1/3] Bug 5905: lot of updates for borrower's fines

Julian Maurice julian.maurice at biblibre.com
Wed Mar 30 11:13:36 CEST 2011


From: Stéphane Delaune <stephane.delaune at biblibre.com>

adding a primary key id on accountlines table and updating calls on specific entries on this table
adding a meansofpayment field on accountlines table and a MeansOfPayment syspref to define a list of means of payment.
adding management of means of payment for borrower's fines
adding management of part payments for borrower's fines
adding jquery.tablesorter and jquery.tablesorter.pager support for boraccount.pl and jquery.numeric support for the others borrower's fines pages
replacing in pay.pl the majority "$input->param( $names[ $i + a variable number ] )" occurrences with "$input->param( the beginning of inputname + id on accountlines ] )" for a better understanding of the code
adding javascript functions to disable negative numbers content on text's numeric's inputs, redefine values of Part payment's inputs where it's higher than the Amount Outstanding, manage readonly params for Part payment's inputs
adding time on boraccount's page

BibLibre bug #4589
---
 C4/Accounts.pm                                     |  175 +++++++++++++-------
 C4/Circulation.pm                                  |   16 +-
 installer/data/mysql/en/mandatory/sysprefs.sql     |    1 +
 installer/data/mysql/kohastructure.sql             |    3 +
 installer/data/mysql/updatedatabase.pl             |   12 ++-
 .../prog/en/lib/jquery/plugins/jquery.numeric.js   |  128 ++++++++++++++
 .../prog/en/modules/members/boraccount.tmpl        |   47 +++++-
 .../prog/en/modules/members/mancredit.tmpl         |   28 +++-
 .../prog/en/modules/members/maninvoice.tmpl        |   30 ++++-
 .../intranet-tmpl/prog/en/modules/members/pay.tmpl |   65 +++++++-
 kohaversion.pl                                     |    2 +-
 members/boraccount.pl                              |   10 +-
 members/mancredit.pl                               |    4 +-
 members/maninvoice.pl                              |    5 +-
 members/pay.pl                                     |   86 ++++++----
 .../lib/KohaTest/Members/GetMemberDetails.pm       |   10 +-
 16 files changed, 493 insertions(+), 129 deletions(-)
 create mode 100644 koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.numeric.js

diff --git a/C4/Accounts.pm b/C4/Accounts.pm
index 6210ea3..584c3f7 100644
--- a/C4/Accounts.pm
+++ b/C4/Accounts.pm
@@ -35,7 +35,7 @@ BEGIN {
 	@ISA    = qw(Exporter);
 	@EXPORT = qw(
 		&recordpayment &makepayment &manualinvoice
-		&getnextacctno &reconcileaccount &getcharges &ModNote &getcredits
+		&getnextacctno &reconcileaccount &getcharges &ModNote &ModMeansOfPayment &ModManagerId &getMeansOfPaymentList &getcredits
 		&getrefunds &chargelostitem
 		&ReversePayment
 	); # removed &fixaccounts
@@ -104,10 +104,10 @@ sub recordpayment {
             $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
             $amountleft = 0;
         }
-        my $thisacct = $accdata->{accountno};
+        my $thisacct = $accdata->{id};
         my $usth     = $dbh->prepare(
             "UPDATE accountlines SET amountoutstanding= ?
-     WHERE (borrowernumber = ?) AND (accountno=?)"
+     WHERE (id=?)"
         );
         $usth->execute( $newamtos, $borrowernumber, $thisacct );
         $usth->finish;
@@ -124,8 +124,8 @@ sub recordpayment {
     # create new line
     my $usth = $dbh->prepare(
         "INSERT INTO accountlines
-  (borrowernumber, accountno,date,amount,description,accounttype,amountoutstanding)
-  VALUES (?,?,now(),?,'Payment,thanks','Pay',?)"
+  (borrowernumber, accountno,date,time,amount,description,accounttype,amountoutstanding)
+  VALUES (?,?,now(),CURRENT_TIME,?,'Payment,thanks','Pay',?)"
     );
     $usth->execute( $borrowernumber, $nextaccntno, 0 - $data, 0 - $amountleft );
     $usth->finish;
@@ -135,7 +135,7 @@ sub recordpayment {
 
 =head2 makepayment
 
-  &makepayment($borrowernumber, $acctnumber, $amount, $branchcode);
+  &makepayment($accountlineid, $borrowernumber, $acctnumber, $amount, $branchcode, $note, $meansofpayment, $manager_id, $partpaymentamount);
 
 Records the fact that a patron has paid off the entire amount he or
 she owes.
@@ -144,7 +144,7 @@ C<$borrowernumber> is the patron's borrower number. C<$acctnumber> is
 the account that was credited. C<$amount> is the amount paid (this is
 only used to record the payment. It is assumed to be equal to the
 amount owed). C<$branchcode> is the code of the branch where payment
-was made.
+was made. If $partpaymentamount > 0 it's a part payment.
 
 =cut
 
@@ -156,7 +156,7 @@ sub makepayment {
     #here we update both the accountoffsets and the account lines
     #updated to check, if they are paying off a lost item, we return the item
     # from their card, and put a note on the item record
-    my ( $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
+    my ( $accountlineid, $borrowernumber, $accountno, $amount, $user, $branch, $note, $meansofpayment, $manager_id, $partpaymentamount ) = @_;
     my $dbh = C4::Context->dbh;
 
     # begin transaction
@@ -164,41 +164,45 @@ sub makepayment {
     my $newamtos    = 0;
     my $sth =
       $dbh->prepare(
-        "SELECT * FROM accountlines WHERE  borrowernumber=? AND accountno=?");
-    $sth->execute( $borrowernumber, $accountno );
+        "SELECT * FROM accountlines WHERE id=?");
+    $sth->execute( $accountlineid );
     my $data = $sth->fetchrow_hashref;
     $sth->finish;
 
+    my $newamountoutstanding=0;
+    my $payment = 0 - $amount;
+    $payment = 0-$data->{'amountoutstanding'};
+    my $finalamount = $amount;
+    my $descriptionpayment="Payment for account n°".$accountno.",thanks - ".$user." : ".$data->{'description'};
+	if($partpaymentamount!=0)
+	{
+		$newamountoutstanding=$data->{'amountoutstanding'}-$partpaymentamount;
+		$payment = 0 - $partpaymentamount;
+		$finalamount = $partpaymentamount;
+		$descriptionpayment="Part Payment for account n°".$accountno.",thanks - ".$user." : ".$data->{'description'};
+	}
+
     $dbh->do(
         "UPDATE  accountlines
-        SET     amountoutstanding = 0
-        WHERE   borrowernumber = $borrowernumber
-          AND   accountno = $accountno
+        SET     amountoutstanding = $newamountoutstanding
+        WHERE   id = $accountlineid
         "
     );
 
-    #  print $updquery;
-#    $dbh->do( "
-#        INSERT INTO     accountoffsets
-#                        (borrowernumber, accountno, offsetaccount,
-#                         offsetamount)
-#        VALUES          ($borrowernumber, $accountno, $nextaccntno, $newamtos)
-#        " );
-
     # create new line
-    my $payment = 0 - $amount;
     $dbh->do( "
         INSERT INTO     accountlines
-                        (borrowernumber, accountno, date, amount,
-                         description, accounttype, amountoutstanding)
-        VALUES          ($borrowernumber, $nextaccntno, now(), $payment,
-                        'Payment,thanks - $user', 'Pay', 0)
+                        (borrowernumber, accountno, date, time, amount,
+                         description, accounttype, amountoutstanding,
+                         note, meansofpayment, manager_id)
+        VALUES          ($borrowernumber, $nextaccntno, now(), CURRENT_TIME, $payment,
+                        '$descriptionpayment', 'Pay', 0, '$note', '$meansofpayment', '$manager_id')
         " );
 
     # FIXME - The second argument to &UpdateStats is supposed to be the
     # branch code.
     # UpdateStats is now being passed $accountno too. MTJ
-    UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber,
+    UpdateStats( $user, 'payment', $finalamount, '', '', '', $borrowernumber,
         $accountno );
     $sth->finish;
 
@@ -206,6 +210,12 @@ sub makepayment {
     if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
         returnlost( $borrowernumber, $data->{'itemnumber'} );
     }
+     
+    my $sth = $dbh->prepare("SELECT max(id) AS lastinsertid FROM accountlines");
+    $sth->execute();
+    my $datalastinsertid = $sth->fetchrow_hashref;
+    $sth->finish;
+    return $datalastinsertid->{'lastinsertid'};
 }
 
 =head2 getnextacctno
@@ -233,18 +243,17 @@ sub getnextacctno ($) {
 
 =head2 fixaccounts (removed)
 
-  &fixaccounts($borrowernumber, $accountnumber, $amount);
+  &fixaccounts($accountlineid, $borrowernumber, $accountnumber, $amount);
 
 #'
 # FIXME - I don't understand what this function does.
 sub fixaccounts {
-    my ( $borrowernumber, $accountno, $amount ) = @_;
+    my ( $accountlineid, $borrowernumber, $accountno, $amount ) = @_;
     my $dbh = C4::Context->dbh;
     my $sth = $dbh->prepare(
-        "SELECT * FROM accountlines WHERE borrowernumber=?
-     AND accountno=?"
+        "SELECT * FROM accountlines WHERE id=?"
     );
-    $sth->execute( $borrowernumber, $accountno );
+    $sth->execute( $accountlineid );
     my $data = $sth->fetchrow_hashref;
 
     # FIXME - Error-checking
@@ -256,8 +265,7 @@ sub fixaccounts {
         UPDATE  accountlines
         SET     amount = '$amount',
                 amountoutstanding = '$outstanding'
-        WHERE   borrowernumber = $borrowernumber
-          AND   accountno = $accountno
+        WHERE   id = $accountlineid
 EOT
 	# FIXME: exceedingly bad form.  Use prepare with placholders ("?") in query and execute args.
 }
@@ -307,8 +315,8 @@ sub chargelostitem{
             #  process (or person) to update it, since we don't handle any defaults for replacement prices.
             my $accountno = getnextacctno($issues->{'borrowernumber'});
             my $sth2=$dbh->prepare("INSERT INTO accountlines
-            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
-            VALUES (?,?,now(),?,?,'L',?,?)");
+            (borrowernumber,accountno,date,time,amount,description,accounttype,amountoutstanding,itemnumber)
+            VALUES (?,?,now(),CURRENT_TIME,?,?,'L',?,?)");
             $sth2->execute($issues->{'borrowernumber'},$accountno,$issues->{'replacementprice'},
             "Lost Item $issues->{'title'} $issues->{'barcode'}",
             $issues->{'replacementprice'},$itemnumber);
@@ -327,7 +335,7 @@ sub chargelostitem{
 =head2 manualinvoice
 
   &manualinvoice($borrowernumber, $itemnumber, $description, $type,
-                 $amount, $note);
+                 $amount, $note, $meansofpayment);
 
 C<$borrowernumber> is the patron's borrower number.
 C<$description> is a description of the transaction.
@@ -351,7 +359,7 @@ should be the empty string.
 #
 
 sub manualinvoice {
-    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note ) = @_;
+    my ( $borrowernumber, $itemnum, $desc, $type, $amount, $note, $meansofpayment ) = @_;
     my $manager_id = C4::Context->userenv->{'number'};
     my $dbh      = C4::Context->dbh;
     my $notifyid = 0;
@@ -404,16 +412,16 @@ sub manualinvoice {
         $desc .= " " . $itemnum;
         my $sth = $dbh->prepare(
             "INSERT INTO  accountlines
-                        (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id)
-        VALUES (?, ?, now(), ?,?, ?,?,?,?,?,?)");
-     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id) || return $sth->errstr;
+                        (borrowernumber, accountno, date, time, amount, description, accounttype, amountoutstanding, itemnumber,notify_id, note, manager_id, meansofpayment)
+        VALUES (?, ?, now(), CURRENT_TIME, ?,?, ?,?,?,?,?,?,?)");
+     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid, $note, $manager_id, $meansofpayment) || return $sth->errstr;
   } else {
     my $sth=$dbh->prepare("INSERT INTO  accountlines
-            (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id)
-            VALUES (?, ?, now(), ?, ?, ?, ?,?,?,?)"
+            (borrowernumber, accountno, date, time, amount, description, accounttype, amountoutstanding,notify_id, note, manager_id, meansofpayment)
+            VALUES (?, ?, now(), CURRENT_TIME, ?, ?, ?, ?,?,?,?,?)"
         );
         $sth->execute( $borrowernumber, $accountno, $amount, $desc, $type,
-            $amountleft, $notifyid, $note, $manager_id );
+            $amountleft, $notifyid, $note, $manager_id, $meansofpayment );
     }
     return 0;
 }
@@ -465,10 +473,10 @@ sub fixcredit {
             $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
             $amountleft = 0;
         }
-        my $thisacct = $accdata->{accountno};
+        my $thisacct = $accdata->{id};
         my $usth     = $dbh->prepare(
             "UPDATE accountlines SET amountoutstanding= ?
-     WHERE (borrowernumber = ?) AND (accountno=?)"
+            WHERE (id=?)"
         );
         $usth->execute( $newamtos, $borrowernumber, $thisacct );
         $usth->finish;
@@ -504,12 +512,12 @@ sub fixcredit {
             $newamtos   = $accdata->{'amountoutstanding'} - $amountleft;
             $amountleft = 0;
         }
-        my $thisacct = $accdata->{accountno};
+        my $thisacct = $accdata->{id};
         my $usth     = $dbh->prepare(
             "UPDATE accountlines SET amountoutstanding= ?
-     WHERE (borrowernumber = ?) AND (accountno=?)"
+     WHERE (id=?)"
         );
-        $usth->execute( $newamtos, $borrowernumber, $thisacct );
+        $usth->execute( $newamtos, $thisacct );
         $usth->finish;
         $usth = $dbh->prepare(
             "INSERT INTO accountoffsets
@@ -557,7 +565,6 @@ sub refund {
     );
     $sth->execute($borrowernumber);
 
-    #  print $amountleft;
     # offset transactions
     while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft < 0 ) ) {
         if ( $accdata->{'amountoutstanding'} > $amountleft ) {
@@ -569,13 +576,12 @@ sub refund {
             $amountleft = 0;
         }
 
-        #     print $amountleft;
-        my $thisacct = $accdata->{accountno};
+        my $thisacct = $accdata->{id};
         my $usth     = $dbh->prepare(
             "UPDATE accountlines SET amountoutstanding= ?
-     WHERE (borrowernumber = ?) AND (accountno=?)"
+             WHERE (id=?)"
         );
-        $usth->execute( $newamtos, $borrowernumber, $thisacct );
+        $usth->execute( $newamtos, $thisacct );
         $usth->finish;
         $usth = $dbh->prepare(
             "INSERT INTO accountoffsets
@@ -608,10 +614,51 @@ sub getcharges {
 }
 
 sub ModNote {
-    my ( $borrowernumber, $accountno, $note ) = @_;
+    my ( $accountlineid, $note ) = @_;
     my $dbh = C4::Context->dbh;
-    my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE borrowernumber = ? AND accountno = ?');
-    $sth->execute( $note, $borrowernumber, $accountno );
+    my $sth = $dbh->prepare('UPDATE accountlines SET note = ? WHERE id = ?');
+    $sth->execute( $note, $accountlineid );
+}
+
+
+sub ModMeansOfPayment {
+    my ( $accountlineid, $meansofpayment ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare('UPDATE accountlines SET meansofpayment = ? WHERE id = ?');
+    $sth->execute( $meansofpayment, $accountlineid );
+}
+
+sub ModManagerId {
+    my ( $accountlineid, $manager_id ) = @_;
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->prepare('UPDATE accountlines SET manager_id = ? WHERE id = ?');
+    $sth->execute( $manager_id, $accountlineid );
+}
+
+sub getMeansOfPaymentList {
+	my ($selectedoption) = @_;
+	my $dbh  = C4::Context->dbh;
+	my $sth = $dbh->prepare( "SELECT * FROM `systempreferences` WHERE variable='MeansOfPayment'" );
+	$sth->execute();
+	my @options;
+	my $booloption=0;
+	while ( my $data = $sth->fetchrow_hashref ) {
+	foreach my $option ( split( /\|/, $data->{'value'} ) ) {
+            my $selected = '';
+            if($option eq $selectedoption)
+            {
+            	$selected = ' selected="selected"';
+            	$booloption=1;
+            }
+            push @options, { option => $option, selected => $selected };
+        }
+	}
+	if($booloption==0 && $selectedoption ne "")
+	{
+		push @options, { option => $selectedoption, selected => ' selected="selected"' };
+	}
+    $sth->finish;
+    return \@options;
 }
 
 sub getcredits {
@@ -656,20 +703,20 @@ sub getrefunds {
 }
 
 sub ReversePayment {
-  my ( $borrowernumber, $accountno ) = @_;
+  my ( $accountlineid ) = @_;
   my $dbh = C4::Context->dbh;
   
-  my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE borrowernumber = ? AND accountno = ?');
-  $sth->execute( $borrowernumber, $accountno );
+  my $sth = $dbh->prepare('SELECT amountoutstanding FROM accountlines WHERE id=?');
+  $sth->execute( $accountlineid );
   my $row = $sth->fetchrow_hashref();
   my $amount_outstanding = $row->{'amountoutstanding'};
   
   if ( $amount_outstanding <= 0 ) {
-    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?');
-    $sth->execute( $borrowernumber, $accountno );
+    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = amount * -1, description = CONCAT( description, " Reversed -" ) WHERE id = ?');
+    $sth->execute( $accountlineid );
   } else {
-    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE borrowernumber = ? AND accountno = ?');
-    $sth->execute( $borrowernumber, $accountno );
+    $sth = $dbh->prepare('UPDATE accountlines SET amountoutstanding = 0, description = CONCAT( description, " Reversed -" ) WHERE id = ?');
+    $sth->execute( $accountlineid );
   }
 }
 
diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index dad54e3..9613851 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -1788,7 +1788,7 @@ sub _FixOverduesOnReturn {
     return 0 unless $data;    # no warning, there's just nothing to fix
 
     my $uquery;
-    my @bind = ($borrowernumber, $item, $data->{'accountno'});
+    my @bind = ($data->{'id'});
     if ($exemptfine) {
         $uquery = "update accountlines set accounttype='FFOR', amountoutstanding=0";
         if (C4::Context->preference("FinesLog")) {
@@ -1808,7 +1808,7 @@ sub _FixOverduesOnReturn {
     } else {
         $uquery = "update accountlines set accounttype='F' ";
     }
-    $uquery .= " where (borrowernumber = ?) and (itemnumber = ?) and (accountno = ?)";
+    $uquery .= " where (id = ?)";
     my $usth = $dbh->prepare($uquery);
     return $usth->execute(@bind);
 }
@@ -1850,9 +1850,8 @@ sub _FixAccountForLostAndReturned {
         $amountleft = $data->{'amountoutstanding'} - $amount;   # Um, isn't this the same as ZERO?  We just tested those two things are ==
     }
     my $usth = $dbh->prepare("UPDATE accountlines SET accounttype = 'LR',amountoutstanding='0'
-        WHERE (borrowernumber = ?)
-        AND (itemnumber = ?) AND (accountno = ?) ");
-    $usth->execute($data->{'borrowernumber'},$itemnumber,$acctno);      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.  
+        WHERE (id = ?) ");
+    $usth->execute($data->{'id'});      # We might be adjusting an account for some OTHER borrowernumber now.  Not the one we passed in.  
     #check if any credit is left if so writeoff other accounts
     my $nextaccntno = getnextacctno($data->{'borrowernumber'});
     $amountleft *= -1 if ($amountleft < 0);
@@ -1871,12 +1870,11 @@ sub _FixAccountForLostAndReturned {
                 $newamtos = $accdata->{'amountoutstanding'} - $amountleft;
                 $amountleft = 0;
             }
-            my $thisacct = $accdata->{'accountno'};
+            my $thisacct = $accdata->{'id'};
             # FIXME: move prepares outside while loop!
             my $usth = $dbh->prepare("UPDATE accountlines SET amountoutstanding= ?
-                    WHERE (borrowernumber = ?)
-                    AND (accountno=?)");
-            $usth->execute($newamtos,$data->{'borrowernumber'},'$thisacct');    # FIXME: '$thisacct' is a string literal!
+                    WHERE (id = ?)");
+            $usth->execute($newamtos,'$thisacct');    # FIXME: '$thisacct' is a string literal!
             $usth = $dbh->prepare("INSERT INTO accountoffsets
                 (borrowernumber, accountno, offsetaccount,  offsetamount)
                 VALUES
diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql
index 9f47292..e367646 100644
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -298,3 +298,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('IntranetFavicon','','Enter a complete URL to an image to replace the default Koha favicon on the Staff client','','free');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('TraceSubjectSubdivisions', '0', 'Create searches on all subdivisions for subject tracings.','1','YesNo');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('StaffAuthorisedValueImages','1','',NULL,'YesNo');
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MeansOfPayment','Undefined|Cash|Cheque|Bank card|Credit transfer|Direct debit','Define means of payment for borrowers payments','Undefined|Cash|Cheque|Bank card|Credit transfer|Direct debit','free');
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index b16cda6..bc90f12 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -2279,10 +2279,12 @@ CREATE TABLE `messages` (
 
 DROP TABLE IF EXISTS `accountlines`;
 CREATE TABLE `accountlines` (
+  `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
   `borrowernumber` int(11) NOT NULL default 0,
   `accountno` smallint(6) NOT NULL default 0,
   `itemnumber` int(11) default NULL,
   `date` date default NULL,
+  `time` time default NULL,
   `amount` decimal(28,6) default NULL,
   `description` mediumtext,
   `dispute` mediumtext,
@@ -2294,6 +2296,7 @@ CREATE TABLE `accountlines` (
   `notify_level` int(2) NOT NULL default 0,
   `note` text NULL default NULL,
   `manager_id` int(11) NULL,
+  `meansofpayment` text NULL default NULL;
   KEY `acctsborridx` (`borrowernumber`),
   KEY `timeidx` (`timestamp`),
   KEY `itemnumber` (`itemnumber`),
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 3eb14a8..009fbe1 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -4166,7 +4166,7 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion ($DBversion);
 }
 
-$DBversion = 'XXX';
+$DBversion = '3.03.00.036';
 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     $dbh->do("ALTER TABLE `accountlines` ADD `note` text NULL default NULL");
     $dbh->do("ALTER TABLE `accountlines` ADD `manager_id` int( 11 ) NULL ");
@@ -4174,6 +4174,16 @@ if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
     SetVersion($DBversion);
 }
 
+$DBversion = '3.03.00.037';
+if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
+    $dbh->do("ALTER TABLE `accountlines` ADD `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
+    $dbh->do("ALTER TABLE `accountlines` ADD `time` TIME DEFAULT NULL AFTER `date`");
+    $dbh->do("ALTER TABLE `accountlines` ADD `meansofpayment` text NULL default NULL");
+    $dbh->do("INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('MeansOfPayment', 'Undefined|Cash|Cheque|Bank card|Credit transfer|Direct debit', 'Define means of payment for borrowers payments', 'Undefined|Cash|Cheque|Bank card|Credit transfert|Direct debit', 'free')");
+    print "Upgrade to $DBversion done (adding id, time, and meansofpayment fields in accountlines table; and adding MeansOfPayment system preference";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 DropAllForeignKeys($table)
diff --git a/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.numeric.js b/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.numeric.js
new file mode 100644
index 0000000..df13e47
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/lib/jquery/plugins/jquery.numeric.js
@@ -0,0 +1,128 @@
+/*
+ *
+ * Copyright (c) 2006/2007 Sam Collett (http://www.texotela.co.uk)
+ * Licensed under the MIT License:
+ * http://www.opensource.org/licenses/mit-license.php
+ * 
+ * Version 1.0
+ * Demo: http://www.texotela.co.uk/code/jquery/numeric/
+ *
+ * $LastChangedDate: 2007-05-29 11:31:36 +0100 (Tue, 29 May 2007) $
+ * $Rev: 2005 $
+ */
+ 
+/*
+ * Allows only valid characters to be entered into input boxes.
+ * Note: does not validate that the final text is a valid number
+ * (that could be done by another script, or server-side)
+ *
+ * @name     numeric
+ * @param    decimal      Decimal separator (e.g. '.' or ',' - default is '.')
+ * @param    callback     A function that runs if the number is not valid (fires onblur)
+ * @author   Sam Collett (http://www.texotela.co.uk)
+ * @example  $(".numeric").numeric();
+ * @example  $(".numeric").numeric(",");
+ * @example  $(".numeric").numeric(null, callback);
+ *
+ */
+jQuery.fn.numeric = function(decimal, callback)
+{
+	decimal = decimal || ".";
+	callback = typeof callback == "function" ? callback : function(){};
+	this.keypress(
+		function(e)
+		{
+			var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
+			// allow enter/return key (only when in an input box)
+			if(key == 13 && this.nodeName.toLowerCase() == "input")
+			{
+				return true;
+			}
+			else if(key == 13)
+			{
+				return false;
+			}
+			var allow = false;
+			// allow Ctrl+A
+			if((e.ctrlKey && key == 97 /* firefox */) || (e.ctrlKey && key == 65) /* opera */) return true;
+			// allow Ctrl+X (cut)
+			if((e.ctrlKey && key == 120 /* firefox */) || (e.ctrlKey && key == 88) /* opera */) return true;
+			// allow Ctrl+C (copy)
+			if((e.ctrlKey && key == 99 /* firefox */) || (e.ctrlKey && key == 67) /* opera */) return true;
+			// allow Ctrl+Z (undo)
+			if((e.ctrlKey && key == 122 /* firefox */) || (e.ctrlKey && key == 90) /* opera */) return true;
+			// allow or deny Ctrl+V (paste), Shift+Ins
+			if((e.ctrlKey && key == 118 /* firefox */) || (e.ctrlKey && key == 86) /* opera */
+			|| (e.shiftKey && key == 45)) return true;
+			// if a number was not pressed
+			if(key < 48 || key > 57)
+			{
+				/* '-' only allowed at start */
+				if(key == 45 && this.value.length == 0) return true;
+				/* only one decimal separator allowed */
+				if(key == decimal.charCodeAt(0) && this.value.indexOf(decimal) != -1)
+				{
+					allow = false;
+				}
+				// check for other keys that have special purposes
+				if(
+					key != 8 /* backspace */ &&
+					key != 9 /* tab */ &&
+					key != 13 /* enter */ &&
+					key != 35 /* end */ &&
+					key != 36 /* home */ &&
+					key != 37 /* left */ &&
+					key != 39 /* right */ &&
+					key != 46 /* del */
+				)
+				{
+					allow = false;
+				}
+				else
+				{
+					// for detecting special keys (listed above)
+					// IE does not support 'charCode' and ignores them in keypress anyway
+					if(typeof e.charCode != "undefined")
+					{
+						// special keys have 'keyCode' and 'which' the same (e.g. backspace)
+						if(e.keyCode == e.which && e.which != 0)
+						{
+							allow = true;
+						}
+						// or keyCode != 0 and 'charCode'/'which' = 0
+						else if(e.keyCode != 0 && e.charCode == 0 && e.which == 0)
+						{
+							allow = true;
+						}
+					}
+				}
+				// if key pressed is the decimal and it is not already in the field
+				if(key == decimal.charCodeAt(0) && this.value.indexOf(decimal) == -1)
+				{
+					allow = true;
+				}
+			}
+			else
+			{
+				allow = true;
+			}
+			return allow;
+		}
+	)
+	.blur(
+		function()
+		{
+			var val = jQuery(this).val();
+			if(val != "")
+			{
+				var re = new RegExp("^\\d+$|\\d*" + decimal + "\\d+");
+				if(!re.exec(val))
+				{
+					callback.apply(this);
+				}
+			}
+		}
+	);
+	return this;
+}
+
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 4f66ec5..0c426f2 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl
@@ -1,6 +1,13 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
 <title>Koha &rsaquo; Patrons &rsaquo; Account for <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.min.js"></script>
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.tablesorter.pager.js"></script>
+<script type="text/javascript" id="js">$(document).ready(function() {
+	$("#table_boracount").tablesorter({
+		sortList: [[0,0]],
+	}).tablesorterPager({container: $("#pagertable_boracount"),positionFixed: false,size: 20});
+}); </script>
 </head>
 <body>
 <!-- TMPL_INCLUDE NAME="header.inc" -->
@@ -26,32 +33,56 @@
 </ul>
 <div class="tabs-container">
 <!-- The table with the account items -->
-<table>
-  <tr>
+<span id="pagertable_boracount" class="pager">
+	<form class="formpager">&nbsp;<strong>page(s)</strong>&nbsp;:
+		<img src="<!-- TMPL_VAR name="interface" -->/prog/img/first.png" class="first"/>
+		<img src="<!-- TMPL_VAR name="interface" -->/prog/img/prev.png" class="prev"/>
+		<input type="text" size="5" class="pagedisplay"/>
+		<img src="<!-- TMPL_VAR name="interface" -->/prog/img/next.png" class="next"/>
+		<img src="<!-- TMPL_VAR name="interface" -->/prog/img/last.png" class="last"/>
+		, entries/page : 
+		<select class="pagesize">
+        	<option value="10">10</option>
+			<option selected="selected" value="20">20</option>
+			<option value="30">30</option>
+			<option value="40">40</option>
+			<option value="50">50</option>
+			<option value="100">100</option>
+		</select>
+	</form>
+</span>
+<table id="table_boracount">
+  <thead>
   	<th>Date</th>
+  	<th style="padding:0.2em 14px">n°</th>
+  	<th>Means of payment</th>
     <th>Description of charges</th>
     <th>Note</th>
     <th>Amount</th>
     <th>Outstanding</th>
+    <th>Manager</th>
     <!-- TMPL_IF NAME="reverse_col" -->
     <th>&nbsp;</th>
     <!-- /TMPL_IF -->
     <th>Print</th>
-  </tr>
+  </thead>
 
 	<!-- FIXME: Shouldn't hardcode dollar signs, since Euro or Pound might be needed -->
   <!-- TMPL_LOOP NAME="accounts" -->
 
-   <!-- TMPL_IF NAME="__odd__" --><tr><!-- TMPL_ELSE --><tr class="highlight"><!-- /TMPL_IF -->
-      <td><!-- TMPL_VAR NAME="date" --></td>
+   <!-- TMPL_IF NAME="__odd__" --><tr><!-- TMPL_ELSE --><tr><!-- /TMPL_IF -->
+      <td><!-- TMPL_VAR NAME="date" --> <!-- TMPL_VAR NAME="time" --></td>
+      <td><!-- TMPL_VAR NAME="accountno" --></td>
+      <td><!-- TMPL_VAR NAME="meansofpayment" --></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="note" --></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><!-- TMPL_VAR NAME="manager_details" --></td>
     <!-- TMPL_IF NAME="reverse_col" -->
       <td>
 	<!-- TMPL_IF NAME="payment" -->
-		<a href="boraccount.pl?action=reverse&amp;borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&amp;accountno=<!-- TMPL_VAR NAME="accountno" -->">Reverse</a>
+        <a href="boraccount.pl?action=reverse&borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&accountno=<!-- TMPL_VAR NAME="accountno" -->&accountlineid=<!-- TMPL_VAR NAME="id" -->">Reverse</a>
 	<!-- TMPL_ELSE -->
 		&nbsp;
 	<!-- /TMPL_IF -->
@@ -69,8 +100,8 @@
   <!-- /TMPL_LOOP -->
 <tfoot>
   <tr>
-    <td colspan="4">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>
+    <td colspan="6">Total due</td>
+    <!-- TMPL_IF NAME="totalcredit" --><td colspan="3" class="credit"><!-- TMPL_ELSE --><td colspan="3" class="debit"><!-- /TMPL_IF --><!-- TMPL_VAR NAME="total" --></td>
   </tr>
   </tfoot>
 </table>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tmpl
index d23cf18..fdf0432 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tmpl
@@ -1,6 +1,20 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
 <title>Koha &rsaquo; Borrowers &rsaquo; Create Manual Credit</title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.numeric.js"></script>
+<script type="text/javascript">
+$(function(){$("input.numeric_only").numeric();});
+</script>
+<script type="text/javascript">
+function amountchange(value)
+{
+	if(value<0)
+	{
+		value=0-value;
+		document.getElementById("amount").value=value;
+	}
+}
+</script>
 <script type="text/javascript">
 //<![CDATA[
 $(document).ready(function(){
@@ -44,7 +58,19 @@ $(document).ready(function(){
 	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
 	<li><label for="desc">Description: </label><input type="text" name="desc" size="50" id="desc" /></li>
     <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
-	<li><label for="amount">Amount: </label><input type="text" name="amount" id="amount" /> Example: 5.00</li>
+	<li><label for="meansofpayment">Means of payment: </label>
+	<select name="meansofpayment" id="meansofpayment">
+<!-- TMPL_LOOP NAME="meansofpaymentoptions" -->
+        		<!-- TMPL_IF Name="selected" -->
+        <option value="<!-- TMPL_VAR NAME="option" -->" selected="selected">
+        <!-- TMPL_ELSE -->
+        <option value="<!-- TMPL_VAR NAME="option" -->">
+        <!-- /TMPL_IF -->
+    <!-- TMPL_VAR NAME="option" --></option>
+<!-- /TMPL_LOOP -->
+</select>
+	</li>
+	<li><label for="amount">Amount: </label><input type="text" class="numeric_only" name="amount" id="amount" onKeyUp="amountchange(this.value)" /> Example: 5.00</li>
 </ol></fieldset>
 
 <fieldset class="action"><input type="submit" name="add" value="Add Credit" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Cancel</a></fieldset>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tmpl
index 0062bfe..ae62c96 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/maninvoice.tmpl
@@ -1,6 +1,20 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
 <title>Koha &rsaquo; Borrowers &rsaquo; Create Manual Invoice</title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.numeric.js"></script>
+<script type="text/javascript">
+$(function(){$("input.numeric_only").numeric();});
+</script>
+<script type="text/javascript">
+function amountchange(value)
+{
+	if(value<0)
+	{
+		value=0-value;
+		document.getElementById("amount").value=value;
+	}
+}
+</script>
 <script type="text/javascript">
 //<![CDATA[
 $(document).ready(function(){
@@ -68,7 +82,21 @@ type_fees['<!-- TMPL_VAR NAME="authorised_value" -->'] = "<!-- TMPL_VAR NAME="li
 	<li><label for="barcode">Barcode: </label><input type="text" name="barcode" id="barcode" /></li>
 	<li><label for="desc">Description: </label><input type="text" name="desc" id="desc" size="50" /></li>
     <li><label for="note">Note: </label><input type="text" name="note" size="50" id="note" /></li>
-	<li><label for="amount">Amount: </label><input type="text" name="amount" id="amount" /> Example: 5.00</li>
+	<li><label for="meansofpayment">Means of payment: </label>
+	
+	
+	<select name="meansofpayment" id="meansofpayment">
+<!-- TMPL_LOOP NAME="meansofpaymentoptions" -->
+        		<!-- TMPL_IF Name="selected" -->
+        <option value="<!-- TMPL_VAR NAME="option" -->" selected="selected">
+        <!-- TMPL_ELSE -->
+        <option value="<!-- TMPL_VAR NAME="option" -->">
+        <!-- /TMPL_IF -->
+    <!-- TMPL_VAR NAME="option" --></option>
+<!-- /TMPL_LOOP -->
+</select>
+	</li>
+	<li><label for="amount">Amount: </label><input type="text" class="numeric_only" name="amount" id="amount" onKeyUp="amountchange(this.value)" /> Example: 5.00</li>
 	</ol></fieldset>
 <fieldset class="action"><input type="submit" name="add" value="Save" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Cancel</a></fieldset>
 </form>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl
index 99fdc2a..082218c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl
@@ -1,6 +1,37 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
 <title>Koha &rsaquo; Patrons &rsaquo; Pay Fines for  <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+<script type="text/javascript" src="<!-- TMPL_VAR name="themelang" -->/lib/jquery/plugins/jquery.numeric.js"></script>
+<script type="text/javascript">
+$(function(){$("input.numeric_only").numeric();});
+</script>
+<script type="text/javascript">
+function payfinechange(value,accountlineid)
+{
+	if(value=="pp")
+	{
+		document.getElementById("partpaymentamount"+accountlineid).readOnly=false;
+	}
+	else
+	{
+		document.getElementById("partpaymentamount"+accountlineid).readOnly=true;
+	}
+}
+
+function partpaymentchange(value,accountlineid,amountoutstanding)
+{
+	if(value>amountoutstanding)
+	{
+		document.getElementById("partpaymentamount"+accountlineid).value=amountoutstanding;
+	}
+	if(value<0)
+	{
+		value=0-value;
+		document.getElementById("partpaymentamount"+accountlineid).value=value;
+	}
+}
+</script>
+
 </head>
 <body>
 <!-- TMPL_INCLUDE NAME="header.inc" -->
@@ -31,8 +62,10 @@
 <table>
 <tr>
 	<th>Fines &amp; Charges</th>
+    <th>Means of payment</th>
 	<th>Description</th>
     <th>Note</th>
+    <th>Part payment</th>
 	<th>Account Type</th>
 	<th>Notify id</th>
 	<th>Level</th>
@@ -43,12 +76,14 @@
 <!-- TMPL_LOOP name="allfile" -->
 	<!-- TMPL_LOOP name="loop_pay" -->
 <tr>
-	<td>
+    <td><input type="hidden" name="accountlineid<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="accountlineid" -->" />
+	
 	<!-- TMPL_IF NAME="net_balance" -->
-	<select name="payfine<!-- TMPL_VAR name="i" -->">
+	<select name="payfine<!-- TMPL_VAR name="i" -->" onChange="payfinechange(this.value,<!-- TMPL_VAR name="i" -->)">
 	<option value="no">Unpaid</option>
 	<option value="yes">Paid</option>
 	<option value="wo">Writeoff</option>
+	<option value="pp">Part payment</option>
 	</select>
 	<!-- /TMPL_IF -->
 	<input type="hidden" name="itemnumber<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="itemnumber" -->" />
@@ -61,6 +96,20 @@
 	<input type="hidden" name="notify_level<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="notify_level" -->" />
 	<input type="hidden" name="totals<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="totals" -->" />
 	</td>
+	<td>
+	<!-- TMPL_IF NAME="net_balance" -->
+	<select name="meansofpayment<!-- TMPL_VAR name="i" -->" id="meansofpayment<!-- TMPL_VAR name="i" -->">
+<!-- TMPL_LOOP NAME="meansofpaymentoptions" -->
+		<!-- TMPL_IF Name="selected" -->
+        <option value="<!-- TMPL_VAR NAME="option" -->" selected="selected">
+        <!-- TMPL_ELSE -->
+        <option value="<!-- TMPL_VAR NAME="option" -->">
+        <!-- /TMPL_IF -->
+    <!-- TMPL_VAR NAME="option" --></option>
+<!-- /TMPL_LOOP -->
+</select><!-- TMPL_ELSE --><!-- TMPL_VAR NAME="meansofpayment" -->
+	<!-- /TMPL_IF -->
+	</td>
 	<td><!-- TMPL_VAR name="description" --> <!-- TMPL_VAR name="title" escape="html" --></td>
     <td>
         <!-- TMPL_IF NAME="net_balance" -->
@@ -69,6 +118,13 @@
         <!-- TMPL_VAR name="note" -->
         <!-- TMPL_IF NAME="net_balance" -->" /><!-- /TMPL_IF -->
     </td>
+	<td>
+	<!-- TMPL_IF NAME="net_balance" -->
+	<input type="text" class="numeric_only" readOnly="true" id="partpaymentamount<!-- TMPL_VAR name="i" -->" name="partpaymentamount<!-- TMPL_VAR name="i" -->" value="
+	<!-- /TMPL_IF -->
+	<!-- TMPL_VAR name="partpaymentamount" -->
+	<!-- TMPL_IF NAME="net_balance" -->" onKeyUp="partpaymentchange(this.value,<!-- TMPL_VAR name="i" -->,<!-- TMPL_VAR name="amountoutstanding" -->)" /><!-- /TMPL_IF -->
+	</td>
 	<td><!-- TMPL_VAR name="accounttype" --></td>
 	<td><!-- TMPL_VAR name="notify_id" --></td>
 	<td><!-- TMPL_VAR name="notify_level" --></td>
@@ -78,14 +134,13 @@
 <!-- /TMPL_LOOP  -->
 <!-- TMPL_IF  NAME="total"-->
 <tr>
-
-	<td colspan="7">Sub Total</td>
+	<td colspan="9">Sub Total <!-- TMPL_VAR name="notify" --></td>
 	<td><!-- TMPL_VAR name="total" --></td>
 </tr>
 <!--/TMPL_IF-->
 <!-- /TMPL_LOOP  -->
 <tr>
-	<td colspan="7">Total Due</td>
+	<td colspan="9">Total Due</td>
 	<td><!-- TMPL_VAR name="total" --></td>
 </tr>
 </table>
diff --git a/kohaversion.pl b/kohaversion.pl
index cd55624..e1bea78 100644
--- a/kohaversion.pl
+++ b/kohaversion.pl
@@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts :
 use strict;
 
 sub kohaversion {
-    our $VERSION = '3.03.00.035';
+    our $VERSION = '3.03.00.037';
     # version needs to be set this way
     # so that it can be picked up by Makefile.PL
     # during install
diff --git a/members/boraccount.pl b/members/boraccount.pl
index 5509f3d..c08ceb4 100755
--- a/members/boraccount.pl
+++ b/members/boraccount.pl
@@ -52,7 +52,7 @@ my $action = $input->param('action') || '';
 my $data=GetMember('borrowernumber' => $borrowernumber);
 
 if ( $action eq 'reverse' ) {
-  ReversePayment( $borrowernumber, $input->param('accountno') );
+  ReversePayment( $input->param('accountlineid') );
 }
 
 if ( $data->{'category_type'} eq 'C') {
@@ -90,6 +90,14 @@ foreach my $accountline ( @{$accts}) {
     if ($accountline->{accounttype} ne 'F' && $accountline->{accounttype} ne 'FU'){
         $accountline->{printtitle} = 1;
     }
+    
+    if ( $accountline->{accounttype} ne 'F' && $accountline->{accounttype} ne 'FU' ) {
+        $accountline->{printtitle} = 1;
+    }
+    if ( $accountline->{manager_id} ne '' ) {
+       my $datamanager = GetMember( 'borrowernumber' => $accountline->{manager_id} );
+    	$accountline->{manager_details}=$datamanager->{'firstname'}." ".$datamanager->{'surname'};
+    }
 }
 
 $template->param( adultborrower => 1 ) if ( $data->{'category_type'} eq 'A' );
diff --git a/members/mancredit.pl b/members/mancredit.pl
index 2d81c09..18f4564 100755
--- a/members/mancredit.pl
+++ b/members/mancredit.pl
@@ -48,10 +48,11 @@ if ($add){
         my $itemnum = GetItemnumberFromBarcode($barcode) if $barcode;
         my $desc    = $input->param('desc');
         my $note    = $input->param('note');
+	    my $meansofpayment    = $input->param('meansofpayment');
         my $amount  = $input->param('amount') || 0;
         $amount = -$amount;
         my $type = $input->param('type');
-        manualinvoice( $borrowernumber, $itemnum, $desc, $type, $amount, $note );
+        manualinvoice( $borrowernumber, $itemnum, $desc, $type, $amount, $note, $meansofpayment );
         print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
     }
 } else {
@@ -94,5 +95,6 @@ if ($add){
 		    branchname => GetBranchName($data->{'branchcode'}),
 		    is_child        => ($data->{'category_type'} eq 'C'),
         );
+    $template->param( 'meansofpaymentoptions' => getMeansOfPaymentList() );
     output_html_with_http_headers $input, $cookie, $template->output;
 }
diff --git a/members/maninvoice.pl b/members/maninvoice.pl
index 12803b5..5eefe22 100755
--- a/members/maninvoice.pl
+++ b/members/maninvoice.pl
@@ -50,7 +50,8 @@ if ($add){
         my $amount=$input->param('amount');
         my $type=$input->param('type');
         my $note    = $input->param('note');
-        my $error   = manualinvoice( $borrowernumber, $itemnum, $desc, $type, $amount, $note );
+        my $meansofpayment = $input->param('meansofpayment');
+        my $error   = manualinvoice( $borrowernumber, $itemnum, $desc, $type, $amount, $note, $meansofpayment );
         if ($error) {
             my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
                 {   template_name   => "members/maninvoice.tmpl",
@@ -65,6 +66,7 @@ if ($add){
                 $template->param( 'ITEMNUMBER' => 1 );
             }
             $template->param( 'ERROR' => $error );
+	        $template->param( 'meansofpaymentoptions' => getMeansOfPaymentList() );
             output_html_with_http_headers $input, $cookie, $template->output;
         } else {
             print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
@@ -122,5 +124,6 @@ if ($add){
 		branchname => GetBranchName($data->{'branchcode'}),
 		is_child        => ($data->{'category_type'} eq 'C'),
     );
+    $template->param( 'meansofpaymentoptions' => getMeansOfPaymentList() );
     output_html_with_http_headers $input, $cookie, $template->output;
 }
diff --git a/members/pay.pl b/members/pay.pl
index 259bcd1..772a6a0 100755
--- a/members/pay.pl
+++ b/members/pay.pl
@@ -41,6 +41,7 @@ use C4::Overdues;
 use C4::Branch; # GetBranches
 
 my $input = new CGI;
+my $lastinsertid = 0;
 
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
@@ -53,6 +54,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 
+my $manager_id = C4::Context->userenv->{'number'};
 my $borrowernumber = $input->param('borrowernumber');
 if ( $borrowernumber eq '' ) {
     $borrowernumber = $input->param('borrowernumber0');
@@ -70,26 +72,42 @@ my @names = $input->param;
 my %inp;
 my $check = 0;
 for ( my $i = 0 ; $i < @names ; $i++ ) {
-    my $temp = $input->param( $names[$i] );
-    if ( $temp eq 'wo' ) {
-        $inp{ $names[$i] } = $temp;
-        $check = 1;
-    }
-    if ( $temp eq 'yes' ) {
-
-# FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
-        my $amount         = $input->param( $names[ $i + 4 ] );
-        my $borrowernumber = $input->param( $names[ $i + 5 ] );
-        my $accountno      = $input->param( $names[ $i + 6 ] );
-        makepayment( $borrowernumber, $accountno, $amount, $user, $branch );
-        $check = 2;
-    }
-    if ( $temp eq 'no'||$temp eq 'yes'||$temp eq 'wo') {
-        my $borrowernumber = $input->param( $names[ $i + 5 ] );
-        my $accountno      = $input->param( $names[ $i + 6 ] );
-        my $note     = $input->param( $names[ $i + 10 ] );
-        ModNote( $borrowernumber, $accountno, $note );
-    }
+	if(defined($input->param( $names[ $i + 1 ] )))
+	{
+	    if(defined($input->param( "payfine".$input->param( $names[ $i + 1 ] ) )))
+	    {
+	    	my $accountlineid      = $input->param( $names[ $i + 1 ] );#7
+		    my $temp = $input->param( "payfine".$accountlineid );
+		    if ( $temp eq 'wo' ) {
+		        $inp{ $names[$i] } = $temp;
+		        $check = 1;
+		    }
+		    if ( $temp eq 'yes' ) {
+				#my $accountlineid = $input->param( $names[ $i + 1 ] );#7
+		        # FIXME : using array +4, +5, +6 is dirty. Should use arrays for each accountline
+		        my $amount = $input->param( "amount".$accountlineid );#4
+		        my $borrowernumber = $input->param( "borrowernumber".$accountlineid );#5
+		        my $accountno = $input->param( "accountno".$accountlineid );#6
+		        my $note = $input->param( "note".$accountlineid );#12
+		        my $meansofpayment = $input->param( "meansofpayment".$accountlineid );#11
+		        #$accountnoupdated = getnextacctno($borrowernumber);
+		        $lastinsertid = makepayment( $accountlineid, $borrowernumber, $accountno, $amount, $user, $branch, $note, $meansofpayment, $manager_id, 0 );
+		        $check = 2;
+		    }
+		    elsif($temp eq 'pp')
+		    {
+		    	#my $accountlineid      = $input->param( $names[ $i +1 ] );#7
+		    	my $amount         = $input->param( "amount".$accountlineid );#4
+		        my $borrowernumber = $input->param( "borrowernumber".$accountlineid );#5
+		        my $accountno      = $input->param( "accountno".$accountlineid );#6
+		        my $note     = $input->param( "note".$accountlineid );#12
+		        my $meansofpayment     = $input->param( "meansofpayment".$accountlineid );#11
+		        my $partpaymentamount         = $input->param( "partpaymentamount".$accountlineid );#13
+		    	$lastinsertid = makepayment( $accountlineid, $borrowernumber, $accountno, $amount, $user, $branch, $note, $meansofpayment, $manager_id, $partpaymentamount);
+		        $check = 2;
+		    }
+	    }
+	}
 }
 
 my $total = $input->param('total') || '';
@@ -113,7 +131,8 @@ if ( $check == 0 ) {
             if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
                 $accts->[$i]{'amount'}            += 0.00;
                 $accts->[$i]{'amountoutstanding'} += 0.00;
-                $line{i}           = $j . "" . $i;
+                $line{i}                 = $accts->[$i]{'id'};
+                $line{accountlineid}     = $accts->[$i]{'id'};
                 $line{itemnumber}  = $accts->[$i]{'itemnumber'};
                 $line{accounttype} = $accts->[$i]{'accounttype'};
                 $line{amount}      = sprintf( "%.2f", $accts->[$i]{'amount'} );
@@ -123,6 +142,8 @@ if ( $check == 0 ) {
                 $line{accountno}      = $accts->[$i]{'accountno'};
                 $line{description}    = $accts->[$i]{'description'};
                 $line{note}           = $accts->[$i]{'note'};
+                $line{meansofpaymentoptions} = getMeansOfPaymentList($accts->[$i]{'meansofpayment'});
+                $line{meansofpayment} = $accts->[$i]{'meansofpayment'};
                 $line{title}          = $accts->[$i]{'title'};
                 $line{notify_id}      = $accts->[$i]{'notify_id'};
                 $line{notify_level}   = $accts->[$i]{'notify_level'};
@@ -197,7 +218,8 @@ else {
         my $itemno    = $input->param("itemnumber$value");
         my $amount    = $input->param("amount$value");
         my $accountno = $input->param("accountno$value");
-        writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount );
+        my $accountlineid = $input->param("accountlineid$value");
+        writeoff( $borrowernumber, $accountno, $itemno, $accounttype, $amount, $accountlineid );
     }
     $borrowernumber = $input->param('borrowernumber');
     print $input->redirect(
@@ -205,14 +227,14 @@ else {
 }
 
 sub writeoff {
-    my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
+    my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount, $accountlineid ) = @_;
     my $user = $input->remote_user;
     my $dbh  = C4::Context->dbh;
     undef $itemnum unless $itemnum; # if no item is attached to fine, make sure to store it as a NULL
-    my $sth =
-      $dbh->prepare(
-"Update accountlines set amountoutstanding=0 where accountno=? and borrowernumber=?"
-      );
+    my $sth = $dbh->prepare("
+        UPDATE accountlines SET amountoutstanding = 0
+        WHERE id = ?
+    ");
     $sth->execute( $accountnum, $borrowernumber );
     $sth->finish;
     $sth = $dbh->prepare("select max(accountno) from accountlines");
@@ -220,10 +242,12 @@ sub writeoff {
     my $account = $sth->fetchrow_hashref;
     $sth->finish;
     $account->{'max(accountno)'}++;
-    $sth = $dbh->prepare(
-"insert into accountlines (borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
-						values (?,?,?,now(),?,'Writeoff','W')"
-    );
+    $sth = $dbh->prepare("
+        INSERT INTO accountlines (borrowernumber,accountno,itemnumber,
+                                  date,time,amount,description,accounttype,
+                                  manager_id)
+		VALUES (?,?,?,now(),CURRENT_TIME,?,'Writeoff','W',?)
+    ");
     $sth->execute( $borrowernumber, $account->{'max(accountno)'},
         $itemnum, $amount );
     $sth->finish;
diff --git a/t/db_dependent/lib/KohaTest/Members/GetMemberDetails.pm b/t/db_dependent/lib/KohaTest/Members/GetMemberDetails.pm
index e93742b..bbe3afe 100644
--- a/t/db_dependent/lib/KohaTest/Members/GetMemberDetails.pm
+++ b/t/db_dependent/lib/KohaTest/Members/GetMemberDetails.pm
@@ -24,7 +24,7 @@ retrieval.
 
 sub startup_create_detailed_borrower : Test( startup => 2 ) {
     my $self = shift;
-    my ( $description, $type, $amount, $user );
+    my ( $description, $type, $amount, $note, $meansofpayment );
 
     my $memberinfo = {
         surname      => 'surname' . $self->random_string(),
@@ -50,11 +50,11 @@ sub startup_create_detailed_borrower : Test( startup => 2 ) {
     $description = 'Test account';
     $type        = 'M';
     $amount      = 5.00;
-    $user        = '';
+    $note        = '';
+    $meansofpayment = '';
 
-    my $acct_added =
-      C4::Accounts::manualinvoice( $borrowernumber, undef, $description, $type, $amount,
-        $user );
+    my $acct_added = C4::Accounts::manualinvoice( $borrowernumber, undef,
+        $description, $type, $amount, $note, $meansofpayment );
 
     ok( $acct_added == 0, 'added account for borrower' );
 
-- 
1.7.4.1



More information about the Koha-patches mailing list