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)
Exemple #2
0
def close_cycle_all():
		try:
			vtoday = datetime.strptime(str(date.today()),'%Y-%m-%d')
			lscd = CusDebit.objects(last_close_date__lt = vtoday ).order_by('loan_date')
			for cd in lscd :
				cus=Customer.objects.get(id=cd.cus_id.id)
				cus_debit_detail=CusDebitDetail.objects.get(cus_debit_id=cd.id,flag = 1)
				insert_missing_debit_detail_test(cus, cd, cus_debit_detail)
		except Exception as ex:
			print(ex)
Exemple #3
0
def getCustomerDebitInfo(owner):
	listcus =  getCustomerInfo(owner)
	allcustomerdebit = CusDebit.objects()
	cusdebitafterfilter  = []
	for	l in listcus:
		for cd in allcustomerdebit:
			if(cd.cus_id ==l.cus_id):
				cusdebitafterfilter.append(cd)
	for aaa  in cusdebitafterfilter:
		print(aaa.cus_id)
	
	
	cusdebitafterfilter = CusDebit.objects.filter(cus_id__in=listcus)
	for aaa  in cusdebitafterfilter:
		print(aaa.cus_id)
	
	
	return cusdebitafterfilter
Exemple #4
0
def createEstimatePayment(vCus_id,vPayment_date,vPayment_trailer):
	try:
		lsCDTT = CusDebitDetailTrailer.objects()
		for l in lsCDTT:
			l.delete()
			
		cus_id = vCus_id
		payment_date=vPayment_date
		payment_trailer = vPayment_trailer
				
		cus=Customer.objects.get(id=cus_id)
		lsCusDebit =CusDebit.objects(cus_id = cus.id,status = 1).order_by('loan_date')
#  		estimate payment
		for cus_debit in lsCusDebit :
			insert_missing_debit_detail_trailer(cus,cus_debit,cus_debit.loan_date,payment_date,cus_debit.debit,cus_debit.rate)
		for cus_debit_temp in lsCusDebit :
			cus_debit = cus_debit_temp
			if payment_trailer > 0:
				if payment_trailer < cus_debit.total_debit_trailer:
					cus_debit.total_debit_trailer -= payment_trailer
# 							cus_debit.payment = payment_trailer
					
					cus_debit_detail_last =CusDebitDetailTrailer.objects.get(cus_debit_id =cus_debit.id ,flag=1)
					
					cus_debit_detail_last.payment = payment_trailer
					cus_debit_detail_last.status = 0
					cus_debit_detail_last.end_cycle = cus_debit.total_debit_trailer
					cus_debit_detail_last.payment = payment_trailer
					payment_trailer = 0
					cus_debit_detail_last.save()
					cus_debit.save()
				else :
					payment_trailer -= cus_debit.total_debit_trailer
					cus_debit_detail_last =CusDebitDetailTrailer.objects.get(cus_debit_id =cus_debit.id ,flag=1)
					
					cus_debit_detail_last.status = 0
					cus_debit_detail_last.end_cycle = 0
					cus_debit_detail_last.payment = cus_debit.total_debit_trailer
					cus_debit.total_debit_trailer = 0
					cus_debit_detail_last.save()
					cus_debit.save()
	except Exception as ex:
		print("createEstimatePayment: "+ex)
Exemple #5
0
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)
Exemple #6
0
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)

	
Exemple #7
0
def createMakePayment(vCus_id,vPayment_date,vPayment,loan_type):
	
		cus=Customer.objects.get(id=vCus_id)
		lsCusDebit =CusDebit.objects(cus_id = cus.id,status = 1).order_by('loan_date')
		createEstimatePayment(vCus_id,vPayment_date,vPayment)
	
	#	create new a payment
		p = Payment()
		p.cus_id = cus
		p.pay_date = vPayment_date
		p.amount = vPayment
		p.status = 1
		p.save()
		
		for cusDebit in lsCusDebit :
					cs=cusDebit
					if cs.total_debit_trailer > 0 and cs.total_debit_trailer < cs.total_debit :
						
						lsCus_debit_detail = CusDebitDetail.objects(cus_debit_id = cs.id)
						for c in lsCus_debit_detail :
							c.delete()
					
						lsCus_debit_detail_trailer = CusDebitDetailTrailer.objects(cus_debit_id = cs.id)
						for  Cus_debit_detail_trailer in lsCus_debit_detail_trailer:
							cdt = Cus_debit_detail_trailer
							
							cd = CusDebitDetail()
							
							cd.cus_id  = cdt.cus_id
							cd.cus_debit_id  = cdt.cus_debit_id
							cd.from_date= cdt.from_date
							cd.to_date= cdt.to_date
							cd.rate = cdt.rate
							cd.start_cycle = cdt.start_cycle
							cd.amount = cdt.amount
							cd.payment = cdt.payment
							cd.end_cycle = cdt.end_cycle
							cd.debit = cdt.debit
							cd.status = cdt.status
							cd.days = cdt.days
							cd.create_date= cdt.create_date
							cd.flag = cdt.flag
							cd.index = cdt.index
							
							cd.save()
							
						cus_debit_detail_trailer = CusDebitDetailTrailer.objects.get(cus_debit_id = cs.id,flag = 1)
						
						cs.total_debit =cs.total_debit_trailer
						cs.status = 0
						cs.payment = cus_debit_detail_trailer.payment
						cs.last_close_date = cus_debit_detail_trailer.to_date
						
						cs.save()
						
						#insert payment_detail
						pd = PaymentDetail()
						pd.payment_id = p
						pd.cus_debit_id = cs
						pd.cus_id = cus
						pd.debit = cus_debit_detail_trailer.payment
						pd.payment = cus_debit_detail_trailer.payment
						pd.cus_debit_detail_id = cus_debit_detail_trailer
						pd.status = 1
						
						pd.save()
						
						#insert record missing
						createcusdebit(cus,cs.last_close_date,cs.total_debit,cs.rate,cs.cycle,loan_type,'')
						
					elif cs.total_debit_trailer == 0 :
						print("update status=0")
						cus_debit_detail_trailer = CusDebitDetailTrailer.objects.get(cus_debit_id = cs.id,flag = 1)
						
						cs.total_debit =cs.total_debit_trailer
						cs.status = 0
						cs.payment = cus_debit_detail_trailer.payment
						cs.last_close_date = cus_debit_detail_trailer.to_date
						
						cs.save()
						
						#insert payment_detail
						pd = PaymentDetail()
						pd.payment_id = p
						pd.cus_debit_id = cs
						pd.cus_id = cus
						pb.debit = cus_debit_detail_trailer.payment
						pd.payment = cus_debit_detail_trailer.payment
						pb.cus_debit_detail_id = cus_debit_detail_trailer
						pd.status = 1
						
						pd.save()
						
					elif cs.total_debit_trailer == cs.total_debit :
						print("no update ")
Exemple #8
0
def createcusdebit(vUser, vLoan_date, vAmount, vRate,vCycle,vLoan_type,vNote):
		try:
			vtoday = date.today()
			cd = CusDebit()
			cd.cus_id  = vUser
			cd.month = vLoan_date
			cd.debit = vAmount
			cd.total_debit = vAmount
			cd.payment = 0.00
			cd.create_date = vtoday
			cd.loan_date = vLoan_date
			cd.loan_type = vLoan_type
			cd.rate = vRate
			cd.cycle = vCycle
			cd.status = 1
			cd.note =vNote
			cd.save()
			createcusdebitdetail(vUser,cd,vLoan_date,vAmount,vRate)
		except Exception as ex:
			print("createcusdebit: "+ex)