Skip to content

Commit

Permalink
Merge pull request #119 from nochlezhka/report-date-fix
Browse files Browse the repository at this point in the history
fix: invalid report dates and unexpected report type
  • Loading branch information
a-menshchikov authored Oct 4, 2023
2 parents d7f7d26 + 4d46933 commit 9d76b1d
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions shared/homeless/src/Service/ReportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,21 @@ public function generate(
mixed $breadwinner,
): void {
if ($dateFrom) {
$date = new \DateTimeImmutable();
$date = $date->setTimestamp(strtotime($dateFrom));
$dateFrom = $date->format('Y-m-d');
$time = strtotime($dateFrom);
if ($time !== false) {
$date = new \DateTimeImmutable();
$date = $date->setTimestamp($time);
$dateFrom = $date->format('Y-m-d');
}
}

if ($dateTo) {
$date = new \DateTimeImmutable();
$date = $date->setTimestamp(strtotime($dateTo));
$dateTo = $date->format('Y-m-d');
$time = strtotime($dateTo);
if ($time !== false) {
$date = new \DateTimeImmutable();
$date = $date->setTimestamp($time);
$dateTo = $date->format('Y-m-d');
}
}

$result = match ($type) {
Expand All @@ -84,6 +90,7 @@ public function generate(
static::AVERAGE_COMPLETED_ITEMS => $this->averageCompletedItems($dateFrom, $dateTo, $userId),
static::AGGREGATED => $this->aggregated($createClientdateFrom, $createClientFromTo, $createServicedateFrom, $createServiceFromTo),
static::AGGREGATED2 => $this->aggregated2($createClientdateFrom, $createClientFromTo, $createServicedateFrom, $createServiceFromTo, $homelessReason, $disease, $breadwinner),
default => throw new \RuntimeException('Unexpected report type "'.$type.'"'),
};

$this->doc->setActiveSheetIndex(0);
Expand Down

0 comments on commit 9d76b1d

Please sign in to comment.