Пример #1
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 ")
Пример #2
0
def insert_missing_debit_detail_test1(vCus,vCus_debit,vFrom_date,vStart_cycle,vRate,index,vCus_debit_detail):
	try:
		vToday = datetime.strptime(str(date.today()),'%Y-%m-%d')
		vTodate = vFrom_date + relativedelta(days=+vCus_debit.cycle)
		vTodate =vTodate + relativedelta(days=-1)
		vStart_cycle_temp=vStart_cycle
		
		vdiff=((vToday -vFrom_date).days)/vCus_debit.cycle
		vdiff_round=int(vdiff)
		index = index
		print(vdiff_round)
		
		
		while vdiff_round > 0:
			print(str(vdiff_round))
			cdt = CusDebitDetail()
			cdt.cus_id  = vCus
			cdt.cus_debit_id  = vCus_debit
			cdt.from_date= vFrom_date
			cdt.rate = vRate
			cdt.start_cycle = vStart_cycle_temp
			
			cdt.amount = (vStart_cycle_temp*vCus_debit.cycle*cdt.rate)/1000000
			cdt.to_date= vTodate
			
			cdt.payment = 0
			cdt.end_cycle = cdt.start_cycle + cdt.amount - cdt.payment
			cdt.debit = 0
			cdt.status = 1
			cdt.days = float(str((cdt.to_date -cdt.from_date).days))+1
			cdt.index =index
			#---------------------------------------------------------------------
			# Assign for next cycle
			vFrom_date = cdt.to_date + relativedelta(days=+1)
			vTodate = vFrom_date + relativedelta(days=+vCus_debit.cycle)
			vTodate =vTodate + relativedelta(days=-1)
			vStart_cycle_temp = cdt.end_cycle
			index += 1
			vdiff_round -= 1
			#---------------------------------------------------------------------
			cdt.save()
		if (((vToday -vFrom_date).days)%vCus_debit.cycle) >= 0 :
			cdt = CusDebitDetail()
			cdt.cus_id  = vCus
			cdt.cus_debit_id = vCus_debit
			cdt.from_date= vFrom_date
			cdt.rate = vRate
			cdt.start_cycle = vStart_cycle_temp
			cdt.amount = (vStart_cycle_temp*(((vToday -vFrom_date).days)%vCus_debit.cycle +1)*cdt.rate)/1000000
			cdt.to_date = vToday
			cdt.payment = 0
			cdt.end_cycle = cdt.start_cycle + cdt.amount - cdt.payment
			cdt.debit = 0
			cdt.status = 1
			cdt.days = float(str((cdt.to_date -cdt.from_date).days))+1
			cdt.flag = 1
			cdt.index= index
			#---------------------------------------------------------------------
			# Assign for next cycle
			vFrom_date = cdt.to_date
			vTodate = vFrom_date + relativedelta(months=+1)
			vStart_cycle_temp = cdt.end_cycle
			#---------------------------------------------------------------------
			cdt.save()
			#total debit and last_close_date
			vCus_debit.total_debit = cdt.end_cycle
			vCus_debit.total_debit_trailer = cdt.end_cycle
			vCus_debit.last_close_date = cdt.to_date
			vCus_debit.save()
			vCus_debit_detail.delete()
	except Exception as ex:
		print(ex)