-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #356 from liberu-accounting/sweep/Add-Tax-Form-Man…
…agement-Feature-for-1099-Forms Add Tax Form Management Feature for 1099 Forms
- Loading branch information
Showing
4 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
|
||
<?php | ||
|
||
namespace App\Filament\App\Resources; | ||
|
||
use App\Models\TaxForm; | ||
use Filament\Forms; | ||
use Filament\Resources\Resource; | ||
use Filament\Tables; | ||
use Filament\Forms\Form; | ||
use Filament\Tables\Table; | ||
use Filament\Forms\Components\Select; | ||
|
||
class TaxFormResource extends Resource | ||
{ | ||
protected static ?string $model = TaxForm::class; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-document-text'; | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Select::make('form_type') | ||
->options([ | ||
'1099-MISC' => '1099-MISC', | ||
'1099-NEC' => '1099-NEC', | ||
]) | ||
->required(), | ||
Forms\Components\Select::make('customer_id') | ||
->relationship('customer', 'customer_name') | ||
->required(), | ||
Forms\Components\TextInput::make('tax_year') | ||
->required() | ||
->numeric() | ||
->minValue(2000) | ||
->maxValue(date('Y')), | ||
Forms\Components\TextInput::make('total_payments') | ||
->required() | ||
->numeric() | ||
->disabled(), | ||
Forms\Components\TextInput::make('total_tax_withheld') | ||
->required() | ||
->numeric() | ||
->disabled(), | ||
Forms\Components\Select::make('status') | ||
->options([ | ||
'draft' => 'Draft', | ||
'generated' => 'Generated', | ||
'submitted' => 'Submitted', | ||
]) | ||
->required(), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('form_type'), | ||
Tables\Columns\TextColumn::make('customer.customer_name'), | ||
Tables\Columns\TextColumn::make('tax_year'), | ||
Tables\Columns\TextColumn::make('total_payments') | ||
->money('USD'), | ||
Tables\Columns\TextColumn::make('status'), | ||
]) | ||
->filters([ | ||
Tables\Filters\SelectFilter::make('form_type'), | ||
Tables\Filters\SelectFilter::make('status'), | ||
]) | ||
->actions([ | ||
Tables\Actions\EditAction::make(), | ||
Tables\Actions\Action::make('generate_pdf') | ||
->label('Generate PDF') | ||
->icon('heroicon-o-document-arrow-down') | ||
->action(fn (TaxForm $record) => $record->generatePDF()), | ||
]); | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ListTaxForms::route('/'), | ||
'create' => Pages\CreateTaxForm::route('/create'), | ||
'edit' => Pages\EditTaxForm::route('/{record}/edit'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
|
||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Barryvdh\DomPDF\Facade\Pdf; | ||
|
||
class TaxForm extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $primaryKey = 'tax_form_id'; | ||
|
||
protected $fillable = [ | ||
'form_type', | ||
'customer_id', | ||
'tax_year', | ||
'total_payments', | ||
'total_tax_withheld', | ||
'status', | ||
'form_data' | ||
]; | ||
|
||
protected $casts = [ | ||
'form_data' => 'array', | ||
'total_payments' => 'decimal:2', | ||
'total_tax_withheld' => 'decimal:2', | ||
]; | ||
|
||
public function customer() | ||
{ | ||
return $this->belongsTo(Customer::class); | ||
} | ||
|
||
public function generatePDF() | ||
{ | ||
$data = [ | ||
'form' => $this, | ||
'customer' => $this->customer, | ||
]; | ||
|
||
$pdf = PDF::loadView('tax-forms.' . strtolower($this->form_type), $data); | ||
return $pdf->download($this->form_type . '_' . $this->tax_year . '.pdf'); | ||
} | ||
|
||
public function calculateTotals() | ||
{ | ||
$invoices = Invoice::where('customer_id', $this->customer_id) | ||
->whereYear('invoice_date', $this->tax_year) | ||
->get(); | ||
|
||
$this->total_payments = $invoices->sum('total_amount'); | ||
$this->total_tax_withheld = $invoices->sum('tax_amount'); | ||
$this->save(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
database/migrations/2024_01_20_000000_create_tax_forms_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
|
||
<?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('tax_forms', function (Blueprint $table) { | ||
$table->id('tax_form_id'); | ||
$table->string('form_type'); // e.g., '1099-MISC' | ||
$table->foreignId('customer_id')->constrained('customers', 'customer_id'); | ||
$table->year('tax_year'); | ||
$table->decimal('total_payments', 12, 2); | ||
$table->decimal('total_tax_withheld', 12, 2); | ||
$table->string('status'); // draft, generated, submitted | ||
$table->json('form_data'); // Store additional form-specific data | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down() | ||
{ | ||
Schema::dropIfExists('tax_forms'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
|
||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Form 1099-MISC</title> | ||
<style> | ||
body { font-family: Arial, sans-serif; } | ||
.form-header { text-align: center; margin-bottom: 20px; } | ||
.form-section { margin-bottom: 15px; } | ||
.field { margin: 5px 0; } | ||
</style> | ||
</head> | ||
<body> | ||
<div class="form-header"> | ||
<h1>Form 1099-MISC</h1> | ||
<h2>Miscellaneous Income</h2> | ||
<p>Tax Year: {{ $form->tax_year }}</p> | ||
</div> | ||
|
||
<div class="form-section"> | ||
<h3>Payer Information</h3> | ||
<div class="field">Company Name: {{ config('app.name') }}</div> | ||
<!-- Add company address and other details --> | ||
</div> | ||
|
||
<div class="form-section"> | ||
<h3>Recipient Information</h3> | ||
<div class="field">Name: {{ $customer->customer_name }}</div> | ||
<!-- Add customer address and tax ID --> | ||
</div> | ||
|
||
<div class="form-section"> | ||
<h3>Payment Information</h3> | ||
<div class="field">Total Payments: ${{ number_format($form->total_payments, 2) }}</div> | ||
<div class="field">Federal Tax Withheld: ${{ number_format($form->total_tax_withheld, 2) }}</div> | ||
</div> | ||
</body> | ||
</html> |