Skip to content

Commit

Permalink
Merge pull request #32 from anujpatel03/hmweb-main
Browse files Browse the repository at this point in the history
Merging hmweb-main into hmweb-test (Changes of Anni)
  • Loading branch information
anujpatel03 authored Apr 10, 2024
2 parents 5908d60 + 0606bb6 commit af7f160
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 4 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ node_modules/
FusionIIIT/static/
package-lock.json

**/migrations/*

**/**/migrations/*
**/**/migrations
.DS_Store
.DS_Store
2 changes: 2 additions & 0 deletions FusionIIIT/applications/hostel_management/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
path('fine/', views.impose_fine_view, name='fine_form_show'),
path('fine/impose/', views.HostelFineView.as_view(), name='fine_form_show'),
path('fine/impose/list/', views.hostel_fine_list, name='fine_list_show'),
path('fine/impose/edit/<int:fine_id>/', views.show_fine_edit_form, name='hostel_fine_edit'),
path('fine/impose/update/<int:fine_id>/', views.update_student_fine, name='update_student_fine'),
path('fine/impose/list/update/<int:fine_id>/', views.HostelFineUpdateView.as_view(), name='fine_update'),
path('fine/delete/<int:fine_id>/', views.HostelFineUpdateView.as_view(), name='fine_delete'),
path('fine/show/', views.student_fine_details, name='fine_show'),
Expand Down
27 changes: 27 additions & 0 deletions FusionIIIT/applications/hostel_management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1832,6 +1832,33 @@ def update_leave_status(request):
# //! Add Fine Functionality


@login_required
def show_fine_edit_form(request,fine_id):
user_id = request.user
staff = user_id.extrainfo.id
caretaker = HallCaretaker.objects.get(staff_id=staff)
hall_id = caretaker.hall_id

fine = HostelFine.objects.filter(fine_id=fine_id)



return render(request, 'hostelmanagement/impose_fine_edit.html', {'fines': fine[0]})

@login_required
def update_student_fine(request,fine_id):
if request.method == 'POST':
fine = HostelFine.objects.get(fine_id=fine_id)
print("------------------------------------------------")
print(request.POST)
fine.amount = request.POST.get('amount')
fine.status = request.POST.get('status')
fine.reason = request.POST.get('reason')
fine.save()

return HttpResponse({'message': 'Fine has edited successfully'}, status=status.HTTP_200_OK)


@login_required
def impose_fine_view(request):
user_id = request.user
Expand Down
28 changes: 27 additions & 1 deletion FusionIIIT/templates/hostelmanagement/hostel_fine_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ <h2 align ="center">Hostel Fine List</h2>
</select>
</td>
<td>{{ hostel_fine.reason }}</td>
<td><button class="ui negative button" onclick="cancelFine('{{ hostel_fine.fine_id }}')">Cancel</button></td>

<td>
<button class="ui negative mini button" onclick="cancelFine('{{ hostel_fine.fine_id }}')">Cancel</button>

<button id="edit-button" class="ui positive medium button" onclick="editFine('{{ hostel_fine.fine_id }}')">Edit</button>

</td>


</tr>
{% endfor %}
</tbody>
Expand All @@ -40,9 +48,20 @@ <h2 align ="center">Hostel Fine List</h2>
text-align: center;
padding: 5px;
}

#edit-button{
margin-top: 2px;
padding: 8px;
width: 67px;
}
</style>

<script>
function editFine(fineId) {
// Redirect to the edit page for the fine
window.location.href = '/hostelmanagement/fine/impose/edit/' + fineId + '/';
}

function updateStatus(fineId, status) {
// Send an AJAX request to update the status
fetch('/hostelmanagement/fine/impose/list/update/' + fineId + '/', {
Expand Down Expand Up @@ -72,6 +91,13 @@ <h2 align ="center">Hostel Fine List</h2>


function cancelFine(fineId) {

var confirmation = confirm("Are you sure you want to remove this fine?");

if(!confirmation) {
return;
}

// Send a DELETE request to delete the fine
fetch('/hostelmanagement/fine/delete/' + fineId + '/', {
method: 'DELETE',
Expand Down
129 changes: 129 additions & 0 deletions FusionIIIT/templates/hostelmanagement/impose_fine_edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{% extends 'globals/base.html' %}
{% load static %}

{% block title %}
Hostel
{% endblock %}


{% block body %}
{% block navBar %}
{% include 'dashboard/navbar.html' %}
{% endblock %}

<div class="ui stackable doubling grid">
<div class="column"></div>

<div class="three wide column">

<div class="row">
{% block userCard %}
{% include 'globals/usercard.html' %}
{% endblock %}
</div>

</div>


<div class="eight wide column">

<h2 align="center">Hostel Fine Form</h2>
<form class="ui form" id="fineForm" action="/hostelmanagement/fine/impose/update/{{fines.fine_id}}/" method="POST">
{% csrf_token %}
<div class="field">
<label for="student_id">Student ID:</label>
<input id="student_id" value="{{ fines.student_id }}" required readonly />
</div>
{% if fines %}
<div class="field">
<label for="student_name">Student Name:</label>
<input type="text" id="student_fine_name" name="student_fine_name" value="{{ fines.student_name }}" required
readonly />
</div>
{% endif %}
<div class="field">
<label for="amount">Amount:</label>
<input value="{{fines.amount}}" type="number" id="amount" name="amount" min="0" step="1" required />
</div>


<div class="field">
<label for="status">Status:</label>
<select name="status" onchange="updateStatus('{{ fines.fine_id }}', this.value)">
<option value="Pending" {% if fines.status == 'Pending' %} selected {% endif %}>Pending</option>
<option value="Paid" {% if fines.status == 'Paid' %} selected {% endif %} >Paid</option>
</select>
</div>


<div class="field">
<label for="reason">Reason:</label>
<textarea id="reason" name="reason" required>{{ fines.reason }}</textarea><br />
</div>

<button type="submit" class="ui primary button">Submit</button>
<a href="{% url 'hostelmanagement:hostel_view' %}" class=" ui button ">Back To Homepage</a>
</form>

<br/>

<div id="responseMessage"></div>
</div>
</div>

<script>

function updateStatus(fineId, status) {
fetch(`/hostelmanagement/fine/impose/list/update/${fineId}/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
},
body: JSON.stringify({
fine_id: fineId,
status: status
})
})
.then(response => {
if (response.ok) {
// Handle successful response if needed
console.log('Status updated successfully');
} else {
// Handle error response if needed
console.error('Error updating status');
}
})
.catch(error => {
// Handle fetch error if needed
console.error('Fetch error:', error);
});
}

document.getElementById("fineForm").addEventListener("submit", function (event) {
event.preventDefault();
var studentId = document.getElementById("student_id").value;
if (!studentId) {
alert("Please select a student ID.");
return;
}

var formData = new FormData(this);
fetch(this.action, {
method: this.method,
body: formData,
})
.then(response => {
if (response.ok) {
window.location.href = "/hostelmanagement/";
} else {
console.error("Error updating status");
}
})
.catch(error => {
console.error("Error:", error);
});
});
</script>

{% endblock %}

0 comments on commit af7f160

Please sign in to comment.