[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha pay_by_amount.pl [dev_week]
From: |
Kyle Hall |
Subject: |
[Koha-cvs] koha pay_by_amount.pl [dev_week] |
Date: |
Thu, 14 Dec 2006 12:44:46 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: dev_week
Changes by: Kyle Hall <kylemhall> 06/12/14 12:44:46
Added files:
. : pay_by_amount.pl
Log message:
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/pay_by_amount.pl?cvsroot=koha&only_with_tag=dev_week&rev=1.1.2.1
Patches:
Index: pay_by_amount.pl
===================================================================
RCS file: pay_by_amount.pl
diff -N pay_by_amount.pl
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ pay_by_amount.pl 14 Dec 2006 12:44:46 -0000 1.1.2.1
@@ -0,0 +1,87 @@
+#!/usr/bin/perl -w
+
+# written 12/07/2006 by address@hidden
+# part of the koha library system, script to facilitate paying off fines
+
+# This script, rather than paying idividual fines, accepts a payment amount
and pays fines
+# unil the give amount is paid.
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it under the
+# terms of the GNU General Public License as published by the Free Software
+# Foundation; either version 2 of the License, or (at your option) any later
+# version.
+#
+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
+# Suite 330, Boston, MA 02111-1307 USA
+
+use strict;
+use C4::Context;
+use C4::Auth;
+use C4::Output;
+use CGI;
+use C4::Search;
+use C4::Accounts2;
+use C4::Stats;
+use HTML::Template;
+
+my $input = new CGI;
+
+# get the POST variables
+my $bornum = $input->param( 'bornum' );
+my $amount = $input->param( 'amount' );
+my $amountpaid = $amount;
+
+# create database handle
+my $dbh = C4::Context->dbh;
+my $env;
+my $sth;
+
+# get all unpaid fines for this user
+# Loop through the fines due, paying them until $amountpaid is 0, or all fines
have been paid.
+# If all fines have been paid and $amountpaid is still greater than 0, just
insert a payment for the leftover amount.
+$sth = $dbh->prepare( "SELECT * FROM accountlines WHERE borrowernumber = ? AND
amountoutstanding > 0" ) || die $sth->errstr;
+$sth->execute( $bornum ) || die $sth->errstr;
+
+while ( my @data = $sth->fetchrow_hashref() && $amountpaid > 0 ) {
+ my $accountno = $data['accountno'];
+ my $amountoutstanding = $data['amountoutstanding'];
+
+ # If the amount paid in is less than the current fine, just lower the
amountoutstanding by what is in $amountpaid
+ my $balance = 0;
+ if ( $amountoutstanding > $amountpaid ) {
+ $balance = $amountoutstanding - $amountpaid;
+ }
+
+ # Update the amount outstanding for this fine, set to 0 if
$amountoutstanding is less than $amountpaid, $amountpaid otherwise
+ $sth = $dbh->prepare( "UPDATE accountlines SET amountoutstanding = ? WHERE
borrowernumber = ? AND accountno = ?" ) || die $sth->errstr;
+ $sth->execute( $balance, $bornum, $accountno ) || die $sth->errstr;
+
+ # decrement $amountpaid by the amount of the fine just paid
+ $amountpaid -= $amountoutstanding;
+}
+
+# Grab the next accountno to use for inserting the payment row into
accountlines
+$sth = $dbh->prepare( "SELECT MAX(accountno) FROM accountlines" ) || die
$sth->errstr;
+$sth->execute || die $sth->errstr;
+my $data = $sth->fetchrow_hashref;
+$sth->finish;
+my $nextAccountno = $data->{ 'MAX(accountno)' } + 1;
+
+# Insert a payment line into accountlines for the entire payment
+$sth = $dbh->prepare( "INSERT INTO accountlines (
+ borrowernumber, accountno, itemnumber, date, amount,
description, dispute, accounttype, amountoutstanding, timestamp
+ ) VALUES (
+ ?, ?, NULL , 'TODAY()', '?', 'Payment', NULL , 'Pay',
'0.000000', NOW()
+ )" ) || die $sth->errstr;
+$sth->execute( $bornum, $nextAccountno, $amount * -1 ) || die $sth->errstr;
+
+# Redirect user back to the members page
+print $input->redirect("/cgi-bin/koha/members/moremember.pl?bornum=$bornum");
+
\ No newline at end of file
- [Koha-cvs] koha pay_by_amount.pl [dev_week],
Kyle Hall <=