Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Statistics v2 #210

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions app/Actions/ExportReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace App\Actions;

use App\Enums\ReportType;
use App\Exports\Report;
use App\Services\Reports\BeneficiariesV2;
use Excel;
use Filament\Infolists\Components\Actions\Action;

class ExportReport extends Action
{
protected ReportType | null $reportType = null;

protected string | null $startDate = null;

protected string | null $endDate = null;

protected bool | null $showMissingValues = false;

protected function setUp(): void
{
parent::setUp();
$this->label(__('report.actions.export'));
$this->icon('heroicon-o-arrow-down-tray');
$this->outlined();
$this->action(fn () => $this->generateExport());
}

public function setReportType(ReportType | string | null $reportType): self
{
$this->reportType = \is_string($reportType) ? ReportType::tryFrom($reportType) : $reportType;

return $this;
}

public function setStartDate(?string $startDate): self
{
$this->startDate = $startDate;

return $this;
}

public function setEndDate(?string $endDate): self
{
$this->endDate = $endDate;

return $this;
}

public function setShowMissingValues(?bool $showMissingValues): self
{
$this->showMissingValues = $showMissingValues;

return $this;
}

public function generateExport(): void
{
$service = new BeneficiariesV2();
$service->setReportType($this->reportType)
->setStartDate($this->startDate)
->setEndDate($this->endDate)
->setShowMissingValue($this->showMissingValues)
->composeReport();

Excel::download(new Report($service), 'test.xlsx');
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasHorizontalSubHeaderAgeInterval.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\AgeInterval;

trait HasHorizontalSubHeaderAgeInterval
{
public function getHorizontalSubHeader(): ?array
{
$header = AgeInterval::options();

if (! $this->showMissingValues) {
return $header;
}

$header['unknown'] = __('report.headers.missing_values');

return $header;
}

public function getHorizontalSubHeaderKey(): ?string
{
return 'age_group';
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasHorizontalSubHeaderEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\ResidenceEnvironment;

trait HasHorizontalSubHeaderEnvironment
{
public function getHorizontalSubHeader(): ?array
{
$header = ResidenceEnvironment::options();

if (! $this->showMissingValues) {
return $header;
}

$header[null] = __('report.headers.missing_values');

return $header;
}

public function getHorizontalSubHeaderKey(): ?string
{
return 'environment';
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasVerticalHeaderCivilStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\CivilStatus;

trait HasVerticalHeaderCivilStatus
{
public function getVerticalHeader(): array
{
$header = CivilStatus::options();

if (! $this->showMissingValues) {
return $header;
}

$header[null] = __('report.headers.missing_values');

return $header;
}

public function getVerticalHeaderKey(): string
{
return 'civil_status';
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasVerticalHeaderEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\ResidenceEnvironment;

trait HasVerticalHeaderEnvironment
{
public function getVerticalHeader(): array
{
$header = ResidenceEnvironment::options();

if (! $this->showMissingValues) {
return $header;
}

$header[null] = __('report.headers.missing_values');

return $header;
}

public function getVerticalHeaderKey(): string
{
return 'environment';
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasVerticalHeaderGender.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\Gender;

trait HasVerticalHeaderGender
{
public function getVerticalHeader(): array
{
$header = Gender::options();

if (! $this->showMissingValues) {
return $header;
}

$header[null] = __('report.headers.missing_values');

return $header;
}

public function getVerticalHeaderKey(): string
{
return 'gender';
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasVerticalHeaderHomeOwnership.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\HomeOwnership;

trait HasVerticalHeaderHomeOwnership
{
public function getVerticalHeader(): array
{
$header = HomeOwnership::options();

if (! $this->showMissingValues) {
return $header;
}

$header[null] = __('report.headers.missing_values');

return $header;
}

public function getVerticalHeaderKey(): string
{
return 'homeownership';
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasVerticalHeaderIncome.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\Income;

trait HasVerticalHeaderIncome
{
public function getVerticalHeader(): array
{
$header = Income::options();

if (! $this->showMissingValues) {
return $header;
}

$header[null] = __('report.headers.missing_values');

return $header;
}

public function getVerticalHeaderKey(): string
{
return 'income';
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasVerticalHeaderOccupation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\Occupation;

trait HasVerticalHeaderOccupation
{
public function getVerticalHeader(): array
{
$header = Occupation::options();

if (! $this->showMissingValues) {
return $header;
}

$header[null] = __('report.headers.missing_values');

return $header;
}

public function getVerticalHeaderKey(): string
{
return 'occupation';
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasVerticalHeaderRelationship.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\AggressorRelationship;

trait HasVerticalHeaderRelationship
{
public function getVerticalHeader(): array
{
$header = AggressorRelationship::options();

if (! $this->showMissingValues) {
return $header;
}

$header[null] = __('report.headers.missing_values');

return $header;
}

public function getVerticalHeaderKey(): string
{
return 'relationship';
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasVerticalHeaderStudies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\Studies;

trait HasVerticalHeaderStudies
{
public function getVerticalHeader(): array
{
$header = Studies::options();

if (! $this->showMissingValues) {
return $header;
}

$header[null] = __('report.headers.missing_values');

return $header;
}

public function getVerticalHeaderKey(): string
{
return 'studies';
}
}
28 changes: 28 additions & 0 deletions app/Concerns/Reports/HasVerticalHeaderViolence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Concerns\Reports;

use App\Enums\Violence;

trait HasVerticalHeaderViolence
{
public function getVerticalHeader(): array
{
$header = Violence::options();

if (! $this->showMissingValues) {
return $header;
}

$header[null] = __('report.headers.missing_values');

return $header;
}

public function getVerticalHeaderKey(): string
{
return 'violence_primary_type';
}
}
Loading