- Nuevo modulo de historial de cambios (ServicioHistorial) - Observer para tracking automatico de cambios en servicios - Correccion de variables auxiliar en ServiciosController - Actualizacion de configuraciones y migraciones - Endpoint para consultar historial de cambios Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
470 lines
14 KiB
PHP
Executable File
470 lines
14 KiB
PHP
Executable File
<?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);
|
|
}
|
|
}
|