Skip to content

Commit

Permalink
Merge pull request #72 from andrewdwallo/development-3.x
Browse files Browse the repository at this point in the history
Development 3.x
  • Loading branch information
andrewdwallo authored Oct 22, 2024
2 parents 4d3f41e + 5ba8e26 commit 61adbe2
Show file tree
Hide file tree
Showing 55 changed files with 1,654 additions and 603 deletions.
6 changes: 6 additions & 0 deletions app/Contracts/ExportableReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Contracts;

use App\DTO\ReportCategoryDTO;
use App\Support\Column;

interface ExportableReport
{
Expand All @@ -17,7 +18,12 @@ public function getCategories(): array;

public function getOverallTotals(): array;

/**
* @return Column[]
*/
public function getColumns(): array;

public function getPdfView(): string;

public function getAlignmentClass(string $columnName): string;
}
23 changes: 23 additions & 0 deletions app/Contracts/HasSummaryReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Contracts;

use App\DTO\ReportCategoryDTO;
use App\Support\Column;

interface HasSummaryReport
{
/**
* @return Column[]
*/
public function getSummaryColumns(): array;

public function getSummaryHeaders(): array;

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

public function getSummaryOverallTotals(): array;
}
8 changes: 5 additions & 3 deletions app/DTO/AccountCategoryDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
class AccountCategoryDTO
{
/**
* @param AccountDTO[] $accounts
* @param AccountDTO[]|null $accounts
* @param AccountTypeDTO[]|null $types
*/
public function __construct(
public array $accounts,
public AccountBalanceDTO $summary,
public ?array $accounts = null,
public ?array $types = null,
public ?AccountBalanceDTO $summary = null,
) {}
}
14 changes: 14 additions & 0 deletions app/DTO/AccountTypeDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\DTO;

class AccountTypeDTO
{
/**
* @param AccountDTO[] $accounts
*/
public function __construct(
public array $accounts,
public AccountBalanceDTO $summary,
) {}
}
12 changes: 9 additions & 3 deletions app/DTO/ReportCategoryDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@

class ReportCategoryDTO
{
/**
* ReportCategoryDTO constructor.
*
* @param ReportTypeDTO[]|null $types
*/
public function __construct(
public array $header,
public array $data,
public array $summary = [],
public ?array $header = null,
public ?array $data = null,
public ?array $summary = null,
public ?array $types = null,
) {}
}
12 changes: 12 additions & 0 deletions app/DTO/ReportTypeDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\DTO;

class ReportTypeDTO
{
public function __construct(
public ?array $header = null,
public ?array $data = null,
public ?array $summary = null,
) {}
}
22 changes: 22 additions & 0 deletions app/Enums/Accounting/AccountType.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ public function getLabel(): ?string
};
}

public function getPluralLabel(): ?string
{
return match ($this) {
self::CurrentAsset => 'Current Assets',
self::NonCurrentAsset => 'Non-Current Assets',
self::ContraAsset => 'Contra Assets',
self::CurrentLiability => 'Current Liabilities',
self::NonCurrentLiability => 'Non-Current Liabilities',
self::ContraLiability => 'Contra Liabilities',
self::Equity => 'Equity',
self::ContraEquity => 'Contra Equity',
self::OperatingRevenue => 'Operating Revenue',
self::NonOperatingRevenue => 'Non-Operating Revenue',
self::ContraRevenue => 'Contra Revenue',
self::UncategorizedRevenue => 'Uncategorized Revenue',
self::OperatingExpense => 'Operating Expenses',
self::NonOperatingExpense => 'Non-Operating Expenses',
self::ContraExpense => 'Contra Expenses',
self::UncategorizedExpense => 'Uncategorized Expenses',
};
}

public function getCategory(): AccountCategory
{
return match ($this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ public static function table(Table $table): Table
$action->cancel();
}
}
})
->hidden(function (Table $table) {
return $table->getAllSelectableRecordsCount() === 0;
}),
]),
])
Expand Down
7 changes: 1 addition & 6 deletions app/Filament/Company/Pages/Accounting/AccountChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,7 @@ class AccountChart extends Page
protected static string $view = 'filament.company.pages.accounting.chart';

#[Url]
public ?string $activeTab = null;

public function mount(): void
{
$this->activeTab = $this->activeTab ?? AccountCategory::Asset->value;
}
public ?string $activeTab = AccountCategory::Asset->value;

