PageSourceSearch

https://app.stoqui.com.br/assets/FiscalDefaultsPage-haXyY2kk.js

js stoqui.com.br collected 2026-10-01 15:18:53 UTC 9,557 bytes, 1 lines download raw bytes

1import{j as r,a7 as E,a6 as K,ad as B,au as ne,ab as U,T as P,z as _,n as j,av as ie}from"./mui-CRsYZxVY.js";import{b as le,r as d}from"./vendor-Dwao9eNC.js";import{y as ce,z as b,T as de,u as Q,w as q,C as ue,F as fe,bz as me,D as N,aK as V}from"./index-TALscxEc.js";import{u as D,a as pe,b as ge}from"./query-8ViTdhdk.js";import{u as he}from"./useFiscalConfig-CQEKyhOW.js";import{a as I,i as _e,b as be,c as xe,d as Se,P as z}from"./fiscalOptions-BZ76yhnP.js";import{L as ye}from"./lab-DSem1Osk.js";import"./datePickers-BIJXYOKG.js";import"./icons-D8aatgQ4.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new e.Error().stack;s&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[s]="3db85123-509c-4fcc-8533-21df2cb55c33",e._sentryDebugIdIdentifier="sentry-dbid-3db85123-509c-4fcc-8533-21df2cb55c33")})()}catch{}const w=e=>{const s=e.replace(/\D/g,"");return s.length!==8?e:`${s.slice(0,4)}.${s.slice(4,6)}.${s.slice(6,8)}`},O=e=>e?e.descricao?`${w(e.codigo)} - ${e.descricao}`:w(e.codigo):"",Ce=(e,s)=>D({queryKey:["ncm-search",e],queryFn:async()=>{const{data:o}=await V.get(`/fiscal/ncm/search?q=${encodeURIComponent(e)}`);return(o.data||[]).map(i=>({codigo:i.codigo,descricao:i.descricao_completa||i.descricao}))},enabled:s&&e.length>=2,staleTime:6e4}),Ne=(e,s)=>{const o=e.replace(/\D/g,"");return D({queryKey:["ncm-lookup",o],queryFn:async()=>{const{data:i}=await V.get(`/fiscal/ncm/${o}`);return i.data?{codigo:i.data.codigo,descricao:i.data.descricao_completa||i.data.descricao}:null},enabled:s&&o.length===8,staleTime:1/0})},G=e=>{const s=(e||"").trim().replace(",",".");return/^\d+(\.\d{1,4})?$/.test(s)?Number(s):null},Oe=e=>{if(e==null||e==="")return null;const s=Number(e);return Number.isFinite(s)?String(s).replace(".",","):null},je=ce({cfop_interno:b().required("CFOP interno é obrigatório"),cfop_interestadual:b().required("CFOP interestadual é obrigatório"),csosn_default:b().required("CSOSN é obrigatório"),aliquota_credito_simples:b().nullable().default(null).when("csosn_default",{is:I,then:e=>e.required("Informe a alíquota de crédito do ICMS").test("aliquota-valida","Informe um percentual maior que 0 e menor que 100",s=>{const o=G(s);return o!==null&&o>0&&o<100})}),pis_default:b().required("CST PIS é obrigatório"),cofins_default:b().required("CST COFINS é obrigatório"),ncm_default:b().nullable().default(null)}),Ie={cfop_interno:"5102",cfop_interestadual:"6102",csosn_default:"102",aliquota_credito_simples:null,pis_default:"49",cofins_default:"49",ncm_default:null},Te=()=>{const{user:e}=Q();return D({queryKey:["fiscal-defaults",e==null?void 0:e.id],queryFn:async()=>{if(!(e!=null&&e.id))throw new Error("User not authenticated");const{data:s,error:o}=await q.from("fiscal_defaults").select("*").eq("user_id",e.id).single();if(o&&o.code!=="PGRST116"&&o.code!=="42P01")throw o;return s},enabled:!!(e!=null&&e.id)})},ve=()=>{const{user:e}=Q(),s=pe();return ge({mutationFn:async o=>{if(!(e!=null&&e.id))throw new Error("User not authenticated");const{data:i}=await q.from("fiscal_defaults").select("user_id").eq("user_id",e.id).single(),g={...o,aliquota_credito_simples:o.csosn_default===I?G(o.aliquota_credito_simples):null},h={...g,user_id:e.id};if(i){const{error:c}=await q.from("fiscal_defaults").update(g).eq("user_id",e.id);if(c)throw c}else{const{error:c}=await q.from("fiscal_defaults").insert(h);if(c)throw c}},onSuccess:()=>{s.invalidateQueries({queryKey:["fiscal-defaults"]})}})},qe=({defaultValues:e,regimeNormal:s,mei:o})=>{const i=ve(),[g,h]=le.useState(null),{control:c,handleSubmit:Y,reset:H,watch:J,formState:{isSubmitting:m,isDirty:L}}=ue({resolver:fe(je),defaultValues:e}),[M,A]=d.useState(!1),[X,x]=d.useState(""),[$,F]=d.useState(""),[u,S]=d.useState(null),[y,T]=d.useState(null),{field:v}=me({control:c,name:"ncm_default"}),C=v.value,{data:p=[],isLoading:Z}=Ce($,M),R=!!C&&!u&&!p.some(a=>a.codigo===C),{data:f,isLoading:ee}=Ne(R?C:y||"",R||!!y),k=d.useCallback(ne(a=>F(a),300),[]),ae=d.useCallback((a,t)=>{if(x(t),t&&t!==O(u)){k(t.replace(/\./g,"").trim());const n=t.replace(/\D/g,"");T(/^[\d.\s-]+$/.test(t)&&n.length===8?n:null)}else t||(F(""),T(null))},[u,k]);d.useEffect(()=>{u?x(O(u)):f&&(S(f),x(O(f)))},[u,f]),d.useEffect(()=>{if(!C)S(null);else{const a=p.find(t=>t.codigo===C);a&&S(a)}},[p,C]),d.useEffect(()=>{if(!y)return;const a=p.find(t=>t.codigo===y)||((f==null?void 0:f.codigo)===y?f:null);a&&(T(null),S(a),x(O(a)),v.onChange(a.codigo))},[y,p,f]);const te=d.useMemo(()=>{const a=[...p];return u&&!a.some(t=>t.codigo===u.codigo)&&a.unshift(u),a},[p,u]),W=Z&&p.length===0||ee,re=J("csosn_default"),se=be.filter(a=>!o||a.value!==I||e.csosn_default===I),oe=async a=>{try{h(null),await i.mutateAsync(a),H(a)}catch(t){h(t.message||"Erro ao salvar configurações fiscais.")}};return r.jsx("form",{onSubmit:Y(oe),children:r.jsxs(U,{spacing:3,children:[r.jsx(P,{variant:"caption",color:"text.secondary",children:s?"CFOP e NCM padrão usados ao emitir notas fiscais. ICMS, PIS e COFINS ficam nas regras de tributação.":"Estes valores serão usados como padrão para todos os produtos ao emitir notas fiscais. Você pode alterar individualmente no cadastro de cada produto."}),r.jsx(N,{name:"cfop_interno",control:c,render:({field:a,fieldState:t})=>{var n;return r.jsx(_,{...a,select:!0,label:"CFOP interno (mesmo estado) *",fullWidth:!0,error:!!t.error,helperText:((n=t.error)==null?void 0:n.message)||"",disabled:m,children:xe.map(l=>r.jsx(j,{value:l.value,children:l.label},l.value))})}}),r.jsx(N,{name:"cfop_interestadual",control:c,render:({field:a,fieldState:t})=>{var n;
1return r.jsx(_,{...a,select:!0,label:"CFOP interestadual (outro estado) *",fullWidth:!0,error:!!t.error,helperText:((n=t.error)==null?void 0:n.message)||"",disabled:m,children:Se.map(l=>r.jsx(j,{value:l.value,children:l.label},l.value))})}}),!s&&r.jsxs(r.Fragment,{children:[r.jsx(N,{name:"csosn_default",control:c,render:({field:a,fieldState:t})=>{var n;return r.jsx(_,{...a,select:!0,label:"CSOSN (Simples Nacional) *",fullWidth:!0,error:!!t.error,helperText:((n=t.error)==null?void 0:n.message)||"",disabled:m,children:se.map(l=>r.jsx(j,{value:l.value,children:l.label},l.value))})}}),re===I&&r.jsx(N,{name:"aliquota_credito_simples",control:c,render:({field:a,fieldState:t})=>{var n;return r.jsx(_,{...a,value:a.value??"",label:"Alíquota de crédito do ICMS (%) *",placeholder:"Ex.: 1,86",fullWidth:!0,inputProps:{inputMode:"decimal"},error:!!t.error,helperText:((n=t.error)==null?void 0:n.message)||(o?"MEI não pode emitir com CSOSN 101. Escolha outro CSOSN.":"Percentual efetivo de ICMS da sua faixa do Simples Nacional (peça ao seu contador). Atualize quando a faixa mudar. O crédito só vai em NF-e para cliente com inscrição estadual; as demais notas saem com 102."),disabled:m})}}),r.jsx(N,{name:"pis_default",control:c,render:({field:a,fieldState:t})=>{var n;return r.jsx(_,{...a,select:!0,label:"CST PIS *",fullWidth:!0,error:!!t.error,helperText:((n=t.error)==null?void 0:n.message)||"",disabled:m,children:z.map(l=>r.jsx(j,{value:l.value,children:l.label},l.value))})}}),r.jsx(N,{name:"cofins_default",control:c,render:({field:a,fieldState:t})=>{var n;return r.jsx(_,{...a,select:!0,label:"CST COFINS *",fullWidth:!0,error:!!t.error,helperText:((n=t.error)==null?void 0:n.message)||"",disabled:m,children:z.map(l=>r.jsx(j,{value:l.value,children:l.label},l.value))})}})]}),r.jsx(ie,{open:M,blurOnSelect:!0,onOpen:()=>{A(!0),F("")},onClose:()=>A(!1),options:te,filterOptions:a=>a,getOptionLabel:a=>O(a),isOptionEqualToValue:(a,t)=>a.codigo===t.codigo,value:u,inputValue:X,onInputChange:ae,onChange:(a,t)=>{T(null),t?(S(t),v.onChange(t.codigo),x(O(t))):(S(null),v.onChange(null),x(""))},loading:W,loadingText:"Carregando...",noOptionsText:$.length<3?"Digite pelo menos 3 caracteres":"Nenhum NCM encontrado",disabled:m,renderInput:a=>r.jsx(_,{...a,label:"NCM padrao (opcional)",helperText:"Usado para produtos que nao possuem NCM cadastrado individualmente",InputProps:{...a.InputProps,endAdornment:r.jsxs(r.Fragment,{children:[W?r.jsx(K,{color:"inherit",size:20}):null,a.InputProps.endAdornment]})}}),renderOption:(a,t)=>d.createElement(E,{component:"li",...a,key:t.codigo},r.jsxs(U,{children:[r.jsx(P,{variant:"body2",fontWeight:600,children:w(t.codigo)}),r.jsx(P,{variant:"caption",color:"text.secondary",children:t.descricao})]}))}),g&&r.jsx(B,{severity:"error",onClose:()=>h(null),children:g}),r.jsx(ye,{type:"submit",variant:"contained",loading:m,disabled:!L,fullWidth:!0,children:L?"Salvar":"Salvo"})]})})},Re=()=>{const{data:e,isLoading:s,isError:o}=Te(),{data:i,isLoading:g}=he(),h=_e(i==null?void 0:i.formData.crt);if(s||g)return r.jsx(E,{sx:{height:"70vh",display:"flex",alignItems:"center",justifyContent:"center"},children:r.jsx(K,{})});const c=e?{cfop_interno:e.cfop_interno,cfop_interestadual:e.cfop_interestadual,csosn_default:e.csosn_default,aliquota_credito_simples:Oe(e.aliquota_credito_simples),pis_default:e.pis_default,cofins_default:e.cofins_default,ncm_default:e.ncm_default||null}:Ie;return r.jsxs(E,{p:2,children:[r.jsx(de,{title:"Padrões fiscais",navigateBack:!0}),o?r.jsx(B,{severity:"error",children:"Erro ao carregar dados. Por favor, tente novamente."}):r.jsx(qe,{defaultValues:c,regimeNormal:h,mei:(i==null?void 0:i.formData.crt)===4})]})};export{Re as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.