Skip to content

Commit

Permalink
Merge pull request #375 from Troter2/294-crear-llistat-de-ofertes-per…
Browse files Browse the repository at this point in the history
…-administrador

294 crear llistat de ofertes per administrador
  • Loading branch information
Juanca192001 authored Jun 12, 2024
2 parents b325cd2 + 729ebfa commit 07923fe
Show file tree
Hide file tree
Showing 6 changed files with 278 additions and 32 deletions.
9 changes: 7 additions & 2 deletions Billing/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ class Meta:

discount_code = forms.ModelChoiceField(
queryset=Coupon.objects.filter(active=True),
label="Código de Descuento"
)
label="discount_code"
)

class CouponForm(forms.ModelForm):
class Meta:
model = Coupon
fields = ['discount_code', 'discount_percentage']
63 changes: 48 additions & 15 deletions Billing/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.shortcuts import render, redirect, get_object_or_404

from Billing.forms import PromotionForm
from Billing.models import Promotion
from Billing.forms import PromotionForm, CouponForm
from Billing.models import Promotion, Coupon
from Reception.models import RoomReservation
from Restaurant.models import RestaurantReservation

Expand All @@ -10,24 +10,58 @@
def list_offers(request):
if request.user.has_perm('accountant'):
promotions = Promotion.objects.all()
return render(request, 'billing/list_offers.html', {'ofertas': promotions})
coupons = Coupon.objects.all()
return render(request, 'billing/list_offers.html', {'ofertas': promotions, 'cupones': coupons})
return redirect('home')


def create_offer(request):
def list_coupons(request):
if request.user.has_perm('accountant'):
if request.method == 'POST':
form = PromotionForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('list_offers')
coupons = Coupon.objects.all()
return render(request, 'billing/list_coupons.html', {'cupones': coupons})
return redirect('home')


def edit_status_coupon(request):
if request.user.has_perm('accountant') and request.method == 'POST':
coupon_id = request.POST['id_coupon']
coupon = get_object_or_404(Coupon, pk=coupon_id)
if coupon.active == True:
coupon.active = False
else:
form = PromotionForm()
return render(request, 'billing/create_offer.html', {'form': form})
coupon.active = True
coupon.save()
return redirect('list_coupons')
return redirect('home')


def create_coupon(request):
if request.user.has_perm('accountant') and request.method == 'POST':
form = CouponForm(request.POST)
if form.is_valid():
form.save()
return redirect('list_coupons')
return redirect('home')


def list_restaurant_and_room(request):
def edit_coupon(request):
if request.user.has_perm('accountant') and request.method == 'POST':
coupon_id = request.POST['id']
coupon = get_object_or_404(Coupon, pk=coupon_id)
coupon.discount_percentage = request.POST['discount_percentage']
coupon.discount_code = request.POST['discount_code']
coupon.save()
return redirect('list_coupons')
return redirect('home')

def create_offer(request):
if request.user.has_perm('accountant') and request.method == 'POST':
form = PromotionForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('list_offers')
return redirect('home')

def list_restaurant_and_room(request):
if request.user.has_perm('accountant'):
reservations = RoomReservation.objects.filter(guest_leaved=True)
return render(request, 'billing/list_reservations.html', {'reservas': reservations})
Expand Down Expand Up @@ -55,8 +89,7 @@ def delete_offer(request, offer_id):
return redirect('list_offers')
return redirect('home')


def details_reservation(request, reservation_id):
room_reservation = get_object_or_404(RoomReservation, pk=reservation_id)
restaurant_reservations = RestaurantReservation.objects.filter(room_reservation=room_reservation)
return render(request, 'billing/details_reservation.html', {'room_reservation': room_reservation, 'restaurant_reservations': restaurant_reservations})
return render(request, 'billing/details_reservation.html', {'room_reservation': room_reservation, 'restaurant_reservations': restaurant_reservations})
8 changes: 5 additions & 3 deletions hotelManagementProject/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
from django.contrib import admin
from django.contrib.auth import login
from django.urls import path, include

from Billing.views import list_offers, create_offer, edit_offer, delete_offer, list_restaurant_and_room, \
details_reservation

