diff --git a/controllers/excel_upload_controller.py b/controllers/excel_upload_controller.py index 68f6aa9..5ab1bf4 100644 --- a/controllers/excel_upload_controller.py +++ b/controllers/excel_upload_controller.py @@ -188,7 +188,7 @@ def save_data(): "SD_Amount": entry.get("SD_Amount", 0.00), "On_Commission": entry.get("On_Commission", 0.00), "Hydro_Testing": entry.get("Hydro_Testing", 0.00), - "Hold_Amount": 0, + "Hold_Amount": entry.get("Hold_Amount", 0.00), # change "GST_SD_Amount": entry.get("GST_SD_Amount", 0.00), "Final_Amount": entry.get("Final_Amount", 0.00), "Payment_Amount": entry.get("Payment_Amount", 0.00), @@ -300,7 +300,8 @@ def save_data(): else: print("Hold columns data is not a valid list of dictionaries.") #---------------------------------------------Credit Note--------------------------------------------------------------------------- - elif any(keyword in Invoice_Details.lower() for keyword in ['credit note','logging report']): + # elif any(keyword in Invoice_Details.lower() for keyword in ['credit note ','credit note details','logging report']): + elif any(keyword in Invoice_Details.lower() for keyword in ['credit', 'logging report']): cursor.callproc( 'AddCreditNoteFromExcel', [ diff --git a/controllers/pmc_report_controller.py b/controllers/pmc_report_controller.py index 9b7313f..290ff70 100644 --- a/controllers/pmc_report_controller.py +++ b/controllers/pmc_report_controller.py @@ -1,14 +1,15 @@ -from flask import Blueprint, render_template, send_from_directory +from flask import Blueprint, render_template, send_from_directory,send_file from flask_login import login_required -from model.PmcReport import PmcReport - +# from model.PmcReport import PmcReport +from model.UnifiedReportService import UnifiedReportService pmc_report_bp = Blueprint("pmc_report", __name__) # ---------------- Contractor Report by pmc no ---------------- + @pmc_report_bp.route("/pmc_report/") @login_required def pmc_report(pmc_no): - data = PmcReport.get_pmc_report(pmc_no) + data = UnifiedReportService.get_report(pmc_no=pmc_no) if not data: return "No PMC found with this number", 404 @@ -17,24 +18,22 @@ def pmc_report(pmc_no): info=data["info"], invoices=data["invoices"], hold_types=data["hold_types"], + hold_data=data["hold_data"], # <-- add this line gst_rel=data["gst_rel"], payments=data["payments"], credit_note=data["credit_note"], hold_release=data["hold_release"], total=data["total"] ) - # ---------------- Contractor Download Report by pmc no ---------------- + @pmc_report_bp.route("/download_pmc_report/") @login_required def download_pmc_report(pmc_no): - result = PmcReport.download_pmc_report(pmc_no) + output_file = UnifiedReportService.download(pmc_no=pmc_no) - if not result: + if not output_file: return "No contractor found for this PMC No", 404 - output_folder, file_name = result - - return send_from_directory(output_folder, file_name, as_attachment=True) - + return send_file(output_file, as_attachment=True) \ No newline at end of file diff --git a/controllers/report_controller.py b/controllers/report_controller.py index a33f13b..e56080b 100644 --- a/controllers/report_controller.py +++ b/controllers/report_controller.py @@ -4,7 +4,7 @@ from flask_login import login_required, current_user from model.Report import ReportHelper from model.Log import LogHelper import os - +from model.UnifiedReportService import UnifiedReportService # DOWNLOAD_FOLDER = "static/download" report_bp = Blueprint("report", __name__) @@ -33,11 +33,13 @@ def search_contractor(): return jsonify(data) # ---------------- Contractor Report by contractor id ---------------- + @report_bp.route('/contractor_report/') @login_required def contractor_report(contractor_id): - data = ReportHelper.get_contractor_report(contractor_id) + # data = UnifiedReportService.get_report(contractor_id) + data = UnifiedReportService.get_report(contractor_id=contractor_id) return render_template( 'subcontractor_report.html', @@ -49,11 +51,10 @@ def contractor_report(contractor_id): @report_bp.route('/download_report/') def download_report(contractor_id): - output_file, error = ReportHelper.create_contractor_report(contractor_id) - - if error: - return error, 404 - - # Send the file to the user - return send_file(output_file, as_attachment=True) \ No newline at end of file + file_path = UnifiedReportService.download(contractor_id=contractor_id) + + if not file_path: + return "Report not found", 404 + + return send_file(file_path, as_attachment=True) \ No newline at end of file diff --git a/logs/activity.log b/logs/activity.log index d9e13ce..cee3aac 100644 --- a/logs/activity.log +++ b/logs/activity.log @@ -9263,3 +9263,321 @@ Timestamp: 2026-04-01 19:23:10 | User: Unknown | Action: Search Contractor | Det Timestamp: 2026-04-01 19:23:10 | User: Unknown | Action: Search Contractor | Details: Timestamp: 2026-04-01 19:23:13 | User: Unknown | Action: Search Contractor | Details: Timestamp: 2026-04-01 19:23:16 | User: Unknown | Action: Download PMC Report | Details: +Timestamp: 2026-04-02 10:33:02 | User: Unknown | Action: Login | Details: +Timestamp: 2026-04-02 10:33:05 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 10:33:06 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 10:33:08 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 10:55:31 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 10:55:32 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 10:55:33 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:06:51 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:06:52 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:06:52 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:06:53 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:06:54 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:06:54 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:07:32 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:07:32 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:07:33 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:07:33 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:07:35 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:19:31 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:19:31 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:19:33 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:23:34 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:23:34 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:23:36 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:28:47 | User: Unknown | Action: Login | Details: +Timestamp: 2026-04-02 11:28:52 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:28:52 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:28:52 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:28:54 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:28:57 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:29:45 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:29:46 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:29:47 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:29:47 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:29:47 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:29:49 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:30:06 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:30:06 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:30:07 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:30:07 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:30:10 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:30:10 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:30:11 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:30:11 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:30:11 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 11:30:24 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:03:05 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:03:05 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:03:05 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:03:06 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:03:06 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:03:12 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:03:13 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:05:48 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:05:48 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:05:50 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:03 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:04 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:04 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:05 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:06 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:07 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:35 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:35 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:36 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:36 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 12:06:38 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 13:15:22 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 13:15:29 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 14:52:17 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-02 14:53:17 | User: Unknown | Action: Login | Details: +Timestamp: 2026-04-02 14:53:25 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-02 14:54:01 | User: Unknown | Action: Login | Details: +Timestamp: 2026-04-02 14:54:17 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 14:54:21 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:01:17 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 15:01:17 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 15:01:18 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 15:02:19 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-02 15:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:23 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:02:31 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 15:02:31 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 15:02:33 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 15:03:31 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-02 15:06:09 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-02 15:06:12 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:12 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:12 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:12 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:12 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:12 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:12 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:12 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:12 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:13 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-02 15:06:20 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 15:06:21 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 15:06:23 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 18:12:06 | User: Unknown | Action: Login | Details: +Timestamp: 2026-04-02 18:30:50 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 18:30:50 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 18:30:50 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 18:30:52 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 18:30:53 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 18:41:05 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 18:41:06 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-02 18:41:07 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 10:00:04 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 10:00:05 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 10:00:05 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 10:00:07 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 17:42:58 | User: Unknown | Action: Login | Details: +Timestamp: 2026-04-03 17:43:03 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 17:43:03 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 17:43:04 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:01:33 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:01:33 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:01:35 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:01:35 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:01:35 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:01:49 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-03 18:01:49 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-03 18:02:07 | User: Unknown | Action: Add Hold Type | Details: +Timestamp: 2026-04-03 18:02:19 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:22 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:02:36 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:02:36 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:02:37 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:09:48 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:09:51 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-03 18:09:59 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-03 18:10:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:06:38 | User: Unknown | Action: Login | Details: +Timestamp: 2026-04-04 12:06:45 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-04 12:06:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:06:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:06:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:06:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:06:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:06:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:06:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:06:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:06:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:06:58 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 12:07:01 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 12:20:57 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-04 12:21:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:21:02 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:21:03 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:21:03 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:21:03 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:21:03 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:21:03 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:21:03 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:21:03 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:21:12 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 12:21:12 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 12:21:13 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 12:24:38 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 12:24:47 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-04 12:24:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:24:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:24:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:24:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:24:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:24:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:24:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:24:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:24:49 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 12:24:57 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 12:24:57 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 12:25:00 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 14:07:44 | User: Unknown | Action: Login | Details: +Timestamp: 2026-04-04 14:07:53 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 14:07:55 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 14:09:31 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:35 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-04-04 14:09:42 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 14:09:42 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 14:09:44 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 14:14:02 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 14:14:02 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-04 14:14:04 | User: Unknown | Action: Search Contractor | Details: diff --git a/model/PmcReport.py b/model/PmcReport.py index 628da52..6086d52 100644 --- a/model/PmcReport.py +++ b/model/PmcReport.py @@ -1,185 +1,185 @@ -import openpyxl -from openpyxl.styles import Font, PatternFill -import config -from flask_login import current_user -from model.Log import LogHelper -from model.excel import excel -from model.Report import ReportHelper -from model.FolderAndFile import FolderAndFile +# import openpyxl +# from openpyxl.styles import Font, PatternFill +# import config +# from flask_login import current_user +# from model.Log import LogHelper +# from model.excel import excel +# from model.Report import ReportHelper +# from model.FolderAndFile import FolderAndFile -class PmcReport: +# class PmcReport: - @staticmethod - def get_pmc_report(pmc_no): +# @staticmethod +# def get_pmc_report(pmc_no): - connection = config.get_db_connection() - cursor = connection.cursor(dictionary=True, buffered=True) +# connection = config.get_db_connection() +# cursor = connection.cursor(dictionary=True, buffered=True) - try: - pmc_info = ReportHelper.execute_sp(cursor, 'GetContractorInfoByPmcNo', [pmc_no], True) +# try: +# pmc_info = ReportHelper.execute_sp(cursor, 'GetContractorInfoByPmcNo', [pmc_no], True) - if not pmc_info: - return None +# if not pmc_info: +# return None - cursor.callproc("Get_pmc_hold_types", (pmc_no, pmc_info["Contractor_Id"])) - hold_types = next(cursor.stored_results()).fetchall() +# cursor.callproc("Get_pmc_hold_types", (pmc_no, pmc_info["Contractor_Id"])) +# hold_types = next(cursor.stored_results()).fetchall() - # Extract hold_type_ids - hold_type_ids = [ht['hold_type_id'] for ht in hold_types] +# # Extract hold_type_ids +# hold_type_ids = [ht['hold_type_id'] for ht in hold_types] - invoices = [] - hold_amount_total = 0 - hold_type_ids_str = ",".join(map(str, hold_type_ids)) - cursor.callproc( - 'GetInvoices_WithHold', - [pmc_no, pmc_info["Contractor_Id"], hold_type_ids_str] - ) +# invoices = [] +# hold_amount_total = 0 +# hold_type_ids_str = ",".join(map(str, hold_type_ids)) +# cursor.callproc( +# 'GetInvoices_WithHold', +# [pmc_no, pmc_info["Contractor_Id"], hold_type_ids_str] +# ) - for result in cursor.stored_results(): - invoices = result.fetchall() +# for result in cursor.stored_results(): +# invoices = result.fetchall() - if hold_type_ids: - hold_amount_total = sum(row.get('hold_amount', 0) or 0 for row in invoices) +# if hold_type_ids: +# hold_amount_total = sum(row.get('hold_amount', 0) or 0 for row in invoices) - total_invo_final = sum(row.get('Final_Amount', 0) or 0 for row in invoices) +# total_invo_final = sum(row.get('Final_Amount', 0) or 0 for row in invoices) - gst_rel = ReportHelper.execute_sp(cursor, 'GetGSTReleaseByPMC', [pmc_no]) - total_gst_basic = sum(row.get('basic_amount', 0) or 0 for row in gst_rel) - total_gst_final = sum(row.get('final_amount', 0) or 0 for row in gst_rel) +# gst_rel = ReportHelper.execute_sp(cursor, 'GetGSTReleaseByPMC', [pmc_no]) +# total_gst_basic = sum(row.get('basic_amount', 0) or 0 for row in gst_rel) +# total_gst_final = sum(row.get('final_amount', 0) or 0 for row in gst_rel) - hold_release = ReportHelper.execute_sp(cursor, 'GetHoldReleaseByPMC', [pmc_no]) +# hold_release = ReportHelper.execute_sp(cursor, 'GetHoldReleaseByPMC', [pmc_no]) - credit_note = ReportHelper.execute_sp(cursor, 'GetCreditNoteByPMC', [pmc_no]) +# credit_note = ReportHelper.execute_sp(cursor, 'GetCreditNoteByPMC', [pmc_no]) - payments = ReportHelper.execute_sp(cursor, 'GetPaymentsByPMC', [pmc_no]) - total_pay_amount = sum(row.get('Payment_Amount', 0) or 0 for row in payments) - total_pay_total = sum(row.get('Total_amount', 0) or 0 for row in payments) +# payments = ReportHelper.execute_sp(cursor, 'GetPaymentsByPMC', [pmc_no]) +# total_pay_amount = sum(row.get('Payment_Amount', 0) or 0 for row in payments) +# total_pay_total = sum(row.get('Total_amount', 0) or 0 for row in payments) - totals = { - "sum_invo_basic_amt": sum(row.get('Basic_Amount', 0) or 0 for row in invoices), - "sum_invo_debit_amt": sum(row.get('Debit_Amount', 0) or 0 for row in invoices), - "sum_invo_after_debit_amt": sum(row.get('After_Debit_Amount', 0) or 0 for row in invoices), - "sum_invo_amt": sum(row.get('Amount', 0) or 0 for row in invoices), - "sum_invo_gst_amt": sum(row.get('GST_Amount', 0) or 0 for row in invoices), - "sum_invo_tds_amt": sum(row.get('TDS_Amount', 0) or 0 for row in invoices), - "sum_invo_ds_amt": sum(row.get('SD_Amount', 0) or 0 for row in invoices), - "sum_invo_on_commission": sum(row.get('On_Commission', 0) or 0 for row in invoices), - "sum_invo_hydro_test": sum(row.get('Hydro_Testing', 0) or 0 for row in invoices), - "sum_invo_gst_sd_amt": sum(row.get('GST_SD_Amount', 0) or 0 for row in invoices), - "sum_invo_final_amt": total_invo_final, - "sum_invo_hold_amt": hold_amount_total, - "sum_gst_basic_amt": total_gst_basic, - "sum_gst_final_amt": total_gst_final, - "sum_pay_payment_amt": total_pay_amount, - "sum_pay_tds_payment_amt": sum(row.get('TDS_Payment_Amount', 0) or 0 for row in payments), - "sum_pay_total_amt": total_pay_total - } +# totals = { +# "sum_invo_basic_amt": sum(row.get('Basic_Amount', 0) or 0 for row in invoices), +# "sum_invo_debit_amt": sum(row.get('Debit_Amount', 0) or 0 for row in invoices), +# "sum_invo_after_debit_amt": sum(row.get('After_Debit_Amount', 0) or 0 for row in invoices), +# "sum_invo_amt": sum(row.get('Amount', 0) or 0 for row in invoices), +# "sum_invo_gst_amt": sum(row.get('GST_Amount', 0) or 0 for row in invoices), +# "sum_invo_tds_amt": sum(row.get('TDS_Amount', 0) or 0 for row in invoices), +# "sum_invo_ds_amt": sum(row.get('SD_Amount', 0) or 0 for row in invoices), +# "sum_invo_on_commission": sum(row.get('On_Commission', 0) or 0 for row in invoices), +# "sum_invo_hydro_test": sum(row.get('Hydro_Testing', 0) or 0 for row in invoices), +# "sum_invo_gst_sd_amt": sum(row.get('GST_SD_Amount', 0) or 0 for row in invoices), +# "sum_invo_final_amt": total_invo_final, +# "sum_invo_hold_amt": hold_amount_total, +# "sum_gst_basic_amt": total_gst_basic, +# "sum_gst_final_amt": total_gst_final, +# "sum_pay_payment_amt": total_pay_amount, +# "sum_pay_tds_payment_amt": sum(row.get('TDS_Payment_Amount', 0) or 0 for row in payments), +# "sum_pay_total_amt": total_pay_total +# } - return { - "info": pmc_info, - "invoices": invoices, - "hold_types": hold_types, - "gst_rel": gst_rel, - "payments": payments, - "credit_note": credit_note, - "hold_release": hold_release, - "total": totals - } +# return { +# "info": pmc_info, +# "invoices": invoices, +# "hold_types": hold_types, +# "gst_rel": gst_rel, +# "payments": payments, +# "credit_note": credit_note, +# "hold_release": hold_release, +# "total": totals +# } - finally: - cursor.close() - connection.close() +# finally: +# cursor.close() +# connection.close() - @staticmethod - def download_pmc_report(pmc_no): +# @staticmethod +# def download_pmc_report(pmc_no): - connection = config.get_db_connection() - if not connection: - return None +# connection = config.get_db_connection() +# if not connection: +# return None - cursor = connection.cursor(dictionary=True) +# cursor = connection.cursor(dictionary=True) - try: - filename = f"PMC_Report_{pmc_no}.xlsx" +# try: +# filename = f"PMC_Report_{pmc_no}.xlsx" - output_folder = FolderAndFile.get_download_folder() - output_file = FolderAndFile.get_download_path(filename) +# output_folder = FolderAndFile.get_download_folder() +# output_file = FolderAndFile.get_download_path(filename) - # ================= DATA FETCH ================= +# # ================= DATA FETCH ================= - contractor_info = ReportHelper.execute_sp( - cursor, 'GetContractorInfoByPmcNo', [pmc_no] - ) +# contractor_info = ReportHelper.execute_sp( +# cursor, 'GetContractorInfoByPmcNo', [pmc_no] +# ) - contractor_info = contractor_info[0] if contractor_info else None - print("contractor_info:::",contractor_info) +# contractor_info = contractor_info[0] if contractor_info else None +# print("contractor_info:::",contractor_info) - if not contractor_info: - return None +# if not contractor_info: +# return None - hold_types = ReportHelper.execute_sp( - cursor, 'GetHoldTypesByContractor', - [contractor_info["Contractor_Id"]] - ) +# hold_types = ReportHelper.execute_sp( +# cursor, 'GetHoldTypesByContractor', +# [contractor_info["Contractor_Id"]] +# ) - hold_type_map = { - ht['hold_type_id']: ht['hold_type'] for ht in hold_types - } +# hold_type_map = { +# ht['hold_type_id']: ht['hold_type'] for ht in hold_types +# } - invoices = ReportHelper.execute_sp( - cursor, 'GetInvoicesByContractorOrPMCNo', [None,pmc_no] - ) +# invoices = ReportHelper.execute_sp( +# cursor, 'GetInvoicesByContractorOrPMCNo', [None,pmc_no] +# ) - credit_notes = ReportHelper.execute_sp( - cursor, 'NewGetCreditNotesByPMCNo', [pmc_no] - ) - credit_note_map = {} - for cn in credit_notes: - key = ( - str(cn['PMC_No']).strip() - ) - credit_note_map.setdefault(key, []).append(cn) +# credit_notes = ReportHelper.execute_sp( +# cursor, 'NewGetCreditNotesByPMCNo', [pmc_no] +# ) +# credit_note_map = {} +# for cn in credit_notes: +# key = ( +# str(cn['PMC_No']).strip() +# ) +# credit_note_map.setdefault(key, []).append(cn) - hold_amounts = ReportHelper.execute_sp( - cursor, 'GetHoldAmountsByContractor', - [contractor_info["Contractor_Id"]] - ) +# hold_amounts = ReportHelper.execute_sp( +# cursor, 'GetHoldAmountsByContractor', +# [contractor_info["Contractor_Id"]] +# ) - gst_releases = ReportHelper.execute_sp( - cursor, 'GetGSTReleaseDetailsByPMC', [pmc_no] - ) - gst_release_map = {} - for gr in gst_releases: +# gst_releases = ReportHelper.execute_sp( +# cursor, 'GetGSTReleaseDetailsByPMC', [pmc_no] +# ) +# gst_release_map = {} +# for gr in gst_releases: - key = ( - str(gr['PMC_No']).strip() - ) - gst_release_map.setdefault(key, []).append(gr) +# key = ( +# str(gr['PMC_No']).strip() +# ) +# gst_release_map.setdefault(key, []).append(gr) - # ================= DATA MAPPING ================= - hold_data = {} - for h in hold_amounts: - hold_data.setdefault(h['Invoice_Id'], {})[h['hold_type_id']] = h['hold_amount'] +# # ================= DATA MAPPING ================= +# hold_data = {} +# for h in hold_amounts: +# hold_data.setdefault(h['Invoice_Id'], {})[h['hold_type_id']] = h['hold_amount'] - # ================= LOG ================= - LogHelper.log_action( - "Download PMC Report", - f"User {current_user.id} Download PMC Report '{pmc_no}'" - ) +# # ================= LOG ================= +# LogHelper.log_action( +# "Download PMC Report", +# f"User {current_user.id} Download PMC Report '{pmc_no}'" +# ) - excel.generate_excel( - 0, contractor_info, invoices, hold_types, hold_data, - credit_note_map,gst_release_map, output_file - ) +# excel.generate_excel( +# 0, contractor_info, invoices, hold_types, hold_data, +# credit_note_map,gst_release_map, output_file +# ) - return output_folder, filename +# return output_folder, filename - except Exception as e: - print(f"Error generating PMC report: {e}") - return None +# except Exception as e: +# print(f"Error generating PMC report: {e}") +# return None - finally: - cursor.close() - connection.close() +# finally: +# cursor.close() +# connection.close() diff --git a/model/Report.py b/model/Report.py index 7047d4f..71a3887 100644 --- a/model/Report.py +++ b/model/Report.py @@ -86,67 +86,7 @@ class ReportHelper: return data - @staticmethod - def get_contractor_report(contractor_id): - connection = config.get_db_connection() - cursor = connection.cursor(dictionary=True, buffered=True) - - try: - # Contractor Info (only one fetch) - contInfo = ReportHelper.execute_sp(cursor, 'GetContractorInfo', [contractor_id], True) - # Hold Types - hold_types = ReportHelper.execute_sp(cursor, 'GetContractorHoldTypes', [contractor_id]) - # Invoices - invoices = ReportHelper.execute_sp(cursor, 'GetContractorInvoices', [contractor_id]) - # GST Release - gst_rel = ReportHelper.execute_sp(cursor, 'GetGSTRelease', [contractor_id]) - # Hold Release - hold_release = ReportHelper.execute_sp(cursor, 'GetHoldRelease', [contractor_id]) - # Credit Note - credit_note = ReportHelper.execute_sp(cursor, 'GetCreditNotesByContractor', [contractor_id]) - # Payments - payments = ReportHelper.execute_sp(cursor, 'GetPayments', [contractor_id]) - - # Totals - total = { - "sum_invo_basic_amt": float(sum(row['Basic_Amount'] or 0 for row in invoices)), - "sum_invo_debit_amt": float(sum(row['Debit_Amount'] or 0 for row in invoices)), - "sum_invo_after_debit_amt": float(sum(row['After_Debit_Amount'] or 0 for row in invoices)), - "sum_invo_amt": float(sum(row['Amount'] or 0 for row in invoices)), - "sum_invo_gst_amt": float(sum(row['GST_Amount'] or 0 for row in invoices)), - "sum_invo_tds_amt": float(sum(row['TDS_Amount'] or 0 for row in invoices)), - "sum_invo_ds_amt": float(sum(row['SD_Amount'] or 0 for row in invoices)), - "sum_invo_on_commission": float(sum(row['On_Commission'] or 0 for row in invoices)), - "sum_invo_hydro_test": float(sum(row['Hydro_Testing'] or 0 for row in invoices)), - "sum_invo_gst_sd_amt": float(sum(row['GST_SD_Amount'] or 0 for row in invoices)), - "sum_invo_final_amt": float(sum(row['Final_Amount'] or 0 for row in invoices)), - "sum_invo_hold_amt": float(sum(row['hold_amount'] or 0 for row in invoices)), - - "sum_gst_basic_amt": float(sum(row['basic_amount'] or 0 for row in gst_rel)), - "sum_gst_final_amt": float(sum(row['final_amount'] or 0 for row in gst_rel)), - - "sum_pay_payment_amt": float(sum(row['Payment_Amount'] or 0 for row in payments)), - "sum_pay_tds_payment_amt": float(sum(row['TDS_Payment_Amount'] or 0 for row in payments)), - "sum_pay_total_amt": float(sum(row['Total_amount'] or 0 for row in payments)) - } - - current_date = datetime.now().strftime('%Y-%m-%d') - - finally: - cursor.close() - connection.close() - - return { - "contInfo": contInfo, - "invoices": invoices, - "hold_types": hold_types, - "gst_rel": gst_rel, - "payments": payments, - "credit_note": credit_note, - "hold_release": hold_release, - "total": total, - "current_date": current_date - } + @staticmethod def get_contractor_info(contractor_id): from model.ContractorInfo import ContractorInfo @@ -154,53 +94,4 @@ class ReportHelper: return contractor.contInfo if contractor.contInfo else None - @staticmethod - def create_contractor_report(contractor_id): - - fileName=f"Contractor_Report_{contractor_id}.xlsx" - output_file = FolderAndFile.get_download_path(filename=fileName) - - # Fetch Data - contInfo = ReportHelper.get_contractor_info(contractor_id) - if not contInfo: - return None, "No contractor found" - - connection = config.get_db_connection() - cursor = connection.cursor(dictionary=True, buffered=True) - - hold_types = ReportHelper.execute_sp(cursor, 'HoldTypesByContractorId', [contractor_id]) - invoices = ReportHelper.execute_sp(cursor, 'GetInvoicesByContractorOrPMCNo', [contractor_id,None]) - hold_amounts = ReportHelper.execute_sp(cursor, 'HoldAmountsByContractorId', [contractor_id]) - hold_data = {} - for h in hold_amounts: - hold_data.setdefault(h['Invoice_Id'], {})[h['hold_type_id']] = h['hold_amount'] - - # -------- Credit Note MAP -------- - credit_note_raw = ReportHelper.execute_sp(cursor, 'GetCreditNotesByContractor', [contractor_id]) - credit_note_map = {} - for cn in credit_note_raw: - - key = ( - str(cn['PMC_No']).strip() - ) - credit_note_map.setdefault(key, []).append(cn) - - # -------- GST MAP -------- - gst_release_raw = ReportHelper.execute_sp(cursor, 'GstReleasesByContractorId', [contractor_id]) - gst_release_map = {} - for gr in gst_release_raw: - key = ( - str(gr['PMC_No']).strip() - ) - gst_release_map.setdefault(key, []).append(gr) - - excel.generate_excel( - contractor_id, contInfo, invoices, hold_types, hold_data, - credit_note_map, gst_release_map, output_file - ) - - return output_file, None - - - - + \ No newline at end of file diff --git a/model/UnifiedReportService.py b/model/UnifiedReportService.py new file mode 100644 index 0000000..799fc96 --- /dev/null +++ b/model/UnifiedReportService.py @@ -0,0 +1,159 @@ +import config +from model.excel import excel +from model.Report import ReportHelper +from model.FolderAndFile import FolderAndFile +from decimal import Decimal +class UnifiedReportService: + + # Static variable to cache report data + _cached_report_data = None + _cached_contractor_id = None + _cached_pmc_no = None + + @staticmethod + def get_report(contractor_id=None, pmc_no=None): + + # If cached and same request, return cached data + if (UnifiedReportService._cached_report_data and + contractor_id == UnifiedReportService._cached_contractor_id and + pmc_no == UnifiedReportService._cached_pmc_no): + return UnifiedReportService._cached_report_data + + connection = config.get_db_connection() + cursor = connection.cursor(dictionary=True, buffered=True) + + try: + # ================= BASIC INFO ================= + if contractor_id: + info = ReportHelper.execute_sp(cursor,'GetContractorInfo',[contractor_id],True) + else: + info = ReportHelper.execute_sp(cursor,'GetContractorInfoByPmcNo',[pmc_no],True) + + + contractor_id = info["Contractor_Id"] if info else None + + if not info: + return None + + # ================= HOLD TYPES ================= + hold_types = ReportHelper.execute_sp(cursor,'GetHoldTypesByContractor',[contractor_id]) or [] + + + # ================= INVOICES ================= + if pmc_no: + invoices = ReportHelper.execute_sp(cursor,'GetInvoicesByContractorOrPMCNo',[None, pmc_no]) or [] + + credit_notes = ReportHelper.execute_sp(cursor,'NewGetCreditNotesByPMCNo',[pmc_no]) or [] + + gst_rel = ReportHelper.execute_sp(cursor,'GetGSTReleaseDetailsByPMC',[pmc_no]) or [] + + payments = ReportHelper.execute_sp(cursor,'GetPaymentsByPMC',[pmc_no]) or [] + + else: + invoices = ReportHelper.execute_sp(cursor,'GetInvoicesByContractorOrPMCNo',[contractor_id, None]) or [] + + credit_notes = ReportHelper.execute_sp(cursor,'GetCreditNotesByContractor',[contractor_id]) or [] + + gst_rel = ReportHelper.execute_sp(cursor,'GstReleasesByContractorId',[contractor_id]) or [] + + payments = ReportHelper.execute_sp(cursor,'GetPayments',[contractor_id]) or [] + + + # ================= HOLD AMOUNTS ================= + hold_amounts = ReportHelper.execute_sp(cursor,'GetHoldAmountsByContractor',[contractor_id]) or [] + + hold_data = {} + for h in hold_amounts: + hold_data.setdefault(h["Invoice_Id"], {})[h["hold_type_id"]] = h["hold_amount"] + + # ================= CREDIT NOTES ================= + + credit_note_map = {} + for cn in credit_notes: + key = str(cn.get("PMC_No")).strip() + credit_note_map.setdefault(key, []).append(cn) + + # ================= GST RELEASE ================= + gst_release_map = {} + for gr in gst_rel: + key = str(gr.get("PMC_No")).strip() + gst_release_map.setdefault(key, []).append(gr) + + # ================= PAYMENTS ================= + total = { + "sum_invo_basic_amt": sum(row.get('Basic_Amount', 0) or 0 for row in invoices), + "sum_invo_debit_amt": sum(row.get('Debit_Amount', 0) or 0 for row in invoices), + "sum_invo_after_debit_amt": sum(row.get('After_Debit_Amount', 0) or 0 for row in invoices), + "sum_invo_amt": sum(row.get('Amount', 0) or 0 for row in invoices), + "sum_invo_gst_amt": sum(row.get('GST_Amount', 0) or 0 for row in invoices), + "sum_invo_tds_amt": sum(row.get('TDS_Amount', 0) or 0 for row in invoices), + "sum_invo_ds_amt": sum(row.get('SD_Amount', 0) or 0 for row in invoices), + "sum_invo_on_commission": sum(row.get('On_Commission', 0) or 0 for row in invoices), + "sum_invo_hydro_test": sum(row.get('Hydro_Testing', 0) or 0 for row in invoices), + "sum_invo_gst_sd_amt": sum(row.get('GST_SD_Amount', 0) or 0 for row in invoices), + "sum_invo_final_amt": sum(r.get("Final_Amount", 0) or 0 for r in invoices), + "sum_invo_hold_amt": sum(r.get("hold_amount", 0) or 0 for r in hold_amounts), + "sum_gst_basic_amt": sum(r.get("Basic_Amount", 0) or 0 for r in gst_rel), + "sum_gst_final_amt": sum(r.get("Final_Amount", 0) or 0 for r in gst_rel), + "sum_gst_total_amt": sum(r.get("Total_Amount", 0) or 0 for r in gst_rel), + "sum_pay_total_amt": sum(Decimal(r.get("Total_amount") or 0) for r in payments), + "sum_pay_payment_amt": sum(Decimal(r.get("Total_amount") or 0) for r in payments), # same as above if you want + "sum_pay_tds_payment_amt": sum(Decimal(r.get("TDS_Payment_Amount") or 0) for r in payments), + + } + + # Prepare final report + report_data = { + "info": info, + "invoices": invoices, + "hold_types": hold_types, + "payments": payments, + "hold_data": hold_data, + "hold_release": hold_data, + "credit_note_map": credit_note_map, + "credit_note": credit_notes, + "gst_release_map": gst_release_map, + "gst_rel": gst_rel, + "total": total + } + + # Cache the report + UnifiedReportService._cached_report_data = report_data + UnifiedReportService._cached_contractor_id = contractor_id + UnifiedReportService._cached_pmc_no = pmc_no + + return report_data + + finally: + cursor.close() + connection.close() + + # ================= DOWNLOAD EXCEL ================= + @staticmethod + def download(contractor_id=None, pmc_no=None): + # Use cached report if available + report_data = UnifiedReportService.get_report(contractor_id, pmc_no) + + if not report_data: + return None + + fileName = ( + f"Contractor_Report_{contractor_id}.xlsx" + if contractor_id else f"PMC_Report_{pmc_no}.xlsx" + ) + + output_file = FolderAndFile.get_download_path(fileName) + + excel.generate_excel( + contractor_id or 0, + report_data["info"], + report_data["invoices"], + report_data["hold_types"], + report_data["hold_data"], + report_data["credit_note_map"], + report_data["gst_release_map"], + report_data["payments"], + output_file + ) + + return output_file \ No newline at end of file diff --git a/model/excel.py b/model/excel.py index 2d9560c..beaf037 100644 --- a/model/excel.py +++ b/model/excel.py @@ -10,16 +10,26 @@ from model.FolderAndFile import FolderAndFile class excel: @staticmethod - def generate_excel(contractor_id, contInfo, invoices, hold_types, hold_data, - credit_note_map, gst_release_map, output_file): - + # def generate_excel(contractor_id, contInfo, invoices, hold_types, hold_data, + # credit_note_map, gst_release_map, output_file): + def generate_excel( + contractor_id, + info, + invoices, + hold_types, + hold_data, + credit_note_map, + gst_release_map, + payments, + output_file + ): workbook = openpyxl.Workbook() sheet = workbook.active sheet.title = "Contractor Report" # Contractor Info - for field, value in contInfo.items(): + for field, value in info.items(): sheet.append([field.replace("_", " "), value]) sheet.append([]) diff --git a/static/images/icons/male_profile.jpeg b/static/images/icons/male_profile.jpeg new file mode 100644 index 0000000..5030590 Binary files /dev/null and b/static/images/icons/male_profile.jpeg differ diff --git a/templates/index.html b/templates/index.html index bc8094b..809a639 100644 --- a/templates/index.html +++ b/templates/index.html @@ -34,7 +34,7 @@ Logout @@ -106,134 +106,93 @@ -

