PageSourceSearch

https://liefersoft.de/assets/CustomerList-BzCSagRk.js

js liefersoft.de collected 2026-09-24 12:02:48 UTC 30,197 bytes, 4 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/useFetchAll-4P6wT-eM.js","assets/index-C3wyiG4j.js","assets/index-DrVYBQMv.css"])))=>i.map(i=>d[i]);
2import{r as l,s as _,g as w,j as e,_ as Nt,a0 as kt,a1 as yt,a2 as St,br as we,bD as Ct,m as At,G as p,bn as Dt,U as Ne,b9 as Pt,bv as Lt,B as v,x as Ve,aJ as Ue,k as V,Y as He,eF as Mt,bk as zt,c6 as Et,c7 as Tt,b7 as Kt,a as Bt,V as Ft,D as It,R as Ot,bL as $t,O as Rt,z as Vt,n as Ut,ad as fe,af as be,ag as je,ah as _e,aj as h,eG as Ge,bJ as Ht,o as We,eH as ve,C as Gt,cg as Wt,eI as qt}from"./index-C3wyiG4j.js";import{L as qe}from"./LeadOriginBadges-0qqVEYFj.js";import{a as Qt,b as Zt,c as Qe,T as R,d as Yt,e as A}from"./table-D4S2VUHx.js";import{C as Jt}from"./CustomerPortalInvite-COrjVw1D.js";import{u as Xt,S as X}from"./SortableTableHead-28Zwh3_Q.js";import{B as es}from"./BulkActionBar-CJqMCtN5.js";import{R as ts,a as ss}from"./radio-group-DtgVu0-I.js";import{S as rs}from"./StickyScrollContainer-ADxfrRPM.js";import{F as Je,a as Xe}from"./quote-funnel-constants-Dc9Kbq6o.js";import{C as as}from"./ContactListImportDialog-CIgODIyZ.js";import{U as ns}from"./upload-wX_mCwNB.js";import{s as is}from"./format-CRNufvVK.js";import{s as ls}from"./startOfMonth-uoIDQ344.js";import"./cloud-D_uO3Cj5.js";import"./formatDistanceToNowStrict-zC-MVuoF.js";import"./differenceInHours-Dk_ctTKQ.js";import"./differenceInDays-c3dYH8lX.js";import"./link-JFXkS2GO.js";import"./arrow-down--Nu6kko0.js";import"./arrow-up-down-B-mbQ8eK.js";import"./types-BGNHEvJc.js";import"./list-todo-Bc2HWz7J.js";import"./lock-open-Df9H6I8p.js";import"./tabs-BpFB6M4d.js";import"./file-spreadsheet-DE9BD4Wb.js";function os({open:c,onClose:k,customerIds:N,onMerged:r}){const[x,D]=l.useState([]),[n,P]=l.useState(""),[U,K]=l.useState(!1),[y,G]=l.useState(!1);l.useEffect(()=>{!c||N.length===0||(G(!0),_.from("customers").select("id, full_name, company, email, customer_number, vertriebsnummer, city, zip_code").in("id",N).then(({data:i,error:b})=>{b&&w.error(b.message);const B=i||[];D(B),B[0]&&P(B[0].id),G(!1)}))},[c,N]);const ee=l.useMemo(()=>[...x.filter(i=>i.id===n),...x.filter(i=>i.id!==n)],[x,n]),ie=async()=>{if(!n||x.length<2)return;const i=x.filter(W=>W.id!==n).map(W=>W.id);K(!0);const{data:b,error:B}=await _.rpc("merge_customers",{_master_id:n,_loser_ids:i});if(K(!1),B){w.error("Fehler beim Zusammenführen: "+B.message);return}const H=(b==null?void 0:b.merged)??i.length;w.success(`${H} Dublette(n) auf Master gemappt`),r(),k()},te=i=>i.company||i.full_name||i.email||i.customer_number||i.id.slice(0,8);return e.jsx(Nt,{open:c,onOpenChange:i=>!i&&!U&&k(),children:e.jsxs(kt,{className:"max-w-2xl",children:[e.jsxs(yt,{children:[e.jsxs(St,{className:"flex items-center gap-2",children:[e.jsx(we,{className:"h-5 w-5"})," Kunden zusammenführen"]}),e.jsx(Ct,{children:"Wähle den Master-Kunden. Alle anderen werden in den Papierkorb verschoben und ihre Angebote, Verträge, Deals, Aufträge, Aktivitäten, Kontakte usw. auf den Master übertragen."})]}),y?e.jsx("div",{className:"text-sm text-muted-foreground py-6 text-center",children:"Lade…"}):e.jsx("div",{className:"space-y-3 max-h-[50vh] overflow-y-auto",children:e.jsx(ts,{value:n,onValueChange:P,children:ee.map(i=>e.jsxs("div",{className:`flex items-start gap-3 p-3 border rounded-lg ${i.id===n?"border-primary bg-primary/5":""}`,children:[e.jsx(ss,{value:i.id,id:`merge-${i.id}`,className:"mt-1"}),e.jsxs(At,{htmlFor:`merge-${i.id}`,className:"flex-1 cursor-pointer space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[i.id===n?e.jsxs(p,{className:"gap-1",children:[e.jsx(Dt,{className:"h-3 w-3"})," Master (bleibt)"]}):e.jsxs(p,{variant:"outline",className:"gap-1 text-muted-foreground",children:[e.jsx(Ne,{className:"h-3 w-3"})," wird zusammengeführt"]}),e.jsx("span",{className:"font-semibold",children:te(i)})]}),e.jsxs("div",{className:"text-xs text-muted-foreground font-mono",children:[i.customer_number||"ohne KdNr",i.vertriebsnummer&&` • VNR ${i.vertriebsnummer}`,i.email&&` • ${i.email}`]}),(i.zip_code||i.city)&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:[i.zip_code," ",i.city]})]})]},i.id))})}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1 border-t pt-3",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(we,{className:"h-3 w-3 mt-0.5 shrink-0"}),"Leere Stammdaten-Felder im Master (Adresse, Telefon, Bank, Steuernummer …) werden aus den Dubletten ergänzt."]}
2),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(Pt,{className:"h-3 w-3 mt-0.5 shrink-0 text-amber-600"}),"Die Dubletten landen im Papierkorb (Grund: ",e.jsx("code",{children:"merge_into:<Master-ID>"}),") und können bei Bedarf wiederhergestellt werden."]})]}),e.jsxs(Lt,{children:[e.jsx(v,{variant:"outline",onClick:k,disabled:U,children:"Abbrechen"}),e.jsx(v,{onClick:ie,disabled:U||x.length<2||!n,children:U?"Wird zusammengeführt…":`${Math.max(x.length-1,0)} Dublette(n) auf Master mappen`})]})]})})}const ds=["draft","sent","rejected","accepted","won"],cs=["kunde_aktiv","upselling_aktiv","risiko_kuendigung"];function us({counts:c,active:k,onChange:N}){const r=x=>{const D=c[x]??0,n=k===x;return e.jsxs("button",{type:"button",onClick:()=>N(n?"all":x),className:Ue("group relative flex flex-col items-start rounded-lg border px-3 py-2 text-left transition-all min-w-[120px]",Je[x],n?"ring-2 ring-primary ring-offset-1 ring-offset-background shadow-md scale-[1.02]":"hover:shadow-sm hover:scale-[1.01] opacity-90 hover:opacity-100"),"aria-pressed":n,children:[e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-wide opacity-80",children:Xe[x]}),e.jsx("span",{className:"text-xl font-bold leading-tight",children:D})]},x)};return e.jsxs("div",{className:"space-y-2 mb-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:["Angebots-Pipeline",e.jsx(Ve,{className:"h-3 w-3"}),e.jsx("span",{children:"Won"}),e.jsx(Ve,{className:"h-3 w-3"}),e.jsx("span",{children:"Post-QA"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>N("all"),className:Ue("text-xs font-medium px-2 py-1 rounded-md transition-colors",k==="all"?"bg-primary/10 text-primary":"text-muted-foreground hover:bg-muted"),children:["Alle (",c.total,")"]}),e.jsxs(V,{to:"/dashboard/risk-cockpit",className:"text-xs font-medium text-primary hover:underline inline-flex items-center gap-1",title:"Risiko-Cockpit für Kündigungen & Re-Assignments",children:["Risiko-Cockpit ",e.jsx(He,{className:"h-3 w-3"})]}),e.jsxs(V,{to:"/dashboard/kundenstrasse",className:"text-xs font-medium text-primary hover:underline inline-flex items-center gap-1",title:"Vollständige Kundenstraße (Trello-Board)",children:["Kundenstraße ",e.jsx(He,{className:"h-3 w-3"})]})]})]}),e.jsxs("div",{className:"flex items-stretch gap-2 overflow-x-auto pb-1",children:[ds.map(r),e.jsx("div",{className:"w-px bg-border mx-1","aria-hidden":!0}),cs.map(r)]})]})}const Ze={neu:"bg-amber-100 text-amber-800",kontaktiert:"bg-blue-100 text-blue-800",termin:"bg-indigo-100 text-indigo-800",persoenlicher_termin:"bg-indigo-100 text-indigo-800",angebot_gesendet:"bg-purple-100 text-purple-800",angenommen:"bg-green-100 text-green-800",abgelehnt:"bg-red-100 text-red-800",abgeschlossen:"bg-gray-100 text-gray-800",live:"bg-emerald-100 text-emerald-800",gekuendigt:"bg-orange-100 text-orange-800",wiedergewonnen:"bg-teal-100 text-teal-800",betriebsaufgabe:"bg-stone-200 text-stone-800"};function Ye(c,k){const N=(k||"").trim().toLowerCase();if(!N)return!0;const r=N.replace(/\D+/g,"");return!!([c.full_name,c.first_name,c.last_name,c.company,c.email,c.vertriebsnummer,c.customer_number,c.zip_code,c.city,c.street,c.legal_company_name,c.vat_id,c.tax_id].filter(Boolean).map(n=>String(n).toLowerCase()).join(" ").includes(N)||r.length>=3&&[c.phone,c.mobile].filter(Boolean).map(P=>String(P).replace(/\D+/g,"")).join(" ").includes(r))}const ms={restaurant:"Restaurant",lieferdienst:"Lieferdienst",cafe:"Café",baeckerei:"Bäckerei",imbiss:"Imbiss",bar:"Bar",hotel:"Hotel",catering:"Catering",foodtruck:"Foodtruck",kantine:"Kantine",metzgerei:"Metzgerei",eisdiele:"Eisdiele"},Fs=()=>{const{isViewAs:c}=Mt(),{isAdmin:k,isHeadOfSales:N,user:r}=zt(),{permissions:x}=Et(),D=Tt(),{t:n}=Kt(),[P,U]=Bt(),K=P.get("source")||"",y=P.get("period")||"",G=P.get("assigned_to")||"",ee=P.get("external_partner_id")||P.get("external_partner")||"",ie=x.can_export,te=k||x.can_delete,i=k||N,[b,B]=l.useState([]),[H,W]=l.useState(""),[ke,et]=l.useState(!0),[L,se]=l.useState("alle"),[ye,tt]=l.useState([]),[le,Se]=l.useState(null),[st,Ce]=l.useState(!1),[F,rt]=l.useState({}),[at,nt]=l.useState({}),[it,lt]=l.useState([]),[z,I]=l.useState(new Set),[Ae,ot]=l.useState([]),[g,De]=l.useState("all"),[O,dt]=l.useState("all"),[q,ct]=l.useState("all"),[oe,ut]=l.useState("all"),[de,Pe]=l.useState({}),[re,Le]=l.useState({}),[ce,mt]=l.useState("all"),[xt,Me]=l.useState(!1);l.useEffect(()=>{G&&De(G),ee&&ct(ee)},[]);const{sortKey:Q,sortDir:Z,toggleSort:Y,sortFn:ze}=Xt("created_at","desc"),ue=t=>t.assigned_to===(r==null?void 0:r.id),me=t=>t.deputy_id===(r==null?void 0:r.id),J=ye.map(t=>t.customer_id),xe={neu:n("statusNeu"),kontaktiert:n("statusKontaktiert"),angebot_gesendet:n("statusAngebotGesendet"),angenommen:n("statusAngenommen"),abgelehnt:n("statusAbgelehnt"),abgeschlossen:n("statusAbgeschlossen"),persoenlicher_termin:n("statusPersoenlicherTermin"),live:n("statusLive"),gekuendigt:n("statusGekuendigt"),wiedergewonnen:n("statusWiedergewonnen"),betriebsaufgabe:n("statusBetriebsaufgabe")},E=async()=>{const{fetchAll:t}=await Wt(async()=>{const{fetchAll:u}=await import("./useFetchAll-4P6wT-eM.js");return{fetchAll:u}},__vite__mapDeps([0,1,2])),[a,s,o,j]=await Promise.all([t((u,S)=>qt().select("*").order("created_at",{ascending:!1}).range(u,S)),t((u,S)=>_.from("customer_accounts").select("id, customer_id, portal_status, user_id").in("portal_status",["pen
2ding","restricted"]).range(u,S)),t((u,S)=>_.from("user_roles").select("user_id, role").neq("role","customer").range(u,S)),t((u,S)=>_.from("external_partners").select("id, first_name, last_name, vertriebsnummer, company").range(u,S))]),f=s,$=o,he=j,ae=[...new Set(($||[]).map(u=>u.user_id))];let ge=[];if(ae.length>0){const{data:u}=await _.from("profiles").select("user_id, full_name, vertriebsnummer").in("user_id",ae);ge=u||[]}B(a||[]),tt(f||[]),lt(he||[]),ot(ge);const Fe=(a||[]).map(u=>u.id);if(Fe.length>0){const{data:u}=await _.from("quotes").select("customer_id, status, sent_at, created_at, won_at, accepted_at, rejected_at").in("customer_id",Fe),S={},ne={},wt=d=>{if(!d)return"draft";const m=d.toLowerCase();return m==="angenommen"?"accepted":m==="abgelehnt"?"rejected":m==="entwurf"?"draft":m==="gesendet"?"sent":m};(u||[]).forEach(d=>{if(!d.customer_id)return;const m=S[d.customer_id]||{count:0,latest_status:null};m.count+=1,S[d.customer_id]=m;const M=wt(d.status),$e=d.created_at,Re=ne[d.customer_id];(!Re||new Date($e)>new Date(Re.created_at))&&(ne[d.customer_id]={status:M,created_at:$e})});const C={};(a||[]).forEach(d=>{const m=d.pipeline_stage||"";if(m==="risiko_kuendigung"){C[d.id]="risiko_kuendigung";return}if(m==="upselling_aktiv"){C[d.id]="upselling_aktiv";return}if(m==="kunde_aktiv"){C[d.id]="kunde_aktiv";return}if(m==="aktiv"||m==="gewonnen"||m==="support"){C[d.id]="kunde_aktiv";return}if(m==="verloren"){C[d.id]="rejected";return}const M=ne[d.id];if(!M){C[d.id]="no_quote";return}if(M.status==="won"){C[d.id]="won";return}if(M.status==="accepted"){C[d.id]="accepted";return}if(M.status==="rejected"){C[d.id]="rejected";return}if(M.status==="sent"||M.status==="viewed"){C[d.id]="sent";return}C[d.id]="draft"}),Object.entries(ne).forEach(([d,m])=>{const M=S[d];M&&(M.latest_status=["sent","accepted","won","viewed"].includes(m.status)?"sent":m.status)}),Pe(S),Le(C)}else Pe({}),Le({});const Ie={},Oe={};ge.forEach(u=>{Ie[u.user_id]=u.full_name,u.vertriebsnummer&&(Oe[u.user_id]=u.vertriebsnummer)}),rt(Ie),nt(Oe),et(!1)},pe=t=>{if(t.external_partner_id){const a=it.find(s=>
2s.id===t.external_partner_id);if(a)return{name:`${a.first_name} ${a.last_name}`,vnr:a.vertriebsnummer}}return t.vertriebsnummer?{name:null,vnr:t.vertriebsnummer}:null};l.useEffect(()=>{E();const t=_.channel("customers-changes").on("postgres_changes",{event:"*",schema:"public",table:"customers"},()=>{E()}).subscribe();return()=>{_.removeChannel(t)}},[]);const pt=async(t,a)=>{if(a.preventDefault(),a.stopPropagation(),!r||le)return;const s=ye.find(j=>j.customer_id===t);if(!s)return;Se(t);const{error:o}=await _.from("customer_accounts").update({portal_status:"active",activated_at:new Date().toISOString(),activated_by:r.id}).eq("id",s.id);o?w.error("Fehler: "+o.message):(w.success("Kunde wurde für das Portal freigeschaltet!"),await E()),Se(null)},ht=async(t,a)=>{if(a.preventDefault(),a.stopPropagation(),!te){w.error("Keine Berechtigung zum Löschen");return}if(!confirm("Kunde in den Papierkorb verschieben?"))return;const{error:s}=await _.from("customers").update({deleted_at:new Date().toISOString(),deleted_reason:"manual",deleted_by:(r==null?void 0:r.id)||null}).eq("id",t);
2s?w.error("Fehler: "+s.message):(w.success("Kunde in Papierkorb verschoben"),E())},gt=async()=>{const t=Array.from(z);if(!confirm(`${t.length} Kunden in den Papierkorb verschieben?`))return;const{error:a}=await _.from("customers").update({deleted_at:new Date().toISOString(),deleted_reason:"bulk",deleted_by:(r==null?void 0:r.id)||null}).in("id",t);a?w.error("Fehler: "+a.message):(w.success(`${t.length} Kunden in Papierkorb verschoben`),I(new Set),E())},ft=async t=>{const a=Array.from(z),{error:s}=await _.from("customers").update({status:t}).in("id",a);s?w.error(s.message):(w.success(`${a.length} Kunden-Status aktualisiert`),I(new Set),E())},bt=async t=>{const a=Array.from(z),{error:s}=await _.from("customers").update({assigned_to:t}).in("id",a);s?w.error(s.message):(w.success(`${a.length} Kunden zugewiesen`),I(new Set),E())},Ee=l.useMemo(()=>y==="today"?new Date(new Date().setHours(0,0,0,0)):y==="week"?is(new Date):y==="month"||y==="current"?ls(new Date):null,[y]),Te=b.filter(t=>{if(!Ye(t,H))return!1;if(L==="portal_wartend")return J.includes(t.id);if(L==="meine")return ue(t);if(L==="vertretung")return me(t);if(g==="mine"&&t.assigned_to!==(r==null?void 0:r.id)||g==="unassigned"&&t.assigned_to||g!=="all"&&g!=="unassigned"&&g!=="mine"&&t.assigned_to!==g||q!=="all"&&t.external_partner_id!==q||oe==="with"&&!de[t.id]||oe==="without"&&de[t.id]||ce!=="all"&&(re[t.id]||"no_quote")!==ce)return!1;if(O!=="all"){const a=(t.country||"DE").toUpperCase(),s=(t.zip_code||"").toString();if(O!==a&&!(O==="DE"&&/^\d{5}$/.test(s)&&!t.country))return!1}return!(K==="lead_conversion"&&t.source!=="lead_conversion"||K==="direct"&&(t.source==="lead_conversion"||t.source==="demo_anfrage")||Ee&&new Date(t.created_at)<Ee)}),T=l.useMemo(()=>{const t=r==null?void 0:r.id;return[...Te].sort((a,s)=>{if(t&&g!=="unassigned"){const o=a.assigned_to===t?0:1,j=s.assigned_to===t?0:1;if(o!==j)return o-j}return ze(a,s)})},[Te,ze,r==null?void 0:r.id,g]),Ke=b.filter(t=>J.includes(t.id)).length,jt=l.useMemo(()=>{const t=b.filter(s=>{if(!Ye(s,H))return!1;if(L==="portal_wartend")return J.includes(s.id);if(L==="meine")return ue(s);if(L==="vertretung")return me(s);if(g==="mine"&&s.assigned_to!==(r==null?void 0:r.id)||g==="unassigned"&&s.assigned_to||g!=="all"&&g!=="unassigned"&&g!=="mine"&&s.assigned_to!==g||q!=="all"&&s.external_partner_id!==q)return!1;if(O!=="all"){const o=(s.country||"DE").toUpperCase(),j=(s.zip_code||"").toString();if(O!==o&&!(O==="DE"&&/^\d{5}$/.test(j)&&!s.country))return!1}return!0}),a={no_quote:0,draft:0,sent:0,rejected:0,accepted:0,won:0,kunde_aktiv:0,upselling_aktiv:0,risiko_kuendigung:0,total:t.length};return t.forEach(s=>{const o=re[s.id]||"no_quote";a[o]=(a[o]||0)+1}),a},[b,re,H,L,g,q,O,r==null?void 0:r.id,J]),_t=()=>{const t=`${n("name")},${n("company")},${n("email")},${n("phone")},${n("status")},Ansprechpartner,Vertreter,VNR,Owner-Typ,${n("created")}
3`,a=T.map(f=>{const $=pe(f),he=($==null?void 0:$.vnr)||f.vertriebsnummer||at[f.assigned_to]||"";return[f.full_name,f.company,f.email,f.phone||"",f.status,F[f.assigned_to]||"",F[f.deputy_id]||"",he,f.owner_type||"intern",new Date(f.created_at).toLocaleDateString("de-DE")].map(ae=>`"${(ae||"").replace(/"/g,'""')}"`).join(",")}).join(`
4`),s=new Blob([t+a],{type:"text/csv;charset=utf-8;"}),o=URL.createObjectURL(s),j=document.createElement("a");j.href=o,j.download=`kunden_export_${new Date().toISOString().split("T")[0]}.csv`,j.click(),URL.revokeObjectURL(o)},Be=k||N,vt=t=>!t||t.length===0?null:e.jsxs("div",{className:"flex flex-wrap gap-0.5 mt-0.5",children:[t.slice(0,3).map(a=>e.jsx(p,{variant:"outline",className:"text-[9px] px-1 py-0 h-4",children:ms[a]||a},a)),t.length>3&&e.jsxs(p,{variant:"outline",className:"text-[9px] px-1 py-0 h-4",children:["+",t.length-3]})]});return e.jsxs("div",{className:"min-w-0 w-full",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4",children:[e.jsx(Ft,{}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:n("customersTitle")}),e.jsxs("div",{className:"flex gap-2",children:[ie&&e.jsxs(v,{variant:"outline",size:D?"sm":"default",onClick:_t,children:[e.jsx(It,{className:"h-4 w-4 mr-1.5"})," ",n("export")]}),i&&e.jsxs(v,{variant:"outline",size:D?"sm":"default",onClick:()=>Ce(!0),children:[e.jsx(ns,{className:"h-4 w-4 mr-1.5"})," Liste importieren"]}),e.jsx(v,{variant:"outline",size:D?"sm":"default",asChild:!0,children:e.jsxs(V,{to:"/dashboard/customers/trash",children:[e.jsx(Ne,{className:"h-4 w-4 mr-1.5"})," Papierkorb"]})}),e.jsx(v,{variant:"outline",size:D?"sm":"default",asChild:!0,title:"Dubletten finden und zusammenführen",children:e.jsxs(V,{to:"/dashboard/duplicates",children:[e.jsx(we,{className:"h-4 w-4 mr-1.5"})," Dubletten"]})}),!c&&e.jsx(v,{asChild:!0,size:D?"sm":"default",children:e.jsxs(V,{to:"/dashboard/leads?new=1",title:"Neue Kunden entstehen aus Lead-Konvertierung",children:[e.jsx(Ot,{className:"h-4 w-4 mr-1.5"})," Neuer Lead"]})})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 mb-4",children:[e.jsx(v,{size:"sm",variant:L==="alle"?"default":"outline",onClick:()=>se("alle"),children:"Alle Kunden"}),e.jsxs(v,{size:"sm",variant:L==="meine"?"default":"outline",onClick:()=>se("meine"),className:"gap-1.5",children:["Meine Kunden",e.jsx(p,{variant:"secondary",className:"ml-1 text-[10px]",children:b.filter(t=>ue(t)).length})]}),e.jsxs(v,{size:"sm",variant:L==="vertretung"?"default":"outline",onClick:()=>se("vertretung"),className:"gap-1.5",children:[e.jsx($t,{className:"h-3.5 w-3.5"})," Vertretung",e.jsx(p,{variant:"secondary",className:"ml-1 text-[10px]",children:b.filter(t=>me(t)).length})]}),Be&&Ke>0&&e.jsxs(v,{size:"sm",variant:L==="portal_wartend"?"default":"outline",onClick:()=>se("portal_wartend"),className:"gap-1.5",children:[e.jsx(Rt,{className:"h-3.5 w-3.5"})," Portal wartend",e.jsx(p,{variant:"secondary",className:"ml-1 text-[10px]",children:Ke})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 mb-4",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Vt,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(Ut,{placeholder:n("searchCustomers"),value:H,onChange:t=>W(t.target.value),className:"pl-10"})]}),e.jsxs(fe,{value:g,onValueChange:De,children:[e.jsx(be,{className:"w-[180px]",children:e.jsx(je,{placeholder:"Benutzer"})}),e.jsxs(_e,{children:[e.jsx(h,{value:"all",children:"Alle Benutzer"}),e.jsx(h,{value:"mine",children:"Meine Kunden"}),e.jsx(h,{value:"unassigned",children:"Nicht zugewiesen"}),Ae.map(t=>e.jsx(h,{value:t.user_id,children:t.full_name},t.user_id))]})]}),e.jsxs(fe,{value:O,onValueChange:dt,children:[e.jsx(be,{className:"w-[140px]",children:e.jsx(je,{placeholder:"Land"})}),e.jsxs(_e,{children:[e.jsx(h,{value:"all",children:"Alle Länder"}),e.jsx(h,{value:"DE",children:"🇩🇪 Deutschland"}),e.jsx(h,{value:"AT",children:"🇦🇹 Österreich"}),e.jsx(h,{value:"CH",children:"🇨🇭 Schweiz"}),e.jsx(h,{value:"NL",children:"🇳🇱 Niederlande"}),e.jsx(h,{value:"FR",children:"🇫🇷 Frankreich"}),e.jsx(h,{value:"IT",children:"🇮🇹 Italien"}),e.jsx(h,{value:"ES",children:"🇪🇸 Spanien"}),e.jsx(h,{value:"PL",children:"🇵🇱 Polen"}),e.jsx(h,{value:"OTHER",children:"Andere"})]})]}),e.jsxs(fe,{value:oe,onValueChange:t=>ut(t),children:[e.jsx(be,{className:"w-[160px]",children:e.jsx(je,{placeholder:"Angebot"})}),e.jsxs(_e,{children:[e.jsx(h,{value:"all",children:"Alle (Angebot)"}),e.jsx(h,{value:"with",children:"Mit Angebot"}),e.jsx(h,{value:"without",children:"Ohne Angebot"})]})]})]}),(K||y)&&e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-primary/30 bg-primary/5 px-3 py-2 text-sm mb-3",children:[e.jsxs("span",{children:["Aktiver Filter:"," ",e.jsxs("strong",{children:[K==="lead_conversion"&&"Aus Leads konvert
4iert",K==="direct"&&"Direktkunden",y==="today"&&" · Heute",y==="week"&&" · Diese Woche",(y==="month"||y==="current")&&" · Dieser Monat"]})]}),e.jsx(v,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>{const t=new URLSearchParams(P);t.delete("source"),t.delete("period"),U(t)},children:"Zurücksetzen"})]}),e.jsx(us,{counts:jt,active:ce,onChange:mt}),!ke&&T.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mb-2",children:[T.length," von ",b.length," Kunden"]}),ke?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:n("loading")}):T.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:b.length===0?n("noCustomersYet"):n("noResults")}):D?e.jsx("div",{className:"space-y-3",children:T.map(t=>{const a=pe(t);return e.jsxs(V,{to:`/dashboard/customers/${t.id}`,className:"block bg-card rounded-xl border p-4 active:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 mb-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-semibold text-foreground text-sm truncate",children:Ge(t)}),e.jsxs("p",{className:"text-xs text-muted-foreground truncate",children:[t.company," ",t.customer_number&&e.jsxs("span",{className:"font-mono",children:["· ",t.customer_number]})]}),vt(t.business_type)]}),e.jsx(p,{variant:"secondary",className:`text-[10px] shrink-0 ${Ze[t.status]||""}`,children:xe[t.status]||t.status})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-1.5 truncate",children:[e.jsx("span",{className:"truncate",children:F[t.assigned_to]||"–"}),a&&e.jsxs("span",{className:"font-mono text-[10px]",children:["VNR ",a.vnr]}),t.deputy_id===(r==null?void 0:r.id)&&e.jsx(p,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 bg-purple-50 text-purple-700 border-purple-300 dark:bg-purple-900/30 dark:text-purple-300",children:"Vertretung"}),t.assigned_to===(r==null?void 0:r.id)&&e.jsx(p,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 bg-blue-50 text-blue-700 border-blue-300 dark:bg-blue-900/30 dark:text-blue-300",children:"Mein Kunde"}),t.has_whatsapp&&e.jsx(Ht,{className:"h-3 w-3 text-green-500 shrink-0"})]}),e.jsx("div",{className:"shrink-0 ml-2",children:e.jsx(qe,{lsCreatedAt:t.created_at,zohoCreatedAt:t.zoho_created_time,compact:!0})})]}),F[t.created_by]&&e.jsxs("div",{className:"text-[10px] text-muted-foreground mt-1",children:["Erstkontakt: ",F[t.created_by]]})]},t.id)})}):e.jsxs(e.Fragment,{children:[e.jsx(rs,{className:"bg-card rounded-xl border",maxHeight:"calc(100vh - 280px)",children:e.jsxs(Qt,{children:[e.jsx(Zt,{className:"sticky top-[14px] z-20 bg-card shadow-[0_1px_0_0_hsl(var(--border))] [&_th]:bg-card",children:e.jsxs(Qe,{className:"hover:bg-card",children:[e.jsx(R,{className:"w-10",children:e.jsx(We,{checked:T.length>0&&z.size===T.length,onCheckedChange:t=>{I(t?new Set(T.map(a=>a.id)):new Set)}})}),e.jsx(R,{className:"whitespace-nowrap",children:"Kd-Nr."}),e.jsx(R,{className:"whitespace-nowrap",children:"VNR"}),e.jsx(X,{label:n("status"),sortKey:"status",currentSort:Q,currentDir:Z,onSort:Y}),e.jsx(X,{label:"Pipeline",sortKey:"pipeline_status",currentSort:Q,currentDir:Z,onSort:Y}),e.jsx(R,{className:"whitespace-nowrap",children:"Angebot"}),e.jsx(X,{label:n("company"),sortKey:"company",currentSort:Q,currentDir:Z,onSort:Y}),e.jsx(X,{label:"Eingang Zoho · LS",sortKey:"created_at",currentSort:Q,currentDir:Z,onSort:Y,className:"whitespace-nowrap"}),e.jsx(R,{className:"whitespace-nowrap",children:"Telefon"}),e.jsx(X,{label:"Kundenbetreuer",sortKey:"assigned_to",currentSort:Q,currentDir:Z,onSort:Y}),e.jsx(R,{children:"Portal"}),e.jsx(R,{children:"Aktionen"})]})}),e.jsx(Yt,{children:T.map(t=>{const a=pe(t);return e.jsxs(Qe,{className:"cursor-pointer hover:bg-muted/30",onClick:()=>window.location.href=`/dashboard/customers/${t.id}`,children:[e.jsx(A,{onClick:s=>s.stopPropagation(),children:e.jsx(We,{checked:z.has(t.id),onCheckedChange:s=>{const o=new Set(z);s?o.add(t.id):o.delete(t.id),I(o)}})}),e.jsx(A,{className:"whitespace-nowrap",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-mono text-muted-foreground",children:t.customer_number||"–"}),t.customer_number&&e.jsx(p,{variant:"outline",className:`text-[9px] px-1 py-0 h-4 ${t.customer_number.startsWith("KD-")?"bg-blue-50 text-blue-700 border-blue-300 dark:bg-blue-900/30 dark:text-blue-300 dark:border-blue-700":"bg-amber-50 text-amber-700 border-amber-300 dark:bg-amber-900/30 dark:text-amber-300 dark:border-amber-700"}`,children:t.customer_number.startsWith("KD-")?"System":"Zoho"})]})}),e.jsx(A,{className:"whitespace-nowrap",children:a?e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(p,{variant:t.owner_type==="partner"?"default":"secondary",className:"text-[9px] px-1.5 py-0 h-4",children:t.owner_type==="partner"?"Partner":"Intern"}),e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground",children:a.vnr})]}):t.vertriebsnummer?e.jsx("span",{className:"text-[10px] font-mono text-muted-foreground",children:t.vertriebsnummer}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"–"})}),e.jsx(A,{children:e.jsx(p,{variant:"secondary",className:Ze[t.status]||"",children:xe[t.status]||t.status})}),e.jsx(A,{children:t.pipeline_status?e.jsx(p,{variant:"outline",className:"text-[10px] capitalize",children:t.pipeline_status.replace(/_/g," ")}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"–"})}),e.jsx(A,{className:"whitespace-nowrap",children:(()=>{const s=re[t.id]||"no_quote",o=de[t.id],j=(o==null?void 0:o.count)||0,f=Je[s],$=Xe[s];return e.jsxs(p,{variant:"outline",className:`text-[10px] ${f}`,children:[$,j>0?` (${j})`:""]})})()}),e.jsxs(A,{className:"text-foreground max-w-[180px] truncate",children:[e.jsx(V,{to:`/dashboard/customers/${t.id}`,className:"text-primary hover:underline font-medium block truncate",onClick:s=>s.stopPropagation(),children:t.company||"–"}),ve(t)&&e.jsx("span",{title:ve(t),className:"text-[11px] text-muted-foreground truncate block",children:ve(t)})]}),e.jsx(A,{className:"whitespace-nowrap",children:e.jsx(qe,{lsCreatedAt:t.created_at,zohoCreatedAt:t.zoho_created_time,compact:!0})}),e.jsx(A,{className:"text-muted-foreground text-xs whitespace-nowrap font-mono",children:t.phone?e.jsx("a",{href:`tel:${t.phone}`,className:"hover:underline",onClick:s=>s.stopPropagation(),children:t.phone}):"–"}),e.jsx(A,{className:"whitespace-nowrap",onClick:s=>s.stopPropagation(),children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[t.assigned_to&&F[t.assigned_to]?e.jsx("span",{title:F[t.assigned_to],className:"inline-flex items-center justify-center min-w-7 h-7 px-2 rounded-full bg-primary/10 text-primary text-[11px] font-semibold",children:F[t.assigned_to].split(/\s+/).filter(
4Boolean).slice(0,2).map(s=>{var o;return(o=s[0])==null?void 0:o.toUpperCase()}).join("")||"–"}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"–"}),t.assigned_to===(r==null?void 0:r.id)&&e.jsx(p,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 bg-blue-50 text-blue-700 border-blue-300 dark:bg-blue-900/30 dark:text-blue-300",children:"Ich"}),t.deputy_id===(r==null?void 0:r.id)&&e.jsx(p,{variant:"outline",className:"text-[9px] px-1 py-0 h-4 bg-purple-50 text-purple-700 border-purple-300 dark:bg-purple-900/30 dark:text-purple-300",children:"Vertretung"})]})}),e.jsx(A,{children:J.includes(t.id)?e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(p,{variant:"secondary",className:"text-[10px] bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200",children:"Wartend"}),Be&&e.jsxs(v,{size:"sm",variant:"outline",className:"h-6 px-2 text-[10px] text-green-700 border-green-300 hover:bg-green-50 dark:text-green-400 dark:border-green-700 dark:hover:bg-green-900/30",disabled:le===t.id,onClick:s=>{s.stopPropagation(),pt(t.id,s)},children:[e.jsx(Gt,{className:"h-3 w-3 mr-0.5"}),le===t.id?"…":"Freischalten"]})]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"–"})}),e.jsx(A,{onClick:s=>s.stopPropagation(),children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(Jt,{customerId:t.id,customerEmail:t.email,customerName:Ge(t)}),te&&e.jsx(v,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:s=>ht(t.id,s),children:e.jsx(Ne,{className:"h-3.5 w-3.5 text-destructive"})})]})})]},t.id)})})]})}),e.jsx(es,{selectedCount:z.size,selectedIds:Array.from(z),entityType:"customers",onClear:()=>I(new Set),statusOptions:Object.entries(xe).map(([t,a])=>({value:t,label:a})),onStatusChange:ft,assignees:Ae.map(t=>({id:t.user_id,name:t.full_name})),onAssign:bt,onDelete:i?gt:void 0,onMerge:i?()=>Me(!0):void 0}),e.jsx(os,{open:xt,onClose:()=>Me(!1),customerIds:Array.from(z),onMerged:()=>{I(new Set),E()}})]}),e.jsx(as,{open:st,onOpenChange:Ce,mode:"customer",onImported:()=>E()})]})};export{Fs 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.