feature/columna-totales #4

Open
atasistro wants to merge 46 commits from feature/columna-totales into master
25 changed files with 434 additions and 9132 deletions

2
.gitignore vendored
View File

@ -18,3 +18,5 @@ yarn-error.log
/.fleet
/.idea
/.vscode
/resources/csv/exports/*
/composer.lock

View File

@ -2,8 +2,14 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Utils\TransporteUtils;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use League\Csv\CannotInsertRecord;
use League\Csv\Writer;
class Barrio extends Model
{
@ -13,7 +19,7 @@ class Barrio extends Model
* @var array<int, string>
*/
protected $fillable = [
'name',
'nombre',
];
/**
@ -31,4 +37,108 @@ public function pedidos(): HasMany
{
return $this->hasMany(Pedido::class);
}
public function crearPedido(string $nombre) : Pedido {
return $this->pedidos()->create(['nombre' => $nombre]);
}
/**
* Devuelve una query, para obtener el resultado agregarle ->get().
* La query devuelve objetos con todos los atributos de un producto, seguidos
* de la cantidad de ese producto pedida entre todos los pedidos del barrio y
* el costo total de dicha cantidad.
*/
public function productosPedidos() {
return DB::table('productos')
->join('pedido_producto', 'productos.id', '=', 'pedido_producto.producto_id')
->join('pedidos', 'pedidos.id', '=', 'pedido_producto.pedido_id')
->where(['pedidos.barrio_id' => $this->id, 'pedidos.pagado' => true])
->select('productos.*',
DB::raw('SUM(pedido_producto.cantidad) as cantidad'),
DB::raw('SUM(pedido_producto.cantidad * productos.precio) as total'))
->groupBy('productos.id');
}
public function totalARecaudar() : float {
return $this->pedidos()->where(['pagado' => true])->get()->sum(
fn($p) => $p->totalATransferir()
);
}
public function totalATransferir() : float {
return $this->totalProductosConTransporte() + $this->totalBonosDeTransporte();
}
public function totalBonosDeTransporte() : int {
return TransporteUtils::calcularTotal($this->totalProductosConTransporte());
}
public function totalProductosConTransporte(): float
{
return $this->totalProductosIf(fn($p) => $p->pagaTransporte());
}
private function totalProductosIf($predicado) : float {
return $this->productosPedidos()->where($predicado)->get()->sum(
fn($producto) => $producto->total
);
}
/**
* Los productos que pertenecen al barrio.
*/
public function productos(): HasMany
{
return $this->hasMany(Producto::class);
}
public function exportarPedidoACsv() {
if ($this->productosPedidos()->get()->isNotEmpty()) {
$columnaProductos = $this->armarColumnaTotales();
try {
$writer = Writer::createFromPath(resource_path('csv/exports/'.$this->nombre.'.csv'), 'w');
$writer->setDelimiter("|");
$writer->setEnclosure("'");
$writer->insertAll($columnaProductos);
return true;
} catch (CannotInsertRecord $e) {
var_export($e->getRecords());
return false;
}
}
return false;
}
private function armarColumnaTotales() : array {
$columnaProductos = [];
$filasVaciasAgregadas = false;
$productos = $this->productosPedidos()->where(['barrial' => false])->get();
foreach (Categoria::orderBy('id')->get() as $categoria) {
if ($categoria->productos()->where(['barrial' => false])->count() == 0)
continue;
$columnaProductos[] = ['nombre' => $categoria->nombre, 'cantidad' => null];
if ($categoria->nombre == 'TRANSPORTE, BONOS Y FINANCIAMIENTO SORORO')
$columnaProductos[] = ['nombre' => 'Bono de Transporte', 'cantidad' => TransporteUtils::cantidad($this->totalProductosConTransporte())];
if ($categoria->nombre == 'PRODUCTOS DE GESTIÓN MENSTRUAL')
$columnaProductos[] = ['nombre' => '¿Cuántas copas quieren y pueden comprar en el grupo?', 'cantidad' => null];
foreach ($categoria->productos()->orderBy('id')->get() as $producto) {
if ($producto->precio == 0 && !$filasVaciasAgregadas) {
$columnaProductos[] = ['nombre' => '¿Cuántas copas quieren adquirir a través del financiamiento sororo?', 'cantidad' => null];
$filasVaciasAgregadas = true;
}
$columnaProductos[] = ['nombre' => $producto->nombre, 'cantidad' => $this->cantidadPedida($producto->id, $productos)];
}
}
return $columnaProductos;
}
private function cantidadPedida($productoId, $productos) {
return $productos->find($productoId)->cantidad ?? 0;
}
}

