import json
import random
from sqlwrapper import gensql,dbget,dbput
import datetime
from ApplicationDate import application_date
def HOTEL_BBL_POST_INSERT_Business_Block_Notes(request):
    d = request.json
    print(d)
    sql = gensql('insert','business_block.business_block_notes',d)
    print(sql)

    s = {}
    s['user_role'] = "Admin"
    block_id = d.get("block_id")
    sqlvalue = json.loads(dbget("select block_name from business_block.business_block where block_id = '"+block_id+"' "))
    app_datetime = application_date()
    #RES_Log_Time = datetime.datetime.utcnow()+datetime.timedelta(hours=5, minutes=30)
    RES_Log_Time = app_datetime[0]
    RES_Log_Date = app_datetime[1]
    print(RES_Log_Date)
    s['date'] = RES_Log_Date
    s['time'] = RES_Log_Time
    s['block_id'] = block_id
    s['action_type_id'] = "Business Block notes"
    s['description'] = "Business Block notes for"+" "+str(block_id)
    gensql('insert','business_block.business_block_activity_log',s)
    return(json.dumps({"Return": "Record Inserted Successfully","ReturnCode": "RIS","Status": "Success","StatusCode": "200"},indent=4))

def HOTEL_BBL_POST_SELECT_Business_Block_Notes(request):
  d = request.json
  sql= json.loads(dbget("select notetype.notetype,* from business_block.business_block_notes \
                        left join profile.notetype on notetype.id=business_block_notes.notes_type \
                         where block_id= '"+str(d['block_id'])+"'"))
  return(json.dumps({'Status': 'Success', 'StatusCode': '200','ReturnValue':sql,'ReturnCode':'RRTS'},indent=4))
   
