Beispiel #1
0
def dispatchLoan():
    db = create_connection()
    try:

        while True:
            """
			-.get loan request list.
			"""
            items = json.loads(_read_loan_payout_queue_sys(db))
            """
			-.loop through each in the list
			"""
            for item in items:
                """
				-.calc loan handling fees.
				"""
                handle_fee = int(item['amount']) * float(
                    loan_params['loan_fee'])
                """
				-.calc amount loaned.
				"""
                loan_amount = int(item['amount']) - float(handle_fee)
                """
				-.calc interest amount.
				"""
                interest_amount = (float(loan_params['interest']) *
                                   int(item['amount']))
                """
				-.calc repayment amount = (principle+interest).
				"""
                repayment_amount = (int(item['amount']) + interest_amount)
                """
				-.log trx affecting utility a/c.
				"""
                _record_loan_transaction_sys(
                    str(item['amount']), item['msisdn'], item['reference_no'],
                    str(eval(accounting_params['accounts'])[1]),
                    str(accounting_params['debit']), db)
                """
				-.log loan fee.
				"""
                _record_loan_fee_sys(
                    item['msisdn'], item['reference_no'], str(handle_fee),
                    str(eval(accounting_params['accounts'])[3]), db)
                """
				-.update wallet bal & log the transaction.
				"""
                _dispatch_loan_sys(item['reference_no'], item['msisdn'],
                                   str(item['amount']), str(loan_amount),
                                   str(repayment_amount), str(interest_amount),
                                   loan_params['duration'],
                                   loan_params['notify_1'], db)

    except MySQLdb.Error, e:
        log.error(e)
Beispiel #2
0
def userAuthentication():
	db = create_connection()
	try:
		resp = 'Ok'
		if(request.method == 'GET'):
			return {"ERROR":"1","RESULT":"FAIL","MESSAGE":"GET method not allowed"}		
		elif(request.method == 'POST'):
			req_data = request.get_json()
			#resp = _loan_approval_api(req_data,db) 
		return jsonify({"ERROR":"0","RESULT":"SUCCESS","MESSAGE":"Authentication successful."})		
	except MySQLdb.Error, e:
		log.error(e)
Beispiel #3
0
def loanApprovalOperation():
	db = create_connection()
	try:
		resp = 'Ok'
		if(request.method == 'GET'):
			return {"ERROR":"1","RESULT":"FAIL","MESSAGE":"GET method not allowed"}		
		elif(request.method == 'POST'):
			req_data = request.get_json()
			resp = _loan_approval_api(req_data,db) 
		return jsonify({"ERROR","0","DATA",resp})		
	except MySQLdb.Error, e:
		log.error(e)
Beispiel #4
0
def getStatement():
	db = create_connection()
	try:
		resp = 'Ok'
		if(request.method == 'POST'):
			return '{"ERROR":"1", "RESULT": "FAIL", "MESSAGE": "POST method not allowed"}'
		elif(request.method == 'GET'):
			msisdn  = request.args.get('msisdn')
			
			resp = _get_statement_api(msisdn,db)
			
		return str(resp)
	except MySQLdb.Error, e:
		log.error(e)
Beispiel #5
0
def getAccountSummary():
	db = create_connection()
	try:
		resp = 'Ok'
		if(request.method == 'POST'):
			return '{"ERROR":"1", "RESULT": "FAIL", "MESSAGE": "POST method not allowed"}'
		elif(request.method == 'GET'):
			max    = request.args.get('max')
			min    = request.args.get('min')
			
			resp = _get_account_summary_api(min,max,db)
					
		return str(resp)
	except MySQLdb.Error, e:
		log.error(e)
