feat: add date formatting utility and enhance filtering in registro-pontos
- Introduced a new utility function `formatarDataDDMMAAAA` to format dates in DD/MM/AAAA format, supporting various input types. - Updated the `registro-pontos` page to utilize the new date formatting function for displaying dates consistently. - Implemented advanced filtering options for status and location, allowing users to filter records based on their criteria. - Enhanced CSV export functionality to include formatted dates and additional filtering capabilities, improving data management for users.
This commit is contained in:
26
apps/web/src/lib/components/ponto/LocalizacaoIcon.svelte
Normal file
26
apps/web/src/lib/components/ponto/LocalizacaoIcon.svelte
Normal file
@@ -0,0 +1,26 @@
|
||||
<script lang="ts">
|
||||
import { MapPin, AlertCircle, HelpCircle } from 'lucide-svelte';
|
||||
|
||||
interface Props {
|
||||
dentroRaioPermitido: boolean | null | undefined;
|
||||
showTooltip?: boolean;
|
||||
}
|
||||
|
||||
let { dentroRaioPermitido, showTooltip = true }: Props = $props();
|
||||
</script>
|
||||
|
||||
{#if dentroRaioPermitido === true}
|
||||
<div class="tooltip tooltip-top" data-tip={showTooltip ? 'Dentro do Raio' : ''}>
|
||||
<MapPin class="h-5 w-5 text-success" strokeWidth={2.5} />
|
||||
</div>
|
||||
{:else if dentroRaioPermitido === false}
|
||||
<div class="tooltip tooltip-top" data-tip={showTooltip ? 'Fora do Raio' : ''}>
|
||||
<AlertCircle class="h-5 w-5 text-error" strokeWidth={2.5} />
|
||||
</div>
|
||||
{:else}
|
||||
<div class="tooltip tooltip-top" data-tip={showTooltip ? 'Não Validado' : ''}>
|
||||
<HelpCircle class="h-5 w-5 text-base-content/40" strokeWidth={2.5} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
36
apps/web/src/lib/components/ponto/SaldoDiarioBadge.svelte
Normal file
36
apps/web/src/lib/components/ponto/SaldoDiarioBadge.svelte
Normal file
@@ -0,0 +1,36 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
saldo?: {
|
||||
saldoMinutos: number;
|
||||
horas: number;
|
||||
minutos: number;
|
||||
positivo: boolean;
|
||||
} | null;
|
||||
size?: 'sm' | 'md' | 'lg';
|
||||
}
|
||||
|
||||
let { saldo, size = 'md' }: Props = $props();
|
||||
|
||||
function formatarSaldo(saldo: NonNullable<Props['saldo']>): string {
|
||||
const sinal = saldo.positivo ? '+' : '-';
|
||||
return `${sinal}${saldo.horas}h ${saldo.minutos}min`;
|
||||
}
|
||||
|
||||
const sizeClasses = {
|
||||
sm: 'badge-sm',
|
||||
md: 'badge-lg',
|
||||
lg: 'badge-xl'
|
||||
};
|
||||
</script>
|
||||
|
||||
{#if saldo}
|
||||
<span
|
||||
class="badge font-semibold shadow-sm {sizeClasses[size]} {saldo.positivo
|
||||
? 'badge-success'
|
||||
: 'badge-error'}"
|
||||
>
|
||||
{formatarSaldo(saldo)}
|
||||
</span>
|
||||
{:else}
|
||||
<span class="badge badge-ghost {sizeClasses[size]}">-</span>
|
||||
{/if}
|
||||
@@ -122,3 +122,37 @@ export function getProximoTipoRegistro(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formata data no formato DD/MM/AAAA
|
||||
* Suporta strings ISO (YYYY-MM-DD), objetos Date, e timestamps
|
||||
*/
|
||||
export function formatarDataDDMMAAAA(data: string | Date | number): string {
|
||||
if (!data) return '';
|
||||
|
||||
let dataObj: Date;
|
||||
|
||||
if (typeof data === 'string') {
|
||||
// Se for string no formato ISO (YYYY-MM-DD), adicionar hora para evitar problemas de timezone
|
||||
if (data.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
||||
dataObj = new Date(data + 'T12:00:00');
|
||||
} else {
|
||||
dataObj = new Date(data);
|
||||
}
|
||||
} else if (typeof data === 'number') {
|
||||
dataObj = new Date(data);
|
||||
} else {
|
||||
dataObj = data;
|
||||
}
|
||||
|
||||
// Verificar se a data é válida
|
||||
if (isNaN(dataObj.getTime())) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const dia = dataObj.getDate().toString().padStart(2, '0');
|
||||
const mes = (dataObj.getMonth() + 1).toString().padStart(2, '0');
|
||||
const ano = dataObj.getFullYear();
|
||||
|
||||
return `${dia}/${mes}/${ano}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user