Ejemplo n.º 1
0
def uploaded_file_list():
    #returns the files for the user in s3
    if request.method == 'OPTIONS':
        return 'ok'
    elif request.method == 'GET':
        con, cur = db.mydbopncon()
        #userid,entityid=jwtnoverify.validatetoken(request)
        userid = 'BfulXOzj3ibSPSBDVgzMEAF1gax1'
        entityid = 'IN'
        s3 = boto3.client('s3')
        respjsonstr = fetchfilelist(userid, entityid, con, cur, s3)

        print('sending values back to frontend')
        db.mydbcloseall(con, cur)
        print((respjsonstr))
        return make_response(jsonify(respjsonstr), 200)
    else:
        print('invalid option for this function')
        return 'ok'
Ejemplo n.º 2
0
def uploaded_file_submit():
    #handles user action for final submit to BSE
    if request.method == 'OPTIONS':
        print('options')
        return 'ok'
    elif request.method == 'GET':
        print('iam inside get of uploadedfilesubmit')
        userid, entityid = jwtnoverify.validatetoken(request)
        con, cur = db.mydbopncon()

        cmdqry = "SELECT lgclientcode FROM userlogin WHERE lguserid = %s AND lgentityid = %s"
        command = cur.mogrify(cmdqry, (
            userid,
            entityid,
        ))
        print(command)
        cur, dbqerr = db.mydbfunc(con, cur, command)
        rowcount = cur.rowcount

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

        records = []
        if rowcount != 0:
            for record in cur:
                print('inside for')
                print(record)
                records.append(record)
        print(records)
        clientcode = records[0]

        #clientcode='A000000001'

        cmdqry = "SELECT fuplfiles3bucket,fuplfiles3key,fuplfiletype FROM fileuploadmaster WHERE fuplfilesubmitstaus != 'S' and fuplfilecat = 'E' AND fupllguserid = %s AND fuplentityid = %s"
        command = cur.mogrify(cmdqry, (
            userid,
            entityid,
        ))
        print(command)
        cur, dbqerr = db.mydbfunc(con, cur, command)
        rowcount = cur.rowcount

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

        records = []
        if rowcount != 0:
            for record in cur:
                print('inside for')
                print(record)
                records.append(record)

        print(records)
        #======delete
        #records=['nat','kumar']
        #======
        reqjsons_payload = {}
        for record in records:
            #======Uncomment
            bucket, key, filetype = record
            #======Uncomment
            s3 = boto3.resource('s3')
            obj = s3.Object(bucket, key)
            fls1 = obj.get()['Body'].read()
            fls = bytearray(fls1)

            files_payload = {'myfiles': fls}
            reqjsons_payload = {
                'ClientCode': clientcode,
                'filetype': filetype,
                'publickey': 'to be implemented'
            }

            print('starting upload')
            #url='http://127.0.0.1:8000/fileuploadapi'
            url = settings.BSESTAR_AOFUPLOAD_URL[settings.LIVE]
            print(url)
            r = requests.post(url, files=files_payload, data=reqjsons_payload)
            rj = json.loads(r.text)
            print(r.content)
            if r.status_code != 200:
                resp = make_response(
                    jsonify({
                        'natstatus': 'error',
                        'statusdetails': rj['ResponseString']
                    }), 400)
            else:
                print('calling bse is successful')
                #for successful cases response is made at the end
                #resp=make_response(jsonify({'natstatus':'error','statusdetails':r.content}), 400)

    else:
        print('No records to upload')
        return 'No records to upload'

    #All successful so we are updating the user status
    #Only time we come here is for GET request

    #Update userstatus to P to indicate completion of document upload Completed
    command = cur.mogrify(
        "UPDATE userlogin SET lguserstatus = 'P', lglmtime = CURRENT_TIMESTAMP WHERE lguserid = %s AND lgentityid = %s;",
        (
            userid,
            entityid,
        ))
    print(command)
    cur, dbqerr = db.mydbfunc(con, cur, command)
    print(dbqerr['natstatus'])
    if cur.closed == True:
        if (dbqerr['natstatus'] == "error"
                or dbqerr['natstatus'] == "warning"):
            dbqerr[
                'statusdetails'] = "user status update after doc upload failed"
            resp = make_response(jsonify(dbqerr), 400)
            return (resp)
    #con.commit()
    #print(cur)
    print('consider insert or update is successful')

    #INSERT NOTIFICATION ENTRY FOR COMPLETION OF REGISTRAION AND DOC UPLOAD START

    command = cur.mogrify(
        "SELECT count(*) FROM notifimaster WHERE nfname='reistrationcomplet' AND nfmuserid = %s and nfmentityid = %s;",
        (
            userid,
            entityid,
        ))
    print(command)
    cur, dbqerr = db.mydbfunc(con, cur, command)
    rowcount = cur.rowcount

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

    records = []
    if rowcount != 0:
        for record in cur:
            print('inside for')
            print(record)
            records.append(record)
    print(records)
    countis = records[0]

    if countis == 0:
        nfmid = datetime.now().strftime('%Y%m%d%H%M%S%f')
        print('nfmid :', nfmid)
        command = cur.mogrify(
            "INSERT INTO notifimaster (nfmid,nfname,nfmuserid,nfmscreenid,nfmessage,nfmsgtype,nfmprocessscope,nfmnxtact,nfmnxtactmsg,nfmnxtactnavtyp,nfmnxtactnavdest,nfmstartdt,nfmoctime,nfmlmtime,nfmentityid) VALUES (%s,'reistrationcomplet',%s,'dashboard','Registration process completed, you can start buying','notifaction','P','Y','','NONE','NONE',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,%s) WHERE NOT EXISTS (SELECT 1 FROM notifimaster WHERE nfname='reistrationcomplet');",
            (
                nfmid,
                userid,
                entityid,
            ))
        print(command)
        cur, dbqerr = db.mydbfunc(con, cur, command)
        print(dbqerr['natstatus'])
        if cur.closed == True:
            if (dbqerr['natstatus'] == "error"
                    or dbqerr['natstatus'] == "warning"):
                dbqerr[
                    'statusdetails'] = "docupload complete notification update failed"
                resp = make_response(jsonify(dbqerr), 400)
                return (resp)
        con.commit()
        print(cur)
        print('consider insert or update is successful')

    #INSERT NOTIFICATION ENTRY FOR COMPLETION OF REGISTRAION AND DOC UPLOAD END
    #Now send resonse back to client confirming registration success.  Navigate to home screen
    resp = make_response(
        jsonify({
            'natstatus': 'success',
            'statusdetails': 'File upload successful'
        }), 200)
    #resp = make_response('File upload successful', 200)

    #resp = 'success da nattu'
    return resp
