update itr and ao from and auto save mat ceadit and utility

This commit is contained in:
2026-02-06 15:11:58 +05:30
parent a0f4568ba2
commit a9af2cde8a
43 changed files with 825 additions and 327 deletions

59
main.py
View File

@@ -15,6 +15,7 @@ from AppCode.AOHandler import AOHandler
from AppCode.CITHandler import CITHandler
from AppCode.ITATHandler import ITATHandler
from AppCode.MatCreditHandler import MatCreditHandler
import subprocess
@@ -59,7 +60,6 @@ def view_documents():
docHandler.View(request=request)
return render_template('view_docs.html', documents=docHandler.documents, years=docHandler.years)
# Upload file documents
@app.route('/uploads/<filename>')
@auth.login_required
@@ -68,20 +68,26 @@ def uploaded_file(filename):
filepath = os.path.join(FileHandler.UPLOAD_FOLDER, secure_filename(filename))
if not os.path.exists(filepath):
abort(404)
flash("Unsupported file type for viewing", "warning")
return redirect(url_for('view_documents'))
file_ext = filename.rsplit('.', 1)[-1].lower()
# --- View Mode ---
if mode == 'view':
# pdf
if file_ext == 'pdf':
return send_file(filepath, mimetype='application/pdf')
# Word
elif file_ext in ['doc', 'docx']:
return send_file(filepath, as_attachment=True)
# Excel
elif file_ext in ['xls', 'xlsx']:
# Excel cannot be rendered in-browser by Flask; trigger download instead
return send_file(filepath, as_attachment=False, download_name=filename, mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
else:
return abort(415) # Unsupported type for viewing
flash("Unsupported file type for viewing", "warning")
return redirect(url_for('view_documents'))
return send_file(filepath, as_attachment=True)
return send_file(filepath, as_attachment=True, download_name=filename)
@@ -105,13 +111,21 @@ def display_itr():
def add_itr():
if request.method == 'POST':
itr = ITRHandler()
mat = MatCreditHandler()
itr.add_itr(request.form)
itr.close()
if 'documents' in request.files:
doc = DocumentHandler()
doc.Upload(request)
# AUTO SAVE MAT FROM ITR
mat.save_from_itr(
year=request.form["year"],
mat_created=float(request.form.get("mat_credit_created", 0)),
mat_utilized=float(request.form.get("mat_credit_utilized", 0)),
remarks="Created via ITR"
)
# flash("ITR record added successfully!", "success")
flash("ITR record and documents uploaded successfully!", "success")
return redirect(url_for('display_itr'))
@@ -166,11 +180,25 @@ def display_ao():
def add_ao():
if request.method == 'POST':
ao = AOHandler()
mat = MatCreditHandler()
ao.add_ao(request.form)
ao.close()
if 'documents' in request.files:
doc = DocumentHandler()
doc.Upload(request)
# AUTO SAVE MAT FROM ITR
mat.save_from_itr(
year=request.form["year"],
mat_created=float(request.form.get("mat_credit_created", 0)),
mat_utilized=float(request.form.get("mat_credit_utilized", 0)),
remarks="Created via ITR"
)
flash("AO record added successfully!", "success")
return redirect(url_for('display_ao'))
return render_template('add_ao.html')
return render_template('add_ao.html',current_date=date.today().isoformat())
# 3. UPDATE AO record
@app.route('/ao/update/<int:id>', methods=['GET', 'POST'])
@@ -449,6 +477,17 @@ def summary_report():
docHandler = DocumentHandler()
return docHandler.Summary_report(request=request)
@app.route('/summary/download', methods=['GET'])
@auth.login_required
def download_summary():
year_raw = request.args.get('year')
if not year_raw:
return "Year parameter is required", 400
docHandler = DocumentHandler()
# reuse your existing Summary_report method
return docHandler.Summary_report(request=request)
# check year in table existe or not by using ajax calling.
# @app.route('/check_year', methods=['POST'])
@@ -519,6 +558,12 @@ def save_mat_row():
finally:
mat.close()
@app.route("/summary/preview")
def summary_preview_route():
handler = DocumentHandler()
return handler.Summary_preview(request)
# save mat credit bulk data
# @app.route("/save_mat_all", methods=["POST"])
# @auth.login_required