Skip to content

Commit

Permalink
Merge pull request #45 from alecostaweb/issue_35
Browse files Browse the repository at this point in the history
Exibindo o saldo de horas
  • Loading branch information
alecostaweb authored Feb 5, 2024
2 parents ea50873 + 4148484 commit 04ab889
Show file tree
Hide file tree
Showing 17 changed files with 281 additions and 66 deletions.
14 changes: 13 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,16 @@ WSFOTO_PASS=
PATH_PICTURES=''

# Mostra foto do monitor que está na sala
FOTO_MONITOR=0
FOTO_MONITOR=0

# Token Invertexto para api de feriados
# https://api.invertexto.com
# Api grátis até 3 mil requisições por mês
# Acesse, crie uma conta e em seguida um token
# Token
TOKEN_INVERTEXTO='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
# Configure abaixo a uf do estado
UF_FERIADOS=SP

# Permitir ao usuário gerar a folha de frequência, padrão no
GERAR_FOLHA=no
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Registro de ponto de monitores das salas Pró-Aluno.

* Registro de ponto com foto.
* Supervisor e autorizador podem acompanhar o ponto das pessoas nos seus grupos. Para isso, após o supervisor ou autorizador logar no sistema, através da rota /senhaunica-users pode-se adicionar essa pessoa à permissão hireárquica **boss**.
* Cálculo de dias úteis.
* Carga horária semanal.
* Feriados através da API Invertexto disponível em https://api.invertexto.com

## Em produção

Expand All @@ -24,6 +27,8 @@ Para receber as últimas atualizações do sistema rode:
composer install
cp .env.example .env
php artisan key:generate
mkdir storage/app/feriados
chmod -R 777 storage/app/feriados

### Senha única

Expand Down Expand Up @@ -66,4 +71,5 @@ Estagiários da STI FFLCH:
- 14/06/2022 - Protegendo os arquivos de imagem
- 14/06/2022 - Exibindo informações e foto do registro
- 31/05/2022 - Código da sala de monitoria parametrizado
- 27/11/2023 - Supervisor e autorizador podem ver o ponto das pessosas nos seus grupos
- 27/11/2023 - Supervisor e autorizador podem ver o ponto das pessosas nos seus grupos
- 07/12/2023 - Carga horária semanal, feriados, dias úteis e saldo de horas
10 changes: 8 additions & 2 deletions app/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@
use Illuminate\Http\Request;

use App\Models\Place;
use Auth;
use App\Models\Grupo;

