Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # ---------------------------------------------------------------
- # Copyright © 2014 Merrimack Valley Library Consortium
- # Jason Stephenson <jason@sigio.com>
- #
- # This program 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.
- #
- # This program 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.
- # ---------------------------------------------------------------
- use strict;
- use warnings;
- use OpenILS::Utils::Cronscript;
- use Data::Dumper;
- my $apputils = 'OpenILS::Application::AppUtils';
- my $script = OpenILS::Utils::Cronscript->new({nolockfile=>1});
- my $login = {
- username => $ARGV[0],
- password => $ARGV[1],
- workstation => $ARGV[2],
- type => 'staff'
- };
- my $authtoken = $script->authenticate($login);
- die "failed to authenticate" unless($authtoken);
- END {
- $script->logout();
- }
- my $barcode;
- do {
- print ("Enter barcode: ");
- $barcode = <STDIN>;
- chomp($barcode);
- if ($barcode) {
- my $user = retrieve_user($barcode);
- if (!defined($user) || ref($user) eq 'HASH') {
- print Dumper $user;
- } else {
- my $bills = $apputils->simplereq(
- 'open-ils.actor',
- 'open-ils.actor.user.transactions.history.have_balance',
- $authtoken,
- $user->id
- );
- if (ref($bills) eq 'ARRAY') {
- my @payments = ();
- foreach my $bill (@$bills) {
- printf("\t%d : %.2f\n", $bill->id, $bill->balance_owed);
- push(@payments, [$bill->id, $bill->balance_owed])
- if ($bill->balance_owed > 0.0);
- }
- if (@payments) {
- my $r = forgive_bills($user, \@payments);
- print Dumper $r;
- }
- } else {
- print Dumper $bills;
- }
- }
- }
- } while ($barcode);
- sub retrieve_user {
- my $barcode = shift;
- my $e = $script->editor(authtoken=>$authtoken);
- my $card = $e->search_actor_card({barcode => $barcode, active => 't'});
- return $e->event unless($card);
- my $user = $e->retrieve_actor_user($card->[0]->usr) if (@$card);
- return $e->event unless($user);
- $e->finish;
- return $user;
- }
- sub forgive_bills {
- my $user = shift;
- my $paymentref = shift;
- my $result = $apputils->simplereq(
- 'open-ils.circ',
- 'open-ils.circ.money.payment',
- $authtoken,
- {
- payment_type => "forgive_payment",
- userid => $user->id,
- note => "Forgiven en masse: forgive_bills.pl",
- payments => $paymentref
- },
- $user->last_xact_id
- );
- return $result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement