"use strict";(()=>{var e={};e.id=113,e.ids=[113],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")},59096:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>x,patchFetch:()=>v,requestAsyncStorage:()=>m,routeModule:()=>l,serverHooks:()=>y,staticGenerationAsyncStorage:()=>h});var a={};r.r(a),r.d(a,{GET:()=>d});var n=r(49303),s=r(88716),o=r(60670),i=r(87070),u=r(8194),c=r(95456);let p=["qris","card","transfer"];async function d(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"),n=e.nextUrl.searchParams.get("storeId"),s=e.nextUrl.searchParams.get("paymentMethod"),o=parseInt(e.nextUrl.searchParams.get("page")||"1"),d=parseInt(e.nextUrl.searchParams.get("limit")||"20"),l=(o-1)*d,m={tenantId:t.tenantId,paymentStatus:"paid"};if(s&&p.includes(s)?"transfer"===s?m.paymentMethod={in:["transfer","va_bca","va_bni","va_bri","va_mandiri","va_cimb","va_permata"]}:m.paymentMethod=s:m.paymentMethod={in:["qris","card","transfer","va_bca","va_bni","va_bri","va_mandiri","va_cimb","va_permata"]},r&&a){let e=new Date(r),t=new Date(a);t.setHours(23,59,59,999),m.createdAt={gte:e,lte:t}}n&&(m.storeId=n),t.storeId&&(m.storeId=t.storeId);let[h,y,x]=await Promise.all([u._.order.findMany({where:m,include:{store:{select:{name:!0}}},orderBy:{createdAt:"desc"},take:d,skip:l}),u._.order.count({where:m}),u._.order.aggregate({where:m,_sum:{total:!0},_count:!0})]),v=await u._.order.groupBy({by:["paymentMethod"],where:m,_sum:{total:!0},_count:!0}),_={};for(let e of v){let t=e.paymentMethod||"other",r=t.startsWith("va_")?"transfer":t;_[r]||(_[r]={count:0,amount:0}),_[r].count+=e._count,_[r].amount+=Number(e._sum.total)||0}return i.NextResponse.json({summary:{totalAmount:Number(x._sum.total)||0,totalTransactions:x._count,breakdown:_},orders:h.map(e=>({id:e.id,createdAt:e.createdAt,orderNumber:e.orderNumber,storeName:e.store.name,total:Number(e.total),paymentMethod:e.paymentMethod||"-",approvalCode:e.approvalCode||"",customerName:e.customerName||"-"})),pagination:{page:o,limit:d,total:y,totalPages:Math.ceil(y/d)}})}catch(e){return console.error("Payment report error:",e),i.NextResponse.json({error:"Server error"},{status:500})}}let l=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/reports/payments/route",pathname:"/api/reports/payments",filename:"route",bundlePath:"app/api/reports/payments/route"},resolvedPagePath:"D:\\PROJECT\\resto-saas\\src\\app\\api\\reports\\payments\\route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:m,staticGenerationAsyncStorage:h,serverHooks:y}=l,x="/api/reports/payments/route";function v(){return(0,o.patchFetch)({serverHooks:y,staticGenerationAsyncStorage:h})}},95456:(e,t,r)=>{r.d(t,{Gv:()=>d,MH:()=>y,PT:()=>x,RA:()=>l,WX:()=>m,c_:()=>p,ts:()=>h});var a=r(41482),n=r.n(a),s=r(42023),o=r.n(s),i=r(71615),u=r(8194);let c=process.env.JWT_SECRET||"fallback-secret-change-me";async function p(e){return o().hash(e,12)}async function d(e,t){return o().compare(e,t)}function l(e){return n().sign(e,c,{expiresIn:"7d"})}function m(e){try{return n().verify(e,c)}catch{return null}}async function h(){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 y(e,t){return t.includes(e)}function x(e){return!["owner","admin"].includes(e.role)&&!!e.storeId&&!!e.store&&!e.store.isActive}},8194:(e,t,r)=>{r.d(t,{_:()=>n});let a=require("@prisma/client"),n=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(59096));module.exports=a})();