Carga inicial
This commit is contained in:
469
app/Http/Controllers/Operador/CheckListController.php
Normal file
469
app/Http/Controllers/Operador/CheckListController.php
Normal file
@@ -0,0 +1,469 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Models\CorreoSucursal;
|
||||
use App\Models\Sucursal;
|
||||
use const App\Http\Controllers\CORREOS_DEV;
|
||||
use const App\Http\Controllers\CORREOS_PROD;
|
||||
use App\Models\RespuestaOperadorDet;
|
||||
use App\Models\RespuestaOperadorEnc;
|
||||
use App\Models\Vehiculo;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
use App\Http\Requests\Operador\RespuestasOperadorRequest;
|
||||
use DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Log;
|
||||
use App\Mail\RespuestasOperador;
|
||||
|
||||
|
||||
class CheckListController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
function index(Request $request)
|
||||
{
|
||||
$now = Carbon::now()->format('Y-m-d');
|
||||
$checklist = [
|
||||
[
|
||||
'id' => 1,
|
||||
'nombre' => "VEHÍCULO ASIGNADO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'nombre' => "NIVEL DE ACEITE MOTOR PRINCIPAL",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'nombre' => "NIVEL DE ANTICONGELANTE MOTOR PRINCIPAL",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 4,
|
||||
'nombre' => "NIVEL ACEITE HIDRAULICO MOTOR PRINCIPAL",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 5,
|
||||
'nombre' => "NIVEL DE ANTICONGELANTE BOMBA SUCCION",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 6,
|
||||
'nombre' => "NIVEL DE ACEITE BOMBA DE SUCCION",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 7,
|
||||
'nombre' => "NIVEL DE COMBUSTIBLE MOTOR PRINCIPAL",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 8,
|
||||
'nombre' => "NIVEL DE COMBUSTIBLE MOTOR AUXILIAR",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 9,
|
||||
'nombre' => "NIVEL DE TANQUE DE AGUA",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 10,
|
||||
'nombre' => "REVISION DE LLANTAS",
|
||||
'tipo_radio_btn' => 1,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 11,
|
||||
'nombre' => "LIMPIEZA DE VEHÍCULO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 12,
|
||||
'nombre' => "REPORTE DE FALLAS E INCIDENCIAS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'REVISION',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 13,
|
||||
'nombre' => "TARJETA DE CIRCULACIÓN",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 14,
|
||||
'nombre' => "MALETIN",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 15,
|
||||
'nombre' => "LICENCIA VIGENTE",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 16,
|
||||
'nombre' => "PÓLIZA DE SEGURO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 17,
|
||||
'nombre' => "ALTA DE SEGURO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 18,
|
||||
'nombre' => "RECIBOS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
/*[
|
||||
'id' => 19,
|
||||
'nombre' => "ENCUESTA",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],*/
|
||||
[
|
||||
'id' => 20,
|
||||
'nombre' => "PERMISO DE TIRADAS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 21,
|
||||
'nombre' => "RADIO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 22,
|
||||
'nombre' => "COMENTARIOS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'MATERIAL',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 23,
|
||||
'nombre' => "PALA",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 24,
|
||||
'nombre' => "BARRA",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 25,
|
||||
'nombre' => "ESPATULA",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 26,
|
||||
'nombre' => "CAJA DE HERRAMIENTAS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 27,
|
||||
'nombre' => "SANITIZANTE",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 28,
|
||||
'nombre' => "CONOS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 29,
|
||||
'nombre' => "CHALECO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 30,
|
||||
'nombre' => "CASCO",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 31,
|
||||
'nombre' => "K-60",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 32,
|
||||
'nombre' => "K-06",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 33,
|
||||
'nombre' => "BOQUILLA SANITARIA",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 0,
|
||||
'tipo_checkbox' => 1,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
],
|
||||
[
|
||||
'id' => 34,
|
||||
'nombre' => "COMENTARIOS",
|
||||
'tipo_radio_btn' => 0,
|
||||
'tipo_text' => 1,
|
||||
'tipo_checkbox' => 0,
|
||||
'tipo' => 'HERRAMIENTA',
|
||||
'fecha' => $now
|
||||
]
|
||||
];
|
||||
|
||||
$reinicio = $request->input('cambiar_vehiculo', 0);
|
||||
|
||||
if($reinicio == 0){
|
||||
if(RespuestaOperadorEnc::where('user_id',Auth::id())->whereDate('fecha',$now)->first()){
|
||||
$checklist = [];
|
||||
}
|
||||
}
|
||||
|
||||
return response()->success($checklist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(RespuestasOperadorRequest $request)
|
||||
{
|
||||
$user_id = Auth::id();
|
||||
$user = Auth::user();
|
||||
$data = $request->all();
|
||||
$ambiente = strtolower(config('ambiente')['ambiente']);
|
||||
|
||||
$correos_sucursales_prod = CorreoSucursal::select('email')->where('correos_sucursales.sucursal_id', $user->sucursal_id)->get();
|
||||
$correos = ($ambiente == 'dev')? $correos_sucursales_prod : CORREOS_DEV;
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$fecha = $data[0]['fecha'];
|
||||
|
||||
$respuesta_operador_enc = RespuestaOperadorEnc::create(['user_id' => $user_id, 'fecha' => $fecha]);
|
||||
|
||||
foreach ($data as $d){
|
||||
|
||||
$info = [
|
||||
'respuestas_operador_enc_id' => $respuesta_operador_enc->id,
|
||||
'nombre' => $d['nombre'],
|
||||
'tipo' => $d['tipo'],
|
||||
'tipo_checkbox' => $d['tipo_checkbox'],
|
||||
'tipo_text' => $d['tipo_text'],
|
||||
'tipo_radio_btn' => $d['tipo_radio_btn'],
|
||||
'respuesta_checkbox' => array_key_exists('respuesta_checkbox', $d) ? $d['respuesta_checkbox'] : null,
|
||||
'respuesta_text' => array_key_exists('respuesta_text', $d) ? $d['respuesta_text'] : null,
|
||||
'respuesta_radio_btn' => array_key_exists('respuesta_radio_btn', $d) ? $d['respuesta_radio_btn'] : null
|
||||
];
|
||||
|
||||
RespuestaOperadorDet::create($info);
|
||||
}
|
||||
|
||||
|
||||
DB::commit();
|
||||
|
||||
try {
|
||||
Mail::to($correos)->send(new RespuestasOperador($respuesta_operador_enc->id));
|
||||
} catch (\Exception $e) {
|
||||
\Log::info("Error al enviar correo: " . json_encode($e->getMessage()));
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
return response()->unprocessable('Error', [$e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
Auth::user();
|
||||
|
||||
$campos = [
|
||||
'user_id',
|
||||
'nombre',
|
||||
'tipo',
|
||||
'tipo_checkbox',
|
||||
'tipo_text',
|
||||
'tipo_radio_btn',
|
||||
'respuesta_checkbox',
|
||||
'respuesta_text',
|
||||
'respuesta_radio_btn',
|
||||
'fecha'
|
||||
];
|
||||
|
||||
$respuestas_operador = RespuestaOperador::select($campos)
|
||||
->where('user_id', $id)
|
||||
->first();
|
||||
|
||||
return response()->success($respuestas_operador);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function vehiculos(){
|
||||
|
||||
$vehiculos = Vehiculo::select('id', 'num_economico as nombre')->get();
|
||||
|
||||
return response()->success($vehiculos);
|
||||
}
|
||||
}
|
||||
28
app/Http/Controllers/Operador/DesplazamientosController.php
Normal file
28
app/Http/Controllers/Operador/DesplazamientosController.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Http\Requests\Operador\DesplazamientoRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
|
||||
class DesplazamientosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(DesplazamientoRequest $request)
|
||||
{
|
||||
/*$data = $request->toArray();
|
||||
|
||||
Auth::user($data)
|
||||
->desplazamientos()
|
||||
->createMany($data);*/
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
130
app/Http/Controllers/Operador/EncuestasController.php
Normal file
130
app/Http/Controllers/Operador/EncuestasController.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Models\ServicioProgreso;
|
||||
use const App\Http\Controllers\DOMESTICO;
|
||||
use App\Models\RespuestaDomestico;
|
||||
use App\Models\RespuestaEmpresarial;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEncuestaDomestico;
|
||||
use App\Models\ServicioEncuestaEmpresarial;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use DB;
|
||||
use Log;
|
||||
|
||||
class EncuestasController extends Controller
|
||||
{
|
||||
|
||||
public function store(Request $request, $servicio_id)
|
||||
{
|
||||
$now = Carbon::now()->format('Y-m-d');
|
||||
$servicio_det = ServicioDet::where('id', $servicio_id)->firstOrFail();
|
||||
|
||||
list($fecha) = explode(" ", $servicio_det->fecha_solicitud);
|
||||
|
||||
//Validar fecha de solicitud
|
||||
if($now != $fecha){
|
||||
//return response()->unprocessable('Parametros inválidos',['No se puede realizar la encuesta ya que corresponde a otra fecha.']);
|
||||
}
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
if($servicio_det->tipo_servicio_id == DOMESTICO) {
|
||||
$validator = Validator::make($data, [
|
||||
'*.pregunta_id' => 'numeric|exists:preguntas_domestico,id',
|
||||
'*.respuesta_id' => 'numeric|exists:respuestas_domestico,id',
|
||||
'*.respuesta' => 'string|max:255'
|
||||
]);
|
||||
|
||||
if(ServicioEncuestaDomestico::where('servicio_det_id', $servicio_id)->first()){
|
||||
//return response()->unprocessable('Parametros inválidos',['La encuesta para este servicio ya se realizó.']);
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
foreach ($data as $d){
|
||||
if(isset($d['respuesta_id'])){
|
||||
$respuesta = RespuestaDomestico::where('pregunta_id', $d['pregunta_id'])
|
||||
->where('id', $d['respuesta_id'])
|
||||
->first();
|
||||
|
||||
if(!$respuesta){
|
||||
return response()->unprocessable('Parametros inválidos',['La respuesta no corresponde a la pregunta.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$validator = Validator::make($data, [
|
||||
'*.pregunta_id' => 'numeric|exists:preguntas_empresarial,id',
|
||||
'*.respuesta_id' => 'numeric|exists:respuestas_empresarial,id',
|
||||
'*.respuesta' => 'string|max:255'
|
||||
]);
|
||||
|
||||
if(ServicioEncuestaEmpresarial::where('servicio_det_id', $servicio_id)->first()){
|
||||
//return response()->unprocessable('Parametros inválidos',['La encuesta para este servicio ya se realizó.']);
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
foreach ($data as $d){
|
||||
if(isset($d['respuesta_id'])){
|
||||
$respuesta = RespuestaEmpresarial::where('pregunta_id', $d['pregunta_id'])
|
||||
->where('id', $d['respuesta_id'])
|
||||
->first();
|
||||
|
||||
if(!$respuesta){
|
||||
return response()->unprocessable('Parametros inválidos',['La respuesta no corresponde a la pregunta.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($validator->fails()){
|
||||
return response()->unprocessable('Parametros inválidos',$validator->errors()->all());
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
if($servicio_det->tipo_servicio_id == DOMESTICO) {
|
||||
foreach ($data as $d){
|
||||
|
||||
$data_domestico = [
|
||||
'servicio_det_id' => $servicio_id,
|
||||
'pregunta_id' => $d['pregunta_id'],
|
||||
'respuesta_id' => (isset($d['respuesta_id']))? $d['respuesta_id'] : null,
|
||||
'respuesta' => (isset($d['respuesta']))? $d['respuesta'] : null
|
||||
];
|
||||
ServicioEncuestaDomestico::create($data_domestico);
|
||||
}
|
||||
|
||||
}else{
|
||||
foreach ($data as $d){
|
||||
$data_empresarial = [
|
||||
'servicio_det_id' => $servicio_id,
|
||||
'pregunta_id' => $d['pregunta_id'],
|
||||
'respuesta_id' => (isset($d['respuesta_id']))? $d['respuesta_id'] : null,
|
||||
'respuesta' => (isset($d['respuesta']))? $d['respuesta'] : null
|
||||
];
|
||||
ServicioEncuestaEmpresarial::create($data_empresarial);
|
||||
}
|
||||
}
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $servicio_det->servicio_enc_id)
|
||||
->where('servicio_det_id', $servicio_det->id)
|
||||
->first();
|
||||
|
||||
if($servicio_progreso){
|
||||
$servicio_progreso->update(['encuesta_contestada' => 1]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al realizar la encuesta.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
193
app/Http/Controllers/Operador/JornadaController.php
Normal file
193
app/Http/Controllers/Operador/JornadaController.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Models\CatMotivoEstatus;
|
||||
use const App\Http\Controllers\PAGADO;
|
||||
use const App\Http\Controllers\PENDIENTE;
|
||||
use const App\Http\Controllers\REPROGRAMADO;
|
||||
use const App\Http\Controllers\VEHICULO_ASIGNADO;
|
||||
use const App\Http\Controllers\VISITA;
|
||||
use App\Http\Requests\Operador\FinalizarJornadaRequest;
|
||||
use App\Http\Requests\Operador\InicioJornadaRequest;
|
||||
use App\Models\BitacoraLaboral;
|
||||
use App\Models\Parametro;
|
||||
use App\Models\PreguntaDomestico;
|
||||
use App\Models\PreguntaEmpresarial;
|
||||
use App\Models\RespuestaDomestico;
|
||||
use App\Models\RespuestaEmpresarial;
|
||||
use App\Models\RespuestaOperadorDet;
|
||||
use App\Models\RespuestaOperadorEnc;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\User;
|
||||
use App\Models\UsuarioDesplazamiento;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
use Log;
|
||||
use DB;
|
||||
|
||||
class JornadaController extends Controller
|
||||
{
|
||||
public function inicioJornada(InicioJornadaRequest $request)
|
||||
{
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
$user = Auth::user();
|
||||
$fecha = Carbon::now()->toDateTimeString();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$bitacora = BitacoraLaboral::where('usuario_id', $user->id)
|
||||
->whereNull('fecha_hora_fin')
|
||||
->first();
|
||||
|
||||
if($bitacora){
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('JORNADA_YA_INICIADA', [$bitacora->id]);
|
||||
}
|
||||
|
||||
$campos = $this->camposSolicitudesServiciosOperador();
|
||||
|
||||
$servicios = ServicioDet::select($campos)
|
||||
->joinDetalleServicioDet()
|
||||
->joinDetalleServicioDetMovil()
|
||||
->leftJoin('servicios_progreso', function($join)
|
||||
{
|
||||
$join->on('servicios_enc.id', '=', 'servicios_progreso.servicio_enc_id');
|
||||
$join->on('servicios_det.id', '=', 'servicios_progreso.servicio_det_id');
|
||||
})
|
||||
->whereNull('servicios_progreso.id')
|
||||
->whereIn('servicios_det.estatus_servicio_id', [PENDIENTE, REPROGRAMADO, VISITA, PAGADO])
|
||||
->where('servicios_det.operador_id', $user->id)
|
||||
->where('servicios_enc.sucursal_id', $user->sucursal_id)
|
||||
->whereDate('servicios_det.fecha_solicitud', Carbon::now()->format('Y-m-d'))
|
||||
->orderBy('servicios_det.fecha_solicitud')
|
||||
->get();
|
||||
|
||||
/*$fecha_actual = Carbon::now()->format('Y-m-d');
|
||||
|
||||
$servicios = [];
|
||||
|
||||
foreach ($servicios_list as $s){
|
||||
|
||||
$fecha_asignacion = Carbon::createFromTimeString($s->fecha_agenda)->format('Y-m-d');
|
||||
|
||||
if($fecha_asignacion == $fecha_actual && $s->aceptado){
|
||||
$servicios[] = $s;
|
||||
}elseif ($fecha_asignacion != $fecha_actual){
|
||||
$servicios[] = $s;
|
||||
}
|
||||
}*/
|
||||
|
||||
$encuesta_operador = RespuestaOperadorEnc::select('respuestas_operador_enc.id')
|
||||
->join('respuestas_operador_det', 'respuestas_operador_det.respuestas_operador_enc_id', '=', 'respuestas_operador_enc.id')
|
||||
->where('respuestas_operador_enc.user_id', $user->id)
|
||||
->orderBy('respuestas_operador_enc.created_at','desc')
|
||||
->first();
|
||||
|
||||
$vehiculo_operador = RespuestaOperadorDet::select('cat_vehiculos.id', 'respuestas_operador_det.respuesta_text')
|
||||
->join('respuestas_operador_enc', 'respuestas_operador_enc.id', '=', 'respuestas_operador_det.respuestas_operador_enc_id')
|
||||
->join('cat_vehiculos','cat_vehiculos.num_economico', '=', 'respuestas_operador_det.respuesta_text')
|
||||
->where('respuestas_operador_enc.user_id', $user->id)
|
||||
->where('respuestas_operador_det.nombre', '=',VEHICULO_ASIGNADO)
|
||||
->where('respuestas_operador_det.respuestas_operador_enc_id', $encuesta_operador->id)
|
||||
->first();
|
||||
|
||||
//$servi = collect($servicios)->first();
|
||||
//$data['vehiculo_id'] = ($servi) ? $servi->vehiculo_id : null;
|
||||
|
||||
$data['vehiculo_id'] = ($vehiculo_operador->id) ? $vehiculo_operador->id : 2;
|
||||
|
||||
$data['usuario_id'] = $user->id;
|
||||
$data['fecha_hora_ini'] = $fecha;
|
||||
$jornada = BitacoraLaboral::create($data);
|
||||
|
||||
$data_desplazamiento = [
|
||||
'bitacora_laboral_id' => $jornada->id,
|
||||
'usuario_id' => $user->id,
|
||||
'fecha' => $fecha,
|
||||
'modelo_celular' => $data['modelo_celular'],
|
||||
'bateria' => $data['bateria'],
|
||||
'lat' => $data['lat_ini'],
|
||||
'lng' => $data['lng_ini']
|
||||
];
|
||||
|
||||
UsuarioDesplazamiento::create($data_desplazamiento);
|
||||
|
||||
User::where('id', $user->id)->first()->update(['token_firebase' => $data['token_firebase']]);
|
||||
|
||||
$parametros = Parametro::get();
|
||||
|
||||
$encuesta_domestico = PreguntaDomestico::get();
|
||||
|
||||
foreach ($encuesta_domestico as $eD){
|
||||
$eD->respuestas = RespuestaDomestico::where('pregunta_id', $eD->id)->get();
|
||||
}
|
||||
|
||||
$encuesta_empresarial = PreguntaEmpresarial::get();
|
||||
|
||||
foreach ($encuesta_empresarial as $eE){
|
||||
$eE->respuestas = RespuestaEmpresarial::where('pregunta_id', $eE->id)->get();
|
||||
}
|
||||
|
||||
$motivos_estatus = CatMotivoEstatus::select('id', 'nombre as descripcion')
|
||||
->get();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(compact('servicios', 'parametros', 'jornada', 'encuesta_domestico', 'encuesta_empresarial', 'motivos_estatus'));
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
return response()->unprocessable('Error', ['Error al guardar el inicio de jornada.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function finalizarJornada(FinalizarJornadaRequest $request, $id){
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
$user = Auth::user();
|
||||
$fecha = Carbon::now()->toDateTimeString();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$jornada = BitacoraLaboral::where('id',$id)
|
||||
->first();
|
||||
|
||||
if($jornada->fecha_hora_fin){
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['La jornada ya se encuentra finalizada.']);
|
||||
}
|
||||
|
||||
$data['fecha_hora_fin'] = $fecha;
|
||||
$jornada->update($data);
|
||||
|
||||
$data_desplazamiento = [
|
||||
'bitacora_laboral_id' => $id,
|
||||
'usuario_id' => $user->id,
|
||||
'fecha' => $fecha,
|
||||
'modelo_celular' => $data['modelo_celular'],
|
||||
'bateria' => $data['bateria'],
|
||||
'lat' => $data['lat_fin'],
|
||||
'lng' => $data['lng_fin']
|
||||
];
|
||||
|
||||
UsuarioDesplazamiento::create($data_desplazamiento);
|
||||
|
||||
User::where('id', $user->id)->update(['token_firebase' => NULL]);
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al guardar el fin de jornada.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
267
app/Http/Controllers/Operador/ServiciosController.php
Normal file
267
app/Http/Controllers/Operador/ServiciosController.php
Normal file
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Models\Parametro;
|
||||
use const App\Http\Controllers\ANCLAJE_SERVICIO_HORAS;
|
||||
use const App\Http\Controllers\LLAVE_ANCLAJE_SERVICIO_HORAS;
|
||||
use const App\Http\Controllers\PAGADO;
|
||||
use const App\Http\Controllers\PENDIENTE;
|
||||
use const App\Http\Controllers\REPROGRAMADO;
|
||||
use const App\Http\Controllers\VISITA;
|
||||
use App\Http\Requests\Operador\RechazarSolicitudRequest;
|
||||
use App\Models\CatServicio;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\ServicioProgreso;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Log;
|
||||
|
||||
class ServiciosController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
if(!Carbon::parse($user->last_login)->isToday()){
|
||||
return response()->json(['error'=>'Es necesario iniciar sesión el día de hoy'],420);
|
||||
}
|
||||
|
||||
$ayer = Carbon::yesterday()->format('Y-m-d 23:00:00');
|
||||
$hoy = Carbon::now()->format('Y-m-d 23:59:59');
|
||||
|
||||
$campos = $this->camposSolicitudesServiciosOperador();
|
||||
|
||||
$s = ServicioDet::select($campos)
|
||||
->joinDetalleServicioDet()
|
||||
->joinDetalleServicioDetMovil()
|
||||
->leftJoin('servicios_progreso', function($join)
|
||||
{
|
||||
$join->on('servicios_enc.id', '=', 'servicios_progreso.servicio_enc_id');
|
||||
$join->on('servicios_det.id', '=', 'servicios_progreso.servicio_det_id');
|
||||
})
|
||||
->whereNull('servicios_progreso.id')
|
||||
->whereIn('servicios_det.estatus_servicio_id', [PENDIENTE, REPROGRAMADO, VISITA, PAGADO])
|
||||
->where('servicios_det.operador_id', $user->id)
|
||||
->where('servicios_enc.sucursal_id', $user->sucursal_id)
|
||||
->whereBetween('servicios_det.fecha_solicitud', [$ayer, $hoy])
|
||||
->get();
|
||||
|
||||
$servicios_progresos = ServicioProgreso::select('servicio_det_id')->get();
|
||||
if(count($servicios_progresos) != 0){
|
||||
$servicios = collect($s)->whereNotIn('id',$servicios_progresos->pluck('servicio_det_id'))->all();
|
||||
}else{
|
||||
$servicios = $s;
|
||||
}
|
||||
|
||||
$tiempo_anclaje = Parametro::where('llave',LLAVE_ANCLAJE_SERVICIO_HORAS)->first();
|
||||
$tiempo_anclaje = ($tiempo_anclaje)? $tiempo_anclaje->valor : ANCLAJE_SERVICIO_HORAS;
|
||||
$tiempo_anclaje = (1 + $tiempo_anclaje) * 60;
|
||||
|
||||
$data = [];
|
||||
$hoy = Carbon::now();
|
||||
$hoy_dia = $hoy->format('Y-m-d');
|
||||
|
||||
foreach ($servicios as $s){
|
||||
if(Carbon::parse($s->fecha_solicitud)->format('Y-m-d') == $hoy_dia){
|
||||
array_push($data, $s);
|
||||
}else{
|
||||
if(Carbon::parse($s->fecha_solicitud)->diffInMinutes($hoy) <= $tiempo_anclaje){
|
||||
array_push($data, $s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Comentado por rechazo del cliente
|
||||
/*$fecha_actual = Carbon::now()->format('Y-m-d');
|
||||
|
||||
$salida = [];
|
||||
|
||||
foreach ($servicios as $s){
|
||||
|
||||
$fecha_asignacion = Carbon::createFromTimeString($s->fecha_agenda)->format('Y-m-d');
|
||||
|
||||
if($fecha_asignacion == $fecha_actual && $s->aceptado){
|
||||
$salida[] = $s;
|
||||
}elseif ($fecha_asignacion != $fecha_actual){
|
||||
$salida[] = $s;
|
||||
}
|
||||
}*/
|
||||
|
||||
return response()->success($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$campos = $this->camposSolicitudesServiciosOperador();
|
||||
|
||||
$servicios = ServicioDet::select($campos)
|
||||
->joinDetalleServicioDet()
|
||||
->joinDetalleServicioDetMovil()
|
||||
->where('servicios_det.id', $id)
|
||||
->whereIn('servicios_det.estatus_servicio_id', [PENDIENTE, REPROGRAMADO, VISITA, PAGADO])
|
||||
->where('servicios_det.operador_id', $user->id)
|
||||
->where('servicios_enc.sucursal_id', $user->sucursal_id)
|
||||
->whereDate('servicios_det.fecha_solicitud', Carbon::now()->format('Y-m-d'))
|
||||
->first();
|
||||
|
||||
return response()->success($servicios);
|
||||
}
|
||||
|
||||
public function aceptarSolicitud($id){
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$ambiente = strtolower(config('ambiente')['ambiente']);
|
||||
|
||||
$url = config('ambiente')[$ambiente];
|
||||
|
||||
$servicio_det = ServicioDet::where('id',$id)->first();
|
||||
|
||||
if(!$servicio_det){
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['El servicio no se encontró en nuestros registros.']);
|
||||
}
|
||||
|
||||
$servicio_det->update(['aceptado' => 1]);
|
||||
|
||||
$servicio_enc = ServicioEnc::where('id',$servicio_det->servicio_enc_id)->first();
|
||||
$usuario = User::where('id', $servicio_enc->usuario_agenda_id)->first();
|
||||
|
||||
if($usuario->token_firebase) {
|
||||
|
||||
$authorization = config('firebase')['authorization'];
|
||||
$project_id = config('firebase')['project_id'];
|
||||
$endpoint = config('firebase')['endpoint'];
|
||||
|
||||
$headers = [
|
||||
'Authorization' => 'key=' . $authorization,
|
||||
'project_id' => $project_id,
|
||||
'content-type' => 'application/json'
|
||||
];
|
||||
|
||||
$cat_servicio = CatServicio::where('id', $servicio_det->servicio_id)->first();
|
||||
|
||||
$datos = ['registration_ids' => array($usuario->token_firebase),
|
||||
'data' => ['url' => $url, 'solicitud_id' => $servicio_det->servicio_enc_id,'servicio_id' => $id, 'title' => 'Servicio Aceptado', 'body' => $cat_servicio->nombre, 'observacion' => '']];
|
||||
|
||||
$client = new Client();
|
||||
$client->post($endpoint, [
|
||||
'headers' => $headers,
|
||||
'json' => $datos,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al aceptar solicitud.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function rechazarSolicitud(RechazarSolicitudRequest $request, $id){
|
||||
|
||||
$data = $request->all();
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$ambiente = strtolower(config('ambiente')['ambiente']);
|
||||
|
||||
$url = config('ambiente')[$ambiente];
|
||||
|
||||
$servicio_det = ServicioDet::where('id',$id)->first();
|
||||
|
||||
if(!$servicio_det){
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['El servicio no se encontró en nuestros registros.']);
|
||||
}
|
||||
|
||||
$servicio_det->update(['aceptado' => 0, 'operador_id' => null, 'vehiculo_id' => null, 'auxiliar_1' => null, 'auxiliar_2' => null, 'observacion' => $data['observacion']]);
|
||||
|
||||
$servicio_enc = ServicioEnc::where('id',$servicio_det->servicio_enc_id)->first();
|
||||
$usuario = User::where('id', $servicio_enc->usuario_agenda_id)->first();
|
||||
|
||||
if($usuario->token_firebase) {
|
||||
|
||||
$authorization = config('firebase')['authorization'];
|
||||
$project_id = config('firebase')['project_id'];
|
||||
$endpoint = config('firebase')['endpoint'];
|
||||
|
||||
$headers = [
|
||||
'Authorization' => 'key=' . $authorization,
|
||||
'project_id' => $project_id,
|
||||
'content-type' => 'application/json'
|
||||
];
|
||||
|
||||
$cat_servicio = CatServicio::where('id', $servicio_det->servicio_id)->first();
|
||||
|
||||
$datos = ['registration_ids' => array($usuario->token_firebase),
|
||||
'data' => ['url' => $url, 'solicitud_id' => $servicio_det->servicio_enc_id, 'servicio_id' => $id, 'title' => 'Servicio Rechazado', 'body' => $cat_servicio->nombre, 'observacion' => $data['observacion']]];
|
||||
|
||||
$client = new Client();
|
||||
$client->post($endpoint, [
|
||||
'headers' => $headers,
|
||||
'json' => $datos,
|
||||
]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al rechazar solicitud.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function ServiciosDiaSiguiente()
|
||||
{
|
||||
$user = Auth::user();
|
||||
|
||||
$campos = $this->camposSolicitudesServiciosOperador();
|
||||
|
||||
$s = ServicioDet::select($campos)
|
||||
->joinDetalleServicioDet()
|
||||
->joinDetalleServicioDetMovil()
|
||||
->whereIn('servicios_det.estatus_servicio_id', [PENDIENTE, REPROGRAMADO, VISITA, PAGADO])
|
||||
->where('servicios_det.operador_id', $user->id)
|
||||
->where('servicios_enc.sucursal_id', $user->sucursal_id)
|
||||
->whereDate('servicios_det.fecha_solicitud', Carbon::tomorrow()->format('Y-m-d'))
|
||||
->get();
|
||||
|
||||
|
||||
$servicios_progresos = ServicioProgreso::select('servicio_det_id')->get();
|
||||
if(count($servicios_progresos) != 0){
|
||||
$servicios = collect($s)->whereNotIn('id',$servicios_progresos->pluck('servicio_det_id'))->all();
|
||||
}else{
|
||||
$servicios = $s;
|
||||
}
|
||||
|
||||
return response()->success($servicios);
|
||||
}
|
||||
}
|
||||
474
app/Http/Controllers/Operador/ServiciosProgresoController.php
Normal file
474
app/Http/Controllers/Operador/ServiciosProgresoController.php
Normal file
@@ -0,0 +1,474 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use const App\Http\Controllers\COSTO_SERVICIO_NEGATIVO;
|
||||
use const App\Http\Controllers\NEGATIVO;
|
||||
use const App\Http\Controllers\REALIZADO;
|
||||
use App\Http\Requests\Operador\FinalizarServicioRequest;
|
||||
use App\Http\Requests\Operador\GuardarEvidenciaRequest;
|
||||
use App\Http\Requests\Operador\GuardarFirmaRequest;
|
||||
use App\Http\Requests\Operador\IniciarServicioRequest;
|
||||
use App\Mail\SolicitudServicioTerminado;
|
||||
use App\Models\Cliente;
|
||||
use App\Models\ClienteDomicilio;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\ServicioEvidencia;
|
||||
use App\Models\ServicioProgreso;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Log;
|
||||
use Excel;
|
||||
|
||||
class ServiciosProgresoController extends Controller
|
||||
{
|
||||
/**
|
||||
* Iniciar Servicio.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function iniciarServicio(IniciarServicioRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
$now = Carbon::now()->format('Y-m-d');
|
||||
$servicio = ServicioProgreso::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('servicio_det_id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
$servicio_det = ServicioDet::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
list($fecha) = explode(" ", $servicio_det->fecha_solicitud);
|
||||
|
||||
//Validar fecha de solicitud
|
||||
if($now != $fecha){
|
||||
//return response()->unprocessable('Parametros inválidos',['El servicio no se puede iniciar ya que corresponde a otra fecha.']);
|
||||
}
|
||||
|
||||
//Validar que el servicio no este iniciado
|
||||
if($servicio){
|
||||
return response()->unprocessable('Parametros inválidos',['El servicio ya está iniciado.']);
|
||||
}
|
||||
$data['fecha_ini_servidor'] = Carbon::now()->toDateTimeString();
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
|
||||
$data['lat_ini'] = $servicio_enc->lat;
|
||||
$data['lng_ini'] = $servicio_enc->lng;
|
||||
//
|
||||
|
||||
ServicioProgreso::create($data);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalizar Servicio.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function finalizarServicio(FinalizarServicioRequest $request)
|
||||
{
|
||||
$data = $request->only(['fecha_fin_celular', 'duracion', 'lat_fin', 'lng_fin', 'comentarios', 'aplica_garantia','litraje']);
|
||||
$cat_motivos_estatus_id = $request->input('cat_motivos_estatus_id',0);
|
||||
$now = Carbon::now();
|
||||
|
||||
$servicio_enc_id = $request->input('servicio_enc_id');
|
||||
$servicio_det_id = $request->input('servicio_det_id');
|
||||
$litraje = $request->litraje;
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $servicio_enc_id)
|
||||
->where('servicio_det_id', $servicio_det_id)
|
||||
->first();
|
||||
|
||||
$servicio_det = ServicioDet::where('servicio_enc_id', $servicio_enc_id)
|
||||
->where('id', $servicio_det_id)
|
||||
->first();
|
||||
$servicio = ServicioEnc::where('id', $servicio_enc_id)->first();
|
||||
|
||||
$correos = [];
|
||||
$correo_cliente = Cliente::select('email')->where('id', $servicio->cliente_id)->first();
|
||||
$correo_cliente_domicilio = ClienteDomicilio::select('email')->where('id', $servicio->cliente_domicilio_id)->first();
|
||||
|
||||
if($correo_cliente && $correo_cliente->email){
|
||||
array_push($correos, $correo_cliente->email);
|
||||
}
|
||||
if($correo_cliente_domicilio && $correo_cliente_domicilio->email){
|
||||
array_push($correos, $correo_cliente_domicilio->email);
|
||||
}
|
||||
|
||||
//Validar fecha de solicitud
|
||||
/*
|
||||
list($fecha) = explode(" ", $servicio_det->fecha_solicitud);
|
||||
|
||||
if($now->format('Y-m-d') != $fecha){
|
||||
return response()->unprocessable('Parametros inválidos',['No se puede finalizar el servicio ya que corresponde a otra fecha.']);
|
||||
}*/
|
||||
|
||||
//Validar que el servicio no este terminado
|
||||
if($servicio_det->estatus_servicio_id == REALIZADO){
|
||||
return response()->unprocessable('Parametros inválidos',['El servicio ya está terminado']);
|
||||
}
|
||||
|
||||
//Validar que el servicio esté iniciado
|
||||
if(!$servicio_progreso){
|
||||
return response()->unprocessable('Parametros inválidos',['El servicio no está iniciado.']);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$data['fecha_fin_servidor'] = $now->toDateTimeString();
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
$data['lat_fin'] = $servicio_enc->lat;
|
||||
$data['lng_fin'] = $servicio_enc->lng;
|
||||
if($litraje == 0){
|
||||
$data['litraje'] = null;
|
||||
}else{
|
||||
$data['litraje'] = $litraje;
|
||||
}
|
||||
|
||||
$servicio_progreso->update($data);
|
||||
if ($cat_motivos_estatus_id != 0){
|
||||
$servicio_det->update(
|
||||
[
|
||||
'estatus_servicio_id' => NEGATIVO,
|
||||
'cat_motivos_estatus_id' => $cat_motivos_estatus_id,
|
||||
'costo_servicio' => COSTO_SERVICIO_NEGATIVO,
|
||||
]
|
||||
);
|
||||
} else{
|
||||
$servicio_det->update(['estatus_servicio_id' => REALIZADO]);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
try {
|
||||
if(count($correos) > 0){
|
||||
Mail::to($correos)->send(new SolicitudServicioTerminado($servicio_enc_id,$servicio_det_id));
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e);
|
||||
return response()->unprocessable('Error', ['Error al finalizar servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Guardar Evidencia.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function guardarEvidencia(GuardarEvidenciaRequest $request)
|
||||
{
|
||||
$data = $request->only(['etapa', 'lat', 'lng', 'servicio_enc_id', 'servicio_det_id']);
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('servicio_det_id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
$servicio_det = ServicioDet::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
//Validar que el servicio no este terminado
|
||||
if($servicio_det->estatus_servicio_id == REALIZADO){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar que el servicio esté iniciado
|
||||
if(!$servicio_progreso){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar imagen
|
||||
if (!$request->hasFile('imagen') || !$request->file('imagen')->isValid()){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar etapa
|
||||
if($data['etapa'] != 'Inicio' && $data['etapa'] != 'Proceso' && $data['etapa'] != 'Final'){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
$imagen = $request->imagen;
|
||||
|
||||
$uuid = $imagen->hash('sha256');
|
||||
|
||||
//Validar que la imagen no haya sido capturada
|
||||
if(ServicioEvidencia::where('uuid', $uuid)->first()){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$data['uuid'] = $uuid;
|
||||
$data['servicio_progreso_id'] = $servicio_progreso->id;
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
$data['lat'] = $servicio_enc->lat;
|
||||
$data['lng'] = $servicio_enc->lng;
|
||||
//
|
||||
|
||||
$evidencia = ServicioEvidencia::create($data);
|
||||
|
||||
/*
|
||||
* IMAGEN
|
||||
*/
|
||||
|
||||
$nombre_img = 'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'_evidencia_'.$evidencia->id.'.'.$imagen->extension();
|
||||
$imagen->storeAs('public/servicios/evidencias', $nombre_img);
|
||||
|
||||
$evidencia->update(['imagen' => $nombre_img]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e);
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Guardar Evidencia.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function guardarFirmas(GuardarFirmaRequest $request)
|
||||
{
|
||||
|
||||
$data = $request->only(['servicio_enc_id', 'servicio_det_id']);
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('servicio_det_id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
/*
|
||||
* Validar imagen
|
||||
* Se comenta por el cambio de guardado
|
||||
*/
|
||||
if (!$request->hasFile('imagen') || !$request->file('imagen')->isValid()){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
$imagen = $request->imagen;
|
||||
|
||||
try {
|
||||
|
||||
/*
|
||||
* IMAGEN
|
||||
*/
|
||||
|
||||
$nombre_img = 'firma_'.'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'.'.$imagen->extension();
|
||||
$imagen->storeAs('public/servicios/firmas', $nombre_img);
|
||||
|
||||
$servicio_progreso->update(['firma' => $nombre_img]);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
Log::info($e);
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Guardar Evidencia.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
/*public function guardarEvidencia(GuardarEvidenciaRequest $request)
|
||||
{
|
||||
$data = $request->only(['etapa', 'lat', 'lng', 'servicio_enc_id', 'servicio_det_id']);
|
||||
$imagen = $request->input('imagen');
|
||||
$now = Carbon::now()->format('Y-m-d');
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('servicio_det_id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
$servicio_det = ServicioDet::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
list($fecha) = explode(" ", $servicio_det->fecha_solicitud);
|
||||
|
||||
//Validar fecha de solicitud
|
||||
if($now != $fecha){
|
||||
//return response()->unprocessable('Parametros inválidos',['No se pueden guardar evidencias ya que el servicio corresponde a otra fecha.']);
|
||||
}
|
||||
|
||||
//Validar que el servicio no este terminado
|
||||
if($servicio_det->estatus_servicio_id == REALIZADO){
|
||||
//return response()->unprocessable('Parametros inválidos',['El servicio ya está terminado']);
|
||||
|
||||
//Se agrega para que regrese la petición pero no se guarda información
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar que el servicio esté iniciado
|
||||
if(!$servicio_progreso){
|
||||
//return response()->unprocessable('Parametros inválidos',['El servicio no está iniciado.']);
|
||||
|
||||
//Se agrega para que regrese la petición pero no se guarda información
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar imagen
|
||||
//if (!$request->hasFile('imagen') || !$request->file('imagen')->isValid()){
|
||||
// return response()->unprocessable('Parametros inválidos',['Imagen invalida']);
|
||||
//}
|
||||
|
||||
//Validar etapa
|
||||
if($data['etapa'] != 'Inicio' && $data['etapa'] != 'Proceso' && $data['etapa'] != 'Final'){
|
||||
//return response()->unprocessable('Parametros inválidos',['El valor etapa no es valido']);
|
||||
|
||||
//Se agrega para que regrese la petición pero no se guarda información
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//$imagen = $request->imagen;
|
||||
|
||||
//$uuid = hash_file('sha256', $imagen);
|
||||
|
||||
//Validar que la imagen no haya sido capturada
|
||||
//if(ServicioEvidencia::where('uuid', $uuid)->first()){
|
||||
return response()->unprocessable('Parametros inválidos',['La imagen ya fue capturada']);
|
||||
//}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
$data['uuid'] = hash('sha256', $imagen);
|
||||
$data['servicio_progreso_id'] = $servicio_progreso->id;
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
$data['lat'] = $servicio_enc->lat;
|
||||
$data['lng'] = $servicio_enc->lng;
|
||||
//
|
||||
|
||||
$evidencia = ServicioEvidencia::create($data);
|
||||
|
||||
//$nombre_img = 'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'_evidencia_'.$evidencia->id.'.'.$imagen->extension();
|
||||
//$imagen->storeAs('public/servicios/evidencias', $nombre_img);
|
||||
|
||||
$nombre_img = 'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'_evidencia_'.$evidencia->id.'.jpeg';
|
||||
Storage::disk('public')->put('servicios/evidencias/' . $nombre_img, $this->base64ToImage($imagen), 'public');
|
||||
|
||||
$evidencia->update(['imagen' => $nombre_img]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e);
|
||||
return response()->unprocessable('Error', ['Error al guardar la evidencia.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function guardarFirmas(GuardarFirmaRequest $request)
|
||||
{
|
||||
|
||||
$data = $request->only(['servicio_enc_id', 'servicio_det_id']);
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
->where('servicio_det_id', $data['servicio_det_id'])
|
||||
->first();
|
||||
|
||||
// $now = Carbon::now()->format('Y-m-d');
|
||||
//
|
||||
// $servicio_det = ServicioDet::where('servicio_enc_id', $data['servicio_enc_id'])
|
||||
// ->where('id', $data['servicio_det_id'])
|
||||
// ->first();
|
||||
//
|
||||
// list($fecha) = explode(" ", $servicio_det->fecha_solicitud);
|
||||
//
|
||||
// //Validar fecha de solicitud
|
||||
// if($now != $fecha){
|
||||
// return response()->unprocessable('Parametros inválidos',['No se pueden guardar evidencias ya que el servicio corresponde a otra fecha.']);
|
||||
// }
|
||||
//
|
||||
// //Validar que el servicio no este terminado
|
||||
// if($servicio_det->estatus_servicio_id == REALIZADO){
|
||||
// return response()->unprocessable('Parametros inválidos',['El servicio ya está terminado']);
|
||||
// }
|
||||
//
|
||||
// //Validar que el servicio esté iniciado
|
||||
// if(!$servicio_progreso){
|
||||
// return response()->unprocessable('Parametros inválidos',['El servicio no está iniciado.']);
|
||||
// }
|
||||
|
||||
// if (!$request->hasFile('imagen') || !$request->file('imagen')->isValid()){
|
||||
// return response()->unprocessable('Parametros inválidos',['Imagen invalida']);
|
||||
// }
|
||||
|
||||
$imagen = $request->input('imagen');
|
||||
|
||||
try {
|
||||
|
||||
// $nombre_img = 'firma_'.'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'.'.$imagen->extension();
|
||||
// $imagen->storeAs('public/servicios/firmas', $nombre_img);
|
||||
|
||||
$nombre_img = 'firma_'.'solicitud_'.$data['servicio_enc_id'].'_servicio_'.$data['servicio_det_id'].'.jpeg';
|
||||
Storage::disk('public')->put('servicios/firmas/' . $nombre_img, $this->base64ToImage($imagen), 'public');
|
||||
|
||||
$servicio_progreso->update(['firma' => $nombre_img]);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
Log::info($e);
|
||||
return response()->unprocessable('Error', ['Error al guardar la firma.']);
|
||||
}
|
||||
}*/
|
||||
|
||||
public function verificarServicio(Request $request){
|
||||
|
||||
$servicios_id = $request->all();
|
||||
|
||||
$servicios = array();
|
||||
foreach ($servicios_id as $s){
|
||||
$servicio_det = ServicioDet::find($s);
|
||||
|
||||
if($servicio_det && $servicio_det->estatus_servicio_id == REALIZADO){
|
||||
array_push($servicios,['servicio_id' => $s]);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->success($servicios);
|
||||
}
|
||||
}
|
||||
294
app/Http/Controllers/Operador/ServiciosProgresoNewController.php
Normal file
294
app/Http/Controllers/Operador/ServiciosProgresoNewController.php
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Mail\SolicitudServicioTerminadoNew;
|
||||
use App\Models\Cliente;
|
||||
use App\Models\ClienteDomicilio;
|
||||
use App\Models\RespuestaDomestico;
|
||||
use App\Models\RespuestaEmpresarial;
|
||||
use App\Models\ServicioDet;
|
||||
use App\Models\ServicioEnc;
|
||||
use App\Models\ServicioEncuestaDomestico;
|
||||
use App\Models\ServicioEncuestaEmpresarial;
|
||||
use App\Models\ServicioEvidencia;
|
||||
use App\Models\ServicioProgreso;
|
||||
use App\Models\Sucursal;
|
||||
use Carbon\Carbon;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use const App\Http\Controllers\COSTO_SERVICIO_NEGATIVO;
|
||||
use const App\Http\Controllers\DEFAULT_PATH_ZIP_EVIDENCES;
|
||||
use const App\Http\Controllers\DOMESTICO;
|
||||
use const App\Http\Controllers\NEGATIVO;
|
||||
use const App\Http\Controllers\REALIZADO;
|
||||
use Log;
|
||||
|
||||
class ServiciosProgresoNewController extends Controller
|
||||
{
|
||||
/**
|
||||
* Finalizar Servicio.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function finalizarServicio(Request $request)
|
||||
{
|
||||
$user = Auth::user();
|
||||
$finalizar_servicio_data = $request->only(['fecha_fin_celular', 'duracion', 'lat_fin', 'lng_fin', 'comentarios', 'aplica_garantia','litraje']);
|
||||
$cat_motivos_estatus_id = $request->input('cat_motivos_estatus_id',0);
|
||||
$now = Carbon::now();
|
||||
|
||||
$servicio_enc_id = $request->input('servicio_enc_id');
|
||||
$servicio_det_id = $request->input('servicio_det_id');
|
||||
|
||||
$litraje = $request->input('litraje', null);
|
||||
|
||||
$servicio_progreso = ServicioProgreso::where('servicio_enc_id', $servicio_enc_id)
|
||||
->where('servicio_det_id', $servicio_det_id)
|
||||
->first();
|
||||
|
||||
$servicio_det = ServicioDet::where('servicio_enc_id', $servicio_enc_id)
|
||||
->where('id', $servicio_det_id)
|
||||
->first();
|
||||
$servicio = ServicioEnc::where('id', $servicio_enc_id)->first();
|
||||
|
||||
$correos = [];
|
||||
$correo_cliente = Cliente::select('email')->where('id', $servicio->cliente_id)->first();
|
||||
$correo_cliente_domicilio = ClienteDomicilio::select('email')->where('id', $servicio->cliente_domicilio_id)->first();
|
||||
|
||||
if($correo_cliente && $correo_cliente->email){
|
||||
$correos[] = $correo_cliente->email;
|
||||
}
|
||||
if($correo_cliente_domicilio && $correo_cliente_domicilio->email){
|
||||
$correos[] = $correo_cliente_domicilio->email;
|
||||
}
|
||||
|
||||
//Validar que el servicio no este terminado
|
||||
if($servicio_det->estatus_servicio_id == REALIZADO){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
//Validar que el servicio esté iniciado
|
||||
if(!$servicio_progreso){
|
||||
return response()->unprocessable('Parametros inválidos',['El servicio no está iniciado.']);
|
||||
}
|
||||
|
||||
if (!$recibo = $request->input('recibo')){
|
||||
return response()->unprocessable('Parametros inválidos',['No se ha podido generar el recibo.']);
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
|
||||
//ENCUESTA
|
||||
if($encuesta = $request->input('encuesta')){
|
||||
$this->encuesta($encuesta, $servicio_det_id);
|
||||
$finalizar_servicio_data['encuesta_contestada'] = 1;
|
||||
}
|
||||
//
|
||||
|
||||
$finalizar_servicio_data['fecha_fin_servidor'] = $now->toDateTimeString();
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_det->servicio_enc_id)
|
||||
->first();
|
||||
$finalizar_servicio_data['lat_fin'] = $servicio_enc->lat;
|
||||
$finalizar_servicio_data['lng_fin'] = $servicio_enc->lng;
|
||||
$finalizar_servicio_data['litraje'] = ($litraje == 0)? null: $litraje;
|
||||
|
||||
$costo_servicio_negativo = Sucursal::select('costo_negativo')->where('sucursales.id', $user->sucursal_id)->get();
|
||||
|
||||
$servicio_progreso->update($finalizar_servicio_data);
|
||||
if ($cat_motivos_estatus_id != 0){
|
||||
$servicio_det->update(
|
||||
[
|
||||
'estatus_servicio_id' => NEGATIVO,
|
||||
'cat_motivos_estatus_id' => $cat_motivos_estatus_id,
|
||||
'costo_servicio' => $costo_servicio_negativo,
|
||||
]
|
||||
);
|
||||
} else{
|
||||
$servicio_det->update(['estatus_servicio_id' => REALIZADO]);
|
||||
}
|
||||
|
||||
$recibo = base64_decode($recibo);
|
||||
$nombre = 'solicitud_' . $servicio_enc_id . '_servicio_' . $servicio_det_id . '.pdf';
|
||||
Storage::disk('public')->put('servicios/recibos_pdf/' . $nombre, $recibo);
|
||||
|
||||
DB::commit();
|
||||
|
||||
try {
|
||||
$ambiente = strtolower(config('ambiente')['ambiente']);
|
||||
if(count($correos) > 0 && $ambiente == 'dev'){
|
||||
try {
|
||||
Mail::to($correos)->send(new SolicitudServicioTerminadoNew($servicio_enc_id,$servicio_det_id, $nombre));
|
||||
} catch (\Exception $e) {
|
||||
\Log::info("Error al enviar correo: " . json_encode($e->getMessage()));
|
||||
}
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
return response()->success(['result' => 'ok']);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e);
|
||||
return response()->unprocessable('Error', ['Error al finalizar servicio.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function encuesta($data, $servicio_id)
|
||||
{
|
||||
$servicio_det = ServicioDet::where('id', $servicio_id)->firstOrFail();
|
||||
|
||||
if($servicio_det->tipo_servicio_id == DOMESTICO) {
|
||||
$validator = Validator::make($data, [
|
||||
'*.pregunta_id' => 'numeric|exists:preguntas_domestico,id',
|
||||
'*.respuesta_id' => 'numeric|exists:respuestas_domestico,id',
|
||||
'*.respuesta' => 'string|max:255'
|
||||
]);
|
||||
|
||||
if(ServicioEncuestaDomestico::where('servicio_det_id', $servicio_id)->first()){
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($data as $d){
|
||||
if(isset($d['respuesta_id'])){
|
||||
$respuesta = RespuestaDomestico::where('pregunta_id', $d['pregunta_id'])
|
||||
->where('id', $d['respuesta_id'])
|
||||
->first();
|
||||
|
||||
if(!$respuesta){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$validator = Validator::make($data, [
|
||||
'*.pregunta_id' => 'numeric|exists:preguntas_empresarial,id',
|
||||
'*.respuesta_id' => 'numeric|exists:respuestas_empresarial,id',
|
||||
'*.respuesta' => 'string|max:255'
|
||||
]);
|
||||
|
||||
if(ServicioEncuestaEmpresarial::where('servicio_det_id', $servicio_id)->first()){
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($data as $d){
|
||||
if(isset($d['respuesta_id'])){
|
||||
$respuesta = RespuestaEmpresarial::where('pregunta_id', $d['pregunta_id'])
|
||||
->where('id', $d['respuesta_id'])
|
||||
->first();
|
||||
|
||||
if(!$respuesta){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($validator->fails()){
|
||||
return false;
|
||||
}
|
||||
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
if($servicio_det->tipo_servicio_id == DOMESTICO) {
|
||||
foreach ($data as $d){
|
||||
|
||||
$data_domestico = [
|
||||
'servicio_det_id' => $servicio_id,
|
||||
'pregunta_id' => $d['pregunta_id'],
|
||||
'respuesta_id' => (isset($d['respuesta_id']))? $d['respuesta_id'] : null,
|
||||
'respuesta' => (isset($d['respuesta']))? $d['respuesta'] : null
|
||||
];
|
||||
ServicioEncuestaDomestico::create($data_domestico);
|
||||
}
|
||||
|
||||
}else{
|
||||
foreach ($data as $d){
|
||||
$data_empresarial = [
|
||||
'servicio_det_id' => $servicio_id,
|
||||
'pregunta_id' => $d['pregunta_id'],
|
||||
'respuesta_id' => (isset($d['respuesta_id']))? $d['respuesta_id'] : null,
|
||||
'respuesta' => (isset($d['respuesta']))? $d['respuesta'] : null
|
||||
];
|
||||
ServicioEncuestaEmpresarial::create($data_empresarial);
|
||||
}
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public function saveEvidence($evidencia, $servicio_enc_id, $servicio_det_id, $servicio_progreso_id){
|
||||
$image = storage_path(DEFAULT_PATH_ZIP_EVIDENCES.$evidencia['nombre']);
|
||||
|
||||
if(file_exists($image)){
|
||||
$data['uuid'] = hash_file('sha256', $image);
|
||||
|
||||
if(ServicioEvidencia::where('uuid', $data['uuid'])->first()){
|
||||
unlink($image);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Se agrego por detalle de Geolocalizacion
|
||||
$servicio_enc = ServicioEnc::select('clientes_domicilios.lat','clientes_domicilios.lng')
|
||||
->join('clientes_domicilios','servicios_enc.cliente_domicilio_id', '=','clientes_domicilios.id')
|
||||
->where('servicios_enc.id', $servicio_enc_id)
|
||||
->first();
|
||||
|
||||
$data['lat'] = $servicio_enc->lat;
|
||||
$data['lng'] = $servicio_enc->lng;
|
||||
$data['servicio_progreso_id'] = $servicio_progreso_id;
|
||||
$data['etapa'] = $evidencia['etapa'];
|
||||
|
||||
$evidence = ServicioEvidencia::create($data);
|
||||
$nombre_img = 'solicitud_'.$servicio_enc_id.'_servicio_'.$servicio_det_id.'_evidencia_'.$evidence->id.'.jpg';
|
||||
rename($image, storage_path("app/public/servicios/evidencias/$nombre_img"));
|
||||
$evidence->update(['imagen' => $nombre_img]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function saveEvidenceImage($pathFile, Collection $collect_evidencias, $servicio_enc_id, $servicio_det_id, $servicio_progreso_id){
|
||||
$zip = new \ZipArchive;
|
||||
$pathInfo = pathinfo(realpath($pathFile), PATHINFO_DIRNAME);
|
||||
if($zip->open($pathFile)){
|
||||
if($zip->extractTo($pathInfo)){
|
||||
for($i=0;$i<$zip->numFiles;++$i){
|
||||
$stat = $zip->statIndex($i);
|
||||
if($evidencia = $collect_evidencias->where('nombre', '=', basename($stat['name']))->first())
|
||||
$this->saveEvidence($evidencia, $servicio_enc_id, $servicio_det_id, $servicio_progreso_id);
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
unlink($pathFile);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function saveSignature($base64_firma, $servicio_enc_id, $servicio_det_id, $servicio_progreso){
|
||||
$nombre_img = 'firma_'.'solicitud_'.$servicio_enc_id.'_servicio_'.$servicio_det_id.'.jpg';
|
||||
Storage::disk('public')->put('servicios/firmas/' . $nombre_img, $this->base64ToImage($base64_firma), 'public');
|
||||
$servicio_progreso->update(['firma' => $nombre_img]);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Operador;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Operador\UltimaIncidenciaRequest;
|
||||
use App\Http\Requests\Operador\VehiculosIncidenciasRequest;
|
||||
use App\Models\BitacoraLaboral;
|
||||
use App\Models\VehiculoIncidencia;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class VehiculosIncidenciasController extends Controller
|
||||
{
|
||||
public function ultimaIncidencia(UltimaIncidenciaRequest $request)
|
||||
{
|
||||
$vehiculo_id = $request->input('vehiculo_id');
|
||||
|
||||
$incidencia = VehiculoIncidencia::where('vehiculo_id', $vehiculo_id)
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if ($incidencia && !$incidencia->resuelta) {
|
||||
return response()->success($incidencia);
|
||||
} else {
|
||||
return response()->success(null);
|
||||
}
|
||||
}
|
||||
|
||||
public function store(VehiculosIncidenciasRequest $request)
|
||||
{
|
||||
$data = $request->only('vehiculo_id', 'descripcion');
|
||||
$user_id = Auth::id();
|
||||
|
||||
$bitacora_laboral = BitacoraLaboral::where('usuario_id', $user_id)
|
||||
->latest()
|
||||
->first();;
|
||||
|
||||
VehiculoIncidencia::create([
|
||||
'vehiculo_id' => $bitacora_laboral->vehiculo_id,
|
||||
'user_id' => $user_id,
|
||||
'descripcion' => $data['descripcion'],
|
||||
]);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
|
||||
public function resolver($id)
|
||||
{
|
||||
$incidencia = VehiculoIncidencia::findOrfail($id);
|
||||
|
||||
$incidencia->update([
|
||||
'resuelta' => true
|
||||
]);
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user