[MVPTN-37] feat(Itens): Implementa a inserção de itens ao pedido
This commit is contained in:
parent
06d55ec125
commit
790c79ede6
17 changed files with 383 additions and 30 deletions
|
|
@ -6,6 +6,7 @@ import API from '@/shared/services/api/Api';
|
|||
|
||||
// Importa o enum que define os métodos HTTP disponíveis (GET, POST, PUT, DELETE, etc.)
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
|
||||
import { GEmolumentoReadInterface } from '../../_interfaces/GEmolumentoReadInterface';
|
||||
|
||||
// Função assíncrona responsável por executar a requisição para listar os tipos de marcação
|
||||
|
|
@ -14,7 +15,7 @@ async function executeGEmolumentoIndexData(data: GEmolumentoReadInterface) {
|
|||
const api = new API();
|
||||
|
||||
// Concatena o endpoint com a query string (caso existam parâmetros)
|
||||
const endpoint = `administrativo/g_emolumento/${data.sistema_id}`;
|
||||
const endpoint = `administrativo/g_emolumento/sistema/${data.sistema_id}`;
|
||||
|
||||
// Envia uma requisição GET para o endpoint 'administrativo/g_marcacao_tipo/'
|
||||
return await api.send({
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
// Importa o hook responsável por gerenciar e exibir respostas globais (sucesso, erro, etc.)
|
||||
import { useMemo, useState } from 'react';
|
||||
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
|
||||
// Importa hooks do React para gerenciamento de estado e memorização de valores
|
||||
import { useMemo, useState } from 'react';
|
||||
|
||||
// Importa a interface que define a estrutura dos dados de "GEmolumento"
|
||||
import { GEmolumentoInterface } from '../../_interfaces/GEmolumentoInterface';
|
||||
import { GEmolumentoReadInterface } from '../../_interfaces/GEmolumentoReadInterface';
|
||||
|
||||
// Importa o serviço responsável por buscar os dados de "GEmolumento" na API
|
||||
import { GEmolumentoIndexService } from '../../_services/g_emolumento/GEmolumentoIndexService';
|
||||
import { GEmolumentoInterface } from '../../_interfaces/GEmolumentoInterface';
|
||||
|
||||
// Hook personalizado para leitura (consulta) dos emolumentos
|
||||
export const useGEmolumentoReadHook = () => {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,16 @@
|
|||
// Importa o hook responsável por gerenciar e exibir respostas globais (sucesso, erro, etc.)
|
||||
import { useMemo, useState } from 'react';
|
||||
|
||||
import { useResponse } from '@/shared/components/response/ResponseContext';
|
||||
|
||||
// Importa hooks do React para gerenciamento de estado e memorização de valores
|
||||
import { useMemo, useState } from 'react';
|
||||
|
||||
// Importa a interface que define a estrutura dos dados de "gEmolumentoItem"
|
||||
import { GEmolumentoItemInterface } from '../../_interfaces/GEmolumentoItemInterface';
|
||||
import { GEmolumentoItemReadInterface } from '../../_interfaces/GEmolumentoItemReadInterface';
|
||||
|
||||
// Importa o serviço responsável por buscar os dados de "GEmolumentoItem" na API
|
||||
import { GEmolumentoItemValorService } from '../../_services/g_emolumento_item/GEmolumentoItemValorService';
|
||||
import { GEmolumentoItemInterface } from '../../_interfaces/GEmolumentoItemInterface';
|
||||
|
||||
// Hook personalizado para leitura (consulta) dos emolumentos
|
||||
export const useGEmolumentoItemReadHook = () => {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,149 @@
|
|||
'use client';
|
||||
|
||||
import { CheckIcon, ChevronsUpDownIcon } from 'lucide-react';
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { useGEmolumentoReadHook } from '@/app/(protected)/(cadastros)/cadastros/_hooks/g_emolumento/useGEmolumentoReadHook';
|
||||
import { GEmolumentoReadInterface } from '@/app/(protected)/(cadastros)/cadastros/_interfaces/GEmolumentoReadInterface';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from '@/components/ui/command';
|
||||
import { FormControl } from '@/components/ui/form';
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||
import { cn } from '@/lib/utils';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
|
||||
// Tipagem das props do componente
|
||||
interface GEmolumentoSelectProps {
|
||||
sistema_id: number;
|
||||
field: any;
|
||||
onSelectChange?: (emolumento: { emolumento_id: number; descricao: string }) => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
// Componente principal do select de emolumentos
|
||||
export default function GEmolumentoServicoSelect({
|
||||
sistema_id,
|
||||
field,
|
||||
onSelectChange,
|
||||
className,
|
||||
}: GEmolumentoSelectProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const gEmolumentoReadParams: GEmolumentoReadInterface = { sistema_id };
|
||||
const { gEmolumento = [], fetchGEmolumento } = useGEmolumentoReadHook();
|
||||
|
||||
/**
|
||||
* Efeito para buscar os dados apenas uma vez.
|
||||
*/
|
||||
const loadData = useCallback(async () => {
|
||||
if (gEmolumento.length) return;
|
||||
setIsLoading(true);
|
||||
await fetchGEmolumento(gEmolumentoReadParams);
|
||||
setIsLoading(false);
|
||||
}, [gEmolumento.length, fetchGEmolumento, gEmolumentoReadParams]);
|
||||
|
||||
useEffect(() => {
|
||||
loadData();
|
||||
}, [loadData]);
|
||||
|
||||
/**
|
||||
* Memoriza o item selecionado para evitar reprocessamentos.
|
||||
*/
|
||||
const selected = useMemo(
|
||||
() =>
|
||||
gEmolumento.find(
|
||||
(item) => String(item.emolumento_id) === String(field?.value?.id ?? ''),
|
||||
),
|
||||
[gEmolumento, field?.value],
|
||||
);
|
||||
|
||||
/**
|
||||
* Manipulador de seleção com verificação segura.
|
||||
*/
|
||||
const handleSelect = useCallback(
|
||||
(item: any) => {
|
||||
if (!field?.onChange) return;
|
||||
|
||||
const selectedValue = {
|
||||
emolumento_id: Number(item.emolumento_id),
|
||||
descricao: item.descricao,
|
||||
};
|
||||
|
||||
field.onChange(selectedValue);
|
||||
|
||||
if (onSelectChange) onSelectChange(selectedValue);
|
||||
|
||||
setOpen(false);
|
||||
},
|
||||
[field, onSelectChange],
|
||||
);
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<FormControl className="w-full">
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
disabled={isLoading}
|
||||
className={cn(
|
||||
'justify-between min-h-[2.5rem] w-full text-left break-words whitespace-normal',
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{isLoading
|
||||
? 'Carregando...'
|
||||
: field.value?.descricao
|
||||
? GetCapitalize(field.value.descricao)
|
||||
: 'Selecione emolumento'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
|
||||
<PopoverContent
|
||||
align="start"
|
||||
side="bottom"
|
||||
className="w-[var(--radix-popover-trigger-width)] max-w-full p-0"
|
||||
>
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar emolumentos..." disabled={isLoading} />
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
{isLoading ? 'Carregando...' : 'Nenhum resultado encontrado.'}
|
||||
</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{gEmolumento.map((item) => (
|
||||
<CommandItem
|
||||
key={item.emolumento_id}
|
||||
value={item.descricao?.toLowerCase() ?? ''}
|
||||
onSelect={() => handleSelect(item)}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
String(field?.value?.emolumento_id ?? '') ===
|
||||
String(item.emolumento_id)
|
||||
? 'opacity-100'
|
||||
: 'opacity-0',
|
||||
)}
|
||||
/>
|
||||
{GetCapitalize(item.descricao ?? '')}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
|
|
@ -19,7 +19,6 @@ import { useTServicoTipoReadHook } from '@/packages/administrativo/hooks/TServic
|
|||
import TServicoTipoSelectInterface from '@/packages/administrativo/interfaces/TServicoTipo/TServicoTipoSelectInterface';
|
||||
import GetCapitalize from '@/shared/actions/text/GetCapitalize';
|
||||
|
||||
|
||||
export default function TServicoTipoSelect({ field }: TServicoTipoSelectInterface) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
|
@ -27,7 +26,6 @@ export default function TServicoTipoSelect({ field }: TServicoTipoSelectInterfac
|
|||
|
||||
/**
|
||||
* Efeito para buscar os dados apenas uma vez.
|
||||
* useCallback evita recriação desnecessária da função.
|
||||
*/
|
||||
const loadData = useCallback(async () => {
|
||||
if (tServicoTipo.length) return;
|
||||
|
|
@ -41,20 +39,29 @@ export default function TServicoTipoSelect({ field }: TServicoTipoSelectInterfac
|
|||
}, [loadData]);
|
||||
|
||||
/**
|
||||
* Memoriza o bairro selecionado para evitar reprocessamentos.
|
||||
* Item selecionado (comparando por ID)
|
||||
*/
|
||||
const selected = useMemo(
|
||||
() => tServicoTipo.find((b) => String(b.servico_tipo_id) === String(field?.value ?? '')),
|
||||
() =>
|
||||
tServicoTipo.find(
|
||||
(item) => String(item.servico_tipo_id) === String(field?.value?.servico_tipo_id ?? ''),
|
||||
),
|
||||
[tServicoTipo, field?.value],
|
||||
);
|
||||
|
||||
/**
|
||||
* Manipulador de seleção com verificação segura.
|
||||
* Manipulador de seleção
|
||||
*/
|
||||
const handleSelect = useCallback(
|
||||
(bairroId: string | number) => {
|
||||
(item: any) => {
|
||||
if (!field?.onChange) return;
|
||||
field.onChange(bairroId);
|
||||
|
||||
const selectedValue = {
|
||||
servico_tipo_id: Number(item.servico_tipo_id),
|
||||
descricao: item.descricao,
|
||||
};
|
||||
|
||||
field.onChange(selectedValue);
|
||||
setOpen(false);
|
||||
},
|
||||
[field],
|
||||
|
|
@ -73,16 +80,17 @@ export default function TServicoTipoSelect({ field }: TServicoTipoSelectInterfac
|
|||
>
|
||||
{isLoading
|
||||
? 'Carregando...'
|
||||
: selected
|
||||
? GetCapitalize(selected.descricao)
|
||||
: field.value?.descricao
|
||||
? GetCapitalize(field.value.descricao)
|
||||
: 'Selecione...'}
|
||||
<ChevronsUpDownIcon className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</FormControl>
|
||||
</PopoverTrigger>
|
||||
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Buscar bairro..." disabled={isLoading} />
|
||||
<CommandInput placeholder="Buscar tipo de serviço..." disabled={isLoading} />
|
||||
<CommandList>
|
||||
<CommandEmpty>
|
||||
{isLoading ? 'Carregando...' : 'Nenhum resultado encontrado.'}
|
||||
|
|
@ -92,12 +100,13 @@ export default function TServicoTipoSelect({ field }: TServicoTipoSelectInterfac
|
|||
<CommandItem
|
||||
key={item.servico_tipo_id}
|
||||
value={item.descricao?.toLowerCase() ?? ''}
|
||||
onSelect={() => handleSelect(Number(item.servico_tipo_id))}
|
||||
onSelect={() => handleSelect(item)}
|
||||
>
|
||||
<CheckIcon
|
||||
className={cn(
|
||||
'mr-2 h-4 w-4',
|
||||
String(field?.value ?? '') === String(item.servico_tipo_id)
|
||||
String(field?.value?.servico_tipo_id ?? '') ===
|
||||
String(item.servico_tipo_id)
|
||||
? 'opacity-100'
|
||||
: 'opacity-0',
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
import GCalculoInterface from '@/packages/administrativo/interfaces/GCalculo/GCalculoInterface';
|
||||
import { withClientErrorHandler } from '@/shared/actions/withClientErrorHandler/withClientErrorHandler';
|
||||
import API from '@/shared/services/api/Api';
|
||||
import { Methods } from '@/shared/services/api/enums/ApiMethodEnum';
|
||||
import ApiResponseInterface from '@/shared/services/api/interfaces/ApiResponseInterface';
|
||||
|
||||
|
||||
async function executeGCalculoCalcularData(data: GCalculoInterface): Promise<ApiResponseInterface> {
|
||||
const api = new API();
|
||||
return api.send({
|
||||
method: Methods.POST,
|
||||
endpoint: `administrativo/g_calculo/servico/`,
|
||||
body: data,
|
||||
});
|
||||
}
|
||||
|
||||
export const GCalculoServico = withClientErrorHandler(executeGCalculoCalcularData);
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
export default interface GCalculoServicoInterface {
|
||||
valor_documento?: number;
|
||||
emolumento_id?: number;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
import { withClientErrorHandler } from "@/shared/actions/withClientErrorHandler/withClientErrorHandler";
|
||||
|
||||
import { GCalculoServico } from "../../data/GCalculo/GCalculoServicoData";
|
||||
import GCalculoServicoInterface from "../../interfaces/GCalculo/GCalculoServicoInterface";
|
||||
|
||||
async function executeGCalculoServicoService(data: GCalculoServicoInterface) {
|
||||
const response = await GCalculoServico(data);
|
||||
return response;
|
||||
}
|
||||
|
||||
export const GCalculoServicoService = withClientErrorHandler(executeGCalculoServicoService);
|
||||
|
|
@ -26,7 +26,7 @@ export default function TServicoItemPedidoFormColumns(
|
|||
<div className="flex items-center gap-3">
|
||||
<div>
|
||||
<div className="font-semibold text-gray-900 capitalize">
|
||||
{GetCapitalize(data.servico)}
|
||||
{GetCapitalize(data.descricao)}
|
||||
</div>
|
||||
<div className="text-sm text-gray-500">
|
||||
{GetCapitalize(data.tabela)}
|
||||
|
|
@ -36,8 +36,8 @@ export default function TServicoItemPedidoFormColumns(
|
|||
);
|
||||
},
|
||||
sortingFn: (a, b) =>
|
||||
(a.original.servico?.toLowerCase() || '').localeCompare(
|
||||
b.original.servico?.toLowerCase() || '',
|
||||
(a.original.descricao?.toLowerCase() || '').localeCompare(
|
||||
b.original.descricao?.toLowerCase() || '',
|
||||
),
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,11 @@ import {
|
|||
FormMessage
|
||||
} from '@/components/ui/form';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import GEmolumentoServicoSelect from '@/packages/administrativo/components/GEmolumento/GEmolumentoServicoSelect';
|
||||
import GUsuarioSelect from '@/packages/administrativo/components/GUsuario/GUsuarioSelect';
|
||||
import TServicoTipoSelect from '@/packages/administrativo/components/TServicoTipo/TServicoTipoSelect';
|
||||
import TServicoItemPedidoFormTable from '@/packages/servicos/components/TServicoItemPedido/TServicoItemPedidoFormTable';
|
||||
import { useTServicoItemPedidoAddHook } from '@/packages/servicos/hooks/TServicoItemPedido/useTServicoItemPedidoAddHook';
|
||||
import { useTServicoPedidoFormHook } from '@/packages/servicos/hooks/TServicoPedido/useTServicoPedidoFormHook';
|
||||
import { useTServicoPedidoSaveHook } from '@/packages/servicos/hooks/TServicoPedido/useTServicoPedidoSaveHook';
|
||||
import TServicoPedidoInterface from '@/packages/servicos/interfaces/TServicoPedido/TServicoPedidoInterface';
|
||||
|
|
@ -26,16 +30,40 @@ import { StepNavigator, StepNavigatorRef, StepSection } from '@/shared/component
|
|||
import TipoPagamentoSelect from '@/shared/components/tipoPagamento/TipoPagamentoSelect';
|
||||
|
||||
|
||||
|
||||
|
||||
export default function TServicoPedidoForm() {
|
||||
|
||||
// Controle de rotas
|
||||
const router = useRouter();
|
||||
|
||||
const form = useTServicoPedidoFormHook({});
|
||||
|
||||
const { setValue, handleSubmit, watch } = form;
|
||||
|
||||
// Controle de estado do botão
|
||||
const [buttonIsLoading, setButtonIsLoading] = useState(false);
|
||||
const { TServicoPedido, saveTServicoPedido } = useTServicoPedidoSaveHook()
|
||||
const { TServicoItemPedido, addTServicoItemPedido } = useTServicoItemPedidoAddHook(setValue)
|
||||
|
||||
const form = useTServicoPedidoFormHook({});
|
||||
const servicoAtual = watch('servico_tipo_id');
|
||||
const emolumentoAtual = watch('emolumento_id');
|
||||
|
||||
const handleAddItem = () => {
|
||||
|
||||
if (servicoAtual && emolumentoAtual) {
|
||||
|
||||
// Cria um novo objeto
|
||||
const servicoEEmolumento = {
|
||||
servico_tipo: servicoAtual,
|
||||
emolumento: emolumentoAtual
|
||||
}
|
||||
|
||||
// Adiciona o item calculado na tabel
|
||||
addTServicoItemPedido(servicoEEmolumento)
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
const sections: StepSection[] = [
|
||||
{ key: 'pedido', id: 'selectPedido', icon: <Package className="h-4 w-4" />, title: 'Pedido', description: 'Dados gerais do pedido.' },
|
||||
|
|
@ -50,8 +78,6 @@ export default function TServicoPedidoForm() {
|
|||
|
||||
async (formData: TServicoPedidoInterface) => {
|
||||
|
||||
console.log(formData);
|
||||
|
||||
// Coloca o botão em estado de loading
|
||||
setButtonIsLoading(true);
|
||||
|
||||
|
|
@ -76,6 +102,11 @@ export default function TServicoPedidoForm() {
|
|||
console.log('Erro no formulário:', error);
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
console.log(JSON.stringify(TServicoItemPedido))
|
||||
}, [TServicoItemPedido])
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h3 className='text-4xl font-bold mb-4'>
|
||||
|
|
@ -205,6 +236,58 @@ export default function TServicoPedidoForm() {
|
|||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card role="presentation" id="selectServicoPedidoItem" className="scroll-mt-6">
|
||||
<CardHeader>
|
||||
<CardTitle>
|
||||
<h4 className='text-3xl'>
|
||||
Itens
|
||||
</h4>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-4">
|
||||
<div className="grid w-full grid-cols-12 gap-4">
|
||||
<div className="col-span-12 sm:col-span-12 md:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="servico_tipo_id"
|
||||
render={({ field }) => (
|
||||
<FormItem className="col-span-1 sm:col-span-2">
|
||||
<FormLabel>Serviços</FormLabel>
|
||||
<TServicoTipoSelect field={field} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-12 sm:col-span-12 md:col-span-6">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="emolumento_id"
|
||||
render={({ field }) => (
|
||||
<FormItem className="col-span-1 sm:col-span-2">
|
||||
<FormLabel>Emolumentos</FormLabel>
|
||||
<GEmolumentoServicoSelect sistema_id={2} field={field} />
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-12 sm:col-span-12 md:col-span-12 text-end">
|
||||
<Button type="button" onClick={handleAddItem}>
|
||||
+ Adicionar
|
||||
</Button>
|
||||
</div>
|
||||
<div className="col-span-12 sm:col-span-12 md:col-span-12">
|
||||
<TServicoItemPedidoFormTable
|
||||
data={TServicoItemPedido}
|
||||
setValue={setValue}
|
||||
onEdit={() => { }}
|
||||
onDelete={() => { }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{/* Seção: Pagamento */}
|
||||
<Card role="presentation" id="selectPayment" className="scroll-mt-6">
|
||||
<CardHeader>
|
||||
|
|
@ -252,7 +335,7 @@ export default function TServicoPedidoForm() {
|
|||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-6">
|
||||
<div className="col-span-12 sm:col-span-12 md:col-span-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="valor_pedido"
|
||||
|
|
@ -271,7 +354,7 @@ export default function TServicoPedidoForm() {
|
|||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-12 sm:col-span-6 md:col-span-6">
|
||||
<div className="col-span-12 sm:col-span-12 md:col-span-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="valor_pago"
|
||||
|
|
@ -290,7 +373,7 @@ export default function TServicoPedidoForm() {
|
|||
)}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-12 sm:col-span-12 md:col-span-12">
|
||||
<div className="col-span-12 sm:col-span-12 md:col-span-4">
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="tipo_pagamento"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { UseFormSetValue } from 'react-hook-form';
|
||||
|
||||
import { GCalculoServicoService } from '@/packages/administrativo/services/GCalculo/GCalculoServicoService';
|
||||
import TServicoItemPedidoAddInterface from '@/packages/servicos/interfaces/TServicoItemPedido/TServicoItemPedidoAddInterface';
|
||||
import TServicoItemPedidoIndexResponseInterface from '@/packages/servicos/interfaces/TServicoItemPedido/TServicoItemPedidoIndexResponseInterface';
|
||||
|
||||
|
||||
|
||||
export const useTServicoItemPedidoAddHook = (setValue: UseFormSetValue<TServicoItemPedidoAddInterface>) => {
|
||||
|
||||
const [TServicoItemPedido, setTServicoItemPedido] = useState<TServicoItemPedidoIndexResponseInterface[]>([]);
|
||||
|
||||
const addTServicoItemPedido = async (data: TServicoItemPedidoAddInterface) => {
|
||||
|
||||
console.log(data.emolumento)
|
||||
|
||||
data.sistema_id = 2
|
||||
data.valor_documento = 0
|
||||
data.quantidade = 1
|
||||
data.emolumento_id = data.emolumento.emolumento_id
|
||||
|
||||
const response = await GCalculoServicoService(data)
|
||||
|
||||
const item = {
|
||||
emolumento_id: data.emolumento.emolumento_id,
|
||||
emolumento_item_id: data.emolumento.emolumento_item_id,
|
||||
servico_tipo_id: data.servico_tipo.servico_tipo_id,
|
||||
descricao: data.servico_tipo.descricao,
|
||||
tabela: data.emolumento.descricao,
|
||||
situacao: 'F',
|
||||
qtd: 1,
|
||||
valor: response.data.valor_total,
|
||||
emolumento: response.data.valor_emolumento,
|
||||
fundesp: response.data.valor_fundos,
|
||||
taxa_judiciaria: response.data.taxa_judiciaria,
|
||||
valor_iss: response.data.valor_iss,
|
||||
}
|
||||
|
||||
setTServicoItemPedido((prev) => {
|
||||
const novoItem = [...prev, item]
|
||||
if (setValue) setValue('itens', novoItem)
|
||||
return novoItem
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
return {
|
||||
TServicoItemPedido,
|
||||
addTServicoItemPedido,
|
||||
};
|
||||
};
|
||||
|
|
@ -13,7 +13,7 @@ export function useTServicoPedidoFormHook(defaults?: Partial<TServicoPedidoFormV
|
|||
data_pedido: "",
|
||||
observacao: "",
|
||||
escrevente_id: 0,
|
||||
situacao: "",
|
||||
situacao: "F",
|
||||
estornado: "",
|
||||
apresentante: "",
|
||||
cpfcnpj_apresentante: "",
|
||||
|
|
@ -21,6 +21,7 @@ export function useTServicoPedidoFormHook(defaults?: Partial<TServicoPedidoFormV
|
|||
selo_pessoa_cpfcnpj: "",
|
||||
login: "",
|
||||
funcao: "",
|
||||
itens: [],
|
||||
...defaults,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
export default interface TServicoItemPedidoAddInterface {
|
||||
emolumento_id: number;
|
||||
servico_tipo: object;
|
||||
sistema_id?: number;
|
||||
valor_documento?: number;
|
||||
quantidade?: number;
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ export default interface TServicoItemPedidoInterface {
|
|||
certidao_previsao?: string | Date
|
||||
certidao_ato_antigo?: string
|
||||
certidao_data_emissao?: string | Date
|
||||
certidao_texto?: string | null // BLOB -> texto longo ou base64
|
||||
certidao_texto?: string | null
|
||||
ato_antigo_tipo?: string
|
||||
valor_iss?: number
|
||||
id_ato_isentado?: number
|
||||
|
|
@ -63,4 +63,5 @@ export default interface TServicoItemPedidoInterface {
|
|||
vrcext?: number
|
||||
valor_fundo_selo?: number
|
||||
averbacao?: string
|
||||
descricao?: string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,4 +17,7 @@ export default interface TServicoPedidoInterface {
|
|||
selo_pessoa_cpfcnpj?: string;
|
||||
login?: string;
|
||||
funcao?: string;
|
||||
itens?: [];
|
||||
servico_tipo_id: object;
|
||||
emolumento_id: object;
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
import z from "zod";
|
||||
|
||||
import { TServicoItemPedidoSchema } from "../TServicoItemPedido/TServicoItemPedidoSchema";
|
||||
|
||||
|
||||
export const TServicoPedidoSchema = z.object({
|
||||
servico_pedido_id: z.number().optional(),
|
||||
|
|
@ -9,7 +11,7 @@ export const TServicoPedidoSchema = z.object({
|
|||
data_pedido: z.string().optional(),
|
||||
mensalista_livrocaixa_id: z.number().optional(),
|
||||
observacao: z.string().optional(),
|
||||
escrevente_id: z.number().optional(),
|
||||
escrevente_id: z.number(),
|
||||
situacao: z.string().optional(),
|
||||
estornado: z.string().optional(),
|
||||
nfse_id: z.number().optional(),
|
||||
|
|
@ -18,7 +20,10 @@ export const TServicoPedidoSchema = z.object({
|
|||
selo_pessoa_nome: z.string().optional(),
|
||||
selo_pessoa_cpfcnpj: z.string().optional(),
|
||||
login: z.string().optional(),
|
||||
funcao: z.string().optional()
|
||||
funcao: z.string().optional(),
|
||||
itens: z.array(TServicoItemPedidoSchema).default([]),
|
||||
servico_tipo_id: z.object(),
|
||||
emolumento_id: z.object(),
|
||||
});
|
||||
|
||||
export type TServicoPedidoFormValues = z.infer<typeof TServicoPedidoSchema>;
|
||||
6
src/shared/actions/data/ToMoney.ts
Normal file
6
src/shared/actions/data/ToMoney.ts
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// Helper: garante número com 2 casas decimais
|
||||
export const toMoney = (v: unknown): number => {
|
||||
const n = Number(v ?? 0);
|
||||
// evita problemas de ponto flutuante
|
||||
return Math.round((n + Number.EPSILON) * 100) / 100;
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue