Controlador de bodega
This commit is contained in:
126
backend/app/Http/Controllers/BodegaController.php
Normal file
126
backend/app/Http/Controllers/BodegaController.php
Normal file
@@ -0,0 +1,126 @@
|
||||
<?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 productos
|
||||
*/
|
||||
public function ingresos(Request $request, $restaurante_id) {
|
||||
app(UuidService::class)->validOrFail($restaurante_id);
|
||||
$restaurante = Restaurante::findOrFail($restaurante_id);
|
||||
|
||||
$ingresos = $restaurante->bodegaIngresos()->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 productos
|
||||
*/
|
||||
public function egresos(Request $request, $restaurante_id) {
|
||||
app(UuidService::class)->validOrFail($restaurante_id);
|
||||
$restaurante = Restaurante::findOrFail($restaurante_id);
|
||||
|
||||
$egresos = $restaurante->bodegaEgresos();
|
||||
|
||||
$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 productos
|
||||
*/
|
||||
public function movimientos(Request $request, $restaurante_id) {
|
||||
app(UuidService::class)->validOrFail($restaurante_id);
|
||||
$restaurante = Restaurante::findOrFail($restaurante_id);
|
||||
|
||||
$movimientos = $restaurante->bodegaMovimientos();
|
||||
|
||||
$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();
|
||||
|
||||
$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
|
||||
]);
|
||||
}
|
||||
}
|
||||
20
backend/app/Models/BodegaActual.php
Normal file
20
backend/app/Models/BodegaActual.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class BodegaActual extends Model {
|
||||
|
||||
protected $table = 'bodega_actual';
|
||||
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
|
||||
public function ingrediente() {
|
||||
return $this->belongsTo(Ingrediente::class);
|
||||
}
|
||||
}
|
||||
20
backend/app/Models/BodegaEgreso.php
Normal file
20
backend/app/Models/BodegaEgreso.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class BodegaEgreso extends Model {
|
||||
|
||||
protected $table = 'bodega_egresos';
|
||||
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
|
||||
public function ingrediente() {
|
||||
return $this->belongsTo(Ingrediente::class);
|
||||
}
|
||||
}
|
||||
20
backend/app/Models/BodegaIngreso.php
Normal file
20
backend/app/Models/BodegaIngreso.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class BodegaIngreso extends Model {
|
||||
|
||||
protected $table = 'bodega_ingresos';
|
||||
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
|
||||
public function ingrediente() {
|
||||
return $this->belongsTo(Ingrediente::class);
|
||||
}
|
||||
}
|
||||
20
backend/app/Models/BodegaMovimiento.php
Normal file
20
backend/app/Models/BodegaMovimiento.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class BodegaMovimiento extends Model {
|
||||
|
||||
protected $table = 'bodega_movimientos';
|
||||
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
|
||||
public function ingrediente() {
|
||||
return $this->belongsTo(Ingrediente::class);
|
||||
}
|
||||
}
|
||||
@@ -73,4 +73,20 @@ class Restaurante extends Model {
|
||||
public function cajas() {
|
||||
return $this->hasMany(Caja::class, 'restaurante_id');
|
||||
}
|
||||
|
||||
public function bodegaIngresos() {
|
||||
return $this->hasMany(BodegaIngreso::class, 'restaurante_id');
|
||||
}
|
||||
|
||||
public function bodegaEgresos() {
|
||||
return $this->hasMany(BodegaEgreso::class, 'restaurante_id');
|
||||
}
|
||||
|
||||
public function bodegaMovimientos() {
|
||||
return $this->hasMany(BodegaMovimiento::class, 'restaurante_id');
|
||||
}
|
||||
|
||||
public function bodegaActual() {
|
||||
return $this->hasMany(BodegaActual::class, 'restaurante_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user