def tada_result(request): if 'Submit' in request.GET: suspense = request.GET['suspense'] departure_time_from_tcc = request.GET['departure_time_from_tcc'] arrival_time_at_site = request.GET['arrival_time_at_site'] departure_time_from_site= request.GET['departure_time_from_site'] arrival_time_at_tcc= request.GET['arrival_time_at_tcc'] tada_amount= request.GET['tada_amount'] start_test_date=request.GET['start_test_date'] end_test_date= request.GET['end_test_date'] source_site= request.GET['source_site'] testing_site= request.GET['testing_site'] testing_staff= request.GET['testing_staff'] obj= TaDa(suspense=suspense, departure_time_from_tcc = departure_time_from_tcc,arrival_time_at_site=arrival_time_at_site, departure_time_from_site=departure_time_from_site, arrival_time_at_tcc=arrival_time_at_tcc,tada_amount=tada_amount, start_test_date=start_test_date,end_test_date=end_test_date, source_site=source_site, testing_site=testing_site, testing_staff=testing_staff ) obj.save() i=TaDa.objects.all().aggregate(Max('id')) j=i['id__max'] staff = testing_staff.split(",") total_cost = 0 for person in staff: total_cost= total_cost + int(tada_amount) rupees_in_words = num2eng(total_cost) obj1 = TaDa.objects.filter(id=j).values('departure_time_from_tcc' , 'arrival_time_at_site','departure_time_from_site', 'arrival_time_at_tcc', 'tada_amount','start_test_date', 'end_test_date','source_site', 'testing_site','testing_staff') return render(request, 'suspense/tada_result.html', { 'obj':obj1, 'total_cost':total_cost, 'staff':staff, 'rupees_in_words': rupees_in_words })
def tada_result(request): if 'Submit' in request.GET: suspense = request.GET['suspense'] departure_time_from_tcc = request.GET['departure_time_from_tcc'] arrival_time_at_site = request.GET['arrival_time_at_site'] departure_time_from_site = request.GET['departure_time_from_site'] arrival_time_at_tcc = request.GET['arrival_time_at_tcc'] tada_amount = request.GET['tada_amount'] start_test_date = request.GET['start_test_date'] end_test_date = request.GET['end_test_date'] source_site = request.GET['source_site'] testing_site = request.GET['testing_site'] testing_staff = request.GET['testing_staff'] obj = TaDa(suspense=suspense, departure_time_from_tcc=departure_time_from_tcc, arrival_time_at_site=arrival_time_at_site, departure_time_from_site=departure_time_from_site, arrival_time_at_tcc=arrival_time_at_tcc, tada_amount=tada_amount, start_test_date=start_test_date, end_test_date=end_test_date, source_site=source_site, testing_site=testing_site, testing_staff=testing_staff) obj.save() i = TaDa.objects.all().aggregate(Max('id')) j = i['id__max'] staff = testing_staff.split(",") total_cost = 0 for person in staff: total_cost = total_cost + int(tada_amount) rupees_in_words = num2eng(total_cost) obj1 = TaDa.objects.filter(id=j).values( 'departure_time_from_tcc', 'arrival_time_at_site', 'departure_time_from_site', 'arrival_time_at_tcc', 'tada_amount', 'start_test_date', 'end_test_date', 'source_site', 'testing_site', 'testing_staff') return render( request, 'suspense/tada_result.html', { 'obj': obj1, 'total_cost': total_cost, 'staff': staff, 'rupees_in_words': rupees_in_words })
def tada_result(request): if request.method == 'POST': form = TaDaForm(request.POST) if form.is_valid(): session = request.POST['session'] voucher = request.POST['voucher_no'] departure_time_from_tcc = request.POST['departure_time_from_tcc'] arrival_time_at_site = request.POST['arrival_time_at_site'] departure_time_from_site = request.POST['departure_time_from_site'] arrival_time_at_tcc = request.POST['arrival_time_at_tcc'] start_test_date = request.POST['start_test_date'] end_test_date = request.POST['end_test_date'] source_site = request.POST['source_site'] testing_site = request.POST['testing_site'] testing_staff = request.POST['testing_staff'] testing_staff_list = testing_staff.split(',') list_staff = [] if start_test_date == end_test_date: days = 1 else: no_of_days = datetime.strptime(end_test_date, '%Y-%m-%d') -\ datetime.strptime(start_test_date, '%Y-%m-%d') days = no_of_days.days + 1 for testing_staff_var in testing_staff_list: testing_staff_details = Staff.objects.filter(\ code=testing_staff_var).values('name','daily_ta_da') for tada_val in testing_staff_details: tada_val['daily_ta_da'] = tada_val['daily_ta_da'] * days list_staff.append(testing_staff_details) header = HeaderFooter.objects.values('header').get(is_active=True) footer = HeaderFooter.objects.values('footer').get(is_active=True) voucher_obj = VoucherId.objects.filter(session=session).\ filter(voucher_no=voucher).\ values_list('purchase_order_id', flat=True) purchase_order_var = 0 for temp_var in voucher_obj: purchase_order_var = temp_var purchase_order_object = PurchaseOrder.objects.filter(\ id = purchase_order_var).values('id', 'buyer_id__username',\ 'buyer_id__first_name', 'buyer_id__last_name') tada_total = 0 for temp_var in list_staff: for tada_value in temp_var: tada_total = tada_value['daily_ta_da'] + tada_total suspense_object = SuspenseOrder.objects.filter(voucher=voucher,\ session_id=session).update(is_cleared=0) if TaDa.objects.filter(voucher_no=voucher).\ filter(session=session).exists(): TaDa.objects.filter(voucher_no=voucher).\ update(voucher_no=voucher, session=session,\ departure_time_from_tcc=departure_time_from_tcc,\ arrival_time_at_site=arrival_time_at_site,\ departure_time_from_site=departure_time_from_site,\ arrival_time_at_tcc=arrival_time_at_tcc,\ tada_amount=tada_total, start_test_date=start_test_date,\ end_test_date=end_test_date, source_site=source_site,\ testing_site=testing_site , testing_staff=testing_staff,) else: obj = TaDa(voucher_no=voucher, session=session,\ departure_time_from_tcc=departure_time_from_tcc,\ arrival_time_at_site=arrival_time_at_site,\ departure_time_from_site=departure_time_from_site,\ arrival_time_at_tcc=arrival_time_at_tcc,\ tada_amount=tada_total, start_test_date=start_test_date,\ end_test_date=end_test_date, source_site=source_site,\ testing_site=testing_site , testing_staff=testing_staff ) obj.save() tada_obj = TaDa.objects.values('departure_time_from_tcc',\ 'arrival_time_at_site', 'departure_time_from_site',\ 'arrival_time_at_tcc', 'tada_amount', 'start_test_date',\ 'end_test_date', 'source_site', 'testing_site',\ 'date_of_generation').get(voucher_no=voucher) tada_amount_in_words = tada_total header = HeaderFooter.objects.values('header').get(is_active=True) footer = HeaderFooter.objects.values('footer').get(is_active=True) request_status = request_notify() return render(request, 'suspense/tada_summary.html',{\ 'purchase_order_object':purchase_order_object, 'tada':tada_obj, 'purchase_order_id':voucher,\ 'list_staff':list_staff, 'words':num2eng(int(tada_total)),\ 'total':tada_total, 'request':request_status}) else: session = request.POST['session'] voucher = request.POST['voucher_no'] form = TaDaForm(request.POST,initial={'voucher_no':voucher,\ 'session': session}) message = 'Fields are mandatory' tada = 'enable' request_status = request_notify() return render(request, 'suspense/form.html',{ 'form':form,'message':message,'request':request_status}) else: return HttpResponseRedirect(\ reverse('librehatti.suspense.views.tada_order_session'))