Skip to content

Commit

Permalink
Merge pull request #91 from Crudzaso/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
DiegoAndresRamirez authored Dec 8, 2024
2 parents 92d430d + 30f4bc7 commit a0b7b54
Show file tree
Hide file tree
Showing 11 changed files with 260 additions and 379 deletions.
70 changes: 39 additions & 31 deletions Modules/Raffle/app/Http/Controllers/RaffleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class RaffleController extends Controller
{
public function index()
{
$raffles = Raffle::with('organizer', 'lottery')->paginate(10);
$user = auth()->user();
$raffles = Raffle::with('organizer', 'lottery')
->where('organizer_id', $user->id)
->paginate(10);

return view('raffle::index', compact('raffles'));
}

Expand All @@ -38,18 +42,17 @@ public function store(Request $request)
]);

Raffle::create([
'name' => $request->name,
'organizer_id' => $request->organizer_id,
'lottery_id' => $request->lottery_id,

'total_tickets' => $request->total_tickets,
'ticket_price' => $request->ticket_price,
'tickets_sold' => $request->tickets_sold ?? 0,
'description' => $request->description,
'start_date' => $request->start_date,
'end_date' => $request->end_date,
'total_sales' => 0, // valor predeterminado de total_sales
]);
'name' => $request->name,
'organizer_id' => $request->organizer_id,
'lottery_id' => $request->lottery_id,
'total_tickets' => $request->total_tickets,
'ticket_price' => $request->ticket_price,
'tickets_sold' => $request->tickets_sold ?? 0,
'description' => $request->description,
'start_date' => $request->start_date,
'end_date' => $request->end_date,
'total_sales' => 0, // valor predeterminado de total_sales
]);

return redirect()->route('raffles.index')->with('success', 'Rifa creada exitosamente.');
}
Expand All @@ -64,24 +67,31 @@ public function edit($id)

public function update(Request $request, $id)
{
$raffle = Raffle::findOrFail($id);

$request->validate([
'organizer_id' => 'required|exists:users,id',
'image' => 'nullable|string',
'lottery_id' => 'required|exists:lotteries,id',
'ticket_price' => 'required|numeric|min:0',
'total_tickets' => 'required|integer|min:1',
'tickets_sold' => 'nullable|integer|min:0',
'name' => 'required|string|max:255',
'description' => 'nullable|string',
'start_date' => 'required|date',
'end_date' => 'required|date|after:start_date',
'image' => 'nullable|image|max:2048', // Validar si es una imagen
]);

$raffle = Raffle::findOrFail($id);
$raffle->update($request->all());


// Manejar imagen si se sube un nuevo archivo
if ($request->hasFile('image')) {
$imagePath = $request->file('image')->store('raffle_images', 'public');
$raffle->image = $imagePath; // Actualizar la ruta de la imagen
}

// Actualizar otros campos
$raffle->update([
'name' => $request->name,
'description' => $request->description,
'end_date' => $request->end_date,
]);

return redirect()->route('raffles.index')->with('success', 'Rifa actualizada exitosamente.');
}

public function destroy($id)
{
$raffle = Raffle::findOrFail($id);
Expand Down Expand Up @@ -121,7 +131,6 @@ public function getLastChanceRaffles()
return response()->json($raffles);
}


public function getActiveRaffles()
{
$activeRaffles = Raffle::where('end_date', '>', now())->get();
Expand All @@ -133,12 +142,12 @@ public function getFilteredRaffles(Request $request)
$filter = $request->input('filter');
$date = $request->input('date');
$query = Raffle::with('organizer', 'lottery');

// Aplicar filtro adicional por fecha
if ($date) {
$query->whereDate('end_date', '>', $date);
}

switch ($filter) {
case 'popular':
$query->where('tickets_sold', '>=', 50)
Expand All @@ -154,9 +163,8 @@ public function getFilteredRaffles(Request $request)
$query->where('end_date', '>', now());
break;
}

$raffles = $query->paginate(6);
return response()->json($raffles);
}

}
}
26 changes: 9 additions & 17 deletions Modules/Raffle/resources/views/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
<!-- Organizador -->
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700">Organizador</label>
<select name="organizer_id" class="form-control" required>
<option value="">Seleccione un organizador</option>
@foreach($organizers as $user)
<option value="{{ $user->id }}">{{ $user->name }}</option>
@endforeach
</select>
<input type="text" name="organizer_name" class="form-control" value="{{ auth()->user()->name }}" readonly>
<input type="hidden" name="organizer_id" value="{{ auth()->user()->id }}">
</div>

<!-- Nombre de la rifa -->
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700">Nombre de la rifa</label>
<input type="text" name="name" class="form-control" required>
Expand All @@ -47,13 +45,13 @@
<!-- Total a Recaudar -->
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700">Total a Recaudar</label>
<input type="number" name="total_to_collect" id="total_to_collect" class="form-control" step="0.01" required>
<input type="number" name="total_to_collect" id="total_to_collect" class="form-control" step="0.01" max="2000000" required>
</div>

<!-- Total de Tickets -->
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700">Total de Tickets</label>
<input type="number" name="total_tickets" id="total_tickets" class="form-control" required>
<input type="number" name="total_tickets" id="total_tickets" class="form-control" max="100" required>
</div>

<!-- Precio del Ticket -->
Expand All @@ -63,10 +61,7 @@
</div>

