Agregando endpoint para consultar el estado de distintos ingredientes

This commit is contained in:
2021-07-20 13:42:22 -04:00
parent 448856e627
commit 02871ab73b
2 changed files with 119 additions and 8 deletions

View File

@@ -13,13 +13,15 @@ use Ramsey\Uuid\Uuid;
class BodegaController extends Controller {
/**
* Obtiene de forma paginada los ingresos de productos
* 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()->with('ingrediente');
$ingresos = $restaurante->bodegaIngresos()
->orderBy('fecha', 'desc')
->with('ingrediente');
$paginate = app(PaginatorService::class)->paginate(
perPage: $request->input('per_page', 15),
@@ -41,7 +43,37 @@ class BodegaController extends Controller {
}
/**
* Obtiene de forma paginada los egresos de productos
* 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);
@@ -69,7 +101,37 @@ class BodegaController extends Controller {
}
/**
* Obtiene de forma paginada los movimientos de productos
* 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);
@@ -96,6 +158,36 @@ class BodegaController extends Controller {
]);
}
/**
* 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
*/
@@ -123,4 +215,19 @@ class BodegaController extends Controller {
'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);
}
}

View File

@@ -90,8 +90,12 @@ $router->group(['prefix' => 'api/v1', 'middleware' => ['auth', 'log_endpoint']],
$router->delete('/{restaurante_id}/compras/{id}/factura', ['as' => 'factura.delete', 'uses' => 'FacturasController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
$router->get( '/{restaurante_id}/bodega/ingresos', ['as' => 'bodega.ingresos', 'uses' => 'BodegaController@ingresos', 'middleware' => ['in_restaurante']]);
$router->get( '/{restaurante_id}/bodega/ingresos/{ingrediente_id}', ['as' => 'bodega.ingresos_ingrediente', 'uses' => 'BodegaController@ingresos_ingrediente', 'middleware' => ['in_restaurante']]);
$router->get( '/{restaurante_id}/bodega/egresos', ['as' => 'bodega.egresos', 'uses' => 'BodegaController@egresos', 'middleware' => ['in_restaurante']]);
$router->get( '/{restaurante_id}/bodega/egresos/{ingrediente_id}', ['as' => 'bodega.egresos_ingrediente', 'uses' => 'BodegaController@egresos_ingrediente', 'middleware' => ['in_restaurante']]);
$router->get( '/{restaurante_id}/bodega/movimientos', ['as' => 'bodega.movimientos', 'uses' => 'BodegaController@movimientos', 'middleware' => ['in_restaurante']]);
$router->get( '/{restaurante_id}/bodega/movimientos/{ingrediente_id}', ['as' => 'bodega.movimientos_ingrediente', 'uses' => 'BodegaController@movimientos_ingrediente', 'middleware' => ['in_restaurante']]);
$router->get( '/{restaurante_id}/bodega/actual', ['as' => 'bodega.actual', 'uses' => 'BodegaController@actual', 'middleware' => ['in_restaurante']]);
$router->get( '/{restaurante_id}/bodega/actual/{ingrediente_id}', ['as' => 'bodega.actual_ingrediente', 'uses' => 'BodegaController@actual_ingrediente', 'middleware' => ['in_restaurante']]);
});
});