details_reservation, list_coupons, create_coupon,edit_status_coupon, edit_coupon
from Cleaning.views import cleaner_page, update_room_status
from User.views import add_guest_view, save_more_guest, save_guest, user_profile, user_edit_profile, \
list_reservations_user, booking_filter_user, delete_booking_user, list_users, delete_user, edit_user, \
Expand Down Expand Up @@ -112,6 +110,10 @@
path('rrhh/users/create', register_admin, name='register_admin'),
path('rrhh/users/search', search_user_rrhh, name='search_user_rrhh'),
path('offer/delete/<int:offer_id>/', delete_offer, name='delete_offer'),
path('coupon/', list_coupons, name='list_coupons'),
path('coupon/create_coupon', create_coupon, name='create_coupon'),
path('coupon/edit_status_coupon/', edit_status_coupon, name='edit_status_coupon'),
path('coupon/edit_coupon/',edit_coupon, name='edit_coupon' )
path('details_reservation/<int:reservation_id>/', details_reservation, name='details_reservation'),
path('pay_reservation_with_invoices', pay_reservation_with_invoices, name='pay_reservation_with_invoices'),
path('generate_room_invoice', generate_room_invoice, name='generate_room_invoice'),
Expand Down
31 changes: 21 additions & 10 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,27 @@
Contable
</a>
<ul class="dropdown-menu bg-light my-0 py-0 text-black-50" aria-labelledby="navbarContable">
<li class="dropdown-item rounded no-blue">
<a href="{% url 'list_offers' %}">
Ofertas
</a>
</li>
<li class="dropdown-item rounded no-blue">
<a href="{% url 'list_restaurant_and_room' %}">
Listado de Reservas
</a>
</li>
<div class="nav-link-div" onclick="navigateToURL('{% url 'list_offers' %}')">
<li class="dropdown-item rounded no-blue">
<a href="{% url 'list_offers' %}">
Ofertas
</a>
</li>
</div>
<div class="nav-link-div" onclick="navigateToURL('{% url 'list_coupons' %}')">
<li class="dropdown-item rounded no-blue">
<a href="{% url 'list_coupons' %}">
Cupones
</a>
</li>
</div>
<div class="nav-link-div" onclick="navigateToURL('{% url 'list_restaurant_and_room' %}')">
<li class="dropdown-item rounded no-blue">
<a href="{% url 'list_restaurant_and_room' %}">
Listado de Reservas
</a>
</li>
</div>
</ul>
</li>
{% endif %}
Expand Down
134 changes: 134 additions & 0 deletions templates/billing/list_coupons.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
{% extends "base.html" %}
{% load static %}
{% block title %} Promociones del Hotel {% endblock %}
{% block content %}
<h1 class="mx-3 my-3">Lista de Cupones del Hotel</h1>
<div class="container-fluid">
<div class="row mt-3">
<div class="col">
<button type="button" data-bs-toggle="modal" data-bs-target="#create-coupon" class="btn btn-primary">
Crear Cupon
</button>
</div>
</div>
</div>
</div>
<div class="promotions-list mt-3">
<div class="container-fluid">
<table class="table table-striped table-dark col-sm-11">
<thead class="thead-dark">
<tr>
<th scope="col">Codigo de descuento</th>
<th scope="col">Porcentage de descuento</th>
<th scope="col">Estado</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{% for cupon in cupones %}
<tr>
<td>{{ cupon.discount_code }}</td>
<td>{{ cupon.discount_percentage }}</td>
{% if cupon.active == True %}
<td>
<form method="post" action="{% url 'edit_status_coupon' %}">
{% csrf_token %}
<input type="hidden" name="id_coupon" value="{{ cupon.pk }}">
<button type="submit" class="btn btn-success">Activo</button>
</form>
</td>
{% else %}
<td>
<form method="post" action="{% url 'edit_status_coupon' %}">
{% csrf_token %}
<input type="hidden" name="id_coupon" value="{{ cupon.pk }}">
<button type="submit" class="btn btn-danger">Inactivo</button>
</form>
</td>
{% endif %}
<td>
<button type="button" class="btn btn-success" data-bs-toggle="modal"
data-bs-target="#Pop-up-edit-{{ cupon.id }}">
Editar Cupon
</button>
</td>
</tr>