Invoice Details

- - - - - - - - - - - - - - - - - - +

Invoice Details

+
PMC NoVillage NameWork TypeInvoice DetailsInvoice DateInvoice NoBasic AmountDebitAfter Debit AmtGST (18%)AmountTDS (1%)SD (5%)On CommissionHydro Testing
+ + + + + + + + + + + + + + + + + - - {% set hold_types = invoices | map(attribute='hold_type') | unique | list %} - {% for hold in hold_types %} - - {% endfor %} + + {% for ht in hold_types %} + + {% endfor %} - - - - - - {% if invoices %} - {% for invoice in invoices %} - - - - - - - - - - - - - - - - + + + + + + {% if invoices %} + {% for invoice in invoices %} + + + + + + + + + + + + + + + + - - {% set hold_types = invoices | map(attribute='hold_type') | unique | list %} - {% for hold in hold_types %} - - {% endfor %} + + {% for ht in hold_types %} + + {% endfor %} - - - + + + + {% endfor %} - {% endfor %} + + + + + + + + + + + + - - - - - - - - - - - + {% for ht in hold_types %} + + {% endfor %} - {% set hold_types = invoices | map(attribute='hold_type') | unique | list %} - {% for hold in hold_types %} - - {% endfor %} - - - - - - {% else %} - - - - {% endif %} - -
PMC NoVillage NameWork TypeInvoice DetailsInvoice DateInvoice NoBasic AmountDebitAfter Debit AmtGST (18%)AmountTDS (1%)SD (5%)On CommissionHydro Testing{{ hold }}{{ ht.hold_type }}GST SD (18%)Final Amount
{{ invoice.PMC_No }}{{ invoice.Village_Name.capitalize() }}{{ invoice.Work_Type }}{{ invoice.Invoice_Details }}{{ invoice.Invoice_Date }}{{ invoice.Invoice_No }}{{ invoice.Basic_Amount }}{{ invoice.Debit_Amount }}{{ invoice.After_Debit_Amount }}{{ invoice.GST_Amount }}{{ invoice.Amount }}{{ invoice.TDS_Amount }}{{ invoice.SD_Amount }}{{ invoice.On_Commission }}{{ invoice.Hydro_Testing }}GST SD (18%)Final Amount
{{ invoice.PMC_No }}{{ invoice.Village_Name }}{{ invoice.Work_Type }}{{ invoice.Invoice_Details }}{{ invoice.Invoice_Date }}{{ invoice.invoice_no }}{{ invoice.Basic_Amount }}{{ invoice.Debit_Amount }}{{ invoice.After_Debit_Amount }}{{ invoice.GST_Amount }}{{ invoice.Amount }}{{ invoice.TDS_Amount }}{{ invoice.SD_Amount }}{{ invoice.On_Commission }}{{ invoice.Hydro_Testing }} - {% if invoice.hold_type == hold %} - {{ invoice.hold_amount }} - {% else %} - 0.00 - {% endif %} - {{ hold_data.get(invoice.Invoice_Id, {}).get(ht.hold_type_id, 0) }}{{ invoice.GST_SD_Amount }}{{ invoice.Final_Amount }}
{{ invoice.GST_SD_Amount }}{{ invoice.Final_Amount }}
Total{{ total.sum_invo_basic_amt }}{{ total.get('sum_invo_debit_amt', 0) }}{{ total.get('sum_invo_after_debit_amt', 0) }}{{ total.get('sum_invo_gst_amt', 0) }}{{ total.get('sum_invo_amt', 0) }}{{ total.get('sum_invo_tds_amt', 0) }}{{ total.get('sum_invo_ds_amt', 0) }}{{ total.get('sum_invo_on_commission', 0) }}{{ total.get('sum_invo_hydro_test', 0) }}
Total{{total["sum_invo_basic_amt"]}}{{total["sum_invo_debit_amt"]}}{{total["sum_invo_after_debit_amt"]}}{{total["sum_invo_gst_amt"]}}{{total["sum_invo_amt"]}}{{total["sum_invo_tds_amt"]}}{{total["sum_invo_ds_amt"]}}{{total["sum_invo_on_commission"]}}{{total["sum_invo_hydro_test"]}}{{ total.sum_invo_hold_amt}}{{total["sum_invo_hold_amt"]}}{{total["sum_invo_gst_sd_amt"]}}{{total["sum_invo_final_amt"]}}
No invoices found.
- -

