Skip to content

Commit 13e33f2

Browse files
shramanpaulAtOM18ompandey0703Vishal-Github-21Pheonix7113
authored
Dashboard client (#1697)
* Get Booking data api added (#1) * bug: fix conditional rendering of booking req * Dashboard client (#3) * Get Booking data api added * active booking api * add: forwardBooking confirmBooking * Dashboard client (#4) * Get Booking data api added * active booking api * Added cancelled, active, completed booking view functionality * cancellation_request done * reject option works * Add items backend functionality (#5) * add: rooms availibility * fix: urls * add: Account statement backend (#6) * "add: account statements" * resolved MC * Updated visitor_hostel URLs and views:added partial booking API (#7) Co-authored-by: Arun7113 <[email protected]> * fix: partial booking feature * fix: completed bookings * fix: account statement * fix: correct income display on account statement --------- Co-authored-by: Hardik Vardaan <[email protected]> Co-authored-by: ompandey0703 <[email protected]> Co-authored-by: Vishal-Github-21 <[email protected]> Co-authored-by: JATOTHU ARUN <[email protected]> Co-authored-by: Arun7113 <[email protected]>
1 parent 5c99c5a commit 13e33f2

File tree

7 files changed

+1070
-149
lines changed

7 files changed

+1070
-149
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from rest_framework import serializers
2+
from applications.visitor_hostel.models import Inventory, InventoryBill
3+
4+
class InventorySerializer(serializers.ModelSerializer):
5+
class Meta:
6+
model = Inventory
7+
fields = ['item_name', 'quantity', 'consumable']
8+
9+
class InventoryBillSerializer(serializers.ModelSerializer):
10+
class Meta:
11+
model = InventoryBill
12+
fields = ['item_name', 'bill_number', 'cost']
13+
class InventoryItemSerializer(serializers.ModelSerializer):
14+
class Meta:
15+
model = Inventory
16+
fields = ['item_name', 'quantity']
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from rest_framework.views import APIView
2+
from rest_framework.response import Response
3+
from rest_framework import status
4+
from applications.visitor_hostel.models import Inventory, InventoryBill
5+
from .serializers import InventorySerializer, InventoryBillSerializer, InventoryItemSerializer
6+
from rest_framework.generics import ListAPIView
7+
class AddToInventory(APIView):
8+
def post(self, request):
9+
# Extract data from request
10+
item_name = request.data.get('item_name')
11+
bill_number = request.data.get('bill_number')
12+
quantity = request.data.get('quantity')
13+
cost = request.data.get('cost')
14+
consumable = request.data.get('consumable')
15+
16+
# Validate and save Inventory item
17+
inventory_data = {
18+
'item_name': item_name,
19+
'quantity': quantity,
20+
'consumable': consumable,
21+
}
22+
inventory_serializer = InventorySerializer(data=inventory_data)
23+
24+
if inventory_serializer.is_valid():
25+
inventory_item = Inventory.objects.filter(item_name=item_name).first()
26+
if inventory_item:
27+
inventory_item.quantity = quantity
28+
inventory_item.consumable = consumable
29+
inventory_item.save()
30+
else:
31+
inventory_item = inventory_serializer.save()
32+
33+
# Save InventoryBill
34+
bill_data = {
35+
'item_name': inventory_item.id, # Link to inventory item
36+
'bill_number': bill_number,
37+
'cost': cost,
38+
}
39+
bill_serializer = InventoryBillSerializer(data=bill_data)
40+
if bill_serializer.is_valid():
41+
bill_serializer.save()
42+
return Response({"message": "Item added successfully!"}, status=status.HTTP_201_CREATED)
43+
else:
44+
return Response(bill_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
45+
else:
46+
return Response(inventory_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
47+
48+
class InventoryListView(ListAPIView):
49+
queryset = Inventory.objects.all()
50+
serializer_class = InventorySerializer

FusionIIIT/applications/visitor_hostel/apps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
class VisitorHostelConfig(AppConfig):
55
name = 'applications.visitor_hostel'
6+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from rest_framework import serializers
2+
from .models import Inventory, InventoryBill
3+
from .models import BookingDetail, Bill
4+
5+
class InventorySerializer(serializers.ModelSerializer):
6+
class Meta:
7+
model = Inventory
8+
fields = '__all__'
9+
10+
class InventoryBillSerializer(serializers.ModelSerializer):
11+
class Meta:
12+
model = InventoryBill
13+
fields = '__all__'
14+
15+
class BillSerializer(serializers.ModelSerializer):
16+
total_bill = serializers.SerializerMethodField()
17+
18+
class Meta:
19+
model = Bill
20+
fields = ['id', 'booking', 'meal_bill', 'room_bill', 'payment_status', 'bill_date', 'total_bill']
21+
22+
def get_total_bill(self, obj):
23+
return obj.meal_bill + obj.room_bill
24+
25+
class BookingDetailSerializer(serializers.ModelSerializer):
26+
intender_name = serializers.CharField(source='intender.username') # Assuming User model has a username field
27+
bill = BillSerializer()
28+
29+
class Meta:
30+
model = BookingDetail
31+
fields = ['intender_name', 'booking_from', 'booking_to', 'bill']

FusionIIIT/applications/visitor_hostel/urls.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.conf.urls import url
2+
from applications.visitor_hostel.api.views import AddToInventory, InventoryListView
23

34
from . import views
45

@@ -9,6 +10,8 @@
910
url(r'^$', views.visitorhostel, name='visitorhostel'),
1011
url(r'^get-booking-requests/', views.get_booking_requests, name='get_booking_requests'),
1112
url(r'^get-active-bookings/', views.get_active_bookings, name='get_active_bookings'),
13+
url(r'^get-inactive-bookings/', views.get_inactive_bookings, name='get_inactive_bookings'),
14+
url(r'^get-completed-bookings/', views.get_completed_bookings, name='get_completed_bookings'),
1215
url(r'^get-booking-form/', views.get_booking_form, name='get_booking_form'),
1316
url(r'^request-booking/' , views.request_booking , name ='request_booking'),
1417
url(r'^confirm-booking/' , views.confirm_booking , name ='confirm_booking'),
@@ -23,9 +26,37 @@
2326

2427
url(r'^bill_between_date_range/', views.bill_between_dates, name = 'generate_records'),
2528
url(r'^room-availability/', views.room_availabity, name = 'room_availabity'),
29+
url(r'^room_availabity_new/', views.room_availabity_new, name = 'room_availabity_new'),
30+
31+
url(r'^check-partial-booking/', views.check_partial_booking, name='check_partial_booking'),
32+
33+
2634
url(r'^add-to-inventory/', views.add_to_inventory, name = 'add_to_inventory'),
2735
url(r'^update-inventory/', views.update_inventory, name = 'update_inventory'),
2836
url(r'^edit-room-status/', views.edit_room_status, name = 'edit_room_status'),
2937
url(r'^booking-details/', views.booking_details, name = 'booking_details'),
3038
url(r'^forward-booking/', views.forward_booking, name = 'forward_booking'),
39+
url(r'^intenders/', views.get_intenders, name='get_intenders'), #
40+
url(r'^user-details/', views.get_user_details, name='get_user_details'), #
41+
url(r'^get-booking-details/(?P<booking_id>\d+)/$', views.get_booking_details, name='get_booking_details'), #
42+
url(r'^forward-booking-new/$', views.forward_booking_new, name='forward_booking_new'),
43+
44+
url(r'^confirm-booking-new/$', views.confirm_booking_new, name='confirm_booking_new'), #
45+
46+
url(r'^inventory/$', views.get_inventory_items, name='get_inventory_items'),
47+
url(r'^inventory/(?P<pk>\d+)/$', views.get_inventory_item, name='get_inventory_item'),
48+
url(r'^inventory-bills/$', views.get_inventory_bills, name='get_inventory_bills'),
49+
url(r'^inventory-bills/(?P<pk>\d+)/$', views.get_inventory_bill, name='get_inventory_bill'),
50+
51+
url(r'^accounts-income/$', views.get_all_bills, name='get_all_bills'),
52+
url(r'^accounts-income/(?P<pk>\d+)/$', views.get_bills_id, name='get_bills_id'),
53+
54+
# url(r'^confirm-booking-new/$', views.confirm_booking_new, name='confirm_booking_new'), #
55+
#api
56+
url('api/inventory_add/', AddToInventory.as_view(), name='add-to-inventory'),
57+
url('api/inventory_list/', InventoryListView.as_view(), name='inventory-list'),
58+
# completed bookings
59+
url(r'^completed-bookings/', views.completed_bookings, name='completed_bookings'),
60+
3161
]
62+

0 commit comments

Comments
 (0)