Ejemplo n.º 3
0
def upload_file():
    #Upload file to s3
    print(request)

    if request.method == 'POST':
        con, cur = db.mydbopncon()
        userid, entityid = jwtnoverify.validatetoken(request)
        # check if the post request has the file part
        if 'selectFile' not in request.files:
            print('No file part')
            return 'failed'
        file = request.files['selectFile']

        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':
            print('No selected file')
            return 'no file selected'
        if file:
            filename = secure_filename(file.filename)
            print(type(file))
            filecontenttype = file.content_type
            print("filecontenttype :", filecontenttype)
            print('userid :', userid)
            print('entityid :', entityid)
            #take values for insert START
            filetype = filename[:-5]
            print('filetype', filetype)
            filename = userid + entityid + filename
            files3bucket = 'zappa-44lyjdddx'
            files3key = filename
            #filesubmitstaus = 'I'

            print('filename', filename)
            #take values for insert END

            print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
            data = file
            print('starting upload to s3')

            s3 = boto3.client('s3')

            try:
                s3.upload_fileobj(data, files3bucket, files3key)
            except Exception as e:
                print(e)
                dbqerr = {}
                db.mydbcloseall(con, cur)
                dbqerr['natstatus'] = 'error'
                dbqerr['statusdetails'] = 'File upload failed'
                resp = make_response(jsonify(dbqerr), 400)
                return (resp)
            else:
                print('success')

            #INSERT UPLOADED DOC DETAILS START

            command = cur.mogrify(
                "INSERT INTO fileuploadmaster (fupllguserid,fuplfilecat,fuplfiletype,fuplfilename,fuplfiles3bucket,fuplfiles3key,fuplfilesubmitstaus,fuploctime,fupllmtime,fuplentityid) VALUES (%s,'E',%s,%s,%s,%s,'I',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,%s);",
                (
                    userid,
                    filetype,
                    filename,
                    files3bucket,
                    files3key,
                    entityid,
                ))
            cur, dbqerr = db.mydbfunc(con, cur, command)
            print(dbqerr['natstatus'])
            if cur.closed == True:
                if (dbqerr['natstatus'] == "error"
                        or dbqerr['natstatus'] == "warning"):
                    dbqerr['statusdetails'] = "SIGNUP update failed"
                resp = make_response(jsonify(dbqerr), 400)
                return (resp)
            con.commit()
            print(cur)
            print('consider insert or update is successful')

            #INSERT UPLOADED DOC DETAILS END

    elif request.method == 'OPTIONS':
        return "ok"
    else:
        print("inside else")

    respjsonstr = fetchfilelist(userid, entityid, con, cur, s3)

    db.mydbcloseall(con, cur)
    return make_response(jsonify(respjsonstr), 200)
