changes of .env file

This commit is contained in:
2026-01-21 22:59:36 +05:30
parent 40fc148287
commit 7bdcee0656
18 changed files with 98 additions and 72 deletions

24
.env Normal file
View File

@@ -0,0 +1,24 @@
# -----------------------------
# Flask App Configuration
# -----------------------------
FLASK_ENV=development
FLASK_DEBUG=True
FLASK_HOST=0.0.0.0
FLASK_PORT=5010
# -----------------------------
# Security
# -----------------------------
SECRET_KEY=secret1234
# -----------------------------
# Database Configuration
# -----------------------------
DB_DIALECT=mysql
# DB_DRIVER=pymysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=test_income_taxdb
DB_USER=root
DB_PASSWORD=root

View File

@@ -4,8 +4,6 @@ import pandas as pd
import io import io
class AOHandler: class AOHandler:
def __init__(self): def __init__(self):
@@ -45,7 +43,6 @@ class AOHandler:
] ]
values = [data.get(f, 0) for f in fields] values = [data.get(f, 0) for f in fields]
print("---- values ---- ",values)
self.cursor.callproc("InsertAO", values) self.cursor.callproc("InsertAO", values)
self.conn.commit() self.conn.commit()
@@ -65,8 +62,6 @@ class AOHandler:
values = [id] + [data.get(f, 0) for f in fields] values = [id] + [data.get(f, 0) for f in fields]
print("AO update values:", values)
self.cursor.callproc("UpdateAOById", values) self.cursor.callproc("UpdateAOById", values)
self.conn.commit() self.conn.commit()

View File

@@ -3,10 +3,10 @@ import os
# Database Config # Database Config
class DBConfig: class DBConfig:
MYSQL_HOST = os.getenv("MYSQL_HOST", "127.0.0.1") MYSQL_HOST = os.getenv("DB_HOST")
MYSQL_USER = os.getenv("MYSQL_USER", "root") MYSQL_USER = os.getenv("DB_USER")
MYSQL_PASSWORD = os.getenv("MYSQL_PASSWORD", "root") MYSQL_PASSWORD = os.getenv("DB_PASSWORD")
MYSQL_DB = os.getenv("MYSQL_DB", "test_income_taxdb") MYSQL_DB = os.getenv("DB_NAME")
@staticmethod @staticmethod
def get_db_connection(): def get_db_connection():

View File

