Sindbad~EG File Manager

Current Path : /home/numerotech/conference.numerotech.com/food_kit_scan_badges/core/model/
Upload File :
Current File : //home/numerotech/conference.numerotech.com/food_kit_scan_badges/core/model/TransactionModel.py

from sqlalchemy import create_engine, MetaData, Table, insert, func, select,text
from sqlalchemy.sql import and_, or_
from core import app
import json

engine      = create_engine(app.config['DATABASE_URI'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)
engine_conf = create_engine(app.config['DATABASE_URI_CONF'],pool_size=5000,pool_pre_ping=True,pool_recycle=3600)


class TransactionModel():
	def __init__(self):
		try:
			self.meta = MetaData()
			self.zztransaction_api_logs = Table("zztransaction_api_logs", self.meta, autoload_with=engine)
			self.delegates = Table("delegates", self.meta, autoload_with=engine)
			self.user_payment = Table("user_payment", self.meta, autoload_with=engine)
			self.conference = Table("conference", self.meta, autoload_with=engine)

			
		except Exception as e:
			print(e)

	def SaveTxnAPIData(self,data, unique_id,conf_id,curr_dt):
		try:
			with engine.connect() as conn:	
				result  = conn.execute(self.zztransaction_api_logs.insert(), data)
				conn.commit()
				stmt_1  = text("SET SQL_SAFE_UPDATES = 0 ;")
				conn.execute(stmt_1)
				stmt    = text(" update user_payment set txn_api_updated  = 1 , txnapi_updated_at = '"+curr_dt+"' where conf_id = " +str(conf_id)+ " and unique_id = '"+unique_id+"' ")
				conn.execute(stmt)
				conn.commit()
				return "success"
		except Exception as e:
			return  str(e)

	def getPaymentData(self,conf_id,from_date,to_date) :
		with engine.connect() as conn :
			stmt  = text("select am_id,conf_id,unique_id,txn_api_updated,txnapi_updated_at from user_payment where conf_id = "+str(conf_id)+" and am_id is not null and txnapi_updated_at is null and date(created_at) between '"+from_date+"' and '"+to_date+"' " )
			result  = conn.execute(stmt).all()
			results = [dict(r._mapping) for r in result] if result else None
			return results

	def getConference(self):
		with engine.connect() as conn:
			stmt   = text("select * from conference ;")
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else 0

	def getTransactionData(self,conf_id) :
		with engine.connect() as conn :
			stmt    = text("select zp.full_name,zp.api_payment_id,zp.email,zp.mobile,zp.unique_id,zp.amount,zp.status,zp.paid_at, da.delegate_id,d.delegate_no from delegates_addons da inner join zztransaction_api_logs zp on da.unique_id = zp.unique_id left join delegates d on d.delegate_id=da.delegate_id where zp.conf_id ="+str(conf_id)+" and d.conference_id="+str(conf_id)+" ;")
			result  = conn.execute(stmt).all()
			results = [dict(r._mapping) for r in result] if result else None
			return results
			
	# Update data start
	def getFilterTransactionData(self,conf_id,from_date,to_date,txn_status):
		connection  = engine.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_del_paymentgateway_filter",[conf_id,from_date,to_date,txn_status])
		if cursor.description :
			columns     = [column[0] for column in cursor.description]
			results     = []
			for row in cursor.fetchall():
				results.append(dict(zip(columns, row)))
			cursor.close()
			connection.commit()
			return results if results else None 
		else :
			cursor.close()
			connection.commit()
			return None		

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists