Merge pull request 'pankaj-dev' (#4) from pankaj-dev into main
Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -2,14 +2,13 @@ from flask import Blueprint, render_template, request, redirect, url_for, jsonif
|
||||
from flask_login import login_required
|
||||
|
||||
import config
|
||||
import mysql.connector
|
||||
|
||||
from model.Block import Block
|
||||
from model.Utilities import HtmlHelper
|
||||
|
||||
block_bp = Blueprint('block', __name__)
|
||||
|
||||
|
||||
#
|
||||
@block_bp.route('/add_block', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def add_block():
|
||||
|
||||
@@ -1,28 +1,16 @@
|
||||
import os
|
||||
import config
|
||||
import ast
|
||||
import re
|
||||
from flask_login import login_required
|
||||
import openpyxl
|
||||
from flask import Blueprint, request, render_template, redirect, url_for, jsonify, current_app
|
||||
from flask_login import current_user
|
||||
from flask_login import login_required
|
||||
from flask import Blueprint, request, render_template, redirect, url_for, jsonify
|
||||
|
||||
from model.Log import LogHelper
|
||||
import config
|
||||
from model.FolderAndFile import FolderAndFile
|
||||
|
||||
excel_bp = Blueprint('excel', __name__)
|
||||
|
||||
# Default folder in case config not set
|
||||
# DEFAULT_UPLOAD_FOLDER = 'uploads'
|
||||
|
||||
|
||||
# def get_upload_folder():
|
||||
# """Returns the upload folder from Flask config or default, ensures it exists."""
|
||||
# folder = current_app.config.get('UPLOAD_FOLDER', DEFAULT_UPLOAD_FOLDER)
|
||||
# if not os.path.exists(folder):
|
||||
# os.makedirs(folder)
|
||||
# return folder
|
||||
|
||||
|
||||
# ---------------- Upload Excel File ----------------
|
||||
@excel_bp.route('/upload_excel_file', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@@ -30,9 +18,6 @@ def upload():
|
||||
if request.method == 'POST':
|
||||
file = request.files.get('file')
|
||||
if file and file.filename.endswith('.xlsx'):
|
||||
# upload_folder = get_upload_folder()
|
||||
# filepath = os.path.join(upload_folder, file.filename)
|
||||
|
||||
filepath =FolderAndFile.get_upload_path(file.filename)
|
||||
|
||||
file.save(filepath)
|
||||
@@ -42,6 +27,9 @@ def upload():
|
||||
f"User {current_user.id} Upload Excel File '{file.filename}'"
|
||||
)
|
||||
return redirect(url_for('excel.show_table', filename=file.filename))
|
||||
else:
|
||||
return redirect(url_for('upload_excel_file'))
|
||||
|
||||
return render_template('uploadExcelFile.html')
|
||||
|
||||
|
||||
@@ -51,7 +39,6 @@ def show_table(filename):
|
||||
global data
|
||||
data = []
|
||||
|
||||
# filepath = os.path.join(get_upload_folder(), filename)
|
||||
filepath = FolderAndFile.get_upload_path(filename)
|
||||
wb = openpyxl.load_workbook(filepath, data_only=True)
|
||||
sheet = wb.active
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
from flask import Blueprint, render_template, send_from_directory
|
||||
from flask_login import login_required, current_user
|
||||
from flask_login import login_required
|
||||
|
||||
from model.PmcReport import PmcReport
|
||||
|
||||
pmc_report_bp = Blueprint("pmc_report", __name__)
|
||||
|
||||
# ---------------- Contractor Report by pmc no ----------------
|
||||
@pmc_report_bp.route("/pmc_report/<pmc_no>")
|
||||
@login_required
|
||||
def pmc_report(pmc_no):
|
||||
@@ -23,6 +25,7 @@ def pmc_report(pmc_no):
|
||||
total=data["total"]
|
||||
)
|
||||
|
||||
# ---------------- Contractor Download Report by pmc no ----------------
|
||||
@pmc_report_bp.route("/download_pmc_report/<pmc_no>")
|
||||
@login_required
|
||||
def download_pmc_report(pmc_no):
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
from flask import Blueprint, render_template, request, jsonify, send_file
|
||||
from flask import Blueprint, render_template, request, jsonify
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
from model.Report import ReportHelper
|
||||
from model.Log import LogHelper
|
||||
import config
|
||||
import os
|
||||
import openpyxl
|
||||
from openpyxl.styles import Font
|
||||
from model.ContractorInfo import ContractorInfo
|
||||
from model.FolderAndFile import FolderAndFile
|
||||
|
||||
|
||||
report_bp = Blueprint("report", __name__)
|
||||
@@ -36,7 +31,7 @@ def search_contractor():
|
||||
|
||||
return jsonify(data)
|
||||
|
||||
# ---------------- Contractor Report ----------------
|
||||
# ---------------- Contractor Report by contractor id ----------------
|
||||
@report_bp.route('/contractor_report/<int:contractor_id>')
|
||||
@login_required
|
||||
def contractor_report(contractor_id):
|
||||
@@ -49,145 +44,10 @@ def contractor_report(contractor_id):
|
||||
**data
|
||||
)
|
||||
|
||||
# ---------------- Contractor Download Report by contractor id ----------------
|
||||
@report_bp.route('/download_report/<int:contractor_id>')
|
||||
@login_required
|
||||
def download_report(contractor_id):
|
||||
|
||||
return ReportHelper().download_report(contractor_id=contractor_id)
|
||||
|
||||
|
||||
|
||||
|
||||
# @report_bp.route('/download_report/<int:contractor_id>')
|
||||
# @login_required
|
||||
# def download_report(contractor_id):
|
||||
# try:
|
||||
# connection = config.get_db_connection()
|
||||
# cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# # -------- Contractor Info --------
|
||||
# contractor = ContractorInfo(contractor_id)
|
||||
# contInfo = contractor.contInfo
|
||||
|
||||
# if not contInfo:
|
||||
# return "No contractor found", 404
|
||||
|
||||
# # -------- Invoice Data --------
|
||||
# cursor.callproc('FetchInvoicesByContractor', [contractor_id])
|
||||
|
||||
# invoices = []
|
||||
# for result in cursor.stored_results():
|
||||
# invoices.extend(result.fetchall())
|
||||
|
||||
# if not invoices:
|
||||
# return "No invoice data found"
|
||||
|
||||
# # -------- Create Workbook --------
|
||||
# workbook = openpyxl.Workbook()
|
||||
# sheet = workbook.active
|
||||
# sheet.title = "Contractor Report"
|
||||
|
||||
# # ================= CONTRACTOR DETAILS =================
|
||||
# sheet.append(["SUB CONTRACTOR DETAILS"])
|
||||
# sheet.cell(row=sheet.max_row, column=1).font = Font(bold=True)
|
||||
# sheet.append([])
|
||||
|
||||
# sheet.append(["Name", contInfo.get("Contractor_Name") or ""])
|
||||
# sheet.append(["Mobile No", contInfo.get("Mobile_No") or ""])
|
||||
# sheet.append(["Email", contInfo.get("Email") or ""])
|
||||
# sheet.append(["Village", contInfo.get("Village_Name") or ""])
|
||||
# sheet.append(["Block", contInfo.get("Block_Name") or ""])
|
||||
# sheet.append(["District", contInfo.get("District_Name") or ""])
|
||||
# sheet.append(["State", contInfo.get("State_Name") or ""])
|
||||
# sheet.append(["Address", contInfo.get("Address") or ""])
|
||||
# sheet.append(["GST No", contInfo.get("GST_No") or ""])
|
||||
# sheet.append(["PAN No", contInfo.get("PAN_No") or ""])
|
||||
# sheet.append([])
|
||||
# sheet.append([])
|
||||
|
||||
# # ================= TABLE HEADERS =================
|
||||
# headers = [
|
||||
# "PMC No", "Village", "Invoice No", "Invoice Date", "Work Type","Invoice_Details",
|
||||
# "Basic Amount", "Debit Amount", "After Debit Amount",
|
||||
# "Amount", "GST Amount", "TDS Amount", "SD Amount",
|
||||
# "On Commission", "Hydro Testing", "Hold Amount",
|
||||
# "GST SD Amount", "Final Amount",
|
||||
# "Payment Amount", "TDS Payment",
|
||||
# "Total Amount", "UTR"
|
||||
# ]
|
||||
# sheet.append(headers)
|
||||
# for col in range(1, len(headers) + 1):
|
||||
# sheet.cell(row=sheet.max_row, column=col).font = Font(bold=True)
|
||||
|
||||
# # ================= DATA =================
|
||||
# total_final = 0
|
||||
# total_payment = 0
|
||||
# total_amount = 0
|
||||
|
||||
# for inv in invoices:
|
||||
# row = [
|
||||
# inv.get("PMC_No"),
|
||||
# inv.get("Village_Name"),
|
||||
# inv.get("invoice_no"),
|
||||
# inv.get("Invoice_Date"),
|
||||
# inv.get("Work_Type"),
|
||||
# inv.get("Invoice_Details"),
|
||||
# inv.get("Basic_Amount"),
|
||||
# inv.get("Debit_Amount"),
|
||||
# inv.get("After_Debit_Amount"),
|
||||
# inv.get("Amount"),
|
||||
# inv.get("GST_Amount"),
|
||||
# inv.get("TDS_Amount"),
|
||||
# inv.get("SD_Amount"),
|
||||
# inv.get("On_Commission"),
|
||||
# inv.get("Hydro_Testing"),
|
||||
# inv.get("Hold_Amount"),
|
||||
# inv.get("GST_SD_Amount"),
|
||||
# inv.get("Final_Amount"),
|
||||
# inv.get("Payment_Amount"),
|
||||
# inv.get("TDS_Payment_Amount"),
|
||||
# inv.get("Total_Amount"),
|
||||
# inv.get("UTR")
|
||||
# ]
|
||||
|
||||
# total_final += float(inv.get("Final_Amount") or 0)
|
||||
# total_payment += float(inv.get("Payment_Amount") or 0)
|
||||
# total_amount += float(inv.get("Total_Amount") or 0)
|
||||
|
||||
# sheet.append(row)
|
||||
|
||||
# # ================= TOTAL ROW =================
|
||||
# sheet.append([])
|
||||
# sheet.append([
|
||||
# "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
|
||||
# "TOTAL",
|
||||
# total_final,
|
||||
# total_payment,
|
||||
# "",
|
||||
# total_amount,
|
||||
# ""
|
||||
# ])
|
||||
|
||||
# # ================= AUTO WIDTH =================
|
||||
# for column in sheet.columns:
|
||||
# max_length = 0
|
||||
# column_letter = column[0].column_letter
|
||||
# for cell in column:
|
||||
# if cell.value:
|
||||
# max_length = max(max_length, len(str(cell.value)))
|
||||
# sheet.column_dimensions[column_letter].width = max_length + 2
|
||||
|
||||
# # ================= SAVE FILE =================
|
||||
# # output_folder = "downloads"
|
||||
# # os.makedirs(output_folder, exist_ok=True)
|
||||
# # filename = f"Contractor_Report_{contInfo.get('Contractor_Name')}.xlsx"
|
||||
# # output_file = os.path.join(output_folder, filename)
|
||||
|
||||
# filename = f"Contractor_Report_{contInfo.get('Contractor_Name')}.xlsx"
|
||||
# output_file = FolderAndFile.get_download_path(filename)
|
||||
# workbook.save(output_file)
|
||||
|
||||
# return send_file(output_file, as_attachment=True)
|
||||
|
||||
# except Exception as e:
|
||||
# return str(e)
|
||||
|
||||
Reference in New Issue
Block a user