village, invoice and contractor info model and controller code
This commit is contained in:
@@ -1,102 +1,3 @@
|
||||
# # controllers/invoice_controller.py
|
||||
|
||||
# from flask import Blueprint, request, jsonify, render_template
|
||||
# from flask_login import login_required, current_user
|
||||
# from model.Invoice import *
|
||||
# from model.Log import LogHelper
|
||||
|
||||
# invoice_bp = Blueprint('invoice', __name__)
|
||||
|
||||
# # -------------------------------- Add Invoice ---------------------------------
|
||||
# @invoice_bp.route('/add_invoice', methods=['GET', 'POST'])
|
||||
# @login_required
|
||||
# def add_invoice():
|
||||
# if request.method == 'POST':
|
||||
# try:
|
||||
# village_name = request.form.get('village')
|
||||
# village_result = get_village_id(village_name)
|
||||
|
||||
# if not village_result:
|
||||
# return jsonify({"status": "error", "message": f"Village '{village_name}' not found"}), 400
|
||||
|
||||
# village_id = village_result['Village_Id']
|
||||
# data = request.form
|
||||
|
||||
# invoice_id = insert_invoice(data, village_id)
|
||||
# assign_subcontractor(data, village_id)
|
||||
# insert_hold_types(data, invoice_id)
|
||||
|
||||
# LogHelper.log_action("Add invoice", f"User {current_user.id} Added invoice '{data.get('pmc_no')}'")
|
||||
|
||||
# return jsonify({"status": "success", "message": "Invoice added successfully"}), 201
|
||||
|
||||
# except Exception as e:
|
||||
# return jsonify({"status": "error", "message": str(e)}), 500
|
||||
|
||||
# invoices = get_all_invoice_details()
|
||||
# villages = get_all_villages()
|
||||
# return render_template('add_invoice.html', invoices=invoices, villages=villages)
|
||||
|
||||
|
||||
# # ------------------- Search Subcontractor -------------------
|
||||
# @invoice_bp.route('/search_subcontractor', methods=['POST'])
|
||||
# @login_required
|
||||
# def search_subcontractor():
|
||||
# sub_query = request.form.get("query")
|
||||
# results = search_contractors(sub_query)
|
||||
|
||||
# if not results:
|
||||
# return "<li>No subcontractor found</li>"
|
||||
|
||||
# output = "".join(
|
||||
# f"<li data-id='{row['Contractor_Id']}'>{row['Contractor_Name']}</li>"
|
||||
# for row in results
|
||||
# )
|
||||
# return output
|
||||
|
||||
|
||||
# # ------------------- Get Hold Types -------------------
|
||||
# @invoice_bp.route('/get_hold_types', methods=['GET'])
|
||||
# @login_required
|
||||
# def get_hold_types():
|
||||
# hold_types = get_all_hold_types()
|
||||
# LogHelper.log_action("Get hold type", f"User {current_user.id} Get hold type '{hold_types}'")
|
||||
# return jsonify(hold_types)
|
||||
|
||||
|
||||
# # ------------------- Edit Invoice -------------------
|
||||
# @invoice_bp.route('/edit_invoice/<int:invoice_id>', methods=['GET', 'POST'])
|
||||
# @login_required
|
||||
# def edit_invoice(invoice_id):
|
||||
# if request.method == 'POST':
|
||||
# data = request.form
|
||||
# update_invoice(data, invoice_id)
|
||||
# update_inpayment(data)
|
||||
|
||||
# LogHelper.log_action("Edit invoice", f"User {current_user.id} Edit invoice '{invoice_id}'")
|
||||
# return jsonify({"status": "success", "message": "Invoice updated successfully"}), 200
|
||||
|
||||
# invoice = get_invoice_by_id(invoice_id)
|
||||
# return render_template('edit_invoice.html', invoice=invoice)
|
||||
|
||||
|
||||
# # ------------------- Delete Invoice -------------------
|
||||
# @invoice_bp.route('/delete_invoice/<int:invoice_id>', methods=['GET'])
|
||||
# @login_required
|
||||
# def delete_invoice_route(invoice_id):
|
||||
# try:
|
||||
# delete_invoice_data(invoice_id, current_user.id)
|
||||
# LogHelper.log_action("Delete Invoice", f"User {current_user.id} deleted Invoice '{invoice_id}'")
|
||||
# return jsonify({
|
||||
# "message": f"Invoice {invoice_id} deleted successfully.",
|
||||
# "status": "success"
|
||||
# })
|
||||
# except Exception as e:
|
||||
# return jsonify({
|
||||
# "message": str(e),
|
||||
# "status": "error"
|
||||
# }), 500
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,170 +1,4 @@
|
||||
# from flask import Blueprint, render_template, request, redirect, url_for, flash, jsonify
|
||||
# from flask_login import login_required
|
||||
|
||||
# import config
|
||||
|
||||
# from model.Village import Village
|
||||
# from model.State import State
|
||||
|
||||
# # Create Blueprint
|
||||
# village_bp = Blueprint('village', __name__)
|
||||
|
||||
|
||||
# # ------------------------- Add Village -------------------------
|
||||
# @village_bp.route('/add_village', methods=['GET', 'POST'])
|
||||
# @login_required
|
||||
# def add_village():
|
||||
|
||||
# village = Village()
|
||||
|
||||
# if request.method == 'POST':
|
||||
# village.AddVillage(request=request)
|
||||
# return village.resultMessage
|
||||
|
||||
# state = State()
|
||||
# states = state.GetAllStates(request=request)
|
||||
|
||||
# villages = village.GetAllVillages(request=request)
|
||||
|
||||
# return render_template(
|
||||
# 'add_village.html',
|
||||
# states=states,
|
||||
# villages=villages
|
||||
# )
|
||||
|
||||
|
||||
# # ------------------------- Fetch Districts -------------------------
|
||||
# @village_bp.route('/get_districts/<int:state_id>')
|
||||
# @login_required
|
||||
# def get_districts(state_id):
|
||||
|
||||
# connection = config.get_db_connection()
|
||||
# cursor = connection.cursor()
|
||||
|
||||
# cursor.callproc("GetDistrictByStateID", [state_id])
|
||||
|
||||
# districts = []
|
||||
|
||||
# for rs in cursor.stored_results():
|
||||
# districts = rs.fetchall()
|
||||
|
||||
# cursor.close()
|
||||
# connection.close()
|
||||
|
||||
# district_list = []
|
||||
|
||||
# for d in districts:
|
||||
# district_list.append({
|
||||
# "id": d[0],
|
||||
# "name": d[1]
|
||||
# })
|
||||
|
||||
# return jsonify(district_list)
|
||||
|
||||
|
||||
# # ------------------------- Fetch Blocks -------------------------
|
||||
# @village_bp.route('/get_blocks/<int:district_id>')
|
||||
# @login_required
|
||||
# def get_blocks(district_id):
|
||||
|
||||
# connection = config.get_db_connection()
|
||||
# cursor = connection.cursor()
|
||||
|
||||
# cursor.callproc("GetBlocksByDistrictID", [district_id])
|
||||
|
||||
# blocks = []
|
||||
|
||||
# for rs in cursor.stored_results():
|
||||
# blocks = rs.fetchall()
|
||||
|
||||
# cursor.close()
|
||||
# connection.close()
|
||||
|
||||
# block_list = []
|
||||
|
||||
# for b in blocks:
|
||||
# block_list.append({
|
||||
# "id": b[0],
|
||||
# "name": b[1]
|
||||
# })
|
||||
|
||||
# return jsonify(block_list)
|
||||
|
||||
|
||||
# # ------------------------- Check Village -------------------------
|
||||
# @village_bp.route('/check_village', methods=['POST'])
|
||||
# @login_required
|
||||
# def check_village():
|
||||
|
||||
# village = Village()
|
||||
# return village.CheckVillage(request=request)
|
||||
|
||||
|
||||
# # ------------------------- Delete Village -------------------------
|
||||
# @village_bp.route('/delete_village/<int:village_id>')
|
||||
# @login_required
|
||||
# def delete_village(village_id):
|
||||
|
||||
# village = Village()
|
||||
|
||||
# village.DeleteVillage(request=request, village_id=village_id)
|
||||
|
||||
# if not village.isSuccess:
|
||||
# flash(village.resultMessage, "error")
|
||||
# else:
|
||||
# flash(village.resultMessage, "success")
|
||||
|
||||
# return redirect(url_for('village.add_village'))
|
||||
|
||||
|
||||
# # ------------------------- Edit Village -------------------------
|
||||
# @village_bp.route('/edit_village/<int:village_id>', methods=['GET', 'POST'])
|
||||
# @login_required
|
||||
# def edit_village(village_id):
|
||||
|
||||
# village = Village()
|
||||
|
||||
# if request.method == 'POST':
|
||||
|
||||
# village.EditVillage(request=request, village_id=village_id)
|
||||
|
||||
# if village.isSuccess:
|
||||
# flash(village.resultMessage, "success")
|
||||
# return redirect(url_for('village.add_village'))
|
||||
|
||||
# else:
|
||||
# flash(village.resultMessage, "error")
|
||||
|
||||
# village_data = village.GetVillageByID(id=village_id)
|
||||
# blocks = village.GetAllBlocks()
|
||||
|
||||
# return render_template(
|
||||
# 'edit_village.html',
|
||||
# village_data=village_data,
|
||||
# blocks=blocks
|
||||
# )
|
||||
|
||||
# else:
|
||||
|
||||
# village_data = village.GetVillageByID(request=request, id=village_id)
|
||||
|
||||
# if not village.isSuccess:
|
||||
# flash(village.resultMessage, "error")
|
||||
# return redirect(url_for('village.add_village'))
|
||||
|
||||
# blocks = village.GetAllBlocks(request=request)
|
||||
|
||||
# if village_data is None:
|
||||
# village_data = []
|
||||
|
||||
# if blocks is None:
|
||||
# blocks = []
|
||||
|
||||
# return render_template(
|
||||
# 'edit_village.html',
|
||||
# village_data=village_data,
|
||||
# blocks=blocks
|
||||
# )
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,76 +1,5 @@
|
||||
# import mysql.connector
|
||||
# from mysql.connector import Error
|
||||
# import config
|
||||
# import openpyxl
|
||||
# import os
|
||||
# import re
|
||||
# import ast
|
||||
# from datetime import datetime
|
||||
|
||||
|
||||
# class ContractorInfo:
|
||||
# ID = ""
|
||||
# contInfo = None
|
||||
# def __init__(self, id):
|
||||
# self.ID = id
|
||||
# print(id)
|
||||
# self.fetchData()
|
||||
|
||||
# def fetchData(self):
|
||||
# try:
|
||||
# connection = config.get_db_connection()
|
||||
# cursor = connection.cursor(dictionary=True, buffered=True)
|
||||
# print("here", flush=True)
|
||||
|
||||
# cursor.callproc('GetContractorInfoById', [self.ID])
|
||||
# for result in cursor.stored_results():
|
||||
# self.contInfo = result.fetchone()
|
||||
|
||||
# print(self.contInfo,flush=True)
|
||||
# finally:
|
||||
# cursor.close()
|
||||
# connection.close()
|
||||
|
||||
# def fetchalldata(self):
|
||||
|
||||
# try:
|
||||
# connection = config.get_db_connection()
|
||||
# cursor = connection.cursor(dictionary=True, buffered=True)
|
||||
# print("here", flush=True)
|
||||
|
||||
|
||||
# # ---------------- Hold Types ----------------
|
||||
# cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# cursor.callproc('GetHoldTypesByContractor', [self.ID])
|
||||
|
||||
# hold_types = []
|
||||
# for result in cursor.stored_results():
|
||||
# hold_types = result.fetchall()
|
||||
# hold_type_map = {ht['hold_type_id']: ht['hold_type'] for ht in hold_types}
|
||||
|
||||
# # ---------------- Invoices ----------------
|
||||
# cursor = connection.cursor(dictionary=True)
|
||||
|
||||
# cursor.callproc('GetInvoicesByContractor', [self.ID])
|
||||
|
||||
# invoices = []
|
||||
# for result in cursor.stored_results():
|
||||
# invoices = result.fetchall()
|
||||
|
||||
# # Remove duplicate invoices
|
||||
# invoice_ids_seen = set()
|
||||
# unique_invoices = []
|
||||
# for inv in invoices:
|
||||
# if inv["Invoice_Id"] not in invoice_ids_seen:
|
||||
# invoice_ids_seen.add(inv["Invoice_Id"])
|
||||
# unique_invoices.append(inv)
|
||||
# invoices = unique_invoices
|
||||
|
||||
# finally:
|
||||
# cursor.close()
|
||||
# connection.close()
|
||||
|
||||
|
||||
from mysql.connector import Error
|
||||
import config
|
||||
|
||||
Reference in New Issue
Block a user