App-CPRReporter
view release on metacpan or search on metacpan
lib/App/CPRReporter.pm view on Meta::CPAN
# Fill in certificate
$self->{_employees}->{$fullname}->{cert} = $date;
} else {
# Oops: user not found in personel database
#carp "Warning: employee '$fullname' not found in employee database"
if ( ref($fullname) ) {
carp "Fullname is reference, this should not be the case!";
}
push( @{ $self->{_not_in_hr}->{cert} }, $fullname );
}
}
}
say "$certificate_count certificates found";
my $training_count = 0;
my $training = $self->{_training};
foreach my $traininguser ( @{$training} ) {
lib/App/CPRReporter.pm view on Meta::CPAN
$self->{_employees}->{$fullname}->{cert} = 'training';
$training_count++;
} else {
#carp "Warning: employee '$fullname' is both in training and has a certificate from $self->{_employees}->{$fullname}->{cert}";
}
} else {
# Oops: user not found in personel database
#carp "Warning: employee '$fullname' not found in employee database";
push( @{ $self->{_not_in_hr}->{training} }, $fullname );
$training_count++;
}
}
say "$training_count people are in training";
# Check people who are in training and that have a certificate
# now run the stats, for every dienst separately report
my $stats;
foreach my $employee ( keys %{$self->{_employees}} ) {
my $dienst = $self->{_employees}->{$employee}->{dienst};
my $cert = $self->{_employees}->{$employee}->{cert} || 'none';
my $course = $self->{_employees}->{$employee}->{course} || 'none';
$stats->{employee_count} += 1;
if ( $cert eq 'none' ) {
$stats->{$dienst}->{'not_started'}->{count} += 1;
push( @{ $stats->{$dienst}->{'not_started'}->{list} }, $employee );
} elsif ( $cert eq 'training' ) {
$stats->{$dienst}->{'training'}->{count} += 1;
push( @{ $stats->{$dienst}->{'training'}->{list} }, $employee );
} else {
$stats->{$dienst}->{'certified'}->{count} += 1;
push( @{ $stats->{$dienst}->{'certified'}->{list} }, $employee );
}
if ( !( $course eq 'none' ) ) {
$stats->{$dienst}->{'course'}->{count} += 1;
lib/App/CPRReporter.pm view on Meta::CPAN
foreach my $dienst ( sort keys %{$stats} ) {
next if ( $dienst eq 'employee_count' );
if ( !defined $stats->{$dienst}->{certified}->{count} ) {
$stats->{$dienst}->{certified}->{count} = 0;
}
if ( !defined $stats->{$dienst}->{training}->{count} ) {
$stats->{$dienst}->{training}->{count} = 0;
}
if ( !defined $stats->{$dienst}->{not_started}->{count} ) {
$stats->{$dienst}->{not_started}->{count} = 0;
}
if ( !defined $stats->{$dienst}->{course}->{count} ) {
$stats->{$dienst}->{course}->{count} = 0;
}
say "$dienst;"
. $stats->{$dienst}->{certified}->{count} . ";"
. $stats->{$dienst}->{training}->{count} . ";"
. $stats->{$dienst}->{not_started}->{count} . ";"
. $stats->{$dienst}->{course}->{count};
}
if ( defined $self->{_not_in_hr}->{cert} ) {
say "";
say "Not found in the HR database while parsing certificates: "
. scalar( @{ $self->{_not_in_hr}->{cert} } );
foreach ( @{ $self->{_not_in_hr}->{cert} } ) {
say;
}
}
if ( defined $self->{_not_in_hr}->{training} ) {
say "Not found in the HR database while parsing in training: "
. scalar( @{ $self->{_not_in_hr}->{training} } );
foreach ( @{ $self->{_not_in_hr}->{training} } ) {
say;
}
}
if ( defined $self->{_not_in_hr}->{theory} ) {
say "Not found in the HR database while parsing theory: "
. scalar( @{ $self->{_not_in_hr}->{theory} } );
foreach ( @{ $self->{_not_in_hr}->{theory} } ) {
say;
}
}
#say "";
#say "Resolved names";
#print Dumper($self->{_resolve});
}
# Parse the employee database to extract the names and the group they are in
lib/App/CPRReporter.pm view on Meta::CPAN
# Extract the formatted value from the cell, we can only call this function once we know the cell has a value
$date = $sheet->{Cells}[$row][7]->value();
# If the employee already exists: OK, go ahead and insert training
if ( defined $self->{_employees}->{$name} ) {
$self->{_employees}->{$name}->{course} = $date;
} else {
#carp "Oops: employee '$name' not found in employee database while parsing the theoretical training list";
push( @{ $self->{_not_in_hr}->{theory} }, $name );
}
}
}
# Try to resolve a name in case it is not found in the personel database
sub _resolve_name {
my ( $self, $fname, $gname ) = @_;
t/01-basic.t view on Meta::CPAN
throws_ok { $reporter = App::CPRReporter->new() } qr/Attribute .+ is required/, "Checking missing parameters";
throws_ok { $reporter = App::CPRReporter->new(employees => 't/stim/missing_file.xlsx', certificates => 't/stim/missing_file.xml', course => 't/stim/missing_file.xlsx') } qr/File does not exist.+/, "Checking missing xml file";
# Check we get the expected carps when we create the app on the stimulus test data
#warnings_like { $reporter = App::CPRReporter->new(employees => 't/stim/employees.xlsx', certificates => 't/stim/certificates.xml', course => 't/stim/course.xlsx') }
# { carped => qr/Oops: employee 'MAJOR LAZER' not found/},
# "On test data we should carp some warnings";
$reporter = App::CPRReporter->new(employees => 't/stim/employees.xlsx', certificates => 't/stim/certificates.xml', course => 't/stim/course.xlsx');
is $reporter->{_not_in_hr}->{theory}->[0], 'MAJOR LAZER', "Found course of person not in employee database";
ok $reporter, 'object created';
ok $reporter->isa('App::CPRReporter'), 'and it is the right class';
# Check that only for users who followed a course the the course field exists
ok exists($reporter->{_employees}->{'CESAR ZJUUL'}->{course}), "Course field exists for user with data";
ok !exists($reporter->{_employees}->{'USER ONE'}->{course}), "Course field does not exist for users wihtout data";
$reporter->run();
( run in 1.059 second using v1.01-cache-2.11-cpan-cc502c75498 )