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() {
|
public function cajas() {
|
||||||
return $this->hasMany(Caja::class, 'restaurante_id');
|
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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,5 +88,10 @@ $router->group(['prefix' => 'api/v1', 'middleware' => ['auth', 'log_endpoint']],
|
|||||||
$router->post( '/{restaurante_id}/compras/{id}/factura', ['as' => 'factura.create', 'uses' => 'FacturasController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
|
$router->post( '/{restaurante_id}/compras/{id}/factura', ['as' => 'factura.create', 'uses' => 'FacturasController@create', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
|
||||||
$router->put( '/{restaurante_id}/compras/{id}/factura', ['as' => 'factura.update', 'uses' => 'FacturasController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
|
$router->put( '/{restaurante_id}/compras/{id}/factura', ['as' => 'factura.update', 'uses' => 'FacturasController@update', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
|
||||||
$router->delete('/{restaurante_id}/compras/{id}/factura', ['as' => 'factura.delete', 'uses' => 'FacturasController@delete', 'middleware' => ['role:admin|global_admin', 'in_restaurante']]);
|
$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/egresos', ['as' => 'bodega.egresos', 'uses' => 'BodegaController@egresos', 'middleware' => ['in_restaurante']]);
|
||||||
|
$router->get( '/{restaurante_id}/bodega/movimientos', ['as' => 'bodega.movimientos', 'uses' => 'BodegaController@movimientos', 'middleware' => ['in_restaurante']]);
|
||||||
|
$router->get( '/{restaurante_id}/bodega/actual', ['as' => 'bodega.actual', 'uses' => 'BodegaController@actual', 'middleware' => ['in_restaurante']]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -334,8 +334,8 @@ create table bodega_egresos
|
|||||||
(
|
(
|
||||||
unidades numeric not null,
|
unidades numeric not null,
|
||||||
fecha timestamptz not null,
|
fecha timestamptz not null,
|
||||||
ingrediente_id uuid references ingredientes,
|
ingrediente_id uuid not null,
|
||||||
restaurante_id uuid references restaurantes,
|
restaurante_id uuid not null,
|
||||||
created_at timestamptz not null default current_timestamp,
|
created_at timestamptz not null default current_timestamp,
|
||||||
updated_at timestamptz not null default current_timestamp,
|
updated_at timestamptz not null default current_timestamp,
|
||||||
deleted_at timestamptz
|
deleted_at timestamptz
|
||||||
@@ -345,8 +345,8 @@ create table bodega_ingresos
|
|||||||
(
|
(
|
||||||
unidades numeric not null,
|
unidades numeric not null,
|
||||||
fecha timestamptz not null,
|
fecha timestamptz not null,
|
||||||
ingrediente_id uuid references ingredientes,
|
ingrediente_id uuid not null,
|
||||||
restaurante_id uuid references restaurantes,
|
restaurante_id uuid not null,
|
||||||
created_at timestamptz not null default current_timestamp,
|
created_at timestamptz not null default current_timestamp,
|
||||||
updated_at timestamptz not null default current_timestamp,
|
updated_at timestamptz not null default current_timestamp,
|
||||||
deleted_at timestamptz
|
deleted_at timestamptz
|
||||||
|
|||||||
11
database/modifications/04-remove-references-from-bodega.sql
Normal file
11
database/modifications/04-remove-references-from-bodega.sql
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
alter table bodega_egresos drop constraint bodega_egresos_ingrediente_id_fkey;
|
||||||
|
alter table bodega_egresos drop constraint bodega_egresos_restaurante_id_fkey;
|
||||||
|
|
||||||
|
alter table bodega_ingresos drop constraint bodega_ingresos_ingrediente_id_fkey;
|
||||||
|
alter table bodega_ingresos drop constraint bodega_ingresos_restaurante_id_fkey;
|
||||||
|
|
||||||
|
alter table bodega_ingresos alter column restaurante_id set not null;
|
||||||
|
alter table bodega_ingresos alter column ingrediente_id set not null;
|
||||||
|
|
||||||
|
alter table bodega_egresos alter column restaurante_id set not null;
|
||||||
|
alter table bodega_egresos alter column ingrediente_id set not null;
|
||||||
Reference in New Issue
Block a user