PageSourceSearch

https://nadort-elektro.nl/assets/Overuren-CmU4oVVB.js

js nadort-elektro.nl collected 2026-10-09 22:03:40 UTC 8,361 bytes, 2 lines download raw bytes

1import{u as W,r as a,b as h,j as e,N as X,z as Z,B as o,am as w,an as b,ao as k,ap as _,aq as j,a5 as ee,a6 as se,a7 as re,a8 as ae,a9 as te,I as V,T as ne,aa as le,c as d}from"./index-DZ2JdFDg.js";import{P as ie}from"./plus-DWaCrKyQ.js";import{D as oe}from"./download-DuCPwZpS.js";import{R as de}from"./refresh-cw-DNf-HIuv.js";import{T as ce}from"./trash-2-DeU-Lotm.js";const R=[{value:"overuur",label:"Overuur"},{value:"tvt_opbouw",label:"Tijd voor tijd (opbouw)"},{value:"meeruur",label:"Meeruur"}];function F(n){var g;return((g=R.find(l=>l.value===n))==null?void 0:g.label)??n}function ue(n){return new Date(n).toLocaleDateString("nl-NL",{day:"2-digit",month:"short",year:"numeric"})}function fe(){const{isAdmin:n,loading:g}=W(),[l,E]=a.useState([]),[f,I]=a.useState([]),[S,C]=a.useState(!0),[p,A]=a.useState("all"),[c,$]=a.useState(new Date().getFullYear()),[B,v]=a.useState(!1),[L,O]=a.useState(!1),T=new Date().toISOString().slice(0,10),[t,i]=a.useState({user_id:"",work_date:T,hours:"",kind:"overuur",note:""}),u=a.useCallback(async()=>{C(!0);const[{data:s},{data:r}]=await Promise.all([h.from("profiles").select("id, full_name, actief").order("full_name"),h.from("overtime_entries").select("id,user_id,work_date,hours,kind,note,created_by,created_at").gte("work_date",`${c}-01-01`).lte("work_date",`${c}-12-31`).order("work_date",{ascending:!1})]);E(s??[]),I(r??[]),C(!1)},[c]);a.useEffect(()=>{n&&u()},[n,u]);const M=a.useMemo(()=>{const s={};return l.forEach(r=>s[r.id]=r),s},[l]),m=a.useMemo(()=>f.filter(s=>p==="all"||s.user_id===p),[f,p]),P=a.useMemo(()=>{const s={};return f.forEach(r=>{s[r.user_id]=(s[r.user_id]??0)+Number(r.hours)}),s},[f]),z=a.useMemo(()=>m.reduce((s,r)=>s+Number(r.hours),0),[m]);if(g)return e.jsx("p",{className:"text-muted-foreground",children:"Laden…"});if(!n)return e.jsx(X,{to:"/portaal",replace:!0});const K=()=>{i({user_id:"",work_date:T,hours:"",kind:"overuur",note:""}),v(!0)},Y=async()=>{if(!t.user_id)return d.error("Kies een medewerker");const s=Number(t.hours.replace(",","."));if(!s||s<=0)return d.error("Vul een geldig aantal uren in");O(!0);const{data:{user:r}}=await h.auth.getUser(),{error:N}=await h.from("overtime_entries").insert({user_id:t.user_id,work_date:t.work_date,hours:s,kind:t.kind,note:t.note||null,created_by:(r==null?void 0:r.id)??null});if(O(!1),N)return d.error(N.message);d.success("Overuren geregistreerd"),v(!1),u()},q=async s=>{if(!confirm("Deze registratie verwijderen?"))return;const{error:r}=await h.from("overtime_entries").delete().eq("id",s);if(r)return d.error(r.message);d.success("Verwijderd"),u()},H=()=>{const s=["Datum","Medewerker","Type","Uren","Opmerking"],r=m.map(x=>{const D=M[x.user_id];return[x.work_date,(D==null?void 0:D.full_name)??"",F(x.kind),String(x.hours),x.note??""].map(Q=>`"${String(Q??"").replace(/"/g,'""')}"`).join(";")}),N=new Blob([[s.join(";"),...r].join(`
2`)],{type:"text/csv"}),U=URL.createObjectURL(N),y=document.createElement("a");y.href=U,y.download=`overuren-${c}.csv`,y.click(),URL.revokeObjectURL(U)},G=l.filter(s=>s.actief),J=Array.from({length:6},(s,r)=>new Date().getFullYear()-r);return e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-start justify-between mb-6 gap-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-xl sm:text-2xl md:text-3xl font-semibold flex items-center gap-2",children:[e.jsx(Z,{className:"w-6 h-6 text-accent"})," Overuren-registratie"]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Registreer overuren per medewerker."})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(o,{onClick:K,className:"gap-2",children:[e.jsx(ie,{className:"w-4 h-4"})," Nieuwe registratie"]}),e.jsxs(o,{variant:"outline",onClick:H,className:"gap-2",children:[e.jsx(oe,{className:"w-4 h-4"})," CSV"]}),e.jsxs(o,{variant:"outline",onClick:()=>u(),disabled:S,className:"gap-2",children:[e.jsx(de,{className:`w-4 h-4 ${S?"animate-spin":""}`})," Vernieuwen"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-2 mb-4",children:[e.jsxs(w,{value:p,onValueChange:A,children:[e.jsx(b,{children:e.jsx(k,{placeholder:"Medewerker"})}),e.jsxs(_,{children:[e.jsx(j,{value:"all",children:"Alle medewerkers"}),l.map(s=>e.jsxs(j,{value:s.id,children:[s.full_name??"—"," · ",(P[s.id]??
20).toLocaleString("nl-NL",{maximumFractionDigits:1})," u"]},s.id))]})]}),e.jsxs(w,{value:String(c),onValueChange:s=>$(Number(s)),children:[e.jsx(b,{children:e.jsx(k,{})}),e.jsx(_,{children:J.map(s=>e.jsx(j,{value:String(s),children:s},s))})]}),e.jsxs("div",{className:"flex items-center justify-end text-sm text-muted-foreground",children:["Totaal: ",e.jsxs("span",{className:"ml-2 font-semibold text-foreground",children:[z.toLocaleString("nl-NL",{maximumFractionDigits:1})," u"]})]})]}),S?e.jsx("p",{className:"text-muted-foreground",children:"Laden…"}):e.jsx("div",{className:"overflow-auto border border-border rounded-xl bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"text-left bg-secondary/50",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3",children:"Datum"}),e.jsx("th",{className:"p-3",children:"Medewerker"}),e.jsx("th",{className:"p-3",children:"Type"}),e.jsx("th",{className:"p-3 text-right",children:"Uren"}),e.jsx("th",{className:"p-3",children:"Opmerking"}),e.jsx("th",{className:"p-3",children:"Ingevoerd"}),e.jsx("th",{className:"p-3 w-10"})]})}),e.jsxs("tbody",{children:[m.map(s=>{const r=M[s.user_id];return e.jsxs("tr",{className:"border-t border-border hover:bg-secondary/30",children:[e.jsx("td",{className:"p-3 whitespace-nowrap",children:ue(s.work_date)}),e.jsx("td",{className:"p-3 font-medium",children:(r==null?void 0:r.full_name)??"—"}),e.jsx("td",{className:"p-3",children:e.jsx("span",{className:"inline-flex items-center px-2 py-0.5 rounded-md text-xs font-medium bg-sky-500/15 text-sky-700 dark:text-sky-400",children:F(s.kind)})}),e.jsx("td",{className:"p-3 text-right font-medium",children:Number(s.hours).toLocaleString("nl-NL",{maximumFractionDigits:2})}),e.jsx("td",{className:"p-3 max-w-[24rem]",children:e.jsx("div",{className:"truncate",title:s.note??"",children:s.note||"—"})}),e.jsx("td",{className:"p-3 text-xs text-muted-foreground whitespace-nowrap",children:new Date(s.created_at).toLocaleDateString("nl-NL")}),e.jsx("td",{className:"p-3",children:e.jsx(o,{size:"icon",variant:"ghost",onClick:()=>q(s.id),"aria-label":"Verwijderen",children:e.jsx(ce,{className:"w-4 h-4"})})})]},s.id)}),m.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-6 text-center text-muted-foreground",children:"Nog geen registraties."})})]})]})}),e.jsx(ee,{open:B,onOpenChange:v,children:e.jsxs(se,{children:[e.jsxs(re,{children:[e.jsx(ae,{children:"Overuren registreren"}),e.jsx(te,{children:"Leg overuren vast voor een medewerker."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Medewerker"}),e.jsxs(w,{value:t.user_id,onValueChange:s=>i(r=>({...r,user_id:s})),children:[e.jsx(b,{children:e.jsx(k,{placeholder:"Kies medewerker"})}),e.jsx(_,{children:G.map(s=>e.jsx(j,{value:s.id,children:s.full_name??"—"},s.id))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Datum"}),e.jsx(V,{type:"date",value:t.work_date,onChange:s=>i(r=>({...r,work_date:s.target.value}))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Uren"}),e.jsx(V,{type:"number",step:"0.25",min:"0",value:t.hours,onChange:s=>i(r=>({...r,hours:s.target.value})),placeholder:"bv. 2.5"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Type"}),e.jsxs(w,{value:t.kind,onValueChange:s=>i(r=>({...r,kind:s})),children:[e.jsx(b,{children:e.jsx(k,{})}),e.jsx(_,{children:R.map(s=>e.jsx(j,{value:s.value,children:s.label},s.value))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium",children:"Opmerking (optioneel)"}),e.jsx(ne,{value:t.note,onChange:s=>i(r=>({...r,note:s.target.value})),placeholder:"Toelichting…"})]})]}),e.jsxs(le,{children:[e.jsx(o,{variant:"outline",onClick:()=>v(!1),children:"Annuleren"}),e.jsx(o,{onClick:Y,disabled:L,children:L?"Opslaan…":"Opslaan"})]})]})})]})}export{fe 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.