<!-- Tickets Vendidos -->
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700">Tickets Vendidos</label>
<input type="number" name="tickets_sold" class="form-control">
</div>
<input type="hidden" name="tickets_sold" value="0">

<!-- Descripción -->
<div class="mb-4">
Expand All @@ -75,10 +70,7 @@
</div>

<!-- Fecha de Inicio -->
<div class="mb-4">
<label class="block text-sm font-medium text-gray-700">Fecha de Inicio</label>
<input type="datetime-local" name="start_date" class="form-control" required>
</div>
<input type="hidden" name="start_date" value="{{ now()->format('Y-m-d\TH:i') }}">

<!-- Fecha de Finalización -->
<div class="mb-4">
Expand Down Expand Up @@ -112,4 +104,4 @@ function calculateTicketPrice() {
}
}
</script>
@stop
@stop
76 changes: 18 additions & 58 deletions Modules/Raffle/resources/views/edit.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<!-- resources/views/raffles/edit.blade.php -->

@extends('adminlte::page')

@section('title', 'Editar Rifa')
Expand All @@ -15,77 +13,37 @@
<h3 class="card-title text-white">Editar Rifa</h3>
</div>
<div class="card-body">
<form action="{{ route('raffles.update', $raffle->id) }}" method="POST">
<form action="{{ route('raffles.update', $raffle->id) }}" method="POST" enctype="multipart/form-data">
@csrf
@method('PUT')

<!-- Organizador -->
<div class="form-group">
<label>Organizador</label>
<select name="organizer_id" class="form-control select2" style="width: 100%;" required>
@foreach($organizers as $user)
<option value="{{ $user->id }}" {{ $raffle->organizer_id == $user->id ? 'selected' : '' }}>
{{ $user->name }}
</option>
@endforeach
</select>
</div>

<!-- Lotería -->
<div class="form-group">
<label>Lotería</label>
<select name="lottery_id" class="form-control select2" style="width: 100%;" required>
@foreach($lotteries as $lottery)
<option value="{{ $lottery->id }}" {{ $raffle->lottery_id == $lottery->id ? 'selected' : '' }}>
{{ $lottery->name }}
</option>
@endforeach
</select>
</div>

<!-- Precio del Ticket -->
<div class="form-group">
<label>Precio del Ticket</label>
<input type="number" name="ticket_price" value="{{ $raffle->ticket_price }}" class="form-control" required>
</div>

<!-- Total de Tickets -->

<!-- Nombre de la rifa -->
<div class="form-group">
<label>Total de Tickets</label>
<input type="number" name="total_tickets" value="{{ $raffle->total_tickets }}" class="form-control" required>
<label>Nombre de la rifa</label>
<input type="text" name="name" value="{{ $raffle->name }}" class="form-control" required>
</div>

<!-- Tickets Vendidos -->
<div class="form-group">
<label>Tickets Vendidos</label>
<input type="number" name="tickets_sold" value="{{ $raffle->tickets_sold }}" class="form-control">
</div>


<!-- Descripción -->
<div class="form-group">
<label>Descripción</label>
<textarea name="description" class="form-control">{{ $raffle->description }}</textarea>
</div>

<!-- Fecha de Inicio -->
<div class="form-group">
<label>Fecha de Inicio</label>
<input type="datetime-local" name="start_date" value="{{ \Carbon\Carbon::parse($raffle->start_date)->format('Y-m-d\TH:i') }}" class="form-control" required>
</div>


<!-- Fecha de Finalización -->
<div class="form-group">
<label>Fecha de Finalización</label>
<input type="datetime-local" name="end_date" value="{{ \Carbon\Carbon::parse($raffle->end_date)->format('Y-m-d\TH:i') }}" class="form-control" required>
</div>

<!-- Botón Actualizar -->
<!-- Imagen -->
<div class="form-group">
<button type="submit" class="btn btn-primary">
<i class="fas fa-save"></i> Actualizar
</button>
<label>Imagen de la Rifa</label>
<input type="file" name="image" class="form-control" accept="image/*">
</div>

<button type="submit" class="btn btn-primary">Actualizar</button>
</form>

</div>
</div>
</div>
Expand All @@ -103,7 +61,9 @@
<script>
// Inicializar Select2 para los dropdowns
$(document).ready(function() {
$('.select2').select2();
if ($.fn.select2) {
$('.select2').select2();
}
});
</script>
@stop
@stop
5 changes: 5 additions & 0 deletions Modules/Raffle/resources/views/layouts/master.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" />



{{-- Vite CSS --}}
Expand All @@ -24,10 +26,13 @@
<body class="bg-gray-100 text-gray-800">
<div id="app">
@yield('content')
@yield('js')
</div>

{{-- Alpine.js --}}
<script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script>


{{-- Vite JS --}}
@vite('Modules/Raffle/resources/assets/js/app.js', 'build-raffle')
Expand Down
2 changes: 1 addition & 1 deletion Modules/Raffle/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
|
*/

Route::prefix('raffles')->name('raffles.')->group(function () {
Route::middleware(['auth', 'role:admin|organizador'])->prefix('raffles')->name('raffles.')->group(function () {
Route::get('/admin/rifas', [RaffleController::class, 'index'])->name('index');
Route::get('/admin/crear-rifa', [RaffleController::class, 'create'])->name('create');
Route::post('/admin/actualizar-rifa', [RaffleController::class, 'store'])->name('store');
Expand Down
Loading

0 comments on commit a0b7b54

Please sign in to comment.