chrissharp123

Untitled

Nov 8th, 2018
282
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use strict;
  2. use warnings;
  3.  
  4. use OpenILS::Utils::Cronscript;
  5. use Data::Dumper;
  6. use DBI;
  7.  
  8. my $apputils = 'OpenILS::Application::AppUtils';
  9.  
  10. my $script = OpenILS::Utils::Cronscript->new({nolockfile=>1});
  11.  
  12. my $login = {
  13.     username => $ARGV[0],
  14.     password => $ARGV[1],
  15.     workstation => $ARGV[2],
  16.     type => 'staff'
  17. };
  18.  
  19. my $authtoken = $script->authenticate($login);
  20.  
  21. die "failed to authenticate" unless($authtoken);
  22.  
  23. END {
  24.     $script->logout();
  25. }
  26.  
  27. my $settings = {
  28.      host => "next-db01",
  29.      db => "evergreen",
  30.      user => "evergreen"
  31. };
  32.  
  33. my $dbh = DBI->connect('DBI:Pg:dbname=' . $settings->{'db'} . ';host=' . $settings->{'host'}, $settings->{'user'},
  34.             undef,
  35.             {
  36.                 RaiseError => 1,
  37.                 ShowErrorStatement => 0,
  38.                 AutoCommit => 0
  39.             }
  40. ) or die DBI->errstr;
  41.  
  42. my $query = "select * from csharp.okrls_forgive_fines_2018_11_07";
  43.  
  44. my $sth = $dbh->prepare($query);
  45. $sth->execute();
  46.  
  47. my @payments;
  48.  
  49. my $xacts = $sth->fetchall_hashref("xact_id");
  50.  
  51.  
  52.  
  53.  
  54. #print Dumper $xacts;
  55.  
  56. my @payments = ();
  57. foreach my $xact (%$xacts) {
  58.     printf("\t%d : %.2f\n", $xact->xact_id, $xact->balance_owed);
  59.     push(@payments, [$xact->xact_id, $xact->balance_owed])
  60.         if ($xact->balance_owed > 0.0);
  61. }
  62. #    if (@payments) {
  63. #        my $r = forgive_bills($user, \@payments);
  64. #        print Dumper $r;
  65. #    }
  66.  
  67. #print Dumper @payments;
  68.  
  69. #sub forgive_bills {
  70. #    my $user = shift;
  71. #    my $paymentref = shift;
  72. #
  73. #    my $result = $apputils->simplereq(
  74. #        'open-ils.circ',
  75. #        'open-ils.circ.money.payment',
  76. #        $authtoken,
  77. #        {
  78. #            payment_type => "forgive_payment",
  79. #            userid => $user->id,
  80. #            note => "Bills forgiven per OKRLS Board action 11/5/2018",
  81. #            payments => $paymentref
  82. #        },
  83. #        $user->last_xact_id
  84. #    );
  85. #    return $result;
  86. #}
  87. #
  88. $sth->finish();
  89. $dbh->disconnect();
RAW Paste Data