Beispiel #1
0
def mfsiporderplace(payload):
    '''
    if request.method=='OPTIONS':
        print ("inside mfsiporderplace options")
        return jsonify({'body':'success'})

    elif request.method=='POST':   
        print ("inside mfsiporderplace post")

        print(request.headers)
        payload= request.get_json()
        #payload = request.stream.read().decode('utf8')            
        print(payload)
    '''

    userid = payload.userid
    entityid = payload.entityid

    con, cur = db.mydbopncon()
Beispiel #2
0
def prepare_order(orderrecord):
    ord = orderrecord
    print("processing order" + ord['mfor_uniquereferencenumber'])
    #time.sleep(0.5)
    #return json.dumps({'mfor_uniquereferencenumber': ord['mfor_uniquereferencenumber'],'order_id': '','amount':ord['mfor_amount']})

    if (ord['mfor_ordertype'] == 'One Time'):
        has_error, order_json = prepare_onetime_ord(ord)
        if has_error:
            pass
        else:
            #CALL ORDER PLACEMENT API to place order
            #order_id = <value returned from BSE>
            orderstat = 'PPY'

    elif (ord['mfor_ordertype'] == 'SIP'):
        has_error, order_json = prepare_isip_ord(ord)
        if has_error:
            pass
        else:
            #CALL ORDER PLACEMENT API to place order
            #order_id = <value returned from BSE>
            orderstat = 'INP'

    con, cur = db.mydbopncon()

    if has_error:
        orderstat = 'FAI'
        command = cur.mogrify(
            """
            UPDATE webapp.mforderdetails SET mfor_valierrors = %s, mfor_orderstatus = %s WHERE mfor_uniquereferencenumber = %s AND mfor_entityid = %s;
        """, (
                order_json,
                orderstat,
                ord['mfor_uniquereferencenumber'],
                ord['mfor_pfuserid'],
                ord['mfor_entityid'],
            ))

        print(command)

        cur, dbqerr = db.mydbfunc(con, cur, command)
        con.commit()
        cur.close()
        con.close()

        print("order id :" + ord['mfor_uniquereferencenumber'] +
              ", has errors in processing")

        return json.dumps({
            'mfor_uniquereferencenumber':
            ord['mfor_uniquereferencenumber'],
            'order_id':
            '',
            'amount':
            ord['mfor_amount']
        })

    else:
        #update the order id in the table
        command = cur.mogrify(
            """
            UPDATE webapp.mforderdetails SET mfor_orderid = %s, mfor_orderstatus = %s WHERE mfor_uniquereferencenumber = %s AND mfor_entityid = %s;
        """, (
                order_id,
                orderstat,
                ord['mfor_uniquereferencenumber'],
                ord['mfor_pfuserid'],
                ord['mfor_entityid'],
            ))

        print(command)

        cur, dbqerr = db.mydbfunc(con, cur, command)
        con.commit()
        cur.close()
        con.close()
        print("order id :" + ord['mfor_uniquereferencenumber'] +
              ", successfully processed")

        return json.dumps({
            'mfor_uniquereferencenumber':
            ord['mfor_uniquereferencenumber'],
            'order_id':
            order_id,
            'amount':
            ord['mfor_amount']
        })
