From bb6de495db563f1a6d851524a791ef3b82f9c0f2 Mon Sep 17 00:00:00 2001 From: Christian Dacid Sullca Puma Date: Tue, 25 Oct 2022 01:35:22 -0500 Subject: [PATCH] evidencias acceso admin y mejora se ruta asignar plan --- .gitignore | 1 - .../Controllers/Api/EvidenciasController.php | 130 ++++--- app/Http/Controllers/Api/PlanController.php | 28 ++ composer.json | 2 + composer.lock | 353 +++++++++++++++++- .../2022_07_07_012118_create_plans_table.php | 10 +- resources/views/planPDF.blade.php | 0 7 files changed, 452 insertions(+), 72 deletions(-) create mode 100644 resources/views/planPDF.blade.php diff --git a/.gitignore b/.gitignore index ae745c2..21152bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ /node_modules /public/hot /public/storage -/storage/*.key /vendor .env .env.backup diff --git a/app/Http/Controllers/Api/EvidenciasController.php b/app/Http/Controllers/Api/EvidenciasController.php index a66409b..3226a62 100644 --- a/app/Http/Controllers/Api/EvidenciasController.php +++ b/app/Http/Controllers/Api/EvidenciasController.php @@ -1,6 +1,7 @@ validate([ - "id_plan"=> "required|integer", - "codigo"=>"required", - "denominacion"=>"required", - "adjunto"=>"required", + "id_plan" => "required|integer", + "codigo" => "required", + "denominacion" => "required", + "adjunto" => "required", ]); - $id_user = auth()->user()->id; - if(plan::where(["id"=>$request->id_plan])->exists()){ + $id_user = auth()->user(); + if ($id_user->isCreadorPlan($request->id_plan) or $id_user->isAdmin()) { $plan = plan::find($request->id_plan); - if($plan->id_user == $id_user){ + if ($plan->id_user == $id_user) { $evidencia = new Evidencias(); $evidencia->id_plan = $request->id_plan; $evidencia->codigo = $plan->codigo; - $evidencia->denominacion = $request->denominacion; - error_log($request->denominacion); - $path = $request->adjunto->store('evidencias'); - $evidencia->adjunto = $path; - $evidencia->id_user = $id_user; + $evidencia->denominacion = $request->denominacion; + error_log($request->denominacion); + $path = $request->adjunto->store('evidencias'); + $evidencia->adjunto = $path; + $evidencia->id_user = $id_user; $evidencia->save(); return response([ "status" => 1, "message" => "Evidencia creada exitosamente", - "evidencia" => $evidencia + "evidencia" => $evidencia ]); - } - else{ + } else { return response([ "status" => 0, "message" => "No tienes permisos para crear esta Evidencia", - ],404); + ], 404); } - } - else{ + } else { return response([ "status" => 0, "message" => "No se encontro el plan", - ],404); + ], 404); } } - public function show($id){ - if(Evidencias::where("id",$id)->exists()){ + public function show($id) + { + if (Evidencias::where("id", $id)->exists()) { $evidencia = Evidencias::find($id); - //Para retornar nombre de user - /*$user = User::find($evidencia->id_user); + //Para retornar nombre de user + /*$user = User::find($evidencia->id_user); $evidencia->id_user = $user->name;*/ return response([ "status" => 1, "msg" => "!Evidencia", "data" => $evidencia, ]); + } else { + return response([ + "status" => 0, + "msg" => "!No se encontro el evidencia", + ], 404); } - else{ - return response([ - "status" => 0, - "msg" => "!No se encontro el evidencia", - ],404); - } - } - public function update(Request $request){ + public function update(Request $request) + { $request->validate([ - "id"=> "required|integer", - "codigo"=> "required", - "denominacion"=> "required", - "adjunto"=> "required" + "id" => "required|integer", + "codigo" => "required", + "denominacion" => "required", + "adjunto" => "required" ]); - $id_user = auth()->user()->id; - if(Evidencias::where(["id"=>$request->id])->exists()){ + $id_user = auth()->user(); + if (Evidencias::where(["id" => $request->id])->exists()) { $evidencia = Evidencias::find($request->id); $plan = plan::find($evidencia->id_plan); - if($plan->id_user == $id_user){ + if ($plan->id_user == $id_user->id or $id_user->isAdmin()) { $evidencia->codigo = $request->codigo; - $evidencia->denominacion = $request->denominacion; - $path = $request->adjunto->store('evidencias'); - $evidencia->adjunto = $path; + $evidencia->denominacion = $request->denominacion; + $path = $request->adjunto->store('evidencias'); + $evidencia->adjunto = $path; $evidencia->save(); return response([ "status" => 1, "message" => "Evidencia actualizada exitosamente", ]); - } - else{ + } else { return response([ "status" => 0, "message" => "No tienes permisos para actualizar esta evidencia", - ],404); + ], 404); } - } - else{ + } else { return response([ "status" => 0, "message" => "No se encontro la evidencia", - ],404); + ], 404); } } public function delete($id) { - $id_user = auth()->user()->id; - if(Evidencias::where(["id"=>$id])->exists()){ + $id_user = auth()->user(); + if (Evidencias::where(["id" => $id])->exists()) { $evidencia = Evidencias::find($id); $plan = plan::find($evidencia->id_plan); - if($plan->id_user == $id_user){ + if ($plan->id_user == $id_user->id or $id_user->isAdmin()) { $evidencia->delete(); return response([ "status" => 1, "message" => "Evidencia eliminada exitosamente", ]); - } - else{ + } else { return response([ "status" => 0, "message" => "No tienes permisos para eliminar esta evidencia", - ],404); + ], 404); } - } - else{ + } else { return response([ "status" => 0, "message" => "No se encontro la evidencia", - ],404); + ], 404); } } - public function download($id){ - if(Evidencias::where("id",$id)->exists()){ + public function download($id) + { + if (Evidencias::where("id", $id)->exists()) { $evidencia = Evidencias::find($id); - $path = storage_path('app/'.$evidencia->adjunto); - //$evidencia->adjunto = download($path); + $path = storage_path('app/' . $evidencia->adjunto); + //$evidencia->adjunto = download($path); return response()->download($path); - } - else{ - return response([ - "status" => 0, - "msg" => "!No se encontro la evidencia", - ],404); + } else { + return response([ + "status" => 0, + "msg" => "!No se encontro la evidencia", + ], 404); } } } diff --git a/app/Http/Controllers/Api/PlanController.php b/app/Http/Controllers/Api/PlanController.php index e8bc1ac..952b12f 100644 --- a/app/Http/Controllers/Api/PlanController.php +++ b/app/Http/Controllers/Api/PlanController.php @@ -15,6 +15,8 @@ use App\Models\ProblemasOportunidades; use App\Models\Recursos; use App\Models\Responsables; +use Barryvdh\DomPDF\Facade\Pdf; + //plan::where(["id_user" => $id_user, "id" => $id])->exists() class PlanController extends Controller @@ -339,6 +341,8 @@ public function assignPlan(Request $request) $plan->id_user = $request->id_user; $plan->id_estandar = $request->id_estandar; $plan->codigo = $request->codigo; + $plan->avance = 0; + $plan->estado = "Programado"; $plan->save(); return response([ "status" => 1, @@ -480,4 +484,28 @@ public function listPlanUser() ], 404); } } + + public function pdfPlan($id) + { + /* $id_user = auth()->user()->id; + if (plan::where("id", $id)->exists()) { + $plan = plan::find($id); + $plan->fuentes = Fuentes::where("id_plan", $id)->get(['id', 'descripcion as value']); + $plan->problemas_oportunidades = ProblemasOportunidades::where("id_plan", $id)->get(['id', 'descripcion as value']); + $plan->causas_raices = CausasRaices::where("id_plan", $id)->get(['id', 'descripcion as value']); + $plan->acciones_mejoras = AccionesMejoras::where("id_plan", $id)->get(['id', 'descripcion as value']); + $plan->recursos = Recursos::where("id_plan", $id)->get(['id', 'descripcion as value']); + $plan->metas = Metas::where("id_plan", $id)->get(['id', 'descripcion as value']); + $plan->observaciones = Observaciones::where("id_plan", $id)->get(['id', 'descripcion as value']); + $plan->responsables = Responsables::where("id_plan", $id)->get(['id', 'nombre as value']); + $plan->evidencias = Evidencias::where("id_plan", $id)->get(); + $pdf = PDF::loadView('planPDF', compact('plan')); + return $pdf->download('plan.pdf'); + } else { + return response([ + "status" => 0, + "message" => "!No se encontro el plan de mejora", + ], 404); + } */ + } } diff --git a/composer.json b/composer.json index d120151..e0e5f46 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,9 @@ "license": "MIT", "require": { "php": "^8.0.2", + "barryvdh/laravel-dompdf": "^2.0", "doctrine/dbal": "^3.4", + "dompdf/dompdf": "^2.0", "fruitcake/laravel-cors": "^3.0", "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.11", diff --git a/composer.lock b/composer.lock index 5c0c5cc..02ffb79 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,85 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "514a36678675ae1c024481b92acaa8ad", + "content-hash": "ad4d8b936acfaca906125948a1f538a5", "packages": [ + { + "name": "barryvdh/laravel-dompdf", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-dompdf.git", + "reference": "1d47648c6cef37f715ecb8bcc5f5a656ad372e27" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/barryvdh/laravel-dompdf/zipball/1d47648c6cef37f715ecb8bcc5f5a656ad372e27", + "reference": "1d47648c6cef37f715ecb8bcc5f5a656ad372e27", + "shasum": "" + }, + "require": { + "dompdf/dompdf": "^2", + "illuminate/support": "^6|^7|^8|^9", + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "nunomaduro/larastan": "^1|^2", + "orchestra/testbench": "^4|^5|^6|^7", + "phpro/grumphp": "^1", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\DomPDF\\ServiceProvider" + ], + "aliases": { + "Pdf": "Barryvdh\\DomPDF\\Facade\\Pdf", + "PDF": "Barryvdh\\DomPDF\\Facade\\Pdf" + } + } + }, + "autoload": { + "psr-4": { + "Barryvdh\\DomPDF\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "A DOMPDF Wrapper for Laravel", + "keywords": [ + "dompdf", + "laravel", + "pdf" + ], + "support": { + "issues": "https://github.com/barryvdh/laravel-dompdf/issues", + "source": "https://github.com/barryvdh/laravel-dompdf/tree/v2.0.0" + }, + "funding": [ + { + "url": "https://fruitcake.nl", + "type": "custom" + }, + { + "url": "https://github.com/barryvdh", + "type": "github" + } + ], + "time": "2022-07-06T11:12:10+00:00" + }, { "name": "brick/math", "version": "0.10.2", @@ -643,6 +720,68 @@ ], "time": "2022-02-28T11:07:21+00:00" }, + { + "name": "dompdf/dompdf", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/dompdf/dompdf.git", + "reference": "c5310df0e22c758c85ea5288175fc6cd777bc085" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dompdf/dompdf/zipball/c5310df0e22c758c85ea5288175fc6cd777bc085", + "reference": "c5310df0e22c758c85ea5288175fc6cd777bc085", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-mbstring": "*", + "masterminds/html5": "^2.0", + "phenx/php-font-lib": ">=0.5.4 <1.0.0", + "phenx/php-svg-lib": ">=0.3.3 <1.0.0", + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "ext-json": "*", + "ext-zip": "*", + "mockery/mockery": "^1.3", + "phpunit/phpunit": "^7.5 || ^8 || ^9", + "squizlabs/php_codesniffer": "^3.5" + }, + "suggest": { + "ext-gd": "Needed to process images", + "ext-gmagick": "Improves image processing performance", + "ext-imagick": "Improves image processing performance", + "ext-zlib": "Needed for pdf stream compression" + }, + "type": "library", + "autoload": { + "psr-4": { + "Dompdf\\": "src/" + }, + "classmap": [ + "lib/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-2.1" + ], + "authors": [ + { + "name": "The Dompdf Community", + "homepage": "https://github.com/dompdf/dompdf/blob/master/AUTHORS.md" + } + ], + "description": "DOMPDF is a CSS 2.1 compliant HTML to PDF converter", + "homepage": "https://github.com/dompdf/dompdf", + "support": { + "issues": "https://github.com/dompdf/dompdf/issues", + "source": "https://github.com/dompdf/dompdf/tree/v2.0.1" + }, + "time": "2022-09-22T13:43:41+00:00" + }, { "name": "dragonmantank/cron-expression", "version": "v3.3.2", @@ -2174,6 +2313,75 @@ }, "time": "2022-04-15T14:02:14+00:00" }, + { + "name": "masterminds/html5", + "version": "2.7.6", + "source": { + "type": "git", + "url": "https://github.com/Masterminds/html5-php.git", + "reference": "897eb517a343a2281f11bc5556d6548db7d93947" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/897eb517a343a2281f11bc5556d6548db7d93947", + "reference": "897eb517a343a2281f11bc5556d6548db7d93947", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "ext-dom": "*", + "ext-libxml": "*", + "php": ">=5.3.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.8.35 || ^5.7.21 || ^6 || ^7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.7-dev" + } + }, + "autoload": { + "psr-4": { + "Masterminds\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matt Butcher", + "email": "technosophos@gmail.com" + }, + { + "name": "Matt Farina", + "email": "matt@mattfarina.com" + }, + { + "name": "Asmir Mustafic", + "email": "goetas@gmail.com" + } + ], + "description": "An HTML5 parser and serializer.", + "homepage": "http://masterminds.github.io/html5-php", + "keywords": [ + "HTML5", + "dom", + "html", + "parser", + "querypath", + "serializer", + "xml" + ], + "support": { + "issues": "https://github.com/Masterminds/html5-php/issues", + "source": "https://github.com/Masterminds/html5-php/tree/2.7.6" + }, + "time": "2022-08-18T16:18:26+00:00" + }, { "name": "monolog/monolog", "version": "2.8.0", @@ -2667,6 +2875,96 @@ ], "time": "2022-10-17T15:20:29+00:00" }, + { + "name": "phenx/php-font-lib", + "version": "0.5.4", + "source": { + "type": "git", + "url": "https://github.com/dompdf/php-font-lib.git", + "reference": "dd448ad1ce34c63d09baccd05415e361300c35b4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dompdf/php-font-lib/zipball/dd448ad1ce34c63d09baccd05415e361300c35b4", + "reference": "dd448ad1ce34c63d09baccd05415e361300c35b4", + "shasum": "" + }, + "require": { + "ext-mbstring": "*" + }, + "require-dev": { + "symfony/phpunit-bridge": "^3 || ^4 || ^5" + }, + "type": "library", + "autoload": { + "psr-4": { + "FontLib\\": "src/FontLib" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Fabien Ménager", + "email": "fabien.menager@gmail.com" + } + ], + "description": "A library to read, parse, export and make subsets of different types of font files.", + "homepage": "https://github.com/PhenX/php-font-lib", + "support": { + "issues": "https://github.com/dompdf/php-font-lib/issues", + "source": "https://github.com/dompdf/php-font-lib/tree/0.5.4" + }, + "time": "2021-12-17T19:44:54+00:00" + }, + { + "name": "phenx/php-svg-lib", + "version": "0.5.0", + "source": { + "type": "git", + "url": "https://github.com/dompdf/php-svg-lib.git", + "reference": "76876c6cf3080bcb6f249d7d59705108166a6685" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dompdf/php-svg-lib/zipball/76876c6cf3080bcb6f249d7d59705108166a6685", + "reference": "76876c6cf3080bcb6f249d7d59705108166a6685", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": "^7.1 || ^8.0", + "sabberworm/php-css-parser": "^8.4" + }, + "require-dev": { + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Svg\\": "src/Svg" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0" + ], + "authors": [ + { + "name": "Fabien Ménager", + "email": "fabien.menager@gmail.com" + } + ], + "description": "A library to read, parse and export to PDF SVG files.", + "homepage": "https://github.com/PhenX/php-svg-lib", + "support": { + "issues": "https://github.com/dompdf/php-svg-lib/issues", + "source": "https://github.com/dompdf/php-svg-lib/tree/0.5.0" + }, + "time": "2022-09-06T12:16:56+00:00" + }, { "name": "phpoption/phpoption", "version": "1.9.0", @@ -3448,6 +3746,59 @@ ], "time": "2022-09-16T03:22:46+00:00" }, + { + "name": "sabberworm/php-css-parser", + "version": "8.4.0", + "source": { + "type": "git", + "url": "https://github.com/sabberworm/PHP-CSS-Parser.git", + "reference": "e41d2140031d533348b2192a83f02d8dd8a71d30" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sabberworm/PHP-CSS-Parser/zipball/e41d2140031d533348b2192a83f02d8dd8a71d30", + "reference": "e41d2140031d533348b2192a83f02d8dd8a71d30", + "shasum": "" + }, + "require": { + "ext-iconv": "*", + "php": ">=5.6.20" + }, + "require-dev": { + "codacy/coverage": "^1.4", + "phpunit/phpunit": "^4.8.36" + }, + "suggest": { + "ext-mbstring": "for parsing UTF-8 CSS" + }, + "type": "library", + "autoload": { + "psr-4": { + "Sabberworm\\CSS\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Raphael Schweikert" + } + ], + "description": "Parser for CSS Files written in PHP", + "homepage": "https://www.sabberworm.com/blog/2010/6/10/php-css-parser", + "keywords": [ + "css", + "parser", + "stylesheet" + ], + "support": { + "issues": "https://github.com/sabberworm/PHP-CSS-Parser/issues", + "source": "https://github.com/sabberworm/PHP-CSS-Parser/tree/8.4.0" + }, + "time": "2021-12-11T13:40:54+00:00" + }, { "name": "symfony/console", "version": "v6.1.6", diff --git a/database/migrations/2022_07_07_012118_create_plans_table.php b/database/migrations/2022_07_07_012118_create_plans_table.php index a0a39ab..4ab9626 100644 --- a/database/migrations/2022_07_07_012118_create_plans_table.php +++ b/database/migrations/2022_07_07_012118_create_plans_table.php @@ -11,12 +11,16 @@ * * @return void */ + + //hacer null todo menos codigo, user, estandar + + public function up() { Schema::create('plans', function (Blueprint $table) { $table->id(); $table->string('codigo', 11); - $table->string('nombre',255)->nullable(); + $table->string('nombre', 255)->nullable(); $table->string('oportunidad_plan')->nullable(); $table->string('semestre_ejecucion', 8)->nullable(); $table->integer('avance')->nullable(); @@ -24,9 +28,9 @@ public function up() $table->string('estado', 30)->nullable(); $table->boolean('evaluacion_eficacia'); $table->foreignId('id_estandar') - ->constrained('estandars'); + ->constrained('estandars'); $table->foreignId('id_user') - ->constrained('users'); + ->constrained('users'); $table->unique(['codigo', 'id_estandar']); $table->timestamps(); }); diff --git a/resources/views/planPDF.blade.php b/resources/views/planPDF.blade.php new file mode 100644 index 0000000..e69de29