def send_redeemed_sms(Voucher, method): recipients = [] transaction_id = '' buy_back_requisition_ref = frappe.db.sql( """select buy_back_requisition_ref,creation from `tabPurchase Receipt` where pin='%s' """ % (Voucher.enter_pin), as_dict=1) if buy_back_requisition_ref: transaction_id = buy_back_requisition_ref[0][ 'buy_back_requisition_ref'] if Voucher.customer: customer = frappe.db.sql( """select phone_no from `tabCustomer` where name='%s' """ % (Voucher.customer), as_list=1) if customer: recipients.append(customer[0][0]) if recipients: if Voucher.mark_voucher_as_redeemed == 1: message = """Dear %s Your Voucher for Transaction %s at '%s' has been successfully redeemed. Value of the voucher: %s Redemption Date: %s Thank You, """ % (Voucher.customer, transaction_id, Voucher.warehouse, fmt_money(flt(Voucher.discount_amount)), formatdate( Voucher.creation)) send_sms(recipients, cstr(message))
def notify_to_do(): profile_ids = get_profile_ids() print "########## TODO #############" print profile_ids if profile_ids: msg={} email_msg={} for profile in profile_ids: user = frappe.db.get_value("User",{"profile_id":profile['profile_id']},"name") if user: pobj = frappe.get_doc('User',user) todoobj = frappe.get_doc('ToDo',profile['name']) if pobj: if frappe.db.get_value("Mobile Verification",{"mobile_no":pobj.contact,"mflag":1},"name"): mob_no = [] mob_no.append(pobj.contact) send_sms(mob_no,msg=get_sms_template("todo",{"to_do":todoobj.description})) send_phrs_mail(pobj.name,"PHR:To Do Alert","templates/emails/todo.html",{"todo":todoobj.description,"name":pobj.first_name}) else: data = search_profile_data_from_solr(profile['profile_id']) if data and data['mobile']: if frappe.db.get_value("Mobile Verification",{"mobile_no":data['mobile'],"mflag":1},"name"): mob_no = [] mob_no.append(data['mobile']) send_sms(mob_no,msg=get_sms_template("todo",{"to_do":todoobj.description})) if data and data['email']: send_phrs_mail(data['email'],"PHR:To Do Alert","templates/emails/todo.html",{"todo":todoobj.description,"name":data["person_firstname"]})
def send_welcome_mail(password,profile_id,args, send_sms=True, is_provider=False): from frappe.utils import random_string, get_url key = random_string(32) db_set(args,"reset_password_key", key) link = get_url("/verify_email?id="+profile_id+"&key=" + key) mob_code = get_mob_code() update_verification_details(args,password,key,mob_code,link,profile_id, is_provider) mail_response = send_login_mail(args,"Verify Your Account", "templates/emails/new_user.html", {"link": link,"password":password,"verify_sms":send_sms}) if send_sms: mob_already_v = frappe.db.get_value("Mobile Verification",{"mobile_no":args["mobile"],"mflag":1},"name") if not mob_already_v: from phr.templates.pages.profile import make_mobile_verification_entry if not frappe.db.get_value("Mobile Verification",{"mobile_no":args["mobile"]},"name"): make_mobile_verification_entry(args["mobile"],profile_id,mob_code) else: pass from phr.templates.pages.utils import get_sms_template sms = get_sms_template("registration",{ "mobile_code": mob_code }) rec_list = [] rec_list.append(args["mobile"]) from erpnext.setup.doctype.sms_settings.sms_settings import send_sms send_sms(rec_list,sms) elif mob_already_v: vd = frappe.get_doc("Verification Details",profile_id) vd.mflag = 1 vd.save(ignore_permissions=True) return mail_response
def validate_duplicate(doc,method): if doc.get("__islocal"): res=frappe.db.sql("select name from `tabZones` where (zone_name='%s' or zone_code='%s') and region='%s'"%(doc.zone_name,doc.zone_code,doc.region)) if res: frappe.throw(_("Zone '{0}' already created with same Zone Name '{1}' or Zone Code '{2}' for Region '{3}'..!").format(res[0][0],doc.zone_name,doc.zone_code,doc.region)) notify_msg = """Dear User,\n\n Zone is created with name '%s' for region '%s'.\n\nRegards,\n\n Love World Synergy"""%(doc.zone_name,doc.region) notify = frappe.db.sql("""select value from `tabSingles` where doctype='Notification Settings' and field='on_creation_of_a_new_cell_pcf_church'""",as_list=1) if notify: if "Email" in notify[0][0]: if doc.contact_email_id: frappe.sendmail(recipients=doc.contact_email_id, content=notify_msg, subject='Zone Creation Notification') if "SMS" in notify[0][0]: if doc.contact_phone_no: send_sms(doc.contact_phone_no, notify_msg) if "Push Notification" in notify[0][0]: data={} data['Message']=notify_msg gcm = GCM('AIzaSyBIc4LYCnUU9wFV_pBoFHHzLoGm_xHl-5k') res1=frappe.db.sql("select device_id from tabUser where name ='%s'" %(doc.contact_email_id),as_list=1) if res1: res1 = gcm.json_request(registration_ids=res1, data=data,collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600) ofc = frappe.new_doc("Offices") ofc.office_id = doc.name ofc.office_name = doc.zone_name ofc.office_code = doc.zone_code ofc.insert()
def send_to_sms(BuyBackRequisition, method): recipients=[] if BuyBackRequisition.phone_no: phone_no=BuyBackRequisition.phone_no recipients.append(cstr(phone_no)) message ="""Dear %s , We received your device at '%s',\nbelow are the details\nTransaction ID: %s,\nDevice Received: %s,\nReceived Date: %s,\nOffered Price: %s,\nYour voucher will be sent to you in a separate email & sms correspondence.\nThanks You.""" %(BuyBackRequisition.customer,BuyBackRequisition.warehouse,BuyBackRequisition.name,BuyBackRequisition.item_name,formatdate(BuyBackRequisition.creation),fmt_money(flt(BuyBackRequisition.offered_price))) send_sms(recipients,cstr(message))
def update_attendance(doc,method): for d in doc.get('attendance'): greeting='' if d.grade!='D': greeting='Congratulations..!' else: greeting='Sorry..! You Failed.' if doc.visitor_type=='FTV': ftvdetails=frappe.db.sql("select ftv_name,email_id,phone_1 from `tabFirst Timer` where name='%s'"%(d.ftv_id)) else: ftvdetails=frappe.db.sql("select member_name,email_id,phone_1 from `tabMember` where name='%s'"%(d.member_id)) # frappe.errprint(doc.foundation__exam) msg_member="""Hello %s,<br><br> %s You are passed Foundation School Exam with grade '%s' <br><br>Regards,<br>Verve """%(ftvdetails[0][0],greeting,d.grade) frappe.sendmail(recipients=ftvdetails[0][1], sender='*****@*****.**', content=msg_member, subject='Verve Exam Result') from erpnext.setup.doctype.sms_settings.sms_settings import send_sms receiver_list=[] baptism='' if d.baptism_when and d.baptism_where: baptism=", baptisum_status='Yes' , baptism_when='"+d.baptism_when+"' , baptism_where='"+cstr(d.baptism_where)+"' " # frappe.errprint(baptism) if d.grade!='D': exm='Completed All Classes and Passed Exam' if doc.visitor_type=='FTV': frappe.db.sql("""update `tabFirst Timer` set school_status='%s' %s where name='%s' """ % (exm,baptism,d.ftv_id)) else: frappe.db.sql("""update `tabMember` set school_status='%s' %s where name='%s' """ % (exm, baptism, d.member_id)) if ftvdetails[0][2]: receiver_list.append(ftvdetails[0][2]) send_sms(receiver_list, cstr(msg_member)) return "Done"
def assignmember(memberid,ftv): frappe.db.sql("""update `tabFirst Timer` set ftv_owner='%s' where name='%s' """ % (memberid,ftv)) # recipients='*****@*****.**' member=frappe.db.sql("select member_name,email_id,phone_1 from `tabMember` where name='%s'"%(memberid)) member_ph = frappe.db.sql("select phone_1 from `tabMember` where name='%s'"%(memberid)) ftvdetails=frappe.db.sql("select ftv_name,email_id,task_description,due_date,phone_1 from `tabFirst Timer` where name='%s'"%(ftv)) ftv_ph = frappe.db.sql("select phone_1 from `tabMember` where name='%s'"%(ftv)) msg_member="""Hello %s,\n The First Timer '%s' name: '%s' Email ID: '%s' is assigned to you for follow up.\n Regards,\n Verve """%(member[0][0],ftv,ftvdetails[0][0],ftvdetails[0][1]) msg_ftv="""Hello %s,\n The Member '%s' name: '%s' Email ID: '%s' is assigned to you for follow up.\n Regards, \n Verve """%(ftvdetails[0][0],memberid,member[0][0],member[0][1]) desc="""Member '%s' is assigned to First Timer '%s' for followup."""%(memberid,ftv) task=frappe.get_doc({ "doctype": "Task", "subject": "Assign For followup", "expected_start_date":nowdate(), "expected_start_date":add_days(nowdate(),2), "status": "Open", "project": "", "description":desc }).insert(ignore_permissions=True) if frappe.db.exists("User", ftvdetails[0][1]): frappe.share.add("Task", task.name, ftvdetails[0][1], write=0) if frappe.db.exists("User", member[0][1]): frappe.share.add("Task", task.name, member[0][1], write=1) notify = frappe.db.sql("""select value from `tabSingles` where doctype='Notification Settings' and field='assign_for_followup'""",as_list=1) if "Email" in notify[0][0]: if member: frappe.sendmail(recipients=member[0][1], content=msg_member, subject='Assign For FollowUp Notification') if ftvdetails: frappe.sendmail(recipients=ftvdetails[0][1], content=msg_ftv, subject='Assign For FollowUp Notification') if "SMS" in notify[0][0]: if member_ph: send_sms(member_ph[0], msg_member) if ftv_ph: send_sms(ftv_ph[0], msg_ftv) if "Push Notification" in notify[0][0]: data={} data['Message']=msg_member gcm = GCM('AIzaSyBIc4LYCnUU9wFV_pBoFHHzLoGm_xHl-5k') res=frappe.db.sql("select device_id from tabUser where name ='%s'" %(member[0][1]),as_list=1) frappe.errprint(res) if res: res = gcm.json_request(registration_ids=res, data=data,collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600) # receiver_list=[] # receiver_list.append(member[0][2]) # frappe.errprint(['rev[0]',receiver_list[0]]) # if receiver_list[0] : # frappe.errprint(receiver_list[0]) # send_sms(receiver_list, cstr(msg_member)) # frappe.sendmail(recipients=member[0][1], sender='*****@*****.**', content=msg_member, subject='Assign for follow up') # frappe.sendmail(recipients=ftvdetails[0][1], sender='*****@*****.**', content=msg_ftv, subject='Assign for follow up') return "Done"
def send_notification(profile_list): if profile_list: email_list = [] sms_recipients = [] msg = {} for profile in profile_list: pobj = frappe.get_doc( 'User', frappe.db.get_value("User", {"profile_id": profile['profile_id']}, "name")) apobj = frappe.get_doc('Appointments', profile['name']) if pobj: sms_recipients.append(pobj.contact) msg[pobj.contact] = get_sms_template( "appointment", { "doctor_name": profile['provider_name'], "appointment_time": profile['time'] }) else: data = search_profile_data_from_solr(profile_id) if data['mobile']: sms_recipients.append(data["mobile"]) msg[data["mobile"]] = get_sms_template( "appointment", { "doctor_name": profile['provider_name'], "appointment_time": profile['time'] }) if sms_recipients: for no in sms_recipients: mob_no = [] mob_no.append(no) send_sms(sms_recipients, msg=msg[no])
def validate_duplicate(doc,method): if doc.get("__islocal"): res=frappe.db.sql("select name from `tabZones` where (zone_name='%s' or zone_code='%s') and region='%s'"%(doc.zone_name,doc.zone_code,doc.region)) frappe.errprint(res) if res: frappe.throw(_("Zone '{0}' already created with same Zone Name '{1}' or Zone Code '{2}' for Region '{3}'..!").format(res[0][0],doc.zone_name,doc.zone_code,doc.region)) notify_msg = """Dear User,\n Region is created with name '%s' for region '%s' \n \n Regards,\n Love World Synergy"""%(doc.zone_name,doc.region) notify = frappe.db.sql("""select value from `tabSingles` where doctype='Notification Settings' and field='on_creation_of_a_new_cell_pcf_church'""",as_list=1) if "Email" in notify[0][0]: if doc.contact_email_id: frappe.sendmail(recipients=doc.contact_email_id, content=notify_msg, subject='Region Creation Notification') if "SMS" in notify[0][0]: if doc.contact_phone_no: send_sms(doc.contact_phone_no, notify_msg) if "Push Notification" in notify[0][0]: data={} data['Message']=notify_msg gcm = GCM('AIzaSyBIc4LYCnUU9wFV_pBoFHHzLoGm_xHl-5k') res1=frappe.db.sql("select device_id from tabUser where name ='%s'" %(doc.contact_email_id),as_list=1) frappe.errprint(res1) if res1: res1 = gcm.json_request(registration_ids=res1, data=data,collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600)
def validate_duplicate(doc,method): if doc.get("__islocal"): res=frappe.db.sql("select name from `tabCells` where cell_name='%s' and cell_code='%s' and senior_cell='%s'"%(doc.cell_name,doc.cell_code,doc.senior_cell)) if res: frappe.throw(_("Another Cell '{0}' With Cell Name '{1}' and Cell Code '{2}' exist in Senior Cell '{3}'..!").format(res[0][0],doc.cell_name,doc.cell_code,doc.senior_cell)) notify_msg = """Dear User,\n Region is created with name '%s' for Senior Cell '%s' \n \n Regards,\n Love World Synergy"""%(doc.cell_name,doc.senior_cell) notify = frappe.db.sql("""select value from `tabSingles` where doctype='Notification Settings' and field='on_creation_of_a_new_cell_pcf_church'""",as_list=1) if "Email" in notify[0][0]: if doc.contact_email_id: frappe.sendmail(recipients=doc.contact_email_id, content=notify_msg, subject='Region Creation Notification') if "SMS" in notify[0][0]: if doc.contact_phone_no: send_sms(doc.contact_phone_no, notify_msg) if "Push Notification" in notify[0][0]: data={} data['Message']=notify_msg gcm = GCM('AIzaSyBIc4LYCnUU9wFV_pBoFHHzLoGm_xHl-5k') res1=frappe.db.sql("select device_id from tabUser where name ='%s'" %(doc.contact_email_id),as_list=1) frappe.errprint(res1) if res1: res1 = gcm.json_request(registration_ids=res1, data=data,collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600)
def notify_about_linked_phrs(profile_id, email_msg=None, text_msg=None, entity=None, user_name=None): linked_phr = frappe.db.sql("""select profile_id from `tabNotification Configuration` where linked_phr=1 and profile_id='%s'""" % (profile_id)) if linked_phr: user = frappe.get_doc( 'User', frappe.db.get_value("User", {"profile_id": profile_id}, "name")) if user: send_phrs_mail(user.name, "HealthSnapp Updates:" + entity + " Updated", "templates/emails/linked_phrs_updates.html", { "user_name": user_name, "entity": entity }) if frappe.db.get_value("Mobile Verification", { "mobile_no": user.contact, "mflag": 1 }, "name"): rec_list = [] rec_list.append(user.contact) send_sms(rec_list, msg=text_msg) else: from phr.templates.pages.dashboard import search_profile_data_from_solr search_profile_data_from_solr(profile_id)
def message_braudcast_send(data): """ this will return recipents details """ dts=json.loads(data) from frappe.model.db_query import DatabaseQuery qry="select user from __Auth where user='******'username'])+"' and password=password('"+cstr(dts['userpass'])+"') " valid=frappe.db.sql(qry) msg='' if not valid: return { "status":"401", "message":"User name or Password is incorrect" } if dts['sms']: from erpnext.setup.doctype.sms_settings.sms_settings import send_sms rc_list=frappe.db.sql("select phone_1 from tabMember where phone_1 is not null and email_id in ('%s') limit 3" %(dts['recipents'].replace(",","','")),as_list=1) if rc_list: send_sms([ x[0] for x in rc_list ], cstr(dts['message'])) msg+= "SMS " rc_list=dts['recipents'].split(',') if dts['push']: data={} data['Message']=dts['message'] gcm = GCM('AIzaSyBIc4LYCnUU9wFV_pBoFHHzLoGm_xHl-5k') res=frappe.db.sql("select device_id from tabUser where name in ('%s')" % "','".join(map(str,rc_list)),as_list=1) if res: res = gcm.json_request(registration_ids=res, data=data,collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600) msg+= "Push notification" if dts['email']: frappe.sendmail(recipients=dts['recipents'], sender='*****@*****.**', content=dts['message'], subject='Broadcast Message') msg+=" Email" return msg +" sent Successfully"
def send_sms1(numbers,msg,user): import math num=json.loads(numbers) i = datetime.datetime.now() today=datetime.date.today() if msg: counter = frappe.db.sql("select sms_credits from `tabUser` where name='%s'"%(user),as_list=1) sms_len = math.ceil(len(msg)/160.0) count = len(num)*cint(sms_len) if counter and count<=cint(counter[0][0]): credit_count = counter[0][0] - count send_sms(num, cstr(msg)) log = frappe.new_doc("SMS Log") log.sender_name = user log.sent_on = today log.receiver_list = numbers log.message = msg log.sms_sending_status = 'SMS Sent Successfully' log.insert() frappe.db.sql("update `tabUser` set sms_credits='%s' where name='%s'"%(credit_count,user)) frappe.db.commit() frappe.msgprint(_("SMS Sent Successfully...")) else: log = frappe.new_doc("SMS Log") log.sender_name = user log.sent_on = today log.receiver_list = numbers log.message = msg log.sms_sending_status = 'Sending Fail' log.insert(ignore_permissions=True) frappe.db.commit() frappe.throw(_("SMS credit is not available for sending SMS, Sending fail..!")) else: frappe.throw(_("Message should not be blank,Please enter text message..."))
def validate_duplicate(doc,method): if doc.get("__islocal"): res=frappe.db.sql("select name from `tabGroup Churches` where church_group='%s' and church_group_code='%s' and zone='%s'"%(doc.church_group,doc.church_group_code,doc.zone)) if res: frappe.throw(_("Another Group Church '{0}' With Group Church Name '{1}' and Church Group Code '{2}' exist in Zone '{3}'..!").format(res[0][0],doc.church_group,doc.church_group_code,doc.zone)) notify_msg = """Dear User,\n\n Group Church is created with name '%s' for zone '%s'. \n\nRegards,\n\n Love World Synergy"""%(doc.church_group,doc.zone) notify = frappe.db.sql("""select value from `tabSingles` where doctype='Notification Settings' and field='on_creation_of_a_new_cell_pcf_church'""",as_list=1) if notify: if "Email" in notify[0][0]: if doc.contact_email_id: frappe.sendmail(recipients=doc.contact_email_id, content=notify_msg, subject='Group Church Creation Notification') if "SMS" in notify[0][0]: if doc.contact_phone_no: send_sms(doc.contact_phone_no, notify_msg) if "Push Notification" in notify[0][0]: data={} data['Message']=notify_msg gcm = GCM('AIzaSyBIc4LYCnUU9wFV_pBoFHHzLoGm_xHl-5k') res1=frappe.db.sql("select device_id from tabUser where name ='%s'" %(doc.contact_email_id),as_list=1) frappe.errprint(res1) if res1: res1 = gcm.json_request(registration_ids=res1, data=data,collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600) ofc = frappe.new_doc("Offices") ofc.office_id = doc.name ofc.office_name = doc.church_group ofc.office_code = doc.church_group_code ofc.insert()
def add_profile_to_db(data,profile_id): res = json.loads(data) actdata = res['actualdata'] dt = json.loads(actdata) sub = dt['person_firstname']+" "+dt['person_lastname']+" "+"delinked Successfully" make_log(profile_id,"profile","delink",sub) args = {'person_firstname':dt['person_firstname'],'person_middlename':dt['person_middlename'],'person_lastname':dt['person_lastname'],'email':dt['email'],'mobile':dt['mobile'],'received_from':'Desktop','provider':'false'} cie = frappe.db.get_value("LinkedPHR Images",{"profile_id":res['entityid']}, ["barcode", "profile_image"], as_dict=1) path = "" if cie.get('barcode'): path = cie.get('barcode') else: path = "" if cie.get('profile_image'): args['user_image'] = cie.get('profile_image') else: args['user_image']= "" ret_res = create_profile_in_db(res['entityid'],args,res,path) user = frappe.get_doc("User",frappe.session.user) send_phrs_mail(user.email,"PHR:Linked PHR Account Delinked","templates/emails/delink_phr.html",{"name":args['person_firstname']}) msg = get_sms_template("delink",{"phr_name":args['person_firstname']}) if user.contact: rec_list = [] rec_list.append(user.contact) send_sms(rec_list,msg=msg) sub = dt['person_firstname']+" "+dt['person_lastname']+" "+"Profile Created Successfully" make_log(profile_id,"profile","create",sub) return ret_res
def send_sms(self): receiver_list = [] if not self.message: msgprint(_("Please enter message before sending")) else: receiver_list = self.get_receiver_nos() if receiver_list: send_sms(receiver_list, cstr(self.message))
def notify_acm_about_acm(lead_record,se_visit,child_id,assign_to): user = frappe.get_doc("User",assign_to) msg = get_sms_template("ACM",{"lead_name":lead_record.lead_name,"lead_mobile":lead_record.mobile_no, "property_title":child_id.property_name,"prop_address":child_id.address,"acm_datetime":se_visit.schedule_date}) if user.mobile_no: rec_list = [] rec_list.append(user.mobile_no) send_sms(rec_list,msg=msg)
def notify_lead_about_sv(lead_record,se_visit,child_id,assign_to): user = frappe.get_doc("User",assign_to) se_name = ' '.join([user.first_name,userlast_name]) if user.first_name and user.last_name else user.first_name msg = get_sms_template("Lead Site Visit",{"site_visit":se_visit.schedule_date,"se_name":se_name,"se_mobile":user.mobile_no}) if lead_record.mobile_no: rec_list = [] rec_list.append(lead_record.mobile_no) send_sms(rec_list,msg=msg)
def send_registration_sms(doc, method): if (frappe.db.get_value("OP Settings", None, "reg_sms")=='1'): context = {"doc": doc, "alert": doc, "comments": None} if doc.get("_comments"): context["comments"] = json.loads(doc.get("_comments")) messages = frappe.db.get_value("OP Settings", None, "reg_msg") messages = frappe.render_template(messages, context) number = [doc.mobile] send_sms(number,messages)
def send_mobile_v_code(mobile, profile_id, mobile_code=None): if mobile_code: from phr.templates.pages.utils import get_sms_template sms = get_sms_template("registration", {"mobile_code": mobile_code}) rec_list = [] rec_list.append(mobile) from erpnext.setup.doctype.sms_settings.sms_settings import send_sms send_sms(rec_list, sms) return "done"
def send_phr_sms(mobile, msg): from erpnext.setup.doctype.sms_settings.sms_settings import send_sms if frappe.db.get_value("Mobile Verification", { "mobile_no": mobile, "mflag": 1 }, "name"): no_list = [] no_list.append(mobile) send_sms(no_list, msg=msg)
def send_mobile_v_code(mobile,profile_id,mobile_code=None): if mobile_code: from phr.templates.pages.utils import get_sms_template sms = get_sms_template("registration",{ "mobile_code": mobile_code }) rec_list = [] rec_list.append(mobile) from erpnext.setup.doctype.sms_settings.sms_settings import send_sms send_sms(rec_list,sms) return "done"
def update_attendance(doc, method): for d in doc.get('attendance'): greeting = '' if d.grade != 'D': greeting = 'Congratulations..!' else: greeting = 'Sorry..! You Failed.' if doc.visitor_type == 'FTV': ftvdetails = frappe.db.sql( "select ftv_name,email_id,phone_1 from `tabFirst Timer` where name='%s'" % (d.ftv_id)) else: ftvdetails = frappe.db.sql( "select member_name,email_id,phone_1 from `tabMember` where name='%s'" % (d.member_id)) msg_member = """Hello %s,<br><br> %s You have grade '%s' in exam '%s' <br><br>Regards,<br>Verve """ % (ftvdetails[0][0], greeting, d.grade, doc.foundation__exam) frappe.sendmail(recipients=ftvdetails[0][1], sender='*****@*****.**', content=msg_member, subject='Verve Exam Result') from erpnext.setup.doctype.sms_settings.sms_settings import send_sms receiver_list = [] baptism = '' if d.baptism_when and d.baptism_where: baptism = ", baptisum_status='Yes' , baptism_when='" + d.baptism_when + "' , baptism_where='" + cstr( d.baptism_where) + "' " # frappe.errprint(baptism) if d.grade != 'D': exm = '' if doc.foundation__exam == 'Class 1': exm = 'Completed Class 1' elif doc.foundation__exam == 'Class 2': exm = 'Completed Class 1&2' elif doc.foundation__exam == 'Class 3': exm = 'Completed Class 1, 2 & 3' elif doc.foundation__exam == 'Class 4': exm = 'Completed Class 1, 2 , 3 & 4' elif doc.foundation__exam == 'Class 5': exm = 'Completed Class 1, 2 , 3 , 4 & 5' elif doc.foundation__exam == 'Class 6': exm = 'Completed All Classes and Passed Exam' if doc.visitor_type == 'FTV': frappe.db.sql( """update `tabFirst Timer` set school_status='%s' %s where name='%s' """ % (exm, baptism, d.ftv_id)) else: frappe.db.sql( """update `tabMember` set school_status='%s' %s where name='%s' """ % (exm, baptism, d.member_id)) if ftvdetails[0][2]: receiver_list.append(ftvdetails[0][2]) send_sms(receiver_list, cstr(msg_member)) return "Done"
def notify_medications(): print "############################~~~~~~~~~~~~Medications~~~~~~~~~~~~~~~~~~~############" recipient_list=[] med_list=get_medictions_to_notify() build_list,msg=fetch_data_from_medications(med_list,recipient_list) if build_list: for no in build_list: no_list=[] no_list.append(no) send_sms(no_list,msg=msg[no])
def send_message(doc, messages): patient = frappe.get_doc("Customer",doc.patient) if(patient.mobile): context = {"doc": doc, "alert": doc, "comments": None} if doc.get("_comments"): context["comments"] = json.loads(doc.get("_comments")) #jinja to string convertion happens here messages = frappe.render_template(messages, context) number = [patient.mobile] send_sms(number,messages)
def assignmember(memberid,ftv): frappe.db.sql("""update `tabFirst Timer` set ftv_owner='%s' where name='%s' """ % (memberid,ftv)) recipients='*****@*****.**' member=frappe.db.sql("select member_name,email_id,phone_1,address from `tabMember` where name='%s'"%(memberid)) ftvdetails=frappe.db.sql("select ftv_name,email_id,task_description,due_date,phone_1,address from `tabFirst Timer` where name='%s'"%(ftv)) msg_member="""Hello %s,<br><br> Greetings from Love World Synergy..!!! <br> Below are the contact details of First Timer. You are advised to visit and contact. <br> FT No :-'%s'<br> Name :-'%s'<br> Email :-'%s'<br> Phone :-'%s'<br> Address :-'%s'<br> """%(member[0][0],ftv,ftvdetails[0][0],ftvdetails[0][1],ftvdetails[0][4],ftvdetails[0][5]) msg_ftv="""Hello %s,<br> Welcome ..!!! Greetings from Love World Synergy. <br> Below are the contact details of Member, Who will contact you in a short while. <br> Member No :-'%s'<br> Name :-'%s'<br> Email :-'%s'<br> Phone :-'%s'<br> Address :-'%s'<br> """%(ftvdetails[0][0],memberid,member[0][0],member[0][1],member[0][2],member[0][3]) # frappe.errprint('gangadhar') # frappe.errprint(['member--',msg_member]) # frappe.errprint(['ftv---',msg_ftv]) desc="""Member '%s' is assigned to First Timer '%s' for followup."""%(memberid,ftv) task=frappe.get_doc({ "doctype": "Task", "subject": "Assign For followup", "expected_start_date":nowdate(), "expected_start_date":add_days(nowdate(),2), "status": "Open", "project": "", "description":desc }).insert(ignore_permissions=True) if frappe.db.exists("User", ftvdetails[0][1]): frappe.share.add("Task", task.name, ftvdetails[0][1], write=0) if frappe.db.exists("User", member[0][1]): frappe.share.add("Task", task.name, member[0][1], write=1) receiver_list=[] if member[0][2]: receiver_list.append(member[0][2]) send_sms(receiver_list, cstr(msg_member)) frappe.sendmail(recipients=member[0][1], sender='*****@*****.**', content=msg_member, subject='Assign for follow up') frappe.sendmail(recipients=ftvdetails[0][1], sender='*****@*****.**', content=msg_ftv, subject='Assign for follow up') return "Done"
def assignmember(memberid, ftv): frappe.db.sql( """update `tabFirst Timer` set ftv_owner='%s' where name='%s' """ % (memberid, ftv)) recipients = '*****@*****.**' member = frappe.db.sql( "select member_name,email_id,phone_1 from `tabMember` where name='%s'" % (memberid)) ftvdetails = frappe.db.sql( "select ftv_name,email_id,task_description,due_date from `tabFirst Timer` where name='%s'" % (ftv)) msg_member = """Hello %s,<br> The First Timer '%s' name: '%s' Email ID: '%s' is assigned to you for follow up <br>Regards,<br>Varve """ % (member[0][0], ftv, ftvdetails[0][0], ftvdetails[0][1]) msg_ftv = """Hello %s,<br> The Member '%s' name: '%s' Email ID: '%s' is assigned to you for follow up <br>Regards,<br>Varve """ % (ftvdetails[0][0], memberid, member[0][0], member[0][1]) desc = """Member '%s' is assigned to First Timer '%s' for followup.""" % ( memberid, ftv) task = frappe.get_doc({ "doctype": "Task", "subject": "Assign For followup", "expected_start_date": nowdate(), "expected_start_date": add_days(nowdate(), 2), "status": "Open", "project": "", "description": desc }).insert(ignore_permissions=True) if frappe.db.exists("User", ftvdetails[0][1]): frappe.share.add("Task", task.name, ftvdetails[0][1], write=0) if frappe.db.exists("User", member[0][1]): frappe.share.add("Task", task.name, member[0][1], write=1) receiver_list = [] receiver_list.append(member[0][2]) frappe.errprint(['rev[0]', receiver_list[0]]) if receiver_list[0]: frappe.errprint(receiver_list[0]) send_sms(receiver_list, cstr(msg_member)) frappe.sendmail(recipients=member[0][1], sender='*****@*****.**', content=msg_member, subject='Assign for follow up') frappe.sendmail(recipients=ftvdetails[0][1], sender='*****@*****.**', content=msg_ftv, subject='Assign for follow up') return "Done"
def send_sms(self): # frappe.errprint("in the send sms") receiver_list = [] if not self.message: frappe.errprint("in self.message") msgprint(_("Please enter message before sending")) else: # frappe.errprint("in the else") receiver_list = self.get_receiver_nos() # frappe.errprint(receiver_list) if receiver_list: # frappe.errprint("in the receiver_list sms") send_sms(receiver_list, cstr(self.message))
def send_pin_sms(PR, method,code): recipients=[] expiry_date='' customer=frappe.db.sql("""select phone_no ,customer from `tabBuy Back Requisition` where name='%s' """%(PR.buy_back_requisition_ref),as_list=1) if customer: recipients.append(cstr(customer[0][0])) cust=cstr(customer[0][1]) no_of_days=frappe.db.sql("""select value from `tabSingles` where field='no_of_days'""",as_dict=1) if no_of_days: expiry_date=add_days(nowdate(),cint(no_of_days[0]['value'])) if recipients: message ="""Dear %s,\nThe PIN below is generated against your transaction %s at '%s',\nPIN: %s,\nPIN Expiry Date: %s,\nKindly redeem the voucher before the expiry date.\nThanks You.""" %(cust,PR.buy_back_requisition_ref,PR.warehouse,code,formatdate(expiry_date)) send_sms(recipients,cstr(message))
def send_appointment_reminder(): from erpnext.setup.doctype.sms_settings.sms_settings import send_sms for appointment in frappe.db.sql("""select name, doctor_name, visit_purpose, patient_id, patient_name, from_time from `tabAppointment` where from_time between '{today} 00:00:00' and '{today} 23:59:59' """.format(today=today())): message = """ Hi {patient_name}, you have appointment with {doctor_name} at {time} for {purpose}""".format(patient_name=appointment.patient_name, doctor_name=appointment.doctor_name, time=appointment.from_time, purpose=appointment.visit_purpose) send_sms(frappe.db.get_value("Patient", appointment.patient_id, "mobile_no"), cstr(message))
def meetings_attendance(data): frappe.errprint("notify") """ Need to add provision to send sms,push notification and emails on present and absent """ dts=json.loads(data) frappe.errprint(dts) qry="select user from __Auth where user='******'username'])+"' and password=password('"+cstr(dts['userpass'])+"') " valid=frappe.db.sql(qry) if not valid: return { "status":"401", "message":"User name or Password is incorrect" } else: for record in dts['records']: frappe.errprint(dts['username']) if record['present']=='0' or record['present']=='1' : frappe.errprint(record) frappe.db.sql("update `tabInvitation Member Details` set present=%s where name=%s",(record['present'],record['name'])) mail_notify_msg = """Dear User, \n Attendance Record updated by Leader. Please Check. \n \n Records, \n Love World Synergy""" frappe.errprint(record['name']) notify = frappe.db.sql("""select value from `tabSingles` where doctype='Notification Settings' and field = 'attendance_updated_by_leader'""",as_list=1) # user = frappe.db.sql("""select parent from `tabDefaultValue` where defkey='Cells' and # defvalue in (select cell from `tabMember` where email_id='%s')"""%(dts['username']),as_list=1) user = frappe.db.sql("""select phone_1 from `tabMember` where email_id='%s'"""%(dts['username']),as_list=1) frappe.errprint(user) if user: member_details = frappe.db.sql("""select phone_1 from `tabMember` where email_id='%s'"""%(user[0][0]),as_list=1) frappe.errprint(member_details) if "Email" in notify[0][0]: frappe.sendmail(recipients=user[0][0], content=mail_notify_msg, subject='Attendance Record Update Notification') if "SMS" in notify[0][0]: frappe.errprint("SMS") if member_details: send_sms(member_details[0], mail_notify_msg) if "Push Notification" in notify[0][0]: data={} data['Message']=mail_notify_msg gcm = GCM('AIzaSyBIc4LYCnUU9wFV_pBoFHHzLoGm_xHl-5k') res=frappe.db.sql("select device_id from tabUser where name ='%s'" %(user[0][0]),as_list=1) frappe.errprint(res) if res: res = gcm.json_request(registration_ids=res, data=data,collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600) return "Updated Attendance"
def notify_acm_about_acm(lead_record, se_visit, child_id, assign_to): user = frappe.get_doc("User", assign_to) msg = get_sms_template( "ACM", { "lead_name": lead_record.lead_name, "lead_mobile": lead_record.mobile_no, "property_title": child_id.property_name, "prop_address": child_id.address, "acm_datetime": se_visit.schedule_date }) if user.mobile_no: rec_list = [] rec_list.append(user.mobile_no) send_sms(rec_list, msg=msg)
def send_welcome_mail(self,password): from frappe.utils import random_string, get_url key = random_string(32) mob_code=self.get_mob_code() self.db_set("reset_password_key", key) link = get_url("/verify_email?id="+self.profile_id+"&key=" + key) self.update_verification_details(password,key,mob_code,link) self.send_login_mail(_("Verify Your Account"), "templates/emails/new_user.html", {"link": link,"password":password}) sms='Your Code for PHR:'+cstr(mob_code) rec_list=[] rec_list.append(self.contact) from erpnext.setup.doctype.sms_settings.sms_settings import send_sms send_sms(rec_list,sms)
def send_redeemed_sms(Voucher, method): recipients=[] transaction_id='' buy_back_requisition_ref=frappe.db.sql("""select buy_back_requisition_ref,creation from `tabPurchase Receipt` where pin='%s' """%(Voucher.enter_pin),as_dict=1) if buy_back_requisition_ref: transaction_id=buy_back_requisition_ref[0]['buy_back_requisition_ref'] if Voucher.customer: customer=frappe.db.sql("""select phone_no from `tabCustomer` where name='%s' """%(Voucher.customer),as_list=1) if customer: recipients.append(customer[0][0]) if recipients: if Voucher.mark_voucher_as_redeemed==1: message ="""Dear %s,\nYour Voucher for Transaction %s at %s has been successfully redeemed.\nValue of the voucher :%s,\nRedemption Date:%s,\nThanks You.""" %(Voucher.customer,transaction_id,Voucher.warehouse,fmt_money(flt(Voucher.discount_amount)),formatdate(Voucher.creation)) send_sms(recipients,cstr(message))
def update_status(self): status = frappe.db.get_value("Task", self.name, "status") if self.status == "Working" and status != "Working" and not self.act_start_date: self.act_start_date = today() if self.status == "Closed" and status != "Closed" and not self.act_end_date: self.act_end_date = today() if self.status == "Closed" and status != "Closed": #receiver_list=frappe.db.sql("") from erpnext.setup.doctype.sms_settings.sms_settings import send_sms receiver_list = [] receiver_list.append("9960066444") send_sms(receiver_list, "Hi the task is closed")
def update_status(self): status = frappe.db.get_value("Task", self.name, "status") if self.status=="Working" and status !="Working" and not self.act_start_date: self.act_start_date = today() if self.status=="Closed" and status != "Closed" and not self.act_end_date: self.act_end_date = today() if self.status=="Closed" and status != "Closed" : #receiver_list=frappe.db.sql("") from erpnext.setup.doctype.sms_settings.sms_settings import send_sms receiver_list=[] receiver_list.append("9960066444") send_sms(receiver_list, "Hi the task is closed")
def make_customer(frm): reg = frappe.get_doc("Registration", frm) if reg.registration_partner: ref = frappe.get_doc("Registraion", reg.registration_partner) cust = frappe.new_doc("Customer") cust.first_name = ref.first_name cust.last_name = ref.last_name cust.customer_name = str(ref.first_name) + ' ' + str(ref.last_name) cust.customer_group = "Individual" cust.customer_type = "Individual" cust.territory = ref.emirates cust.telephone_no = ref.telephone_no cust.height = ref.height cust.weight = ref.weight cust.refistration = frm cust.insert() rlist = [] rlist.append(ref.telephone_no) send_sms(rlist, "You have been registered successfully", "Cambridge") test = frappe.new_doc("Customer") test.first_name = reg.first_name test.last_name = reg.last_name test.customer_name = str(reg.first_name) + ' ' + str(reg.last_name) test.customer_group = "Individual" test.customer_type = "Individual" test.territory = reg.emirates test.sex = reg.sex test.age = reg.age test.telephone_no = reg.telephone_no test.height = reg.height test.weight = reg.weight test.registration = frm test.insert() rlist = [] rlist.append(reg.telephone_no) send_sms(rlist, "You have been registered successfully", "Cambridge") if reg.registration_payment == "Free": reg.registration_payment = "Complete" reg.save() return test if reg.registration_payment == "Pending": si = frappe.new_doc("Sales Invoice") si.customer = test.name si.is_pos = 1 si.is_registration = 1 si.debit_to = "Registrations - CHFDXB" si.append("items", {"item_code": "Registration Charge", "qty": 1}) si.set_missing_values() return si
def fetch_data_from_medications(med_list,recipient_list): if med_list: msg={} for md in med_list: sms_send = True mobj = frappe.get_doc("Medication",md) week = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] import datetime now_day = datetime.datetime.today().weekday() fobj = frappe.get_doc("Dosage",mobj.dosage) options = json.loads(mobj.options) if mobj.dosage == "Weekly": if options['day'] != week[now_day]: sms_send = False if sms_send: for d in fobj.get('dosage_fields'): time_diff = 0 if d.fieldtype == "time": time_now = datetime.datetime.strftime(datetime.datetime.now(),'%H:%M') if options[d.fieldname]: med_time = datetime.datetime.strptime(options[d.fieldname], '%I:%M %p').strftime('%H:%M') time_diff = cint((datetime.datetime.strptime(time_now,'%H:%M')-datetime.datetime.strptime(med_time,'%H:%M')).total_seconds()/60) elif d.fieldname == "datetime": now_time = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S.%f') now_time_str = datetime.datetime.strptime(now_time, '%Y-%m-%d %H:%M:%S.%f') if options[d.fieldname]: med_time = datetime.datetime.strptime(options[d.fieldname], '%Y-%m-%d %H:%M:%S.%f') time_diff = cint((time_now-med_time).total_seconds()/60) if time_diff and (time_diff >= 0 and time_diff <= 5): uexists = frappe.db.get_value("User",{"profile_id":mobj.profile_id},"name") if uexists: user = frappe.get_doc("User",uexists) if user: if frappe.db.get_value("Mobile Verification",{"mobile_no":user.contact,"mflag":1},"name"): no_list = [] no_list.append(user.contact) send_sms(no_list,msg=get_sms_template("medication",{"medication":mobj.get('medicine_name')})) else: data = search_profile_data_from_solr(mobj.profile_id) if data and data['mobile']: if frappe.db.get_value("Mobile Verification",{"mobile_no":data['mobile'],"mflag":1},"name"): no_list = [] no_list.append(data['mobile']) send_sms(no_list,msg=get_sms_template("medication",{"medication":mobj.get('medicine_name')})) return "done"
def notify_lead_about_acm(lead_record, se_visit, child_id, assign_to): user = frappe.get_doc("User", assign_to) acm_name = ' '.join([ user.first_name, userlast_name ]) if user.first_name and user.last_name else user.first_name msg = get_sms_template( "Lead ACM", { "meeting_time": se_visit.schedule_date, "acm_name": acm_name, "acm_no": user.mobile_no }) if lead_record.mobile_no: rec_list = [] rec_list.append(lead_record.mobile_no) send_sms(rec_list, msg=msg)
def notify_provider(provider_id,patient,template,args,email_msg=None): provider_info = frappe.db.get_value("Provider",{"provider_id":provider_id},"name") if provider_info: provider = frappe.get_doc("Provider",provider_info) if provider.mobile_number: from phr.templates.pages.patient import get_sms_template msg = get_sms_template(template,args) recipient_list = [] recipient_list.append(provider.mobile_number) from erpnext.setup.doctype.sms_settings.sms_settings import send_sms send_sms(recipient_list,msg=msg) if provider.email and email_msg: from frappe.utils.email_lib import sendmail sendmail(provider.email, subject="HealthSnapp Updates:Data Shared With You", msg=email_msg)
def notify_about_linked_phrs(profile_id,email_msg=None,text_msg=None,entity=None,user_name=None): linked_phr = frappe.db.sql("""select profile_id from `tabNotification Configuration` where linked_phr=1 and profile_id='%s'"""%(profile_id)) if linked_phr: user = frappe.get_doc('User',frappe.db.get_value("User",{"profile_id":profile_id},"name")) if user: send_phrs_mail(user.name,"HealthSnapp Updates:"+entity+" Updated","templates/emails/linked_phrs_updates.html",{"user_name":user_name,"entity":entity}) if frappe.db.get_value("Mobile Verification",{"mobile_no":user.contact,"mflag":1},"name"): rec_list = [] rec_list.append(user.contact) send_sms(rec_list,msg=text_msg) else: from phr.templates.pages.dashboard import search_profile_data_from_solr search_profile_data_from_solr(profile_id)
def add_profile_to_db(data, profile_id): res = json.loads(data) actdata = res['actualdata'] dt = json.loads(actdata) sub = dt['person_firstname'] + " " + dt[ 'person_lastname'] + " " + "delinked Successfully" make_log(profile_id, "profile", "delink", sub) args = { 'person_firstname': dt['person_firstname'], 'person_middlename': dt['person_middlename'], 'person_lastname': dt['person_lastname'], 'email': dt['email'], 'mobile': dt['mobile'], 'received_from': 'Desktop', 'provider': 'false' } cie = frappe.db.get_value("LinkedPHR Images", {"profile_id": res['entityid']}, ["barcode", "profile_image"], as_dict=1) path = "" if cie.get('barcode'): path = cie.get('barcode') else: path = "" if cie.get('profile_image'): args['user_image'] = cie.get('profile_image') else: args['user_image'] = "" ret_res = create_profile_in_db(res['entityid'], args, res, path) user = frappe.get_doc("User", frappe.session.user) send_phrs_mail(user.email, "PHR:Linked PHR Account Delinked", "templates/emails/delink_phr.html", {"name": args['person_firstname']}) msg = get_sms_template("delink", {"phr_name": args['person_firstname']}) if user.contact: rec_list = [] rec_list.append(user.contact) send_sms(rec_list, msg=msg) sub = dt['person_firstname'] + " " + dt[ 'person_lastname'] + " " + "Profile Created Successfully" make_log(profile_id, "profile", "create", sub) return ret_res
def add_comment(doc): """allow any logged user to post a comment""" record = json.loads(doc) if record['comment_doctype'] == 'Attendance Record': mail_notify_msg = """Dear User, \n '{0}' had commented '{1}' on the Attendance Record '{2}'. \n Please Check. \n \n Records, \n Love World Synergy""".format(record['comment_by'], record['comment'], record['comment_docname']) notify = frappe.db.sql( """select value from `tabSingles` where doctype='Notification Settings' and field = 'when_a_leader_makes_a_comment'""", as_list=1) hirerchy = frappe.db.sql( "select a.name,a.device_id from `tabDefaultValue` b, `tabUser` a where a.name=b.parent and b.defkey='Senior Cells' and b.defvalue=(select senior_cell from `tabAttendance Record` where name='%s')" % record['comment_docname'], as_list=1) user = frappe.db.sql( """select phone_1 from `tabMember` where email_id='%s'""" % (hirerchy[0][0]), as_list=1) if "Email" in notify[0][0]: frappe.sendmail(recipients=hirerchy[0][0], content=mail_notify_msg, subject='Attendance Record comment Notification') frappe.sendmail(recipients='*****@*****.**', content=mail_notify_msg, subject='Attendance Record comment Notification') if "SMS" in notify[0][0]: from erpnext.setup.doctype.sms_settings.sms_settings import send_sms if user: send_sms(user[0][0], mail_notify_msg) if "Push Notification" in notify[0][0]: data = {} data['Message'] = mail_notify_msg from gcm import GCM gcm = GCM('AIzaSyBIc4LYCnUU9wFV_pBoFHHzLoGm_xHl-5k') res = gcm.json_request(registration_ids=[x[1] for x in hirerchy], data=data, collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600) doc = frappe.get_doc(record) doc.insert(ignore_permissions=True) return doc.as_dict()
def send_welcome_mail(password, profile_id, args, send_sms=True, is_provider=False): from frappe.utils import random_string, get_url key = random_string(32) db_set(args, "reset_password_key", key) link = get_url("/verify_email?id=" + profile_id + "&key=" + key) mob_code = get_mob_code() update_verification_details(args, password, key, mob_code, link, profile_id, is_provider) mail_response = send_login_mail(args, "Verify Your Account", "templates/emails/new_user.html", { "link": link, "password": password, "verify_sms": send_sms }) if send_sms: mob_already_v = frappe.db.get_value("Mobile Verification", { "mobile_no": args["mobile"], "mflag": 1 }, "name") if not mob_already_v: from phr.templates.pages.profile import make_mobile_verification_entry if not frappe.db.get_value("Mobile Verification", {"mobile_no": args["mobile"]}, "name"): make_mobile_verification_entry(args["mobile"], profile_id, mob_code) else: pass from phr.templates.pages.utils import get_sms_template sms = get_sms_template("registration", {"mobile_code": mob_code}) rec_list = [] rec_list.append(args["mobile"]) from erpnext.setup.doctype.sms_settings.sms_settings import send_sms send_sms(rec_list, sms) elif mob_already_v: vd = frappe.get_doc("Verification Details", profile_id) vd.mflag = 1 vd.save(ignore_permissions=True) return mail_response
def send_to_sms(BuyBackRequisition, method): recipients = [] if BuyBackRequisition.phone_no: phone_no = BuyBackRequisition.phone_no recipients.append(cstr(phone_no)) message = """Dear %s , We received your device at '%s', below are the details Transaction ID: %s, Device Received: %s, Received Date: %s, Offered Price: %s, Your voucher will be sent to you in a separate email & sms correspondence. Thank You.""" % (BuyBackRequisition.customer, BuyBackRequisition.warehouse, BuyBackRequisition.name, BuyBackRequisition.item_name, formatdate(BuyBackRequisition.creation), fmt_money(flt(BuyBackRequisition.offered_price))) send_sms(recipients, cstr(message))
def validate_duplicate(doc, method): if doc.get("__islocal"): res = frappe.db.sql( "select name from `tabChurches` where church_name='%s' and church_group='%s' and church_code='%s'" % (doc.church_name, doc.church_group, doc.church_code)) if res: frappe.throw( _("Another Church '{3}' With Church Name '{0}' and Church Code '{2}'' exist in Church Group '{1}'" ).format(doc.church_name, doc.church_group, doc.church_code, res[0][0])) notify_msg = """Dear User,\n\n Church is created with name '%s' for Group Church '%s'. \n\n Regards,\n\n Love World Synergy""" % ( doc.church_name, doc.church_group) notify = frappe.db.sql( """select value from `tabSingles` where doctype='Notification Settings' and field='on_creation_of_a_new_cell_pcf_church'""", as_list=1) if notify: if "Email" in notify[0][0]: if doc.email_id: frappe.sendmail(recipients=doc.email_id, content=notify_msg, subject='Church Creation Notification') if "SMS" in notify[0][0]: if doc.phone_no: send_sms(doc.phone_no, notify_msg) if "Push Notification" in notify[0][0]: data = {} data['Message'] = notify_msg gcm = GCM('AIzaSyBIc4LYCnUU9wFV_pBoFHHzLoGm_xHl-5k') res1 = frappe.db.sql( "select device_id from tabUser where name ='%s'" % (doc.email_id), as_list=1) frappe.errprint(res1) if res1: res1 = gcm.json_request(registration_ids=res1, data=data, collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600) ofc = frappe.new_doc("Offices") ofc.office_id = doc.name ofc.office_name = doc.church_name ofc.office_code = doc.church_code ofc.insert()
def otp(customer): size=6 chars=string.ascii_uppercase + string.digits + string.ascii_lowercase code=''.join(random.choice(chars) for _ in range(size)) # frappe.errprint(docname) # docname.save() # frappe.db.set_value("Sales Order",docname,"otp",code) text="Your otp is %s"%code cust=frappe.get_doc("Customer",customer) number= mobile_no=frappe.db.get_value("Customer",{"mobile_no":cust.mobile_no},"mobile_no") a=[] a.append(number) send_sms(a,text) # docname=frappe.get_doc("Customer",customer) frappe.db.set_value("Customer",customer,"otp",code) frappe.db.set_value("Customer",customer,"date",datetime.datetime.now()) # docname.save() return code
def notify_to_do(): print "############################~~~~~~~~~~~~todo~~~~~~~~~~~~~~~~~~~############" profile_ids = get_profile_ids() if profile_ids: email_list = [] sms_recipients = [] msg = {} email_msg = {} for profile in profile_ids: pobj = frappe.get_doc( 'User', frappe.db.get_value("User", {"profile_id": profile['profile_id']}, "name")) todoobj = frappe.get_doc('ToDo', profile['name']) if pobj: sms_recipients.append(pobj.contact) email_list.append(pobj.name) msg[pobj.contact] = get_sms_template( "todo", {"to_do": todoobj.description}) email_msg[pobj.name] = todoobj.description print pobj.name else: data = search_profile_data_from_solr(profile) if data['mobile']: sms_recipients.append(data["mobile"]) msg[data['mobile']] = get_sms_template( "todo", {"to_do": todoobj.description}) if data['email']: email_list.append(data["email"]) email_msg[data["email"]] = todoobj.description if sms_recipients: for no in sms_recipients: mob_no = [] mob_no.append(no) send_sms(sms_recipients, msg=msg[no]) if email_list: for email in email_list: print email_msg[email] send_phrs_mail(email, "PHR:To Do Alert", "templates/emails/todo.html", {"todo": email_msg[email]})
def notify_about_linked_phrs(profile_id, email_msg=None, text_msg=None, entity=None): linked_phr = ( """select profile_id from `tabNotification Configuration` where linked_phr=1""" ) if linked_phr: user = frappe.get_doc( 'User', frappe.db.get_value("User", {"profile_id": profile_id}, "name")) if user: sendmail(user.name, subject="PHR Updates:" + entity + " Updated", msg=email_msg) rec_list = [] rec_list.append(user.contact) send_sms(rec_list, msg=text_msg) else: search_profile_data_from_solr(profile_id)
def notify_provider(provider_id, patient, template, args, email_msg=None): provider_info = frappe.db.get_value("Provider", {"provider_id": provider_id}, "name") if provider_info: provider = frappe.get_doc("Provider", provider_info) if provider.mobile_number: from phr.templates.pages.utils import get_sms_template msg = get_sms_template(template, args) recipient_list = [] recipient_list.append(provider.mobile_number) from erpnext.setup.doctype.sms_settings.sms_settings import send_sms send_sms(recipient_list, msg=msg) if provider.email and email_msg: from frappe.utils.email_lib import sendmail sendmail(provider.email, subject="HealthSnapp Updates:Data Shared With You", msg=email_msg) return "done"
def send_sms1(numbers, msg, user): import math num = json.loads(numbers) i = datetime.datetime.now() today = datetime.date.today() if msg: counter = frappe.db.sql( "select sms_credits from `tabUser` where name='%s'" % (user), as_list=1) sms_len = math.ceil(len(msg) / 160.0) count = len(num) * cint(sms_len) if counter and count <= cint(counter[0][0]): credit_count = counter[0][0] - count send_sms(num, cstr(msg)) log = frappe.new_doc("SMS Log") log.sender_name = user log.sent_on = today log.receiver_list = numbers log.message = msg log.sms_sending_status = 'SMS Sent Successfully' log.insert() frappe.db.sql( "update `tabUser` set sms_credits='%s' where name='%s'" % (credit_count, user)) frappe.db.commit() frappe.msgprint(_("SMS Sent Successfully...")) else: log = frappe.new_doc("SMS Log") log.sender_name = user log.sent_on = today log.receiver_list = numbers log.message = msg log.sms_sending_status = 'Sending Fail' log.insert(ignore_permissions=True) frappe.db.commit() frappe.throw( _("SMS credit is not available for sending SMS, Sending fail..!" )) else: frappe.throw( _("Message should not be blank,Please enter text message..."))
def otp(customer): size = 6 chars = string.ascii_uppercase + string.digits + string.ascii_lowercase code = ''.join(random.choice(chars) for _ in range(size)) # frappe.errprint(docname) # docname.save() # frappe.db.set_value("Sales Order",docname,"otp",code) text = "Your otp is %s" % code cust = frappe.get_doc("Customer", customer) number = mobile_no = frappe.db.get_value("Customer", {"mobile_no": cust.mobile_no}, "mobile_no") a = [] a.append(number) send_sms(a, text) # docname=frappe.get_doc("Customer",customer) frappe.db.set_value("Customer", customer, "otp", code) frappe.db.set_value("Customer", customer, "date", datetime.datetime.now()) # docname.save() return code
def assignmember(memberid,ftv): frappe.db.sql("""update `tabFirst Timer` set ftv_owner='%s' where name='%s' """ % (memberid,ftv)) recipients='*****@*****.**' member=frappe.db.sql("select member_name,email_id,phone_1 from `tabMember` where name='%s'"%(memberid)) ftvdetails=frappe.db.sql("select ftv_name,email_id,task_description,due_date from `tabFirst Timer` where name='%s'"%(ftv)) msg_member="""Hello %s,<br> The First Timer '%s' name: '%s' Email ID: '%s' is assigned to you for follow up <br>Regards,<br>Varve """%(member[0][0],ftv,ftvdetails[0][0],ftvdetails[0][1]) msg_ftv="""Hello %s,<br> The Member '%s' name: '%s' Email ID: '%s' is assigned to you for follow up <br>Regards,<br>Varve """%(ftvdetails[0][0],memberid,member[0][0],member[0][1]) desc="""Member '%s' is assigned to First Timer '%s' for followup."""%(memberid,ftv) task=frappe.get_doc({ "doctype": "Task", "subject": "Assign For followup", "expected_start_date":nowdate(), "expected_start_date":add_days(nowdate(),2), "status": "Open", "project": "", "description":desc }).insert(ignore_permissions=True) if frappe.db.exists("User", ftvdetails[0][1]): frappe.share.add("Task", task.name, ftvdetails[0][1], write=0) if frappe.db.exists("User", member[0][1]): frappe.share.add("Task", task.name, member[0][1], write=1) receiver_list=[] receiver_list.append(member[0][2]) frappe.errprint(['rev[0]',receiver_list[0]]) if receiver_list[0] : frappe.errprint(receiver_list[0]) send_sms(receiver_list, cstr(msg_member)) frappe.sendmail(recipients=member[0][1], sender='*****@*****.**', content=msg_member, subject='Assign for follow up') frappe.sendmail(recipients=ftvdetails[0][1], sender='*****@*****.**', content=msg_ftv, subject='Assign for follow up') return "Done"
def update_attendance(doc,method): for d in doc.get('attendance'): if doc.visitor_type=='FTV': ftvdetails=frappe.db.sql("select ftv_name,email_id,phone_1 from `tabFirst Timer` where name='%s'"%(d.ftv_id)) else: ftvdetails=frappe.db.sql("select member_name,email_id,phone_1 from `tabMember` where name='%s'"%(d.member_id)) msg_member="""Hello %s,<br><br> You have '%s' for Foundation Class '%s' <br><br>Regards,<br>Verve """%(ftvdetails[0][0],d.attendance,doc.fc_class) if ftvdetails and ftvdetails[0][1]: frappe.sendmail(recipients=ftvdetails[0][1], sender='*****@*****.**', content=msg_member, subject='Verve Class Attendance') from erpnext.setup.doctype.sms_settings.sms_settings import send_sms receiver_list=[] baptism='' if d.baptism_when and d.baptism_where: baptism=", baptisum_status='Yes' , baptism_when='"+d.baptism_when+"' , baptism_where='"+cstr(d.baptism_where)+"' " if d.attendance=='Present': if doc.fc_class=='Class 1': exm='Completed Class 1' elif doc.fc_class=='Class 2': exm='Completed Class 1&2' elif doc.fc_class=='Class 3': exm='Completed Class 1, 2 & 3' elif doc.fc_class=='Class 4': exm='Completed Class 1, 2 , 3 & 4' elif doc.fc_class=='Class 5': exm='Completed Class 1, 2 , 3 , 4 & 5' elif doc.fc_class=='Class 6': exm='Completed Class 1, 2 , 3 , 4 , 5 & 6' if doc.visitor_type=='FTV': frappe.db.sql("""update `tabFirst Timer` set school_status='%s' %s where name='%s' """ % (exm,baptism,d.ftv_id)) else: frappe.db.sql("""update `tabMember` set school_status='%s' %s where name='%s' """ % (exm, baptism, d.member_id)) if ftvdetails and ftvdetails[0][2]: receiver_list.append(ftvdetails[0][2]) # frappe.errprint(['sssss',receiver_list[0][2]]) send_sms(receiver_list, cstr(msg_member)) return "Done"
def send_adv_sms(adv): sms = get_sms_template("Advertisement Notification", adv) send_sms(['9773595372', '9860733789'],sms)
def send_adv_sms(adv): sms = get_sms_template("Advertisement Notification", adv) send_sms(adv.get("notify_to"),sms)
def notify_about_registration(): mobile_nos = get_mobile_nos() if mobile_nos: send_sms(mobile_nos,msg='Please Complete Your Healthsnapp Registration')
def send_phr_sms(mobile,msg): from erpnext.setup.doctype.sms_settings.sms_settings import send_sms if frappe.db.get_value("Mobile Verification",{"mobile_no":mobile,"mflag":1},"name"): no_list = [] no_list.append(mobile) send_sms(no_list,msg=msg)