class IndexController extends Controller
{
public function index()
{
if (Auth::check()) {
$places = Place::all();
} else {
$places = Place::where('name', 'like', '%pro-aluno%')->orWhere('name', 'like', '%proaluno%')->get();
}
return view('index',[
// Retorna somente os lugares com para monitores das salas Pró-Aluno ou Próaluno
'places' => Place::where('name', 'like', '%pro-aluno%')->orWhere('name', 'like', '%proaluno%')->get(),
'places' => $places,
]);
}
}
17 changes: 13 additions & 4 deletions app/Http/Controllers/PdfController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
class PdfController extends Controller
{
public function folha(Request $request, $codpes){
$this->authorize('owner',$codpes);
if (config('ponto.gerarFolha') == 'yes') {
$permission = 'owner';
} else {
$permission = 'boss';
}

$this->authorize($permission, $codpes);

$request->validate([
'in' => 'required|date_format:d/m/Y',
Expand All @@ -25,6 +31,8 @@ public function folha(Request $request, $codpes){
$in = Carbon::createFromFormat('d/m/Y',$request->in);
$out = Carbon::createFromFormat('d/m/Y',$request->out);

$datas = Util::listarDiasUteis($in->format('d/m/Y'), $out->format('d/m/Y'));

$computes = Util::compute($codpes, $in, $out);

if(count($computes) > 31) {
Expand All @@ -51,9 +59,10 @@ public function folha(Request $request, $codpes){
'out' => $request->out,
'total' => Util::computeTotal($computes),
'codpes' => $codpes,
'codpes_supervisor' => $codpes_supervisor,
'nome' => $nome,
'nome_supervisor' => $nome_supervisor,
'codpes_supervisor' => $codpes_supervisor,
'nome' => $nome,
'nome_supervisor' => $nome_supervisor,
'datas' => $datas,
]);

return $pdf->download("$codpes.pdf");
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/PessoaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public function show(Request $request, $codpes = 'my')
$in = Carbon::createFromFormat('d/m/Y H:i:s', $request->in . ' 00:00:00');
$out = Carbon::createFromFormat('d/m/Y H:i:s', $request->out . ' 23:59:59');

$datas = Util::listarDiasUteis($in->format('d/m/Y'), $out->format('d/m/Y'));

$computes = Util::compute($pessoa['codpes'], $in, $out);

if(count($computes) > 31) {
Expand All @@ -105,7 +107,8 @@ public function show(Request $request, $codpes = 'my')
'telefones' => $telefones,
'registros' => $registros,
'computes' => $computes,
'total' => Util::computeTotal($computes)
'total' => Util::computeTotal($computes),
'datas' => $datas,
]);
}
}
1 change: 1 addition & 0 deletions app/Http/Requests/GrupoRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function rules()
'codpes_autorizador' => 'required|integer',
'inicio_folha' => 'required|integer',
'fim_folha' => 'required|integer',
'carga_horaria' => 'required|integer',
];

return $rules;
Expand Down
80 changes: 80 additions & 0 deletions app/Utils/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,84 @@ public function computeDayMinutes($computes, $day) {

return [$day,$registros, self::formatMinutes($minutos_do_dia)];
}

/**
* Método que retorna o feriado
* recebe $dia em formato string Y-m-d
* retorna array do feriado
* https://api.invertexto.com
*
* @param string $dia
* @return array $feriado
*/
public function obterFeriado($dia) {
$dia = Carbon::createFromFormat('Y-m-d', $dia);
$ano = $dia->format('Y');
$url = 'https://api.invertexto.com/v1/holidays/' . $ano . '?token=' . config('ponto.tokenInvertexto') . '&state=' . config('ponto.ufFeriados');
$arquivoFeriados = '../storage/app/feriados/' . $ano . '.json';
if (!file_exists($arquivoFeriados)) {
file_put_contents('../storage/app/feriados/' . $ano . '.json', file_get_contents($url));
}
$feriados = json_decode(file_get_contents($arquivoFeriados), true);
$feriado = [];
foreach ($feriados as $key => $val) {
if ($val['date'] === $dia->format('Y-m-d')) {
$feriado = $feriados[$key];
}
}
return $feriado;
}

/**
* Método que retorna a quantidade de dias úteis
* recebe $in e $out em formato string d/m/Y
* retorna int $dias
*
* @param string $in
* @param string $out
* @return int $dias
*/
public function contarDiasUteis($in, $out) {
$in = Carbon::createFromFormat('d/m/Y', $in);
$out = Carbon::createFromFormat('d/m/Y', $out);
$periodo = CarbonPeriod::between($in, $out);
$dias = 0;
foreach ($periodo as $data) {
if (!$data->isSaturday() && !$data->isSunday() && empty(self::obterFeriado($data->format('Y-m-d')))) $dias++;
}
return $dias;
}

/**
* Método que retorna a lista de dias úteis
* recebe $in e $out em formato string d/m/Y
* retorna array $datas
*
* @param string $in
* @param string $out
* @return array $datas
*/
public function listarDiasUteis($in, $out) {
$in = Carbon::createFromFormat('d/m/Y', $in);
$out = Carbon::createFromFormat('d/m/Y', $out);
$periodo = CarbonPeriod::between($in->format('Y-m-d'), $out->format('Y-m-d'));
$datas = [];
foreach ($periodo as $data) {
$feriado = Util::obterFeriado($data->format('Y-m-d'));
$style = 'style="background-color: #ccc;"';
if ($data->isSaturday() || $data->isSunday()) {
$texto = ucfirst($data->locale('pt_Br')->dayName);
} elseif (!empty($feriado)) {
$texto = $feriado['name'];
} else {
$style = '';
$texto = '';
}
$datas[$data->format('d')] = [
'style' => $style,
'texto' => $texto,
];
}
return $datas;
}
}
3 changes: 3 additions & 0 deletions config/ponto.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
return [
'pathPictures' => env('PATH_PICTURES', ''),
'fotoMonitor' => env('FOTO_MONITOR', 0),
'tokenInvertexto' => env('TOKEN_INVERTEXTO', ''),
'ufFeriados' => env('UF_FERIADOS', 'SP'),
'gerarFolha' => env('GERAR_FOLHA', 'yes'),
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class UpdateCargaHorariaInGruposTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('grupos', function (Blueprint $table) {
$table->integer('carga_horaria');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('grupos', function (Blueprint $table) {
$table->dropColumn('carga_horaria')->default('20');
});
}
}
2 changes: 2 additions & 0 deletions resources/views/grupos/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<th scope="col">Nome</th>
<th scope="col">Supervisor</th>
<th scope="col">Autorizador</th>
<th scope="col">Carga horária semanal</th>
<th scope="col">Operações</th>
</tr>
</thead>
Expand All @@ -28,6 +29,7 @@
<td>{{ $grupo->name }}</td>
<td>{{ $grupo->codpes_supervisor }}</td>
<td>{{ $grupo->codpes_autorizador }}</td>
<td>{{ $grupo->carga_horaria }}</td>
<td align="center">
<a href="/grupos/{{$grupo->id}}/edit"><i class="fas fa-pencil-alt" color="#007bff"></i></a>
@can ('admin')
Expand Down
6 changes: 5 additions & 1 deletion resources/views/grupos/partials/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
<br> <br>
<label for="inicio_folha">Dia que fecha da folha de pagamento:</label>
<input type="number" id="fim_folha" name="fim_folha" value="{{ old('fim_folha', $grupo->fim_folha) }}">


<br> <br>
<label for="carga_horaria">Carga horária semanal:</label>
<input type="number" id="carga_horaria" name="carga_horaria" value="{{ old('carga_horaria', $grupo->carga_horaria) }}">

<br> <br>
<button type="submit" class="btn btn-primary">Enviar</button>

Expand Down
22 changes: 14 additions & 8 deletions resources/views/pdfs/folha.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
border-left: none;
border-right: none;
}
td.registros {
font-size: 0.75em;
font-style: italic;
font-weight: bold;
}
</style>
</head>

