Skip to content

Commit

Permalink
Merge pull request #379 from liberu-accounting/sweep/Add-Category-Sup…
Browse files Browse the repository at this point in the history
…port-for-Expenses

Add Category Support for Expenses
  • Loading branch information
curtisdelicata authored Dec 24, 2024
2 parents 55f4fb4 + 5b1f6b4 commit b4932a1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/Filament/Resources/ExpenseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public static function form(Forms\Form $form): Forms\Form
Forms\Components\DatePicker::make('date')
->required()
->maxDate(now()),
Forms\Components\Select::make('categories')
->multiple()
->relationship('categories', 'name')
->preload()
->required(),
Forms\Components\Select::make('approval_status')
->options([
'pending' => 'Pending',
Expand Down Expand Up @@ -135,6 +140,10 @@ public static function table(Tables\Table $table): Tables\Table
Tables\Columns\TextColumn::make('date')
->date()
->sortable(),
Tables\Columns\TextColumn::make('categories.name')
->badge()
->separator(',')
->searchable(),
Tables\Columns\TextColumn::make('user.name')
->label('Submitted By')
->searchable(),
Expand All @@ -156,6 +165,10 @@ public static function table(Tables\Table $table): Tables\Table
'approved' => 'Approved',
'rejected' => 'Rejected',
]),
Tables\Filters\SelectFilter::make('categories')
->relationship('categories', 'name')
->multiple()
->preload(),
])
->actions([
Tables\Actions\ViewAction::make(),
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Expense.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Facades\Auth;
use App\Notifications\ExpenseApprovalNotification;
use App\Services\ExchangeRateService;
Expand Down Expand Up @@ -56,6 +57,10 @@ public function costCenter(): BelongsTo
return $this->belongsTo(CostCenter::class);
}

public function categories(): BelongsToMany
{
return $this->belongsToMany(Category::class);
}
public function supplier(): BelongsTo
{
return $this->belongsTo(Supplier::class, 'supplier_id', 'supplier_id');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up()
{
Schema::create('expense_category', function (Blueprint $table) {
$table->id();
$table->foreignId('expense_id')->constrained()->onDelete('cascade');
$table->foreignId('category_id')->constrained()->onDelete('cascade');
$table->timestamps();
});
}

public function down()
{
Schema::dropIfExists('expense_category');
}
};

0 comments on commit b4932a1

Please sign in to comment.