feat: implementar jornadas y validar aliases
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>Gastos</h2>
|
||||
<p v-if="!jornadaAbierta" style="color: orange">Sin jornada abierta - debe abrir jornada para registrar gastos</p>
|
||||
<p v-else style="color: green">Jornada abierta</p>
|
||||
<section>
|
||||
<input v-model="concepto" placeholder="Concepto (cinta, lapicero, bolsas...)" />
|
||||
<input v-model.number="monto" type="number" placeholder="Monto" />
|
||||
@@ -8,7 +10,7 @@
|
||||
<option value="EFECTIVO">Efectivo</option>
|
||||
<option value="QR">QR</option>
|
||||
</select>
|
||||
<button @click="registrar">Registrar Gasto</button>
|
||||
<button @click="registrar" :disabled="!jornadaAbierta">Registrar Gasto</button>
|
||||
</section>
|
||||
<section>
|
||||
<h3>Gastos del día</h3>
|
||||
@@ -21,32 +23,43 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { GastosService } from '@toldo/services';
|
||||
import { GastosService, JornadaService } from '@toldo/services';
|
||||
|
||||
const gastosService = new GastosService();
|
||||
const jornadaService = new JornadaService();
|
||||
const concepto = ref('');
|
||||
const monto = ref(0);
|
||||
const formaPago = ref<'EFECTIVO' | 'QR'>('EFECTIVO');
|
||||
const gastos = ref<any[]>([]);
|
||||
const jornadaAbierta = ref<any>(null);
|
||||
|
||||
async function cargar() {
|
||||
gastos.value = await gastosService.getGastosDelDia(new Date());
|
||||
jornadaAbierta.value = await jornadaService.getJornadaAbierta();
|
||||
}
|
||||
|
||||
async function registrar() {
|
||||
if (!concepto.value || monto.value <= 0) return;
|
||||
await gastosService.registrarGasto({
|
||||
id: crypto.randomUUID(),
|
||||
fecha: new Date(),
|
||||
concepto: concepto.value,
|
||||
monto: monto.value,
|
||||
formaPago: formaPago.value,
|
||||
createdAt: new Date()
|
||||
} as any);
|
||||
concepto.value = '';
|
||||
monto.value = 0;
|
||||
await cargar();
|
||||
alert('Gasto registrado');
|
||||
if (!jornadaAbierta.value) {
|
||||
alert('Debe abrir una jornada primero (Jornada > Apertura)');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await jornadaService.registrarGastoEnJornada(jornadaAbierta.value.id, {
|
||||
id: crypto.randomUUID(),
|
||||
fecha: new Date(),
|
||||
concepto: concepto.value,
|
||||
monto: monto.value,
|
||||
formaPago: formaPago.value,
|
||||
createdAt: new Date()
|
||||
} as any);
|
||||
concepto.value = '';
|
||||
monto.value = 0;
|
||||
await cargar();
|
||||
alert('Gasto registrado');
|
||||
} catch (e: any) {
|
||||
alert(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(cargar);
|
||||
|
||||
Reference in New Issue
Block a user