From 89124948e3bd77f153f7cc214a3a8d2375a5721b Mon Sep 17 00:00:00 2001 From: Harshul-25 Date: Sun, 5 May 2024 20:16:35 +0530 Subject: [PATCH] fixed bugs api chages --- .../central_mess/api/serializers.py | 4 + .../applications/central_mess/api/urls.py | 2 + .../applications/central_mess/api/views.py | 73 +++++++++++++++++++ .../applications/central_mess/models.py | 4 +- FusionIIIT/applications/central_mess/views.py | 2 +- .../messModule/de-registraionsrequests.html | 2 +- 6 files changed, 83 insertions(+), 4 deletions(-) diff --git a/FusionIIIT/applications/central_mess/api/serializers.py b/FusionIIIT/applications/central_mess/api/serializers.py index 582f2725e..1e077d6d4 100644 --- a/FusionIIIT/applications/central_mess/api/serializers.py +++ b/FusionIIIT/applications/central_mess/api/serializers.py @@ -98,4 +98,8 @@ class Meta: class DeregistrationRequestSerializer(serializers.ModelSerializer): class Meta: model = Deregistration_Request + fields = ('__all__') +class UpdatePaymentRequestSerializer(serializers.ModelSerializer): + class Meta: + model = Update_Payment fields = ('__all__') \ No newline at end of file diff --git a/FusionIIIT/applications/central_mess/api/urls.py b/FusionIIIT/applications/central_mess/api/urls.py index 7f4c03286..e0a86b9d7 100644 --- a/FusionIIIT/applications/central_mess/api/urls.py +++ b/FusionIIIT/applications/central_mess/api/urls.py @@ -26,4 +26,6 @@ url("get_student_all_details",views.Get_Student_Details.as_view(),name="get_student_details_API"), url('registrationRequestApi', views.RegistrationRequestApi.as_view(), name='registrationRequestApi'), url('deRegistrationRequestApi', views.DeregistrationRequestApi.as_view(), name='deRegistrationRequestApi'), + url('deRegistrationApi', views.DeregistrationApi.as_view(), name='deRegistrationApi'), + url('updatePaymentRequestApi', views.UpdatePaymentRequestApi.as_view(), name='updatePaymentRequestApi'), ] \ No newline at end of file diff --git a/FusionIIIT/applications/central_mess/api/views.py b/FusionIIIT/applications/central_mess/api/views.py index a6fbe4a97..4a6076ec4 100644 --- a/FusionIIIT/applications/central_mess/api/views.py +++ b/FusionIIIT/applications/central_mess/api/views.py @@ -656,6 +656,7 @@ def put(self, request): reg_main = Reg_main.objects.get(student_id=student) reg_main.current_mess_status = "Registered" reg_main.balance = F('balance') + amount + reg_main.mess_option = mess_option except Reg_main.DoesNotExist: reg_main = Reg_main.objects.create( student_id=student, @@ -717,6 +718,78 @@ def put(self, request): reg_record.end_date = end_date reg_record.save() return Response({'status': 200}) + except Exception as e: + print({'error': str(e)}) + return Response({'error': str(e)}, status=400) + +class DeregistrationApi(APIView): + def post(self, request): + try: + data = request.data + print(data) + student_id = data['student_id'] + end_date = data['end_date'] + + username = get_object_or_404(User, username=student_id) + idd = ExtraInfo.objects.get(user=username) + student = Student.objects.get(id=idd.id) + + reg_main = Reg_main.objects.get(student_id=student) + reg_main.current_mess_status = "Deregistered" + reg_main.save() + + reg_record = Reg_records.objects.filter(student_id=student).latest('start_date') + reg_record.end_date = end_date + reg_record.save() + return Response({'status': 200}) + except Exception as e: + print({'error': str(e)}) + return Response({'error': str(e)}, status=400) + +class UpdatePaymentRequestApi(APIView): + def get(self, request): + update_payment_requests = Update_Payment.objects.all() + serializer = UpdatePaymentRequestSerializer(update_payment_requests, many=True) + return Response({'status': 200, 'payload': serializer.data}) + + def post(self, request): + serializer = UpdatePaymentRequestSerializer(data=request.data) + if serializer.is_valid(): + serializer.save() + return Response({'status': 200}) + return Response(serializer.errors, status=400) + + def put(self, request): + try: + data = request.data + print(data) + student_id = data['student_id'] + payment_date = data['payment_date'] + amount = data['amount'] + Txn_no = data['Txn_no'] + img = data['img'] + new_status = data['status'] + new_remark = data['update_payment_remark'] + + username = get_object_or_404(User, username=student_id) + idd = ExtraInfo.objects.get(user=username) + student = Student.objects.get(id=idd.id) + + UpdatePayment_request = get_object_or_404(Update_Payment, student_id = student_id, payment_date = payment_date, amount = amount, Txn_no = Txn_no) + + UpdatePayment_request.status = new_status + UpdatePayment_request.update_payment_remark = new_remark + UpdatePayment_request.save() + + if (new_status == 'accept'): + new_payment_record = Payments(student_id = student, amount_paid = amount, payment_date=payment_date, payment_month=current_month(), payment_year=current_year()) + new_payment_record.save() + + reg_main = Reg_main.objects.get(student_id=student) + reg_main.balance = F('balance') + amount + reg_main.save() + + return Response({'status': 200}) except Exception as e: print({'error': str(e)}) return Response({'error': str(e)}, status=400) \ No newline at end of file diff --git a/FusionIIIT/applications/central_mess/models.py b/FusionIIIT/applications/central_mess/models.py index f92614ba1..ae96e8f82 100644 --- a/FusionIIIT/applications/central_mess/models.py +++ b/FusionIIIT/applications/central_mess/models.py @@ -156,8 +156,8 @@ class Payments(models.Model): payment_year = models.IntegerField(default = current_year) payment_date = models.DateField(default= datetime.date.today()) - class Meta: - unique_together = (('student_id', 'payment_date')) + # class Meta: + # unique_together = (('student_id', 'payment_date')) def __str__(self): return '{}'.format(self.student_id.id) diff --git a/FusionIIIT/applications/central_mess/views.py b/FusionIIIT/applications/central_mess/views.py index 255f34e40..60a4abb3b 100644 --- a/FusionIIIT/applications/central_mess/views.py +++ b/FusionIIIT/applications/central_mess/views.py @@ -335,7 +335,7 @@ def mess(request): context = { 'menu': menu_data, # 'reg_menu': y, - # 'messinfo': mess_optn, + 'messinfo': mess_optn, 'monthly_bill': monthly_bill, # 'total_due': amount_due, 'vaca': vaca_obj, diff --git a/FusionIIIT/templates/messModule/de-registraionsrequests.html b/FusionIIIT/templates/messModule/de-registraionsrequests.html index 2ce8ae2e1..cf513fec7 100644 --- a/FusionIIIT/templates/messModule/de-registraionsrequests.html +++ b/FusionIIIT/templates/messModule/de-registraionsrequests.html @@ -139,7 +139,7 @@ -
+