PageSourceSearch

https://omniconnects.com/assets/Employees-CS6eR6Z3.js

js omniconnects.com collected 2026-10-09 22:56:15 UTC 16,221 bytes, 1 lines download raw bytes

1import{a7 as z,a8 as re,a9 as G,r as d,Y as B,v as e,aa as W,ab as O,Q as se,G as J,O as R,H,V as K,K as X,ac as ne,E as I,ad as E,N as q,T as M,U,ae as A,af as oe,ag as ce,J as ie,a2 as ae,a3 as de,a5 as L,ah as ue,ai as xe,aj as Z,L as he,ak as fe}from"./index-BCVPuY6S.js";import{H as ye}from"./Header-DGh_AHwk.js";import{s as me}from"./SearchFunctions-Dm0FztDT.js";import{S as ge}from"./Search-DjfgJxPg.js";import{T as pe}from"./Tabs-1pOKKldI.js";import{M as je}from"./Modal-gDhRxLtC.js";function ee(l,s){const a=z(l),i=z(s),o=te(a,i),u=Math.abs(re(a,i));a.setDate(a.getDate()-o*u);const j=+(te(a,i)===-o),w=o*(u-j);return w===0?0:w}function te(l,s){const a=l.getFullYear()-s.getFullYear()||l.getMonth()-s.getMonth()||l.getDate()-s.getDate()||l.getHours()-s.getHours()||l.getMinutes()-s.getMinutes()||l.getSeconds()-s.getSeconds()||l.getMilliseconds()-s.getMilliseconds();return a<0?-1:a>0?1:a}const we=({selected:l})=>{const s=G(),[a,i]=d.useState(""),{user:o}=B(b=>b.user),[u,j]=d.useState(!1),w=b=>b.reduce((c,h)=>(l==="Hourly Based"&&h.payType==="Hourly"&&c.push(h),l==="Weekly Based"&&h.payType==="Weekly"&&c.push(h),l==="Comission Based"&&h.payType==="Commission"&&c.push(h),l==="Rent Chair Based"&&h.payType==="Rent Chair"&&c.push(h),c),[]),P=async b=>{if(b.preventDefault(),a.trim()===""){const c=await W(o==null?void 0:o.id),h=w(c);s(O(h));return}try{const c=await me(se.bussiness,"email",a);s(O(c)),j(!0)}catch(c){console.log("Error searching payroll:",c)}},x=async b=>{if(i(b.target.value),u&&b.target.value.trim()===""){const c=await W(o==null?void 0:o.id),h=w(c);s(O(h))}};return e.jsxs("form",{onSubmit:P,className:"border-[1px] border-[#0000001A] rounded-md w-full px-[12px] my-[24px] flex items-center gap-[18px]",children:[e.jsx("img",{src:ge,alt:"Search Icon"}),e.jsx("input",{type:"text",placeholder:"Search Employee by email...",value:a,onChange:x,className:"w-full h-full outline-none md:text-[14px] text-[8px]  py-5 placeholder:font-poppins-regular placeholder:text-[#434343] "}),e.jsx("button",{type:"submit",className:"bg-orange text-white px-4 py-2 rounded-md max-sm:px-w max-sm:py-1 max-sm:text-[12px]",children:"Search"})]})},F=({children:l,type:s})=>e.jsx("thead",{className:"tHead",children:e.jsxs("tr",{children:[e.jsx("td",{className:"td",children:"Name"}),e.jsx("td",{className:"td",children:e.jsx("h1",{className:"text-[8px] md:text-[12px]",children:"Working e-mail Address"})}),e.jsx("td",{className:"td",children:"Phone number"}),e.jsx("td",{className:"td",children:"Account Status"}),l]})}),be=({toggleModal:l})=>{G();const{modalData:s}=B(n=>n==null?void 0:n.modalData),{employeeList:a}=B(n=>n.employeeData),i=B(n=>n.currentUser.currentUser),[o,u]=d.useState(""),[j,w]=d.useState(""),[P,x]=d.useState(!1),[b,c]=d.useState(0);console.log("attendenve modal data => ",s);const h=async()=>{if(!o||!j){I("Please select a valid date range!","warn");return}x(!0);try{const n=R(H,"Payroll"),{uid:D,chairRent:m}=s,N=E.fromDate(new Date(o)),y=E.fromDate(new Date(j)),T=q(n,M("userId","==",D),M("startDate","<=",y),M("endDate",">=",N));if(!(await U(T)).empty){A.error("Payroll already calculated for this date range",{autoClose:3e3});return}const r=a.find(v=>v.uid===D),g=ee(new Date(j),new Date(o))+1;if(g<7){I("Rent Chair payroll requires at least 7 days!","warn",!0);return}if(g%7!==0){I("Select complete week(s) — multiples of 7 days!","warn",!0);return}const S=g/7,t=(m??0)*S,p=J(n);await K(p,{id:p.id,userId:D,type:"Rent Chair",startDate:N,endDate:y,totalHours:0,total:t,paid:0,remaining:t,lastPaid:E.now(),associatedBusinessId:(i==null?void 0:i.uid)||null,createdAt:E.now(),fullName:(r==null?void 0:r.fullName)||"",email:(r==null?void 0:r.email)||"",imageUrl:(r==null?void 0:r.imageUrl)||""}),A.success("Payroll created successfully",{autoClose:3e3})}catch(n){console.error(n),A.error("Failed to create payroll",{autoClose:3e3})}finally{x(!1)}},k=async()=>{if(!o||!j){I("Please select a valid date range!","warn");return}x(!0);try{const{uid:n,rate:D,payType:m,hasChairRented:N,chairRent:y}=s,T=q(R(H,"Attendance"),M("employeeID","==",n),M("clockIn",">=",E.fromDate(new Date(o))),M("clockIn","<=",E.fromDate(new Date(j))),M("isPaid","==",!1)),C=await U(T);if(C.empty){I("No unpaid attendance found in this range!","warn",!0),x(!1);return}let r=0;
1C.forEach(p=>{var V,_;const v=p.data(),Q=(V=v.clockIn)==null?void 0:V.toDate(),Y=(_=v.clockOut)==null?void 0:_.toDate();if(Q&&Y){const le=(Y-Q)/36e5;r+=le}});let g=0;const S=ee(new Date(j),new Date(o))+1;if((m==null?void 0:m.toLowerCase())==="hourly")g=r*D,N&&(g-=r*(y||0));else if((m==null?void 0:m.toLowerCase())==="weekly"){if(S<7){I("Weekly payroll requires at least 7 days!","warn",!0),x(!1);return}if(S%7!==0){I("Select complete week(s) — multiples of 7 days!","warn",!0),x(!1);return}const p=S/7;g=D*p,N&&(g-=p*(y||0))}else if(m=="Rent Chair"){const p=S/7;g=y*p}const t=Math.round(g*100)/100;return c(t>0?t:0),{totalHours:r,grossPay:t,snapshot:C}}catch(n){console.error("Error calculating payroll:",n),I(`Error: ${n.message}`,"error")}finally{x(!1)}},f=async()=>{if(x(!0),(s==null?void 0:s.payType)=="Rent Chair"){try{await h()}catch(y){console.log("some thing went wrong => ",y)}finally{x(!1),l(),u(""),w(""),c(0)}return}const n=await k();if(!n)return;const{totalHours:D,grossPay:m,snapshot:N}=n;try{const{uid:y}=s,T=J(R(H,se.payroll)),C=T.id,r=a.find(S=>S.uid===y);await K(T,{id:C,userId:y,type:r==null?void 0:r.payType,startDate:o,endDate:j,totalHours:D,total:m,paid:0,remaining:m,lastPaid:X(),associatedBusinessId:(i==null?void 0:i.uid)||null,createdAt:X(),fullName:(r==null?void 0:r.fullName)||"",email:(r==null?void 0:r.email)||"",imageUrl:(r==null?void 0:r.imageUrl)||""});const g=ne(H);N.forEach(S=>{g.update(S.ref,{isPaid:!0})}),await g.commit(),I("Payroll generated and attendance marked as paid!","success",!0),l(),u(""),w(""),c(0)}catch(y){console.error("Error saving payroll:",y),I(`Error saving payroll: ${y.message}`,"error")}finally{x(!1)}};return e.jsx(je,{handleCancelChanges:l,handleSaveChanges:f,heading:"Generate Payroll",loading:P,children:e.jsxs("div",{className:"flex flex-col gap-4 justify-center items-center w-full",children:[e.jsxs("div",{className:"flex flex-col md:flex-row gap-4 w-full",children:[e.jsx("input",{type:"date",className:"h-[56px] border px-3 rounded-[8px] w-full",value:o,max:new Date().toISOString().split("T")[0],onChange:n=>u(n.target.value)}),e.jsx("input",{type:"date",className:"h-[56px] border px-3 rounded-[8px] w-full",value:j,max:new Date().toISOString().split("T")[0],onChange:n=>w(n.target.value)})]}),b>0&&e.jsx("p",{className:"font-poppins-regular text-[16px] text-[#434343] my-4 text-center",children:`Calculated Payroll: $${b.toFixed(2)}`})]})})},Ne=({open:l,onClose:s,employeeID:a})=>
1{const[i,o]=d.useState(""),[u,j]=d.useState(""),[w,P]=d.useState(""),[x,b]=d.useState(!1);console.log("employee id => ",a);const c=B(f=>f.currentUser.currentUser),h=new Date().toISOString().split("T")[0],k=async()=>{try{if(b(!0),!i||!u||!w){A.error("Please fill all fields.",{autoClose:5e3});return}const f=new Date(`${i}T${u}:00`),n=new Date(`${i}T${w}:00`);if(n<f){A.error("Clock-out cannot be earlier than clock-in.",{autoClose:5e3});return}const D=q(R(H,"Attendance"),M("employeeID","==",a));if((await U(D)).docs.some(g=>{var p;return((p=g.data().clockIn)==null?void 0:p.toDate().toISOString().split("T")[0])===i})){A.error("Attendance for this date already exists!",{autoClose:5e3});return}const y=!0,T=!1,C=E.now(),r=await ce(R(H,"Attendance"),{employeeID:a,clockIn:E.fromDate(f),clockOut:E.fromDate(n),isPresent:y,issueDateTime:C,businessId:c==null?void 0:c.uid,isPaid:T,docId:""});await ie(r,{docId:r.id}),console.log("Attendance record added with ID:",r.id),A.success("Attendance saved successfully!",{autoClose:5e3}),s()}catch(f){console.error("Error adding attendance:",f),A.error("Failed to add attendance.",{autoClose:5e3})}finally{b(!1)}};return l?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center backdrop-blur-sm",onClick:s,children:e.jsxs("div",{className:"bg-white  rounded-2xl shadow-lg w-full max-w-md mx-4 p-6 relative transform transition-all duration-300",onClick:f=>f.stopPropagation(),children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-800 ",children:"Mark Attendance"}),e.jsx("button",{onClick:s,className:"text-gray-500 hover:text-gray-700  text-xl leading-none",children:"×"})]}),e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-sm text-gray-700 ",children:"Date"}),e.jsx("input",{type:"date",max:h,value:i,onChange:f=>o(f.target.value),className:"border rounded-lg p-2  dark:border-gray-700  focus:ring-2 focus:ring-blue-500 outline-none"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-sm text-gray-700 ",children:"Clock-In"}),e.jsx("input",{type:"time",value:u,onChange:f=>j(f.target.value),className:"border rounded-lg p-2  dark:border-gray-700  focus:ring-2 focus:ring-blue-500 outline-none"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-sm text-gray-700 ",children:"Clock-Out"}),e.jsx("input",{type:"time",value:w,onChange:f=>P(f.target.value),className:"border rounded-lg p-2  dark:border-gray-700 dark:text-gray-200 focus:ring-2 focus:ring-blue-500 outline-none"})]})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[e.jsx("button",{disabled:x,onClick:s,className:"px-4 py-2 rounded-lg bg-gray-200 hover:bg-gray-300  text-sm font-medium",children:"Cancel"}),e.jsx("button",{disabled:x,onClick:k,className:"px-4 py-2 rounded-lg bg-blue-600 hover:bg-blue-700 text-white text-sm font-medium",children:e.jsxs("p",{className:"flex items-center gap-1",children:[e.jsx("span",{children:"Save"})," ",x&&e.jsx("span",{children:e.jsx(oe,{className:"animate-spin"})})]})})]})]})}):null},$=({weekly:l,comission:s,hourly:a,rentChair:i,children:o,employees:u,type:j})=>{const w=G(),P=ae(),[x,b]=d.useState(!1),[c,h]=d.useState(null),{employeeList:k}=B(t=>t.employeeData),[f,n]=d.useState(!1),[D,m]=d.useState(!0),[N,y]=d.useState(null),[T,C]=d.useState(!1);d.useEffect(()=>{const t=u==null?void 0:u.reduce((p,v)=>(a&&v.payType==="Hourly"&&p.push(v),l&&v.payType==="Weekly"&&p.push(v),s&&v.payType==="Commission"&&p.push(v),i&&v.payType==="Rent Chair"&&p.push(v),p),[]);w(O(t))},[u]);const r=t=>{w(xe(t)),n(!f)},g=t=>{P(`/admin/employeeDetails/${t}`)},S=t=>{C(!0),h(t==null?void 0:t.uid)};return e.jsxs(e.Fragment,{children:[e.jsx("tbody",{className:"border",children:(k==null?void 0:k.length)==0?e.jsxs("tr",{children:[e.jsx("td",{}),e.jsx("td",{}),e.jsx("td",{className:"py-5",children:"No Employee "}),e.jsx("td",{}),e.jsx("td",{})]}):k==null?void 0:k.map((t,p)=>e.jsxs("tr",{className:"border-b cursor-pointer text-[14px]",children:[e.jsxs("td",{onClick:()=>g(t==null?void 0:t.uid),className:"tdFirstInput mx-4",children:[e.jsx("img",{src:(t==null?void 0:t.imageUrl)||de,alt:"",className:"md:h-[40px] md:w-[40px] h-[20px] w-[20px] rounded-full object-cover"}),e.jsx("p",{className:"text-[#101828] font-poppins-semibold whitespace-nowrap text-[8px] md:text-[14px]",children:t==null?void 0:t.fullName})]}),e.jsx("td",{onClick:()=>g(t==null?void 0:t.uid),className:"tbodyTd",children:e.jsx("h1",{className:"max-w-[110px] md:w-auto whitespace-nowrap  overflow-ellipsis break-all text-[7px] md:text-[14px]  lg:overflow-visible xl:break-normal",children:t==null?void 0:t.email})}),e.jsx("td",{onClick:()=>g(t==null?void 0:t.uid),className:"tbodyTd",children:t==null?void 0:t.phoneNumber}),e.jsx("td",{onClick:()=>g(t==null?void 0:t.uid),className:"tbodyTd",children:e.jsx("span",{className:`py-1 px-2 rounded-full text-xs ${(t==null?void 0:t.accountStatus)==="Approved"?"bg-green/10 text-green":"bg-red-600/10 text-red"}`,children:t!=null&&t.accountStatus?t.accountStatus:"Active"})}),i&&!s&&e.jsx("td",{children:t!=null&&t.chairRent?`$${t==null?void 0:t.chairRent}`:"-"}),!l&&!a&&e.jsxs("td",{className:"tbodyTd",children:[i&&!s&&(t!=null&&t.hasCommission)?(t==null?void 0:t.hasCommission)&&(t==null?void 0:t.commissionPercentage):t==null?void 0:t.rate,"%"]}),e.jsxs(e.Fragment,{children:[e.jsx("td",{className:"md:text-[14px] curs
1or-pointer text-[10px] whitespace-nowrap font-poppins-semibold  text-[#434343] md:px-[24px] md:py-[16px] p-[5px]",children:e.jsx(L,{onClick:()=>S(t),color:"orange",children:"Attendence"})}),(l||a||i)&&e.jsx("td",{onClick:()=>{m(!1),r(t)},className:"md:text-[14px] cursor-pointer text-[10px] whitespace-nowrap font-poppins-semibold  text-[#434343] md:px-[24px] md:py-[16px] p-[5px]",children:e.jsx(L,{color:"orange",children:"Generate Payroll"})}),f&&e.jsx(be,{toggleModal:r,isClockIn:D,employee:t}),T&&e.jsx(Ne,{open,onClose:()=>C(!1),employeeID:c})]})]},p))}),e.jsx(ue,{userId:c,isModalOpen:x,setIsModalOpen:b,weekly:l,comission:s,rentChair:i,employeeData:N})]})},De=({employees:l,setEmployees:s})=>(console.log("all employee list  =>",l),e.jsx("div",{className:"rounded-xl overflow-hidden border w-full",children:e.jsxs("table",{className:"w-full border-0 ",children:[e.jsxs(F,{children:[e.jsx("td",{className:"td"}),e.jsx("td",{className:"td"})]}),e.jsx($,{hourly:!0,employees:l,setEmployees:s})]})})),Ce=({employees:l,setEmployees:s,type:a})=>e.jsxs("table",{className:" w-full rounded-lg overflow-hidden",children:[e.jsxs(F,{type:a,children:[e.jsx("td",{className:"td",children:"Commission"}),e.jsx("td",{className:"opacity-0"}),e.jsx("td",{className:"opacity-0"}),e.jsx("td",{className:"opacity-0"})]}),e.jsx($,{comission:!0,employees:l,setEmployees:s,type:a})]}),Se=({employees:l,setEmployees:s})=>e.jsx(e.Fragment,{children:e.jsxs("table",{className:"w-full rounded-lg overflow-hidden",children:[e.jsxs(F,{children:[e.jsx("td",{className:"td"}),e.jsx("td",{className:"td opacity-0"})]}),e.jsx($,{weekly:!0,employees:l,setEmployees:s})]})}),ve=({employees:l,setEmployees:s})=>e.jsxs("table",{className:" w-full rounded-lg overflow-hidden",children:[e.jsxs(F,{children:[e.jsx("td",{className:"td",children:"Rent Chair"}),e.jsx("td",{className:"",children:"Commission"}),e.jsx("td",{className:"opacity-0"}),e.jsx("td",{className:"opacity-0"})]}),e.jsx($,{rentChair:!0,comission:!1,employees:l,setEmployees:s})]}),ke=({selected:l,employees:s,setEmployees:a})=>{switch(console.log("all employees=> ",s),l){case"Hourly Based":return e.jsx(De,{employees:s,setEmployees:a});case"Weekly Based":return e.jsx(Se,{employees:s,setEmployees:a});case"Comission Based":return e.jsx(Ce,{employees:s,setEmployees:a,type:"commission"});case"Rent Chair Based":return e.jsx(ve,{employees:s,setEmployees:a});default:return null}},Be=()=>{ae();const{currentUser:l,subscription:s}=B(m=>m.currentUser),[a,i]=d.useState(Z[0]),[o,u]=d.useState([]),[j,w]=d.useState(!1),[P,x]=d.useState(null),[b,c]=d.useState(!0);console.log("my current => ",l);const h=async(m=!1)=>{if(l!=null&&l.uid)try{w(!0);const N=a!=null&&a.includes("Hourly")?"Hourly":a!=null&&a.includes("Weekly")?"Weekly":a!=null&&a.includes("Comission")?"Commission":"Rent Chair";console.log("employee type => ",N);const{employees:y,lastVisible:T}=await W({businessId:l.uid,userType:N,lastDoc:m?null:P});u(m?y:C=>[...C,...y]),x(T),c(y.length===20)}catch(N){console.error("Error fetching employees:",N)}finally{w(!1)}};d.useEffect(()=>{u([]),x(null),c(!0),h(!0)},[a,l]);const k=()=>{b&&!j&&h(!1)},f=fe.includes(s),n=(o==null?void 0:o.length)>=20,D=f&&n;return e.jsxs("div",{className:"mt-8 pr-[8px] md:max-w-[90%] flex flex-col",children:[e.jsx(ye,{heading:"Employee",btnText:"Add Employee",to:"/admin/AddMember",showPopUp:D}),e.jsx("div",{className:"flex gap-[16px] mt-[24px]",children:e.jsx(pe,{data:Z,selectedTab:a,setSelectedTab:i})}),e.jsx(we,{selected:a}),e.jsx("div",{className:"w-full overflow-x-auto scrollbar-hide mt-4",children:j&&o.length===0?e.jsx("div",{className:"flex justify-center items-center w-full min-h-[200px]",children:e.jsx(he,{})}):e.jsx("div",{className:"min-w-max w-full",children:e.jsx(ke,{selected:a,employees:o,setEmployees:u})})}),b&&e.jsx(L,{onClick:k,loading:j,className:"self-center mt-4",children:"Load More"})]})};export{Be 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.