1import{T as C,r as u,U as b,j as e,L as _,I as c,F as A,B as F,s as o,f as m}from"./index-KSWbwNeY.js";import{u as T}from"./useMutation-eCaSwUD_.js";import{L as i}from"./label-ndOKmXJw.js";import{C as d,b as h,c as p,a as x}from"./card-CwL_ed79.js";import{A as y}from"./AdminNav-DsaLvjFx.js";import{S as w}from"./user-cog-DvqSS7bY.js";import{B as G}from"./building-2-BHBT7DvO.js";import{P as M}from"./percent-eJe4-D1A.js";import{S as P}from"./save-xjMYTeam.js";import"./index-DsYLezIw.js";import"./trash-2-CwcwS_bf.js";import"./book-open-DS7Nmuzn.js";import"./receipt-DgWJf9Ou.js";import"./chevron-down-D7IdZFzc.js";const O=()=>{const j=C(),[a,g]=u.useState({company_name:"",company_gstin:"",company_address:"",company_state:"Maharashtra",cgst_rate:9,sgst_rate:9,igst_rate:18,hsn_code:"998314",invoice_prefix:"AIM",invoice_sequence:0,is_active:!0}),{data:r,isLoading:N}=b({queryKey:["gst-settings"],queryFn:async()=>{const{data:s,error:t}=await o.from("gst_settings").select("*").eq("is_active",!0).single();if(t&&t.code!=="PGRST116")throw t;return s}});u.useEffect(()=>{r&&g(r)},[r]);const l=T({mutationFn:async s=>{if(r!=null&&r.id){const{error:t}=await o.from("gst_settings").update({company_name:s.company_name,company_gstin:s.company_gstin,company_address:s.company_address,company_
1state:s.company_state,cgst_rate:s.cgst_rate,sgst_rate:s.sgst_rate,igst_rate:s.igst_rate,hsn_code:s.hsn_code,invoice_prefix:s.invoice_prefix,updated_at:new Date().toISOString()}).eq("id",r.id);if(t)throw t}else{const{error:t}=await o.from("gst_settings").insert({company_name:s.company_name||"",company_gstin:s.company_gstin||"",company_address:s.company_address||"",company_state:s.company_state||"Maharashtra",cgst_rate:s.cgst_rate||9,sgst_rate:s.sgst_rate||9,igst_rate:s.igst_rate||18,hsn_code:s.hsn_code||"998314",invoice_prefix:s.invoice_prefix||"AIM",is_active:!0});if(t)throw t}},onSuccess:()=>{j.invalidateQueries({queryKey:["gst-settings"]}),m.success("GST settings saved successfully")},onError:s=>{console.error("Error saving GST settings:",s),m.error("Failed to save GST settings")}}),n=(s,t)=>{g(S=>({...S,[s]:t}))},v=s=>{if(s.preventDefault(),!a.company_name||!a.company_gstin||!a.company_address){m.error("Please fill in all required company details");return}if(!/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/.test(a.company_gstin||"")){m.error("Please enter a valid GSTIN format");return}l.mutate(a)},f=["Andhra Pradesh","Arunachal Pradesh","Assam","Bihar","Chhattisgarh","Goa","Gujarat","Haryana","Himachal Pradesh","Jharkhand","Karnataka","Kerala","Madhya Pradesh","Maharashtra","Manipur","Meghalaya","Mizoram","Nagaland","Odisha","Punjab","Rajasthan","Sikkim","Tamil Nadu","Telangana","Tripura","Uttar Pradesh","Uttarakhand","West Bengal","Andaman and Nicobar Islands","Chandigarh","Dadra and Nagar Haveli and Daman and Diu","Delhi","Jammu and Kashmir","Ladakh","Lakshadweep","Puducherry"];return N?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(y,{}),e.jsx("main",{className:"md:ml-52 p-6",children:e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx(_,{className:"h-8 w-8 animate-spin text-muted-foreground"})})})]}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(y,{}),e.jsx("main",{className:"md:ml-52 p-6",children:e.jsxs("div",{className:"max-w-3xl mx-auto space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-serif font-bold flex items-center gap-2",children:[e.jsx(w,{className:"h-6 w-6"}),"GST Settings"]}),e.jsx("p",{className:"text-muted-foreground text-sm mt-1",children:"Configure company GST details for invoice generation"})]}),e.jsxs("form",{onSubmit:v,className:"space-y-4",children:[e.jsxs(d,{children:[e.jsx(h,{className:"pb-3",children:e.jsxs(p,{className:"text-base flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"Company Details"]})}),e.jsxs(x,{className:"space-y-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(i,{htmlFor:"company_name",className:"text-xs",children:"Company Name *"}),e.jsx(c,{id:"company_name",value:a.company_name||"",onChange:s=>n("company_name",s.target.value),placeholder:"Your Company Name",className:"h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(i,{htmlFor:"company_gstin",className:"text-xs",children:"GSTIN *"}),e.jsx(c,{id:"company_gstin",value:a.company_gstin||"",onChange:s=>n("company_gstin",s.target.value.toUpperCase()),placeholder:"22AAAAA0000A1Z5",maxLength:15,className:"h-9 font-mono"})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"md:col-span-2 space-y-1.5",children:[e.jsx(i,{htmlFor:"company_address",className:"text-xs",children:"Registered Address *"}),e.jsx(c,{id:"company_address",value:a.company_address||"",onChange:s=>n("company_address",s.target.value),placeholder:"Full registered address",className:"h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(i,{htmlFor:"company_state",className:"text-xs",children:"State"}),e.jsx("select",{id:"company_state",value:a.company_state||"Maharashtra",onChange:s=>n("company_state",s.target.value),className:"w-full h-9 px-3 rounded-md border border-input bg-background text-sm",children:f.map(s=>e.jsx("option",{value:s,children:s},s))})]})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs(d,{children:[e.jsx(h,{className:"pb-3",children:e.jsxs(p,{className:"text-base flex items-center gap-2",children:[e.jsx(M,{className:"h-4 w-4"}),"Tax Rates"]})}),e.jsxs(x,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(i,{htmlFor:"cgst_rate",className:"text-xs",children:"CGST %"}),e.jsx(c,{id:"cgst_rate",type:"number",step:"0.01",min:"0",max:"50",value:a.cgst_rate||9,onChange:s=>n("cgst_rate",parseFloat(s.target.value)),className:"h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(i,{htmlFor:"sgst_rate",className:"text-xs",children:"SGST %"}),e.jsx(c,{id:"sgst_rate",type:"number",step:"0.01",min:"0",max:"50",value:a.sgst_rate||9,onChange:s=>n("sgst_rate",parseFloat(s.target.value)),className:"h-9"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(i,{htmlFor:"igst_rate",className:"text-xs",children:"IGST %"}),e.jsx(c,{id:"igst_rate",type:"number",step:"0.01",min:"0",max:"50",value:a.igst_rate||18,onCh
1ange:s=>n("igst_rate",parseFloat(s.target.value)),className:"h-9"})]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Standard: CGST 9% + SGST 9% (intra-state) or IGST 18% (inter-state)"})]})]}),e.jsxs(d,{children:[e.jsx(h,{className:"pb-3",children:e.jsxs(p,{className:"text-base flex items-center gap-2",children:[e.jsx(A,{className:"h-4 w-4"}),"Invoice Settings"]})}),e.jsxs(x,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(i,{htmlFor:"invoice_prefix",className:"text-xs",children:"Prefix"}),e.jsx(c,{id:"invoice_prefix",value:a.invoice_prefix||"AIM",onChange:s=>n("invoice_prefix",s.target.value.toUpperCase()),placeholder:"AIM",maxLength:10,className:"h-9 font-mono"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(i,{htmlFor:"hsn_code",className:"text-xs",children:"HSN/SAC Code"}),e.jsx(c,{id:"hsn_code",value:a.hsn_code||"998314",onChange:s=>n("hsn_code",s.target.value),placeholder:"998314",className:"h-9 font-mono"})]})]}),(r==null?void 0:r.invoice_sequence)!==void 0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Next: ",e.jsxs("span",{className:"font-mono",children:[a.invoice_prefix,"-",new Date().getFullYear(),"-",String(r.invoice_sequence+1).padStart(6,"0")]})]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-2",children:e.jsx(F,{type:"submit",disabled:l.isPending,children:l.isPending?e.jsxs(e.Fragment,{children:[e.jsx(_,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"h-4 w-4 mr-2"}),"Save Settings"]})})})]})]})})]})};export{O 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.