Beispiel #6
0
def freknurRegistration():
	db = create_connection()
	try:
		resp = 'Ok'
		if(request.method == 'GET'):
			return '{"ERROR":"1", "RESULT": "FAIL", "MESSAGE": "POST method not allowed"}'
		elif(request.method == 'POST'):	
			if(request.data):
				content = json.loads(request.data)
				resp = _registration_api(content,db)
			else:
				resp = {"ERROR":"1","RESULT":"FAIL" ,"MESSAGE":"No data posted"}
			
		return str(resp)
	except MySQLdb.Error, e:
		log.error(e)
Beispiel #7
0
def getDefaulterList():
	db = create_connection()
	try:
		resp = 'Ok'
		if(request.method == 'POST'):
			return '{"ERROR":"1", "RESULT": "FAIL", "MESSAGE": "POST method not allowed"}'
		elif(request.method == 'GET'):
			search = request.args.get('search')
			max    = request.args.get('max')
			min    = request.args.get('min')
			
			resp = _get_defaulter_list_api(search,min,max,db)
					
		return str(resp)
	except MySQLdb.Error, e:
		log.error(e)
Beispiel #8
0
def getAccountsLog():
	db = create_connection()
	try:
		resp = 'Ok'
		if(request.method == 'POST'):
			return '{"ERROR":"1", "RESULT": "FAIL", "MESSAGE": "POST method not allowed"}'
		elif(request.method == 'GET'):
			code = request.args.get('account_code')
			max  = request.args.get('max')
			min  = request.args.get('min')
			search = request.args.get('search')
			
			resp = _get_accounts_log_api(code,search,min,max,db)
					
		return str(resp)
	except MySQLdb.Error, e:
		log.error(e)
Beispiel #9
0
def importCsvContent():
    db = create_connection()
    target = str(path_param['src_dir'] + path_param['csvfile'])
    try:
        while True:
            #if(myfile.is_file)
            if (os.path.isfile(target)):
                with open(target, 'rb') as f:
                    csv_data = csv.reader(f)
                    for row in csv_data:
                        #-.routine call.
                        _import_msisdn_sys(row, db)
                f.close()
                #r-.routine call.
                _archive_csv_file()
    except MySQLdb.Error, e:
        log.error(e)
Beispiel #10
0
def cashoutOperation():
	db = create_connection()
	try:
        try:
			resp = 'Ok'
			if(request.method == 'GET'):
				return {"ERROR":"1","RESULT":"FAIL","MESSAGE":"GET method not allowed"}
			elif(request.method == 'POST'):
				if(request.data):
					content = json.loads(request.data)
					resp = _mpesa_receipt_api(content,db)
					if(resp is None):
						resp = {"ERROR":"1","RESULT":"FAIL","MESSAGE":"A/C does not exist."}
				else:
					return {"ERROR":"1","RESULT":"FAIL","MESSAGE":"MSISDN|AMOUNT must be SET."}
			return resp		
	except MySQLdb.Error, e:
		log.error(e)
	except Exception, e:
		log.error(e)
Beispiel #11
0
def handleLoanRequest():
    db = create_connection()
    try:
        while True:
            """
			-.get loan request list.
			"""
            items = json.loads(_read_loan_request_queue_sys(db))
            """
			-.loop through each in the list
			"""
            for item in items:
                """
				-.check for loan allowed.
				"""
                if (str(int(item['amount'])) < str(loan_params['min_loan'])):
                    """
					-.json output.
					"""
                    print(
                        '{"ERROR":"1","RESULT":"FAIL","MESSAGE":"Allowed minimun loan is KES."'
                        + str(loan_params['min_loan']) + '}')
                elif (str(int(item['amount'])) > str(loan_params['max_loan'])):
                    """
					-.json output.
					"""
                    print(
                        '{"ERROR":"1","RESULT":"FAIL","MESSAGE":"Allowed maximum loan is KES."'
                        + str(loan_params['max_loan']) + '}')
                else:
                    """
					-.queue loan & mark as processed.
					"""
                    _queue_loan_sys(item['reference_no'], item['msisdn'],
                                    str(item['amount']), item['approved_by'],
                                    db)

    except MySQLdb.Error, e:
        log.error(e)