diff --git a/app/Filament/Resources/ExpenseResource.php b/app/Filament/Resources/ExpenseResource.php index c84393de..28ced381 100644 --- a/app/Filament/Resources/ExpenseResource.php +++ b/app/Filament/Resources/ExpenseResource.php @@ -1,11 +1,10 @@ - - schema([ + Forms\Components\Select::make('supplier_id') + ->relationship('supplier', 'supplier_first_name', fn ($query) => $query->orderBy('supplier_first_name')) + ->searchable() + ->preload() + ->label('Supplier') + ->createOptionForm([ + Forms\Components\TextInput::make('supplier_first_name') + ->required() + ->label('First Name'), + Forms\Components\TextInput::make('supplier_last_name') + ->required() + ->label('Last Name'), + Forms\Components\TextInput::make('supplier_email') + ->email() + ->label('Email'), + Forms\Components\TextInput::make('supplier_phone_number') + ->tel() + ->label('Phone Number'), + ]), Forms\Components\BelongsToSelect::make('currency_id') ->relationship('currency', 'code') ->required() @@ -74,6 +92,10 @@ public static function table(Tables\Table $table): Tables\Table { return $table ->columns([ + Tables\Columns\TextColumn::make('supplier.supplier_first_name') + ->label('Supplier') + ->searchable() + ->sortable(), Tables\Columns\TextColumn::make('currency.code') ->label('Currency') ->sortable(), diff --git a/app/Models/Expense.php b/app/Models/Expense.php index d5eb8c2a..57182b63 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -24,6 +24,7 @@ class Expense extends Model 'cost_center_id', 'is_indirect', 'allocation_percentage', + 'supplier_id' 'currency_id' ]; @@ -55,6 +56,10 @@ public function costCenter(): BelongsTo return $this->belongsTo(CostCenter::class); } + public function supplier(): BelongsTo + { + return $this->belongsTo(Supplier::class, 'supplier_id', 'supplier_id'); + } public function currency(): BelongsTo { return $this->belongsTo(Currency::class, 'currency_id'); diff --git a/database/migrations/2024_01_15_000000_add_supplier_id_to_expenses_table.php b/database/migrations/2024_01_15_000000_add_supplier_id_to_expenses_table.php new file mode 100644 index 00000000..3a250e79 --- /dev/null +++ b/database/migrations/2024_01_15_000000_add_supplier_id_to_expenses_table.php @@ -0,0 +1,28 @@ + + +foreignId('supplier_id') + ->nullable() + ->constrained('suppliers', 'supplier_id') + ->nullOnDelete(); + }); + } + + public function down() + { + Schema::table('expenses', function (Blueprint $table) { + $table->dropForeign(['supplier_id']); + $table->dropColumn('supplier_id'); + }); + } +}; \ No newline at end of file