package MpmasActivityInfo;

use strict;
use warnings;
use Exporter;
use Storable qw(dclone);
use Data::Dumper;
use MpmasInputfile;
use MpmasInputBlock;
our @ISA = qw(MpmasInputfile);

sub filename {
	return "ActivityInfo";
}
sub extension {
	return ".txt";
}
sub leftmargin {
	return "";
}

sub prepare_special {
	my $self = shift;

	my $NumRow = $self->milpinfo("NumRow");
	my $NumCol = $self->milpinfo("NumCol");
	my $numMilps = scalar @{ $self->milplist };
	my $ainfo;
	
	if ($NumCol > $self->config_entry("LIMIT_FOR_IMMEDIATE") / $numMilps or $NumRow > $self->config_entry("LIMIT_FOR_IMMEDIATE") / $numMilps) {
		$ainfo = MpmasInputBlockImmediate->new(0,100,1);
	}
	else {
		$ainfo = MpmasInputBlock->new(0,100);
	}
	
	my @SortedActivityGroupings = sort{$a cmp $b} keys %{$self->config_entry("Groupings")->{activity}}; 
	 $ainfo->add_row("Column","Code","Name","OutfileCol", "MpmasqlType", $self->config_entry("MULTIPERIOD") ? "Unit" : "Account", $self->config_entry("MULTIPERIOD") ? "MPeriod" : (), @SortedActivityGroupings);
	for my $i (@{$self->sorted_activity_objects}) {

		my $col = $i->lp_column + 15;
		my @temp = ($i->lp_column,$i->id,$i->attr("name"),"$col",  $i->attr("type") , $self->config_entry("MULTIPERIOD") ?  $i->attr("unit")   : ($i->attr_defined("account") ? $i->attr("account") : $i->get_default_value("account"))  );	
		if ($self->config_entry("MULTIPERIOD")) {
			push @temp, $i->attr("mperiod");
		}
		for my $j (@SortedActivityGroupings) {				
			my $group = -1;
			$group = $i->get_group($j) if (defined $i->get_group($j));
			push @temp, $group;
		}
		$ainfo->add_row(@temp);
	}
	$self->add_block($ainfo);

}
1;
