Standardize input options, some verbosity, separator constants.

master
Lio Novelli 2022-05-15 11:55:50 +02:00
parent 7dfe2df78b
commit f498315b53
7 changed files with 56 additions and 18 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
/resources/data
/scratch
.phpcs-cache
*~undo-tree~

View File

@ -103,7 +103,7 @@ class InvoiceCommand extends Command
);
$this->addOption(
'recipients',
'r',
't',
InputOption::VALUE_REQUIRED,
'Comma separated list of recipients that should get the exported pdf.'
);
@ -129,7 +129,7 @@ class InvoiceCommand extends Command
);
$this->addOption(
'report',
't',
'r',
InputOption::VALUE_OPTIONAL,
'Show time tracked for report.',
FALSE
@ -164,6 +164,10 @@ class InvoiceCommand extends Command
}
if ($youtrack = $input->getOption('youtrack')) {
$report_id = $this->youtrack->getReportId();
$cache_clear_status = $this->youtrack->clearReportCache($report_id);
if ($output->isVerbose()) {
$output->writeln("Report cache cleared, status: {$cache_clear_status}");
}
$file = $this->youtrack->downloadReport($report_id);
}
if ($input->hasParameterOption('--expenses') || $input->hasParameterOption('-e')) {
@ -174,7 +178,9 @@ class InvoiceCommand extends Command
}
if ($youtrack || $file = $input->getOption('file')) {
// Youtrack can also provide a file name.
// var_dump($file);
if ($output->isVerbose()) {
$output->writeln("Csv file downloaded to: <info>{$file}</info>");
}
$data = $this->csv->getInvoiceData($file);
if (!empty($expenses)) {
$data = array_merge($data, $expenses);

View File

@ -73,12 +73,25 @@ class ReportCommand extends Command {
elseif ($report = $this->config->get('tracking_service.youtrack.report.default')) {
$this->trackingService->setReportId($report);
}
elseif ($timeRange = $input->getParameterOption('time-range')) {
// @TODO: Implement time range option:
// - Request workTime items from tracking service
// - Filter them, join by issue, project ...
$output->writeln('<error>This option is not supported yet.</error>');
return Command::FAILURE;
}
// Currently we only support csv download.
$report_id = $this->trackingService->getReportId();
$report_name = $reports[$report_id];
$this->trackingService->clearReportCache($report_id);
// Code duplication.
$cache_clear_status = $this->timeTrackingService->clearReportCache($report_id);
if ($output->isVerbose()) {
$output->writeln("Report cache cleared, status: {$cache_clear_status}");
}
$file = $this->trackingService->downloadReport($report_id);
// var_dump($file);
if ($output->isVerbose()) {
$output->writeln("Csv file downloaded to: <info>{$file}</info>");
}
$output->writeln("report: <info>{$report_name}</info>");
$data = $this->csv->generateReportTable($file);
$table = $this->buildTable($output, $data);

View File

@ -128,8 +128,8 @@ class ReportCsv implements ReportCsvInterface
foreach ($data as $invoice_element) {
if ($invoice_element instanceof ExpensesInterface) {
if (!isset($added_expenses)) {
// @TODO - separator 0: Make next line bold and centered.
$rows[] = 0;
// Separator 0: Make next line bold and centered.
$rows[] = ReportCsvInterface::SEPARATOR_HARD;
$rows[] = [
null,
null,
@ -137,7 +137,7 @@ class ReportCsv implements ReportCsvInterface
'EUR',
];
// Don't make next line bold. See RprtCli\PdfExport\PdfExportService::parsedDataToHtml.
$rows[] = FALSE;
$rows[] = ReportCsvInterface::SEPARATOR_SOFT;
$added_expenses = TRUE;
}
$add_separator = TRUE;
@ -151,7 +151,7 @@ class ReportCsv implements ReportCsvInterface
}
}
if ($add_separator) {
$rows[] = null;
$rows[] = ReportCsvInterface::SEPARATOR_MEDIUM;
}
$rows[] = [null, null, 'Gessamt brutto', number_format($totalPrice, 2, ',', '.')];
return $rows;
@ -184,9 +184,9 @@ class ReportCsv implements ReportCsvInterface
$previous_project = explode('-', $previous)[0];
if ($project !== $previous_project) {
// When project changes, add a sum of time for that project.
$table[] = null;
$table[] = ReportCsvInterface::SEPARATOR_MEDIUM;
$table[] = [null, $previous_project, null, $project_time/60];
$table[] = null;
$table[] = ReportCsvInterface::SEPARATOR_MEDIUM;
$time_sum += (float) $project_time;
$project_time = 0;
$all_projects[] = $project;
@ -196,12 +196,12 @@ class ReportCsv implements ReportCsvInterface
$table[] = array_values($line);
}
// Add sum for the last project.
$table[] = null;
$table[] = ReportCsvInterface::SEPARATOR_MEDIUM;
$table[] = [null, $project, null, $project_time / 60];
$time_sum += (float) $project_time;
$all_projects[] = $project;
// Add a sum of time for whole day.
$table[] = null;
$table[] = ReportCsvInterface::SEPARATOR_MEDIUM;
$table[] = [null, implode(', ', $all_projects), null, $time_sum/60];
return $table;
}

View File

@ -9,6 +9,22 @@ namespace RprtCli\Utils\CsvReport;
*/
interface ReportCsvInterface
{
/**
* Normal separator.
*/
const SEPARATOR_SOFT = FALSE;
/**
* Medium separator. Next line bold.
*/
const SEPARATOR_MEDIUM = NULL;
/**
* Next line should be bold and centered.
*/
const SEPARATOR_HARD = 0;
/**
* Returns array of hours per configured projects.
*

View File

@ -7,6 +7,7 @@ namespace RprtCli\Utils\PdfExport;
use Exception;
use RprtCli\Utils\Configuration\ConfigurationInterface;
use Mpdf\Output\Destination;
use RprtCli\Utils\CsvReport\ReportCsvInterface;
class PdfExportService implements PdfExportInterface {
@ -59,10 +60,10 @@ class PdfExportService implements PdfExportInterface {
$table .= '</tr></thead><tbody>';
foreach ($data as $row_index => $row) {
if (!$row) {
if ($row === NULL) {
if ($row === ReportCsvInterface::SEPARATOR_MEDIUM) {
$classes = 'bold';
}
elseif ($row === 0) {
elseif ($row === ReportCsvInterface::SEPARATOR_HARD) {
$classes = 'bold center';
}
continue;

View File

@ -104,7 +104,7 @@ class YoutrackService implements YoutrackInterface
]);
// Write csv response test into temporary file.
$csv_file = tempnam(sys_get_temp_dir(), 'yt_csv_');
$csv_file = tempnam(sys_get_temp_dir(), "rprt-cli/{$report_id}_");
file_put_contents($csv_file, $csv_response->getBody());
return $csv_file;
}
@ -113,7 +113,7 @@ class YoutrackService implements YoutrackInterface
if (isset($this->ytToken)) {
return $this->ytToken;
}
$yt_token = $this->config->get('tracking_service.youtrack.auth_token', FALSE); //
$yt_token = $this->config->get('tracking_service.youtrack.auth_token', FALSE);
if (!$yt_token) {
$yt_token = readline('Enter your youtrack authentication token: ');
}
@ -184,8 +184,9 @@ class YoutrackService implements YoutrackInterface
'headers' => $this->getHeaders(),
'json' => $post,
]);
$body = (string) $response->getBody()->getContents();
// $body = (string) $response->getBody()->getContents();
// var_dump($body);
return $response->getStatusCode();
}
}