| Current Path : /home/emeraadmin/public_html/pages/emeraadmin/ |
| Current File : /home/emeraadmin/public_html/pages/emeraadmin/report_subtaskswithnotes.php |
<?php
include('head.php');
require_once '../../Classes/Database.php';
require_once '../../Service/TaskService.php';
require_once '../../Classes/System.php';
require_once '../../Service/ServiceService.php';
// Initialize necessary services and objects
$serviceService = new ServiceService();
$taskService = new TaskService();
$System = new System();
// Fetch services for dropdown
$services = $serviceService->getAllServicesForDropdown();
// Fetch assigned user ID from session or request
$assignedUserId = $_SESSION['user_id'] ?? ($_GET['user_id'] ?? 1); // Default to 1 if not set
// Fetch all notes grouped by date
$startDate = $_GET['start_date'] ?? null;
$endDate = $_GET['end_date'] ?? null;
$subcontractorId = $_GET['subcontractor_id'] ?? null;
$serviceLocationId = $_GET['service_location_id'] ?? null;
if ($_GET['filter_today'] ?? false) {
$startDate = date('Y-m-d');
$endDate = date('Y-m-d');
}
$subtasks = $taskService->getAllSubtasksWithNotesGroupByDate($startDate, $endDate, $subcontractorId, $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>Report Submitting 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">All Subtasks</li>
</ol>
</nav>
</div>
</div>
</div>
<!-- Date Filter and Today Checkbox -->
<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="subcontractorId">Select a Subcontractor:</label>
<select id="subcontractorId" name="subcontractorId" class="form-control select2">
<!-- Default option -->
<option value="">All Subcontractors</option>
<?php
// Fetch company list from the database
$companies = $taskService->getAllCompanies();
if ($companies) {
foreach ($companies as $company) {
// Check if subcontractor_id is set in the URL
$selected = '';
if (isset($_GET['subcontractor_id']) && $_GET['subcontractor_id'] == $company->id) {
$selected = 'selected';
}
echo '<option value="' . $company->id . '" ' . $selected . '>' . $company->first_name . ' ' . $company->last_name . '</option>';
}
} else {
echo '<option value="">No subcontractors available</option>';
}
?>
</select>
</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
// Collect unique regions
foreach ($services as $service) {
// Check if serviceLocationId is set in the URL
$selected = '';
if (isset($_GET['service_location_id']) && $_GET['service_location_id'] == $service->id) {
$selected = '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">
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" id="todayCheckbox" value="today" <?= ($startDate == date('Y-m-d') && $endDate == date('Y-m-d')) ? 'checked' : '' ?>>
<label class="form-check-label" for="todayCheckbox">Today</label>
</div>
</div>
<div class="col-md-3 d-flex align-items-center">
<button id="applyFilter" class="btn btn-primary">Apply Filter</button>
<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
// Check if all subtasks under this date have empty notes
$allEmpty = true;
foreach ($subtaskList as $subtask) {
if (!empty($subtask['notes'])) {
$allEmpty = false;
break;
}
}
// If all subtasks have empty notes, skip displaying this section
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 <?php
if ($date == date('Y-m-d')) {
echo 'Today';
} else if ($date == date('Y-m-d', strtotime('tomorrow'))) {
echo 'Tomorrow';
} else {
echo date('l, F j, Y', strtotime($date));
}
?></h3>
</div>
<div class="card-body">
<div class="dt-responsive">
<table class="table" id="advanced_table_<?php echo strtotime($date); ?>">
<thead>
<tr>
<th>ID</th>
<th>Service Name</th>
<th>Subcontractor</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; // Skip rows with empty notes ?>
<tr class="subtask-row">
<td>ST-000<?= $subtask['id']; ?></td>
<td><?= $subtask['service_name']; ?></td>
<td><?= $subtask['assigned_user_first_name'].' '.$subtask['assigned_user_last_name']; ?></td>
<td><?= $subtask['subtask_date']; ?></td>
<td><?= $subtask['subtask_time'] ? date('h:i A', strtotime($subtask['subtask_time'])) : ''; ?></td>
<td><?= $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>
</div>
<?php } ?>
</div>
</div>
<?php include('footer.php'); ?>
<!-- Include jQuery and Bootstrap Datepicker JS -->
<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() {
// Initialize datepickers
$('.datepicker').datepicker({
format: 'yyyy-mm-dd',
autoclose: true,
todayHighlight: true
});
// Function to save filters to localStorage
function saveFilters() {
var filters = {
startDate: $('#startDate').val(),
endDate: $('#endDate').val(),
subcontractorId: $('#subcontractorId').val(),
serviceLocationId: $('#serviceLocationId').val(),
todayCheckbox: $('#todayCheckbox').is(':checked')
};
localStorage.setItem('dateRangeFilters', JSON.stringify(filters));
}
// Function to apply saved filters
function applyFilters() {
var filters = JSON.parse(localStorage.getItem('dateRangeFilters'));
if (filters) {
$('#startDate').val(filters.startDate);
$('#endDate').val(filters.endDate);
$('#subcontractorId').val(filters.subcontractorId);
$('#serviceLocationId').val(filters.serviceLocationId);
$('#todayCheckbox').prop('checked', filters.todayCheckbox);
}
}
// Function to reset filters
function resetFilters() {
$('#startDate').val('');
$('#endDate').val('');
$('#subcontractorId').val('');
$('#serviceLocationId').val('');
$('#todayCheckbox').prop('checked', false);
localStorage.removeItem('dateRangeFilters');
applyDateRangeFilter();
}
// Apply date range filter by modifying the URL
function applyDateRangeFilter() {
var startDate = $('#startDate').val();
var endDate = $('#endDate').val();
var subcontractorId = $('#subcontractorId').val();
var serviceLocationId = $('#serviceLocationId').val();
var url = window.location.href.split('?')[0] + '?start_date=' + startDate + '&end_date=' + endDate + '&subcontractor_id=' + subcontractorId + '&service_location_id=' + serviceLocationId;
window.location.href = url;
}
// Event handler for applyFilter button
$('#applyFilter').on('click', function() {
saveFilters();
applyDateRangeFilter();
});
// Event handler for todayCheckbox
$('#todayCheckbox').on('change', function() {
if ($(this).is(':checked')) {
var today = '<?= date('Y-m-d') ?>';
$('#startDate').val(today);
$('#endDate').val(today);
} else {
$('#startDate').val('');
$('#endDate').val('');
}
saveFilters();
applyDateRangeFilter();
});
// Add reset filters button functionality
$('#reset_filters').on('click', function() {
resetFilters();
});
// Apply saved filters on initial load
applyFilters();
});
</script>