79 lines
2.6 KiB
PHP
79 lines
2.6 KiB
PHP
<?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;
|
|
|
|
use App\Models\Filament;
|
|
use App\Models\FilamentType;
|
|
use App\Models\Manufacturer;
|
|
use App\Models\Color;
|
|
|
|
#[title('Calculator')]
|
|
class Calculator extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public string $selection = '1';
|
|
public float $time = 0;
|
|
public string $timeunit = 'h';
|
|
public float $additionalcost = 0;
|
|
public string $additionalcostunit = 'per Piece';
|
|
public int $countonplate = 0;
|
|
public int $selcountonplate = 0;
|
|
public string $search_type = '';
|
|
public string $search_manufacturer = '';
|
|
public string $search_name = '';
|
|
public string $search_color = '';
|
|
|
|
public array $selectedFilaments = []; // [filament_id => amount_g]
|
|
|
|
public function toggleFilament($filamentId)
|
|
{
|
|
if (isset($this->selectedFilaments[$filamentId])) {
|
|
unset($this->selectedFilaments[$filamentId]);
|
|
} else {
|
|
$this->selectedFilaments[$filamentId] = 0;
|
|
}
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
$filaments = Filament::query()
|
|
->where(function ($query) {
|
|
$query->when($this->search_type, function ($query) {
|
|
$query->whereHas('type', function ($q) {
|
|
$q->where('name', $this->search_type);
|
|
});
|
|
})
|
|
->when($this->search_manufacturer, function ($query) {
|
|
$query->whereHas('manufacturer', function ($q) {
|
|
$q->where('name', 'like', '%' . $this->search_manufacturer . '%');
|
|
});
|
|
})
|
|
->when($this->search_name, function ($query) {
|
|
$query->where('name', 'like', '%' . $this->search_name . '%');
|
|
})
|
|
->when($this->search_color, function ($query) {
|
|
$query->whereHas('color', function ($q) {
|
|
$q->where('name', 'like', '%' . $this->search_color . '%');
|
|
});
|
|
});
|
|
})
|
|
->orWhereIn('id', array_keys($this->selectedFilaments))
|
|
->with(['type', 'manufacturer', 'color'])
|
|
->get();
|
|
|
|
return view('livewire.calculator', [
|
|
'presets' => \App\Models\Calculationpreset::all(),
|
|
'calculationpreset' => \App\Models\Calculationpreset::find($this->selection),
|
|
'filaments' => $filaments,
|
|
'filamenttypes' => FilamentType::all(),
|
|
]);
|
|
}
|
|
}
|