PageSourceSearch

https://growthtitan.ai/assets/ABCleanup-ChFSmT-l.js

js growthtitan.ai collected 2026-10-05 15:35:15 UTC 6,024 bytes, 1 lines download raw bytes

1import{u as S,r as n,R as _,j as e,T as u,C as F,c as D,B as E,L as v,d as w,b as p}from"./index-DbTt4sgL.js";import{C as m,a as x,b as C,c as T}from"./card-CEAQTVAa.js";import{d as $}from"./budgetVersioning-DnTsQcjr.js";console.log("✅ ABCleanup VERSION 6 LOADED - Duplicate Remover Added");function O(){const{currentClient:s}=S(),[h,j]=n.useState(!1),[R,k]=n.useState(!1),[o,f]=n.useState(""),[N,b]=n.useState(!1),[r,g]=n.useState(null),[c,y]=n.useState(null),A=async()=>{if(o==="DELETE"&&s!=null&&s.id){j(!0);try{await $(s.id),k(!0)}catch(a){console.error("Error deleting data:",a),alert("Error deleting data: "+a.message)}finally{j(!1),f("")}}},L=async()=>{if(s!=null&&s.id)try{const a=await p.entities.ExpenseBudgetMonthly.filter({client_company_id:s.id}),d=new Map;let l=0;a.forEach(t=>{const i=`${t.category_name}-${t.month}-${t.gl_account}`;d.has(i)?l++:d.set(i,t.id)}),y(l)}catch(a){console.error("Error checking duplicates:",a)}},B=async()=>{if(s!=null&&s.id){b(!0),g(null);try{const a=await p.entities.ExpenseBudgetMonthly.filter({client_company_id:s.id}),d=new Map,l=[];a.forEach(t=>{const i=`${t.category_name}-${t.month}-${t.gl_account}`;d.has(i)?l.push(t.id):d.set(i,t.id)}),console.log("Found",l.length,"duplicate expense records to delete");for(const t of l)await p.entities.ExpenseBudgetMonthly.delete(t);g({success:!0,deleted:l.length,remaining:a.length-l.length}),y(0)}catch(a){console.error("Error removing duplicates:",a),g({success:!1,error:a.message})}finally{b(!1)}}};return _.useEffect(()=>{s!=null&&s.id&&L()},[s==null?void 0:s.id]),s?e.jsx("div",{className:"p-6 bg-gray-50 min-h-screen",children:e.jsxs("div",{className:"max-w-2xl mx-auto space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(u,{className:"w-8 h-8 text-red-600"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Delete Budget Data"}),e.jsx("p",{className:"text-gray-500",children:"Remove all budget data for the selected client"})]})]}),e.jsxs(m,{className:c>0?"border-amber-500 border-2 bg-amber-50":"border-gray-200",children:[e.jsx(C,{children:e.jsxs(T,{className:"flex items-center gap-2",children:[e.jsx(F,{className:"w-5 h-5"}),"Remove Duplicate Expenses"]})}),e.jsxs(x,{className:"space-y-4",children:[c===null?e.jsx("p",{className:"text-gray-600",children:"Checking for duplicates..."}):c>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(D,{className:"w-6 h-6 text-amber-600 mt-1 flex-shrink-0"}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium text-amber-900",children:["Found ",c.toLocaleString()," duplicate expense records"]}),e.jsx("p",{className:"text-sm text-amber-700 mt-1",children:"These duplicates are inflating your P&L expenses. Click below to remove them safely."})]})]}),e.jsx(E,{onClick:B,disabled:N,className:"bg-amber-600 hover:bg-amber-700",children:N?e.jsxs(e.Fragment,{children:[e.jsx(v,{className:"w-4 h-4 mr-2 animate-spin"}),"Removing Duplicates..."]}):e.jsxs(e.Fragment,{children:[e.jsx(u,{className:"w-4 h-4 mr-2"}),"Remove ",c.toLocaleString()," Duplicates"]})})]}):e.jsxs("div",{className:"flex items-center gap-2 text-green-700",children:[e.jsx(w,{className:"w-5 h-5"}),e.jsx("span",{children:"No duplicate expense records found"})]}),r&&e.jsx("div",{className:`p-4 rounded-lg ${r.success?"bg-green-100":"bg-red-100"}`,children:r.success?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"font-medium text-green-800",children:["Successfully removed ",r.deleted.toLocaleString()," duplicate records"]}),e.jsxs("p",{className:"text-sm text-green-700",children:[r.remaining.toLocaleString()," unique expense records remain"]})]}):e.jsxs("p",{className:"text-red-800",children:["Error: ",r.error]})})]})]}),R?e.jsx(m,{className:"border-green-500 border-2 bg-green-50",children:e.jsx(x,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx(w,{className:"w-12 h-12 text-green-600 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-green-800",children:"All Data Deleted"}),e.jsxs("p",{className:"text-sm text-green-700 mt-2",children:["All budget data has been removed for ",s.company_name,"."]}),e.jsx("p",{className:"text-sm text-green-700 mt-1",children:"You can now upload a fresh budget file."})]})})}):e.jsxs(m,{className:"border-red-300 bg-red-50",children:[e.jsx(C,{children:e.jsx(T,{className:"text-red-900",children:"Delete All Budget Data"})}),e.jsxs(x,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(D,{className:"w-6 h-6 text-red-600 mt-1 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-red-900",children:s.company_name}),e.jsx("p",{className:"text-sm text-red-700 mt-1",children:"This will permanently delete all budget data including demand calls, scheduled calls, installations, marketing, labor, expenses, CAPEX, and training. This action cannot be undone."})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-red-900 mb-2",children:["Type ",e.jsx("strong",{children:"DELETE"})," to confirm:"]}),e.jsx("input",{type:"text",value:o,onChange:a=>f(a.target.value),className:"w-full px-3 py-2 border border-red-300 rounded-md focus:ring-2 focus:ring-red-500",placeholder:"DELETE",disabled:h})]}),e.jsx(E,{onClick:A,disabled:h||o!=="DELETE",className:`w-full ${o==="DELETE"?"bg-red-600 hover:bg-red-700":"bg-gray-300"}`,size:"lg",children:h?e.jsxs(e.Fragment,{children:[e.jsx(v,{className:"w-4 h-4 mr-2 animate-spin"}),"Deleting All Data..."]}):e.jsxs(e.Fragment,{children:[e.jsx(u,{className:"w-4 h-4 mr-2"}),"Delete All Budget Data"]})})]})]})]})}):e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Data Cleanup"}),e.jsx(m,{children:e.jsx(x,{className:"p-8 text-center",children:e.jsx("p",{className:"text-gray-600",children:"Please select a client from the dropdown above to proceed."})})})]})}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.