@extends('admin.layouts.app')
@section('title', 'Customer Return')
@section('content')
<div class="page-head"><div><h1 class="page-title">Customer Return</h1><div class="page-subtitle">Choose sold items carefully. The system now protects against over-return.</div></div></div>
<div class="card card-body">
    <form method="POST" action="{{ route('admin.sale-returns.store') }}">@csrf
        <div class="row g-3 mb-3">
            <div class="col-md-3"><label>Customer Name</label><input class="form-control" name="customer_name" value="{{ old('customer_name') }}" required></div>
            <div class="col-md-3"><label>Phone</label><input class="form-control" name="customer_phone" value="{{ old('customer_phone') }}"></div>
            <div class="col-md-3"><label>Return Date</label><input class="form-control" type="date" name="return_date" value="{{ old('return_date', now()->toDateString()) }}" required></div>
            <div class="col-md-3"><label>Refund Method</label><select class="form-select" name="refund_method"><option>Cash</option><option>Bank</option><option>Mobile Banking</option><option>Adjustment</option></select></div>
            <div class="col-12"><label>Address</label><input class="form-control" name="customer_address" value="{{ old('customer_address') }}"></div>
        </div>
        <div class="table-responsive"><table class="table table-bordered"><thead><tr><th>Sale Item</th><th>Qty Return</th><th>Restock</th></tr></thead><tbody>@for($i=0;$i<5;$i++)<tr><td><select class="form-select" name="rows[{{ $i }}][sale_id]"><option value="">Select Sale Item</option>@foreach($sales as $sale)<option value="{{ $sale->id }}">{{ $sale->invoice_no }} - {{ $sale->product_name }} (Sold: {{ $sale->quantity_sold }} {{ $sale->sale_unit ?: 'pcs' }})</option>@endforeach</select></td><td><input class="form-control" type="number" step="0.01" min="0.01" name="rows[{{ $i }}][qty]" value="{{ $i===0 ? 1 : '' }}"></td><td><input type="hidden" name="rows[{{ $i }}][restock]" value="0"><input class="form-check-input" type="checkbox" name="rows[{{ $i }}][restock]" value="1" checked></td></tr>@endfor</tbody></table></div>
        <div><label>Notes</label><textarea class="form-control" rows="4" name="notes">{{ old('notes') }}</textarea></div>
        <div class="mt-3"><button class="btn btn-primary">Save Return</button></div>
    </form>
</div>
@endsection