def index(request): if request.method == 'GET': try: type='' user_name='anhphongkiem' debt_owner=User.objects.get(username=user_name) lsCusomer=Customer.objects(debt_owner=debt_owner.id) lsCusDebit = CusDebit.objects(status=1).order_by('-create_date,loan_date') lsCusDebitDetail =CusDebitDetail.objects(status=1).order_by('-create_date,cus_debit_id') if 'type' in request.GET: if request.GET['type']=='chovay': type = 'chovay' elif request.GET['type']=='trano': type = 'trano' except Exception as ex: print(ex) finally: context = {'type':type,'lsCusomer':lsCusomer,'lsCusDebit':lsCusDebit,'lsCusDebitDetail':lsCusDebitDetail} return render(request,'myapp/d-CustomerDebitDetail.html', context) elif request.method == 'POST': if request.POST['type'] == "cusLoan": try: # cus_id = request.POST['hd_cus_id'] # cusDebit_debit =float(request.POST['hd_cus_amount']) # cusDebit_loan_date=datetime.strptime(request.POST['cus_loan_date'],'%m/%d/%Y') # cusDebit_rate = float(request.POST['hd_cus_rate']) # cusDebit_cycle = float(request.POST['cus_cycle']) # cus=Customer.objects.get(id=cus_id) # # loan_type = LoanType.objects.get(code='LN',unit='D') # # createcusdebit(cus,cusDebit_loan_date,cusDebit_debit,cusDebit_rate,cusDebit_cycle,loan_type) close_cycle_all() print('add cusdebit ') type = "chovay" user_name='anhphongkiem' debt_owner=User.objects.get(username=user_name) lsCusomer=Customer.objects(debt_owner=debt_owner.id) lsCusDebit = CusDebit.objects(status=1).order_by('loan_date') lsCusDebitDetail =CusDebitDetail.objects(status=1).order_by('cus_debit_id') except Exception as ex: print(ex) finally: context = {'type':type,'lsCusomer':lsCusomer,'lsCusDebit':lsCusDebit,'lsCusDebitDetail':lsCusDebitDetail} return render(request,'myapp/d-CustomerDebitDetail.html', context)
def index(request): debt_owner1= User.objects.get(username=str(request.user)) firstname = "" lastname = "" idNo = "" Address = "" HomeAddress = "" PhoneNumber = "" About = "" if request.method == 'GET': context={} return render(request, 'myapp/d-NewCus.html', context) elif request.method == 'POST': firstname = request.POST['txtFirstName'] lastname = request.POST['txtLastName'] idNo = request.POST['txtidNo'] Address = request.POST['txtAddress'] HomeAddress = request.POST['txtHomeAddress'] PhoneNumber = request.POST['txtPhoneNumber'] About = request.POST['txaAbout'] type = request.POST['typeSave'] try: #user = User() #user.username = firstname + lastname #user.first_name = firstname #user.last_name = lastname #user.set_password(idNo); #user.save() _customer = Customer() _customer.id_no = idNo _customer.first_name = firstname _customer.last_name = lastname _customer.full_name = firstname +' '+ lastname _customer.cus_code = lastname _customer.address = Address _customer.home_address = HomeAddress _customer.fone_number = PhoneNumber _customer.about = About _customer.status = 1 _customer.debt_owner = debt_owner1 if len(Customer.objects(debt_owner=debt_owner1,id_no=idNo,full_name=_customer.full_name))> 0: return getNewCusError(request,'Đã tồn tại thông tin khách hàng tương tư trong hệ thống',firstname,lastname,idNo,Address,HomeAddress,PhoneNumber,About) else: _customer.save() #user.backend = 'mongoengine.django.auth.MongoEngineBackend' except e: print(e) if type == "normalsave": return HttpResponseRedirect('/newcustomer') elif type == "saveandredirect": return HttpResponseRedirect('/custom-debit-detail?type=loan')
def index(request): debt_owner1= User.objects.get(username=str(request.user)) if request.method == 'GET': lsCusomer = getlistCustomerbyDebtOwner(debt_owner1) context={'lsCusomer':lsCusomer} return render(request, 'myapp/editCus.html', context) elif request.method == 'POST': firstname = request.POST['txtFirstName'] lastname = request.POST['txtLastName'] idNo = request.POST['txtidNo'] Address = request.POST['txtAddress'] HomeAddress = request.POST['txtHomeAddress'] PhoneNumber = request.POST['txtPhoneNumber'] About = request.POST['txaAbout'] type = request.POST['typeSave'] cusID = request.POST['cusID'] try: #user = User() #user.username = firstname + lastname #user.first_name = firstname #user.last_name = lastname #user.set_password(idNo); #user.save() cus = Customer.objects(id=cusID)[:1] _customer=cus[0] _customer.id_no = idNo _customer.first_name = firstname _customer.last_name = lastname _customer.full_name = firstname +' '+ lastname _customer.cus_code = lastname _customer.address = Address _customer.home_address = HomeAddress _customer.fone_number = PhoneNumber _customer.about = About _customer.status = 1 _customer.debt_owner = debt_owner1 _customer.save() #user.backend = 'mongoengine.django.auth.MongoEngineBackend' except Exception: print(Exception) if type == "normalsave": return HttpResponseRedirect('/editCus') elif type == "saveandredirect": return HttpResponseRedirect('/custom-debit-detail?type=loan')
def index(request): try: user=User.objects.get(username=str(request.user)) listcus = Customer.objects(debt_owner=user) cusdebitafterfilter = CusDebit.objects.filter(cus_id__in=listcus) for a in cusdebitafterfilter: print(a.cus_id.cus_id) except Exception as e: print(e) context={} return render(request, 'myapp/d-mainScreen.html', context)
def make_payment(vCus_id,vAmount,vPay_date): try: vtoday = datetime.now().strftime("%y-%m-%d-%H-%M-%S") #vuser = User.objects.get(id=vCus_id) vCustomer = Customer.objects(cus_id = vCus_id) lscd = CusDebit.objects(cus_id = vCus_id,status=1).order_by('loan_date') #Insert data in to Payment #------------------------------------------------------------------------- pt = Payment.objects() pt.cus_id = vCustomer pt.create_date= vtoday pt.pay_date= vPay_date pt.amount = vAmount pt.status = 1 #------------------------------------------------------------------------- for cd in lscd: analyze_payment(vCus_id,cd.id,vAmount,pt.id) except Exception as ex: print(ex)
def index(request): debt_owner1= User.objects.get(username=str(request.user)) cus = Customer.objects(debt_owner = debt_owner1) numCus = len(cus) lscusdebt = getCusDebitofadebtowner(debt_owner1) numdebt = len(lscusdebt) data = [] datenow = datetime.date.today() for i in 5: date1month = datenow + relativedelta(months=1) inmonth = CusDebit.objects(create_date__lt=datenow,create_date__gt=date1month) data.append(len(inmonth)) datenow = datenow + relativedelta(months=1) print(str(len(inmonth))) context={ "numCus":numCus, "numdebt":numdebt } return render(request, 'myapp/d-mainScreen.html', context)
def getCustomerInfo(ownner): customer = Customer.objects(debt_owner = ownner) return customer