Sindbad~EG File Manager

Current Path : /home/numerotech/workshops.numerotech.com/common_workshop_reg/core/library/
Upload File :
Current File : //home/numerotech/workshops.numerotech.com/common_workshop_reg/core/library/Allmailfunctions.py

from core import app
from flask import Flask, request, Blueprint, jsonify, redirect, url_for,flash, render_template,session,Response,jsonify,json
from werkzeug.utils import secure_filename
from os.path import join, dirname,isfile, realpath
import datetime
from datetime import timedelta,date,datetime
from .. import Helper
from core.library.email import EMAIL
import os
import boto3, botocore
from botocore.exceptions import ClientError
from core.model.BOModel import BOModel
from core.model.DevelopersSettingModel import DevelopersSettingModel
from core.model.SurgicalUserModel import SurgicalUserModel
from .. import Auth

class AllMailFunctions:

	def BOAllConferenceDelegateReportSendMail(self,date_1,is_send_manual=None,is_send_backup=None,is_send_sample=None,sample_mail=None):
		row_val           = []
		today_count       = 0
		total_count       = 0
		today_paid_amount = 0
		total_paid_amount = 0
		today_del_count   = 0
		total_del_count   = 0
		current_dt        = datetime.now() - timedelta(1)
		yester_dt         = datetime.strftime(current_dt, '%d-%m-%Y')
		if date_1 :
			previous_date = date_1
		else :
			yesterday     = datetime.now() - timedelta(1)
			yesterday     = datetime.strftime(yesterday, '%Y-%m-%d')
			previous_date = yesterday
		
		users             = BOModel().get_all_conference_daily_count_send_mail()
		conferences_db    = BOModel().get_conference()
		conferences       = {}
		for conference in conferences_db:
			conferences[conference['conf_id']] = conference	
	   
		dt_string         = datetime.now().strftime("%d-%m-%Y %I:%M %p")
		
		in_conf_id  = []
		sender_mail = []
		if users :
			for row in users:
				html        = []
				email       = ""
				full_name   = ""
				mobile      = ""
				email       = row['email']
				full_name   = row['full_name']
				mobile      = row['mobile']
				str_conf_id = row['conf_id']
				lst_conf_id = str_conf_id.split(",")
				html.clear()
				for x in lst_conf_id:
					conf = conferences.get(int(x),None)
					if conf:
						reg_data = BOModel().GetRegDataForMail(previous_date,x)
						today_count       = 0
						total_count       = 0
						today_paid_amount = 0
						total_paid_amount = 0
						today_del_count   = 0
						total_del_count   = 0
						for index, value in enumerate(reg_data):
							addon_type_id       = value["addon_type_id"]
							today_count         = today_count+value['today_count']
							total_count         = total_count+value['total_count']
							today_paid_amount   = today_paid_amount+value['today_paid_amount']
							total_paid_amount   = total_paid_amount+value['total_paid_amount']
							if addon_type_id == 1:
								today_del_count         = today_del_count+value['today_count']
								total_del_count         = total_del_count+value['total_count']
						
						if int(x) == 46:
							base_url 	      = request.host_url
							if "https" in base_url :
								pass
							else :
								base_url = base_url.replace("http" ,"https")
							
							yesterday_dt         = datetime.strftime(current_dt, '%Y-%m-%d')		
							previous_reg_count = SurgicalUserModel().get_total_previous_reg_count(x,yesterday_dt)
							current_reg_count  = SurgicalUserModel().get_total__current_reg_count(x,yesterday_dt)
							if previous_reg_count:
								previous_reg_count = previous_reg_count['total_previous_count']
							else:
								previous_reg_count = 0
			
							if current_reg_count:
								current_reg_count = current_reg_count['total_current_count']
							else:
								current_reg_count = 0
										
							dt_string     = datetime.now().strftime("%d-%m-%Y %I:%M %p")
							html_data     = render_template('email/ss_daily_count_mail.html',conf=conf,date=dt_string,previous_reg_count=previous_reg_count,current_reg_count=current_reg_count,previous_date=previous_date,base_url=base_url)		
						else:
							html_data    = render_template('email/all_conference_dail_mail_count.html',previous_date =yester_dt,reg_data = reg_data,conf=conf,date=dt_string,today_count=today_count,total_count=total_count,today_paid_amount=today_paid_amount,total_paid_amount=total_paid_amount,today_del_count=today_del_count,total_del_count=total_del_count)	
						
						htmls        = html_data.replace("\n", "")
						html.append(htmls)

				html_datas   = str(html).replace("['", " ").replace("']", " ").replace(",", "").replace("' '", "")
				html_tmp     = render_template('email/reg_report_email_all.html',html=html_datas)
				
				subject = "All Delegate Registration Count as on {}".format(dt_string)
				receiver_email   = email
				receiver_mobile  = mobile
				receiver_name    = full_name
				created_at       = datetime.now()

				if int(is_send_sample) == 1 :
					email   = sample_mail
					subject = "All Delegate Registration Count as on {} to {}".format(dt_string,receiver_email)
					EMAIL.allconfcountsendMail(subject,html_tmp,email)
					comments = "Mail Send to "+str(email)

				elif int(is_send_backup) == 1 :
					email   = "ntecBackup@gmail.com"
					subject = "Backup mail of All Delegate Registration Count as on {} to {}".format(dt_string,receiver_email)
					EMAIL.allconfcountsendMail(subject,html_tmp,email)
					comments = "Mail Send to Ntec Backup"

				elif int(is_send_manual) == 1 :
					comments = "Mail Send Manually"
					subject = "All Delegate Registration Count as on {}".format(dt_string)
					EMAIL.allconfcountsendMail(subject,html_tmp,email)
				else :
					pass

				stmt_1              =('''INSERT INTO send_mail_index (conf_id,receiver_name,receiver_email,receiver_mobile,mail_send_at,created_at,comments) VALUES ''')
				row_val.append(('(' + ''''{}','{}',"{}",'{}','{}','{}','{}' ''' +')').format(x,receiver_name,receiver_email,receiver_mobile,created_at,created_at,comments))
				
				stmt_1 = stmt_1 +  ",".join(row_val)
				stmt_1 = stmt_1 + ';'   

				BOModel().save_delegate_report_sendmail(stmt_1)
				sender_mail.append(email) 
			return jsonify(sender_mail)	
		else : 
			return "Report data is not available."


	def BODelegateReportSendMail(self,conf_id,conf_key,date_1,is_send_manual=None,is_send_backup=None,is_send_sample=None,sample_mail=None):
		conf              = Auth.getConf(conf_id,conf_key)
		row_val           = []
		today_count       = 0
		total_count       = 0
		today_paid_amount = 0
		total_paid_amount = 0
		today_del_count   = 0
		total_del_count   = 0
		current_dt        = datetime.now() - timedelta(1)
		yester_dt         = datetime.strftime(current_dt, '%d-%m-%Y')
		base_url 	      = request.host_url
		to_mail           = []
		bcc_mail          = []
		if "https" in base_url :
			pass
		else :
			base_url = base_url.replace("http" ,"https")
		
		if date_1 :
			previous_date = date_1
		else :
			yesterday     = datetime.now() - timedelta(1)
			yesterday     = datetime.strftime(yesterday, '%Y-%m-%d')
			previous_date = yesterday
		
		users             = BOModel().get_daily_count_send_mail(conf_id,conf_key)
		for index,value in enumerate(users):
			if "@numerotec.com"  in  value['email'] :
				bcc_mail.append(value['email'])
			else :
				to_mail.append(value['email'])
				
		if to_mail :
			to_str  = str(to_mail).replace(",",' / ')
		else :
			to_mail  = ['karthick@numerotec.com','ramya@numerotec.com','aravinth@numerotec.com','santhosh@numerotec.com','sridharan.r@numerotec.com','sai@numerotec.com','dp@numerotec.com','manjula@numerotec.com']
			bcc_mail = None
			to_str   = None
			
			
		dt_string         = datetime.now().strftime("%d-%m-%Y %I:%M %p")
		if users :
			reg_data = BOModel().GetRegDataForMail_v2(previous_date,conf_id)
			for index,value in enumerate(reg_data):
				print(index,value)
				if index == 0:
					reg_data   = value
				if index == 1:
					conf_db    = value[0]
				if index == 2:
					waiting_for_approval_data = value
				if index == 3:
					additional_adon_data = value		


			waiting_count = {}
			if waiting_for_approval_data :
				waiting_total_count = waiting_for_approval_data['total_waiting_count']
				if int(waiting_total_count) == 0 :
					is_show_waiting_count = 0
				else:
					today_waiting_count         = 0
					total_waiting_count         = 0
					today_waiting_paid_amount   = 0
					total_waiting_paid_amount   = 0
					is_show_waiting_count       = 1
					today_waiting_count         = today_waiting_count + waiting_for_approval_data['today_waiting_count']
					total_waiting_count         = total_waiting_count + waiting_for_approval_data['total_waiting_count']
					today_waiting_paid_amount   = today_waiting_paid_amount + waiting_for_approval_data['today_waiting_paid_amount']
					total_waiting_paid_amount   = total_waiting_paid_amount + waiting_for_approval_data['total_waiting_paid_amount']
					waiting_count               = {'today_waiting_count':today_waiting_count,'total_waiting_count':total_waiting_count,'today_waiting_paid_amount':today_waiting_paid_amount,'total_waiting_paid_amount':total_waiting_paid_amount}
			else :
				is_show_waiting_count = 0


			for index, value in enumerate(reg_data):
				addon_type_id       = value["addon_type_id"]
				today_count         = today_count+value['today_count']
				total_count         = total_count+value['total_count']
				today_paid_amount   = today_paid_amount+value['today_paid_amount']
				total_paid_amount   = total_paid_amount+value['total_paid_amount']
				if addon_type_id == 1:
					today_del_count         = today_del_count+value['today_count']
					total_del_count         = total_del_count+value['total_count']

			if reg_data :
				html    = render_template('email/reg_report_email.html',waiting_count=waiting_count,is_show_waiting_count=is_show_waiting_count,previous_date =yester_dt,reg_data = reg_data,conf=conf,date=dt_string,today_count=today_count,total_count=total_count,today_paid_amount=today_paid_amount,total_paid_amount=total_paid_amount,today_del_count=today_del_count,total_del_count=total_del_count,base_url=base_url,to_mail=to_str,additional_adon_data=additional_adon_data)
				
				if int(is_send_sample) == 1 :
					subject        = conf['conf_name']+"- Delegate Registration Count as on {}".format(dt_string)
					receiver_email = sample_mail
					# for test use this 
				# 	receiver_email = "ramya@numerotec.com"
					# for test use this
					
					EMAIL.MailTemplateSendMail_v2(subject,html,receiver_email,None,None,conf)
					comments = "Mail Send to "+str(receiver_email)

				elif int(is_send_backup) == 1 :

					subject        = conf['conf_name']+"- Delegate Registration Count as on {}".format(dt_string)
					receiver_email = "ntecBackup@gmail.com"
					
					EMAIL.MailTemplateSendMail_v2(subject,html,receiver_email,None,None,conf)
					comments = "Mail Send to Ntec Backup"

				elif int(is_send_manual) == 1 :
					
					# for test use this 
				# 	bcc_mail = ['karthick@numerotec.com']
				# 	to_mail = ['ramya@numerotec.com']
					# for test use this 
					
					subject = conf['conf_name']+"- Delegate Registration Count as on {}".format(dt_string)
					comments = "Mail Send Manually"
					EMAIL.MailTemplateSendMail_v2(subject,html,to_mail,bcc_mail,None,conf)
				else :
					pass
				return "success"
		else : 
			return "Report data is not available."      
	 

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