Work on invoice reports
This commit is contained in:
parent
0528506dfa
commit
e4899de42a
@ -3,6 +3,7 @@
|
|||||||
namespace App\Filament\Resources;
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
use App\Filament\Resources\InvoiceReportResource\Pages;
|
use App\Filament\Resources\InvoiceReportResource\Pages;
|
||||||
|
use App\Filament\Resources\InvoiceReportResource\RelationManagers\InvoicesRelationManager;
|
||||||
use Filament\Forms\Components\DatePicker;
|
use Filament\Forms\Components\DatePicker;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
@ -55,12 +56,15 @@ public static function table(Table $table): Table
|
|||||||
{
|
{
|
||||||
return $table
|
return $table
|
||||||
->columns([
|
->columns([
|
||||||
TextColumn::make('id')
|
TextColumn::make('internal_id')
|
||||||
->formatStateUsing(fn ($state) => 'TN-INR-'.$state)
|
->label('ID')
|
||||||
->fontFamily(FontFamily::Mono)
|
->fontFamily(FontFamily::Mono)
|
||||||
->color('primary'),
|
->color('primary')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
TextColumn::make('customer.company_name')
|
TextColumn::make('customer.company_name')
|
||||||
->extraHeaderAttributes(['class' => 'w-full']),
|
->extraHeaderAttributes(['class' => 'w-full'])
|
||||||
|
->searchable(),
|
||||||
TextColumn::make('date_start')
|
TextColumn::make('date_start')
|
||||||
->label('Start Date')
|
->label('Start Date')
|
||||||
->date('Y-m-d'),
|
->date('Y-m-d'),
|
||||||
@ -91,7 +95,7 @@ public static function table(Table $table): Table
|
|||||||
public static function getRelations(): array
|
public static function getRelations(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
//
|
InvoicesRelationManager::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\InvoiceReportResource\RelationManagers;
|
||||||
|
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class InvoicesRelationManager extends RelationManager
|
||||||
|
{
|
||||||
|
protected static string $relationship = 'invoices';
|
||||||
|
|
||||||
|
public function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->schema([
|
||||||
|
Forms\Components\TextInput::make('id')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->recordTitleAttribute('internal_id')
|
||||||
|
->columns([
|
||||||
|
Tables\Columns\TextColumn::make('internal_id'),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
//
|
||||||
|
])
|
||||||
|
->headerActions([
|
||||||
|
// Tables\Actions\CreateAction::make(),
|
||||||
|
Tables\Actions\AssociateAction::make(),
|
||||||
|
])
|
||||||
|
->actions([
|
||||||
|
Tables\Actions\DissociateAction::make(),
|
||||||
|
// Tables\Actions\EditAction::make(),
|
||||||
|
// Tables\Actions\DeleteAction::make(),
|
||||||
|
])
|
||||||
|
->bulkActions([
|
||||||
|
// Tables\Actions\BulkActionGroup::make([
|
||||||
|
// Tables\Actions\DeleteBulkAction::make(),
|
||||||
|
// ]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\InvoiceReportResource\RelationManagers;
|
||||||
|
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Resources\RelationManagers\RelationManager;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
|
||||||
|
class OrdersRelationManager extends RelationManager
|
||||||
|
{
|
||||||
|
protected static string $relationship = 'orders';
|
||||||
|
|
||||||
|
public function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->schema([
|
||||||
|
Forms\Components\TextInput::make('customer_po')
|
||||||
|
->required()
|
||||||
|
->maxLength(255),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->recordTitleAttribute('customer_po')
|
||||||
|
->columns([
|
||||||
|
Tables\Columns\TextColumn::make('customer_po'),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
//
|
||||||
|
])
|
||||||
|
->headerActions([
|
||||||
|
Tables\Actions\CreateAction::make(),
|
||||||
|
])
|
||||||
|
->actions([
|
||||||
|
Tables\Actions\EditAction::make(),
|
||||||
|
Tables\Actions\DeleteAction::make(),
|
||||||
|
])
|
||||||
|
->bulkActions([
|
||||||
|
Tables\Actions\BulkActionGroup::make([
|
||||||
|
Tables\Actions\DeleteBulkAction::make(),
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -108,4 +108,9 @@ public function productServices(): HasManyThrough
|
|||||||
{
|
{
|
||||||
return $this->hasManyThrough(ProductService::class, Order::class);
|
return $this->hasManyThrough(ProductService::class, Order::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function invoiceReports(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(InvoiceReport::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,15 @@
|
|||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||||
|
|
||||||
class InvoiceReport extends Model
|
class InvoiceReport extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
'internal_id',
|
||||||
'customer_id',
|
'customer_id',
|
||||||
'date_start',
|
'date_start',
|
||||||
'date_end',
|
'date_end',
|
||||||
@ -21,8 +24,37 @@ class InvoiceReport extends Model
|
|||||||
'total',
|
'total',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public static function boot(): void
|
||||||
|
{
|
||||||
|
parent::boot();
|
||||||
|
|
||||||
|
static::created(function ($model) {
|
||||||
|
$model->attributes['internal_id'] = 'TN-INR-'.$model->id;
|
||||||
|
|
||||||
|
$invoices = Invoice::whereBetween('date', [$model->date_start, $model->date_end])
|
||||||
|
->where('customer_id', $model->customer_id)->get()->pluck('id')->toArray();
|
||||||
|
|
||||||
|
$model->invoices()->sync($invoices);
|
||||||
|
|
||||||
|
$model->save();
|
||||||
|
});
|
||||||
|
|
||||||
|
// todo: sync all invoices within time and customer constraints
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function customer(): BelongsTo
|
public function customer(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Customer::class);
|
return $this->belongsTo(Customer::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function invoices(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->BelongsToMany(Invoice::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function orders(): HasManyThrough
|
||||||
|
{
|
||||||
|
return $this->hasManyThrough(Order::class, Invoice::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ public function up(): void
|
|||||||
{
|
{
|
||||||
Schema::create('invoice_reports', function (Blueprint $table) {
|
Schema::create('invoice_reports', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
|
$table->string('internal_id')->nullable();
|
||||||
|
|
||||||
$table->foreignId('customer_id')->constrained();
|
$table->foreignId('customer_id')->constrained();
|
||||||
|
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('invoice_invoice_report', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
|
||||||
|
$table->foreignId('invoice_id')->constrained();
|
||||||
|
$table->foreignId('invoice_report_id')->constrained();
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('invoice_invoice_report');
|
||||||
|
}
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user