Skip to content

Commit

Permalink
move list to reports (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamBiB authored Oct 31, 2023
1 parent 217f73a commit 85644ef
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
37 changes: 35 additions & 2 deletions app/Filament/Resources/ReportsResource/Pages/GenerateReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
use App\Models\MapPointType as MapPointTypeModel;
use App\Models\RecycleMaterial as RecycleMaterialModel;
use App\Models\Report;
use Filament\Actions\Action;
use Filament\Actions\Action as FormAction;
use Filament\Actions\Contracts\HasActions;
// use Filament\Resources\Pages\CreateRecord;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Radio;
// use Filament\Resources\Pages\CreateRecord;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
Expand All @@ -37,6 +38,7 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Facades\Excel;

class GenerateReport extends Page implements HasForms, WithTabs, HasTable, HasActions
Expand Down Expand Up @@ -72,6 +74,14 @@ public function mount(): void
$this->data['is_grouped'] = false;
}

protected function getHeaderActions(): array
{
return [
Action::make('view_list')->label(__('report.action.view_list'))->url('/admin/reports'),

];
}

protected function authorizeAccess(): void
{
static::authorizeResourceAccess();
Expand Down Expand Up @@ -385,7 +395,7 @@ public function table(Table $table): Table
{
$report = new Report();
$report->form_data = $this->data;
$report->results = $this->getEloquentQuery()->get();
$report->results = $this->formatResults($this->getEloquentQuery()->get());
$report->title = $data['title'];
$report->save();
Notification::make()
Expand Down Expand Up @@ -432,4 +442,27 @@ public function table(Table $table): Table
]);
// ->view('filament-tables::index');
}

public function formatResults(Collection $items): Collection
{
$values = [];
$columns = [];
foreach ($this->getTableColumns() as $column)
{
$columns[] = $column->getLabel();
}
$returnArr['header'] = $columns;
foreach($columns as $column)
{
$record = $items->where('grouped_by', $column)->first();
$value = 0;
if($record):
$value = $record->total;
endif;
$values[] = $value;
}
$returnArr['results'] = $values;

return collect($returnArr);
}
}
4 changes: 2 additions & 2 deletions app/Filament/Resources/ReportsResource/Pages/ListReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @Author: Bogdan Bocioaca
* @Date: 2023-10-21 13:06:49
* @Last Modified by: Bogdan Bocioaca
* @Last Modified time: 2023-10-21 13:06:55
* @Last Modified time: 2023-10-31 09:01:26
*/

namespace App\Filament\Resources\ReportsResource\Pages;
Expand All @@ -20,7 +20,7 @@ class ListReport extends ListRecords
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
// Actions\CreateAction::make(),
];
}
}
18 changes: 11 additions & 7 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ public function boot(): void

Filament::registerNavigationItems([

NavigationItem::make('Lista rapoarte')
->url('/admin/reports')
->icon('heroicon-o-presentation-chart-line')
->activeIcon('heroicon-s-presentation-chart-line')
->group('Rapoarte')
->sort(2)
->hidden(auth()->user() && !auth()->user()->can('view_reports')),
// NavigationItem::make('Lista rapoarte')
// ->url('/admin/reports')
// ->icon('heroicon-o-presentation-chart-line')
// // ->activeIcon('heroicon-s-presentation-chart-line')
// ->group('Rapoarte')
// ->sort(2)
// // ->isActiveWhen(function ()
// // {
// // return request()->route()->uri == 'admin/reports';
// // })
// ->hidden(auth()->user() && !auth()->user()->can('view_reports')),
]);
});
Filament::registerNavigationGroups([
Expand Down
12 changes: 7 additions & 5 deletions lang/en/report.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @Author: Bogdan Bocioaca
* @Date: 2023-10-23 10:36:09
* @Last Modified by: Bogdan Bocioaca
* @Last Modified time: 2023-10-27 11:47:42
* @Last Modified time: 2023-10-31 09:00:50
*/
return [
'column' => [
Expand All @@ -24,10 +24,12 @@
'created_at' => 'Created',
],
'action' => [
'generate'=> 'Generate report',
'reset'=>'Reset report',
'save_report' => 'Save report',
'export' => 'Export',
'generate'=> 'Genereaza raport',
'reset'=>'Reseteaza raportul',
'save_report' => 'Salveaza raportul',
'export' => 'Exporta',
'view_list' => 'Vezi lista',

],
'section'=>[
'generator' => 'Generate report',
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 85644ef

Please sign in to comment.