Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

SimpleMoney

by Fingo (Monk)
on Mar 05, 2001 at 02:17 UTC ( [id://62136]=sourcecode: print w/replies, xml ) Need Help??
Category: Miscellaneous
Author/Contact Info Maxim Veytsman Email:maxim@bilbo.dynip.com /msg Fingo
Description: SimpleMoney is a quick and *simple* program to manage your funds. Currently it allows simple transaction, but I am planing on a reoccuring transaction feature. Other planed features include an ability to output a gnuplot readable file to draw graphs, the possibility of an optional tk gui, and (distant future) a sort of small scripting language to write more complex things (manage taxes anyone? ;) I want this program while containing many features to still not bog down the user and allow normal things without forcing the user to learn too much.
#!/usr/bin/perl -w
# Please run with -h for help
# Please run with -c for configuration (first time)
use strict;
# use Date::Calc; -- for later
my ($i, %conf);
CheckArg(@ARGV) if @ARGV;
die "file simplemoney.conf does not exist, please run -c to configure\
+n" unless (-e "simplemoney.conf"); #check for existance of configurat
+ion file

open (RCONF, "simplemoney.conf")  || die "Could not open simplemoney.c
+onf $!";

foreach ("rt", "balance", "transaction"){ #load config variables into 
+a hash
    chomp ($conf{$_} = <RCONF>);
}
close (RCONF) || die "Could not close simplemoney.conf $!"; 
unless (-e $conf{rt} && -e $conf{balance} && -e $conf{transaction}) { 
+ 
   die "One of the required files is missing, please run with -c to co
+nfigure\n";
}
while (1) {
    my ($command, $arg1, $arg2);
    print "Your command (help for list of commands):\n";
    chomp ($command = <STDIN>);
    if ($command =~ /^balance/) {
     print CalcBalance($conf{balance});
    } elsif ($command =~ /^help/i) {
    PrintHelp();
    } elsif ($command =~ /^deposit/i) {
    (undef, $arg1, $arg2) = split (/\s+/, $command); 
    CalcBalance($conf{balance},$arg1);
    AddTransaction($conf{transaction},$arg2);
    } elsif ($command =~ /^withdraw/i) {
    (undef, $arg1, $arg2) = split (/\s+/, $command); 
    $arg1 = -$arg1;
    CalcBalance($conf{balance},$arg1);
    AddTransaction($conf{transaction},$arg2);
    } elsif ($command =~ /^rt/i) {
    print "RT is not yet supported.";
    } elsif ($command =~ /^exit/i || $command =~ /^quit/i || $command 
+=~ /^e/i || $command =~ /^q/i) {
    exit 0;
    } else { #must be undefined command, try again.
    print "\nBad Command\n";
    next;
    }
}



###Subs### 

sub PrintHelp {
print "This program calculates your money balance, please run with the
+ -c flag to configure.\n";
        print "Flags:\n";
        print "     -c -- Configure\n";
        print "     -h -- This file\n";
        print "Default Files:\n";
        print "     rt.log -- Reocuring transaction configuration\n";
        print "     balance.log -- Backlog of user's balance\n";
        print "     transaction.log -- Backlog of transaction descript
+ions\n";
        print "     Configuration File: simplemoney.conf\n";
        
print "Commands:\n";
    print "      help -- show this file.\n";
    print "      deposit <arg1> <arg2> -- deposit <arg1> dollars with 
+<arg2> description in the log.\n";
    print "      withdraw <arg1> <arg2> -- same as above, but withdraw
+.\n";
    print "      rt -- not yet supported.\n";  
    print "      exit, quit, e, or q -- quit the program.\n";         
+ 
print "Note: running deposit or withdraw with no arguments will do not
+hing, running with only a value will print 'this description is inten
+tionaly left blank' in balance.log\n"  
}

sub CheckArg {
    my $rargs = (shift @_);
    my $arg;
    foreach ($rargs) {
    if ($_ =~ /^-h/) {
        PrintHelp();
        exit 0;
    }
    elsif ($_ =~ /^-c/) {
        Configure();
    }
    else { #must be an undefined option
        die"Undefined Option: Please run the program with the -h flag 
+for help\n";
    }
    }

}
sub Configure {
    my ($rt, $balance, $transaction);
    print "Welcome, please follow the instructions to configure this p
+rogram (this will overwrite your current configuration)\n";
   
    print "Reoccuring transaction file (rt.log by default)?";
    chomp ($rt = <STDIN>);
    $rt        = "rt.log" unless ($rt); #assumes default if user gave 
+no input.
    open  (WRT, ">$rt");
    close (WRT);
    
    print "Balance file (balance.log by default)";
    chomp ($balance = <STDIN>);
    $balance = "balance.log" unless ($balance); #assumes default if us
+er gave no input.
    open  (WBALANCE, ">$balance") || die "could not open balance.log $
+!";
    print WBALANCE "0\n";
    close (WBALANCE) || die "could not close balance.log $!";
    
    print "Transaction file (transaction.log by default)";
    chomp ($transaction = <STDIN>);
    $transaction = "transaction.log" unless ($transaction); #assumes d
+efault if user gave no input.
    open  (WTRANSACTION, ">$transaction") || die "could not open trans
+action.log $!";
    print WTRANSACTION "start\n";
    close (WTRANSACTION) || die "could not close transaction.log $!";

    #write everything into configuration file
    open  (WCONF, ">simplemoney.conf") || die "could not open simplemo
+eny.conf $!";
    print WCONF "$rt\n$balance\n$transaction";
    close (WCONF) || die "could not close simplemoney.conf $!";
}

sub CalcBalance {
    my ($balance, @log);
    my  $location = shift(@_);
    open (RBALANCE, $location) || die "Can't open $location $!";
    @log = <RBALANCE>;
    close (RBALANCE) || die "Can't close $location $!";
    $balance = $log[-1];
    if ($_[0]) {     # we check to see if there is another 
                                  # argument (the amount to change) an
+d 
                                  # it is not 0.
    my $toChange = shift(@_);     # we only declare this if another 
                                  # argument exists to make the test 
                                  # above work. 
    $balance += $toChange;
    open (WBALANCE, ">>$location") || die "Can't open $location $!";
    print WBALANCE "$balance\n";
    close (WBALANCE) || die "Can't close $location $!";
    }
    return $balance;
}

sub AddTransaction {
    my ($location) = shift(@_); 
    my ($description) = shift(@_) || "This description is intentionaly
+ left blank";
    open (WTRANSACTION, ">>$location") || die "Can't open $location $!
+";
    print WTRANSACTION "$description\n";
    close (WTRANSACTION) || die "Can't close $location $!";

}
Replies are listed 'Best First'.
Re: SimpleMoney
by Fingo (Monk) on Mar 05, 2001 at 09:02 UTC
    I have been told that it does not work under windows. Can any windows using Monks please tell me what errors they get if they have any. I sadly don't have the means to test under windows :(
    Thus Spake the Master Programmer: 
    "After three days without programming, life becomes meaningless." 
        ---Tao of Programing
    
    UPDATE: The problem has now been resolved, they had recived a corrupt version of the code.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://62136]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-29 01:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found