my $tkdata = load_timesheet_file($args->{'<file>'});
#print Dumper($tkdata);
-# connect to wrms
-my $wrms = WRMS->new({
+my $wrmsargs = {
username => $config{default}{username},
password => $config{default}{password},
site => $config{default}{site},
login => 1,
-}) if $args->{'-c'};
+};
+
+$config{default}{system} ||= 'WRMS';
+my $module = $config{default}{system};
+
+eval "use $module";
+if ( $@ ) { print "Something went wrong: $@"; die "GAH!"; }
+my $wrms = eval { $module->new($wrmsargs) };
+if ( $@ ) { print "Something went wrong: $@"; die "GAH!"; }
# map of textual representations for WRs
my $wrmap = $config{'wrmap'};
$entry->{time} = int($entry->{time} * 100 + .5) / 100;
# add the time to wrms
- $wrms->add_time(
+ my $win = $wrms->add_time(
$entry->{wr},
$date,
$entry->{comment},
);
# comment it out in the file
- @lines[$entry->{linenumber} - 1] = '# ' . @lines[$entry->{linenumber} - 1];
+ if ($win == 1) {
+ @lines[$entry->{linenumber} - 1] = '# ' . @lines[$entry->{linenumber} - 1];
+ } else {
+ warn "Communicating timesheet data failed for the following entry. You will have to add it later. Not commenting out\n";
+ warn Dumper($entry);
+ }
$file_needs_write = 1;
}