Expand Down Expand Up @@ -68,25 +74,25 @@

@for($i = 0; $i < 16; $i++)
@if(array_key_exists($i, $dias))
@php $col1 = App\Utils\Util::computeDayMinutes($computes,$dias[$i]); @endphp
@php $col1 = App\Utils\Util::computeDayMinutes($computes,$dias[$i]) @endphp
@else
@php $col1 = ['','',''] @endphp
@endif

@if(array_key_exists($i+16, $dias))
@php $col2 = App\Utils\Util::computeDayMinutes($computes,$dias[$i+16]); @endphp
@php $col2 = App\Utils\Util::computeDayMinutes($computes,$dias[$i+16]) @endphp
@else
@php $col2 = ['','',''] @endphp
@endif

<tr>
<td><b>{{ $col1[0] }}</b></td>
<td>{{{ $col1[1] }}}</td>
<td>{{ $col1[2] }}</td>
<td class="registros">{{ $col1[0] }}</td>
<td class="registros">{{ $col1[1] }} {{ $datas[substr($col1[0], 0, 2)]['texto'] ?? '' }}</td>
<td class="registros" @if (!empty($datas[substr($col1[0], 0, 2)]['texto'])) style="background-color: #ccc;" @endif>{{ $col1[2] }}</td>

<td><b>{{ $col2[0] }}</b></td>
<td>{{{ $col2[1] }}}</td>
<td>{{ $col2[2] }}</td>
<td class="registros">{{ $col2[0] }}</td>
<td class="registros">{{ $col2[1] }} {{ $datas[substr($col2[0], 0, 2)]['texto'] ?? '' }}</td>
<td class="registros" @if (!empty($datas[substr($col2[0], 0, 2)]['texto'])) style="background-color: #ccc;" @endif>{{ $col2[2] }} </td>
</tr>
@endfor
</table>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/pessoas/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<div class="card">
<div class="card-header font-weight-bold">
{{ $grupo->name }}
{{ $grupo->name }}: {{ $grupo->carga_horaria }} horas semanais
</div>
<div class="card-body">
<table class="table table-sm table-striped table-hover datatable-pessoas">
Expand Down
36 changes: 13 additions & 23 deletions resources/views/pessoas/partials/form.blade.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
@foreach ($registros as $registro)
<br>
@if($registro->type == 'in')
<i class="fas fa-sign-in-alt text-success"></i>
<a href="/registros/{{ $registro->id }}">
({{ $registro->status }}) {{ $registro->created_at->format('d/m/Y - H:i') }} (Entrada)</a>
@else
<i class="fas fa-sign-out-alt text-danger"></i>
<a href="/registros/{{ $registro->id }}">
({{ $registro->status }}) {{ $registro->created_at->format('d/m/Y - H:i') }} (Saída)</a>
@endif

@can('admin')
@if($registro->status == 'válido')
<form style="display: inline;" method="POST" action="registros/{{ $registro->id }}/invalidate">
@csrf
@method('PATCH')
<button type="submit" class="btn btn-danger btn-sm mb-1" title="Invalidar registro"><i class="fa fa-thumbs-down"></i> Invalidar</button>
</form>
@else
{{ $registro->analise }}
@endif
@endcan

<tr>
<td>
@if($registro->type == 'in')
<i class="fas fa-sign-in-alt text-success"></i>
@can('boss') <a href="/registros/{{ $registro->id }}"> @endcan
({{ $registro->status }}) {{ $registro->created_at->format('d/m/Y - H:i') }} (Entrada) @can('boss') </a> @endcan
@else
<i class="fas fa-sign-out-alt text-danger"></i>
@can('boss') <a href="/registros/{{ $registro->id }}"> @endcan
({{ $registro->status }}) {{ $registro->created_at->format('d/m/Y - H:i') }} (Saída) @can('boss') </a> @endcan
@endif
</td>
</tr>
@endforeach
Loading

0 comments on commit 04ab889

Please sign in to comment.