1import{d as ne,u as le,g as e,o as r,c as d,F as U,e as re,p as B,b as t,t as a,z as Ee,h as p,q as je,K as Se,L as Ae,b6 as ae,a as De,s as Me,f as u,_ as Ke,y as m,w as h,v as w,m as y,N as Ne,I as L,l as P,Y as ie,j as Re}from"./BD8pidEa.js";import{_ as Pe}from"./Bk8aYtze.js";import{_ as Oe}from"./BmV3vp-X.js";import{_ as Te}from"./rnxw8XHF.js";import{_ as Ve}from"./CdxGiw-B.js";import{_ as ze}from"./WKiMrynA.js";import{_ as Ie}from"./CjLby7_a.js";import{u as Le,_ as Ue}from"./cNRNXz0m.js";import{a as Be}from"./D5Fe4I0v.js";import{f as qe}from"./oImBWf_C.js";import"./Cf1gkL7T.js";import"./DlAUqK2U.js";const Fe={key:0,class:"space-y-1 whitespace-normal","data-testid":"payment-limitations-list"},Je={class:"inline font-medium normal-case"},He={class:"text-body/70 ml-1 inline"},Ye={key:1,class:"text-body/50"},Ze=ne({__name:"PaymentLimitations",props:{limitations:{}},setup(Q){const $=Q,{$t:D}=le(),o=l=>l.replace(/([a-z\d])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").trim().replace(/^./,x=>x.toUpperCase()).replace(/\bids\b/gi,"IDs"),_=l=>l==null||l===""?"â":typeof l=="boolean"?D(l?"Yes":"No"):Array.isArray(l)?l.length?l.map(_).join(", "):"â":typeof l=="object"?Object.entries(l).map(([x,f])=>`${o(x)}: ${_(f)}`).join(", "):String(l),q=l=>{if(typeof l=="string")try{const x=JSON.parse(l);return x&&typeof x=="object"&&!Array.isArray(x)?x:null}catch{return null}return l&&typeof l=="object"&&!Array.isArray(l)?l:null},C=B(()=>{const l=q($.limitations);return l?Object.entries(l).map(([x,f])=>({key:x,label:o(x),value:_(f)})):[]});return(l,x)=>e(C).length?(r(),d("dl",Fe,[(r(!0),d(U,null,re(e(C),f=>(r(),d("div",{key:f.key,class:"break-words leading-snug","data-testid":"payment-limitation"},[t("dt",Je,a(f.label)+":",1),t("dd",He,a(f.value),1)]))),128))])):(r(),d("span",Ye,"â"))}}),Ge=Object.assign(Ze,{__name:"SchoolPaymentLimitations"}),We={class:"grow py-5 pl-4 pr-4 lg:p-8"},Qe={class:"mb-6 flex items-center justify-between"},Xe={class:"title1"},et={class:"flex items-center gap-2"},tt={class:"mb-6 grid gap-4 xl:h-56 xl:grid-cols-2 xl:items-stretch"},st={class:"stat px-4 py-3 xl:!grid-cols-[auto_minmax(0,1fr)_auto] xl:items-center xl:gap-3"},ot={class:"stat-figure text-black xl:!col-start-1 xl:!row-start-1 xl:!row-span-1 xl:justify-self-start"},at={class:"stat-title flex items-center gap-1 text-black xl:!col-start-2 xl:!row-start-1 xl:min-w-0"},it={class:"stat-value text-primary text-2xl xl:!col-start-3 xl:!row-start-1 xl:justify-self-end"},nt={class:"stat px-4 py-3 xl:!grid-cols-[auto_minmax(0,1fr)_auto] xl:items-center xl:gap-3"},lt={class:"stat-figure text-black xl:!col-start-1 xl:!row-start-1 xl:!row-span-1 xl:justify-self-start"},rt={class:"stat-title flex items-center gap-1 text-black xl:!col-start-2 xl:!row-start-1 xl:min-w-0"},dt={class:"stat-value text-secondary text-2xl xl:!col-start-3 xl:!row-start-1 xl:justify-self-end"},ct={class:"stat px-4 py-3 xl:!grid-cols-[auto_minmax(0,1fr)_auto] xl:items-center xl:gap-3"},ut={class:"stat-figure text-black xl:!col-start-1 xl:!row-start-1 xl:!row-span-1 xl:justify-self-start"},mt={class:"stat-title flex items-center gap-1 text-black xl:!col-start-2 xl:!row-start-1 xl:min-w-0"},pt={class:"stat-value text-secondary text-2xl xl:!col-start-3 xl:!row-start-1 xl:justify-self-end"},ht={class:"border-body/10 flex min-w-0 flex-col overflow-hidden rounded-md border xl:h-56","data-testid":"credit-expiries-panel"},xt={class:"border-body/10 flex flex-wrap items-center justify-between gap-3 border-b px-3 py-2"},_t={class:"flex min-w-0 flex-wrap items-center gap-2"},gt={class:"text-sm font-semibold"},bt={class:"badge badge-ghost badge-sm h-auto whitespace-normal py-1 text-center leading-snug"},ft={key:0,class:"text-body/60 text-sm"},vt={key:0,class:"flex flex-1 items-center justify-center"},yt={key:1,class:"min-h-0 flex-1 overflow-y-auto"},kt={class:"border-body/10 bg-base-100 text-body/60 sticky top-0 grid grid-cols-[minmax(0,10rem)_5rem_minmax(7rem,1fr)_8rem] gap-2 border-b px-3 py-1.5 text-xs font-semibold uppercase"},wt={class:"pr-3 text-right"},Ct={class:"pr-3 text-right font-semibold"},$t={class:"text-body/70 flex min-w-0 items-center gap-2"},Et={key:0,class:"badge badge-sm border-base-300 bg-base-300 text-body/70 shrink-0"},jt={class:"truncate"},St=["data-testid","onClick"],At={key:1},Dt={key:2,class:"text-body/60 flex flex-1 items-center px-3 py-4 text-sm"},Mt={class:"border-body/10 mb-9 flex items-center justify-between gap-2 border-b py-2"},Kt={class:"flex flex-auto gap-5 items-center"},Nt={class:"flex items-center gap-2 cursor-pointer"},Rt={class:"flex gap-2"},Pt={class:"whitespace-nowrap"},Ot={class:"whitespace-nowrap"},Tt=["data-testid","onClick"],Vt={class:"flex flex-col gap-4"},zt={class:"form-group"},It={class:"form-group"},Lt={class:"mt-4 flex justify-end gap-3"},Ut=["disabled"],Bt={class:"leading-7 text-body/80"},qt={class:"mt-4 rounded-xl bg-base-200 p-4 text-sm leading-6"},Ft={key:0,class:"flex items-center gap-2 text-body/70","data-testid":"archive-school-eligibility-loading"},Jt={key:1,"data-testid":"archive-school-registration-count"},Ht={key:2,class:"text-danger","data-testid":"archive-school-eligibility-error"},Yt={key:0,class:"mt-3 text-sm text-danger"},Zt={key:1,class:"mt-4 rounded-xl bg-danger/10 p-4 text-sm leading-6 text-body/80","data-testid":"archive-school-error"}
1,Gt={class:"mt-8 flex justify-end gap-3"},Wt=["disabled"],Qt={class:"leading-7 text-body/80"},Xt={class:"mt-3 text-sm text-body/70"},es={key:0,class:"mt-4 rounded-xl bg-danger/10 p-4 text-sm text-danger","data-testid":"expire-school-credits-error"},ts={class:"mt-8 flex justify-end gap-3"},ss=["disabled"],os=["disabled"],as={key:0,class:"loading loading-spinner loading-xs"},bs=ne({__name:"index",async setup(Q){let $,D;const{$t:o,$toast:_}=le(),q=Ee(),C=p(q.query.search||""),l=p(!1),x=[{text:o("Name"),value:"name",sortable:!0,width:100},{text:o("Payer"),value:"default_payer",width:80},{text:o("Students"),value:"_count.students",sortable:!0,width:20},{text:o("School Reps"),value:"_count.school_reps",sortable:!0,width:20},{text:o("Credits"),value:"credits",sortable:!0,width:20},{text:o("Seat price"),value:"seat_price",sortable:!0,width:20},{text:o("Payment info"),value:"payment_condition_text",sortable:!0,width:300},{text:o("Limitations"),value:"payment_limitations",sortable:!0,width:150},{text:"",value:"actions",width:24}],f=B(()=>de.value?.schools||[]),X=i=>{_.warning(i?.message||o("An error occurred"))},{data:de,error:F,refresh:J}=([$,D]=je(()=>Re("/api/v1/schools",{query:B(()=>({fields:"id,name,default_payer,counts,payment_condition_text,payment_limitations,credits,seat_price",partner_only:l.value?"true":void 0}))},"$-PNobKJgOH")),$=await $,D(),$);F.value&&(Se(F.value),Ae(F.value));const{data:O,pending:ce,refresh:ue}=ae("/api/v1/schools/dashboard","$WGr2Kzd8-h"),{data:me,pending:pe,refresh:he}=ae("/api/v1/schools/credit-expiries","$0nMO6wTmZE"),T=p(!0),V=B(()=>[...me.value?.expiries||[]].sort((i,s)=>(i.status==="OVERDUE"?0:1)-(s.status==="OVERDUE"?0:1)||new Date(i.earliestExpiry).getTime()-new Date(s.earliestExpiry).getTime()||s.expiringCredits-i.expiringCredits||i.schoolName.localeCompare(s.schoolName))),H=i=>qe(new Date(i),"dd.MM.yyyy"),ee=i=>{const s=new Date(i.earliestExpiry),c=new Date(i.latestExpiry);return s.getTime()===c.getTime()?H(s):`${H(s)} - ${H(c)}`},{openModal:g}=Le(),E=p(""),j=p(""),Y=p(!1),v=p(null),b=p(null),M=p(!1),z=p(""),Z=p(!1),S=p(""),k=p(null),K=p(!1),A=p(""),xe=()=>{E.value="",j.value="",g.value="add-school"},_e=async()=>{const i=E.value.trim(),s=j.value.trim();if(!i||!s)return _.error("Kooli nimi ja registrikood on kohustuslikud");if(!/^\d+$/.test(s))return _.error("Registrikood peab koosnema ainult numbritest");Y.value=!0;try{await $fetch("/api/v1/schools",{method:"POST",body:{name:i,registration_code:s}}),await J(),g.value=null,_.success("Kool on lisatud")}catch(c){_.error(c?.data?.message??"Kooli lisamine ebaõnnestus")}finally{Y.value=!1}},te=()=>{v.value=null,b.value=null,M.value=!1,z.value="",S.value=""},se=()=>{g.value=null,te()},ge=async(i,s)=>{v.value={id:i,name:s},b.value=null,z.value="",S.value="",M.value=!0,g.value="archive-school";try{const c=await $fetch(`/api/v1/schools/${i}/archive`);v.value?.id===i&&(b.value=c)}catch(c){v.value?.id===i&&(z.value=c?.data?.message??"Registreerumiste kontrollimine ebaõnnestus")}finally{v.value?.id===i&&(M.value=!1)}},be=async()=>{if(!(!v.value||!b.value?.canArchive)){Z.value=!0,S.value="";try{await $fetch(`/api/v1/schools/${v.value.id}/archive`,{method:"POST"}),await J(),se(),_.success("Kool on arhiveeritud")}catch(i){const s=i?.data?.data?.recentRegistrations;typeof s=="number"&&(b.value={recentRegistrations:s,canArchive:!1}),S.value=i?.data?.message??"Kooli arhiveerimine ebaõnnestus"}finally{Z.value=!1}}},fe=i=>{k.value=i,A.value="",g.value="expire-school-credits"},G=()=>{g.value=null,k.value=null,A.value=""},ve=async()=>{if(k.value){K.value=!0,A.value="";try{const i=await $fetch(`/api/v1/schools/${k.value.schoolId}/expire-credits`,{method:"POST"});await Promise.all([he(),ue(),J()]),G(),i.expiredCredits>0?_.success(`${i.expiredCredits} krediidi aegumine kanti logisse`):_.info("Aegumiskannet ei olnud vaja lisada")}catch(i){A.value=i?.data?.message??"Krediitide aegumine ebaõnnestus"}finally{K.value=!1}}};return De({title:o("Schools")}),(i,s)=>{const c=Ke,ye=Pe,I=Oe,ke=Te,oe=Ve,we=Ge,Ce=ze,$e=Ie,W=Ue,N=Me("tooltip");return r(),d("main",We,[t("div",Qe,[t("h1",Xe,a(e(o)("Schools")),1),t("div",et,[t("button",{class:"btn btn-ghost btn-sm gap-1",onClick:s[0]||(s[0]=n=>T.value=!e(T))},[u(c,{name:e(T)?"bi:chevron-up":"bi:chevron-down",size:"16"},null,8,["name"]),m(" "+a(e(o)("Dashboard")),1)]),t("button",{class:"btn btn-secondary btn-sm gap-1","data-testid":"add-school-button",onClick:xe},[u(c,{name:"bi:plus",size:"16"}),s[6]||(s[6]=m(" Lisa kool ",-1))])])]),t("div",tt,[u(ye,{open:e(T),loading:e(ce),show:!!e(O),compact:"","wide-vertical":""},{default:h(()=>[t("div",st,[t("div",ot,[u(c,{name:"bi:building",size:"20"})]),t("div",at,[m(a(e(o)("Partner Schools"))+" ",1),w(u(c,{name:"bi:info-circle",size:"14",class:"cursor-help opacity-60"},null,512),[[N,e(o)("Schools whose students do not need to pay with a subscription â the school pays using credits.")]])]),t("div",it,a(e(O).partner
1SchoolCount),1)]),t("div",nt,[t("div",lt,[u(c,{name:"bi:credit-card-2-front",size:"20"})]),t("div",rt,[m(a(e(o)("Credits in Use"))+" ",1),w(u(c,{name:"bi:info-circle",size:"14",class:"cursor-help opacity-60"},null,512),[[N,e(o)("Credits tied to registrations that are currently in Registered, In Progress, or Awaiting Result status.")]])]),t("div",dt,a(e(O).creditsInUse),1)]),t("div",ct,[t("div",ut,[u(c,{name:"bi:wallet2",size:"20"})]),t("div",mt,[m(a(e(o)("Credit Balance"))+" ",1),w(u(c,{name:"bi:info-circle",size:"14",class:"cursor-help opacity-60"},null,512),[[N,e(o)("Total credits currently not tied to any registration â available to allocate.")]])]),t("div",pt,a(e(O).creditBalance),1)])]),_:1},8,["open","loading","show"]),t("section",ht,[t("div",xt,[t("div",_t,[u(c,{name:"bi:calendar-event",size:"16",class:"text-success"}),t("h2",gt,a(e(o)("Upcoming credit expiries")),1),t("span",bt,a(e(o)("Overdue + next 12 months")),1)]),e(V).length?(r(),d("span",ft,a(e(o)("Entries"))+": "+a(e(V).length),1)):y("",!0)]),e(pe)?(r(),d("div",vt,[...s[7]||(s[7]=[t("span",{class:"loading loading-dots loading-md"},null,-1)])])):e(V).length?(r(),d("div",yt,[t("div",kt,[t("span",null,a(e(o)("School")),1),t("span",wt,a(e(o)("Credits")),1),t("span",null,a(e(o)("Expiring")),1),s[8]||(s[8]=t("span",null,null,-1))]),(r(!0),d(U,null,re(e(V),n=>(r(),d("div",{key:`${n.schoolId}-${n.status}`,class:"border-body/10 hover:bg-base-200 grid grid-cols-[minmax(0,10rem)_5rem_minmax(7rem,1fr)_8rem] items-center gap-2 border-b px-3 py-2 text-sm last:border-b-0"},[u(I,{to:`/manage/schools/${n.schoolId}/credits`,class:"truncate font-medium underline"},{default:h(()=>[m(a(n.schoolName),1)]),_:2},1032,["to"]),t("span",Ct,a(n.expiringCredits),1),t("span",$t,[n.status==="OVERDUE"?(r(),d("span",Et," Juba aegunud ")):y("",!0),t("span",jt,a(ee(n)),1)]),n.status==="OVERDUE"?(r(),d("button",{key:0,type:"button",class:"btn btn-error bt
1n-xs h-auto min-h-0 px-2 py-2 text-white","data-testid":`expire-school-credits-${n.schoolId}`,onClick:R=>fe(n)}," Märgi aegunuks ",8,St)):(r(),d("span",At))]))),128))])):(r(),d("div",Dt,a(e(o)("No upcoming credit expiries")),1))])]),t("aside",Mt,[t("div",Kt,[t("label",Nt,[w(t("input",{"onUpdate:modelValue":s[1]||(s[1]=n=>L(l)?l.value=n:null),type:"checkbox",class:"checkbox checkbox-primary checkbox-sm"},null,512),[[Ne,e(l)]]),s[9]||(s[9]=t("span",{class:"text-sm font-medium"},"Näita ainult partnerkoole",-1))])]),t("div",Rt,[u(ke,{modelValue:e(C),"onUpdate:modelValue":s[2]||(s[2]=n=>L(C)?C.value=n:null),placeholder:e(o)("Search for a school")},null,8,["modelValue","placeholder"]),w((r(),P(oe,{url:"/api/v1/export/schools-billing-data",onError:X},{default:h(()=>[t("span",Pt,a(e(o)("Eelmise kuu arve info")),1)]),_:1})),[[N,e(o)("It will export cohorts which started last month and their students")]]),w((r(),P(oe,{url:"/api/v1/export/schools-billing-data?all=true",onError:X},{default:h(()=>[t("span",Ot,a(e(o)("Kogu ajaloo arvete info")),1)]),_:1})),[[N,e(o)("It will export cohorts which started last month and their students")]])])]),u($e,{items:e(f),headers:x,"search-value":e(C),"search-field":"name","sort-by":"credits","sort-type":"desc"},{"item-name":h(({name:n,id:R})=>[u(I,{to:`/manage/schools/${R}/conditions`,class:"font-semibold underline"},{default:h(()=>[m(a(n),1)]),_:2},1032,["to"])]),"item-default_payer":h(({default_payer:n})=>[n?(r(),d(U,{key:0},[m(a(("useDefaultPayer"in i?i.useDefaultPayer:e(Be))(n)),1)],64)):(r(),d(U,{key:1},[m(a(e(o)("Undetermined")),1)],64))]),"item-payment_limitations":h(({payment_limitations:n})=>[u(we,{limitations:n},null,8,["limitations"])]),"item-actions":h(({id:n,name:R})=>[u(Ce,null,{default:h(()=>[u(I,{to:`/manage/schools/${n}/students`,class:"hover:bg-body rounded-md border px-2 py-1 text-center hover:text-white"},{default:h(()=>[m(a(e(o)("Students")),1)]),_:1},8,["to"]),u(I,{to:`/manage/schools/${n}/credits`,class:"hover:bg-body rounded-md border px-2 py-1 text-center hover:text-white"},{default:h(()=>[m(a(e(o)("School Credits")),1)]),_:1},8,["to"]),t("button",{type:"button",class:"hover:bg-danger rounded-md border px-2 py-1 text-center text-danger hover:text-white","data-testid":`archive-school-button-${R}`,onClick:is=>ge(Number(n),String(R))}," Arhiveeri kool ",8,Tt)]),_:2},1024)]),_:1},8,["items","search-value"]),e(g)==="add-school"?(r(),P(W,{key:0,type:"add-school",title:"Lisa uus kool",fit:""},{default:h(()=>[t("div",Vt,[t("div",zt,[s[10]||(s[10]=t("label",{class:"form-label required"},"Kooli nimi",-1)),w(t("input",{"onUpdate:modelValue":s[3]||(s[3]=n=>L(E)?E.value=n:null),type:"text",class:"form-control","data-testid":"new-school-name",placeholder:"Kooli nimi",maxlength:"255"},null,512),[[ie,e(E)]])]),t("div",It,[s[11]||(s[11]=t("label",{class:"form-label required"},"Registrikood",-1)),w(t("input",{"onUpdate:modelValue":s[4]||(s[4]=n=>L(j)?j.value=n:null),type:"text",inputmode:"numeric",class:"form-control","data-testid":"new-school-reg-code",placeholder:"Registrikood",maxlength:"20"},null,512),[[ie,e(j)]])]),t("div",Lt,[t("button",{class:"btn btn-ghost btn-sm",onClick:s[5]||(s[5]=n=>g.value=null)}," Tühista "),t("button",{class:"btn btn-secondary btn-sm","data-testid":"confirm-ad
1d-school",disabled:e(Y)||!e(E).trim()||!e(j).trim(),onClick:_e}," Lisa kool ",8,Ut)])])]),_:1})):y("",!0),e(g)==="archive-school"&&e(v)?(r(),P(W,{key:1,type:"archive-school",title:"Arhiveeri kool",fit:"",onCloseModal:te},{default:h(()=>[t("p",Bt," Kool â"+a(e(v).name)+"â eemaldatakse kõigist koolide nimekirjadest nii admin- kui ka kasutajavaates. Kooliga seotud registreerumised jäävad registreerumiste tabelisse alles. ",1),t("div",qt,[e(M)?(r(),d("div",Ft,[...s[12]||(s[12]=[t("span",{class:"loading loading-spinner loading-sm"},null,-1),m(" Kontrollin viimase 12 kuu registreerumisi⦠",-1)])])):e(b)?(r(),d("p",Jt,[s[13]||(s[13]=m(" Registreerumisi viimase 12 kuu jooksul: ",-1)),t("strong",null,a(e(b).recentRegistrations),1)])):(r(),d("p",Ht,a(e(z)),1))]),e(b)&&!e(b).canArchive?(r(),d("p",Yt," Kooli ei saa arhiveerida, sest viimase 12 kuu jooksul on olnud registreerumisi. ")):y("",!0),e(S)?(r(),d("div",Zt,a(e(S)),1)):y("",!0),t("div",Gt,[t("button",{class:"btn btn-ghost btn-sm",onClick:se}," Tühista "),t("button",{class:"btn btn-error bt
1n-sm text-white","data-testid":"confirm-archive-school",disabled:e(M)||e(Z)||!e(b)?.canArchive,onClick:be}," Arhiveeri kool ",8,Wt)])]),_:1})):y("",!0),e(g)==="expire-school-credits"&&e(k)?(r(),P(W,{key:2,type:"expire-school-credits",title:"Märgi aegunuks",fit:"",onCloseModal:G},{default:h(()=>[t("p",Qt,[m(" Koolil â"+a(e(k).schoolName)+"â on ",1),t("strong",null,a(e(k).expiringCredits),1),s[14]||(s[14]=m(" aegunud krediiti. Kinnita, et soovid need krediidid märkida aegunuks. ",-1))]),t("p",Xt,[s[15]||(s[15]=m(" Algne aegumistähtaeg: ",-1)),t("strong",null,a(ee(e(k))),1)]),e(A)?(r(),d("div",es,a(e(A)),1)):y("",!0),t("div",ts,[t("button",{class:"btn btn-ghost btn-sm",disabled:e(K),onClick:G}," Tühista ",8,ss),t("button",{class:"btn btn-error btn-sm text-white","data-testid":"confirm-expire-school-credits",disabled:e(K),onClick:ve},[e(K)?(r(),d("span",as)):y("",!0),s[16]||(s[16]=m(" Märgi aegunuks ",-1))],8,os)])]),_:1})):y("",!0)])}}});export{bs 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.