Carga inicial
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\SupervisorOperaciones;
|
||||
|
||||
use App\Models\BitacoraLaboral;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use DB;
|
||||
use Log;
|
||||
|
||||
class JornadaController extends Controller
|
||||
{
|
||||
public function inicioJornada(Request $request)
|
||||
{
|
||||
$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]);
|
||||
}
|
||||
|
||||
$bitacora_laboral = BitacoraLaboral::create(['fecha_hora_ini' => $fecha, 'usuario_id' => $user->id]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success($bitacora_laboral);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
Log::info($e->getMessage());
|
||||
return response()->unprocessable('Error', ['Error al guardar el inicio de jornada.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function finalizarJornada(Request $request, $id){
|
||||
|
||||
$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.']);
|
||||
}
|
||||
|
||||
$jornada->update(['fecha_hora_fin' => $fecha]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->success(['result' => 'ok']);
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
return response()->unprocessable('Error', ['Error al guardar el fin de jornada.']);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user