Hold Release

- - - - - - - - - - - - - {% if hold_release %} - {% for hold in hold_release %} - - - - - - - - - {% endfor %} - {% else %} - - - - {% endif %} - -
PMC NoInvoice NoInvoice DetailsBasic AmountTotal AmountUTR
{{ hold['PMC_No'] }}{{ hold['Invoice_No'] }}{{ hold['Invoice_Details'] }}{{ hold['Basic_Amount'] }}{{ hold['Total_Amount'] }}{{ hold['UTR'] }}
No data present
+ {{ total.get('sum_invo_gst_sd_amt', 0) }} + {{ total.sum_invo_final_amt }} + + {% else %} + + No invoices found. + + {% endif %} + + +
@@ -286,40 +245,57 @@

GST Release Note Details

- - - - - - - - +
PMC NoInvoice NoBasic AmountFinal Amount
+ + + + + + + + + + - - - {% if gst_rel %} - {% for gst in gst_rel %} - - - - - - - {% endfor %} - - + - - - - {% else %} - - - - {% endif %} - -
PMC NoInvoice NoBasic AmountFinal AmountTotal_AmountUTR
{{ gst.pmc_no }}{{ gst.invoice_no }}{{ gst.basic_amount }}{{ gst.final_amount }}
Total
{{total["sum_gst_basic_amt"]}}{{total["sum_gst_final_amt"]}}
No GST release found.
+ {% if gst_rel %} + + {% for gst in gst_rel %} + + + {{ gst.PMC_No }} + {{ gst.Invoice_No }} + {{ gst.Basic_Amount }} + {{ gst.Final_Amount }} + {{gst.Total_Amount}} + {{gst.UTR}} + + + {% endfor %} + + + Total + + {{ total["sum_gst_basic_amt"] }} + + {{ total["sum_gst_final_amt"] }} + {{total["sum_gst_total_amt"]}} + + + + + {% else %} + + + No GST release found. + + + {% endif %} + + +
@@ -350,7 +326,8 @@ Total - {{total["sum_pay_payment_amt"]}} + + 0.00 {{total["sum_pay_tds_payment_amt"]}} {{total["sum_pay_total_amt"]}}