PageSourceSearch

https://www.bikely.com/assets/CustomerServiceAgreement-T4Bfs9PL.js

js bikely.com collected 2026-10-02 10:00:01 UTC 34,106 bytes, 1 lines download raw bytes

1import{aa as ye,v as be,r as x,w as $,i as u,j as e,B as j,L as X,I as m,S as Z,o as ee,p as se,q as te,t as re,c as ae,k as g}from"./index-DTL302P6.js";import{G as we,p as Se,g as Ce}from"./pdf.worker.min-Y0bsH4Sj.js";import{D as Ie}from"./DashboardSidebar-Bi0Jtbd1.js";import{D as Pe}from"./DashboardHeader-DG1afYNx.js";import{S as De,a as Le}from"./sidebar-O3-mXb5J.js";import{C as G,a as U,b as J,d as H}from"./card-Bn2w8S0a.js";import{L as c}from"./label-D672ps04.js";import{B as le}from"./badge-C58b7yU7.js";import{T as ce}from"./textarea-pTCLOTM4.js";import{R as Te,a as me}from"./radio-group-CM-ngzwV.js";import{A as qe,a as z,b as B,c as M}from"./accordion-Rk22wZmi.js";import{T as Fe,a as Ae,b as ue,c as xe}from"./tabs-DUZ3dAp_.js";import{C as Ke}from"./checkbox-DnGQJWen.js";import{S as Ee}from"./switch-D_zjmv9v.js";import{A as Oe}from"./arrow-left-CH7HL-Mn.js";import{F as Ve}from"./file-pen-line-BzF2iAML.js";import{E as $e}from"./eye-5fqgV9qE.js";import{D as ze}from"./download-CD9rcI65.js";import{T as Be}from"./trash-2-zgL8Hpzu.js";import{R as Me}from"./refresh-cw--kHgCMc-.js";import"./collapsible-BMxbzh0W.js";import"./index-CCbpT8Vc.js";import"./PortalLanguageToggle-nGkdsYbz.js";import"./useUnreadCount-CmcO4JsF.js";import"./scroll-text-BN0JJbaM.js";import"./map-pin-Dwxh9WPE.js";import"./chart-column-BWYOVxkC.js";import"./receipt-BVRybrtN.js";import"./inbox-C0h_WNyl.js";import"./send-BFXInBbE.js";import"./factory-Dm91uim-.js";import"./headset-D2OVY1mp.js";import"./users-BDLZvLSi.js";import"./building-DtD2xdJ9.js";import"./message-square-BrwXl32Z.js";import"./ticket-B1MANAx2.js";import"./clipboard-list-BMw4YT03.js";import"./package-N-RlFvO8.js";import"./megaphone-Bo68BxOq.js";import"./life-buoy-CYBV-fvN.js";import"./trending-up-BR2Y5PxQ.js";import"./sparkles-Dx6o-AoE.js";import"./bot-BBDPxNas.js";import"./settings-ZaCH7G4V.js";import"./activity-XWTh-ccA.js";import"./external-link-BeWgJguS.js";import"./bike-CLQnIyjX.js";import"./dropdown-menu-pwXDEaeM.js";import"./index-BpyFMlGF.js";import"./useAdminAuth-COEOZ2Bz.js";import"./auth-CNI9qFaZ.js";import"./search-D3U0uVfS.js";import"./bell-Dw8ipi73.js";import"./user-DPpI2OVC.js";import"./separator-BXcg3puw.js";import"./index-B07Nqcis.js";import"./skeleton-CFvFMfzl.js";we.workerSrc=Se;const Qe=()=>new Date().toISOString().slice(0,10),O=a=>a?new Date(a).toLocaleDateString("nb-NO",{day:"2-digit",month:"2-digit",year:"numeric"}):"—",Re=a=>a?new Date(a).toLocaleString("nb-NO",{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"}):"—",b=a=>a==null||isNaN(Number(a))?"—":Number(a).toLocaleString("nb-NO"),Ge=a=>a==="signed"?"default":a==="sent"?"secondary":"outline",pe=a=>({draft:"Utkast",sent:"Sendt",signed:"Signert",archived:"Arkivert"})[a]||a,Ue=a=>a.trim()===""?null:Number(a);function Je({location:a,onSaved:_}){const[D,C]=x.useState(a.etablert_dato||""),[S,L]=x.useState(a.pris_per_plass??""),[y,w]=x.useState(a.antall_plasser??""),[t,N]=x.useState(!1),p=async()=>{N(!0);const{error:o}=await u.from("locations").update({etablert_dato:D||null,pris_per_plass:S===""?null:Number(S),antall_plasser:y===""?null:Number(y)}).eq("id",a.id);if(N(!1),o)return g.error(o.message);g.success("Lokasjon oppdatert"),_()};return e.jsxs("div",{className:"border rounded p-2 space-y-2",children:[e.jsxs("p",{className:"text-xs font-medium",children:[a.location_name||"(uten navn)"," ",e.jsxs("span",{className:"text-muted-foreground",children:["· ",a.cabinet_count||0," dører"]})]}),e.jsxs("div",{className:"grid grid-cols-4 gap-2 items-end",children:[e.jsxs("div",{children:[e.jsx(c,{className:"text-[10px]",children:"Etablert"}),e.jsx(m,{className:"h-8 text-xs",type:"date",value:D,onChange:o=>C(o.target.value)})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-[10px]",children:"Plasser"}),e.jsx(m,{className:"h-8 text-xs",type:"number",value:y,onChange:o=>w(o.target.value)})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-[10px]",children:"Pris/plass"}),e.jsx(m,{className:"h-8 text-xs",type:"number",value:S,onChange:o=>L(o.target.value)})]}),e.jsx(j,{size:"sm",variant:"outline",className:"h-8",disabled:t,onClick:p,children:t?"Lagrer...":"Lagre"})]})]})}function He({data:a}){const _=x.useRef(null),[D,C]=x.useState(!0),[S,L]=x.useState(null);return x.useEffect(()=>{let y=!1;const w=_.current;return w?(w.innerHTML="",C(!0),L(null),(async()=>{try{const N=await Ce({data:new Uint8Array(a)}).promise;for(let p=1;p<=N.numPages&&!y;p+=1){const o=await N.getPage(p),f=o.getViewport({scale:1}),V=Math.min(w.clientWidth||960,960)/f.width,A=o.getViewport({scale:V}),P=document.createElement("canvas"),Q=P.getContext("2d");if(!Q)throw new Error("Kunne ikke initialisere PDF-visning");P.width=Math.floor(A.width),P.height=Math.floor(A.height),P.className="w-full max-w-[960px] border rounded bg-background shadow-sm",w.appendChild(P),await o.render({canvas:P,canvasContext:Q,viewport:A}).promise}y||C(!1)}catch(N){y||(L((N==null?void 0:N.message)||"Kunne ikke vise PDF"),C(!1))}})(),()=>{y=!0,w.innerHTML=""}):void 0},[a]),e.jsxs("div",{className:"min-h-[800px] border rounded bg-muted/20 p-4",children:[D&&e.jsxs("div",{className:"h-[760px] flex items-center justify-center text-sm text-muted-foreground",children:[e.jsx(ae,{className:"w-4 h-4 mr-2 animate-spin"}
1)," Laster PDF-visning..."]}),S&&e.jsx("div",{className:"h-[760px] flex items-center justify-center text-sm text-destructive",children:S}),e.jsx("div",{ref:_,className:"space-y-4 flex flex-col items-center"})]})}function Zs(){const{id:a}=ye(),_=be(),[D,C]=x.useState(!1),[S,L]=x.useState(!1),[y,w]=x.useState(null),[t,N]=x.useState({startdato:Qe(),varighet_ar:2,opsjon_ar:1,oppsigelsestid_mnd:3,kunde_kontakt_navn:"",kunde_kontakt_tittel:"",kunde_kontakt_epost:"",kunde_kontakt_telefon:"",kunde_kontakt_drift_navn:"",kunde_kontakt_drift_epost:"",kunde_kontakt_drift_telefon:"",kunde_ordrereferanse:"",kunde_fakturakontakt_navn:"",kunde_fakturakontakt_epost:"",kunde_organisasjonsnummer:"",kunde_fakturaadresse:"",pris_arlig_per_dor_nok:"",transport_inkludert:"true",fakturafrekvens:"arlig",betalingsfrist_dager:"30",faktura_kommentar:"",notater:"",appendix1_kommentar:"",appendix2_overrides:{rows:[],reise_kommentar:""},appendix4_versjonlogg:[]}),{data:p}=$({queryKey:["customer",a],queryFn:async()=>{const{data:s,error:r}=await u.from("customers").select("id, name, address, contact_person, email").eq("id",a).single();if(r)throw r;return s},enabled:!!a}),{data:o}=$({queryKey:["service-agreement-settings"],queryFn:async()=>{const{data:s,error:r}=await u.from("service_agreement_settings").select("*").order("created_at",{ascending:!0}).limit(1).maybeSingle();if(r)throw r;return s}});x.useEffect(()=>{p&&N(s=>({...s,kunde_kontakt_navn:s.kunde_kontakt_navn||p.contact_person||"",kunde_kontakt_epost:s.kunde_kontakt_epost||p.email||"",kunde_fakturaadresse:s.kunde_fakturaadresse||p.address||""}))},[p]);const{data:f=[]}=$({queryKey:["sa-locations",a],queryFn:async()=>{const{data:s,error:r}=await u.from("locations").select("id, location_name, address, municipality, cabinet_count, license_fee, service_agreement, install_date, etablert_dato, pris_per_plass, antall_plasser, status").eq("customer_id",a).order("location_name");if(r)throw r;return s||[]},enabled:!!a}),[I,V]=x.useState(new Set),[A,P]=x.useState(!1);x.useEffect(()=>{!A&&f.length>0&&(V(new Set(f.filter(s=>s.status==="active").map(s=>s.id))),P(!0))},[f,A]);const Q=s=>{V(r=>{const n=new Set(r);return n.has(s)?n.delete(s):n.add(s),n})},ge=s=>{V(r=>{const n=new Set(r);for(const i of f)i.status!=="active"&&(s?n.add(i.id):n.delete(i.id));return n})},_e=f.filter(s=>s.status!=="active").every(s=>I.has(s.id)),ke=f.some(s=>s.status!=="active"),K=x.useMemo(()=>f.filter(s=>I.has(s.id)),[f,I]),{data:Y=[]}=$({queryKey:["service-agreements-customer",a],queryFn:async()=>{const{data:s,error:r}=await u.from("service_agreements").select("id, startdato, varighet_ar, opsjon_ar, status, mal_versjon, versjon_nr, customer_document_id, created_at, updated_at, godkjent_av_kunde_at, godkjent_av_kunde_navn, godkjent_av_bikely_at, godkjent_av_bikely_navn").eq("customer_id",a).order("created_at",{ascending:!1});if(r)throw r;return s||[]},enabled:!!a}),R=Y.map(s=>s.customer_document_id).filter(Boolean),{data:ne={}}=$({queryKey:["sa-docs",a,R.join(",")],queryFn:async()=>{if(R.length===0)return{};const{data:s,error:r}=await u.from("customer_documents").select("id, file_path, file_name, created_at").in("id",R);if(r)throw r;return Object.fromEntries((s||[]).map(n=>[n.id,n]))},enabled:R.length>0}),E=x.useMemo(()=>K.map(s=>{const r=Number(s.cabinet_count)||0,n=Number(s.license_fee)||0,i=Number(s.service_agreement)||0,d=n*r*12,k=i;return{...s,doors:r,licPerDoorMnd:n,slaArlig:i,lic:d,sla:k,sum:d+k}}),[K]),T=x.useMemo(()=>{const s=E.reduce((k,v)=>k+v.doors,0),r=E.reduce((k,v)=>k+v.lic,0),n=E.reduce((k,v)=>k+v.sla,0),i=t.startdato?new Date(t.startdato):null,d=i?new Date(i):null;return d&&d.setFullYear(d.getFullYear()+Number(t.varighet_ar)),{antall:K.length,sumDorer:s,sumLisens:r,sumSla:n,sumArlig:r+n,startStr:i?O(i.toISOString()):"—",sluttStr:d?O(d.toISOString()):"—"}},[E,t.startdato,t.varighet_ar,K.length]),l=(s,r)=>N(n=>({...n,[s]:r})),ie=()=>({customer_id:a,startdato:t.startdato,varighet_ar:Number(t.varighet_ar),opsjon_ar:Number(t.opsjon_ar),oppsigelsestid_mnd:Number(t.oppsigelsestid_mnd
1)||3,kunde_kontakt_navn:t.kunde_kontakt_navn||null,kunde_kontakt_tittel:t.kunde_kontakt_tittel||null,kunde_kontakt_epost:t.kunde_kontakt_epost||null,kunde_kontakt_telefon:t.kunde_kontakt_telefon||null,kunde_kontakt_drift_navn:t.kunde_kontakt_drift_navn||null,kunde_kontakt_drift_epost:t.kunde_kontakt_drift_epost||null,kunde_kontakt_drift_telefon:t.kunde_kontakt_drift_telefon||null,kunde_ordrereferanse:t.kunde_ordrereferanse||null,kunde_fakturakontakt_navn:t.kunde_fakturakontakt_navn||null,kunde_fakturakontakt_epost:t.kunde_fakturakontakt_epost||null,kunde_organisasjonsnummer:t.kunde_organisasjonsnummer||null,kunde_fakturaadresse:t.kunde_fakturaadresse||null,pris_arlig_per_dor_nok:Ue(t.pris_arlig_per_dor_nok),transport_inkludert:t.transport_inkludert==="true",fakturafrekvens:t.fakturafrekvens,betalingsfrist_dager:Number(t.betalingsfrist_dager)||30,faktura_kommentar:t.faktura_kommentar||null,notater:t.notater||null,mal_versjon:"v3.1",appendix1_kommentar:t.appendix1_kommentar||null,appendix2_overrides:t.appendix2_overrides.rows&&t.appendix2_overrides.rows.length>0||t.appendix2_overrides.reise_kommentar?t.appendix2_overrides:null,appendix4_versjonlogg:t.appendix4_versjonlogg.length>0?t.appendix4_versjonlogg:null,included_location_ids:Array.from(I)}),ve=async()=>{var s;if(a){L(!0),w(null);try{const r="https://mmachrwtepvcjiiqscsd.supabase.co",{data:n}=await u.auth.getSession(),i=(s=n.session)==null?void 0:s.access_token,d=await fetch(`${r}/functions/v1/preview-service-agreement`,{method:"POST",headers:{"Content-Type":"application/json",...i?{Authorization:`Bearer ${i}`}:{},apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im1tYWNocnd0ZXB2Y2ppaXFzY3NkIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njg1NTAzNDQsImV4cCI6MjA4NDEyNjM0NH0.dy4rPJiuAZRhn3q8L_Qchqi5QxZ-0CMIjKczEfi9jX4"},body:JSON.stringify({customer_id:a,agreement:ie()})});if(!d.ok){const v=await d.text();throw new Error(`HTTP ${d.status}: ${v}`)}const k=await d.arrayBuffer();w(new Uint8Array(k))}catch(r){g.error(`Preview feilet: ${(r==null?void 0:r.message)||r}`,{duration:1e4})}finally{L(!1)}}},he=async()=>{var s;if(!t.startdato)return g.error("Startdato er påkrevd");if(a){C(!0);try{const r=ie(),{included_location_ids:n,...i}=r,{data:d}=await u.from("service_agreements").select("id, godkjent_av_kunde_at, godkjent_av_bikely_at").eq("customer_id",a).order("created_at",{ascending:!1}).limit(1).maybeSingle(),k=!!(d!=null&&d.godkjent_av_kunde_at&&(d!=null&&d.godkjent_av_bikely_at));let v;if(d&&!k){const{error:h}=await u.from("service_agreements").update(i).eq("id",d.id);if(h)throw new Error(h.message);v=d.id}else{const{data:h,error:F}=await u.from("service_agreements").insert(i).select().single();if(F||!h)throw new Error((F==null?void 0:F.message)||"Kunne ikke opprette avtale");v=h.id}const{data:q,error:W}=await u.functions.invoke("generate-service-agreement",{body:{agreement_id:v,included_location_ids:n}});if(W){const h=W.context;let F="";try{const de=await((s=h==null?void 0:h.text)==null?void 0:s.call(h));F=de?` — ${de}`:""}catch{}throw new Error(`Edge function feilet (HTTP ${(h==null?void 0:h.status)??"?"})${F}: ${W.message}`)}if(q!=null&&q.error)throw new Error(q.error);g.success(d&&!k?"Avtalen er oppdatert (samme versjon)":"Ny versjon av serviceavtale generert"),_.invalidateQueries({queryKey:["service-agreements-customer",a]}),_.invalidateQueries({queryKey:["service-agreement-latest",a]}),_.invalidateQueries({queryKey:["service-agreements-all"]})}catch(r){g.error((r==null?void 0:r.message)||"Generering feilet",{duration:1e4})}finally{C(!1)}}},oe=async(s,r)=>{if(!s)return g.error("Dokument mangler");const n=ne[s];if(!n)return g.error("Fant ikke filen");const{data:i,error:d}=await u.storage.from("customer-documents").createSignedUrl(n.file_path,600);if(d)return g.error(`Kunne ikke åpne: ${d.message}`);window.open(i.signedUrl,"_blank")},je=async(s,r)=>{const n={status:r};n.sendt_at=new Date().toISOString();const{error:i}=await u.from("service_agreements").update(n).eq("id",s);if(i)return g.error(i.message);g.success(`Merket som ${pe(r).toLowerCase()}
1`),_.invalidateQueries({queryKey:["service-agreements-customer",a]}),_.invalidateQueries({queryKey:["service-agreements-all"]})},fe=async s=>{var v,q;const{data:r}=await u.auth.getSession(),n=((q=(v=r.session)==null?void 0:v.user)==null?void 0:q.email)||"",i=prompt("Navn på godkjenner (Bikely):",n);if(!i)return;const{error:d}=await u.from("service_agreements").update({godkjent_av_bikely_at:new Date().toISOString(),godkjent_av_bikely_navn:i,godkjent_av_bikely_epost:n}).eq("id",s);if(d)return g.error(d.message);const{error:k}=await u.functions.invoke("generate-service-agreement",{body:{agreement_id:s,included_location_ids:Array.from(I),skip_log_entry:!0}});k?g.error(`Godkjent, men regenerering feilet: ${k.message}`):g.success("Godkjent som Bikely – PDF regenerert"),_.invalidateQueries({queryKey:["service-agreements-customer",a]}),_.invalidateQueries({queryKey:["service-agreements-all"]})},Ne=async s=>{if(s.godkjent_av_kunde_at||s.godkjent_av_bikely_at)return g.error("Kan ikke slette: avtalen er allerede signert av minst én part");if(confirm(`Slette avtaleversjon v${s.versjon_nr??1}? Dette fjerner også PDF-en fra kundeportalen.`))try{if(s.customer_document_id){const{data:n}=await u.from("customer_documents").select("file_path").eq("id",s.customer_document_id).maybeSingle();n!=null&&n.file_path&&await u.storage.from("customer-documents").remove([n.file_path]),await u.from("customer_documents").delete().eq("id",s.customer_document_id)}const{error:r}=await u.from("service_agreements").delete().eq("id",s.id);if(r)throw r;g.success("Avtaleversjon slettet"),_.invalidateQueries({queryKey:["service-agreements-customer",a]}),_.invalidateQueries({queryKey:["service-agreements-all"]}),_.invalidateQueries({queryKey:["customer-documents",a]})}catch(r){g.error((r==null?void 0:r.message)||"Sletting feilet")}};return e.jsx(De,{children:e.jsxs("div",{className:"min-h-screen flex w-full",children:[e.jsx(Ie,{}),e.jsxs(Le,{children:[e.jsx(Pe,{title:"Serviceavtale"}),e.jsxs("main",{className:"p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(j,{asChild:!0,size:"sm",variant:"ghost",children:e.jsxs(X,{to:"/dashboard/customers",children:[e.jsx(Oe,{className:"w-4 h-4 mr-1"})," Tilbake til kunder"]})}),e.jsx(Ve,{className:"w-6 h-6 ml-2"}),e.jsx("h1",{className:"text-2xl",children:(p==null?void 0:p.name)||"..."})]}),e.jsxs(Fe,{defaultValue:"skjema",className:"w-full",children:[e.jsxs(Ae,{children:[e.jsx(ue,{value:"skjema",children:"Skjema"}),e.jsx(ue,{value:"preview",children:"Forhåndsvisning"})]}),e.jsx(xe,{value:"skjema",className:"mt-4",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-4",children:[e.jsxs(G,{children:[e.jsx(U,{children:e.jsx(J,{className:"text-base",children:"Avtaleparametre"})}
1),e.jsxs(H,{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Startdato *"}),e.jsx(m,{type:"date",value:t.startdato,onChange:s=>l("startdato",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Varighet"}),e.jsxs(Z,{value:String(t.varighet_ar),onValueChange:s=>l("varighet_ar",Number(s)),children:[e.jsx(ee,{children:e.jsx(se,{})}),e.jsx(te,{children:[1,2,3,5].map(s=>e.jsxs(re,{value:String(s),children:[s," år"]},s))})]})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Opsjon"}),e.jsxs(Z,{value:String(t.opsjon_ar),onValueChange:s=>l("opsjon_ar",Number(s)),children:[e.jsx(ee,{children:e.jsx(se,{})}),e.jsx(te,{children:[0,1,2].map(s=>e.jsxs(re,{value:String(s),children:[s," år"]},s))})]})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Oppsigelsestid"}),e.jsxs(Z,{value:String(t.oppsigelsestid_mnd),onValueChange:s=>l("oppsigelsestid_mnd",Number(s)),children:[e.jsx(ee,{children:e.jsx(se,{})}),e.jsx(te,{children:[1,3,6].map(s=>e.jsxs(re,{value:String(s),children:[s," mnd"]},s))})]})]})]})]}),e.jsxs(qe,{type:"multiple",defaultValue:["kontakt","priser"],className:"space-y-2",children:[e.jsxs(z,{value:"kontakt",className:"border rounded-lg px-4",children:[e.jsx(B,{className:"text-sm",children:"Kontaktpersoner – kunde"}),e.jsxs(M,{className:"grid grid-cols-2 gap-3",children:[e.jsx("div",{className:"col-span-2 text-xs font-medium text-muted-foreground mt-1",children:"Kontrakt"}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Navn"}),e.jsx(m,{value:t.kunde_kontakt_navn,onChange:s=>l("kunde_kontakt_navn",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Tittel"}),e.jsx(m,{value:t.kunde_kontakt_tittel,onChange:s=>l("kunde_kontakt_tittel",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"E-post"}),e.jsx(m,{type:"email",value:t.kunde_kontakt_epost,onChange:s=>l("kunde_kontakt_epost",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Telefon"}),e.jsx(m,{value:t.kunde_kontakt_telefon,onChange:s=>l("kunde_kontakt_telefon",s.target.value)})]}),e.jsx("div",{className:"col-span-2 text-xs font-medium text-muted-foreground mt-2",children:"Drift"}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Navn"}),e.jsx(m,{value:t.kunde_kontakt_drift_navn,onChange:s=>l("kunde_kontakt_drift_navn",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Telefon"}),e.jsx(m,{value:t.kunde_kontakt_drift_telefon,onChange:s=>l("kunde_kontakt_drift_telefon",s.target.value)})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(c,{className:"text-xs",children:"E-post"}),e.jsx(m,{type:"email",value:t.kunde_kontakt_drift_epost,onChange:s=>l("kunde_kontakt_drift_epost",s.target.value)})]}),e.jsx("div",{className:"col-span-2 text-xs font-medium text-muted-foreground mt-2",children:"Faktura & referanse"}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Fakturakontakt – navn"}),e.jsx(m,{value:t.kunde_fakturakontakt_navn,onChange:s=>l("kunde_fakturakontakt_navn",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Fakturakontakt – e-post"}),e.jsx(m,{type:"email",value:t.kunde_fakturakontakt_epost,onChange:s=>l("kunde_fakturakontakt_epost",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Organisasjonsnr"}),e.jsx(m,{value:t.kunde_organisasjonsnummer,onChange:s=>l("kunde_organisasjonsnummer",s.target.value)})]}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Ordrereferanse (PO)"}),e.jsx(m,{value:t.kunde_ordrereferanse,onChange:s=>l("kunde_ordrereferanse",s.target.value)})]}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(c,{className:"text-xs",children:"Fakturaadresse"}),e.jsx(m,{value:t.kunde_fakturaadresse,onChange:s=>l("kunde_fakturaadresse",s.target.value)})]})]})]}),e.jsxs(z,{value:"lokasjoner",className:"border rounded-lg px-4",children:[e.jsxs(B,{className:"text-sm",children:["Lokasjoner i avtalen (",I.size," / ",f.length,")"]}),e.jsxs(M,{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Velg hvilke lokasjoner som skal med i serviceavtalen. Inaktive lokasjoner er som standard ekskludert."}),ke&&e.jsxs("div",{className:"flex items-center justify-between rounded-md border bg-muted/30 p-2",children:[e.jsx(c,{htmlFor:"incl-inactive",className:"text-xs cursor-pointer",children:"Inkluder alle inaktive lokasjoner"}),e.jsx(Ee,{id:"incl-inactive",checked:_e,onCheckedChange:ge})]}),f.length===0&&e.jsx("p",{className:"text-xs italic text-muted-foreground",children:"Ingen lokasjoner."}),e.jsx("div",{className:"space-y-1",children:f.map(s=>{const r=s.status!=="active",n=I.has(s.id);return e.jsxs("div",{className:`flex items-center gap-2 rounded-md border p-2 text-xs ${r?"bg-muted/20":""}`,children:[e.jsx(Ke,{id:`loc-${s.id}`,checked:n,onCheckedChange:()=>Q(s.id)}),e.jsxs(c,{htmlFor:`loc-${s.id}`,className:"flex-1 cursor-pointer font-normal",children:[e.jsx("span",{className:"font-medium",children:s.location_name||"(uten navn)"}),s.municipality&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",s.municipality]}),s.cabinet_count!=null&&e.jsxs("span",{className:"text-muted-foreground",children:[" · ",s.cabinet_count," dører"]})]}),r&&e.jsx(le,{variant:"outline",className:"text-[10px]",children:"Inaktiv"})]},s.id)})}),e.jsxs("div",{className:"pt-2 border-t",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Overstyringer (Vedlegg 1) – kun valgte"}),K.length===0&&e.jsx("p",{className:"text-xs italic text-muted-foreground",children:"Ingen lokasjoner valgt."}),K.map(s=>e.jsx(Je,{location:s,onSaved:()=>_.invalidateQueries({queryKey:["sa-locations",a]})},s.id))]})]})]}),e.jsxs(z,{value:"priser",className:"border rounded-lg px-4",children:[e.jsx(B,{className:"text-sm",children:"Priser"}),e.jsxs(M,{className:"space-y-4",children:[e.jsx("div",{className:"grid grid-cols-2 gap-3",children:e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Årlig pris per dør (NOK)"}),e.jsx(m,{type:"number",value:t.pris_arlig_per_dor_nok,onChange:s=>l("pris_arlig_per_dor_nok",s.target.value)})]})}),e.jsxs("div",{children:[e.jsx(c,{className:"text-xs mb-2 block",children:"Transport"}),e.jsxs(Te,{value:t.transport_inkludert,onValueChange:s=>l("transport_inkludert",s),className:"flex gap-6",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(me,{value:"true",id:"t-inc"}),e.jsx(c,{htmlFor:"t-inc",className:"text-sm font-normal cursor-pointer",children:"Inkludert i pris"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(me,{value:"false",id:"t-ext"}),e.jsx(c,{htmlFor:"t-ext",className:"text-sm font-normal cursor-pointer",children:"Kommer i tillegg"})]})]})]}),e.jsxs("div",{className:"rounded-md bg-muted/40 p-3 text-xs space-y-1",children:[e.jsx("p",{className:"font-medium text-muted-foreground",children:"Globale verdier (KPI, reservedeler, timepriser)"}),e.jsxs("p",{children:["KPI: ",b(o==null?void 0:o.pris_arlig_indeksregulering_pct)," % · Siste revisjon: ",O(o==null?void 0:o.pris_siste_kpi_revisjon)]}),e.jsxs("p",{children:["Arbeid: kr ",b(o==null?void 0:o.pris_arbeid_per_time_nok),"/t · Transport: kr ",b(o==null?void 0:o.pris_transport_per_time_nok),"/t · Reise: kr ",b(o==null?void 0:o.pris_reise_per_km_nok),"/km"]}),e.jsx(X,{to:"/dashboard/service-agreement-settings",className:"text-primary hover:underline",children:"Rediger globale innstillinger →"})]})]})]}),e.jsxs(z,{value:"vedlegg",className:"border rounded-lg px-4",children:[e.jsx(B,{className:"text-sm",children:"Vedlegg (appendixer)"}),e.jsxs(M,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(c,{className:"text-xs",children:"Vedlegg 1 – kommentar / annet"}),e.jsx(ce,{rows:2,placeholder:"Transporttid og kjøregodtgjørelse ikke inkludert. Alle priser i avtalen er eks MVA.",value:t.appendix1_kommentar,onChange:s=>l("appendix1_kommentar",s.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(c,{className:"text-xs",children:"Vedlegg 2 – timepriser (overstyring)"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(j,{size:"sm",variant:"ghost",type:"button",onClick:()=>l("appendix2_overrides",{rows:[{type:"Prosjektering/Engineering",timepris:`${(o==null?void 0:o.pris_prosjektering_per_time_nok)??1450} kr/t`},{type:"Utforming av ekstra folie",timepris:`${(o==null?void 0:o.pris_folie_per_time_nok)??1450} kr/t`},{type:"Tekniker Bikely",timepris:`${(o==null?void 0:o.pris_transport_per_time_nok)??1085} kr/t`}
1,{type:"Reiseutgifter",timepris:(o==null?void 0:o.pris_reise_kommentar)||"områdespesifikt / etter avtale"}],reise_kommentar:t.appendix2_overrides.reise_kommentar}),children:"Forhåndsutfyll fra globalt"}),e.jsx(j,{size:"sm",variant:"outline",type:"button",onClick:()=>l("appendix2_overrides",{...t.appendix2_overrides,rows:[...t.appendix2_overrides.rows,{type:"",timepris:""}]}),children:"+ rad"})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Tomt = bruker globale timepriser fra innstillinger."}),t.appendix2_overrides.rows.map((s,r)=>e.jsxs("div",{className:"grid grid-cols-[1fr_140px_auto] gap-2 items-center",children:[e.jsx(m,{className:"h-8 text-xs",placeholder:"Type",value:s.type,onChange:n=>{const i=[...t.appendix2_overrides.rows];i[r]={...i[r],type:n.target.value},l("appendix2_overrides",{...t.appendix2_overrides,rows:i})}}),e.jsx(m,{className:"h-8 text-xs",placeholder:"Timepris",value:s.timepris,onChange:n=>{const i=[...t.appendix2_overrides.rows];i[r]={...i[r],timepris:n.target.value},l("appendix2_overrides",{...t.appendix2_overrides,rows:i})}}),e.jsx(j,{size:"sm",variant:"ghost",type:"button",onClick:()=>{const n=t.appendix2_overrides.rows.filter((i,d)=>d!==r);l("appendix2_overrides",{...t.appendix2_overrides,rows:n})},children:"Slett"})]},r))]}),e.jsxs("div",{className:"rounded-md bg-muted/40 p-3 text-xs",children:[e.jsx("p",{className:"font-medium text-muted-foreground mb-1",children:"Vedlegg 3 – reservedeler"}),e.jsx("p",{children:"Styres globalt for alle avtaler i innstillinger."}),e.jsx(X,{to:"/dashboard/service-agreement-settings",className:"text-primary hover:underline",children:"Rediger globalt →"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(c,{className:"text-xs",children:"Vedlegg 4 – versjonlogg (overstyring)"}),e.jsx(j,{size:"sm",variant:"outline",type:"button",onClick:()=>l("appendix4_versjonlogg",[...t.appendix4_versjonlogg,{versjon:"",dato:"",endring:""}]),children:"+ rad"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Tomt = bruker standard versjonlogg."}),t.appendix4_versjonlogg.map((s,r)=>e.jsxs("div",{className:"grid grid-cols-[1fr_120px_2fr_auto] gap-2 items-center",children:[e.jsx(m,{className:"h-8 text-xs",placeholder:"Versjon",value:s.versjon,onChange:n=>{const i=[...t.appendix4_versjonlogg];i[r]={...i[r],versjon:n.target.value},l("appendix4_versjonlogg",i)}}),e.jsx(m,{className:"h-8 text-xs",placeholder:"Dato",value:s.dato,onChange:n=>{const i=[...t.appendix4_versjonlogg];i[r]={...i[r],dato:n.target.value},l("appendix4_versjonlogg",i)}}),e.jsx(m,{className:"h-8 text-xs",placeholder:"Endring",value:s.endring,onChange:n=>{const i=[...t.appendix4_versjonlogg];i[r]={...i[r],endring:n.target.value},l("appendix4_versjonlogg",i)}}),e.jsx(j,{size:"sm",variant:"ghost",type:"button",onClick:()=>l("appendix4_versjonlogg",t.appendix4_versjonlogg.filter((n,i)=>i!==r)),children:"Slett"})]},r))]})]})]}),e.jsxs(z,{value:"notater",className:"border rounded-lg px-4",children:[e.jsx(B,{className:"text-sm",children:"Interne notater"}),e.jsx(M,{children:e.jsx(ce,{value:t.notater,onChange:s=>l("notater",s.target.value),rows:4})})]})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs(G,{children:[e.jsx(U,{children:e.jsx(J,{className:"text-base",children:"Sammendrag"})}
1),e.jsxs(H,{className:"space-y-2 text-xs",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Kunde:"}),e.jsx("span",{className:"font-medium",children:(p==null?void 0:p.name)||"—"})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Periode:"}),e.jsxs("span",{children:[T.startStr," – ",T.sluttStr]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Lokasjoner:"}),e.jsxs("span",{children:[T.antall," · ",T.sumDorer," dører"]})]}),e.jsx("div",{className:"border-t my-2 pt-2 space-y-1",children:E.length===0?e.jsx("p",{className:"text-muted-foreground italic",children:"Ingen aktive lokasjoner"}):E.map(s=>e.jsxs("div",{className:"border rounded p-2 space-y-0.5",children:[e.jsxs("p",{className:"font-medium",children:[s.location_name||"(uten navn)"," ",e.jsxs("span",{className:"text-muted-foreground",children:["· ",s.doors," dører"]})]}),e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsxs("span",{children:["Lisens: ",s.doors," × kr ",b(s.licPerDoorMnd),"/mnd × 12"]}),e.jsxs("span",{children:["kr ",b(s.lic)]})]}),e.jsxs("div",{className:"flex justify-between text-muted-foreground",children:[e.jsx("span",{children:"SLA (årlig per lokasjon)"}),e.jsxs("span",{children:["kr ",b(s.sla)]})]}),e.jsxs("div",{className:"flex justify-between font-medium border-t pt-0.5",children:[e.jsx("span",{children:"Sum/år"}),e.jsxs("span",{children:["kr ",b(s.sum)]})]})]},s.id))}),e.jsxs("div",{className:"border-t pt-2 space-y-1",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Total lisens/år:"}),e.jsxs("span",{children:["kr ",b(T.sumLisens)]})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("span",{className:"text-muted-foreground",children:"Total SLA/år:"}),e.jsxs("span",{children:["kr ",b(T.sumSla)]})]}),e.jsxs("div",{className:"flex justify-between text-sm font-bold pt-1 border-t",children:[e.jsx("span",{children:"Sum årlig:"}),e.jsxs("span",{children:["kr ",b(T.sumArlig)]})]})]})]})]}),e.jsx(j,{className:"w-full",onClick:he,disabled:D||!t.startdato,children:D?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-4 h-4 mr-2 animate-spin"})," Genererer..."]}):"Generer serviceavtale (PDF)"}),e.jsxs(G,{children:[e.jsx(U,{children:e.jsx(J,{className:"text-base",children:"Tidligere avtaler"})}),e.jsx(H,{children:Y.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ingen avtaler ennå."}):e.jsx("div",{className:"space-y-2",children:Y.map(s=>{var r;return e.jsxs("div",{className:"border rounded p-2 text-xs space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"font-medium",children:[O(s.startdato)," ",e.jsxs("span",{className:"text-muted-foreground",children:["· v",s.versjon_nr??1]})]}),e.jsx(le,{variant:Ge(s.status),className:"text-[10px]",children:pe(s.status)})]}),e.jsxs("p",{className:"text-muted-foreground",children:[s.varighet_ar," år · mal ",s.mal_versjon]}),e.jsxs("p",{className:"text-muted-foreground",children:["Generert: ",Re(((r=ne[s.customer_document_id])==null?void 0:r.created_at)||s.updated_at||s.created_at)]}),e.jsxs("div",{className:"grid grid-cols-2 gap-1 text-[11px]",children:[e.jsx("div",{className:s.godkjent_av_kunde_at?"text-emerald-700":"text-muted-foreground",children:s.godkjent_av_kunde_at?`✓ Kunde: ${s.godkjent_av_kunde_navn||""} (${O(s.godkjent_av_kunde_at)})`:"Kunde: venter"}),e.jsx("div",{className:s.godkjent_av_bikely_at?"text-emerald-700":"text-muted-foreground",children:s.godkjent_av_bikely_at?`✓ Bikely: ${s.godkjent_av_bikely_navn||""} (${O(s.godkjent_av_bikely_at)})`:"Bikely: venter"})]}),e.jsxs("div",{className:"flex flex-wrap gap-1 pt-1",children:[e.jsxs(j,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",disabled:!s.customer_document_id,onClick:()=>oe(s.customer_document_id),children:[e.jsx($e,{className:"w-3 h-3 mr-1"})," Vis"]}),e.jsxs(j,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",disabled:!s.customer_document_id,onClick:()=>oe(s.customer_document_id),children:[e.jsx(ze,{className:"w-3 h-3 mr-1"})," Last ned"]}),s.status==="draft"&&e.jsx(j,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs",onClick:()=>je(s.id,"sent"),children:"Merk sendt"}),!s.godkjent_av_bikely_at&&e.jsx(j,{size:"sm",variant:"outline",className:"h-6 px-2 text-xs",onClick:()=>fe(s.id),children:"Godkjenn som Bikely"}),!s.godkjent_av_kunde_at&&!s.godkjent_av_bikely_at&&e.jsxs(j,{size:"sm",variant:"ghost",className:"h-6 px-2 text-xs text-destructive hover:text-destructive hover:bg-destructive/10",onClick:()=>Ne(s),children:[e.jsx(Be,{className:"w-3 h-3 mr-1"})," Slett"]})]})]},s.id)})})})]})]})]})}),e.jsx(xe,{value:"preview",className:"mt-4",children:e.jsxs(G,{children:[e.jsxs(U,{className:"flex flex-row items-center justify-between",children:[e.jsx(J,{className:"text-base",children:"Forhåndsvisning (PDF)"}),e.jsx(j,{size:"sm",onClick:ve,disabled:S,children:S?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-4 h-4 mr-2 animate-spin"})," Bygger..."]}
1):e.jsxs(e.Fragment,{children:[e.jsx(Me,{className:"w-4 h-4 mr-2"})," Oppdater forhåndsvisning"]})})]}),e.jsx(H,{children:y?e.jsx(He,{data:y}):e.jsx("div",{className:"h-[800px] border rounded flex items-center justify-center text-sm text-muted-foreground",children:'Klikk "Oppdater forhåndsvisning" for å bygge PDF-en'})})]})})]})]})]})]})})}export{Zs 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.