diff --git a/app/Filament/App/Resources/OpportunityResource.php b/app/Filament/App/Resources/OpportunityResource.php index bf5abc2..3526206 100644 --- a/app/Filament/App/Resources/OpportunityResource.php +++ b/app/Filament/App/Resources/OpportunityResource.php @@ -2,6 +2,93 @@ namespace App\Filament\App\Resources; +use App\Filament\App\Resources\OpportunityResource\Pages; +use App\Models\Opportunity; +use Filament\Forms; +use Filament\Forms\Form; +use Filament\Resources\Resource; +use Filament\Tables; +use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\SoftDeletingScope; + +class OpportunityResource extends Resource +{ + protected static ?string $model = Opportunity::class; + + protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack'; + + public static function form(Form $form): Form + { + return $form + ->schema([ + // Your form schema here + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('name') + ->searchable(), + Tables\Columns\TextColumn::make('value') + ->money() + ->sortable(), + Tables\Columns\TextColumn::make('stage.name') + ->sortable(), + Tables\Columns\TextColumn::make('created_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('updated_at') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + // + ]) + ->actions([ + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } + + public static function getPipelineTable(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\ViewColumn::make('pipeline') + ->view('livewire.opportunity-pipeline') + ->label('Pipeline View') + ]) + ->paginated(false); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListOpportunities::route('/'), + 'create' => Pages\CreateOpportunity::route('/create'), + 'edit' => Pages\EditOpportunity::route('/{record}/edit'), + ]; + } +} + +namespace App\Filament\App\Resources; + use Filament\Forms; use Filament\Tables; use Filament\Forms\Form; diff --git a/app/Filament/App/Resources/OpportunityResource/Pages/ListOpportunities.php b/app/Filament/App/Resources/OpportunityResource/Pages/ListOpportunities.php index 4e50dc1..c3f92c1 100644 --- a/app/Filament/App/Resources/OpportunityResource/Pages/ListOpportunities.php +++ b/app/Filament/App/Resources/OpportunityResource/Pages/ListOpportunities.php @@ -5,9 +5,7 @@ use App\Filament\App\Resources\OpportunityResource; use Filament\Actions; use Filament\Resources\Pages\ListRecords; - -use Illuminate\Contracts\View\View; -use Illuminate\Contracts\View\View; +use Filament\Tables\Table; class ListOpportunities extends ListRecords { @@ -20,8 +18,8 @@ protected function getHeaderActions(): array ]; } - public function table(): View + public function table(Table $table): Table { - return OpportunityResource::getPipelineView(); + return OpportunityResource::getPipelineTable($table); } } diff --git a/app/Http/Livewire/OpportunityPipeline.php b/app/Http/Livewire/OpportunityPipeline.php index c992944..d382721 100644 --- a/app/Http/Livewire/OpportunityPipeline.php +++ b/app/Http/Livewire/OpportunityPipeline.php @@ -2,6 +2,48 @@ namespace App\Http\Livewire; +use Livewire\Component; +use App\Models\Pipeline; +use App\Models\Deal; +use App\Models\Stage; +use Filament\Tables\Table; + +class OpportunityPipeline extends Component +{ + public $stages; + public $deals; + public Table $table; + + public function mount(Table $table) + { + $this->table = $table; + $this->loadPipeline(); + } + + public function loadPipeline() + { + $pipeline = Pipeline::first(); + $this->stages = $pipeline->stages; + $this->deals = Deal::all()->groupBy('stage_id'); + } + + public function updateDealStage($dealId, $stageId) + { + $deal = Deal::findOrFail($dealId); + $deal->stage_id = $stageId; + $deal->save(); + + $this->loadPipeline(); + } + + public function render() + { + return view('livewire.opportunity-pipeline'); + } +} + +namespace App\Http\Livewire; + use Livewire\Component; use App\Models\Pipeline; use App\Models\Deal; diff --git a/resources/views/livewire/opportunity-pipeline.blade.php b/resources/views/livewire/opportunity-pipeline.blade.php index 6db4ed4..cedb5a5 100644 --- a/resources/views/livewire/opportunity-pipeline.blade.php +++ b/resources/views/livewire/opportunity-pipeline.blade.php @@ -1,28 +1,30 @@ -
-
- @foreach($stages as $stage) -
-

{{ $stage->name }}

-
- @foreach($deals[$stage->id] ?? [] as $deal) -
-

{{ $deal->name }}

-

{{ $deal->value }}

-
- @endforeach +
+
+
+ @foreach($stages as $stage) +
+

{{ $stage->name }}

+
+ @foreach($deals[$stage->id] ?? [] as $deal) +
+

{{ $deal->name }}

+

{{ $deal->value }}

+
+ @endforeach +
-
- @endforeach + @endforeach +
\ No newline at end of file