Your IP : 216.73.216.86


Current Path : /home/emeraadmin/public_html/pages/taskprovider/
Upload File :
Current File : /home/emeraadmin/public_html/pages/taskprovider/report_subtaskswithnotes.php

<?php
include('head.php');
require_once '../../Classes/Database.php';
require_once '../../Service/TaskService.php';
require_once '../../Classes/System.php';

// Initialize necessary services and objects
$taskService = new TaskService();
$System = new System();

// Fetch filter parameters
$startDate = $_GET['start_date'] ?? null;
$endDate = $_GET['end_date'] ?? null;
$serviceLocationId = $_GET['service_location_id'] ?? null;

if ($_GET['filter_today'] ?? false) {
    $startDate = date('Y-m-d');
    $endDate = date('Y-m-d');
}

// Fetch all notes grouped by date without subcontractor filtering
$subtasks = $taskService->getAllSubtasksWithNotesGroupByDateForTeamKidsAdmin($startDate, $endDate, $serviceLocationId);
?>

<!-- Include Bootstrap Datepicker CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/css/bootstrap-datepicker.min.css" />

<div class="main-content">
    <div class="container-fluid">
        <div class="page-header">
            <div class="row align-items-end">
                <div class="col-lg-8">
                    <div class="page-header-title">
                        <i class="ik ik-layers bg-blue"></i>
                        <div class="d-inline">
                            <h5>Tasks</h5>
                            <span>View and Submit Notes</span>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4">
                    <nav class="breadcrumb-container" aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item">
                                <a href="#"><i class="ik ik-home"></i></a>
                            </li>
                            <li class="breadcrumb-item">
                                <a href="#">Tasks</a>
                            </li>
                            <li class="breadcrumb-item active" aria-current="page">Subtasks</li>
                        </ol>
                    </nav>
                </div>
            </div>
        </div>

        <!-- Date Filter -->
        <div class="row mb-4">
            <div class="col-md-3">
                <div class="form-group">
                    <label for="startDate">Start Date</label>
                    <input type="text" id="startDate" class="form-control datepicker" placeholder="Select start date" value="<?= htmlspecialchars($startDate) ?>">
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label for="endDate">End Date</label>
                    <input type="text" id="endDate" class="form-control datepicker" placeholder="Select end date" value="<?= htmlspecialchars($endDate) ?>">
                </div>
            </div>
            <div class="col-md-3">
                <div class="form-group">
                    <label for="serviceLocationId">Select a Service Location:</label>
                    <select id="serviceLocationId" name="serviceLocationId" class="form-control">
                        <option value="">All Locations</option>
                        <?php
                        // Populate service locations
                        $services = $taskService->getAllServicesForDropdown();
                        foreach ($services as $service) {
                            $selected = ($serviceLocationId == $service->id) ? 'selected' : '';
                            echo '<option value="' . htmlspecialchars($service->id) . '" ' . $selected . '>' . htmlspecialchars($service->name) . '</option>';
                        }
                        ?>
                    </select>
                </div>
            </div>
            <div class="col-md-3 d-flex align-items-center">
                <button id="applyFilter" class="btn btn-primary">Apply Filter</button>
                &nbsp;
                <button type="button" id="reset_filters" class="btn btn-icon btn-outline-danger"><i class="ik ik-refresh-cw"></i></button>
            </div>
        </div>

        <!-- Display subtasks grouped by date -->
        <?php foreach ($subtasks as $date => $subtaskList) { ?>
            <?php
            // Skip if all notes are empty
            $allEmpty = true;
            foreach ($subtaskList as $subtask) {
                if (!empty($subtask['notes'])) {
                    $allEmpty = false;
                    break;
                }
            }
            if ($allEmpty) continue;
            ?>
            <div class="row subtask-row" data-date="<?php echo $date; ?>">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-header">
                            <h3>Subtasks for <?= date('l, F j, Y', strtotime($date)); ?></h3>
                        </div>
                        <div class="card-body">
                            <table class="table">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Service Name</th>
                                    <th>Date</th>
                                    <th>Time</th>
                                    <th>Notes</th>
                                    <th>Actions</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach ($subtaskList as $subtask) { ?>
                                    <?php if (empty($subtask['notes'])) continue; ?>
                                    <tr>
                                        <td>ST-<?= htmlspecialchars($subtask['id']); ?></td>
                                        <td><?= htmlspecialchars($subtask['service_name']); ?></td>
                                        <td><?= htmlspecialchars($subtask['subtask_date']); ?></td>
                                        <td><?= htmlspecialchars($subtask['subtask_time'] ? date('h:i A', strtotime($subtask['subtask_time'])) : ''); ?></td>
                                        <td><?= htmlspecialchars($subtask['notes']); ?></td>
                                        <td>
                                            <a href="viewsubtask.php?id=<?= $System->encryptData($subtask['id']); ?>" class="btn btn-primary">View</a>
                                        </td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        <?php } ?>
    </div>
</div>

<?php include('footer.php'); ?>

<!-- Include Scripts -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.9.0/js/bootstrap-datepicker.min.js"></script>
<script>
    $(document).ready(function () {
        // Datepicker initialization
        $('.datepicker').datepicker({format: 'yyyy-mm-dd', autoclose: true, todayHighlight: true});

        // Apply filter
        $('#applyFilter').on('click', function () {
            var startDate = $('#startDate').val();
            var endDate = $('#endDate').val();
            var serviceLocationId = $('#serviceLocationId').val();
            var url = window.location.href.split('?')[0] + '?start_date=' + startDate + '&end_date=' + endDate + '&service_location_id=' + serviceLocationId;
            window.location.href = url;
        });

        // Reset filters
        $('#reset_filters').on('click', function () {
            window.location.href = window.location.href.split('?')[0];
        });
    });
</script>