diff --git a/app/Http/Controllers/DeviceController.php b/app/Http/Controllers/DeviceController.php index 7bc1e02..0f0c160 100644 --- a/app/Http/Controllers/DeviceController.php +++ b/app/Http/Controllers/DeviceController.php @@ -543,4 +543,42 @@ public function Populate(Request $request, $id) return redirect()->route('devices.index')->with('error', 'Error al actualizar biométrico'); } } + + public function deleteEmployeeRecord(Request $request) + { + $oficinas = Oficina::all(); + $title = "Delete Employee Record from Device"; + return view('devices.delete_employee', compact('oficinas', 'title')); + } + + public function runDeleteFingerRecord(Request $request) + { + $idagente = $request->input('idagente'); + $idoficina = $request->input('oficina'); + + $devices = Device::where('idoficina', $idoficina)->get(); + + if ($devices->isEmpty()) { + return redirect()->back()->with('error', 'No devices found for this office'); + } + + try { + $cmdIdService = resolve(CommandIdService::class); + + foreach ($devices as $device) { + $nextCmdId = $cmdIdService->getNextCmdId(); + $device->commands()->create([ + 'device_id' => $device->id, + 'command' => $nextCmdId, + 'data' => "C:{$nextCmdId}:DATA DELETE USERINFO PIN={$idagente}", + 'executed_at' => null + ]); + } + + return redirect()->route('devices.index')->with('success', "Command to delete user {$idagente} sent to " . $devices->count() . " devices."); + } catch (\Exception $e) { + Log::error('Error deleting employee record', ['error' => $e->getMessage()]); + return redirect()->back()->with('error', 'Error sending delete command'); + } + } } diff --git a/app/Http/Controllers/iclockController.php b/app/Http/Controllers/iclockController.php index aaa8699..511d578 100644 --- a/app/Http/Controllers/iclockController.php +++ b/app/Http/Controllers/iclockController.php @@ -316,22 +316,33 @@ public function getrequest(Request $request) $nextCmdId = $cmdIdService->getNextCmdId(); Log::info('Get Request', ['nextCmdId' => $nextCmdId]); + $timezone = 'America/Mexico_City'; // Default fallback + if ($device && $device->oficina && $device->oficina->timezone) { + $timezone = $device->oficina->timezone; + } + $intDateTime = $this->oldEncodeTime( - Carbon::now('America/Mexico_City')->year, - Carbon::now('America/Mexico_City')->month, - Carbon::now('America/Mexico_City')->day, - Carbon::now('America/Mexico_City')->hour, - Carbon::now('America/Mexico_City')->minute, - Carbon::now('America/Mexico_City')->second + Carbon::now($timezone)->year, + Carbon::now($timezone)->month, + Carbon::now($timezone)->day, + Carbon::now($timezone)->hour, + Carbon::now($timezone)->minute, + Carbon::now($timezone)->second ); - /* - // Add a set time command to the database - $device->commands()->create([ - 'device_id' => $device->id, - 'command' => $nextCmdId, - 'data' => "C:{$nextCmdId}:SET OPTIONS DateTime=" . $intDateTime, - 'executed_at' => null - ]);*/ + + // Add a set time command to the database synchronously if clock is out of sync + // For now, mirroring the logic to always send it or send it as a regular command + // We will send it as a pending command if there's a discrepancy + if ($device->getTimezoneDiscrepancyCount() > 0) { + $device->commands()->create([ + 'device_id' => $device->id, + 'command' => $nextCmdId, + 'data' => "C:{$nextCmdId}:SET OPTIONS DateTime=" . $intDateTime, + 'executed_at' => null + ]); + // refresh pending commands + $commands = $device->pendingCommands(); + } Log::info('getrequest commands', ['commands' => count($commands)]); diff --git a/database/migrations/2026_02_13_000000_add_idoficina_idempresa_to_device_options.php b/database/migrations/2026_02_13_000000_add_idoficina_idempresa_to_device_options.php new file mode 100644 index 0000000..9e46c69 --- /dev/null +++ b/database/migrations/2026_02_13_000000_add_idoficina_idempresa_to_device_options.php @@ -0,0 +1,32 @@ +unsignedInteger('idoficina')->after('timestamp')->nullable(); + $table->unsignedInteger('idempresa')->after('idoficina')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('device_options', function (Blueprint $table) { + $table->dropColumn(['idoficina', 'idempresa']); + }); + } +}; diff --git a/resources/views/devices/delete_employee.blade.php b/resources/views/devices/delete_employee.blade.php new file mode 100644 index 0000000..1c511ca --- /dev/null +++ b/resources/views/devices/delete_employee.blade.php @@ -0,0 +1,32 @@ +@extends('layouts.app') + +@section('content') +
+

{{ $title }}

+
+ @csrf +
+ + + The delete command will be sent to all devices in this office. +
+ +
+ + +
+ +
+ Warning! This will queue a command to remove the user from the biometric devices. This action cannot be undone from the server easily. +
+ + + Cancel +
+
+@endsection diff --git a/resources/views/devices/index.blade.php b/resources/views/devices/index.blade.php index 2fc88e8..b9d4c1f 100644 --- a/resources/views/devices/index.blade.php +++ b/resources/views/devices/index.blade.php @@ -5,6 +5,9 @@

{{ $title }}

{{ __('devices.create_device') }} + + Delete User from Device + {{ __('devices.monitor_status') }}