Merge pull request 'dataase field updateds and model updateds' (#12) from pankaj-dev into main
Reviewed-on: #12
This commit was merged in pull request #12.
This commit is contained in:
@@ -13,6 +13,8 @@ from app.models.trench_excavation_model import TrenchExcavation
|
||||
from app.models.manhole_excavation_model import ManholeExcavation
|
||||
from app.models.laying_model import Laying
|
||||
|
||||
from app.models.subcontractor_model import Subcontractor
|
||||
|
||||
dashboard_bp = Blueprint("dashboard", __name__, url_prefix="/dashboard")
|
||||
|
||||
|
||||
@@ -23,97 +25,6 @@ def dashboard():
|
||||
return render_template("dashboard.html", title="Business Intelligence Dashboard")
|
||||
|
||||
|
||||
|
||||
|
||||
# import matplotlib
|
||||
# matplotlib.use("Agg")
|
||||
|
||||
# from flask import Blueprint, render_template, session, redirect, url_for
|
||||
# import matplotlib.pyplot as plt
|
||||
# import io
|
||||
# import base64
|
||||
# from app.utils.plot_utils import plot_to_base64
|
||||
# from app.services.dashboard_service import DashboardService
|
||||
|
||||
# dashboard_bp = Blueprint("dashboard", __name__, url_prefix="/dashboard")
|
||||
|
||||
# # dashboard_bp = Blueprint("dashboard", __name__)
|
||||
|
||||
# # charts
|
||||
# # def plot_to_base64():
|
||||
# # img = io.BytesIO()
|
||||
# # plt.savefig(img, format="png", bbox_inches="tight")
|
||||
# # plt.close()
|
||||
# # img.seek(0)
|
||||
# # return base64.b64encode(img.getvalue()).decode()
|
||||
|
||||
# # bar chart
|
||||
# def bar_chart():
|
||||
# categories = ["Trench", "Manhole", "Pipe Laying", "Restoration"]
|
||||
# values = [120, 80, 150, 60]
|
||||
|
||||
# plt.figure()
|
||||
# plt.bar(categories, values)
|
||||
# plt.title("Work Category Report")
|
||||
# plt.xlabel("test Category")
|
||||
# plt.ylabel("test Quantity")
|
||||
|
||||
|
||||
# return plot_to_base64(plt)
|
||||
|
||||
# # Pie chart
|
||||
# def pie_chart():
|
||||
# labels = ["Completed", "In Progress", "Pending"]
|
||||
# sizes = [55, 20, 25]
|
||||
|
||||
# plt.figure()
|
||||
# plt.pie(sizes, labels=labels, autopct="%1.1f%%", startangle=140)
|
||||
# plt.title("Project Status")
|
||||
|
||||
# return plot_to_base64(plt)
|
||||
|
||||
# # Histogram chart
|
||||
# def histogram_chart():
|
||||
# daily_work = [5, 10, 15, 20, 20, 25, 30, 35, 40, 45, 50]
|
||||
|
||||
# plt.figure()
|
||||
# plt.hist(daily_work, bins=5)
|
||||
# plt.title("Daily Work Distribution")
|
||||
# plt.xlabel("Work Units")
|
||||
# plt.ylabel("Frequency")
|
||||
|
||||
# return plot_to_base64(plt)
|
||||
|
||||
# # Dashboaed page
|
||||
# @dashboard_bp.route("/")
|
||||
# def dashboard():
|
||||
# if not session.get("user_id"):
|
||||
# return redirect(url_for("auth.login"))
|
||||
|
||||
# return render_template(
|
||||
# "dashboard.html",
|
||||
# title="Dashboard",
|
||||
# bar_chart=bar_chart(),
|
||||
# pie_chart=pie_chart(),
|
||||
# histogram=histogram_chart()
|
||||
# )
|
||||
|
||||
# # subcontractor dashboard
|
||||
# @dashboard_bp.route("/subcontractor_dashboard", methods=["GET", "POST"])
|
||||
# def subcontractor_dashboard():
|
||||
# if not session.get("user_id"):
|
||||
# return redirect(url_for("auth.login"))
|
||||
|
||||
# tr_dash = DashboardService().bar_chart_of_tr_ex
|
||||
|
||||
|
||||
# return render_template(
|
||||
# "subcontractor_dashboard.html",
|
||||
# title="Dashboard",
|
||||
# bar_chart=tr_dash
|
||||
# )
|
||||
|
||||
|
||||
@dashboard_bp.route("/api/live-stats")
|
||||
def live_stats():
|
||||
try:
|
||||
@@ -152,16 +63,49 @@ def live_stats():
|
||||
|
||||
|
||||
# subcontractor dashboard
|
||||
@dashboard_bp.route("/subcontractor_dashboard", methods=["GET", "POST"])
|
||||
@dashboard_bp.route("/subcontractor_dashboard")
|
||||
def subcontractor_dashboard():
|
||||
|
||||
if not session.get("user_id"):
|
||||
return redirect(url_for("auth.login"))
|
||||
|
||||
tr_dash = DashboardService().bar_chart_of_tr_ex
|
||||
|
||||
|
||||
subcontractors = Subcontractor.query.all()
|
||||
|
||||
return render_template(
|
||||
"subcontractor_dashboard.html",
|
||||
title="Dashboard",
|
||||
bar_chart=tr_dash
|
||||
)
|
||||
subcontractors=subcontractors
|
||||
)
|
||||
|
||||
|
||||
# API FOR CHART DATA
|
||||
@dashboard_bp.route("/api/subcontractor-chart")
|
||||
def subcontractor_chart():
|
||||
|
||||
subcontractor_id = request.args.get("subcontractor")
|
||||
category = request.args.get("category")
|
||||
ra_bill = request.args.get("ra_bill")
|
||||
|
||||
query = db.session.query(
|
||||
TrenchExcavation.excavation_category,
|
||||
func.sum(TrenchExcavation.Total)
|
||||
)
|
||||
|
||||
if subcontractor_id:
|
||||
query = query.filter(TrenchExcavation.subcontractor_id == subcontractor_id)
|
||||
|
||||
if ra_bill:
|
||||
query = query.filter(TrenchExcavation.RA_Bill_No == ra_bill)
|
||||
|
||||
results = query.group_by(TrenchExcavation.excavation_category).all()
|
||||
|
||||
labels = []
|
||||
values = []
|
||||
|
||||
for r in results:
|
||||
labels.append(r[0])
|
||||
values.append(float(r[1] or 0))
|
||||
|
||||
return jsonify({
|
||||
"labels": labels,
|
||||
"values": values
|
||||
})
|
||||
@@ -40,7 +40,8 @@ def save_subcontractor():
|
||||
address=request.form.get("address"),
|
||||
mobile_no=request.form.get("mobile_no"),
|
||||
email_id=request.form.get("email_id"),
|
||||
gst_no=request.form.get("gst_no")
|
||||
gst_no=request.form.get("gst_no"),
|
||||
pan_no=request.form.get("pan_no")
|
||||
)
|
||||
|
||||
db.session.add(subcontractor)
|
||||
@@ -120,6 +121,8 @@ def update_subcontractor(id):
|
||||
subcontractor.mobile_no = request.form.get("mobile_no")
|
||||
subcontractor.email_id = request.form.get("email_id")
|
||||
subcontractor.gst_no = request.form.get("gst_no")
|
||||
subcontractor.gst_no = request.form.get("pan_no")
|
||||
subcontractor.status = request.form.get("status")
|
||||
|
||||
db.session.commit()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user