View File

@ -2,7 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Model;
class Caracteristica extends Model

View File

@ -2,7 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Model;
class Categoria extends Model
@ -13,7 +13,7 @@ class Categoria extends Model
* @var array<int, string>
*/
protected $fillable = [
'name',
'nombre',
];
/**

View File

@ -2,7 +2,11 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Utils\TransporteUtils;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;
class Pedido extends Model
@ -13,22 +17,90 @@ class Pedido extends Model
* @var array<int, string>
*/
protected $fillable = [
'name',
'nombre', 'pagado', 'terminado'
];
/**
* El barrio al que pertenece el pedido.
*/
public function barrio(): BelongsTo
{
public function barrio(): BelongsTo {
return $this->belongsTo(Barrio::class);
}
public function togglePagado() : bool {
$this->pagado = !$this->pagado;
$this->save();
return $this->pagado;
}
public function toggleTerminado() : bool {
$this->terminado = !$this->terminado;
$this->save();
return $this->terminado;
}
/**
* Los productos que pertenecen al pedido.
*/
public function productos(): BelongsToMany
public function productos(): BelongsToMany {
return $this->belongsToMany(Producto::class)->withPivot(['cantidad']);
}
public function productosConTransporte() : Collection
{
return $this->belongsToMany(Producto::class);
return $this->productos()->where(fn($p) => $p->pagaTransporte())->get();
}
public function agregarProducto(Producto $producto, int $cantidad) : Producto {
$productoEnChismosa = $this->productos()->find($producto->id);
if ($productoEnChismosa) {
$productoEnChismosa->pivot->cantidad += $cantidad;
if ($productoEnChismosa->pivot->cantidad != 0)
$productoEnChismosa->save();
else
$this->quitarProducto($producto);
return $productoEnChismosa;
} else {
$this->productos()->attach($producto, ['cantidad' => $cantidad]);
return $this->productos()->find($producto->id);
}
}
public function quitarProducto(Producto $producto) {
$this->productos()->detach($producto);
}
/**
* El total de los productos del pedido
* sumado al total de los bonos de transporte
*/
public function totalATransferir() : float {
return $this->totalProductos() + $this->totalBonosDeTransporte();
}
/**
* Toma como parámetro una colección de productos
* y devuelve la suma de los totales (precio * cantidad)
* de cada uno.
*
* Si la colección es null o no se pasa ningún parámetro
* se toman todos los productos del pedido.
*/
private function totalProductos($productos = null) {
if (!$productos)
$productos = $this->productos()->get();
return $productos->map(
fn($producto) => $producto->precio * $producto->pivot->cantidad
)->sum();
}
/**
* El total de bonos de transporte del pedido
*/
public function totalBonosDeTransporte() : int {
return TransporteUtils::calcularTotal(
$this->totalProductos($this->productosConTransporte())
);
}
}

View File

@ -2,7 +2,8 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;
class Producto extends Model
@ -13,7 +14,7 @@ class Producto extends Model
* @var array<int, string>
*/
protected $fillable = [
'name', 'price', 'solidario', 'bono', 'categoria_id'
'nombre', 'precio', 'solidario', 'bono', 'barrial', 'categoria_id', 'barrio_id'
];
/**
@ -29,7 +30,7 @@ public function categoria(): BelongsTo
*/
public function pedidos(): BelongsToMany
{
return $this->belongsToMany(Pedido::class);
return $this->belongsToMany(Pedido::class)->withPivot(['cantidad']);
}
/**
@ -39,4 +40,17 @@ public function caracteristicas(): BelongsToMany
{
return $this->belongsToMany(Caracteristica::class);
}
/**
* El barrio a la que pertenece el producto.
*/
public function barrio(): BelongsTo
{
return $this->belongsTo(Barrio::class);
}
public function pagaTransporte() : bool
{
return !$this->bono && !$this->barrial;
}
}

View File

