work on reports

orders
Nisse Lommerde 2 weeks ago
parent fdbc2653d4
commit fcb1eda56f

@ -42,7 +42,6 @@ class EditOrder extends EditRecord
// Product Services
foreach ($order->productServices as $key => $service) {
$data['services'][$key] = [
'service_type' => $service->service_type ?? '',
'placement' => $service->placement ?? '',
'amount' => $service->amount ?? '',
'amount_price' => $service->amount_price ?? '',
@ -53,6 +52,9 @@ class EditOrder extends EditRecord
'serviceFileCode' => $service->serviceFile->code ?? '',
'serviceFileSetupNumber' => $service->serviceFile->setup_number ?? '',
];
//todo ServiceType
// $service->serviceType()->associate(ServiceType::)
}
foreach (OrderAttributes::cases() as $case) {

@ -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';
}
}

@ -21,7 +21,6 @@ class Invoice extends Model
'total',
'gst',
'pst',
'paid',
'date',
];
@ -46,14 +45,6 @@ class Invoice extends Model
});
}
public function setPaid(bool $value): void
{
if ($this->paid != $value) {
$this->paid = $value;
$this->save();
}
}
public function setStatus(InvoiceStatus $status)
{
if ($this->status !== $status) {

@ -16,7 +16,7 @@ class ProductService extends Model
protected $fillable = [
'order_id',
'service_file_id',
'service_type',
// 'service_type',
'placement',
'setup_amount',
'amount',
@ -29,6 +29,11 @@ class ProductService extends Model
'price',
];
// public function getServiceType(): string
// {
// return $this->serviceType->name ?? '';
// }
public function getPriceAttribute(): float
{
return number_format($this->amount * $this->amount_price, 2);
@ -41,17 +46,16 @@ class ProductService extends Model
return $file->name.', '.$this->placement.', '.$file->width.' W, '.$file->height.' H';
}
/**
* @return BelongsTo<Order, self>
*/
public function serviceType(): BelongsTo
{
return $this->belongsTo(ServiceType::class);
}
public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
}
/**
* @return BelongsTo<ServiceFile, self>
*/
public function serviceFile(): BelongsTo
{
return $this->BelongsTo(ServiceFile::class);

@ -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);
}
}

@ -21,7 +21,6 @@ class InvoiceFactory extends Factory
'gst' => true,
'pst' => $this->faker->boolean(25),
'status' => $this->faker->randomElement(InvoiceStatus::cases())->value,
'paid' => $this->faker->boolean(),
'customer_id' => $customer->id,
'updated_at' => Carbon::now(),
];

@ -15,10 +15,9 @@ class ProductServiceFactory extends Factory
return [
'created_at' => Carbon::now(),
'updated_at' => Carbon::now(),
'service_type' => $this->faker->randomElement(['EMB', 'SCP', 'DTG', 'VINYL']),
'placement' => $this->faker->randomElement(['L/C', 'C/F', 'F/B', 'R/C']),
'amount' => $this->faker->randomNumber(1),
'amount_price' => random_int(1, 15),
'amount_price' => rand(1, 15),
'notes' => $this->faker->randomElement(['1) 1149 2) GREY 3) WHITE', '1) WHITE', '1) BLACK 2) WHITE']),
];
}

@ -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],
];
}
}

@ -21,7 +21,6 @@ return new class extends Migration
$table->boolean('gst')->default(0);
$table->boolean('pst')->default(0);
$table->boolean('paid')->default(0);
$table->date('date')->default(today());
$table->date('due_date')->nullable();

@ -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');
}
};

@ -10,13 +10,17 @@ return new class extends Migration
{
Schema::create('product_services', function (Blueprint $table) {
$table->id();
$table->foreignId('order_id');
$table->foreignId('service_file_id')->nullable();
$table->string('service_type')->nullable();
$table->foreignId('service_type_id')->nullable();
// $table->string('service_type')->nullable();
$table->string('placement')->nullable();
$table->string('amount')->nullable();
$table->string('amount_price')->nullable();
$table->string('notes')->nullable();
$table->softDeletes();
$table->timestamps();
});

@ -21,6 +21,7 @@ class DatabaseSeeder extends Seeder
OrderSeeder::class,
OrderProductSeeder::class,
ProductSizeSeeder::class,
ServiceTypeSeeder::class,
ProductServiceSeeder::class,
ServiceFileSeeder::class,
QuoteSeeder::class,

@ -4,6 +4,7 @@ namespace Database\Seeders;
use App\Models\Order;
use App\Models\ProductService;
use App\Models\ServiceType;
use Illuminate\Database\Seeder;
class ProductServiceSeeder extends Seeder
@ -14,7 +15,10 @@ class ProductServiceSeeder extends Seeder
public function run(): void
{
foreach (Order::all() as $order) {
ProductService::factory(rand(1, 4), ['order_id' => $order->id])->create();
ProductService::factory(rand(1, 4), [
'order_id' => $order->id,
'service_type_id' => ServiceType::find(rand(1, count(ServiceType::all()))),
])->create();
}
}
}

@ -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],
]);
}
}
}

@ -351,7 +351,7 @@
<div class="col-1 px-1 fw-bold" style="width: 40px;">{{$loop->index+1}}</div>
<div class="col-1 px-2 fw-bold text-uppercase">
<!-- Service type -->
{{$service->service_type}}
{{$service->serviceType->name}}
</div>
<div class="col-2 px-1 text-uppercase">
{{$service->placement}}

Binary file not shown.
Loading…
Cancel
Save