Sindbad~EG File Manager

Current Path : /home/webg5288/www/laravel_kendal/app/Filament/Resources/
Upload File :
Current File : /home/webg5288/www/laravel_kendal/app/Filament/Resources/StockBalanceResource.php

<?php

// namespace App\Filament\Resources;

// use App\Filament\Resources\StockBalanceGudangResource\Pages;
// use App\Models\VwStockSummaryMonthly;
// use Filament\Resources\Resource;
// use Filament\Tables\Table;

// class StockBalanceGudangResource extends Resource
// {
//     protected static ?string $model = VwStockSummaryMonthly::class;

//     protected static ?string $navigationIcon = 'heroicon-o-chart-bar';
//     protected static ?string $navigationLabel = 'Laporan Saldo Per Gudang';
//     protected static ?string $navigationGroup = 'Laporan';

//     public static function table(Table $table): Table
//     {
//         return $table;
//     }

//     public static function getPages(): array
//     {
//         return [
//             'index' => Pages\ListStockBalanceGudangs::route('/'),
//         ];
//     }
// }


namespace App\Filament\Resources;

use App\Filament\Resources\StockBalanceResource\Pages;
use App\Models\VwStockSummaryMonthlyGudang;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables\Table;
use Illuminate\Support\Facades\DB;

class StockBalanceResource extends Resource
{
    protected static ?string $model = VwStockSummaryMonthlyGudang::class;

    protected static ?string $navigationIcon = 'heroicon-o-chart-bar';
    protected static ?string $navigationLabel = 'Laporan Saldo Bulanan Gudang';
    protected static ?string $modelLabel = 'Saldo Bulanan Gudang';
    protected static ?string $pluralModelLabel = 'Laporan Saldo Bulanan Gudang';
    protected static ?string $navigationGroup = 'Laporan';

    public static function form(Form $form): Form
    {
        return $form->schema([
            Forms\Components\Section::make('Filter Laporan')
                ->schema([
                    Forms\Components\Select::make('tahun')
                        ->label('Tahun')
                        ->options(function () {
                            return DB::table('vw_stock_kartu_stock_gudang')
                                ->selectRaw('YEAR(TGL_AWAL_BULAN) as tahun')
                                ->distinct()
                                ->orderBy('tahun', 'desc')
                                ->pluck('tahun', 'tahun')
                                ->toArray();
                        })
                        ->default(date('Y'))
                        ->searchable(),
                ]),
        ]);
    }

    /**
     * Table kamu jangan taruh di Resource kalau mau stateful filter + query custom.
     * Nanti table() kita taruh di Pages\List... agar bisa akses $this->tableFilters.
     */
    public static function table(Table $table): Table
    {
        return $table;
    }

    protected static function bulanOptions(): array
    {
        // return DB::table('vw_stock_summary_monthly_base')
         return DB::table('vw_stock_kartu_stock_gudang')
            ->selectRaw("DATE_FORMAT(TGL_INV, '%Y-%m') AS bulan")
            ->groupBy('bulan')
            ->orderBy('bulan', 'desc')
            ->pluck('bulan', 'bulan')
            ->toArray();
    }

    public static function getRelations(): array
    {
        return [];
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListStockBalances::route('/'),
        ];
    }
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists