Files
Comparison_Project/app/templates/subcontractor_report.html

375 lines
14 KiB
HTML

{% extends "base.html" %}
{% block content %}
<div class="container-fluid py-4">
<!-- Page Header -->
<div class="card shadow-sm border-0 mb-4">
<div class="card-body">
<div class="d-flex justify-content-between align-items-center">
<div>
<h2 class="fw-bold text-primary mb-1">
<i class="bi bi-file-earmark-bar-graph"></i>
Subcontractor Report
</h2>
<small class="text-muted">
View, Filter, Edit and Delete Subcontractor Records
</small>
</div>
</div>
</div>
</div>
<!-- Filter Card -->
<div class="card shadow-sm border-0">
<div class="card-header bg-primary text-white">
<h5 class="mb-0">
<i class="bi bi-funnel-fill"></i>
Report Filters
</h5>
</div>
<div class="card-body">
<form method="POST" class="loading-form">
<div class="row g-3">
<div class="col-lg-3">
<label class="form-label fw-semibold">
Subcontractor
<span class="text-danger">*</span>
</label>
<select name="subcontractor_id" class="form-select" required>
<option value="">--- Select Contractor ---</option>
{% for sc in subcontractors %}
<option value="{{ sc.id }}"
{% if selected_sc_id|string == sc.id|string %}selected{% endif %}>
{{ sc.subcontractor_name }}
</option>
{% endfor %}
</select>
</div>
<div class="col-lg-3">
<label class="form-label fw-semibold"> RA Bill No</label>
<input
type="text"
name="ra_bill_no"
class="form-control"
placeholder="Enter RA Bill"
value="{{ selected_ra_bill or '' }}">
</div>
<div class="col-lg-3">
<label class="form-label fw-semibold"> Location </label>
<input
type="text"
name="location"
class="form-control"
placeholder="Project Location"
value="{{ selected_location or '' }}">
</div>
<div class="col-lg-3">
<label class="form-label fw-semibold">Work Category</label>
<select name="category" class="form-select">
<option value="all">All Categories</option>
<option value="tr"
{% if request.form.get('category')=='tr' %}selected{% endif %}>
Trench Excavation
</option>
<option value="mh"
{% if request.form.get('category')=='mh' %}selected{% endif %}>
Manhole Excavation
</option>
<option value="dc"
{% if request.form.get('category')=='dc' %}selected{% endif %}>
Domestic Chamber
</option>
<option value="laying"
{% if request.form.get('category')=='laying' %}selected{% endif %}>
Pipe Laying
</option>
</select>
</div>
</div>
<div class="mt-4 d-flex justify-content-end gap-2">
<!-- Preview -->
<button type="submit" name="action" value="preview"class="btn btn-primary">
<i class="bi bi-search"></i>
Preview Report
</button>
<!-- Download -->
<div class="btn-group">
<button type="button" class="btn btn-success dropdown-toggle"data-bs-toggle="dropdown">
<i class="bi bi-download"></i>
Download Report
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<button class="dropdown-item"type="submit" name="action" value="excel">
<i class="bi bi-file-earmark-excel text-success"></i>
Download Excel
</button>
</li>
<li>
<button class="dropdown-item" type="submit" name="action"
value="excel_all">
<i class="bi bi-file-earmark-spreadsheet text-primary"></i>
Download All Excel
</button>
</li>
<li><hr class="dropdown-divider"></li>
<li>
<button class="dropdown-item"type="submit"name="action" value="pdf">
<i class="bi bi-file-earmark-pdf text-danger"></i>
PDF (Coming Soon)
</button>
</li>
</ul>
</div>
<button type="reset" class="btn btn-secondary" id="resetBtn">
<i class="bi bi-arrow-clockwise"></i>
Reset
</button>
</div>
</form>
</div>
</div>
{% if tables %}
{% set show_all = (not selected_category) or selected_category == 'all' %}
<!-- Tabs -->
<div class="card shadow-sm border-0 mt-4">
<div class="card-header bg-light">
<ul class="nav nav-pills">
<li class="nav-item">
<button class="nav-link {% if show_all %}active{% endif %}" data-bs-toggle="tab" data-bs-target="#abstract">
<i class="bi bi-file-earmark-text"></i> Abstract
</button>
</li>
{% if show_all or selected_category == 'tr' %}
<li class="nav-item">
<button class="nav-link {% if selected_category == 'tr' %}active{% endif %}" data-bs-toggle="tab" data-bs-target="#tr">
<i class="bi bi-cone-striped"></i> Trench Excavation
</button>
</li>
{% endif %}
{% if show_all or selected_category == 'mh' %}
<li class="nav-item">
<button class="nav-link {% if selected_category == 'mh' %}active{% endif %}" data-bs-toggle="tab" data-bs-target="#mh">
<i class="bi bi-nut"></i> Manhole Excavation
</button>
</li>
{% endif %}
{% if show_all or selected_category == 'dc' %}
<li class="nav-item">
<button class="nav-link {% if selected_category == 'dc' %}active{% endif %}" data-bs-toggle="tab" data-bs-target="#dc">
<i class="bi bi-grid-3x3"></i> Manhole & Domestic Chambers Construction
</button>
</li>
{% endif %}
{% if show_all or selected_category == 'laying' %}
<li class="nav-item">
<button class="nav-link {% if selected_category == 'laying' %}active{% endif %}" data-bs-toggle="tab" data-bs-target="#laying">
<i class="bi bi-bezier2"></i> Pipe Laying
</button>
</li>
{% endif %}
</ul>
</div>
<div class="card-body">
<div class="tab-content">
<div class="tab-pane fade {% if show_all %}show active{% endif %}" id="abstract">
{{ abstract_html|safe }}
</div>
{% if show_all or selected_category == 'tr' %}
<!-- Trench -->
<div class="tab-pane fade {% if selected_category == 'tr' %}show active{% endif %}" id="tr">
<div class="mb-3">
<button onclick="deleteSelected('tr')" class="btn btn-danger">
<i class="bi bi-trash"></i> Delete Selected
</button>
</div>
<div class="table-responsive border rounded shadow-sm">
{{ tables.tr|safe }}
</div>
</div>
{% endif %}
{% if show_all or selected_category == 'mh' %}
<!-- MH -->
<div class="tab-pane fade {% if selected_category == 'mh' %}show active{% endif %}" id="mh">
<div class="mb-3">
<button onclick="deleteSelected('mh')" class="btn btn-danger">
<i class="bi bi-trash"></i>Delete Selected
</button>
</div>
<div class="table-responsive border rounded shadow-sm">
{{ tables.mh|safe }}
</div>
</div>
{% endif %}
{% if show_all or selected_category == 'dc' %}
<!-- DC -->
<div class="tab-pane fade {% if selected_category == 'dc' %}show active{% endif %}" id="dc">
<div class="mb-3">
<button onclick="deleteSelected('dc')"class="btn btn-danger">
<i class="bi bi-trash"></i>
Delete Selected
</button>
</div>
<div class="table-responsive border rounded shadow-sm">
{{ tables.dc|safe }}
</div>
</div>
{% endif %}
{% if show_all or selected_category == 'laying' %}
<!-- Laying -->
<div class="tab-pane fade {% if selected_category == 'laying' %}show active{% endif %}" id="laying">
<div class="mb-3">
<button onclick="deleteSelected('laying')"
class="btn btn-danger">
<i class="bi bi-trash"></i>
Delete Selected
</button>
</div>
<div class="table-responsive border rounded shadow-sm">
{{ tables.laying|safe }}
</div>
</div>
{% endif %}
</div>
</div>
</div>
{% endif %}
</div>
<script>
document.getElementById("resetBtn").addEventListener("click", function () {
window.location.href = window.location.pathname;
});
// DATATABLE
$(document).ready(function () {
$('.datatable').each(function () {
$(this).DataTable({
pageLength: 10,
dom: 'Bfrtip',
buttons: ['copy', 'csv', 'excel', 'print'],
initComplete: function () {
$(this).closest('.dataTables_wrapper')
.find('thead tr th:first-child')
.html('<input type="checkbox" class="select-all" title="Select All">');
}
});
});
});
// SELECT ALL — scoped to the checkbox's own table only
$(document).on("change", ".select-all", function () {
$(this).closest("table").find(".row-check").prop("checked", this.checked);
});
// If a row checkbox is unchecked manually, uncheck that table's select-all
$(document).on("change", ".row-check", function () {
if (!this.checked) {
$(this).closest("table").find(".select-all").prop("checked", false);
}
});
function getSelectedIds(model) {
let ids = [];
$("#" + model + " .row-check:checked").each(function () {
ids.push($(this).data("id"));
});
return ids;
}
// BULK DELETE
function deleteSelected(model) {
let ids = getSelectedIds(model);
if (ids.length === 0) return alert("Select records");
if (!confirm(`Delete ${ids.length} record(s)?`)) return;
fetch("/file/delete_records", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model: model, ids: ids })
})
.then(res => res.json().then(data => ({ ok: res.ok, data })))
.then(({ ok, data }) => {
if (ok && data.status === "success") {
alert("Deleted Successfully");
location.reload();
} else {
alert("Delete failed: " + (data.message || "Unknown error"));
}
})
.catch(err => {
alert("Delete request failed: " + err);
});
}
// SINGLE DELETE
$(document).on("click", ".delete-btn", function () {
let id = $(this).data("id");
let model = $(this).data("model");
if (!confirm("Are you sure you want to delete this record?")) return;
fetch("/file/delete_records", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ model: model, ids: [id] })
})
.then(res => res.json().then(data => ({ ok: res.ok, data })))
.then(({ ok, data }) => {
if (ok && data.status === "success") {
alert("Deleted Successfully");
location.reload();
} else {
alert("Delete failed: " + (data.message || "Unknown error"));
}
})
.catch(err => {
alert("Delete request failed: " + err);
});
});
</script>
{% endblock %}