İki input da editable, otomatik senkronizasyon
Kullanıcı KDV hariç girerse: 1.000 TL → Sistem otomatik 1.200 TL hesaplar
Kullanıcı KDV dahil girerse: 1.200 TL → Sistem otomatik 1.000 TL hesaplar
Database'e kaydedilen: Sadece price_without_tax (tek kaynak!)
// ShopProductManageComponent.php
public $price_without_tax;
public $price_with_tax;
public $tax_rate = 20.0;
public function mount($productId = null)
{
if ($productId) {
$product = ShopProduct::find($productId);
$this->price_without_tax = $product->price_without_tax;
$this->tax_rate = $product->tax_rate ?? 20.0;
// KDV dahil fiyatı hesapla
$this->calculatePriceWithTax();
}
}
// KDV hariç fiyat değiştiğinde
public function updatedPriceWithoutTax()
{
$this->calculatePriceWithTax();
}
// KDV dahil fiyat değiştiğinde
public function updatedPriceWithTax()
{
$this->calculatePriceWithoutTax();
}
// KDV oranı değiştiğinde
public function updatedTaxRate()
{
// Hangisi doluysa ondan diğerini hesapla
if ($this->price_without_tax) {
$this->calculatePriceWithTax();
} elseif ($this->price_with_tax) {
$this->calculatePriceWithoutTax();
}
}
private function calculatePriceWithTax()
{
if (!$this->price_without_tax || !$this->tax_rate) {
$this->price_with_tax = null;
return;
}
$this->price_with_tax = $this->price_without_tax * (1 + $this->tax_rate / 100);
}
private function calculatePriceWithoutTax()
{
if (!$this->price_with_tax || !$this->tax_rate) {
$this->price_without_tax = null;
return;
}
$this->price_without_tax = $this->price_with_tax / (1 + $this->tax_rate / 100);
}
public function save()
{
// Database'e SADECE price_without_tax kaydedilir
$product->update([
'price_without_tax' => $this->price_without_tax,
'tax_rate' => $this->tax_rate,
// price_with_tax KAYDEDİLMEZ! (accessor ile hesaplanır)
]);
}
<div class="form-group">
<label class="form-label">KDV Hariç Fiyat (₺)</label>
<input
type="number"
wire:model.live="price_without_tax"
class="form-input"
step="0.01"
>
</div>
<div class="form-group">
<label class="form-label">KDV Dahil Fiyat (₺)</label>
<input
type="number"
wire:model.live="price_with_tax"
class="form-input"
step="0.01"
>
<small>Otomatik hesaplanır</small>
</div>
<div class="form-group">
<label class="form-label">KDV Oranı (%)</label>
<input
type="number"
wire:model.live="tax_rate"
class="form-input"
step="0.01"
>
</div>
<!-- Özet Gösterim -->
<div class="price-summary">
<div>KDV Hariç: {{ number_format($price_without_tax, 2) }} ₺</div>
<div>KDV Tutarı: {{ number_format(($price_with_tax - $price_without_tax), 2) }} ₺</div>
<div>KDV Dahil: {{ number_format($price_with_tax, 2) }} ₺</div>
</div>
<!-- Ürün kartında fiyat gösterimi -->
@php
$displayMode = setting('shop_product_tax', true); // true = KDV dahil
@endphp
@if($displayMode)
<!-- KDV Dahil Göster -->
<div class="product-price">
{{ number_format($product->price_with_tax, 2) }} ₺
<small>KDV Dahil</small>
</div>
@else
<!-- KDV Hariç Göster -->
<div class="product-price">
{{ number_format($product->price_without_tax, 2) }} ₺
<small>+ KDV</small>
</div>
@endif