-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Agregada vista de regularización de documentos
- Loading branch information
1 parent
2954300
commit a1f2c98
Showing
24 changed files
with
625 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ | |
"password": "admin", | ||
"email": "[email protected]", | ||
"address": "Z. ZONA AV. AVENIDA Nº 123456", | ||
"phone": "7654321", | ||
"phone": "7654321" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
app/Http/Controllers/ProcedureRequirementController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Procedure; | ||
use App\Http\Requests\ProcedureRequirementRequest; | ||
use App\Http\Resources\ProcedureRequirementResource; | ||
use App\Http\Resources\ProcedureFlowResource; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Http\Request; | ||
|
||
class ProcedureRequirementController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index(Request $request) | ||
{ | ||
/** @var \App\Models\User */ | ||
$user = Auth::user(); | ||
$area_id = $user->area_id; | ||
$owned_procedures = DB::table('procedures')->where('area_id', $area_id)->where('verified', '=', false)->select('id'); | ||
if ($request->has('sort_by') && $request->has('sort_desc')) { | ||
foreach ($request->sort_by as $i => $sort) { | ||
$owned_procedures->orderBy($sort, filter_var($request->sort_desc[$i], FILTER_VALIDATE_BOOLEAN) ? 'DESC' : 'ASC'); | ||
} | ||
} | ||
// Tramites que se encuentran actualmente en la sección | ||
$current = DB::table('procedures as p')->select('p.id', 'pf.from_area', 'pf.created_at as incoming_at', 'pf.user_id as incoming_user', DB::raw('null as to_area'), DB::raw('null as outgoing_at'), DB::raw('null as outgoing_user'), DB::raw('TRUE as owner'), 'p.archived')->leftJoin('procedure_flows as pf', function($query) { | ||
$query->on('pf.procedure_id','=','p.id')->whereRaw('pf.id IN (select MAX(a.id) from procedure_flows as a join procedures as b on a.procedure_id = b.id group by b.id)'); | ||
})->whereIn('p.id', $owned_procedures->where('pending', false))->where('p.deleted_at', null)->where('p.archived', false); | ||
if ($request->has('search')) { | ||
if ($request->search != '') { | ||
$current->where(function($q) use ($request) { | ||
return $q->orWhere(DB::raw('upper(p.code)'), 'like', '%'.trim(mb_strtoupper($request->search)).'%')->orWhere(DB::raw('upper(p.origin)'), 'like', '%'.trim(mb_strtoupper($request->search)).'%'); | ||
}); | ||
} | ||
} | ||
$procedures = DB::table($current)->orderBy('archived', 'ASC')->orderByRaw('-outgoing_at ASC')->orderByRaw('incoming_at DESC'); | ||
return [ | ||
'message' => 'Lista de trámites', | ||
'payload' => ProcedureFlowResource::collection($procedures->paginate($request->per_page ?? 8, ['*'], 'page', $request->page ?? 1))->resource, | ||
]; | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param \App\Models\Procedure $procedure | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show(Procedure $procedure) | ||
{ | ||
return [ | ||
'message' => 'Requisitos de hoja de ruta', | ||
'payload' => [ | ||
'procedure' => new ProcedureRequirementResource($procedure), | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \App\Models\Procedure $procedure | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(ProcedureRequirementRequest $request, Procedure $procedure) | ||
{ | ||
DB::beginTransaction(); | ||
try { | ||
foreach($request->requirements as $requirement) { | ||
$procedure->requirements()->updateExistingPivot($requirement['id'], [ | ||
'validated' => $requirement['validated'], | ||
], false); | ||
} | ||
$procedure->update([ | ||
'verified' => $procedure->validated, | ||
]); | ||
DB::commit(); | ||
return [ | ||
'message' => $procedure->validated ? 'Hoja de ruta lista para derivar' : 'Hoja de ruta enviada a regularización', | ||
'payload' => [ | ||
'procedure' => new ProcedureRequirementResource($procedure), | ||
] | ||
]; | ||
} catch(\Throwable $e) { | ||
DB::rollBack(); | ||
return response()->json([ | ||
'message' => 'Error al actualizar los requisitos del hoja de ruta', | ||
], 500); | ||
} | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param \App\Models\Procedure $procedure | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy(Procedure $procedure) | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Middleware; | ||
|
||
use App\Models\Procedure; | ||
use Closure; | ||
use Illuminate\Http\Request; | ||
|
||
class EnsureUserOwnsProcedure | ||
{ | ||
/** | ||
* Handle an incoming request. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param \Closure $next | ||
* @return mixed | ||
*/ | ||
public function handle(Request $request, Closure $next) | ||
{ | ||
$user = auth()->user(); | ||
$procedure = Procedure::findOrFail($request->procedure->id); | ||
if ($procedure->user_id === $user->id) { | ||
return $next($request); | ||
} else { | ||
return response()->json([ | ||
'message' => 'El trámite no se modificar porque no se encuentra en su bandeja', | ||
], 422); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
class ProcedureRequirementResource extends JsonResource | ||
{ | ||
/** | ||
* Transform the resource into an array. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return array | ||
*/ | ||
public function toArray($request) | ||
{ | ||
return [ | ||
'id' => $this->id, | ||
'code' => $this->code, | ||
'verified' => $this->verified, | ||
'requirements' => $this->requirements()->orderBy('name')->get()->map(function($item, $key) { | ||
$item->validated = $item->pivot->validated; | ||
return $item->only(['id', 'name', 'validated', 'updated_at']); | ||
}), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.