@ -2,7 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Model;
class Region extends Model
@ -20,7 +20,7 @@ class Region extends Model
* @var array<int, string>
*/
protected $fillable = [
'name',
'nombre',
];
/**

View File

@ -0,0 +1,19 @@
<?php
namespace App\Utils;
class TransporteUtils
{
public const COSTO_TRANSPORTE = 15;
public const DIVISOR_TRANSPORTE = 500;
public static function cantidad(float $total) : int {
if ($total)
return 1 + floor($total / TransporteUtils::DIVISOR_TRANSPORTE);
return 0;
}
public static function calcularTotal(float $total) : int {
return TransporteUtils::cantidad($total) * TransporteUtils::COSTO_TRANSPORTE;
}
}

View File

@ -6,6 +6,7 @@
"license": "MIT",
"require": {
"php": "^8.1",
"doctrine/dbal": "^3.8",
"guzzlehttp/guzzle": "^7.2",
"inertiajs/inertia-laravel": "^0.6.8",
"laravel/framework": "^10.10",

8850
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,28 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('regiones', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('regiones');
}
};

View File

@ -1,30 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('pedidos', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->unsignedBigInteger('barrio_id');
$table->timestamps();
$table->foreign('barrio_id')->references('id')->on('barrios');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('pedidos');
}
};

View File

@ -1,28 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('categorias', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('categorias');
}
};

View File

@ -1,33 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('productos', function (Blueprint $table) {
$table->id();
$table->string('name', 200);
$table->double('price', 15, 2);
$table->unsignedBigInteger('categoria_id');
$table->boolean('solidario');
$table->boolean('bono');
$table->timestamps();
$table->foreign('categoria_id')->references('id')->on('categorias');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('productos');
}
};

View File

@ -1,32 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('productos_pedidos', function (Blueprint $table) {
$table->unsignedBigInteger('pedido_id');
$table->unsignedBigInteger('producto_id');
$table->unsignedInteger('ammount');
$table->timestamps();
$table->primary(['pedido_id','producto_id']);
$table->foreign('pedido_id')->references('id')->on('pedidos');
$table->foreign('producto_id')->references('id')->on('productos');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('productos_pedidos');
}
};

View File

@ -1,29 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('caracteristicas', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->string('key', 100);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('caracteristicas');
}
};

View File

@ -1,30 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('productos_caracteristicas', function (Blueprint $table) {
$table->unsignedBigInteger('producto_id');
$table->unsignedBigInteger('caracteristica_id');
$table->primary(['producto_id','caracteristica_id']);
$table->foreign('producto_id')->references('id')->on('productos');
$table->foreign('caracteristica_id')->references('id')->on('caracteristicas');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('productos_caracteristicas');
}
};

View File

@ -11,9 +11,15 @@
*/
public function up(): void
{
Schema::create('regiones', function (Blueprint $table) {
$table->id();
$table->string('nombre', 100);
$table->timestamps();
});
Schema::create('barrios', function (Blueprint $table) {
$table->id();
$table->string('name', 100);
$table->string('nombre', 100);
$table->unsignedBigInteger('region_id');
$table->timestamps();
$table->foreign('region_id')->references('id')->on('regiones');
@ -26,5 +32,6 @@ public function up(): void
public function down(): void
{
Schema::dropIfExists('barrios');
Schema::dropIfExists('regiones');
}
};

View File

@ -0,0 +1,60 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('categorias', function (Blueprint $table) {
$table->id();
$table->string('nombre', 100);
$table->timestamps();
});
Schema::create('caracteristicas', function (Blueprint $table) {
$table->id();
$table->string('nombre', 100);
$table->string('codigo', 100);
$table->timestamps();
});
Schema::create('productos', function (Blueprint $table) {
$table->id();
$table->string('nombre', 200);
$table->double('precio', 15, 2);
$table->unsignedBigInteger('categoria_id');
$table->boolean('solidario');
$table->boolean('bono');
$table->boolean('barrial')->default(false);
$table->unsignedBigInteger('barrio_id')->nullable();
$table->timestamps();
$table->foreign('categoria_id')->references('id')->on('categorias');
$table->foreign('barrio_id')->references('id')->on('barrios');
});
Schema::create('caracteristica_producto', function (Blueprint $table) {
$table->unsignedBigInteger('producto_id');
$table->unsignedBigInteger('caracteristica_id');
$table->primary(['producto_id','caracteristica_id']);
$table->foreign('producto_id')->references('id')->on('productos');
$table->foreign('caracteristica_id')->references('id')->on('caracteristicas');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('caracteristica_producto');
Schema::dropIfExists('productos');
Schema::dropIfExists('caracteristicas');
Schema::dropIfExists('categorias');
}
};

View File

@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('pedidos', function (Blueprint $table) {
$table->id();
$table->string('nombre', 100);
$table->boolean('terminado')->default(false);
$table->boolean('pagado')->default(false);
$table->unsignedBigInteger('barrio_id');
$table->timestamps();
$table->foreign('barrio_id')->references('id')->on('barrios');
$table->unique(['barrio_id','nombre']);
});
Schema::create('pedido_producto', function (Blueprint $table) {
$table->unsignedBigInteger('pedido_id');
$table->unsignedBigInteger('producto_id');
$table->unsignedInteger('cantidad');
$table->timestamps();
$table->primary(['pedido_id','producto_id']);
$table->foreign('pedido_id')->references('id')->on('pedidos');
$table->foreign('producto_id')->references('id')->on('productos');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('pedido_producto');
Schema::dropIfExists('pedidos');
}
};

View File

@ -17,11 +17,11 @@ class BarrioSeeder extends Seeder
public function run(): void
{
$prueba_id = Region::create([
'name' => 'PRUEBA',
'nombre' => 'PRUEBA',
])->id;
Barrio::create([
'name'=>'PRUEBA','region_id'=>$prueba_id, 'created_at'=>Date::now()
'nombre'=>'PRUEBA','region_id'=>$prueba_id, 'created_at'=>Date::now()
]);
}
}

View File

@ -20,9 +20,9 @@ class CanastaSeeder extends Seeder
*/
public function run(): void
{
$tipoColumn = 'Tipo';
$productoColumn = 'Producto';
$precioColumn = 'Precio';
$columnaTipo = 'Tipo';
$columnaProducto = 'Producto';
$columnaPrecio = 'Precio';
$tipos = ['P','PTC','B'];
$csv = Reader::createFromPath(resource_path('csv/productos.csv'), 'r');
@ -30,83 +30,75 @@ public function run(): void
$csv->setHeaderOffset(0);
$records = $csv->getRecords();
$productosToInsert = [];
$caracteristicasToInsert = [];
$currentCategoria;
$productos = [];
$caracteristicasAInsertar = [];
$categoriaActual;
foreach ($records as $i => $record) {
$tipo = trim($record[$tipoColumn]);
$tipo = trim($record[$columnaTipo]);
if (!in_array($tipo, $tipos)) {
if (!Str::contains($tipo,'¿') && ($tipo != 'T')) {
$currentCategoria = Categoria::firstOrCreate(['name' => $tipo]);
$categoriaActual = Categoria::firstOrCreate(['nombre' => $tipo]);
}
} else {
$parsed = $this->parseAndFormatName($record[$productoColumn]);
[$solidario, $nombre, $caracteristicas] = $this->parsearNombre($record[$columnaProducto]);
$productosToInsert[] = [
'name' => $parsed['name'],
'price' => $record[$precioColumn],
'solidario' => $parsed['solidario'],
$productos[] = [
'nombre' => $nombre,
'precio' => $record[$columnaPrecio],
'solidario' => $solidario,
'bono' => $tipo == 'B',
'categoria_id' => $currentCategoria->id,
'categoria_id' => $categoriaActual->id,
'created_at' => Date::now(),
'updated_at' => Date::now(),
];
$caracteristicasToInsert[] = [
'name' => $parsed['name'],
'caracteristicas' => $parsed['caracteristicas']
$caracteristicasAInsertar[] = [
'nombre' => $nombre,
'caracteristicas' => $caracteristicas
];
}
}
foreach (array_chunk($productosToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) {
foreach (array_chunk($productos,DatabaseSeeder::CHUNK_SIZE) as $chunk)
DB::table('productos')->insert($chunk);
}
$this->insertCaracteristicas($caracteristicasToInsert);
$this->insertarCaracteristicas($caracteristicasAInsertar);
}
/**
* Returns an array data parsed from productoColumn.
* Devuelve un array con datos parseados de $columnaProducto
*
* @return array{solidario: bool, name: string, caracteristicas: array(Caracteristica)}
* @return array{solidario: bool, nombre: string, caracteristicas: array(Caracteristica)}
*/
private function parseAndFormatName($productoColumn): array {
$solidario = Str::contains($productoColumn, '*');
$name = Str::replace('*','',$productoColumn);
private function parsearNombre($columnaProducto): array {
$solidario = Str::contains($columnaProducto, '*');
$nombre = Str::replace('*','',$columnaProducto);
$caracteristicas = [];
if (Str::contains($name, 'S-G'))
$caracteristicas[] = Caracteristica::where('key','S-G')->first()->id;
if (Str::contains($name, 'S-A'))
$caracteristicas[] = Caracteristica::where('key','S-A')->first()->id;
if (Str::contains($name, 'S-S'))
$caracteristicas[] = Caracteristica::where('key','S-S')->first()->id;
if (Str::contains($name, 'S-P-A'))
$caracteristicas[] = Caracteristica::where('key','S-P-A')->first()->id;
if (Str::contains($nombre, 'S-G'))
$caracteristicas[] = Caracteristica::where('codigo','S-G')->first()->id;
if (Str::contains($nombre, 'S-A'))
$caracteristicas[] = Caracteristica::where('codigo','S-A')->first()->id;
if (Str::contains($nombre, 'S-S'))
$caracteristicas[] = Caracteristica::where('codigo','S-S')->first()->id;
if (Str::contains($nombre, 'S-P-A'))
$caracteristicas[] = Caracteristica::where('codigo','S-P-A')->first()->id;
if ($caracteristicas) {
$name = Str::replaceMatches('/\(S\-.*\)/', '', $name);
$nombre = Str::replaceMatches('/\(S\-.*\)/', '', $nombre);
}
return [
'solidario' => $solidario,
'name' => trim($name),
'caracteristicas' => $caracteristicas
];
return [$solidario, trim($nombre), $caracteristicas];
}
private function insertCaracteristicas($caracteristicasToInsert) : void {
foreach ($caracteristicasToInsert as $key => $item) {
$name = $item['name'];
$match = Producto::where('name',$name)->first();
private function insertarCaracteristicas($caracteristicasAInsertar) : void {
foreach ($caracteristicasAInsertar as $codigo => $item) {
$nombre = $item['nombre'];
$match = Producto::where('nombre',$nombre)->first();
if ($match) {
foreach ($item['caracteristicas'] as $key => $caracteristica) {
DB::table('productos_caracteristicas')->insert([
'producto_id' => $match->id,
'caracteristica_id' => $caracteristica,
]);
foreach ($item['caracteristicas'] as $codigo => $caracteristica) {
$match->caracteristicas()->attach($caracteristica);
}
}
}

View File

@ -15,10 +15,10 @@ class CaracteristicaSeeder extends Seeder
public function run(): void
{
DB::table('caracteristicas')->insert([
['name' => 'SIN GLUTEN', 'key' => 'S-G', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['name' => 'SIN SAL AGREGADA', 'key' => 'S-S', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['name' => 'SIN AZÚCAR AGREGADA', 'key' => 'S-A', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['name' => 'SIN PRODUCTOS DE ORIGEN ANIMAL', 'key' => 'S-P-A', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['nombre' => 'SIN GLUTEN', 'codigo' => 'S-G', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['nombre' => 'SIN SAL AGREGADA', 'codigo' => 'S-S', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['nombre' => 'SIN AZÚCAR AGREGADA', 'codigo' => 'S-A', 'created_at' => Date::now(), 'updated_at' => Date::now()],
['nombre' => 'SIN PRODUCTOS DE ORIGEN ANIMAL', 'codigo' => 'S-P-A', 'created_at' => Date::now(), 'updated_at' => Date::now()],
]);
}
}

View File

@ -15,9 +15,10 @@ class DatabaseSeeder extends Seeder
public function run(): void
{
$this->call([
BarrioSeeder::class,
CaracteristicaSeeder::class,
CanastaSeeder::class,
BarrioSeeder::class,
TestDataSeeder::class,
]);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Database\Seeders;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Region;
use App\Models\Barrio;
use App\Models\Producto;
use App\Models\Categoria;
class TestDataSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
$barrioPrueba = Barrio::find(1);
$productoBarrial = $barrioPrueba->productos()->create([
'nombre' => 'Producto Barrial',
'precio' => 100,
'solidario' => true,
'bono' => true,
'barrial' => true,
'categoria_id' => Categoria::firstOrCreate([
'nombre' => 'PRODUCTOS BARRIALES'
])->id
]);
$pedido = $barrioPrueba->crearPedido("Pedido de prueba");
$pedido->agregarProducto($productoBarrial, 2);
$pedido->agregarProducto(Producto::find(1), 1);
$segundoPedido = $barrioPrueba->crearPedido("Segunda prueba");
$segundoPedido->agregarProducto($productoBarrial, 5);
$tercerPedido = $barrioPrueba->crearPedido("Tercera prueba");
$tercerPedido->agregarProducto($productoBarrial, 3);
}
}