Skip to content

Commit

Permalink
Merge pull request #53 from andrewdwallo/development-3.x
Browse files Browse the repository at this point in the history
Refactor app and reporting
  • Loading branch information
andrewdwallo committed Jun 21, 2024
2 parents 943cd98 + 5756649 commit 339300e
Show file tree
Hide file tree
Showing 80 changed files with 3,067 additions and 1,727 deletions.
9 changes: 0 additions & 9 deletions app/Contracts/AccountHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

namespace App\Contracts;

use App\DTO\AccountBalanceDTO;
use App\DTO\AccountBalanceReportDTO;
use App\Enums\Accounting\AccountCategory;
use App\Models\Accounting\Account;
use App\ValueObjects\Money;

Expand All @@ -20,14 +17,8 @@ public function getStartingBalance(Account $account, string $startDate): ?Money;

public function getEndingBalance(Account $account, string $startDate, string $endDate): ?Money;

public function calculateNetMovementByCategory(AccountCategory $category, int $debitBalance, int $creditBalance): int;

public function getBalances(Account $account, string $startDate, string $endDate): array;

public function formatBalances(array $balances): AccountBalanceDTO;

public function buildAccountBalanceReport(string $startDate, string $endDate): AccountBalanceReportDTO;

public function getTotalBalanceForAllBankAccounts(string $startDate, string $endDate): Money;

public function getAccountCategoryOrder(): array;
Expand Down
21 changes: 21 additions & 0 deletions app/Contracts/ExportableReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Contracts;

use App\DTO\ReportCategoryDTO;

interface ExportableReport
{
public function getTitle(): string;

public function getHeaders(): array;

/**
* @return ReportCategoryDTO[]
*/
public function getCategories(): array;

public function getOverallTotals(): array;

public function getColumns(): array;
}
3 changes: 1 addition & 2 deletions app/DTO/AccountBalanceDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public function __construct(
public string $creditBalance,
public ?string $netMovement,
public ?string $endingBalance,
) {
}
) {}

public function toLivewire(): array
{
Expand Down
3 changes: 1 addition & 2 deletions app/DTO/AccountCategoryDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class AccountCategoryDTO implements Wireable
public function __construct(
public array $accounts,
public AccountBalanceDTO $summary,
) {
}
) {}

public function toLivewire(): array
{
Expand Down
3 changes: 1 addition & 2 deletions app/DTO/AccountDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public function __construct(
public string $accountName,
public string $accountCode,
public AccountBalanceDTO $balance,
) {
}
) {}

public function toLivewire(): array
{
Expand Down
17 changes: 17 additions & 0 deletions app/DTO/ReportCategoryDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\DTO;

class ReportCategoryDTO
{
/**
* @param string[] $header
* @param string[][] $data
* @param string[] $summary
*/
public function __construct(
public array $header,
public array $data,
public array $summary,
) {}
}
8 changes: 5 additions & 3 deletions app/DTO/AccountBalanceReportDTO.php → app/DTO/ReportDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@

use Livewire\Wireable;

class AccountBalanceReportDTO implements Wireable
class ReportDTO implements Wireable
{
public function __construct(
/**
* @var AccountCategoryDTO[]
*/
public array $categories,
public AccountBalanceDTO $overallTotal,
) {
}
public array $fields,
) {}

public function toLivewire(): array
{
return [
'categories' => $this->categories,
'overallTotal' => $this->overallTotal->toLivewire(),
'fields' => $this->fields,
];
}

Expand All @@ -28,6 +29,7 @@ public static function fromLivewire($value): static
return new static(
$value['categories'],
AccountBalanceDTO::fromLivewire($value['overallTotal']),
$value['fields'],
);
}
}
12 changes: 3 additions & 9 deletions app/Events/CompanyConfigured.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ class CompanyConfigured
use InteractsWithSockets;
use SerializesModels;

public Company $company;

/**
* Create a new event instance.
*/
public function __construct(Company $company)
{
$this->company = $company;
}
public function __construct(
public Company $company
) {}
}
9 changes: 3 additions & 6 deletions app/Events/CompanyDefaultEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ class CompanyDefaultEvent
use InteractsWithSockets;
use SerializesModels;

public Model $model;

/**
* Create a new event instance.
*/
public function __construct(Model $model)
{
$this->model = $model;
}
public function __construct(
public Model $model
) {}
}
13 changes: 4 additions & 9 deletions app/Events/CompanyDefaultUpdated.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@ class CompanyDefaultUpdated
use InteractsWithSockets;
use SerializesModels;

public Model $record;

public array $data;

/**
* Create a new event instance.
*/
public function __construct(Model $record, array $data)
{
$this->record = $record;
$this->data = $data;
}
public function __construct(
public Model $record,
public array $data
) {}
}
25 changes: 7 additions & 18 deletions app/Events/CompanyGenerated.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,14 @@ class CompanyGenerated
use Dispatchable;
use SerializesModels;

public User $user;

public Company $company;

public string $country;

public string $language;

public string $currency;