Beispiel #3
0
def mfordersubmit_cpy(payload_org):
################ COPY FROM mfordersubmit #########################
    
    con,cur=db.mydbopncon()
    
    one_time_pay_details = payload_org['one_time_pay']
    sip_pay_details = payload_org['sip_pay']  #Not required for one time
    payload = payload_org['succrecs']
    userid = payload_org['userid']
    entityid = payload_org['entityid']


    ord_ids=[]
    for payld in payload:
        ord_ids.append(payld['mfor_uniquereferencenumber'])

    str=tuple(ord_ids)
    print(str)

    if userid is None or userid == '':
        userid,entityid=jwtnoverify.validatetoken(request)
    
    if entityid is None or userid == '':
        userid,entityid=jwtnoverify.validatetoken(request)

    con,cur=db.mydbopncon()

    command = cur.mogrify("""
                SELECT mfor_msgjson FROM webapp.mforderdetails WHERE mfor_uniquereferencenumber IN %s AND mfor_pfuserid = %s AND mfor_entityid = %s and mfor_orderstatus = 'VAS';
                """,(str,userid,entityid,))
    print(command)
    cur, dbqerr = db.mydbfunc(con,cur,command)
    if cur.closed == True:
        if(dbqerr['natstatus'] == "error" or dbqerr['natstatus'] == "warning"):
            dbqerr['statusdetails']="selecting order to submit to BSE failed"
        resp = make_response(jsonify(dbqerr), 400)
        return(resp)
    
    #Model to follow in all fetch
    orders=[]
    for record in cur:
        print(record[0])
        orders.append(record[0])

    print(orders)
    order_records = json.dumps(orders)
    
    ###  this should be a API call in lambda  #####
    orderresp = mforderapi.place_order_bse(order_records)
    ###  this should be a API call in lambda  #####

    print(orderresp)
    #Add code to update the order id

    ot_orderids=[]
    sip_orderids=[]

    for orderres in orderresp:
        
        if orderres['success_flag'] == '0':
        
            if orderres['order_type'] == 'OneTime':
                ot_orderids.append(orderres['trans_no'])
                command = cur.mogrify("""
                    UPDATE webapp.mforderdetails SET mfor_orderstatus = 'PPY', mfor_orderid = %s, mfor_bseremarks = %s WHERE mfor_uniquereferencenumber = %s AND mfor_pfuserid = %s AND mfor_entityid = %s;
                """,(orderres['order_id'],orderres['bse_remarks'],orderres['trans_no'],userid,entityid,))
            
            elif orderres['order_type'] == 'SIP':
                sip_orderids.append(orderres['trans_no'])
                command = cur.mogrify("""
                    UPDATE webapp.mforderdetails SET mfor_orderstatus = 'INP', mfor_orderid = %s, mfor_bseremarks = %s WHERE mfor_uniquereferencenumber = %s AND mfor_pfuserid = %s AND mfor_entityid = %s;
                """,(orderres['order_id'],orderres['bse_remarks'],orderres['trans_no'],userid,entityid,))
        
        else:
            if orderres['order_type'] == 'OneTime':
                ot_orderids.append(orderres['trans_no'])
                command = cur.mogrify("""
                    UPDATE webapp.mforderdetails SET mfor_orderstatus = 'FAI', mfor_valierrors = %s WHERE mfor_uniquereferencenumber = %s AND mfor_pfuserid = %s AND mfor_entityid = %s;
                """,(orderres['bse_remarks'],orderres['trans_no'],userid,entityid,))

            elif orderres['order_type'] == 'SIP':
                sip_orderids.append(orderres['trans_no'])
                command = cur.mogrify("""
                    UPDATE webapp.mforderdetails SET mfor_orderstatus = 'FAI', mfor_valierrors = %s WHERE mfor_uniquereferencenumber = %s AND mfor_pfuserid = %s AND mfor_entityid = %s;
                """,(orderres['bse_remarks'],orderres['trans_no'],userid,entityid,))

        print(command)

        cur, dbqerr = db.mydbfunc(con,cur,command)
        con.commit()

    if orderres['order_type'] == 'OneTime':
        str2 = tuple(ot_orderids)           
        
        frmdt = (datetime.now() + timedelta(days=-1)).strftime('%d-%b-%Y')
        todt = datetime.now().strftime('%d-%b-%Y')

        all_recs = mforder.fetchsucfai_recs(con, cur, str2, 'One Time', userid, entityid, frmdt, todt, 'BFP')
        print('*******************ord_type')
        print(orderres['order_type'])
        print(str2)
        print(all_recs)
        print('*******************ord_type')

        resp_recs = all_recs
        '''
        resp_recs={
            'success_recs': all_records['suc_records,
            'failure_recs': fai_records
        }
        '''
        print(json.dumps(resp_recs))
        
    elif orderres['order_type'] == 'SIP':
        resp_recs = {
            'status' : 'completed',
            'sip_orderids': sip_orderids
            }
    con.commit()
    cur.close()
    con.close()  
    return json.dumps(resp_recs)
