234 lines
7.1 KiB
PHP
234 lines
7.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Restaurante;
|
|
use App\Services\UuidService;
|
|
use App\Services\PaginatorService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Ramsey\Uuid\Uuid;
|
|
|
|
class BodegaController extends Controller {
|
|
|
|
/**
|
|
* Obtiene de forma paginada los ingresos de ingredientes
|
|
*/
|
|
public function ingresos(Request $request, $restaurante_id) {
|
|
app(UuidService::class)->validOrFail($restaurante_id);
|
|
$restaurante = Restaurante::findOrFail($restaurante_id);
|
|
|
|
$ingresos = $restaurante->bodegaIngresos()
|
|
->orderBy('fecha', 'desc')
|
|
->with('ingrediente');
|
|
|
|
$paginate = app(PaginatorService::class)->paginate(
|
|
perPage: $request->input('per_page', 15),
|
|
page: $request->input('page', 1),
|
|
total: $ingresos->count(),
|
|
route: 'bodega.ingresos',
|
|
data: ['restaurante_id' => $restaurante_id],
|
|
);
|
|
|
|
$data = $ingresos->get()
|
|
->skip($paginate['from'] - 1)
|
|
->take($paginate['per_page'])
|
|
->all();
|
|
|
|
return response()->json([
|
|
'pagination' => $paginate,
|
|
'data' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Obtiene los ingresos de un ingrediente
|
|
*/
|
|
public function ingresos_ingrediente(Request $request, $restaurante_id, $ingrediente_id) {
|
|
app(UuidService::class)->validOrFail($restaurante_id);
|
|
$restaurante = Restaurante::findOrFail($restaurante_id);
|
|
|
|
$ingresos = $restaurante->bodegaIngresos()
|
|
->where('ingrediente_id', $ingrediente_id)
|
|
->with('ingrediente');
|
|
|
|
$paginate = app(PaginatorService::class)->paginate(
|
|
perPage: $request->input('per_page', 15),
|
|
page: $request->input('page', 1),
|
|
total: $ingresos->count(),
|
|
route: 'bodega.ingresos',
|
|
data: ['restaurante_id' => $restaurante_id],
|
|
);
|
|
|
|
$data = $ingresos->get()
|
|
->skip($paginate['from'] - 1)
|
|
->take($paginate['per_page'])
|
|
->all();
|
|
|
|
return response()->json([
|
|
'pagination' => $paginate,
|
|
'data' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Obtiene de forma paginada los egresos de ingredientes
|
|
*/
|
|
public function egresos(Request $request, $restaurante_id) {
|
|
app(UuidService::class)->validOrFail($restaurante_id);
|
|
$restaurante = Restaurante::findOrFail($restaurante_id);
|
|
|
|
$egresos = $restaurante->bodegaEgresos()->with('ingrediente');
|
|
|
|
$paginate = app(PaginatorService::class)->paginate(
|
|
perPage: $request->input('per_page', 15),
|
|
page: $request->input('page', 1),
|
|
total: $egresos->count(),
|
|
route: 'bodega.egresos',
|
|
data: ['restaurante_id' => $restaurante_id],
|
|
);
|
|
|
|
$data = $egresos->get()
|
|
->skip($paginate['from'] - 1)
|
|
->take($paginate['per_page'])
|
|
->all();
|
|
|
|
return response()->json([
|
|
'pagination' => $paginate,
|
|
'data' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Obtiene los egresos de un ingrediente
|
|
*/
|
|
public function egresos_ingrediente(Request $request, $restaurante_id, $ingrediente_id) {
|
|
app(UuidService::class)->validOrFail($restaurante_id);
|
|
$restaurante = Restaurante::findOrFail($restaurante_id);
|
|
|
|
$egresos = $restaurante->bodegaEgresos()
|
|
->where('ingrediente_id', $ingrediente_id)
|
|
->with('ingrediente');
|
|
|
|
$paginate = app(PaginatorService::class)->paginate(
|
|
perPage: $request->input('per_page', 15),
|
|
page: $request->input('page', 1),
|
|
total: $egresos->count(),
|
|
route: 'bodega.egresos',
|
|
data: ['restaurante_id' => $restaurante_id],
|
|
);
|
|
|
|
$data = $egresos->get()
|
|
->skip($paginate['from'] - 1)
|
|
->take($paginate['per_page'])
|
|
->all();
|
|
|
|
return response()->json([
|
|
'pagination' => $paginate,
|
|
'data' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Obtiene de forma paginada los movimientos de ingredientes
|
|
*/
|
|
public function movimientos(Request $request, $restaurante_id) {
|
|
app(UuidService::class)->validOrFail($restaurante_id);
|
|
$restaurante = Restaurante::findOrFail($restaurante_id);
|
|
|
|
$movimientos = $restaurante->bodegaMovimientos()->with('ingrediente');
|
|
|
|
$paginate = app(PaginatorService::class)->paginate(
|
|
perPage: $request->input('per_page', 15),
|
|
page: $request->input('page', 1),
|
|
total: $movimientos->count(),
|
|
route: 'bodega.movimientos',
|
|
data: ['restaurante_id' => $restaurante_id],
|
|
);
|
|
|
|
$data = $movimientos->get()
|
|
->skip($paginate['from'] - 1)
|
|
->take($paginate['per_page'])
|
|
->all();
|
|
|
|
return response()->json([
|
|
'pagination' => $paginate,
|
|
'data' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Obtiene de forma paginada los movimientos de un ingrediente
|
|
*/
|
|
public function movimientos_ingrediente(Request $request, $restaurante_id, $ingrediente_id) {
|
|
app(UuidService::class)->validOrFail($restaurante_id);
|
|
$restaurante = Restaurante::findOrFail($restaurante_id);
|
|
|
|
$movimientos = $restaurante->bodegaMovimientos()
|
|
->where('ingrediente_id', $ingrediente_id)
|
|
->with('ingrediente');
|
|
|
|
$paginate = app(PaginatorService::class)->paginate(
|
|
perPage: $request->input('per_page', 15),
|
|
page: $request->input('page', 1),
|
|
total: $movimientos->count(),
|
|
route: 'bodega.movimientos',
|
|
data: ['restaurante_id' => $restaurante_id],
|
|
);
|
|
|
|
$data = $movimientos->get()
|
|
->skip($paginate['from'] - 1)
|
|
->take($paginate['per_page'])
|
|
->all();
|
|
|
|
return response()->json([
|
|
'pagination' => $paginate,
|
|
'data' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Obtiene de forma paginada el estado actual de la bodega
|
|
*/
|
|
public function actual(Request $request, $restaurante_id) {
|
|
app(UuidService::class)->validOrFail($restaurante_id);
|
|
$restaurante = Restaurante::findOrFail($restaurante_id);
|
|
|
|
$actual = $restaurante->bodegaActual()->with('ingrediente');
|
|
|
|
$paginate = app(PaginatorService::class)->paginate(
|
|
perPage: $request->input('per_page', 15),
|
|
page: $request->input('page', 1),
|
|
total: $actual->count(),
|
|
route: 'bodega.actual',
|
|
data: ['restaurante_id' => $restaurante_id],
|
|
);
|
|
|
|
$data = $actual->get()
|
|
->skip($paginate['from'] - 1)
|
|
->take($paginate['per_page'])
|
|
->all();
|
|
|
|
return response()->json([
|
|
'pagination' => $paginate,
|
|
'data' => $data
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Obtiene el estado actual de un ingrediente
|
|
*/
|
|
public function actual_ingrediente(Request $request, $restaurante_id, $ingrediente_id) {
|
|
app(UuidService::class)->validOrFail($restaurante_id);
|
|
$restaurante = Restaurante::findOrFail($restaurante_id);
|
|
|
|
$actual = $restaurante->bodegaActual()
|
|
->where('ingrediente_id', $ingrediente_id)
|
|
->with('ingrediente')
|
|
->first();
|
|
|
|
return response()->json($actual);
|
|
}
|
|
}
|