def add_supplier_ajax(request): if request.method == 'POST': name = request.POST['name'] account_number = request.POST.get('account_number') bank_code = request.POST.get('bank_code') description = request.POST.get('description') # Create Recipients recipient_obj = Recipients() req = recipient_obj.create_recipient(name,account_number,bank_code,description) status = recipient_obj.get_request_status(req) if not status[0]: return HttpResponse( json.dumps({"error": "There was an error adding the supplier"}), content_type="application/json" ) else: response_data = {} response_data['status'] = 'success' response_data['success'] = 'Supplier has been successfully added!' return HttpResponse( json.dumps(response_data), content_type="application/json" ) else: return HttpResponse( json.dumps({"status":"fail","error": "A supplier can only be added from the Add Supplier page"}), content_type="application/json" )
def __init__(self): # List recipients recipient_obj = Recipients() rec_res = recipient_obj.list_recipients() # List Transfer trans_obj = Transfers() tran_res = trans_obj.list_transfers()
def fetch_suppliers_count(self): recipient_obj = Recipients() sup_res = recipient_obj.list_recipients() status = util_obj.get_request_status(sup_res) if not status[0]: return False else: return len(res.json()["data"])
def delete_supplier(request, id): # Delete Recipients recipient_obj = Recipients() req = recipient_obj.delete_recipient(id) status = recipient_obj.get_request_status(req) if not status[0]: return HttpResponse( json.dumps({"status":"success","error": "There was an error deleting the supplier!"}), content_type="application/json" ) else: return HttpResponse( json.dumps({"status":"success","success": "A supplier successfully delted!"}), content_type="application/json" )
def edit_supplier(request, id): if request.method == 'POST': email = request.POST['email'] name = request.POST['name'] # Update Recipients recipient_obj = Recipients() req = recipient_obj.update_recipient(id, name,email) status = recipient_obj.get_request_status(req) if not status[0]: messages.success(request, ("Error Updating Recipient Details!")) else: return redirect('suppliers')
def suppliers(request): #List recipients recipient_obj = Recipients() res = recipient_obj.list_recipients() status = recipient_obj.get_request_status(res) # Check if the status of the balance enquiry call is true if not status[0]: messages.success(request, ("Error Fetching Recipients!")) else: ws_date = res.json()["data"][0]["createdAt"] the_date = parse_datetime(ws_date) context = {"content": res.json()["data"],"the_date":the_date} return render(request,'suppliers.html',context)
def bulk_disbursements(request): print("I got here 1") if request.method == 'POST': amount = int(request.POST['amount']) recipient = str(request.POST['recipient']).strip() reason = request.POST['reason'] print("I got here 2") # Initiate Transfer trans_obj = Transfers() res = trans_obj.initate_transfer(amount,reason,recipient) print(res.json()["message"]) return redirect('disbursements') print("I got here 3") #List recipients recipient_obj = Recipients() res = recipient_obj.list_recipients() print("I got here 4") status = recipient_obj.get_request_status(res) # Check if the status of the balance enquiry call is true print("I got here 5") if not status[0]: messages.success(request, ("Error Fetchingy Recipient Details!")) print("I got here 6") else: supplier_dic = {} for supplier in res.json()["data"]: supplier_dic.update( {supplier["recipient_code"]:supplier["name"]} ) print("I got here 7") context = {"suppliers":supplier_dic} print("I got here 8") return render(request,'bulk_disbursements.html',context)
def single_disbursement(request): #List recipients recipient_obj = Recipients() res = recipient_obj.list_recipients() status = recipient_obj.get_request_status(res) # Check if the status of the balance enquiry call is true if not status[0]: messages.success(request, ("Error Fetchingy Recipient Details!")) else: supplier_dic = {} for supplier in res.json()["data"]: supplier_dic.update( {supplier["recipient_code"]:supplier["name"]} ) context = {"suppliers":supplier_dic} return render(request,'single_disbursement.html',context)
def index(request): ''' acc_bal = Preloader() res = acc_bal.fetch_balance() ''' context = {} # Balance Enquiry util_obj = Utils() bal_res = util_obj.balance_enquiry() status = util_obj.get_request_status(bal_res) if not status[0]: return False else: print(bal_res) balance = int((bal_res.json()["data"][0]["balance"])/100) currency = bal_res.json()["data"][0]["currency"] current_balance = "{} {:,.2f}".format(currency,balance) context["balance"] = current_balance # Fetch Suppliers count recipient_obj = Recipients() sup_res = recipient_obj.list_recipients() status_sup_res = util_obj.get_request_status(sup_res) if not status_sup_res[0]: return False else: supplier_count = len(sup_res.json()["data"]) print(supplier_count) context["number_supplier"] = supplier_count # Total No of Disbursements trans_obj = Transfers() total_res = trans_obj.list_transfers() status_total_res = util_obj.get_request_status(total_res) if not status_total_res[0]: return False else: amount = 0 lista = total_res.json()["data"] for item in lista: amount += item['amount'] print(amount) context["total_disbursements"] = "{} {:,.2f}".format("NGN",amount) # List Transfer list_trans_obj = Transfers() list_trans_res = list_trans_obj.list_transfers() #print(list_trans_res.json()["data"]) new_list = list_trans_res.json()["data"] #print(new_list) latest_five = new_list[:5] print(latest_five) status_list_trans = util_obj.get_request_status(total_res) if not status_list_trans[0]: return False else: context["latest_five"] = latest_five return render(request,'index.html',context)