Sindbad~EG File Manager

Current Path : /home/numerotech/workshops.numerotech.com/common_workshop_reg/core/model/
Upload File :
Current File : //home/numerotech/workshops.numerotech.com/common_workshop_reg/core/model/AddonsModel.py

from flask import session
from flask import request, Blueprint, jsonify
from sqlalchemy import create_engine, select, MetaData, Table,text
from sqlalchemy.sql import and_, or_

from core import app

from .. import engine

# engine = create_engine(app.config['DATABASE_URI'],pool_pre_ping=True,pool_recycle=3600)

class AddonsModel():  
	def __init__(self):
		try:
			self.meta = MetaData()
			self.states    = Table("states", self.meta,autoload_with=engine)
			
		except Exception as e:
			print(e)

	def getInternationalAddons(self,curr_dt):
		with engine.connect() as conn:
			stmt = text("SELECT a.addon_id, a.amount,a.international_amount,a.currency ,c.conf_id,c.conf_name,a.start_by,end_by from addons a "
				+ " inner join conference c on c.conf_id = a.conference_id  "  
				+ " WHERE '"+curr_dt+"' between a.start_by and a.end_by  and a.international_amount is not null;")
			result = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None


	def update_international_currancy(self,stmt_1):
		with engine.connect() as conn:
			stmt2   = text("set sql_safe_updates  = 0 ;")
			conn.execute(stmt2)
			result 	= conn.execute(stmt_1)
			return result		

	# Wet Lab and Dry Lab Start		
	def	get_courses_wetlab_drylabs(self,conf_id):
		with engine.connect() as conn:
			stmt    = text("select distinct addon_name,addon_type_id,amount from addons where addon_type_id in (2,5) and conference_id = "+str(conf_id)+" and is_visible= 1 ;")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
			
	def	get_day_wetlab_drylabs(self,conf_id):
		with engine.connect() as conn:
			stmt    = text("select distinct day,addon_type_id from addons where addon_type_id in (2,5) and conference_id = "+str(conf_id)+" and is_visible= 1  ;")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
			

	def	get_time_wetlab_drylabs(self,conf_id):
		with engine.connect() as conn:
			stmt    = text("select distinct start_time,end_time,concat(SUBSTRING(start_time,1,5),' - ',SUBSTRING(end_time,1,5)) as display_time ,addon_type_id from addons where addon_type_id in (2,5) and conference_id = "+str(conf_id)+" and is_visible= 1 ;")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
			

	def get_delegate_courses(self,delegate_id):
		with engine.connect() as conn:
			stmt    = text("select concat(a.start_time,' - ',a.end_time) as display_time,da.*,a.* from delegates_addons da inner join addons a on a.addon_id = da.addon_id where delegate_id ="+str(delegate_id)+" and a.addon_type_id in (2,5) and a.is_visible= 1 order by a.day,a.start_time;")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
			


	def get_wetdry_insert_data(self,delegate_id,addon_type_id,courses,day,time):
		connection  = engine.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_del_wet_and_dry_lab_course",[delegate_id or None,addon_type_id or None,courses or None,day or None,time or None])
		if cursor.description :
			columns 	= [column[0] for column in cursor.description]
			results_1   = []
			for row in cursor.fetchall():
				results_1.append(dict(zip(columns, row)))
			cursor.close()
			connection.commit()
			return results_1[0]
		else:
			cursor.close()
			connection.commit()
			return None		


	def	delete_delegates_addons(self,delegate_addon_id):
		with engine.connect() as conn:
			stmt 	= text("delete from delegates_addons where delegate_addon_id = "+str(delegate_addon_id)+";")
			result  = conn.execute(stmt)
			conn.commit()
			return "success"
		


	def get_total_amount_for_wetlab(self,delegate_id):
		with engine.connect() as conn:
			stmt    = text("select sum(da.amount) as total_amount from delegates_addons da inner join addons a on a.addon_id = da.addon_id where delegate_id = " +str(delegate_id) +" and da.reg_status not in (2,3) and a.addon_type_id in (2,5) order by a.day,a.start_time;")
			result  = conn.execute(stmt).one_or_none()
			return dict(result._mapping) if result else None
			
	
	def get_day_by_course_for_WetLabDryLab(self,courses,addon_type_id,conf_id):
		with engine.connect() as conn:
			stmt    = text("select distinct day from addons where addon_name = '"+courses+"' and addon_type_id = "+str(addon_type_id) +" and is_visible= 1 and conference_id = "+str(conf_id) +" ;")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
			


	def get_time_by_course_for_WetLabDryLab(self,courses,day,addon_type_id,conf_id):
		with engine.connect() as conn:
			stmt    = text("select distinct start_time,end_time,concat(SUBSTRING(start_time,1,5),' - ',SUBSTRING(end_time,1,5)) as display_time from addons where addon_name = '"+courses+"' and addon_type_id = "+str(addon_type_id) +" and day = '"+ day +"' and is_visible= 1 and conference_id = "+str(conf_id) +"  order by  start_time;")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
				


	def get_count_delegates_addons(self,delegate_id):
		with engine.connect() as conn:
			stmt    = text("select count(delegate_addon_id) as total_count, sum(da.amount) as total_amount from delegates_addons da inner join addons a on a.addon_id = da.addon_id where delegate_id = "+str(delegate_id)+" and a.addon_type_id in (2,5) and is_visible= 1 group by delegate_id ;")
			result  = conn.execute(stmt).one_or_none()
			return dict(result._mapping) if result else None
			
				

	def get_addons_limit(self,delegate_id):
		with engine.connect() as conn:
			# updated by query by R.Sridharan on 2023-07-05 12:09:00
			stmt    = text("select a.addon_id,a.addon_name,a.display_name,a.head_count,da.reg_status,t.addon_count,case when  "
						+" a.head_count <= t.addon_count then 1 else 0 end is_full from delegates_addons da "
						+" inner join addons a on a.addon_id = da.addon_id "
						+" inner join (select addon_id, count(delegate_id) as addon_count from delegates_addons where  reg_status in (2,3) and addon_id in "
						+" (select addon_id  from delegates_addons  where delegate_id = "+str(delegate_id)+") group by addon_id ) t on t.addon_id = da.addon_id "
						+" where a.addon_type_id in (2,5) and da.delegate_id = "+str(delegate_id)+";")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
			

	def get_usp_del_get_delegates_by_delegate_no(self,delegate_no,conf_id):
		connection = engine.raw_connection()
		cursor     = connection.cursor()
		cursor.callproc("usp_del_get_delegates_by_delegate_no",[delegate_no,conf_id])
		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
		else :
			return None


	def get_addons_where_addon_type_id(self,conf_id,addon_type_id):
		with engine.connect() as conn:
			stmt    = text("select * from addons  where conference_id = "+str(conf_id)+" and addon_type_id in ("+str(addon_type_id)+") and is_visible = 1;")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
			


	def	wetdry_lab_edit_course(self,delegate_id,delegate_addon_id,addon_id,old_addon_id,addon_type_id,curr_dt):
		with engine.connect() as conn:
			stmt    = text("update delegates_addons set addon_id = "+str(addon_id)+" ,old_addon_id = "+str(old_addon_id)+", updated_at = '"+str(curr_dt)+"' where delegate_id = "+str(delegate_id)+" and delegate_addon_id = "+str(delegate_addon_id)+" ;")
			result  = conn.execute(stmt)
			conn.commit()
			return "success"


	def get_datas_by_addon_type_id(self,conf_id,addon_type_id,addon_name):
		with engine.connect() as conn:
			if addon_type_id :
				where_con = " and  a.addon_type_id in ("+addon_type_id+") and a.addon_name not in ('"+str(addon_name)+"') group by a.addon_id order by  ats.addon_type DESC,a.addon_name ,a.day ;"
			else :
				where_con = " group by a.addon_id order by  ats.addon_type DESC,a.addon_name ,a.day ;"

			stmt = text("select a.addon_id,a.display_name,a.head_count,count(d.delegate_id)as delegate_count,ats.addon_type "
						+" from numerotech_primary_db.delegates d"
						+" inner join numerotech_primary_db.delegates_addons da on da.delegate_id = d.delegate_id"
						+" inner join numerotech_primary_db.addons a on a.addon_id = da.addon_id"
						+" inner join numerotech_primary_db.addon_types ats on ats.addon_type_id = a.addon_type_id"
						+" where a.is_visible = 1 and d.conference_id ="+str(conf_id)+" and da.reg_status in (2,3) and delegate_no is not null and a.addon_type_id in(2,5) "+str(where_con)+" "
						+" ")
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None
			
	def get_wetdry_get_data(self,delegate_id,addon_type_id,addon_id):
		connection  = engine.raw_connection()
		cursor      = connection.cursor()
		cursor.callproc("usp_del_wet_and_dry_lab_course_v2",[delegate_id or None,addon_type_id or None,addon_id or None])
		if cursor.description :
			columns 	= [column[0] for column in cursor.description]
			results_1   = []
			for row in cursor.fetchall():
				results_1.append(dict(zip(columns, row)))
			cursor.close()
			connection.commit()
			return results_1[0]
		else:
			cursor.close()
			connection.commit()
			return None


	def get_exist_addon_name(self,conf_id,addon_type_id,delegate_id,addon_id):		
		with engine.connect() as conn:
			stmt = text("select a.addon_name from delegates d "
					+"inner join delegates_addons da on da.delegate_id = d.delegate_id "
					+"inner join addons a on a.addon_id = da.addon_id "
					+"where d.conference_id = "+str(conf_id)+" and a.addon_type_id in ("+str(addon_type_id)+") and da.addon_id not in ("+str(addon_id)+") and d.delegate_id = "+str(delegate_id)+"; ")
			result  = conn.execute(stmt).one_or_none()
			return dict(r._mapping) if result else None
			

	# Wet Lab and Dry Lab End		

	def get_addons_head_reg_limit(self,conf_id,addon_type_id):
		with engine.connect() as conn:
			# updated by query by R.Sridharan on 2023-07-05 12:09:00
			stmt    = text("select a.addon_type_id,a.addon_id,a.addon_name,a.display_name,a.head_count,da.reg_status, "
						 + "a.head_count,count(da.delegate_id) as reg_count "
						 + "from addons a "
						 + "left join delegates_addons da on a.addon_id = da.addon_id "
						 + "where a.addon_type_id in ("+str(addon_type_id)+") and a.conference_id = "+str(conf_id)+" and da.reg_status in(2,3) "
						 + "group by a.display_name;") 
			result  = conn.execute(stmt).all()
			return [dict(r._mapping) for r in result] if result else None

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