unreleased_gst will comment for not use

This commit is contained in:
2026-04-06 12:22:28 +05:30
parent 5ae1fbe320
commit a202da621c
14 changed files with 61 additions and 1554 deletions

View File

@@ -1,147 +0,0 @@
{% extends 'base.html' %}
{% block content %}
<head>
<title>Manage Purchases</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<div class="button-container">
<button id="addButton" class="action-button">Add Purchase</button>
<button id="displayButton" class="action-button">Display Purchases</button>
</div>
<!-- ADD PURCHASE FORM -->
<!-- ADD PURCHASE FORM -->
<div id="addForm" style="display: none;">
<h2>Add Purchase Entry</h2>
<form action="/add_purchase_order" method="POST">
<label for="purchase_date">Purchase Date:</label><br>
<input type="date" id="purchase_date" name="purchase_date" required><br><br>
<label for="supplier_name">Supplier Name:</label><br>
<input type="text" id="supplier_name" name="supplier_name" required><br><br>
<label for="Purchase Order No">Purchase Order No:</label><br>
<input type="text" name="purchase_order_no" required><br><br>
<label for="unit">Item Name:</label><br>
<input type="text" id="item_name" name="item_name" required><br><br>
<label for="quantity">Quantity:</label><br>
<input type="number" id="quantity" name="quantity" step="1" required><br><br>
<label for="unit">Unit:</label><br>
<input type="text" id="unit" name="unit" required><br><br>
<label for="rate">Rate:</label><br>
<input type="number" step="0.01" id="rate" name="rate" required><br><br>
<label for="amount">Amount:</label><br>
<input type="number" step="0.01" id="amount" name="amount" readonly><br><br>
<!-- GST input -->
<label for="gst_percent">GST %:</label><br>
<input type="number" step="0.01" id="gst_percent"><br><br>
<label>GST Amount:</label><br>
<input type="number" step="0.01" id="GST_Amount" name="GST_Amount" readonly><br><br>
<!-- TDS input -->
<label for="tds_percent">TDS %:</label><br>
<input type="number" step="0.01" id="tds_percent"><br><br>
<label>TDS:</label><br>
<input type="number" step="0.01" id="TDS" name="TDS" readonly><br><br>
<label>Final Amount:</label><br>
<input type="number" step="0.01" id="final_amount" name="final_amount" readonly><br><br>
<input type="submit" value="Submit">
</form>
</div>
<!-- DISPLAY TABLE -->
<div id="displayTable" style="display: none;">
<h2>Purchase List</h2>
<table border="1">
<tr>
<th>ID</th>
<th>Purchase Date</th>
<th>Supplier Name</th>
<th>Purchase Order No</th>
<th>Item Name</th>
<th>Quantity</th>
<th>Unit</th>
<th>Rate</th>
<th>Amount</th>
<th>GST Amount</th>
<th>TDS</th>
<th>Final Amount</th>
<th>Edit</th>
<th>Delete</th>
</tr>
{% for purchase in purchases %}
<tr>
<td>{{ purchase['purchase_id'] }}</td>
<td>{{ purchase['purchase_date'] }}</td>
<td>{{ purchase['supplier_name'] }}</td>
<td>{{ purchase['purchase_order_no'] }}</td>
<td>{{ purchase['item_name'] }}</td>
<td>{{ purchase['quantity'] }}</td>
<td>{{ purchase['unit'] }}</td>
<td>{{ purchase['rate'] }}</td>
<td>{{ purchase['amount'] }}</td>
<td>{{ purchase['GST_Amount'] }}</td>
<td>{{ purchase['TDS'] }}</td>
<td>{{ purchase['final_amount'] }}</td>
<td><a href="{{ url_for('update_purchase', id=purchase['purchase_id']) }}">Edit</a></td>
<td>
<form method="POST" action="{{ url_for('delete_purchase', id=purchase['purchase_id']) }}" style="display:inline;">
<button type="submit" onclick="return confirm('Are you sure?')">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</table>
</div>
<script>
$(document).ready(function() {
$('#addButton').click(function() {
$('#addForm').toggle();
});
$('#displayButton').click(function() {
$('#displayTable').toggle();
});
});
</script>
<script>
function calculateAmounts() {
const qty = parseFloat(document.getElementById('quantity').value) || 0;
const rate = parseFloat(document.getElementById('rate').value) || 0;
const gstPercent = parseFloat(document.getElementById('gst_percent').value) || 0;
const tdsPercent = parseFloat(document.getElementById('tds_percent').value) || 0;
const amount = qty * rate;
document.getElementById('amount').value = amount.toFixed(2);
const gstAmount = (gstPercent / 100) * amount;
document.getElementById('GST_Amount').value = gstAmount.toFixed(2);
const tdsAmount = (tdsPercent / 100) * amount;
document.getElementById('TDS').value = tdsAmount.toFixed(2);
const finalAmount = amount + gstAmount - tdsAmount;
document.getElementById('final_amount').value = finalAmount.toFixed(2);
}
// Attach events
document.getElementById('quantity').addEventListener('input', calculateAmounts);
document.getElementById('rate').addEventListener('input', calculateAmounts);
document.getElementById('gst_percent').addEventListener('input', calculateAmounts);
document.getElementById('tds_percent').addEventListener('input', calculateAmounts);
</script>
</body>
{% endblock %}

View File

@@ -1,137 +0,0 @@
{% extends 'base.html' %}
{% block content %}
<head>
<title>Manage Work Order</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}">
</head>
</head>
<body>
<div class="button-container">
<button id="addButton" class="action-button">Add</button>
<button id="displayButton" class="action-button">Display</button>
</div>
<form action="/submit_work_order" method="POST">
<div id="addForm" style="display: none;">
<h2>Create Work Order</h2>
<!-- Subcontractor Dropdown -->
<label for="subcontractor_id">Select Vender Name:</label><br>
<select name="vendor_name" id="vendor_name" required>
<option value="">-- Select Subcontractor --</option>
{% for sc in subcontractor %}
<option value="{{ sc.Contractor_Name }}">{{ sc.Contractor_Name }}</option>
{% endfor %}
</select><br><br>
<label for="work_order_number">Work Order Number:</label><br>
<input type="text" id="work_order_number" name="work_order_number" required><br><br>
<label for="work_order_amount">Work Order Amount</label><br>
<input type="number" step="0.01" id="work_order_amount" name="work_order_amount" required><br><br>
<label for="gst_amount">GST Amount:</label><br>
<input type="number" step="0.01" id="gst_amount" name="gst_amount" required><br><br>
<label for="tds_amount">TDS Amount:</label><br>
<input type="number" step="0.01" id="tds_amount" name="tds_amount" required><br><br>
<label for="security_deposit">Security Deposit:</label><br>
<input type="number" step="0.01" id="security_deposit" name="security_deposit" required><br><br>
<label for="sd_against_gst">SD Against GST:</label><br>
<input type="number" step="0.01" id="sd_against_gst" name="sd_against_gst" required><br><br>
<label for="final_total">Final Total:</label><br>
<input type="number" step="0.01" id="final_total" name="final_total" readonly><br><br>
<input type="submit" value="Submit">
</div>
</form>
{# display data #}
<div id="addTable" style="display: none;">
{# <div class="search-container">#}
{# <h2>Hold Type List</h2>#}
{# <input type="text" id="searchBar" placeholder="Searching..." onkeyup="searchTable()">#}
{# </div>#}
<table id="sortableTable" border="1">
<tr>
<th>ID</th>
<th class="sortable-header">
Vender Name
{# <span class="sort-buttons">#}
{# <span class="sort-asc">⬆️</span>#}
{# <span class="sort-desc">⬇️</span>#}
{# </span>#}
</th>
<th>Work Order Type</th>
<th>Work Order Amount</th>
<th>BOQ Amount</th>
<th>Work Done Percentage</th>
<th>Update</th>
<th>Delete</th>
</tr>
{% for htd in wo %}
<tr>
<td>{{ htd.work_order_id }}</td>
<td>{{ htd['vendor_name'] }}</td>
<td>{{ htd['work_order_type'] }}</td>
<td>{{ htd['work_order_amount'] }}</td>
<td>{{ htd['boq_amount'] }}</td>
<td>{{ htd['work_done_percentage'] }}</td>
<td>{{ htd['work_order_number'] }}</td>
<td>{{ htd['gst_amount'] }}</td>
<td>{{ htd['tds_amount'] }}</td>
<td>{{ htd[''] }}</td>
<td><a href="{{ url_for('update_work_order', id=htd['work_order_id']) }}">Edit</a></td>
<td>
<form action="{{ url_for('delete_work_order', id=htd['work_order_id']) }}" method="POST" style="display:inline;">
<button type="submit" onclick="return confirm('Are you sure you want to delete this work order?');" class="delete-button">Delete</button>
</form>
</td>
</tr>
{% endfor %}
</table>
<a href="/">Back to Dashboard</a>
</div>
<script>
$(document).ready(function () {
$('#displayButton').click(function () {
$('#addTable').toggle();
});
$('#addButton').click(function () {
$('#addForm').toggle();
// Bind input event handlers ONLY after form is shown
setTimeout(function () {
["work_order_amount", "gst_amount", "tds_amount", "security_deposit", "sd_against_gst"].forEach(function (id) {
document.getElementById(id).addEventListener("input", calculateFinalTotal);
});
}, 100); // Delay ensures elements are available in DOM
});
function calculateFinalTotal() {
const workOrderAmount = parseFloat(document.getElementById("work_order_amount").value) || 0;
const gstAmount = parseFloat(document.getElementById("gst_amount").value) || 0;
const tdsAmount = parseFloat(document.getElementById("tds_amount").value) || 0;
const securityDeposit = parseFloat(document.getElementById("security_deposit").value) || 0;
const sdAgainstGst = parseFloat(document.getElementById("sd_against_gst").value) || 0;
const finalTotal = workOrderAmount + gstAmount - (tdsAmount + securityDeposit + sdAgainstGst);
document.getElementById("final_total").value = finalTotal.toFixed(2);
}
});
</script>
</body>
{% endblock %}

View File

@@ -1,39 +0,0 @@
<!DOCTYPE html>
<html>
<head><title>Edit GRN</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<h2>Edit GRN</h2>
<form method="POST">
<label>GRN Date:</label>
<input type="date" name="grn_date" value="{{ grn['grn_date'] }}" required><br><br>
<label>Purchase ID:</label>
<input type="number" name="purchase_id" value="{{ grn['purchase_id'] }}" required><br><br>
<label>Supplier Name:</label>
<input type="text" name="supplier_name" value="{{ grn['supplier_name'] }}" required><br><br>
<label>Item Description:</label>
<input type="text" name="item_description" value="{{ grn['item_description'] }}" required><br><br>
<label>Received Quantity:</label>
<input type="number" name="received_quantity" value="{{ grn['received_quantity'] }}" required><br><br>
<label>Unit:</label>
<input type="text" name="unit" value="{{ grn['unit'] }}" required><br><br>
<label>Rate:</label>
<input type="number" step="0.01" name="rate" value="{{ grn['rate'] }}" required><br><br>
<label>Amount:</label>
<input type="number" step="0.01" name="amount" value="{{ grn['amount'] }}" required><br><br>
<label>Remarks:</label>
<input type="text" name="remarks" value="{{ grn['remarks'] }}"><br><br>
<input type="submit" value="Update GRN">
</form>
</body>
</html>

View File

@@ -1,47 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Edit Purchase</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<h2>Edit Purchase Order</h2>
<form method="POST">
<label>Purchase Date:</label>
<input type="date" name="purchase_date" value="{{ purchase['purchase_date'] }}" required><br><br>
<label>Supplier Name:</label>
<input type="text" name="supplier_name" value="{{ purchase['supplier_name'] }}" required><br><br>
<label>Purchase Order No:</label>
<input type="text" name="purchase_order_no" value="{{ purchase['purchase_order_no'] }}" required><br><br>
<label>Item Name:</label>
<input type="text" name="item_name" value="{{ purchase['item_name'] }}" required><br><br>
<label>Quantity:</label>
<input type="number" name="quantity" value="{{ purchase['quantity'] }}" required><br><br>
<label>Unit:</label>
<input type="text" name="unit" value="{{ purchase['unit'] }}" required><br><br>
<label>Rate:</label>
<input type="number" step="0.01" name="rate" value="{{ purchase['rate'] }}" required><br><br>
<label>Amount:</label>
<input type="number" step="0.01" name="amount" value="{{ purchase['amount'] }}" required><br><br>
<label>GST Amount:</label>
<input type="text" name="GST_Amount" value="{{ purchase['GST_Amount'] }}" required><br><br>
<label>TDS:</label>
<input type="number" step="0.01" name="TDS" value="{{ purchase['TDS'] }}" required><br><br>
<label>Final Amount:</label>
<input type="number" step="0.01" name="final_amount" value="{{ purchase['final_amount'] }}" required><br><br>
<input type="submit" value="Update">
</form>
</body>
</html>

View File

@@ -1,77 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>GRN Management</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<h2>Add GRN</h2>
<form method="POST" action="/add_grn">
<label>GRN Date:</label>
<input type="date" name="grn_date" required><br><br>
<label>Purchase ID:</label>
<input type="number" name="purchase_id" required><br><br>
{# <label for="purchase_id">Purchase Order:</label>#}
{# <select name="purchase_id" id="purchase_id" required>#}
{# {% for order in purchase_orders %}#}
{# <option value="{{ order['purchase_id'] }}">{{ order['supplier_name'] }}</option>#}
{# {% endfor %}#}
{#</select>#}
<label>Supplier Name:</label>
<input type="text" name="supplier_name" required><br><br>
<label>Item Description:</label>
<input type="text" name="item_description" required><br><br>
<label>Received Quantity:</label>
<input type="number" name="received_quantity" required><br><br>
<label>Unit:</label>
<input type="text" name="unit" required><br><br>
<label>Rate:</label>
<input type="number" step="0.01" name="rate" required><br><br>
<label>Amount:</label>
<input type="number" step="0.01" name="amount" required><br><br>
<label>Remarks:</label>
<input type="text" name="remarks"><br><br>
<input type="submit" value="Add GRN">
</form>
<h2>All GRNs</h2>
<table border="1">
<tr>
<th>ID</th><th>Date</th><th>Purchase ID</th><th>Supplier</th><th>Item</th>
<th>Qty</th><th>Unit</th><th>Rate</th><th>Amount</th><th>Remarks</th><th>Actions</th>
</tr>
{% for grn in grns %}
<tr>
<td>{{ grn[0] }}</td>
<td>{{ grn[1] }}</td>
<td>{{ grn[2] }}</td>
<td>{{ grn[3] }}</td>
<td>{{ grn[4] }}</td>
<td>{{ grn[5] }}</td>
<td>{{ grn[6] }}</td>
<td>{{ grn[7] }}</td>
<td>{{ grn[8] }}</td>
<td>{{ grn[9] }}</td>
<td style="white-space: nowrap;">
<a href="/update_grn/{{ grn['grn_id'] }}" style="margin-right: 10px;">Edit</a>
<form action="/delete_grn/{{ grn[0] }}" method="POST" style="display:inline;">
<button type="submit" onclick="return confirm('Are you sure you want to delete this GRN?')" style="background:none;border:none;color:blue;cursor:pointer;text-decoration:underline;">
Delete
</button>
</form>
</td>
</tr>
{% endfor %}
</table>
</body>
</html>

View File

@@ -133,30 +133,7 @@
<h2>Hold Types</h2>
<a class="btn" href="/add_hold_type">Go ➜</a>
</div>
<div class="card">
<h2>Work Order</h2>
<!-- <a class="btn" href="/add_work_order">Go ➜</a> -->
<a class="btn">Go ➜</a>
</div>
<!-- <div class="card">
<h2>Purchase Order</h2>
<a class="btn" href="/add_purchase_order">Go ➜</a>
</div> -->
<!-- <div class="card">
<h2>Goods Receive Note</h2>
<a class="btn" href="/add_grn">Go ➜</a>
</div> -->
<!-- <div class="card">
<h2>Unreleased GST</h2>
<a class="btn" href="/unreleased_gst">Go ➜</a>
</div>
{# <div class="card">#}
{# <h2>Hold Release </h2>#}
{# <a class="btn" href="/add_hold_release">Go ➜</a>#}
{# </div>#}
</div> -->
</div>
</body>

View File

@@ -1,10 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Purchase Order</title>
</head>
<body>
</body>
</html>

View File

@@ -1,205 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Purchase Order Report</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/subcontractor_report.css') }}">
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<style>
h2.report-title {
font-size: 28px;
color: #1a73e8;
text-align: center;
margin-top: 20px;
margin-bottom: 30px;
}
.filter-section {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
margin-bottom: 20px;
}
label {
font-weight: bold;
margin-right: 10px;
}
select {
padding: 6px;
}
#downloadBtn, #searchBtn {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
margin-top: 20px;
}
#downloadBtn:hover, #searchBtn:hover {
background-color: #45a049;
}
table {
margin: 0 auto;
margin-top: 30px;
border-collapse: collapse;
width: 95%;
}
th, td {
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<h2 class="report-title">Purchase Order Report</h2>
<div class="filter-section">
<div>
<label for="supplier_name">Select Supplier Name:</label>
<select id="supplier_name" name="supplier_name" style="width: 300px;"></select>
</div>
<div>
<label for="purchase_order_no">Select Purchase Order Number:</label>
<select id="purchase_order_no" name="purchase_order_no" style="width: 300px;"></select>
</div>
<button id="searchBtn">Search</button>
<button id="downloadBtn" style="display: none;">Download Report</button>
</div>
<table border="1" id="purchaseorderTable" style="display: none;">
<thead>
<tr>
<th>Purchase ID</th>
<th>Purchase Date</th>
<th>Supplier Name</th>
<th>Purchase Order No</th>
<th>Item Name</th>
<th>Quantity</th>
<th>Unit</th>
<th>Rate</th>
<th>Amount</th>
<th>GST Amount</th>
<th>TDS</th>
<th>Final Amount</th>
</tr>
</thead>
<tbody></tbody>
</table>
<!-- JS Scripts -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function () {
// Initialize Select2 for supplier_name
$('#supplier_name').select2({
placeholder: 'Search Supplier Name',
ajax: {
url: '/get_supplier_names',
data: function (params) {
return { q: params.term };
},
processResults: function (data) {
return {
results: data.map(name => ({ id: name, text: name }))
};
},
delay: 250,
cache: true
}
});
// Initialize Select2 for purchase_order_no
$('#purchase_order_no').select2({
placeholder: 'Search Purchase Order No',
ajax: {
url: '/get_purchase_order_numbers',
data: function (params) {
return {
q: params.term,
supplier_name: $('#supplier_name').val()
};
},
processResults: function (data) {
return {
results: data.map(no => ({ id: no, text: no }))
};
},
delay: 250,
cache: true
}
});
// Search button click
$('#searchBtn').click(function () {
let supplier = $('#supplier_name').val();
let poNumber = $('#purchase_order_no').val();
if (!supplier && !poNumber) {
alert("Please select Supplier or Purchase Order No or both.");
return;
}
$.ajax({
url: '/get_purchase_order_data',
data: {
supplier_name: supplier,
purchase_order_no: poNumber
},
success: function (data) {
let tbody = $('#purchaseorderTable tbody');
tbody.empty();
if (data.length > 0) {
$('#purchaseorderTable').show();
$('#downloadBtn').show();
data.forEach(function (row) {
tbody.append(`
<tr>
<td>${row.purchase_id}</td>
<td>${row.purchase_date}</td>
<td>${row.supplier_name}</td>
<td>${row.purchase_order_no}</td>
<td>${row.item_name}</td>
<td>${row.quantity}</td>
<td>${row.unit}</td>
<td>${row.rate}</td>
<td>${row.amount}</td>
<td>${row.GST_Amount}</td>
<td>${row.TDS}</td>
<td>${row.final_amount}</td>
</tr>
`);
});
} else {
alert("No matching purchase orders found.");
$('#purchaseorderTable').hide();
$('#downloadBtn').hide();
}
}
});
});
// Download report
$('#downloadBtn').click(function () {
let supplier = $('#supplier_name').val();
let poNumber = $('#purchase_order_no').val();
if (!supplier && !poNumber) {
alert("Please select filters before downloading.");
return;
}
let url = '/download_purchase_order_report?';
if (supplier) url += 'supplier_name=' + encodeURIComponent(supplier);
if (poNumber) url += '&purchase_order_no=' + encodeURIComponent(poNumber);
window.location.href = url;
});
});
</script>
</body>
</html>

View File

@@ -1,209 +0,0 @@
{% extends 'base.html' %}
{% block content %}
<head>
<title>Work Order Report</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/subcontractor_report.css') }}">
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<style>
h2.report-title {
font-size: 28px;
color: #1a73e8;
text-align: center;
margin-top: 20px;
margin-bottom: 30px;
}
.filter-section {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
margin-bottom: 20px;
}
label {
font-weight: bold;
margin-right: 10px;
}
select {
padding: 6px;
}
#downloadBtn, #searchBtn {
padding: 10px 20px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
margin-top: 20px;
}
#downloadBtn:hover, #searchBtn:hover {
background-color: #45a049;
}
table {
margin: 0 auto;
margin-top: 30px;
border-collapse: collapse;
width: 95%;
}
th, td {
padding: 10px;
text-align: center;
}
</style>
</head>
<body>
<h2 class="report-title">Work Order Report</h2>
<div class="filter-section">
<div>
<label for="vendor_name">Select Vendor Name:</label>
<select id="vendor_name" name="vendor_name" style="width: 300px;"></select>
</div>
<div>
<label for="work_order_number">Select Work Order Number:</label>
<select id="work_order_number" name="work_order_number" style="width: 300px;"></select>
</div>
<button id="searchBtn">Search</button>
<button id="downloadBtn" style="display: none;">Download Report</button>
</div>
<table border="1" id="workOrderTable" style="display: none;">
<thead>
<tr>
<th>ID</th>
<th>Vendor Name</th>
<th>Work Order Type</th>
<th>Amount</th>
<th>BOQ</th>
<th>Done %</th>
<th>GST</th>
<th>TDS</th>
<th>Security Deposit</th>
<th>SD GST</th>
<th>Final Total</th>
<th>TDS of GST</th>
</tr>
</thead>
<tbody></tbody>
</table>
<!-- JS Scripts -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
<script>
$(document).ready(function () {
$('#vendor_name, #work_order_number').select2({
placeholder: 'Search',
minimumInputLength: 1,
ajax: {
delay: 250,
dataType: 'json',
cache: true
}
});
$('#vendor_name').select2({
placeholder: 'Search Vendor',
ajax: {
url: '/get_vendor_names',
data: function (params) {
return { q: params.term };
},
processResults: function (data) {
return {
results: data.map(v => ({ id: v, text: v }))
};
}
}
});
$('#work_order_number').select2({
placeholder: 'Search Work Order',
ajax: {
url: '/get_work_order_numbers',
data: function (params) {
return {
q: params.term,
vendor_name: $('#vendor_name').val()
};
},
processResults: function (data) {
return {
results: data.map(o => ({ id: o, text: o }))
};
}
}
});
// Fetch and display table
$('#searchBtn').click(function () {
let vendor = $('#vendor_name').val();
let order = $('#work_order_number').val();
if (!vendor && !order) {
alert("Please select Vendor or Work Order Number or both.");
return;
}
$.ajax({
url: '/get_work_order_data',
data: {
vendor_name: vendor,
work_order_number: order
},
success: function (data) {
let tbody = $('#workOrderTable tbody');
tbody.empty();
if (data.length > 0) {
$('#workOrderTable').show();
$('#downloadBtn').show();
data.forEach(function (row) {
tbody.append(`
<tr>
<td>${row.work_order_id}</td>
<td>${row.vendor_name}</td>
<td>${row.work_order_type}</td>
<td>${row.work_order_amount}</td>
<td>${row.boq_amount}</td>
<td>${row.work_done_percentage}</td>
<td>${row.gst_amount}</td>
<td>${row.tds_amount}</td>
<td>${row.security_deposit}</td>
<td>${row.sd_against_gst}</td>
<td>${row.final_total}</td>
<td>${row.tds_of_gst}</td>
</tr>
`);
});
} else {
alert("No data found for selected filters.");
$('#workOrderTable').hide();
$('#downloadBtn').hide();
}
}
});
});
// Download report
$('#downloadBtn').click(function () {
let vendor = $('#vendor_name').val();
let order = $('#work_order_number').val();
if (!vendor && !order) {
alert("Please select filters before downloading.");
return;
}
let url = '/download_work_order_report?';
if (vendor) url += 'vendor_name=' + encodeURIComponent(vendor);
if (order) url += '&work_order_number=' + encodeURIComponent(order);
window.location.href = url;
});
});
</script>
</body>
{% endblock %}