diff --git a/controllers/district_controller.py b/controllers/district_controller.py index fe6efd7..7cbf337 100644 --- a/controllers/district_controller.py +++ b/controllers/district_controller.py @@ -5,12 +5,13 @@ from model.District import District from model.State import State district_bp = Blueprint('district', __name__) +district = District() # ------- District page -------- @district_bp.route('/add_district', methods=['GET', 'POST']) @login_required def add_district(): - district = District() + # district = District() if request.method == 'POST': district.AddDistrict(request=request) @@ -32,7 +33,7 @@ def add_district(): @login_required def check_district(): - district = District() + # district = District() return district.CheckDistrict(request=request) @@ -41,7 +42,7 @@ def check_district(): @login_required def delete_district(district_id): - district = District() + # district = District() district.DeleteDistrict(request=request, district_id=district_id) @@ -56,7 +57,7 @@ def delete_district(district_id): @login_required def edit_district(district_id): - district = District() + # district = District() state = State() if request.method == 'POST': diff --git a/controllers/report_controller.py b/controllers/report_controller.py index 55afc03..f471493 100644 --- a/controllers/report_controller.py +++ b/controllers/report_controller.py @@ -5,7 +5,7 @@ from model.Report import ReportHelper from model.Log import LogHelper import os -DOWNLOAD_FOLDER = "static/download" +# DOWNLOAD_FOLDER = "static/download" report_bp = Blueprint("report", __name__) @@ -58,6 +58,7 @@ def download_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 diff --git a/logs/activity.log b/logs/activity.log index 29fb355..65fffc8 100644 --- a/logs/activity.log +++ b/logs/activity.log @@ -9210,3 +9210,47 @@ Timestamp: 2026-03-31 15:56:33 | User: Unknown | Action: Download PMC Report | D Timestamp: 2026-03-31 15:56:48 | User: Unknown | Action: Download PMC Report | Details: Timestamp: 2026-03-31 15:57:43 | User: Unknown | Action: Download PMC Report | Details: Timestamp: 2026-03-31 16:15:32 | User: Unknown | Action: Download PMC Report | Details: +Timestamp: 2026-03-31 17:44:34 | User: Unknown | Action: Upload Excel File | Details: +Timestamp: 2026-03-31 17:44:42 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-03-31 17:44:42 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-03-31 17:44:42 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-03-31 17:44:42 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-03-31 17:44:42 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-03-31 17:44:42 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-03-31 17:44:42 | User: Unknown | Action: Data saved | Details: +Timestamp: 2026-03-31 17:46:40 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-03-31 17:46:40 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-03-31 17:46:42 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-03-31 17:46:48 | User: Unknown | Action: Download PMC Report | Details: +Timestamp: 2026-03-31 18:50:08 | User: Unknown | Action: Check Village | Details: +Timestamp: 2026-03-31 18:50:10 | User: Unknown | Action: Check Village | Details: +Timestamp: 2026-03-31 18:50:10 | User: Unknown | Action: Add Village | Details: +Timestamp: 2026-03-31 18:50:21 | User: Unknown | Action: Edit Village | Details: +Timestamp: 2026-03-31 18:50:29 | User: Unknown | Action: Delete Village | Details: +Timestamp: 2026-03-31 20:30:29 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-03-31 20:30:31 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-03-31 20:33:39 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-03-31 20:33:39 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-03-31 20:33:40 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-03-31 20:33:41 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-03-31 20:35:04 | User: Unknown | Action: Download PMC Report | Details: +Timestamp: 2026-04-01 10:15:01 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 10:15:01 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 10:15:01 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 10:15:03 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 10:15:05 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 10:15:12 | User: Unknown | Action: Download PMC Report | Details: +Timestamp: 2026-04-01 10:55:00 | User: Unknown | Action: Login | Details: +Timestamp: 2026-04-01 10:55:54 | User: Unknown | Action: Login | Details: +Timestamp: 2026-04-01 10:55:57 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 10:55:58 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 10:55:59 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 11:00:21 | User: Unknown | Action: Download PMC Report | Details: +Timestamp: 2026-04-01 11:01:33 | User: Unknown | Action: Download PMC Report | Details: +Timestamp: 2026-04-01 11:03:18 | User: Unknown | Action: Download PMC Report | Details: +Timestamp: 2026-04-01 11:03:36 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 11:03:37 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 11:03:37 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 11:03:39 | User: Unknown | Action: Search Contractor | Details: +Timestamp: 2026-04-01 11:03:44 | User: Unknown | Action: Download PMC Report | Details: +Timestamp: 2026-04-01 11:08:22 | User: Unknown | Action: Download PMC Report | Details: diff --git a/model/ItemCRUD.py b/model/ItemCRUD.py index 5ba53e3..cb2932b 100644 --- a/model/ItemCRUD.py +++ b/model/ItemCRUD.py @@ -332,7 +332,7 @@ class ItemCRUD: # ---------------------------------------------------------- # GET BY ID # ---------------------------------------------------------- - def GetDataByID(self, id, storedproc): + def GetDataByID(self, id, storedproc): data = None connection = config.get_db_connection() diff --git a/model/PmcReport.py b/model/PmcReport.py index e6638de..21ec353 100644 --- a/model/PmcReport.py +++ b/model/PmcReport.py @@ -146,6 +146,16 @@ class PmcReport: credit_notes = ReportHelper.execute_sp( cursor, 'NewGetCreditNotesByPMCNo', [pmc_no] ) + credit_note_map = {} + for cn in credit_notes: + # key = ( + # str(cn['PMC_No']).strip(), + # str(cn['Invoice_No']).replace(" ", "") if cn['Invoice_No'] else "" + # ) + key = ( + str(cn['PMC_No']).strip() + ) + credit_note_map.setdefault(key, []).append(cn) hold_amounts = ReportHelper.execute_sp( cursor, 'GetHoldAmountsByContractor', @@ -155,23 +165,33 @@ class PmcReport: gst_releases = ReportHelper.execute_sp( cursor, 'GetGSTReleaseDetailsByPMC', [pmc_no] ) + gst_release_map = {} + for gr in gst_releases: + # key = ( + # str(gr['PMC_No']).strip(), + # str(gr['Invoice_No']).replace(" ", "") if gr['Invoice_No'] else "" + # ) + 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'] - credit_note_map = {} - for cn in credit_notes: - pmc = cn.get("PMC_No") - if pmc: - credit_note_map.setdefault(pmc, []).append(cn) + # credit_note_map = {} + # for cn in credit_notes: + # pmc = cn.get("PMC_No") + # if pmc: + # credit_note_map.setdefault(pmc, []).append(cn) - gst_map = {} - for gst in gst_releases: - pmc = gst.get("PMC_No") - if pmc: - gst_map.setdefault(pmc, []).append(gst) + # gst_map = {} + # for gst in gst_releases: + # pmc = gst.get("PMC_No") + # if pmc: + # gst_map.setdefault(pmc, []).append(gst) # ================= LOG ================= LogHelper.log_action( @@ -179,116 +199,126 @@ class PmcReport: f"User {current_user.id} Download PMC Report '{pmc_no}'" ) - # ================= EXCEL ================= - workbook = openpyxl.Workbook() - sheet = workbook.active - sheet.title = "PMC Report" + # # ================= EXCEL ================= + # workbook = openpyxl.Workbook() + # sheet = workbook.active + # sheet.title = "PMC Report" - # HEADER INFO - sheet.append(["", "", "Laxmi Civil Engineering Services PVT. LTD."]) - sheet.append(["Contractor Name", contractor_info["Contractor_Name"]]) - sheet.append(["State", contractor_info["State_Name"]]) - sheet.append(["District", contractor_info["District_Name"]]) - sheet.append(["Block", contractor_info["Block_Name"]]) - sheet.append([]) + # # HEADER INFO + # sheet.append(["", "", "Laxmi Civil Engineering Services PVT. LTD."]) + # sheet.append(["Contractor Name", contractor_info["Contractor_Name"]]) + # sheet.append(["State", contractor_info["State_Name"]]) + # sheet.append(["District", contractor_info["District_Name"]]) + # sheet.append(["Block", contractor_info["Block_Name"]]) + # sheet.append([]) - base_headers = [ - "PMC No", "Village", "Work Type", "Invoice Details", - "Invoice Date", "Invoice No", "Basic Amount", "Debit", "After Debit Amount", - "GST", "Amount", "TDS", "SD", "On Commission", "Hydro Testing", "GST SD Amount" - ] + # base_headers = [ + # "PMC No", "Village", "Work Type", "Invoice Details", + # "Invoice Date", "Invoice No", "Basic Amount", "Debit", "After Debit Amount", + # "GST", "Amount", "TDS", "SD", "On Commission", "Hydro Testing", "GST SD Amount" + # ] - hold_headers = [ht['hold_type'] for ht in hold_types] - payment_headers = ["Final Amount", "Payment Amount", "TDS Payment", "Total Paid", "UTR"] + # hold_headers = [ht['hold_type'] for ht in hold_types] + # payment_headers = ["Final Amount", "Payment Amount", "TDS Payment", "Total Paid", "UTR"] - headers = base_headers + hold_headers + payment_headers - sheet.append(headers) - for cell in sheet[sheet.max_row]: - cell.font = Font(bold=True) + # headers = base_headers + hold_headers + payment_headers + # sheet.append(headers) + # for cell in sheet[sheet.max_row]: + # cell.font = Font(bold=True) - # ================= INVOICE ROWS ================= - for inv in invoices: - row = [ - pmc_no, - inv.get("Village_Name", ""), - inv.get("Work_Type", ""), - inv.get("Invoice_Details", ""), - inv.get("Invoice_Date", ""), - inv.get("invoice_no", ""), - inv.get("Basic_Amount", ""), - inv.get("Debit_Amount", ""), - inv.get("After_Debit_Amount", ""), - inv.get("GST_Amount", ""), - inv.get("Amount", ""), - inv.get("TDS_Amount", ""), - inv.get("SD_Amount", ""), - inv.get("On_Commission", ""), - inv.get("Hydro_Testing", ""), - inv.get("GST_SD_Amount", "") - ] + # # ================= INVOICE ROWS ================= + # for inv in invoices: + # row = [ + # pmc_no, + # inv.get("Village_Name", ""), + # inv.get("Work_Type", ""), + # inv.get("Invoice_Details", ""), + # inv.get("Invoice_Date", ""), + # inv.get("invoice_no", ""), + # inv.get("Basic_Amount", ""), + # inv.get("Debit_Amount", ""), + # inv.get("After_Debit_Amount", ""), + # inv.get("GST_Amount", ""), + # inv.get("Amount", ""), + # inv.get("TDS_Amount", ""), + # inv.get("SD_Amount", ""), + # inv.get("On_Commission", ""), + # inv.get("Hydro_Testing", ""), + # inv.get("GST_SD_Amount", "") + # ] - # HOLD DATA - invoice_holds = hold_data.get(inv.get("Invoice_Id"), {}) - for ht_id in hold_type_map.keys(): - row.append(invoice_holds.get(ht_id, "")) + # # HOLD DATA + # invoice_holds = hold_data.get(inv.get("Invoice_Id"), {}) + # for ht_id in hold_type_map.keys(): + # row.append(invoice_holds.get(ht_id, "")) - # PAYMENT DATA - row += [ - inv.get("Final_Amount", ""), - inv.get("Payment_Amount", ""), - inv.get("TDS_Payment_Amount", ""), - inv.get("Total_Amount", ""), - inv.get("UTR", "") - ] + # # PAYMENT DATA + # row += [ + # inv.get("Final_Amount", ""), + # inv.get("Payment_Amount", ""), + # inv.get("TDS_Payment_Amount", ""), + # inv.get("Total_Amount", ""), + # inv.get("UTR", "") + # ] - # GST release placeholders (will add real GST below) - row += ["", ""] + # # GST release placeholders (will add real GST below) + # row += ["", ""] - sheet.append(row) + # sheet.append(row) - for pmc, cn_list in credit_note_map.items(): - for cn in cn_list: - cn_row = [ - pmc_no, - "", "", "Credit Note", - "", cn.get("Invoice_No", ""), - cn.get("Basic_Amount", ""), - "", "", "", "", "", "", "", "", "", "", "" - ] - cn_row += [""] * len(hold_headers) - cn_row += [ - cn.get("Final_Amount", ""), - cn.get("Total_Amount", ""), - cn.get("UTR", "") - ] - sheet.append(cn_row) + # for pmc, cn_list in credit_note_map.items(): + # for cn in cn_list: + # cn_row = [ + # pmc_no, + # "", "", "Credit Note", + # "", cn.get("Invoice_No", ""), + # cn.get("Basic_Amount", ""), + # "", "", "", "", "", "", "", "", "", "", "" + # ] + # cn_row += [""] * len(hold_headers) + # cn_row += [ + # cn.get("Final_Amount", ""), + # cn.get("Total_Amount", ""), + # cn.get("UTR", "") + # ] + # sheet.append(cn_row) - # ================= GST RELEASE ROWS ================= - for gst in gst_releases: - gst_row = [ - gst.get("PMC_No", ""), - "", "", "GST Release Note", - "", gst.get("Invoice_No", ""), - gst.get("Basic_Amount", ""), - "", "", "", "", "", "", "", "", "" - ] - gst_row += [""] * len(hold_headers) - gst_row += [ - gst.get("Final_Amount", ""), - "", - "", - gst.get("Total_Amount", ""), - gst.get("UTR", "") - ] - sheet.append(gst_row) + # # ================= GST RELEASE ROWS ================= + # for gst in gst_releases: + # gst_row = [ + # gst.get("PMC_No", ""), + # "", "", "GST Release Note", + # "", gst.get("Invoice_No", ""), + # gst.get("Basic_Amount", ""), + # "", "", "", "", "", "", "", "", "" + # ] + # gst_row += [""] * len(hold_headers) + # gst_row += [ + # gst.get("Final_Amount", ""), + # "", + # "", + # gst.get("Total_Amount", ""), + # gst.get("UTR", "") + # ] + # sheet.append(gst_row) - # ================= AUTO WIDTH ================= - for col in sheet.columns: - max_len = max((len(str(cell.value)) for cell in col if cell.value), default=0) - sheet.column_dimensions[col[0].column_letter].width = max_len + 2 + # # ================= AUTO WIDTH ================= + # for col in sheet.columns: + # max_len = max((len(str(cell.value)) for cell in col if cell.value), default=0) + # sheet.column_dimensions[col[0].column_letter].width = max_len + 2 - workbook.save(output_file) - workbook.close() + # workbook.save(output_file) + # workbook.close() + + + ReportHelper.generate_excel( + 0, contractor_info, invoices, hold_types, hold_data, + credit_note_map,gst_release_map, output_file + ) + # ReportHelper.generate_excel( + # contractor_id, contInfo, invoices, hold_types, hold_data, + # credit_note_map, gst_release_map, output_file + # ) return output_folder, filename except Exception as e: diff --git a/model/Report.py b/model/Report.py index 2f1b254..7870f81 100644 --- a/model/Report.py +++ b/model/Report.py @@ -1,7 +1,6 @@ import config from datetime import datetime from flask import send_file -import os import openpyxl from openpyxl.styles import Font, PatternFill @@ -199,8 +198,8 @@ class ReportHelper: inv["invoice_no"].replace(" ", "") if inv["invoice_no"] else "" if inv["invoice_no"] not in (None, "", 0) else "" - ) - + ) + # key = (pmc_no, invoice_no) key = (pmc_no) diff --git a/model/Utilities.py b/model/Utilities.py index b38e644..d6e352a 100644 --- a/model/Utilities.py +++ b/model/Utilities.py @@ -9,6 +9,7 @@ class ItemCRUDType(Enum): HoldType = 5 Subcontractor = 6 GSTRelease = 7 + Invoice = 8 class RegEx: patternAlphabetOnly = r"^[A-Za-z ]+$"