<?php $__env->startSection('content'); ?>
<div class="card">
    <div class="card-header">
        <div class="row align-items-center">
            <div class="col">
                <h5 class="mb-0">Create Payroll Process</h5>
            </div>
        </div>   
    </div>
    <div class="card-body">
        <form id="payroll-process-form">
            <?php echo csrf_field(); ?>
            <div class="row g-3 mb-3">
                <div class="col-md-3">
                    <label for="branch_id" class="form-label">Branch <span class="text-danger">*</span></label>
                    <select name="branch_id" id="branch_id" class="form-select" required>
                        <option value="">Select Branch</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($branch->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="col-md-3">
                    <label for="payroll_group_id" class="form-label">Payroll Group <span class="text-danger">*</span></label>
                    <select name="payroll_group_id" id="payroll_group_id" class="form-select" required>
                        <option value="">Select Payroll Group</option>
                        <?php $__currentLoopData = $payrollGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $group): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($group->id); ?>"><?php echo e($group->name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <div class="col-md-3">
                    <label for="date_from" class="form-label">From Date <span class="text-danger">*</span></label>
                    <input type="date" class="form-control" id="date_from" name="date_from" required>
                </div>

                <div class="col-md-3">
                    <label for="date_to" class="form-label">To Date <span class="text-danger">*</span></label>
                    <input type="date" class="form-control" id="date_to" name="date_to" required>
                </div>

                <div class="col-md-12">
                    <label for="remarks" class="form-label">Remarks</label>
                    <textarea class="form-control" id="remarks" name="remarks" rows="3"></textarea>
                </div>
            </div>

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

<?php $__env->startSection('scripts'); ?>
<script>
    $(document).ready(function() {
        $('#payroll-process-form').on('submit', function(e) {
            e.preventDefault();

            const formData = $(this).serialize();

            $.ajax({
                url: '<?php echo e(route('payroll.payroll-processes.store')); ?>',
                type: 'POST',
                data: formData,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function(response) {
                    if (response.status) {
                        Swal.fire('Success!', response.message, 'success').then(function() {
                            window.location.href = '<?php echo e(route('payroll.payroll-processes.index')); ?>';
                        });
                    } else {
                        Swal.fire('Error!', response.message, 'error');
                    }
                },
                error: function(xhr) {
                    const response = xhr.responseJSON;
                    if (response && response.errors) {
                        const errorMsg = Object.values(response.errors).map(e => e[0]).join('<br>');
                        Swal.fire('Validation Error', errorMsg, 'error');
                    } else {
                        Swal.fire('Error!', response?.message || 'Error creating payroll process', 'error');
                    }
                }
            });
        });
    });
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/codeproh/va.laraoffice.com/app/Modules/HR/Payroll/Providers/../Views/payroll-processes/create.blade.php ENDPATH**/ ?>