Add Calculationpresets and Calculator modules with CRUD functionality, migrations, and UI components.

This commit is contained in:
2026-01-24 13:23:03 +01:00
parent fd61f14ffe
commit 0356063015
14 changed files with 560 additions and 2 deletions
@@ -0,0 +1,43 @@
<?php
namespace App\Livewire\Calculationpreset;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use App\Models\Calculationpreset as Model;
use Livewire\WithPagination;
use Livewire\Attributes\title;
#[title('Calculationpreset')]
class Calculationpreset extends Component
{
use WithPagination;
public Model $calculationpreset ;
public $search = '';
public function create(){
return $this->redirectRoute('calculationpresets.create', navigate: true);
}
public function show($id){
return $this->redirectRoute('calculationpresets.show', $id);
}
public function edit($id){
return $this->redirectRoute('calculationpresets.edit', $id);
}
public function delete($id){
@Auth::check();
Model::destroy($id);
}
public function render()
{
return view('livewire.calculationpreset.index', [
'calculationpresets' => Model::search('name', $this->search)->paginate(25)
]);
}
}
@@ -0,0 +1,55 @@
<?php
namespace App\Livewire\Calculationpreset;
use Livewire\Attributes\Validate;
use Livewire\Component;
use App\Models\Calculationpreset as Model;
use Livewire\Attributes\title;
#[title('Create Calculationpreset')]
class CreateCalculationpreset extends Component
{
public Model $calculationpreset ;
public string $name = '';
public string $description = '';
public float $price_kwh = 0;
public float $factor_printer = 0;
public float $factor_maintenance = 0;
public float $factor_price = 0;
#[Validate('required')]
public function save(){
$this->validate([
'name' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string', 'max:255'],
'price_kwh' => ['required', 'numeric'],
'factor_printer' => ['nullable', 'numeric'],
'factor_maintenance' => ['nullable', 'numeric'],
'factor_price' => ['nullable', 'numeric']
]);
$calculationpreset = new Model();
$calculationpreset->name = $this->name;
$calculationpreset->description = $this->description;
$calculationpreset->price_kwh = $this->price_kwh;
$calculationpreset->factor_printer = $this->factor_printer;
$calculationpreset->factor_maintenance = $this->factor_maintenance;
$calculationpreset->factor_price = $this->factor_price;
$calculationpreset->save();
return $this->redirectRoute('calculationpresets.show', $calculationpreset->id, navigate: true);
}
public function cancel(){
return $this->redirectRoute('calculationpresets.index', navigate: true);
}
public function render()
{
return view('livewire.calculationpreset.create', [
]);
}
}
@@ -0,0 +1,64 @@
<?php
namespace App\Livewire\Calculationpreset;
use Livewire\Attributes\Validate;
use Livewire\Component;
use App\Models\Calculationpreset as Model;
use Livewire\Attributes\title;
#[title('Edit Calculationpreset')]
class EditCalculationpreset extends Component
{
public Model $calculationpreset ;
public string $name = '';
public string $description = '';
public float $price_kwh = 0;
public float $factor_printer = 0;
public float $factor_maintenance = 0;
public float $factor_price = 0;
#[Validate('required')]
public function save(){
$this->validate([
'name' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string', 'max:255'],
'price_kwh' => ['required', 'numeric'],
'factor_printer' => ['nullable', 'numeric'],
'factor_maintenance' => ['nullable', 'numeric'],
'factor_price' => ['nullable', 'numeric']
]);
$this->calculationpreset->update([
'name' => $this->name,
'description' => $this->description,
'price_kwh' => $this->price_kwh,
'factor_printer' => $this->factor_printer,
'factor_maintenance' => $this->factor_maintenance,
'factor_price' => $this->factor_price
]);
return $this->redirectRoute('calculationpresets.show', $this->calculationpreset->id, navigate: true);
}
public function cancel(){
return $this->redirectRoute('calculationpresets.index', navigate: true);
}
public function mount(Model $calculationpreset){
$this->calculationpreset = $calculationpreset;
$this->name = $calculationpreset->name;
$this->description = $calculationpreset->description;
$this->price_kwh = $calculationpreset->price_kwh;
$this->factor_printer = $calculationpreset->factor_printer;
$this->factor_maintenance = $calculationpreset->factor_maintenance;
$this->factor_price = $calculationpreset->factor_price;
}
public function render()
{
return view('livewire.calculationpreset.create', [
]);
}
}
@@ -0,0 +1,29 @@
<?php
namespace App\Livewire\Calculationpreset;
use Livewire\Component;
use App\Models\Calculationpreset as Model;
use Livewire\Attributes\title;
#[title('Show Calculationpreset')]
class ShowCalculationpreset extends Component
{
public Model $calculationpreset ;
public function back(){
return redirect()->route('calculationpresets.index');
}
public function edit($id){
return redirect()->route('calculationpresets.edit', $id);
}
public function render()
{
return view('livewire.calculationpreset.show', [
]);
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace App\Livewire\Calculator;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use App\Models\Calculationpreset as Model;
use Livewire\WithPagination;
use Livewire\Attributes\title;
#[title('Calculator')]
class Calculator extends Component
{
use WithPagination;
public Model $calculationpreset ;
public function render()
{
return view('livewire.calculator', [
]);
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Calculationpreset extends Model
{
// Calculationpreset Model
protected $table = 'calculatorpresets';
protected $primaryKey = 'id';
protected $fillable = [
'name',
'description',
'price_kwh',
'factor_printer',
'factor_maintenance',
'factor_price'
];
}
@@ -0,0 +1,33 @@
<?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('calculatorpresets', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description')->nullable();
$table->decimal('price_kwh', 10, 2);
$table->decimal('factor_printer', 10, 2);
$table->decimal('factor_maintenance', 10, 2);
$table->decimal('factor_price', 10, 2);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('calculatorpresets');
}
};
+2 -2
View File
@@ -9,7 +9,7 @@
<flux:navbar.item wire:navigate icon="home" href="{{ route('dashboard') }}">
Dashboard
</flux:navbar.item>
<flux:navbar.item wire:navigate icon="calculator" href="{{ route('filaments.index') }}">
<flux:navbar.item wire:navigate icon="calculator" href="{{ route('calculator.index') }}">
Calculator
</flux:navbar.item>
<flux:navbar.item wire:navigate icon="shopping-bag" href="{{ route('orders.index') }}">
@@ -48,7 +48,7 @@
<flux:navmenu.item wire:navigate icon="beaker" href="{{ route('printertypes.index') }}">
PrinterTypes
</flux:navmenu.item>
<flux:navmenu.item wire:navigate icon="calculator" href="{{ route('manufacturer.index') }}">
<flux:navmenu.item wire:navigate icon="calculator" href="{{ route('calculationpresets.index') }}">
Calculation Presets
</flux:navmenu.item>
<flux:menu.separator />
@@ -0,0 +1,74 @@
<section>
<form wire:submit="save">
<x-header>
{{ __('Create Calculationpreset') }}
<x-slot name="headerright">
<flux:button type="submit" variant="primary" class="bg-selective hover:bg-selective-600 text-gray-950 hover:cursor-pointer transition-all ease-in-out" icon="check">Save</flux:button>
<flux:button wire:click="cancel" variant="primary" class=" bg-red-700 shadow hover:bg-red-800 hover:cursor-pointer transition-all ease-in-out" icon="x-mark">Cancel</flux:button>
</x-slot>
</x-header>
<div class="container m-auto my-8 bg-elephant-950 border border-elephant-900 rounded-lg shadow p-6 text-gray-50">
<div>
<div class="px-4 sm:px-0">
<h3 class="text-base/7 font-semibold text-white">Calculationpreset Information</h3>
<p class="mt-1 max-w-2xl text-sm/6 text-gray-200">Calculationpreset details.</p>
</div>
<div class="mt-6 border-t border-white/10">
<dl class="divide-y divide-white/10">
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Name</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:input wire:model="name" type="text" class="mt-1 block w-full"/>
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Description</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:textarea wire:model="description" type="text" class="mt-1 block w-full"/>
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Price kW/h</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:input.group>
<flux:input wire:model="price_kwh" type="text" class="mt-1 block w-full"/>
<flux:input.group.suffix></flux:input.group.suffix>
</flux:input.group>
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Factor Printer</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:input.group>
<flux:input wire:model="factor_printer" type="text" class="mt-1 block w-full"/>
<flux:input.group.suffix></flux:input.group.suffix>
</flux:input.group>
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Factor Maintenance</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:input.group>
<flux:input wire:model="factor_maintenance" type="text" class="mt-1 block w-full"/>
<flux:input.group.suffix></flux:input.group.suffix>
</flux:input.group>
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Factor Price</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:input.group>
<flux:input wire:model="factor_price" type="text" class="mt-1 block w-full"/>
<flux:input.group.suffix>%</flux:input.group.suffix>
</flux:input.group>
</dd>
</div>
</dl>
</div>
</div>
</div>
</form>
</section>
@@ -0,0 +1,74 @@
<section>
<form wire:submit="save">
<x-header>
{{ __('Edit Calculationpreset') }}
<x-slot name="headerright">
<flux:button type="submit" variant="primary" class="bg-selective hover:bg-selective-600 text-gray-950 hover:cursor-pointer transition-all ease-in-out" icon="check">Save</flux:button>
<flux:button wire:click="cancel" variant="primary" class=" bg-red-700 shadow hover:bg-red-800 hover:cursor-pointer transition-all ease-in-out" icon="x-mark">Cancel</flux:button>
</x-slot>
</x-header>
<div class="container m-auto my-8 bg-elephant-950 border border-elephant-900 rounded-lg shadow p-6 text-gray-50">
<div>
<div class="px-4 sm:px-0">
<h3 class="text-base/7 font-semibold text-white">Calculationpreset Information</h3>
<p class="mt-1 max-w-2xl text-sm/6 text-gray-200">Calculationpreset details.</p>
</div>
<div class="mt-6 border-t border-white/10">
<dl class="divide-y divide-white/10">
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Name</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:input wire:model="name" type="text" class="mt-1 block w-full"/>
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Description</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:textarea wire:model="description" type="text" class="mt-1 block w-full"/>
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Price kW/h</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:input.group>
<flux:input wire:model="price_kwh" type="text" class="mt-1 block w-full"/>
<flux:input.group.suffix></flux:input.group.suffix>
</flux:input.group>
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Factor Printer</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:input.group>
<flux:input wire:model="factor_printer" type="text" class="mt-1 block w-full"/>
<flux:input.group.suffix></flux:input.group.suffix>
</flux:input.group>
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Factor Maintenance</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:input.group>
<flux:input wire:model="factor_maintenance" type="text" class="mt-1 block w-full"/>
<flux:input.group.suffix></flux:input.group.suffix>
</flux:input.group>
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Factor Price</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
<flux:input.group>
<flux:input wire:model="factor_price" type="text" class="mt-1 block w-full"/>
<flux:input.group.suffix>%</flux:input.group.suffix>
</flux:input.group>
</dd>
</div>
</dl>
</div>
</div>
</div>
</form>
</section>
@@ -0,0 +1,53 @@
<section>
<x-header>
{{ __('Calculationpreset') }}
<x-slot name="headerleft">
<input type="text" placeholder="Search..." wire:model.live="search" class="bg-black/10 border-white/20 rounded text-gray-50 placeholder:text-gray-200 focus:border-white/50 focus:ring-white/50" />
</x-slot>
<x-slot name="headerright">
<flux:button wire:click="create" variant="primary" class="bg-selective hover:bg-selective-600 text-gray-950 transition ease-in-out hover:cursor-pointer">Create Calculationpreset</flux:button>
</x-slot>
</x-header>
<div class="container m-auto my-8 bg-elephant border border-elephant-900 rounded-lg shadow p-6 text-gray-50">
</div>
<div class="container m-auto my-8 bg-elephant border border-elephant-900 rounded-lg shadow p-6 text-gray-50">
<x-table>
<x-slot name="tableheader">
<x-table.header class="w-[50px]">ID</x-table.header>
<x-table.header>Name</x-table.header>
<x-table.header>Price kw/h</x-table.header>
<x-table.header>Factor Printer</x-table.header>
<x-table.header>Factor Maintenance</x-table.header>
<x-table.header>Factor Price</x-table.header>
<x-table.header class="w-[150px]">Actions</x-table.header>
</x-slot>
@foreach ($calculationpresets as $calculationpreset)
<tr wire:key="{{ $calculationpreset->id }}" class="text-gray-200 border-b border-white/50 hover:bg-white/10 transition duration-150 ease-in-out">
<x-table.item><p class="p-4 px-3 pl-6">{{ $calculationpreset->id }}</p></x-table.item>
<x-table.item><p class="p-4 px-3 font-bold">{{ $calculationpreset->name }}</p></x-table.item>
<x-table.item><p class="p-4 px-3">{{ $calculationpreset->price_kwh }}/kWh</p></x-table.item>
<x-table.item><p class="p-4 px-3">{{ $calculationpreset->factor_printer }}/h</p></x-table.item>
<x-table.item><p class="p-4 px-3">{{ $calculationpreset->factor_maintenance }}/h</p></x-table.item>
<x-table.item><p class="p-4 px-3">{{ $calculationpreset->factor_price }}%</p></x-table.item>
<x-table.item>
<div class="flex flex-row gap-4 justify-end pr-8">
<flux:button variant="primary" class="text-gray-200 bg-transparent shadow-none hover:bg-cornflower hover:shadow hover:text-gray-950 hover:cursor-pointer" wire:click="show({{ $calculationpreset->id }})" icon="magnifying-glass"></flux:button>
<flux:button variant="primary" class="text-gray-200 bg-transparent shadow-none hover:bg-gold-drop hover:shadow hover:text-gray-950 hover:cursor-pointer" wire:click="edit({{ $calculationpreset->id }})" icon="pencil"></flux:button>
<flux:button variant="primary" class="text-gray-200 bg-transparent shadow-none hover:bg-red-700 hover:shadow hover:cursor-pointer" wire:click="delete({{ $calculationpreset->id }})" icon="trash"></flux:button>
</div>
</x-table.item>
</tr>
@endforeach
<x-slot name="pagination">
{{ $calculationpresets->links() }}
</x-slot>
</x-table>
</div>
</section>
@@ -0,0 +1,62 @@
<section>
<form wire:submit="save">
<x-header>
{{ __('Show Calculationpreset') }}
<x-slot name="headerright">
<flux:button wire:click="back" variant="primary" class="bg-transparent shadow-none text-gray-50 hover:bg-black/10 hover:cursor-pointer transition-all ease-in-out" icon="arrow-left">Back</flux:button>
<flux:button wire:click="edit({{ $calculationpreset->id }})" variant="primary" class="bg-selective text-gray-950 shadow-none hover:bg-selective-600 hover:cursor-pointer transition-all ease-in-out" icon="check">Edit</flux:button>
</x-slot>
</x-header>
<div class="container m-auto my-8 bg-elephant-950 border border-elephant-900 rounded-lg shadow p-6 text-gray-50">
<div>
<div class="px-4 sm:px-0">
<h3 class="text-base/7 font-semibold text-white">Calculationpreset Information</h3>
<p class="mt-1 max-w-2xl text-sm/6 text-gray-200">Calculationpreset details.</p>
</div>
<div class="mt-6 border-t border-white/10">
<dl class="divide-y divide-white/10">
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Name</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
{{ $calculationpreset->name }}
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Description</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
{{ $calculationpreset->description }}
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Price kW/h</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
{{ $calculationpreset->price_kwh }}
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Factor Printer</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
{{ $calculationpreset->factor_printer }}
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Factor Maintenance</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
{{ $calculationpreset->factor_maintenance }}
</dd>
</div>
<div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0 items-center">
<dt class="text-sm/6 font-medium text-gray-100">Factor Price</dt>
<dd class="mt-1 text-sm/6 text-gray-200 sm:col-span-2 sm:mt-0">
{{ $calculationpreset->factor_price }} %
</dd>
</div>
</dl>
</div>
</div>
</div>
</form>
</section>
@@ -0,0 +1,17 @@
<div>
<x-header>
{{ __('Calculator') }}
<x-slot name="headerleft">
<flux:select wire:model.live="calculationpreset" placeholder="Select a preset">
@foreach ( \App\Models\Calculationpreset::all() as $preset)
<flux:select.option value="{{ $preset->id }}">{{ $preset->name }}</flux:select.option>
@endforeach
</flux:select>
</x-slot>
</x-header>
<div class="container m-auto my-8 bg-elephant border border-elephant-900 rounded-lg shadow p-6 text-gray-50">
{{ $preset->name }} : {{ $preset->price_kwh }}
</div>
</div>
+11
View File
@@ -13,6 +13,8 @@ use App\Livewire\Type\EditType;
use App\Livewire\Type\Type;
use App\Livewire\Printertype\Printertype;
use App\Livewire\Printer\Printer;
use App\Livewire\Calculationpreset\Calculationpreset;
use App\Livewire\Calculator\Calculator;
use Illuminate\Support\Facades\Route;
@@ -83,6 +85,15 @@ Route::middleware([
Route::get('extruder/{extruder}/edit', \App\Livewire\Extruder\EditExtruder::class)->name('extruder.edit');
Route::get('extruder/{extruder}', \App\Livewire\Extruder\ShowExtruder::class)->name('extruder.show');
// Calculationpresets
Route::get('calculationpresets', Calculationpreset::class)->name('calculationpresets.index');
Route::get('calculationpresets/create', \App\Livewire\Calculationpreset\CreateCalculationpreset::class)->name('calculationpresets.create');
Route::get('calculationpresets/{calculationpreset}/edit', \App\Livewire\Calculationpreset\EditCalculationpreset::class)->name('calculationpresets.edit');
Route::get('calculationpresets/{calculationpreset}', \App\Livewire\Calculationpreset\ShowCalculationpreset::class)->name('calculationpresets.show');
// Calculator
Route::get('calculator', Calculator::class)->name('calculator.index');
// Orders
Route::get('orders', Orders::class)->name('orders.index');