#!/usr/bin/perl

# wealth 0.2
# by Gav Ford
# revford@blueyonder.co.uk
# http://revford.pwp.blueyonder.co.uk
# 2008 early, updated 2008-05-01
# Convert a wealth DC to cash value
# Convert a cash value to a wealth DC


use Term::ANSIColor qw(:constants);
use FindBin '$RealBin';


require "$RealBin/lib-wb-commaformatted.pl";


$from = $ARGV[0];
$value = $ARGV[1];

@dollars = (
  0, 1, 5, 12, 20, 30, 40, 55, 70, 90, 
  120, 150, 200, 275, 350, 500, 650, 900, 1200, 1500, 
  2000, 2750, 3500, 5000, 6500, 9000, 12000, 15000, 20000, 27500, 
  35000, 50000, 65000, 90000, 120000, 150000, 200000, 275000, 350000, 500000, 
  650000, 900000, 1200000, 1500000, 2000000, 2750000, 3500000, 5000000, 6500000, 9000000,
  12000000, 15000000, 20000000, 27500000, 35000000, 50000000, 65000000, 90000000, 120000000, 150000000, 
  200000000, 275000000, 350000000, 500000000, 650000000, 900000000, 1200000000, 1500000000, 2000000000, 
    2750000000, 
  3500000000, 5000000000, 6500000000, 9000000000, 12000000000, 15000000000, 20000000000, 27500000000, 
    35000000000, 50000000000, 65000000000, 90000000000);

if ($from eq "dc")
  {
  if ($value > 81) {print RED, "Error:", RESET,"  Value too great, DC 81 or less\n"}
  else {print GREEN, "\$ ", RESET, CommaFormatted($dollars[$value])."\n"}
  }
elsif ($from eq "cash")
  {
  $value =~ s/[^0-9]//g;    # strip everything but the numbers out
  for ($i = 81; $i >= 0; $i--)
    {
    if ($value > $dollars[$i]) { print GREEN, "DC ", RESET, $i."\n"; exit }
    }
  }
else {print RED, "Error:", RESET, "  Syntax, usage is 'wealth dc 5 or wealth cash 1200'\n"}

