Modelo de base de datos en lumen
This commit is contained in:
17
backend/app/Models/Administrador.php
Normal file
17
backend/app/Models/Administrador.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Administrador extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'administradores';
|
||||
|
||||
public function usuario() {
|
||||
return $this->belongsTo(Usuario::class);
|
||||
}
|
||||
}
|
||||
21
backend/app/Models/BoletaElectronica.php
Normal file
21
backend/app/Models/BoletaElectronica.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class BoletaElectronica extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'boletas_electronicas';
|
||||
|
||||
public function venta() {
|
||||
return $this->belongsTo(Venta::class);
|
||||
}
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
}
|
||||
21
backend/app/Models/BoletaExenta.php
Normal file
21
backend/app/Models/BoletaExenta.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class BoletaExenta extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'boletas_exentas';
|
||||
|
||||
public function venta() {
|
||||
return $this->belongsTo(Venta::class);
|
||||
}
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
}
|
||||
25
backend/app/Models/CanalVenta.php
Normal file
25
backend/app/Models/CanalVenta.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class CanalVenta extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'canales_venta';
|
||||
|
||||
public function tipoCanal() {
|
||||
return $this->belongsTo(TipoCanal::class);
|
||||
}
|
||||
|
||||
public function sector() {
|
||||
return $this->belongsTo(Sector::class);
|
||||
}
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
}
|
||||
17
backend/app/Models/Categoria.php
Normal file
17
backend/app/Models/Categoria.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Categoria extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'categorias';
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
}
|
||||
29
backend/app/Models/Compra.php
Normal file
29
backend/app/Models/Compra.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Compra extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'compras';
|
||||
|
||||
public function compraIngredientes() {
|
||||
return $this->hasMany(CompraIngrediente::class);
|
||||
}
|
||||
|
||||
public function facturas() {
|
||||
return $this->hasMany(Factura::class);
|
||||
}
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
|
||||
public function proveedor() {
|
||||
return $this->belongsTo(Proveedor::class);
|
||||
}
|
||||
}
|
||||
21
backend/app/Models/CompraIngrediente.php
Normal file
21
backend/app/Models/CompraIngrediente.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class CompraIngrediente extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'compra_ingredientes';
|
||||
|
||||
public function ingrediente() {
|
||||
return $this->belongsTo(Ingrediente::class);
|
||||
}
|
||||
|
||||
public function compra() {
|
||||
return $this->belongsTo(Compra::class);
|
||||
}
|
||||
}
|
||||
13
backend/app/Models/EstadoProduccion.php
Normal file
13
backend/app/Models/EstadoProduccion.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class EstadoProduccion extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'estados_produccion';
|
||||
}
|
||||
17
backend/app/Models/Factura.php
Normal file
17
backend/app/Models/Factura.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Factura extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'facturas';
|
||||
|
||||
public function compra() {
|
||||
return $this->belongsTo(Compra::class);
|
||||
}
|
||||
}
|
||||
22
backend/app/Models/Ingrediente.php
Normal file
22
backend/app/Models/Ingrediente.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Ingrediente extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'ingredientes';
|
||||
|
||||
|
||||
public function recetas() {
|
||||
return $this->hasMany(Receta::class, 'ingrediente_id');
|
||||
}
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
}
|
||||
17
backend/app/Models/Mesero.php
Normal file
17
backend/app/Models/Mesero.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Mesero extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'meseros';
|
||||
|
||||
public function usuario() {
|
||||
return $this->belongsTo(Usuario::class);
|
||||
}
|
||||
}
|
||||
29
backend/app/Models/Producto.php
Normal file
29
backend/app/Models/Producto.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Producto extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'productos';
|
||||
|
||||
public function recetas() {
|
||||
return $this->hasMany(Receta::class, 'producto_id');
|
||||
}
|
||||
|
||||
public function categoria() {
|
||||
return $this->belongsTo(Categoria::class);
|
||||
}
|
||||
|
||||
public function zonaProduccion() {
|
||||
return $this->belongsTo(ZonaProduccion::class);
|
||||
}
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
}
|
||||
21
backend/app/Models/Productor.php
Normal file
21
backend/app/Models/Productor.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Productor extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'productores';
|
||||
|
||||
public function usuario() {
|
||||
return $this->belongsTo(Usuario::class);
|
||||
}
|
||||
|
||||
public function zonaProduccion() {
|
||||
return $this->belongsTo(ZonaProduccion::class);
|
||||
}
|
||||
}
|
||||
17
backend/app/Models/Proveedor.php
Normal file
17
backend/app/Models/Proveedor.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Proveedor extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'proveedores';
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
}
|
||||
17
backend/app/Models/Recaudador.php
Normal file
17
backend/app/Models/Recaudador.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Recaudador extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'recaudadores';
|
||||
|
||||
public function usuario() {
|
||||
return $this->belongsTo(Usuario::class);
|
||||
}
|
||||
}
|
||||
20
backend/app/Models/Receta.php
Normal file
20
backend/app/Models/Receta.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Receta extends Model {
|
||||
use UuidPrimaryKey;
|
||||
|
||||
protected $table = 'recetas';
|
||||
|
||||
public function ingrediente() {
|
||||
return $this->belongsTo(Ingrediente::class);
|
||||
}
|
||||
|
||||
public function producto() {
|
||||
return $this->belongsTo(Producto::class);
|
||||
}
|
||||
}
|
||||
17
backend/app/Models/Restaurante.php
Normal file
17
backend/app/Models/Restaurante.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Restaurante extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'restaurantes';
|
||||
|
||||
public function usuarios() {
|
||||
return $this->belongsToMany(Usuario::class, 'usuarios_restaurantes', 'restaurante_id', 'usuario_id');
|
||||
}
|
||||
}
|
||||
17
backend/app/Models/Sector.php
Normal file
17
backend/app/Models/Sector.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Sector extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'sectores';
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
}
|
||||
13
backend/app/Models/TipoCanal.php
Normal file
13
backend/app/Models/TipoCanal.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class TipoCanal extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'tipos_canal';
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Laravel\Lumen\Auth\Authorizable;
|
||||
|
||||
class User extends Model implements AuthenticatableContract, AuthorizableContract
|
||||
{
|
||||
use Authenticatable, Authorizable, HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes excluded from the model's JSON form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
}
|
||||
17
backend/app/Models/Usuario.php
Normal file
17
backend/app/Models/Usuario.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Usuario extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'usuarios';
|
||||
|
||||
public function restaurantes() {
|
||||
return $this->belongsToMany(Restaurante::class, 'usuarios_restaurantes', 'usuario_id', 'restaurante_id');
|
||||
}
|
||||
}
|
||||
29
backend/app/Models/Venta.php
Normal file
29
backend/app/Models/Venta.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Venta extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'ventas';
|
||||
|
||||
public function mesero() {
|
||||
return $this->belongsTo(Mesero::class);
|
||||
}
|
||||
|
||||
public function canal() {
|
||||
return $this->belongsTo(CanalVenta::class);
|
||||
}
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
|
||||
public function productos() {
|
||||
return $this->hasMany(VentaProducto::class);
|
||||
}
|
||||
}
|
||||
25
backend/app/Models/VentaProducto.php
Normal file
25
backend/app/Models/VentaProducto.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class VentaProducto extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'venta_productos';
|
||||
|
||||
public function venta() {
|
||||
return $this->belongsTo(Venta::class);
|
||||
}
|
||||
|
||||
public function producto() {
|
||||
return $this->belongsTo(Producto::class);
|
||||
}
|
||||
|
||||
public function estado() {
|
||||
return $this->belongsTo(EstadoProduccion::class);
|
||||
}
|
||||
}
|
||||
17
backend/app/Models/ZonaProduccion.php
Normal file
17
backend/app/Models/ZonaProduccion.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\UuidPrimaryKey;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class ZonaProduccion extends Model {
|
||||
use UuidPrimaryKey, SoftDeletes;
|
||||
|
||||
protected $table = 'zonas_produccion';
|
||||
|
||||
public function restaurante() {
|
||||
return $this->belongsTo(Restaurante::class);
|
||||
}
|
||||
}
|
||||
16
backend/app/Traits/UuidPrimaryKey.php
Normal file
16
backend/app/Traits/UuidPrimaryKey.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait UuidPrimaryKey {
|
||||
|
||||
public function getKeyType()
|
||||
{
|
||||
return 'string';
|
||||
}
|
||||
|
||||
public function getIncrementing()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -23,9 +23,9 @@ $app = new Laravel\Lumen\Application(
|
||||
dirname(__DIR__)
|
||||
);
|
||||
|
||||
// $app->withFacades();
|
||||
$app->withFacades();
|
||||
|
||||
// $app->withEloquent();
|
||||
$app->withEloquent();
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
@@ -76,9 +76,9 @@ $app->configure('app');
|
||||
// App\Http\Middleware\ExampleMiddleware::class
|
||||
// ]);
|
||||
|
||||
$app->routeMiddleware([
|
||||
'auth' => App\Http\Middleware\Auth0Middleware::class,
|
||||
]);
|
||||
$app->routeMiddleware([
|
||||
'auth' => App\Http\Middleware\Auth0Middleware::class,
|
||||
]);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
|
||||
/** @var \Laravel\Lumen\Routing\Router $router */
|
||||
|
||||
/*
|
||||
@@ -16,8 +17,8 @@
|
||||
$router->get('/', function () use ($router) {
|
||||
return 'Public View';
|
||||
});
|
||||
$router->group(['prefix' => 'api/v1', 'middleware' => 'auth'], function () use ($router){
|
||||
$router->group(['prefix' => 'api/v1', 'middleware' => 'auth'], function () use ($router) {
|
||||
$router->get('/', function () use ($router) {
|
||||
return 'Protected View';
|
||||
return \App\Models\Venta::with('productos')->get();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -108,22 +108,22 @@ values ('2021-01-01'::date, (select id from proveedores where nombre = 'Coca-Col
|
||||
('2021-02-01'::date, (select id from proveedores where nombre = 'Santa Isabel'), (select id from restaurantes where nombre = 'Todo Rico Restaurant')),
|
||||
('2021-01-01'::date, (select id from proveedores where nombre = 'Coca-Cola'), (select id from restaurantes where nombre = 'Todo Rico Restaurant'));
|
||||
|
||||
insert into compra_ingredientes (unidades, monto_unitario_bruto, iva, ila, monto_unitario_neto, compra_id, ingrediente_id)
|
||||
values (20, 500, 500 * .19, 0, 500 * 1.19, (select id from compras limit 1 offset 0), (select id from ingredientes where nombre = 'Coca-Cola')),
|
||||
(50, 1000, 1000 * .19, 0, 1000 * 1.19, (select id from compras limit 1 offset 1), (select id from ingredientes where nombre = 'Chuletas')),
|
||||
(25, 1000, 1000 * .19, 0, 1000 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Papas')),
|
||||
(10, 500, 500 * .19, 0, 500 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Papas Pre-Fritas')),
|
||||
(5, 300, 300 * .19, 0, 300 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Sal')),
|
||||
(10, 2000, 2000 * .19, 0, 2000 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Mantequilla')),
|
||||
(10, 700, 700 * .19, 0, 700 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Leche')),
|
||||
(50, 1000, 1000 * .19, 0, 1000 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Aceite')),
|
||||
(20, 500, 500 * .19, 0, 500 * 1.19, (select id from compras limit 1 offset 3), (select id from ingredientes where nombre = 'Coca-Cola'));
|
||||
insert into compra_ingredientes (unidades, monto_unitario_bruto, monto_unitario_neto, compra_id, ingrediente_id)
|
||||
values (20, 500, 500 * 1.19, (select id from compras limit 1 offset 0), (select id from ingredientes where nombre = 'Coca-Cola')),
|
||||
(50, 1000, 1000 * 1.19, (select id from compras limit 1 offset 1), (select id from ingredientes where nombre = 'Chuletas')),
|
||||
(25, 1000, 1000 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Papas')),
|
||||
(10, 500, 500 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Papas Pre-Fritas')),
|
||||
(5, 300, 300 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Sal')),
|
||||
(10, 2000, 2000 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Mantequilla')),
|
||||
(10, 700, 700 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Leche')),
|
||||
(50, 1000, 1000 * 1.19, (select id from compras limit 1 offset 2), (select id from ingredientes where nombre = 'Aceite')),
|
||||
(20, 500, 500 * 1.19, (select id from compras limit 1 offset 3), (select id from ingredientes where nombre = 'Coca-Cola'));
|
||||
|
||||
insert into facturas (numero, monto_bruto, iva, ila, monto_neto, fecha_emision, fecha_vencimiento, compra_id)
|
||||
values ('1', 500 * 20, 500 * 20 * .19, 0, 500 * 20 * 1.19, '2021-01-01'::date, '2021-01-30'::date, (select id from compras limit 1 offset 0)),
|
||||
('1', 1000 * 50, 1000 * 50 * .19, 0, 1000 * 50 * 1.19, '2021-02-01'::date, '2021-02-28'::date, (select id from compras limit 1 offset 1)),
|
||||
('1', 108500, 20615, 0, 129115, '2021-02-10'::date, '2021-02-28'::date, (select id from compras limit 1 offset 2)),
|
||||
('1', 500 * 20, 500 * 20 * .19, 0, 500 * 20 * 1.19, '2021-01-01'::date, '2021-01-30'::date, (select id from compras limit 1 offset 0));
|
||||
insert into facturas (numero, monto_bruto, monto_neto, fecha_emision, fecha_vencimiento, compra_id)
|
||||
values ('1', 500 * 20, 500 * 20 * 1.19, '2021-01-01'::date, '2021-01-30'::date, (select id from compras limit 1 offset 0)),
|
||||
('1', 1000 * 50, 1000 * 50 * 1.19, '2021-02-01'::date, '2021-02-28'::date, (select id from compras limit 1 offset 1)),
|
||||
('1', 108500, 129115, '2021-02-10'::date, '2021-02-28'::date, (select id from compras limit 1 offset 2)),
|
||||
('1', 500 * 20, 500 * 20 * 1.19, '2021-01-01'::date, '2021-01-30'::date, (select id from compras limit 1 offset 0));
|
||||
|
||||
-----------------------------------
|
||||
--- Creando ventas para descontar del inventario
|
||||
|
||||
@@ -12,7 +12,6 @@ create table categorias (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index categorias_restaurante_id on categorias (restaurante_id);
|
||||
|
||||
create table zonas_produccion (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -22,7 +21,6 @@ create table zonas_produccion (
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
|
||||
);
|
||||
create index zonas_produccion_restaurante_id on zonas_produccion (restaurante_id);
|
||||
|
||||
create table usuarios (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -45,8 +43,6 @@ create table productores (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index productores_usuario_id on productores (usuario_id);
|
||||
create index productores_zona_produccion_id on productores (zona_produccion_id);
|
||||
|
||||
create table recaudadores (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -54,7 +50,6 @@ create table recaudadores (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index recaudadores_usuario_id on recaudadores (usuario_id);
|
||||
|
||||
create table meseros (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -62,7 +57,6 @@ create table meseros (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index meseros_usuario_id on meseros (usuario_id);
|
||||
|
||||
create table administradores (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -70,7 +64,6 @@ create table administradores (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index administradores_usuario_id on administradores (usuario_id);
|
||||
|
||||
create table ingredientes (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -80,7 +73,6 @@ create table ingredientes (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index ingredientes_restaurante_id on ingredientes (restaurante_id);
|
||||
|
||||
create table productos (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -92,9 +84,6 @@ create table productos (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index productos_categoria_id on productos (categoria_id);
|
||||
create index productos_zona_produccion_id on productos (zona_produccion_id);
|
||||
create index productos_restaurante_id on productos (restaurante_id);
|
||||
|
||||
create table recetas (
|
||||
producto_id uuid references productos,
|
||||
@@ -116,7 +105,6 @@ create table proveedores (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index proveedores_restaurante_id on proveedores (restaurante_id);
|
||||
|
||||
create table compras (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -126,8 +114,6 @@ create table compras (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index compras_proveedor_id on compras (proveedor_id);
|
||||
create index compras_restaurante_id on compras (restaurante_id);
|
||||
|
||||
create table facturas (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -142,22 +128,17 @@ create table facturas (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index facturas_compra_id on facturas (compra_id);
|
||||
|
||||
create table compra_ingredientes (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
unidades numeric not null,
|
||||
monto_unitario_bruto bigint not null,
|
||||
iva bigint not null default 0,
|
||||
ila bigint not null default 0,
|
||||
monto_unitario_neto bigint not null,
|
||||
compra_id uuid references compras,
|
||||
ingrediente_id uuid references ingredientes,
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index compra_ingredientes_compra_id on compra_ingredientes (compra_id);
|
||||
create index compra_ingredientes_ingrediente_id on compra_ingredientes (ingrediente_id);
|
||||
|
||||
create table sectores (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -166,7 +147,6 @@ create table sectores (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index sectores_restaurante_id on sectores (restaurante_id);
|
||||
|
||||
create table tipos_canal (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -184,9 +164,6 @@ create table canales_venta (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index canales_venta_sector_id on canales_venta (sector_id);
|
||||
create index canales_venta_tipo_canal_id on canales_venta (tipo_canal_id);
|
||||
create index canales_venta_restaurante_id on canales_venta (restaurante_id);
|
||||
|
||||
create table ventas (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -197,9 +174,6 @@ create table ventas (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index ventas_mesero_id on ventas (mesero_id);
|
||||
create index ventas_canal_id on ventas (canal_id);
|
||||
create index ventas_restaurante_id on ventas (restaurante_id);
|
||||
|
||||
create table boletas_electronicas (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -209,8 +183,6 @@ create table boletas_electronicas (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index boletas_electronicas_venta_id on boletas_electronicas (venta_id);
|
||||
create index boletas_electronicas_restaurante_id on boletas_electronicas (restaurante_id);
|
||||
|
||||
create table boletas_exentas (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -219,8 +191,6 @@ create table boletas_exentas (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
create index boletas_exentas_venta_id on boletas_exentas (venta_id);
|
||||
create index boletas_exentas_restaurante_id on boletas_exentas (restaurante_id);
|
||||
|
||||
create table estados_produccion (
|
||||
id uuid primary key default gen_random_uuid(),
|
||||
@@ -239,167 +209,42 @@ create table venta_productos (
|
||||
inserted_at timestamptz not null default current_timestamp,
|
||||
updated_at timestamptz not null default current_timestamp
|
||||
);
|
||||
|
||||
------------------------------------
|
||||
--- Indexes para todas las referencias
|
||||
------------------------------------
|
||||
create index categorias_restaurante_id on categorias (restaurante_id);
|
||||
create index zonas_produccion_restaurante_id on zonas_produccion (restaurante_id);
|
||||
create index productores_usuario_id on productores (usuario_id);
|
||||
create index productores_zona_produccion_id on productores (zona_produccion_id);
|
||||
create index recaudadores_usuario_id on recaudadores (usuario_id);
|
||||
create index meseros_usuario_id on meseros (usuario_id);
|
||||
create index administradores_usuario_id on administradores (usuario_id);
|
||||
create index ingredientes_restaurante_id on ingredientes (restaurante_id);
|
||||
create index productos_categoria_id on productos (categoria_id);
|
||||
create index productos_zona_produccion_id on productos (zona_produccion_id);
|
||||
create index productos_restaurante_id on productos (restaurante_id);
|
||||
create index proveedores_restaurante_id on proveedores (restaurante_id);
|
||||
create index compras_proveedor_id on compras (proveedor_id);
|
||||
create index compras_restaurante_id on compras (restaurante_id);
|
||||
create index facturas_compra_id on facturas (compra_id);
|
||||
create index compra_ingredientes_compra_id on compra_ingredientes (compra_id);
|
||||
create index compra_ingredientes_ingrediente_id on compra_ingredientes (ingrediente_id);
|
||||
create index sectores_restaurante_id on sectores (restaurante_id);
|
||||
create index canales_venta_sector_id on canales_venta (sector_id);
|
||||
create index canales_venta_tipo_canal_id on canales_venta (tipo_canal_id);
|
||||
create index canales_venta_restaurante_id on canales_venta (restaurante_id);
|
||||
create index ventas_mesero_id on ventas (mesero_id);
|
||||
create index ventas_canal_id on ventas (canal_id);
|
||||
create index ventas_restaurante_id on ventas (restaurante_id);
|
||||
create index boletas_electronicas_venta_id on boletas_electronicas (venta_id);
|
||||
create index boletas_electronicas_restaurante_id on boletas_electronicas (restaurante_id);
|
||||
create index boletas_exentas_venta_id on boletas_exentas (venta_id);
|
||||
create index boletas_exentas_restaurante_id on boletas_exentas (restaurante_id);
|
||||
create index venta_productos_venta_id on venta_productos (venta_id);
|
||||
create index venta_productos_producto_id on venta_productos (producto_id);
|
||||
create index venta_productos_estado_id on venta_productos (estado_id);
|
||||
|
||||
------------------------------------
|
||||
--- Triggers para update
|
||||
------------------------------------
|
||||
|
||||
CREATE OR REPLACE FUNCTION trigger_set_timestamp()
|
||||
RETURNS TRIGGER AS
|
||||
$$
|
||||
BEGIN
|
||||
NEW.updated_at = current_timestamp;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
create trigger trigger_update_restaurantes
|
||||
before update
|
||||
on restaurantes
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_categorias
|
||||
before update
|
||||
on categorias
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_zonas_produccion
|
||||
before update
|
||||
on zonas_produccion
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_usuarios
|
||||
before update
|
||||
on usuarios
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_usuarios_restaurantes
|
||||
before update
|
||||
on usuarios_restaurantes
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_productores
|
||||
before update
|
||||
on productores
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_recaudadores
|
||||
before update
|
||||
on recaudadores
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_meseros
|
||||
before update
|
||||
on meseros
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_administradores
|
||||
before update
|
||||
on administradores
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_ingredientes
|
||||
before update
|
||||
on ingredientes
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_productos
|
||||
before update
|
||||
on productos
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_recetas
|
||||
before update
|
||||
on recetas
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_proveedores
|
||||
before update
|
||||
on proveedores
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_compras
|
||||
before update
|
||||
on compras
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_facturas
|
||||
before update
|
||||
on facturas
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_compra_ingredientes
|
||||
before update
|
||||
on compra_ingredientes
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_sectores
|
||||
before update
|
||||
on sectores
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_tipos_canal
|
||||
before update
|
||||
on tipos_canal
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_canales_venta
|
||||
before update
|
||||
on canales_venta
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_ventas
|
||||
before update
|
||||
on ventas
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_boletas_electronicas
|
||||
before update
|
||||
on boletas_electronicas
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_boletas_exentas
|
||||
before update
|
||||
on boletas_exentas
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_estados_produccion
|
||||
before update
|
||||
on estados_produccion
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
create trigger trigger_update_venta_productos
|
||||
before update
|
||||
on venta_productos
|
||||
for each row
|
||||
execute procedure trigger_set_timestamp();
|
||||
|
||||
------------------------------------
|
||||
--- Views para crear la bodega
|
||||
------------------------------------
|
||||
@@ -414,7 +259,6 @@ from ventas
|
||||
join venta_productos on ventas.id = venta_productos.venta_id
|
||||
join productos on venta_productos.producto_id = productos.id
|
||||
join recetas on productos.id = recetas.producto_id;
|
||||
|
||||
--- View para obtener la lista de ingresos a bodega
|
||||
create view bodega_ingresos as
|
||||
select compra_ingredientes.ingrediente_id as ingrediente_id,
|
||||
|
||||
Reference in New Issue
Block a user