Skip to content

Commit

Permalink
Merge pull request #356 from liberu-accounting/sweep/Add-Tax-Form-Man…
Browse files Browse the repository at this point in the history
…agement-Feature-for-1099-Forms

Add Tax Form Management Feature for 1099 Forms
  • Loading branch information
curtisdelicata authored Dec 24, 2024
2 parents ca658b4 + 51a6a56 commit b789fc4
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 0 deletions.
89 changes: 89 additions & 0 deletions app/Filament/App/Resources/TaxFormResource.php
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'),
];
}
}
59 changes: 59 additions & 0 deletions app/Models/TaxForm.php
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 database/migrations/2024_01_20_000000_create_tax_forms_table.php
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');
}
};
39 changes: 39 additions & 0 deletions resources/views/tax-forms/1099-misc.blade.php
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>

0 comments on commit b789fc4

Please sign in to comment.