@extends('store.layout.main') @section('page-header') @endsection @section('main-container') @php $productOptionsJson = $products->map(fn ($p) => ['id' => (int) $p->id, 'name' => (string) $p->name])->values(); $categoryOptionsJson = $categories->map(fn ($c) => ['id' => (int) $c->id, 'name' => (string) (($c->parent_id ? '— ' : '') . $c->name)])->values(); @endphp
{{-- ═══════════════════ DISCOUNTS PANEL ═══════════════════ --}}
@forelse($discountItems as $d) @php $isActive = $d->is_active; $now = now()->startOfDay(); $expired = $d->end_date && $d->end_date->lt($now); $targetPids = array_map('intval', (array) ($d->target_product_ids ?? [])); $targetCids = array_map('intval', (array) ($d->target_category_ids ?? [])); $pNames = !empty($targetPids) ? $products->whereIn('id', $targetPids)->pluck('name')->values() : collect(); $cNames = !empty($targetCids) ? $categories->whereIn('id', $targetCids)->map(fn ($c) => ($c->parent_id ? '— ' : '') . $c->name)->values() : collect(); @endphp @empty @endforelse
Name Value Applies To Period Actions
{{ $d->name }}
{{ $d->discount_type === 'percentage' ? 'Percentage' : 'Fixed' }} @if($isActive && !$expired) Active @elseif($expired) Expired @else Inactive @endif @if($d->new_customers_only) New Customers @endif
{{ $d->discount_type === 'percentage' ? $d->value . '%' : format_currency($d->value) . ' off' }} @if($pNames->count() === 1) Product: {{ $pNames->first() }} @elseif($pNames->count() === 2) Products: {{ $pNames->implode(', ') }} @elseif($pNames->count() >= 3) Products: {{ count($targetPids) }} selected
@elseif($cNames->count() === 1) Category: {{ $cNames->first() }} @elseif($cNames->count() === 2) Categories: {{ $cNames->implode(', ') }} @elseif($cNames->count() >= 3) Categories: {{ count($targetCids) }} selected
@elseif($d->target_product_tag) Tag: {{ $d->target_product_tag }} @elseif($d->product) Product: {{ $d->product->name }} @elseif($d->category) Category: {{ $d->category->name }} @else All Products @endif
@if($d->start_date) From {{ $d->start_date->format('d M Y') }} @endif @if($d->end_date) Expires {{ $d->end_date->format('d M Y') }} @else No expiry @endif
Created: {{ $d->created_at->format('d M Y') }}@if($d->creator) by {{ $d->creator->name }}@endif
No discounts yet. Click "Add Discount" to create one.
@if($discountItems->hasPages()) @endif
{{-- ═══════════════════ COUPONS PANEL ═══════════════════ --}}
{{-- ══════════════════════════════════════ ADD MODAL (unified — adapts to tab) ══════════════════════════════════════ --}} {{-- ══════════════════════════ EDIT MODAL ══════════════════════════ --}} @endsection @section('style') @endsection @section('script') @endsection