<?php $__env->startSection('title', 'New Customer'); ?>

<?php $__env->startSection('content'); ?>
<div class="d-flex align-items-center mb-3">
    <a href="<?php echo e(route('customers.index')); ?>" class="btn btn-sm btn-outline-secondary me-3"><i class="bi bi-arrow-left"></i></a>
    <h4 class="mb-0 fw-bold"><i class="bi bi-person-plus text-primary me-2"></i>New Customer</h4>
</div>

<?php if($errors->any()): ?>
<div class="alert alert-danger small">
    <ul class="mb-0 ps-3"><?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $e): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><li><?php echo e($e); ?></li><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></ul>
</div>
<?php endif; ?>

<form method="POST" action="<?php echo e(route('customers.store')); ?>">
<?php echo csrf_field(); ?>

<div class="row g-3">
    
    <div class="col-md-8">
        <div class="card border-0 shadow-sm h-100">
            <div class="card-header bg-transparent border-bottom fw-bold">Basic Information</div>
            <div class="card-body">
                <div class="row g-3">
                    <div class="col-md-4">
                        <label class="form-label fw-semibold small">Customer Code *</label>
                        <input type="text" name="customer_code" class="form-control form-control-sm <?php $__errorArgs = ['customer_code'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" value="<?php echo e(old('customer_code', $autoCode)); ?>" required>
                        <?php $__errorArgs = ['customer_code'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label fw-semibold small">Type *</label>
                        <select name="customer_type" class="form-select form-select-sm" required>
                            <option value="business" <?php echo e(old('customer_type','business') == 'business' ? 'selected':''); ?>>Business</option>
                            <option value="retail"   <?php echo e(old('customer_type') == 'retail'   ? 'selected':''); ?>>Retail</option>
                            <option value="cash"     <?php echo e(old('customer_type') == 'cash'     ? 'selected':''); ?>>Cash</option>
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label fw-semibold small">Status *</label>
                        <select name="status" class="form-select form-select-sm" required>
                            <option value="active"   <?php echo e(old('status','active') == 'active'   ? 'selected':''); ?>>Active</option>
                            <option value="inactive" <?php echo e(old('status') == 'inactive' ? 'selected':''); ?>>Inactive</option>
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label fw-semibold small">Name (English) *</label>
                        <input type="text" name="name_en" class="form-control form-control-sm <?php $__errorArgs = ['name_en'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" value="<?php echo e(old('name_en')); ?>" required>
                        <?php $__errorArgs = ['name_en'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label fw-semibold small">Name (Arabic)</label>
                        <input type="text" name="name_ar" class="form-control form-control-sm" value="<?php echo e(old('name_ar')); ?>" dir="rtl">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label fw-semibold small">Mobile</label>
                        <input type="text" name="mobile" class="form-control form-control-sm" value="<?php echo e(old('mobile')); ?>" placeholder="05XXXXXXXX">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label fw-semibold small">Phone</label>
                        <input type="text" name="phone" class="form-control form-control-sm" value="<?php echo e(old('phone')); ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label fw-semibold small">Email</label>
                        <input type="email" name="email" class="form-control form-control-sm" value="<?php echo e(old('email')); ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label fw-semibold small">Contact Person</label>
                        <input type="text" name="contact_person" class="form-control form-control-sm" value="<?php echo e(old('contact_person')); ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label fw-semibold small">Customer Ref</label>
                        <input type="text" name="customer_ref" class="form-control form-control-sm" value="<?php echo e(old('customer_ref')); ?>">
                    </div>
                    <div class="col-md-4">
                        <label class="form-label fw-semibold small">Branch</label>
                        <select name="branch_id" class="form-select form-select-sm">
                            <option value="">All Branches</option>
                            <?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $branch): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($branch->id); ?>" <?php echo e(old('branch_id') == $branch->id ? 'selected':''); ?>><?php echo e($branch->name_en); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>

    
    <div class="col-md-4">
        <div class="card border-0 shadow-sm mb-3">
            <div class="card-header bg-transparent border-bottom fw-bold small">VAT & CR Registration</div>
            <div class="card-body">
                <div class="mb-3">
                    <label class="form-label fw-semibold small">VAT Registered? *</label>
                    <select name="vat_registered" class="form-select form-select-sm" id="vatRegistered" required>
                        <option value="0" <?php echo e(old('vat_registered','0') == '0' ? 'selected':''); ?>>No</option>
                        <option value="1" <?php echo e(old('vat_registered') == '1' ? 'selected':''); ?>>Yes</option>
                    </select>
                </div>
                <div class="mb-3">
                    <label class="form-label fw-semibold small">VAT Number (15 digits)</label>
                    <input type="text" name="vat_number" class="form-control form-control-sm <?php $__errorArgs = ['vat_number'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>" value="<?php echo e(old('vat_number')); ?>" maxlength="15" placeholder="3XXXXXXXXXXX3">
                    <div class="form-text">Saudi VAT: starts and ends with 3, 15 digits total.</div>
                    <?php $__errorArgs = ['vat_number'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?><div class="invalid-feedback"><?php echo e($message); ?></div><?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                </div>
                <div class="mb-3">
                    <label class="form-label fw-semibold small">CR Number</label>
                    <input type="text" name="cr_number" class="form-control form-control-sm" value="<?php echo e(old('cr_number')); ?>">
                </div>
            </div>
        </div>

        <div class="card border-0 shadow-sm">
            <div class="card-header bg-transparent border-bottom fw-bold small">Credit Settings</div>
            <div class="card-body">
                <div class="row g-2">
                    <div class="col-6">
                        <label class="form-label fw-semibold small">Allow Credit *</label>
                        <select name="credit_allowed" class="form-select form-select-sm" required>
                            <option value="0" <?php echo e(old('credit_allowed','0') == '0' ? 'selected':''); ?>>No</option>
                            <option value="1" <?php echo e(old('credit_allowed') == '1' ? 'selected':''); ?>>Yes</option>
                        </select>
                    </div>
                    <div class="col-6">
                        <label class="form-label fw-semibold small">Price Level *</label>
                        <select name="price_level" class="form-select form-select-sm" required>
                            <option value="retail"     <?php echo e(old('price_level','retail') == 'retail'     ? 'selected':''); ?>>Retail</option>
                            <option value="wholesale"  <?php echo e(old('price_level') == 'wholesale'  ? 'selected':''); ?>>Wholesale</option>
                            <option value="special"    <?php echo e(old('price_level') == 'special'    ? 'selected':''); ?>>Special</option>
                        </select>
                    </div>
                    <div class="col-6">
                        <label class="form-label fw-semibold small">Credit Limit (SAR)</label>
                        <input type="number" name="credit_limit" class="form-control form-control-sm" value="<?php echo e(old('credit_limit', '0')); ?>" min="0" step="0.01">
                    </div>
                    <div class="col-6">
                        <label class="form-label fw-semibold small">Credit Days</label>
                        <input type="number" name="credit_days" class="form-control form-control-sm" value="<?php echo e(old('credit_days', '0')); ?>" min="0">
                    </div>
                    <div class="col-12">
                        <label class="form-label fw-semibold small">Payment Type *</label>
                        <select name="default_payment_type" class="form-select form-select-sm" required>
                            <option value="cash"   <?php echo e(old('default_payment_type','cash') == 'cash'   ? 'selected':''); ?>>Cash</option>
                            <option value="credit" <?php echo e(old('default_payment_type') == 'credit' ? 'selected':''); ?>>Credit</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>


<div class="card border-0 shadow-sm mt-3">
    <div class="card-header bg-transparent border-bottom fw-bold">Saudi National Address (for ZATCA)</div>
    <div class="card-body">
        <div class="row g-3">
            <div class="col-md-2">
                <label class="form-label fw-semibold small">Building No.</label>
                <input type="text" name="building_number" class="form-control form-control-sm" value="<?php echo e(old('building_number')); ?>" maxlength="4">
            </div>
            <div class="col-md-3">
                <label class="form-label fw-semibold small">Street (EN)</label>
                <input type="text" name="street_en" class="form-control form-control-sm" value="<?php echo e(old('street_en')); ?>">
            </div>
            <div class="col-md-3">
                <label class="form-label fw-semibold small">Street (AR)</label>
                <input type="text" name="street_ar" class="form-control form-control-sm" value="<?php echo e(old('street_ar')); ?>" dir="rtl">
            </div>
            <div class="col-md-2">
                <label class="form-label fw-semibold small">Additional No.</label>
                <input type="text" name="additional_number" class="form-control form-control-sm" value="<?php echo e(old('additional_number')); ?>" maxlength="4">
            </div>
            <div class="col-md-2">
                <label class="form-label fw-semibold small">Postal Code</label>
                <input type="text" name="postal_code" class="form-control form-control-sm" value="<?php echo e(old('postal_code')); ?>" maxlength="5">
            </div>
            <div class="col-md-3">
                <label class="form-label fw-semibold small">District (EN)</label>
                <input type="text" name="district_en" class="form-control form-control-sm" value="<?php echo e(old('district_en')); ?>">
            </div>
            <div class="col-md-3">
                <label class="form-label fw-semibold small">District (AR)</label>
                <input type="text" name="district_ar" class="form-control form-control-sm" value="<?php echo e(old('district_ar')); ?>" dir="rtl">
            </div>
            <div class="col-md-2">
                <label class="form-label fw-semibold small">City (EN)</label>
                <input type="text" name="city_en" class="form-control form-control-sm" value="<?php echo e(old('city_en')); ?>">
            </div>
            <div class="col-md-2">
                <label class="form-label fw-semibold small">City (AR)</label>
                <input type="text" name="city_ar" class="form-control form-control-sm" value="<?php echo e(old('city_ar')); ?>" dir="rtl">
            </div>
            <div class="col-md-2">
                <label class="form-label fw-semibold small">Country</label>
                <input type="text" name="country" class="form-control form-control-sm" value="<?php echo e(old('country', 'Saudi Arabia')); ?>">
            </div>
        </div>
    </div>
</div>


<div class="card border-0 shadow-sm mt-3">
    <div class="card-header bg-transparent border-bottom fw-bold">Opening Balance (Optional)</div>
    <div class="card-body">
        <div class="row g-3">
            <div class="col-md-3">
                <label class="form-label fw-semibold small">Financial Year</label>
                <select name="financial_year_id" class="form-select form-select-sm">
                    <option value="">-- None --</option>
                    <?php $__currentLoopData = $financialYears; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $fy): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($fy->id); ?>" <?php echo e(old('financial_year_id') == $fy->id ? 'selected':''); ?>><?php echo e($fy->year_name ?? $fy->name ?? $fy->year); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="col-md-2">
                <label class="form-label fw-semibold small">Opening Date</label>
                <input type="date" name="opening_date" class="form-control form-control-sm" value="<?php echo e(old('opening_date', now()->toDateString())); ?>">
            </div>
            <div class="col-md-2">
                <label class="form-label fw-semibold small">Amount (SAR)</label>
                <input type="number" name="opening_balance" class="form-control form-control-sm" value="<?php echo e(old('opening_balance', '0')); ?>" min="0" step="0.01">
            </div>
            <div class="col-md-2">
                <label class="form-label fw-semibold small">Type</label>
                <select name="opening_balance_type" class="form-select form-select-sm">
                    <option value="receivable" <?php echo e(old('opening_balance_type','receivable') == 'receivable' ? 'selected':''); ?>>Receivable (Debit)</option>
                    <option value="advance"    <?php echo e(old('opening_balance_type') == 'advance' ? 'selected':''); ?>>Advance (Credit)</option>
                </select>
            </div>
            <div class="col-md-3">
                <label class="form-label fw-semibold small">Notes</label>
                <input type="text" name="notes" class="form-control form-control-sm" value="<?php echo e(old('notes')); ?>">
            </div>
        </div>
    </div>
</div>

<div class="d-flex gap-2 justify-content-end mt-3">
    <a href="<?php echo e(route('customers.index')); ?>" class="btn btn-outline-secondary">Cancel</a>
    <button type="submit" class="btn btn-primary px-4"><i class="bi bi-save me-1"></i>Create Customer</button>
</div>

</form>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\saudi\resources\views\customers\create.blade.php ENDPATH**/ ?>