Private
Public Access
1 parent
bc0db6dbee
commit
fcf16df5d3
21 files changed
+728
-3
No files matched your search
@@ -14,3 +14,4 @@ comms/.idea/
|
||||
skills/
|
||||
/scripts/.idea
|
||||
/scripts/.bsp
|
||||
front/.svelte-kit.old/
|
||||
@@ -32,6 +32,7 @@ var permisosSemilla = []permisoSemilla{
|
||||
{14, "Generar Reporte de Stock", "stock/reportes", "Generar y consultar reportes de stock."},
|
||||
{15, "Gestión de Ventas y Facturación", "facturas", "Consultar y operar la facturación y ventas de la empresa."},
|
||||
{16, "Gestión de Descuentos", "descuentos", "Crear, editar y eliminar descuentos."},
|
||||
{17, "Gestión de Formas de Pago", "formas-pago", "Crear, editar y eliminar formas de pago."},
|
||||
}
|
||||
|
||||
// InitPermisos crea el catálogo global de permisos y garantiza que cada
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package formapago
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"repuestera_back/models"
|
||||
r "repuestera_back/repositorios"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// ActualizarFormaDePago actualiza una forma de pago existente.
|
||||
func ActualizarFormaDePago(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID invalido"})
|
||||
return
|
||||
}
|
||||
if id < 1 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID no puede ser menor que 1"})
|
||||
return
|
||||
}
|
||||
|
||||
// Obtener la forma de pago actual
|
||||
fp, err := r.ObtenerRepositorios(c).FormaDePago.ObtenerPorID(uint(id))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Forma de pago no encontrada"})
|
||||
return
|
||||
}
|
||||
|
||||
var input models.FormaDePago
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if input.Descripcion == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "La descripción no puede estar vacía"})
|
||||
return
|
||||
}
|
||||
|
||||
// Verificar que no exista otra forma de pago con la misma descripción
|
||||
if existing, _ := r.ObtenerRepositorios(c).FormaDePago.ObtenerPorDescripcion(input.Descripcion); existing != nil && existing.ID != fp.ID {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "ya existe una forma de pago con esa descripción"})
|
||||
return
|
||||
}
|
||||
|
||||
uid := c.GetUint("userID")
|
||||
if err := r.ObtenerRepositorios(c).FormaDePago.Actualizar(fp, input, uid); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, fp)
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package formapago
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
r "repuestera_back/repositorios"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func AltaFormaDePago(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID invalido"})
|
||||
return
|
||||
}
|
||||
if id < 1 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID no puede ser menor que 1"})
|
||||
return
|
||||
}
|
||||
|
||||
uid := c.GetUint("userID")
|
||||
fp, err := r.ObtenerRepositorios(c).FormaDePago.ObtenerPorID(uint(id))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Forma de pago no encontrada"})
|
||||
return
|
||||
}
|
||||
|
||||
if !fp.DeletedAt.Valid {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "Forma de pago no está eliminada"})
|
||||
return
|
||||
}
|
||||
|
||||
fp.DeletedAt = gorm.DeletedAt{}
|
||||
if err := r.ObtenerRepositorios(c).FormaDePago.Alta(fp, *fp, uid); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package formapago
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"repuestera_back/models"
|
||||
r "repuestera_back/repositorios"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func CrearFormaDePago(c *gin.Context) {
|
||||
var fp models.FormaDePago
|
||||
if err := c.ShouldBindJSON(&fp); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if fp.Descripcion == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "La descripción es obligatoria"})
|
||||
return
|
||||
}
|
||||
|
||||
repo := r.ObtenerRepositorios(c).FormaDePago
|
||||
if _, err := repo.ObtenerPorDescripcion(fp.Descripcion); err == nil {
|
||||
c.JSON(http.StatusConflict, gin.H{"error": "ya existe una forma de pago con esa descripción"})
|
||||
return
|
||||
} else if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
if err := repo.Crear(fp, c.GetUint("userID")); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.Status(http.StatusCreated)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package formapago
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
r "repuestera_back/repositorios"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func EliminarFormaDePago(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID invalido"})
|
||||
return
|
||||
}
|
||||
if id < 1 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID no puede ser menor que 1"})
|
||||
return
|
||||
}
|
||||
|
||||
uid := c.GetUint("userID")
|
||||
err = r.ObtenerRepositorios(c).FormaDePago.Baja(uint(id), uid)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package formapago
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func ObtenerFormaDePago(c *gin.Context) {
|
||||
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID invalido"})
|
||||
return
|
||||
}
|
||||
if id < 1 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "ID no puede ser menor que 1"})
|
||||
return
|
||||
}
|
||||
|
||||
fp, err := r.ObtenerRepositorios(c).FormaDePago.ObtenerPorID(uint(id))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusNotFound, gin.H{"error": "Forma de pago no encontrada"})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, fp)
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
type RepositorioFormaDePago interface {
|
||||
IRepositorio[models.FormaDePago]
|
||||
ObtenerPorDescripcion(descripcion string) (*models.FormaDePago, error)
|
||||
}
|
||||
|
||||
type repositorioFormaDePago struct {
|
||||
@@ -23,3 +24,13 @@ func NuevoRepositorioFormaDePago(db *gorm.DB, empresaID uint) RepositorioFormaDe
|
||||
empresaID: empresaID,
|
||||
}
|
||||
}
|
||||
|
||||
// ObtenerPorDescripcion busca una forma de pago por descripción dentro de la
|
||||
// empresa, incluyendo las dadas de baja para validar duplicados al reactivar.
|
||||
func (r *repositorioFormaDePago) ObtenerPorDescripcion(descripcion string) (*models.FormaDePago, error) {
|
||||
var fp models.FormaDePago
|
||||
if err := r.db.Unscoped().Where("descripcion = ?", descripcion).First(&fp).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fp, nil
|
||||
}
|
||||
@@ -8,9 +8,21 @@ import (
|
||||
)
|
||||
|
||||
func FormaDePagoRoute(r *gin.Engine) {
|
||||
grupo := r.Group("/formas-pago")
|
||||
grupo.Use(middleware.AuthMiddleware(15))
|
||||
// Lectura: facturación (15) necesita las formas de pago activas, y gestión
|
||||
// de formas de pago (17) necesita el listado completo.
|
||||
lectura := r.Group("/formas-pago")
|
||||
lectura.Use(middleware.AuthMiddleware(15, 17))
|
||||
{
|
||||
grupo.GET("/", formapago.ObtenerFormasPago)
|
||||
lectura.GET("/", formapago.ObtenerFormasPago)
|
||||
lectura.GET("/:id", formapago.ObtenerFormaDePago)
|
||||
}
|
||||
|
||||
gestion := r.Group("/formas-pago")
|
||||
gestion.Use(middleware.AuthMiddleware(17))
|
||||
{
|
||||
gestion.POST("/", formapago.CrearFormaDePago)
|
||||
gestion.PUT("/:id", formapago.ActualizarFormaDePago)
|
||||
gestion.DELETE("/:id", formapago.EliminarFormaDePago)
|
||||
gestion.PATCH("/:id/alta", formapago.AltaFormaDePago)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { API_URL } from '$lib/env';
|
||||
import { getToken } from '../token';
|
||||
|
||||
export async function actualizarFormaDePago(id: number, descripcion: string) {
|
||||
descripcion = descripcion.trim();
|
||||
if (descripcion === '') return 'No se acepta una descripción vacía o con espacios';
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/formas-pago/${id}`, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
Authorization: `Bearer ${getToken()}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ descripcion })
|
||||
});
|
||||
if (!req.ok) {
|
||||
const data: { error: string } = await req.json();
|
||||
return data.error || 'No se pudo actualizar la forma de pago';
|
||||
}
|
||||
return 'ok';
|
||||
} catch {
|
||||
return 'No se pudo alcanzar el servidor';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { API_URL } from '$lib/env';
|
||||
import { getToken } from '../token';
|
||||
|
||||
export async function AltaFormaDePago(id: number) {
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/formas-pago/${id}/alta`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
}
|
||||
});
|
||||
if (req.ok) {
|
||||
return 'ok';
|
||||
}
|
||||
const data = await req.json();
|
||||
return data.error;
|
||||
} catch {
|
||||
return 'no se pudo alcanzar el servidor';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { API_URL } from '$lib/env';
|
||||
import { getToken } from '../token';
|
||||
|
||||
export async function crearFormaDePago(descripcion: string) {
|
||||
descripcion = descripcion.trim();
|
||||
if (descripcion === '') return 'No se acepta una descripción vacía o con espacios';
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/formas-pago/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: `Bearer ${getToken()}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({ descripcion })
|
||||
});
|
||||
if (!req.ok) {
|
||||
const data: { error: string } = await req.json();
|
||||
return data.error || 'No se pudo crear la forma de pago';
|
||||
}
|
||||
return 'ok';
|
||||
} catch {
|
||||
return 'No se pudo alcanzar el servidor';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { API_URL } from '$lib/env';
|
||||
import { getToken } from '../token';
|
||||
|
||||
export async function eliminarFormaDePago(id: number) {
|
||||
try {
|
||||
const req = await fetch(`${API_URL}/formas-pago/${id}`, {
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
}
|
||||
});
|
||||
if (req.ok) {
|
||||
return 'Ok';
|
||||
}
|
||||
const data = await req.json();
|
||||
return data.error;
|
||||
} catch {
|
||||
return 'no se pudo alcanzar el servidor';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { API_URL } from '$lib/env';
|
||||
import type { FormaDePago } from '../../../types';
|
||||
import { getToken } from '../token';
|
||||
|
||||
export async function obtenerFormasPago(fetch2?: Function) {
|
||||
const fetchFn = fetch2 ? fetch2 : fetch;
|
||||
const req = await fetchFn(`${API_URL}/formas-pago/`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
Authorization: `Bearer ${getToken()}`
|
||||
}
|
||||
});
|
||||
if (!req.ok) return 'Hubo un error y no se pudieron obtener las formas de pago';
|
||||
return (await req.json()) as FormaDePago[];
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<script lang="ts">
|
||||
import Header from '$lib/components/Header.svelte';
|
||||
import { Button, DataTableSkeleton, InlineNotification, Table, TableBody, TableCell, TableContainer, TableHead, TableHeader, TableRow } from 'carbon-components-svelte';
|
||||
import { Add, ArrowUp, Edit, TrashCan } from 'carbon-icons-svelte';
|
||||
import type { FormaDePago } from '../../types';
|
||||
import CrearFormaDePagoForm from './CrearFormaDePagoForm.svelte';
|
||||
import EditarFormaDePagoForm from './EditarFormaDePagoForm.svelte';
|
||||
import EliminarFormaDePagoForm from './EliminarFormaDePagoForm.svelte';
|
||||
import AltaFormaDePagoForm from './AltaFormaDePagoForm.svelte';
|
||||
|
||||
let error = $state("");
|
||||
|
||||
let { data }: {data: {formasPago: string | Array<FormaDePago>}} = $props();
|
||||
|
||||
let formasPago = $derived(Array.isArray(data.formasPago) ? data.formasPago : []);
|
||||
|
||||
$effect(()=>{
|
||||
if (typeof data.formasPago === "string"){
|
||||
error = data.formasPago
|
||||
}
|
||||
});
|
||||
|
||||
const headers: { key: keyof FormaDePago; value: string }[] = [
|
||||
{ key: 'ID', value: 'ID' },
|
||||
{ key: 'descripcion', value: 'Descripción' },
|
||||
{ key: 'CreatedAt', value: 'Creado' },
|
||||
{ key: 'UpdatedAt', value: 'Actualizado' },
|
||||
{ key: 'DeletedAt', value: 'Estado' }
|
||||
];
|
||||
|
||||
let openCrear = $state(false);
|
||||
let openEdit = $state(false);
|
||||
let openDelete = $state(false);
|
||||
let formaSeleccionada: FormaDePago | null = $state(null);
|
||||
let formaAEliminar: FormaDePago | null = $state(null);
|
||||
let openAlta = $state(false);
|
||||
let formaAAlta: FormaDePago | null = $state(null);
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<Header />
|
||||
<div class="page-container">
|
||||
<div class="flex justify-between">
|
||||
<h1 class="page-title">Gestión de Formas de Pago</h1>
|
||||
<Button onclick={() => {openCrear = true}} icon={Add}>Nueva Forma de Pago</Button>
|
||||
</div>
|
||||
{#if error}
|
||||
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
||||
{/if}
|
||||
{#if typeof data.formasPago === "undefined" || data.formasPago === null}
|
||||
<DataTableSkeleton />
|
||||
{:else if formasPago.length === 0}
|
||||
<TableContainer title="Formas de Pago">
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
{#each headers as header}
|
||||
<TableHeader>{header.value}</TableHeader>
|
||||
{/each}
|
||||
<TableHeader>Acciones</TableHeader>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
<TableRow>
|
||||
<TableCell colspan={headers.length+1}>No hay formas de pago para mostrar, registre una</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
{:else}
|
||||
<TableContainer title="Listado de Formas de Pago">
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
{#each headers as header}
|
||||
<TableHeader>{header.value}</TableHeader>
|
||||
{/each}
|
||||
<TableHeader>Acciones</TableHeader>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{#each formasPago as p}
|
||||
<TableRow>
|
||||
{#each headers as header}
|
||||
<TableCell>{header.key === 'DeletedAt' ? (p.DeletedAt ? '✖' : '✔') : String(p[header.key] ?? '-')}</TableCell>
|
||||
{/each}
|
||||
<TableCell>
|
||||
<Button kind="ghost" size="small" icon={Edit} onclick={() => { formaSeleccionada = p; openEdit = true; }}>Editar</Button>
|
||||
{#if p.DeletedAt}
|
||||
<Button kind="ghost" size="small" icon={ArrowUp} onclick={() => { formaAAlta = p; openAlta = true; }}>Alta</Button>
|
||||
{:else}
|
||||
<Button kind="ghost" size="small" icon={TrashCan} onclick={() => { formaAEliminar = p; openDelete = true; }}>Eliminar</Button>
|
||||
{/if}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
||||
<CrearFormaDePagoForm bind:open={openCrear} onClose={() => openCrear = false} />
|
||||
|
||||
<EliminarFormaDePagoForm bind:open={openDelete} forma={formaAEliminar} onClose={() => { openDelete = false; formaAEliminar = null; }} />
|
||||
|
||||
<AltaFormaDePagoForm bind:open={openAlta} forma={formaAAlta} onClose={()=> openAlta = false} />
|
||||
|
||||
<EditarFormaDePagoForm bind:open={openEdit} forma={formaSeleccionada} onClose={() => { openEdit = false; formaSeleccionada = null; }} />
|
||||
@@ -0,0 +1,10 @@
|
||||
import { obtenerFormasPago } from '$lib/hooks/formas-pago/obtenerFormasPago';
|
||||
|
||||
export const ssr = false;
|
||||
|
||||
export async function load({ depends, fetch }) {
|
||||
depends('formasPago:load');
|
||||
const formasPago = await obtenerFormasPago(fetch);
|
||||
|
||||
return { formasPago: formasPago };
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<script lang="ts">
|
||||
import { Modal, InlineNotification } from 'carbon-components-svelte';
|
||||
import type { FormaDePago } from '../../types';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { AltaFormaDePago } from '$lib/hooks/formas-pago/altaFormaDePago';
|
||||
|
||||
interface Props {
|
||||
open?: boolean;
|
||||
forma?: FormaDePago | null;
|
||||
onClose: Function
|
||||
}
|
||||
let { open = $bindable(), forma = null, onClose}:Props = $props();
|
||||
|
||||
let error = $state('');
|
||||
let loading = $state(false);
|
||||
let success = $state(false);
|
||||
|
||||
function reset() {
|
||||
error = '';
|
||||
loading = false;
|
||||
success = false;
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
reset();
|
||||
onClose();
|
||||
}
|
||||
|
||||
async function altaFormaDePago() {
|
||||
if (!forma) return;
|
||||
loading = true;
|
||||
error = '';
|
||||
success = false;
|
||||
try {
|
||||
const result = await AltaFormaDePago(forma.ID);
|
||||
if (result === 'ok') {
|
||||
success = true;
|
||||
invalidate('formasPago:load');
|
||||
// Close after success
|
||||
handleClose();
|
||||
} else {
|
||||
throw new Error(result);
|
||||
}
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : String(e);
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<form
|
||||
id="altaFormaDePagoForm"
|
||||
onsubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
if (loading) return;
|
||||
await altaFormaDePago();
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="altaFormaDePagoForm"
|
||||
bind:open
|
||||
size="sm"
|
||||
modalHeading="Dar de alta forma de pago"
|
||||
primaryButtonText="Dar de alta"
|
||||
primaryButtonDisabled={loading}
|
||||
secondaryButtonText="Cancelar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<InlineNotification kind="error" title="Error" subtitle={error} hideCloseButton />
|
||||
{/if}
|
||||
{#if forma}
|
||||
<p>¿Dar de alta la forma de pago <strong>{forma.descripcion}</strong>?</p>
|
||||
{/if}
|
||||
{#if success}
|
||||
<InlineNotification kind="success" title="Éxito" subtitle="Forma de pago dada de alta correctamente" hideCloseButton />
|
||||
{/if}
|
||||
</Modal>
|
||||
</form>
|
||||
@@ -0,0 +1,68 @@
|
||||
<script lang="ts">
|
||||
import { Modal, TextInput } from 'carbon-components-svelte';
|
||||
import type { FormaDePago } from '../../types';
|
||||
import { crearFormaDePago } from '$lib/hooks/formas-pago/crearFormaDePago';
|
||||
import { invalidate } from '$app/navigation';
|
||||
|
||||
let { open = $bindable(), onClose } = $props();
|
||||
|
||||
let error = $state('');
|
||||
let enviando = $state(false);
|
||||
let descripcion = $state('');
|
||||
|
||||
function handleClose() {
|
||||
reset();
|
||||
onClose?.();
|
||||
}
|
||||
function reset() {
|
||||
descripcion = '';
|
||||
error = '';
|
||||
enviando = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<form
|
||||
id="crearFormaDePagoForm"
|
||||
onsubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
if (enviando) return;
|
||||
enviando = true;
|
||||
error = '';
|
||||
if (!descripcion.trim()) {
|
||||
error = 'Falta Descripción';
|
||||
}
|
||||
if (error === '') {
|
||||
const result = await crearFormaDePago(descripcion);
|
||||
if (result === 'ok') {
|
||||
invalidate('formasPago:load');
|
||||
handleClose();
|
||||
} else {
|
||||
error = result ?? 'Error desconocido';
|
||||
}
|
||||
}
|
||||
enviando = false;
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="crearFormaDePagoForm"
|
||||
bind:open
|
||||
size={'lg'}
|
||||
modalHeading="Registrar Forma de Pago"
|
||||
primaryButtonText="Registrar"
|
||||
primaryButtonDisabled={enviando}
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="error-msg">{error}</div>
|
||||
{/if}
|
||||
<TextInput
|
||||
name="descripcion"
|
||||
type="text"
|
||||
labelText="Descripción:"
|
||||
bind:value={descripcion}
|
||||
maxlength={20}
|
||||
/>
|
||||
<div class="text-sm text-gray-500 mt-1">{String(descripcion).length}/20</div>
|
||||
</Modal>
|
||||
</form>
|
||||
@@ -0,0 +1,74 @@
|
||||
<script lang="ts">
|
||||
import { Modal, TextInput } from 'carbon-components-svelte';
|
||||
import type { FormaDePago } from '../../types';
|
||||
import { actualizarFormaDePago } from '$lib/hooks/formas-pago/actualizarFormaDePago';
|
||||
import { invalidate } from '$app/navigation';
|
||||
|
||||
let { open = $bindable(), onClose, forma } = $props();
|
||||
|
||||
let error = $state('');
|
||||
let enviando = $state(false);
|
||||
let descripcion = $state('');
|
||||
|
||||
$effect(()=>{
|
||||
if (forma) {
|
||||
descripcion = forma.descripcion ?? '';
|
||||
}
|
||||
})
|
||||
|
||||
function handleClose() {
|
||||
reset();
|
||||
onClose?.();
|
||||
}
|
||||
function reset() {
|
||||
descripcion = '';
|
||||
error = '';
|
||||
enviando = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<form
|
||||
id="editarFormaDePagoForm"
|
||||
onsubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
if (enviando) return;
|
||||
enviando = true;
|
||||
error = '';
|
||||
if (!descripcion.trim()) {
|
||||
error = 'Falta Descripción';
|
||||
}
|
||||
if (error === '' && forma) {
|
||||
const result = await actualizarFormaDePago(forma.ID, descripcion);
|
||||
if (result === 'ok') {
|
||||
invalidate('formasPago:load');
|
||||
handleClose();
|
||||
} else {
|
||||
error = result ?? 'Error desconocido';
|
||||
}
|
||||
}
|
||||
enviando = false;
|
||||
}}
|
||||
>
|
||||
<Modal
|
||||
formId="editarFormaDePagoForm"
|
||||
bind:open
|
||||
size={'lg'}
|
||||
modalHeading="Editar Forma de Pago"
|
||||
primaryButtonText="Guardar"
|
||||
primaryButtonDisabled={enviando}
|
||||
secondaryButtonText="Cancelar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="error-msg">{error}</div>
|
||||
{/if}
|
||||
<TextInput
|
||||
name="descripcion"
|
||||
type="text"
|
||||
labelText="Descripción:"
|
||||
bind:value={descripcion}
|
||||
maxlength={20}
|
||||
/>
|
||||
<div class="text-sm text-gray-500 mt-1">{String(descripcion).length}/20</div>
|
||||
</Modal>
|
||||
</form>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script lang="ts">
|
||||
import { Modal } from 'carbon-components-svelte';
|
||||
import { eliminarFormaDePago } from '$lib/hooks/formas-pago/eliminarFormaDePago';
|
||||
import { invalidate } from '$app/navigation';
|
||||
import type { FormaDePago } from '../../types';
|
||||
|
||||
let {
|
||||
open = $bindable(),
|
||||
onClose,
|
||||
forma
|
||||
}: { open?: boolean; onClose: () => void; forma?: FormaDePago | null } = $props();
|
||||
|
||||
let error = $state('');
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault();
|
||||
error = '';
|
||||
if (!forma?.ID) {
|
||||
error = 'No se pudo obtener la id de la Forma de Pago? recarga la página.';
|
||||
return;
|
||||
}
|
||||
const result = await eliminarFormaDePago(forma.ID);
|
||||
if (result !== 'Ok') {
|
||||
error = result;
|
||||
return;
|
||||
}
|
||||
invalidate('formasPago:load');
|
||||
handleClose();
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
error = '';
|
||||
onClose();
|
||||
}
|
||||
</script>
|
||||
|
||||
<form id="eliminarFormaDePagoForm" onsubmit={handleSubmit}>
|
||||
<Modal
|
||||
formId="eliminarFormaDePagoForm"
|
||||
bind:open={open}
|
||||
modalHeading="Eliminar Forma de Pago"
|
||||
primaryButtonText="Eliminar"
|
||||
secondaryButtonText="Cerrar"
|
||||
on:click:button--secondary={handleClose}
|
||||
>
|
||||
{#if error}
|
||||
<div class="text-red-500">{error}</div>
|
||||
{/if}
|
||||
¿Está seguro de que desea borrar esta Forma de Pago?
|
||||
</Modal>
|
||||
</form>
|
||||
Vendored
+5
@@ -327,3 +327,8 @@ export interface FacturaResumen {
|
||||
precioUnitario: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface FormaDePago extends BaseModel {
|
||||
empresaId?: number;
|
||||
descripcion: string;
|
||||
}
|
||||
Reference in new issue
Block a user