예제 #1
0
def getPaymentDetail():
	listcus =  getCustomerInfo()
	allpaymentdetaildetail = PaymentDetail.objects()
	paymentdetailafterfilter  = []
	for	l in listcus:
		for pmd in allpaymentdetaildetail:
			if(pmd.cus_id == l.cus_id ):
				paymentdetailafterfilter.append(pmd)
	return paymentdetailafterfilter
예제 #2
0
def analyze_payment(vCus_id,vcus_debit_id,vAmount,vPayment_id):
	try:
		vToday = datetime.now().strftime("%y-%m-%d-%H-%M-%S")
		vRemainAmount = vAmount
		lscdt = CusDebitDetail.objects(cus_debit_id = vcus_debit_id,status=1).order_by('loan_date')
		pdt = PaymentDetail.objects()
		
		for cd in lscdt:
			payment_amount = 0.00
			current_debit = cd.end_cycle
			if vRemainAmount > 0:
				if cd.end_cycle >= vAmount:
					payment_amount = vAmount
					cd.payment = payment_amount
					remain_debit = cd.end_cycle - payment_amount
					cd.end_cycle = remain_debit
					vRemainAmount = 0.00
				else:
					payment_amount = cd.end_cycle
					cd.payment = payment_amount
					remain_debit = cd.end_cycle - payment_amount
					cd.end_cycle = remain_debit
					vRemainAmount = vAmount - payment_amount
				#Insert into payment detail
				
				pdt.payment_id = vPayment_id
				pdt.cus_debit_id = vcus_debit_id
				pdt.cus_id  = vCus_id
				pdt.create_date= vToday
				pdt.debit = current_debit
				pdt.payment = payment_amount
				pdt.remain = pdt.debit - pdt.payment 
				pdt.status = 1
				pdt.save()
		#End for
		if vRemainAmount > 0:
			analyze_payment(vCus_id,vcus_debit_id,vRemainAmount,vPayment_id)
	except Exception as ex:
		print(ex)
예제 #3
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 ")