
<?php $__env->startSection('content'); ?>
    <!-- begin::main content -->
    <main class="main-content">
        <div class="container">
            <!-- begin::page header -->
            <div class="page-header">
                <h3>HRMS & Payroll Reports</h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="<?php echo e(asset('dashboard')); ?>"><?php echo e(__('message.dashboard')); ?></a></li>
                        <li class="breadcrumb-item active" aria-current="page">Reports</li>
                    </ol>
                </nav>
            </div>
            <!-- end::page header -->
            
            <div class="card">
                <div class="card-body">
                    <!-- Report Actions -->
                    
                    
                    <div class="mb-4 p-3 ">
                        <form action="<?php echo e(asset('hrms/reports')); ?>">
                            
                            <div class="row mb-4">
                                <div class="col-md-10"></div>
                                <div class="col-md-2">
                                    <div class="">
                                        <label>Export Type</label>
                                        <select class="form-control" name="type" >
                                            <option value="pdf" <?php echo e(isset($_GET["type"]) ? ($_GET["type"] == "pdf" ? "select" : "") : ""); ?>>PDF</option>
                                            <option value="csv" <?php echo e(isset($_GET["type"]) ? ($_GET["type"] == "csv" ? "select" : "") : ""); ?>>CSV</option>
                                            <option value="excel" <?php echo e(isset($_GET["type"]) ? ($_GET["type"] == "excel" ? "select" : "") : ""); ?>>EXCEL</option>
                                        </select>
                                        
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label>Branch</label>
                                        <select class="form-control select2" name="branch_id" >                                            
                                            <?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $b): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($b->id); ?>" <?php echo e(isset($_GET['branch_id']) ? $_GET['branch_id']==$b->id : ''); ?>><?php echo e($b->school); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label>Department</label>
                                        <select class="form-control select2" name="department_id" id="department">
                                            <option value="">All Departments</option>
                                            <?php $__currentLoopData = $departments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $dept): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($dept->id); ?>" <?php echo e(isset($_GET['department_id']) ? $_GET['department_id']==$dept->id : ''); ?>><?php echo e($dept->name); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label>Report Type</label>
                                        <select class="form-control select2" name="report_type" >
                                            
                                            <option value="payroll">Payroll Summary</option>
                                            <option value="tax">Tax Deduction</option>
                                            <option value="epf">EPF</option>
                                            <option value="esi">ESI</option>
                                        </select>
                                    </div>
                                </div>
                                
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label>Date From</label>
                                        <input type="date" class="form-control" name="date_from" id="dateFrom">
                                    </div>
                                </div>
                                
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label>Date To</label>
                                        <input type="date" class="form-control" name="date_to" id="dateTo">
                                    </div>
                                </div>
                                
                                
                                <div class="col-md-3">
                                    <div class="form-group">
                                        <label>Employee Id</label>
                                        <input type="text" class="form-control" name="employee_id" value="<?php echo e(isset($_GET['employee_id']) ? $_GET['employee_id'] : ''); ?>">
                                    </div>
                                </div>
                            </div>
                            
                            <div class="row">
                                <div class="col-md-12 text-right">
                                    <a href="<?php echo e(asset('hrms/reports')); ?>" class="btn btn-outline-secondary" >Reset</a>
                                    <button type="submit" class="btn btn-outline-primary">Generate Report</button>
                                </div>
                            </div>
                        </form>
                    </div>
                    
                    
                </div>
            </div>
        </div>
    </main>
    <!-- end::main content -->
<?php $__env->stopSection(); ?>

<?php $__env->startPush('footer-script'); ?>
    <script src="<?php echo e(asset('public/admin/js/examples/datatable.js')); ?>"></script>
    <script>
        $(document).ready(function() {
           
            
            // Reset filters
            $("#resetFilters").click(function(){
                $("#reportFilterForm")[0].reset();
            });
            
            // Export buttons
            $(".export-btn").click(function(e){
                e.preventDefault();
                var exportType = $(this).data('type');
                var reportType = $("#reportType").val();
                var dateFrom = $("#dateFrom").val();
                var dateTo = $("#dateTo").val();
                var department = $("#department").val();
                
                // Build export URL
                var url = "<?php echo e(asset('hrms/reports')); ?>?type=" + exportType + 
                          "&report_type=" + reportType + 
                          "&date_from=" + dateFrom + 
                          "&date_to=" + dateTo + 
                          "&department=" + department;
                
                window.location.href = url;
            });
            
            // Form submission for report generation
            $("#reportFilterForm").submit(function(e){
                e.preventDefault();
                
                // Show loading indicator
                $(".card-body").append('<div class="overlay"><i class="fas fa-2x fa-sync-alt fa-spin"></i></div>');
                
                // Get form data
                var formData = $(this).serialize();
                
                // AJAX request to get filtered data
                $.ajax({
                    url: "",
                    type: "GET",
                    data: formData,
                    success: function(response) {
                        // Update table with new data
                        updateReportTable(response.data);
                        updateSummaryCards(response.summary);
                        
                        // Hide loading indicator
                        $(".overlay").remove();
                    },
                    error: function(xhr) {
                        alert("Error generating report");
                        $(".overlay").remove();
                    }
                });
            });
            
            // Function to update table with new data
            function updateReportTable(data) {
                var tableBody = $("#reportTable tbody");
                tableBody.empty();
                
                $.each(data, function(index, item) {
                    var row = '<tr>' +
                                '<td>' + item.emp_id + '</td>' +
                                '<td>' + item.name + '</td>' +
                                '<td>' + item.department + '</td>' +
                                '<td>' + item.days_present + '</td>' +
                                '<td>' + item.days_absent + '</td>' +
                                '<td>' + item.basic_salary + '</td>' +
                                '<td>' + item.allowances + '</td>' +
                                '<td>' + item.deductions + '</td>' +
                                '<td>' + item.net_pay + '</td>' +
                              '</tr>';
                    
                    tableBody.append(row);
                });
            }
            
            // Function to update summary cards
            function updateSummaryCards(summary) {
                $(".card-text.display-4").eq(0).text(summary.total_employees);
                $(".card-text.display-4").eq(1).text(summary.total_payroll);
                $(".card-text.display-4").eq(2).text(summary.avg_attendance + '%');
                $(".card-text.display-4").eq(3).text(summary.pending_leaves);
            }
        });
    </script>
    
    <style>
        .overlay {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.8);
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }
        .card {
            position: relative;
        }
    </style>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\xampp\htdocs\blurb_erp\resources\views/hrms/reports/list.blade.php ENDPATH**/ ?>