@@ -24,8 +24,6 @@ class ITRHandler:
# GET ALL ITR RECORDS using stored procedure "GetAllItr" # GET ALL ITR RECORDS using stored procedure "GetAllItr"
def get_all_itr(self): def get_all_itr(self):
# self.cursor = conn.cursor(dictionary=True)
self.cursor.callproc("GetAllItr") self.cursor.callproc("GetAllItr")
records = [] records = []
for result in self.cursor.stored_results(): for result in self.cursor.stored_results():
@@ -80,9 +78,6 @@ class ITRHandler:
] ]
values = [id] + [data.get(col, 0) for col in columns] values = [id] + [data.get(col, 0) for col in columns]
print("Final values:", values)
self.cursor.callproc("UpdateITR", values) self.cursor.callproc("UpdateITR", values)
self.conn.commit() self.conn.commit()
@@ -95,7 +90,6 @@ class ITRHandler:
# report download by year # report download by year
def itr_report_download(self, selected_year): def itr_report_download(self, selected_year):
try: try:
# Call stored procedure # Call stored procedure
self.cursor.callproc("GetITRByYear", [selected_year]) self.cursor.callproc("GetITRByYear", [selected_year])
@@ -109,14 +103,10 @@ class ITRHandler:
# Convert SQL rows to DataFrame # Convert SQL rows to DataFrame
df = pd.DataFrame(rows) df = pd.DataFrame(rows)
# Transpose # Transpose
df_transposed = df.transpose() df_transposed = df.transpose()
df_transposed.insert(0, 'Field', df_transposed.index) df_transposed.insert(0, 'Field', df_transposed.index)
print("df-->",df_transposed)
record_cols = { record_cols = {
i: f"Record {i}" i: f"Record {i}"
for i in df_transposed.columns if isinstance(i, int) for i in df_transposed.columns if isinstance(i, int)
@@ -139,7 +129,6 @@ class ITRHandler:
print("MySQL Error →", e) print("MySQL Error →", e)
return None return None
# CLOSE CONNECTION # CLOSE CONNECTION
def close(self): def close(self):
self.cursor.close() self.cursor.close()

View File

@@ -1,8 +1,6 @@
from AppCode.Config import DBConfig from AppCode.Config import DBConfig
import mysql.connector import mysql.connector
class MatCreditHandler: class MatCreditHandler:
def __init__(self): def __init__(self):

View File

@@ -11,27 +11,30 @@ class YearGet:
def get_year_by_model(self, proc_name): def get_year_by_model(self, proc_name):
try: try:
self.cursor.callproc(proc_name) self.cursor.callproc(proc_name)
years = [] years = []
for result in self.cursor.stored_results(): for result in self.cursor.stored_results():
rows = result.fetchall() rows = result.fetchall()
years = [row["year"] for row in rows] years = [row["year"] for row in rows]
print("-- years get --",years)
return years return years
except mysql.connector.Error as e: except mysql.connector.Error as e:
print("MySQL Error:", e) print("MySQL Error:", e)
return [] return []
# def get_all_year_in_all_model(self):
# self.cursor.callproc("AllYearsInAllModel")
# years = []
# for result in self.cursor.stored_results():
# rows = result.fetchall()
# years = [row["year"] for row in rows]
# return years
def CheckYearExists(self, table_name, year):
try:
self.cursor.callproc('CheckYearExists', (table_name, year))
result = 0
for result_set in self.cursor.stored_results():
result = result_set.fetchone()[0]
return {"exists": result > 0}
except mysql.connector.Error as e:
print("MySQL Error:", e)
return {"exists": False, "error": str(e)}
def close(self): def close(self):
self.cursor.close() self.cursor.close()

89
main.py
View File

@@ -1,11 +1,9 @@
from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort, flash,send_file ,jsonify from flask import Flask, render_template, request, redirect, url_for, send_from_directory, abort, flash,send_file ,jsonify
import os import os
from dotenv import load_dotenv
load_dotenv()
import pandas as pd import pandas as pd
import pymysql
import io
import mysql.connector
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from datetime import datetime
from AppCode.Config import DBConfig from AppCode.Config import DBConfig
from AppCode.FileHandler import FileHandler from AppCode.FileHandler import FileHandler
@@ -22,8 +20,8 @@ from AppCode.MatCreditHandler import MatCreditHandler
# Server # Server
app = Flask(__name__) app = Flask(__name__)
app.secret_key="secret1234" app.secret_key=os.getenv("SECRET_KEY")
app.config['UPLOAD_FOLDER'] = FileHandler.UPLOAD_FOLDER
auth = LoginAuth() auth = LoginAuth()
app.register_blueprint(auth.bp) app.register_blueprint(auth.bp)
@@ -40,13 +38,10 @@ def welcome():
def index(): def index():
return render_template('index.html') return render_template('index.html')
# Ensure folder exists
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in FileHandler.ALLOWED_EXTENSIONS
# Upload File route # Upload File route
@app.route('/upload', methods=['GET', 'POST']) @app.route('/upload', methods=['GET', 'POST'])
@auth.login_required
def upload_file(): def upload_file():
if request.method == 'POST': if request.method == 'POST':
FileHandler.CHeckExistingOrCreateNewUploadFolder() FileHandler.CHeckExistingOrCreateNewUploadFolder()
@@ -58,6 +53,7 @@ def upload_file():
# View all documents with filters # View all documents with filters
@app.route('/documents') @app.route('/documents')
@auth.login_required
def view_documents(): def view_documents():
docHandler = DocumentHandler() docHandler = DocumentHandler()
docHandler.View(request=request) docHandler.View(request=request)
@@ -66,15 +62,15 @@ def view_documents():
# Upload file documents # Upload file documents
@app.route('/uploads/<filename>') @app.route('/uploads/<filename>')
@auth.login_required
def uploaded_file(filename): def uploaded_file(filename):
mode = request.args.get('mode', 'view') mode = request.args.get('mode', 'view')
filepath = os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(filename)) filepath = os.path.join(FileHandler.UPLOAD_FOLDER, secure_filename(filename))
if not os.path.exists(filepath): if not os.path.exists(filepath):
abort(404) abort(404)
file_ext = filename.rsplit('.', 1)[-1].lower() file_ext = filename.rsplit('.', 1)[-1].lower()
# --- View Mode --- # --- View Mode ---
if mode == 'view': if mode == 'view':
if file_ext == 'pdf': if file_ext == 'pdf':
@@ -95,6 +91,7 @@ def uploaded_file(filename):
## 1. READ/DISPLAY all ITR records ## 1. READ/DISPLAY all ITR records
@app.route('/itr_records') @app.route('/itr_records')
@auth.login_required
def display_itr(): def display_itr():
itr = ITRHandler() itr = ITRHandler()
records = itr.get_all_itr() records = itr.get_all_itr()
@@ -104,6 +101,7 @@ def display_itr():
## 2. CREATE/ADD a new ITR record ## 2. CREATE/ADD a new ITR record
@app.route('/itr/add', methods=['GET', 'POST']) @app.route('/itr/add', methods=['GET', 'POST'])
@auth.login_required
def add_itr(): def add_itr():
if request.method == 'POST': if request.method == 'POST':
itr = ITRHandler() itr = ITRHandler()
@@ -116,6 +114,7 @@ def add_itr():
## 4. DELETE an ITR record ## 4. DELETE an ITR record
@app.route('/itr/delete/<int:id>', methods=['POST']) @app.route('/itr/delete/<int:id>', methods=['POST'])
@auth.login_required
def delete_itr(id): def delete_itr(id):
itr = ITRHandler() itr = ITRHandler()
itr.delete_itr_by_id(id=id) itr.delete_itr_by_id(id=id)
@@ -124,12 +123,13 @@ def delete_itr(id):
## 3. UPDATE an existing ITR record ## 3. UPDATE an existing ITR record
@app.route('/itr/update/<int:id>', methods=['GET', 'POST']) @app.route('/itr/update/<int:id>', methods=['GET', 'POST'])
@auth.login_required
def update_itr(id): def update_itr(id):
itr = ITRHandler() itr = ITRHandler()
if request.method == 'POST': if request.method == 'POST':
data = {k: request.form.get(k, 0) for k in request.form} # data = {k: request.form.get(k, 0) for k in request.form}
itr.update(id, data=data) itr.update(id, request.form)
itr.close() itr.close()
return redirect(url_for('display_itr')) return redirect(url_for('display_itr'))
@@ -146,6 +146,7 @@ def update_itr(id):
# 1. DISPLAY all AO records # 1. DISPLAY all AO records
@app.route('/ao_records') @app.route('/ao_records')
@auth.login_required
def display_ao(): def display_ao():
ao = AOHandler() ao = AOHandler()
ao_records = ao.get_all_ao() ao_records = ao.get_all_ao()
@@ -155,6 +156,7 @@ def display_ao():
# 2. ADD a new AO record # 2. ADD a new AO record
@app.route('/ao/add', methods=['GET', 'POST']) @app.route('/ao/add', methods=['GET', 'POST'])
@auth.login_required
def add_ao(): def add_ao():
if request.method == 'POST': if request.method == 'POST':
ao = AOHandler() ao = AOHandler()
@@ -166,6 +168,7 @@ def add_ao():
# 3. UPDATE AO record # 3. UPDATE AO record
@app.route('/ao/update/<int:id>', methods=['GET', 'POST']) @app.route('/ao/update/<int:id>', methods=['GET', 'POST'])
@auth.login_required
def update_ao(id): def update_ao(id):
ao = AOHandler() ao = AOHandler()
record = ao.get_ao_by_id(id) record = ao.get_ao_by_id(id)
@@ -186,6 +189,7 @@ def update_ao(id):
# 4. DELETE AO record safely # 4. DELETE AO record safely
@app.route('/ao/delete/<int:id>', methods=['POST']) @app.route('/ao/delete/<int:id>', methods=['POST'])
@auth.login_required
def delete_ao(id): def delete_ao(id):
ao = AOHandler() ao = AOHandler()
ao.delete_ao_by_id(id=id) ao.delete_ao_by_id(id=id)
@@ -201,6 +205,7 @@ def delete_ao(id):
# 1 DISPLAY all CIT records # 1 DISPLAY all CIT records
@app.route('/cit_records') @app.route('/cit_records')
@auth.login_required
def display_cit(): def display_cit():
cit = CITHandler() cit = CITHandler()
cit_records = cit.get_all_cit() cit_records = cit.get_all_cit()
@@ -209,6 +214,7 @@ def display_cit():
# 2 new CIT records add # 2 new CIT records add
@app.route('/cit/add', methods=['GET', 'POST']) @app.route('/cit/add', methods=['GET', 'POST'])
@auth.login_required
def add_cit(): def add_cit():
if request.method == 'POST': if request.method == 'POST':
cit = CITHandler() cit = CITHandler()
@@ -221,6 +227,7 @@ def add_cit():
# 3 delete CIT records by id # 3 delete CIT records by id
@app.route('/cit/delete/<int:id>', methods=['POST']) @app.route('/cit/delete/<int:id>', methods=['POST'])
@auth.login_required
def delete_cit(id): def delete_cit(id):
cit = CITHandler() cit = CITHandler()
cit.delete_cit(id) cit.delete_cit(id)
@@ -230,6 +237,7 @@ def delete_cit(id):
# 4 update CIT records by id # 4 update CIT records by id
@app.route('/cit/update/<int:id>', methods=['GET', 'POST']) @app.route('/cit/update/<int:id>', methods=['GET', 'POST'])
@auth.login_required
def update_cit(id): def update_cit(id):
cit = CITHandler() cit = CITHandler()
record = cit.get_cit_by_id(id) record = cit.get_cit_by_id(id)
@@ -239,8 +247,8 @@ def update_cit(id):
return "CIT record not found", 404 return "CIT record not found", 404
if request.method == 'POST': if request.method == 'POST':
data = {k: request.form.get(k, 0) for k in request.form} # data = {k: request.form.get(k, 0) for k in request.form}
cit.update_cit(id, data) cit.update_cit(id, request.form)
cit.close() cit.close()
return redirect(url_for('display_cit')) return redirect(url_for('display_cit'))
@@ -254,6 +262,7 @@ def update_cit(id):
# 1.DISPLAY all ITAT records # 1.DISPLAY all ITAT records
@app.route('/itat_records') @app.route('/itat_records')
@auth.login_required
def display_itat(): def display_itat():
itat = ITATHandler() itat = ITATHandler()
records = itat.get_all_itat() records = itat.get_all_itat()
@@ -262,6 +271,7 @@ def display_itat():
# 2.Add new ITAT records # 2.Add new ITAT records
@app.route('/itat/add', methods=['GET', 'POST']) @app.route('/itat/add', methods=['GET', 'POST'])
@auth.login_required
def add_itat(): def add_itat():
if request.method == 'POST': if request.method == 'POST':
itat = ITATHandler() itat = ITATHandler()
@@ -275,6 +285,7 @@ def add_itat():
# 3.Update ITAT records by id # 3.Update ITAT records by id
@app.route('/itat/update/<int:id>', methods=['GET', 'POST']) @app.route('/itat/update/<int:id>', methods=['GET', 'POST'])
@auth.login_required
def update_itat(id): def update_itat(id):
itat = ITATHandler() itat = ITATHandler()
record = itat.get_itat_by_id(id) record = itat.get_itat_by_id(id)
@@ -294,6 +305,7 @@ def update_itat(id):
# 3.delete ITAT records by id # 3.delete ITAT records by id
@app.route('/itat/delete/<int:id>', methods=['POST']) @app.route('/itat/delete/<int:id>', methods=['POST'])
@auth.login_required
def delete_itat(id): def delete_itat(id):
itat = ITATHandler() itat = ITATHandler()
itat.delete_itat_by_id(id) itat.delete_itat_by_id(id)
@@ -307,11 +319,13 @@ def delete_itat(id):
## ======================================================= ## =======================================================
# report page # report page
@app.route('/reports') @app.route('/reports')
@auth.login_required
def reports(): def reports():
return render_template("reports.html") return render_template("reports.html")
# Itr report download by year # Itr report download by year
@app.route('/itr_report', methods=['GET']) @app.route('/itr_report', methods=['GET'])
@auth.login_required
def itr_report(): def itr_report():
yearGetter = YearGet() yearGetter = YearGet()
selected_year = request.args.get('year') selected_year = request.args.get('year')
@@ -338,6 +352,7 @@ def itr_report():
# Ao report download by year # Ao report download by year
@app.route('/ao_report', methods=['GET']) @app.route('/ao_report', methods=['GET'])
@auth.login_required
def ao_report(): def ao_report():
yearGetter = YearGet() yearGetter = YearGet()
selected_year = request.args.get('year') selected_year = request.args.get('year')
@@ -365,6 +380,7 @@ def ao_report():
# Cit report download by year # Cit report download by year
@app.route('/cit_report', methods=['GET']) @app.route('/cit_report', methods=['GET'])
@auth.login_required
def cit_report(): def cit_report():
selected_year = request.args.get('year') selected_year = request.args.get('year')
yearGetter = YearGet() yearGetter = YearGet()
@@ -393,6 +409,7 @@ def cit_report():
# Itat report download by year # Itat report download by year
@app.route('/itat_report', methods=['GET']) @app.route('/itat_report', methods=['GET'])
@auth.login_required
def itat_report(): def itat_report():
selected_year = request.args.get('year') selected_year = request.args.get('year')
yearGetter = YearGet() yearGetter = YearGet()
@@ -421,34 +438,28 @@ def itat_report():
# summary report # summary report
@app.route('/summary_report', methods=['GET']) @app.route('/summary_report', methods=['GET'])
@auth.login_required
def summary_report(): def summary_report():
docHandler = DocumentHandler() docHandler = DocumentHandler()
return docHandler.Summary_report(request=request) return docHandler.Summary_report(request=request)
# new new -- check year in table existe or not by using ajax calling. # check year in table existe or not by using ajax calling.
@app.route('/check_year', methods=['POST']) # @app.route('/check_year', methods=['POST'])
def check_year(): # @auth.login_required
table_name = request.json.get("table") # def check_year():
year = request.json.get("year") # data = request.get_json()
# table_name = data.get("table")
# year = data.get("year")
conn = DBConfig.get_db_connection() # check_year_obj = YearGet()
cursor = conn.cursor() # result = check_year_obj.CheckYearExists(table_name, year)
# check_year_obj.close()
sqlstr = f"SELECT COUNT(*) FROM {table_name} WHERE year = %s"
cursor.execute(sqlstr, (year,))
result = cursor.fetchone()[0]
cursor.close()
conn.close()
return {"exists": result > 0}
# new new
# Mat credit from # Mat credit from
@app.route("/mat_credit", methods=["GET"]) @app.route("/mat_credit", methods=["GET"])
@auth.login_required
def mat_credit(): def mat_credit():
mat= MatCreditHandler() mat= MatCreditHandler()
@@ -473,6 +484,7 @@ def mat_credit():
# save mat credit row data # save mat credit row data
@app.route("/save_mat_row", methods=["POST"]) @app.route("/save_mat_row", methods=["POST"])
@auth.login_required
def save_mat_row(): def save_mat_row():
mat= MatCreditHandler() mat= MatCreditHandler()
try: try:
@@ -483,6 +495,7 @@ def save_mat_row():
# save mat credit bulk data # save mat credit bulk data
@app.route("/save_mat_all", methods=["POST"]) @app.route("/save_mat_all", methods=["POST"])
@auth.login_required
def save_mat_all(): def save_mat_all():
mat= MatCreditHandler() mat= MatCreditHandler()
try: try:
@@ -492,6 +505,10 @@ def save_mat_all():
return jsonify({"error": str(e)}), 500 return jsonify({"error": str(e)}), 500
# run # run server
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=5003, debug=True) app.run(
host=os.getenv("FLASK_HOST"),
port=int(os.getenv("FLASK_PORT")),
debug=os.getenv("FLASK_DEBUG") == "true"
)

View File

@@ -61,7 +61,7 @@
<br> <br>
<button onclick="addRow()"> Add Row</button> <button onclick="addRow()"> Add Row</button>
<button onclick="saveAll()">💾 Save All</button> <!-- <button onclick="saveAll()">💾 Save All</button> -->
</div> </div>