Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions FusionIIIT/applications/visitor_hostel/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from rest_framework import serializers
from .models import Inventory, InventoryBill
from .models import BookingDetail, Bill

class InventorySerializer(serializers.ModelSerializer):
class Meta:
model = Inventory
fields = '__all__'

class InventoryBillSerializer(serializers.ModelSerializer):
class Meta:
model = InventoryBill
fields = '__all__'

class BillSerializer(serializers.ModelSerializer):
total_bill = serializers.SerializerMethodField()

class Meta:
model = Bill
fields = ['id', 'booking', 'meal_bill', 'room_bill', 'payment_status', 'bill_date', 'total_bill']

def get_total_bill(self, obj):
return obj.meal_bill + obj.room_bill

class BookingDetailSerializer(serializers.ModelSerializer):
intender_name = serializers.CharField(source='intender.username') # Assuming User model has a username field
bill = BillSerializer()

class Meta:
model = BookingDetail
fields = ['intender_name', 'booking_from', 'booking_to', 'bill']
15 changes: 14 additions & 1 deletion FusionIIIT/applications/visitor_hostel/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,21 @@
url(r'^user-details/', views.get_user_details, name='get_user_details'), #
url(r'^get-booking-details/(?P<booking_id>\d+)/$', views.get_booking_details, name='get_booking_details'), #
url(r'^forward-booking-new/$', views.forward_booking_new, name='forward_booking_new'),
url(r'^confirm-booking-new/$', views.confirm_booking_new, name='confirm_booking_new'), #

url(r'^confirm-booking-new/$', views.confirm_booking_new, name='confirm_booking_new'), #

url(r'^inventory/$', views.get_inventory_items, name='get_inventory_items'),
url(r'^inventory/(?P<pk>\d+)/$', views.get_inventory_item, name='get_inventory_item'),
url(r'^inventory-bills/$', views.get_inventory_bills, name='get_inventory_bills'),
url(r'^inventory-bills/(?P<pk>\d+)/$', views.get_inventory_bill, name='get_inventory_bill'),

url(r'^accounts-income/$', views.get_all_bills, name='get_all_bills'),
url(r'^accounts-income/(?P<pk>\d+)/$', views.get_bills_id, name='get_bills_id'),

# url(r'^confirm-booking-new/$', views.confirm_booking_new, name='confirm_booking_new'), #
#api
url('api/inventory_add/', AddToInventory.as_view(), name='add-to-inventory'),
url('api/inventory_list/', InventoryListView.as_view(), name='inventory-list'),

]

132 changes: 132 additions & 0 deletions FusionIIIT/applications/visitor_hostel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@

from django.views.decorators.http import require_GET


#----
#account staments
from rest_framework.decorators import api_view, permission_classes, authentication_classes
from rest_framework.permissions import IsAuthenticated
from rest_framework.authentication import TokenAuthentication
from rest_framework.response import Response
from .models import Inventory, InventoryBill
from .serializers import InventorySerializer, InventoryBillSerializer

#income
from rest_framework import generics
from .models import BookingDetail
from .serializers import BookingDetailSerializer
#--



# from .forms import InventoryForm

# for notifications
Expand Down Expand Up @@ -1473,3 +1491,117 @@ def forward_booking_new(request):
return JsonResponse({'error': 'One or more rooms not found'}, status=404)
except Exception as e:
return JsonResponse({'error': str(e)}, status=400)


#account statements

# Fetch all inventory items
@api_view(['GET'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def get_inventory_items(request):
inventories = Inventory.objects.all()
serializer = InventorySerializer(inventories, many=True)
return Response(serializer.data)

# Fetch a specific inventory item by ID
@api_view(['GET'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def get_inventory_item(request, pk):
try:
inventory = Inventory.objects.get(id=pk)
serializer = InventorySerializer(inventory)
return Response(serializer.data)
except Inventory.DoesNotExist:
return Response({"error": "Inventory item not found"}, status=404)

# Fetch all bills
@api_view(['GET'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def get_inventory_bills(request):
bills = InventoryBill.objects.all()
serializer = InventoryBillSerializer(bills, many=True)
return Response(serializer.data)

# Fetch a specific bill by ID
@api_view(['GET'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def get_inventory_bill(request, pk):
try:
bill = InventoryBill.objects.get(id=pk)
serializer = InventoryBillSerializer(bill)
return Response(serializer.data)
except InventoryBill.DoesNotExist:
return Response({"error": "Bill not found"}, status=404)


#income
# account statements

from rest_framework.decorators import api_view, permission_classes, authentication_classes
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from rest_framework.authentication import TokenAuthentication
from .models import BookingDetail
from .serializers import BookingDetailSerializer

# Fetch all booking details
@api_view(['GET'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def get_all_bills(request):
bookings = BookingDetail.objects.all()
response_data = []

for booking in bookings:
# Check if the related bill exists
if hasattr(booking, 'bill'):
total_bill = booking.bill.meal_bill + booking.bill.room_bill
bill_id = booking.bill.id
bill_date = booking.bill.bill_date
else:
total_bill = 0
bill_id = None
bill_date = None

response_data.append({
'intender_name': booking.intender.username, # Assuming `username` for the user's name
'booking_from': booking.booking_from,
'booking_to': booking.booking_to,
'total_bill': total_bill,
'bill_id': bill_id,
'bill_date': bill_date,
})

return Response(response_data)

# Fetch a specific booking detail by ID
@api_view(['GET'])
@permission_classes([IsAuthenticated])
@authentication_classes([TokenAuthentication])
def get_bills_id(request, pk):
try:
booking = BookingDetail.objects.get(id=pk)
if hasattr(booking, 'bill'):
total_bill = booking.bill.meal_bill + booking.bill.room_bill
bill_id = booking.bill.id
bill_date = booking.bill.bill_date
else:
total_bill = 0
bill_id = None
bill_date = None

response_data = {
'intender_name': booking.intender.username, # Assuming `username` for the user's name
'booking_from': booking.booking_from,
'booking_to': booking.booking_to,
'total_bill': total_bill,
'bill_id': bill_id,
'bill_date': bill_date,
}
return Response(response_data)
except BookingDetail.DoesNotExist:
return Response({"error": "Booking detail not found"}, status=404)