From 800fed20978f78589aee284dce85678a22553c6e Mon Sep 17 00:00:00 2001 From: ale Date: Tue, 27 Aug 2024 19:53:57 -0300 Subject: [PATCH 01/20] Agregada ruta para obtener total de pedidos --- routes/web.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/routes/web.php b/routes/web.php index 2b57d96..c5c4d6e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -34,11 +34,11 @@ Route::get('/admin/obtener_sesion', function() { Route::middleware(['auth', 'admin'])->group( function () { Route::get('/admin/pedidos', 'AdminController@index')->name('admin_login.index'); - + Route::get('/admin/exportar-planillas-a-pdf/{gdc}', 'AdminController@exportarPlanillasAPdf'); - + Route::get('/admin/exportar-pedido-a-csv/{gdc}', 'AdminController@exportarPedidoACSV'); - + Route::get('/admin/exportar-pedido-con-nucleos-a-csv/{gdc}', 'AdminController@exportarPedidoConNucleosACSV'); }); @@ -70,3 +70,7 @@ Route::middleware('auth')->group( function() { })->name('obtenerSesion'); }); }); + +Route::middleware(['auth', 'comi_compras'])->group( function() { + Route::get('/compras/pedidos', 'ComprasController@pedidos')->name('compras.pedidos'); +}); From f0f05f836130d3ef4588917afcd5b0f687c4fa2f Mon Sep 17 00:00:00 2001 From: ale Date: Tue, 27 Aug 2024 20:56:20 -0300 Subject: [PATCH 02/20] Borrado controller no usado --- app/Http/Controllers/Api/PedidoController.php | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 app/Http/Controllers/Api/PedidoController.php diff --git a/app/Http/Controllers/Api/PedidoController.php b/app/Http/Controllers/Api/PedidoController.php deleted file mode 100644 index 8f2ec61..0000000 --- a/app/Http/Controllers/Api/PedidoController.php +++ /dev/null @@ -1,9 +0,0 @@ - Date: Tue, 27 Aug 2024 20:56:27 -0300 Subject: [PATCH 03/20] =?UTF-8?q?Borrado=20m=C3=A9todo=20no=20usado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Producto.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/Producto.php b/app/Producto.php index a37d16a..3474063 100644 --- a/app/Producto.php +++ b/app/Producto.php @@ -16,7 +16,7 @@ class Producto extends Model { return $this->belongsToMany('App\Subpedido','productos_subpedidos')->withPivot(["cantidad"]); } - + public function proveedor() { return $this->belongsTo('App\Proveedor'); @@ -33,10 +33,6 @@ class Producto extends Model return $request->has('paginar') && intval($request->input('paginar')) ? intval($request->input('paginar')) : self::$paginarPorDefecto; } - public static function productosIDFila() { - return Producto::pluck('fila', 'id',)->all(); - } - public static function productosFilaID() { return Producto::pluck('id', 'fila',)->all(); } @@ -44,5 +40,5 @@ class Producto extends Model public static function productosIDNombre() { return Producto::pluck('nombre', 'id',)->all(); } - + } From 2beda0bf5b0f3fac8dbbaf1db6dd55fd8280add6 Mon Sep 17 00:00:00 2001 From: ale Date: Tue, 27 Aug 2024 20:57:11 -0300 Subject: [PATCH 04/20] =?UTF-8?q?ComprasController=20+=20hice=20est=C3=A1t?= =?UTF-8?q?icos=20algunos=20m=C3=A9todos=20+=20primeros=20pasos=20hacia=20?= =?UTF-8?q?total=20de=20pedidos=20de=20los=20barrios?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/GrupoDeCompra.php | 78 ++++++++++++++-------- app/Http/Controllers/ComprasController.php | 14 ++++ 2 files changed, 66 insertions(+), 26 deletions(-) create mode 100644 app/Http/Controllers/ComprasController.php diff --git a/app/GrupoDeCompra.php b/app/GrupoDeCompra.php index 09ec62b..ead150c 100644 --- a/app/GrupoDeCompra.php +++ b/app/GrupoDeCompra.php @@ -2,11 +2,11 @@ namespace App; +use App\Producto; use Illuminate\Database\Eloquent\Model; use Mpdf\Mpdf; use League\Csv\CannotInsertRecord; use League\Csv\Writer; -use App\Producto; use DB; use League\Csv\Reader; @@ -40,7 +40,8 @@ class GrupoDeCompra extends Model $mpdf->Output($filename, "D"); } - function filaVacia(string $product, int $columns) { + static function filaVacia(string $product, int $columns): array + { $fila = [$product]; for ($i = 1; $i <= $columns; $i++) { $fila[$i] = "0"; @@ -49,23 +50,23 @@ class GrupoDeCompra extends Model } //Asume que los productos están gruadados en orden de fila - public function obtenerTemplateDeFilasVacias(int $columns){ + public static function obtenerTemplateDeFilasVacias(int $columns){ $productosFilaID = Producto::productosFilaID(); $productosIDNombre = Producto::productosIDNombre(); $num_fila = 1; $template = []; foreach ($productosFilaID as $fila => $id) { for ($i = $num_fila; $i < $fila; $i++) { - $template[$i] = $this->filaVacia("", $columns); + $template[$i] = GrupoDeCompra::filaVacia("", $columns); } - $template[$fila] = $this->filaVacia($productosIDNombre[$id], $columns); + $template[$fila] = GrupoDeCompra::filaVacia($productosIDNombre[$id], $columns); $num_fila = $fila+1; } - $template[$this->obtenerFilaDeBonoTransporte()] = $this->filaVacia("Bonos de transporte", $columns); + $template[GrupoDeCompra::obtenerFilaDeBonoTransporte()] = GrupoDeCompra::filaVacia("Bonos de transporte", $columns); return $template; } - private function obtenerFilaDeBonoTransporte() { + private static function obtenerFilaDeBonoTransporte() { $csv = Reader::createFromPath(resource_path('csv/productos.csv'), 'r'); $csv->setDelimiter("|"); $csv->setEnclosure("'"); @@ -105,19 +106,7 @@ class GrupoDeCompra extends Model } public function exportarPedidoEnCSV(){ - $productos_en_pedido = DB::table('pedidos_aprobados')->where('grupo_de_compra_id',$this->id)->get()->keyBy('producto_id'); - - //si no hay pedidos aprobados, salir - if ($productos_en_pedido->count() == 0) { \Log::debug("El grupo de compra ". $this->nombre . " no tiene pedidos aprobados."); return; } - $records = $this->obtenerTemplateDeFilasVacias(1); - $productos_id_fila = Producto::productosIdFila(); - foreach ($productos_en_pedido as $id => $producto_pedido){ - $fila = $productos_id_fila[$id]; - $records[$fila][1] = $producto_pedido->cantidad_pedida; - } - - $records[$this->obtenerFilaDeBonoTransporte()][1] = $this->calcularCantidadBDT(); - + $records = $this->generarColumnaCantidades(); try { $writer = Writer::createFromPath(resource_path('csv/exports/'.$this->nombre.'.csv'), 'w'); $writer->insertAll($records); @@ -126,17 +115,41 @@ class GrupoDeCompra extends Model } } + public function generarColumnaCantidades() { + $productos_en_pedido = DB::table('pedidos_aprobados')->where('grupo_de_compra_id',$this->id)->get()->keyBy('producto_id'); + + //si no hay pedidos aprobados, salir + if ($productos_en_pedido->count() == 0) { + \Log::debug("El grupo de compra ". $this->nombre . " no tiene pedidos aprobados."); + return []; + } + + $records = $this->obtenerTemplateDeFilasVacias(1); + $productos_id_fila = Producto::productosIdFila(); + foreach ($productos_en_pedido as $id => $producto_pedido){ + $fila = $productos_id_fila[$id]; + $records[$fila][1] = $producto_pedido->cantidad_pedida; + } + + $records[$this->obtenerFilaDeBonoTransporte()][1] = $this->calcularCantidadBDT(); + + return $records; + } + public function exportarPedidoConNucleosEnCSV() { $productos_en_pedido = DB::table('pedidos_aprobados')->where('grupo_de_compra_id',$this->id)->get()->keyBy('producto_id'); // si no hay pedidos aprobados, salir - if ($productos_en_pedido->count() == 0) { \Log::debug("El grupo de compra ". $this->nombre . " no tiene pedidos aprobados."); return; } - + if ($productos_en_pedido->count() == 0) { + \Log::debug("El grupo de compra ". $this->nombre . " no tiene pedidos aprobados."); + return; + } + $pedidos = $this->pedidosAprobados(); // Generar tabla vacía con una columna por núcleo $records = $this->obtenerTemplateDeFilasVacias($pedidos->count()); $productos_id_fila = Producto::productosIdFila(); - + foreach ($productos_en_pedido as $id => $producto_pedido) { $fila = $productos_id_fila[$id]; $i = 1; @@ -155,7 +168,7 @@ class GrupoDeCompra extends Model $i++; } array_splice($records, 0, 0, array($nucleos)); - + // Guardar en un archivo .csv try { $writer = Writer::createFromPath(resource_path('csv/exports/'.$this->nombre.'-completo.csv'), 'w'); @@ -166,7 +179,20 @@ class GrupoDeCompra extends Model } public static function exportarTodosLosPedidosEnCSV(){ - $gdcs=GrupoDeCompra::all(); - foreach ($gdcs as $gdc){ $gdc->exportarPedidoEnCSV(); } + $gdcs = GrupoDeCompra::all(); + $planilla = GrupoDeCompra::obtenerTemplateDeFilasVacias($gdcs->count()); + $barrios = [""]; + foreach ($gdcs as $gdc) { + $barrios[] = $gdc->nombre; + } + array_splice($planilla, 0, 0, array($barrios)); + + // Guardar en un archivo .csv + try { + $writer = Writer::createFromPath(resource_path('csv/exports/total-pedidos.csv'), 'w'); + $writer->insertAll($planilla); + } catch (CannotInsertRecord $e) { + var_export($e->getRecords()); + } } } diff --git a/app/Http/Controllers/ComprasController.php b/app/Http/Controllers/ComprasController.php new file mode 100644 index 0000000..ae4de0e --- /dev/null +++ b/app/Http/Controllers/ComprasController.php @@ -0,0 +1,14 @@ +download($file); + } +} From 2d7a90f6b2697e480b3239fe6619732f74da6ba9 Mon Sep 17 00:00:00 2001 From: ale Date: Tue, 27 Aug 2024 21:21:10 -0300 Subject: [PATCH 05/20] Agregado middleware para comision compras + columna en tabla users --- app/Http/Middleware/Compras.php | 26 +++++++++++++++ ...08_28_000025_agregar_is_compras_a_user.php | 32 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 app/Http/Middleware/Compras.php create mode 100644 database/migrations/2024_08_28_000025_agregar_is_compras_a_user.php diff --git a/app/Http/Middleware/Compras.php b/app/Http/Middleware/Compras.php new file mode 100644 index 0000000..8852113 --- /dev/null +++ b/app/Http/Middleware/Compras.php @@ -0,0 +1,26 @@ +is_compras) { + return $next($request); + } else { + return response('Necesitás ser de comisión compras para hacer esto', 403); + } + } +} diff --git a/database/migrations/2024_08_28_000025_agregar_is_compras_a_user.php b/database/migrations/2024_08_28_000025_agregar_is_compras_a_user.php new file mode 100644 index 0000000..57d12ac --- /dev/null +++ b/database/migrations/2024_08_28_000025_agregar_is_compras_a_user.php @@ -0,0 +1,32 @@ +boolean('is_compras')->after('is_admin')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('producto_subpedido', function (Blueprint $table) { + $table->dropColumn('is_compras'); + }); + } +} From 5453b1158fddeb2b831df6c101c6d94ca5fa43aa Mon Sep 17 00:00:00 2001 From: ale Date: Fri, 30 Aug 2024 01:13:06 -0300 Subject: [PATCH 06/20] Cambio en logica de registro automatico de componentes --- resources/js/app.js | 5 ++--- resources/js/components.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 resources/js/components.js diff --git a/resources/js/app.js b/resources/js/app.js index 026177f..3259426 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -4,7 +4,6 @@ * building robust, powerful web applications using Vue and Laravel. */ import axios from 'axios'; -import animate from 'animate.css'; import Vue from 'vue'; window.Vue = require('vue'); window.Event = new Vue(); @@ -18,8 +17,8 @@ window.bulmaToast = require('bulma-toast'); * * Eg. ./components/ExampleComponent.vue -> */ -const files = require.context('./', true, /\.vue$/i) -files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default)) +import './components'; + /** * Constants */ diff --git a/resources/js/components.js b/resources/js/components.js new file mode 100644 index 0000000..e67790e --- /dev/null +++ b/resources/js/components.js @@ -0,0 +1,22 @@ +import Vue from 'vue'; + +const requireComponent = require.context('./components', true, /\.vue$/); + +requireComponent.keys().forEach(fileName => { + // Get the component config + const componentConfig = requireComponent(fileName); + // Get the PascalCase name of the component + const componentName = fileName + .replace(/^\.\/(.*)\.\w+$/, '$1') // Remove "./" from the beginning and the file extension from the end + .replace(/\//g, '-') // Replace directories with hyphens + .replace(/([a-z])([A-Z])/g, '$1-$2') // Insert hyphen between camelCase words + .toLowerCase() // Convert to lowercase + // Globally register the component + Vue.component( + componentName, + // Look for the component options on `.default`, which will + // exist if the component was exported with `export default`, + // otherwise fall back to module's root. + componentConfig.default || componentConfig + ); +}); From 12b77de01885f636873d21316ce962c1ac33d1dc Mon Sep 17 00:00:00 2001 From: ale Date: Fri, 30 Aug 2024 01:14:10 -0300 Subject: [PATCH 07/20] Refactor de componentes de pantallas de login --- .../{BotonAdminLogin.vue => admin/BotonLogin.vue} | 3 --- .../components/{LoginAdmin.vue => admin/Login.vue} | 0 .../js/components/{ => comunes}/BarrioSelect.vue | 0 .../js/components/{ => comunes}/RegionSelect.vue | 0 resources/views/auth/admin_login.blade.php | 6 +++--- resources/views/auth/login.blade.php | 12 +++--------- 6 files changed, 6 insertions(+), 15 deletions(-) rename resources/js/components/{BotonAdminLogin.vue => admin/BotonLogin.vue} (88%) rename resources/js/components/{LoginAdmin.vue => admin/Login.vue} (100%) rename resources/js/components/{ => comunes}/BarrioSelect.vue (100%) rename resources/js/components/{ => comunes}/RegionSelect.vue (100%) diff --git a/resources/js/components/BotonAdminLogin.vue b/resources/js/components/admin/BotonLogin.vue similarity index 88% rename from resources/js/components/BotonAdminLogin.vue rename to resources/js/components/admin/BotonLogin.vue index 87d03ba..717af22 100644 --- a/resources/js/components/BotonAdminLogin.vue +++ b/resources/js/components/admin/BotonLogin.vue @@ -12,9 +12,6 @@ diff --git a/resources/js/components/PedidosAdminCaracteristicasOpcionales.vue b/resources/js/components/admin/CaracteristicasOpcionales.vue similarity index 71% rename from resources/js/components/PedidosAdminCaracteristicasOpcionales.vue rename to resources/js/components/admin/CaracteristicasOpcionales.vue index 50d72e7..242dfb2 100644 --- a/resources/js/components/PedidosAdminCaracteristicasOpcionales.vue +++ b/resources/js/components/admin/CaracteristicasOpcionales.vue @@ -1,10 +1,8 @@ diff --git a/resources/views/auth/compras_login.blade.php b/resources/views/auth/compras_login.blade.php index c76f045..e34b53b 100644 --- a/resources/views/auth/compras_login.blade.php +++ b/resources/views/auth/compras_login.blade.php @@ -24,6 +24,7 @@ @enderror
@csrf +
From 2337ad9a37af9c2629ee87d835f267ebb69ad8a2 Mon Sep 17 00:00:00 2001 From: ale Date: Sat, 14 Sep 2024 13:37:06 -0300 Subject: [PATCH 14/20] Login de compras funcionando --- app/Http/Controllers/ComprasController.php | 2 +- app/Http/Middleware/Compras.php | 2 +- resources/js/components/LoginCompras.vue | 2 +- routes/web.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/ComprasController.php b/app/Http/Controllers/ComprasController.php index 0104a7e..7cc60c3 100644 --- a/app/Http/Controllers/ComprasController.php +++ b/app/Http/Controllers/ComprasController.php @@ -12,7 +12,7 @@ class ComprasController return response()->download($file); } - public function showLoginForm() + public function show() { return view('auth/compras_login'); } diff --git a/app/Http/Middleware/Compras.php b/app/Http/Middleware/Compras.php index d3a81ad..a9d9f6b 100644 --- a/app/Http/Middleware/Compras.php +++ b/app/Http/Middleware/Compras.php @@ -18,7 +18,7 @@ class Compras public function handle(Request $request, Closure $next) { if (!Auth::check()) - return redirect()->route('compras.login'); + return redirect()->route('compras_login.show'); if (Auth::user()->is_compras) { return $next($request); diff --git a/resources/js/components/LoginCompras.vue b/resources/js/components/LoginCompras.vue index b68a95e..23d1133 100644 --- a/resources/js/components/LoginCompras.vue +++ b/resources/js/components/LoginCompras.vue @@ -4,7 +4,7 @@
- +
diff --git a/routes/web.php b/routes/web.php index 147ffc0..6872466 100644 --- a/routes/web.php +++ b/routes/web.php @@ -76,7 +76,7 @@ Route::middleware('auth')->group( function() { }); }); -Route::get('/compras/login', 'ComprasController@showLoginForm')->name('compras.login'); +Route::get('/compras', 'ComprasController@show')->name('compras_login.show'); Route::middleware(['compras'])->group( function() { Route::get('/compras/pedidos', 'ComprasController@pedidos')->name('compras.pedidos'); From 917e3e1df3fbc8d8435b809308647eea2e528589 Mon Sep 17 00:00:00 2001 From: ale Date: Sat, 14 Sep 2024 16:25:57 -0300 Subject: [PATCH 15/20] Ajustes de refactor --- resources/js/components.js | 3 +++ .../js/components/{LoginCompras.vue => compras/Login.vue} | 0 resources/js/components/{ => pedidos}/ProductoCard.vue | 2 +- resources/js/components/pedidos/ProductosContainer.vue | 4 ++-- resources/views/auth/compras_login.blade.php | 2 +- resources/views/auth/login.blade.php | 2 +- resources/views/subpedidos_create.blade.php | 2 +- 7 files changed, 9 insertions(+), 6 deletions(-) rename resources/js/components/{LoginCompras.vue => compras/Login.vue} (100%) rename resources/js/components/{ => pedidos}/ProductoCard.vue (98%) diff --git a/resources/js/components.js b/resources/js/components.js index e67790e..d2ca0bb 100644 --- a/resources/js/components.js +++ b/resources/js/components.js @@ -2,6 +2,9 @@ import Vue from 'vue'; const requireComponent = require.context('./components', true, /\.vue$/); +// Registro automático de componentes: +// e.g. components/foo/bar/UnComponente.vue +// se registra como 'foo-bar-un-componente' requireComponent.keys().forEach(fileName => { // Get the component config const componentConfig = requireComponent(fileName); diff --git a/resources/js/components/LoginCompras.vue b/resources/js/components/compras/Login.vue similarity index 100% rename from resources/js/components/LoginCompras.vue rename to resources/js/components/compras/Login.vue diff --git a/resources/js/components/ProductoCard.vue b/resources/js/components/pedidos/ProductoCard.vue similarity index 98% rename from resources/js/components/ProductoCard.vue rename to resources/js/components/pedidos/ProductoCard.vue index 0790be0..8722642 100644 --- a/resources/js/components/ProductoCard.vue +++ b/resources/js/components/pedidos/ProductoCard.vue @@ -103,7 +103,7 @@ export default { \ No newline at end of file + diff --git a/resources/js/components/Producto/ProductoCantidad.vue b/resources/js/components/pedidos/ProductoCantidad.vue similarity index 100% rename from resources/js/components/Producto/ProductoCantidad.vue rename to resources/js/components/pedidos/ProductoCantidad.vue diff --git a/resources/js/components/pedidos/ProductoCard.vue b/resources/js/components/pedidos/ProductoCard.vue index 7f03510..320a9fd 100644 --- a/resources/js/components/pedidos/ProductoCard.vue +++ b/resources/js/components/pedidos/ProductoCard.vue @@ -1,11 +1,6 @@