new fom of MAT credit add in table formate and update show

This commit is contained in:
2026-01-07 16:26:59 +05:30
parent 9c2486fdd6
commit 68511b7558
6 changed files with 595 additions and 6 deletions

58
main.py
View File

@@ -1,11 +1,11 @@
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort, flash,send_file
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort, flash,send_file ,jsonify
import os
import pandas as pd
import pymysql
import io
import mysql.connector
from werkzeug.utils import secure_filename
from datetime import datetime
from AppCode.Config import DBConfig
from AppCode.FileHandler import FileHandler
@@ -16,6 +16,8 @@ from AppCode.CITHandler import CITHandler
from AppCode.ITATHandler import ITATHandler
from AppCode.YearGet import YearGet
from AppCode.LoginAuth import LoginAuth
from AppCode.MatCreditHandler import MatCreditHandler
# Server
@@ -433,8 +435,8 @@ def check_year():
conn = DBConfig.get_db_connection()
cursor = conn.cursor()
query = f"SELECT COUNT(*) FROM {table_name} WHERE year = %s"
cursor.execute(query, (year,))
sqlstr = f"SELECT COUNT(*) FROM {table_name} WHERE year = %s"
cursor.execute(sqlstr, (year,))
result = cursor.fetchone()[0]
cursor.close()
@@ -442,6 +444,54 @@ def check_year():
return {"exists": result > 0}
# new new
# Mat credit from
@app.route("/mat_credit", methods=["GET"])
def mat_credit():
mat= MatCreditHandler()
mat_rows, utilization_rows = mat.fetch_all()
utilization_map = {}
all_years = set()
for u in utilization_rows:
all_years.add(u["utilized_year"])
utilization_map.setdefault(
u["mat_credit_id"], {}
)[u["utilized_year"]] = u["utilized_amount"]
return render_template(
"mat_credit.html",
mat_rows=mat_rows,
utilization_map=utilization_map,
added_years=sorted(all_years)
)
# save mat credit row data
@app.route("/save_mat_row", methods=["POST"])
def save_mat_row():
mat= MatCreditHandler()
try:
mat.save_single(request.json)
return jsonify({"message": "Row saved successfully"})
except Exception as e:
return jsonify({"error": str(e)}), 500
# save mat credit bulk data
@app.route("/save_mat_all", methods=["POST"])
def save_mat_all():
mat= MatCreditHandler()
try:
skipped = mat.save_bulk(request.json)
return jsonify({"message": "Saved successfully", "skipped": skipped})
except Exception as e:
return jsonify({"error": str(e)}), 500
# run
if __name__ == '__main__':