<!-- Modales de editar cupon -->
<div class="modal fade" id="Pop-up-edit-{{ cupon.id }}" tabindex="-1" role="dialog"
aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">
Editar cupon Nº{{ cupon.id }}
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<form action="{% url 'edit_coupon' %}" method="post">
{% csrf_token %}
<div class="modal-body d-flex row ">
<input type="hidden" name="id" value="{{ cupon.pk }}">
<div class="col-6">
<div class="col-12">
<p><strong>Codigo de descuento:</strong></p>
<input type="text" class="form-control" id="discount_code"
value="{{ cupon.discount_code }}" name="discount_code">
</div>
</div>
<div class="col-6">
<div class="col-12">
<p><strong>Porcentage de descuento:</strong></p>
<input type="number" max="100" min="0" class="form-control"
id="discount_percentage" value="{{ cupon.discount_percentage }}"
name="discount_percentage">
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">
Guardar
</button>
</div>
</div>
</form>
</div>
</div>
</div>

{% endfor %}

<!-- Modal para crear un cupon -->
<div class="modal fade" id="create-coupon" tabindex="-1" role="dialog"
aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">
Crear cupon
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<form method="POST" action="{% url 'create_coupon' %}">
<div class="modal-body">
{% csrf_token %}
<p><strong>Codigo:</strong></p>
<input type="text" class="form-control" id="discount_code" name="discount_code">
<p><strong>Porcentage de descuento:</strong></p>
<input type="number" max="100" min="0" class="form-control" id="discount_percentage"
name="discount_percentage">
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">Crear</button>
</div>
</form>
</div>
</div>
</div>

</tbody>
</table>
</div>
</div>
{% endblock %}
65 changes: 63 additions & 2 deletions templates/billing/list_offers.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ <h1 class="mx-3 my-3">Lista de Promociones del Hotel</h1>
<div class="container-fluid">
<div class="row mt-3">
<div class="col">
<a href="{% url 'create_offer' %}" class="btn btn-primary">Crear Oferta</a>
<button type="button" data-bs-toggle="modal" data-bs-target="#create-promotion" class="btn btn-primary">
Crear Oferta
</button>
</div>
</div>
</div>
Expand Down Expand Up @@ -115,7 +117,8 @@ <h5 class="modal-title" id="deleteModalLabel">Confirmar Borrado</h5>
</div>
</div>

<!-- Modales de editar oferta-->
<!-- Modal de editar oferta-->

<div class="modal fade" id="Pop-up-edit-{{ oferta.id }}" tabindex="-1" role="dialog"
aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
Expand Down Expand Up @@ -168,6 +171,64 @@ <h5 class="modal-title" id="exampleModalLabel">
</div>
</div>

<!-- Modal para crear un cupon -->

<div class="modal fade" id="create-promotion" tabindex="-1" role="dialog"
aria-labelledby="ModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">
Crear Promocion
</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
<form method="POST" action="{% url 'create_offer' %}" enctype="multipart/form-data">
<div class="modal-body d-flex row ">
{% csrf_token %}
<div class="col-12">
<p><strong>Imagen:</strong></p>
<div class="input-group mb-3">
<input type="file" class="form-control" id="image"
name="image">
</div>
</div>
<div class="col-6">
<div class="col-12">
<p><strong>Titulo:</strong></p>
<input type="text" class="form-control"
id="title" name="title">
</div>
</div>
<div class="col-6">
<div class="col-12">
<p><strong>Descripcion:</strong></p>
<input type="text" class="form-control"
id="description" name="description">
</div>
</div>
<div class="col-12">
<p><strong>Codigo:</strong></p>
<div class="col-12">
<select class="form-select" id="discount_code" name="discount_code">
{% for cupon in cupones %}
{% if cupon.active == True %}
<option value="{{ cupon.id }}">{{ cupon.discount_code }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">Crear</button>
</div>
</div>
</form>
</div>
</div>
</div>

{% if not ofertas %}
<p class="mx-3 my-3"><strong>No hay ofertas disponibles</strong></p>
{% endif %}
Expand Down

0 comments on commit 07923fe

Please sign in to comment.