[Koha-patches] [PATCH] [head] 1/2 New feature - fines editable
Michael Hafen
mdhafen at tech.washk12.org
Fri Apr 10 19:35:21 CEST 2009
This adds a system preference controlled feature. With the sys. pref.
on the fines can be edited or deleted. The sys. pref. defaults to off.
---
C4/Accounts.pm | 67 ++++++++++-
admin/systempreferences.pl | 1 +
installer/data/mysql/en/mandatory/sysprefs.sql | 1 +
.../1-Obligatoire/unimarc_standard_systemprefs.sql | 1 +
.../prog/en/modules/members/boraccount.tmpl | 3 +
.../prog/en/modules/members/updateaccount.tmpl | 58 +++++++++
members/boraccount.pl | 2 +
members/updateaccount.pl | 123 ++++++++++++++++++++
8 files changed, 254 insertions(+), 2 deletions(-)
create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/members/updateaccount.tmpl
create mode 100755 members/updateaccount.pl
diff --git a/C4/Accounts.pm b/C4/Accounts.pm
index c43741b..d9a1c80 100644
--- a/C4/Accounts.pm
+++ b/C4/Accounts.pm
@@ -25,17 +25,18 @@ use C4::Members;
use C4::Items;
use C4::Circulation qw(MarkIssueReturned);
-use vars qw($VERSION @ISA @EXPORT);
+use vars qw($VERSION @ISA @EXPORT $debug);
BEGIN {
# set the version for version checking
$VERSION = 3.03;
+ $debug = $ENV{DEBUG} || 0;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
&recordpayment &makepayment &manualinvoice
&getnextacctno &reconcileaccount &getcharges &getcredits
- &getrefunds &chargelostitem
+ &getrefunds &chargelostitem &updateline &deleteline
); # removed &fixaccounts
}
@@ -602,6 +603,68 @@ sub getcharges {
}
+sub updateline {
+ my ( $borrno, $accountno, $desc, $amount, $outstanding, $type ) = @_;
+ my $dbh = C4::Context->dbh;
+ my $query = "SELECT * FROM accountlines WHERE borrowernumber = ? AND accountno = ?";
+ my $sth = $dbh->prepare( $query );
+ $sth->execute( $borrno, $accountno );
+ my $results = $sth->fetchrow_hashref;
+ my %diff;
+ my @bind;
+ my %data = (
+ description => $desc,
+ type => $type,
+ amount => $amount,
+ amountoutstanding => $outstanding,
+ );
+
+ return unless ( $results && %$results );
+
+ foreach ( 'description', 'type' ) {
+ if ( $$results{$_} ne $data{$_} ) {
+ $diff{$_} = $data{$_};
+ }
+ }
+ foreach ( 'amount', 'amountoutstanding' ) {
+ if ( $$results{$_} != $data{$_} ) {
+ $diff{$_} = $data{$_};
+ }
+ }
+
+ if ( %diff ) {
+ $query = "UPDATE accountlines SET ";
+ foreach ( keys %diff ) {
+ $query .= "$_ = ?,";
+ push @bind, $diff{$_};
+ }
+ chop $query; # trim last ','
+ $query .= " WHERE borrowernumber = ? AND accountno = ?";
+ push @bind, ( $borrno, $accountno );
+ $dbh->do( $query, {}, @bind );
+ $debug && defined $dbh->err && warn "Database Error: ". $dbh->errstr;
+ return ( defined $dbh->err ) ? 0 : 1;
+ }
+}
+
+sub deleteline {
+ my ( $borrno, $accountno ) = @_;
+ my $dbh = C4::Context->dbh;
+ my $query = "SELECT * FROM accountlines WHERE borrowernumber = ? AND accountno = ?";
+ my $sth = $dbh->prepare( $query );
+ $sth->execute( $borrno, $accountno );
+ my $results = $sth->fetchrow_hashref;
+ my @bind;
+
+ return unless ( $results && %$results );
+
+ $query = "DELETE FROM accountlines WHERE borrowernumber = ? AND accountno = ?";
+ push @bind, ( $borrno, $accountno );
+ $dbh->do( $query, {}, @bind );
+ $debug && defined $dbh->err && warn "Database Error: ". $dbh->errstr;
+ return ( defined $dbh->err ) ? 0 : 1;
+}
+
sub getcredits {
my ( $date, $date2 ) = @_;
my $dbh = C4::Context->dbh;
diff --git a/admin/systempreferences.pl b/admin/systempreferences.pl
index 2733b91..6a9eafa 100755
--- a/admin/systempreferences.pl
+++ b/admin/systempreferences.pl
@@ -93,6 +93,7 @@ $tabsysprefs{SessionStorage} = "Admin";
$tabsysprefs{noItemTypeImages} = "Admin";
$tabsysprefs{OPACBaseURL} = "Admin";
$tabsysprefs{GranularPermissions} = "Admin";
+$tabsysprefs{AccountLinesEditable} = "Admin";
# Authorities
$tabsysprefs{authoritysep} = "Authorities";
diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql
index c59b6f0..1f315cc 100644
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -25,6 +25,7 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('EnhancedMessagingPreferences',0,'If ON, allows patrons to select to receive additional messages about items due or nearly due.','','YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('expandedSearchOption',0,'If ON, set advanced search to be expanded by default',NULL,'YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('FinesLog',1,'If ON, log fines',NULL,'YesNo');
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AccountLinesEditable',0,'If ON Patron account lines can be changed in the staff client',NULL,'YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('hidelostitems',0,'If ON, disables display of\"lost\" items in OPAC.','','YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('hide_marc',0,'If ON, disables display of MARC fields, subfield codes & indicators (still shows data)',NULL,'YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('IndependantBranches',0,'If ON, increases security between libraries',NULL,'YesNo');
diff --git a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
index 8455c7e..aba0d65 100644
--- a/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
+++ b/installer/data/mysql/fr-FR/1-Obligatoire/unimarc_standard_systemprefs.sql
@@ -28,6 +28,7 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES ('EnhancedMessagingPreferences',0,'If ON, allows patrons to select to receive additional messages about items due or nearly due.','','YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('expandedSearchOption', '1', 'active par défaut la recherche la plus avancée', '', 'YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('FinesLog', '0', 'Activer ce paramètre pour enregistrer les actions sur les pénalités financières', '', 'YesNo');
+INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('AccountLinesEditable',0,'Autorise la modification des lignes de compte des adhérents',NULL,'YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('gist', '0', 'Ce paramètre définit le taux de TVA. Attention : ce n''est pas un % mais un nombre (0.055 et pas 5.5%) Laisser à 0 si vous ne récupérez pas la TVA, ce qui est le cas de la plupart des bibliothèques françaises', '', 'Integer');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('hidelostitems', '0', 'Si ce paramètre est activé, l''OPAC n''affichera pas les notices pour lesquelles le ou les exemplaires sont marqués "perdus"', '', 'YesNo');
INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('hide_marc', '0', 'Si ce paramètre est positionné, les code des champs et sous-champs MARC sont cachés, on ne voit que les libellés.', '', 'YesNo');
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 d71b744..e2ff75b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/boraccount.tmpl
@@ -32,6 +32,7 @@
<th>Description of charges</th>
<th>Amount</th>
<th>Outstanding</th>
+ <!-- TMPL_IF NAME="accountlineseditable" --><th> </th><!-- /TMPL_IF -->
</tr>
<!-- FIXME: Shouldn't hardcode dollar signs, since Euro or Pound might be needed -->
@@ -42,6 +43,7 @@
<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>
<!-- 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>
+ <!-- TMPL_IF NAME="accountlineseditable" --><td><a href="/cgi-bin/koha/members/updateaccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&accountnumber=<!-- TMPL_VAR NAME="accountno" -->">Edit</a> <a href="/cgi-bin/koha/members/updateaccount.pl?button=Delete&borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->&accountnumber=<!-- TMPL_VAR NAME="accountno" -->">Delete</a></td><!-- /TMPL_IF -->
</tr>
<!-- /TMPL_LOOP -->
@@ -49,6 +51,7 @@
<tr>
<td colspan="3">Total due</td>
<!-- TMPL_IF NAME="totalcredit" --><td class="credit"><!-- TMPL_ELSE --><td class="debit"><!-- /TMPL_IF -->$<!-- TMPL_VAR NAME="total" --></td>
+ <!-- TMPL_IF NAME="accountlineseditable" --><td> </td><!-- /TMPL_IF -->
</tr>
</tfoot>
</table>
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/updateaccount.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/members/updateaccount.tmpl
new file mode 100644
index 0000000..dbec35e
--- /dev/null
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/updateaccount.tmpl
@@ -0,0 +1,58 @@
+<!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
+<title>Koha › Borrowers › Update Account Line</title>
+<!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
+</head>
+<body>
+<!-- TMPL_INCLUDE NAME="header.inc" -->
+<!-- TMPL_INCLUDE NAME="patron-search.inc" -->
+
+<div id="breadcrumbs"><a href="/cgi-bin/koha/mainpage.pl">Home</a> › <a href="/cgi-bin/koha/members/members-home.pl">Patrons</a> › Update Account Line</div>
+
+<div id="doc3" class="yui-t2">
+
+ <div id="bd">
+ <div id="yui-main">
+ <div class="yui-b">
+<!-- TMPL_INCLUDE NAME="members-toolbar.inc" -->
+
+<!-- The manual invoice and credit buttons -->
+<div class="toptabs">
+<ul class="ui-tabs-nav">
+ <li class="ui-tabs-selected"><a href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Account</a></li>
+ <li><a href="/cgi-bin/koha/members/pay.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->" >Pay fines</a></li>
+ <li><a href="/cgi-bin/koha/members/maninvoice.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->" >Create Manual Invoice</a></li>
+ <li><a href="/cgi-bin/koha/members/mancredit.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->" >Create Manual Credit</a></li>
+</ul>
+<div class="tabs-container">
+<!-- TMPL_IF NAME="op" -->
+<!-- TMPL_IF NAME="error" -->
+<div class="dialog alert">
+Update failed.
+</div>
+<!-- /TMPL_IF -->
+<!-- /TMPL_IF -->
+
+<form action="/cgi-bin/koha/members/updateaccount.pl" method="post"><input type="hidden" name="borrowernumber" id="borrowernumber" value="<!-- TMPL_VAR Name="borrowernumber" -->" />
+<input type="hidden" name="borrowernumber" value="<!-- TMPL_VAR NAME="borrowernumber" -->"/>
+<input type="hidden" name="accountnumber" value="<!-- TMPL_VAR NAME="accountnumber" -->"/>
+ <fieldset class="rows">
+ <legend>Update Account Line</legend>
+ <ol>
+ <li><label for="description">Description: </label><input type="text" name="description" value="<!-- TMPL_VAR NAME="description" -->" /></li>
+ <li><label for="amount">Amount: </label><input type="text" name="amount" value="<!-- TMPL_VAR NAME="amount" -->" /></li>
+ <li><label for="amount">Amount Outstanding: </label><input type="text" name="outstanding" value="<!-- TMPL_VAR NAME="outstanding" -->" /></li>
+ </ol></fieldset>
+<fieldset class="action"><input type="submit" name="button" value="Update" /> <a class="cancel" href="/cgi-bin/koha/members/boraccount.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->">Cancel</a></fieldset>
+</form>
+
+
+</div></div>
+
+</div>
+</div>
+
+<div class="yui-b">
+<!-- TMPL_INCLUDE NAME="circ-menu.inc" -->
+</div>
+</div>
+<!-- TMPL_INCLUDE NAME="intranet-bottom.inc" -->
diff --git a/members/boraccount.pl b/members/boraccount.pl
index 40dd68a..7edb9f7 100755
--- a/members/boraccount.pl
+++ b/members/boraccount.pl
@@ -78,6 +78,7 @@ for (my $i=0;$i<$numaccts;$i++){
$accts->[$i]{'amountoutstandingcredit'} = 1;
}
my %row = ( 'date' => format_date($accts->[$i]{'date'}),
+ 'accountno' => $accts->[$i]{'accountno'},
'amountcredit' => $accts->[$i]{'amountcredit'},
'amountoutstandingcredit' => $accts->[$i]{'amountoutstandingcredit'},
'toggle' => $accts->[$i]{'toggle'},
@@ -102,6 +103,7 @@ $template->param( picture => 1 ) if $picture;
$template->param(
finesview => 1,
+ accountlineseditable=> C4::Context->preference('AccountLinesEditable'),
firstname => $data->{'firstname'},
surname => $data->{'surname'},
borrowernumber => $borrowernumber,
diff --git a/members/updateaccount.pl b/members/updateaccount.pl
new file mode 100755
index 0000000..3c612a8
--- /dev/null
+++ b/members/updateaccount.pl
@@ -0,0 +1,123 @@
+#!/usr/bin/perl
+
+#written 2009-03-30 by mdhafen at tech.washk12.org
+#page to update information of an account line.
+
+# 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 CGI;
+use C4::Auth;
+use C4::Output;
+use C4::Members;
+use C4::Accounts;
+use C4::Items;
+use C4::Branch;
+
+my $input = new CGI;
+
+my ($template, $loggedinuser, $cookie)
+ = get_template_and_user({template_name => "members/updateaccount.tmpl",
+ query => $input,
+ type => "intranet",
+ authnotrequired => 0,
+ flagsrequired => { updatecharges => 1 },
+ debug => 1,
+ });
+
+my $borrowernumber = $input->param('borrowernumber');
+my $accountno = $input->param('accountnumber');
+
+unless ( C4::Context->preference('AccountLinesEditable') ) {
+ print $input->redirect( "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" );
+ exit;
+}
+
+unless ( $borrowernumber && $accountno ) {
+ # FIXME should check if $borrowernumber is set before this.
+ print $input->redirect( "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" );
+ exit;
+}
+
+my $op = $input->param('button');
+my $result = 0;
+my ( $desc, $type, $amount, $outstanding ) = ( '', '', 0, 0 );
+my $borr = GetMember( $borrowernumber, 'borrowernumber' );
+
+if ( $op ) {
+ $desc = $input->param('description');
+ $type = $input->param('type');
+ $amount = $input->param('amount');
+ $outstanding = $input->param('outstanding');
+
+ if ( $op eq 'Delete' ) {
+ $result = deleteline( $borrowernumber, $accountno );
+ if ( $result ) {
+ print $input->redirect( "/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber" );
+ exit;
+ }
+ } elsif ( $desc || $type || $amount || $outstanding ) {
+ $result = updateline( $borrowernumber, $accountno, $desc, $amount, $outstanding, $type );
+ }
+} else {
+ my ( $charge ) = getcharges( $borrowernumber, undef, $accountno );
+ $desc = $$charge{ 'description' };
+ $type = $$charge{ 'type' };
+ $amount = sprintf '%.02f', $$charge{ 'amount' };
+ $outstanding = sprintf '%.02f', $$charge{ 'amountoutstanding' };
+}
+
+$template->param(
+ op => $op,
+ borrowernumber => $borrowernumber,
+ accountnumber => $accountno,
+ description => $desc,
+ type => $type,
+ amount => $amount,
+ outstanding => $outstanding,
+ error => !$result,
+ );
+
+# Borrower information for template
+if ( $borr->{'category_type'} eq 'C') {
+ my ( $catcodes, $labels ) = GetborCatFromCatType( 'A', 'WHERE category_type = ?' );
+ my $cnt = scalar(@$catcodes);
+ $template->param( 'CATCODE_MULTI' => 1) if $cnt > 1;
+ $template->param( 'catcode' => $catcodes->[0] ) if $cnt == 1;
+}
+
+$template->param( adultborrower => 1 ) if ( $borr->{'category_type'} eq 'A' );
+my ($picture, $dberror) = GetPatronImage($borr->{'cardnumber'});
+$template->param( picture => 1 ) if $picture;
+$template->param(
+ firstname => $borr->{'firstname'},
+ surname => $borr->{'surname'},
+ cardnumber => $borr->{'cardnumber'},
+ categorycode => $borr->{'categorycode'},
+ category_type => $borr->{'category_type'},
+ categoryname => $borr->{'description'},
+ address => $borr->{'address'},
+ address2 => $borr->{'address2'},
+ city => $borr->{'city'},
+ zipcode => $borr->{'zipcode'},
+ phone => $borr->{'phone'},
+ email => $borr->{'email'},
+ branchcode => $borr->{'branchcode'},
+ branchname => GetBranchName($borr->{'branchcode'}),
+ is_child => ($borr->{'category_type'} eq 'C'),
+ );
+
+output_html_with_http_headers $input, $cookie, $template->output;
--
1.5.6.3
More information about the Koha-patches
mailing list