diff options
| author | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-09-18 00:23:40 +0000 |
|---|---|---|
| committer | dujinkim <dujin.kim@dtsolution.co.kr> | 2025-09-18 00:23:40 +0000 |
| commit | cf8dac0c6490469dab88a560004b0c07dbd48612 (patch) | |
| tree | b9e76061e80d868331e6b4277deecb9086f845f3 /app | |
| parent | e5745fc0268bbb5770bc14a55fd58a0ec30b466e (diff) | |
(대표님) rfq, 계약, 서명 등
Diffstat (limited to 'app')
| -rw-r--r-- | app/[lng]/evcp/(evcp)/buyer-signature/page.tsx | 24 | ||||
| -rw-r--r-- | app/[lng]/evcp/(evcp)/general-contracts/page.tsx | 39 | ||||
| -rw-r--r-- | app/[lng]/evcp/(evcp)/itb-create/page.tsx | 164 | ||||
| -rw-r--r-- | app/api/contracts/get-template/route.ts | 16 | ||||
| -rw-r--r-- | app/api/upload/purchase-request/route.ts | 56 | ||||
| -rw-r--r-- | app/api/upload/signed-contract/route.ts | 3 |
6 files changed, 261 insertions, 41 deletions
diff --git a/app/[lng]/evcp/(evcp)/buyer-signature/page.tsx b/app/[lng]/evcp/(evcp)/buyer-signature/page.tsx new file mode 100644 index 00000000..fa3a1953 --- /dev/null +++ b/app/[lng]/evcp/(evcp)/buyer-signature/page.tsx @@ -0,0 +1,24 @@ +import { BuyerSignatureUploadForm } from '@/lib/shi-signature/upload-form'; +import { SignatureList } from '@/lib/shi-signature/signature-list'; +import { getAllSignatures } from '@/lib/shi-signature/buyer-signature'; + +export default async function BuyerSignaturePage() { + const signatures = await getAllSignatures(); + + return ( + <div className="container mx-auto py-8 max-w-4xl"> + <div className="space-y-8"> + <div> + <h1 className="text-3xl font-bold">구매자 서명 관리</h1> + <p className="text-muted-foreground mt-2"> + 계약서에 자동으로 적용될 삼성중공업 서명을 관리합니다. + </p> + </div> + + <BuyerSignatureUploadForm /> + + <SignatureList signatures={signatures} /> + </div> + </div> + ); +}
\ No newline at end of file diff --git a/app/[lng]/evcp/(evcp)/general-contracts/page.tsx b/app/[lng]/evcp/(evcp)/general-contracts/page.tsx index 47677bb3..a6d5057c 100644 --- a/app/[lng]/evcp/(evcp)/general-contracts/page.tsx +++ b/app/[lng]/evcp/(evcp)/general-contracts/page.tsx @@ -7,6 +7,7 @@ import { getGeneralContractCategoryCounts,
getVendors
} from "@/lib/general-contracts/service"
+import { searchParamsCache } from "@/lib/general-contracts/validation"
import { GeneralContractsTable } from "@/lib/general-contracts/main/general-contracts-table"
import { getValidFilters } from "@/lib/data-table"
import { type SearchParams } from "@/types/table"
@@ -21,43 +22,13 @@ interface IndexPageProps { searchParams: Promise<SearchParams>
}
-// searchParams 파싱을 위한 기본 파서 함수
-function parseSearchParams(searchParams: SearchParams) {
- const page = Number(searchParams.page) || 1
- const perPage = Number(searchParams.per_page) || 10
- const sort = searchParams.sort
- ? Array.isArray(searchParams.sort)
- ? searchParams.sort.map((s: string) => {
- const [id, desc] = s.split('.')
- return { id, desc: desc === 'desc' }
- })
- : [{ id: searchParams.sort.split('.')[0], desc: searchParams.sort.split('.')[1] === 'desc' }]
- : [{ id: "registeredAt", desc: true }]
-
- return {
- page,
- perPage,
- sort,
- filters: [],
- contractNumber: searchParams.contractNumber as string,
- name: searchParams.name as string,
- status: searchParams.status as string,
- category: searchParams.category as string,
- type: searchParams.type as string,
- vendorId: searchParams.vendorId ? Number(searchParams.vendorId) : undefined,
- createdAtFrom: searchParams.createdAtFrom as string,
- createdAtTo: searchParams.createdAtTo as string,
- signedAtFrom: searchParams.signedAtFrom as string,
- signedAtTo: searchParams.signedAtTo as string,
- search: searchParams.search as string,
- }
-}
-
export default async function GeneralContractsPage(props: IndexPageProps) {
// ✅ searchParams 파싱
const searchParams = await props.searchParams
- const search = parseSearchParams(searchParams)
-
+ const search = searchParamsCache.parse(searchParams)
+
+ console.log("Parsed search params:", search)
+
const validFilters = getValidFilters(search.filters)
// ✅ 모든 데이터를 병렬로 로드
diff --git a/app/[lng]/evcp/(evcp)/itb-create/page.tsx b/app/[lng]/evcp/(evcp)/itb-create/page.tsx new file mode 100644 index 00000000..54040e7f --- /dev/null +++ b/app/[lng]/evcp/(evcp)/itb-create/page.tsx @@ -0,0 +1,164 @@ +// app/[lng]/purchase-requests/page.tsx + +import * as React from "react"; +import { type SearchParams } from "@/types/table"; +import { getValidFilters } from "@/lib/data-table"; +import { Shell } from "@/components/shell"; +import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton"; +import { Button } from "@/components/ui/button"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; +import { Plus, FileText, Clock, CheckCircle, XCircle, Send } from "lucide-react"; +import Link from "next/link"; +import { searchParamsPurchaseRequestCache } from "@/lib/itb/validations"; +import { getAllPurchaseRequests, getPurchaseRequestStats } from "@/lib/itb/service"; +import { PurchaseRequestsTable } from "@/lib/itb/table/purchase-requests-table"; + +interface PurchaseRequestsPageProps { + params: { + lng: string; + }; + searchParams: Promise<SearchParams>; +} + +export default async function PurchaseRequestsPage(props: PurchaseRequestsPageProps) { + const resolvedParams = await props.params; + const lng = resolvedParams.lng; + + const searchParams = await props.searchParams; + + // Parse search params + const search = searchParamsPurchaseRequestCache.parse(searchParams); + const validFilters = getValidFilters(search.filters); + + // Load data + const promises = Promise.all([ + getAllPurchaseRequests({ + ...search, + filters: validFilters, + }), + getPurchaseRequestStats(), + ]); + + return ( + <Shell className="gap-4"> + <div className="flex items-center justify-between"> + <div> + <h2 className="text-2xl font-bold tracking-tight"> + 구매 요청 관리 + </h2> + <p className="text-muted-foreground"> + 프로젝트별 자재 구매 요청을 생성하고 관리합니다. + </p> + </div> + </div> + + {/* 통계 카드 */} + <React.Suspense + fallback={ + <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-6"> + {[...Array(6)].map((_, i) => ( + <Card key={i}> + <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2"> + <CardTitle className="text-sm font-medium"> + <div className="h-4 w-20 bg-muted animate-pulse rounded" /> + </CardTitle> + </CardHeader> + <CardContent> + <div className="h-8 w-12 bg-muted animate-pulse rounded" /> + </CardContent> + </Card> + ))} + </div> + } + > + <PurchaseRequestStats promises={promises} /> + </React.Suspense> + + <React.Suspense + fallback={ + <DataTableSkeleton + columnCount={13} + searchableColumnCount={1} + filterableColumnCount={3} + cellWidths={[ + "8rem", // requestCode + "15rem", // requestTitle + "12rem", // projectCode + "15rem", // projectName + "10rem", // packageNo + "8rem", // status + "10rem", // engPicName + "10rem", // purchasePicName + "10rem", // estimatedBudget + "10rem", // requestedDeliveryDate + "8rem", // itemCount + "10rem", // createdAt + "8rem", // actions + ]} + shrinkZero + /> + } + > + <PurchaseRequestsTable promises={promises} /> + </React.Suspense> + </Shell> + ); +} + +// 통계 컴포넌트 +async function PurchaseRequestStats({ + promises +}: { + promises: Promise<[any, any]> +}) { + const [, stats] = await promises; + + const statCards = [ + { + title: "전체", + value: stats?.total || 0, + icon: FileText, + color: "text-blue-500", + }, + { + title: "작성중", + value: stats?.draft || 0, + icon: Clock, + color: "text-gray-500", + }, + + { + title: "RFQ 생성", + value: stats?.rfqCreated || 0, + icon: Send, + color: "text-red-500", + }, + ]; + + return ( + <div className="grid gap-4 md:grid-cols-2 lg:grid-cols-3"> + {statCards.map((card, index) => { + const Icon = card.icon; + return ( + <Card key={index}> + <CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2"> + <CardTitle className="text-sm font-medium"> + {card.title} + </CardTitle> + <Icon className={`h-4 w-4 ${card.color}`} /> + </CardHeader> + <CardContent> + <div className="text-2xl font-bold">{card.value}</div> + </CardContent> + </Card> + ); + })} + </div> + ); +} + +// Metadata +export const metadata = { + title: "Purchase Request Management", + description: "Create and manage material purchase requests for projects", +};
\ No newline at end of file diff --git a/app/api/contracts/get-template/route.ts b/app/api/contracts/get-template/route.ts index ff42196f..b7965481 100644 --- a/app/api/contracts/get-template/route.ts +++ b/app/api/contracts/get-template/route.ts @@ -12,14 +12,18 @@ export async function POST(request: NextRequest) { { status: 400 } ); } + + // /api/files로 시작하는 경우 제거 + const cleanPath = templatePath.startsWith('/api/files') + ? templatePath.slice('/api/files'.length) + : templatePath; + const isDev = process.env.NODE_ENV === 'development'; - const fullPath = - isDev ? - path.join(process.cwd(), `public`, templatePath) - : - path.join(`${process.env.NAS_PATH}`, templatePath); - + const fullPath = isDev + ? path.join(process.cwd(), `public`, cleanPath) + : path.join(`${process.env.NAS_PATH}`, cleanPath); + const fileBuffer = await readFile(fullPath); return new NextResponse(fileBuffer, { diff --git a/app/api/upload/purchase-request/route.ts b/app/api/upload/purchase-request/route.ts new file mode 100644 index 00000000..8e49afcd --- /dev/null +++ b/app/api/upload/purchase-request/route.ts @@ -0,0 +1,56 @@ +// app/api/upload/purchase-request/route.ts +import { NextRequest, NextResponse } from "next/server"; +import { saveDRMFile } from "@/lib/file-stroage"; +import { getServerSession } from 'next-auth/next' +import { authOptions } from '@/app/api/auth/[...nextauth]/route' +import { decryptWithServerAction } from '@/components/drm/drmUtils' + +export async function POST(request: NextRequest) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.id) { + return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); + } + + const formData = await request.formData(); + const files = formData.getAll("files") as File[]; + + if (!files || files.length === 0) { + return NextResponse.json({ error: "No files provided" }, { status: 400 }); + } + + const uploadResults = []; + + for (const file of files) { + const result = await saveDRMFile( + file, + decryptWithServerAction, + "purchase-requests", + session.user.id, + ); + + if (!result.success) { + return NextResponse.json( + { error: result.error || "파일 업로드 실패" }, + { status: 400 } + ); + } + + uploadResults.push({ + fileName: result.fileName!, + originalFileName: file.name, + filePath: result.publicPath!, + fileSize: result.fileSize!, + fileType: file.type, + }); + } + + return NextResponse.json({ files: uploadResults }); + } catch (error) { + console.error("Upload error:", error); + return NextResponse.json( + { error: "파일 업로드 중 오류가 발생했습니다" }, + { status: 500 } + ); + } +}
\ No newline at end of file diff --git a/app/api/upload/signed-contract/route.ts b/app/api/upload/signed-contract/route.ts index 873f21e5..880f54b2 100644 --- a/app/api/upload/signed-contract/route.ts +++ b/app/api/upload/signed-contract/route.ts @@ -48,8 +48,9 @@ export async function POST(request: NextRequest) { status: "VENDOR_SIGNED", fileName: saveResult.originalName || originalFileName, // 원본 파일명 filePath: saveResult.publicPath, // 웹 접근 가능한 경로 + vendorSignedAt:new Date(), updatedAt: new Date(), - completedAt: null + completedAt:templateName.includes("GTC")? null : new Date() }) .where(eq(basicContract.id, tableRowId)); }); |
