|
|
@@ -1,5 +1,6 @@
|
|
|
"use client"
|
|
|
|
|
|
+import { useState } from 'react'
|
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
|
|
import { Input } from "@/components/ui/input"
|
|
|
import { Label } from "@/components/ui/label"
|
|
|
@@ -7,7 +8,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
|
|
import type { InfoTributaria } from "@/types/factura"
|
|
|
import { useConfiguracionesTributarias } from '@/hooks/useConfiguracionesTributarias'
|
|
|
import { Button } from "@/components/ui/button"
|
|
|
-import { ExternalLink } from 'lucide-react'
|
|
|
+import { Lock, Unlock } from 'lucide-react'
|
|
|
|
|
|
interface InfoTributariaFormProps {
|
|
|
infoTributaria: InfoTributaria
|
|
|
@@ -16,6 +17,8 @@ interface InfoTributariaFormProps {
|
|
|
|
|
|
export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaFormProps) {
|
|
|
const { configuraciones } = useConfiguracionesTributarias()
|
|
|
+ const [isLocked, setIsLocked] = useState(false)
|
|
|
+ const [selectedConfigId, setSelectedConfigId] = useState<string>('')
|
|
|
|
|
|
const loadConfiguracion = (config: any) => {
|
|
|
onChange('ambiente', config.ambiente)
|
|
|
@@ -28,25 +31,39 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
onChange('ptoEmi', config.ptoEmi)
|
|
|
onChange('secuencial', config.secuencial)
|
|
|
onChange('obligadoContabilidad', config.obligadoContabilidad || 'NO')
|
|
|
+ setIsLocked(true)
|
|
|
// Nota: claveAcceso se genera automáticamente al crear el XML
|
|
|
}
|
|
|
|
|
|
+ const toggleLock = () => {
|
|
|
+ setIsLocked(!isLocked)
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
<Card>
|
|
|
<CardHeader>
|
|
|
<div className="flex justify-between items-start">
|
|
|
<div>
|
|
|
<CardTitle>Información Tributaria</CardTitle>
|
|
|
- <CardDescription>Datos del emisor de la factura</CardDescription>
|
|
|
+ <CardDescription>
|
|
|
+ {isLocked
|
|
|
+ ? "Datos del emisor (bloqueados - click en el candado para editar)"
|
|
|
+ : "Datos del emisor de la factura"}
|
|
|
+ </CardDescription>
|
|
|
</div>
|
|
|
- {configuraciones.length > 0 && (
|
|
|
- <div className="flex gap-2">
|
|
|
- <Select onValueChange={(value) => {
|
|
|
- const config = configuraciones.find(c => c.id === value)
|
|
|
- if (config) {
|
|
|
- loadConfiguracion(config)
|
|
|
- }
|
|
|
- }}>
|
|
|
+ <div className="flex gap-2">
|
|
|
+ {configuraciones.length > 0 && (
|
|
|
+ <Select
|
|
|
+ value={selectedConfigId}
|
|
|
+ onValueChange={(value) => {
|
|
|
+ const config = configuraciones.find(c => c.id === value)
|
|
|
+ if (config) {
|
|
|
+ setSelectedConfigId(value)
|
|
|
+ loadConfiguracion(config)
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ disabled={isLocked}
|
|
|
+ >
|
|
|
<SelectTrigger className="w-[200px]">
|
|
|
<SelectValue placeholder="Cargar configuración" />
|
|
|
</SelectTrigger>
|
|
|
@@ -58,22 +75,37 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
))}
|
|
|
</SelectContent>
|
|
|
</Select>
|
|
|
- {/* <Button
|
|
|
+ )}
|
|
|
+ {isLocked && (
|
|
|
+ <Button
|
|
|
+ variant="outline"
|
|
|
+ size="sm"
|
|
|
+ onClick={toggleLock}
|
|
|
+ className="flex items-center gap-2"
|
|
|
+ >
|
|
|
+ <Lock className="w-4 h-4" />
|
|
|
+ Desbloquear
|
|
|
+ </Button>
|
|
|
+ )}
|
|
|
+ {!isLocked && selectedConfigId && (
|
|
|
+ <Button
|
|
|
variant="outline"
|
|
|
size="sm"
|
|
|
- onClick={() => window.open('/configuracion', '_blank')}
|
|
|
+ onClick={toggleLock}
|
|
|
+ className="flex items-center gap-2"
|
|
|
>
|
|
|
- <ExternalLink className="w-4 h-4" />
|
|
|
- </Button> */}
|
|
|
- </div>
|
|
|
- )}
|
|
|
+ <Unlock className="w-4 h-4" />
|
|
|
+ Bloquear
|
|
|
+ </Button>
|
|
|
+ )}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</CardHeader>
|
|
|
<CardContent>
|
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
|
<div className="space-y-2">
|
|
|
<Label htmlFor="ambiente">Ambiente</Label>
|
|
|
- <Select value={infoTributaria.ambiente} onValueChange={(value) => onChange('ambiente', value)}>
|
|
|
+ <Select value={infoTributaria.ambiente} onValueChange={(value) => onChange('ambiente', value)} disabled={isLocked}>
|
|
|
<SelectTrigger>
|
|
|
<SelectValue />
|
|
|
</SelectTrigger>
|
|
|
@@ -83,10 +115,10 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
</SelectContent>
|
|
|
</Select>
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
<div className="space-y-2">
|
|
|
<Label htmlFor="tipoEmision">Tipo Emisión</Label>
|
|
|
- <Select value={infoTributaria.tipoEmision} onValueChange={(value) => onChange('tipoEmision', value)}>
|
|
|
+ <Select value={infoTributaria.tipoEmision} onValueChange={(value) => onChange('tipoEmision', value)} disabled={isLocked}>
|
|
|
<SelectTrigger>
|
|
|
<SelectValue />
|
|
|
</SelectTrigger>
|
|
|
@@ -95,7 +127,7 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
</SelectContent>
|
|
|
</Select>
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
<div className="space-y-2">
|
|
|
<Label htmlFor="ruc">RUC *</Label>
|
|
|
<Input
|
|
|
@@ -104,9 +136,10 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
onChange={(e) => onChange('ruc', e.target.value)}
|
|
|
placeholder="13 dígitos"
|
|
|
maxLength={13}
|
|
|
+ disabled={isLocked}
|
|
|
/>
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
<div className="space-y-2">
|
|
|
<Label htmlFor="razonSocial">Razón Social *</Label>
|
|
|
<Input
|
|
|
@@ -114,9 +147,10 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
value={infoTributaria.razonSocial}
|
|
|
onChange={(e) => onChange('razonSocial', e.target.value)}
|
|
|
placeholder="Empresa S.A."
|
|
|
+ disabled={isLocked}
|
|
|
/>
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
<div className="space-y-2">
|
|
|
<Label htmlFor="nombreComercial">Nombre Comercial *</Label>
|
|
|
<Input
|
|
|
@@ -124,9 +158,10 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
value={infoTributaria.nombreComercial}
|
|
|
onChange={(e) => onChange('nombreComercial', e.target.value)}
|
|
|
placeholder="Nombre Comercial"
|
|
|
+ disabled={isLocked}
|
|
|
/>
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
<div className="space-y-2">
|
|
|
<Label htmlFor="estab">Establecimiento</Label>
|
|
|
<Input
|
|
|
@@ -135,9 +170,10 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
onChange={(e) => onChange('estab', e.target.value)}
|
|
|
placeholder="001"
|
|
|
maxLength={3}
|
|
|
+ disabled={isLocked}
|
|
|
/>
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
<div className="space-y-2">
|
|
|
<Label htmlFor="ptoEmi">Punto Emisión</Label>
|
|
|
<Input
|
|
|
@@ -146,9 +182,10 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
onChange={(e) => onChange('ptoEmi', e.target.value)}
|
|
|
placeholder="001"
|
|
|
maxLength={3}
|
|
|
+ disabled={isLocked}
|
|
|
/>
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
<div className="space-y-2">
|
|
|
<Label htmlFor="secuencial">Secuencial</Label>
|
|
|
<Input
|
|
|
@@ -157,9 +194,10 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
onChange={(e) => onChange('secuencial', e.target.value)}
|
|
|
placeholder="000000001"
|
|
|
maxLength={9}
|
|
|
+ disabled={isLocked}
|
|
|
/>
|
|
|
</div>
|
|
|
-
|
|
|
+
|
|
|
<div className="space-y-2 lg:col-span-2">
|
|
|
<Label htmlFor="dirMatriz">Dirección Matriz *</Label>
|
|
|
<Input
|
|
|
@@ -167,12 +205,13 @@ export function InfoTributariaForm({ infoTributaria, onChange }: InfoTributariaF
|
|
|
value={infoTributaria.dirMatriz}
|
|
|
onChange={(e) => onChange('dirMatriz', e.target.value)}
|
|
|
placeholder="Av. Principal 123 y Secundaria"
|
|
|
+ disabled={isLocked}
|
|
|
/>
|
|
|
</div>
|
|
|
|
|
|
<div className="space-y-2">
|
|
|
<Label htmlFor="obligadoContabilidad">Obligado a Llevar Contabilidad *</Label>
|
|
|
- <Select value={infoTributaria.obligadoContabilidad} onValueChange={(value) => onChange('obligadoContabilidad', value)}>
|
|
|
+ <Select value={infoTributaria.obligadoContabilidad} onValueChange={(value) => onChange('obligadoContabilidad', value)} disabled={isLocked}>
|
|
|
<SelectTrigger>
|
|
|
<SelectValue />
|
|
|
</SelectTrigger>
|