protected function configureAction(Action $action): void
{
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Company/Pages/Accounting/Transactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ protected function buildTransactionAction(string $name, string $label, Transacti
protected function getFormDefaultsForType(TransactionType $type): array
{
$commonDefaults = [
'posted_at' => now()->format('Y-m-d'),
'posted_at' => today(),
];

return match ($type) {
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Company/Pages/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Filament\Company\Pages\Reports\AccountBalances;
use App\Filament\Company\Pages\Reports\AccountTransactions;
use App\Filament\Company\Pages\Reports\BalanceSheet;
use App\Filament\Company\Pages\Reports\IncomeStatement;
use App\Filament\Company\Pages\Reports\TrialBalance;
use App\Infolists\Components\ReportEntry;
Expand Down Expand Up @@ -41,7 +42,7 @@ public function reportsInfolist(Infolist $infolist): Infolist
->description('Snapshot of assets, liabilities, and equity at a specific point in time.')
->icon('heroicon-o-clipboard-document-list')
->iconColor(Color::Emerald)
->url('#'),
->url(BalanceSheet::getUrl()),
ReportEntry::make('cash_flow_statement')
->hiddenLabel()
->heading('Cash Flow Statement')
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Company/Pages/Reports/AccountTransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getTable(): array
->label('Credit')
->alignment(Alignment::Right),
Column::make('balance')
->label('Balance')
->label('Running Balance')
->alignment(Alignment::Right),
];
}
Expand Down
87 changes: 87 additions & 0 deletions app/Filament/Company/Pages/Reports/BalanceSheet.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

namespace App\Filament\Company\Pages\Reports;

use App\Contracts\ExportableReport;
use App\DTO\ReportDTO;
use App\Filament\Forms\Components\DateRangeSelect;
use App\Services\ExportService;
use App\Services\ReportService;
use App\Support\Column;
use App\Transformers\BalanceSheetReportTransformer;
use Filament\Forms\Form;
use Filament\Support\Enums\Alignment;
use Livewire\Attributes\Url;
use Symfony\Component\HttpFoundation\StreamedResponse;

class BalanceSheet extends BaseReportPage
{
protected static string $view = 'filament.company.pages.reports.balance-sheet';

protected static bool $shouldRegisterNavigation = false;

protected ReportService $reportService;

protected ExportService $exportService;

#[Url]
public ?string $activeTab = 'summary';

public function boot(ReportService $reportService, ExportService $exportService): void
{
$this->reportService = $reportService;
$this->exportService = $exportService;
}

public function getTable(): array
{
return [
Column::make('account_code')
->label('Account Code')
->toggleable()
->alignment(Alignment::Center),
Column::make('account_name')
->label('Account')
->alignment(Alignment::Left),
Column::make('ending_balance')
->label('Amount')
->alignment(Alignment::Right),
];
}

public function filtersForm(Form $form): Form
{
return $form
->inlineLabel()
->columns(3)
->schema([
DateRangeSelect::make('dateRange')
->label('As of')
->selectablePlaceholder(false)
->endDateField('asOfDate'),
$this->getAsOfDateFormComponent()
->hiddenLabel()
->extraFieldWrapperAttributes([]),
]);
}

protected function buildReport(array $columns): ReportDTO
{
return $this->reportService->buildBalanceSheetReport($this->getFormattedAsOfDate(), $columns);
}

protected function getTransformer(ReportDTO $reportDTO): ExportableReport
{
return new BalanceSheetReportTransformer($reportDTO);
}

public function exportCSV(): StreamedResponse
{
return $this->exportService->exportToCsv($this->company, $this->report, endDate: $this->getFilterState('asOfDate'));
}

public function exportPDF(): StreamedResponse
{
return $this->exportService->exportToPdf($this->company, $this->report, endDate: $this->getFilterState('asOfDate'));
}
}
4 changes: 4 additions & 0 deletions app/Filament/Company/Pages/Reports/IncomeStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Filament\Forms\Form;
use Filament\Support\Enums\Alignment;
use Guava\FilamentClusters\Forms\Cluster;
use Livewire\Attributes\Url;
use Symfony\Component\HttpFoundation\StreamedResponse;

class IncomeStatement extends BaseReportPage
Expand All @@ -25,6 +26,9 @@ class IncomeStatement extends BaseReportPage

protected ExportService $exportService;

#[Url]
public ?string $activeTab = 'summary';

public function boot(ReportService $reportService, ExportService $exportService): void
{
$this->reportService = $reportService;
Expand Down
5 changes: 4 additions & 1 deletion app/Filament/Company/Resources/Banking/AccountResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ public static function table(Table $table): Table
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make()
->requiresConfirmation()
->modalDescription('Are you sure you want to delete the selected accounts? All transactions associated with the accounts will be deleted as well.'),
->modalDescription('Are you sure you want to delete the selected accounts? All transactions associated with the accounts will be deleted as well.')
->hidden(function (Table $table) {
return $table->getAllSelectableRecordsCount() === 0;
}),
]),
])
->checkIfRecordIsSelectableUsing(static function (BankAccount $record) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Filament\Company\Resources\Banking\AccountResource\Pages;

use App\Filament\Company\Resources\Banking\AccountResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditAccount extends EditRecord
Expand All @@ -12,7 +13,7 @@ class EditAccount extends EditRecord
protected function getHeaderActions(): array
{
return [
//
Actions\DeleteAction::make(),
];
}

Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/UpdateAccountBalances.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function handle(CurrencyRateChanged $event): void
'type' => $transactionType,
'amount' => $formattedSimpleDifference,
'payment_channel' => 'other',
'posted_at' => now(),
'posted_at' => today(),
'description' => $description,
'pending' => false,
'reviewed' => false,
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Accounting/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Transaction extends Model
'amount' => TransactionAmountCast::class,
'pending' => 'boolean',
'reviewed' => 'boolean',
'posted_at' => 'datetime',
'posted_at' => 'date',
];

public function account(): BelongsTo
Expand Down
3 changes: 2 additions & 1 deletion app/Services/AccountService.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function getAccountBalances(string $startDate, string $endDate, array $ac
'accounts.id',
'accounts.name',
'accounts.category',
'accounts.type',
'accounts.subtype_id',
'accounts.currency_code',
'accounts.code',
Expand Down Expand Up @@ -227,6 +228,6 @@ public function getEarliestTransactionDate(): string
{
$earliestDate = Transaction::min('posted_at');

return $earliestDate ?? now()->toDateTimeString();
return $earliestDate ?? today()->toDateTimeString();
}
}
Loading

0 comments on commit 61adbe2

Please sign in to comment.