diff --git a/README.org b/README.org index 2aa6e9a..187d29b 100644 --- a/README.org +++ b/README.org @@ -50,6 +50,11 @@ *** ValueObjects +*** List my reports + +#+begin_example bash +curl 'https://drunomics.myjetbrains.com/youtrack/api/reports?$top=-1&fields=id,name,own,owner(login,name)&query=owner:+%7Bme%7D' -H "Authorization: Bearer $YTOKEN" -H 'Cache-Control: no-cache' | jq '.[] | select( .own == true )' +#+end_example ** Motivation - practice php diff --git a/app/src/Commands/RprtCommand.php b/app/src/Commands/RprtCommand.php index cb281f6..5fda1b6 100644 --- a/app/src/Commands/RprtCommand.php +++ b/app/src/Commands/RprtCommand.php @@ -75,7 +75,7 @@ class RprtCommand extends Command 'youtrack', 'y', InputOption::VALUE_NONE, - 'Use youtrack api to get a report. If this option is used --file does not have any effect.' + 'Use youtrack api to get a report. If this option is used --file does not have any effect..' ); $this->addOption( 'pdf', @@ -102,7 +102,7 @@ class RprtCommand extends Command 'Send pdf export via email to recipient.' ); $this->addOption( - 'send-to', + 'recipients', 'r', InputOption::VALUE_REQUIRED, 'Comma separated list of recipients that should get the exported pdf.' @@ -121,6 +121,19 @@ class RprtCommand extends Command 'Additional custom work untracked in format: name1=time1;name2=time2... Project to assign work items to has to be configured in app config. Leave empty for interactive output.', FALSE ); + $this->addOption( + 'list-reports', + 'l', + InputOption::VALUE_NONE, + 'List my reports' + ); + $this->addOption( + 'report', + 'g', + InputOption::VALUE_OPTIONAL, + 'Show time tracked for report.', + FALSE + ); } protected function execute(InputInterface $input, OutputInterface $output) : int @@ -129,15 +142,35 @@ class RprtCommand extends Command $test = $this->youtrack->testYoutrackapi(); $output->writeln($test); } + if ($input->getOption('list-reports')) { + $list = $this->youtrack->listReports(); + $output->writeln(var_export($list, TRUE)); + } + if ($input->hasParameterOption('--report') || $input->hasParameterOption('-g')) { + if ($report = $input->getOption('report')) { + $this->youtrack->setReportId($report); + } + else { + $reports = $this->youtrack->listReports(); + $count = 1; + foreach ($reports as $id => $name) { + $output->writeln("[{$count}] {$name} ({$id})"); + $count++; + } + $report = readline('Select id of the report: '); + // Asume people are literate. + $this->youtrack->setReportId($report); + } + } if ($youtrack = $input->getOption('youtrack')) { $report_id = $this->youtrack->getReportId(); $file = $this->youtrack->downloadReport($report_id); } - if ($input->hasParameterOption('expenses') || $input->hasParameterOption('-e')) { - $expenses = $this->getExpenses($input->getOption('expenses')); + if ($input->hasParameterOption('--expenses') || $input->hasParameterOption('-e')) { + $expenses = $this->getCustomWorkOrExpenses($input->getOption('expenses'), self::TYPE_EXPENSE); } - if ($input->hasParameterOption('custom') || $input->hasParameterOption('-c')) { - $custom = $this->getCustomWork($input->getOption('custom')); + if ($input->hasParameterOption('--custom') || $input->hasParameterOption('-c')) { + $custom = $this->getCustomWorkOrExpenses($input->getOption('custom'), self::TYPE_WORK); } if ($youtrack || $file = $input->getOption('file')) { // Youtrack can also provide a file name. diff --git a/app/src/Utils/CsvReport/ReportCsv.php b/app/src/Utils/CsvReport/ReportCsv.php index 35d2068..519f4a1 100644 --- a/app/src/Utils/CsvReport/ReportCsv.php +++ b/app/src/Utils/CsvReport/ReportCsv.php @@ -105,7 +105,7 @@ class ReportCsv implements ReportCsvInterface $hours = $config['time_format'] == 'm' ? $time/60 : $time; $price = $hours * (float) $config['price']; $row = [ - $config['label'] ?? $project, + $config['name'] ?? $project, number_format($hours, 2, ',', '.'), number_format($config['price'], 2, ',', '.'), number_format($price, 2, ',', '.'), diff --git a/app/src/Utils/PdfExport/PdfExportService.php b/app/src/Utils/PdfExport/PdfExportService.php index a9ff713..6ef2185 100644 --- a/app/src/Utils/PdfExport/PdfExportService.php +++ b/app/src/Utils/PdfExport/PdfExportService.php @@ -75,7 +75,7 @@ class PdfExportService implements PdfExportInterface { } if ($colspan) { $colspan += 1; - $cells[] = "