Beispiel #4
0
def sip_order_processing(sip_data_for_processing):
#This is called for sip processing
    '''
    if request.method=='OPTIONS':
        print("inside sip_order_processing options")
        return make_response(jsonify('inside sip_order_processing options'), 200)  

    elif request.method=='POST':
        print("inside sip_order_processing GET")
        print((request))        
        print(request.headers)
        payload_org= request.get_json()
        sip_pay 
        print(payload_org)
        userid,entityid=jwtnoverify.validatetoken(request)
        print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

    '''
    payload_org = sip_data_for_processing
    #sip_mandate_details = payload_org['sip_mandate_details']
    userid = payload_org['userid']
    entityid = payload_org['entityid']

    print(userid,entityid)
    
    con,cur=db.mydbopncon()

    command = cur.mogrify("select json_agg(b) from (SELECT * FROM webapp.mforderdetails WHERE mfor_ordertype = 'SIP' AND mfor_orderstatus='PNS' AND mfor_pfuserid = %s AND mfor_entityid =%s) as b;",(userid,entityid,))
    print(command)
    cur, dbqerr = db.mydbfunc(con,cur,command)
                            
    if cur.closed == True:
        if(dbqerr['natstatus'] == "error" or dbqerr['natstatus'] == "warning"):
            dbqerr['statusdetails']="Data for order multiprocess fetch failed"
        resp = make_response(jsonify(dbqerr), 400)
        return(resp)
    print("cur") 
    print(cur)
    
    #Model to follow in all fetch
    sip_records=[]
    sip_records_orderids=[]
    
    if cur:
        for record in cur:           
            sip_records = record[0]
    
    if sip_records is None:
        sip_records = []
    print(sip_records)
    print("len(sip_records")
    print(len(sip_records))
    if len(sip_records) > 0:    
        print("i am insider sip records")
        for record in sip_records:    
            sip_records_orderids.append(record['mfor_uniquereferencenumber'])

        sipordersets = sip_records
        siporderids = sip_records_orderids
        

        pool = Pool(processes=10)
        result = pool.map_async(sip_prepare_order, sipordersets)   
        result.wait()  
        print(result.get())        
        pool.close()
        pool.join()
        str2=tuple(siporderids)
        todt  = datetime.now().strftime('%d-%b-%Y')
        frmdt = (datetime.now() + timedelta(days=-1)).strftime('%d-%b-%Y')    

        ###  this should be a API call in lambda  #####
        all_recs = mforder.fetchsucfai_recs(con, cur, str2, 'SIP', userid, entityid,frmdt,todt,'VAS')
        ###  this should be a API call in lambda  #####
        resp_recs = all_recs['sip']
        resp_suc_recs = resp_recs['success_recs']
        
        ###  this should be a API call in lambda  #####
        sip_submit_rec = {
            'sip_pay':'',
            'one_time_pay' : '',
            'succrecs' : resp_suc_recs,
            'userid': userid,
            'entityid': entityid
        }
 
        
        recs = mfordersubmit_cpy(sip_submit_rec)
        ###  this should be a API call in lambda  #####
    
    else:
        recs = {
            'status' : 'notrantoprocess',
            'sip_orderids': []
        }


    return recs    
