Bugzilla – Attachment 82793 Details for
Bug 21915
Add a way to automatically reconcile balance for patrons
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21915: Add a cli script to reconcile balances
Bug-21915-Add-a-cli-script-to-reconcile-balances.patch (text/plain), 4.04 KB, created by
Tomás Cohen Arazi (tcohen)
on 2018-11-30 13:44:50 UTC
(
hide
)
Description:
Bug 21915: Add a cli script to reconcile balances
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2018-11-30 13:44:50 UTC
Size:
4.04 KB
patch
obsolete
>From 9571d952cd0f50a9ed827e9479d9f36dc2f16b43 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 30 Nov 2018 10:28:48 -0300 >Subject: [PATCH] Bug 21915: Add a cli script to reconcile balances > >This patch adds a CLI script, reconcile_balances.pl that takes care >of calling the reconcile operation for all patrons that have outstanding >credits. > >To test: >- Have patrons with outstanding credits and debits >- Run the script: > $ kshell > k$ perl misc/cronjobs/reconcile_balances.pl --verbose >=> SUCCESS: Notice patrons got their balances reconciled, and useful > information is output. >- Add new outstanding credits and debits to patrons you con easily >identify >- Run: > k$ perl misc/cronjobs/reconcile_balances.pl >=> SUCCESS: Notice balances are reconciled, but no output >- Run: > k$ perl misc/cronjobs/reconcile_balances.pl --help >=> SUCCESS: Usage information is printed. >- Sign off :-D >--- > misc/cronjobs/reconcile_balances.pl | 116 ++++++++++++++++++++++++++++ > 1 file changed, 116 insertions(+) > create mode 100755 misc/cronjobs/reconcile_balances.pl > >diff --git a/misc/cronjobs/reconcile_balances.pl b/misc/cronjobs/reconcile_balances.pl >new file mode 100755 >index 0000000000..3adbf41ba7 >--- /dev/null >+++ b/misc/cronjobs/reconcile_balances.pl >@@ -0,0 +1,116 @@ >+#!/usr/bin/perl >+ >+# Copyright 2018 Theke Solutions >+# >+# 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 3 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, see <http://www.gnu.org/licenses>. >+ >+=head1 NAME >+ >+reconcile_balances.pl - cron script to reconcile patron's balances >+ >+=head1 SYNOPSIS >+ >+./reconcile_balances.pl >+ >+or, in crontab: >+0 1 * * * reconcile_balances.pl >+ >+=head1 DESCRIPTION >+ >+This script loops through patrons with outstanding credits and proceeds >+to reconcile their balances. >+ >+=head1 OPTIONS >+ >+=over 8 >+ >+=item B<--help> >+ >+Prints a brief help message and exits. >+ >+=item B<--verbose> >+ >+Makes the process print information about the taken actions. >+ >+=back >+ >+=cut >+ >+use Modern::Perl; >+ >+use Getopt::Long; >+use Pod::Usage; >+ >+BEGIN { >+ # find Koha's Perl modules >+ # test carefully before changing this >+ use FindBin; >+ eval { require "$FindBin::Bin/../kohalib.pl" }; >+} >+ >+use C4::Log; >+ >+use Koha::Account::Lines; >+use Koha::Patrons; >+ >+my $help = 0; >+my $verbose = 0; >+ >+GetOptions( >+ 'help' => \$help, >+ 'verbose' => \$verbose >+) or pod2usage(2); >+ >+pod2usage(1) if $help; >+ >+cronlogaction(); >+ >+my @patron_ids = map { $_->borrowernumber } Koha::Account::Lines->search( >+ { >+ amountoutstanding => { '<' => 0 } >+ }, >+ { >+ columns => [ qw/borrowernumber/ ], >+ distinct => 1, >+ } >+ ); >+ >+my $patrons = Koha::Patrons->search({ borrowernumber => { -in => \@patron_ids } }); >+ >+while (my $patron = $patrons->next) { >+ >+ my $account = $patron->account; >+ my $total_outstanding_credit = $account->outstanding_credits->total_outstanding; >+ my $total_outstanding_debit = $account->outstanding_debits->total_outstanding; >+ >+ if ( $total_outstanding_credit < 0 >+ and $total_outstanding_debit > 0) { >+ >+ $account->reconcile_balance; >+ >+ print $patron->id . ": credit: $total_outstanding_credit " . >+ "debit: $total_outstanding_debit " . >+ "=> outstanding " . >+ "credit: " . $account->outstanding_credits->total_outstanding . >+ " debit: " . $account->outstanding_debits->total_outstanding . "\n" >+ if $verbose; >+ >+ } >+} >+ >+1; >+ >+__END__ >-- >2.19.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 21915
:
82762
|
82763
|
82764
|
82765
|
82781
|
82782
|
82784
|
82789
|
82790
|
82791
|
82792
|
82793
|
82803
|
82804
|
82805
|
82806
|
82807
|
82863
|
82864
|
82865
|
82866
|
82867
|
83053
|
83062
|
83063
|
83064
|
83065
|
83066