"use strict";(()=>{var e={};e.id=9663,e.ids=[9663],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")},95970:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>g,patchFetch:()=>h,requestAsyncStorage:()=>d,routeModule:()=>p,serverHooks:()=>x,staticGenerationAsyncStorage:()=>m});var a={};r.r(a),r.d(a,{GET:()=>l});var s=r(49303),n=r(88716),o=r(60670),i=r(87070),u=r(8194),c=r(95456);async function l(e){try{let t=await (0,c.ts)();if(!t)return i.NextResponse.json({error:"Unauthorized"},{status:401});let r=e.nextUrl.searchParams.get("startDate"),a=e.nextUrl.searchParams.get("endDate"),s=e.nextUrl.searchParams.get("storeId"),n=e.nextUrl.searchParams.get("type")||"all",o=parseInt(e.nextUrl.searchParams.get("page")||"1"),l=parseInt(e.nextUrl.searchParams.get("limit")||"20"),p=(o-1)*l,d={tenantId:t.tenantId,paymentStatus:"paid"};if("tax"===n?d.tax={gt:0}:"service"===n&&(d.serviceCharge={gt:0}),r&&a){let e=new Date(r),t=new Date(a);t.setHours(23,59,59,999),d.createdAt={gte:e,lte:t}}s&&(d.storeId=s),t.storeId&&(d.storeId=t.storeId);let[m,x,g]=await Promise.all([u._.order.findMany({where:d,include:{store:{select:{name:!0}}},orderBy:{createdAt:"desc"},take:l,skip:p}),u._.order.count({where:d}),u._.order.aggregate({where:d,_sum:{tax:!0,serviceCharge:!0,subtotal:!0,total:!0},_count:!0})]),h=Number(g._sum.tax)||0,v=Number(g._sum.serviceCharge)||0,f=g._count;return i.NextResponse.json({type:n,summary:{totalTax:h,totalServiceCharge:v,totalTransactions:f,avgTax:f>0?h/f:0,avgServiceCharge:f>0?v/f:0,totalSubtotal:Number(g._sum.subtotal)||0,totalTotal:Number(g._sum.total)||0},orders:m.map(e=>({id:e.id,createdAt:e.createdAt,orderNumber:e.orderNumber,storeName:e.store.name,subtotal:Number(e.subtotal),tax:Number(e.tax),serviceCharge:Number(e.serviceCharge),total:Number(e.total),paymentMethod:e.paymentMethod||"-"})),pagination:{page:o,limit:l,total:x,totalPages:Math.ceil(x/l)}})}catch(e){return console.error("Tax report error:",e),i.NextResponse.json({error:"Server error"},{status:500})}}let p=new s.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/reports/tax/route",pathname:"/api/reports/tax",filename:"route",bundlePath:"app/api/reports/tax/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\reports\\tax\\route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:d,staticGenerationAsyncStorage:m,serverHooks:x}=p,g="/api/reports/tax/route";function h(){return(0,o.patchFetch)({serverHooks:x,staticGenerationAsyncStorage:m})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>p,MH:()=>g,PT:()=>h,RA:()=>d,WX:()=>m,c_:()=>l,ts:()=>x});var a=r(41482),s=r.n(a),n=r(42023),o=r.n(n),i=r(71615),u=r(8194);let c=process.env.JWT_SECRET||"fallback-secret-change-me";async function l(e){return o().hash(e,12)}async function p(e,t){return o().compare(e,t)}function d(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,i.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 g(e,t){return t.includes(e)}function h(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>s});let a=require("@prisma/client"),s=globalThis.prisma??new a.PrismaClient}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[8948,5972,4261,2023],()=>r(95970));module.exports=a})();