Beispiel #5
0
def funddatafetch():
#This is called by fund data fetch service
    if request.method=='OPTIONS':
        print("inside FUNDDATAFETCH options")
        return make_response(jsonify('inside FUNDDATAFETCH options'), 200)  

    elif request.method=='POST':
        print("inside PFDATAFETCH GET")
        
        print((request))        
        print(request.headers)
        userid,entityid=jwtnoverify.validatetoken(request)
        print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        print(userid,entityid)
        payload= request.get_json()
        print(payload)
        print('after')
        con,cur=db.mydbopncon()

        print(con)
        print(cur)
        teee='%'+payload+'%'
        #cur.execute("select row_to_json(art) from (select a.*, (select json_agg(b) from (select * from pfstklist where pfportfolioid = a.pfportfolioid ) as b) as pfstklist, (select json_agg(c) from (select * from pfmflist where pfportfolioid = a.pfportfolioid ) as c) as pfmflist from pfmaindetail as a where pfuserid =%s ) art",(userid,))
        #command = cur.mogrify("select row_to_json(art) from (select a.*,(select json_agg(c) from (select * from webapp.fundsipdt where sipfndnatcode = a.fndnatcode ) as c) as fnsipdt from webapp.fundmaster as a where fnddisplayname like %s) art",(teee,))
        command = cur.mogrify("select row_to_json(art) from (select a.fndnatcode,a.fndschcdfrmbse,a.fnddisplayname,a.fndminpuramt,a.fndaddpuramt,a.fndmaxpuramt,a.fndpuramtinmulti,a.fndpurcutoff,a.fndamcnatcode, (select json_agg(c) from (select sipfreq,sipfreqdates,sipminamt,sipmaxamt,sipmulamt,sipmininstal,sipmaxinstal,sipmingap from webapp.fundsipdt where sipfndnatcode = a.fndnatcode ) as c) as fnsipdt from webapp.fundmaster as a where UPPER(fnddisplayname) like (%s)) art",(teee,))
        cur, dbqerr = db.mydbfunc(con,cur,command)
        print(command)
        print(cur)
        print(dbqerr)
        print(type(dbqerr))
        print(dbqerr['natstatus'])

        if cur.closed == True:
            if(dbqerr['natstatus'] == "error" or dbqerr['natstatus'] == "warning"):
                dbqerr['statusdetails']="pf Fetch failed"
            resp = make_response(jsonify(dbqerr), 400)
            return(resp)


        #Model to follow in all fetch
        records=[]
        for record in cur:  
            records.append(record[0])        
        print(records)
        print("Fund details returned for user: "******"--------------")
            print(record)
            print("--------------")
            if record.get('fnsipdt') != None:
                for sipdt in record.get('fnsipdt'):
                    print(sipdt)
                    mydate=int(datetime.now().strftime('%d'))+10
                    mymnt=int(datetime.now().strftime('%m'))
                    mynxtmnt=int(datetime.now().strftime('%m'))+1
                    myyr=datetime.now().strftime('%Y')
                    sipdates=sipdt.get('sipfreqdates').split(',')
                    print(sipdt['sipfreqdates'])
                    sipdt['sipfreqdates']=[]
                    for sipdate in sipdates:
                        print(type(sipdate))
                        print(type(mydate))
                        if(int(sipdate)>mydate):
                            now = (datetime.strptime((str(sipdate)+'/'+str(mymnt)+'/'+str(myyr)), '%d/%m/%Y').date()).strftime('%d-%b-%Y')         
                                                
                            print(now)
                            print(type(now))
                            
                            #sipdt['sipfreqdates'].append(str(sipdate)+'/'+str(mymnt)+'/'+str(myyr))
                            sipdt['sipfreqdates'].append(now)
                            
                        else:
                            #sipdt['sipfreqdates'].append(str(sipdate)+'/'+str(mynxtmnt)+'/'+str(myyr))
                            #now = datetime.strptime((str(sipdate)+'/'+str(mynxtmnt)+'/'+str(myyr)), '%d/%m/%Y').date()
                            now1=(datetime.strptime((str(sipdate)+'/'+str(mynxtmnt)+'/'+str(myyr)), '%d/%m/%Y').date()).strftime('%d-%b-%Y')
                            print(now1)                         
                            print(type(now1))
                            sipdt['sipfreqdates'].append(now1)


                    print(sipdt['sipfreqdates'])
                
                


        
        resp = json.dumps(records)
    
    return resp