home *** CD-ROM | disk | FTP | other *** search
/ Enter 2000 February / Enter2_2.iso / live / usr / X11R6 / lib / X11 / cbb / reports / uncleared-txn.pl < prev   
Encoding:
Perl Script  |  1998-10-07  |  4.8 KB  |  173 lines

  1. #!/usr/bin/perl
  2. #  uncleared-txn.pl - Prints a report of the uncleared transactions sorted 
  3. #                     by date
  4. #
  5. #  Written by Kevin L. McWhirter (klmcw@crl.com).  Started May 18, 1997
  6. #
  7. #  Copyright (C) 1994 - 1997  Curtis L. Olson  - curt@sledge.mn.org
  8. #
  9. #  This program is free software; you can redistribute it and/or modify
  10. #  it under the terms of the GNU General Public License as published by
  11. #  the Free Software Foundation; either version 2 of the License, or
  12. #  (at your option) any later version.
  13. #
  14. #  This program is distributed in the hope that it will be useful,
  15. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. #  GNU General Public License for more details.
  18. #
  19. #  You should have received a copy of the GNU General Public License
  20. #  along with this program; if not, write to the Free Software
  21. #  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. # $Id: uncleared-txn.pl,v 1.1.1.1 1998/10/07 07:11:44 phil Exp $
  24. # (Log is kept at end of this file)
  25.  
  26.  
  27. package CBB;
  28.  
  29. use strict;    # don't take no guff
  30.  
  31.  
  32. my($cbb_incl_dir, $temp);
  33. my($account, @account_list, $name, $key, $trans, %ALLTRANS);
  34. my($firstdate, $lastdate);
  35. my($firstday, $firstmon, $firstyear, $lastday, $lastmon, $lastyear);
  36. my($totalmonths);
  37. my($junk, $result);
  38. my($date, $todate, $fromdate);
  39.  
  40.  
  41. # return the directory of a file name (this is duplicated in common.pl
  42. # but we need this to find the include directory for common.pl :-(
  43. sub my_file_dirname {
  44.     my($file) = @_;
  45.     my($pos);
  46.  
  47.     $pos = rindex($file, "/");
  48.     if ( $pos >= 0 ) {
  49.     return substr($file, 0, ($pos + 1));
  50.     } else { 
  51.     return "./"; 
  52.     }
  53. }
  54.  
  55. # specify the installed location of the necessary pieces.
  56. $temp = &my_file_dirname($0); chop($temp);
  57. $cbb_incl_dir = &my_file_dirname($temp);
  58. unshift(@INC, $cbb_incl_dir);
  59.  
  60. require "common.pl";
  61. require "reports.pl";
  62. require "engine.pl";
  63. require "memorized.pl";
  64.  
  65.  
  66. ($#ARGV >= 0) || 
  67.     die "Usage: report [ -from mm/dd/[yy]yy ] [ -to mm/dd/[yy]yy ] accounts";
  68.  
  69.  
  70. # process arguments
  71.  
  72. ($fromdate, $todate, @account_list) = &process_rep_args();
  73.  
  74. if ( $fromdate eq "all" ) {
  75.     $fromdate = "";
  76. }
  77.  
  78. if ( $todate eq "all" ) {
  79.     $todate = "";
  80. }
  81.  
  82. # print "'$fromdate' '$todate' '@account_list'\n";
  83.  
  84. %ALLTRANS = ();
  85.  
  86. # load all matching transactions from all specified accounts (ignoring
  87. # those that are outside the specified date range)
  88.  
  89. foreach $account ( @account_list ) {
  90.     $name = &file_basename($account);
  91.  
  92.     # open the account
  93.     (&load_trans($account) eq "ok") || die "Cannot open account:  $account";
  94.  
  95.     $result = &first_trans();
  96.     while ( $result ne "none" ) {
  97.         ($key, $trans) = split(/\t/, $result, 2);
  98.         my($date, $check, $desc, $debit, $credit, $cat, $com, $cleared,
  99.        $junk) = split(/\t/, $trans, 9);
  100.  
  101.     if ( ($firstdate eq "") || ($date < $firstdate) ) {
  102.         $firstdate = $date;
  103.     }
  104.  
  105.     if ( ($lastdate eq "") || ($date > $lastdate) ) {
  106.         $lastdate = $date;
  107.     }
  108.  
  109.         if ( (($fromdate == 0) || ($fromdate <= $date)) && 
  110.             (($todate == 0) || ($todate >= $date)) &&
  111.         ($cleared ne "x") ) {
  112.         $ALLTRANS{"$key$name"} = $trans;
  113.         }
  114.  
  115.         $result = &next_trans();
  116.     }
  117. }
  118.  
  119. # determine number of months in range
  120. ($firstyear,$firstmon,$firstday) = $firstdate =~ /(\d\d\d\d)(\d\d)(\d\d)/;
  121. ($lastyear,$lastmon,$lastday) = $lastdate =~ /(\d\d\d\d)(\d\d)(\d\d)/;
  122.  
  123. $totalmonths = ($lastyear - $firstyear) * 12;
  124. $totalmonths += ($lastmon - $firstmon);
  125. $totalmonths++;
  126.  
  127. print "Uncleared Transactions for $firstmon/$firstday/$firstyear".
  128.       " to $lastmon/$lastday/$lastyear.\n";
  129. print "    (Range is $totalmonths months.)\n";
  130. print "\n";
  131.  
  132. # sort and print
  133. foreach $key (sort (keys %ALLTRANS) ) {
  134.     # print $ALLTRANS{$key} . "\n";
  135.     &format_line("$ALLTRANS{$key}");
  136. }
  137.  
  138.  
  139. sub format_line {
  140.     my($date, $check, $desc, $debit, $credit, $cat, $com, $cleared,
  141.           $total) = split(/\t/, $_[0]);
  142.     my($year,$mon,$day) = $date =~ /(\d\d\d\d)(\d\d)(\d\d)/;
  143.     my($nicedate, $cutdesc, $cutcom, $nicecat);
  144.  
  145.     $year = substr($year, 2, 4);
  146.  
  147.     $nicedate = "$mon/$day/$year";
  148.     $cutdesc = substr($desc, 0, 15);
  149.     $cutcom = substr($com, 0, 15);
  150.     $nicecat = substr($cat, 0, 9);
  151.     if ( substr($cat, 0, 1) eq "|" ) {
  152.         $nicecat = "-Splits-";
  153.     }
  154.  
  155.     printf("%5s  %-8s  %-15s  %9.2f  %9.2f  %-1s  %9.2f\n",
  156.           $check, $nicedate, $cutdesc, $debit, $credit, $cleared, $total);
  157.     printf("%5s  %-8s  %-15s  %-9s\n\n", "", "", $cutcom, $nicecat);
  158. }
  159.  
  160. # ----------------------------------------------------------------------------
  161. # $Log: uncleared-txn.pl,v $
  162. # Revision 1.1.1.1  1998/10/07 07:11:44  phil
  163. #
  164. #
  165. # Revision 2.2  1998/08/14 14:28:52  curt
  166. # Added desc-pie graph.
  167. # Added option to eliminate splash screen.
  168. # Other misc. tweaks and bug fixes.
  169. #
  170. # Revision 2.1  1997/07/02 18:31:56  curt
  171. # Add an "Uncleared transaction" report.
  172. #
  173.