/**
* Create a new event instance.
*/
public function __construct(User $user, Company $company, string $country, string $language = 'en', string $currency = 'USD')
{
$this->user = $user;
$this->company = $company;
$this->country = $country;
$this->language = $language;
$this->currency = $currency;
}
public function __construct(
public User $user,
public Company $company,
public string $country,
public string $language = 'en',
public string $currency = 'USD'
) {}
}
20 changes: 5 additions & 15 deletions app/Events/CurrencyRateChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,9 @@ class CurrencyRateChanged
use InteractsWithSockets;
use SerializesModels;

public Currency $currency;

public float $oldRate;

public float $newRate;

/**
* Create a new event instance.
*/
public function __construct(Currency $currency, float $oldRate, float $newRate)
{
$this->currency = $currency;
$this->oldRate = $oldRate;
$this->newRate = $newRate;
}
public function __construct(
public Currency $currency,
public float $oldRate,
public float $newRate
) {}
}
9 changes: 3 additions & 6 deletions app/Events/DefaultCurrencyChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,10 @@ class DefaultCurrencyChanged
use InteractsWithSockets;
use SerializesModels;

public Currency $currency;

/**
* Create a new event instance.
*/
public function __construct(Currency $currency)
{
$this->currency = $currency;
}
public function __construct(
public Currency $currency
) {}
}
17 changes: 5 additions & 12 deletions app/Events/PlaidSuccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,12 @@ class PlaidSuccess
use Dispatchable;
use SerializesModels;

public string $publicToken;

public string $accessToken;

public Company $company;

/**
* Create a new event instance.
*/
public function __construct(string $publicToken, string $accessToken, Company $company)
{
$this->publicToken = $publicToken;
$this->accessToken = $accessToken;
$this->company = $company;
}
public function __construct(
public string $publicToken,
public string $accessToken,
public Company $company
) {}
}
21 changes: 6 additions & 15 deletions app/Events/StartTransactionImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,13 @@ class StartTransactionImport
use Dispatchable;
use SerializesModels;

public Company $company;

public ConnectedBankAccount $connectedBankAccount;

public int | string $selectedBankAccountId;

public string $startDate;

/**
* Create a new event instance.
*/
public function __construct(Company $company, ConnectedBankAccount $connectedBankAccount, int | string $selectedBankAccountId, string $startDate)
{
$this->company = $company;
$this->connectedBankAccount = $connectedBankAccount;
$this->selectedBankAccountId = $selectedBankAccountId;
$this->startDate = $startDate;
}
public function __construct(
public Company $company,
public ConnectedBankAccount $connectedBankAccount,
public int | string $selectedBankAccountId,
public string $startDate
) {}
}
6 changes: 0 additions & 6 deletions app/Facades/Accounting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
namespace App\Facades;

use App\Contracts\AccountHandler;
use App\DTO\AccountBalanceDTO;
use App\DTO\AccountBalanceReportDTO;
use App\Enums\Accounting\AccountCategory;
use App\Models\Accounting\Account;
use App\ValueObjects\Money;
use Illuminate\Support\Facades\Facade;
Expand All @@ -16,10 +13,7 @@
* @method static Money getNetMovement(Account $account, string $startDate, string $endDate)
* @method static Money|null getStartingBalance(Account $account, string $startDate)
* @method static Money|null getEndingBalance(Account $account, string $startDate, string $endDate)
* @method static int calculateNetMovementByCategory(AccountCategory $category, int $debitBalance, int $creditBalance)
* @method static array getBalances(Account $account, string $startDate, string $endDate)
* @method static AccountBalanceDTO formatBalances(array $balances)
* @method static AccountBalanceReportDTO buildAccountBalanceReport(string $startDate, string $endDate)
* @method static Money getTotalBalanceForAllBankAccounts(string $startDate, string $endDate)
* @method static array getAccountCategoryOrder()
* @method static string getEarliestTransactionDate()
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Company/Clusters/Settings/Pages/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Filament\Forms\Components\Component;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
Expand Down Expand Up @@ -163,7 +162,8 @@ protected function getContentSection(): Component
TextInput::make('subheader')
->localizeLabel()
->nullable(),
MarkdownEditor::make('terms')
Textarea::make('terms')
->localizeLabel()
->nullable(),
Textarea::make('footer')
->localizeLabel('Footer / Notes')
Expand Down
4 changes: 2 additions & 2 deletions app/Filament/Company/Clusters/Settings/Pages/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ protected function getGeneralSection(): Component
->options(LocalizationModel::getAllLanguages())
->searchable(),
Select::make('timezone')
->softRequired()
->localizeLabel()
->options(Timezone::getTimezoneOptions(CompanyProfileModel::first()->country))
->searchable()
->nullable(),
->searchable(),
])->columns();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CreateCurrency extends CreateRecord

protected function getRedirectUrl(): string
{
return $this->previousUrl;
return $this->getResource()::getUrl('index');
}

protected function mutateFormDataBeforeCreate(array $data): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ protected function getHeaderActions(): array
];
}

protected function getRedirectUrl(): ?string
protected function getRedirectUrl(): string
{
return $this->previousUrl;
return $this->getResource()::getUrl('index');
}

protected function mutateFormDataBeforeSave(array $data): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CreateDiscount extends CreateRecord

protected function getRedirectUrl(): string
{
return $this->previousUrl;
return $this->getResource()::getUrl('index');
}

protected function mutateFormDataBeforeCreate(array $data): array
Expand Down
Loading

0 comments on commit 339300e

Please sign in to comment.