1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/exceljs.min-BPGfNIG4.js","assets/index-X4aSNaeS.js","assets/index-D4FtQacX.css","assets/_commonjs-dynamic-modules-TDtrdbi3.js"])))=>i.map(i=>d[i]); 2import{J as Ne,o as ve,u as T,r as N,j as e,C as k,f as R,g as F,k as S,aV as se,aW as le,aX as C,aY as m,aZ as ie,a_ as i,F as H,b4 as ke,b5 as Se,H as W,bH as Ae,N as Ee,O as De,T as Pe,p as te,bF as Ve,ap as Le,aq as Re,ar as Fe,as as Te,at as Me,B as Ie,e as $e,bI as Ke,a7 as he,ad as Be}from"./index-X4aSNaeS.js";import{u as We,a as Ge}from"./useCallCategoryAnalysis-CF-f8jU_.js";import{C as ge,a as Oe,c as be,b as ze}from"./CostCenterSummary-DBbgClxm.js";import{L as qe}from"./lock-CwDoV9TA.js";import{D as Ue}from"./download-DUsZ_3gJ.js";function He(t,l,a){return Ne({queryKey:["billing-month-reconciliation",t,l.toISOString(),a.toISOString()],enabled:!!t,queryFn:async()=>{const{data:c,error:n}=await ve.rpc("get_billing_month_reconciliation",{p_organization_id:t,p_from:l.toISOString(),p_to:a.toISOString()});if(n)throw n;return c}})}const ne=[{key:"06",de:"Kundenservice-Wunsch (ohne Transfer)",en:"Customer service request (no transfer)",group:"transfer",hintDe:"Anrufer wollte den Kundenservice, es wurde aber keine Weiterleitung erkannt.",hintEn:"Caller asked for customer service, but no transfer was detected."},{key:"12",de:"Leeres Gespräch",en:"Empty conversation",group:"waste",hintDe:"Verbindung stand, aber kein verwertbarer Gesprächsinhalt.",hintEn:"Call connected but no usable conversation content."},{key:"02",de:"ADAC Tel. Weiterleitung (Pannenhotline)",en:"ADAC phone transfer (breakdown hotline)",group:"transfer",hintDe:"Weiterleitung an die ADAC-Hotline (+49 32221 092181).",hintEn:"Transferred to the ADAC hotline (+49 32221 092181)."},{key:"11",de:"KI-Fall Info / im Gespräch gelöst",en:"AI case info / resolved in conversation",group:"value",hintDe:"Anliegen wurde direkt von der KI beantwortet oder gelöst.",hintEn:"Request was answered or resolved directly by the AI."},{key:"05a",de:"ADAC Digi-Pannenhilfe â Auftrag",en:"ADAC digital roadside â order",group:"value",hintDe:"Anruf, der zu einem digitalen Abschleppauftrag geführt hat (RSA-Tool).",hintEn:"Call that produced a digital towing dispatch via the RSA tool."},{key:"05b",de:"ADAC Digi-Pannenhilfe â Folgeanruf",en:"ADAC digital roadside â follow-up call",group:"waste",hintDe:"Wiederanruf zu einem bereits digital beauftragten Fall (Partner liefert nicht).",hintEn:"Repeat call on an already dispatched case (partner not delivering)."},{key:"05c",de:"ADAC Digi-Pannenhilfe â No-Show",en:"ADAC digital roadside â no-show",group:"waste",hintDe:"Kunde meldet, dass der Partner nicht erschienen ist.",hintEn:"Customer reports that the partner never arrived."},{key:"13",de:"Abgebrochen / Eskaliert",en:"Aborted / escalated",group:"waste",hintDe:"Gespräch endete ohne Lösung oder wurde eskaliert.",hintEn:"Conversation ended without resolution or was escalated."},{key:"01",de:"Kurzanruf (< 10 Sek.)",en:"Short call (< 10 sec)",group:"waste",hintDe:"Aufgelegt bevor ein Gespräch entstehen konnte.",hintEn:"Hung up before a conversation could start."},{key:"03",de:"Avis CS Tel. Weiterleitung",en:"Avis CS phone transfer",group:"transfer",hintDe:"Weiterleitung an Avis Customer Service (+49 89 76761439) mit CS-Anliegen.",hintEn:"Transferred to Avis customer service (+49 89 76761439) with a CS request."},{key:"04",de:"Weiterleitung sonstige",en:"Other transfer",group:"transfer",hintDe:"Weiterleitung an Avis-Nummer ohne eindeutiges CS-Anliegen.",hintEn:"Transfer to the Avis number without a clear CS intent."},{key:"10",de:"Unvollständige Erfassung",en:"Incomplete intake",group:"waste",hintDe:"Gespräch endete, bevor alle Pflichtdaten erfasst waren.",hintEn:"Call ended before all mandatory data was captured."},{key:"14",de:"Sonstige",en:"Other",group:"other",hintDe:"Kein Ergebniscode gespeichert oder nicht zugeordneter Code.",hintEn:"No outcome code stored or code not mapped yet."},{key:"08",de:"KI-Fall Unfall / Schaden",en:"AI case accident / damage",group:"value",hintDe:"Schadenmeldung durch die KI aufgenommen.",hintEn:"Claim intake completed by the AI."},{key:"09",de:"KI-Fall Technisch / Panne",en:"AI case technical / breakdown",group:"value",hintDe:"Technischer Fall durch die KI aufgenommen (ohne digitalen Auftrag).",hintEn:"Technical case captured by the AI (without a digital dispatch)."},{key:"07",de:"Ersatzfahrzeug / Mobilität",en:"Replacement vehicle / mobility",group:"value",hintDe:"Anliegen rund um Ersatzmobilität.",hintEn:"Request related to replacement mobility."}],ae=new Map(ne.map(t=>[t.key,t])),Ye={value:"bg-[hsl(var(--success))]",transfer:"bg-[hsl(var(--warning))]",waste:"bg-destructive",other:"bg-muted-foreground"},Ze={unclassified_no_result:{de:"Kein Ergebnis gespeichert (Messlücke)",en:"No result stored (measurement gap)"},unclassified_no_outcome:{de:"Kein Ergebnis gespeichert (Messlücke)",en:"No result stored (measurement gap)"},unclassified_too_short:{de:"Zu kurz für Auswertung",en:"Too short to evaluate"},unmapped_code:{de:"Code nicht zugeordnet",en:"Code not mapped"},no_content:{de:"Ohne Inhalt (kein Transkript)",en:"No content (no transcript)"},case_empty_conversation:{de:"Leeres Gespräch (aus Fall)",en:"Empty conversation (from case)"},suspect_empty_conversation:{de:"Verdacht: falsch als leeres Gespräch markiert",en:"Suspected: wrongly flagged as empty conversation"}},Je={rule:{de:"Regel",en:"Rule"},outcome:{de:"Gesprächsergebnis",en:"Call outcome"},case_category:{de:"Fall-Kategorie (Fallback)",en:"Case category (fallback)"},case_empty:{de:"Leeres Gespräch (Fallback)",en:"Empty conversation (fallback)"},empty_fallback:{de:"Ohne Inhalt (Fallback)",en:"No content (fallback)"},unresolved:{de:"Nicht auflösbar",en:"Unresolved"}};function re(t,l){const a=Ze[t];if(a)return l.startsWith("de")?a.de:a.en;if(t.startsWith("case:")){const c=re(t.slice(5),l);return l.startsWith("de")?`${c} (aus Fall)`:`${c} (from case)`}return t.replace(/^cat_/,"").replace(/_/g," ").replace(/\b\w/g,c=>c.toUpperCase())}function Qe(t,l){const a=Je[t];return a?l.startsWith("de")?a.de:a.en:t}function U(t){const l=Math.floor(t/60),a=Math.round(t%60);return l<60?`${l}:${String(a).padStart(2,"0")} min`:`${Math.floor(l/60)}h ${l%60}m`}const $=t=>
2`â¬${t.toLocaleString("de-DE",{minimumFractionDigits:2,maximumFractionDigits:2})}`;function Xe({categories:t,subcategories:l,totals:a,costCenters:c=[]}){const{t:n,i18n:o}=T("admin"),p=o.language||"de",[A,x]=N.useState(null),v=N.useMemo(()=>{const d=new Map;for(const h of c){const f=d.get(h.category_key)??[];f.push(h),d.set(h.category_key,f)}return d},[c]),s=N.useMemo(()=>new Map(t.map(d=>[d.category_key,d])),[t]),_=N.useMemo(()=>{const d=new Map;for(const h of l){const f=d.get(h.category_key)??[];f.push(h),d.set(h.category_key,f)}for(const h of d.values())h.sort((f,K)=>K.calls-f.calls);return d},[l]),G=t.map(d=>d.category_key).filter(d=>!ae.has(d)),Y=[...ne.map(d=>d.key),...G];return e.jsxs(k,{children:[e.jsx(R,{children:e.jsx(F,{className:"text-base",children:n("billingPage.callCategories.tableTitle",{defaultValue:"Calls by category"})})}),e.jsx(S,{className:"px-0 sm:px-6",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(se,{children:[e.jsx(le,{children:e.jsxs(C,{children:[e.jsx(m,{className:"w-[42%]",children:n("billingPage.callCategories.col.category",{defaultValue:"Category"})}),e.jsx(m,{className:"text-right",children:n("billingPage.callCategories.col.calls",{defaultValue:"Calls"})}),e.jsx(m,{className:"text-right",children:n("billingPage.callCategories.col.duration",{defaultValue:"Duration"})}),e.jsx(m,{className:"text-right",children:n("billingPage.callCategories.col.avg",{defaultValue:"à / call"})}),e.jsx(m,{className:"text-right",children:n("billingPage.callCategories.col.credits",{defaultValue:"Credits"})}),e.jsx(m,{className:"text-right",children:n("billingPage.callCategories.col.creditShare",{defaultValue:"Share"})}),e.jsx(m,{className:"text-right",children:n("billingPage.callCategories.col.cost",{defaultValue:"Cost"})}),e.jsx(m,{className:"text-right",children:n("billingPage.callCategories.col.avgCost",{defaultValue:"à cost / call"})}),e.jsx(m,{className:"w-[170px]",children:n("billingPage.callCategories.col.area",{defaultValue:"Business area"})})]})}),e.jsxs(ie,{children:[Y.map(d=>{const h=s.get(d);if(!h)return null;const f=ae.get(d),K=_.get(d)??[],M=A===d,b=a.calls?h.calls/a.calls*100:0,E=a.credits?h.credits/a.credits*100:0;return e.jsxs(e.Fragment,{children:[e.jsxs(C,{className:"cursor-pointer",onClick:()=>x(M?null:d),children:[e.jsx(i,{children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:H("mt-1.5 h-2 w-2 shrink-0 rounded-full",Ye[(f==null?void 0:f.group)??"other"]),"aria-hidden":!0}),M?e.jsx(ke,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}):e.jsx(Se,{className:"mt-0.5 h-4 w-4 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"font-medium",children:[e.jsx("span",{className:"text-muted-foreground mr-2",children:d}),n(`billingPage.callCategories.cat.${d}`,{defaultValue:f?p.startsWith("de")?f.de:f.en:d})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f?p.startsWith("de")?f.hintDe:f.hintEn:null})]})]})}),e.jsxs(i,{className:"text-right tabular-nums",children:[h.calls.toLocaleString(),e.jsxs("span",{className:"ml-1 text-xs text-muted-foreground",children:[b.toFixed(1),"%"]})]}),e.jsx(i,{className:"text-right tabular-nums",children:U(h.total_seconds)}),e.jsxs(i,{className:"text-right tabular-nums",children:[h.avg_seconds,"s"]}),e.jsx(i,{className:"text-right tabular-nums",children:h.credits.toLocaleString("de-DE",{maximumFractionDigits:1})}),e.jsx(i,{className:"text-right tabular-nums",children:e.jsxs("span",{className:"font-medium",children:[E.toFixed(1),"%"]})}),e.jsx(i,{className:"text-right tabular-nums font-medium",children:$(h.cost_eur)}),e.jsx(i,{className:"text-right tabular-nums",children:$(h.calls?h.cost_eur/h.calls:0)}),e.jsx(i,{children:(()=>{const g=v.get(d)??[],I=g.reduce((j,P)=>j+Number(P.credits||0),0);if(!I)return e.jsx("span",{className:"text-xs text-muted-foreground",children:"â"});const B=[...g].sort((j,P)=>ge.indexOf(j.cost_center)-ge.indexOf(P.cost_center)),y=[...g].sort((j,P)=>Number(P.credits)-Number(j.credits))[0];return e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"flex h-1.5 w-full overflow-hidden rounded-full bg-muted",children:B.map(j=>e.jsx("div",{className:H("h-full",Oe[j.cost_center]??"bg-primary"),style:{width:`${Number(j.credits)/I*100}%`},"aria-hidden":!0},j.cost_center))}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[be(n,y.cost_center)," ",(Number(y.credits)/I*100).toFixed(0),"%"]})]})})()})]},d),M&&K.map(g=>e.jsxs(C,{className:"bg-muted/40",children:[e.jsx(i,{className:"pl-14 text-sm text-muted-foreground",children:re(g.sub_code,p)}),e.jsx(i,{className:"text-right text-sm tabular-nums",children:g.calls.toLocaleStr
2ing()}),e.jsx(i,{className:"text-right text-sm tabular-nums",children:U(g.total_seconds)}),e.jsxs(i,{className:"text-right text-sm tabular-nums",children:[g.calls?Math.round(g.total_seconds/g.calls):0,"s"]}),e.jsx(i,{className:"text-right text-sm tabular-nums",children:g.credits.toLocaleString("de-DE",{maximumFractionDigits:1})}),e.jsxs(i,{className:"text-right text-sm tabular-nums",children:[a.credits?(g.credits/a.credits*100).toFixed(1):"0.0","%"]}),e.jsx(i,{className:"text-right text-sm tabular-nums",children:$(g.cost_eur)}),e.jsx(i,{className:"text-right text-sm tabular-nums",children:$(g.calls?g.cost_eur/g.calls:0)}),e.jsx(i,{})]},`${d}-${g.sub_code}`))]})}),e.jsxs(C,{className:"border-t-2 font-semibold",children:[e.jsxs(i,{children:[n("billingPage.callCategories.total",{defaultValue:"Total"}),e.jsx(W,{variant:"outline",className:"ml-2 font-normal",children:n("billingPage.callCategories.prodOnly",{defaultValue:"production only"})})]}),e.jsx(i,{className:"text-right tabular-nums",children:a.calls.toLocaleString()}),e.jsx(i,{className:"text-right tabular-nums",children:U(a.total_seconds)}),e.jsxs(i,{className:"text-right tabular-nums",children:[a.calls?Math.round(a.total_seconds/a.calls):0,"s"]}),e.jsx(i,{className:"text-right tabular-nums",children:a.credits.toLocaleString("de-DE",{maximumFractionDigits:1})}),e.jsx(i,{className:"text-right tabular-nums font-medium",children:"100.0%"}),e.jsx(i,{className:"text-right tabular-nums",children:$(a.cost_eur)}),e.jsx(i,{className:"text-right tabular-nums",children:$(a.calls?a.cost_eur/a.calls:0)}),e.jsx(i,{})]})]})]})})})]})}const me=["rule","outcome","case_category","case_empty","empty_fallback","unresolved"],xe={rule:"bg-[hsl(var(--success))]",outcome:"bg-primary",case_category:"bg-[hsl(var(--warning))]",case_empty:"bg-muted-foreground",empty_fallback:"bg-muted-foreground/60",unresolved:"bg-destructive"},et=t=>`â¬${t.toLocaleString("de-DE",{minimumFractionDigits:2,maximumFractionDigits:2})}`;function tt({rows:t}){const{t:l,i18n:a}=T("admin"),c=a.language||"de",{sorted:n,totalCredits:o,unresolved:p}=N.useMemo(()=>{const x=[...t].sort((s,_)=>me.indexOf(s.tier)-me.indexOf(_.tier)),v=t.reduce((s,_)=>s+Number(_.credits||0),0);return{sorted:x,totalCredits:v,unresolved:t.find(s=>s.tier==="unresolved")}},[t]);if(!t.length)return null;const A=o?((p==null?void 0:p.credits)??0)/o*100:0;return e.jsxs(k,{children:[e.jsxs(R,{className:"pb-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx(F,{className:"text-base",children:l("billingPage.callCategories.quality.title",{defaultValue:"Classification quality"})}),e.jsx(W,{variant:A>5?"destructive":"outline",className:"font-normal",children:l("billingPage.callCategories.quality.unresolvedShare",{defaultValue:"{{share}}% of credits unresolved",share:A.toFixed(1)})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l("billingPage.callCategories.quality.hint",{defaultValue:"How each call reached its category: rules first, then the stored call outcome, then the case problem category as fallback."})})]}),e.jsxs(S,{className:"space-y-3",children:[e.jsx("div",{className:"flex h-2 w-full overflow-hidden rounded-full bg-muted",children:n.map(x=>e.jsx("div",{className:H("h-full",xe[x.tier]??"bg-primary"),style:{width:`${o?Number(x.credits)/o*100:0}%`},"aria-hidden":!0},x.tier))}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 lg:grid-cols-3",children:n.map(x=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border p-2",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:H("h-2 w-2 shrink-0 rounded-full",xe[x.tier]??"bg-primary"),"aria-hidden":!0}),e.jsx("span",{className:"truncate text-sm",children:Qe(x.tier,c)})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("div",{className:"text-sm font-medium tabular-nums",children:x.calls.toLocaleString()}),e.jsx("div",{className:"text-xs text-muted-foreground tabular-nums",children:et(x.cost_eur)})]})]},x.tier))})]})]})}const X=t=>`â¬${t.toLocaleString("de-DE",{minimumFractionDigits:2,maximumFractionDigits:2})}`;function at({repeat:t}){const{t:l}=T("admin"),a=t.dispatched_cases?t.dispatched_cases_with_repeat/t.dispatched_cases*100:0,c=[{label:l("billingPage.callCategories.repeat.cases",{defaultValue:"Dispatched cases"}
2),value:t.dispatched_cases.toLocaleString()},{label:l("billingPage.callCategories.repeat.withRepeat",{defaultValue:"â¦with follow-up calls"}),value:`${t.dispatched_cases_with_repeat.toLocaleString()} (${a.toFixed(0)}%)`},{label:l("billingPage.callCategories.repeat.fivePlus",{defaultValue:"â¦with 5+ calls"}),value:t.dispatched_cases_5plus.toLocaleString()},{label:l("billingPage.callCategories.repeat.calls",{defaultValue:"Follow-up calls"}),value:t.repeat_calls.toLocaleString()},{label:l("billingPage.callCategories.repeat.minutes",{defaultValue:"Follow-up talk time"}),value:U(t.repeat_seconds)},{label:l("billingPage.callCategories.repeat.cost",{defaultValue:"Follow-up cost"}),value:X(t.repeat_cost_eur??0)},{label:l("billingPage.callCategories.repeat.avgHours",{defaultValue:"à time to first follow-up"}),value:t.avg_hours_to_repeat!=null?`${t.avg_hours_to_repeat} h`:"â"},{label:l("billingPage.callCategories.repeat.etaCalls",{defaultValue:"â¦of these: ETA / status chasing"}),value:`${(t.eta_calls??0).toLocaleString()} · ${X(t.eta_cost_eur??0)}`},{label:l("billingPage.callCategories.repeat.otherCalls",{defaultValue:"â¦of these: other topics"}),value:`${(t.other_calls??0).toLocaleString()} · ${X(t.other_cost_eur??0)}`},{label:l("billingPage.callCategories.repeat.inTransfer",{defaultValue:"Follow-ups booked as transfers"}),value:(t.followups_in_transfer_categories??0).toLocaleString()},{label:l("billingPage.callCategories.repeat.withoutCase",{defaultValue:"Calls without a case"}),value:(t.calls_without_case??0).toLocaleString()}];return e.jsxs(k,{children:[e.jsx(R,{children:e.jsxs(F,{className:"flex items-center gap-2 text-base",children:[e.jsx(Ae,{className:"h-4 w-4 text-muted-foreground"}),l("billingPage.callCategories.repeat.title",{defaultValue:"Follow-up calls after digital dispatch"})]})}),e.jsxs(S,{children:[e.jsx("div",{className:"grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:c.map(n=>e.jsxs("div",{className:"rounded-lg border p-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:n.label}),e.jsx("p",{className:"mt-1 text-lg font-semibold tabular-nums",children:n.value})]},n.label))}),e.jsx("p",{className:"mt-4 text-xs text-muted-foreground",children:l("billingPage.callCategories.repeat.hint",{defaultValue:"Follow-up calls are calls on a case that already had a towing dispatch before the call started â independently of the billing category, so a follow-up that ends in a transfer is counted here too. Only the ETA/status subset is a candidate for proactive-SMS deflection."})})]})]})}const st=t=>`â¬${t.toLocaleString("de-DE",{minimumFractionDigits:2,maximumFractionDigits:2})}`;function lt({towing:t,tieOut:l}){const{t:a}=T("admin"),c=((l==null?void 0:l.ledger_credits)??0)-((l==null?void 0:l.report_credits)??0),n=t.dispatches-t.emails_sent;return e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsxs(k,{children:[e.jsx(R,{children:e.jsxs(F,{className:"flex items-center gap-2 text-base",children:[e.jsx(Ee,{className:"h-4 w-4 text-muted-foreground"}),a("billingPage.callCategories.towing.title",{defaultValue:"Towing dispatch vs. ADAC emails"})]})}),e.jsxs(S,{className:"space-y-3 text-sm",children:[e.jsx(w,{label:a("billingPage.callCategories.towing.dispatches",{defaultValue:"Dispatch records (RSA tool)"}),value:t.dispatches.toLocaleString()}),e.jsx(w,{label:a("billingPage.callCategories.towing.emails",{defaultValue:"ADAC towing emails sent"}),value:t.emails_sent.toLocaleString()}),e.jsx(w,{label:a("billingPage.callCategories.towing.withEmail",{defaultValue:"Dispatches with exactly 1 email"}),value:t.with_email.toLocaleString()}),e.jsx(w,{label:a("billingPage.callCategories.towing.withoutEmail",{defaultValue:"Dispatches without email"}),value:t.without_email.toLocaleString(),warn:t.without_email>0}),e.jsx(w,{label:a("billingPage.callCategories.towing.multiEmail",{defaultValue:"Dispatches with multiple emails"}),value:t.multiple_emails.toLocaleString(),warn:t.multiple_emails>0}),e.jsx(w,{label:a("billingPage.callCategories.towing.oem",{defaultValue:"Handed off to OEM (no ADAC email)"}
2),value:t.handed_off_oem.toLocaleString()}),e.jsx(w,{label:a("billingPage.callCategories.towing.cancellations",{defaultValue:"Cancellation emails"}),value:t.cancellation_emails.toLocaleString()}),e.jsx("div",{className:"flex flex-wrap gap-2 pt-2",children:t.by_status.map(o=>e.jsxs(W,{variant:"secondary",children:[o.status,": ",o.n]},o.status))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("billingPage.callCategories.towing.hint",{defaultValue:"Difference dispatch vs. email: {{delta}} (OEM hand-offs and failed dispatches never send an ADAC email).",delta:n})})]})]}),e.jsxs(k,{children:[e.jsx(R,{children:e.jsxs(F,{className:"flex items-center gap-2 text-base",children:[Math.abs(c)<1?e.jsx(De,{className:"h-4 w-4 text-[hsl(var(--success))]"}):e.jsx(Pe,{className:"h-4 w-4 text-[hsl(var(--warning))]"}),a("billingPage.callCategories.tieOut.title",{defaultValue:"Invoice tie-out (phone AI)"})]})}),e.jsxs(S,{className:"space-y-3 text-sm",children:[e.jsx(w,{label:a("billingPage.callCategories.tieOut.ledger",{defaultValue:"Billed credits (ledger)"}),value:((l==null?void 0:l.ledger_credits)??0).toLocaleString("de-DE",{maximumFractionDigits:2})}),e.jsx(w,{label:a("billingPage.callCategories.tieOut.report",{defaultValue:"Credits in this report"}),value:((l==null?void 0:l.report_credits)??0).toLocaleString("de-DE",{maximumFractionDigits:2})}),e.jsx(w,{label:a("billingPage.callCategories.tieOut.delta",{defaultValue:"Difference"}),value:c.toLocaleString("de-DE",{maximumFractionDigits:2}),warn:Math.abs(c)>=1}),e.jsx(w,{label:a("billingPage.callCategories.tieOut.ledgerCost",{defaultValue:"Billed amount (ledger)"}),value:st((l==null?void 0:l.ledger_cost_eur)??0)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("billingPage.callCategories.tieOut.hint",{defaultValue:"The report counts production phone calls only. Test numbers, staging traffic and calls that started in the previous month explain small differences to the invoice."})})]})]})]})}function w({label:t,value:l,warn:a}){return e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-muted-foreground",children:t}),e.jsx("span",{className:a?"font-semibold tabular-nums text-[hsl(var(--warning))]":"font-medium tabular-nums",children:l})]})}const ee=t=>`â¬${Number(t).toLocaleString("de-DE",{minimumFractionDigits:2,maximumFractionDigits:2})}`,q=t=>Number(t).toLocaleString("de-DE",{maximumFractionDigits:1}),it={phone_ai:"Phone AI",whatsapp_ai:"WhatsApp AI",chat_ai:"Chat AI",email_parsing:"Email parsing",email_sending:"Email sending",sms:"SMS",remote_diagnosis:"Remote diagnosis",manual_adjustment:"Adjustment"};function nt({data:t,isLoading:l}){var c;const{t:a}=T("admin");return l?e.jsx(te,{className:"h-64 w-full"}):(c=t==null?void 0:t.months)!=null&&c.length?e.jsxs(k,{children:[e.jsx(R,{children:e.jsx(F,{className:"text-base",children:a("billingPage.callCategories.reconciliation.title",{defaultValue:"Monthly invoice reconciliation"})})}),e.jsxs(S,{className:"px-0 sm:px-6",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(se,{children:[e.jsx(le,{children:e.jsxs(C,{children:[e.jsx(m,{children:a("billingPage.callCategories.reconciliation.month",{defaultValue:"Month"})}),e.jsx(m,{children:a("billingPage.callCategories.reconciliation.channels",{defaultValue:"Channels"})}),e.jsx(m,{children:a("billingPage.callCategories.reconciliation.areas",{defaultValue:"Business areas"})}),e.jsx(m,{className:"text-right",children:a("billingPage.callCategories.col.credits",{defaultValue:"Credits"})}),e.jsx(m,{className:"text-right",children:a("billingPage.callCategories.reconciliation.creditCost",{defaultValue:"Credit amount"})}),e.jsx(m,{className:"text-right",children:a("billingPage.callCategories.reconciliation.baseFee",{defaultValue:"Base fee"})}),e.jsx(m,{className:"text-right",children:a("billingPage.callCategories.reconciliation.net",{defaultValue:"Net total"})})]})}),e.jsx(ie,{children:t.months.map(n=>e.jsxs(C,{children:[e.jsx(i,{className:"font-medium",children:e.jsxs("div",{className:"flex items-center gap-2",children:[n.month,n.is_locked&&e.jsxs(W,{variant:"secondary",className:"gap-1",children:[e.jsx(qe,{className:"h-3 w-3","aria-hidden":!0}),a("billingPage.callCategories.reconciliation.locked",{defaultValue:"Final"})]}),!n.is_locked&&n.is_partially_locked&&e.jsx(W,{variant:"outline",children:a("billingPage.callCategories.reconciliation.partiallyLocked",{defaultValue:"Partly final"})})]})}),e.jsx(i,{className:"text-xs text-muted-foreground",children:n.channels.map(o=>e.jsxs("div",{className:"tabular-nums",children:[it[o.event_type]??o.event_type,": ",q(o.credits)]},o.event_type))}),e.jsxs(i,{className:"text-xs text-muted-foreground",children:[n.cost_centers.map(o=>e.jsxs("div",{className:"tabular-nums",children:[be(a,o.cost_center),": ",q(o.credits)]},o.cost_center)),Math.abs(Number(n.allocation_delta))>.5&&e.jsxs("div",{className:"text-destructive",children:[a("billingPage.callCategories.reconciliation.delta",{defaultValue:"Unallocated"}),":"," ",q(n.allocation_delta)]})]}),e.jsx(i,{className:"text-right tabular-nums",children:q(n.ledger_credits)}),e.jsx(i,{className:"text-right tabular-nums",children:ee(n.credit_cost_eur)}),e.jsx(i,{className:"text-right tabular-nums",children:ee(n.base_fee_eur)}),e.jsx(i,{className:"text-right font-semibold tabular-nums",children:ee(n.net_total_eur)})]},n.month))})]})}),e.jsx("p",{className:"mt-3 px-4 text-xs text-muted-foreground sm:px-0",children:a("billingPage.callCategories.reconciliation.hint",{defaultValue:"Net total = billed credits à {{price}} ct + monthly base fee. Business areas always add up to the billed credits â they only split them, they never change the amount.",price:t.price_cents})})]})]}):null}const pe={phone_ai:{de:"Phone AI",en:"Phone AI"},whatsapp_ai:{de:"WhatsApp AI",en:"WhatsApp AI"},chat_ai:{de:"Chat AI",en:"Chat AI"},email_parsing:{de:"Inbound E-Mail",en:"Inbound email"},email_sending:{de:"Outbound E-Mail",en:"Outbound email"},sms:{de:"SMS",en:"SMS"},remote_diagnosis:{de:"Ferndiagnose",en:"Remote diagnosis"},manual_adjustment:{de:"Korrekturen / Gutschriften",en:"Adjustments / refunds"},monthly_allocation:{de:"Monatliche Zuteilung",en:"Monthly allocation"}},L=t=>
2`â¬${Number(t).toLocaleString("de-DE",{minimumFractionDigits:2,maximumFractionDigits:2})}`,fe=t=>Number(t).toLocaleString("de-DE",{maximumFractionDigits:2});function rt({rows:t,baseFeeEur:l,priceCents:a}){const{t:c,i18n:n}=T("admin"),o=(n.language||"de").startsWith("de"),p=t.reduce((s,_)=>s+Number(_.credits||0),0),x=t.reduce((s,_)=>s+Number(_.cost_eur||0),0)+Number(l||0),v=x*.19;return e.jsxs(k,{children:[e.jsx(R,{children:e.jsx(F,{className:"text-base",children:c("billingPage.callCategories.statement.title",{defaultValue:"Invoice statement (all channels)"})})}),e.jsxs(S,{className:"px-0 sm:px-6",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(se,{children:[e.jsx(le,{children:e.jsxs(C,{children:[e.jsx(m,{children:c("billingPage.callCategories.statement.item",{defaultValue:"Item"})}),e.jsx(m,{className:"text-right",children:c("billingPage.callCategories.statement.events",{defaultValue:"Events"})}),e.jsx(m,{className:"text-right",children:c("billingPage.callCategories.col.credits",{defaultValue:"Credits"})}),e.jsx(m,{className:"text-right",children:c("billingPage.callCategories.statement.price",{defaultValue:"Price"})}),e.jsx(m,{className:"text-right",children:c("billingPage.callCategories.col.cost",{defaultValue:"Cost"})})]})}),e.jsxs(ie,{children:[e.jsxs(C,{children:[e.jsx(i,{className:"font-medium",children:c("billingPage.callCategories.statement.licence",{defaultValue:"Monthly platform licence"})}),e.jsx(i,{className:"text-right tabular-nums",children:"1"}),e.jsx(i,{className:"text-right tabular-nums",children:"â"}),e.jsx(i,{className:"text-right tabular-nums",children:L(l)}),e.jsx(i,{className:"text-right tabular-nums",children:L(l)})]}),t.map(s=>{const _=pe[s.event_type];return e.jsxs(C,{children:[e.jsx(i,{className:"font-medium",children:_?o?_.de:_.en:s.event_type}),e.jsx(i,{className:"text-right tabular-nums",children:s.events.toLocaleString("de-DE")}),e.jsx(i,{className:"text-right tabular-nums",children:fe(s.credits)}),e.jsx(i,{className:"text-right tabular-nums",children:L(a/100)}),e.jsx(i,{className:"text-right tabular-nums",children:L(s.cost_eur)})]},s.event_type)}),e.jsxs(C,{className:"border-t-2 font-semibold",children:[e.jsx(i,{children:c("billingPage.callCategories.statement.net",{defaultValue:"Subtotal (net)"})}),e.jsx(i,{}),e.jsx(i,{className:"text-right tabular-nums",children:fe(p)}),e.jsx(i,{}),e.jsx(i,{className:"text-right tabular-nums",children:L(x)})]}),e.jsxs(C,{children:[e.jsx(i,{children:c("billingPage.callCategories.statement.vat",{defaultValue:"VAT 19%"})}),e.jsx(i,{}),e.jsx(i,{}),e.jsx(i,{}),e.jsx(i,{className:"text-right tabular-nums",children:L(v)})]}),e.jsxs(C,{className:"font-semibold",children:[e.jsx(i,{children:c("billingPage.callCategories.statement.total",{defaultValue:"Total"})}),e.jsx(i,{}),e.jsx(i,{}),e.jsx(i,{}),e.jsx(i,{className:"text-right tabular-nums",children:L(x+v)})]})]})]})}),e.jsx("p",{className:"mt-3 px-4 text-xs text-muted-foreground sm:px-0",children:c("billingPage.callCategories.statement.hint",{defaultValue:"Source: credit ledger of the selected period, including manual adjustments. The call category table above is a finer cut of the Phone AI line only."})})]})]})}function mt(){var M;const{startDate:t,endDate:l}=Ve(),{t:a,i18n:c}=T("admin"),n=c.language||"de",{data:o}=We(),[p,A]=N.useState(),[x,v]=N.useState(!1);N.useEffect(()=>{if(p||!(o!=null&&o.length))return;const b=o.find(E=>{var g;return(g=E.name)==null?void 0:g.toLowerCase().includes("avis")});A((b==null?void 0:b.id)??o[0].id)},[o,p]);const{data:s,isLoading:_,error:G}=Ge(p,t,l),Y=N.useMemo(()=>new Date(2026,4,1),[]),{data:d,isLoading:h}=He(p,Y,new Date),f=N.useMemo(()=>{var b;return((b=o==null?void 0:o.find(E=>E.id===p))==null?void 0:b.name)??""},[o,p]),K=async()=>{var b,E,g,I;if(s){v(!0);try{const B=(await Ke(async()=>{const{default:r}=await import("./exceljs.min-BPGfNIG4.js").then(u=>u.e);return{default:r}},__vite__mapDeps([0,1,2,3]))).default,y=new B.Workbook,j=y.addWorksheet(a("billingPage.callCategories.tableTitle",{defaultValue:"Categories"}));j.columns=[{header:"#",key:"k",width:8},{header:"Kategorie",key:"label",width:46},{header:"Anrufe (n)",key:"calls",width:12},{header:"à Dauer (Sek.)",key:"avg",width:14},{header:"Gesamt-Sek.",key:"secs",width:14},{header:"Credits",key:"credits",width:14},{header:"Anteil Credits %",key:"creditShare",width:16},{header:"à Kosten / Anruf (â¬)",key:"avgCost",width:20},{header:"Kosten gesamt (â¬)",key:"cost",width:18}],j.getRow(1).font={bold:!0};const P=new Map(s.categories.map(r=>[r.category_key,r]));for(const r of ne){const u=P.get(r.key);u&&j.addRow({k:r.key,label:n.startsWith("de")?r.de:r.en,calls:u.calls,secs:u.total_seconds,avg:u.avg_seconds,credits:u.credits,creditShare:s.totals.credits?u.credits/s.totals.credits*100:0,avgCost:u.calls?Number((u.cost_eur/u.calls).toFixed(2)):0,cost:u.cost_eur})}j.addRow({k:"",label:"GESAMT",calls:s.totals.calls,secs:s.totals.total_seconds,avg:s.totals.calls?Math.round(s.totals.total_seconds/s.totals.calls):0,credits:s.totals.credits,avgCost:s.totals.calls?Number((s.totals.cost_eur/s.totals.calls).toFixed(2)):0,cost:s.totals.cost_eur}).font={bold:!0};const D=y.addWorksheet("Rechnung");D.columns=[{header:"Position",key:"label",width:34},{header:"Menge",key:"qty",width:14},{header:"Einheit",key:"unit",width:14},{header:"Preis â¬",key:"price",width:12}
2,{header:"Betrag â¬",key:"amount",width:16}],D.getRow(1).font={bold:!0};const ce=Number(s.base_fee_eur??0),_e=(s.price_cents??45)/100;D.addRow({label:"Plattformlizenz (Monat)",qty:1,unit:"Lizenz",price:ce,amount:ce});for(const r of s.channel_statement??[]){const u=pe[r.event_type];D.addRow({label:u?n.startsWith("de")?u.de:u.en:r.event_type,qty:r.credits,unit:"Credit",price:_e,amount:r.cost_eur})}const je=2,Ce=D.rowCount,O=D.addRow({label:"Zwischensumme (netto)"});O.getCell("amount").value={formula:`SUM(E${je}:E${Ce})`},O.font={bold:!0};const oe=D.addRow({label:"USt. 19 %"});oe.getCell("amount").value={formula:`E${O.number}*0.19`};const de=D.addRow({label:"Gesamt"});de.getCell("amount").value={formula:`E${O.number}+E${oe.number}`},de.font={bold:!0};const Z=y.addWorksheet("Unterkategorien");Z.columns=[{header:"Kategorie",key:"cat",width:12},{header:"Code",key:"code",width:42},{header:"Anrufe",key:"calls",width:12},{header:"Sekunden",key:"secs",width:14},{header:"Credits",key:"credits",width:14},{header:"Kosten â¬",key:"cost",width:14}],Z.getRow(1).font={bold:!0};for(const r of[...s.subcategories].sort((u,V)=>V.calls-u.calls))Z.addRow({cat:r.category_key,code:re(r.sub_code,n),calls:r.calls,secs:r.total_seconds,credits:r.credits,cost:r.cost_eur});const J=y.addWorksheet("Abgleich");J.columns=[{header:"Kennzahl",key:"label",width:46},{header:"Wert",key:"value",width:20}],J.getRow(1).font={bold:!0},[["Abgeschleppte Fälle (Dispatch)",s.repeat.dispatched_cases],["Fälle mit Folgeanrufen",s.repeat.dispatched_cases_with_repeat],["Fälle mit 5+ Anrufen",s.repeat.dispatched_cases_5plus],["Folgeanrufe",s.repeat.repeat_calls],["Folgeanruf-Sekunden",s.repeat.repeat_seconds],["Folgeanruf-Kosten â¬",s.repeat.repeat_cost_eur],["à Stunden bis Folgeanruf",s.repeat.avg_hours_to_repeat??0],["Dispatch-Datensätze",s.towing.dispatches],["ADAC Abschlepp-Mails",s.towing.emails_sent],["Dispatch ohne Mail",s.towing.without_email],["Stornierungs-Mails",s.towing.cancellation_emails],["Credits laut Ledger",((b=s.tie_out)==null?void 0:b.ledger_credits)??0],["Credits im Report",((E=s.tie_out)==null?void 0:E.report_credits)??0],["Betrag laut Ledger â¬",((g=s.tie_out)==null?void 0:g.ledger_cost_eur)??0]].forEach(([r,u])=>J.addRow({label:r,value:u}));const z=y.addWorksheet("Bereiche");z.columns=[{header:"Kategorie",key:"cat",width:12},{header:"Bereich",key:"cc",width:26},{header:"Credits",key:"credits",width:14},{header:"Kosten â¬",key:"cost",width:14}],z.getRow(1).font={bold:!0};for(const r of s.category_cost_centers??[])z.addRow({cat:r.category_key,cc:r.cost_center,credits:r.credits,cost:r.cost_eur});for(const r of s.cost_center_totals??[])z.addRow({cat:"GESAMT",cc:r.cost_center,credits:r.credits,cost:r.cost_eur}).font={bold:!0};if((I=d==null?void 0:d.months)!=null&&I.length){const r=y.addWorksheet("Monatsabgleich");r.columns=[{header:"Monat",key:"month",width:12}
2,{header:"Kanäle",key:"channels",width:46},{header:"Bereiche",key:"cc",width:46},{header:"Credits",key:"credits",width:14},{header:"Credit-Betrag â¬",key:"creditCost",width:16},{header:"Grundgebühr â¬",key:"base",width:16},{header:"Netto â¬",key:"net",width:14}],r.getRow(1).font={bold:!0};for(const u of d.months)r.addRow({month:u.month,channels:u.channels.map(V=>`${V.event_type}: ${V.credits}`).join(", "),cc:u.cost_centers.map(V=>`${V.cost_center}: ${V.credits}`).join(", "),credits:u.ledger_credits,creditCost:u.credit_cost_eur,base:u.base_fee_eur,net:u.net_total_eur})}const we=await y.xlsx.writeBuffer(),ye=new Blob([we],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}),ue=URL.createObjectURL(ye),Q=document.createElement("a");Q.href=ue,Q.download=`${f||"org"}_Anrufkategorien_${he(t,"yyyy-MM-dd")}_${he(l,"yyyy-MM-dd")}.xlsx`,Q.click(),URL.revokeObjectURL(ue)}catch(B){Be.error(a("billingPage.callCategories.exportError",{defaultValue:"Export failed"})),console.error(B)}finally{v(!1)}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold",children:a("billingPage.callCategories.title",{defaultValue:"Call category analysis"})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("billingPage.callCategories.subtitle",{defaultValue:"Monthly call categories, repeat-call drivers and towing reconciliation â tied to the billed credits."})})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Le,{value:p,onValueChange:A,children:[e.jsx(Re,{className:"w-[220px]",children:e.jsx(Fe,{placeholder:a("billingPage.callCategories.selectOrg",{defaultValue:"Select customer"})})}),e.jsx(Te,{children:o==null?void 0:o.map(b=>e.jsx(Me,{value:b.id,children:b.name},b.id))})]}),e.jsxs(Ie,{variant:"outline",onClick:K,disabled:!s||x,children:[x?e.jsx($e,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Ue,{className:"mr-2 h-4 w-4"}),a("billingPage.callCategories.export",{defaultValue:"Export Excel"})]})]})]}),_&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(te,{className:"h-64 w-full"}),e.jsx(te,{className:"h-40 w-full"})]}),G&&e.jsx(k,{children:e.jsx(S,{className:"p-6 text-sm text-destructive",children:G.message})}),s&&!_&&e.jsxs(e.Fragment,{children:[e.jsx(ze,{totals:s.cost_center_totals??[],coverage:s.coverage,channelTotals:s.channel_totals,testTraffic:s.test_traffic,testTrafficByChannel:s.test_traffic_by_channel}),e.jsx(tt,{rows:s.classification_quality??[]}),e.jsx(Xe,{categories:s.categories,subcategories:s.subcategories,totals:s.totals,costCenters:s.category_cost_centers??[]}),e.jsx(rt,{rows:s.channel_statement??[],baseFeeEur:Number(s.base_fee_eur??0),priceCents:s.price_cents??45}),e.jsx(nt,{data:d,isLoading:h}),e.jsx(at,{repeat:s.repeat}),e.jsx(lt,{towing:s.towing,tieOut:s.tie_out}),((M=s.unmapped_codes)==null?void 0:M.length)>0&&e.jsx(k,{children:e.jsxs(S,{className:"p-4 text-sm",children:[e.jsx("p",{className:"mb-2 font-medium",children:a("billingPage.callCategories.unmapped",{defaultValue:"Unmapped outcome codes (counted as 14)"})}),e.jsx("div",{className:"flex flex-wrap gap-2 text-xs text-muted-foreground",children:s.unmapped_codes.map(b=>e.jsxs("span",{className:"rounded border px-2 py-1",children:[b.code," · ",b.calls]},b.code))})]})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[ae.size," ",a("billingPage.callCategories.footer",{defaultValue:"canonical categories"})]})]})]})}export{mt 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.