Ejemplo n.º 4
0
def uploaded_file_delete():
    #handles user action for deleting file
    if request.method == 'OPTIONS':
        return 'ok'
    elif request.method == 'POST':
        print('uploadfiledelete inside POST')
        payload = request.get_json()
        print(payload)
        objbucket = payload['files3bucket']
        objkey = payload['files3key']
        category = payload['filecat']
        userid, entityid = jwtnoverify.validatetoken(request)
        print('starting with s3')

        s3 = boto3.client('s3')
        try:
            s3.delete_object(Bucket=objbucket, Key=objkey)
        except Exception as e:
            print('file deletion failed')
            dbqerr = {}
            dbqerr['natstatus'] = 'error'
            dbqerr['statusdetails'] = 'File deletion failed'
            resp = make_response(jsonify(dbqerr), 400)
            return (resp)
        else:
            print('file deletion successful')

        print('file deletion successful and starting with db connection')
        con, cur = db.mydbopncon()

        #Delete the entry of the file from db START
        command = cur.mogrify(
            "DELETE FROM fileuploadmaster WHERE fuplfiles3bucket = %s AND fuplfiles3key = %s AND fuplfilecat = %s AND fupllguserid = %s AND fuplentityid = %s",
            (
                objbucket,
                objkey,
                category,
                userid,
                entityid,
            ))
        print(command)
        cur, dbqerr = db.mydbfunc(con, cur, 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'] = "Fileupload master delete failed"
                resp = make_response(jsonify(dbqerr), 400)
                return (resp)
        con.commit()
        print(cur)
        print('consider delete is successful')

        #Delete the entry of the file from db END

        respjsonstr = fetchfilelist(userid, entityid, con, cur, s3)

        db.mydbcloseall(con, cur)
    return make_response(jsonify(respjsonstr), 200)
Ejemplo n.º 5
0
def bankdets():
    #This is called by setjws service
    if request.method == 'OPTIONS':
        print("inside bankdets options")
        return 'ok'

    elif request.method == 'POST':
        print("inside bankdetails POST")
        payload = request.get_json()
        print(payload)
        reqdataifsc = payload['ifsc']
        print(reqdataifsc)
        print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

        con, cur = db.mydbopncon()

        command = cur.mogrify("select * from bankifscmaster where ifsc = %s;",
                              (reqdataifsc, ))
        cur, dbqerr = db.mydbfunc(con, cur, 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'] = "IFSC Fetch failed"
            resp = make_response(jsonify(dbqerr), 400)
            return (resp)
        else:
            pass

        records = []
        for record in cur:
            print('inside for')
            print(record)
            records.append(record)

        print(len(records))

        #if len(records) == 0:
        if cur.rowcount == 0:
            bank, ifsc, micr, branch, address, contact, city, district, state, entity = [
                ''
            ] * 10
            failed = True
            errormsg = 'Not a valid IFSC'
        else:
            bank, ifsc, micr, branch, address, contact, city, district, state, entity = records[
                0]
            failed = False
            errormsg = ''

        bankdetailresp = bank + ' ' + address + '    ' + city + ' ' + state
        print(bankdetailresp)

        return (json.dumps({
            'bank': bank,
            'ifsc': ifsc,
            'micr': micr,
            'branch': branch,
            'address': address,
            'contact': contact,
            'city': city,
            'district': district,
            'state': state,
            'failed': failed,
            'errormsg': errormsg
        }))
Ejemplo n.º 6
0
def regisandfatcsubmit():
    #Endpoint to submit both registration and fatca details
    if request.method == 'OPTIONS':
        print("inside regisandfatcsubmit options")
        return make_response(jsonify('inside regisandfatcsubmit options'), 200)

    elif request.method == 'POST':
        #return make_response(jsonify('inside regisandfatcsubmit options'), 200)
        print("inside regisandfatcsubmit POST")

        print((request))
        userid, entityid = jwtnoverify.validatetoken(request)
        print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

        con, cur = db.mydbopncon()

        print(con)
        print(cur)

        command = cur.mogrify(
            "SELECT row_to_json(t) from(SELECT * FROM uccclientmaster A FULL OUTER JOIN fatcamaster B ON A.ucclguserid = B.fatcalguserid) as t where t.fatcalguserid = %s and t.fatcaentityid = %s AND t.ucclguserid = %s AND t.uccentityid = %s;",
            (
                userid,
                entityid,
                userid,
                entityid,
            ))
        print(command)
        cur, dbqerr = db.mydbfunc(con, cur, 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'] = "loginuser Fetch failed"
            resp = make_response(jsonify(dbqerr), 400)
            return (resp)
        else:
            pass

        records = []
        for record in cur:
            print('inside for')
            print(record)
            records.append(record)

        print(len(records))

        #if len(records) == 0:
        if (cur.rowcount) == 0:
            errorresp = {
                'natstatus': 'error',
                'statusdetails': 'User not registered/activated'
            }
            resps = make_response(jsonify(errorresp), 400)
            print(resps)
            return (resps)
        else:
            custrecord = records[0][0]

        print(custrecord)
        print(type(custrecord))

        #make all NONE to '' so JOSN serialisation will not fail
        for key, value in custrecord.items():
            custrecord[key] = '' if value is None else str(value)

        #Next step is to post this data to customer creation and wait for its make_response
        #Based on the response send response to front end
        del custrecord['fatcalguserid']
        del custrecord['fatcaoctime']
        del custrecord['fatcalmtime']
        del custrecord['fatcaentityid']
        del custrecord['ucclguserid']
        del custrecord['uccoctime']
        del custrecord['ucclmtime']
        del custrecord['uccentityid']
        del custrecord['clientnomineedob']
        del custrecord['clientnomineeaddress']

        processadd = custrecord['clientadd1'] + custrecord[
            'clientadd2'] + custrecord['clientadd3']

        custrecord['clientadd1'] = processadd[:30]
        if (len(processadd) > 30):
            custrecord['clientadd2'] = processadd[30:60]
            if (len(processadd) > 60):
                custrecord['clientadd3'] = processadd[60:90]
            else:
                custrecord['clientadd3'] = ''
        else:
            custrecord['clientadd2'] = custrecord['clientadd3'] = ''

        appname1 = custrecord['clientappname1']  #firstname
        '''
        if (custrecord['clientappname2'] != ''):							#middlename
            appname1 = appname1 + ' ' + custrecord['clientappname2']		
        if (custrecord[clientappname3] != ''):
            appname1 = appname1 + ' ' + custrecord['clientappname3']		#lastname
        '''
        custrecord['clientappname1'] = appname1[:70]

        custrecord['clientdob'] = (datetime.strptime(
            custrecord['clientdob'], '%Y-%m-%d').date()).strftime('%d/%m/%Y')
        custrecord['dob'] = (datetime.strptime(
            custrecord['clientdob'], '%d/%m/%Y').date()).strftime('%m/%d/%Y')
        #(datetime.strptime(custrecord['clientdob'], '%Y-%m-%d').date()).strftime('%d/%m/%Y')

        #All formating should be done above
        for key, value in custrecord.items():
            custrecord[key] = '' if value is None else str(value)

        #url='http://192.168.1.27:8000/custcreation'
        url = settings.BSESTAR_USERCREATION_URL[settings.LIVE]
        print(url)
        print(custrecord)

        r = requests.post(url, json=custrecord)
        print(r.text)
        rj = json.loads(r.text)
        print('rj :', rj)
        if r.status_code != 200:
            resp = make_response(
                jsonify({
                    'natstatus': 'error',
                    'statusdetails': rj['statusmessage']
                }), 400)
        else:
            #Update userstatus to U to indicate completion of registration and pending document upload
            command = cur.mogrify(
                "UPDATE userlogin SET lguserstatus = 'U', lglmtime = CURRENT_TIMESTAMP WHERE lguserid = %s AND lgentityid = %s;",
                (
                    userid,
                    entityid,
                ))
            print(command)
            cur, dbqerr = db.mydbfunc(con, cur, command)
            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)
            con.commit()
            #print(cur)
            print('consider insert or update is successful')

            #INSERT NOTIFICATION ENTRY FOR PENDING REGISTRAION DOC UPLOAD START
            nfmid = datetime.now().strftime('%Y%m%d%H%M%S%f')
            print('nfmid :', nfmid)
            command = cur.mogrify(
                "INSERT INTO notifimaster (nfmid,nfname,nfmuserid,nfmscreenid,nfmessage,nfmsgtype,nfmprocessscope,nfmnxtact,nfmnxtactmsg,nfmnxtactnavtyp,nfmnxtactnavdest,nfmstartdt,nfmoctime,nfmlmtime,nfmentityid) VALUES (%s,'pendingregisupload',%s,'dashboard','<div fxLayout=#column# fxLayoutWrap><div><p> Account Open Form (AOF) is sent to your email. Please upload the form to complete registration </p><p>Go to Setting > Docupload </div><div>','notifaction','P','Y','','NONE','NONE',CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP,%s) ON CONFLICT DO NOTHING;",
                (
                    nfmid,
                    userid,
                    entityid,
                ))
            print(command)
            cur, dbqerr = db.mydbfunc(con, cur, command)
            print(dbqerr['natstatus'])
            if cur.closed == True:
                if (dbqerr['natstatus'] == "error"
                        or dbqerr['natstatus'] == "warning"):
                    dbqerr['statusdetails'] = "SIGNUP update failed"
                resp = make_response(jsonify(dbqerr), 400)
                return (resp)
            con.commit()
            print(cur)
            print('consider insert or update is successful')

            #INSERT NOTIFICATION ENTRY FOR PENDING REGISTRAION DOC UPLOAD END

            #Now send resonse back to client confirming registration success.  Nav to registration success screen
            resp = make_response(
                jsonify({
                    'natstatus': 'success',
                    'statusdetails': 'client registration successful'
                }), 200)

        db.mydbcloseall(con, cur)
        #return the resp as set above
        return resp
Ejemplo n.º 7
0
def dtlfrmsave():
    #This is called when save for later button is clicked
    if request.method == 'OPTIONS':
        print("inside DETAIL FORM SAVE options")
        return make_response(jsonify('inside DETAIL FORM SAVE options'), 200)

    elif request.method == 'POST':
        print("inside DETAIL FORM SAVE post")

        regisdbdata = {}
        fatcadbdata = {}

        print((request))
        userid, entityid = jwtnoverify.validatetoken(request)
        print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        data = request.get_json()
        print(data)

        regisdbdata['clientappname1'] = data['clientname']
        regisdbdata['clientpan'] = data['clientpan']
        regisdbdata['clientcode'] = data['clientcode']
        regisdbdata['clientgender'] = data['clientgender']

        print('date', data['clientdob'])

        #regisdbdata['clientdob'] = data['clientdob']
        #data['clientdob'] = None

        if data['clientdob'] == 'None':
            regisdbdata['clientdob'] = '01/01/1800'
            fatcadbdata['dob'] = '01/01/1800'
            print('correctly inside elif  none string')
        elif data['clientdob'] == None:
            regisdbdata['clientdob'] = '01/01/1800'
            fatcadbdata['dob'] = '01/01/1800'
            print('correctly inside elif  none')
        elif data['clientdob']:
            regisdbdata['clientdob'] = data['clientdob']
            fatcadbdata['dob'] = data['clientdob']
        else:
            regisdbdata['clientdob'] = '01/01/1800'
            fatcadbdata['dob'] = '01/01/1800'
            print('correctly inside else')

        #regisdbdata['clientdob'] = (item or NULL if data['clientdob'])
        regisdbdata['clientemail'] = data['clientemail']
        regisdbdata['cm_mobile'] = data['clientmobile']
        regisdbdata['clientcommmode'] = 'M'  #M- Mail
        regisdbdata[
            'clientholding'] = 'SI'  #SI - Single, JO - Joint, AS - Anyone or Survivor

        if data['clientpepflg']:
            fatcadbdata['pep_flag'] = 'Y'
        else:
            fatcadbdata['pep_flag'] = 'N'

        regisdbdata['clienttype'] = 'P'  #P- Physical, D-Demat

        regisdbdata['clientadd1'] = data['clientaddress1']
        regisdbdata['clientadd2'] = data['clientaddress2']
        regisdbdata['clientadd3'] = data['clientaddress3']
        regisdbdata['clientcity'] = data['clientcity']
        #regisdbdata['clientstate'] = data['clientstate']

        regisdbdata['clientstate'] = getcountryorstate(data['clientstate'],
                                                       'uccstcode')
        #fatstcode[statesname.index(data['clientstate'])]

        regisdbdata['clientpincode'] = data['clientpincode']

        regisdbdata['clientcountry'] = data['clientcountry']
        #regisdbdata['clientcountry'] = getcountryorstate(data['clientcountry'],'ucccncode')
        #ucccncode[forcntry.index(data['clientcountry'])]

        regisdbdata['cm_foradd1'] = data['clientforinadd1']
        regisdbdata['cm_foradd2'] = data['clientforinadd2']
        regisdbdata['cm_foradd3'] = data['clientforinadd3']
        regisdbdata['cm_forcity'] = data['clientforcity']
        regisdbdata['cm_forstate'] = data['clientforstate']

        #regisdbdata['cm_forcountry'] = data['clientforcountry']
        regisdbdata['cm_forcountry'] = getcountryorstate(
            data['clientforcountry'], 'ucccncode')
        #ucccncode[forcntry.index(data['clientforcountry'])]

        regisdbdata['cm_forpincode'] = data['clientforpin']
        regisdbdata['clientacctype1'] = data['clientactype']
        regisdbdata['clientaccno1'] = data['clientacnumb']
        regisdbdata['clientmicrno1'] = data['clientmicrno']
        regisdbdata['clientifsccode1'] = data['clientifsc']
        regisdbdata['defaultbankflag1'] = 'Y'

        if data['clientisnri']:
            regisdbdata['clienttaxstatus'] = data['clienttaxstatusnri']
            fatcadbdata['tax_status'] = data['clienttaxstatusnri']
        else:
            regisdbdata['clienttaxstatus'] = '01'
            fatcadbdata['tax_status'] = '01'

        regisdbdata['clientoccupationcode'] = data['clientocupation']
        fatcadbdata['occ_code'] = data['clientocupation']

        if data['clientocupation'] in ['01', '43']:
            fatcadbdata['occ_type'] = 'B'
        elif data['clientocupation'] in [
                '02', '03', '04', '09', '41', '42', '44'
        ]:
            fatcadbdata['occ_type'] = 'S'
        elif data['clientocupation'] in ['05', '06', '07', '08', '99']:
            fatcadbdata['occ_type'] = 'O'
        else:
            fatcadbdata['occ_type'] = ''

        if data['clienthasnominee']:
            regisdbdata['clientnominee'] = data['clientnomineename']
            regisdbdata['clientnomineerelation'] = data['clientnomineerel']
            regisdbdata['clientnomineeaddress'] = data['clientnomineeaddres']

        else:
            regisdbdata['clientnominee'] = ''
            regisdbdata['clientnomineerelation'] = ''
            regisdbdata['clientnomineeaddress'] = ''

        if data['clientnomineedob']:
            regisdbdata['clientnomineedob'] = data['clientnomineedob']
        else:
            regisdbdata['clientnomineedob'] = '01-01-1800'

        fatcadbdata['srce_wealt'] = data['clientsrcwealth']
        fatcadbdata['inc_slab'] = data['clientincslb']
        print('########################')
        print(data['clientpobir'])
        print(data['clientcobir'])
        print('########################')
        fatcadbdata['po_bir_inc'] = data['clientpobir']
        fatcadbdata['co_bir_inc'] = data['clientcobir']
        #fatcadbdata['tax_res1'] = data['clienttaxrescntry1']
        fatcadbdata['tax_res1'] = getcountryorstate(data['clienttaxrescntry1'],
                                                    'fatcncode')
        #ucccncode[forcntry.index(data['clienttaxrescntry1'])]
        fatcadbdata['tpin1'] = data['clienttaxid1']
        fatcadbdata['id1_type'] = data['clienttaxidtype1']
        #fatcadbdata['tax_res2'] = data['clienttaxrescntry2']
        fatcadbdata['tax_res2'] = getcountryorstate(data['clienttaxrescntry2'],
                                                    'fatcncode')
        #ucccncode[forcntry.index(data['clienttaxrescntry2'])]
        fatcadbdata['tpin2'] = data['clienttaxid2']
        fatcadbdata['id2_type'] = data['clienttaxidtype2']
        #fatcadbdata['tax_res3'] =  data['clienttaxrescntry3']
        fatcadbdata['tax_res3'] = getcountryorstate(data['clienttaxrescntry3'],
                                                    'fatcncode')
        #ucccncode[forcntry.index(data['clienttaxrescntry3'])]
        fatcadbdata['tpin3'] = data['clienttaxid3']
        fatcadbdata['id3_type'] = data['clienttaxidtype3']
        #fatcadbdata['tax_res4'] =  data['clienttaxrescntry4']
        fatcadbdata['tax_res4'] = getcountryorstate(data['clienttaxrescntry4'],
                                                    'fatcncode')
        #ucccncode[forcntry.index(data['clienttaxrescntry4'])]
        fatcadbdata['tpin4'] = data['clienttaxid4']
        fatcadbdata['id4_type'] = data['clienttaxidtype4']

        regisdbdata[
            'clientdivpaymode'] = '02'  #01-Cheque, 02-Direct Credit, 03-ECS, 04-NEFT, 05-RTGS
        regisdbdata['ucclmtime'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')

        fatcadbdata[
            'addr_type'] = '1'  #1 - Residential or Business;2 - Residential; 3 - Business;4 - Registered Office; 5 -Unspecified
        fatcadbdata['data_src'] = 'E'  #E - Electronic   P - Physical
        fatcadbdata['ubo_appl'] = 'N'
        fatcadbdata['sdf_flag'] = 'N'
        fatcadbdata['ubo_df'] = 'N'
        fatcadbdata['exch_name'] = 'O'  #B - BSE, N - NSE, O - Others
        fatcadbdata['new_change'] = 'N'  #N-New

        #Logname to be set from the lamda
        fatcadbdata['log_name'] = 'logname.log'
        #Logname to be set from the lamda

        fatcadbdata['fatcalmtime'] = datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')

        regiskeys = ",".join(regisdbdata.keys())
        regisvals = "','".join(item or '' for item in regisdbdata.values())
        regisvals = "'" + regisvals + "'"
        fatcakeys = ",".join(fatcadbdata.keys())
        fatcavals = "','".join(item or '' for item in fatcadbdata.values())
        fatcavals = "'" + fatcavals + "'"

        con, cur = db.mydbopncon()

        #update UCC CLIENT MASTER table START
        comqry = 'UPDATE webapp.uccclientmaster SET (' + regiskeys + ') = (' + regisvals + ') WHERE ucclguserid = %s AND uccentityid = %s;'
        command = cur.mogrify(comqry, (
            userid,
            entityid,
        ))
        print('command :', command)

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

        if cur.closed == True:
            if (dbqerr['natstatus'] == "error"
                    or dbqerr['natstatus'] == "warning"):
                dbqerr['statusdetails'] = "User details insert Failed"
            resp = make_response(jsonify(dbqerr), 400)
            return (resp)
        #update UCC CLIENT MASTER table END

        #update FATCA CLIENT MASTER table START
        comqry = 'UPDATE fatcamaster SET (' + fatcakeys + ') = (' + fatcavals + ') WHERE fatcalguserid = %s AND fatcaentityid = %s;'
        command = cur.mogrify(comqry, (
            userid,
            entityid,
        ))
        print('command :', command)

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

        if cur.closed == True:
            if (dbqerr['natstatus'] == "error"
                    or dbqerr['natstatus'] == "warning"):
                dbqerr['statusdetails'] = "FATCA details insert Failed"
            resp = make_response(jsonify(dbqerr), 400)
            return (resp)
        #update FATCA CLIENT MASTER table END

        con.commit()
        db.mydbcloseall(con, cur)
        print('commit successful')
        return make_response(
            jsonify({
                'natstatus': 'success',
                'statusdetails': 'Data saved'
            }), 200)
Ejemplo n.º 8
0
def registdetfetch():
    #This is called by setjws service
    if request.method == 'OPTIONS':
        print("inside REGISTRATIONDETAILSFETCH options")
        return make_response(
            jsonify('inside REGISTRATIONDETAILSFETCH options'), 200)

    elif request.method == 'GET':
        print("inside REGISTRATIONDETAILSFETCH GET")

        print((request))
        userid, entityid = jwtnoverify.validatetoken(request)
        print(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
        '''
        try:
            con
        except NameError:
            print("con not defined so assigning as null")
            conn_string = "host='localhost' dbname='postgres' user='******' password='******'"
            con=psycopg2.connect(conn_string)
            cur = con.cursor(cursor_factory=psycopg2.extras.DictCursor)
        else:            
            if con.closed:
                conn_string = "host='localhost' dbname='postgres' user='******' password='******'"
                con=psycopg2.connect(conn_string)
                cur = con.cursor(cursor_factory=psycopg2.extras.DictCursor)
        '''

        #need to think on a way to get entity id for this

        #Select registration details for the userid and entity id derived from JWT START

        con, cur = db.mydbopncon()

        print(con)
        print(cur)

        command = cur.mogrify(
            "SELECT clientcode, clientholding, clienttaxstatus, clientoccupationcode,clientappname1,(CASE WHEN clientdob < '01-01-1801' THEN NULL ELSE clientdob END) AS clientdob, clientgender , clientpan, clientnominee, clientnomineerelation, (CASE WHEN clientnomineedob < '01-01-1801' THEN NULL ELSE clientnomineedob END) AS clientnomineedob, clientnomineeaddress, clienttype, clientacctype1, clientaccno1, clientmicrno1, clientifsccode1, defaultbankflag1, clientadd1, clientadd2, clientadd3, clientcity, clientstate, clientpincode, clientcountry, clientemail, clientcommmode, clientdivpaymode, cm_foradd1, cm_foradd2, cm_foradd3, cm_forcity, cm_forpincode , cm_forstate, cm_forcountry, cm_mobile FROM uccclientmaster WHERE ucclguserid = %s AND uccentityid = %s;",
            (
                userid,
                entityid,
            ))
        print(command)
        cur, dbqerr = db.mydbfunc(con, cur, 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'] = "loginuser Fetch failed"
            resp = make_response(jsonify(dbqerr), 400)
            return (resp)
        else:
            pass

        if (cur.rowcount) != 1:
            errorresp = {
                'natstatus':
                'error',
                'statusdetails':
                'ZERO or MORE THAN ONE registration record for user'
            }
            resps = make_response(jsonify(errorresp), 400)
            print(resps)
            return (resps)
        else:
            rec = cur.fetchone()
            #createdetailfrm
            clientname = rec['clientappname1']
            clientpan = rec['clientpan']
            clientcode = rec['clientcode']
            clientgender = rec['clientgender']
            clientdob = rec['clientdob']
            clientemail = rec['clientemail']
            clientmobile = rec['cm_mobile']
            clientcommode = rec['clientcommmode']
            clientholding = rec['clientholding']
            #clientpepflg='' this is set in fatca

            #CLIENT TAX STATUS: 1-individual, 21-NRE, 24-NRO
            if rec['clienttaxstatus'] == '21' or rec['clienttaxstatus'] == '24':
                clientisnri = True
                clienttaxstatusres = False
                clienttaxstatusnri = rec['clienttaxstatus']
            else:
                clientisnri = False
                clienttaxstatusres = True
                clienttaxstatusnri = ''

            clientocupation = rec['clientoccupationcode']

            if clientocupation in ['01', '43']:
                clientocutyp = 'B'
            elif clientocupation in ['02', '03', '04', '09', '41', '42', '44']:
                clientocutyp = 'S'
            elif clientocupation in ['05', '06', '07', '08', '99']:
                clientocutyp = 'O'
            else:
                clientocutyp = ''

            clientnomineename = rec['clientnominee']
            if clientnomineename:
                clienthasnominee = True
                clientnomineerel = rec['clientnomineerelation']
                clientnomineedob = rec['clientnomineedob']
                clientnomineeaddres = rec['clientnomineeaddress']
            else:
                clienthasnominee = False
                clientnomineerel = ''
                clientnomineedob = ''
                clientnomineeaddres = ''

            clientfndhldtype = rec['clienttype']  #Defaulted to PHYS
            #createclientaddfrm
            clientaddress1 = rec['clientadd1']
            clientaddress2 = rec['clientadd2']
            clientaddress3 = rec['clientadd3']
            clientcity = rec['clientcity']

            clientstate = getcountryorstate(rec['clientstate'], 'uccstname')

            clientpincode = rec['clientpincode']
            print('pincode to send :', rec['clientpincode'])
            clientcountry = rec['clientcountry']
            #clientcountry = getcountryorstate(rec['clientcountry'],'ucccnname')

            if clientisnri:
                clientforinadd1 = rec['cm_foradd1']
                clientforinadd2 = rec['cm_foradd2']
                clientforinadd3 = rec['cm_foradd3']
                clientforcity = rec['cm_forcity']
                clientforstate = rec['cm_forstate']
                #clientforcountry =  rec['cm_forcountry']

                clientforcountry = getcountryorstate(rec['cm_forcountry'],
                                                     'ucccnname')
                #forcntry[ucccncode.index(rec['cm_forcountry'])]
                clientforpin = rec['cm_forpincode']
            else:
                clientforinadd1 = ''
                clientforinadd2 = ''
                clientforinadd3 = ''
                clientforcity = ''
                clientforstate = ''
                clientforcountry = ''
                clientforpin = ''

            #createclientbankfrm
            clientactype = rec['clientacctype1']
            clientacnumb = rec['clientaccno1']
            clientmicrno = rec['clientmicrno1']
            clientifsc = rec['clientifsccode1']

        command = cur.mogrify(
            "SELECT pan_rp,inv_name,tax_status,po_bir_inc,co_bir_inc,tax_res1,tpin1,id1_type,tax_res2,tpin2,id2_type,tax_res3,tpin3,id3_type,tax_res4,tpin4,id4_type,srce_wealt,inc_slab,pep_flag,occ_code,occ_type FROM fatcamaster WHERE fatcalguserid = %s AND fatcaentityid = %s;",
            (
                userid,
                entityid,
            ))
        print(command)
        cur, dbqerr = db.mydbfunc(con, cur, 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'] = "loginuser Fetch failed"
            resp = make_response(jsonify(dbqerr), 400)
            return (resp)
        else:
            pass

        if (cur.rowcount) != 1:
            errorresp = {
                'natstatus': 'error',
                'statusdetails': 'ZERO or MORE THAN ONE Fatca record for user'
            }
            resps = make_response(jsonify(errorresp), 400)
            print(resps)
            return (resps)
        else:
            rec = cur.fetchone()
            #createclientfatcafrm
            clientsrcwealth = rec['srce_wealt']
            clientincslb = rec['inc_slab']
            clientpobir = rec['po_bir_inc']
            clientcobir = rec['co_bir_inc']
            #clienttaxrescntry1 = rec['tax_res1']
            clienttaxrescntry1 = getcountryorstate(rec['tax_res1'],
                                                   'fatcnname')
            #forcntry[ucccncode.index(rec['tax_res1'])]
            clienttaxid1 = rec['tpin1']
            clienttaxidtype1 = rec['id1_type']
            #clienttaxrescntry2 = rec['tax_res2']
            clienttaxrescntry2 = getcountryorstate(rec['tax_res2'],
                                                   'fatcnname')
            #forcntry[ucccncode.index(rec['tax_res2'])]
            clienttaxid2 = rec['tpin2']
            clienttaxidtype2 = rec['id2_type']
            #clienttaxrescntry3 = rec['tax_res3']
            clienttaxrescntry3 = getcountryorstate(rec['tax_res3'],
                                                   'fatcnname')
            #forcntry[ucccncode.index(rec['tax_res3'])]
            clienttaxid3 = rec['tpin3']
            clienttaxidtype3 = rec['id3_type']
            #clienttaxrescntry4 = rec['tax_res4']
            clienttaxrescntry4 = getcountryorstate(rec['tax_res4'],
                                                   'fatcnname')
            #forcntry[ucccncode.index(rec['tax_res4'])]
            clienttaxid4 = rec['tpin4']
            clienttaxidtype4 = rec['id4_type']
            clientpepflg = rec['pep_flag']

        #Select registration details for the userid and entity id derived from JWT END
        db.mydbcloseall(con, cur)
        return (json.dumps({
            'clientname': clientname,
            'clientpan': clientpan,
            'clientcode': clientcode,
            'clientgender': clientgender,
            'clientdob': str(clientdob),
            'clientemail': clientemail,
            'clientmobile': clientmobile,
            'clientcommode': clientcommode,
            'clientholding': clientholding,
            'clientpepflg': clientpepflg,
            'clientisnri': clientisnri,
            'clienttaxstatusres': clienttaxstatusres,
            'clienttaxstatusnri': clienttaxstatusnri,
            'clientocupation': clientocupation,
            'clientocutyp': clientocutyp,
            'clientnomineename': clientnomineename,
            'clienthasnominee': clienthasnominee,
            'clientnomineerel': clientnomineerel,
            'clientnomineedob': str(clientnomineedob),
            'clientnomineeaddres': clientnomineeaddres,
            'clientfndhldtype': clientfndhldtype,
            'clientaddress1': clientaddress1,
            'clientaddress2': clientaddress2,
            'clientaddress3': clientaddress3,
            'clientcity': clientcity,
            'clientstate': clientstate,
            'clientcountry': clientcountry,
            'clientpincode': clientpincode,
            'clientforinadd1': clientforinadd1,
            'clientforinadd2': clientforinadd2,
            'clientforinadd3': clientforinadd3,
            'clientforcity': clientforcity,
            'clientforstate': clientforstate,
            'clientforcountry': clientforcountry,
            'clientforpin': clientforpin,
            'clientactype': clientactype,
            'clientacnumb': clientacnumb,
            'clientmicrno': clientmicrno,
            'clientifsc': clientifsc,
            'clientsrcwealth': clientsrcwealth,
            'clientincslb': clientincslb,
            'clientpobir': clientpobir,
            'clientcobir': clientcobir,
            'clienttaxrescntry1': clienttaxrescntry1,
            'clienttaxid1': clienttaxid1,
            'clienttaxidtype1': clienttaxidtype1,
            'clienttaxrescntry2': clienttaxrescntry2,
            'clienttaxid2': clienttaxid2,
            'clienttaxidtype2': clienttaxidtype2,
            'clienttaxrescntry3': clienttaxrescntry3,
            'clienttaxid3': clienttaxid3,
            'clienttaxidtype3': clienttaxidtype3,
            'clienttaxrescntry4': clienttaxrescntry4,
            'clienttaxid4': clienttaxid4,
            'clienttaxidtype4': clienttaxidtype4,
            'clientpepflg': clientpepflg
        }))