diff --git a/FusionIIIT/applications/central_mess/api/urls.py b/FusionIIIT/applications/central_mess/api/urls.py index e0a86b9d7..aad7b4891 100644 --- a/FusionIIIT/applications/central_mess/api/urls.py +++ b/FusionIIIT/applications/central_mess/api/urls.py @@ -28,4 +28,5 @@ url('deRegistrationRequestApi', views.DeregistrationRequestApi.as_view(), name='deRegistrationRequestApi'), url('deRegistrationApi', views.DeregistrationApi.as_view(), name='deRegistrationApi'), url('updatePaymentRequestApi', views.UpdatePaymentRequestApi.as_view(), name='updatePaymentRequestApi'), + url('get_mess_balance_statusApi', views.Get_Mess_Balance_Status.as_view(), name='get_mess_balance_statusApi'), ] \ 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 bc7da7767..61be21b2f 100644 --- a/FusionIIIT/applications/central_mess/api/views.py +++ b/FusionIIIT/applications/central_mess/api/views.py @@ -1,7 +1,9 @@ #APIs +from datetime import date, datetime, timedelta from django.db.models import F from rest_framework.views import APIView from rest_framework.response import Response +# from FusionIIIT.notification.views import central_mess_notif from .serializers import * from django.shortcuts import get_object_or_404 from applications.central_mess.models import * @@ -9,6 +11,8 @@ from applications.globals.models import ExtraInfo, HoldsDesignation, Designation from django.http import JsonResponse +today_g = datetime.datetime.now() + class FeedbackApi(APIView): def get(self, request): @@ -253,6 +257,7 @@ def post(self, request): data = request.data # student_id = data['mess_option'] + flag=1 start_date = data['start_date'] end_date = data['end_date'] purpose = data['purpose'] @@ -266,10 +271,30 @@ def post(self, request): app_date = data['app_date'] leave_type = data['leave_type'] + if (end_date < start_date): + flag = 0 + return Response({'status': 3, 'message': 'Please check the dates'}) + username = get_object_or_404(User,username=request.user.username) idd = ExtraInfo.objects.get(user=username) student = Student.objects.get(id=idd.id) + date_format = "%Y-%m-%d" + b = datetime.datetime.strptime(str(start_date), date_format) + d = datetime.datetime.strptime(str(end_date), date_format) + + rebate_check = Rebate.objects.filter(student_id=student, status='2') + for r in rebate_check: + a = datetime.datetime.strptime(str(r.start_date), date_format) + c = datetime.datetime.strptime(str(r.end_date), date_format) + if ((b <= a and (d >= a and d <= c)) or (b >= a and (d >= a and d <= c)) + or (b <= a and (d >= c)) or ((b >= a and b <= c) and (d >= c))): + flag = 0 + data = { + 'status': 3, + 'message': "Already applied for these dates", + } + return Response({'status': 3, 'message': 'Already applied for these dates'}) obj = Rebate( student_id = student, @@ -280,6 +305,10 @@ def post(self, request): end_date= end_date, start_date = start_date ) + + if flag == 1: + message = 'Your leave request has been accepted between dates ' + str(b.date()) + ' and ' + str(d.date()) + # central_mess_notif(request.user, student.id.user, 'leave_request', message) obj.save() return Response({'status':200}) @@ -439,8 +468,7 @@ def get(self, request): def post(self, request): data = request.data - - + start_date = data['start_date'] end_date = data['end_date'] status = data['status'] @@ -783,7 +811,12 @@ def post(self, request): class UpdatePaymentRequestApi(APIView): def get(self, request): - update_payment_requests = Update_Payment.objects.all() + student_id = request.query_params.get('student_id') + if student_id: + update_payment_requests = Update_Payment.objects.filter(student_id=student_id) + else: + update_payment_requests = Update_Payment.objects.all() + serializer = UpdatePaymentRequestSerializer(update_payment_requests, many=True) return Response({'status': 200, 'payload': serializer.data}) @@ -889,4 +922,23 @@ def post(self, request): return Response({'message': 'File processed successfully'}, status=status.HTTP_200_OK) except Exception as e: - return Response({'error': f'An error occurred: {str(e)}'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file + return Response({'error': f'An error occurred: {str(e)}'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + +class Get_Mess_Balance_Status(APIView): + def get(self, request): + username = get_object_or_404(User,username=request.user.username) + idd = ExtraInfo.objects.get(user=username) + student_id = Student.objects.get(id=idd.id) + try: + mess_optn = Reg_main.objects.select_related('student_id','student_id__id','student_id__id__user','student_id__id__department').get(student_id=student_id) + # y = Menu.objects.filter(mess_option=mess_optn.mess_option) + current_rem_balance = mess_optn.balance + current_mess_status = mess_optn.current_mess_status + except: + mess_optn={} + mess_optn={'mess_option':'no-mess'} + # y = Menu.objects.filter(mess_option="mess1") + current_rem_balance = 0 + current_mess_status = 'Deregistered' + + return Response({'payload': {'mess_option': mess_optn.mess_option, 'current_rem_balance': current_rem_balance, 'current_mess_status': current_mess_status}})