2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
import{r as d,j as e}from"./ui-Z445SNHD.js";import{P as Z}from"./page-template-CDooloYn.js";import{u as ee,c as te,x as h,P as re,r as m,C as v,l as f,D as se,t as a,m as ae,n as ie,o as y}from"./app-BJfYyIIX.js";import{C as le}from"./CrudFormModal-I0cLiJrd.js";import{C as ne}from"./CrudDeleteModal-B6HMcwYN.js";import{P as oe}from"./pagination-CkJ-fhRF.js";import{S as ce}from"./search-and-filter-bar-BqVa3_Yk.js";import de from"./view-B-zRkelf.js";import{S as M}from"./shield-D4lNYMUI.js";import{C as me}from"./circle-check-big-CcY08IiJ.js";import{C as S}from"./clock-Dx30a3fw.js";import{D as L}from"./dollar-sign-GjiaL2_k.js";import{E as pe}from"./eye-bHRQkV_M.js";import{S as xe}from"./square-pen-CtvYVz4A.js";import{L as ge}from"./lock-BIgt4mUB.js";import{T as ue}from"./trash-2-CUSPqIMQ.js";import"./textarea-Am1DxbQR.js";import"./select-v6HfP-lT.js";import"./index-BdQq_4o_.js";import"./index-9MclThM-.js";import"./chevron-up-C77P-Xnl.js";import"./react-country-flag.esm-Bs2jngHP.js";import"./language-BbwPiY59.js";import"./sparkles-DiRyEFzz.js";import"./loader-circle-BSOgoX7W.js";import"./copy-C-oQ_m_8.js";import"./CookieConsentBanner-C38N4PTk.js";import"./refresh-cw-ALYE7VHu.js";import"./globe-BDbxh4XP.js";import"./settings-iEK2zkZs.js";import"./switch-Cx2aNaqN.js";import"./chevron-right-C_sLmqOC.js";import"./layout-grid-CoeIbdlV.js";import"./briefcase-XD6VuWqm.js";import"./credit-card-7DJJO-Xg.js";import"./gift-BfcFhtsh.js";import"./users-TIev6QWg.js";import"./calendar-CbSq6zTy.js";import"./calendar-days-C8NX5zeY.js";import"./timer-BEVp3YT6.js";import"./coins-Bsoy02xu.js";import"./index-BFT_C1pH.js";import"./user-DLrpac_w.js";import"./log-out-BMSBi6tX.js";/* empty css *//* empty css */import"./utils-BWxnHGCV.js";import"./radio-group-KOpzhUXP.js";import"./circle-DWyWs_iS.js";import"./checkbox-D89mOuIk.js";import"./scroll-area-oGCj-C9A.js";import"./filter-CC8qq1a5.js";import"./list-Ds3PdXRr.js";function ut(){var T,q,I;const{t}=ee(),{auth:N,attendancePolicies:i,stats:l,filters:o={}}=te().props,g=(N==null?void 0:N.permissions)||[],[p,C]=d.useState(o.search||""),[n,_]=d.useState(o.status||"all"),[R,P]=d.useState(!1),[V,u]=d.useState(!1),[$,w]=d.useState(!1),[x,A]=d.useState(null),[b,F]=d.useState("create"),[k,D]=d.useState(null),G=()=>p!==""||n!=="all",z=()=>(p?1:0)+(n!=="all"?1:0),B=r=>{r.preventDefault(),O()},O=()=>{m.get(route("hr.attendance-policies.index"),{page:1,search:p||void 0,status:n!=="all"?n:void 0,per_page:o.per_page},{preserveState:!0,preserveScroll:!0})},j=(r,s)=>{switch(A(s),r){case"view":D(s);break;case"edit":F("edit"),u(!0);break;case"delete":w(!0);break;case"toggle-status":K(s);break}},H=()=>{A(null),F("create"),u(!0)},U=r=>{b==="create"?(a.loading(t("Creating attendance policy...")),m.post(route("hr.attendance-policies.store"),r,{onSuccess:s=>{u(!1),a.dismiss(),s.props.flash.success?a.success(t(s.props.flash.success)):s.props.flash.error&&a.error(t(s.props.flash.error))},onError:s=>{a.dismiss(),typeof s=="string"?a.error(s):a.error(`Failed to create attendance policy: ${Object.values(s).join(", ")}`)}})):b==="edit"&&(a.loading(t("Updating attendance policy...")),m.put(route("hr.attendance-policies.update",x.id),r,{onSuccess:s=>{u(!1),a.dismiss(),s.props.flash.success?a.success(t(s.props.flash.success)):s.props.flash.error&&a.error(t(s.props.flash.error))},onError:s=>{a.dismiss(),typeof s=="string"?a.error(s):a.error(`Failed to update attendance policy: ${Object.values(s).join(", ")}`)}}))},J=()=>{a.loading(t("Deleting attendance policy...")),m.delete(route("hr.attendance-policies.destroy",x.id),{onSuccess:r=>{w(!1),a.dismiss(),r.props.flash.success?a.success(t(r.props.flash.success)):r.props.flash.error&&a.error(t(r.props.flash.error))},onError:r=>{a.dismiss(),typeof r=="string"?a.error(r):a.error(`Failed to delete attendance policy: ${Object.values(r).join(", ")}`)}})},K=r=>{const s=r.status==="active"?"inactive":"active";a.loading(`${t(s==="active"?"Activating":"Deactivating")} attendance policy...`),m.put(route("hr.attendance-policies.toggle-status",r.id),{},{onSuccess:c=>{a.dismiss(),c.props.flash.success?a.success(t(c.props.flash.success)):c.props.flash.error&&a.error(t(c.props.flash.error))},onError:c=>{a.dismiss(),typeof c=="string"?a.error(c):a.error(`Failed to update attendance policy status: ${Object.values(c).join(", ")}`)}})},Q=()=>{C(""),_("all"),P(!1),m.get(route("hr.attendance-policies.index"),{page:1,per_page:o.per_page},{preserveState:!0,preserveScroll:!0})},E=[];h(g,"create-attendance-policies")&&E.push({label:t("Add Attendance Policy"),icon:e.jsx(re,{className:"h-4 w-4 mr-2"}),variant:"default",onClick:()=>H()});const W=[{title:t("Dashboard"),href:route("dashboard")},{title:t("Shift Management"),href:route("hr.attendance-policies.index")},{title:t("Attendance Policies")}];t("Policy Name"),t("Late Grace (mins)"),t("Early Grace (mins)"),t("Overtime Rate"),t("Status"),t("View"),t("Edit"),t("Toggle Status"),t("Delete");const X=[{value:"all",label:t("All Statuses"),disabled:!0},{value:"active",label:t("Active")},{value:"inactive",label:t("Inactive")}],Y=r=>{var s;return e.jsxs(v,{className:"group hover:shadow-md transition-all duration-200 border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800",children:[e.jsx(ae,{className:"pb-4",children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"p-2.5 rounded-lg bg-blue-100 text-blue-600 dark:bg-blue-900/30 dark:text-blue-400",children:e.jsx(M,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx(ie,{className:"text-lg font-semibold text-gray-900 dark:text-white mb-2",children:r.name}),e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx("span",{className:`inline-flex items-center rounded-md px-2 py-1 text-xs font-medium ring-1 ring-inset ${r.status==="active"?"bg-green-50 text-green-700 ring-green-600/20":"bg-red-50 text-red-700 ring-red-600/20"}`,children:r.status==="active"?t("Active"):t("Inactive")})})]})]}),e.jsxs("div",{className:"flex items-center space-x-1",children:[h(g,"view-attendance-policies")&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>j("view",r),className:"h-8 w-8 p-0 text-blue-500",title:t("View Policy"),children:e.jsx(pe,{className:"h-4 w-4"})}),h(g,"edit-attendance-policies")&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>j("edit",r),className:"h-8 w-8 p-0 text-amber-500",title:t("Edit Policy"),children:e.jsx(xe,{className:"h-4 w-4"})}),h(g,"edit-attendance-policies")&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>j("toggle-status",r),className:`h-8 w-8 p-0 text-amber-500 ${r.status==="active"?"hover:text-amber-600":"hover:text-green-600"}`,title:r.status==="active"?t("Deactivate Policy"):t("Activate Policy"),children:e.jsx(ge,{className:"h-4 w-4"})}),h(g,"delete-attendance-policies")&&e.jsx(y,{variant:"ghost",size:"sm",onClick:()=>j("delete",r),className:"h-8 w-8 p-0 text-red-500",title:t("Delete Policy"),children:e.jsx(ue,{className:"h-4 w-4"})})]})]})}),e.jsxs(f,{className:"pt-0",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(S,{className:"h-4 w-4 text-orange-500 mt-0.5"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:[r.late_arrival_grace," ",t("minutes")]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:t("Late Arrival Grace")})]})]}),e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(S,{className:"h-4 w-4 text-blue-500 mt-0.5"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:[r.early_departure_grace," ",t("minutes")]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:t("Early Departure Grace")})]})]})]}),e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"flex items-start space-x-3",children:[e.jsx(L,{className:"h-4 w-4 text-green-500 mt-0.5"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-semibold text-gray-900 dark:text-white",children:[(s=window.appSettings)==null?void 0:s.formatCurrency(r.overtime_rate_per_hour),"/hr"]}),e.jsx("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:t("Overtime Rate")})]})]})})]}),r.description&&e.jsx("div",{className:"mt-4 pt-4 border-t border-gray-100 dark:border-gray-700",children:e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 truncate",children:r.description})})]})]},r.id)};return e.jsxs(Z,{title:t("Attendance Policies"),url:"/hr/attendance-policies",actions:E,breadcrumbs:W,noPadding:!0,children:[e.jsx("div",{className:"bg-white dark:bg-gray-900 rounded-lg shadow mb-6 p-4",children:e.jsx(ce,{searchTerm:p,onSearchChange:C,onSearch:B,filters:[{name:"status",label:t("Status"),type:"select",value:n,onChange:_,options:X}],showFilters:R,setShowFilters:P,hasActiveFilters:G,activeFilterCount:z,onResetFilters:Q,onApplyFilters:O,currentPerPage:((T=o.per_page)==null?void 0:T.toString())||"9",onPerPageChange:r=>{m.get(route("hr.attendance-policies.index"),{page:1,per_page:parseInt(r),search:p||void 0,status:n!=="all"?n:void 0},{preserveState:!0,preserveScroll:!0})},perPageOptions:[9,27,45,90]})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx(v,{className:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700",children:e.jsx(f,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-gray-600 dark:text-gray-400 text-sm font-medium",children:t("Total Policies")}),e.jsx("p",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:(l==null?void 0:l.total)||0})]}),e.jsx("div",{className:"p-2 bg-gray-100 dark:bg-gray-700 rounded-lg",children:e.jsx(M,{className:"h-6 w-6 text-gray-600 dark:text-gray-400"})})]})})}),e.jsx(v,{className:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700",children:e.jsx(f,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-gray-600 dark:text-gray-400 text-sm font-medium",children:t("Active Policies")}),e.jsx("p",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:(l==null?void 0:l.active)||0})]}),e.jsx("div",{className:"p-2 bg-green-100 dark:bg-green-900/30 rounded-lg",children:e.jsx(me,{className:"h-6 w-6 text-green-600 dark:text-green-400"})})]})})}),e.jsx(v,{className:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700",children:e.jsx(f,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-gray-600 dark:text-gray-400 text-sm font-medium",children:t("Avg Late Grace")}),e.jsxs("p",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:[(l==null?void 0:l.avg_late_grace)||0," ",t("min")]})]}),e.jsx("div",{className:"p-2 bg-orange-100 dark:bg-orange-900/30 rounded-lg",children:e.jsx(S,{className:"h-6 w-6 text-orange-600 dark:text-orange-400"})})]})})}),e.jsx(v,{className:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700",children:e.jsx(f,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-gray-600 dark:text-gray-400 text-sm font-medium",children:t("Avg Overtime Rate")}),e.jsx("p",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:(q=window.appSettings)==null?void 0:q.formatCurrency((l==null?void 0:l.avg_overtime_rate)||0)})]}),e.jsx("div",{className:"p-2 bg-green-100 dark:bg-green-900/30 rounded-lg",children:e.jsx(L,{className:"h-6 w-6 text-green-600 dark:text-green-400"})})]})})})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6",children:(I=i==null?void 0:i.data)==null?void 0:I.map(r=>Y(r))}),e.jsx("div",{className:"bg-white dark:bg-gray-900 rounded-lg shadow border border-gray-200 dark:border-gray-700 p-4",children:e.jsx(oe,{from:(i==null?void 0:i.from)||0,to:(i==null?void 0:i.to)||0,total:(i==null?void 0:i.total)||0,links:i==null?void 0:i.links,entityName:t("attendance policies"),onPageChange:r=>{const s=new URL(r).searchParams.get("page")||"1";m.get(route("hr.attendance-policies.index"),{page:s,search:p||void 0,status:n!=="all"?n:void 0,sort_field:o.sort_field||void 0,sort_direction:o.sort_direction||void 0,per_page:o.per_page},{preserveState:!0,preserveScroll:!0})}})})]}),e.jsx(le,{isOpen:V,onClose:()=>u(!1),onSubmit:U,formConfig:{fields:[{name:"name",label:t("Policy Name"),type:"text",required:!0},{name:"description",label:t("Description"),type:"textarea"},{name:"late_arrival_grace",label:t("Late Arrival Grace (minutes)"),type:"number",required:!0,min:0,defaultValue:15},{name:"early_departure_grace",label:t("Early Departure Grace (minutes)"),type:"number",required:!0,min:0,defaultValue:15},{name:"overtime_rate_per_hour",label:t("Overtime Rate Per Hour"),type:"number",required:!0,min:0,step:.01,defaultValue:150},{name:"status",label:t("Status"),type:"select",options:[{value:"active",label:"Active"},{value:"inactive",label:"Inactive"}],defaultValue:"active"}],modalSize:"lg"},initialData:x,title:t(b==="create"?"Add New Attendance Policy":"Edit Attendance Policy"),mode:b}),e.jsx(ne,{isOpen:$,onClose:()=>w(!1),onConfirm:J,itemName:(x==null?void 0:x.name)||"",entityName:"attendance policy"}),e.jsx(se,{open:!!k,onOpenChange:()=>D(null),children:k&&e.jsx(de,{policy:k})})]})}export{ut as default};
|