work on reports
parent
fdbc2653d4
commit
fcb1eda56f
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\ProductServiceReportResource\Pages;
|
||||
use App\Models\ProductService;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ProductServiceReportResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ProductService::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Reports';
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
//
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
])
|
||||
->bulkActions([
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListProductServiceReports::route('/'),
|
||||
'create' => Pages\CreateProductServiceReport::route('/create'),
|
||||
'edit' => Pages\EditProductServiceReport::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProductServiceReportResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ProductServiceReportResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateProductServiceReport extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ProductServiceReportResource::class;
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProductServiceReportResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ProductServiceReportResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditProductServiceReport extends EditRecord
|
||||
{
|
||||
protected static string $resource = ProductServiceReportResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ProductServiceReportResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ProductServiceReportResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListProductServiceReports extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProductServiceReportResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\ServiceTypeResource\Pages;
|
||||
use App\Filament\Resources\ServiceTypeResource\Widgets\ServiceTypeOverview;
|
||||
use App\Models\ServiceType;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ServiceTypeResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ServiceType::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Reports';
|
||||
|
||||
protected static ?string $label = 'Product Services';
|
||||
|
||||
public static function getWidgets(): array
|
||||
{
|
||||
return [
|
||||
ServiceTypeOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->getStateUsing(function () {
|
||||
return 'test';
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('quantity'),
|
||||
Tables\Columns\TextColumn::make('amount')
|
||||
->prefix('$'),
|
||||
Tables\Columns\TextColumn::make('salesPercentage')
|
||||
->suffix('%')
|
||||
->label('Percentage'),
|
||||
Tables\Columns\TextColumn::make('averagePrice')
|
||||
->prefix('$'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
])
|
||||
->bulkActions([
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListServiceTypes::route('/'),
|
||||
'create' => Pages\CreateServiceType::route('/create'),
|
||||
'edit' => Pages\EditServiceType::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServiceTypeResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ServiceTypeResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateServiceType extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ServiceTypeResource::class;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServiceTypeResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ServiceTypeResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditServiceType extends EditRecord
|
||||
{
|
||||
protected static string $resource = ServiceTypeResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServiceTypeResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ServiceTypeResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListServiceTypes extends ListRecords
|
||||
{
|
||||
protected static string $resource = ServiceTypeResource::class;
|
||||
|
||||
protected function getHeaderWidgets(): array
|
||||
{
|
||||
return [
|
||||
// ServiceTypeResource\Widgets\ServiceTypeOverview::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
// Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ServiceTypeResource\Widgets;
|
||||
|
||||
use Filament\Widgets\ChartWidget;
|
||||
|
||||
class ServiceTypeOverview extends ChartWidget
|
||||
{
|
||||
protected static ?string $heading = 'Services';
|
||||
|
||||
protected static ?string $maxHeight = '200px';
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Test Label',
|
||||
'data' => [30, 15, 25, 30],
|
||||
],
|
||||
],
|
||||
'labels' => [
|
||||
'Test 1',
|
||||
'Test 2',
|
||||
'Test 3',
|
||||
'Test 4',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'pie';
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ServiceType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'value',
|
||||
];
|
||||
|
||||
protected $appends = [
|
||||
'quantity',
|
||||
'amount',
|
||||
'sales_percentage',
|
||||
'average_price',
|
||||
];
|
||||
|
||||
//to do: date between?
|
||||
|
||||
public function getQuantityAttribute(): int
|
||||
{
|
||||
return $this->productServices()->sum('amount');
|
||||
}
|
||||
|
||||
public function getAmountAttribute(): string
|
||||
{
|
||||
return number_format($this->productServices()->sum('amount_price'), 2);
|
||||
}
|
||||
|
||||
public function getSalesPercentageAttribute(): float
|
||||
{
|
||||
$total = ProductService::all()->count();
|
||||
$part = ProductService::where('service_type_id', $this->id)->count();
|
||||
|
||||
return round(($part / $total) * 100, 2);
|
||||
}
|
||||
|
||||
public function getAveragePriceAttribute(): string
|
||||
{
|
||||
return number_format(floatval($this->amount) / $this->quantity, 2);
|
||||
}
|
||||
|
||||
public function productServices(): HasMany
|
||||
{
|
||||
return $this->hasMany(ProductService::class);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Model>
|
||||
*/
|
||||
class ServiceTypeFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$values = [
|
||||
'Emb' => 'Embroidery',
|
||||
'Scp' => 'Screen Printing',
|
||||
'Dtf' => 'Direct-to-film',
|
||||
'Vyl' => 'Vinyl',
|
||||
];
|
||||
|
||||
$key = array_rand($values);
|
||||
|
||||
return [
|
||||
'name' => $key,
|
||||
'value' => $values[$key],
|
||||
];
|
||||
}
|
||||
}
|
@ -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('service_types', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('name');
|
||||
$table->string('value');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('service_types');
|
||||
}
|
||||
};
|
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\ServiceType;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class ServiceTypeSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$services = [
|
||||
['Emb', 'Embroidery'],
|
||||
['Scp', 'Screen Printing'],
|
||||
['Dtf', 'Direct-to-film'],
|
||||
['Vyl', 'Vinyl'],
|
||||
];
|
||||
|
||||
foreach ($services as $service) {
|
||||
ServiceType::create([
|
||||
'name' => $service[0],
|
||||
'value' => $service[1],
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue