"use strict";(()=>{var e={};e.id=5481,e.ids=[5481],e.modules={4530:e=>{e.exports=require("@prisma/client/runtime/library")},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")},42716:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>w,patchFetch:()=>y,requestAsyncStorage:()=>x,routeModule:()=>m,serverHooks:()=>v,staticGenerationAsyncStorage:()=>f});var n={};r.r(n),r.d(n,{GET:()=>p});var s=r(49303),a=r(88716),i=r(60670),o=r(87070),u=r(95456),c=r(8194),l=r(45239),d=r(4530);async function p(e){try{let t=await (0,u.ts)();if(!t)return o.NextResponse.json({error:"Unauthorized"},{status:401});let r=await (0,l.F)(t.tenantId,"inventory");if(r)return r;let n=e.nextUrl.searchParams.get("storeId"),s="true"===e.nextUrl.searchParams.get("lowStockOnly");if(!n)return o.NextResponse.json({error:"storeId wajib diisi"},{status:400});let a=await c._.store.findFirst({where:{id:n,tenantId:t.tenantId}});if(!a)return o.NextResponse.json({error:"Cabang tidak ditemukan"},{status:404});let i={storeId:n,ingredient:{tenantId:t.tenantId,isActive:!0}},p=(await c._.stockLevel.findMany({where:i,include:{ingredient:{select:{id:!0,name:!0,unit:!0,costPerUnit:!0}}},orderBy:{ingredient:{name:"asc"}}})).map(e=>{let t=new d.Decimal(e.currentStock),r=new d.Decimal(e.minStock),n="ok";return t.lte(0)?n="out":t.lte(r)&&(n="low"),{...e,status:n}}).filter(e=>!s||"out"===e.status||"low"===e.status).sort((e,t)=>{let r={out:0,low:1,ok:2};return r[e.status]-r[t.status]});return o.NextResponse.json({stockLevels:p,store:a})}catch{return o.NextResponse.json({error:"Internal server error"},{status:500})}}let m=new s.AppRouteRouteModule({definition:{kind:a.x.APP_ROUTE,page:"/api/inventory/stock-levels/route",pathname:"/api/inventory/stock-levels",filename:"route",bundlePath:"app/api/inventory/stock-levels/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\inventory\\stock-levels\\route.ts",nextConfigOutput:"",userland:n}),{requestAsyncStorage:x,staticGenerationAsyncStorage:f,serverHooks:v}=m,w="/api/inventory/stock-levels/route";function y(){return(0,i.patchFetch)({serverHooks:v,staticGenerationAsyncStorage:f})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>d,MH:()=>f,PT:()=>v,RA:()=>p,WX:()=>m,c_:()=>l,ts:()=>x});var n=r(41482),s=r.n(n),a=r(42023),i=r.n(a),o=r(71615),u=r(8194);let c=process.env.JWT_SECRET||"fallback-secret-change-me";async function l(e){return i().hash(e,12)}async function d(e,t){return i().compare(e,t)}function p(e){return s().sign(e,c,{expiresIn:"7d"})}function m(e){try{return s().verify(e,c)}catch{return null}}async function x(){let e=await (0,o.cookies)(),t=e.get("token")?.value;if(!t)return null;let r=m(t);return r?await u._.user.findUnique({where:{id:r.userId},include:{tenant:!0,store:!0}}):null}function f(e,t){return t.includes(e)}function v(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>s});let n=require("@prisma/client"),s=globalThis.prisma??new n.PrismaClient},45239:(e,t,r)=>{r.d(t,{F:()=>a});var n=r(87070),s=r(15230);async function a(e,t){let r=await (0,s.p6)(e);return(0,s.U6)(r.features,t)?null:n.NextResponse.json({error:"Fitur ini tidak tersedia pada paket Anda. Silakan upgrade."},{status:403})}},15230:(e,t,r)=>{r.d(t,{MN:()=>a,U6:()=>i,p6:()=>s});var n=r(8194);async function s(e){let t=await n._.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 a(e,t){let r=await s(e),a=0,i=0;switch(t){case"stores":a=await n._.store.count({where:{tenantId:e,isActive:!0}}),i=r.maxStores;break;case"staff":a=await n._.user.count({where:{tenantId:e,isActive:!0}}),i=r.maxStaff;break;case"menuItems":a=await n._.menuItem.count({where:{tenantId:e,isActive:!0}}),i=r.maxMenuItems;break;case"orders":let o=new Date;o.setDate(1),o.setHours(0,0,0,0),a=await n._.order.count({where:{tenantId:e,createdAt:{gte:o}}}),i=r.maxOrders}return 0===i?{allowed:!0,current:a,max:i}:{allowed:a<i,current:a,max:i}}function i(e,t){return e.includes(t)}}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),n=t.X(0,[8948,5972,4261,2023],()=>r(42716));module.exports=n})();