Files
jouwdriedee/resources/views/admin/products/create.blade.php
T

504 lines
29 KiB
PHP

@extends('layouts.admin')
@section('title', 'Nieuw Product Toevoegen | Jouwdriedee Beheer')
@section('content')
<div class="space-y-6 max-w-5xl mx-auto"
x-data="{
basePrice: '{{ old('base_price', '14.95') }}',
weightGrams: {{ old('weight_grams', 85) }},
printTimeHours: {{ old('print_time_hours', 4.0) }},
colorCount: 1,
material: 'pla',
markupPercent: {{ setting('calc_default_markup', 65.0) }},
showCalculator: true,
rates: {
filamentPriceKg: {{ setting('calc_filament_price_kg', 20.00) }},
electricityKwh: {{ setting('calc_electricity_kwh', 0.35) }},
machineHourly: {{ setting('calc_machine_hourly_rate', 0.50) }},
handlingFlat: {{ setting('calc_handling_flat', 1.50) }},
failureRate: {{ setting('calc_failure_rate', 5.0) }}
},
colorWasteMults: { 1: 1.0, 2: 1.15, 3: 1.25, 4: 1.35 },
materialMults: { 'pla': 1.0, 'petg': 1.20, 'silk': 1.30, 'tpu': 1.40 },
get effectiveWeight() {
let mult = this.colorWasteMults[this.colorCount] || 1.0;
return (this.weightGrams * mult).toFixed(1);
},
get purgeWasteGrams() {
return Math.max(0, this.effectiveWeight - this.weightGrams).toFixed(1);
},
get materialCost() {
let matMult = this.materialMults[this.material] || 1.0;
return ((this.effectiveWeight / 1000) * (this.rates.filamentPriceKg * matMult)).toFixed(2);
},
get electricityCost() {
return (this.printTimeHours * 0.15 * this.rates.electricityKwh).toFixed(2);
},
get machineCost() {
return (this.printTimeHours * this.rates.machineHourly).toFixed(2);
},
get handlingCost() {
let extraColorFee = Math.max(0, this.colorCount - 1) * 0.50;
return (this.rates.handlingFlat + extraColorFee).toFixed(2);
},
get subtotalCost() {
return (parseFloat(this.materialCost) + parseFloat(this.electricityCost) + parseFloat(this.machineCost) + parseFloat(this.handlingCost)).toFixed(2);
},
get failureCost() {
return (parseFloat(this.subtotalCost) * (this.rates.failureRate / 100)).toFixed(2);
},
get totalProductionCost() {
return (parseFloat(this.subtotalCost) + parseFloat(this.failureCost)).toFixed(2);
},
get priceExclVat() {
return (parseFloat(this.totalProductionCost) * (1 + this.markupPercent / 100)).toFixed(2);
},
get suggestedPrice() {
let rawWithVat = parseFloat(this.priceExclVat) * 1.21;
if (rawWithVat <= 7.0) return '6.95';
let floor = Math.floor(rawWithVat);
let fraction = rawWithVat - floor;
if (fraction <= 0.25) {
return (floor < rawWithVat ? floor + 0.50 : floor - 0.05).toFixed(2);
} else if (fraction <= 0.70) {
return (floor + 0.50).toFixed(2);
} else {
return (floor + 0.95).toFixed(2);
}
},
applySuggestedPrice() {
this.basePrice = this.suggestedPrice;
}
}">
<!-- Header -->
<div class="flex items-center justify-between pb-5 border-b border-slate-200/60">
<div>
<a href="{{ route('admin.products.index') }}" class="text-xs text-slate-500 hover:text-slate-900 font-medium inline-flex items-center space-x-1 mb-1">
<i data-lucide="arrow-left" class="w-3.5 h-3.5"></i>
<span>Terug naar Producten</span>
</a>
<h1 class="font-heading text-2xl font-bold text-slate-900 tracking-tight">Nieuw Product Toevoegen</h1>
</div>
</div>
<!-- Create Form -->
<form action="{{ route('admin.products.store') }}" method="POST" class="space-y-6">
@csrf
<div class="p-6 sm:p-7 rounded-2xl bg-white border border-slate-200/60 shadow-2xs space-y-6">
<!-- Basis Informatie -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="md:col-span-2 space-y-1.5">
<label class="block text-xs font-medium text-slate-700">Productnaam *</label>
<input type="text" name="name" value="{{ old('name') }}" required placeholder="bijv. Articulated Mecha Robot" class="w-full bg-slate-50/70 focus:bg-white border border-slate-200 rounded-lg px-3 py-2 text-xs text-slate-900 font-medium focus:outline-none focus:ring-1 focus:ring-slate-400 transition">
</div>
<div class="space-y-1.5">
<label class="block text-xs font-medium text-slate-700">Categorie *</label>
<select name="category_id" required class="w-full bg-slate-50/70 focus:bg-white border border-slate-200 rounded-lg px-3 py-2 text-xs text-slate-900 font-medium">
@foreach($categories as $cat)
<option value="{{ $cat->id }}" {{ old('category_id') == $cat->id ? 'selected' : '' }}>
{{ $cat->name }}
</option>
@endforeach
</select>
</div>
</div>
<!-- ==================================================== -->
<!-- 3D PRINT KOSTPRIJSCALCULATOR WIDGET (Sleek & Subtle) -->
<!-- ==================================================== -->
<div class="p-4 sm:p-5 rounded-xl bg-slate-50/70 border border-slate-200/70 space-y-4">
<div class="flex items-center justify-between">
<div class="flex items-center space-x-2">
<i data-lucide="calculator" class="w-4 h-4 text-slate-500"></i>
<h3 class="text-xs font-semibold text-slate-900 uppercase tracking-wider">3D Print Kostprijscalculator</h3>
<span class="px-2 py-0.5 rounded-full bg-slate-200/70 text-slate-700 font-mono text-[10px]">Formule</span>
</div>
<button type="button" @click="showCalculator = !showCalculator" class="text-xs text-slate-500 hover:text-slate-800 font-medium flex items-center space-x-1 cursor-pointer">
<span x-text="showCalculator ? 'Inklappen' : 'Openen'"></span>
<i data-lucide="chevron-down" class="w-3.5 h-3.5 transition-transform" :class="showCalculator ? 'rotate-180' : ''"></i>
</button>
</div>
<div x-show="showCalculator" x-transition class="space-y-4 pt-1">
<div class="grid grid-cols-2 sm:grid-cols-4 gap-3 text-xs">
<!-- Gewicht -->
<div class="space-y-1">
<label class="block text-[11px] font-medium text-slate-600">Gewicht</label>
<div class="relative">
<input type="number" x-model.number="weightGrams" min="1" max="5000" class="w-full bg-white border border-slate-200 rounded-lg px-2.5 py-1.5 text-xs font-semibold text-slate-900">
<span class="absolute right-2.5 top-1/2 -translate-y-1/2 text-[10px] text-slate-400">gram</span>
</div>
</div>
<!-- Printtijd -->
<div class="space-y-1">
<label class="block text-[11px] font-medium text-slate-600">Printduur</label>
<div class="relative">
<input type="number" step="0.1" x-model.number="printTimeHours" min="0.1" max="100" class="w-full bg-white border border-slate-200 rounded-lg px-2.5 py-1.5 text-xs font-semibold text-slate-900">
<span class="absolute right-2.5 top-1/2 -translate-y-1/2 text-[10px] text-slate-400">uur</span>
</div>
</div>
<!-- Aantal Kleuren (AMS Purge) -->
<div class="space-y-1">
<label class="block text-[11px] font-medium text-slate-600">Kleuren (AMS)</label>
<div class="grid grid-cols-4 gap-1">
<template x-for="c in [1, 2, 3, 4]" :key="c">
<button
type="button"
@click="colorCount = c"
class="py-1 rounded-md text-center font-medium text-xs transition border cursor-pointer"
:class="colorCount === c ? 'bg-slate-900 border-slate-900 text-white shadow-2xs' : 'bg-white border-slate-200 text-slate-600 hover:bg-slate-50'"
x-text="c"
></button>
</template>
</div>
</div>
<!-- Materiaalsoort -->
<div class="space-y-1">
<label class="block text-[11px] font-medium text-slate-600">Materiaalsoort</label>
<select x-model="material" class="w-full bg-white border border-slate-200 rounded-lg px-2.5 py-1.5 text-xs font-medium text-slate-900">
<option value="pla">Bio-PLA (1.0x)</option>
<option value="petg">PETG Tough (1.2x)</option>
<option value="silk">Silk Zijdeglans (1.3x)</option>
<option value="tpu">TPU Flexibel (1.4x)</option>
</select>
</div>
</div>
<!-- Marge Selector -->
<div class="flex flex-wrap items-center justify-between gap-2 pt-2 border-t border-slate-200/60 text-xs">
<div class="flex items-center space-x-2">
<span class="text-slate-500 font-medium text-[11px]">Marge:</span>
<div class="inline-flex rounded-lg border border-slate-200 bg-white p-0.5 text-[11px] font-medium">
<button type="button" @click="markupPercent = 35" :class="markupPercent === 35 ? 'bg-slate-900 text-white' : 'text-slate-600 hover:text-slate-900'" class="px-2 py-0.5 rounded transition">35%</button>
<button type="button" @click="markupPercent = 50" :class="markupPercent === 50 ? 'bg-slate-900 text-white' : 'text-slate-600 hover:text-slate-900'" class="px-2 py-0.5 rounded transition">50%</button>
<button type="button" @click="markupPercent = 65" :class="markupPercent === 65 ? 'bg-slate-900 text-white' : 'text-slate-600 hover:text-slate-900'" class="px-2 py-0.5 rounded transition">65%</button>
<button type="button" @click="markupPercent = 100" :class="markupPercent === 100 ? 'bg-slate-900 text-white' : 'text-slate-600 hover:text-slate-900'" class="px-2 py-0.5 rounded transition">100%</button>
</div>
</div>
<!-- Live Cost Breakdown -->
<div class="flex items-center space-x-3 text-[11px] text-slate-400 font-normal">
<span>Materiaal: €<span x-text="materialCost"></span></span>
<span>Stroom: €<span x-text="electricityCost"></span></span>
<span>Slijtage: €<span x-text="machineCost"></span></span>
<span class="font-semibold text-slate-700">Kostprijs: €<span x-text="totalProductionCost"></span></span>
</div>
</div>
<!-- Callout Strip -->
<div class="p-3 rounded-lg bg-white border border-slate-200/80 shadow-2xs flex flex-col sm:flex-row sm:items-center justify-between gap-3">
<div>
<span class="text-[10px] text-slate-400 uppercase font-medium block">Adviesprijs (incl. 21% btw)</span>
<div class="flex items-baseline space-x-1.5">
<span class="font-heading text-lg font-bold text-slate-900">€ <span x-text="suggestedPrice"></span></span>
<span class="text-[11px] text-slate-400">(op basis van <span x-text="weightGrams"></span>g &bull; <span x-text="printTimeHours"></span>u &bull; <span x-text="colorCount"></span> kleur)</span>
</div>
</div>
<button
type="button"
@click="applySuggestedPrice"
class="px-3.5 py-1.5 bg-slate-900 hover:bg-slate-800 text-white font-medium text-xs rounded-lg transition flex items-center justify-center space-x-1.5 cursor-pointer shadow-2xs"
>
<i data-lucide="check" class="w-3.5 h-3.5"></i>
<span>Neem Adviesprijs Over (€ <span x-text="suggestedPrice"></span>)</span>
</button>
</div>
</div>
</div>
<!-- Prijs & Korte Omschrijving -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="space-y-1.5">
<label class="block text-xs font-medium text-slate-700">Basisprijs (€) *</label>
<div class="relative">
<span class="absolute left-3 top-1/2 -translate-y-1/2 font-medium text-slate-400 text-xs">€</span>
<input
type="number"
step="0.01"
name="base_price"
x-model="basePrice"
required
class="w-full bg-slate-50/70 focus:bg-white border border-slate-200 rounded-lg pl-7 pr-3 py-2 text-xs text-slate-900 font-semibold focus:outline-none focus:ring-1 focus:ring-slate-400"
>
</div>
</div>
<div class="md:col-span-2 space-y-1.5">
<label class="block text-xs font-medium text-slate-700">Korte Omschrijving (voor catalogus cards)</label>
<input type="text" name="short_description" value="{{ old('short_description') }}" placeholder="Korte samenvatting in 1 zin..." class="w-full bg-slate-50/70 focus:bg-white border border-slate-200 rounded-lg px-3 py-2 text-xs text-slate-900">
</div>
</div>
<!-- Afbeeldingen & Galerij Beheer -->
<div class="pt-5 border-t border-slate-200/60 space-y-4"
x-data="{
imageUrl: '{{ old('image_url', '') }}',
galleryImages: {{ json_encode(old('gallery_images', []), JSON_UNESCAPED_SLASHES) }},
newImageUrl: '',
addError: '',
isUploading: false,
uploadError: '',
showUrlInput: false,
setAsCover(index) {
let oldCover = this.imageUrl;
let newCover = this.galleryImages[index];
this.imageUrl = newCover;
if (oldCover && oldCover !== newCover) {
this.galleryImages[index] = oldCover;
} else {
this.galleryImages.splice(index, 1);
}
},
removeGalleryImage(index) {
this.galleryImages.splice(index, 1);
},
removeCover() {
if (this.galleryImages.length > 0) {
this.imageUrl = this.galleryImages.shift();
} else {
this.imageUrl = '';
}
},
addImageUrl() {
this.addError = '';
let url = this.newImageUrl.trim();
if (!url) return;
if (url === this.imageUrl || this.galleryImages.includes(url)) {
this.addError = 'Deze afbeelding is al gekoppeld!';
return;
}
if (!this.imageUrl) {
this.imageUrl = url;
} else {
this.galleryImages.push(url);
}
this.newImageUrl = '';
},
uploadFile(event) {
let file = event.target.files[0];
if (!file) return;
this.isUploading = true;
this.uploadError = '';
let formData = new FormData();
formData.append('image', file);
formData.append('_token', '{{ csrf_token() }}');
fetch('{{ route('admin.products.upload-image') }}', {
method: 'POST',
body: formData
})
.then(r => r.json())
.then(data => {
this.isUploading = false;
if (data.success && data.url) {
if (!this.imageUrl) {
this.imageUrl = data.url;
} else {
this.galleryImages.push(data.url);
}
} else {
this.uploadError = data.message || 'Uploaden is mislukt';
}
})
.catch(err => {
this.isUploading = false;
this.uploadError = 'Fout bij uploaden';
});
event.target.value = '';
}
}">
<input type="hidden" name="image_url" :value="imageUrl">
<template x-for="(img, idx) in galleryImages" :key="idx">
<input type="hidden" name="gallery_images[]" :value="img">
</template>
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-2">
<div>
<div class="flex items-center space-x-2">
<i data-lucide="image" class="w-4 h-4 text-slate-500"></i>
<h3 class="text-xs font-semibold text-slate-900 uppercase tracking-wider">Afbeeldingen</h3>
<span class="px-2 py-0.5 rounded-full bg-slate-100 text-slate-600 font-mono text-[11px]" x-text="(imageUrl ? 1 : 0) + galleryImages.length + ' foto(\'s)'"></span>
</div>
<p class="text-xs text-slate-500 mt-0.5">
Hoofdfoto en extra foto's voor de galerij.
</p>
</div>
<div class="flex items-center space-x-2">
<label class="px-3 py-1.5 rounded-lg bg-white hover:bg-slate-50 text-slate-700 text-xs font-medium transition flex items-center space-x-1.5 border border-slate-200/80 shadow-2xs cursor-pointer">
<i data-lucide="upload" class="w-3.5 h-3.5 text-slate-400"></i>
<span x-text="isUploading ? 'Uploaden...' : 'Foto Uploaden'"></span>
<input type="file" accept="image/*" class="hidden" @change="uploadFile" :disabled="isUploading">
</label>
<button type="button" @click="showUrlInput = !showUrlInput" class="px-3 py-1.5 rounded-lg bg-white hover:bg-slate-50 text-slate-700 text-xs font-medium transition flex items-center space-x-1.5 border border-slate-200/80 shadow-2xs">
<i data-lucide="link" class="w-3.5 h-3.5 text-slate-400"></i>
<span>URL Plakken</span>
</button>
</div>
</div>
<!-- URL Toevoegen Bar -->
<div x-show="showUrlInput" x-transition class="p-3 bg-slate-50 rounded-xl border border-slate-200/60 space-y-2">
<div class="flex items-center space-x-2">
<input
type="text"
x-model="newImageUrl"
@keydown.enter.prevent="addImageUrl"
placeholder="Plak hier een foto-URL..."
class="flex-1 bg-white border border-slate-200 rounded-lg px-3 py-1.5 text-xs text-slate-900 placeholder-slate-400 focus:outline-none focus:ring-1 focus:ring-slate-400"
>
<button type="button" @click="addImageUrl" class="px-3.5 py-1.5 bg-slate-900 hover:bg-slate-800 text-white rounded-lg text-xs font-medium transition">
Toevoegen
</button>
</div>
<p x-show="addError" x-text="addError" class="text-xs text-rose-600 font-medium"></p>
</div>
<div x-show="uploadError" x-text="uploadError" class="p-2.5 bg-rose-50 border border-rose-200 text-xs text-rose-700 rounded-lg font-medium"></div>
<!-- Visuele Weergave -->
<div class="grid grid-cols-1 md:grid-cols-12 gap-4 items-start">
<!-- Cover Box -->
<div class="md:col-span-5 bg-slate-50/70 rounded-xl border border-slate-200/80 p-3 space-y-2 relative overflow-hidden">
<div class="flex items-center justify-between">
<span class="text-[10px] font-semibold text-slate-500 uppercase tracking-wider">Hoofdafbeelding</span>
<template x-if="imageUrl">
<button type="button" @click="removeCover" class="text-slate-400 hover:text-rose-600 text-[11px] transition">
Verwijderen
</button>
</template>
</div>
<div class="aspect-4/3 rounded-lg bg-white overflow-hidden flex items-center justify-center relative border border-slate-200/60 shadow-2xs">
<template x-if="imageUrl">
<img :src="imageUrl" alt="Hoofdafbeelding" class="w-full h-full object-cover">
</template>
<template x-if="!imageUrl">
<div class="text-center p-4 text-slate-400 space-y-1">
<i data-lucide="image" class="w-6 h-6 mx-auto text-slate-300"></i>
<p class="text-xs">Nog geen foto geselecteerd</p>
</div>
</template>
</div>
</div>
<!-- Gallerij Grid -->
<div class="md:col-span-7 bg-slate-50/50 rounded-xl border border-slate-200/60 p-3 space-y-2">
<div class="flex items-center justify-between">
<span class="text-xs font-medium text-slate-700">Extra Galerijfoto's</span>
<span class="text-[10px] text-slate-400" x-text="galleryImages.length + ' foto(\'s)'"></span>
</div>
<div class="grid grid-cols-2 sm:grid-cols-3 gap-2 max-h-80 overflow-y-auto pr-1">
<template x-for="(img, index) in galleryImages" :key="index">
<div class="group relative rounded-lg bg-white border border-slate-200/80 overflow-hidden shadow-2xs">
<div class="aspect-square w-full overflow-hidden bg-slate-100">
<img :src="img" alt="Gallerij foto" class="w-full h-full object-cover" loading="lazy">
</div>
<div class="absolute inset-0 bg-slate-900/60 opacity-0 group-hover:opacity-100 transition flex flex-col items-center justify-center gap-1 p-2">
<button
type="button"
@click="setAsCover(index)"
class="w-full py-1 px-2 bg-white text-slate-900 rounded text-[10px] font-semibold transition"
>
Als Cover
</button>
<button
type="button"
@click="removeGalleryImage(index)"
class="w-full py-1 px-2 bg-rose-600 text-white rounded text-[10px] font-medium transition"
>
Verwijder
</button>
</div>
</div>
</template>
</div>
<div x-show="galleryImages.length === 0" class="text-center py-6 px-3 rounded-lg border border-dashed border-slate-200 text-slate-400 text-xs">
Geen extra foto's in de galerij.
</div>
</div>
</div>
</div>
<!-- Beschrijving -->
<div class="space-y-1.5">
<label class="block text-xs font-medium text-slate-700">Productbeschrijving *</label>
<textarea name="description" rows="5" required placeholder="Gedetailleerde informatie over dit 3D model..." class="w-full bg-slate-50/70 focus:bg-white border border-slate-200 rounded-lg px-3 py-2 text-xs text-slate-900 leading-relaxed focus:outline-none focus:ring-1 focus:ring-slate-400">{{ old('description') }}</textarea>
</div>
<!-- Print Specs -->
<div class="grid grid-cols-1 sm:grid-cols-3 gap-4 pt-4 border-t border-slate-200/60">
<div class="space-y-1.5">
<label class="block text-xs font-medium text-slate-700">Afmetingen</label>
<input type="text" name="dimensions" value="{{ old('dimensions') }}" placeholder="bijv. 12 x 8 x 10 cm" class="w-full bg-slate-50/70 focus:bg-white border border-slate-200 rounded-lg px-3 py-1.5 text-xs text-slate-900">
</div>
<div class="space-y-1.5">
<label class="block text-xs font-medium text-slate-700">Gewicht (gram)</label>
<input type="number" name="weight_grams" x-model.number="weightGrams" class="w-full bg-slate-50/70 focus:bg-white border border-slate-200 rounded-lg px-3 py-1.5 text-xs text-slate-900">
</div>
<div class="space-y-1.5">
<label class="block text-xs font-medium text-slate-700">Printduur (uren)</label>
<input type="number" step="0.1" name="print_time_hours" x-model.number="printTimeHours" class="w-full bg-slate-50/70 focus:bg-white border border-slate-200 rounded-lg px-3 py-1.5 text-xs text-slate-900">
</div>
</div>
<!-- Toggles -->
<div class="pt-4 border-t border-slate-200/60 flex items-center space-x-6 text-xs text-slate-700 font-medium">
<label class="flex items-center space-x-2 cursor-pointer">
<input type="checkbox" name="is_active" value="1" {{ old('is_active', 1) ? 'checked' : '' }} class="w-4 h-4 rounded text-slate-900 border-slate-300">
<span>Direct zichtbaar in webshop (Actief)</span>
</label>
<label class="flex items-center space-x-2 cursor-pointer">
<input type="checkbox" name="is_featured" value="1" {{ old('is_featured') ? 'checked' : '' }} class="w-4 h-4 rounded text-slate-900 border-slate-300">
<span>Uitlichten op homepage</span>
</label>
</div>
</div>
<div class="flex items-center justify-end space-x-3">
<a href="{{ route('admin.products.index') }}" class="px-4 py-2 rounded-lg bg-white hover:bg-slate-50 text-slate-600 text-xs font-medium transition border border-slate-200">
Annuleren
</a>
<button type="submit" class="px-5 py-2 rounded-lg bg-slate-900 hover:bg-slate-800 text-white font-medium text-xs transition flex items-center space-x-1.5 shadow-xs cursor-pointer">
<i data-lucide="plus" class="w-4 h-4"></i>
<span>Product Opslaan</span>
</button>
</div>
</form>
</div>
@endsection