#!/usr/bin/perl

use strict;
use warnings;

## is used from web
use lib qw(/home/ernad/ernad/perl /home/ernad/usr/share/perl /home/ernad/lib/perl);

use Carp qw(confess);
use Data::Dumper;
use Getopt::Std;

use Ernad::Args;
use Ernad::Erimp;
use Ernad::Indat::Add;
use Ernad::Indat::Vypot;

my %o;
&Getopt::Std::getopts('t', \%o);
our $do_test = $o{'t'} // 0;

our ($in_file, $impna, $repcode, $issuedate, $e);
&Ernad::Args::parse();

## invoque on a file to do the whole issue
if($in_file) {
  #  $e=Ernad::Erimp->new({'impna'=> $impna, 'verbose'=>3});
  #  my $i=Ernad::Indat::Add->new();
  #  $i->clear();
  #
  #  my $return=$i->file($in_file);
  #  if($return) {
  #    $i->save();
  #  }
  ## impna is set by the parse
  if(not $impna) {
    print "I see no impna.\n";
    exit;
  }
  ### argument from Args
  #$i->add();
  &do_full();
  exit;
}
if(not $ARGV[0]) {
  print "I need an argument, a file is best.\n";
  exit;
}
## for test calls on an issue without having to copy and paste a file name
if(not $impna) {
  print "I don't have a impna.\n";
  exit;
}
if(not $repcode) {
  print "I don't have a report.\n";
  exit;
}
if(not $issuedate) {
  print "I don't have an issuedate.\n";
  exit;
}
&do_full();

sub do_full {
  $e=Ernad::Erimp->new({'impna'=> $impna, 'verbose'=>3});
  my $i=Ernad::Indat::Vypot->new();
  ## argument from Args
  $i->add();
  $i->postpare($issuedate);
}
