#!/usr/bin/perl -w

#require 'pl.pm';
require 'vb.pm';

@ARGV == 2 or die "Please specify a begin date and an end date\n";
my $begin=shift;
my $end=shift;
my $max=9;

sub delim { '\\\\' ;}
sub fs { 'C:' }

#sub Src { fs().delim().'QUICKENW'.delim(); }
#sub Dest { fs().delim().'COB'.delim(); }
sub Src { ''; }
sub Dest { ''; }
sub Disamb { 'z'; }

sub OpenEntity { my $name=shift; f().op().Src().$name.'.qdb'.tab(5).rt(); }

sub EntityList {
  use IO::File;
  my $fh=IO::File->new();
  $fh->open( 'foo.qdb' );
  my @files; local ($_, @_); while (<$fh>) { @_=split; push @files, $_[0]; }
  @files;
}

sub ExportAccount { my $entity=shift; $account=shift; my $type=shift;
  my $begin=shift; my $end=shift;
    
  f().ex().Name($entity, $account, $type).tab().(down()x$account).tab().$begin.
  tab().$end.Type($type).tab(2).rt(); }

sub Name { my $entity=shift; my $account=shift; my $type=shift;
  my %trans=(
    'transactions'=>'t',
    'accounts'=>'a',
    'categories'=>'c',
    'memorized' => 'm',
  );
  Dest().$entity.'.'.Disamb().$trans{$type}.$account;
}
  
sub Type { my $type=shift;
  $type eq 'transactions' and return  tab(4);
  $type eq 'accounts' and return  tab().' '.tab().' '.tab(2);
  $type eq 'categories' and return  tab().' '.tab(2).' '.tab();
  $type eq 'memorized' and return  tab().' '.tab(3).' ';
}

for my $entity ( EntityList ) {
  print OpenEntity($entity);
  for my $account (  0..$max ) {
    for my $type ( qw(transactions accounts categories memorized) ){
      print ExportAccount( $entity, $account, $type, $begin, $end )
    }
  }
}

