module.exports=[896114,e=>{"use strict";var t=e.i(747909),a=e.i(174017),s=e.i(996250),n=e.i(759756),r=e.i(561916),o=e.i(174677),i=e.i(869741),l=e.i(316795),d=e.i(487718),p=e.i(995169),u=e.i(47587),c=e.i(666012),h=e.i(570101),m=e.i(626937),g=e.i(10372),v=e.i(193695);e.i(52474);var f=e.i(600220),x=e.i(89171),w=e.i(679371);e.i(484848);var b=e.i(196705),y=e.i(526571),R=e.i(875225),E=e.i(349129),A=e.i(518899),C=e.i(39048),$=e.i(35355);let T={bkash:"bKash",nagad:"Nagad",rocket:"Rocket",upay:"Upay",bank_transfer:"Bank Transfer",cash:"Cash"};async function N(e){try{var t,a,s;let n,r,o,i=await (0,C.getAuthUser)(e);if(!i?.id)return x.NextResponse.json({error:"Session not found. Please login first."},{status:401});if(!["admin","super_admin"].includes(i.role))return x.NextResponse.json({error:"Unauthorized. Admin access required."},{status:403});let{searchParams:l}=new URL(e.url),d=l.get("status"),p=l.get("method"),u=l.get("plan"),c=l.get("search"),h=l.get("startDate"),m=l.get("endDate"),g=[];if(d&&g.push((0,R.eq)(b.payments.status,d)),p&&g.push((0,R.eq)(b.payments.method,p)),u&&g.push((0,R.eq)(b.payments.plan,u)),c&&g.push((0,R.or)((0,R.ilike)(b.payments.transaction_id,`%${c}%`),A.sql`EXISTS (
            SELECT 1 FROM ${y.users}
            WHERE ${y.users.id} = ${b.payments.user_id}
            AND (
              ${y.users.name} ILIKE ${`%${c}%`}
              OR ${y.users.phone} ILIKE ${`%${c}%`}
            )
          )`)),h&&g.push(A.sql`${b.payments.created_at} >= ${new Date(h)}`),m){let e=new Date(m);e.setDate(e.getDate()+1),g.push(A.sql`${b.payments.created_at} < ${e}`)}let v=g.length>0?(0,R.and)(...g):void 0,f=await w.db.select({id:b.payments.id,transaction_id:b.payments.transaction_id,amount:b.payments.amount,method:b.payments.method,status:b.payments.status,plan:b.payments.plan,created_at:b.payments.created_at,user:{name:y.users.name,phone:y.users.phone}}).from(b.payments).leftJoin(y.users,(0,R.eq)(b.payments.user_id,y.users.id)).where(v).orderBy((0,E.desc)(b.payments.created_at)),N=await w.db.select({status:b.payments.status,count:A.sql`count(*)::int`}).from(b.payments).where(v).groupBy(b.payments.status),q=await w.db.select({total:A.sql`coalesce(sum(${b.payments.amount}), 0)::int`}).from(b.payments).where((0,R.and)(v||A.sql`1=1`,(0,R.eq)(b.payments.status,"approved"))),O={total:f.length,pending:0,approved:0,rejected:0,totalApprovedAmount:q[0]?.total||0};N.forEach(({status:e,count:t})=>{"pending"===e&&(O.pending=t),"approved"===e&&(O.approved=t),"rejected"===e&&(O.rejected=t)});let k=await (0,$.launchBrowser)(),I=await k.newPage(),U=(t=f,a=O,s={status:d,method:p,plan:u,search:c,startDate:h,endDate:m},n="",t.forEach((e,t)=>{let a={pending:"#f59e0b",approved:"#10b981",rejected:"#ef4444"}[e.status]||"#6b7280";n+=`
      <tr class="${t%2==0?"even":"odd"}">
        <td class="text-center">${_(t+1)}</td>
        <td>${P(e.transaction_id||"")}</td>
        <td>${P(e.user?.name||"N/A")}</td>
        <td>${P(e.user?.phone||"N/A")}</td>
        <td>${P(T[e.method]||e.method)}</td>
        <td class="text-center">${P(e.plan||"N/A")}</td>
        <td class="text-right">৳${_(e.amount)}</td>
        <td class="text-center">
          <span style="color: ${a}; font-weight: 600;">${D(e.status)}</span>
        </td>
        <td class="text-center">${S(e.created_at)}</td>
      </tr>
    `}),r="সকল পেমেন্ট",o=[],s.status&&o.push(D(s.status)),s.method&&o.push(T[s.method]),s.plan&&o.push(s.plan),s.startDate&&o.push(`${s.startDate} থেকে`),s.endDate&&o.push(`${s.endDate} পর্যন্ত`),o.length>0&&(r=o.join(" + ")),`
    <!DOCTYPE html>
    <html lang="bn">
    <head>
      <meta charset="UTF-8">
      <title>Payments Export</title>
      <link href="https://banglawebfonts.pages.dev/css/kalpurush.css" rel="stylesheet">
      <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
          font-family: "Kalpurush", "Noto Sans Bengali", Arial, sans-serif;
          font-size: 10px;
          line-height: 1.3;
          color: #000;
          background: #fff;
          padding: 8px;
        }
        .header {
          text-align: center;
          margin-bottom: 8px;
          border-bottom: 2px solid #000;
          padding-bottom: 6px;
        }
        .title {
          font-size: 18px;
          font-weight: bold;
          margin-bottom: 4px;
        }
        .subtitle {
          font-size: 12px;
          color: #666;
          margin-bottom: 4px;
        }
        .stats-row {
          display: flex;
          justify-content: space-between;
          margin-bottom: 8px;
          flex-wrap: wrap;
          gap: 8px;
        }
        .stat-box {
          flex: 1;
          min-width: 120px;
          padding: 8px;
          border: 1px solid #000;
          border-radius: 4px;
          text-align: center;
        }
        .stat-label {
          font-size: 9px;
          color: #666;
          margin-bottom: 2px;
        }
        .stat-value {
          font-size: 16px;
          font-weight: bold;
          color: #000;
        }
        .stat-value.green { color: #10b981; }
        .stat-value.yellow { color: #f59e0b; }
        .stat-value.red { color: #ef4444; }
        .stat-value.emerald { color: #059669; }
        .table-container {
          width: 100%;
          overflow-x: auto;
        }
        table {
          width: 100%;
          border-collapse: collapse;
          font-size: 9px;
        }
        thead {
          background: #f3f4f6;
        }
        th {
          padding: 6px 4px;
          text-align: left;
          font-weight: 600;
          border: 1px solid #000;
          font-size: 9px;
        }
        th.text-center { text-align: center; }
        th.text-right { text-align: right; }
        td {
          padding: 4px;
          border: 1px solid #000;
        }
        tr.even { background: #f9fafb; }
        tr.odd { background: #ffffff; }
        td.text-center { text-align: center; }
        td.text-right { text-align: right; }
        .footer {
          margin-top: 8px;
          text-align: center;
          font-size: 8px;
          color: #999;
        }
      </style>
    </head>
    <body>
      <div class="header">
        <div class="title">পেমেন্ট রিপোর্ট</div>
        <div class="subtitle">${P(r)}</div>
        <div class="subtitle">রিপোর্ট তারিখ: ${S(new Date)}</div>
      </div>

      <div class="stats-row">
        <div class="stat-box">
          <div class="stat-label">মোট পেমেন্ট</div>
          <div class="stat-value">${_(a.total)}</div>
        </div>
        <div class="stat-box">
          <div class="stat-label">অপেক্ষমাণ</div>
          <div class="stat-value yellow">${_(a.pending)}</div>
        </div>
        <div class="stat-box">
          <div class="stat-label">অনুমোদিত</div>
          <div class="stat-value green">${_(a.approved)}</div>
        </div>
        <div class="stat-box">
          <div class="stat-label">প্রত্যাখ্যাত</div>
          <div class="stat-value red">${_(a.rejected)}</div>
        </div>
        <div class="stat-box">
          <div class="stat-label">মোট অনুমোদিত টাকা</div>
          <div class="stat-value emerald">৳${_(a.totalApprovedAmount)}</div>
        </div>
      </div>

      <div class="table-container">
        <table>
          <thead>
            <tr>
              <th class="text-center" width="5%">ক্র.</th>
              <th width="12%">ট্রানজেকশন ID</th>
              <th width="15%">নাম</th>
              <th width="12%">ফোন</th>
              <th width="10%">মেথড</th>
              <th class="text-center" width="10%">প্ল্যান</th>
              <th class="text-right" width="10%">টাকা</th>
              <th class="text-center" width="10%">স্ট্যাটাস</th>
              <th class="text-center" width="16%">তারিখ</th>
            </tr>
          </thead>
          <tbody>
            ${n}
          </tbody>
        </table>
      </div>

      <div class="footer">
        Generated by ekappbd.com | ${new Date().toLocaleDateString("bn-BD")}
      </div>
    </body>
    </html>
  `);await I.setContent(U,{waitUntil:["networkidle0","domcontentloaded"],timeout:3e4}),await I.evaluate(()=>Promise.all([document.fonts.ready])),await new Promise(e=>setTimeout(e,1e3));let H=await I.pdf({format:"A4",printBackground:!0,margin:{top:"8mm",right:"8mm",bottom:"8mm",left:"8mm"}});return await k.close(),new x.NextResponse(H,{headers:{"Content-Type":"application/pdf","Content-Disposition":`attachment; filename="Payments-Export-${new Date().toISOString().split("T")[0]}.pdf"`,"Cache-Control":"no-cache"}})}catch(e){return console.error("Payments PDF generation error:",e),x.NextResponse.json({error:"Failed to generate PDF",message:e.message},{status:500})}}function _(e){let t=["০","১","২","৩","৪","৫","৬","৭","৮","৯"];return String(e).replace(/\d/g,e=>t[parseInt(e)])}function D(e){return({pending:"অপেক্ষমাণ",approved:"অনুমোদিত",rejected:"প্রত্যাখ্যাত"})[e]||e}function P(e){if(!e)return"";let t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};return e.replace(/[&<>"']/g,e=>t[e])}function S(e){let t=new Date(e),a=_(t.getDate()),s=["জানুয়ারি","ফেব্রুয়ারি","মার্চ","এপ্রিল","মে","জুন","জুলাই","আগস্ট","সেপ্টেম্বর","অক্টোবর","নভেম্বর","ডিসেম্বর"][t.getMonth()],n=_(t.getFullYear());return`${a} ${s}, ${n}`}let q=async()=>new Response(null,{status:204,headers:{"Access-Control-Allow-Credentials":"true","Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"GET,OPTIONS","Access-Control-Allow-Headers":"Authorization, Content-Type"}});e.s(["GET",0,N,"OPTIONS",0,q],573079);var O=e.i(573079);let k=new t.AppRouteRouteModule({definition:{kind:a.RouteKind.APP_ROUTE,page:"/api/payments/export/route",pathname:"/api/payments/export",filename:"route",bundlePath:""},distDir:"_next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/payments/export/route.ts",nextConfigOutput:"standalone",userland:O,...{}}),{workAsyncStorage:I,workUnitAsyncStorage:U,serverHooks:H}=k;async function j(e,t,s){s.requestMeta&&(0,n.setRequestMeta)(e,s.requestMeta),k.isDev&&(0,n.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let x="/api/payments/export/route";x=x.replace(/\/index$/,"")||"/";let w=await k.prepare(e,t,{srcPage:x,multiZoneDraftMode:!1});if(!w)return t.statusCode=400,t.end("Bad Request"),null==s.waitUntil||s.waitUntil.call(s,Promise.resolve()),null;let{buildId:b,params:y,nextConfig:R,parsedUrl:E,isDraftMode:A,prerenderManifest:C,routerServerContext:$,isOnDemandRevalidate:T,revalidateOnlyGenerated:N,resolvedPathname:_,clientReferenceManifest:D,serverActionsManifest:P}=w,S=(0,i.normalizeAppPath)(x),q=!!(C.dynamicRoutes[S]||C.routes[_]),O=async()=>((null==$?void 0:$.render404)?await $.render404(e,t,E,!1):t.end("This page could not be found"),null);if(q&&!A){let e=!!C.routes[_],t=C.dynamicRoutes[S];if(t&&!1===t.fallback&&!e){if(R.adapterPath)return await O();throw new v.NoFallbackError}}let I=null;!q||k.isDev||A||(I="/index"===(I=_)?"/":I);let U=!0===k.isDev||!q,H=q&&!U;P&&D&&(0,o.setManifestsSingleton)({page:x,clientReferenceManifest:D,serverActionsManifest:P});let j=e.method||"GET",M=(0,r.getTracer)(),F=M.getActiveScopeSpan(),B=!!(null==$?void 0:$.isWrappedByNextServer),z=!!(0,n.getRequestMeta)(e,"minimalMode"),K=(0,n.getRequestMeta)(e,"incrementalCache")||await k.getIncrementalCache(e,R,C,z);null==K||K.resetRequestCache(),globalThis.__incrementalCache=K;let L={params:y,previewProps:C.preview,renderOpts:{experimental:{authInterrupts:!!R.experimental.authInterrupts},cacheComponents:!!R.cacheComponents,supportsDynamicResponse:U,incrementalCache:K,cacheLifeProfiles:R.cacheLife,waitUntil:s.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,a,s,n)=>k.onRequestError(e,t,s,n,$)},sharedContext:{buildId:b}},G=new l.NodeNextRequest(e),W=new l.NodeNextResponse(t),X=d.NextRequestAdapter.fromNodeNextRequest(G,(0,d.signalFromNodeResponse)(t));try{let n,o=async e=>k.handle(X,L).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let a=M.getRootSpanAttributes();if(!a)return;if(a.get("next.span_type")!==p.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${a.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let s=a.get("next.route");if(s){let t=`${j} ${s}`;e.setAttributes({"next.route":s,"http.route":s,"next.span_name":t}),e.updateName(t),n&&n!==e&&(n.setAttribute("http.route",s),n.updateName(t))}else e.updateName(`${j} ${x}`)}),i=async n=>{var r,i;let l=async({previousCacheEntry:a})=>{try{if(!z&&T&&N&&!a)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let r=await o(n);e.fetchMetrics=L.renderOpts.fetchMetrics;let i=L.renderOpts.pendingWaitUntil;i&&s.waitUntil&&(s.waitUntil(i),i=void 0);let l=L.renderOpts.collectedTags;if(!q)return await (0,c.sendResponse)(G,W,r,L.renderOpts.pendingWaitUntil),null;{let e=await r.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(r.headers);l&&(t[g.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let a=void 0!==L.renderOpts.collectedRevalidate&&!(L.renderOpts.collectedRevalidate>=g.INFINITE_CACHE)&&L.renderOpts.collectedRevalidate,s=void 0===L.renderOpts.collectedExpire||L.renderOpts.collectedExpire>=g.INFINITE_CACHE?void 0:L.renderOpts.collectedExpire;return{value:{kind:f.CachedRouteKind.APP_ROUTE,status:r.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:a,expire:s}}}}catch(t){throw(null==a?void 0:a.isStale)&&await k.onRequestError(e,t,{routerKind:"App Router",routePath:x,routeType:"route",revalidateReason:(0,u.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:T})},!1,$),t}},d=await k.handleResponse({req:e,nextConfig:R,cacheKey:I,routeKind:a.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:C,isRoutePPREnabled:!1,isOnDemandRevalidate:T,revalidateOnlyGenerated:N,responseGenerator:l,waitUntil:s.waitUntil,isMinimalMode:z});if(!q)return null;if((null==d||null==(r=d.value)?void 0:r.kind)!==f.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==d||null==(i=d.value)?void 0:i.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});z||t.setHeader("x-nextjs-cache",T?"REVALIDATED":d.isMiss?"MISS":d.isStale?"STALE":"HIT"),A&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let p=(0,h.fromNodeOutgoingHttpHeaders)(d.value.headers);return z&&q||p.delete(g.NEXT_CACHE_TAGS_HEADER),!d.cacheControl||t.getHeader("Cache-Control")||p.get("Cache-Control")||p.set("Cache-Control",(0,m.getCacheControlHeader)(d.cacheControl)),await (0,c.sendResponse)(G,W,new Response(d.value.body,{headers:p,status:d.value.status||200})),null};B&&F?await i(F):(n=M.getActiveScopeSpan(),await M.withPropagatedContext(e.headers,()=>M.trace(p.BaseServerSpan.handleRequest,{spanName:`${j} ${x}`,kind:r.SpanKind.SERVER,attributes:{"http.method":j,"http.target":e.url}},i),void 0,!B))}catch(t){if(t instanceof v.NoFallbackError||await k.onRequestError(e,t,{routerKind:"App Router",routePath:S,routeType:"route",revalidateReason:(0,u.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:T})},!1,$),q)throw t;return await (0,c.sendResponse)(G,W,new Response(null,{status:500})),null}}e.s(["handler",0,j,"patchFetch",0,function(){return(0,s.patchFetch)({workAsyncStorage:I,workUnitAsyncStorage:U})},"routeModule",0,k,"serverHooks",0,H,"workAsyncStorage",0,I,"workUnitAsyncStorage",0,U],896114)}];

//# sourceMappingURL=node_modules_next_dist_esm_build_templates_app-route_08vnthk.js.map