[Koha-patches] [PATCH] Fines System Updates
Kyle M Hall
kyle.m.hall at gmail.com
Mon Oct 12 17:24:30 CEST 2009
This is a new version of the fines system updates discussed on koha-devel. This version leaves accountno intact.
Added accountid and accountid_paid to accountlines table
Updated fines payment system to use accountid
Added columns for accountid and accountid_paid to the borrower account page.
---
C4/Accounts.pm | 23 +++-----
installer/data/mysql/kohastructure.sql | 2 +
installer/data/mysql/updatedatabase.pl | 7 ++
.../prog/en/modules/members/boraccount.tmpl | 9 ++-
.../intranet-tmpl/prog/en/modules/members/pay.tmpl | 2 +
members/boraccount.pl | 3 +-
members/pay.pl | 59 +++++++++++---------
7 files changed, 60 insertions(+), 45 deletions(-)
diff --git a/C4/Accounts.pm b/C4/Accounts.pm
index e137587..0e160f7 100644
--- a/C4/Accounts.pm
+++ b/C4/Accounts.pm
@@ -134,7 +134,7 @@ sub recordpayment {
=head2 makepayment
- &makepayment($borrowernumber, $acctnumber, $amount, $branchcode);
+ &makepayment($accountid, $borrowernumber, $accountno, $amount, $user, $branchcode);
Records the fact that a patron has paid off the entire amount he or
she owes.
@@ -155,7 +155,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 ( $accountid, $borrowernumber, $accountno, $amount, $user, $branch ) = @_;
my $dbh = C4::Context->dbh;
# begin transaction
@@ -163,18 +163,12 @@ sub makepayment {
my $newamtos = 0;
my $sth =
$dbh->prepare(
- "SELECT * FROM accountlines WHERE borrowernumber=? AND accountno=?");
- $sth->execute( $borrowernumber, $accountno );
+ "SELECT * FROM accountlines WHERE accountid=?");
+ $sth->execute( $accountid );
my $data = $sth->fetchrow_hashref;
$sth->finish;
- $dbh->do(
- "UPDATE accountlines
- SET amountoutstanding = 0
- WHERE borrowernumber = $borrowernumber
- AND accountno = $accountno
- "
- );
+ $dbh->do("UPDATE accountlines SET amountoutstanding = 0 WHERE accountid = $accountid");
# print $updquery;
# $dbh->do( "
@@ -188,17 +182,16 @@ sub makepayment {
my $payment = 0 - $amount;
$dbh->do( "
INSERT INTO accountlines
- (borrowernumber, accountno, date, amount,
+ (accountid_paid, borrowernumber, accountno, date, amount,
description, accounttype, amountoutstanding)
- VALUES ($borrowernumber, $nextaccntno, now(), $payment,
+ VALUES ($accountid, $borrowernumber, $nextaccntno, now(), $payment,
'Payment,thanks - $user', 'Pay', 0)
" );
# 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,
- $accountno );
+ UpdateStats( $user, 'payment', $amount, '', '', '', $borrowernumber, $accountno );
$sth->finish;
#check to see what accounttype
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index eaf47e0..ff3fc47 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -21,6 +21,8 @@
DROP TABLE IF EXISTS `accountlines`;
CREATE TABLE `accountlines` (
+ `accountid` int(11) NOT NULL auto_increment,
+ `accountid_paid` int(11) default NULL,
`borrowernumber` int(11) NOT NULL default 0,
`accountno` smallint(6) NOT NULL default 0,
`itemnumber` int(11) default NULL,
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 10c3451..b8a5461 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -2675,6 +2675,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
SetVersion ($DBversion);
}
+$DBversion = '3.01.00.XXX';
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("ALTER TABLE `accountlines` ADD `accountid` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST , ADD `accountid_paid` INT( 11 ) NULL AFTER `accountid` ;");
+ print "Upgrade to $DBversion done ( Added accountid and accountid_paid to accountlines table )\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..564187f 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl
@@ -27,9 +27,12 @@
<div class="tabs-container">
<!-- The table with the account items -->
<table>
+
<tr>
- <th>Date</th>
+ <th>Account</th>
+ <th>Date</th>
<th>Description of charges</th>
+ <th>Account Paid</th>
<th>Amount</th>
<th>Outstanding</th>
<th> </th>
@@ -39,8 +42,10 @@
<!-- TMPL_LOOP NAME="accounts" -->
<!-- TMPL_IF NAME="toggle" --> <tr><!-- TMPL_ELSE --><tr class="highlight"><!-- /TMPL_IF -->
+ <td><!-- TMPL_VAR NAME="accountid" --></td>
<td><!-- TMPL_VAR NAME="date" --></td>
<td><!-- TMPL_VAR NAME="description" --> <!-- TMPL_IF NAME="itemnumber" --><a href="/cgi-bin/koha/catalogue/moredetail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->&itemnumber=<!-- TMPL_VAR NAME="itemnumber" -->">View item</a> <!-- /TMPL_IF --><!-- TMPL_IF NAME="printtitle" --> <!-- TMPL_VAR NAME="title" escape="html" --><!-- /TMPL_IF --></td>
+ <td><!-- TMPL_VAR NAME="accountid_paid" --></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 +60,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/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl
index 1177ba2..9d59f9e 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/pay.tmpl
@@ -59,6 +59,8 @@
<input type="hidden" name="notify_id<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="notify_id" -->" />
<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" -->" />
+ <input type="hidden" name="accountid<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="accountid" -->" />
+ <input type="hidden" name="accountid_paid<!-- TMPL_VAR name="i" -->" value="<!-- TMPL_VAR name="accountid_paid" -->" />
</td>
<td><!-- TMPL_VAR name="description" --> <!-- TMPL_VAR name="title" escape="html" --></td>
<td><!-- TMPL_VAR name="accounttype" --></td>
diff --git a/members/boraccount.pl b/members/boraccount.pl
index 9417ab9..8a3d731 100755
--- a/members/boraccount.pl
+++ b/members/boraccount.pl
@@ -97,7 +97,8 @@ for (my $i=0;$i<$numaccts;$i++){
'amountoutstanding' => sprintf("%.2f",$accts->[$i]{'amountoutstanding'}),
'accountno' => $accts->[$i]{'accountno'},
'payment' => ( $accts->[$i]{'accounttype'} eq 'Pay' ),
-
+ 'accountid' => $accts->[$i]{'accountid'},
+ 'accountid_paid' => $accts->[$i]{'accountid_paid'},
);
if ($accts->[$i]{'accounttype'} ne 'F' && $accts->[$i]{'accounttype'} ne 'FU'){
diff --git a/members/pay.pl b/members/pay.pl
index 02bb683..3d12baa 100755
--- a/members/pay.pl
+++ b/members/pay.pl
@@ -65,25 +65,29 @@ my $user = $input->remote_user;
my $branches = GetBranches();
my $branch = GetBranch( $input, $branches );
-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;
+for ( my $i = 0 ; $input->param( 'payfine' . sprintf("%02d", $i) ) ; $i++ ) {
+ my $index = sprintf("%02d", $i);
+
+ my $payfine = $input->param( "payfine$index" );
+ if ( $payfine eq 'wo' ) {
+ $inp{ "payfine$index" } = $payfine;
+
$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 );
+ if ( $payfine eq 'yes' ) {
+ my $amount = $input->param( "amount$index" );
+ my $borrowernumber = $input->param( "borrowernumber$index" );
+ my $accountno = $input->param( "accountno$index" );
+ my $accountid = $input->param( "accountid$index" );
+ makepayment( $accountid, $borrowernumber, $accountno, $amount, $user, $branch );
+
$check = 2;
}
}
+
my $total = $input->param('total') || '';
if ( $check == 0 ) {
if ( $total ne '' ) {
@@ -102,6 +106,10 @@ if ( $check == 0 ) {
GetBorNotifyAcctRecord( $borrowernumber, $notify[$j] );
for ( my $i = 0 ; $i < $numaccts ; $i++ ) {
my %line;
+
+ $line{accountid} = $accts->[$i]{'accountid'};
+ $line{accountid_paid} = $accts->[$i]{'accountid_paid'};
+
if ( $accts->[$i]{'amountoutstanding'} != 0 ) {
$accts->[$i]{'amount'} += 0.00;
$accts->[$i]{'amountoutstanding'} += 0.00;
@@ -188,7 +196,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 $accountid = $input->param("accountid$value");
+ writeoff( $accountid, $borrowernumber, $accountno, $itemno, $accounttype, $amount );
}
$borrowernumber = $input->param('borrowernumber');
print $input->redirect(
@@ -196,28 +205,24 @@ else {
}
sub writeoff {
- my ( $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
+ my ( $accountid, $borrowernumber, $accountnum, $itemnum, $accounttype, $amount ) = @_;
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=?"
- );
- $sth->execute( $accountnum, $borrowernumber );
+ $dbh->prepare("UPDATE accountlines SET amountoutstanding=0 WHERE accountid=?");
+ $sth->execute( $accountid );
$sth->finish;
- $sth = $dbh->prepare("select max(accountno) from accountlines");
+
+ $sth = $dbh->prepare("SELECT MAX(accountno) FROM accountlines");
$sth->execute;
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->execute( $borrowernumber, $account->{'max(accountno)'},
- $itemnum, $amount );
+ $account->{'max(accountno)'}++;
+
+ $sth = $dbh->prepare("INSERT INTO accountlines (accountid_paid,borrowernumber,accountno,itemnumber,date,amount,description,accounttype)
+ VALUES (?,?,?,?,now(),?,'Writeoff','W')");
+ $sth->execute( $accountid, $borrowernumber, $account->{'max(accountno)'}, $itemnum, $amount );
$sth->finish;
- UpdateStats( $branch, 'writeoff', $amount, '', '', '',
- $borrowernumber );
+ UpdateStats( $branch, 'writeoff', $amount, '', '', '', $borrowernumber );
}
--
1.5.6.5
More information about the Koha-patches
mailing list