Small fixes in Report command and csv parsing.

master
Lio Novelli 2022-05-12 02:48:53 +02:00
parent c8e38922c0
commit 78c57e65c8
2 changed files with 9 additions and 4 deletions

View File

@ -49,12 +49,12 @@ class ReportCommand extends Command {
} }
protected function execute(InputInterface $input, OutputInterface $output) :int { protected function execute(InputInterface $input, OutputInterface $output) :int {
$reports = $this->trackingService->listReports();
// Could just parse a csv file or actually get workItems from youtrack ... // Could just parse a csv file or actually get workItems from youtrack ...
if ($input->hasParameterOption('--report') || $input->hasParameterOption('-r')) { if ($input->hasParameterOption('--report') || $input->hasParameterOption('-r')) {
if ($report = $input->getOption('report')) { if ($report = $input->getOption('report')) {
$this->trackingService->setReportId($report); $this->trackingService->setReportId($report);
} else { } else {
$reports = $this->trackingService->listReports();
$count = 1; $count = 1;
foreach ($reports as $id => $name) { foreach ($reports as $id => $name) {
$output->writeln("[{$count}] {$name} ({$id})"); $output->writeln("[{$count}] {$name} ({$id})");
@ -73,8 +73,10 @@ class ReportCommand extends Command {
// Currently we only support csv download. // Currently we only support csv download.
$report_id = $this->trackingService->getReportId(); $report_id = $this->trackingService->getReportId();
$report_name = $reports[$report_id];
$file = $this->trackingService->downloadReport($report_id); $file = $this->trackingService->downloadReport($report_id);
// var_dump($file); // var_dump($file);
$output->writeln("report: <info>{$report_name}</info>");
$data = $this->csv->generateReportTable($file); $data = $this->csv->generateReportTable($file);
$table = $this->buildTable($output, $data); $table = $this->buildTable($output, $data);
$table->render(); $table->render();

View File

@ -122,6 +122,9 @@ class ReportCsv implements ReportCsvInterface
$rows[] = ['Gesamt netto', number_format($totalHours, 2, ',', '.'), ' ', number_format($totalPrice, 2, ',', '.')]; $rows[] = ['Gesamt netto', number_format($totalHours, 2, ',', '.'), ' ', number_format($totalPrice, 2, ',', '.')];
$add_separator = FALSE; $add_separator = FALSE;
} }
if (empty($data)) {
$add_separator = TRUE;
}
foreach ($data as $invoice_element) { foreach ($data as $invoice_element) {
if ($invoice_element instanceof ExpensesInterface) { if ($invoice_element instanceof ExpensesInterface) {
if (!isset($added_expenses)) { if (!isset($added_expenses)) {
@ -176,8 +179,6 @@ class ReportCsv implements ReportCsvInterface
foreach ($data as $line) { foreach ($data as $line) {
$project = explode('-', $line['id'])[0]; $project = explode('-', $line['id'])[0];
$previous_project = explode('-', $previous)[0]; $previous_project = explode('-', $previous)[0];
$project_time += (float) $line['time'];
$table[] = array_values($line);
if ($project !== $previous_project) { if ($project !== $previous_project) {
// When project changes, add a sum of time for that project. // When project changes, add a sum of time for that project.
$table[] = null; $table[] = null;
@ -187,7 +188,9 @@ class ReportCsv implements ReportCsvInterface
$project_time = 0; $project_time = 0;
$all_projects[] = $project; $all_projects[] = $project;
} }
$project_time += (float) $line['time'];
$previous = $line['id']; $previous = $line['id'];
$table[] = array_values($line);
} }
// Add sum for the last project. // Add sum for the last project.
$table[] = null; $table[] = null;
@ -217,7 +220,7 @@ class ReportCsv implements ReportCsvInterface
// @TODO validate line // @TODO validate line
$output[] = [ $output[] = [
'id' => $line[1], 'id' => $line[1],
'name' => substr($line[2], 0, 80), 'name' => substr($line[2], 0, 60),
'time' => $line[4], 'time' => $line[4],
'estimation' => $line[3], 'estimation' => $line[3],
]; ];