From d91d46c5892261305efaed4bc47a968b5e65af73 Mon Sep 17 00:00:00 2001 From: ale Date: Wed, 4 Sep 2024 15:41:35 -0300 Subject: [PATCH 1/4] Seeding simplificado --- ...arProductoSeeder.php => CanastaSeeder.php} | 14 +++---- database/seeds/DatabaseSeeder.php | 3 +- database/seeds/ProductoSeeder.php | 40 ------------------- 3 files changed, 8 insertions(+), 49 deletions(-) rename database/seeds/{ImportarProductoSeeder.php => CanastaSeeder.php} (93%) delete mode 100644 database/seeds/ProductoSeeder.php diff --git a/database/seeds/ImportarProductoSeeder.php b/database/seeds/CanastaSeeder.php similarity index 93% rename from database/seeds/ImportarProductoSeeder.php rename to database/seeds/CanastaSeeder.php index d929371..f9a5756 100644 --- a/database/seeds/ImportarProductoSeeder.php +++ b/database/seeds/CanastaSeeder.php @@ -4,7 +4,7 @@ use Illuminate\Database\Seeder; use League\Csv\Reader; use App\Proveedor; -class ImportarProductoSeeder extends Seeder +class CanastaSeeder extends Seeder { const FILA_HEADER = "Tipo"; const ULTIMA_FILA = "TOTAL"; @@ -21,14 +21,14 @@ class ImportarProductoSeeder extends Seeder $iHeader = $this->obtenerIndiceDeHeader($csv); $csv->setHeaderOffset($iHeader); $registros = $csv->getRecords(); - + $toInsert = []; $categoria = ''; foreach($registros as $i => $registro){ //filas que están arriba del header if ($i <= $iHeader){ continue; - } + } //finalizar if ($registro[$this::FILA_HEADER] == $this::ULTIMA_FILA){ @@ -39,7 +39,7 @@ class ImportarProductoSeeder extends Seeder if (!Arr::has($registro,$this::FILA_HEADER)|| trim($registro[$this::FILA_HEADER]) == ''){ var_dump("no hay tipo en la fila " . $i); continue; - } + } //saltear bono de transporte if ($registro[$this::FILA_HEADER] == "T"){ @@ -51,7 +51,7 @@ class ImportarProductoSeeder extends Seeder //es la pregunta de la copa? if (Str::contains($registro[$this::FILA_HEADER],"¿")) { continue; } $categoria = $registro[$this::FILA_HEADER]; - continue; + continue; } //completar producto @@ -65,9 +65,9 @@ class ImportarProductoSeeder extends Seeder ]; } - foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) + foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) { - DB::table('productos')->insert($chunk); + DB::table('productos')->insert($chunk); } } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 1e8ec0e..b71ca5a 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -12,7 +12,6 @@ class DatabaseSeeder extends Seeder */ public function run() { - $this->call(GrupoDeCompraSeeder::class); - $this->call(ImportarProductoSeeder::class); + $this->call(CanastaSeeder::class); } } diff --git a/database/seeds/ProductoSeeder.php b/database/seeds/ProductoSeeder.php deleted file mode 100644 index 95cab3e..0000000 --- a/database/seeds/ProductoSeeder.php +++ /dev/null @@ -1,40 +0,0 @@ -setDelimiter("|"); - $csv->setEnclosure("'"); - $csv->setHeaderOffset(0); - $registros = $csv->getRecords(); - $toInsert = []; - - foreach($registros as $registro){ - $toInsert[] = [ - 'categoria' => $registro['categoria'], - 'nombre' => $registro['producto'], - 'precio' => $registro['precio'], - 'proveedor_id' => isset($registro['proveedor']) ? Proveedor::firstOrCreate([ - 'nombre' => $registro['proveedor'] - ])->id : null, - 'bono' => $registro['categoria'] == 'BONOS Y FINANCIAMIENTO SORORO' - ]; - } - - foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) - { - DB::table('productos')->insert($chunk); - } - } -} From c86eb97cb911442659523cec622189d112738ef0 Mon Sep 17 00:00:00 2001 From: ale Date: Thu, 5 Sep 2024 13:34:33 -0300 Subject: [PATCH 2/4] =?UTF-8?q?Cambio=20l=C3=B3gica=20de=20pago=20de=20tra?= =?UTF-8?q?nsporte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/GrupoDeCompra.php | 6 +++++- app/Producto.php | 9 +++++++-- app/Subpedido.php | 16 +++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/GrupoDeCompra.php b/app/GrupoDeCompra.php index b36ea8d..8ab1f9c 100644 --- a/app/GrupoDeCompra.php +++ b/app/GrupoDeCompra.php @@ -93,7 +93,11 @@ class GrupoDeCompra extends Model } public function calcularCantidadBDT() { - return ceil($this->totalPedidosSinBonos() / 500); + $total = 0; + foreach ($this->pedidosAprobados() as $pedido) { + $total += $pedido->totalParaTransporte(); + } + return ceil($total / 500); } public function totalBonosBarriales() { diff --git a/app/Producto.php b/app/Producto.php index a37d16a..d075724 100644 --- a/app/Producto.php +++ b/app/Producto.php @@ -5,6 +5,7 @@ namespace App; use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use App\Filtros\FiltroDeProducto; +use Illuminate\Support\Str; class Producto extends Model { @@ -16,12 +17,16 @@ class Producto extends Model { return $this->belongsToMany('App\Subpedido','productos_subpedidos')->withPivot(["cantidad"]); } - + public function proveedor() { return $this->belongsTo('App\Proveedor'); } + public function pagaTransporte() { + return !($this->bono || Str::contains($this->categoria, 'SUBSIDIADO')); + } + //Este método permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda) public function scopeFiltrar($query, FiltroDeProducto $filtros) { @@ -44,5 +49,5 @@ class Producto extends Model public static function productosIDNombre() { return Producto::pluck('nombre', 'id',)->all(); } - + } diff --git a/app/Subpedido.php b/app/Subpedido.php index 276d743..136716f 100644 --- a/app/Subpedido.php +++ b/app/Subpedido.php @@ -46,10 +46,20 @@ class Subpedido extends Model return $this->productosSinBonos()->sum('total'); } + public function totalParaTransporte() { + $total = 0; + foreach ($this->productos()->get() as $producto) { + if ($producto->pagaTransporte()) { + $total += $producto->precio * $producto->pivot->cantidad; + } + } + return ceil($total); + } + //Cantidad de bonos de transporte public function cantidadBDT() { - return ceil($this->totalSinBonos() / 500); + return ceil($this->totalParaTransporte() / 500); } //Subtotal de dinero de bonos de transporte @@ -98,11 +108,11 @@ class Subpedido extends Model $view = view("pdfgen.subpedido_tabla", ["subpedido" => $this]); return $view->render(); } - + public function getDevoluciones() { return $this->devoluciones_total; } - + public function getNotasDevoluciones() { return $this->devoluciones_notas; } From 3770d728c31b41d34b8d4a3608e0cbe5b00443c4 Mon Sep 17 00:00:00 2001 From: ale Date: Thu, 5 Sep 2024 13:52:31 -0300 Subject: [PATCH 3/4] =?UTF-8?q?Mejoras=20en=20c=C3=A1lculo=20de=20cantidad?= =?UTF-8?q?=20de=20bonos=20de=20transporte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/GrupoDeCompra.php | 2 +- app/Subpedido.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/GrupoDeCompra.php b/app/GrupoDeCompra.php index 8ab1f9c..1e6a60b 100644 --- a/app/GrupoDeCompra.php +++ b/app/GrupoDeCompra.php @@ -97,7 +97,7 @@ class GrupoDeCompra extends Model foreach ($this->pedidosAprobados() as $pedido) { $total += $pedido->totalParaTransporte(); } - return ceil($total / 500); + return $total ? floor($total / 500) + 1 : 0; } public function totalBonosBarriales() { diff --git a/app/Subpedido.php b/app/Subpedido.php index 136716f..bc3d7bf 100644 --- a/app/Subpedido.php +++ b/app/Subpedido.php @@ -53,7 +53,7 @@ class Subpedido extends Model $total += $producto->precio * $producto->pivot->cantidad; } } - return ceil($total); + return $total ? floor($total) + 1 : 0; } //Cantidad de bonos de transporte From 3340de941b3878a6776b7017c98d84c94a5c110f Mon Sep 17 00:00:00 2001 From: ale Date: Thu, 5 Sep 2024 17:11:53 -0300 Subject: [PATCH 4/4] =?UTF-8?q?Revert=20"Mejoras=20en=20c=C3=A1lculo=20de?= =?UTF-8?q?=20cantidad=20de=20bonos=20de=20transporte"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 3770d728c31b41d34b8d4a3608e0cbe5b00443c4. --- app/GrupoDeCompra.php | 2 +- app/Subpedido.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/GrupoDeCompra.php b/app/GrupoDeCompra.php index 1e6a60b..8ab1f9c 100644 --- a/app/GrupoDeCompra.php +++ b/app/GrupoDeCompra.php @@ -97,7 +97,7 @@ class GrupoDeCompra extends Model foreach ($this->pedidosAprobados() as $pedido) { $total += $pedido->totalParaTransporte(); } - return $total ? floor($total / 500) + 1 : 0; + return ceil($total / 500); } public function totalBonosBarriales() { diff --git a/app/Subpedido.php b/app/Subpedido.php index bc3d7bf..136716f 100644 --- a/app/Subpedido.php +++ b/app/Subpedido.php @@ -53,7 +53,7 @@ class Subpedido extends Model $total += $producto->precio * $producto->pivot->cantidad; } } - return $total ? floor($total) + 1 : 0; + return ceil($total); } //Cantidad de bonos de transporte