"use strict";(()=>{var e={};e.id=7339,e.ids=[7339],e.modules={72934:e=>{e.exports=require("next/dist/client/components/action-async-storage.external.js")},54580:e=>{e.exports=require("next/dist/client/components/request-async-storage.external.js")},45869:e=>{e.exports=require("next/dist/client/components/static-generation-async-storage.external.js")},20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},78893:e=>{e.exports=require("buffer")},84770:e=>{e.exports=require("crypto")},76162:e=>{e.exports=require("stream")},21764:e=>{e.exports=require("util")},42068:(e,t,a)=>{a.r(t),a.d(t,{originalPathname:()=>f,patchFetch:()=>A,requestAsyncStorage:()=>p,routeModule:()=>m,serverHooks:()=>x,staticGenerationAsyncStorage:()=>S});var r={};a.r(r),a.d(r,{GET:()=>c});var s=a(49303),n=a(88716),u=a(60670),o=a(87070),i=a(95456),l=a(8194),d=a(45239);async function c(e){try{let t,a;let r=await (0,i.ts)();if(!r)return o.NextResponse.json({error:"Unauthorized"},{status:401});if(!["owner","admin","manager"].includes(r.role))return o.NextResponse.json({error:"Forbidden"},{status:403});let s=await (0,d.F)(r.tenantId,"attendance");if(s)return s;let n=e.nextUrl.searchParams.get("storeId"),u=e.nextUrl.searchParams.get("month"),c=new Date;if(u&&/^\d{4}-\d{2}$/.test(u)){let[e,r]=u.split("-").map(Number);t=e,a=r}else t=c.getFullYear(),a=c.getMonth()+1;let m=new Date(Date.UTC(t,a-1,1)),p=new Date(Date.UTC(t,a,0)),S=(n?await l._.$queryRaw`
        SELECT
          a.userId,
          u.name AS userName,
          COUNT(*) AS totalDays,
          COALESCE(SUM(a.totalHours), 0) AS totalHours,
          COALESCE(AVG(a.totalHours), 0) AS avgHoursPerDay,
          SUM(CASE WHEN a.status = 'late' THEN 1 ELSE 0 END) AS lateDays,
          COALESCE(SUM(a.overtimeMinutes), 0) AS totalOvertimeMinutes
        FROM attendances a
        JOIN users u ON u.id = a.userId
        WHERE a.tenantId = ${r.tenantId}
          AND a.storeId = ${n}
          AND a.date >= ${m}
          AND a.date <= ${p}
        GROUP BY a.userId, u.name
        ORDER BY u.name ASC
      `:await l._.$queryRaw`
        SELECT
          a.userId,
          u.name AS userName,
          COUNT(*) AS totalDays,
          COALESCE(SUM(a.totalHours), 0) AS totalHours,
          COALESCE(AVG(a.totalHours), 0) AS avgHoursPerDay,
          SUM(CASE WHEN a.status = 'late' THEN 1 ELSE 0 END) AS lateDays,
          COALESCE(SUM(a.overtimeMinutes), 0) AS totalOvertimeMinutes
        FROM attendances a
        JOIN users u ON u.id = a.userId
        WHERE a.tenantId = ${r.tenantId}
          AND a.date >= ${m}
          AND a.date <= ${p}
        GROUP BY a.userId, u.name
        ORDER BY u.name ASC
      `).map(e=>({userId:e.userId,userName:e.userName,totalDays:Number(e.totalDays),totalHours:parseFloat((e.totalHours||0).toString()),avgHoursPerDay:parseFloat((e.avgHoursPerDay||0).toString()),lateDays:Number(e.lateDays),totalOvertimeMinutes:Number(e.totalOvertimeMinutes)})),x=S.length,f=S.reduce((e,t)=>e+t.totalDays,0),A=S.reduce((e,t)=>e+t.lateDays,0),E=`${t}-${String(a).padStart(2,"0")}`;return o.NextResponse.json({summary:S,overallStats:{totalStaff:x,totalWorkDays:f,totalLateDays:A},month:E})}catch{return o.NextResponse.json({error:"Server error"},{status:500})}}let m=new s.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/attendance/summary/route",pathname:"/api/attendance/summary",filename:"route",bundlePath:"app/api/attendance/summary/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\attendance\\summary\\route.ts",nextConfigOutput:"",userland:r}),{requestAsyncStorage:p,staticGenerationAsyncStorage:S,serverHooks:x}=m,f="/api/attendance/summary/route";function A(){return(0,u.patchFetch)({serverHooks:x,staticGenerationAsyncStorage:S})}},95456:(e,t,a)=>{a.d(t,{Gv:()=>c,MH:()=>x,PT:()=>f,RA:()=>m,WX:()=>p,c_:()=>d,ts:()=>S});var r=a(41482),s=a.n(r),n=a(42023),u=a.n(n),o=a(71615),i=a(8194);let l=process.env.JWT_SECRET||"fallback-secret-change-me";async function d(e){return u().hash(e,12)}async function c(e,t){return u().compare(e,t)}function m(e){return s().sign(e,l,{expiresIn:"7d"})}function p(e){try{return s().verify(e,l)}catch{return null}}async function S(){let e=await (0,o.cookies)(),t=e.get("token")?.value;if(!t)return null;let a=p(t);return a?await i._.user.findUnique({where:{id:a.userId},include:{tenant:!0,store:!0}}):null}function x(e,t){return t.includes(e)}function f(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,a)=>{a.d(t,{_:()=>s});let r=require("@prisma/client"),s=globalThis.prisma??new r.PrismaClient},45239:(e,t,a)=>{a.d(t,{F:()=>n});var r=a(87070),s=a(15230);async function n(e,t){let a=await (0,s.p6)(e);return(0,s.U6)(a.features,t)?null:r.NextResponse.json({error:"Fitur ini tidak tersedia pada paket Anda. Silakan upgrade."},{status:403})}},15230:(e,t,a)=>{a.d(t,{MN:()=>n,U6:()=>u,p6:()=>s});var r=a(8194);async function s(e){let t=await r._.subscription.findFirst({where:{tenantId:e,status:{in:["active","trial"]}},include:{plan:!0},orderBy:{createdAt:"desc"}});return t?{maxStores:t.plan.maxStores,maxStaff:t.plan.maxStaff,maxMenuItems:t.plan.maxMenuItems,maxOrders:t.plan.maxOrders,features:JSON.parse(t.plan.features)}:{maxStores:1,maxStaff:3,maxMenuItems:30,maxOrders:100,features:["pos","qr_menu"]}}async function n(e,t){let a=await s(e),n=0,u=0;switch(t){case"stores":n=await r._.store.count({where:{tenantId:e,isActive:!0}}),u=a.maxStores;break;case"staff":n=await r._.user.count({where:{tenantId:e,isActive:!0}}),u=a.maxStaff;break;case"menuItems":n=await r._.menuItem.count({where:{tenantId:e,isActive:!0}}),u=a.maxMenuItems;break;case"orders":let o=new Date;o.setDate(1),o.setHours(0,0,0,0),n=await r._.order.count({where:{tenantId:e,createdAt:{gte:o}}}),u=a.maxOrders}return 0===u?{allowed:!0,current:n,max:u}:{allowed:n<u,current:n,max:u}}function u(e,t){return e.includes(t)}}};var t=require("../../../../webpack-runtime.js");t.C(e);var a=e=>t(t.s=e),r=t.X(0,[8948,5972,4261,2023],()=>a(42068));module.exports=r})();