<?php $__env->startSection('content'); ?>
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0 fw-semibold">Create Loan Type</h5>
        </div>

        <div class="card-body">
            <form id="loanForm">
                <?php echo csrf_field(); ?>

                <div class="row g-2 mb-3">
                    <div class="col-md-4">
                        <label class="form-label">Branch <span class="text-danger">*</span></label>
                        <select name="branch_id" class="form-control">
                            <?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($branch->name); ?>

                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <label class="form-label">Code <span class="text-danger">*</span></label>
                        <input type="text" name="code" class="form-control" required>
                    </div>

                    <div class="col-md-5">
                        <label class="form-label">Name <span class="text-danger">*</span></label>
                        <input type="text" name="name" class="form-control" required>
                    </div>

                    <div class="col-md-4">
                        <label class="form-label">Description</label>
                        <textarea name="description" class="form-control"></textarea>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label">Min Amount  <span class="text-danger">*</span></label>
                        <input type="number" step="0.01" name="min_amount" class="form-control" required>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label">Max Amount  <span class="text-danger">*</span></label>
                        <input type="number" step="0.01" name="max_amount" class="form-control" required>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label">Min Installments  <span class="text-danger">*</span></label>
                        <input type="number" name="min_installments" class="form-control" required>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label">Max Installments  <span class="text-danger">*</span></label>
                        <input type="number" name="max_installments" class="form-control" required>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label">Interest Type</label>
                        <select name="interest_type" class="form-control">
                            <option value="NONE">NONE</option>
                            <option value="FIXED">FIXED</option>
                            <option value="REDUCING">REDUCING</option>
                        </select>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label">Interest Rate (%)  <span class="text-danger">*</span></label>
                        <input type="number" step="0.01" name="interest_rate" class="form-control" required>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label">Recovery Start</label>
                        <select name="recovery_start" class="form-control">
                            <option value="IMMEDIATE">IMMEDIATE</option>
                            <option value="NEXT_MONTH">NEXT_MONTH</option>
                        </select>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label">Recovery Frequency</label>
                        <select name="recovery_frequency" class="form-control">
                            <option value="MONTHLY">MONTHLY</option>
                            <option value="BIWEEKLY">BIWEEKLY</option>
                        </select>
                    </div>

                    <div class="col-md-3">
                        <label class="form-label">Deduction Code</label>
                        <input type="text" name="deduction_code" class="form-control">
                    </div>

                    <div class="col-md-2">
                        <label><input type="checkbox" name="allow_partial_recovery"> Partial Recovery</label>
                    </div>

                    <div class="col-md-2">
                        <label><input type="checkbox" name="requires_approval" id="requiresApproval"> Requires Approval</label>
                    </div>

                    <div class="col-md-2">
                        <label class="form-label">Approval Levels</label>
                        <input type="number" name="approval_levels" id="approvalLevels"
                            class="form-control" min="1" disabled>
                    </div>

                    <div class="col-md-2">
                        <label class="form-label">Sort Order</label>
                        <input type="number" name="sort_order" class="form-control" value="0">
                    </div>

                    <div class="col-md-2">
                        <label class="form-label">Effective From</label>
                        <input type="date" name="effective_from" class="form-control">
                    </div>

                    <div class="col-md-2">
                        <label class="form-label">Effective To</label>
                        <input type="date" name="effective_to" class="form-control">
                    </div>

                    <div class="col-md-2 d-flex align-items-end">
                        <label>
                            <input type="checkbox" name="status" checked> Active
                        </label>
                    </div>
                </div>

                <button type="submit" class="btn btn-primary">Save</button>
                <a href="<?php echo e(route('payroll.loans.index')); ?>" class="btn btn-secondary">Back</a>
            </form>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
$('#requiresApproval').on('change', function () {
    $('#approvalLevels').prop('disabled', !this.checked).val(this.checked ? 1 : '');
});

$('#loanForm').on('submit', function(e){
    e.preventDefault();

    $.post("<?php echo e(route('payroll.loans.store')); ?>", $(this).serialize())
        .done(res => {
            Swal.fire('Success', res.message, 'success')
            .then(() => window.location.href = "<?php echo e(route('payroll.loans.index')); ?>");
        })
        .fail(err => {
            if (err.status === 422) {
                Swal.fire('Validation Error', err.responseJSON.errors, 'error');
            } else {
                 Swal.fire('Something went wrong','error');
            }
        });
});
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /media/madu/E8460E1D460DECDE/projects/laraoffice/app/Modules/HR/Payroll/Providers/../Views/loans/create.blade.php ENDPATH**/ ?>