diff options
53 files changed, 53095 insertions, 652 deletions
diff --git a/app/[lng]/evcp/(evcp)/b-rfq/[id]/initial/page.tsx b/app/[lng]/evcp/(evcp)/b-rfq/[id]/initial/page.tsx index e69de29b..1a9f4b18 100644 --- a/app/[lng]/evcp/(evcp)/b-rfq/[id]/initial/page.tsx +++ b/app/[lng]/evcp/(evcp)/b-rfq/[id]/initial/page.tsx @@ -0,0 +1,55 @@ +import { Separator } from "@/components/ui/separator" +import { type SearchParams } from "@/types/table" +import { getValidFilters } from "@/lib/data-table" +import { getMatchedVendors } from "@/lib/rfqs/service" +import { searchParamsMatchedVCache } from "@/lib/rfqs/validations" +import { MatchedVendorsTable } from "@/lib/rfqs/vendor-table/vendors-table" + +interface IndexPageProps { + // Next.js 13 App Router에서 기본으로 주어지는 객체들 + params: { + lng: string + id: string + } + searchParams: Promise<SearchParams> +} + +export default async function RfqPage(props: IndexPageProps) { + const resolvedParams = await props.params + const lng = resolvedParams.lng + const id = resolvedParams.id + + const idAsNumber = Number(id) + + // 2) SearchParams 파싱 (Zod) + // - "filters", "page", "perPage", "sort" 등 contact 전용 컬럼 + const searchParams = await props.searchParams + const search = searchParamsMatchedVCache.parse(searchParams) + const validFilters = getValidFilters(search.filters) + + const promises = Promise.all([ + getMatchedVendors({ + ...search, + filters: validFilters, + }, + idAsNumber) + ]) + + // 4) 렌더링 + return ( + <div className="space-y-6"> + <div> + <h3 className="text-lg font-medium"> + Vendors + </h3> + <p className="text-sm text-muted-foreground"> + 등록된 협력업체 중에서 이 RFQ 아이템에 매칭되는 업체를 보여줍니다. <br/>"발행하기" 버튼을 통해 RFQ를 전송하면 첨부파일과 함께 RFQ 내용이 메일로 전달되고 eVCP에도 협력업체가 입력할 수 있게 자동 생성됩니다. + </p> + </div> + <Separator /> + <div> + <MatchedVendorsTable promises={promises} rfqId={idAsNumber}/> + </div> + </div> + ) +}
\ No newline at end of file diff --git a/app/[lng]/evcp/(evcp)/b-rfq/[id]/layout.tsx b/app/[lng]/evcp/(evcp)/b-rfq/[id]/layout.tsx index 75ce5ee5..8dad7676 100644 --- a/app/[lng]/evcp/(evcp)/b-rfq/[id]/layout.tsx +++ b/app/[lng]/evcp/(evcp)/b-rfq/[id]/layout.tsx @@ -2,7 +2,6 @@ import { Metadata } from "next" import Link from "next/link" import { Separator } from "@/components/ui/separator" import { SidebarNav } from "@/components/layout/sidebar-nav" -import { RfqViewWithItems } from "@/db/schema/rfq" import { formatDate } from "@/lib/utils" import { Button } from "@/components/ui/button" import { ArrowLeft } from "lucide-react" diff --git a/app/[lng]/evcp/(evcp)/b-rfq/[id]/page.tsx b/app/[lng]/evcp/(evcp)/b-rfq/[id]/page.tsx index e8820af5..26dc45fb 100644 --- a/app/[lng]/evcp/(evcp)/b-rfq/[id]/page.tsx +++ b/app/[lng]/evcp/(evcp)/b-rfq/[id]/page.tsx @@ -1,6 +1,9 @@ import { Separator } from "@/components/ui/separator" import { type SearchParams } from "@/types/table" import { getValidFilters } from "@/lib/data-table" +import { searchParamsRfqAttachmentsCache } from "@/lib/b-rfq/validations" +import { getRfqAttachments } from "@/lib/b-rfq/service" +import { RfqAttachmentsTable } from "@/lib/b-rfq/attachment/attachment-table" interface IndexPageProps { // Next.js 13 App Router에서 기본으로 주어지는 객체들 @@ -18,36 +21,32 @@ export default async function RfqPage(props: IndexPageProps) { const idAsNumber = Number(id) - console.log(idAsNumber) // 2) SearchParams 파싱 (Zod) // - "filters", "page", "perPage", "sort" 등 contact 전용 컬럼 const searchParams = await props.searchParams - // const search = searchParamsMatchedVCache.parse(searchParams) - // const validFilters = getValidFilters(search.filters) + const search = searchParamsRfqAttachmentsCache.parse(searchParams) + const validFilters = getValidFilters(search.filters) - // const promises = Promise.all([ - // getMatchedVendors({ - // ...search, - // filters: validFilters, - // }, - // idAsNumber) - // ]) + const promises = getRfqAttachments({ + ...search, + filters: validFilters, + }, idAsNumber) // 4) 렌더링 return ( <div className="space-y-6"> <div> <h3 className="text-lg font-medium"> - 견적 RFQ 문서관리 + 견적 RFQ 문서관리 </h3> <p className="text-sm text-muted-foreground"> - 설계로부터 받은 RFQ 문서와 구매 RFQ 문서를 관리하고 Vendor 회신을 점검/관리하는 화면입니다. + 설계로부터 받은 RFQ 문서와 구매 RFQ 문서를 관리하고 Vendor 회신을 점검/관리하는 화면입니다. </p> </div> <Separator /> <div> - {/* <MatchedVendorsTable promises={promises} rfqId={idAsNumber}/> */} + <RfqAttachmentsTable promises={promises} rfqId={idAsNumber} /> </div> </div> ) diff --git a/app/[lng]/partners/(partners)/document-list-ship/page.tsx b/app/[lng]/partners/(partners)/document-list-ship/page.tsx new file mode 100644 index 00000000..8b7f61e2 --- /dev/null +++ b/app/[lng]/partners/(partners)/document-list-ship/page.tsx @@ -0,0 +1,135 @@ +// page.tsx (간단한 Promise 생성과 로그인 처리) +import * as React from "react" +import { type SearchParams } from "@/types/table" +import { getValidFilters } from "@/lib/data-table" +import { Skeleton } from "@/components/ui/skeleton" +import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton" +import { Shell } from "@/components/shell" +import { searchParamsRfqsForVendorsCache } from "@/lib/rfqs/validations" +import { getServerSession } from "next-auth" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" +import Link from "next/link" +import { Button } from "@/components/ui/button" +import { LogIn } from "lucide-react" +import { getUserVendorDocumentStats, getUserVendorDocuments } from "@/lib/vendor-document-list/enhanced-document-service" +import { UserVendorDocumentDisplay } from "@/components/ship-vendor-document/user-vendor-document-table-container" + +interface IndexPageProps { + searchParams: Promise<SearchParams> +} + +export default async function IndexPage(props: IndexPageProps) { + const searchParams = await props.searchParams + const search = searchParamsRfqsForVendorsCache.parse(searchParams) + const validFilters = getValidFilters(search.filters) + + // Get session + const session = await getServerSession(authOptions) + + // Check if user is logged in + if (!session || !session.user) { + return ( + <Shell className="gap-6"> + <div className="flex items-center justify-between"> + <div> + <h2 className="text-2xl font-bold tracking-tight"> + Document Management + </h2> + <p className="text-muted-foreground"> + 소속 회사의 모든 도서/도면을 확인하고 관리합니다. + </p> + </div> + </div> + + <div className="flex flex-col items-center justify-center py-12 text-center"> + <div className="rounded-lg border border-dashed p-10 shadow-sm"> + <h3 className="mb-2 text-xl font-semibold">로그인이 필요합니다</h3> + <p className="mb-6 text-muted-foreground"> + 문서를 확인하려면 먼저 로그인하세요. + </p> + <Button size="lg" asChild> + <Link href="/partners"> + <LogIn className="mr-2 h-4 w-4" /> + 로그인하기 + </Link> + </Button> + </div> + </div> + </Shell> + ) + } + + // User is logged in, get user ID + const requesterId = session.user.id ? Number(session.user.id) : null + + if (!requesterId) { + return ( + <Shell className="gap-6"> + <div className="flex items-center justify-between"> + <div> + <h2 className="text-2xl font-bold tracking-tight"> + Document Management + </h2> + </div> + </div> + <div className="flex flex-col items-center justify-center py-12 text-center"> + <div className="rounded-lg border border-dashed p-10 shadow-sm"> + <h3 className="mb-2 text-xl font-semibold">계정 오류</h3> + <p className="mb-6 text-muted-foreground"> + 사용자 정보가 올바르게 설정되지 않았습니다. 관리자에게 문의하세요. + </p> + </div> + </div> + </Shell> + ) + } + + // 검색 파라미터 정리 + const searchInput = { + ...search, + filters: validFilters, + } + + // Promise 생성 (모든 데이터를 페이지에서 처리) + const documentsPromise = getUserVendorDocuments(requesterId, searchInput) + const statsPromise = getUserVendorDocumentStats(requesterId) + + // Promise.all로 감싸서 전달 + const allPromises = Promise.all([documentsPromise, statsPromise]) + + return ( + <Shell className="gap-2"> + <div className="flex items-center justify-between space-y-2"> + <div> + <h2 className="text-2xl font-bold tracking-tight"> + 내 문서 관리 + </h2> + <p className="text-muted-foreground"> + 소속 회사의 모든 계약 문서를 확인하고 관리합니다. + </p> + </div> + </div> + + <React.Suspense fallback={<Skeleton className="h-7 w-52" />}> + {/* DateRangePicker can go here */} + </React.Suspense> + + <React.Suspense + fallback={ + <DataTableSkeleton + columnCount={8} + searchableColumnCount={1} + filterableColumnCount={3} + cellWidths={["10rem", "30rem", "15rem", "15rem", "15rem", "15rem", "8rem", "8rem"]} + shrinkZero + /> + } + > + <UserVendorDocumentDisplay + allPromises={allPromises} + /> + </React.Suspense> + </Shell> + ) +} + diff --git a/app/api/upload/rfq-attachment-revision/route.ts b/app/api/upload/rfq-attachment-revision/route.ts new file mode 100644 index 00000000..a7dd4117 --- /dev/null +++ b/app/api/upload/rfq-attachment-revision/route.ts @@ -0,0 +1,67 @@ +import { NextRequest, NextResponse } from "next/server" +import { writeFile, mkdir } from "fs/promises" +import { existsSync } from "fs" +import path from "path" + +export async function POST(request: NextRequest) { + try { + const formData = await request.formData() + const attachmentId = formData.get("attachmentId") as string + const file = formData.get("file") as File + const isRevision = formData.get("isRevision") as string + + if (!attachmentId) { + return NextResponse.json( + { message: "첨부파일 ID가 필요합니다." }, + { status: 400 } + ) + } + + if (!file) { + return NextResponse.json( + { message: "파일이 선택되지 않았습니다." }, + { status: 400 } + ) + } + + // 파일 크기 검증 + if (file.size > 10 * 1024 * 1024) { // 10MB + return NextResponse.json( + { message: `파일이 너무 큽니다. (최대 10MB)` }, + { status: 400 } + ) + } + + // 업로드 디렉토리 생성 (첨부파일 ID별) + const uploadDir = path.join(process.cwd(), "public", "uploads", "rfq", "revisions", attachmentId) + if (!existsSync(uploadDir)) { + await mkdir(uploadDir, { recursive: true }) + } + + // 고유한 파일명 생성 (리비전용) + const timestamp = Date.now() + const sanitizedName = file.name.replace(/[^a-zA-Z0-9.-]/g, "_") + const fileName = `${timestamp}_${sanitizedName}` + const filePath = `/uploads/rfq/revisions/${attachmentId}/${fileName}` + const fullPath = path.join(uploadDir, fileName) + + // 파일 저장 + const buffer = Buffer.from(await file.arrayBuffer()) + await writeFile(fullPath, buffer) + + return NextResponse.json({ + fileName, + originalFileName: file.name, + filePath, + fileSize: file.size, + fileType: file.type || path.extname(file.name).slice(1), + }) + + } catch (error) { + console.error("File upload error:", error) + return NextResponse.json( + { message: "파일 업로드 중 오류가 발생했습니다." }, + { status: 500 } + ) + } +}
\ No newline at end of file diff --git a/app/api/upload/rfq-attachment/route.ts b/app/api/upload/rfq-attachment/route.ts new file mode 100644 index 00000000..306919fb --- /dev/null +++ b/app/api/upload/rfq-attachment/route.ts @@ -0,0 +1,66 @@ +import { NextRequest, NextResponse } from "next/server" +import { writeFile, mkdir } from "fs/promises" +import { existsSync } from "fs" +import path from "path" + +export async function POST(request: NextRequest) { + try { + const formData = await request.formData() + const rfqId = formData.get("rfqId") as string + const file = formData.get("file") as File + + if (!rfqId) { + return NextResponse.json( + { message: "RFQ ID가 필요합니다." }, + { status: 400 } + ) + } + + if (!file) { + return NextResponse.json( + { message: "파일이 선택되지 않았습니다." }, + { status: 400 } + ) + } + + // 파일 크기 검증 + if (file.size > 10 * 1024 * 1024) { // 10MB + return NextResponse.json( + { message: `파일이 너무 큽니다. (최대 10MB)` }, + { status: 400 } + ) + } + + // 업로드 디렉토리 생성 + const uploadDir = path.join(process.cwd(), "public", "uploads", "rfq", rfqId) + if (!existsSync(uploadDir)) { + await mkdir(uploadDir, { recursive: true }) + } + + // 고유한 파일명 생성 (타임스탬프 + 원본명) + const timestamp = Date.now() + const sanitizedName = file.name.replace(/[^a-zA-Z0-9.-]/g, "_") + const fileName = `${timestamp}_${sanitizedName}` + const filePath = `/uploads/rfq/${rfqId}/${fileName}` + const fullPath = path.join(uploadDir, fileName) + + // 파일 저장 + const buffer = Buffer.from(await file.arrayBuffer()) + await writeFile(fullPath, buffer) + + return NextResponse.json({ + fileName, + originalFileName: file.name, + filePath, + fileSize: file.size, + fileType: file.type || path.extname(file.name).slice(1), + }) + + } catch (error) { + console.error("File upload error:", error) + return NextResponse.json( + { message: "파일 업로드 중 오류가 발생했습니다." }, + { status: 500 } + ) + } +}
\ No newline at end of file diff --git a/components/document-lists/vendor-doc-list-client.tsx b/components/document-lists/vendor-doc-list-client.tsx index 6ba155a7..4dea591f 100644 --- a/components/document-lists/vendor-doc-list-client.tsx +++ b/components/document-lists/vendor-doc-list-client.tsx @@ -34,7 +34,7 @@ export default function VendorDocumentListClient({ ) // projectType 상태 추가 - const [projectType, setProjectType] = React.useState<string>("ship") + const [projectType, setProjectType] = React.useState<string>("plant") // Update selectedContractId when URL changes React.useEffect(() => { @@ -48,10 +48,10 @@ export default function VendorDocumentListClient({ const foundProjectType = projects.find(v => v.projectId === projectId)?.projectType || "ship" setSelectedContractId(contractId) - setProjectType(foundProjectType) + setProjectType("plant") // Navigate to the contract's documents page - router.push(`/partners/document-list/${contractId}?projectType=${foundProjectType}`) + router.push(`/partners/document-list/${contractId}?projectType=plnat`) } return ( diff --git a/components/ship-vendor-document/user-vendor-document-table-container.tsx b/components/ship-vendor-document/user-vendor-document-table-container.tsx new file mode 100644 index 00000000..0ede3e19 --- /dev/null +++ b/components/ship-vendor-document/user-vendor-document-table-container.tsx @@ -0,0 +1,129 @@ +"use client" + +import React from "react" +import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" +import { Badge } from "@/components/ui/badge" +import { Building, FileText, AlertCircle } from "lucide-react" +import { SimplifiedDocumentsTable } from "@/lib/vendor-document-list/ship/enhanced-documents-table" +import { getUserVendorDocuments, getUserVendorDocumentStats } from "@/lib/vendor-document-list/enhanced-document-service" + +interface UserVendorDocumentDisplayProps { + allPromises: Promise<[ + Awaited<ReturnType<typeof getUserVendorDocuments>>, + Awaited<ReturnType<typeof getUserVendorDocumentStats>> + ]> +} + +// DrawingKind별 설명 매핑 +const DRAWING_KIND_INFO = { + B3: { + title: "B3 승인 도면", + description: "Approval → Work 단계로 진행되는 승인 중심 도면", + color: "bg-blue-50 text-blue-700 border-blue-200" + }, + B4: { + title: "B4 작업 도면", + description: "Pre → Work 단계로 진행되는 DOLCE 연동 도면", + color: "bg-green-50 text-green-700 border-green-200" + }, + B5: { + title: "B5 단계 도면", + description: "First → Second 단계로 진행되는 순차적 도면", + color: "bg-purple-50 text-purple-700 border-purple-200" + } +} as const + +export function UserVendorDocumentDisplay({ + allPromises +}: UserVendorDocumentDisplayProps) { + // allPromises가 제대로 전달되었는지 확인 + if (!allPromises) { + return ( + <Card> + <CardContent className="flex items-center justify-center py-8"> + <div className="text-center"> + <AlertCircle className="w-8 h-8 text-gray-400 mx-auto mb-2" /> + <p className="text-gray-600">데이터를 불러올 수 없습니다.</p> + </div> + </CardContent> + </Card> + ) + } + + // Promise.all로 감싸진 Promise를 사용해서 데이터 가져오기 + const [documentResult, statsResult] = React.use(allPromises) + + const { data, pageCount, total, drawingKind, vendorInfo } = documentResult + const { stats, totalDocuments, primaryDrawingKind } = statsResult + + // 문서가 없는 경우 + if (total === 0) { + return ( + <Card> + <CardContent className="flex items-center justify-center py-8"> + <div className="text-center"> + <FileText className="w-8 h-8 text-gray-400 mx-auto mb-2" /> + <p className="text-gray-600">등록된 문서가 없습니다.</p> + </div> + </CardContent> + </Card> + ) + } + + // 실제 데이터의 drawingKind 또는 주요 drawingKind 사용 + const activeDrawingKind = drawingKind || primaryDrawingKind + + if (!activeDrawingKind) { + return ( + <Card> + <CardContent className="flex items-center justify-center py-8"> + <div className="text-center"> + <AlertCircle className="w-8 h-8 text-gray-400 mx-auto mb-2" /> + <p className="text-gray-600">문서 유형을 확인할 수 없습니다.</p> + </div> + </CardContent> + </Card> + ) + } + + // SimplifiedDocumentsTable에 전달할 promise (단일 객체로 변경) + const tablePromise = Promise.resolve({ data, pageCount, total }) + + const kindInfo = DRAWING_KIND_INFO[activeDrawingKind] + + return ( + <div className="space-y-6"> + {/* 벤더 정보 헤더 */} + <Card> + <CardHeader> + <CardTitle className="flex items-center gap-2"> + <Building className="w-5 h-5" /> + {vendorInfo?.vendorName || "내 회사"} 문서 관리 + </CardTitle> + <CardDescription> + {vendorInfo?.vendorCode && `코드: ${vendorInfo.vendorCode} • `} + 총 {totalDocuments}개 문서 + </CardDescription> + </CardHeader> + <CardContent> + <div className="flex gap-4"> + {Object.entries(stats).map(([kind, count]) => ( + <Badge + key={kind} + variant={kind === activeDrawingKind ? "default" : "outline"} + className="flex items-center gap-1" + > + <FileText className="w-3 h-3" /> + {kind}: {count}개 + </Badge> + ))} + </div> + </CardContent> + </Card> + + + <SimplifiedDocumentsTable promises={tablePromise} /> + + </div> + ) +}
\ No newline at end of file diff --git a/config/menuConfig.ts b/config/menuConfig.ts index c039ed34..d3aa16bf 100644 --- a/config/menuConfig.ts +++ b/config/menuConfig.ts @@ -392,7 +392,12 @@ export const mainNavVendor: MenuSection[] = [ // description: "입력된 협력업체 데이터를 도서/문서와 연계하여 리스트하여 출력", // }, { - title: "문서/도서 리스트 및 제출", + title: "문서/도서 리스트 및 제출 (조선)", + href: `/partners/document-list-ship`, + description: "벤더의 제출 도서/문서의 리스트를 관리하고 문서를 제출", + }, + { + title: "문서/도서 리스트 및 제출 (해양)", href: `/partners/document-list`, description: "벤더의 제출 도서/문서의 리스트를 관리하고 문서를 제출", }, diff --git a/db/migrations/0128_sad_vermin.sql b/db/migrations/0128_sad_vermin.sql new file mode 100644 index 00000000..86c27be9 --- /dev/null +++ b/db/migrations/0128_sad_vermin.sql @@ -0,0 +1,36 @@ +DROP INDEX "latest_revision_idx";--> statement-breakpoint +ALTER TABLE "b_rfq_attachments" ADD COLUMN "current_revision" varchar(10) DEFAULT 'Rev.0' NOT NULL;--> statement-breakpoint +ALTER TABLE "b_rfq_attachments" ADD COLUMN "latest_revision_id" integer;--> statement-breakpoint +ALTER TABLE "b_rfq_attachments" ADD COLUMN "updated_at" timestamp DEFAULT now() NOT NULL;--> statement-breakpoint +CREATE UNIQUE INDEX "attachment_revision_idx" ON "b_rfq_attachment_revisions" USING btree ("attachment_id","revision_no");--> statement-breakpoint +CREATE UNIQUE INDEX "latest_revision_idx" ON "b_rfq_attachment_revisions" USING btree ("attachment_id","is_latest") WHERE "b_rfq_attachment_revisions"."is_latest" = $1;--> statement-breakpoint +ALTER TABLE "b_rfq_attachments" DROP COLUMN "file_name";--> statement-breakpoint +ALTER TABLE "b_rfq_attachments" DROP COLUMN "original_file_name";--> statement-breakpoint +ALTER TABLE "b_rfq_attachments" DROP COLUMN "file_path";--> statement-breakpoint +ALTER TABLE "b_rfq_attachments" DROP COLUMN "file_size";--> statement-breakpoint +ALTER TABLE "b_rfq_attachments" DROP COLUMN "file_type";--> statement-breakpoint +CREATE VIEW "public"."attachments_with_latest_revision" AS ( + SELECT + a.id as attachment_id, + a.attachment_type, + a.serial_no, + a.rfq_id, + a.description, + a.current_revision, + + r.id as revision_id, + r.file_name, + r.original_file_name, + r.file_path, + r.file_size, + r.file_type, + r.revision_comment, + + a.created_by, + u.name as created_by_name, + a.created_at, + a.updated_at + FROM b_rfq_attachments a + LEFT JOIN b_rfq_attachment_revisions r ON a.latest_revision_id = r.id + LEFT JOIN users u ON a.created_by = u.id + );
\ No newline at end of file diff --git a/db/migrations/0129_nifty_albert_cleary.sql b/db/migrations/0129_nifty_albert_cleary.sql new file mode 100644 index 00000000..724b3e66 --- /dev/null +++ b/db/migrations/0129_nifty_albert_cleary.sql @@ -0,0 +1,224 @@ +DROP VIEW "public"."enhanced_documents_view";--> statement-breakpoint +CREATE VIEW "public"."enhanced_documents_view" AS ( + WITH document_stats AS ( + SELECT + d.id as document_id, + COUNT(ist.id) as total_stages, + COUNT(CASE WHEN ist.stage_status IN ('COMPLETED', 'APPROVED') THEN 1 END) as completed_stages, + CASE + WHEN COUNT(ist.id) > 0 + THEN ROUND((COUNT(CASE WHEN ist.stage_status IN ('COMPLETED', 'APPROVED') THEN 1 END) * 100.0) / COUNT(ist.id)) + ELSE 0 + END as progress_percentage + FROM documents d + LEFT JOIN issue_stages ist ON d.id = ist.document_id + GROUP BY d.id + ), + current_stage_info AS ( + SELECT DISTINCT ON (document_id) + document_id, + id as current_stage_id, + stage_name as current_stage_name, + stage_status as current_stage_status, + stage_order as current_stage_order, + plan_date as current_stage_plan_date, + actual_date as current_stage_actual_date, + assignee_name as current_stage_assignee_name, + priority as current_stage_priority, + CASE + WHEN actual_date IS NULL AND plan_date IS NOT NULL + THEN plan_date - CURRENT_DATE + ELSE NULL + END as days_until_due, + CASE + WHEN actual_date IS NULL AND plan_date < CURRENT_DATE + THEN true + WHEN actual_date IS NOT NULL AND actual_date > plan_date + THEN true + ELSE false + END as is_overdue, + CASE + WHEN actual_date IS NOT NULL AND plan_date IS NOT NULL + THEN actual_date - plan_date + ELSE NULL + END as days_difference + FROM issue_stages + WHERE stage_status NOT IN ('COMPLETED', 'APPROVED') + ORDER BY document_id, stage_order ASC, priority DESC + ), + latest_revision_info AS ( + SELECT DISTINCT ON (ist.document_id) + ist.document_id, + r.id as latest_revision_id, + r.revision as latest_revision, + r.revision_status as latest_revision_status, + r.uploader_name as latest_revision_uploader_name, + r.submitted_date as latest_submitted_date + FROM revisions r + JOIN issue_stages ist ON r.issue_stage_id = ist.id + ORDER BY ist.document_id, r.created_at DESC + ), + -- 리비전별 첨부파일 집계 + revision_attachments AS ( + SELECT + r.id as revision_id, + COALESCE( + json_agg( + json_build_object( + 'id', da.id, + 'revisionId', da.revision_id, + 'fileName', da.file_name, + 'filePath', da.file_path, + 'fileSize', da.file_size, + 'fileType', da.file_type, + 'createdAt', da.created_at, + 'updatedAt', da.updated_at + ) ORDER BY da.created_at + ) FILTER (WHERE da.id IS NOT NULL), + '[]'::json + ) as attachments + FROM revisions r + LEFT JOIN document_attachments da ON r.id = da.revision_id + GROUP BY r.id + ), + -- 스테이지별 리비전 집계 (첨부파일 포함) + stage_revisions AS ( + SELECT + ist.id as stage_id, + COALESCE( + json_agg( + json_build_object( + 'id', r.id, + 'issueStageId', r.issue_stage_id, + 'revision', r.revision, + 'uploaderType', r.uploader_type, + 'uploaderId', r.uploader_id, + 'uploaderName', r.uploader_name, + 'comment', r.comment, + 'usage', r.usage, + 'revisionStatus', r.revision_status, + 'submittedDate', r.submitted_date, + 'uploadedAt', r.uploaded_at, + 'approvedDate', r.approved_date, + 'reviewStartDate', r.review_start_date, + 'rejectedDate', r.rejected_date, + 'reviewerId', r.reviewer_id, + 'reviewerName', r.reviewer_name, + 'reviewComments', r.review_comments, + 'createdAt', r.created_at, + 'updatedAt', r.updated_at, + 'attachments', ra.attachments + ) ORDER BY r.created_at + ) FILTER (WHERE r.id IS NOT NULL), + '[]'::json + ) as revisions + FROM issue_stages ist + LEFT JOIN revisions r ON ist.id = r.issue_stage_id + LEFT JOIN revision_attachments ra ON r.id = ra.revision_id + GROUP BY ist.id + ), + -- 문서별 스테이지 집계 (리비전 포함) + stage_aggregation AS ( + SELECT + ist.document_id, + json_agg( + json_build_object( + 'id', ist.id, + 'stageName', ist.stage_name, + 'stageStatus', ist.stage_status, + 'stageOrder', ist.stage_order, + 'planDate', ist.plan_date, + 'actualDate', ist.actual_date, + 'assigneeName', ist.assignee_name, + 'priority', ist.priority, + 'revisions', sr.revisions + ) ORDER BY ist.stage_order + ) as all_stages + FROM issue_stages ist + LEFT JOIN stage_revisions sr ON ist.id = sr.stage_id + GROUP BY ist.document_id + ), + attachment_counts AS ( + SELECT + ist.document_id, + COUNT(da.id) as attachment_count + FROM issue_stages ist + LEFT JOIN revisions r ON ist.id = r.issue_stage_id + LEFT JOIN document_attachments da ON r.id = da.revision_id + GROUP BY ist.document_id + ) + + SELECT + d.id as document_id, + d.doc_number, + d.drawing_kind, + d.vendor_doc_number, -- ✅ 벤더 문서 번호 추가 + d.title, + d.pic, + d.status, + d.issued_date, + d.contract_id, + + d.c_gbn, + d.d_gbn, + d.degree_gbn, + d.dept_gbn, + d.s_gbn, + d.j_gbn, + + + + -- ✅ 프로젝트 및 벤더 정보 추가 + p.code as project_code, + v.vendor_name as vendor_name, + v.vendor_code as vendor_code, + + -- 현재 스테이지 정보 + csi.current_stage_id, + csi.current_stage_name, + csi.current_stage_status, + csi.current_stage_order, + csi.current_stage_plan_date, + csi.current_stage_actual_date, + csi.current_stage_assignee_name, + csi.current_stage_priority, + + -- 계산 필드 + csi.days_until_due, + csi.is_overdue, + csi.days_difference, + + -- 진행률 정보 + ds.total_stages, + ds.completed_stages, + ds.progress_percentage, + + -- 최신 리비전 정보 + lri.latest_revision_id, + lri.latest_revision, + lri.latest_revision_status, + lri.latest_revision_uploader_name, + lri.latest_submitted_date, + + -- 전체 스테이지 (리비전 및 첨부파일 포함) + COALESCE(sa.all_stages, '[]'::json) as all_stages, + + -- 기타 + COALESCE(ac.attachment_count, 0) as attachment_count, + d.created_at, + d.updated_at + + FROM documents d + -- ✅ contracts, projects, vendors 테이블 JOIN 추가 + LEFT JOIN contracts c ON d.contract_id = c.id + LEFT JOIN projects p ON c.project_id = p.id + LEFT JOIN vendors v ON c.vendor_id = v.id + + LEFT JOIN document_stats ds ON d.id = ds.document_id + LEFT JOIN current_stage_info csi ON d.id = csi.document_id + LEFT JOIN latest_revision_info lri ON d.id = lri.document_id + LEFT JOIN stage_aggregation sa ON d.id = sa.document_id + LEFT JOIN attachment_counts ac ON d.id = ac.document_id + + ORDER BY d.created_at DESC +);
\ No newline at end of file diff --git a/db/migrations/0130_brown_nightmare.sql b/db/migrations/0130_brown_nightmare.sql new file mode 100644 index 00000000..2a41dfb9 --- /dev/null +++ b/db/migrations/0130_brown_nightmare.sql @@ -0,0 +1,183 @@ +CREATE VIEW "public"."simplified_documents_view" AS ( + WITH + -- 리비전별 첨부파일 집계 + revision_attachments AS ( + SELECT + r.id as revision_id, + COALESCE( + json_agg( + json_build_object( + 'id', da.id, + 'revisionId', da.revision_id, + 'fileName', da.file_name, + 'filePath', da.file_path, + 'fileSize', da.file_size, + 'fileType', da.file_type, + 'createdAt', da.created_at, + 'updatedAt', da.updated_at + ) ORDER BY da.created_at + ) FILTER (WHERE da.id IS NOT NULL), + '[]'::json + ) as attachments + FROM revisions r + LEFT JOIN document_attachments da ON r.id = da.revision_id + GROUP BY r.id + ), + -- 스테이지별 리비전 집계 (첨부파일 포함) + stage_revisions AS ( + SELECT + ist.id as stage_id, + COALESCE( + json_agg( + json_build_object( + 'id', r.id, + 'issueStageId', r.issue_stage_id, + 'revision', r.revision, + 'uploaderType', r.uploader_type, + 'uploaderId', r.uploader_id, + 'uploaderName', r.uploader_name, + 'comment', r.comment, + 'usage', r.usage, + 'revisionStatus', r.revision_status, + 'submittedDate', r.submitted_date, + 'uploadedAt', r.uploaded_at, + 'approvedDate', r.approved_date, + 'reviewStartDate', r.review_start_date, + 'rejectedDate', r.rejected_date, + 'reviewerId', r.reviewer_id, + 'reviewerName', r.reviewer_name, + 'reviewComments', r.review_comments, + 'createdAt', r.created_at, + 'updatedAt', r.updated_at, + 'attachments', ra.attachments + ) ORDER BY r.created_at + ) FILTER (WHERE r.id IS NOT NULL), + '[]'::json + ) as revisions + FROM issue_stages ist + LEFT JOIN revisions r ON ist.id = r.issue_stage_id + LEFT JOIN revision_attachments ra ON r.id = ra.revision_id + GROUP BY ist.id + ), + -- 문서별 스테이지 집계 (리비전 포함) + stage_aggregation AS ( + SELECT + ist.document_id, + json_agg( + json_build_object( + 'id', ist.id, + 'stageName', ist.stage_name, + 'stageStatus', ist.stage_status, + 'stageOrder', ist.stage_order, + 'planDate', ist.plan_date, + 'actualDate', ist.actual_date, + 'assigneeName', ist.assignee_name, + 'priority', ist.priority, + 'revisions', sr.revisions + ) ORDER BY ist.stage_order + ) as all_stages + FROM issue_stages ist + LEFT JOIN stage_revisions sr ON ist.id = sr.stage_id + GROUP BY ist.document_id + ), + -- 첫 번째 스테이지 정보 (drawingKind에 따라 다른 조건) + first_stage_info AS ( + SELECT DISTINCT ON (ist.document_id) + ist.document_id, + ist.id as first_stage_id, + ist.stage_name as first_stage_name, + ist.plan_date as first_stage_plan_date, + ist.actual_date as first_stage_actual_date + FROM issue_stages ist + JOIN documents d ON ist.document_id = d.id + WHERE + (d.drawing_kind = 'B4' AND LOWER(ist.stage_name) LIKE '%pre%') OR + (d.drawing_kind = 'B3' AND LOWER(ist.stage_name) LIKE '%approval%') OR + (d.drawing_kind = 'B5' AND LOWER(ist.stage_name) LIKE '%first%') + ORDER BY ist.document_id, ist.stage_order ASC + ), + -- 두 번째 스테이지 정보 (drawingKind에 따라 다른 조건) + second_stage_info AS ( + SELECT DISTINCT ON (ist.document_id) + ist.document_id, + ist.id as second_stage_id, + ist.stage_name as second_stage_name, + ist.plan_date as second_stage_plan_date, + ist.actual_date as second_stage_actual_date + FROM issue_stages ist + JOIN documents d ON ist.document_id = d.id + WHERE + (d.drawing_kind = 'B4' AND LOWER(ist.stage_name) LIKE '%work%') OR + (d.drawing_kind = 'B3' AND LOWER(ist.stage_name) LIKE '%work%') OR + (d.drawing_kind = 'B5' AND LOWER(ist.stage_name) LIKE '%second%') + ORDER BY ist.document_id, ist.stage_order ASC + ), + -- 첨부파일 수 집계 + attachment_counts AS ( + SELECT + ist.document_id, + COUNT(da.id) as attachment_count + FROM issue_stages ist + LEFT JOIN revisions r ON ist.id = r.issue_stage_id + LEFT JOIN document_attachments da ON r.id = da.revision_id + GROUP BY ist.document_id + ) + + SELECT + d.id as document_id, + d.doc_number, + d.drawing_kind, + d.vendor_doc_number, + d.title, + d.pic, + d.status, + d.issued_date, + d.contract_id, + + -- B4 전용 필드들 + d.c_gbn, + d.d_gbn, + d.degree_gbn, + d.dept_gbn, + d.s_gbn, + d.j_gbn, + + -- 프로젝트 및 벤더 정보 + p.code as project_code, + v.vendor_name as vendor_name, + v.vendor_code as vendor_code, + + -- 첫 번째 스테이지 정보 + fsi.first_stage_id, + fsi.first_stage_name, + fsi.first_stage_plan_date, + fsi.first_stage_actual_date, + + -- 두 번째 스테이지 정보 + ssi.second_stage_id, + ssi.second_stage_name, + ssi.second_stage_plan_date, + ssi.second_stage_actual_date, + + -- 전체 스테이지 (리비전 및 첨부파일 포함) + COALESCE(sa.all_stages, '[]'::json) as all_stages, + + -- 기타 + COALESCE(ac.attachment_count, 0) as attachment_count, + d.created_at, + d.updated_at + + FROM documents d + -- contracts, projects, vendors 테이블 JOIN + LEFT JOIN contracts c ON d.contract_id = c.id + LEFT JOIN projects p ON c.project_id = p.id + LEFT JOIN vendors v ON c.vendor_id = v.id + + -- 스테이지 정보 JOIN + LEFT JOIN first_stage_info fsi ON d.id = fsi.document_id + LEFT JOIN second_stage_info ssi ON d.id = ssi.document_id + LEFT JOIN stage_aggregation sa ON d.id = sa.document_id + LEFT JOIN attachment_counts ac ON d.id = ac.document_id + + ORDER BY d.created_at DESC +);
\ No newline at end of file diff --git a/db/migrations/meta/0128_snapshot.json b/db/migrations/meta/0128_snapshot.json new file mode 100644 index 00000000..ac7c9853 --- /dev/null +++ b/db/migrations/meta/0128_snapshot.json @@ -0,0 +1,14188 @@ +{ + "id": "89ab6bb0-8ac0-4a79-a5be-a500197f5c00", + "prevId": "4ade0f12-cd16-49cf-a911-89353a9249f7", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.companies": { + "name": "companies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "companies_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "taxID": { + "name": "taxID", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contract_envelopes": { + "name": "contract_envelopes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contract_envelopes_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "envelope_id": { + "name": "envelope_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "envelope_status": { + "name": "envelope_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "contract_envelopes_contract_id_contracts_id_fk": { + "name": "contract_envelopes_contract_id_contracts_id_fk", + "tableFrom": "contract_envelopes", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contract_items": { + "name": "contract_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contract_items_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "unit_price": { + "name": "unit_price", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "tax_rate": { + "name": "tax_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "tax_amount": { + "name": "tax_amount", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "total_line_amount": { + "name": "total_line_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "contract_items_contract_item_idx": { + "name": "contract_items_contract_item_idx", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "contract_items_contract_id_contracts_id_fk": { + "name": "contract_items_contract_id_contracts_id_fk", + "tableFrom": "contract_items", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contract_items_item_id_items_id_fk": { + "name": "contract_items_item_id_items_id_fk", + "tableFrom": "contract_items", + "tableTo": "items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "contract_items_contract_id_item_id_unique": { + "name": "contract_items_contract_id_item_id_unique", + "nullsNotDistinct": false, + "columns": [ + "contract_id", + "item_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contract_signers": { + "name": "contract_signers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contract_signers_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "envelope_id": { + "name": "envelope_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_contact_id": { + "name": "vendor_contact_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "signer_type": { + "name": "signer_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'VENDOR'" + }, + "signer_email": { + "name": "signer_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "signer_name": { + "name": "signer_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "signer_position": { + "name": "signer_position", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "signer_status": { + "name": "signer_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'PENDING'" + }, + "signed_at": { + "name": "signed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "contract_signers_envelope_id_contract_envelopes_id_fk": { + "name": "contract_signers_envelope_id_contract_envelopes_id_fk", + "tableFrom": "contract_signers", + "tableTo": "contract_envelopes", + "columnsFrom": [ + "envelope_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contract_signers_vendor_contact_id_vendor_contacts_id_fk": { + "name": "contract_signers_vendor_contact_id_vendor_contacts_id_fk", + "tableFrom": "contract_signers", + "tableTo": "vendor_contacts", + "columnsFrom": [ + "vendor_contact_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contracts": { + "name": "contracts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contracts_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "contract_name": { + "name": "contract_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "payment_terms": { + "name": "payment_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'KRW'" + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "partial_shipping_allowed": { + "name": "partial_shipping_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "partial_payment_allowed": { + "name": "partial_payment_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "remarks": { + "name": "remarks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "contracts_project_id_projects_id_fk": { + "name": "contracts_project_id_projects_id_fk", + "tableFrom": "contracts", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contracts_vendor_id_vendors_id_fk": { + "name": "contracts_vendor_id_vendors_id_fk", + "tableFrom": "contracts", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "contracts_contract_no_unique": { + "name": "contracts_contract_no_unique", + "nullsNotDistinct": false, + "columns": [ + "contract_no" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.poa": { + "name": "poa", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "poa_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "original_contract_no": { + "name": "original_contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "original_contract_name": { + "name": "original_contract_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_status": { + "name": "original_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "change_reason": { + "name": "change_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approval_status": { + "name": "approval_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'PENDING'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "poa_original_contract_no_contracts_contract_no_fk": { + "name": "poa_original_contract_no_contracts_contract_no_fk", + "tableFrom": "poa", + "tableTo": "contracts", + "columnsFrom": [ + "original_contract_no" + ], + "columnsTo": [ + "contract_no" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "poa_project_id_projects_id_fk": { + "name": "poa_project_id_projects_id_fk", + "tableFrom": "poa", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "poa_vendor_id_vendors_id_fk": { + "name": "poa_vendor_id_vendors_id_fk", + "tableFrom": "poa", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.item_offshore_hull": { + "name": "item_offshore_hull", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "work_type": { + "name": "work_type", + "type": "offshore_hull_work_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "item_list": { + "name": "item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sub_item_list": { + "name": "sub_item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "item_offshore_hull_item_code_items_item_code_fk": { + "name": "item_offshore_hull_item_code_items_item_code_fk", + "tableFrom": "item_offshore_hull", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.item_offshore_top": { + "name": "item_offshore_top", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "work_type": { + "name": "work_type", + "type": "offshore_top_work_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "item_list": { + "name": "item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sub_item_list": { + "name": "sub_item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "item_offshore_top_item_code_items_item_code_fk": { + "name": "item_offshore_top_item_code_items_item_code_fk", + "tableFrom": "item_offshore_top", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.item_shipbuilding": { + "name": "item_shipbuilding", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "work_type": { + "name": "work_type", + "type": "work_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "item_list": { + "name": "item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ship_types": { + "name": "ship_types", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'OPTION'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "item_shipbuilding_item_code_items_item_code_fk": { + "name": "item_shipbuilding_item_code_items_item_code_fk", + "tableFrom": "item_shipbuilding", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.items": { + "name": "items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_no": { + "name": "project_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "package_code": { + "name": "package_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "sm_code": { + "name": "sm_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_item_code": { + "name": "parent_item_code", + "type": "varchar(18)", + "primaryKey": false, + "notNull": false + }, + "item_level": { + "name": "item_level", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "delete_flag": { + "name": "delete_flag", + "type": "varchar(1)", + "primaryKey": false, + "notNull": false + }, + "unit_of_measure": { + "name": "unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "steel_type": { + "name": "steel_type", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "grade_material": { + "name": "grade_material", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "change_date": { + "name": "change_date", + "type": "varchar(8)", + "primaryKey": false, + "notNull": false + }, + "base_unit_of_measure": { + "name": "base_unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "items_item_code_unique": { + "name": "items_item_code_unique", + "nullsNotDistinct": false, + "columns": [ + "item_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.materials": { + "name": "materials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_item_code": { + "name": "parent_item_code", + "type": "varchar(18)", + "primaryKey": false, + "notNull": false + }, + "item_level": { + "name": "item_level", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "delete_flag": { + "name": "delete_flag", + "type": "varchar(1)", + "primaryKey": false, + "notNull": false + }, + "unit_of_measure": { + "name": "unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "steel_type": { + "name": "steel_type", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "grade_material": { + "name": "grade_material", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "change_date": { + "name": "change_date", + "type": "varchar(8)", + "primaryKey": false, + "notNull": false + }, + "base_unit_of_measure": { + "name": "base_unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "materials_item_code_unique": { + "name": "materials_item_code_unique", + "nullsNotDistinct": false, + "columns": [ + "item_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pq_criterias": { + "name": "pq_criterias", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "check_point": { + "name": "check_point", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "remarks": { + "name": "remarks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "group_name": { + "name": "group_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pq_criterias_extension": { + "name": "pq_criterias_extension", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pq_criteria_id": { + "name": "pq_criteria_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "contract_info": { + "name": "contract_info", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "additional_requirement": { + "name": "additional_requirement", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "pq_criterias_extension_pq_criteria_id_pq_criterias_id_fk": { + "name": "pq_criterias_extension_pq_criteria_id_pq_criterias_id_fk", + "tableFrom": "pq_criterias_extension", + "tableTo": "pq_criterias", + "columnsFrom": [ + "pq_criteria_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "pq_criterias_extension_project_id_projects_id_fk": { + "name": "pq_criterias_extension_project_id_projects_id_fk", + "tableFrom": "pq_criterias_extension", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_criteria_attachments": { + "name": "vendor_criteria_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_criteria_answer_id": { + "name": "vendor_criteria_answer_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_criteria_attachments_vendor_criteria_answer_id_vendor_pq_criteria_answers_id_fk": { + "name": "vendor_criteria_attachments_vendor_criteria_answer_id_vendor_pq_criteria_answers_id_fk", + "tableFrom": "vendor_criteria_attachments", + "tableTo": "vendor_pq_criteria_answers", + "columnsFrom": [ + "vendor_criteria_answer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_investigation_attachments": { + "name": "vendor_investigation_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "investigation_id": { + "name": "investigation_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "mime_type": { + "name": "mime_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'REPORT'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_investigation_attachments_investigation_id_vendor_investigations_id_fk": { + "name": "vendor_investigation_attachments_investigation_id_vendor_investigations_id_fk", + "tableFrom": "vendor_investigation_attachments", + "tableTo": "vendor_investigations", + "columnsFrom": [ + "investigation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_investigations": { + "name": "vendor_investigations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pq_submission_id": { + "name": "pq_submission_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requester_id": { + "name": "requester_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "qm_manager_id": { + "name": "qm_manager_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "investigation_status": { + "name": "investigation_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'PLANNED'" + }, + "evaluation_type": { + "name": "evaluation_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_address": { + "name": "investigation_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "investigation_method": { + "name": "investigation_method", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "scheduled_start_at": { + "name": "scheduled_start_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scheduled_end_at": { + "name": "scheduled_end_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "forecasted_at": { + "name": "forecasted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "evaluation_score": { + "name": "evaluation_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluation_result": { + "name": "evaluation_result", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_notes": { + "name": "investigation_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_investigations_vendor_id_vendors_id_fk": { + "name": "vendor_investigations_vendor_id_vendors_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_investigations_pq_submission_id_vendor_pq_submissions_id_fk": { + "name": "vendor_investigations_pq_submission_id_vendor_pq_submissions_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "vendor_pq_submissions", + "columnsFrom": [ + "pq_submission_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + }, + "vendor_investigations_requester_id_users_id_fk": { + "name": "vendor_investigations_requester_id_users_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "users", + "columnsFrom": [ + "requester_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_investigations_qm_manager_id_users_id_fk": { + "name": "vendor_investigations_qm_manager_id_users_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "users", + "columnsFrom": [ + "qm_manager_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_pq_submissions": { + "name": "vendor_pq_submissions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pq_number": { + "name": "pq_number", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "requester_id": { + "name": "requester_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'REQUESTED'" + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "rejected_at": { + "name": "rejected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "reject_reason": { + "name": "reject_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_pq_submission": { + "name": "unique_pq_submission", + "columns": [ + { + "expression": "vendor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "vendor_pq_submissions_requester_id_users_id_fk": { + "name": "vendor_pq_submissions_requester_id_users_id_fk", + "tableFrom": "vendor_pq_submissions", + "tableTo": "users", + "columnsFrom": [ + "requester_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_pq_submissions_vendor_id_vendors_id_fk": { + "name": "vendor_pq_submissions_vendor_id_vendors_id_fk", + "tableFrom": "vendor_pq_submissions", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_pq_submissions_project_id_projects_id_fk": { + "name": "vendor_pq_submissions_project_id_projects_id_fk", + "tableFrom": "vendor_pq_submissions", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "vendor_pq_submissions_pq_number_unique": { + "name": "vendor_pq_submissions_pq_number_unique", + "nullsNotDistinct": false, + "columns": [ + "pq_number" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_pq_criteria_answers": { + "name": "vendor_pq_criteria_answers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "criteria_id": { + "name": "criteria_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "answer": { + "name": "answer", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_pq_criteria_answers_vendor_id_vendors_id_fk": { + "name": "vendor_pq_criteria_answers_vendor_id_vendors_id_fk", + "tableFrom": "vendor_pq_criteria_answers", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_pq_criteria_answers_criteria_id_pq_criterias_id_fk": { + "name": "vendor_pq_criteria_answers_criteria_id_pq_criterias_id_fk", + "tableFrom": "vendor_pq_criteria_answers", + "tableTo": "pq_criterias", + "columnsFrom": [ + "criteria_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_pq_criteria_answers_project_id_projects_id_fk": { + "name": "vendor_pq_criteria_answers_project_id_projects_id_fk", + "tableFrom": "vendor_pq_criteria_answers", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_pq_review_logs": { + "name": "vendor_pq_review_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_pq_criteria_answer_id": { + "name": "vendor_pq_criteria_answer_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "reviewer_comment": { + "name": "reviewer_comment", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reviewer_name": { + "name": "reviewer_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_pq_review_logs_vendor_pq_criteria_answer_id_vendor_pq_criteria_answers_id_fk": { + "name": "vendor_pq_review_logs_vendor_pq_criteria_answer_id_vendor_pq_criteria_answers_id_fk", + "tableFrom": "vendor_pq_review_logs", + "tableTo": "vendor_pq_criteria_answers", + "columnsFrom": [ + "vendor_pq_criteria_answer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_project_pqs": { + "name": "vendor_project_pqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'REQUESTED'" + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "rejected_at": { + "name": "rejected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "reject_reason": { + "name": "reject_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_project_pqs_vendor_id_vendors_id_fk": { + "name": "vendor_project_pqs_vendor_id_vendors_id_fk", + "tableFrom": "vendor_project_pqs", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_project_pqs_project_id_projects_id_fk": { + "name": "vendor_project_pqs_project_id_projects_id_fk", + "tableFrom": "vendor_project_pqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.bidding_projects": { + "name": "bidding_projects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pspid": { + "name": "pspid", + "type": "char(24)", + "primaryKey": false, + "notNull": true + }, + "proj_nm": { + "name": "proj_nm", + "type": "varchar(90)", + "primaryKey": false, + "notNull": false + }, + "sector": { + "name": "sector", + "type": "char(1)", + "primaryKey": false, + "notNull": false + }, + "proj_msrm": { + "name": "proj_msrm", + "type": "numeric(3, 0)", + "primaryKey": false, + "notNull": false + }, + "kunnr": { + "name": "kunnr", + "type": "char(10)", + "primaryKey": false, + "notNull": false + }, + "kunnr_nm": { + "name": "kunnr_nm", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "cls_1": { + "name": "cls_1", + "type": "char(10)", + "primaryKey": false, + "notNull": false + }, + "cls1_nm": { + "name": "cls1_nm", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "ptype": { + "name": "ptype", + "type": "char(3)", + "primaryKey": false, + "notNull": false + }, + "ptype_nm": { + "name": "ptype_nm", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "pmodel_cd": { + "name": "pmodel_cd", + "type": "char(10)", + "primaryKey": false, + "notNull": false + }, + "pmodel_nm": { + "name": "pmodel_nm", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "pmodel_sz": { + "name": "pmodel_sz", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "pmodel_uom": { + "name": "pmodel_uom", + "type": "char(5)", + "primaryKey": false, + "notNull": false + }, + "txt04": { + "name": "txt04", + "type": "char(4)", + "primaryKey": false, + "notNull": false + }, + "txt30": { + "name": "txt30", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "estm_pm": { + "name": "estm_pm", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "bidding_projects_pspid_unique": { + "name": "bidding_projects_pspid_unique", + "nullsNotDistinct": false, + "columns": [ + "pspid" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.project_series": { + "name": "project_series", + "schema": "", + "columns": { + "pspid": { + "name": "pspid", + "type": "char(24)", + "primaryKey": false, + "notNull": true + }, + "sers_no": { + "name": "sers_no", + "type": "char(3)", + "primaryKey": false, + "notNull": true + }, + "sc_dt": { + "name": "sc_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "kl_dt": { + "name": "kl_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "lc_dt": { + "name": "lc_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "dl_dt": { + "name": "dl_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "dock_no": { + "name": "dock_no", + "type": "char(3)", + "primaryKey": false, + "notNull": false + }, + "dock_nm": { + "name": "dock_nm", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "proj_no": { + "name": "proj_no", + "type": "char(24)", + "primaryKey": false, + "notNull": false + }, + "post1": { + "name": "post1", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "project_sersNo_unique": { + "name": "project_sersNo_unique", + "columns": [ + { + "expression": "pspid", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sers_no", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "project_series_pspid_bidding_projects_pspid_fk": { + "name": "project_series_pspid_bidding_projects_pspid_fk", + "tableFrom": "project_series", + "tableTo": "bidding_projects", + "columnsFrom": [ + "pspid" + ], + "columnsTo": [ + "pspid" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.projects": { + "name": "projects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'ship'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cbe_evaluations": { + "name": "cbe_evaluations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "evaluated_by": { + "name": "evaluated_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluated_at": { + "name": "evaluated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "result": { + "name": "result", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "total_cost": { + "name": "total_cost", + "type": "numeric(18, 2)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "payment_terms": { + "name": "payment_terms", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "incoterms": { + "name": "incoterms", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "delivery_schedule": { + "name": "delivery_schedule", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "cbe_evaluations_rfq_id_rfqs_id_fk": { + "name": "cbe_evaluations_rfq_id_rfqs_id_fk", + "tableFrom": "cbe_evaluations", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cbe_evaluations_vendor_id_vendors_id_fk": { + "name": "cbe_evaluations_vendor_id_vendors_id_fk", + "tableFrom": "cbe_evaluations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cbe_evaluations_evaluated_by_users_id_fk": { + "name": "cbe_evaluations_evaluated_by_users_id_fk", + "tableFrom": "cbe_evaluations", + "tableTo": "users", + "columnsFrom": [ + "evaluated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_attachments": { + "name": "rfq_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "evaluation_id": { + "name": "evaluation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cbe_id": { + "name": "cbe_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "comment_id": { + "name": "comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_attachments_rfq_id_rfqs_id_fk": { + "name": "rfq_attachments_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_vendor_id_vendors_id_fk": { + "name": "rfq_attachments_vendor_id_vendors_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_evaluation_id_rfq_evaluations_id_fk": { + "name": "rfq_attachments_evaluation_id_rfq_evaluations_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "rfq_evaluations", + "columnsFrom": [ + "evaluation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_cbe_id_cbe_evaluations_id_fk": { + "name": "rfq_attachments_cbe_id_cbe_evaluations_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "cbe_evaluations", + "columnsFrom": [ + "cbe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_comment_id_rfq_comments_id_fk": { + "name": "rfq_attachments_comment_id_rfq_comments_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "rfq_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_comments": { + "name": "rfq_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "comment_text": { + "name": "comment_text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "commented_by": { + "name": "commented_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "evaluation_id": { + "name": "evaluation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cbe_id": { + "name": "cbe_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_comments_rfq_id_rfqs_id_fk": { + "name": "rfq_comments_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_vendor_id_vendors_id_fk": { + "name": "rfq_comments_vendor_id_vendors_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_commented_by_users_id_fk": { + "name": "rfq_comments_commented_by_users_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "users", + "columnsFrom": [ + "commented_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_evaluation_id_rfq_evaluations_id_fk": { + "name": "rfq_comments_evaluation_id_rfq_evaluations_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "rfq_evaluations", + "columnsFrom": [ + "evaluation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_cbe_id_vendor_responses_id_fk": { + "name": "rfq_comments_cbe_id_vendor_responses_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "vendor_responses", + "columnsFrom": [ + "cbe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_evaluations": { + "name": "rfq_evaluations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "eval_type": { + "name": "eval_type", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_evaluations_rfq_id_rfqs_id_fk": { + "name": "rfq_evaluations_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_evaluations", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_evaluations_vendor_id_vendors_id_fk": { + "name": "rfq_evaluations_vendor_id_vendors_id_fk", + "tableFrom": "rfq_evaluations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_items": { + "name": "rfq_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "uom": { + "name": "uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_items_rfq_id_rfqs_id_fk": { + "name": "rfq_items_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_items", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "rfq_items_item_code_items_item_code_fk": { + "name": "rfq_items_item_code_items_item_code_fk", + "tableFrom": "rfq_items", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfqs": { + "name": "rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "bid_project_id": { + "name": "bid_project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "rfq_type": { + "name": "rfq_type", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false, + "default": "'PURCHASE'" + }, + "parent_rfq_id": { + "name": "parent_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfqs_project_id_projects_id_fk": { + "name": "rfqs_project_id_projects_id_fk", + "tableFrom": "rfqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "rfqs_bid_project_id_bidding_projects_id_fk": { + "name": "rfqs_bid_project_id_bidding_projects_id_fk", + "tableFrom": "rfqs", + "tableTo": "bidding_projects", + "columnsFrom": [ + "bid_project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "rfqs_created_by_users_id_fk": { + "name": "rfqs_created_by_users_id_fk", + "tableFrom": "rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "rfqs_parent_rfq_id_rfqs_id_fk": { + "name": "rfqs_parent_rfq_id_rfqs_id_fk", + "tableFrom": "rfqs", + "tableTo": "rfqs", + "columnsFrom": [ + "parent_rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "rfqs_rfq_code_unique": { + "name": "rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_commercial_responses": { + "name": "vendor_commercial_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "response_id": { + "name": "response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "total_price": { + "name": "total_price", + "type": "numeric(18, 2)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "payment_terms": { + "name": "payment_terms", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "incoterms": { + "name": "incoterms", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "delivery_period": { + "name": "delivery_period", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "warranty_period": { + "name": "warranty_period", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "validity_period": { + "name": "validity_period", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "price_breakdown": { + "name": "price_breakdown", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "commercial_notes": { + "name": "commercial_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_commercial_responses_response_id_vendor_responses_id_fk": { + "name": "vendor_commercial_responses_response_id_vendor_responses_id_fk", + "tableFrom": "vendor_commercial_responses", + "tableTo": "vendor_responses", + "columnsFrom": [ + "response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_response_attachments": { + "name": "vendor_response_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "response_id": { + "name": "response_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "technical_response_id": { + "name": "technical_response_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "commercial_response_id": { + "name": "commercial_response_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_response_attachments_response_id_vendor_responses_id_fk": { + "name": "vendor_response_attachments_response_id_vendor_responses_id_fk", + "tableFrom": "vendor_response_attachments", + "tableTo": "vendor_responses", + "columnsFrom": [ + "response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_attachments_technical_response_id_vendor_technical_responses_id_fk": { + "name": "vendor_response_attachments_technical_response_id_vendor_technical_responses_id_fk", + "tableFrom": "vendor_response_attachments", + "tableTo": "vendor_technical_responses", + "columnsFrom": [ + "technical_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_attachments_commercial_response_id_vendor_commercial_responses_id_fk": { + "name": "vendor_response_attachments_commercial_response_id_vendor_commercial_responses_id_fk", + "tableFrom": "vendor_response_attachments", + "tableTo": "vendor_commercial_responses", + "columnsFrom": [ + "commercial_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_responses": { + "name": "vendor_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'REVIEWING'" + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "responded_by": { + "name": "responded_by", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "responded_at": { + "name": "responded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "vendor_response_unique": { + "name": "vendor_response_unique", + "columns": [ + { + "expression": "rfq_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "vendor_responses_rfq_id_rfqs_id_fk": { + "name": "vendor_responses_rfq_id_rfqs_id_fk", + "tableFrom": "vendor_responses", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_responses_vendor_id_vendors_id_fk": { + "name": "vendor_responses_vendor_id_vendors_id_fk", + "tableFrom": "vendor_responses", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_technical_responses": { + "name": "vendor_technical_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "response_id": { + "name": "response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_technical_responses_response_id_vendor_responses_id_fk": { + "name": "vendor_technical_responses_response_id_vendor_responses_id_fk", + "tableFrom": "vendor_technical_responses", + "tableTo": "vendor_responses", + "columnsFrom": [ + "response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.otps": { + "name": "otps", + "schema": "", + "columns": { + "email": { + "name": "email", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(6)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "otpToken": { + "name": "otpToken", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "otp_expires": { + "name": "otp_expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.permissions": { + "name": "permissions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "permissions_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "permission_key": { + "name": "permission_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.role_permissions": { + "name": "role_permissions", + "schema": "", + "columns": { + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "permission_id": { + "name": "permission_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "role_permissions_role_id_roles_id_fk": { + "name": "role_permissions_role_id_roles_id_fk", + "tableFrom": "role_permissions", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "role_permissions_permission_id_permissions_id_fk": { + "name": "role_permissions_permission_id_permissions_id_fk", + "tableFrom": "role_permissions", + "tableTo": "permissions", + "columnsFrom": [ + "permission_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.roles": { + "name": "roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "roles_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "user_domain", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "roles_company_id_vendors_id_fk": { + "name": "roles_company_id_vendors_id_fk", + "tableFrom": "roles", + "tableTo": "vendors", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_roles": { + "name": "user_roles", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_roles_user_id_users_id_fk": { + "name": "user_roles_user_id_users_id_fk", + "tableFrom": "user_roles", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_roles_role_id_roles_id_fk": { + "name": "user_roles_role_id_roles_id_fk", + "tableFrom": "user_roles", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "users_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "domain": { + "name": "domain", + "type": "user_domain", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'partners'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "image_url": { + "name": "image_url", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false + }, + "language": { + "name": "language", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'en'" + } + }, + "indexes": {}, + "foreignKeys": { + "users_company_id_vendors_id_fk": { + "name": "users_company_id_vendors_id_fk", + "tableFrom": "users", + "tableTo": "vendors", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.form_entries": { + "name": "form_entries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "form_entries_contract_item_id_contract_items_id_fk": { + "name": "form_entries_contract_item_id_contract_items_id_fk", + "tableFrom": "form_entries", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.form_metas": { + "name": "form_metas", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "form_name": { + "name": "form_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "columns": { + "name": "columns", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "form_metas_project_id_projects_id_fk": { + "name": "form_metas_project_id_projects_id_fk", + "tableFrom": "form_metas", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "form_code_project_unique": { + "name": "form_code_project_unique", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "form_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.forms": { + "name": "forms", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "forms_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "form_name": { + "name": "form_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "eng": { + "name": "eng", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "im": { + "name": "im", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "contract_item_form_code_unique": { + "name": "contract_item_form_code_unique", + "columns": [ + { + "expression": "contract_item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "form_code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "forms_contract_item_id_contract_items_id_fk": { + "name": "forms_contract_item_id_contract_items_id_fk", + "tableFrom": "forms", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_class_attributes": { + "name": "tag_class_attributes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "tag_class_attributes_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "tag_class_id": { + "name": "tag_class_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "att_id": { + "name": "att_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "def_val": { + "name": "def_val", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "uom_id": { + "name": "uom_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "seq": { + "name": "seq", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "tag_class_attributes_seq_idx": { + "name": "tag_class_attributes_seq_idx", + "columns": [ + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tag_class_attributes_tag_class_id_tag_classes_id_fk": { + "name": "tag_class_attributes_tag_class_id_tag_classes_id_fk", + "tableFrom": "tag_class_attributes", + "tableTo": "tag_classes", + "columnsFrom": [ + "tag_class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_att_id_in_tag_class": { + "name": "uniq_att_id_in_tag_class", + "nullsNotDistinct": false, + "columns": [ + "tag_class_id", + "att_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_classes": { + "name": "tag_classes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "tag_classes_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_type_code": { + "name": "tag_type_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_classes_project_id_projects_id_fk": { + "name": "tag_classes_project_id_projects_id_fk", + "tableFrom": "tag_classes", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tag_classes_tag_type_code_project_id_tag_types_code_project_id_fk": { + "name": "tag_classes_tag_type_code_project_id_tag_types_code_project_id_fk", + "tableFrom": "tag_classes", + "tableTo": "tag_types", + "columnsFrom": [ + "tag_type_code", + "project_id" + ], + "columnsTo": [ + "code", + "project_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_code_in_project": { + "name": "uniq_code_in_project", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_subfield_options": { + "name": "tag_subfield_options", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "attributes_id": { + "name": "attributes_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_subfield_options_project_id_projects_id_fk": { + "name": "tag_subfield_options_project_id_projects_id_fk", + "tableFrom": "tag_subfield_options", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_attribute_project_code": { + "name": "uniq_attribute_project_code", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "attributes_id", + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_subfields": { + "name": "tag_subfields", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "tag_type_code": { + "name": "tag_type_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "attributes_id": { + "name": "attributes_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "attributes_description": { + "name": "attributes_description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expression": { + "name": "expression", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delimiter": { + "name": "delimiter", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_subfields_project_id_projects_id_fk": { + "name": "tag_subfields_project_id_projects_id_fk", + "tableFrom": "tag_subfields", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_tag_type_attribute": { + "name": "uniq_tag_type_attribute", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "tag_type_code", + "attributes_id" + ] + }, + "uniq_attribute_id_project": { + "name": "uniq_attribute_id_project", + "nullsNotDistinct": false, + "columns": [ + "attributes_id", + "project_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_type_class_form_mappings": { + "name": "tag_type_class_form_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "tag_type_label": { + "name": "tag_type_label", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "class_label": { + "name": "class_label", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "form_name": { + "name": "form_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "ep": { + "name": "ep", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_mapping_in_project": { + "name": "uniq_mapping_in_project", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "tag_type_label", + "class_label", + "form_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_types": { + "name": "tag_types", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_types_project_id_projects_id_fk": { + "name": "tag_types_project_id_projects_id_fk", + "tableFrom": "tag_types", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "tag_types_code_project_id_pk": { + "name": "tag_types_code_project_id_pk", + "columns": [ + "code", + "project_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tags": { + "name": "tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "tags_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_id": { + "name": "form_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tag_no": { + "name": "tag_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "tag_type": { + "name": "tag_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "class": { + "name": "class", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tags_contract_item_id_contract_items_id_fk": { + "name": "tags_contract_item_id_contract_items_id_fk", + "tableFrom": "tags", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tags_form_id_forms_id_fk": { + "name": "tags_form_id_forms_id_fk", + "tableFrom": "tags", + "tableTo": "forms", + "columnsFrom": [ + "form_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "contract_item_tag_no_unique": { + "name": "contract_item_tag_no_unique", + "nullsNotDistinct": false, + "columns": [ + "contract_item_id", + "tag_no" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_data_report_temps": { + "name": "vendor_data_report_temps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_id": { + "name": "form_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_data_report_temps_contract_item_id_contract_items_id_fk": { + "name": "vendor_data_report_temps_contract_item_id_contract_items_id_fk", + "tableFrom": "vendor_data_report_temps", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_data_report_temps_form_id_forms_id_fk": { + "name": "vendor_data_report_temps_form_id_forms_id_fk", + "tableFrom": "vendor_data_report_temps", + "tableTo": "forms", + "columnsFrom": [ + "form_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.change_logs": { + "name": "change_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "changed_fields": { + "name": "changed_fields", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "old_values": { + "name": "old_values", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "new_values": { + "name": "new_values", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_name": { + "name": "user_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "is_synced": { + "name": "is_synced", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "sync_attempts": { + "name": "sync_attempts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "synced_at": { + "name": "synced_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "target_systems": { + "name": "target_systems", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + } + }, + "indexes": { + "idx_change_logs_contract_synced": { + "name": "idx_change_logs_contract_synced", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "is_synced", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_change_logs_created_at": { + "name": "idx_change_logs_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_change_logs_entity": { + "name": "idx_change_logs_entity", + "columns": [ + { + "expression": "entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entity_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_change_logs_sync_attempts": { + "name": "idx_change_logs_sync_attempts", + "columns": [ + { + "expression": "sync_attempts", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.document_attachments": { + "name": "document_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "document_attachments_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "revision_id": { + "name": "revision_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "upload_id": { + "name": "upload_id", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false + }, + "file_id": { + "name": "file_id", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "dolce_file_path": { + "name": "dolce_file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "document_attachments_revision_id_revisions_id_fk": { + "name": "document_attachments_revision_id_revisions_id_fk", + "tableFrom": "document_attachments", + "tableTo": "revisions", + "columnsFrom": [ + "revision_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.documents": { + "name": "documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "documents_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "pic": { + "name": "pic", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "vendor_doc_number": { + "name": "vendor_doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "drawing_kind": { + "name": "drawing_kind", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "drawing_move_gbn": { + "name": "drawing_move_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "discipline": { + "name": "discipline", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "external_document_id": { + "name": "external_document_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "external_system_type": { + "name": "external_system_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "external_synced_at": { + "name": "external_synced_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "c_gbn": { + "name": "c_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "d_gbn": { + "name": "d_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "degree_gbn": { + "name": "degree_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "dept_gbn": { + "name": "dept_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "j_gbn": { + "name": "j_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "s_gbn": { + "name": "s_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "shi_drawing_no": { + "name": "shi_drawing_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "manager": { + "name": "manager", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "manager_enm": { + "name": "manager_enm", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "manager_no": { + "name": "manager_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "register_group": { + "name": "register_group", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "register_group_id": { + "name": "register_group_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "create_user_no": { + "name": "create_user_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "create_user_id": { + "name": "create_user_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "create_user_enm": { + "name": "create_user_enm", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_contract_doc_status": { + "name": "unique_contract_doc_status", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "doc_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "unique_contract_vendor_doc": { + "name": "unique_contract_vendor_doc", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor_doc_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"documents\".\"vendor_doc_number\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "unique_external_doc": { + "name": "unique_external_doc", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_system_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"documents\".\"external_document_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "drawing_kind_idx": { + "name": "drawing_kind_idx", + "columns": [ + { + "expression": "drawing_kind", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "documents_contract_id_contracts_id_fk": { + "name": "documents_contract_id_contracts_id_fk", + "tableFrom": "documents", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.issue_stages": { + "name": "issue_stages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "issue_stages_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "document_id": { + "name": "document_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stage_name": { + "name": "stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "plan_date": { + "name": "plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "actual_date": { + "name": "actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "stage_status": { + "name": "stage_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'PLANNED'" + }, + "stage_order": { + "name": "stage_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "priority": { + "name": "priority", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false, + "default": "'MEDIUM'" + }, + "assignee_id": { + "name": "assignee_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "assignee_name": { + "name": "assignee_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "reminder_days": { + "name": "reminder_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "varchar(1000)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_document_stage": { + "name": "unique_document_stage", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stage_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_stage_order": { + "name": "document_stage_order", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stage_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "issue_stages_document_id_documents_id_fk": { + "name": "issue_stages_document_id_documents_id_fk", + "tableFrom": "issue_stages", + "tableTo": "documents", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.revisions": { + "name": "revisions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "revisions_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "issue_stage_id": { + "name": "issue_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "uploader_type": { + "name": "uploader_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'vendor'" + }, + "uploader_id": { + "name": "uploader_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploader_name": { + "name": "uploader_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "usage": { + "name": "usage", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "revision_status": { + "name": "revision_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'SUBMITTED'" + }, + "submitted_date": { + "name": "submitted_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "review_start_date": { + "name": "review_start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "approved_date": { + "name": "approved_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "rejected_date": { + "name": "rejected_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "reviewer_id": { + "name": "reviewer_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "reviewer_name": { + "name": "reviewer_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "review_comments": { + "name": "review_comments", + "type": "varchar(1000)", + "primaryKey": false, + "notNull": false + }, + "external_upload_id": { + "name": "external_upload_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_stage_rev": { + "name": "unique_stage_rev", + "columns": [ + { + "expression": "issue_stage_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "revision", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sync_batches": { + "name": "sync_batches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_system": { + "name": "target_system", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "batch_size": { + "name": "batch_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "retry_count": { + "name": "retry_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "change_log_ids": { + "name": "change_log_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "success_count": { + "name": "success_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "failure_count": { + "name": "failure_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "sync_metadata": { + "name": "sync_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_sync_batches_contract_system": { + "name": "idx_sync_batches_contract_system", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_system", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_sync_batches_status": { + "name": "idx_sync_batches_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_sync_batches_created_at": { + "name": "idx_sync_batches_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sync_configs": { + "name": "sync_configs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_system": { + "name": "target_system", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "sync_enabled": { + "name": "sync_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "sync_interval_minutes": { + "name": "sync_interval_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 30 + }, + "last_successful_sync": { + "name": "last_successful_sync", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_sync_attempt": { + "name": "last_sync_attempt", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "endpoint_url": { + "name": "endpoint_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "auth_token": { + "name": "auth_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "api_version": { + "name": "api_version", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false, + "default": "'v1'" + }, + "max_batch_size": { + "name": "max_batch_size", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 100 + }, + "retry_max_attempts": { + "name": "retry_max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_sync_configs_contract_system": { + "name": "idx_sync_configs_contract_system", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_system", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sync_configs_contract_id_contracts_id_fk": { + "name": "sync_configs_contract_id_contracts_id_fk", + "tableFrom": "sync_configs", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_attachments": { + "name": "vendor_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'GENERAL'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_attachments_vendor_id_vendors_id_fk": { + "name": "vendor_attachments_vendor_id_vendors_id_fk", + "tableFrom": "vendor_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_candidates": { + "name": "vendor_candidates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_name": { + "name": "company_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_email": { + "name": "contact_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "contact_phone": { + "name": "contact_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'COLLECTED'" + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_candidates_vendor_id_vendors_id_fk": { + "name": "vendor_candidates_vendor_id_vendors_id_fk", + "tableFrom": "vendor_candidates", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_contacts": { + "name": "vendor_contacts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "contact_name": { + "name": "contact_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_position": { + "name": "contact_position", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "contact_email": { + "name": "contact_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_phone": { + "name": "contact_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "is_primary": { + "name": "is_primary", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_contacts_vendor_id_vendors_id_fk": { + "name": "vendor_contacts_vendor_id_vendors_id_fk", + "tableFrom": "vendor_contacts", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_possible_items": { + "name": "vendor_possible_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_possible_items_vendor_id_vendors_id_fk": { + "name": "vendor_possible_items_vendor_id_vendors_id_fk", + "tableFrom": "vendor_possible_items", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_possible_items_item_code_items_item_code_fk": { + "name": "vendor_possible_items_item_code_items_item_code_fk", + "tableFrom": "vendor_possible_items", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_possible_materials": { + "name": "vendor_possible_materials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_possible_materials_vendor_id_vendors_id_fk": { + "name": "vendor_possible_materials_vendor_id_vendors_id_fk", + "tableFrom": "vendor_possible_materials", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_possible_materials_item_code_materials_item_code_fk": { + "name": "vendor_possible_materials_item_code_materials_item_code_fk", + "tableFrom": "vendor_possible_materials", + "tableTo": "materials", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_types": { + "name": "vendor_types", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name_ko": { + "name": "name_ko", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "name_en": { + "name": "name_en", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "vendor_types_code_unique": { + "name": "vendor_types_code_unique", + "nullsNotDistinct": false, + "columns": [ + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendors": { + "name": "vendors", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "website": { + "name": "website", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING_REVIEW'" + }, + "vendor_type_id": { + "name": "vendor_type_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "representative_name": { + "name": "representative_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_birth": { + "name": "representative_birth", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "representative_email": { + "name": "representative_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_phone": { + "name": "representative_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "corporate_registration_number": { + "name": "corporate_registration_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credit_agency": { + "name": "credit_agency", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "credit_rating": { + "name": "credit_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "cash_flow_rating": { + "name": "cash_flow_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "business_size": { + "name": "business_size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendors_vendor_type_id_vendor_types_id_fk": { + "name": "vendors_vendor_type_id_vendor_types_id_fk", + "tableFrom": "vendors", + "tableTo": "vendor_types", + "columnsFrom": [ + "vendor_type_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'todo'" + }, + "label": { + "name": "label", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'bug'" + }, + "priority": { + "name": "priority", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'low'" + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "current_timestamp" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "tasks_code_unique": { + "name": "tasks_code_unique", + "nullsNotDistinct": false, + "columns": [ + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_candidate_logs": { + "name": "vendor_candidate_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_candidate_id": { + "name": "vendor_candidate_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "old_status": { + "name": "old_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "new_status": { + "name": "new_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_candidate_logs_vendor_candidate_id_vendor_candidates_id_fk": { + "name": "vendor_candidate_logs_vendor_candidate_id_vendor_candidates_id_fk", + "tableFrom": "vendor_candidate_logs", + "tableTo": "vendor_candidates", + "columnsFrom": [ + "vendor_candidate_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_candidate_logs_user_id_users_id_fk": { + "name": "vendor_candidate_logs_user_id_users_id_fk", + "tableFrom": "vendor_candidate_logs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendors_logs": { + "name": "vendors_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "old_status": { + "name": "old_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "new_status": { + "name": "new_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendors_logs_vendor_id_vendors_id_fk": { + "name": "vendors_logs_vendor_id_vendors_id_fk", + "tableFrom": "vendors_logs", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendors_logs_user_id_users_id_fk": { + "name": "vendors_logs_user_id_users_id_fk", + "tableFrom": "vendors_logs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.basic_contract": { + "name": "basic_contract", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "basic_contract_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "template_id": { + "name": "template_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requested_by": { + "name": "requested_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "basic_contract_template_id_basic_contract_templates_id_fk": { + "name": "basic_contract_template_id_basic_contract_templates_id_fk", + "tableFrom": "basic_contract", + "tableTo": "basic_contract_templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "basic_contract_vendor_id_vendors_id_fk": { + "name": "basic_contract_vendor_id_vendors_id_fk", + "tableFrom": "basic_contract", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "basic_contract_requested_by_users_id_fk": { + "name": "basic_contract_requested_by_users_id_fk", + "tableFrom": "basic_contract", + "tableTo": "users", + "columnsFrom": [ + "requested_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.basic_contract_templates": { + "name": "basic_contract_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "basic_contract_templates_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "template_name": { + "name": "template_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "validity_period": { + "name": "validity_period", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.incoterms": { + "name": "incoterms", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "varchar(20)", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "incoterms_created_by_users_id_fk": { + "name": "incoterms_created_by_users_id_fk", + "tableFrom": "incoterms", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payment_terms": { + "name": "payment_terms", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "payment_terms_created_by_users_id_fk": { + "name": "payment_terms_created_by_users_id_fk", + "tableFrom": "payment_terms", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pr_items": { + "name": "pr_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_item": { + "name": "rfq_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_item": { + "name": "pr_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_no": { + "name": "pr_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "material_code": { + "name": "material_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_category": { + "name": "material_category", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "acc": { + "name": "acc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_description": { + "name": "material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "size": { + "name": "size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "uom": { + "name": "uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "gross_weight": { + "name": "gross_weight", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "gw_uom": { + "name": "gw_uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "spec_no": { + "name": "spec_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "spec_url": { + "name": "spec_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "tracking_no": { + "name": "tracking_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "major_yn": { + "name": "major_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "project_def": { + "name": "project_def", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_sc": { + "name": "project_sc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_kl": { + "name": "project_kl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_lc": { + "name": "project_lc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_dl": { + "name": "project_dl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pr_items_procurement_rfqs_id_procurement_rfqs_id_fk": { + "name": "pr_items_procurement_rfqs_id_procurement_rfqs_id_fk", + "tableFrom": "pr_items", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "procurement_rfqs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_attachments": { + "name": "procurement_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "procurement_rfq_details_id": { + "name": "procurement_rfq_details_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_attachments_procurement_rfqs_id_procurement_rfqs_id_fk": { + "name": "procurement_attachments_procurement_rfqs_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_attachments", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "procurement_rfqs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_attachments_procurement_rfq_details_id_procurement_rfq_details_id_fk": { + "name": "procurement_attachments_procurement_rfq_details_id_procurement_rfq_details_id_fk", + "tableFrom": "procurement_attachments", + "tableTo": "procurement_rfq_details", + "columnsFrom": [ + "procurement_rfq_details_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_attachments_created_by_users_id_fk": { + "name": "procurement_attachments_created_by_users_id_fk", + "tableFrom": "procurement_attachments", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "attachment_type_check": { + "name": "attachment_type_check", + "value": "\"procurement_attachments\".\"procurement_rfqs_id\" IS NOT NULL OR \"procurement_attachments\".\"procurement_rfq_details_id\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.procurement_quotation_items": { + "name": "procurement_quotation_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "quotation_id": { + "name": "quotation_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pr_item_id": { + "name": "pr_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "material_code": { + "name": "material_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "material_description": { + "name": "material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "uom": { + "name": "uom", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "unit_price": { + "name": "unit_price", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "total_price": { + "name": "total_price", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "vendor_material_code": { + "name": "vendor_material_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_material_description": { + "name": "vendor_material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "lead_time_in_days": { + "name": "lead_time_in_days", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tax_rate": { + "name": "tax_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "tax_amount": { + "name": "tax_amount", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "discount_rate": { + "name": "discount_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "discount_amount": { + "name": "discount_amount", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_alternative": { + "name": "is_alternative", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "is_recommended": { + "name": "is_recommended", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_quotation_items_quotation_id_procurement_vendor_quotations_id_fk": { + "name": "procurement_quotation_items_quotation_id_procurement_vendor_quotations_id_fk", + "tableFrom": "procurement_quotation_items", + "tableTo": "procurement_vendor_quotations", + "columnsFrom": [ + "quotation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_quotation_items_pr_item_id_pr_items_id_fk": { + "name": "procurement_quotation_items_pr_item_id_pr_items_id_fk", + "tableFrom": "procurement_quotation_items", + "tableTo": "pr_items", + "columnsFrom": [ + "pr_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfq_attachments": { + "name": "procurement_rfq_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "comment_id": { + "name": "comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "quotation_id": { + "name": "quotation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "file_path": { + "name": "file_path", + "type": "varchar(500)", + "primaryKey": false, + "notNull": true + }, + "is_vendor_upload": { + "name": "is_vendor_upload", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfq_attachments_rfq_id_procurement_rfqs_id_fk": { + "name": "procurement_rfq_attachments_rfq_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_comment_id_procurement_rfq_comments_id_fk": { + "name": "procurement_rfq_attachments_comment_id_procurement_rfq_comments_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "procurement_rfq_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_quotation_id_procurement_vendor_quotations_id_fk": { + "name": "procurement_rfq_attachments_quotation_id_procurement_vendor_quotations_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "procurement_vendor_quotations", + "columnsFrom": [ + "quotation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_uploaded_by_users_id_fk": { + "name": "procurement_rfq_attachments_uploaded_by_users_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_vendor_id_vendors_id_fk": { + "name": "procurement_rfq_attachments_vendor_id_vendors_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfq_comments": { + "name": "procurement_rfq_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_vendor_comment": { + "name": "is_vendor_comment", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "is_read": { + "name": "is_read", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "parent_comment_id": { + "name": "parent_comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfq_comments_rfq_id_procurement_rfqs_id_fk": { + "name": "procurement_rfq_comments_rfq_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_comments_vendor_id_vendors_id_fk": { + "name": "procurement_rfq_comments_vendor_id_vendors_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_comments_user_id_users_id_fk": { + "name": "procurement_rfq_comments_user_id_users_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_comments_parent_comment_id_procurement_rfq_comments_id_fk": { + "name": "procurement_rfq_comments_parent_comment_id_procurement_rfq_comments_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "procurement_rfq_comments", + "columnsFrom": [ + "parent_comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfq_details": { + "name": "procurement_rfq_details", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendors_id": { + "name": "vendors_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_detail": { + "name": "incoterms_detail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "tax_code": { + "name": "tax_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "default": "'VV'" + }, + "place_of_shipping": { + "name": "place_of_shipping", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_destination": { + "name": "place_of_destination", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "material_price_related_yn": { + "name": "material_price_related_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfq_details_procurement_rfqs_id_procurement_rfqs_id_fk": { + "name": "procurement_rfq_details_procurement_rfqs_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "procurement_rfqs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_vendors_id_vendors_id_fk": { + "name": "procurement_rfq_details_vendors_id_vendors_id_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "vendors", + "columnsFrom": [ + "vendors_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_payment_terms_code_payment_terms_code_fk": { + "name": "procurement_rfq_details_payment_terms_code_payment_terms_code_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "payment_terms", + "columnsFrom": [ + "payment_terms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_incoterms_code_incoterms_code_fk": { + "name": "procurement_rfq_details_incoterms_code_incoterms_code_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_updated_by_users_id_fk": { + "name": "procurement_rfq_details_updated_by_users_id_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfqs": { + "name": "procurement_rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "series": { + "name": "series", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "rfq_send_date": { + "name": "rfq_send_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'RFQ Created'" + }, + "rfq_sealed_yn": { + "name": "rfq_sealed_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_by": { + "name": "sent_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfqs_project_id_projects_id_fk": { + "name": "procurement_rfqs_project_id_projects_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfqs_sent_by_users_id_fk": { + "name": "procurement_rfqs_sent_by_users_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "users", + "columnsFrom": [ + "sent_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfqs_created_by_users_id_fk": { + "name": "procurement_rfqs_created_by_users_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfqs_updated_by_users_id_fk": { + "name": "procurement_rfqs_updated_by_users_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "procurement_rfqs_rfq_code_unique": { + "name": "procurement_rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_vendor_quotations": { + "name": "procurement_vendor_quotations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "quotation_code": { + "name": "quotation_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "quotation_version": { + "name": "quotation_version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "total_items_count": { + "name": "total_items_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "sub_total": { + "name": "sub_total", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "tax_total": { + "name": "tax_total", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "discount_total": { + "name": "discount_total", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "total_price": { + "name": "total_price", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "valid_until": { + "name": "valid_until", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "estimated_delivery_date": { + "name": "estimated_delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_detail": { + "name": "incoterms_detail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'Draft'" + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rejection_reason": { + "name": "rejection_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_vendor_quotations_rfq_id_procurement_rfqs_id_fk": { + "name": "procurement_vendor_quotations_rfq_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_vendor_quotations_vendor_id_vendors_id_fk": { + "name": "procurement_vendor_quotations_vendor_id_vendors_id_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_vendor_quotations_payment_terms_code_payment_terms_code_fk": { + "name": "procurement_vendor_quotations_payment_terms_code_payment_terms_code_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "payment_terms", + "columnsFrom": [ + "payment_terms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_vendor_quotations_incoterms_code_incoterms_code_fk": { + "name": "procurement_vendor_quotations_incoterms_code_incoterms_code_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.preset_shares": { + "name": "preset_shares", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "preset_id": { + "name": "preset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "shared_with_user_id": { + "name": "shared_with_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "permission": { + "name": "permission", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'read'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "preset_shares_preset_id_table_presets_id_fk": { + "name": "preset_shares_preset_id_table_presets_id_fk", + "tableFrom": "preset_shares", + "tableTo": "table_presets", + "columnsFrom": [ + "preset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.table_presets": { + "name": "table_presets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "settings": { + "name": "settings", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "is_default": { + "name": "is_default", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_shared": { + "name": "is_shared", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_attachments": { + "name": "tech_sales_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "tech_sales_rfq_id": { + "name": "tech_sales_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_attachments_tech_sales_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_attachments_tech_sales_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_attachments", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "tech_sales_rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_attachments_created_by_users_id_fk": { + "name": "tech_sales_attachments_created_by_users_id_fk", + "tableFrom": "tech_sales_attachments", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_rfq_comment_attachments": { + "name": "tech_sales_rfq_comment_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "comment_id": { + "name": "comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "quotation_id": { + "name": "quotation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "file_path": { + "name": "file_path", + "type": "varchar(500)", + "primaryKey": false, + "notNull": true + }, + "is_vendor_upload": { + "name": "is_vendor_upload", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_rfq_comment_attachments_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_rfq_comment_attachments_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_comment_id_tech_sales_rfq_comments_id_fk": { + "name": "tech_sales_rfq_comment_attachments_comment_id_tech_sales_rfq_comments_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "tech_sales_rfq_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_quotation_id_tech_sales_vendor_quotations_id_fk": { + "name": "tech_sales_rfq_comment_attachments_quotation_id_tech_sales_vendor_quotations_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "tech_sales_vendor_quotations", + "columnsFrom": [ + "quotation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_uploaded_by_users_id_fk": { + "name": "tech_sales_rfq_comment_attachments_uploaded_by_users_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_vendor_id_vendors_id_fk": { + "name": "tech_sales_rfq_comment_attachments_vendor_id_vendors_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_rfq_comments": { + "name": "tech_sales_rfq_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_vendor_comment": { + "name": "is_vendor_comment", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "is_read": { + "name": "is_read", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "parent_comment_id": { + "name": "parent_comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_rfq_comments_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_rfq_comments_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comments_vendor_id_vendors_id_fk": { + "name": "tech_sales_rfq_comments_vendor_id_vendors_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfq_comments_user_id_users_id_fk": { + "name": "tech_sales_rfq_comments_user_id_users_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfq_comments_parent_comment_id_tech_sales_rfq_comments_id_fk": { + "name": "tech_sales_rfq_comments_parent_comment_id_tech_sales_rfq_comments_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "tech_sales_rfq_comments", + "columnsFrom": [ + "parent_comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_rfqs": { + "name": "tech_sales_rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "item_shipbuilding_id": { + "name": "item_shipbuilding_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "bidding_project_id": { + "name": "bidding_project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "material_code": { + "name": "material_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "rfq_send_date": { + "name": "rfq_send_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'RFQ Created'" + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_by": { + "name": "sent_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_snapshot": { + "name": "project_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "series_snapshot": { + "name": "series_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_rfqs_item_shipbuilding_id_item_shipbuilding_id_fk": { + "name": "tech_sales_rfqs_item_shipbuilding_id_item_shipbuilding_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "item_shipbuilding", + "columnsFrom": [ + "item_shipbuilding_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfqs_bidding_project_id_bidding_projects_id_fk": { + "name": "tech_sales_rfqs_bidding_project_id_bidding_projects_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "bidding_projects", + "columnsFrom": [ + "bidding_project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfqs_sent_by_users_id_fk": { + "name": "tech_sales_rfqs_sent_by_users_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "users", + "columnsFrom": [ + "sent_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfqs_created_by_users_id_fk": { + "name": "tech_sales_rfqs_created_by_users_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfqs_updated_by_users_id_fk": { + "name": "tech_sales_rfqs_updated_by_users_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "tech_sales_rfqs_rfq_code_unique": { + "name": "tech_sales_rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_vendor_quotations": { + "name": "tech_sales_vendor_quotations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "quotation_code": { + "name": "quotation_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "quotation_version": { + "name": "quotation_version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "total_price": { + "name": "total_price", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "valid_until": { + "name": "valid_until", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'Draft'" + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rejection_reason": { + "name": "rejection_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_vendor_quotations_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_vendor_quotations_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_vendor_quotations", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_vendor_quotations_vendor_id_vendors_id_fk": { + "name": "tech_sales_vendor_quotations_vendor_id_vendors_id_fk", + "tableFrom": "tech_sales_vendor_quotations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_rotation_attempts": { + "name": "ocr_rotation_attempts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "rotation": { + "name": "rotation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "confidence": { + "name": "confidence", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "tables_found": { + "name": "tables_found", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "text_quality": { + "name": "text_quality", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "keyword_count": { + "name": "keyword_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "score": { + "name": "score", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "extracted_rows_count": { + "name": "extracted_rows_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "ocr_rotation_attempts_session_id_ocr_sessions_id_fk": { + "name": "ocr_rotation_attempts_session_id_ocr_sessions_id_fk", + "tableFrom": "ocr_rotation_attempts", + "tableTo": "ocr_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_rows": { + "name": "ocr_rows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "table_id": { + "name": "table_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "row_index": { + "name": "row_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "report_no": { + "name": "report_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "no": { + "name": "no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "identification_no": { + "name": "identification_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tag_no": { + "name": "tag_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "joint_no": { + "name": "joint_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "joint_type": { + "name": "joint_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "welding_date": { + "name": "welding_date", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "source_table": { + "name": "source_table", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "source_row": { + "name": "source_row", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_ocr_report_no_unique": { + "name": "idx_ocr_report_no_unique", + "columns": [ + { + "expression": "report_no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tag_no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "joint_no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "joint_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "ocr_rows_table_id_ocr_tables_id_fk": { + "name": "ocr_rows_table_id_ocr_tables_id_fk", + "tableFrom": "ocr_rows", + "tableTo": "ocr_tables", + "columnsFrom": [ + "table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ocr_rows_session_id_ocr_sessions_id_fk": { + "name": "ocr_rows_session_id_ocr_sessions_id_fk", + "tableFrom": "ocr_rows", + "tableTo": "ocr_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ocr_rows_user_id_users_id_fk": { + "name": "ocr_rows_user_id_users_id_fk", + "tableFrom": "ocr_rows", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_sessions": { + "name": "ocr_sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "processing_time": { + "name": "processing_time", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "best_rotation": { + "name": "best_rotation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_tables": { + "name": "total_tables", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_rows": { + "name": "total_rows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "image_enhanced": { + "name": "image_enhanced", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "pdf_converted": { + "name": "pdf_converted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "success": { + "name": "success", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "warnings": { + "name": "warnings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_tables": { + "name": "ocr_tables", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "table_index": { + "name": "table_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "row_count": { + "name": "row_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "ocr_tables_session_id_ocr_sessions_id_fk": { + "name": "ocr_tables_session_id_ocr_sessions_id_fk", + "tableFrom": "ocr_tables", + "tableTo": "ocr_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.b_rfq_attachment_revisions": { + "name": "b_rfq_attachment_revisions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_id": { + "name": "attachment_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "revision_no": { + "name": "revision_no", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true + }, + "revision_comment": { + "name": "revision_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_latest": { + "name": "is_latest", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "latest_revision_idx": { + "name": "latest_revision_idx", + "columns": [ + { + "expression": "attachment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "is_latest", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"b_rfq_attachment_revisions\".\"is_latest\" = $1", + "concurrently": false, + "method": "btree", + "with": {} + }, + "attachment_revision_idx": { + "name": "attachment_revision_idx", + "columns": [ + { + "expression": "attachment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "revision_no", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "b_rfq_attachment_revisions_attachment_id_b_rfq_attachments_id_fk": { + "name": "b_rfq_attachment_revisions_attachment_id_b_rfq_attachments_id_fk", + "tableFrom": "b_rfq_attachment_revisions", + "tableTo": "b_rfq_attachments", + "columnsFrom": [ + "attachment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "b_rfq_attachment_revisions_created_by_users_id_fk": { + "name": "b_rfq_attachment_revisions_created_by_users_id_fk", + "tableFrom": "b_rfq_attachment_revisions", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.b_rfqs": { + "name": "b_rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pic_name": { + "name": "pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "eng_pic_name": { + "name": "eng_pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_company": { + "name": "project_company", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_flag": { + "name": "project_flag", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_site": { + "name": "project_site", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "package_no": { + "name": "package_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_name": { + "name": "package_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "b_rfqs_project_id_projects_id_fk": { + "name": "b_rfqs_project_id_projects_id_fk", + "tableFrom": "b_rfqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "b_rfqs_created_by_users_id_fk": { + "name": "b_rfqs_created_by_users_id_fk", + "tableFrom": "b_rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "b_rfqs_updated_by_users_id_fk": { + "name": "b_rfqs_updated_by_users_id_fk", + "tableFrom": "b_rfqs", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "b_rfqs_rfq_code_unique": { + "name": "b_rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.b_rfq_attachments": { + "name": "b_rfq_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "serial_no": { + "name": "serial_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "current_revision": { + "name": "current_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "default": "'Rev.0'" + }, + "latest_revision_id": { + "name": "latest_revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "b_rfq_attachments_rfq_id_b_rfqs_id_fk": { + "name": "b_rfq_attachments_rfq_id_b_rfqs_id_fk", + "tableFrom": "b_rfq_attachments", + "tableTo": "b_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "b_rfq_attachments_created_by_users_id_fk": { + "name": "b_rfq_attachments_created_by_users_id_fk", + "tableFrom": "b_rfq_attachments", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.final_rfq": { + "name": "final_rfq", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "final_rfq_status": { + "name": "final_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'KRW'" + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "tax_code": { + "name": "tax_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "default": "'VV'" + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "place_of_shipping": { + "name": "place_of_shipping", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_destination": { + "name": "place_of_destination", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "firsttime_yn": { + "name": "firsttime_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "material_price_related_yn": { + "name": "material_price_related_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vendor_remark": { + "name": "vendor_remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "final_rfq_rfq_id_b_rfqs_id_fk": { + "name": "final_rfq_rfq_id_b_rfqs_id_fk", + "tableFrom": "final_rfq", + "tableTo": "b_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "final_rfq_vendor_id_vendors_id_fk": { + "name": "final_rfq_vendor_id_vendors_id_fk", + "tableFrom": "final_rfq", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "final_rfq_incoterms_code_incoterms_code_fk": { + "name": "final_rfq_incoterms_code_incoterms_code_fk", + "tableFrom": "final_rfq", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "final_rfq_payment_terms_code_payment_terms_code_fk": { + "name": "final_rfq_payment_terms_code_payment_terms_code_fk", + "tableFrom": "final_rfq", + "tableTo": "payment_terms", + "columnsFrom": [ + "payment_terms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.initial_rfq": { + "name": "initial_rfq", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "initial_rfq_status": { + "name": "initial_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "initial_rfq_rfq_id_b_rfqs_id_fk": { + "name": "initial_rfq_rfq_id_b_rfqs_id_fk", + "tableFrom": "initial_rfq", + "tableTo": "b_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "initial_rfq_vendor_id_vendors_id_fk": { + "name": "initial_rfq_vendor_id_vendors_id_fk", + "tableFrom": "initial_rfq", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "initial_rfq_incoterms_code_incoterms_code_fk": { + "name": "initial_rfq_incoterms_code_incoterms_code_fk", + "tableFrom": "initial_rfq", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_attachment_responses": { + "name": "vendor_attachment_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_id": { + "name": "attachment_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "rfq_type": { + "name": "rfq_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "rfq_record_id": { + "name": "rfq_record_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'NOT_RESPONDED'" + }, + "current_revision": { + "name": "current_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'Rev.0'" + }, + "responded_revision": { + "name": "responded_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "response_comment": { + "name": "response_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vendor_comment": { + "name": "vendor_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "responded_at": { + "name": "responded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "vendor_response_idx": { + "name": "vendor_response_idx", + "columns": [ + { + "expression": "attachment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "rfq_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "vendor_attachment_responses_attachment_id_b_rfq_attachments_id_fk": { + "name": "vendor_attachment_responses_attachment_id_b_rfq_attachments_id_fk", + "tableFrom": "vendor_attachment_responses", + "tableTo": "b_rfq_attachments", + "columnsFrom": [ + "attachment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_attachment_responses_vendor_id_vendors_id_fk": { + "name": "vendor_attachment_responses_vendor_id_vendors_id_fk", + "tableFrom": "vendor_attachment_responses", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_response_attachments_b": { + "name": "vendor_response_attachments_b", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_response_id": { + "name": "vendor_response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_response_attachments_b_vendor_response_id_vendor_attachment_responses_id_fk": { + "name": "vendor_response_attachments_b_vendor_response_id_vendor_attachment_responses_id_fk", + "tableFrom": "vendor_response_attachments_b", + "tableTo": "vendor_attachment_responses", + "columnsFrom": [ + "vendor_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_attachments_b_uploaded_by_users_id_fk": { + "name": "vendor_response_attachments_b_uploaded_by_users_id_fk", + "tableFrom": "vendor_response_attachments_b", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_response_history": { + "name": "vendor_response_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_response_id": { + "name": "vendor_response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "previous_status": { + "name": "previous_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "new_status": { + "name": "new_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_by": { + "name": "action_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "action_at": { + "name": "action_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_response_history_vendor_response_id_vendor_attachment_responses_id_fk": { + "name": "vendor_response_history_vendor_response_id_vendor_attachment_responses_id_fk", + "tableFrom": "vendor_response_history", + "tableTo": "vendor_attachment_responses", + "columnsFrom": [ + "vendor_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_history_action_by_users_id_fk": { + "name": "vendor_response_history_action_by_users_id_fk", + "tableFrom": "vendor_response_history", + "tableTo": "users", + "columnsFrom": [ + "action_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.offshore_hull_work_type": { + "name": "offshore_hull_work_type", + "schema": "public", + "values": [ + "HA", + "HE", + "HH", + "HM", + "NC" + ] + }, + "public.offshore_top_work_type": { + "name": "offshore_top_work_type", + "schema": "public", + "values": [ + "TM", + "TS", + "TE", + "TP" + ] + }, + "public.work_type": { + "name": "work_type", + "schema": "public", + "values": [ + "기장", + "전장", + "선실", + "배관", + "철의" + ] + }, + "public.user_domain": { + "name": "user_domain", + "schema": "public", + "values": [ + "evcp", + "partners" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": { + "public.contracts_detail_view": { + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contracts_detail_view_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "contract_name": { + "name": "contract_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "payment_terms": { + "name": "payment_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'KRW'" + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "partial_shipping_allowed": { + "name": "partial_shipping_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "partial_payment_allowed": { + "name": "partial_payment_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "remarks": { + "name": "remarks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"contracts\".\"id\", \"contracts\".\"contract_no\", \"contracts\".\"contract_name\", \"contracts\".\"status\", \"contracts\".\"start_date\", \"contracts\".\"end_date\", \"contracts\".\"project_id\", \"projects\".\"code\", \"projects\".\"name\", \"contracts\".\"vendor_id\", \"vendors\".\"vendor_name\", \"contracts\".\"payment_terms\", \"contracts\".\"delivery_terms\", \"contracts\".\"delivery_date\", \"contracts\".\"delivery_location\", \"contracts\".\"currency\", \"contracts\".\"total_amount\", \"contracts\".\"discount\", \"contracts\".\"tax\", \"contracts\".\"shipping_fee\", \"contracts\".\"net_total\", \"contracts\".\"partial_shipping_allowed\", \"contracts\".\"partial_payment_allowed\", \"contracts\".\"remarks\", \"contracts\".\"version\", \"contracts\".\"created_at\", \"contracts\".\"updated_at\", EXISTS (\n SELECT 1 \n FROM \"contract_envelopes\" \n WHERE \"contract_envelopes\".\"contract_id\" = \"contracts\".\"id\"\n ) as \"has_signature\", COALESCE((\n SELECT json_agg(\n json_build_object(\n 'id', ci.id,\n 'itemId', ci.item_id,\n 'description', ci.description,\n 'quantity', ci.quantity,\n 'unitPrice', ci.unit_price,\n 'taxRate', ci.tax_rate,\n 'taxAmount', ci.tax_amount,\n 'totalLineAmount', ci.total_line_amount,\n 'remark', ci.remark,\n 'createdAt', ci.created_at,\n 'updatedAt', ci.updated_at\n )\n )\n FROM \"contract_items\" AS ci\n WHERE ci.contract_id = \"contracts\".\"id\"\n ), '[]') as \"items\", COALESCE((\n SELECT json_agg(\n json_build_object(\n 'id', ce.id,\n 'envelopeId', ce.envelope_id,\n 'documentId', ce.document_id,\n 'envelopeStatus', ce.envelope_status,\n 'fileName', ce.file_name,\n 'filePath', ce.file_path,\n 'createdAt', ce.created_at,\n 'updatedAt', ce.updated_at,\n 'signers', (\n SELECT json_agg(\n json_build_object(\n 'id', cs.id,\n 'vendorContactId', cs.vendor_contact_id,\n 'signerType', cs.signer_type,\n 'signerEmail', cs.signer_email,\n 'signerName', cs.signer_name,\n 'signerPosition', cs.signer_position,\n 'signerStatus', cs.signer_status,\n 'signedAt', cs.signed_at\n )\n )\n FROM \"contract_signers\" AS cs\n WHERE cs.envelope_id = ce.id\n )\n )\n )\n FROM \"contract_envelopes\" AS ce\n WHERE ce.contract_id = \"contracts\".\"id\"\n ), '[]') as \"envelopes\" from \"contracts\" left join \"projects\" on \"contracts\".\"project_id\" = \"projects\".\"id\" left join \"vendors\" on \"contracts\".\"vendor_id\" = \"vendors\".\"id\"", + "name": "contracts_detail_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.poa_detail_view": { + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "poa_detail_view_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "change_reason": { + "name": "change_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approval_status": { + "name": "approval_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'PENDING'" + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"poa\".\"id\", \"poa\".\"contract_no\", \"contracts\".\"project_id\", \"contracts\".\"vendor_id\", \"poa\".\"change_reason\", \"poa\".\"approval_status\", \"contracts\".\"contract_name\" as \"original_contract_name\", \"contracts\".\"status\" as \"original_status\", \"contracts\".\"start_date\" as \"original_start_date\", \"contracts\".\"end_date\" as \"original_end_date\", \"poa\".\"delivery_terms\", \"poa\".\"delivery_date\", \"poa\".\"delivery_location\", \"poa\".\"currency\", \"poa\".\"total_amount\", \"poa\".\"discount\", \"poa\".\"tax\", \"poa\".\"shipping_fee\", \"poa\".\"net_total\", \"poa\".\"created_at\", \"poa\".\"updated_at\", EXISTS (\n SELECT 1 \n FROM \"contract_envelopes\" \n WHERE \"contract_envelopes\".\"contract_id\" = \"poa\".\"id\"\n ) as \"has_signature\" from \"poa\" left join \"contracts\" on \"poa\".\"contract_no\" = \"contracts\".\"contract_no\"", + "name": "poa_detail_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.project_approved_vendors": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING_REVIEW'" + }, + "name_ko": { + "name": "name_ko", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "name_en": { + "name": "name_en", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'ship'" + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"vendors\".\"id\", \"vendors\".\"vendor_name\", \"vendors\".\"vendor_code\", \"vendors\".\"tax_id\", \"vendors\".\"email\", \"vendors\".\"phone\", \"vendors\".\"status\", \"vendor_types\".\"name_ko\", \"vendor_types\".\"name_en\", \"projects\".\"code\", \"projects\".\"name\", \"projects\".\"type\", \"vendor_pq_submissions\".\"submitted_at\", \"vendor_pq_submissions\".\"approved_at\" from \"vendors\" inner join \"vendor_pq_submissions\" on \"vendor_pq_submissions\".\"vendor_id\" = \"vendors\".\"id\" inner join \"projects\" on \"vendor_pq_submissions\".\"project_id\" = \"projects\".\"id\" left join \"vendor_types\" on \"vendors\".\"vendor_type_id\" = \"vendor_types\".\"id\" where \"vendor_pq_submissions\".\"status\" = 'APPROVED'", + "name": "project_approved_vendors", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_investigations_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pq_submission_id": { + "name": "pq_submission_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requester_id": { + "name": "requester_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "qm_manager_id": { + "name": "qm_manager_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "investigation_status": { + "name": "investigation_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'PLANNED'" + }, + "evaluation_type": { + "name": "evaluation_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_address": { + "name": "investigation_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "investigation_method": { + "name": "investigation_method", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "scheduled_start_at": { + "name": "scheduled_start_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scheduled_end_at": { + "name": "scheduled_end_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "forecasted_at": { + "name": "forecasted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "evaluation_score": { + "name": "evaluation_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluation_result": { + "name": "evaluation_result", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_notes": { + "name": "investigation_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"vendor_investigations\".\"id\", \"vendor_investigations\".\"vendor_id\", \"vendor_investigations\".\"pq_submission_id\", \"vendor_investigations\".\"requester_id\", \"vendor_investigations\".\"qm_manager_id\", \"vendor_investigations\".\"investigation_status\", \"vendor_investigations\".\"evaluation_type\", \"vendor_investigations\".\"investigation_address\", \"vendor_investigations\".\"investigation_method\", \"vendor_investigations\".\"scheduled_start_at\", \"vendor_investigations\".\"scheduled_end_at\", \"vendor_investigations\".\"forecasted_at\", \"vendor_investigations\".\"requested_at\", \"vendor_investigations\".\"confirmed_at\", \"vendor_investigations\".\"completed_at\", \"vendor_investigations\".\"evaluation_score\", \"vendor_investigations\".\"evaluation_result\", \"vendor_investigations\".\"investigation_notes\", \"vendor_investigations\".\"created_at\", \"vendor_investigations\".\"updated_at\", \"vendors\".\"vendor_name\", \"vendors\".\"vendor_code\", requester.name as \"requesterName\", requester.email as \"requesterEmail\", qm_manager.name as \"qmManagerName\", qm_manager.email as \"qmManagerEmail\", (\n CASE \n WHEN EXISTS (\n SELECT 1 FROM vendor_investigation_attachments via \n WHERE via.investigation_id = \"vendor_investigations\".\"id\"\n ) \n THEN true \n ELSE false \n END\n ) as \"hasAttachments\" from \"vendor_investigations\" left join \"vendors\" on \"vendor_investigations\".\"vendor_id\" = \"vendors\".\"id\" left join users AS requester on \"vendor_investigations\".\"requester_id\" = requester.id left join users AS qm_manager on \"vendor_investigations\".\"qm_manager_id\" = qm_manager.id", + "name": "vendor_investigations_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.cbe_view": { + "columns": {}, + "definition": "select \"cbe_evaluations\".\"id\" as \"cbe_id\", \"cbe_evaluations\".\"rfq_id\" as \"rfq_id\", \"cbe_evaluations\".\"vendor_id\" as \"vendor_id\", \"cbe_evaluations\".\"total_cost\" as \"total_cost\", \"cbe_evaluations\".\"currency\" as \"currency\", \"cbe_evaluations\".\"payment_terms\" as \"payment_terms\", \"cbe_evaluations\".\"incoterms\" as \"incoterms\", \"cbe_evaluations\".\"result\" as \"result\", \"cbe_evaluations\".\"notes\" as \"notes\", \"cbe_evaluations\".\"evaluated_by\" as \"evaluated_by\", \"cbe_evaluations\".\"evaluated_at\" as \"evaluated_at\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"rfq_description\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"users\".\"name\" as \"evaluator_name\", \"users\".\"email\" as \"evaluator_email\" from \"cbe_evaluations\" inner join \"rfqs\" on \"cbe_evaluations\".\"rfq_id\" = \"rfqs\".\"id\" inner join \"vendors\" on \"cbe_evaluations\".\"vendor_id\" = \"vendors\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"users\" on \"cbe_evaluations\".\"evaluated_by\" = \"users\".\"id\"", + "name": "cbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.rfqs_view": { + "columns": {}, + "definition": "select \"rfqs\".\"id\" as \"rfq_id\", \"rfqs\".\"status\" as \"status\", \"rfqs\".\"created_at\" as \"created_at\", \"rfqs\".\"updated_at\" as \"updated_at\", \"rfqs\".\"created_by\" as \"created_by\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"rfqs\".\"parent_rfq_id\" as \"parent_rfq_id\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"users\".\"email\" as \"user_email\", \"users\".\"name\" as \"user_name\", (\n SELECT COUNT(*) \n FROM \"rfq_items\" \n WHERE \"rfq_items\".\"rfq_id\" = \"rfqs\".\"id\"\n ) as \"item_count\", (\n SELECT COUNT(*) \n FROM \"rfq_attachments\" \n WHERE \"rfq_attachments\".\"rfq_id\" = \"rfqs\".\"id\"\n ) as \"attachment_count\" from \"rfqs\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"users\" on \"rfqs\".\"created_by\" = \"users\".\"id\"", + "name": "rfqs_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_cbe_view": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"email\" as \"email\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"vendor_status\", \"vendor_responses\".\"id\" as \"vendor_response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"response_status\" as \"rfq_vendor_status\", \"vendor_responses\".\"updated_at\" as \"rfq_vendor_updated\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"cbe_evaluations\".\"id\" as \"cbe_id\", \"cbe_evaluations\".\"result\" as \"cbe_result\", \"cbe_evaluations\".\"notes\" as \"cbe_note\", \"cbe_evaluations\".\"updated_at\" as \"cbe_updated\", \"cbe_evaluations\".\"total_cost\" as \"total_cost\", \"cbe_evaluations\".\"currency\" as \"currency\", \"cbe_evaluations\".\"payment_terms\" as \"payment_terms\", \"cbe_evaluations\".\"incoterms\" as \"incoterms\", \"cbe_evaluations\".\"delivery_schedule\" as \"delivery_schedule\" from \"vendors\" left join \"vendor_responses\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"cbe_evaluations\" on (\"cbe_evaluations\".\"vendor_id\" = \"vendors\".\"id\" and \"cbe_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\")", + "name": "vendor_cbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_response_cbe_view": { + "columns": {}, + "definition": "select \"vendor_responses\".\"id\" as \"response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"vendor_id\" as \"vendor_id\", \"vendor_responses\".\"response_status\" as \"response_status\", \"vendor_responses\".\"notes\" as \"response_notes\", \"vendor_responses\".\"responded_by\" as \"responded_by\", \"vendor_responses\".\"responded_at\" as \"responded_at\", \"vendor_responses\".\"updated_at\" as \"response_updated_at\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"rfq_description\", \"rfqs\".\"due_date\" as \"rfq_due_date\", \"rfqs\".\"status\" as \"rfq_status\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"status\" as \"vendor_status\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"vendor_commercial_responses\".\"id\" as \"commercial_response_id\", \"vendor_commercial_responses\".\"response_status\" as \"commercial_response_status\", \"vendor_commercial_responses\".\"total_price\" as \"total_price\", \"vendor_commercial_responses\".\"currency\" as \"currency\", \"vendor_commercial_responses\".\"payment_terms\" as \"payment_terms\", \"vendor_commercial_responses\".\"incoterms\" as \"incoterms\", \"vendor_commercial_responses\".\"delivery_period\" as \"delivery_period\", \"vendor_commercial_responses\".\"warranty_period\" as \"warranty_period\", \"vendor_commercial_responses\".\"validity_period\" as \"validity_period\", \"vendor_commercial_responses\".\"price_breakdown\" as \"price_breakdown\", \"vendor_commercial_responses\".\"commercial_notes\" as \"commercial_notes\", \"vendor_commercial_responses\".\"created_at\" as \"commercial_created_at\", \"vendor_commercial_responses\".\"updated_at\" as \"commercial_updated_at\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n ) as \"attachment_count\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"commercial_response_id\" = \"vendor_commercial_responses\".\"id\"\n ) as \"commercial_attachment_count\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n AND \"vendor_response_attachments\".\"attachment_type\" = 'TECHNICAL_SPEC'\n ) as \"technical_attachment_count\", (\n SELECT MAX(\"uploaded_at\") \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n ) as \"latest_attachment_date\" from \"vendor_responses\" inner join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" inner join \"vendors\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendor_commercial_responses\" on \"vendor_commercial_responses\".\"response_id\" = \"vendor_responses\".\"id\"", + "name": "vendor_response_cbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_responses_view": { + "columns": {}, + "definition": "select \"vendor_responses\".\"id\" as \"response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"vendor_id\" as \"vendor_id\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"rfq_description\", \"rfqs\".\"due_date\" as \"rfq_due_date\", \"rfqs\".\"status\" as \"rfq_status\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"created_at\" as \"rfq_created_at\", \"rfqs\".\"updated_at\" as \"rfq_updated_at\", \"rfqs\".\"created_by\" as \"rfq_created_by\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendor_responses\".\"response_status\" as \"response_status\", \"vendor_responses\".\"responded_at\" as \"responded_at\", CASE WHEN \"vendor_technical_responses\".\"id\" IS NOT NULL THEN TRUE ELSE FALSE END as \"has_technical_response\", \"vendor_technical_responses\".\"id\" as \"technical_response_id\", CASE WHEN \"vendor_commercial_responses\".\"id\" IS NOT NULL THEN TRUE ELSE FALSE END as \"has_commercial_response\", \"vendor_commercial_responses\".\"id\" as \"commercial_response_id\", \"vendor_commercial_responses\".\"total_price\" as \"total_price\", \"vendor_commercial_responses\".\"currency\" as \"currency\", \"rfq_evaluations\".\"id\" as \"tbe_id\", \"rfq_evaluations\".\"result\" as \"tbe_result\", \"cbe_evaluations\".\"id\" as \"cbe_id\", \"cbe_evaluations\".\"result\" as \"cbe_result\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n ) as \"attachment_count\" from \"vendor_responses\" inner join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" inner join \"vendors\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendor_technical_responses\" on \"vendor_technical_responses\".\"response_id\" = \"vendor_responses\".\"id\" left join \"vendor_commercial_responses\" on \"vendor_commercial_responses\".\"response_id\" = \"vendor_responses\".\"id\" left join \"rfq_evaluations\" on (\"rfq_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\" and \"rfq_evaluations\".\"vendor_id\" = \"vendor_responses\".\"vendor_id\" and \"rfq_evaluations\".\"eval_type\" = 'TBE') left join \"cbe_evaluations\" on (\"cbe_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\" and \"cbe_evaluations\".\"vendor_id\" = \"vendor_responses\".\"vendor_id\")", + "name": "vendor_responses_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_rfq_view": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"email\" as \"email\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"vendor_status\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"response_status\" as \"rfq_vendor_status\", \"vendor_responses\".\"updated_at\" as \"rfq_vendor_updated\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\" from \"vendors\" left join \"vendor_responses\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\"", + "name": "vendor_rfq_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_tbe_view": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"email\" as \"email\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"vendor_status\", \"vendor_responses\".\"id\" as \"vendor_response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"response_status\" as \"rfq_vendor_status\", \"vendor_responses\".\"updated_at\" as \"rfq_vendor_updated\", \"vendor_technical_responses\".\"id\" as \"technical_response_id\", \"vendor_technical_responses\".\"response_status\" as \"technical_response_status\", \"vendor_technical_responses\".\"summary\" as \"technical_summary\", \"vendor_technical_responses\".\"notes\" as \"technical_notes\", \"vendor_technical_responses\".\"updated_at\" as \"technical_updated\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"status\" as \"rfq_status\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"rfq_evaluations\".\"id\" as \"tbe_id\", \"rfq_evaluations\".\"result\" as \"tbe_result\", \"rfq_evaluations\".\"notes\" as \"tbe_note\", \"rfq_evaluations\".\"updated_at\" as \"tbe_updated\" from \"vendors\" left join \"vendor_responses\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendor_technical_responses\" on \"vendor_technical_responses\".\"response_id\" = \"vendor_responses\".\"id\" left join \"rfq_evaluations\" on (\"rfq_evaluations\".\"vendor_id\" = \"vendors\".\"id\" and \"rfq_evaluations\".\"eval_type\" = 'TBE' and \"rfq_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\")", + "name": "vendor_tbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.role_view": { + "columns": {}, + "definition": "select \"roles\".\"id\" as \"id\", \"roles\".\"name\" as \"name\", \"roles\".\"description\" as \"description\", \"roles\".\"domain\" as \"domain\", \"roles\".\"created_at\" as \"created_at\", \"vendors\".\"id\" as \"company_id\", \"vendors\".\"vendor_name\" as \"company_name\", COUNT(\"users\".\"id\") as \"user_count\" from \"roles\" left join \"user_roles\" on \"user_roles\".\"role_id\" = \"roles\".\"id\" left join \"users\" on \"users\".\"id\" = \"user_roles\".\"user_id\" left join \"vendors\" on \"roles\".\"company_id\" = \"vendors\".\"id\" group by \"roles\".\"id\", \"vendors\".\"id\"", + "name": "role_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.user_view": { + "columns": {}, + "definition": "select \"users\".\"id\" as \"user_id\", \"users\".\"name\" as \"user_name\", \"users\".\"email\" as \"user_email\", \"users\".\"domain\" as \"user_domain\", \"users\".\"image_url\" as \"user_image\", \"vendors\".\"id\" as \"company_id\", \"vendors\".\"vendor_name\" as \"company_name\", \n array_agg(\"roles\".\"name\")\n as \"roles\", \"users\".\"created_at\" as \"created_at\" from \"users\" left join \"vendors\" on \"users\".\"company_id\" = \"vendors\".\"id\" left join \"user_roles\" on \"users\".\"id\" = \"user_roles\".\"user_id\" left join \"roles\" on \"user_roles\".\"role_id\" = \"roles\".\"id\" group by \"users\".\"id\", \"vendors\".\"id\"", + "name": "user_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.form_lists_view": { + "columns": {}, + "definition": "select \"tag_type_class_form_mappings\".\"id\" as \"id\", \"tag_type_class_form_mappings\".\"project_id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"tag_type_class_form_mappings\".\"tag_type_label\" as \"tag_type_label\", \"tag_type_class_form_mappings\".\"class_label\" as \"class_label\", \"tag_type_class_form_mappings\".\"form_code\" as \"form_code\", \"tag_type_class_form_mappings\".\"form_name\" as \"form_name\", \"tag_type_class_form_mappings\".\"ep\" as \"ep\", \"tag_type_class_form_mappings\".\"remark\" as \"remark\", \"tag_type_class_form_mappings\".\"created_at\" as \"created_at\", \"tag_type_class_form_mappings\".\"updated_at\" as \"updated_at\" from \"tag_type_class_form_mappings\" inner join \"projects\" on \"tag_type_class_form_mappings\".\"project_id\" = \"projects\".\"id\"", + "name": "form_lists_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.view_tag_subfields": { + "columns": { + "tag_type_code": { + "name": "tag_type_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "attributes_id": { + "name": "attributes_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "attributes_description": { + "name": "attributes_description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expression": { + "name": "expression", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delimiter": { + "name": "delimiter", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "definition": "select \"tag_subfields\".\"id\" as \"id\", \"tag_subfields\".\"tag_type_code\", \"tag_types\".\"description\", \"tag_subfields\".\"attributes_id\", \"tag_subfields\".\"attributes_description\", \"tag_subfields\".\"expression\", \"tag_subfields\".\"delimiter\", \"tag_subfields\".\"sort_order\", \"tag_subfields\".\"created_at\", \"tag_subfields\".\"updated_at\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\", \"projects\".\"name\" from \"tag_subfields\" inner join \"tag_types\" on (\"tag_subfields\".\"tag_type_code\" = \"tag_types\".\"code\" and \"tag_subfields\".\"project_id\" = \"tag_types\".\"project_id\") inner join \"projects\" on \"tag_subfields\".\"project_id\" = \"projects\".\"id\"", + "name": "view_tag_subfields", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.document_stages_view": { + "columns": { + "document_id": { + "name": "document_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stage_count": { + "name": "stage_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stage_list": { + "name": "stage_list", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "definition": "\n SELECT\n d.id AS document_id,\n d.doc_number,\n d.title,\n d.status,\n d.issued_date,\n d.contract_id,\n (SELECT COUNT(*) FROM issue_stages WHERE document_id = d.id) AS stage_count,\n COALESCE( \n (SELECT json_agg(i.stage_name) FROM issue_stages i WHERE i.document_id = d.id), \n '[]'\n ) AS stage_list,\n d.created_at,\n d.updated_at\n FROM documents d\n", + "name": "document_stages_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.enhanced_documents_view": { + "columns": { + "document_id": { + "name": "document_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "drawing_kind": { + "name": "drawing_kind", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_doc_number": { + "name": "vendor_doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "pic": { + "name": "pic", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_code": { + "name": "project_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "c_gbn": { + "name": "c_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "d_gbn": { + "name": "d_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "degree_gbn": { + "name": "degree_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "dept_gbn": { + "name": "dept_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "j_gbn": { + "name": "j_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "s_gbn": { + "name": "s_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "current_stage_id": { + "name": "current_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "current_stage_name": { + "name": "current_stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "current_stage_status": { + "name": "current_stage_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "current_stage_order": { + "name": "current_stage_order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "current_stage_plan_date": { + "name": "current_stage_plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "current_stage_actual_date": { + "name": "current_stage_actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "current_stage_assignee_name": { + "name": "current_stage_assignee_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "current_stage_priority": { + "name": "current_stage_priority", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "days_until_due": { + "name": "days_until_due", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "is_overdue": { + "name": "is_overdue", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "days_difference": { + "name": "days_difference", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "total_stages": { + "name": "total_stages", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "completed_stages": { + "name": "completed_stages", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "progress_percentage": { + "name": "progress_percentage", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_revision_id": { + "name": "latest_revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_revision": { + "name": "latest_revision", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_status": { + "name": "latest_revision_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_uploader_name": { + "name": "latest_revision_uploader_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "latest_submitted_date": { + "name": "latest_submitted_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "all_stages": { + "name": "all_stages", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "attachment_count": { + "name": "attachment_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "definition": "\n WITH document_stats AS (\n SELECT \n d.id as document_id,\n COUNT(ist.id) as total_stages,\n COUNT(CASE WHEN ist.stage_status IN ('COMPLETED', 'APPROVED') THEN 1 END) as completed_stages,\n CASE \n WHEN COUNT(ist.id) > 0 \n THEN ROUND((COUNT(CASE WHEN ist.stage_status IN ('COMPLETED', 'APPROVED') THEN 1 END) * 100.0) / COUNT(ist.id))\n ELSE 0 \n END as progress_percentage\n FROM documents d\n LEFT JOIN issue_stages ist ON d.id = ist.document_id\n GROUP BY d.id\n ),\n current_stage_info AS (\n SELECT DISTINCT ON (document_id)\n document_id,\n id as current_stage_id,\n stage_name as current_stage_name,\n stage_status as current_stage_status,\n stage_order as current_stage_order,\n plan_date as current_stage_plan_date,\n actual_date as current_stage_actual_date,\n assignee_name as current_stage_assignee_name,\n priority as current_stage_priority,\n CASE \n WHEN actual_date IS NULL AND plan_date IS NOT NULL \n THEN plan_date - CURRENT_DATE\n ELSE NULL \n END as days_until_due,\n CASE \n WHEN actual_date IS NULL AND plan_date < CURRENT_DATE \n THEN true\n WHEN actual_date IS NOT NULL AND actual_date > plan_date \n THEN true\n ELSE false \n END as is_overdue,\n CASE \n WHEN actual_date IS NOT NULL AND plan_date IS NOT NULL \n THEN actual_date - plan_date\n ELSE NULL \n END as days_difference\n FROM issue_stages\n WHERE stage_status NOT IN ('COMPLETED', 'APPROVED')\n ORDER BY document_id, stage_order ASC, priority DESC\n ),\n latest_revision_info AS (\n SELECT DISTINCT ON (ist.document_id)\n ist.document_id,\n r.id as latest_revision_id,\n r.revision as latest_revision,\n r.revision_status as latest_revision_status,\n r.uploader_name as latest_revision_uploader_name,\n r.submitted_date as latest_submitted_date\n FROM revisions r\n JOIN issue_stages ist ON r.issue_stage_id = ist.id\n ORDER BY ist.document_id, r.created_at DESC\n ),\n -- 리비전별 첨부파일 집계\n revision_attachments AS (\n SELECT \n r.id as revision_id,\n COALESCE(\n json_agg(\n json_build_object(\n 'id', da.id,\n 'revisionId', da.revision_id,\n 'fileName', da.file_name,\n 'filePath', da.file_path,\n 'fileSize', da.file_size,\n 'fileType', da.file_type,\n 'createdAt', da.created_at,\n 'updatedAt', da.updated_at\n ) ORDER BY da.created_at\n ) FILTER (WHERE da.id IS NOT NULL),\n '[]'::json\n ) as attachments\n FROM revisions r\n LEFT JOIN document_attachments da ON r.id = da.revision_id\n GROUP BY r.id\n ),\n -- 스테이지별 리비전 집계 (첨부파일 포함)\n stage_revisions AS (\n SELECT \n ist.id as stage_id,\n COALESCE(\n json_agg(\n json_build_object(\n 'id', r.id,\n 'issueStageId', r.issue_stage_id,\n 'revision', r.revision,\n 'uploaderType', r.uploader_type,\n 'uploaderId', r.uploader_id,\n 'uploaderName', r.uploader_name,\n 'comment', r.comment,\n 'usage', r.usage,\n 'revisionStatus', r.revision_status,\n 'submittedDate', r.submitted_date,\n 'uploadedAt', r.uploaded_at,\n 'approvedDate', r.approved_date,\n 'reviewStartDate', r.review_start_date,\n 'rejectedDate', r.rejected_date,\n 'reviewerId', r.reviewer_id,\n 'reviewerName', r.reviewer_name,\n 'reviewComments', r.review_comments,\n 'createdAt', r.created_at,\n 'updatedAt', r.updated_at,\n 'attachments', ra.attachments\n ) ORDER BY r.created_at\n ) FILTER (WHERE r.id IS NOT NULL),\n '[]'::json\n ) as revisions\n FROM issue_stages ist\n LEFT JOIN revisions r ON ist.id = r.issue_stage_id\n LEFT JOIN revision_attachments ra ON r.id = ra.revision_id\n GROUP BY ist.id\n ),\n -- 문서별 스테이지 집계 (리비전 포함)\n stage_aggregation AS (\n SELECT \n ist.document_id,\n json_agg(\n json_build_object(\n 'id', ist.id,\n 'stageName', ist.stage_name,\n 'stageStatus', ist.stage_status,\n 'stageOrder', ist.stage_order,\n 'planDate', ist.plan_date,\n 'actualDate', ist.actual_date,\n 'assigneeName', ist.assignee_name,\n 'priority', ist.priority,\n 'revisions', sr.revisions\n ) ORDER BY ist.stage_order\n ) as all_stages\n FROM issue_stages ist\n LEFT JOIN stage_revisions sr ON ist.id = sr.stage_id\n GROUP BY ist.document_id\n ),\n attachment_counts AS (\n SELECT \n ist.document_id,\n COUNT(da.id) as attachment_count\n FROM issue_stages ist\n LEFT JOIN revisions r ON ist.id = r.issue_stage_id\n LEFT JOIN document_attachments da ON r.id = da.revision_id\n GROUP BY ist.document_id\n )\n \n SELECT \n d.id as document_id,\n d.doc_number,\n d.drawing_kind,\n d.vendor_doc_number, -- ✅ 벤더 문서 번호 추가\n d.title,\n d.pic,\n d.status,\n d.issued_date,\n d.contract_id,\n\n d.c_gbn,\n d.d_gbn,\n d.degree_gbn,\n d.dept_gbn,\n d.s_gbn,\n\n\n \n -- ✅ 프로젝트 및 벤더 정보 추가\n p.code as project_code,\n v.vendor_name as vendor_name,\n v.vendor_code as vendor_code,\n \n -- 현재 스테이지 정보\n csi.current_stage_id,\n csi.current_stage_name,\n csi.current_stage_status,\n csi.current_stage_order,\n csi.current_stage_plan_date,\n csi.current_stage_actual_date,\n csi.current_stage_assignee_name,\n csi.current_stage_priority,\n \n -- 계산 필드\n csi.days_until_due,\n csi.is_overdue,\n csi.days_difference,\n \n -- 진행률 정보\n ds.total_stages,\n ds.completed_stages,\n ds.progress_percentage,\n \n -- 최신 리비전 정보\n lri.latest_revision_id,\n lri.latest_revision,\n lri.latest_revision_status,\n lri.latest_revision_uploader_name,\n lri.latest_submitted_date,\n \n -- 전체 스테이지 (리비전 및 첨부파일 포함)\n COALESCE(sa.all_stages, '[]'::json) as all_stages,\n \n -- 기타\n COALESCE(ac.attachment_count, 0) as attachment_count,\n d.created_at,\n d.updated_at\n \n FROM documents d\n -- ✅ contracts, projects, vendors 테이블 JOIN 추가\n LEFT JOIN contracts c ON d.contract_id = c.id\n LEFT JOIN projects p ON c.project_id = p.id\n LEFT JOIN vendors v ON c.vendor_id = v.id\n \n LEFT JOIN document_stats ds ON d.id = ds.document_id\n LEFT JOIN current_stage_info csi ON d.id = csi.document_id\n LEFT JOIN latest_revision_info lri ON d.id = lri.document_id\n LEFT JOIN stage_aggregation sa ON d.id = sa.document_id\n LEFT JOIN attachment_counts ac ON d.id = ac.document_id\n \n ORDER BY d.created_at DESC\n", + "name": "enhanced_documents_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.sync_status_view": { + "columns": { + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_system": { + "name": "target_system", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "total_changes": { + "name": "total_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pending_changes": { + "name": "pending_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "synced_changes": { + "name": "synced_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "failed_changes": { + "name": "failed_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "next_sync_at": { + "name": "next_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "sync_enabled": { + "name": "sync_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n WITH change_stats AS (\n SELECT \n cl.contract_id,\n sc.target_system,\n COUNT(*) as total_changes,\n COUNT(CASE WHEN cl.is_synced = false AND cl.sync_attempts < sc.retry_max_attempts THEN 1 END) as pending_changes,\n COUNT(CASE WHEN cl.is_synced = true THEN 1 END) as synced_changes,\n COUNT(CASE WHEN cl.sync_attempts >= sc.retry_max_attempts AND cl.is_synced = false THEN 1 END) as failed_changes,\n MAX(cl.synced_at) as last_sync_at\n FROM change_logs cl\n CROSS JOIN sync_configs sc \n WHERE cl.contract_id = sc.contract_id\n AND (cl.target_systems IS NULL OR cl.target_systems @> to_jsonb(sc.target_system))\n GROUP BY cl.contract_id, sc.target_system\n )\n SELECT \n cs.contract_id,\n cs.target_system,\n COALESCE(cs.total_changes, 0) as total_changes,\n COALESCE(cs.pending_changes, 0) as pending_changes,\n COALESCE(cs.synced_changes, 0) as synced_changes,\n COALESCE(cs.failed_changes, 0) as failed_changes,\n cs.last_sync_at,\n CASE \n WHEN sc.sync_enabled = true AND sc.last_successful_sync IS NOT NULL \n THEN sc.last_successful_sync + (sc.sync_interval_minutes || ' minutes')::interval\n ELSE NULL\n END as next_sync_at,\n sc.sync_enabled\n FROM sync_configs sc\n LEFT JOIN change_stats cs ON sc.contract_id = cs.contract_id AND sc.target_system = cs.target_system\n", + "name": "sync_status_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_documents_view": { + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "pic": { + "name": "pic", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "latest_stage_id": { + "name": "latest_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_stage_name": { + "name": "latest_stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "latest_stage_plan_date": { + "name": "latest_stage_plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "latest_stage_actual_date": { + "name": "latest_stage_actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "latest_revision_id": { + "name": "latest_revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_revision": { + "name": "latest_revision", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_uploader_type": { + "name": "latest_revision_uploader_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_uploader_name": { + "name": "latest_revision_uploader_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "attachment_count": { + "name": "attachment_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "definition": "\n SELECT \n d.id, \n d.doc_number,\n d.title,\n d.pic,\n d.status,\n d.issued_date,\n d.contract_id,\n \n (SELECT id FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_id,\n (SELECT stage_name FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_name,\n (SELECT plan_date FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_plan_date,\n (SELECT actual_date FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_actual_date,\n \n (SELECT r.id FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision_id,\n (SELECT r.revision FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision,\n (SELECT r.uploader_type FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision_uploader_type,\n (SELECT r.uploader_name FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision_uploader_name,\n \n (SELECT COUNT(*) FROM document_attachments a JOIN revisions r ON a.revision_id = r.id JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id) AS attachment_count,\n \n d.created_at,\n d.updated_at\n FROM documents d\n JOIN contracts c ON d.contract_id = c.id\n ", + "name": "vendor_documents_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_candidates_with_vendor_info": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_name": { + "name": "company_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_email": { + "name": "contact_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "contact_phone": { + "name": "contact_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'COLLECTED'" + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"vendor_candidates\".\"id\", \"vendor_candidates\".\"company_name\", \"vendor_candidates\".\"contact_email\", \"vendor_candidates\".\"contact_phone\", \"vendor_candidates\".\"tax_id\", \"vendor_candidates\".\"address\", \"vendor_candidates\".\"country\", \"vendor_candidates\".\"source\", \"vendor_candidates\".\"status\", \"vendor_candidates\".\"items\", \"vendor_candidates\".\"remark\", \"vendor_candidates\".\"created_at\", \"vendor_candidates\".\"updated_at\", \"vendors\".\"vendor_name\", \"vendors\".\"vendor_code\", \"vendors\".\"created_at\" as \"vendor_created_at\", (\n SELECT l2.\"created_at\"\n FROM \"vendor_candidate_logs\" l2\n WHERE l2.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l2.\"action\" = 'status_change'\n ORDER BY l2.\"created_at\" DESC\n LIMIT 1\n ) as \"last_status_change_at\", (\n SELECT u.\"name\"\n FROM \"users\" u\n JOIN \"vendor_candidate_logs\" l3\n ON l3.\"user_id\" = u.\"id\"\n WHERE l3.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l3.\"action\" = 'status_change'\n ORDER BY l3.\"created_at\" DESC\n LIMIT 1\n ) as \"last_status_change_by\", (\n SELECT l4.\"created_at\"\n FROM \"vendor_candidate_logs\" l4\n WHERE l4.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l4.\"action\" = 'invite_sent'\n ORDER BY l4.\"created_at\" DESC\n LIMIT 1\n ) as \"last_invitation_at\", (\n SELECT u2.\"name\"\n FROM \"users\" u2\n JOIN \"vendor_candidate_logs\" l5\n ON l5.\"user_id\" = u2.\"id\"\n WHERE l5.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l5.\"action\" = 'invite_sent'\n ORDER BY l5.\"created_at\" DESC\n LIMIT 1\n ) as \"last_invitation_by\" from \"vendor_candidates\" left join \"vendors\" on \"vendor_candidates\".\"vendor_id\" = \"vendors\".\"id\"", + "name": "vendor_candidates_with_vendor_info", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_detail_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "business_size": { + "name": "business_size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "website": { + "name": "website", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING_REVIEW'" + }, + "representative_name": { + "name": "representative_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_birth": { + "name": "representative_birth", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "representative_email": { + "name": "representative_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_phone": { + "name": "representative_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "corporate_registration_number": { + "name": "corporate_registration_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "credit_agency": { + "name": "credit_agency", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "credit_rating": { + "name": "credit_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "cash_flow_rating": { + "name": "cash_flow_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"id\", \"vendor_name\", \"vendor_code\", \"tax_id\", \"address\", \"business_size\", \"country\", \"phone\", \"email\", \"website\", \"status\", \"representative_name\", \"representative_birth\", \"representative_email\", \"representative_phone\", \"corporate_registration_number\", \"credit_agency\", \"credit_rating\", \"cash_flow_rating\", \"created_at\", \"updated_at\", \n (SELECT COALESCE(\n json_agg(\n json_build_object(\n 'id', c.id,\n 'contactName', c.contact_name,\n 'contactPosition', c.contact_position,\n 'contactEmail', c.contact_email,\n 'contactPhone', c.contact_phone,\n 'isPrimary', c.is_primary\n )\n ),\n '[]'::json\n )\n FROM vendor_contacts c\n WHERE c.vendor_id = vendors.id)\n as \"contacts\", \n (SELECT COALESCE(\n json_agg(\n json_build_object(\n 'id', a.id,\n 'fileName', a.file_name,\n 'filePath', a.file_path,\n 'attachmentType', a.attachment_type,\n 'createdAt', a.created_at\n )\n ORDER BY a.attachment_type, a.created_at DESC\n ),\n '[]'::json\n )\n FROM vendor_attachments a\n WHERE a.vendor_id = vendors.id)\n as \"attachments\", \n (SELECT COUNT(*)\n FROM vendor_attachments a\n WHERE a.vendor_id = vendors.id)\n as \"attachment_count\", \n (SELECT COUNT(*) \n FROM vendor_contacts c\n WHERE c.vendor_id = vendors.id)\n as \"contact_count\" from \"vendors\"", + "name": "vendor_detail_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_items_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"vendor_possible_items\".\"id\", \"vendor_possible_items\".\"vendor_id\", \"items\".\"item_name\", \"items\".\"item_code\", \"items\".\"description\", \"vendor_possible_items\".\"created_at\", \"vendor_possible_items\".\"updated_at\" from \"vendor_possible_items\" left join \"items\" on \"vendor_possible_items\".\"item_code\" = \"items\".\"item_code\"", + "name": "vendor_items_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_materials_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "unit_of_measure": { + "name": "unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "steel_type": { + "name": "steel_type", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "grade_material": { + "name": "grade_material", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"vendor_possible_materials\".\"id\", \"vendor_possible_materials\".\"vendor_id\", \"materials\".\"item_name\", \"materials\".\"item_code\", \"materials\".\"description\", \"materials\".\"unit_of_measure\", \"materials\".\"steel_type\", \"materials\".\"grade_material\", \"vendor_possible_materials\".\"created_at\", \"vendor_possible_materials\".\"updated_at\" from \"vendor_possible_materials\" left join \"materials\" on \"vendor_possible_materials\".\"item_code\" = \"materials\".\"item_code\"", + "name": "vendor_materials_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendors_with_types": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"tax_id\" as \"tax_id\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"phone\" as \"phone\", \"vendors\".\"email\" as \"email\", \"vendors\".\"business_size\" as \"business_size\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"status\", \"vendors\".\"vendor_type_id\" as \"vendor_type_id\", \"vendors\".\"representative_name\" as \"representative_name\", \"vendors\".\"representative_birth\" as \"representative_birth\", \"vendors\".\"representative_email\" as \"representative_email\", \"vendors\".\"representative_phone\" as \"representative_phone\", \"vendors\".\"corporate_registration_number\" as \"corporate_registration_number\", \"vendors\".\"items\" as \"items\", \"vendors\".\"credit_agency\" as \"credit_agency\", \"vendors\".\"credit_rating\" as \"credit_rating\", \"vendors\".\"cash_flow_rating\" as \"cash_flow_rating\", \"vendors\".\"created_at\" as \"created_at\", \"vendors\".\"updated_at\" as \"updated_at\", \"vendor_types\".\"name_ko\" as \"vendor_type_name\", \"vendor_types\".\"name_en\" as \"vendor_type_name_en\", \"vendor_types\".\"code\" as \"vendor_type_code\", \n CASE\n WHEN \"vendors\".\"status\" = 'ACTIVE' THEN '정규업체'\n WHEN \"vendors\".\"status\" IN ('INACTIVE', 'BLACKLISTED', 'REJECTED') THEN ''\n ELSE '잠재업체'\n END\n as \"vendor_category\" from \"vendors\" left join \"vendor_types\" on \"vendors\".\"vendor_type_id\" = \"vendor_types\".\"id\"", + "name": "vendors_with_types", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.basic_contract_view": { + "columns": {}, + "definition": "select \"basic_contract\".\"id\" as \"id\", \"basic_contract\".\"template_id\" as \"template_id\", \"basic_contract\".\"vendor_id\" as \"vendor_id\", \"basic_contract\".\"requested_by\" as \"requested_by\", \"basic_contract\".\"status\" as \"basic_contract_status\", \"basic_contract\".\"created_at\" as \"created_at\", \"basic_contract\".\"updated_at\" as \"updated_at\", \"basic_contract\".\"updated_at\" as \"completed_at\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"email\" as \"vendor_email\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"users\".\"name\" as \"user_name\", \"basic_contract_templates\".\"template_name\" as \"template_name\", \"basic_contract_templates\".\"validity_period\" as \"validityPeriod\", \"basic_contract_templates\".\"file_path\" as \"file_path\", \"basic_contract_templates\".\"file_name\" as \"file_name\", \"basic_contract\".\"file_path\" as \"signed_file_path\" from \"basic_contract\" left join \"vendors\" on \"basic_contract\".\"vendor_id\" = \"vendors\".\"id\" left join \"users\" on \"basic_contract\".\"requested_by\" = \"users\".\"id\" left join \"basic_contract_templates\" on \"basic_contract\".\"template_id\" = \"basic_contract_templates\".\"id\"", + "name": "basic_contract_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.pr_items_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_item": { + "name": "rfq_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_item": { + "name": "pr_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_no": { + "name": "pr_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "material_code": { + "name": "material_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_category": { + "name": "material_category", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "acc": { + "name": "acc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_description": { + "name": "material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "size": { + "name": "size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "uom": { + "name": "uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "gross_weight": { + "name": "gross_weight", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "gw_uom": { + "name": "gw_uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "spec_no": { + "name": "spec_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "spec_url": { + "name": "spec_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "tracking_no": { + "name": "tracking_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "major_yn": { + "name": "major_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "project_def": { + "name": "project_def", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_sc": { + "name": "project_sc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_kl": { + "name": "project_kl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_lc": { + "name": "project_lc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_dl": { + "name": "project_dl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"pr_items\".\"id\", \"pr_items\".\"procurement_rfqs_id\", \"pr_items\".\"rfq_item\", \"pr_items\".\"pr_item\", \"pr_items\".\"pr_no\", \"pr_items\".\"material_code\", \"pr_items\".\"material_category\", \"pr_items\".\"acc\", \"pr_items\".\"material_description\", \"pr_items\".\"size\", \"pr_items\".\"delivery_date\", \"pr_items\".\"quantity\", \"pr_items\".\"uom\", \"pr_items\".\"gross_weight\", \"pr_items\".\"gw_uom\", \"pr_items\".\"spec_no\", \"pr_items\".\"spec_url\", \"pr_items\".\"tracking_no\", \"pr_items\".\"major_yn\", \"pr_items\".\"project_def\", \"pr_items\".\"project_sc\", \"pr_items\".\"project_kl\", \"pr_items\".\"project_lc\", \"pr_items\".\"project_dl\", \"pr_items\".\"remark\", \"procurement_rfqs\".\"rfq_code\", \"procurement_rfqs\".\"item_code\", \"procurement_rfqs\".\"item_name\" from \"pr_items\" left join \"procurement_rfqs\" on \"pr_items\".\"procurement_rfqs_id\" = \"procurement_rfqs\".\"id\"", + "name": "pr_items_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.procurement_rfq_details_view": { + "columns": {}, + "definition": "select \"rfq_details\".\"id\" as \"detail_id\", \"rfqs\".\"id\" as \"rfq_id\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"rfqs\".\"item_code\" as \"item_code\", \"rfqs\".\"item_name\" as \"item_name\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"country\" as \"vendor_country\", \"rfq_details\".\"currency\" as \"currency\", \"payment_terms\".\"code\" as \"payment_terms_code\", \"payment_terms\".\"description\" as \"payment_terms_description\", \"incoterms\".\"code\" as \"incoterms_code\", \"incoterms\".\"description\" as \"incoterms_description\", \"rfq_details\".\"incoterms_detail\" as \"incoterms_detail\", \"rfq_details\".\"delivery_date\" as \"delivery_date\", \"rfq_details\".\"tax_code\" as \"tax_code\", \"rfq_details\".\"place_of_shipping\" as \"place_of_shipping\", \"rfq_details\".\"place_of_destination\" as \"place_of_destination\", \"rfq_details\".\"material_price_related_yn\" as \"material_price_related_yn\", \"updated_by_user\".\"name\" as \"updated_by_user_name\", \"rfq_details\".\"updated_at\" as \"updated_at\", (\n SELECT COUNT(*) \n FROM pr_items \n WHERE procurement_rfqs_id = \"rfqs\".\"id\"\n ) as \"pr_items_count\", (\n SELECT COUNT(*) \n FROM pr_items \n WHERE procurement_rfqs_id = \"rfqs\".\"id\" \n AND major_yn = true\n ) as \"major_items_count\", (\n SELECT COUNT(*) \n FROM procurement_rfq_comments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"comment_count\", (\n SELECT created_at \n FROM procurement_rfq_comments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY created_at DESC LIMIT 1\n ) as \"last_comment_date\", (\n SELECT created_at \n FROM procurement_rfq_comments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\" AND is_vendor_comment = true\n ORDER BY created_at DESC LIMIT 1\n ) as \"last_vendor_comment_date\", (\n SELECT COUNT(*) \n FROM procurement_rfq_attachments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"attachment_count\", (\n SELECT COUNT(*) > 0\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"has_quotation\", (\n SELECT status\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY created_at DESC LIMIT 1\n ) as \"quotation_status\", (\n SELECT total_price\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY created_at DESC LIMIT 1\n ) as \"quotation_total_price\", (\n SELECT quotation_version\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY quotation_version DESC LIMIT 1\n ) as \"quotation_version\", (\n SELECT COUNT(DISTINCT quotation_version)\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"quotation_version_count\", (\n SELECT created_at\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY quotation_version DESC LIMIT 1\n ) as \"last_quotation_date\" from \"procurement_rfq_details\" \"rfq_details\" left join \"procurement_rfqs\" \"rfqs\" on \"rfq_details\".\"procurement_rfqs_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendors\" on \"rfq_details\".\"vendors_id\" = \"vendors\".\"id\" left join \"payment_terms\" on \"rfq_details\".\"payment_terms_code\" = \"payment_terms\".\"code\" left join \"incoterms\" on \"rfq_details\".\"incoterms_code\" = \"incoterms\".\"code\" left join \"users\" \"updated_by_user\" on \"rfq_details\".\"updated_by\" = \"updated_by_user\".\"id\"", + "name": "procurement_rfq_details_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.procurement_rfqs_view": { + "columns": {}, + "definition": "select \"procurement_rfqs\".\"id\" as \"id\", \"procurement_rfqs\".\"rfq_code\" as \"rfq_code\", \"procurement_rfqs\".\"series\" as \"series\", \"procurement_rfqs\".\"rfq_sealed_yn\" as \"rfq_sealed_yn\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"procurement_rfqs\".\"item_code\" as \"item_code\", \"procurement_rfqs\".\"item_name\" as \"item_name\", \"procurement_rfqs\".\"status\" as \"status\", \"procurement_rfqs\".\"pic_code\" as \"pic_code\", \"procurement_rfqs\".\"rfq_send_date\" as \"rfq_send_date\", \"procurement_rfqs\".\"due_date\" as \"due_date\", (\n SELECT MIN(submitted_at)\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"procurement_rfqs\".\"id\"\n AND submitted_at IS NOT NULL\n ) as \"earliest_quotation_submitted_at\", \"created_by_user\".\"name\" as \"created_by_user_name\", \"sent_by_user\".\"name\" as \"sent_by_user_name\", \"procurement_rfqs\".\"updated_at\" as \"updated_at\", \"updated_by_user\".\"name\" as \"updated_by_user_name\", \"procurement_rfqs\".\"remark\" as \"remark\", (\n SELECT material_code \n FROM pr_items \n WHERE procurement_rfqs_id = \"procurement_rfqs\".\"id\"\n AND major_yn = true\n LIMIT 1\n ) as \"major_item_material_code\", (\n SELECT pr_no \n FROM pr_items \n WHERE procurement_rfqs_id = \"procurement_rfqs\".\"id\"\n AND major_yn = true\n LIMIT 1\n ) as \"po_no\", (\n SELECT COUNT(*) \n FROM pr_items \n WHERE procurement_rfqs_id = \"procurement_rfqs\".\"id\"\n ) as \"pr_items_count\" from \"procurement_rfqs\" left join \"projects\" on \"procurement_rfqs\".\"project_id\" = \"projects\".\"id\" left join \"users\" \"created_by_user\" on \"procurement_rfqs\".\"created_by\" = \"created_by_user\".\"id\" left join \"users\" \"updated_by_user\" on \"procurement_rfqs\".\"updated_by\" = \"updated_by_user\".\"id\" left join \"users\" \"sent_by_user\" on \"procurement_rfqs\".\"sent_by\" = \"sent_by_user\".\"id\"", + "name": "procurement_rfqs_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.attachments_with_latest_revision": { + "columns": { + "attachment_id": { + "name": "attachment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "serial_no": { + "name": "serial_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "current_revision": { + "name": "current_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "revision_id": { + "name": "revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "revision_comment": { + "name": "revision_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by_name": { + "name": "created_by_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n a.id as attachment_id,\n a.attachment_type,\n a.serial_no,\n a.rfq_id,\n a.description,\n a.current_revision,\n \n r.id as revision_id,\n r.file_name,\n r.original_file_name,\n r.file_path,\n r.file_size,\n r.file_type,\n r.revision_comment,\n \n a.created_by,\n u.name as created_by_name,\n a.created_at,\n a.updated_at\n FROM b_rfq_attachments a\n LEFT JOIN b_rfq_attachment_revisions r ON a.latest_revision_id = r.id\n LEFT JOIN users u ON a.created_by = u.id\n ", + "name": "attachments_with_latest_revision", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.b_rfqs_master": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pic_name": { + "name": "pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "eng_pic_name": { + "name": "eng_pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_no": { + "name": "package_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_name": { + "name": "package_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "project_code": { + "name": "project_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_name": { + "name": "project_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_type": { + "name": "project_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "project_company": { + "name": "project_company", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_flag": { + "name": "project_flag", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_site": { + "name": "project_site", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "total_attachments": { + "name": "total_attachments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.description,\n br.status,\n br.due_date,\n br.pic_code,\n br.pic_name,\n br.eng_pic_name,\n br.package_no,\n br.package_name,\n br.project_id,\n p.code as project_code,\n p.name as project_name,\n p.type as project_type,\n br.project_company,\n br.project_flag,\n br.project_site,\n COALESCE(att_count.total_attachments, 0) as total_attachments,\n br.created_at,\n br.updated_at\n FROM b_rfqs br\n LEFT JOIN projects p ON br.project_id = p.id\n LEFT JOIN (\n SELECT rfq_id, COUNT(*) as total_attachments\n FROM b_rfq_attachments\n GROUP BY rfq_id\n ) att_count ON br.id = att_count.rfq_id\n", + "name": "b_rfqs_master", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.final_rfq_detail": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_status": { + "name": "rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "final_rfq_id": { + "name": "final_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "final_rfq_status": { + "name": "final_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_country": { + "name": "vendor_country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "vendor_business_size": { + "name": "vendor_business_size", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_description": { + "name": "incoterms_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "payment_terms_description": { + "name": "payment_terms_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "tax_code": { + "name": "tax_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_shipping": { + "name": "place_of_shipping", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_destination": { + "name": "place_of_destination", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "firsttime_yn": { + "name": "firsttime_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "material_price_related_yn": { + "name": "material_price_related_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vendor_remark": { + "name": "vendor_remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.status as rfq_status,\n fr.id as final_rfq_id,\n fr.final_rfq_status,\n fr.vendor_id,\n v.vendor_code,\n v.vendor_name,\n v.country as vendor_country,\n v.business_size as vendor_business_size,\n fr.due_date,\n fr.valid_date,\n fr.delivery_date,\n fr.incoterms_code,\n inc.description as incoterms_description,\n fr.payment_terms_code,\n pt.description as payment_terms_description,\n fr.currency,\n fr.tax_code,\n fr.place_of_shipping,\n fr.place_of_destination,\n fr.short_list,\n fr.return_yn,\n fr.cp_request_yn,\n fr.prject_gtc_yn,\n fr.firsttime_yn,\n fr.material_price_related_yn,\n fr.return_revision,\n fr.gtc,\n fr.gtc_valid_date,\n fr.classification,\n fr.sparepart,\n fr.remark,\n fr.vendor_remark,\n fr.created_at,\n fr.updated_at\n FROM b_rfqs br\n JOIN final_rfq fr ON br.id = fr.rfq_id\n LEFT JOIN vendors v ON fr.vendor_id = v.id\n LEFT JOIN incoterms inc ON fr.incoterms_code = inc.code\n LEFT JOIN payment_terms pt ON fr.payment_terms_code = pt.code\n", + "name": "final_rfq_detail", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.initial_rfq_detail": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_status": { + "name": "rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "initial_rfq_id": { + "name": "initial_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "initial_rfq_status": { + "name": "initial_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_country": { + "name": "vendor_country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "vendor_business_size": { + "name": "vendor_business_size", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_description": { + "name": "incoterms_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.status as rfq_status,\n ir.id as initial_rfq_id,\n ir.initial_rfq_status,\n ir.vendor_id,\n v.vendor_code,\n v.vendor_name,\n v.country as vendor_country,\n v.business_size as vendor_business_size,\n ir.due_date,\n ir.valid_date,\n ir.incoterms_code,\n inc.description as incoterms_description,\n ir.short_list,\n ir.return_yn,\n ir.cp_request_yn,\n ir.prject_gtc_yn,\n ir.return_revision,\n ir.gtc,\n ir.gtc_valid_date,\n ir.classification,\n ir.sparepart,\n ir.created_at,\n ir.updated_at\n FROM b_rfqs br\n JOIN initial_rfq ir ON br.id = ir.rfq_id\n LEFT JOIN vendors v ON ir.vendor_id = v.id\n LEFT JOIN incoterms inc ON ir.incoterms_code = inc.code\n", + "name": "initial_rfq_detail", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.rfq_dashboard": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "project_code": { + "name": "project_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_name": { + "name": "project_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "package_no": { + "name": "package_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_name": { + "name": "package_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pic_name": { + "name": "pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "eng_pic_name": { + "name": "eng_pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_company": { + "name": "project_company", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_flag": { + "name": "project_flag", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_site": { + "name": "project_site", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "total_attachments": { + "name": "total_attachments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "initial_vendor_count": { + "name": "initial_vendor_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "final_vendor_count": { + "name": "final_vendor_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "initial_response_rate": { + "name": "initial_response_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "final_response_rate": { + "name": "final_response_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "overall_progress": { + "name": "overall_progress", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "days_to_deadline": { + "name": "days_to_deadline", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by_name": { + "name": "updated_by_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "updated_by_email": { + "name": "updated_by_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n -- ② SELECT 절 확장 -------------------------------------------\n SELECT\n br.id AS rfq_id,\n br.rfq_code,\n br.description,\n br.status,\n br.due_date,\n p.code AS project_code,\n p.name AS project_name,\n br.package_no,\n br.package_name,\n br.pic_code,\n br.pic_name,\n br.eng_pic_name,\n br.project_company,\n br.project_flag,\n br.project_site,\n br.remark,\n \n -- 첨부/벤더 요약 -----------------------\n COALESCE(att_count.total_attachments, 0) AS total_attachments,\n COALESCE(init_summary.vendor_count, 0) AS initial_vendor_count,\n COALESCE(final_summary.vendor_count, 0) AS final_vendor_count,\n COALESCE(init_summary.avg_response_rate, 0) AS initial_response_rate,\n COALESCE(final_summary.avg_response_rate, 0) AS final_response_rate,\n \n -- 진행률·마감까지 일수 --------------\n CASE \n WHEN br.status = 'DRAFT' THEN 0\n WHEN br.status = 'Doc. Received' THEN 10\n WHEN br.status = 'PIC Assigned' THEN 20\n WHEN br.status = 'Doc. Confirmed' THEN 30\n WHEN br.status = 'Init. RFQ Sent' THEN 40\n WHEN br.status = 'Init. RFQ Answered' THEN 50\n WHEN br.status = 'TBE started' THEN 60\n WHEN br.status = 'TBE finished' THEN 70\n WHEN br.status = 'Final RFQ Sent' THEN 80\n WHEN br.status = 'Quotation Received' THEN 90\n WHEN br.status = 'Vendor Selected' THEN 100\n ELSE 0\n END AS overall_progress,\n (br.due_date - CURRENT_DATE) AS days_to_deadline,\n \n br.created_at,\n br.updated_at,\n \n -- 💡 추가되는 컬럼 -------------------\n upd.name AS updated_by_name,\n upd.email AS updated_by_email\n FROM b_rfqs br\n LEFT JOIN projects p ON br.project_id = p.id\n \n -- ③ 사용자 정보 조인 --------------------\n LEFT JOIN users upd ON br.updated_by = upd.id\n \n -- (나머지 이미 있던 JOIN 들은 그대로) -----\n LEFT JOIN (\n SELECT rfq_id, COUNT(*) AS total_attachments\n FROM b_rfq_attachments\n GROUP BY rfq_id\n ) att_count ON br.id = att_count.rfq_id\n \n LEFT JOIN (\n SELECT \n rfq_id, \n COUNT(DISTINCT vendor_id) AS vendor_count,\n AVG(response_rate) AS avg_response_rate\n FROM vendor_response_summary\n WHERE rfq_type = 'INITIAL'\n GROUP BY rfq_id\n ) init_summary ON br.id = init_summary.rfq_id\n \n LEFT JOIN (\n SELECT \n rfq_id, \n COUNT(DISTINCT vendor_id) AS vendor_count,\n AVG(response_rate) AS avg_response_rate\n FROM vendor_response_summary\n WHERE rfq_type = 'FINAL'\n GROUP BY rfq_id\n ) final_summary ON br.id = final_summary.rfq_id\n ", + "name": "rfq_dashboard", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_response_summary": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_status": { + "name": "rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_country": { + "name": "vendor_country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "vendor_business_size": { + "name": "vendor_business_size", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_type": { + "name": "rfq_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "total_attachments": { + "name": "total_attachments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "responded_count": { + "name": "responded_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "pending_count": { + "name": "pending_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "waived_count": { + "name": "waived_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "revision_requested_count": { + "name": "revision_requested_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "response_rate": { + "name": "response_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "completion_rate": { + "name": "completion_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.status as rfq_status,\n v.id as vendor_id,\n v.vendor_code,\n v.vendor_name,\n v.country as vendor_country,\n v.business_size as vendor_business_size,\n var.rfq_type,\n COUNT(var.id) as total_attachments,\n COUNT(CASE WHEN var.response_status = 'RESPONDED' THEN 1 END) as responded_count,\n COUNT(CASE WHEN var.response_status = 'NOT_RESPONDED' THEN 1 END) as pending_count,\n COUNT(CASE WHEN var.response_status = 'WAIVED' THEN 1 END) as waived_count,\n COUNT(CASE WHEN var.response_status = 'REVISION_REQUESTED' THEN 1 END) as revision_requested_count,\n ROUND(\n (COUNT(CASE WHEN var.response_status = 'RESPONDED' THEN 1 END) * 100.0 / \n NULLIF(COUNT(CASE WHEN var.response_status != 'WAIVED' THEN 1 END), 0)), \n 2\n ) as response_rate,\n ROUND(\n ((COUNT(CASE WHEN var.response_status = 'RESPONDED' THEN 1 END) + \n COUNT(CASE WHEN var.response_status = 'WAIVED' THEN 1 END)) * 100.0 / COUNT(var.id)), \n 2\n ) as completion_rate\n FROM b_rfqs br\n JOIN b_rfq_attachments bra ON br.id = bra.rfq_id\n JOIN vendor_attachment_responses var ON bra.id = var.attachment_id\n JOIN vendors v ON var.vendor_id = v.id\n GROUP BY br.id, br.rfq_code, br.status, v.id, v.vendor_code, v.vendor_name, v.country, v.business_size, var.rfq_type\n", + "name": "vendor_response_summary", + "schema": "public", + "isExisting": false, + "materialized": false + } + }, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +}
\ No newline at end of file diff --git a/db/migrations/meta/0129_snapshot.json b/db/migrations/meta/0129_snapshot.json new file mode 100644 index 00000000..18ca4949 --- /dev/null +++ b/db/migrations/meta/0129_snapshot.json @@ -0,0 +1,14188 @@ +{ + "id": "5cb02083-21c1-4195-a09b-448010cccef0", + "prevId": "89ab6bb0-8ac0-4a79-a5be-a500197f5c00", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.companies": { + "name": "companies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "companies_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "taxID": { + "name": "taxID", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contract_envelopes": { + "name": "contract_envelopes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contract_envelopes_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "envelope_id": { + "name": "envelope_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "envelope_status": { + "name": "envelope_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "contract_envelopes_contract_id_contracts_id_fk": { + "name": "contract_envelopes_contract_id_contracts_id_fk", + "tableFrom": "contract_envelopes", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contract_items": { + "name": "contract_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contract_items_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "unit_price": { + "name": "unit_price", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "tax_rate": { + "name": "tax_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "tax_amount": { + "name": "tax_amount", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "total_line_amount": { + "name": "total_line_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "contract_items_contract_item_idx": { + "name": "contract_items_contract_item_idx", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "contract_items_contract_id_contracts_id_fk": { + "name": "contract_items_contract_id_contracts_id_fk", + "tableFrom": "contract_items", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contract_items_item_id_items_id_fk": { + "name": "contract_items_item_id_items_id_fk", + "tableFrom": "contract_items", + "tableTo": "items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "contract_items_contract_id_item_id_unique": { + "name": "contract_items_contract_id_item_id_unique", + "nullsNotDistinct": false, + "columns": [ + "contract_id", + "item_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contract_signers": { + "name": "contract_signers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contract_signers_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "envelope_id": { + "name": "envelope_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_contact_id": { + "name": "vendor_contact_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "signer_type": { + "name": "signer_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'VENDOR'" + }, + "signer_email": { + "name": "signer_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "signer_name": { + "name": "signer_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "signer_position": { + "name": "signer_position", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "signer_status": { + "name": "signer_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'PENDING'" + }, + "signed_at": { + "name": "signed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "contract_signers_envelope_id_contract_envelopes_id_fk": { + "name": "contract_signers_envelope_id_contract_envelopes_id_fk", + "tableFrom": "contract_signers", + "tableTo": "contract_envelopes", + "columnsFrom": [ + "envelope_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contract_signers_vendor_contact_id_vendor_contacts_id_fk": { + "name": "contract_signers_vendor_contact_id_vendor_contacts_id_fk", + "tableFrom": "contract_signers", + "tableTo": "vendor_contacts", + "columnsFrom": [ + "vendor_contact_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contracts": { + "name": "contracts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contracts_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "contract_name": { + "name": "contract_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "payment_terms": { + "name": "payment_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'KRW'" + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "partial_shipping_allowed": { + "name": "partial_shipping_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "partial_payment_allowed": { + "name": "partial_payment_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "remarks": { + "name": "remarks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "contracts_project_id_projects_id_fk": { + "name": "contracts_project_id_projects_id_fk", + "tableFrom": "contracts", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contracts_vendor_id_vendors_id_fk": { + "name": "contracts_vendor_id_vendors_id_fk", + "tableFrom": "contracts", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "contracts_contract_no_unique": { + "name": "contracts_contract_no_unique", + "nullsNotDistinct": false, + "columns": [ + "contract_no" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.poa": { + "name": "poa", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "poa_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "original_contract_no": { + "name": "original_contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "original_contract_name": { + "name": "original_contract_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_status": { + "name": "original_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "change_reason": { + "name": "change_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approval_status": { + "name": "approval_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'PENDING'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "poa_original_contract_no_contracts_contract_no_fk": { + "name": "poa_original_contract_no_contracts_contract_no_fk", + "tableFrom": "poa", + "tableTo": "contracts", + "columnsFrom": [ + "original_contract_no" + ], + "columnsTo": [ + "contract_no" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "poa_project_id_projects_id_fk": { + "name": "poa_project_id_projects_id_fk", + "tableFrom": "poa", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "poa_vendor_id_vendors_id_fk": { + "name": "poa_vendor_id_vendors_id_fk", + "tableFrom": "poa", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.item_offshore_hull": { + "name": "item_offshore_hull", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "work_type": { + "name": "work_type", + "type": "offshore_hull_work_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "item_list": { + "name": "item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sub_item_list": { + "name": "sub_item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "item_offshore_hull_item_code_items_item_code_fk": { + "name": "item_offshore_hull_item_code_items_item_code_fk", + "tableFrom": "item_offshore_hull", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.item_offshore_top": { + "name": "item_offshore_top", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "work_type": { + "name": "work_type", + "type": "offshore_top_work_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "item_list": { + "name": "item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sub_item_list": { + "name": "sub_item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "item_offshore_top_item_code_items_item_code_fk": { + "name": "item_offshore_top_item_code_items_item_code_fk", + "tableFrom": "item_offshore_top", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.item_shipbuilding": { + "name": "item_shipbuilding", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "work_type": { + "name": "work_type", + "type": "work_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "item_list": { + "name": "item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ship_types": { + "name": "ship_types", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'OPTION'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "item_shipbuilding_item_code_items_item_code_fk": { + "name": "item_shipbuilding_item_code_items_item_code_fk", + "tableFrom": "item_shipbuilding", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.items": { + "name": "items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_no": { + "name": "project_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "package_code": { + "name": "package_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "sm_code": { + "name": "sm_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_item_code": { + "name": "parent_item_code", + "type": "varchar(18)", + "primaryKey": false, + "notNull": false + }, + "item_level": { + "name": "item_level", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "delete_flag": { + "name": "delete_flag", + "type": "varchar(1)", + "primaryKey": false, + "notNull": false + }, + "unit_of_measure": { + "name": "unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "steel_type": { + "name": "steel_type", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "grade_material": { + "name": "grade_material", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "change_date": { + "name": "change_date", + "type": "varchar(8)", + "primaryKey": false, + "notNull": false + }, + "base_unit_of_measure": { + "name": "base_unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "items_item_code_unique": { + "name": "items_item_code_unique", + "nullsNotDistinct": false, + "columns": [ + "item_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.materials": { + "name": "materials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_item_code": { + "name": "parent_item_code", + "type": "varchar(18)", + "primaryKey": false, + "notNull": false + }, + "item_level": { + "name": "item_level", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "delete_flag": { + "name": "delete_flag", + "type": "varchar(1)", + "primaryKey": false, + "notNull": false + }, + "unit_of_measure": { + "name": "unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "steel_type": { + "name": "steel_type", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "grade_material": { + "name": "grade_material", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "change_date": { + "name": "change_date", + "type": "varchar(8)", + "primaryKey": false, + "notNull": false + }, + "base_unit_of_measure": { + "name": "base_unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "materials_item_code_unique": { + "name": "materials_item_code_unique", + "nullsNotDistinct": false, + "columns": [ + "item_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pq_criterias": { + "name": "pq_criterias", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "check_point": { + "name": "check_point", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "remarks": { + "name": "remarks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "group_name": { + "name": "group_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pq_criterias_extension": { + "name": "pq_criterias_extension", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pq_criteria_id": { + "name": "pq_criteria_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "contract_info": { + "name": "contract_info", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "additional_requirement": { + "name": "additional_requirement", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "pq_criterias_extension_pq_criteria_id_pq_criterias_id_fk": { + "name": "pq_criterias_extension_pq_criteria_id_pq_criterias_id_fk", + "tableFrom": "pq_criterias_extension", + "tableTo": "pq_criterias", + "columnsFrom": [ + "pq_criteria_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "pq_criterias_extension_project_id_projects_id_fk": { + "name": "pq_criterias_extension_project_id_projects_id_fk", + "tableFrom": "pq_criterias_extension", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_criteria_attachments": { + "name": "vendor_criteria_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_criteria_answer_id": { + "name": "vendor_criteria_answer_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_criteria_attachments_vendor_criteria_answer_id_vendor_pq_criteria_answers_id_fk": { + "name": "vendor_criteria_attachments_vendor_criteria_answer_id_vendor_pq_criteria_answers_id_fk", + "tableFrom": "vendor_criteria_attachments", + "tableTo": "vendor_pq_criteria_answers", + "columnsFrom": [ + "vendor_criteria_answer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_investigation_attachments": { + "name": "vendor_investigation_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "investigation_id": { + "name": "investigation_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "mime_type": { + "name": "mime_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'REPORT'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_investigation_attachments_investigation_id_vendor_investigations_id_fk": { + "name": "vendor_investigation_attachments_investigation_id_vendor_investigations_id_fk", + "tableFrom": "vendor_investigation_attachments", + "tableTo": "vendor_investigations", + "columnsFrom": [ + "investigation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_investigations": { + "name": "vendor_investigations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pq_submission_id": { + "name": "pq_submission_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requester_id": { + "name": "requester_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "qm_manager_id": { + "name": "qm_manager_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "investigation_status": { + "name": "investigation_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'PLANNED'" + }, + "evaluation_type": { + "name": "evaluation_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_address": { + "name": "investigation_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "investigation_method": { + "name": "investigation_method", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "scheduled_start_at": { + "name": "scheduled_start_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scheduled_end_at": { + "name": "scheduled_end_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "forecasted_at": { + "name": "forecasted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "evaluation_score": { + "name": "evaluation_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluation_result": { + "name": "evaluation_result", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_notes": { + "name": "investigation_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_investigations_vendor_id_vendors_id_fk": { + "name": "vendor_investigations_vendor_id_vendors_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_investigations_pq_submission_id_vendor_pq_submissions_id_fk": { + "name": "vendor_investigations_pq_submission_id_vendor_pq_submissions_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "vendor_pq_submissions", + "columnsFrom": [ + "pq_submission_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + }, + "vendor_investigations_requester_id_users_id_fk": { + "name": "vendor_investigations_requester_id_users_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "users", + "columnsFrom": [ + "requester_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_investigations_qm_manager_id_users_id_fk": { + "name": "vendor_investigations_qm_manager_id_users_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "users", + "columnsFrom": [ + "qm_manager_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_pq_submissions": { + "name": "vendor_pq_submissions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pq_number": { + "name": "pq_number", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "requester_id": { + "name": "requester_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'REQUESTED'" + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "rejected_at": { + "name": "rejected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "reject_reason": { + "name": "reject_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_pq_submission": { + "name": "unique_pq_submission", + "columns": [ + { + "expression": "vendor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "vendor_pq_submissions_requester_id_users_id_fk": { + "name": "vendor_pq_submissions_requester_id_users_id_fk", + "tableFrom": "vendor_pq_submissions", + "tableTo": "users", + "columnsFrom": [ + "requester_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_pq_submissions_vendor_id_vendors_id_fk": { + "name": "vendor_pq_submissions_vendor_id_vendors_id_fk", + "tableFrom": "vendor_pq_submissions", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_pq_submissions_project_id_projects_id_fk": { + "name": "vendor_pq_submissions_project_id_projects_id_fk", + "tableFrom": "vendor_pq_submissions", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "vendor_pq_submissions_pq_number_unique": { + "name": "vendor_pq_submissions_pq_number_unique", + "nullsNotDistinct": false, + "columns": [ + "pq_number" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_pq_criteria_answers": { + "name": "vendor_pq_criteria_answers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "criteria_id": { + "name": "criteria_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "answer": { + "name": "answer", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_pq_criteria_answers_vendor_id_vendors_id_fk": { + "name": "vendor_pq_criteria_answers_vendor_id_vendors_id_fk", + "tableFrom": "vendor_pq_criteria_answers", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_pq_criteria_answers_criteria_id_pq_criterias_id_fk": { + "name": "vendor_pq_criteria_answers_criteria_id_pq_criterias_id_fk", + "tableFrom": "vendor_pq_criteria_answers", + "tableTo": "pq_criterias", + "columnsFrom": [ + "criteria_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_pq_criteria_answers_project_id_projects_id_fk": { + "name": "vendor_pq_criteria_answers_project_id_projects_id_fk", + "tableFrom": "vendor_pq_criteria_answers", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_pq_review_logs": { + "name": "vendor_pq_review_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_pq_criteria_answer_id": { + "name": "vendor_pq_criteria_answer_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "reviewer_comment": { + "name": "reviewer_comment", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reviewer_name": { + "name": "reviewer_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_pq_review_logs_vendor_pq_criteria_answer_id_vendor_pq_criteria_answers_id_fk": { + "name": "vendor_pq_review_logs_vendor_pq_criteria_answer_id_vendor_pq_criteria_answers_id_fk", + "tableFrom": "vendor_pq_review_logs", + "tableTo": "vendor_pq_criteria_answers", + "columnsFrom": [ + "vendor_pq_criteria_answer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_project_pqs": { + "name": "vendor_project_pqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'REQUESTED'" + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "rejected_at": { + "name": "rejected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "reject_reason": { + "name": "reject_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_project_pqs_vendor_id_vendors_id_fk": { + "name": "vendor_project_pqs_vendor_id_vendors_id_fk", + "tableFrom": "vendor_project_pqs", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_project_pqs_project_id_projects_id_fk": { + "name": "vendor_project_pqs_project_id_projects_id_fk", + "tableFrom": "vendor_project_pqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.bidding_projects": { + "name": "bidding_projects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pspid": { + "name": "pspid", + "type": "char(24)", + "primaryKey": false, + "notNull": true + }, + "proj_nm": { + "name": "proj_nm", + "type": "varchar(90)", + "primaryKey": false, + "notNull": false + }, + "sector": { + "name": "sector", + "type": "char(1)", + "primaryKey": false, + "notNull": false + }, + "proj_msrm": { + "name": "proj_msrm", + "type": "numeric(3, 0)", + "primaryKey": false, + "notNull": false + }, + "kunnr": { + "name": "kunnr", + "type": "char(10)", + "primaryKey": false, + "notNull": false + }, + "kunnr_nm": { + "name": "kunnr_nm", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "cls_1": { + "name": "cls_1", + "type": "char(10)", + "primaryKey": false, + "notNull": false + }, + "cls1_nm": { + "name": "cls1_nm", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "ptype": { + "name": "ptype", + "type": "char(3)", + "primaryKey": false, + "notNull": false + }, + "ptype_nm": { + "name": "ptype_nm", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "pmodel_cd": { + "name": "pmodel_cd", + "type": "char(10)", + "primaryKey": false, + "notNull": false + }, + "pmodel_nm": { + "name": "pmodel_nm", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "pmodel_sz": { + "name": "pmodel_sz", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "pmodel_uom": { + "name": "pmodel_uom", + "type": "char(5)", + "primaryKey": false, + "notNull": false + }, + "txt04": { + "name": "txt04", + "type": "char(4)", + "primaryKey": false, + "notNull": false + }, + "txt30": { + "name": "txt30", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "estm_pm": { + "name": "estm_pm", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "bidding_projects_pspid_unique": { + "name": "bidding_projects_pspid_unique", + "nullsNotDistinct": false, + "columns": [ + "pspid" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.project_series": { + "name": "project_series", + "schema": "", + "columns": { + "pspid": { + "name": "pspid", + "type": "char(24)", + "primaryKey": false, + "notNull": true + }, + "sers_no": { + "name": "sers_no", + "type": "char(3)", + "primaryKey": false, + "notNull": true + }, + "sc_dt": { + "name": "sc_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "kl_dt": { + "name": "kl_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "lc_dt": { + "name": "lc_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "dl_dt": { + "name": "dl_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "dock_no": { + "name": "dock_no", + "type": "char(3)", + "primaryKey": false, + "notNull": false + }, + "dock_nm": { + "name": "dock_nm", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "proj_no": { + "name": "proj_no", + "type": "char(24)", + "primaryKey": false, + "notNull": false + }, + "post1": { + "name": "post1", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "project_sersNo_unique": { + "name": "project_sersNo_unique", + "columns": [ + { + "expression": "pspid", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sers_no", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "project_series_pspid_bidding_projects_pspid_fk": { + "name": "project_series_pspid_bidding_projects_pspid_fk", + "tableFrom": "project_series", + "tableTo": "bidding_projects", + "columnsFrom": [ + "pspid" + ], + "columnsTo": [ + "pspid" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.projects": { + "name": "projects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'ship'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cbe_evaluations": { + "name": "cbe_evaluations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "evaluated_by": { + "name": "evaluated_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluated_at": { + "name": "evaluated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "result": { + "name": "result", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "total_cost": { + "name": "total_cost", + "type": "numeric(18, 2)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "payment_terms": { + "name": "payment_terms", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "incoterms": { + "name": "incoterms", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "delivery_schedule": { + "name": "delivery_schedule", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "cbe_evaluations_rfq_id_rfqs_id_fk": { + "name": "cbe_evaluations_rfq_id_rfqs_id_fk", + "tableFrom": "cbe_evaluations", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cbe_evaluations_vendor_id_vendors_id_fk": { + "name": "cbe_evaluations_vendor_id_vendors_id_fk", + "tableFrom": "cbe_evaluations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cbe_evaluations_evaluated_by_users_id_fk": { + "name": "cbe_evaluations_evaluated_by_users_id_fk", + "tableFrom": "cbe_evaluations", + "tableTo": "users", + "columnsFrom": [ + "evaluated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_attachments": { + "name": "rfq_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "evaluation_id": { + "name": "evaluation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cbe_id": { + "name": "cbe_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "comment_id": { + "name": "comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_attachments_rfq_id_rfqs_id_fk": { + "name": "rfq_attachments_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_vendor_id_vendors_id_fk": { + "name": "rfq_attachments_vendor_id_vendors_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_evaluation_id_rfq_evaluations_id_fk": { + "name": "rfq_attachments_evaluation_id_rfq_evaluations_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "rfq_evaluations", + "columnsFrom": [ + "evaluation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_cbe_id_cbe_evaluations_id_fk": { + "name": "rfq_attachments_cbe_id_cbe_evaluations_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "cbe_evaluations", + "columnsFrom": [ + "cbe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_comment_id_rfq_comments_id_fk": { + "name": "rfq_attachments_comment_id_rfq_comments_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "rfq_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_comments": { + "name": "rfq_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "comment_text": { + "name": "comment_text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "commented_by": { + "name": "commented_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "evaluation_id": { + "name": "evaluation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cbe_id": { + "name": "cbe_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_comments_rfq_id_rfqs_id_fk": { + "name": "rfq_comments_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_vendor_id_vendors_id_fk": { + "name": "rfq_comments_vendor_id_vendors_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_commented_by_users_id_fk": { + "name": "rfq_comments_commented_by_users_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "users", + "columnsFrom": [ + "commented_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_evaluation_id_rfq_evaluations_id_fk": { + "name": "rfq_comments_evaluation_id_rfq_evaluations_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "rfq_evaluations", + "columnsFrom": [ + "evaluation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_cbe_id_vendor_responses_id_fk": { + "name": "rfq_comments_cbe_id_vendor_responses_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "vendor_responses", + "columnsFrom": [ + "cbe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_evaluations": { + "name": "rfq_evaluations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "eval_type": { + "name": "eval_type", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_evaluations_rfq_id_rfqs_id_fk": { + "name": "rfq_evaluations_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_evaluations", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_evaluations_vendor_id_vendors_id_fk": { + "name": "rfq_evaluations_vendor_id_vendors_id_fk", + "tableFrom": "rfq_evaluations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_items": { + "name": "rfq_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "uom": { + "name": "uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_items_rfq_id_rfqs_id_fk": { + "name": "rfq_items_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_items", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "rfq_items_item_code_items_item_code_fk": { + "name": "rfq_items_item_code_items_item_code_fk", + "tableFrom": "rfq_items", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfqs": { + "name": "rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "bid_project_id": { + "name": "bid_project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "rfq_type": { + "name": "rfq_type", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false, + "default": "'PURCHASE'" + }, + "parent_rfq_id": { + "name": "parent_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfqs_project_id_projects_id_fk": { + "name": "rfqs_project_id_projects_id_fk", + "tableFrom": "rfqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "rfqs_bid_project_id_bidding_projects_id_fk": { + "name": "rfqs_bid_project_id_bidding_projects_id_fk", + "tableFrom": "rfqs", + "tableTo": "bidding_projects", + "columnsFrom": [ + "bid_project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "rfqs_created_by_users_id_fk": { + "name": "rfqs_created_by_users_id_fk", + "tableFrom": "rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "rfqs_parent_rfq_id_rfqs_id_fk": { + "name": "rfqs_parent_rfq_id_rfqs_id_fk", + "tableFrom": "rfqs", + "tableTo": "rfqs", + "columnsFrom": [ + "parent_rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "rfqs_rfq_code_unique": { + "name": "rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_commercial_responses": { + "name": "vendor_commercial_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "response_id": { + "name": "response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "total_price": { + "name": "total_price", + "type": "numeric(18, 2)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "payment_terms": { + "name": "payment_terms", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "incoterms": { + "name": "incoterms", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "delivery_period": { + "name": "delivery_period", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "warranty_period": { + "name": "warranty_period", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "validity_period": { + "name": "validity_period", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "price_breakdown": { + "name": "price_breakdown", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "commercial_notes": { + "name": "commercial_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_commercial_responses_response_id_vendor_responses_id_fk": { + "name": "vendor_commercial_responses_response_id_vendor_responses_id_fk", + "tableFrom": "vendor_commercial_responses", + "tableTo": "vendor_responses", + "columnsFrom": [ + "response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_response_attachments": { + "name": "vendor_response_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "response_id": { + "name": "response_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "technical_response_id": { + "name": "technical_response_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "commercial_response_id": { + "name": "commercial_response_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_response_attachments_response_id_vendor_responses_id_fk": { + "name": "vendor_response_attachments_response_id_vendor_responses_id_fk", + "tableFrom": "vendor_response_attachments", + "tableTo": "vendor_responses", + "columnsFrom": [ + "response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_attachments_technical_response_id_vendor_technical_responses_id_fk": { + "name": "vendor_response_attachments_technical_response_id_vendor_technical_responses_id_fk", + "tableFrom": "vendor_response_attachments", + "tableTo": "vendor_technical_responses", + "columnsFrom": [ + "technical_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_attachments_commercial_response_id_vendor_commercial_responses_id_fk": { + "name": "vendor_response_attachments_commercial_response_id_vendor_commercial_responses_id_fk", + "tableFrom": "vendor_response_attachments", + "tableTo": "vendor_commercial_responses", + "columnsFrom": [ + "commercial_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_responses": { + "name": "vendor_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'REVIEWING'" + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "responded_by": { + "name": "responded_by", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "responded_at": { + "name": "responded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "vendor_response_unique": { + "name": "vendor_response_unique", + "columns": [ + { + "expression": "rfq_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "vendor_responses_rfq_id_rfqs_id_fk": { + "name": "vendor_responses_rfq_id_rfqs_id_fk", + "tableFrom": "vendor_responses", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_responses_vendor_id_vendors_id_fk": { + "name": "vendor_responses_vendor_id_vendors_id_fk", + "tableFrom": "vendor_responses", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_technical_responses": { + "name": "vendor_technical_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "response_id": { + "name": "response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_technical_responses_response_id_vendor_responses_id_fk": { + "name": "vendor_technical_responses_response_id_vendor_responses_id_fk", + "tableFrom": "vendor_technical_responses", + "tableTo": "vendor_responses", + "columnsFrom": [ + "response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.otps": { + "name": "otps", + "schema": "", + "columns": { + "email": { + "name": "email", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(6)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "otpToken": { + "name": "otpToken", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "otp_expires": { + "name": "otp_expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.permissions": { + "name": "permissions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "permissions_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "permission_key": { + "name": "permission_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.role_permissions": { + "name": "role_permissions", + "schema": "", + "columns": { + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "permission_id": { + "name": "permission_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "role_permissions_role_id_roles_id_fk": { + "name": "role_permissions_role_id_roles_id_fk", + "tableFrom": "role_permissions", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "role_permissions_permission_id_permissions_id_fk": { + "name": "role_permissions_permission_id_permissions_id_fk", + "tableFrom": "role_permissions", + "tableTo": "permissions", + "columnsFrom": [ + "permission_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.roles": { + "name": "roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "roles_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "user_domain", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "roles_company_id_vendors_id_fk": { + "name": "roles_company_id_vendors_id_fk", + "tableFrom": "roles", + "tableTo": "vendors", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_roles": { + "name": "user_roles", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_roles_user_id_users_id_fk": { + "name": "user_roles_user_id_users_id_fk", + "tableFrom": "user_roles", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_roles_role_id_roles_id_fk": { + "name": "user_roles_role_id_roles_id_fk", + "tableFrom": "user_roles", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "users_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "domain": { + "name": "domain", + "type": "user_domain", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'partners'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "image_url": { + "name": "image_url", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false + }, + "language": { + "name": "language", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'en'" + } + }, + "indexes": {}, + "foreignKeys": { + "users_company_id_vendors_id_fk": { + "name": "users_company_id_vendors_id_fk", + "tableFrom": "users", + "tableTo": "vendors", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.form_entries": { + "name": "form_entries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "form_entries_contract_item_id_contract_items_id_fk": { + "name": "form_entries_contract_item_id_contract_items_id_fk", + "tableFrom": "form_entries", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.form_metas": { + "name": "form_metas", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "form_name": { + "name": "form_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "columns": { + "name": "columns", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "form_metas_project_id_projects_id_fk": { + "name": "form_metas_project_id_projects_id_fk", + "tableFrom": "form_metas", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "form_code_project_unique": { + "name": "form_code_project_unique", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "form_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.forms": { + "name": "forms", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "forms_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "form_name": { + "name": "form_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "eng": { + "name": "eng", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "im": { + "name": "im", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "contract_item_form_code_unique": { + "name": "contract_item_form_code_unique", + "columns": [ + { + "expression": "contract_item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "form_code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "forms_contract_item_id_contract_items_id_fk": { + "name": "forms_contract_item_id_contract_items_id_fk", + "tableFrom": "forms", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_class_attributes": { + "name": "tag_class_attributes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "tag_class_attributes_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "tag_class_id": { + "name": "tag_class_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "att_id": { + "name": "att_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "def_val": { + "name": "def_val", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "uom_id": { + "name": "uom_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "seq": { + "name": "seq", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "tag_class_attributes_seq_idx": { + "name": "tag_class_attributes_seq_idx", + "columns": [ + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tag_class_attributes_tag_class_id_tag_classes_id_fk": { + "name": "tag_class_attributes_tag_class_id_tag_classes_id_fk", + "tableFrom": "tag_class_attributes", + "tableTo": "tag_classes", + "columnsFrom": [ + "tag_class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_att_id_in_tag_class": { + "name": "uniq_att_id_in_tag_class", + "nullsNotDistinct": false, + "columns": [ + "tag_class_id", + "att_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_classes": { + "name": "tag_classes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "tag_classes_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_type_code": { + "name": "tag_type_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_classes_project_id_projects_id_fk": { + "name": "tag_classes_project_id_projects_id_fk", + "tableFrom": "tag_classes", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tag_classes_tag_type_code_project_id_tag_types_code_project_id_fk": { + "name": "tag_classes_tag_type_code_project_id_tag_types_code_project_id_fk", + "tableFrom": "tag_classes", + "tableTo": "tag_types", + "columnsFrom": [ + "tag_type_code", + "project_id" + ], + "columnsTo": [ + "code", + "project_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_code_in_project": { + "name": "uniq_code_in_project", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_subfield_options": { + "name": "tag_subfield_options", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "attributes_id": { + "name": "attributes_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_subfield_options_project_id_projects_id_fk": { + "name": "tag_subfield_options_project_id_projects_id_fk", + "tableFrom": "tag_subfield_options", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_attribute_project_code": { + "name": "uniq_attribute_project_code", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "attributes_id", + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_subfields": { + "name": "tag_subfields", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "tag_type_code": { + "name": "tag_type_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "attributes_id": { + "name": "attributes_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "attributes_description": { + "name": "attributes_description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expression": { + "name": "expression", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delimiter": { + "name": "delimiter", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_subfields_project_id_projects_id_fk": { + "name": "tag_subfields_project_id_projects_id_fk", + "tableFrom": "tag_subfields", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_tag_type_attribute": { + "name": "uniq_tag_type_attribute", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "tag_type_code", + "attributes_id" + ] + }, + "uniq_attribute_id_project": { + "name": "uniq_attribute_id_project", + "nullsNotDistinct": false, + "columns": [ + "attributes_id", + "project_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_type_class_form_mappings": { + "name": "tag_type_class_form_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "tag_type_label": { + "name": "tag_type_label", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "class_label": { + "name": "class_label", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "form_name": { + "name": "form_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "ep": { + "name": "ep", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_mapping_in_project": { + "name": "uniq_mapping_in_project", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "tag_type_label", + "class_label", + "form_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_types": { + "name": "tag_types", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_types_project_id_projects_id_fk": { + "name": "tag_types_project_id_projects_id_fk", + "tableFrom": "tag_types", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "tag_types_code_project_id_pk": { + "name": "tag_types_code_project_id_pk", + "columns": [ + "code", + "project_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tags": { + "name": "tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "tags_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_id": { + "name": "form_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tag_no": { + "name": "tag_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "tag_type": { + "name": "tag_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "class": { + "name": "class", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tags_contract_item_id_contract_items_id_fk": { + "name": "tags_contract_item_id_contract_items_id_fk", + "tableFrom": "tags", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tags_form_id_forms_id_fk": { + "name": "tags_form_id_forms_id_fk", + "tableFrom": "tags", + "tableTo": "forms", + "columnsFrom": [ + "form_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "contract_item_tag_no_unique": { + "name": "contract_item_tag_no_unique", + "nullsNotDistinct": false, + "columns": [ + "contract_item_id", + "tag_no" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_data_report_temps": { + "name": "vendor_data_report_temps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_id": { + "name": "form_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_data_report_temps_contract_item_id_contract_items_id_fk": { + "name": "vendor_data_report_temps_contract_item_id_contract_items_id_fk", + "tableFrom": "vendor_data_report_temps", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_data_report_temps_form_id_forms_id_fk": { + "name": "vendor_data_report_temps_form_id_forms_id_fk", + "tableFrom": "vendor_data_report_temps", + "tableTo": "forms", + "columnsFrom": [ + "form_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.change_logs": { + "name": "change_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "changed_fields": { + "name": "changed_fields", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "old_values": { + "name": "old_values", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "new_values": { + "name": "new_values", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_name": { + "name": "user_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "is_synced": { + "name": "is_synced", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "sync_attempts": { + "name": "sync_attempts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "synced_at": { + "name": "synced_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "target_systems": { + "name": "target_systems", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + } + }, + "indexes": { + "idx_change_logs_contract_synced": { + "name": "idx_change_logs_contract_synced", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "is_synced", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_change_logs_created_at": { + "name": "idx_change_logs_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_change_logs_entity": { + "name": "idx_change_logs_entity", + "columns": [ + { + "expression": "entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entity_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_change_logs_sync_attempts": { + "name": "idx_change_logs_sync_attempts", + "columns": [ + { + "expression": "sync_attempts", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.document_attachments": { + "name": "document_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "document_attachments_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "revision_id": { + "name": "revision_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "upload_id": { + "name": "upload_id", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false + }, + "file_id": { + "name": "file_id", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "dolce_file_path": { + "name": "dolce_file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "document_attachments_revision_id_revisions_id_fk": { + "name": "document_attachments_revision_id_revisions_id_fk", + "tableFrom": "document_attachments", + "tableTo": "revisions", + "columnsFrom": [ + "revision_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.documents": { + "name": "documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "documents_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "pic": { + "name": "pic", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "vendor_doc_number": { + "name": "vendor_doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "drawing_kind": { + "name": "drawing_kind", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "drawing_move_gbn": { + "name": "drawing_move_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "discipline": { + "name": "discipline", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "external_document_id": { + "name": "external_document_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "external_system_type": { + "name": "external_system_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "external_synced_at": { + "name": "external_synced_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "c_gbn": { + "name": "c_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "d_gbn": { + "name": "d_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "degree_gbn": { + "name": "degree_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "dept_gbn": { + "name": "dept_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "j_gbn": { + "name": "j_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "s_gbn": { + "name": "s_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "shi_drawing_no": { + "name": "shi_drawing_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "manager": { + "name": "manager", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "manager_enm": { + "name": "manager_enm", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "manager_no": { + "name": "manager_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "register_group": { + "name": "register_group", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "register_group_id": { + "name": "register_group_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "create_user_no": { + "name": "create_user_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "create_user_id": { + "name": "create_user_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "create_user_enm": { + "name": "create_user_enm", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_contract_doc_status": { + "name": "unique_contract_doc_status", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "doc_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "unique_contract_vendor_doc": { + "name": "unique_contract_vendor_doc", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor_doc_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"documents\".\"vendor_doc_number\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "unique_external_doc": { + "name": "unique_external_doc", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_system_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"documents\".\"external_document_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "drawing_kind_idx": { + "name": "drawing_kind_idx", + "columns": [ + { + "expression": "drawing_kind", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "documents_contract_id_contracts_id_fk": { + "name": "documents_contract_id_contracts_id_fk", + "tableFrom": "documents", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.issue_stages": { + "name": "issue_stages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "issue_stages_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "document_id": { + "name": "document_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stage_name": { + "name": "stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "plan_date": { + "name": "plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "actual_date": { + "name": "actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "stage_status": { + "name": "stage_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'PLANNED'" + }, + "stage_order": { + "name": "stage_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "priority": { + "name": "priority", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false, + "default": "'MEDIUM'" + }, + "assignee_id": { + "name": "assignee_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "assignee_name": { + "name": "assignee_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "reminder_days": { + "name": "reminder_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "varchar(1000)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_document_stage": { + "name": "unique_document_stage", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stage_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_stage_order": { + "name": "document_stage_order", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stage_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "issue_stages_document_id_documents_id_fk": { + "name": "issue_stages_document_id_documents_id_fk", + "tableFrom": "issue_stages", + "tableTo": "documents", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.revisions": { + "name": "revisions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "revisions_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "issue_stage_id": { + "name": "issue_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "uploader_type": { + "name": "uploader_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'vendor'" + }, + "uploader_id": { + "name": "uploader_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploader_name": { + "name": "uploader_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "usage": { + "name": "usage", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "revision_status": { + "name": "revision_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'SUBMITTED'" + }, + "submitted_date": { + "name": "submitted_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "review_start_date": { + "name": "review_start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "approved_date": { + "name": "approved_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "rejected_date": { + "name": "rejected_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "reviewer_id": { + "name": "reviewer_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "reviewer_name": { + "name": "reviewer_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "review_comments": { + "name": "review_comments", + "type": "varchar(1000)", + "primaryKey": false, + "notNull": false + }, + "external_upload_id": { + "name": "external_upload_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_stage_rev": { + "name": "unique_stage_rev", + "columns": [ + { + "expression": "issue_stage_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "revision", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sync_batches": { + "name": "sync_batches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_system": { + "name": "target_system", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "batch_size": { + "name": "batch_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "retry_count": { + "name": "retry_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "change_log_ids": { + "name": "change_log_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "success_count": { + "name": "success_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "failure_count": { + "name": "failure_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "sync_metadata": { + "name": "sync_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_sync_batches_contract_system": { + "name": "idx_sync_batches_contract_system", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_system", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_sync_batches_status": { + "name": "idx_sync_batches_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_sync_batches_created_at": { + "name": "idx_sync_batches_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sync_configs": { + "name": "sync_configs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_system": { + "name": "target_system", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "sync_enabled": { + "name": "sync_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "sync_interval_minutes": { + "name": "sync_interval_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 30 + }, + "last_successful_sync": { + "name": "last_successful_sync", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_sync_attempt": { + "name": "last_sync_attempt", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "endpoint_url": { + "name": "endpoint_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "auth_token": { + "name": "auth_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "api_version": { + "name": "api_version", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false, + "default": "'v1'" + }, + "max_batch_size": { + "name": "max_batch_size", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 100 + }, + "retry_max_attempts": { + "name": "retry_max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_sync_configs_contract_system": { + "name": "idx_sync_configs_contract_system", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_system", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sync_configs_contract_id_contracts_id_fk": { + "name": "sync_configs_contract_id_contracts_id_fk", + "tableFrom": "sync_configs", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_attachments": { + "name": "vendor_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'GENERAL'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_attachments_vendor_id_vendors_id_fk": { + "name": "vendor_attachments_vendor_id_vendors_id_fk", + "tableFrom": "vendor_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_candidates": { + "name": "vendor_candidates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_name": { + "name": "company_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_email": { + "name": "contact_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "contact_phone": { + "name": "contact_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'COLLECTED'" + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_candidates_vendor_id_vendors_id_fk": { + "name": "vendor_candidates_vendor_id_vendors_id_fk", + "tableFrom": "vendor_candidates", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_contacts": { + "name": "vendor_contacts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "contact_name": { + "name": "contact_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_position": { + "name": "contact_position", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "contact_email": { + "name": "contact_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_phone": { + "name": "contact_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "is_primary": { + "name": "is_primary", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_contacts_vendor_id_vendors_id_fk": { + "name": "vendor_contacts_vendor_id_vendors_id_fk", + "tableFrom": "vendor_contacts", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_possible_items": { + "name": "vendor_possible_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_possible_items_vendor_id_vendors_id_fk": { + "name": "vendor_possible_items_vendor_id_vendors_id_fk", + "tableFrom": "vendor_possible_items", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_possible_items_item_code_items_item_code_fk": { + "name": "vendor_possible_items_item_code_items_item_code_fk", + "tableFrom": "vendor_possible_items", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_possible_materials": { + "name": "vendor_possible_materials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_possible_materials_vendor_id_vendors_id_fk": { + "name": "vendor_possible_materials_vendor_id_vendors_id_fk", + "tableFrom": "vendor_possible_materials", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_possible_materials_item_code_materials_item_code_fk": { + "name": "vendor_possible_materials_item_code_materials_item_code_fk", + "tableFrom": "vendor_possible_materials", + "tableTo": "materials", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_types": { + "name": "vendor_types", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name_ko": { + "name": "name_ko", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "name_en": { + "name": "name_en", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "vendor_types_code_unique": { + "name": "vendor_types_code_unique", + "nullsNotDistinct": false, + "columns": [ + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendors": { + "name": "vendors", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "website": { + "name": "website", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING_REVIEW'" + }, + "vendor_type_id": { + "name": "vendor_type_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "representative_name": { + "name": "representative_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_birth": { + "name": "representative_birth", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "representative_email": { + "name": "representative_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_phone": { + "name": "representative_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "corporate_registration_number": { + "name": "corporate_registration_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credit_agency": { + "name": "credit_agency", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "credit_rating": { + "name": "credit_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "cash_flow_rating": { + "name": "cash_flow_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "business_size": { + "name": "business_size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendors_vendor_type_id_vendor_types_id_fk": { + "name": "vendors_vendor_type_id_vendor_types_id_fk", + "tableFrom": "vendors", + "tableTo": "vendor_types", + "columnsFrom": [ + "vendor_type_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'todo'" + }, + "label": { + "name": "label", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'bug'" + }, + "priority": { + "name": "priority", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'low'" + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "current_timestamp" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "tasks_code_unique": { + "name": "tasks_code_unique", + "nullsNotDistinct": false, + "columns": [ + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_candidate_logs": { + "name": "vendor_candidate_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_candidate_id": { + "name": "vendor_candidate_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "old_status": { + "name": "old_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "new_status": { + "name": "new_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_candidate_logs_vendor_candidate_id_vendor_candidates_id_fk": { + "name": "vendor_candidate_logs_vendor_candidate_id_vendor_candidates_id_fk", + "tableFrom": "vendor_candidate_logs", + "tableTo": "vendor_candidates", + "columnsFrom": [ + "vendor_candidate_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_candidate_logs_user_id_users_id_fk": { + "name": "vendor_candidate_logs_user_id_users_id_fk", + "tableFrom": "vendor_candidate_logs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendors_logs": { + "name": "vendors_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "old_status": { + "name": "old_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "new_status": { + "name": "new_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendors_logs_vendor_id_vendors_id_fk": { + "name": "vendors_logs_vendor_id_vendors_id_fk", + "tableFrom": "vendors_logs", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendors_logs_user_id_users_id_fk": { + "name": "vendors_logs_user_id_users_id_fk", + "tableFrom": "vendors_logs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.basic_contract": { + "name": "basic_contract", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "basic_contract_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "template_id": { + "name": "template_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requested_by": { + "name": "requested_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "basic_contract_template_id_basic_contract_templates_id_fk": { + "name": "basic_contract_template_id_basic_contract_templates_id_fk", + "tableFrom": "basic_contract", + "tableTo": "basic_contract_templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "basic_contract_vendor_id_vendors_id_fk": { + "name": "basic_contract_vendor_id_vendors_id_fk", + "tableFrom": "basic_contract", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "basic_contract_requested_by_users_id_fk": { + "name": "basic_contract_requested_by_users_id_fk", + "tableFrom": "basic_contract", + "tableTo": "users", + "columnsFrom": [ + "requested_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.basic_contract_templates": { + "name": "basic_contract_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "basic_contract_templates_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "template_name": { + "name": "template_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "validity_period": { + "name": "validity_period", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.incoterms": { + "name": "incoterms", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "varchar(20)", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "incoterms_created_by_users_id_fk": { + "name": "incoterms_created_by_users_id_fk", + "tableFrom": "incoterms", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payment_terms": { + "name": "payment_terms", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "payment_terms_created_by_users_id_fk": { + "name": "payment_terms_created_by_users_id_fk", + "tableFrom": "payment_terms", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pr_items": { + "name": "pr_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_item": { + "name": "rfq_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_item": { + "name": "pr_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_no": { + "name": "pr_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "material_code": { + "name": "material_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_category": { + "name": "material_category", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "acc": { + "name": "acc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_description": { + "name": "material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "size": { + "name": "size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "uom": { + "name": "uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "gross_weight": { + "name": "gross_weight", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "gw_uom": { + "name": "gw_uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "spec_no": { + "name": "spec_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "spec_url": { + "name": "spec_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "tracking_no": { + "name": "tracking_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "major_yn": { + "name": "major_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "project_def": { + "name": "project_def", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_sc": { + "name": "project_sc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_kl": { + "name": "project_kl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_lc": { + "name": "project_lc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_dl": { + "name": "project_dl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pr_items_procurement_rfqs_id_procurement_rfqs_id_fk": { + "name": "pr_items_procurement_rfqs_id_procurement_rfqs_id_fk", + "tableFrom": "pr_items", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "procurement_rfqs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_attachments": { + "name": "procurement_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "procurement_rfq_details_id": { + "name": "procurement_rfq_details_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_attachments_procurement_rfqs_id_procurement_rfqs_id_fk": { + "name": "procurement_attachments_procurement_rfqs_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_attachments", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "procurement_rfqs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_attachments_procurement_rfq_details_id_procurement_rfq_details_id_fk": { + "name": "procurement_attachments_procurement_rfq_details_id_procurement_rfq_details_id_fk", + "tableFrom": "procurement_attachments", + "tableTo": "procurement_rfq_details", + "columnsFrom": [ + "procurement_rfq_details_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_attachments_created_by_users_id_fk": { + "name": "procurement_attachments_created_by_users_id_fk", + "tableFrom": "procurement_attachments", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "attachment_type_check": { + "name": "attachment_type_check", + "value": "\"procurement_attachments\".\"procurement_rfqs_id\" IS NOT NULL OR \"procurement_attachments\".\"procurement_rfq_details_id\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.procurement_quotation_items": { + "name": "procurement_quotation_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "quotation_id": { + "name": "quotation_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pr_item_id": { + "name": "pr_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "material_code": { + "name": "material_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "material_description": { + "name": "material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "uom": { + "name": "uom", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "unit_price": { + "name": "unit_price", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "total_price": { + "name": "total_price", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "vendor_material_code": { + "name": "vendor_material_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_material_description": { + "name": "vendor_material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "lead_time_in_days": { + "name": "lead_time_in_days", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tax_rate": { + "name": "tax_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "tax_amount": { + "name": "tax_amount", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "discount_rate": { + "name": "discount_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "discount_amount": { + "name": "discount_amount", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_alternative": { + "name": "is_alternative", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "is_recommended": { + "name": "is_recommended", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_quotation_items_quotation_id_procurement_vendor_quotations_id_fk": { + "name": "procurement_quotation_items_quotation_id_procurement_vendor_quotations_id_fk", + "tableFrom": "procurement_quotation_items", + "tableTo": "procurement_vendor_quotations", + "columnsFrom": [ + "quotation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_quotation_items_pr_item_id_pr_items_id_fk": { + "name": "procurement_quotation_items_pr_item_id_pr_items_id_fk", + "tableFrom": "procurement_quotation_items", + "tableTo": "pr_items", + "columnsFrom": [ + "pr_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfq_attachments": { + "name": "procurement_rfq_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "comment_id": { + "name": "comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "quotation_id": { + "name": "quotation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "file_path": { + "name": "file_path", + "type": "varchar(500)", + "primaryKey": false, + "notNull": true + }, + "is_vendor_upload": { + "name": "is_vendor_upload", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfq_attachments_rfq_id_procurement_rfqs_id_fk": { + "name": "procurement_rfq_attachments_rfq_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_comment_id_procurement_rfq_comments_id_fk": { + "name": "procurement_rfq_attachments_comment_id_procurement_rfq_comments_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "procurement_rfq_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_quotation_id_procurement_vendor_quotations_id_fk": { + "name": "procurement_rfq_attachments_quotation_id_procurement_vendor_quotations_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "procurement_vendor_quotations", + "columnsFrom": [ + "quotation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_uploaded_by_users_id_fk": { + "name": "procurement_rfq_attachments_uploaded_by_users_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_vendor_id_vendors_id_fk": { + "name": "procurement_rfq_attachments_vendor_id_vendors_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfq_comments": { + "name": "procurement_rfq_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_vendor_comment": { + "name": "is_vendor_comment", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "is_read": { + "name": "is_read", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "parent_comment_id": { + "name": "parent_comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfq_comments_rfq_id_procurement_rfqs_id_fk": { + "name": "procurement_rfq_comments_rfq_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_comments_vendor_id_vendors_id_fk": { + "name": "procurement_rfq_comments_vendor_id_vendors_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_comments_user_id_users_id_fk": { + "name": "procurement_rfq_comments_user_id_users_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_comments_parent_comment_id_procurement_rfq_comments_id_fk": { + "name": "procurement_rfq_comments_parent_comment_id_procurement_rfq_comments_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "procurement_rfq_comments", + "columnsFrom": [ + "parent_comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfq_details": { + "name": "procurement_rfq_details", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendors_id": { + "name": "vendors_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_detail": { + "name": "incoterms_detail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "tax_code": { + "name": "tax_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "default": "'VV'" + }, + "place_of_shipping": { + "name": "place_of_shipping", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_destination": { + "name": "place_of_destination", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "material_price_related_yn": { + "name": "material_price_related_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfq_details_procurement_rfqs_id_procurement_rfqs_id_fk": { + "name": "procurement_rfq_details_procurement_rfqs_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "procurement_rfqs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_vendors_id_vendors_id_fk": { + "name": "procurement_rfq_details_vendors_id_vendors_id_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "vendors", + "columnsFrom": [ + "vendors_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_payment_terms_code_payment_terms_code_fk": { + "name": "procurement_rfq_details_payment_terms_code_payment_terms_code_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "payment_terms", + "columnsFrom": [ + "payment_terms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_incoterms_code_incoterms_code_fk": { + "name": "procurement_rfq_details_incoterms_code_incoterms_code_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_updated_by_users_id_fk": { + "name": "procurement_rfq_details_updated_by_users_id_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfqs": { + "name": "procurement_rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "series": { + "name": "series", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "rfq_send_date": { + "name": "rfq_send_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'RFQ Created'" + }, + "rfq_sealed_yn": { + "name": "rfq_sealed_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_by": { + "name": "sent_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfqs_project_id_projects_id_fk": { + "name": "procurement_rfqs_project_id_projects_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfqs_sent_by_users_id_fk": { + "name": "procurement_rfqs_sent_by_users_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "users", + "columnsFrom": [ + "sent_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfqs_created_by_users_id_fk": { + "name": "procurement_rfqs_created_by_users_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfqs_updated_by_users_id_fk": { + "name": "procurement_rfqs_updated_by_users_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "procurement_rfqs_rfq_code_unique": { + "name": "procurement_rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_vendor_quotations": { + "name": "procurement_vendor_quotations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "quotation_code": { + "name": "quotation_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "quotation_version": { + "name": "quotation_version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "total_items_count": { + "name": "total_items_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "sub_total": { + "name": "sub_total", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "tax_total": { + "name": "tax_total", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "discount_total": { + "name": "discount_total", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "total_price": { + "name": "total_price", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "valid_until": { + "name": "valid_until", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "estimated_delivery_date": { + "name": "estimated_delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_detail": { + "name": "incoterms_detail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'Draft'" + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rejection_reason": { + "name": "rejection_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_vendor_quotations_rfq_id_procurement_rfqs_id_fk": { + "name": "procurement_vendor_quotations_rfq_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_vendor_quotations_vendor_id_vendors_id_fk": { + "name": "procurement_vendor_quotations_vendor_id_vendors_id_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_vendor_quotations_payment_terms_code_payment_terms_code_fk": { + "name": "procurement_vendor_quotations_payment_terms_code_payment_terms_code_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "payment_terms", + "columnsFrom": [ + "payment_terms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_vendor_quotations_incoterms_code_incoterms_code_fk": { + "name": "procurement_vendor_quotations_incoterms_code_incoterms_code_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.preset_shares": { + "name": "preset_shares", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "preset_id": { + "name": "preset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "shared_with_user_id": { + "name": "shared_with_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "permission": { + "name": "permission", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'read'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "preset_shares_preset_id_table_presets_id_fk": { + "name": "preset_shares_preset_id_table_presets_id_fk", + "tableFrom": "preset_shares", + "tableTo": "table_presets", + "columnsFrom": [ + "preset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.table_presets": { + "name": "table_presets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "settings": { + "name": "settings", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "is_default": { + "name": "is_default", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_shared": { + "name": "is_shared", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_attachments": { + "name": "tech_sales_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "tech_sales_rfq_id": { + "name": "tech_sales_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_attachments_tech_sales_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_attachments_tech_sales_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_attachments", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "tech_sales_rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_attachments_created_by_users_id_fk": { + "name": "tech_sales_attachments_created_by_users_id_fk", + "tableFrom": "tech_sales_attachments", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_rfq_comment_attachments": { + "name": "tech_sales_rfq_comment_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "comment_id": { + "name": "comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "quotation_id": { + "name": "quotation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "file_path": { + "name": "file_path", + "type": "varchar(500)", + "primaryKey": false, + "notNull": true + }, + "is_vendor_upload": { + "name": "is_vendor_upload", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_rfq_comment_attachments_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_rfq_comment_attachments_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_comment_id_tech_sales_rfq_comments_id_fk": { + "name": "tech_sales_rfq_comment_attachments_comment_id_tech_sales_rfq_comments_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "tech_sales_rfq_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_quotation_id_tech_sales_vendor_quotations_id_fk": { + "name": "tech_sales_rfq_comment_attachments_quotation_id_tech_sales_vendor_quotations_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "tech_sales_vendor_quotations", + "columnsFrom": [ + "quotation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_uploaded_by_users_id_fk": { + "name": "tech_sales_rfq_comment_attachments_uploaded_by_users_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_vendor_id_vendors_id_fk": { + "name": "tech_sales_rfq_comment_attachments_vendor_id_vendors_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_rfq_comments": { + "name": "tech_sales_rfq_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_vendor_comment": { + "name": "is_vendor_comment", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "is_read": { + "name": "is_read", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "parent_comment_id": { + "name": "parent_comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_rfq_comments_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_rfq_comments_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comments_vendor_id_vendors_id_fk": { + "name": "tech_sales_rfq_comments_vendor_id_vendors_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfq_comments_user_id_users_id_fk": { + "name": "tech_sales_rfq_comments_user_id_users_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfq_comments_parent_comment_id_tech_sales_rfq_comments_id_fk": { + "name": "tech_sales_rfq_comments_parent_comment_id_tech_sales_rfq_comments_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "tech_sales_rfq_comments", + "columnsFrom": [ + "parent_comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_rfqs": { + "name": "tech_sales_rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "item_shipbuilding_id": { + "name": "item_shipbuilding_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "bidding_project_id": { + "name": "bidding_project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "material_code": { + "name": "material_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "rfq_send_date": { + "name": "rfq_send_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'RFQ Created'" + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_by": { + "name": "sent_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_snapshot": { + "name": "project_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "series_snapshot": { + "name": "series_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_rfqs_item_shipbuilding_id_item_shipbuilding_id_fk": { + "name": "tech_sales_rfqs_item_shipbuilding_id_item_shipbuilding_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "item_shipbuilding", + "columnsFrom": [ + "item_shipbuilding_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfqs_bidding_project_id_bidding_projects_id_fk": { + "name": "tech_sales_rfqs_bidding_project_id_bidding_projects_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "bidding_projects", + "columnsFrom": [ + "bidding_project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfqs_sent_by_users_id_fk": { + "name": "tech_sales_rfqs_sent_by_users_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "users", + "columnsFrom": [ + "sent_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfqs_created_by_users_id_fk": { + "name": "tech_sales_rfqs_created_by_users_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfqs_updated_by_users_id_fk": { + "name": "tech_sales_rfqs_updated_by_users_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "tech_sales_rfqs_rfq_code_unique": { + "name": "tech_sales_rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_vendor_quotations": { + "name": "tech_sales_vendor_quotations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "quotation_code": { + "name": "quotation_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "quotation_version": { + "name": "quotation_version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "total_price": { + "name": "total_price", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "valid_until": { + "name": "valid_until", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'Draft'" + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rejection_reason": { + "name": "rejection_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_vendor_quotations_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_vendor_quotations_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_vendor_quotations", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_vendor_quotations_vendor_id_vendors_id_fk": { + "name": "tech_sales_vendor_quotations_vendor_id_vendors_id_fk", + "tableFrom": "tech_sales_vendor_quotations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_rotation_attempts": { + "name": "ocr_rotation_attempts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "rotation": { + "name": "rotation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "confidence": { + "name": "confidence", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "tables_found": { + "name": "tables_found", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "text_quality": { + "name": "text_quality", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "keyword_count": { + "name": "keyword_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "score": { + "name": "score", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "extracted_rows_count": { + "name": "extracted_rows_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "ocr_rotation_attempts_session_id_ocr_sessions_id_fk": { + "name": "ocr_rotation_attempts_session_id_ocr_sessions_id_fk", + "tableFrom": "ocr_rotation_attempts", + "tableTo": "ocr_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_rows": { + "name": "ocr_rows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "table_id": { + "name": "table_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "row_index": { + "name": "row_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "report_no": { + "name": "report_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "no": { + "name": "no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "identification_no": { + "name": "identification_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tag_no": { + "name": "tag_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "joint_no": { + "name": "joint_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "joint_type": { + "name": "joint_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "welding_date": { + "name": "welding_date", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "source_table": { + "name": "source_table", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "source_row": { + "name": "source_row", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_ocr_report_no_unique": { + "name": "idx_ocr_report_no_unique", + "columns": [ + { + "expression": "report_no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tag_no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "joint_no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "joint_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "ocr_rows_table_id_ocr_tables_id_fk": { + "name": "ocr_rows_table_id_ocr_tables_id_fk", + "tableFrom": "ocr_rows", + "tableTo": "ocr_tables", + "columnsFrom": [ + "table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ocr_rows_session_id_ocr_sessions_id_fk": { + "name": "ocr_rows_session_id_ocr_sessions_id_fk", + "tableFrom": "ocr_rows", + "tableTo": "ocr_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ocr_rows_user_id_users_id_fk": { + "name": "ocr_rows_user_id_users_id_fk", + "tableFrom": "ocr_rows", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_sessions": { + "name": "ocr_sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "processing_time": { + "name": "processing_time", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "best_rotation": { + "name": "best_rotation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_tables": { + "name": "total_tables", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_rows": { + "name": "total_rows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "image_enhanced": { + "name": "image_enhanced", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "pdf_converted": { + "name": "pdf_converted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "success": { + "name": "success", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "warnings": { + "name": "warnings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_tables": { + "name": "ocr_tables", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "table_index": { + "name": "table_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "row_count": { + "name": "row_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "ocr_tables_session_id_ocr_sessions_id_fk": { + "name": "ocr_tables_session_id_ocr_sessions_id_fk", + "tableFrom": "ocr_tables", + "tableTo": "ocr_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.b_rfq_attachment_revisions": { + "name": "b_rfq_attachment_revisions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_id": { + "name": "attachment_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "revision_no": { + "name": "revision_no", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true + }, + "revision_comment": { + "name": "revision_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_latest": { + "name": "is_latest", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "latest_revision_idx": { + "name": "latest_revision_idx", + "columns": [ + { + "expression": "attachment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "is_latest", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"b_rfq_attachment_revisions\".\"is_latest\" = $1", + "concurrently": false, + "method": "btree", + "with": {} + }, + "attachment_revision_idx": { + "name": "attachment_revision_idx", + "columns": [ + { + "expression": "attachment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "revision_no", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "b_rfq_attachment_revisions_attachment_id_b_rfq_attachments_id_fk": { + "name": "b_rfq_attachment_revisions_attachment_id_b_rfq_attachments_id_fk", + "tableFrom": "b_rfq_attachment_revisions", + "tableTo": "b_rfq_attachments", + "columnsFrom": [ + "attachment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "b_rfq_attachment_revisions_created_by_users_id_fk": { + "name": "b_rfq_attachment_revisions_created_by_users_id_fk", + "tableFrom": "b_rfq_attachment_revisions", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.b_rfqs": { + "name": "b_rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pic_name": { + "name": "pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "eng_pic_name": { + "name": "eng_pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_company": { + "name": "project_company", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_flag": { + "name": "project_flag", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_site": { + "name": "project_site", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "package_no": { + "name": "package_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_name": { + "name": "package_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "b_rfqs_project_id_projects_id_fk": { + "name": "b_rfqs_project_id_projects_id_fk", + "tableFrom": "b_rfqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "b_rfqs_created_by_users_id_fk": { + "name": "b_rfqs_created_by_users_id_fk", + "tableFrom": "b_rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "b_rfqs_updated_by_users_id_fk": { + "name": "b_rfqs_updated_by_users_id_fk", + "tableFrom": "b_rfqs", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "b_rfqs_rfq_code_unique": { + "name": "b_rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.b_rfq_attachments": { + "name": "b_rfq_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "serial_no": { + "name": "serial_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "current_revision": { + "name": "current_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "default": "'Rev.0'" + }, + "latest_revision_id": { + "name": "latest_revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "b_rfq_attachments_rfq_id_b_rfqs_id_fk": { + "name": "b_rfq_attachments_rfq_id_b_rfqs_id_fk", + "tableFrom": "b_rfq_attachments", + "tableTo": "b_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "b_rfq_attachments_created_by_users_id_fk": { + "name": "b_rfq_attachments_created_by_users_id_fk", + "tableFrom": "b_rfq_attachments", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.final_rfq": { + "name": "final_rfq", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "final_rfq_status": { + "name": "final_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'KRW'" + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "tax_code": { + "name": "tax_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "default": "'VV'" + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "place_of_shipping": { + "name": "place_of_shipping", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_destination": { + "name": "place_of_destination", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "firsttime_yn": { + "name": "firsttime_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "material_price_related_yn": { + "name": "material_price_related_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vendor_remark": { + "name": "vendor_remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "final_rfq_rfq_id_b_rfqs_id_fk": { + "name": "final_rfq_rfq_id_b_rfqs_id_fk", + "tableFrom": "final_rfq", + "tableTo": "b_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "final_rfq_vendor_id_vendors_id_fk": { + "name": "final_rfq_vendor_id_vendors_id_fk", + "tableFrom": "final_rfq", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "final_rfq_incoterms_code_incoterms_code_fk": { + "name": "final_rfq_incoterms_code_incoterms_code_fk", + "tableFrom": "final_rfq", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "final_rfq_payment_terms_code_payment_terms_code_fk": { + "name": "final_rfq_payment_terms_code_payment_terms_code_fk", + "tableFrom": "final_rfq", + "tableTo": "payment_terms", + "columnsFrom": [ + "payment_terms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.initial_rfq": { + "name": "initial_rfq", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "initial_rfq_status": { + "name": "initial_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "initial_rfq_rfq_id_b_rfqs_id_fk": { + "name": "initial_rfq_rfq_id_b_rfqs_id_fk", + "tableFrom": "initial_rfq", + "tableTo": "b_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "initial_rfq_vendor_id_vendors_id_fk": { + "name": "initial_rfq_vendor_id_vendors_id_fk", + "tableFrom": "initial_rfq", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "initial_rfq_incoterms_code_incoterms_code_fk": { + "name": "initial_rfq_incoterms_code_incoterms_code_fk", + "tableFrom": "initial_rfq", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_attachment_responses": { + "name": "vendor_attachment_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_id": { + "name": "attachment_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "rfq_type": { + "name": "rfq_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "rfq_record_id": { + "name": "rfq_record_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'NOT_RESPONDED'" + }, + "current_revision": { + "name": "current_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'Rev.0'" + }, + "responded_revision": { + "name": "responded_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "response_comment": { + "name": "response_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vendor_comment": { + "name": "vendor_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "responded_at": { + "name": "responded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "vendor_response_idx": { + "name": "vendor_response_idx", + "columns": [ + { + "expression": "attachment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "rfq_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "vendor_attachment_responses_attachment_id_b_rfq_attachments_id_fk": { + "name": "vendor_attachment_responses_attachment_id_b_rfq_attachments_id_fk", + "tableFrom": "vendor_attachment_responses", + "tableTo": "b_rfq_attachments", + "columnsFrom": [ + "attachment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_attachment_responses_vendor_id_vendors_id_fk": { + "name": "vendor_attachment_responses_vendor_id_vendors_id_fk", + "tableFrom": "vendor_attachment_responses", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_response_attachments_b": { + "name": "vendor_response_attachments_b", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_response_id": { + "name": "vendor_response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_response_attachments_b_vendor_response_id_vendor_attachment_responses_id_fk": { + "name": "vendor_response_attachments_b_vendor_response_id_vendor_attachment_responses_id_fk", + "tableFrom": "vendor_response_attachments_b", + "tableTo": "vendor_attachment_responses", + "columnsFrom": [ + "vendor_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_attachments_b_uploaded_by_users_id_fk": { + "name": "vendor_response_attachments_b_uploaded_by_users_id_fk", + "tableFrom": "vendor_response_attachments_b", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_response_history": { + "name": "vendor_response_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_response_id": { + "name": "vendor_response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "previous_status": { + "name": "previous_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "new_status": { + "name": "new_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_by": { + "name": "action_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "action_at": { + "name": "action_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_response_history_vendor_response_id_vendor_attachment_responses_id_fk": { + "name": "vendor_response_history_vendor_response_id_vendor_attachment_responses_id_fk", + "tableFrom": "vendor_response_history", + "tableTo": "vendor_attachment_responses", + "columnsFrom": [ + "vendor_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_history_action_by_users_id_fk": { + "name": "vendor_response_history_action_by_users_id_fk", + "tableFrom": "vendor_response_history", + "tableTo": "users", + "columnsFrom": [ + "action_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.offshore_hull_work_type": { + "name": "offshore_hull_work_type", + "schema": "public", + "values": [ + "HA", + "HE", + "HH", + "HM", + "NC" + ] + }, + "public.offshore_top_work_type": { + "name": "offshore_top_work_type", + "schema": "public", + "values": [ + "TM", + "TS", + "TE", + "TP" + ] + }, + "public.work_type": { + "name": "work_type", + "schema": "public", + "values": [ + "기장", + "전장", + "선실", + "배관", + "철의" + ] + }, + "public.user_domain": { + "name": "user_domain", + "schema": "public", + "values": [ + "evcp", + "partners" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": { + "public.contracts_detail_view": { + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contracts_detail_view_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "contract_name": { + "name": "contract_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "payment_terms": { + "name": "payment_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'KRW'" + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "partial_shipping_allowed": { + "name": "partial_shipping_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "partial_payment_allowed": { + "name": "partial_payment_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "remarks": { + "name": "remarks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"contracts\".\"id\", \"contracts\".\"contract_no\", \"contracts\".\"contract_name\", \"contracts\".\"status\", \"contracts\".\"start_date\", \"contracts\".\"end_date\", \"contracts\".\"project_id\", \"projects\".\"code\", \"projects\".\"name\", \"contracts\".\"vendor_id\", \"vendors\".\"vendor_name\", \"contracts\".\"payment_terms\", \"contracts\".\"delivery_terms\", \"contracts\".\"delivery_date\", \"contracts\".\"delivery_location\", \"contracts\".\"currency\", \"contracts\".\"total_amount\", \"contracts\".\"discount\", \"contracts\".\"tax\", \"contracts\".\"shipping_fee\", \"contracts\".\"net_total\", \"contracts\".\"partial_shipping_allowed\", \"contracts\".\"partial_payment_allowed\", \"contracts\".\"remarks\", \"contracts\".\"version\", \"contracts\".\"created_at\", \"contracts\".\"updated_at\", EXISTS (\n SELECT 1 \n FROM \"contract_envelopes\" \n WHERE \"contract_envelopes\".\"contract_id\" = \"contracts\".\"id\"\n ) as \"has_signature\", COALESCE((\n SELECT json_agg(\n json_build_object(\n 'id', ci.id,\n 'itemId', ci.item_id,\n 'description', ci.description,\n 'quantity', ci.quantity,\n 'unitPrice', ci.unit_price,\n 'taxRate', ci.tax_rate,\n 'taxAmount', ci.tax_amount,\n 'totalLineAmount', ci.total_line_amount,\n 'remark', ci.remark,\n 'createdAt', ci.created_at,\n 'updatedAt', ci.updated_at\n )\n )\n FROM \"contract_items\" AS ci\n WHERE ci.contract_id = \"contracts\".\"id\"\n ), '[]') as \"items\", COALESCE((\n SELECT json_agg(\n json_build_object(\n 'id', ce.id,\n 'envelopeId', ce.envelope_id,\n 'documentId', ce.document_id,\n 'envelopeStatus', ce.envelope_status,\n 'fileName', ce.file_name,\n 'filePath', ce.file_path,\n 'createdAt', ce.created_at,\n 'updatedAt', ce.updated_at,\n 'signers', (\n SELECT json_agg(\n json_build_object(\n 'id', cs.id,\n 'vendorContactId', cs.vendor_contact_id,\n 'signerType', cs.signer_type,\n 'signerEmail', cs.signer_email,\n 'signerName', cs.signer_name,\n 'signerPosition', cs.signer_position,\n 'signerStatus', cs.signer_status,\n 'signedAt', cs.signed_at\n )\n )\n FROM \"contract_signers\" AS cs\n WHERE cs.envelope_id = ce.id\n )\n )\n )\n FROM \"contract_envelopes\" AS ce\n WHERE ce.contract_id = \"contracts\".\"id\"\n ), '[]') as \"envelopes\" from \"contracts\" left join \"projects\" on \"contracts\".\"project_id\" = \"projects\".\"id\" left join \"vendors\" on \"contracts\".\"vendor_id\" = \"vendors\".\"id\"", + "name": "contracts_detail_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.poa_detail_view": { + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "poa_detail_view_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "change_reason": { + "name": "change_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approval_status": { + "name": "approval_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'PENDING'" + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"poa\".\"id\", \"poa\".\"contract_no\", \"contracts\".\"project_id\", \"contracts\".\"vendor_id\", \"poa\".\"change_reason\", \"poa\".\"approval_status\", \"contracts\".\"contract_name\" as \"original_contract_name\", \"contracts\".\"status\" as \"original_status\", \"contracts\".\"start_date\" as \"original_start_date\", \"contracts\".\"end_date\" as \"original_end_date\", \"poa\".\"delivery_terms\", \"poa\".\"delivery_date\", \"poa\".\"delivery_location\", \"poa\".\"currency\", \"poa\".\"total_amount\", \"poa\".\"discount\", \"poa\".\"tax\", \"poa\".\"shipping_fee\", \"poa\".\"net_total\", \"poa\".\"created_at\", \"poa\".\"updated_at\", EXISTS (\n SELECT 1 \n FROM \"contract_envelopes\" \n WHERE \"contract_envelopes\".\"contract_id\" = \"poa\".\"id\"\n ) as \"has_signature\" from \"poa\" left join \"contracts\" on \"poa\".\"contract_no\" = \"contracts\".\"contract_no\"", + "name": "poa_detail_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.project_approved_vendors": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING_REVIEW'" + }, + "name_ko": { + "name": "name_ko", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "name_en": { + "name": "name_en", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'ship'" + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"vendors\".\"id\", \"vendors\".\"vendor_name\", \"vendors\".\"vendor_code\", \"vendors\".\"tax_id\", \"vendors\".\"email\", \"vendors\".\"phone\", \"vendors\".\"status\", \"vendor_types\".\"name_ko\", \"vendor_types\".\"name_en\", \"projects\".\"code\", \"projects\".\"name\", \"projects\".\"type\", \"vendor_pq_submissions\".\"submitted_at\", \"vendor_pq_submissions\".\"approved_at\" from \"vendors\" inner join \"vendor_pq_submissions\" on \"vendor_pq_submissions\".\"vendor_id\" = \"vendors\".\"id\" inner join \"projects\" on \"vendor_pq_submissions\".\"project_id\" = \"projects\".\"id\" left join \"vendor_types\" on \"vendors\".\"vendor_type_id\" = \"vendor_types\".\"id\" where \"vendor_pq_submissions\".\"status\" = 'APPROVED'", + "name": "project_approved_vendors", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_investigations_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pq_submission_id": { + "name": "pq_submission_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requester_id": { + "name": "requester_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "qm_manager_id": { + "name": "qm_manager_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "investigation_status": { + "name": "investigation_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'PLANNED'" + }, + "evaluation_type": { + "name": "evaluation_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_address": { + "name": "investigation_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "investigation_method": { + "name": "investigation_method", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "scheduled_start_at": { + "name": "scheduled_start_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scheduled_end_at": { + "name": "scheduled_end_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "forecasted_at": { + "name": "forecasted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "evaluation_score": { + "name": "evaluation_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluation_result": { + "name": "evaluation_result", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_notes": { + "name": "investigation_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"vendor_investigations\".\"id\", \"vendor_investigations\".\"vendor_id\", \"vendor_investigations\".\"pq_submission_id\", \"vendor_investigations\".\"requester_id\", \"vendor_investigations\".\"qm_manager_id\", \"vendor_investigations\".\"investigation_status\", \"vendor_investigations\".\"evaluation_type\", \"vendor_investigations\".\"investigation_address\", \"vendor_investigations\".\"investigation_method\", \"vendor_investigations\".\"scheduled_start_at\", \"vendor_investigations\".\"scheduled_end_at\", \"vendor_investigations\".\"forecasted_at\", \"vendor_investigations\".\"requested_at\", \"vendor_investigations\".\"confirmed_at\", \"vendor_investigations\".\"completed_at\", \"vendor_investigations\".\"evaluation_score\", \"vendor_investigations\".\"evaluation_result\", \"vendor_investigations\".\"investigation_notes\", \"vendor_investigations\".\"created_at\", \"vendor_investigations\".\"updated_at\", \"vendors\".\"vendor_name\", \"vendors\".\"vendor_code\", requester.name as \"requesterName\", requester.email as \"requesterEmail\", qm_manager.name as \"qmManagerName\", qm_manager.email as \"qmManagerEmail\", (\n CASE \n WHEN EXISTS (\n SELECT 1 FROM vendor_investigation_attachments via \n WHERE via.investigation_id = \"vendor_investigations\".\"id\"\n ) \n THEN true \n ELSE false \n END\n ) as \"hasAttachments\" from \"vendor_investigations\" left join \"vendors\" on \"vendor_investigations\".\"vendor_id\" = \"vendors\".\"id\" left join users AS requester on \"vendor_investigations\".\"requester_id\" = requester.id left join users AS qm_manager on \"vendor_investigations\".\"qm_manager_id\" = qm_manager.id", + "name": "vendor_investigations_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.cbe_view": { + "columns": {}, + "definition": "select \"cbe_evaluations\".\"id\" as \"cbe_id\", \"cbe_evaluations\".\"rfq_id\" as \"rfq_id\", \"cbe_evaluations\".\"vendor_id\" as \"vendor_id\", \"cbe_evaluations\".\"total_cost\" as \"total_cost\", \"cbe_evaluations\".\"currency\" as \"currency\", \"cbe_evaluations\".\"payment_terms\" as \"payment_terms\", \"cbe_evaluations\".\"incoterms\" as \"incoterms\", \"cbe_evaluations\".\"result\" as \"result\", \"cbe_evaluations\".\"notes\" as \"notes\", \"cbe_evaluations\".\"evaluated_by\" as \"evaluated_by\", \"cbe_evaluations\".\"evaluated_at\" as \"evaluated_at\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"rfq_description\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"users\".\"name\" as \"evaluator_name\", \"users\".\"email\" as \"evaluator_email\" from \"cbe_evaluations\" inner join \"rfqs\" on \"cbe_evaluations\".\"rfq_id\" = \"rfqs\".\"id\" inner join \"vendors\" on \"cbe_evaluations\".\"vendor_id\" = \"vendors\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"users\" on \"cbe_evaluations\".\"evaluated_by\" = \"users\".\"id\"", + "name": "cbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.rfqs_view": { + "columns": {}, + "definition": "select \"rfqs\".\"id\" as \"rfq_id\", \"rfqs\".\"status\" as \"status\", \"rfqs\".\"created_at\" as \"created_at\", \"rfqs\".\"updated_at\" as \"updated_at\", \"rfqs\".\"created_by\" as \"created_by\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"rfqs\".\"parent_rfq_id\" as \"parent_rfq_id\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"users\".\"email\" as \"user_email\", \"users\".\"name\" as \"user_name\", (\n SELECT COUNT(*) \n FROM \"rfq_items\" \n WHERE \"rfq_items\".\"rfq_id\" = \"rfqs\".\"id\"\n ) as \"item_count\", (\n SELECT COUNT(*) \n FROM \"rfq_attachments\" \n WHERE \"rfq_attachments\".\"rfq_id\" = \"rfqs\".\"id\"\n ) as \"attachment_count\" from \"rfqs\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"users\" on \"rfqs\".\"created_by\" = \"users\".\"id\"", + "name": "rfqs_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_cbe_view": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"email\" as \"email\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"vendor_status\", \"vendor_responses\".\"id\" as \"vendor_response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"response_status\" as \"rfq_vendor_status\", \"vendor_responses\".\"updated_at\" as \"rfq_vendor_updated\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"cbe_evaluations\".\"id\" as \"cbe_id\", \"cbe_evaluations\".\"result\" as \"cbe_result\", \"cbe_evaluations\".\"notes\" as \"cbe_note\", \"cbe_evaluations\".\"updated_at\" as \"cbe_updated\", \"cbe_evaluations\".\"total_cost\" as \"total_cost\", \"cbe_evaluations\".\"currency\" as \"currency\", \"cbe_evaluations\".\"payment_terms\" as \"payment_terms\", \"cbe_evaluations\".\"incoterms\" as \"incoterms\", \"cbe_evaluations\".\"delivery_schedule\" as \"delivery_schedule\" from \"vendors\" left join \"vendor_responses\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"cbe_evaluations\" on (\"cbe_evaluations\".\"vendor_id\" = \"vendors\".\"id\" and \"cbe_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\")", + "name": "vendor_cbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_response_cbe_view": { + "columns": {}, + "definition": "select \"vendor_responses\".\"id\" as \"response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"vendor_id\" as \"vendor_id\", \"vendor_responses\".\"response_status\" as \"response_status\", \"vendor_responses\".\"notes\" as \"response_notes\", \"vendor_responses\".\"responded_by\" as \"responded_by\", \"vendor_responses\".\"responded_at\" as \"responded_at\", \"vendor_responses\".\"updated_at\" as \"response_updated_at\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"rfq_description\", \"rfqs\".\"due_date\" as \"rfq_due_date\", \"rfqs\".\"status\" as \"rfq_status\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"status\" as \"vendor_status\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"vendor_commercial_responses\".\"id\" as \"commercial_response_id\", \"vendor_commercial_responses\".\"response_status\" as \"commercial_response_status\", \"vendor_commercial_responses\".\"total_price\" as \"total_price\", \"vendor_commercial_responses\".\"currency\" as \"currency\", \"vendor_commercial_responses\".\"payment_terms\" as \"payment_terms\", \"vendor_commercial_responses\".\"incoterms\" as \"incoterms\", \"vendor_commercial_responses\".\"delivery_period\" as \"delivery_period\", \"vendor_commercial_responses\".\"warranty_period\" as \"warranty_period\", \"vendor_commercial_responses\".\"validity_period\" as \"validity_period\", \"vendor_commercial_responses\".\"price_breakdown\" as \"price_breakdown\", \"vendor_commercial_responses\".\"commercial_notes\" as \"commercial_notes\", \"vendor_commercial_responses\".\"created_at\" as \"commercial_created_at\", \"vendor_commercial_responses\".\"updated_at\" as \"commercial_updated_at\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n ) as \"attachment_count\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"commercial_response_id\" = \"vendor_commercial_responses\".\"id\"\n ) as \"commercial_attachment_count\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n AND \"vendor_response_attachments\".\"attachment_type\" = 'TECHNICAL_SPEC'\n ) as \"technical_attachment_count\", (\n SELECT MAX(\"uploaded_at\") \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n ) as \"latest_attachment_date\" from \"vendor_responses\" inner join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" inner join \"vendors\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendor_commercial_responses\" on \"vendor_commercial_responses\".\"response_id\" = \"vendor_responses\".\"id\"", + "name": "vendor_response_cbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_responses_view": { + "columns": {}, + "definition": "select \"vendor_responses\".\"id\" as \"response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"vendor_id\" as \"vendor_id\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"rfq_description\", \"rfqs\".\"due_date\" as \"rfq_due_date\", \"rfqs\".\"status\" as \"rfq_status\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"created_at\" as \"rfq_created_at\", \"rfqs\".\"updated_at\" as \"rfq_updated_at\", \"rfqs\".\"created_by\" as \"rfq_created_by\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendor_responses\".\"response_status\" as \"response_status\", \"vendor_responses\".\"responded_at\" as \"responded_at\", CASE WHEN \"vendor_technical_responses\".\"id\" IS NOT NULL THEN TRUE ELSE FALSE END as \"has_technical_response\", \"vendor_technical_responses\".\"id\" as \"technical_response_id\", CASE WHEN \"vendor_commercial_responses\".\"id\" IS NOT NULL THEN TRUE ELSE FALSE END as \"has_commercial_response\", \"vendor_commercial_responses\".\"id\" as \"commercial_response_id\", \"vendor_commercial_responses\".\"total_price\" as \"total_price\", \"vendor_commercial_responses\".\"currency\" as \"currency\", \"rfq_evaluations\".\"id\" as \"tbe_id\", \"rfq_evaluations\".\"result\" as \"tbe_result\", \"cbe_evaluations\".\"id\" as \"cbe_id\", \"cbe_evaluations\".\"result\" as \"cbe_result\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n ) as \"attachment_count\" from \"vendor_responses\" inner join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" inner join \"vendors\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendor_technical_responses\" on \"vendor_technical_responses\".\"response_id\" = \"vendor_responses\".\"id\" left join \"vendor_commercial_responses\" on \"vendor_commercial_responses\".\"response_id\" = \"vendor_responses\".\"id\" left join \"rfq_evaluations\" on (\"rfq_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\" and \"rfq_evaluations\".\"vendor_id\" = \"vendor_responses\".\"vendor_id\" and \"rfq_evaluations\".\"eval_type\" = 'TBE') left join \"cbe_evaluations\" on (\"cbe_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\" and \"cbe_evaluations\".\"vendor_id\" = \"vendor_responses\".\"vendor_id\")", + "name": "vendor_responses_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_rfq_view": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"email\" as \"email\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"vendor_status\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"response_status\" as \"rfq_vendor_status\", \"vendor_responses\".\"updated_at\" as \"rfq_vendor_updated\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\" from \"vendors\" left join \"vendor_responses\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\"", + "name": "vendor_rfq_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_tbe_view": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"email\" as \"email\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"vendor_status\", \"vendor_responses\".\"id\" as \"vendor_response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"response_status\" as \"rfq_vendor_status\", \"vendor_responses\".\"updated_at\" as \"rfq_vendor_updated\", \"vendor_technical_responses\".\"id\" as \"technical_response_id\", \"vendor_technical_responses\".\"response_status\" as \"technical_response_status\", \"vendor_technical_responses\".\"summary\" as \"technical_summary\", \"vendor_technical_responses\".\"notes\" as \"technical_notes\", \"vendor_technical_responses\".\"updated_at\" as \"technical_updated\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"status\" as \"rfq_status\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"rfq_evaluations\".\"id\" as \"tbe_id\", \"rfq_evaluations\".\"result\" as \"tbe_result\", \"rfq_evaluations\".\"notes\" as \"tbe_note\", \"rfq_evaluations\".\"updated_at\" as \"tbe_updated\" from \"vendors\" left join \"vendor_responses\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendor_technical_responses\" on \"vendor_technical_responses\".\"response_id\" = \"vendor_responses\".\"id\" left join \"rfq_evaluations\" on (\"rfq_evaluations\".\"vendor_id\" = \"vendors\".\"id\" and \"rfq_evaluations\".\"eval_type\" = 'TBE' and \"rfq_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\")", + "name": "vendor_tbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.role_view": { + "columns": {}, + "definition": "select \"roles\".\"id\" as \"id\", \"roles\".\"name\" as \"name\", \"roles\".\"description\" as \"description\", \"roles\".\"domain\" as \"domain\", \"roles\".\"created_at\" as \"created_at\", \"vendors\".\"id\" as \"company_id\", \"vendors\".\"vendor_name\" as \"company_name\", COUNT(\"users\".\"id\") as \"user_count\" from \"roles\" left join \"user_roles\" on \"user_roles\".\"role_id\" = \"roles\".\"id\" left join \"users\" on \"users\".\"id\" = \"user_roles\".\"user_id\" left join \"vendors\" on \"roles\".\"company_id\" = \"vendors\".\"id\" group by \"roles\".\"id\", \"vendors\".\"id\"", + "name": "role_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.user_view": { + "columns": {}, + "definition": "select \"users\".\"id\" as \"user_id\", \"users\".\"name\" as \"user_name\", \"users\".\"email\" as \"user_email\", \"users\".\"domain\" as \"user_domain\", \"users\".\"image_url\" as \"user_image\", \"vendors\".\"id\" as \"company_id\", \"vendors\".\"vendor_name\" as \"company_name\", \n array_agg(\"roles\".\"name\")\n as \"roles\", \"users\".\"created_at\" as \"created_at\" from \"users\" left join \"vendors\" on \"users\".\"company_id\" = \"vendors\".\"id\" left join \"user_roles\" on \"users\".\"id\" = \"user_roles\".\"user_id\" left join \"roles\" on \"user_roles\".\"role_id\" = \"roles\".\"id\" group by \"users\".\"id\", \"vendors\".\"id\"", + "name": "user_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.form_lists_view": { + "columns": {}, + "definition": "select \"tag_type_class_form_mappings\".\"id\" as \"id\", \"tag_type_class_form_mappings\".\"project_id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"tag_type_class_form_mappings\".\"tag_type_label\" as \"tag_type_label\", \"tag_type_class_form_mappings\".\"class_label\" as \"class_label\", \"tag_type_class_form_mappings\".\"form_code\" as \"form_code\", \"tag_type_class_form_mappings\".\"form_name\" as \"form_name\", \"tag_type_class_form_mappings\".\"ep\" as \"ep\", \"tag_type_class_form_mappings\".\"remark\" as \"remark\", \"tag_type_class_form_mappings\".\"created_at\" as \"created_at\", \"tag_type_class_form_mappings\".\"updated_at\" as \"updated_at\" from \"tag_type_class_form_mappings\" inner join \"projects\" on \"tag_type_class_form_mappings\".\"project_id\" = \"projects\".\"id\"", + "name": "form_lists_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.view_tag_subfields": { + "columns": { + "tag_type_code": { + "name": "tag_type_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "attributes_id": { + "name": "attributes_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "attributes_description": { + "name": "attributes_description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expression": { + "name": "expression", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delimiter": { + "name": "delimiter", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "definition": "select \"tag_subfields\".\"id\" as \"id\", \"tag_subfields\".\"tag_type_code\", \"tag_types\".\"description\", \"tag_subfields\".\"attributes_id\", \"tag_subfields\".\"attributes_description\", \"tag_subfields\".\"expression\", \"tag_subfields\".\"delimiter\", \"tag_subfields\".\"sort_order\", \"tag_subfields\".\"created_at\", \"tag_subfields\".\"updated_at\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\", \"projects\".\"name\" from \"tag_subfields\" inner join \"tag_types\" on (\"tag_subfields\".\"tag_type_code\" = \"tag_types\".\"code\" and \"tag_subfields\".\"project_id\" = \"tag_types\".\"project_id\") inner join \"projects\" on \"tag_subfields\".\"project_id\" = \"projects\".\"id\"", + "name": "view_tag_subfields", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.document_stages_view": { + "columns": { + "document_id": { + "name": "document_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stage_count": { + "name": "stage_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stage_list": { + "name": "stage_list", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "definition": "\n SELECT\n d.id AS document_id,\n d.doc_number,\n d.title,\n d.status,\n d.issued_date,\n d.contract_id,\n (SELECT COUNT(*) FROM issue_stages WHERE document_id = d.id) AS stage_count,\n COALESCE( \n (SELECT json_agg(i.stage_name) FROM issue_stages i WHERE i.document_id = d.id), \n '[]'\n ) AS stage_list,\n d.created_at,\n d.updated_at\n FROM documents d\n", + "name": "document_stages_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.enhanced_documents_view": { + "columns": { + "document_id": { + "name": "document_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "drawing_kind": { + "name": "drawing_kind", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_doc_number": { + "name": "vendor_doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "pic": { + "name": "pic", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_code": { + "name": "project_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "c_gbn": { + "name": "c_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "d_gbn": { + "name": "d_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "degree_gbn": { + "name": "degree_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "dept_gbn": { + "name": "dept_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "j_gbn": { + "name": "j_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "s_gbn": { + "name": "s_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "current_stage_id": { + "name": "current_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "current_stage_name": { + "name": "current_stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "current_stage_status": { + "name": "current_stage_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "current_stage_order": { + "name": "current_stage_order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "current_stage_plan_date": { + "name": "current_stage_plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "current_stage_actual_date": { + "name": "current_stage_actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "current_stage_assignee_name": { + "name": "current_stage_assignee_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "current_stage_priority": { + "name": "current_stage_priority", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "days_until_due": { + "name": "days_until_due", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "is_overdue": { + "name": "is_overdue", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "days_difference": { + "name": "days_difference", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "total_stages": { + "name": "total_stages", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "completed_stages": { + "name": "completed_stages", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "progress_percentage": { + "name": "progress_percentage", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_revision_id": { + "name": "latest_revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_revision": { + "name": "latest_revision", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_status": { + "name": "latest_revision_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_uploader_name": { + "name": "latest_revision_uploader_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "latest_submitted_date": { + "name": "latest_submitted_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "all_stages": { + "name": "all_stages", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "attachment_count": { + "name": "attachment_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "definition": "\n WITH document_stats AS (\n SELECT \n d.id as document_id,\n COUNT(ist.id) as total_stages,\n COUNT(CASE WHEN ist.stage_status IN ('COMPLETED', 'APPROVED') THEN 1 END) as completed_stages,\n CASE \n WHEN COUNT(ist.id) > 0 \n THEN ROUND((COUNT(CASE WHEN ist.stage_status IN ('COMPLETED', 'APPROVED') THEN 1 END) * 100.0) / COUNT(ist.id))\n ELSE 0 \n END as progress_percentage\n FROM documents d\n LEFT JOIN issue_stages ist ON d.id = ist.document_id\n GROUP BY d.id\n ),\n current_stage_info AS (\n SELECT DISTINCT ON (document_id)\n document_id,\n id as current_stage_id,\n stage_name as current_stage_name,\n stage_status as current_stage_status,\n stage_order as current_stage_order,\n plan_date as current_stage_plan_date,\n actual_date as current_stage_actual_date,\n assignee_name as current_stage_assignee_name,\n priority as current_stage_priority,\n CASE \n WHEN actual_date IS NULL AND plan_date IS NOT NULL \n THEN plan_date - CURRENT_DATE\n ELSE NULL \n END as days_until_due,\n CASE \n WHEN actual_date IS NULL AND plan_date < CURRENT_DATE \n THEN true\n WHEN actual_date IS NOT NULL AND actual_date > plan_date \n THEN true\n ELSE false \n END as is_overdue,\n CASE \n WHEN actual_date IS NOT NULL AND plan_date IS NOT NULL \n THEN actual_date - plan_date\n ELSE NULL \n END as days_difference\n FROM issue_stages\n WHERE stage_status NOT IN ('COMPLETED', 'APPROVED')\n ORDER BY document_id, stage_order ASC, priority DESC\n ),\n latest_revision_info AS (\n SELECT DISTINCT ON (ist.document_id)\n ist.document_id,\n r.id as latest_revision_id,\n r.revision as latest_revision,\n r.revision_status as latest_revision_status,\n r.uploader_name as latest_revision_uploader_name,\n r.submitted_date as latest_submitted_date\n FROM revisions r\n JOIN issue_stages ist ON r.issue_stage_id = ist.id\n ORDER BY ist.document_id, r.created_at DESC\n ),\n -- 리비전별 첨부파일 집계\n revision_attachments AS (\n SELECT \n r.id as revision_id,\n COALESCE(\n json_agg(\n json_build_object(\n 'id', da.id,\n 'revisionId', da.revision_id,\n 'fileName', da.file_name,\n 'filePath', da.file_path,\n 'fileSize', da.file_size,\n 'fileType', da.file_type,\n 'createdAt', da.created_at,\n 'updatedAt', da.updated_at\n ) ORDER BY da.created_at\n ) FILTER (WHERE da.id IS NOT NULL),\n '[]'::json\n ) as attachments\n FROM revisions r\n LEFT JOIN document_attachments da ON r.id = da.revision_id\n GROUP BY r.id\n ),\n -- 스테이지별 리비전 집계 (첨부파일 포함)\n stage_revisions AS (\n SELECT \n ist.id as stage_id,\n COALESCE(\n json_agg(\n json_build_object(\n 'id', r.id,\n 'issueStageId', r.issue_stage_id,\n 'revision', r.revision,\n 'uploaderType', r.uploader_type,\n 'uploaderId', r.uploader_id,\n 'uploaderName', r.uploader_name,\n 'comment', r.comment,\n 'usage', r.usage,\n 'revisionStatus', r.revision_status,\n 'submittedDate', r.submitted_date,\n 'uploadedAt', r.uploaded_at,\n 'approvedDate', r.approved_date,\n 'reviewStartDate', r.review_start_date,\n 'rejectedDate', r.rejected_date,\n 'reviewerId', r.reviewer_id,\n 'reviewerName', r.reviewer_name,\n 'reviewComments', r.review_comments,\n 'createdAt', r.created_at,\n 'updatedAt', r.updated_at,\n 'attachments', ra.attachments\n ) ORDER BY r.created_at\n ) FILTER (WHERE r.id IS NOT NULL),\n '[]'::json\n ) as revisions\n FROM issue_stages ist\n LEFT JOIN revisions r ON ist.id = r.issue_stage_id\n LEFT JOIN revision_attachments ra ON r.id = ra.revision_id\n GROUP BY ist.id\n ),\n -- 문서별 스테이지 집계 (리비전 포함)\n stage_aggregation AS (\n SELECT \n ist.document_id,\n json_agg(\n json_build_object(\n 'id', ist.id,\n 'stageName', ist.stage_name,\n 'stageStatus', ist.stage_status,\n 'stageOrder', ist.stage_order,\n 'planDate', ist.plan_date,\n 'actualDate', ist.actual_date,\n 'assigneeName', ist.assignee_name,\n 'priority', ist.priority,\n 'revisions', sr.revisions\n ) ORDER BY ist.stage_order\n ) as all_stages\n FROM issue_stages ist\n LEFT JOIN stage_revisions sr ON ist.id = sr.stage_id\n GROUP BY ist.document_id\n ),\n attachment_counts AS (\n SELECT \n ist.document_id,\n COUNT(da.id) as attachment_count\n FROM issue_stages ist\n LEFT JOIN revisions r ON ist.id = r.issue_stage_id\n LEFT JOIN document_attachments da ON r.id = da.revision_id\n GROUP BY ist.document_id\n )\n \n SELECT \n d.id as document_id,\n d.doc_number,\n d.drawing_kind,\n d.vendor_doc_number, -- ✅ 벤더 문서 번호 추가\n d.title,\n d.pic,\n d.status,\n d.issued_date,\n d.contract_id,\n\n d.c_gbn,\n d.d_gbn,\n d.degree_gbn,\n d.dept_gbn,\n d.s_gbn,\n d.j_gbn,\n\n\n \n -- ✅ 프로젝트 및 벤더 정보 추가\n p.code as project_code,\n v.vendor_name as vendor_name,\n v.vendor_code as vendor_code,\n \n -- 현재 스테이지 정보\n csi.current_stage_id,\n csi.current_stage_name,\n csi.current_stage_status,\n csi.current_stage_order,\n csi.current_stage_plan_date,\n csi.current_stage_actual_date,\n csi.current_stage_assignee_name,\n csi.current_stage_priority,\n \n -- 계산 필드\n csi.days_until_due,\n csi.is_overdue,\n csi.days_difference,\n \n -- 진행률 정보\n ds.total_stages,\n ds.completed_stages,\n ds.progress_percentage,\n \n -- 최신 리비전 정보\n lri.latest_revision_id,\n lri.latest_revision,\n lri.latest_revision_status,\n lri.latest_revision_uploader_name,\n lri.latest_submitted_date,\n \n -- 전체 스테이지 (리비전 및 첨부파일 포함)\n COALESCE(sa.all_stages, '[]'::json) as all_stages,\n \n -- 기타\n COALESCE(ac.attachment_count, 0) as attachment_count,\n d.created_at,\n d.updated_at\n \n FROM documents d\n -- ✅ contracts, projects, vendors 테이블 JOIN 추가\n LEFT JOIN contracts c ON d.contract_id = c.id\n LEFT JOIN projects p ON c.project_id = p.id\n LEFT JOIN vendors v ON c.vendor_id = v.id\n \n LEFT JOIN document_stats ds ON d.id = ds.document_id\n LEFT JOIN current_stage_info csi ON d.id = csi.document_id\n LEFT JOIN latest_revision_info lri ON d.id = lri.document_id\n LEFT JOIN stage_aggregation sa ON d.id = sa.document_id\n LEFT JOIN attachment_counts ac ON d.id = ac.document_id\n \n ORDER BY d.created_at DESC\n", + "name": "enhanced_documents_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.sync_status_view": { + "columns": { + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_system": { + "name": "target_system", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "total_changes": { + "name": "total_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pending_changes": { + "name": "pending_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "synced_changes": { + "name": "synced_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "failed_changes": { + "name": "failed_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "next_sync_at": { + "name": "next_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "sync_enabled": { + "name": "sync_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n WITH change_stats AS (\n SELECT \n cl.contract_id,\n sc.target_system,\n COUNT(*) as total_changes,\n COUNT(CASE WHEN cl.is_synced = false AND cl.sync_attempts < sc.retry_max_attempts THEN 1 END) as pending_changes,\n COUNT(CASE WHEN cl.is_synced = true THEN 1 END) as synced_changes,\n COUNT(CASE WHEN cl.sync_attempts >= sc.retry_max_attempts AND cl.is_synced = false THEN 1 END) as failed_changes,\n MAX(cl.synced_at) as last_sync_at\n FROM change_logs cl\n CROSS JOIN sync_configs sc \n WHERE cl.contract_id = sc.contract_id\n AND (cl.target_systems IS NULL OR cl.target_systems @> to_jsonb(sc.target_system))\n GROUP BY cl.contract_id, sc.target_system\n )\n SELECT \n cs.contract_id,\n cs.target_system,\n COALESCE(cs.total_changes, 0) as total_changes,\n COALESCE(cs.pending_changes, 0) as pending_changes,\n COALESCE(cs.synced_changes, 0) as synced_changes,\n COALESCE(cs.failed_changes, 0) as failed_changes,\n cs.last_sync_at,\n CASE \n WHEN sc.sync_enabled = true AND sc.last_successful_sync IS NOT NULL \n THEN sc.last_successful_sync + (sc.sync_interval_minutes || ' minutes')::interval\n ELSE NULL\n END as next_sync_at,\n sc.sync_enabled\n FROM sync_configs sc\n LEFT JOIN change_stats cs ON sc.contract_id = cs.contract_id AND sc.target_system = cs.target_system\n", + "name": "sync_status_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_documents_view": { + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "pic": { + "name": "pic", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "latest_stage_id": { + "name": "latest_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_stage_name": { + "name": "latest_stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "latest_stage_plan_date": { + "name": "latest_stage_plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "latest_stage_actual_date": { + "name": "latest_stage_actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "latest_revision_id": { + "name": "latest_revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_revision": { + "name": "latest_revision", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_uploader_type": { + "name": "latest_revision_uploader_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_uploader_name": { + "name": "latest_revision_uploader_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "attachment_count": { + "name": "attachment_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "definition": "\n SELECT \n d.id, \n d.doc_number,\n d.title,\n d.pic,\n d.status,\n d.issued_date,\n d.contract_id,\n \n (SELECT id FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_id,\n (SELECT stage_name FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_name,\n (SELECT plan_date FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_plan_date,\n (SELECT actual_date FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_actual_date,\n \n (SELECT r.id FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision_id,\n (SELECT r.revision FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision,\n (SELECT r.uploader_type FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision_uploader_type,\n (SELECT r.uploader_name FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision_uploader_name,\n \n (SELECT COUNT(*) FROM document_attachments a JOIN revisions r ON a.revision_id = r.id JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id) AS attachment_count,\n \n d.created_at,\n d.updated_at\n FROM documents d\n JOIN contracts c ON d.contract_id = c.id\n ", + "name": "vendor_documents_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_candidates_with_vendor_info": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_name": { + "name": "company_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_email": { + "name": "contact_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "contact_phone": { + "name": "contact_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'COLLECTED'" + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"vendor_candidates\".\"id\", \"vendor_candidates\".\"company_name\", \"vendor_candidates\".\"contact_email\", \"vendor_candidates\".\"contact_phone\", \"vendor_candidates\".\"tax_id\", \"vendor_candidates\".\"address\", \"vendor_candidates\".\"country\", \"vendor_candidates\".\"source\", \"vendor_candidates\".\"status\", \"vendor_candidates\".\"items\", \"vendor_candidates\".\"remark\", \"vendor_candidates\".\"created_at\", \"vendor_candidates\".\"updated_at\", \"vendors\".\"vendor_name\", \"vendors\".\"vendor_code\", \"vendors\".\"created_at\" as \"vendor_created_at\", (\n SELECT l2.\"created_at\"\n FROM \"vendor_candidate_logs\" l2\n WHERE l2.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l2.\"action\" = 'status_change'\n ORDER BY l2.\"created_at\" DESC\n LIMIT 1\n ) as \"last_status_change_at\", (\n SELECT u.\"name\"\n FROM \"users\" u\n JOIN \"vendor_candidate_logs\" l3\n ON l3.\"user_id\" = u.\"id\"\n WHERE l3.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l3.\"action\" = 'status_change'\n ORDER BY l3.\"created_at\" DESC\n LIMIT 1\n ) as \"last_status_change_by\", (\n SELECT l4.\"created_at\"\n FROM \"vendor_candidate_logs\" l4\n WHERE l4.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l4.\"action\" = 'invite_sent'\n ORDER BY l4.\"created_at\" DESC\n LIMIT 1\n ) as \"last_invitation_at\", (\n SELECT u2.\"name\"\n FROM \"users\" u2\n JOIN \"vendor_candidate_logs\" l5\n ON l5.\"user_id\" = u2.\"id\"\n WHERE l5.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l5.\"action\" = 'invite_sent'\n ORDER BY l5.\"created_at\" DESC\n LIMIT 1\n ) as \"last_invitation_by\" from \"vendor_candidates\" left join \"vendors\" on \"vendor_candidates\".\"vendor_id\" = \"vendors\".\"id\"", + "name": "vendor_candidates_with_vendor_info", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_detail_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "business_size": { + "name": "business_size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "website": { + "name": "website", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING_REVIEW'" + }, + "representative_name": { + "name": "representative_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_birth": { + "name": "representative_birth", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "representative_email": { + "name": "representative_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_phone": { + "name": "representative_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "corporate_registration_number": { + "name": "corporate_registration_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "credit_agency": { + "name": "credit_agency", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "credit_rating": { + "name": "credit_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "cash_flow_rating": { + "name": "cash_flow_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"id\", \"vendor_name\", \"vendor_code\", \"tax_id\", \"address\", \"business_size\", \"country\", \"phone\", \"email\", \"website\", \"status\", \"representative_name\", \"representative_birth\", \"representative_email\", \"representative_phone\", \"corporate_registration_number\", \"credit_agency\", \"credit_rating\", \"cash_flow_rating\", \"created_at\", \"updated_at\", \n (SELECT COALESCE(\n json_agg(\n json_build_object(\n 'id', c.id,\n 'contactName', c.contact_name,\n 'contactPosition', c.contact_position,\n 'contactEmail', c.contact_email,\n 'contactPhone', c.contact_phone,\n 'isPrimary', c.is_primary\n )\n ),\n '[]'::json\n )\n FROM vendor_contacts c\n WHERE c.vendor_id = vendors.id)\n as \"contacts\", \n (SELECT COALESCE(\n json_agg(\n json_build_object(\n 'id', a.id,\n 'fileName', a.file_name,\n 'filePath', a.file_path,\n 'attachmentType', a.attachment_type,\n 'createdAt', a.created_at\n )\n ORDER BY a.attachment_type, a.created_at DESC\n ),\n '[]'::json\n )\n FROM vendor_attachments a\n WHERE a.vendor_id = vendors.id)\n as \"attachments\", \n (SELECT COUNT(*)\n FROM vendor_attachments a\n WHERE a.vendor_id = vendors.id)\n as \"attachment_count\", \n (SELECT COUNT(*) \n FROM vendor_contacts c\n WHERE c.vendor_id = vendors.id)\n as \"contact_count\" from \"vendors\"", + "name": "vendor_detail_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_items_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"vendor_possible_items\".\"id\", \"vendor_possible_items\".\"vendor_id\", \"items\".\"item_name\", \"items\".\"item_code\", \"items\".\"description\", \"vendor_possible_items\".\"created_at\", \"vendor_possible_items\".\"updated_at\" from \"vendor_possible_items\" left join \"items\" on \"vendor_possible_items\".\"item_code\" = \"items\".\"item_code\"", + "name": "vendor_items_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_materials_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "unit_of_measure": { + "name": "unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "steel_type": { + "name": "steel_type", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "grade_material": { + "name": "grade_material", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"vendor_possible_materials\".\"id\", \"vendor_possible_materials\".\"vendor_id\", \"materials\".\"item_name\", \"materials\".\"item_code\", \"materials\".\"description\", \"materials\".\"unit_of_measure\", \"materials\".\"steel_type\", \"materials\".\"grade_material\", \"vendor_possible_materials\".\"created_at\", \"vendor_possible_materials\".\"updated_at\" from \"vendor_possible_materials\" left join \"materials\" on \"vendor_possible_materials\".\"item_code\" = \"materials\".\"item_code\"", + "name": "vendor_materials_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendors_with_types": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"tax_id\" as \"tax_id\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"phone\" as \"phone\", \"vendors\".\"email\" as \"email\", \"vendors\".\"business_size\" as \"business_size\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"status\", \"vendors\".\"vendor_type_id\" as \"vendor_type_id\", \"vendors\".\"representative_name\" as \"representative_name\", \"vendors\".\"representative_birth\" as \"representative_birth\", \"vendors\".\"representative_email\" as \"representative_email\", \"vendors\".\"representative_phone\" as \"representative_phone\", \"vendors\".\"corporate_registration_number\" as \"corporate_registration_number\", \"vendors\".\"items\" as \"items\", \"vendors\".\"credit_agency\" as \"credit_agency\", \"vendors\".\"credit_rating\" as \"credit_rating\", \"vendors\".\"cash_flow_rating\" as \"cash_flow_rating\", \"vendors\".\"created_at\" as \"created_at\", \"vendors\".\"updated_at\" as \"updated_at\", \"vendor_types\".\"name_ko\" as \"vendor_type_name\", \"vendor_types\".\"name_en\" as \"vendor_type_name_en\", \"vendor_types\".\"code\" as \"vendor_type_code\", \n CASE\n WHEN \"vendors\".\"status\" = 'ACTIVE' THEN '정규업체'\n WHEN \"vendors\".\"status\" IN ('INACTIVE', 'BLACKLISTED', 'REJECTED') THEN ''\n ELSE '잠재업체'\n END\n as \"vendor_category\" from \"vendors\" left join \"vendor_types\" on \"vendors\".\"vendor_type_id\" = \"vendor_types\".\"id\"", + "name": "vendors_with_types", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.basic_contract_view": { + "columns": {}, + "definition": "select \"basic_contract\".\"id\" as \"id\", \"basic_contract\".\"template_id\" as \"template_id\", \"basic_contract\".\"vendor_id\" as \"vendor_id\", \"basic_contract\".\"requested_by\" as \"requested_by\", \"basic_contract\".\"status\" as \"basic_contract_status\", \"basic_contract\".\"created_at\" as \"created_at\", \"basic_contract\".\"updated_at\" as \"updated_at\", \"basic_contract\".\"updated_at\" as \"completed_at\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"email\" as \"vendor_email\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"users\".\"name\" as \"user_name\", \"basic_contract_templates\".\"template_name\" as \"template_name\", \"basic_contract_templates\".\"validity_period\" as \"validityPeriod\", \"basic_contract_templates\".\"file_path\" as \"file_path\", \"basic_contract_templates\".\"file_name\" as \"file_name\", \"basic_contract\".\"file_path\" as \"signed_file_path\" from \"basic_contract\" left join \"vendors\" on \"basic_contract\".\"vendor_id\" = \"vendors\".\"id\" left join \"users\" on \"basic_contract\".\"requested_by\" = \"users\".\"id\" left join \"basic_contract_templates\" on \"basic_contract\".\"template_id\" = \"basic_contract_templates\".\"id\"", + "name": "basic_contract_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.pr_items_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_item": { + "name": "rfq_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_item": { + "name": "pr_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_no": { + "name": "pr_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "material_code": { + "name": "material_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_category": { + "name": "material_category", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "acc": { + "name": "acc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_description": { + "name": "material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "size": { + "name": "size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "uom": { + "name": "uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "gross_weight": { + "name": "gross_weight", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "gw_uom": { + "name": "gw_uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "spec_no": { + "name": "spec_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "spec_url": { + "name": "spec_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "tracking_no": { + "name": "tracking_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "major_yn": { + "name": "major_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "project_def": { + "name": "project_def", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_sc": { + "name": "project_sc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_kl": { + "name": "project_kl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_lc": { + "name": "project_lc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_dl": { + "name": "project_dl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"pr_items\".\"id\", \"pr_items\".\"procurement_rfqs_id\", \"pr_items\".\"rfq_item\", \"pr_items\".\"pr_item\", \"pr_items\".\"pr_no\", \"pr_items\".\"material_code\", \"pr_items\".\"material_category\", \"pr_items\".\"acc\", \"pr_items\".\"material_description\", \"pr_items\".\"size\", \"pr_items\".\"delivery_date\", \"pr_items\".\"quantity\", \"pr_items\".\"uom\", \"pr_items\".\"gross_weight\", \"pr_items\".\"gw_uom\", \"pr_items\".\"spec_no\", \"pr_items\".\"spec_url\", \"pr_items\".\"tracking_no\", \"pr_items\".\"major_yn\", \"pr_items\".\"project_def\", \"pr_items\".\"project_sc\", \"pr_items\".\"project_kl\", \"pr_items\".\"project_lc\", \"pr_items\".\"project_dl\", \"pr_items\".\"remark\", \"procurement_rfqs\".\"rfq_code\", \"procurement_rfqs\".\"item_code\", \"procurement_rfqs\".\"item_name\" from \"pr_items\" left join \"procurement_rfqs\" on \"pr_items\".\"procurement_rfqs_id\" = \"procurement_rfqs\".\"id\"", + "name": "pr_items_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.procurement_rfq_details_view": { + "columns": {}, + "definition": "select \"rfq_details\".\"id\" as \"detail_id\", \"rfqs\".\"id\" as \"rfq_id\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"rfqs\".\"item_code\" as \"item_code\", \"rfqs\".\"item_name\" as \"item_name\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"country\" as \"vendor_country\", \"rfq_details\".\"currency\" as \"currency\", \"payment_terms\".\"code\" as \"payment_terms_code\", \"payment_terms\".\"description\" as \"payment_terms_description\", \"incoterms\".\"code\" as \"incoterms_code\", \"incoterms\".\"description\" as \"incoterms_description\", \"rfq_details\".\"incoterms_detail\" as \"incoterms_detail\", \"rfq_details\".\"delivery_date\" as \"delivery_date\", \"rfq_details\".\"tax_code\" as \"tax_code\", \"rfq_details\".\"place_of_shipping\" as \"place_of_shipping\", \"rfq_details\".\"place_of_destination\" as \"place_of_destination\", \"rfq_details\".\"material_price_related_yn\" as \"material_price_related_yn\", \"updated_by_user\".\"name\" as \"updated_by_user_name\", \"rfq_details\".\"updated_at\" as \"updated_at\", (\n SELECT COUNT(*) \n FROM pr_items \n WHERE procurement_rfqs_id = \"rfqs\".\"id\"\n ) as \"pr_items_count\", (\n SELECT COUNT(*) \n FROM pr_items \n WHERE procurement_rfqs_id = \"rfqs\".\"id\" \n AND major_yn = true\n ) as \"major_items_count\", (\n SELECT COUNT(*) \n FROM procurement_rfq_comments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"comment_count\", (\n SELECT created_at \n FROM procurement_rfq_comments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY created_at DESC LIMIT 1\n ) as \"last_comment_date\", (\n SELECT created_at \n FROM procurement_rfq_comments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\" AND is_vendor_comment = true\n ORDER BY created_at DESC LIMIT 1\n ) as \"last_vendor_comment_date\", (\n SELECT COUNT(*) \n FROM procurement_rfq_attachments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"attachment_count\", (\n SELECT COUNT(*) > 0\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"has_quotation\", (\n SELECT status\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY created_at DESC LIMIT 1\n ) as \"quotation_status\", (\n SELECT total_price\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY created_at DESC LIMIT 1\n ) as \"quotation_total_price\", (\n SELECT quotation_version\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY quotation_version DESC LIMIT 1\n ) as \"quotation_version\", (\n SELECT COUNT(DISTINCT quotation_version)\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"quotation_version_count\", (\n SELECT created_at\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY quotation_version DESC LIMIT 1\n ) as \"last_quotation_date\" from \"procurement_rfq_details\" \"rfq_details\" left join \"procurement_rfqs\" \"rfqs\" on \"rfq_details\".\"procurement_rfqs_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendors\" on \"rfq_details\".\"vendors_id\" = \"vendors\".\"id\" left join \"payment_terms\" on \"rfq_details\".\"payment_terms_code\" = \"payment_terms\".\"code\" left join \"incoterms\" on \"rfq_details\".\"incoterms_code\" = \"incoterms\".\"code\" left join \"users\" \"updated_by_user\" on \"rfq_details\".\"updated_by\" = \"updated_by_user\".\"id\"", + "name": "procurement_rfq_details_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.procurement_rfqs_view": { + "columns": {}, + "definition": "select \"procurement_rfqs\".\"id\" as \"id\", \"procurement_rfqs\".\"rfq_code\" as \"rfq_code\", \"procurement_rfqs\".\"series\" as \"series\", \"procurement_rfqs\".\"rfq_sealed_yn\" as \"rfq_sealed_yn\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"procurement_rfqs\".\"item_code\" as \"item_code\", \"procurement_rfqs\".\"item_name\" as \"item_name\", \"procurement_rfqs\".\"status\" as \"status\", \"procurement_rfqs\".\"pic_code\" as \"pic_code\", \"procurement_rfqs\".\"rfq_send_date\" as \"rfq_send_date\", \"procurement_rfqs\".\"due_date\" as \"due_date\", (\n SELECT MIN(submitted_at)\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"procurement_rfqs\".\"id\"\n AND submitted_at IS NOT NULL\n ) as \"earliest_quotation_submitted_at\", \"created_by_user\".\"name\" as \"created_by_user_name\", \"sent_by_user\".\"name\" as \"sent_by_user_name\", \"procurement_rfqs\".\"updated_at\" as \"updated_at\", \"updated_by_user\".\"name\" as \"updated_by_user_name\", \"procurement_rfqs\".\"remark\" as \"remark\", (\n SELECT material_code \n FROM pr_items \n WHERE procurement_rfqs_id = \"procurement_rfqs\".\"id\"\n AND major_yn = true\n LIMIT 1\n ) as \"major_item_material_code\", (\n SELECT pr_no \n FROM pr_items \n WHERE procurement_rfqs_id = \"procurement_rfqs\".\"id\"\n AND major_yn = true\n LIMIT 1\n ) as \"po_no\", (\n SELECT COUNT(*) \n FROM pr_items \n WHERE procurement_rfqs_id = \"procurement_rfqs\".\"id\"\n ) as \"pr_items_count\" from \"procurement_rfqs\" left join \"projects\" on \"procurement_rfqs\".\"project_id\" = \"projects\".\"id\" left join \"users\" \"created_by_user\" on \"procurement_rfqs\".\"created_by\" = \"created_by_user\".\"id\" left join \"users\" \"updated_by_user\" on \"procurement_rfqs\".\"updated_by\" = \"updated_by_user\".\"id\" left join \"users\" \"sent_by_user\" on \"procurement_rfqs\".\"sent_by\" = \"sent_by_user\".\"id\"", + "name": "procurement_rfqs_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.attachments_with_latest_revision": { + "columns": { + "attachment_id": { + "name": "attachment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "serial_no": { + "name": "serial_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "current_revision": { + "name": "current_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "revision_id": { + "name": "revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "revision_comment": { + "name": "revision_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by_name": { + "name": "created_by_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n a.id as attachment_id,\n a.attachment_type,\n a.serial_no,\n a.rfq_id,\n a.description,\n a.current_revision,\n \n r.id as revision_id,\n r.file_name,\n r.original_file_name,\n r.file_path,\n r.file_size,\n r.file_type,\n r.revision_comment,\n \n a.created_by,\n u.name as created_by_name,\n a.created_at,\n a.updated_at\n FROM b_rfq_attachments a\n LEFT JOIN b_rfq_attachment_revisions r ON a.latest_revision_id = r.id\n LEFT JOIN users u ON a.created_by = u.id\n ", + "name": "attachments_with_latest_revision", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.b_rfqs_master": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pic_name": { + "name": "pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "eng_pic_name": { + "name": "eng_pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_no": { + "name": "package_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_name": { + "name": "package_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "project_code": { + "name": "project_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_name": { + "name": "project_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_type": { + "name": "project_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "project_company": { + "name": "project_company", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_flag": { + "name": "project_flag", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_site": { + "name": "project_site", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "total_attachments": { + "name": "total_attachments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.description,\n br.status,\n br.due_date,\n br.pic_code,\n br.pic_name,\n br.eng_pic_name,\n br.package_no,\n br.package_name,\n br.project_id,\n p.code as project_code,\n p.name as project_name,\n p.type as project_type,\n br.project_company,\n br.project_flag,\n br.project_site,\n COALESCE(att_count.total_attachments, 0) as total_attachments,\n br.created_at,\n br.updated_at\n FROM b_rfqs br\n LEFT JOIN projects p ON br.project_id = p.id\n LEFT JOIN (\n SELECT rfq_id, COUNT(*) as total_attachments\n FROM b_rfq_attachments\n GROUP BY rfq_id\n ) att_count ON br.id = att_count.rfq_id\n", + "name": "b_rfqs_master", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.final_rfq_detail": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_status": { + "name": "rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "final_rfq_id": { + "name": "final_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "final_rfq_status": { + "name": "final_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_country": { + "name": "vendor_country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "vendor_business_size": { + "name": "vendor_business_size", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_description": { + "name": "incoterms_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "payment_terms_description": { + "name": "payment_terms_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "tax_code": { + "name": "tax_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_shipping": { + "name": "place_of_shipping", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_destination": { + "name": "place_of_destination", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "firsttime_yn": { + "name": "firsttime_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "material_price_related_yn": { + "name": "material_price_related_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vendor_remark": { + "name": "vendor_remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.status as rfq_status,\n fr.id as final_rfq_id,\n fr.final_rfq_status,\n fr.vendor_id,\n v.vendor_code,\n v.vendor_name,\n v.country as vendor_country,\n v.business_size as vendor_business_size,\n fr.due_date,\n fr.valid_date,\n fr.delivery_date,\n fr.incoterms_code,\n inc.description as incoterms_description,\n fr.payment_terms_code,\n pt.description as payment_terms_description,\n fr.currency,\n fr.tax_code,\n fr.place_of_shipping,\n fr.place_of_destination,\n fr.short_list,\n fr.return_yn,\n fr.cp_request_yn,\n fr.prject_gtc_yn,\n fr.firsttime_yn,\n fr.material_price_related_yn,\n fr.return_revision,\n fr.gtc,\n fr.gtc_valid_date,\n fr.classification,\n fr.sparepart,\n fr.remark,\n fr.vendor_remark,\n fr.created_at,\n fr.updated_at\n FROM b_rfqs br\n JOIN final_rfq fr ON br.id = fr.rfq_id\n LEFT JOIN vendors v ON fr.vendor_id = v.id\n LEFT JOIN incoterms inc ON fr.incoterms_code = inc.code\n LEFT JOIN payment_terms pt ON fr.payment_terms_code = pt.code\n", + "name": "final_rfq_detail", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.initial_rfq_detail": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_status": { + "name": "rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "initial_rfq_id": { + "name": "initial_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "initial_rfq_status": { + "name": "initial_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_country": { + "name": "vendor_country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "vendor_business_size": { + "name": "vendor_business_size", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_description": { + "name": "incoterms_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.status as rfq_status,\n ir.id as initial_rfq_id,\n ir.initial_rfq_status,\n ir.vendor_id,\n v.vendor_code,\n v.vendor_name,\n v.country as vendor_country,\n v.business_size as vendor_business_size,\n ir.due_date,\n ir.valid_date,\n ir.incoterms_code,\n inc.description as incoterms_description,\n ir.short_list,\n ir.return_yn,\n ir.cp_request_yn,\n ir.prject_gtc_yn,\n ir.return_revision,\n ir.gtc,\n ir.gtc_valid_date,\n ir.classification,\n ir.sparepart,\n ir.created_at,\n ir.updated_at\n FROM b_rfqs br\n JOIN initial_rfq ir ON br.id = ir.rfq_id\n LEFT JOIN vendors v ON ir.vendor_id = v.id\n LEFT JOIN incoterms inc ON ir.incoterms_code = inc.code\n", + "name": "initial_rfq_detail", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.rfq_dashboard": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "project_code": { + "name": "project_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_name": { + "name": "project_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "package_no": { + "name": "package_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_name": { + "name": "package_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pic_name": { + "name": "pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "eng_pic_name": { + "name": "eng_pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_company": { + "name": "project_company", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_flag": { + "name": "project_flag", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_site": { + "name": "project_site", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "total_attachments": { + "name": "total_attachments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "initial_vendor_count": { + "name": "initial_vendor_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "final_vendor_count": { + "name": "final_vendor_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "initial_response_rate": { + "name": "initial_response_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "final_response_rate": { + "name": "final_response_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "overall_progress": { + "name": "overall_progress", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "days_to_deadline": { + "name": "days_to_deadline", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by_name": { + "name": "updated_by_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "updated_by_email": { + "name": "updated_by_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n -- ② SELECT 절 확장 -------------------------------------------\n SELECT\n br.id AS rfq_id,\n br.rfq_code,\n br.description,\n br.status,\n br.due_date,\n p.code AS project_code,\n p.name AS project_name,\n br.package_no,\n br.package_name,\n br.pic_code,\n br.pic_name,\n br.eng_pic_name,\n br.project_company,\n br.project_flag,\n br.project_site,\n br.remark,\n \n -- 첨부/벤더 요약 -----------------------\n COALESCE(att_count.total_attachments, 0) AS total_attachments,\n COALESCE(init_summary.vendor_count, 0) AS initial_vendor_count,\n COALESCE(final_summary.vendor_count, 0) AS final_vendor_count,\n COALESCE(init_summary.avg_response_rate, 0) AS initial_response_rate,\n COALESCE(final_summary.avg_response_rate, 0) AS final_response_rate,\n \n -- 진행률·마감까지 일수 --------------\n CASE \n WHEN br.status = 'DRAFT' THEN 0\n WHEN br.status = 'Doc. Received' THEN 10\n WHEN br.status = 'PIC Assigned' THEN 20\n WHEN br.status = 'Doc. Confirmed' THEN 30\n WHEN br.status = 'Init. RFQ Sent' THEN 40\n WHEN br.status = 'Init. RFQ Answered' THEN 50\n WHEN br.status = 'TBE started' THEN 60\n WHEN br.status = 'TBE finished' THEN 70\n WHEN br.status = 'Final RFQ Sent' THEN 80\n WHEN br.status = 'Quotation Received' THEN 90\n WHEN br.status = 'Vendor Selected' THEN 100\n ELSE 0\n END AS overall_progress,\n (br.due_date - CURRENT_DATE) AS days_to_deadline,\n \n br.created_at,\n br.updated_at,\n \n -- 💡 추가되는 컬럼 -------------------\n upd.name AS updated_by_name,\n upd.email AS updated_by_email\n FROM b_rfqs br\n LEFT JOIN projects p ON br.project_id = p.id\n \n -- ③ 사용자 정보 조인 --------------------\n LEFT JOIN users upd ON br.updated_by = upd.id\n \n -- (나머지 이미 있던 JOIN 들은 그대로) -----\n LEFT JOIN (\n SELECT rfq_id, COUNT(*) AS total_attachments\n FROM b_rfq_attachments\n GROUP BY rfq_id\n ) att_count ON br.id = att_count.rfq_id\n \n LEFT JOIN (\n SELECT \n rfq_id, \n COUNT(DISTINCT vendor_id) AS vendor_count,\n AVG(response_rate) AS avg_response_rate\n FROM vendor_response_summary\n WHERE rfq_type = 'INITIAL'\n GROUP BY rfq_id\n ) init_summary ON br.id = init_summary.rfq_id\n \n LEFT JOIN (\n SELECT \n rfq_id, \n COUNT(DISTINCT vendor_id) AS vendor_count,\n AVG(response_rate) AS avg_response_rate\n FROM vendor_response_summary\n WHERE rfq_type = 'FINAL'\n GROUP BY rfq_id\n ) final_summary ON br.id = final_summary.rfq_id\n ", + "name": "rfq_dashboard", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_response_summary": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_status": { + "name": "rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_country": { + "name": "vendor_country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "vendor_business_size": { + "name": "vendor_business_size", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_type": { + "name": "rfq_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "total_attachments": { + "name": "total_attachments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "responded_count": { + "name": "responded_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "pending_count": { + "name": "pending_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "waived_count": { + "name": "waived_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "revision_requested_count": { + "name": "revision_requested_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "response_rate": { + "name": "response_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "completion_rate": { + "name": "completion_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.status as rfq_status,\n v.id as vendor_id,\n v.vendor_code,\n v.vendor_name,\n v.country as vendor_country,\n v.business_size as vendor_business_size,\n var.rfq_type,\n COUNT(var.id) as total_attachments,\n COUNT(CASE WHEN var.response_status = 'RESPONDED' THEN 1 END) as responded_count,\n COUNT(CASE WHEN var.response_status = 'NOT_RESPONDED' THEN 1 END) as pending_count,\n COUNT(CASE WHEN var.response_status = 'WAIVED' THEN 1 END) as waived_count,\n COUNT(CASE WHEN var.response_status = 'REVISION_REQUESTED' THEN 1 END) as revision_requested_count,\n ROUND(\n (COUNT(CASE WHEN var.response_status = 'RESPONDED' THEN 1 END) * 100.0 / \n NULLIF(COUNT(CASE WHEN var.response_status != 'WAIVED' THEN 1 END), 0)), \n 2\n ) as response_rate,\n ROUND(\n ((COUNT(CASE WHEN var.response_status = 'RESPONDED' THEN 1 END) + \n COUNT(CASE WHEN var.response_status = 'WAIVED' THEN 1 END)) * 100.0 / COUNT(var.id)), \n 2\n ) as completion_rate\n FROM b_rfqs br\n JOIN b_rfq_attachments bra ON br.id = bra.rfq_id\n JOIN vendor_attachment_responses var ON bra.id = var.attachment_id\n JOIN vendors v ON var.vendor_id = v.id\n GROUP BY br.id, br.rfq_code, br.status, v.id, v.vendor_code, v.vendor_name, v.country, v.business_size, var.rfq_type\n", + "name": "vendor_response_summary", + "schema": "public", + "isExisting": false, + "materialized": false + } + }, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +}
\ No newline at end of file diff --git a/db/migrations/meta/0130_snapshot.json b/db/migrations/meta/0130_snapshot.json new file mode 100644 index 00000000..eccffb45 --- /dev/null +++ b/db/migrations/meta/0130_snapshot.json @@ -0,0 +1,14377 @@ +{ + "id": "fdf940e8-cf28-4e35-8462-fefb2dccaf29", + "prevId": "5cb02083-21c1-4195-a09b-448010cccef0", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.companies": { + "name": "companies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "companies_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "taxID": { + "name": "taxID", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contract_envelopes": { + "name": "contract_envelopes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contract_envelopes_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "envelope_id": { + "name": "envelope_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "envelope_status": { + "name": "envelope_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "contract_envelopes_contract_id_contracts_id_fk": { + "name": "contract_envelopes_contract_id_contracts_id_fk", + "tableFrom": "contract_envelopes", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contract_items": { + "name": "contract_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contract_items_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "unit_price": { + "name": "unit_price", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "tax_rate": { + "name": "tax_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "tax_amount": { + "name": "tax_amount", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "total_line_amount": { + "name": "total_line_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "contract_items_contract_item_idx": { + "name": "contract_items_contract_item_idx", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "contract_items_contract_id_contracts_id_fk": { + "name": "contract_items_contract_id_contracts_id_fk", + "tableFrom": "contract_items", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contract_items_item_id_items_id_fk": { + "name": "contract_items_item_id_items_id_fk", + "tableFrom": "contract_items", + "tableTo": "items", + "columnsFrom": [ + "item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "contract_items_contract_id_item_id_unique": { + "name": "contract_items_contract_id_item_id_unique", + "nullsNotDistinct": false, + "columns": [ + "contract_id", + "item_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contract_signers": { + "name": "contract_signers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contract_signers_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "envelope_id": { + "name": "envelope_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_contact_id": { + "name": "vendor_contact_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "signer_type": { + "name": "signer_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'VENDOR'" + }, + "signer_email": { + "name": "signer_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "signer_name": { + "name": "signer_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "signer_position": { + "name": "signer_position", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "signer_status": { + "name": "signer_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'PENDING'" + }, + "signed_at": { + "name": "signed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "contract_signers_envelope_id_contract_envelopes_id_fk": { + "name": "contract_signers_envelope_id_contract_envelopes_id_fk", + "tableFrom": "contract_signers", + "tableTo": "contract_envelopes", + "columnsFrom": [ + "envelope_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contract_signers_vendor_contact_id_vendor_contacts_id_fk": { + "name": "contract_signers_vendor_contact_id_vendor_contacts_id_fk", + "tableFrom": "contract_signers", + "tableTo": "vendor_contacts", + "columnsFrom": [ + "vendor_contact_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contracts": { + "name": "contracts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contracts_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "contract_name": { + "name": "contract_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "payment_terms": { + "name": "payment_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'KRW'" + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "partial_shipping_allowed": { + "name": "partial_shipping_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "partial_payment_allowed": { + "name": "partial_payment_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "remarks": { + "name": "remarks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "contracts_project_id_projects_id_fk": { + "name": "contracts_project_id_projects_id_fk", + "tableFrom": "contracts", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "contracts_vendor_id_vendors_id_fk": { + "name": "contracts_vendor_id_vendors_id_fk", + "tableFrom": "contracts", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "contracts_contract_no_unique": { + "name": "contracts_contract_no_unique", + "nullsNotDistinct": false, + "columns": [ + "contract_no" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.poa": { + "name": "poa", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "poa_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "original_contract_no": { + "name": "original_contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "original_contract_name": { + "name": "original_contract_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_status": { + "name": "original_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "change_reason": { + "name": "change_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approval_status": { + "name": "approval_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'PENDING'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "poa_original_contract_no_contracts_contract_no_fk": { + "name": "poa_original_contract_no_contracts_contract_no_fk", + "tableFrom": "poa", + "tableTo": "contracts", + "columnsFrom": [ + "original_contract_no" + ], + "columnsTo": [ + "contract_no" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "poa_project_id_projects_id_fk": { + "name": "poa_project_id_projects_id_fk", + "tableFrom": "poa", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "poa_vendor_id_vendors_id_fk": { + "name": "poa_vendor_id_vendors_id_fk", + "tableFrom": "poa", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.item_offshore_hull": { + "name": "item_offshore_hull", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "work_type": { + "name": "work_type", + "type": "offshore_hull_work_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "item_list": { + "name": "item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sub_item_list": { + "name": "sub_item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "item_offshore_hull_item_code_items_item_code_fk": { + "name": "item_offshore_hull_item_code_items_item_code_fk", + "tableFrom": "item_offshore_hull", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.item_offshore_top": { + "name": "item_offshore_top", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "work_type": { + "name": "work_type", + "type": "offshore_top_work_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "item_list": { + "name": "item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sub_item_list": { + "name": "sub_item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "item_offshore_top_item_code_items_item_code_fk": { + "name": "item_offshore_top_item_code_items_item_code_fk", + "tableFrom": "item_offshore_top", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.item_shipbuilding": { + "name": "item_shipbuilding", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "work_type": { + "name": "work_type", + "type": "work_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "item_list": { + "name": "item_list", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ship_types": { + "name": "ship_types", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'OPTION'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "item_shipbuilding_item_code_items_item_code_fk": { + "name": "item_shipbuilding_item_code_items_item_code_fk", + "tableFrom": "item_shipbuilding", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.items": { + "name": "items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_no": { + "name": "project_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "package_code": { + "name": "package_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "sm_code": { + "name": "sm_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_item_code": { + "name": "parent_item_code", + "type": "varchar(18)", + "primaryKey": false, + "notNull": false + }, + "item_level": { + "name": "item_level", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "delete_flag": { + "name": "delete_flag", + "type": "varchar(1)", + "primaryKey": false, + "notNull": false + }, + "unit_of_measure": { + "name": "unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "steel_type": { + "name": "steel_type", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "grade_material": { + "name": "grade_material", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "change_date": { + "name": "change_date", + "type": "varchar(8)", + "primaryKey": false, + "notNull": false + }, + "base_unit_of_measure": { + "name": "base_unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "items_item_code_unique": { + "name": "items_item_code_unique", + "nullsNotDistinct": false, + "columns": [ + "item_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.materials": { + "name": "materials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_item_code": { + "name": "parent_item_code", + "type": "varchar(18)", + "primaryKey": false, + "notNull": false + }, + "item_level": { + "name": "item_level", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "delete_flag": { + "name": "delete_flag", + "type": "varchar(1)", + "primaryKey": false, + "notNull": false + }, + "unit_of_measure": { + "name": "unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "steel_type": { + "name": "steel_type", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "grade_material": { + "name": "grade_material", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "change_date": { + "name": "change_date", + "type": "varchar(8)", + "primaryKey": false, + "notNull": false + }, + "base_unit_of_measure": { + "name": "base_unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "materials_item_code_unique": { + "name": "materials_item_code_unique", + "nullsNotDistinct": false, + "columns": [ + "item_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pq_criterias": { + "name": "pq_criterias", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "check_point": { + "name": "check_point", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "remarks": { + "name": "remarks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "group_name": { + "name": "group_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pq_criterias_extension": { + "name": "pq_criterias_extension", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pq_criteria_id": { + "name": "pq_criteria_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "contract_info": { + "name": "contract_info", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "additional_requirement": { + "name": "additional_requirement", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "pq_criterias_extension_pq_criteria_id_pq_criterias_id_fk": { + "name": "pq_criterias_extension_pq_criteria_id_pq_criterias_id_fk", + "tableFrom": "pq_criterias_extension", + "tableTo": "pq_criterias", + "columnsFrom": [ + "pq_criteria_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "pq_criterias_extension_project_id_projects_id_fk": { + "name": "pq_criterias_extension_project_id_projects_id_fk", + "tableFrom": "pq_criterias_extension", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_criteria_attachments": { + "name": "vendor_criteria_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_criteria_answer_id": { + "name": "vendor_criteria_answer_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_criteria_attachments_vendor_criteria_answer_id_vendor_pq_criteria_answers_id_fk": { + "name": "vendor_criteria_attachments_vendor_criteria_answer_id_vendor_pq_criteria_answers_id_fk", + "tableFrom": "vendor_criteria_attachments", + "tableTo": "vendor_pq_criteria_answers", + "columnsFrom": [ + "vendor_criteria_answer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_investigation_attachments": { + "name": "vendor_investigation_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "investigation_id": { + "name": "investigation_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "mime_type": { + "name": "mime_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'REPORT'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_investigation_attachments_investigation_id_vendor_investigations_id_fk": { + "name": "vendor_investigation_attachments_investigation_id_vendor_investigations_id_fk", + "tableFrom": "vendor_investigation_attachments", + "tableTo": "vendor_investigations", + "columnsFrom": [ + "investigation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_investigations": { + "name": "vendor_investigations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pq_submission_id": { + "name": "pq_submission_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requester_id": { + "name": "requester_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "qm_manager_id": { + "name": "qm_manager_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "investigation_status": { + "name": "investigation_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'PLANNED'" + }, + "evaluation_type": { + "name": "evaluation_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_address": { + "name": "investigation_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "investigation_method": { + "name": "investigation_method", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "scheduled_start_at": { + "name": "scheduled_start_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scheduled_end_at": { + "name": "scheduled_end_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "forecasted_at": { + "name": "forecasted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "evaluation_score": { + "name": "evaluation_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluation_result": { + "name": "evaluation_result", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_notes": { + "name": "investigation_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_investigations_vendor_id_vendors_id_fk": { + "name": "vendor_investigations_vendor_id_vendors_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_investigations_pq_submission_id_vendor_pq_submissions_id_fk": { + "name": "vendor_investigations_pq_submission_id_vendor_pq_submissions_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "vendor_pq_submissions", + "columnsFrom": [ + "pq_submission_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "cascade" + }, + "vendor_investigations_requester_id_users_id_fk": { + "name": "vendor_investigations_requester_id_users_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "users", + "columnsFrom": [ + "requester_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_investigations_qm_manager_id_users_id_fk": { + "name": "vendor_investigations_qm_manager_id_users_id_fk", + "tableFrom": "vendor_investigations", + "tableTo": "users", + "columnsFrom": [ + "qm_manager_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_pq_submissions": { + "name": "vendor_pq_submissions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pq_number": { + "name": "pq_number", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "requester_id": { + "name": "requester_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'REQUESTED'" + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "rejected_at": { + "name": "rejected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "reject_reason": { + "name": "reject_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_pq_submission": { + "name": "unique_pq_submission", + "columns": [ + { + "expression": "vendor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "vendor_pq_submissions_requester_id_users_id_fk": { + "name": "vendor_pq_submissions_requester_id_users_id_fk", + "tableFrom": "vendor_pq_submissions", + "tableTo": "users", + "columnsFrom": [ + "requester_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_pq_submissions_vendor_id_vendors_id_fk": { + "name": "vendor_pq_submissions_vendor_id_vendors_id_fk", + "tableFrom": "vendor_pq_submissions", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_pq_submissions_project_id_projects_id_fk": { + "name": "vendor_pq_submissions_project_id_projects_id_fk", + "tableFrom": "vendor_pq_submissions", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "vendor_pq_submissions_pq_number_unique": { + "name": "vendor_pq_submissions_pq_number_unique", + "nullsNotDistinct": false, + "columns": [ + "pq_number" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_pq_criteria_answers": { + "name": "vendor_pq_criteria_answers", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "criteria_id": { + "name": "criteria_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "answer": { + "name": "answer", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_pq_criteria_answers_vendor_id_vendors_id_fk": { + "name": "vendor_pq_criteria_answers_vendor_id_vendors_id_fk", + "tableFrom": "vendor_pq_criteria_answers", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_pq_criteria_answers_criteria_id_pq_criterias_id_fk": { + "name": "vendor_pq_criteria_answers_criteria_id_pq_criterias_id_fk", + "tableFrom": "vendor_pq_criteria_answers", + "tableTo": "pq_criterias", + "columnsFrom": [ + "criteria_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_pq_criteria_answers_project_id_projects_id_fk": { + "name": "vendor_pq_criteria_answers_project_id_projects_id_fk", + "tableFrom": "vendor_pq_criteria_answers", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_pq_review_logs": { + "name": "vendor_pq_review_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_pq_criteria_answer_id": { + "name": "vendor_pq_criteria_answer_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "reviewer_comment": { + "name": "reviewer_comment", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reviewer_name": { + "name": "reviewer_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_pq_review_logs_vendor_pq_criteria_answer_id_vendor_pq_criteria_answers_id_fk": { + "name": "vendor_pq_review_logs_vendor_pq_criteria_answer_id_vendor_pq_criteria_answers_id_fk", + "tableFrom": "vendor_pq_review_logs", + "tableTo": "vendor_pq_criteria_answers", + "columnsFrom": [ + "vendor_pq_criteria_answer_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_project_pqs": { + "name": "vendor_project_pqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'REQUESTED'" + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "rejected_at": { + "name": "rejected_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "reject_reason": { + "name": "reject_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_project_pqs_vendor_id_vendors_id_fk": { + "name": "vendor_project_pqs_vendor_id_vendors_id_fk", + "tableFrom": "vendor_project_pqs", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + }, + "vendor_project_pqs_project_id_projects_id_fk": { + "name": "vendor_project_pqs_project_id_projects_id_fk", + "tableFrom": "vendor_project_pqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "cascade" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.bidding_projects": { + "name": "bidding_projects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "pspid": { + "name": "pspid", + "type": "char(24)", + "primaryKey": false, + "notNull": true + }, + "proj_nm": { + "name": "proj_nm", + "type": "varchar(90)", + "primaryKey": false, + "notNull": false + }, + "sector": { + "name": "sector", + "type": "char(1)", + "primaryKey": false, + "notNull": false + }, + "proj_msrm": { + "name": "proj_msrm", + "type": "numeric(3, 0)", + "primaryKey": false, + "notNull": false + }, + "kunnr": { + "name": "kunnr", + "type": "char(10)", + "primaryKey": false, + "notNull": false + }, + "kunnr_nm": { + "name": "kunnr_nm", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "cls_1": { + "name": "cls_1", + "type": "char(10)", + "primaryKey": false, + "notNull": false + }, + "cls1_nm": { + "name": "cls1_nm", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "ptype": { + "name": "ptype", + "type": "char(3)", + "primaryKey": false, + "notNull": false + }, + "ptype_nm": { + "name": "ptype_nm", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "pmodel_cd": { + "name": "pmodel_cd", + "type": "char(10)", + "primaryKey": false, + "notNull": false + }, + "pmodel_nm": { + "name": "pmodel_nm", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "pmodel_sz": { + "name": "pmodel_sz", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "pmodel_uom": { + "name": "pmodel_uom", + "type": "char(5)", + "primaryKey": false, + "notNull": false + }, + "txt04": { + "name": "txt04", + "type": "char(4)", + "primaryKey": false, + "notNull": false + }, + "txt30": { + "name": "txt30", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "estm_pm": { + "name": "estm_pm", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "bidding_projects_pspid_unique": { + "name": "bidding_projects_pspid_unique", + "nullsNotDistinct": false, + "columns": [ + "pspid" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.project_series": { + "name": "project_series", + "schema": "", + "columns": { + "pspid": { + "name": "pspid", + "type": "char(24)", + "primaryKey": false, + "notNull": true + }, + "sers_no": { + "name": "sers_no", + "type": "char(3)", + "primaryKey": false, + "notNull": true + }, + "sc_dt": { + "name": "sc_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "kl_dt": { + "name": "kl_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "lc_dt": { + "name": "lc_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "dl_dt": { + "name": "dl_dt", + "type": "char(8)", + "primaryKey": false, + "notNull": false + }, + "dock_no": { + "name": "dock_no", + "type": "char(3)", + "primaryKey": false, + "notNull": false + }, + "dock_nm": { + "name": "dock_nm", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "proj_no": { + "name": "proj_no", + "type": "char(24)", + "primaryKey": false, + "notNull": false + }, + "post1": { + "name": "post1", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "project_sersNo_unique": { + "name": "project_sersNo_unique", + "columns": [ + { + "expression": "pspid", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sers_no", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "project_series_pspid_bidding_projects_pspid_fk": { + "name": "project_series_pspid_bidding_projects_pspid_fk", + "tableFrom": "project_series", + "tableTo": "bidding_projects", + "columnsFrom": [ + "pspid" + ], + "columnsTo": [ + "pspid" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.projects": { + "name": "projects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'ship'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cbe_evaluations": { + "name": "cbe_evaluations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "evaluated_by": { + "name": "evaluated_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluated_at": { + "name": "evaluated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "result": { + "name": "result", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "total_cost": { + "name": "total_cost", + "type": "numeric(18, 2)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "payment_terms": { + "name": "payment_terms", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "incoterms": { + "name": "incoterms", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "delivery_schedule": { + "name": "delivery_schedule", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "cbe_evaluations_rfq_id_rfqs_id_fk": { + "name": "cbe_evaluations_rfq_id_rfqs_id_fk", + "tableFrom": "cbe_evaluations", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cbe_evaluations_vendor_id_vendors_id_fk": { + "name": "cbe_evaluations_vendor_id_vendors_id_fk", + "tableFrom": "cbe_evaluations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cbe_evaluations_evaluated_by_users_id_fk": { + "name": "cbe_evaluations_evaluated_by_users_id_fk", + "tableFrom": "cbe_evaluations", + "tableTo": "users", + "columnsFrom": [ + "evaluated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_attachments": { + "name": "rfq_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "evaluation_id": { + "name": "evaluation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cbe_id": { + "name": "cbe_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "comment_id": { + "name": "comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_attachments_rfq_id_rfqs_id_fk": { + "name": "rfq_attachments_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_vendor_id_vendors_id_fk": { + "name": "rfq_attachments_vendor_id_vendors_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_evaluation_id_rfq_evaluations_id_fk": { + "name": "rfq_attachments_evaluation_id_rfq_evaluations_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "rfq_evaluations", + "columnsFrom": [ + "evaluation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_cbe_id_cbe_evaluations_id_fk": { + "name": "rfq_attachments_cbe_id_cbe_evaluations_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "cbe_evaluations", + "columnsFrom": [ + "cbe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_attachments_comment_id_rfq_comments_id_fk": { + "name": "rfq_attachments_comment_id_rfq_comments_id_fk", + "tableFrom": "rfq_attachments", + "tableTo": "rfq_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_comments": { + "name": "rfq_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "comment_text": { + "name": "comment_text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "commented_by": { + "name": "commented_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "evaluation_id": { + "name": "evaluation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cbe_id": { + "name": "cbe_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_comments_rfq_id_rfqs_id_fk": { + "name": "rfq_comments_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_vendor_id_vendors_id_fk": { + "name": "rfq_comments_vendor_id_vendors_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_commented_by_users_id_fk": { + "name": "rfq_comments_commented_by_users_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "users", + "columnsFrom": [ + "commented_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_evaluation_id_rfq_evaluations_id_fk": { + "name": "rfq_comments_evaluation_id_rfq_evaluations_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "rfq_evaluations", + "columnsFrom": [ + "evaluation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_comments_cbe_id_vendor_responses_id_fk": { + "name": "rfq_comments_cbe_id_vendor_responses_id_fk", + "tableFrom": "rfq_comments", + "tableTo": "vendor_responses", + "columnsFrom": [ + "cbe_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_evaluations": { + "name": "rfq_evaluations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "eval_type": { + "name": "eval_type", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_evaluations_rfq_id_rfqs_id_fk": { + "name": "rfq_evaluations_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_evaluations", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "rfq_evaluations_vendor_id_vendors_id_fk": { + "name": "rfq_evaluations_vendor_id_vendors_id_fk", + "tableFrom": "rfq_evaluations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfq_items": { + "name": "rfq_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "uom": { + "name": "uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfq_items_rfq_id_rfqs_id_fk": { + "name": "rfq_items_rfq_id_rfqs_id_fk", + "tableFrom": "rfq_items", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "rfq_items_item_code_items_item_code_fk": { + "name": "rfq_items_item_code_items_item_code_fk", + "tableFrom": "rfq_items", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.rfqs": { + "name": "rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "bid_project_id": { + "name": "bid_project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "rfq_type": { + "name": "rfq_type", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false, + "default": "'PURCHASE'" + }, + "parent_rfq_id": { + "name": "parent_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "rfqs_project_id_projects_id_fk": { + "name": "rfqs_project_id_projects_id_fk", + "tableFrom": "rfqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "rfqs_bid_project_id_bidding_projects_id_fk": { + "name": "rfqs_bid_project_id_bidding_projects_id_fk", + "tableFrom": "rfqs", + "tableTo": "bidding_projects", + "columnsFrom": [ + "bid_project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "rfqs_created_by_users_id_fk": { + "name": "rfqs_created_by_users_id_fk", + "tableFrom": "rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "rfqs_parent_rfq_id_rfqs_id_fk": { + "name": "rfqs_parent_rfq_id_rfqs_id_fk", + "tableFrom": "rfqs", + "tableTo": "rfqs", + "columnsFrom": [ + "parent_rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "rfqs_rfq_code_unique": { + "name": "rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_commercial_responses": { + "name": "vendor_commercial_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "response_id": { + "name": "response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "total_price": { + "name": "total_price", + "type": "numeric(18, 2)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "payment_terms": { + "name": "payment_terms", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "incoterms": { + "name": "incoterms", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "delivery_period": { + "name": "delivery_period", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "warranty_period": { + "name": "warranty_period", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "validity_period": { + "name": "validity_period", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "price_breakdown": { + "name": "price_breakdown", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "commercial_notes": { + "name": "commercial_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_commercial_responses_response_id_vendor_responses_id_fk": { + "name": "vendor_commercial_responses_response_id_vendor_responses_id_fk", + "tableFrom": "vendor_commercial_responses", + "tableTo": "vendor_responses", + "columnsFrom": [ + "response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_response_attachments": { + "name": "vendor_response_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "response_id": { + "name": "response_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "technical_response_id": { + "name": "technical_response_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "commercial_response_id": { + "name": "commercial_response_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_response_attachments_response_id_vendor_responses_id_fk": { + "name": "vendor_response_attachments_response_id_vendor_responses_id_fk", + "tableFrom": "vendor_response_attachments", + "tableTo": "vendor_responses", + "columnsFrom": [ + "response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_attachments_technical_response_id_vendor_technical_responses_id_fk": { + "name": "vendor_response_attachments_technical_response_id_vendor_technical_responses_id_fk", + "tableFrom": "vendor_response_attachments", + "tableTo": "vendor_technical_responses", + "columnsFrom": [ + "technical_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_attachments_commercial_response_id_vendor_commercial_responses_id_fk": { + "name": "vendor_response_attachments_commercial_response_id_vendor_commercial_responses_id_fk", + "tableFrom": "vendor_response_attachments", + "tableTo": "vendor_commercial_responses", + "columnsFrom": [ + "commercial_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_responses": { + "name": "vendor_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'REVIEWING'" + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "responded_by": { + "name": "responded_by", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "responded_at": { + "name": "responded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "vendor_response_unique": { + "name": "vendor_response_unique", + "columns": [ + { + "expression": "rfq_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "vendor_responses_rfq_id_rfqs_id_fk": { + "name": "vendor_responses_rfq_id_rfqs_id_fk", + "tableFrom": "vendor_responses", + "tableTo": "rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_responses_vendor_id_vendors_id_fk": { + "name": "vendor_responses_vendor_id_vendors_id_fk", + "tableFrom": "vendor_responses", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_technical_responses": { + "name": "vendor_technical_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "response_id": { + "name": "response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_technical_responses_response_id_vendor_responses_id_fk": { + "name": "vendor_technical_responses_response_id_vendor_responses_id_fk", + "tableFrom": "vendor_technical_responses", + "tableTo": "vendor_responses", + "columnsFrom": [ + "response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.otps": { + "name": "otps", + "schema": "", + "columns": { + "email": { + "name": "email", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(6)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "otpToken": { + "name": "otpToken", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "otp_expires": { + "name": "otp_expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.permissions": { + "name": "permissions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "permissions_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "permission_key": { + "name": "permission_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.role_permissions": { + "name": "role_permissions", + "schema": "", + "columns": { + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "permission_id": { + "name": "permission_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "role_permissions_role_id_roles_id_fk": { + "name": "role_permissions_role_id_roles_id_fk", + "tableFrom": "role_permissions", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "role_permissions_permission_id_permissions_id_fk": { + "name": "role_permissions_permission_id_permissions_id_fk", + "tableFrom": "role_permissions", + "tableTo": "permissions", + "columnsFrom": [ + "permission_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.roles": { + "name": "roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "roles_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "user_domain", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "roles_company_id_vendors_id_fk": { + "name": "roles_company_id_vendors_id_fk", + "tableFrom": "roles", + "tableTo": "vendors", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user_roles": { + "name": "user_roles", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_roles_user_id_users_id_fk": { + "name": "user_roles_user_id_users_id_fk", + "tableFrom": "user_roles", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_roles_role_id_roles_id_fk": { + "name": "user_roles_role_id_roles_id_fk", + "tableFrom": "user_roles", + "tableTo": "roles", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "users_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "domain": { + "name": "domain", + "type": "user_domain", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'partners'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "image_url": { + "name": "image_url", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false + }, + "language": { + "name": "language", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'en'" + } + }, + "indexes": {}, + "foreignKeys": { + "users_company_id_vendors_id_fk": { + "name": "users_company_id_vendors_id_fk", + "tableFrom": "users", + "tableTo": "vendors", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.form_entries": { + "name": "form_entries", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "form_entries_contract_item_id_contract_items_id_fk": { + "name": "form_entries_contract_item_id_contract_items_id_fk", + "tableFrom": "form_entries", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.form_metas": { + "name": "form_metas", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "form_name": { + "name": "form_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "columns": { + "name": "columns", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "form_metas_project_id_projects_id_fk": { + "name": "form_metas_project_id_projects_id_fk", + "tableFrom": "form_metas", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "form_code_project_unique": { + "name": "form_code_project_unique", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "form_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.forms": { + "name": "forms", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "forms_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "form_name": { + "name": "form_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "eng": { + "name": "eng", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "im": { + "name": "im", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "contract_item_form_code_unique": { + "name": "contract_item_form_code_unique", + "columns": [ + { + "expression": "contract_item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "form_code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "forms_contract_item_id_contract_items_id_fk": { + "name": "forms_contract_item_id_contract_items_id_fk", + "tableFrom": "forms", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_class_attributes": { + "name": "tag_class_attributes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "tag_class_attributes_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "tag_class_id": { + "name": "tag_class_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "att_id": { + "name": "att_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "def_val": { + "name": "def_val", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "uom_id": { + "name": "uom_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "seq": { + "name": "seq", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "tag_class_attributes_seq_idx": { + "name": "tag_class_attributes_seq_idx", + "columns": [ + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tag_class_attributes_tag_class_id_tag_classes_id_fk": { + "name": "tag_class_attributes_tag_class_id_tag_classes_id_fk", + "tableFrom": "tag_class_attributes", + "tableTo": "tag_classes", + "columnsFrom": [ + "tag_class_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_att_id_in_tag_class": { + "name": "uniq_att_id_in_tag_class", + "nullsNotDistinct": false, + "columns": [ + "tag_class_id", + "att_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_classes": { + "name": "tag_classes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "tag_classes_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tag_type_code": { + "name": "tag_type_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_classes_project_id_projects_id_fk": { + "name": "tag_classes_project_id_projects_id_fk", + "tableFrom": "tag_classes", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tag_classes_tag_type_code_project_id_tag_types_code_project_id_fk": { + "name": "tag_classes_tag_type_code_project_id_tag_types_code_project_id_fk", + "tableFrom": "tag_classes", + "tableTo": "tag_types", + "columnsFrom": [ + "tag_type_code", + "project_id" + ], + "columnsTo": [ + "code", + "project_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_code_in_project": { + "name": "uniq_code_in_project", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_subfield_options": { + "name": "tag_subfield_options", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "attributes_id": { + "name": "attributes_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_subfield_options_project_id_projects_id_fk": { + "name": "tag_subfield_options_project_id_projects_id_fk", + "tableFrom": "tag_subfield_options", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_attribute_project_code": { + "name": "uniq_attribute_project_code", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "attributes_id", + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_subfields": { + "name": "tag_subfields", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "tag_type_code": { + "name": "tag_type_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "attributes_id": { + "name": "attributes_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "attributes_description": { + "name": "attributes_description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expression": { + "name": "expression", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delimiter": { + "name": "delimiter", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_subfields_project_id_projects_id_fk": { + "name": "tag_subfields_project_id_projects_id_fk", + "tableFrom": "tag_subfields", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_tag_type_attribute": { + "name": "uniq_tag_type_attribute", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "tag_type_code", + "attributes_id" + ] + }, + "uniq_attribute_id_project": { + "name": "uniq_attribute_id_project", + "nullsNotDistinct": false, + "columns": [ + "attributes_id", + "project_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_type_class_form_mappings": { + "name": "tag_type_class_form_mappings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "tag_type_label": { + "name": "tag_type_label", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "class_label": { + "name": "class_label", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "form_code": { + "name": "form_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "form_name": { + "name": "form_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "ep": { + "name": "ep", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uniq_mapping_in_project": { + "name": "uniq_mapping_in_project", + "nullsNotDistinct": false, + "columns": [ + "project_id", + "tag_type_label", + "class_label", + "form_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tag_types": { + "name": "tag_types", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tag_types_project_id_projects_id_fk": { + "name": "tag_types_project_id_projects_id_fk", + "tableFrom": "tag_types", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "tag_types_code_project_id_pk": { + "name": "tag_types_code_project_id_pk", + "columns": [ + "code", + "project_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tags": { + "name": "tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "tags_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_id": { + "name": "form_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tag_no": { + "name": "tag_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "tag_type": { + "name": "tag_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "class": { + "name": "class", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tags_contract_item_id_contract_items_id_fk": { + "name": "tags_contract_item_id_contract_items_id_fk", + "tableFrom": "tags", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tags_form_id_forms_id_fk": { + "name": "tags_form_id_forms_id_fk", + "tableFrom": "tags", + "tableTo": "forms", + "columnsFrom": [ + "form_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "contract_item_tag_no_unique": { + "name": "contract_item_tag_no_unique", + "nullsNotDistinct": false, + "columns": [ + "contract_item_id", + "tag_no" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_data_report_temps": { + "name": "vendor_data_report_temps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_item_id": { + "name": "contract_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "form_id": { + "name": "form_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_data_report_temps_contract_item_id_contract_items_id_fk": { + "name": "vendor_data_report_temps_contract_item_id_contract_items_id_fk", + "tableFrom": "vendor_data_report_temps", + "tableTo": "contract_items", + "columnsFrom": [ + "contract_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_data_report_temps_form_id_forms_id_fk": { + "name": "vendor_data_report_temps_form_id_forms_id_fk", + "tableFrom": "vendor_data_report_temps", + "tableTo": "forms", + "columnsFrom": [ + "form_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.change_logs": { + "name": "change_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "entity_type": { + "name": "entity_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "entity_id": { + "name": "entity_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "changed_fields": { + "name": "changed_fields", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "old_values": { + "name": "old_values", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "new_values": { + "name": "new_values", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_name": { + "name": "user_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "is_synced": { + "name": "is_synced", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "sync_attempts": { + "name": "sync_attempts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "synced_at": { + "name": "synced_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "target_systems": { + "name": "target_systems", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'[]'::jsonb" + } + }, + "indexes": { + "idx_change_logs_contract_synced": { + "name": "idx_change_logs_contract_synced", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "is_synced", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_change_logs_created_at": { + "name": "idx_change_logs_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_change_logs_entity": { + "name": "idx_change_logs_entity", + "columns": [ + { + "expression": "entity_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entity_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_change_logs_sync_attempts": { + "name": "idx_change_logs_sync_attempts", + "columns": [ + { + "expression": "sync_attempts", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.document_attachments": { + "name": "document_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "document_attachments_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "revision_id": { + "name": "revision_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "upload_id": { + "name": "upload_id", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false + }, + "file_id": { + "name": "file_id", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "dolce_file_path": { + "name": "dolce_file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "document_attachments_revision_id_revisions_id_fk": { + "name": "document_attachments_revision_id_revisions_id_fk", + "tableFrom": "document_attachments", + "tableTo": "revisions", + "columnsFrom": [ + "revision_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.documents": { + "name": "documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "documents_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "pic": { + "name": "pic", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "vendor_doc_number": { + "name": "vendor_doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "drawing_kind": { + "name": "drawing_kind", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "drawing_move_gbn": { + "name": "drawing_move_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "discipline": { + "name": "discipline", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "external_document_id": { + "name": "external_document_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "external_system_type": { + "name": "external_system_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "external_synced_at": { + "name": "external_synced_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "c_gbn": { + "name": "c_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "d_gbn": { + "name": "d_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "degree_gbn": { + "name": "degree_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "dept_gbn": { + "name": "dept_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "j_gbn": { + "name": "j_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "s_gbn": { + "name": "s_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "shi_drawing_no": { + "name": "shi_drawing_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "manager": { + "name": "manager", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "manager_enm": { + "name": "manager_enm", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "manager_no": { + "name": "manager_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "register_group": { + "name": "register_group", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "register_group_id": { + "name": "register_group_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "create_user_no": { + "name": "create_user_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "create_user_id": { + "name": "create_user_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "create_user_enm": { + "name": "create_user_enm", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_contract_doc_status": { + "name": "unique_contract_doc_status", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "doc_number", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "unique_contract_vendor_doc": { + "name": "unique_contract_vendor_doc", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor_doc_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"documents\".\"vendor_doc_number\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "unique_external_doc": { + "name": "unique_external_doc", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_system_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"documents\".\"external_document_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "drawing_kind_idx": { + "name": "drawing_kind_idx", + "columns": [ + { + "expression": "drawing_kind", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "documents_contract_id_contracts_id_fk": { + "name": "documents_contract_id_contracts_id_fk", + "tableFrom": "documents", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.issue_stages": { + "name": "issue_stages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "issue_stages_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "document_id": { + "name": "document_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stage_name": { + "name": "stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "plan_date": { + "name": "plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "actual_date": { + "name": "actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "stage_status": { + "name": "stage_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'PLANNED'" + }, + "stage_order": { + "name": "stage_order", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "priority": { + "name": "priority", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false, + "default": "'MEDIUM'" + }, + "assignee_id": { + "name": "assignee_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "assignee_name": { + "name": "assignee_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "reminder_days": { + "name": "reminder_days", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "varchar(1000)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_document_stage": { + "name": "unique_document_stage", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stage_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_stage_order": { + "name": "document_stage_order", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stage_order", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "issue_stages_document_id_documents_id_fk": { + "name": "issue_stages_document_id_documents_id_fk", + "tableFrom": "issue_stages", + "tableTo": "documents", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.revisions": { + "name": "revisions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "revisions_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "issue_stage_id": { + "name": "issue_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "uploader_type": { + "name": "uploader_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'vendor'" + }, + "uploader_id": { + "name": "uploader_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploader_name": { + "name": "uploader_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "usage": { + "name": "usage", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "revision_status": { + "name": "revision_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'SUBMITTED'" + }, + "submitted_date": { + "name": "submitted_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "review_start_date": { + "name": "review_start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "approved_date": { + "name": "approved_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "rejected_date": { + "name": "rejected_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "reviewer_id": { + "name": "reviewer_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "reviewer_name": { + "name": "reviewer_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "review_comments": { + "name": "review_comments", + "type": "varchar(1000)", + "primaryKey": false, + "notNull": false + }, + "external_upload_id": { + "name": "external_upload_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "unique_stage_rev": { + "name": "unique_stage_rev", + "columns": [ + { + "expression": "issue_stage_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "revision", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sync_batches": { + "name": "sync_batches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_system": { + "name": "target_system", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "batch_size": { + "name": "batch_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "retry_count": { + "name": "retry_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "change_log_ids": { + "name": "change_log_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "success_count": { + "name": "success_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "failure_count": { + "name": "failure_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "sync_metadata": { + "name": "sync_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_sync_batches_contract_system": { + "name": "idx_sync_batches_contract_system", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_system", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_sync_batches_status": { + "name": "idx_sync_batches_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_sync_batches_created_at": { + "name": "idx_sync_batches_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sync_configs": { + "name": "sync_configs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_system": { + "name": "target_system", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "sync_enabled": { + "name": "sync_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "sync_interval_minutes": { + "name": "sync_interval_minutes", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 30 + }, + "last_successful_sync": { + "name": "last_successful_sync", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_sync_attempt": { + "name": "last_sync_attempt", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "endpoint_url": { + "name": "endpoint_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "auth_token": { + "name": "auth_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "api_version": { + "name": "api_version", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false, + "default": "'v1'" + }, + "max_batch_size": { + "name": "max_batch_size", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 100 + }, + "retry_max_attempts": { + "name": "retry_max_attempts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 3 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_sync_configs_contract_system": { + "name": "idx_sync_configs_contract_system", + "columns": [ + { + "expression": "contract_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_system", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sync_configs_contract_id_contracts_id_fk": { + "name": "sync_configs_contract_id_contracts_id_fk", + "tableFrom": "sync_configs", + "tableTo": "contracts", + "columnsFrom": [ + "contract_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_attachments": { + "name": "vendor_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'GENERAL'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_attachments_vendor_id_vendors_id_fk": { + "name": "vendor_attachments_vendor_id_vendors_id_fk", + "tableFrom": "vendor_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_candidates": { + "name": "vendor_candidates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_name": { + "name": "company_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_email": { + "name": "contact_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "contact_phone": { + "name": "contact_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'COLLECTED'" + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_candidates_vendor_id_vendors_id_fk": { + "name": "vendor_candidates_vendor_id_vendors_id_fk", + "tableFrom": "vendor_candidates", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_contacts": { + "name": "vendor_contacts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "contact_name": { + "name": "contact_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_position": { + "name": "contact_position", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "contact_email": { + "name": "contact_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_phone": { + "name": "contact_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "is_primary": { + "name": "is_primary", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_contacts_vendor_id_vendors_id_fk": { + "name": "vendor_contacts_vendor_id_vendors_id_fk", + "tableFrom": "vendor_contacts", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_possible_items": { + "name": "vendor_possible_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_possible_items_vendor_id_vendors_id_fk": { + "name": "vendor_possible_items_vendor_id_vendors_id_fk", + "tableFrom": "vendor_possible_items", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_possible_items_item_code_items_item_code_fk": { + "name": "vendor_possible_items_item_code_items_item_code_fk", + "tableFrom": "vendor_possible_items", + "tableTo": "items", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_possible_materials": { + "name": "vendor_possible_materials", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_possible_materials_vendor_id_vendors_id_fk": { + "name": "vendor_possible_materials_vendor_id_vendors_id_fk", + "tableFrom": "vendor_possible_materials", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "vendor_possible_materials_item_code_materials_item_code_fk": { + "name": "vendor_possible_materials_item_code_materials_item_code_fk", + "tableFrom": "vendor_possible_materials", + "tableTo": "materials", + "columnsFrom": [ + "item_code" + ], + "columnsTo": [ + "item_code" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_types": { + "name": "vendor_types", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name_ko": { + "name": "name_ko", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "name_en": { + "name": "name_en", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "vendor_types_code_unique": { + "name": "vendor_types_code_unique", + "nullsNotDistinct": false, + "columns": [ + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendors": { + "name": "vendors", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "website": { + "name": "website", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING_REVIEW'" + }, + "vendor_type_id": { + "name": "vendor_type_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "representative_name": { + "name": "representative_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_birth": { + "name": "representative_birth", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "representative_email": { + "name": "representative_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_phone": { + "name": "representative_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "corporate_registration_number": { + "name": "corporate_registration_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credit_agency": { + "name": "credit_agency", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "credit_rating": { + "name": "credit_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "cash_flow_rating": { + "name": "cash_flow_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "business_size": { + "name": "business_size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendors_vendor_type_id_vendor_types_id_fk": { + "name": "vendors_vendor_type_id_vendor_types_id_fk", + "tableFrom": "vendors", + "tableTo": "vendor_types", + "columnsFrom": [ + "vendor_type_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tasks": { + "name": "tasks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(30)", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'todo'" + }, + "label": { + "name": "label", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'bug'" + }, + "priority": { + "name": "priority", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'low'" + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "current_timestamp" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "tasks_code_unique": { + "name": "tasks_code_unique", + "nullsNotDistinct": false, + "columns": [ + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_candidate_logs": { + "name": "vendor_candidate_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_candidate_id": { + "name": "vendor_candidate_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "old_status": { + "name": "old_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "new_status": { + "name": "new_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_candidate_logs_vendor_candidate_id_vendor_candidates_id_fk": { + "name": "vendor_candidate_logs_vendor_candidate_id_vendor_candidates_id_fk", + "tableFrom": "vendor_candidate_logs", + "tableTo": "vendor_candidates", + "columnsFrom": [ + "vendor_candidate_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_candidate_logs_user_id_users_id_fk": { + "name": "vendor_candidate_logs_user_id_users_id_fk", + "tableFrom": "vendor_candidate_logs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendors_logs": { + "name": "vendors_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "old_status": { + "name": "old_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "new_status": { + "name": "new_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendors_logs_vendor_id_vendors_id_fk": { + "name": "vendors_logs_vendor_id_vendors_id_fk", + "tableFrom": "vendors_logs", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendors_logs_user_id_users_id_fk": { + "name": "vendors_logs_user_id_users_id_fk", + "tableFrom": "vendors_logs", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.basic_contract": { + "name": "basic_contract", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "basic_contract_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "template_id": { + "name": "template_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requested_by": { + "name": "requested_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'PENDING'" + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "basic_contract_template_id_basic_contract_templates_id_fk": { + "name": "basic_contract_template_id_basic_contract_templates_id_fk", + "tableFrom": "basic_contract", + "tableTo": "basic_contract_templates", + "columnsFrom": [ + "template_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "basic_contract_vendor_id_vendors_id_fk": { + "name": "basic_contract_vendor_id_vendors_id_fk", + "tableFrom": "basic_contract", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "basic_contract_requested_by_users_id_fk": { + "name": "basic_contract_requested_by_users_id_fk", + "tableFrom": "basic_contract", + "tableTo": "users", + "columnsFrom": [ + "requested_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.basic_contract_templates": { + "name": "basic_contract_templates", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "basic_contract_templates_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "template_name": { + "name": "template_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "validity_period": { + "name": "validity_period", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.incoterms": { + "name": "incoterms", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "varchar(20)", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "incoterms_created_by_users_id_fk": { + "name": "incoterms_created_by_users_id_fk", + "tableFrom": "incoterms", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.payment_terms": { + "name": "payment_terms", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": true, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "payment_terms_created_by_users_id_fk": { + "name": "payment_terms_created_by_users_id_fk", + "tableFrom": "payment_terms", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pr_items": { + "name": "pr_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_item": { + "name": "rfq_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_item": { + "name": "pr_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_no": { + "name": "pr_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "material_code": { + "name": "material_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_category": { + "name": "material_category", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "acc": { + "name": "acc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_description": { + "name": "material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "size": { + "name": "size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "uom": { + "name": "uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "gross_weight": { + "name": "gross_weight", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "gw_uom": { + "name": "gw_uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "spec_no": { + "name": "spec_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "spec_url": { + "name": "spec_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "tracking_no": { + "name": "tracking_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "major_yn": { + "name": "major_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "project_def": { + "name": "project_def", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_sc": { + "name": "project_sc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_kl": { + "name": "project_kl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_lc": { + "name": "project_lc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_dl": { + "name": "project_dl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pr_items_procurement_rfqs_id_procurement_rfqs_id_fk": { + "name": "pr_items_procurement_rfqs_id_procurement_rfqs_id_fk", + "tableFrom": "pr_items", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "procurement_rfqs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_attachments": { + "name": "procurement_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "procurement_rfq_details_id": { + "name": "procurement_rfq_details_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_attachments_procurement_rfqs_id_procurement_rfqs_id_fk": { + "name": "procurement_attachments_procurement_rfqs_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_attachments", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "procurement_rfqs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_attachments_procurement_rfq_details_id_procurement_rfq_details_id_fk": { + "name": "procurement_attachments_procurement_rfq_details_id_procurement_rfq_details_id_fk", + "tableFrom": "procurement_attachments", + "tableTo": "procurement_rfq_details", + "columnsFrom": [ + "procurement_rfq_details_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_attachments_created_by_users_id_fk": { + "name": "procurement_attachments_created_by_users_id_fk", + "tableFrom": "procurement_attachments", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "attachment_type_check": { + "name": "attachment_type_check", + "value": "\"procurement_attachments\".\"procurement_rfqs_id\" IS NOT NULL OR \"procurement_attachments\".\"procurement_rfq_details_id\" IS NOT NULL" + } + }, + "isRLSEnabled": false + }, + "public.procurement_quotation_items": { + "name": "procurement_quotation_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "quotation_id": { + "name": "quotation_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pr_item_id": { + "name": "pr_item_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "material_code": { + "name": "material_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "material_description": { + "name": "material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "uom": { + "name": "uom", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "unit_price": { + "name": "unit_price", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "total_price": { + "name": "total_price", + "type": "numeric", + "primaryKey": false, + "notNull": true + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "vendor_material_code": { + "name": "vendor_material_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_material_description": { + "name": "vendor_material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "lead_time_in_days": { + "name": "lead_time_in_days", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tax_rate": { + "name": "tax_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "tax_amount": { + "name": "tax_amount", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "discount_rate": { + "name": "discount_rate", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "discount_amount": { + "name": "discount_amount", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_alternative": { + "name": "is_alternative", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "is_recommended": { + "name": "is_recommended", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_quotation_items_quotation_id_procurement_vendor_quotations_id_fk": { + "name": "procurement_quotation_items_quotation_id_procurement_vendor_quotations_id_fk", + "tableFrom": "procurement_quotation_items", + "tableTo": "procurement_vendor_quotations", + "columnsFrom": [ + "quotation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_quotation_items_pr_item_id_pr_items_id_fk": { + "name": "procurement_quotation_items_pr_item_id_pr_items_id_fk", + "tableFrom": "procurement_quotation_items", + "tableTo": "pr_items", + "columnsFrom": [ + "pr_item_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfq_attachments": { + "name": "procurement_rfq_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "comment_id": { + "name": "comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "quotation_id": { + "name": "quotation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "file_path": { + "name": "file_path", + "type": "varchar(500)", + "primaryKey": false, + "notNull": true + }, + "is_vendor_upload": { + "name": "is_vendor_upload", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfq_attachments_rfq_id_procurement_rfqs_id_fk": { + "name": "procurement_rfq_attachments_rfq_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_comment_id_procurement_rfq_comments_id_fk": { + "name": "procurement_rfq_attachments_comment_id_procurement_rfq_comments_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "procurement_rfq_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_quotation_id_procurement_vendor_quotations_id_fk": { + "name": "procurement_rfq_attachments_quotation_id_procurement_vendor_quotations_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "procurement_vendor_quotations", + "columnsFrom": [ + "quotation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_uploaded_by_users_id_fk": { + "name": "procurement_rfq_attachments_uploaded_by_users_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_attachments_vendor_id_vendors_id_fk": { + "name": "procurement_rfq_attachments_vendor_id_vendors_id_fk", + "tableFrom": "procurement_rfq_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfq_comments": { + "name": "procurement_rfq_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_vendor_comment": { + "name": "is_vendor_comment", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "is_read": { + "name": "is_read", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "parent_comment_id": { + "name": "parent_comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfq_comments_rfq_id_procurement_rfqs_id_fk": { + "name": "procurement_rfq_comments_rfq_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_rfq_comments_vendor_id_vendors_id_fk": { + "name": "procurement_rfq_comments_vendor_id_vendors_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_comments_user_id_users_id_fk": { + "name": "procurement_rfq_comments_user_id_users_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_comments_parent_comment_id_procurement_rfq_comments_id_fk": { + "name": "procurement_rfq_comments_parent_comment_id_procurement_rfq_comments_id_fk", + "tableFrom": "procurement_rfq_comments", + "tableTo": "procurement_rfq_comments", + "columnsFrom": [ + "parent_comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfq_details": { + "name": "procurement_rfq_details", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendors_id": { + "name": "vendors_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_detail": { + "name": "incoterms_detail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "tax_code": { + "name": "tax_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "default": "'VV'" + }, + "place_of_shipping": { + "name": "place_of_shipping", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_destination": { + "name": "place_of_destination", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "material_price_related_yn": { + "name": "material_price_related_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfq_details_procurement_rfqs_id_procurement_rfqs_id_fk": { + "name": "procurement_rfq_details_procurement_rfqs_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "procurement_rfqs_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_vendors_id_vendors_id_fk": { + "name": "procurement_rfq_details_vendors_id_vendors_id_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "vendors", + "columnsFrom": [ + "vendors_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_payment_terms_code_payment_terms_code_fk": { + "name": "procurement_rfq_details_payment_terms_code_payment_terms_code_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "payment_terms", + "columnsFrom": [ + "payment_terms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_incoterms_code_incoterms_code_fk": { + "name": "procurement_rfq_details_incoterms_code_incoterms_code_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfq_details_updated_by_users_id_fk": { + "name": "procurement_rfq_details_updated_by_users_id_fk", + "tableFrom": "procurement_rfq_details", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_rfqs": { + "name": "procurement_rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "series": { + "name": "series", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "rfq_send_date": { + "name": "rfq_send_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'RFQ Created'" + }, + "rfq_sealed_yn": { + "name": "rfq_sealed_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_by": { + "name": "sent_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_rfqs_project_id_projects_id_fk": { + "name": "procurement_rfqs_project_id_projects_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfqs_sent_by_users_id_fk": { + "name": "procurement_rfqs_sent_by_users_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "users", + "columnsFrom": [ + "sent_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfqs_created_by_users_id_fk": { + "name": "procurement_rfqs_created_by_users_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_rfqs_updated_by_users_id_fk": { + "name": "procurement_rfqs_updated_by_users_id_fk", + "tableFrom": "procurement_rfqs", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "procurement_rfqs_rfq_code_unique": { + "name": "procurement_rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.procurement_vendor_quotations": { + "name": "procurement_vendor_quotations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "quotation_code": { + "name": "quotation_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "quotation_version": { + "name": "quotation_version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "total_items_count": { + "name": "total_items_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "sub_total": { + "name": "sub_total", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "tax_total": { + "name": "tax_total", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "discount_total": { + "name": "discount_total", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "total_price": { + "name": "total_price", + "type": "numeric", + "primaryKey": false, + "notNull": false, + "default": "'0'" + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'USD'" + }, + "valid_until": { + "name": "valid_until", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "estimated_delivery_date": { + "name": "estimated_delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_detail": { + "name": "incoterms_detail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'Draft'" + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rejection_reason": { + "name": "rejection_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "procurement_vendor_quotations_rfq_id_procurement_rfqs_id_fk": { + "name": "procurement_vendor_quotations_rfq_id_procurement_rfqs_id_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "procurement_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "procurement_vendor_quotations_vendor_id_vendors_id_fk": { + "name": "procurement_vendor_quotations_vendor_id_vendors_id_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_vendor_quotations_payment_terms_code_payment_terms_code_fk": { + "name": "procurement_vendor_quotations_payment_terms_code_payment_terms_code_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "payment_terms", + "columnsFrom": [ + "payment_terms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "procurement_vendor_quotations_incoterms_code_incoterms_code_fk": { + "name": "procurement_vendor_quotations_incoterms_code_incoterms_code_fk", + "tableFrom": "procurement_vendor_quotations", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.preset_shares": { + "name": "preset_shares", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "preset_id": { + "name": "preset_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "shared_with_user_id": { + "name": "shared_with_user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "permission": { + "name": "permission", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'read'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "preset_shares_preset_id_table_presets_id_fk": { + "name": "preset_shares_preset_id_table_presets_id_fk", + "tableFrom": "preset_shares", + "tableTo": "table_presets", + "columnsFrom": [ + "preset_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.table_presets": { + "name": "table_presets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "table_id": { + "name": "table_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "settings": { + "name": "settings", + "type": "json", + "primaryKey": false, + "notNull": true + }, + "is_default": { + "name": "is_default", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_shared": { + "name": "is_shared", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_attachments": { + "name": "tech_sales_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "tech_sales_rfq_id": { + "name": "tech_sales_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_attachments_tech_sales_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_attachments_tech_sales_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_attachments", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "tech_sales_rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_attachments_created_by_users_id_fk": { + "name": "tech_sales_attachments_created_by_users_id_fk", + "tableFrom": "tech_sales_attachments", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_rfq_comment_attachments": { + "name": "tech_sales_rfq_comment_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "comment_id": { + "name": "comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "quotation_id": { + "name": "quotation_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "file_path": { + "name": "file_path", + "type": "varchar(500)", + "primaryKey": false, + "notNull": true + }, + "is_vendor_upload": { + "name": "is_vendor_upload", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_rfq_comment_attachments_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_rfq_comment_attachments_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_comment_id_tech_sales_rfq_comments_id_fk": { + "name": "tech_sales_rfq_comment_attachments_comment_id_tech_sales_rfq_comments_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "tech_sales_rfq_comments", + "columnsFrom": [ + "comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_quotation_id_tech_sales_vendor_quotations_id_fk": { + "name": "tech_sales_rfq_comment_attachments_quotation_id_tech_sales_vendor_quotations_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "tech_sales_vendor_quotations", + "columnsFrom": [ + "quotation_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_uploaded_by_users_id_fk": { + "name": "tech_sales_rfq_comment_attachments_uploaded_by_users_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfq_comment_attachments_vendor_id_vendors_id_fk": { + "name": "tech_sales_rfq_comment_attachments_vendor_id_vendors_id_fk", + "tableFrom": "tech_sales_rfq_comment_attachments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_rfq_comments": { + "name": "tech_sales_rfq_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_vendor_comment": { + "name": "is_vendor_comment", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "is_read": { + "name": "is_read", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "parent_comment_id": { + "name": "parent_comment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_rfq_comments_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_rfq_comments_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfq_comments_vendor_id_vendors_id_fk": { + "name": "tech_sales_rfq_comments_vendor_id_vendors_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfq_comments_user_id_users_id_fk": { + "name": "tech_sales_rfq_comments_user_id_users_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfq_comments_parent_comment_id_tech_sales_rfq_comments_id_fk": { + "name": "tech_sales_rfq_comments_parent_comment_id_tech_sales_rfq_comments_id_fk", + "tableFrom": "tech_sales_rfq_comments", + "tableTo": "tech_sales_rfq_comments", + "columnsFrom": [ + "parent_comment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_rfqs": { + "name": "tech_sales_rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "item_shipbuilding_id": { + "name": "item_shipbuilding_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "bidding_project_id": { + "name": "bidding_project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "material_code": { + "name": "material_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "rfq_send_date": { + "name": "rfq_send_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'RFQ Created'" + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_by": { + "name": "sent_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "cancel_reason": { + "name": "cancel_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_snapshot": { + "name": "project_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "series_snapshot": { + "name": "series_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_rfqs_item_shipbuilding_id_item_shipbuilding_id_fk": { + "name": "tech_sales_rfqs_item_shipbuilding_id_item_shipbuilding_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "item_shipbuilding", + "columnsFrom": [ + "item_shipbuilding_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_rfqs_bidding_project_id_bidding_projects_id_fk": { + "name": "tech_sales_rfqs_bidding_project_id_bidding_projects_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "bidding_projects", + "columnsFrom": [ + "bidding_project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfqs_sent_by_users_id_fk": { + "name": "tech_sales_rfqs_sent_by_users_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "users", + "columnsFrom": [ + "sent_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfqs_created_by_users_id_fk": { + "name": "tech_sales_rfqs_created_by_users_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "tech_sales_rfqs_updated_by_users_id_fk": { + "name": "tech_sales_rfqs_updated_by_users_id_fk", + "tableFrom": "tech_sales_rfqs", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "tech_sales_rfqs_rfq_code_unique": { + "name": "tech_sales_rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tech_sales_vendor_quotations": { + "name": "tech_sales_vendor_quotations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "quotation_code": { + "name": "quotation_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "quotation_version": { + "name": "quotation_version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "total_price": { + "name": "total_price", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "valid_until": { + "name": "valid_until", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'Draft'" + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rejection_reason": { + "name": "rejection_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "tech_sales_vendor_quotations_rfq_id_tech_sales_rfqs_id_fk": { + "name": "tech_sales_vendor_quotations_rfq_id_tech_sales_rfqs_id_fk", + "tableFrom": "tech_sales_vendor_quotations", + "tableTo": "tech_sales_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "tech_sales_vendor_quotations_vendor_id_vendors_id_fk": { + "name": "tech_sales_vendor_quotations_vendor_id_vendors_id_fk", + "tableFrom": "tech_sales_vendor_quotations", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_rotation_attempts": { + "name": "ocr_rotation_attempts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "rotation": { + "name": "rotation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "confidence": { + "name": "confidence", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "tables_found": { + "name": "tables_found", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "text_quality": { + "name": "text_quality", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "keyword_count": { + "name": "keyword_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "score": { + "name": "score", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "extracted_rows_count": { + "name": "extracted_rows_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "ocr_rotation_attempts_session_id_ocr_sessions_id_fk": { + "name": "ocr_rotation_attempts_session_id_ocr_sessions_id_fk", + "tableFrom": "ocr_rotation_attempts", + "tableTo": "ocr_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_rows": { + "name": "ocr_rows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "table_id": { + "name": "table_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "row_index": { + "name": "row_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "report_no": { + "name": "report_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "no": { + "name": "no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "identification_no": { + "name": "identification_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tag_no": { + "name": "tag_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "joint_no": { + "name": "joint_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "joint_type": { + "name": "joint_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "welding_date": { + "name": "welding_date", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "numeric(5, 4)", + "primaryKey": false, + "notNull": false + }, + "source_table": { + "name": "source_table", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "source_row": { + "name": "source_row", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_ocr_report_no_unique": { + "name": "idx_ocr_report_no_unique", + "columns": [ + { + "expression": "report_no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tag_no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "joint_no", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "joint_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "ocr_rows_table_id_ocr_tables_id_fk": { + "name": "ocr_rows_table_id_ocr_tables_id_fk", + "tableFrom": "ocr_rows", + "tableTo": "ocr_tables", + "columnsFrom": [ + "table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ocr_rows_session_id_ocr_sessions_id_fk": { + "name": "ocr_rows_session_id_ocr_sessions_id_fk", + "tableFrom": "ocr_rows", + "tableTo": "ocr_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "ocr_rows_user_id_users_id_fk": { + "name": "ocr_rows_user_id_users_id_fk", + "tableFrom": "ocr_rows", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_sessions": { + "name": "ocr_sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_type": { + "name": "file_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "processing_time": { + "name": "processing_time", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "best_rotation": { + "name": "best_rotation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_tables": { + "name": "total_tables", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "total_rows": { + "name": "total_rows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "image_enhanced": { + "name": "image_enhanced", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "pdf_converted": { + "name": "pdf_converted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "success": { + "name": "success", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "warnings": { + "name": "warnings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ocr_tables": { + "name": "ocr_tables", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "session_id": { + "name": "session_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "table_index": { + "name": "table_index", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "row_count": { + "name": "row_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "ocr_tables_session_id_ocr_sessions_id_fk": { + "name": "ocr_tables_session_id_ocr_sessions_id_fk", + "tableFrom": "ocr_tables", + "tableTo": "ocr_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.b_rfq_attachment_revisions": { + "name": "b_rfq_attachment_revisions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_id": { + "name": "attachment_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "revision_no": { + "name": "revision_no", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true + }, + "revision_comment": { + "name": "revision_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_latest": { + "name": "is_latest", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "latest_revision_idx": { + "name": "latest_revision_idx", + "columns": [ + { + "expression": "attachment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "is_latest", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"b_rfq_attachment_revisions\".\"is_latest\" = $1", + "concurrently": false, + "method": "btree", + "with": {} + }, + "attachment_revision_idx": { + "name": "attachment_revision_idx", + "columns": [ + { + "expression": "attachment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "revision_no", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "b_rfq_attachment_revisions_attachment_id_b_rfq_attachments_id_fk": { + "name": "b_rfq_attachment_revisions_attachment_id_b_rfq_attachments_id_fk", + "tableFrom": "b_rfq_attachment_revisions", + "tableTo": "b_rfq_attachments", + "columnsFrom": [ + "attachment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "b_rfq_attachment_revisions_created_by_users_id_fk": { + "name": "b_rfq_attachment_revisions_created_by_users_id_fk", + "tableFrom": "b_rfq_attachment_revisions", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.b_rfqs": { + "name": "b_rfqs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pic_name": { + "name": "pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "eng_pic_name": { + "name": "eng_pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_company": { + "name": "project_company", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_flag": { + "name": "project_flag", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_site": { + "name": "project_site", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "package_no": { + "name": "package_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_name": { + "name": "package_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "b_rfqs_project_id_projects_id_fk": { + "name": "b_rfqs_project_id_projects_id_fk", + "tableFrom": "b_rfqs", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "b_rfqs_created_by_users_id_fk": { + "name": "b_rfqs_created_by_users_id_fk", + "tableFrom": "b_rfqs", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "b_rfqs_updated_by_users_id_fk": { + "name": "b_rfqs_updated_by_users_id_fk", + "tableFrom": "b_rfqs", + "tableTo": "users", + "columnsFrom": [ + "updated_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "b_rfqs_rfq_code_unique": { + "name": "b_rfqs_rfq_code_unique", + "nullsNotDistinct": false, + "columns": [ + "rfq_code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.b_rfq_attachments": { + "name": "b_rfq_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "serial_no": { + "name": "serial_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "current_revision": { + "name": "current_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "default": "'Rev.0'" + }, + "latest_revision_id": { + "name": "latest_revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "b_rfq_attachments_rfq_id_b_rfqs_id_fk": { + "name": "b_rfq_attachments_rfq_id_b_rfqs_id_fk", + "tableFrom": "b_rfq_attachments", + "tableTo": "b_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "b_rfq_attachments_created_by_users_id_fk": { + "name": "b_rfq_attachments_created_by_users_id_fk", + "tableFrom": "b_rfq_attachments", + "tableTo": "users", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.final_rfq": { + "name": "final_rfq", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "final_rfq_status": { + "name": "final_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'KRW'" + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "tax_code": { + "name": "tax_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "default": "'VV'" + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "place_of_shipping": { + "name": "place_of_shipping", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_destination": { + "name": "place_of_destination", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "firsttime_yn": { + "name": "firsttime_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "material_price_related_yn": { + "name": "material_price_related_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vendor_remark": { + "name": "vendor_remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "final_rfq_rfq_id_b_rfqs_id_fk": { + "name": "final_rfq_rfq_id_b_rfqs_id_fk", + "tableFrom": "final_rfq", + "tableTo": "b_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "final_rfq_vendor_id_vendors_id_fk": { + "name": "final_rfq_vendor_id_vendors_id_fk", + "tableFrom": "final_rfq", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "final_rfq_incoterms_code_incoterms_code_fk": { + "name": "final_rfq_incoterms_code_incoterms_code_fk", + "tableFrom": "final_rfq", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "final_rfq_payment_terms_code_payment_terms_code_fk": { + "name": "final_rfq_payment_terms_code_payment_terms_code_fk", + "tableFrom": "final_rfq", + "tableTo": "payment_terms", + "columnsFrom": [ + "payment_terms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.initial_rfq": { + "name": "initial_rfq", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "initial_rfq_status": { + "name": "initial_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'DRAFT'" + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "initial_rfq_rfq_id_b_rfqs_id_fk": { + "name": "initial_rfq_rfq_id_b_rfqs_id_fk", + "tableFrom": "initial_rfq", + "tableTo": "b_rfqs", + "columnsFrom": [ + "rfq_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "initial_rfq_vendor_id_vendors_id_fk": { + "name": "initial_rfq_vendor_id_vendors_id_fk", + "tableFrom": "initial_rfq", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "initial_rfq_incoterms_code_incoterms_code_fk": { + "name": "initial_rfq_incoterms_code_incoterms_code_fk", + "tableFrom": "initial_rfq", + "tableTo": "incoterms", + "columnsFrom": [ + "incoterms_code" + ], + "columnsTo": [ + "code" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_attachment_responses": { + "name": "vendor_attachment_responses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "attachment_id": { + "name": "attachment_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "rfq_type": { + "name": "rfq_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "rfq_record_id": { + "name": "rfq_record_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "response_status": { + "name": "response_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'NOT_RESPONDED'" + }, + "current_revision": { + "name": "current_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'Rev.0'" + }, + "responded_revision": { + "name": "responded_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "response_comment": { + "name": "response_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vendor_comment": { + "name": "vendor_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "responded_at": { + "name": "responded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "vendor_response_idx": { + "name": "vendor_response_idx", + "columns": [ + { + "expression": "attachment_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vendor_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "rfq_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "vendor_attachment_responses_attachment_id_b_rfq_attachments_id_fk": { + "name": "vendor_attachment_responses_attachment_id_b_rfq_attachments_id_fk", + "tableFrom": "vendor_attachment_responses", + "tableTo": "b_rfq_attachments", + "columnsFrom": [ + "attachment_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_attachment_responses_vendor_id_vendors_id_fk": { + "name": "vendor_attachment_responses_vendor_id_vendors_id_fk", + "tableFrom": "vendor_attachment_responses", + "tableTo": "vendors", + "columnsFrom": [ + "vendor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_response_attachments_b": { + "name": "vendor_response_attachments_b", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_response_id": { + "name": "vendor_response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uploaded_at": { + "name": "uploaded_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_response_attachments_b_vendor_response_id_vendor_attachment_responses_id_fk": { + "name": "vendor_response_attachments_b_vendor_response_id_vendor_attachment_responses_id_fk", + "tableFrom": "vendor_response_attachments_b", + "tableTo": "vendor_attachment_responses", + "columnsFrom": [ + "vendor_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_attachments_b_uploaded_by_users_id_fk": { + "name": "vendor_response_attachments_b_uploaded_by_users_id_fk", + "tableFrom": "vendor_response_attachments_b", + "tableTo": "users", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.vendor_response_history": { + "name": "vendor_response_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_response_id": { + "name": "vendor_response_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "previous_status": { + "name": "previous_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "new_status": { + "name": "new_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action_by": { + "name": "action_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "action_at": { + "name": "action_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "vendor_response_history_vendor_response_id_vendor_attachment_responses_id_fk": { + "name": "vendor_response_history_vendor_response_id_vendor_attachment_responses_id_fk", + "tableFrom": "vendor_response_history", + "tableTo": "vendor_attachment_responses", + "columnsFrom": [ + "vendor_response_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "vendor_response_history_action_by_users_id_fk": { + "name": "vendor_response_history_action_by_users_id_fk", + "tableFrom": "vendor_response_history", + "tableTo": "users", + "columnsFrom": [ + "action_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.offshore_hull_work_type": { + "name": "offshore_hull_work_type", + "schema": "public", + "values": [ + "HA", + "HE", + "HH", + "HM", + "NC" + ] + }, + "public.offshore_top_work_type": { + "name": "offshore_top_work_type", + "schema": "public", + "values": [ + "TM", + "TS", + "TE", + "TP" + ] + }, + "public.work_type": { + "name": "work_type", + "schema": "public", + "values": [ + "기장", + "전장", + "선실", + "배관", + "철의" + ] + }, + "public.user_domain": { + "name": "user_domain", + "schema": "public", + "values": [ + "evcp", + "partners" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": { + "public.contracts_detail_view": { + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "contracts_detail_view_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "contract_name": { + "name": "contract_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'ACTIVE'" + }, + "start_date": { + "name": "start_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "end_date": { + "name": "end_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "payment_terms": { + "name": "payment_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false, + "default": "'KRW'" + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "partial_shipping_allowed": { + "name": "partial_shipping_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "partial_payment_allowed": { + "name": "partial_payment_allowed", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "remarks": { + "name": "remarks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"contracts\".\"id\", \"contracts\".\"contract_no\", \"contracts\".\"contract_name\", \"contracts\".\"status\", \"contracts\".\"start_date\", \"contracts\".\"end_date\", \"contracts\".\"project_id\", \"projects\".\"code\", \"projects\".\"name\", \"contracts\".\"vendor_id\", \"vendors\".\"vendor_name\", \"contracts\".\"payment_terms\", \"contracts\".\"delivery_terms\", \"contracts\".\"delivery_date\", \"contracts\".\"delivery_location\", \"contracts\".\"currency\", \"contracts\".\"total_amount\", \"contracts\".\"discount\", \"contracts\".\"tax\", \"contracts\".\"shipping_fee\", \"contracts\".\"net_total\", \"contracts\".\"partial_shipping_allowed\", \"contracts\".\"partial_payment_allowed\", \"contracts\".\"remarks\", \"contracts\".\"version\", \"contracts\".\"created_at\", \"contracts\".\"updated_at\", EXISTS (\n SELECT 1 \n FROM \"contract_envelopes\" \n WHERE \"contract_envelopes\".\"contract_id\" = \"contracts\".\"id\"\n ) as \"has_signature\", COALESCE((\n SELECT json_agg(\n json_build_object(\n 'id', ci.id,\n 'itemId', ci.item_id,\n 'description', ci.description,\n 'quantity', ci.quantity,\n 'unitPrice', ci.unit_price,\n 'taxRate', ci.tax_rate,\n 'taxAmount', ci.tax_amount,\n 'totalLineAmount', ci.total_line_amount,\n 'remark', ci.remark,\n 'createdAt', ci.created_at,\n 'updatedAt', ci.updated_at\n )\n )\n FROM \"contract_items\" AS ci\n WHERE ci.contract_id = \"contracts\".\"id\"\n ), '[]') as \"items\", COALESCE((\n SELECT json_agg(\n json_build_object(\n 'id', ce.id,\n 'envelopeId', ce.envelope_id,\n 'documentId', ce.document_id,\n 'envelopeStatus', ce.envelope_status,\n 'fileName', ce.file_name,\n 'filePath', ce.file_path,\n 'createdAt', ce.created_at,\n 'updatedAt', ce.updated_at,\n 'signers', (\n SELECT json_agg(\n json_build_object(\n 'id', cs.id,\n 'vendorContactId', cs.vendor_contact_id,\n 'signerType', cs.signer_type,\n 'signerEmail', cs.signer_email,\n 'signerName', cs.signer_name,\n 'signerPosition', cs.signer_position,\n 'signerStatus', cs.signer_status,\n 'signedAt', cs.signed_at\n )\n )\n FROM \"contract_signers\" AS cs\n WHERE cs.envelope_id = ce.id\n )\n )\n )\n FROM \"contract_envelopes\" AS ce\n WHERE ce.contract_id = \"contracts\".\"id\"\n ), '[]') as \"envelopes\" from \"contracts\" left join \"projects\" on \"contracts\".\"project_id\" = \"projects\".\"id\" left join \"vendors\" on \"contracts\".\"vendor_id\" = \"vendors\".\"id\"", + "name": "contracts_detail_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.poa_detail_view": { + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "identity": { + "type": "always", + "name": "poa_detail_view_id_seq", + "schema": "public", + "increment": "1", + "startWith": "1", + "minValue": "1", + "maxValue": "2147483647", + "cache": "1", + "cycle": false + } + }, + "contract_no": { + "name": "contract_no", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "change_reason": { + "name": "change_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "approval_status": { + "name": "approval_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'PENDING'" + }, + "delivery_terms": { + "name": "delivery_terms", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_location": { + "name": "delivery_location", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "total_amount": { + "name": "total_amount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "tax": { + "name": "tax", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "shipping_fee": { + "name": "shipping_fee", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "net_total": { + "name": "net_total", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"poa\".\"id\", \"poa\".\"contract_no\", \"contracts\".\"project_id\", \"contracts\".\"vendor_id\", \"poa\".\"change_reason\", \"poa\".\"approval_status\", \"contracts\".\"contract_name\" as \"original_contract_name\", \"contracts\".\"status\" as \"original_status\", \"contracts\".\"start_date\" as \"original_start_date\", \"contracts\".\"end_date\" as \"original_end_date\", \"poa\".\"delivery_terms\", \"poa\".\"delivery_date\", \"poa\".\"delivery_location\", \"poa\".\"currency\", \"poa\".\"total_amount\", \"poa\".\"discount\", \"poa\".\"tax\", \"poa\".\"shipping_fee\", \"poa\".\"net_total\", \"poa\".\"created_at\", \"poa\".\"updated_at\", EXISTS (\n SELECT 1 \n FROM \"contract_envelopes\" \n WHERE \"contract_envelopes\".\"contract_id\" = \"poa\".\"id\"\n ) as \"has_signature\" from \"poa\" left join \"contracts\" on \"poa\".\"contract_no\" = \"contracts\".\"contract_no\"", + "name": "poa_detail_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.project_approved_vendors": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING_REVIEW'" + }, + "name_ko": { + "name": "name_ko", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "name_en": { + "name": "name_en", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'ship'" + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "approved_at": { + "name": "approved_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"vendors\".\"id\", \"vendors\".\"vendor_name\", \"vendors\".\"vendor_code\", \"vendors\".\"tax_id\", \"vendors\".\"email\", \"vendors\".\"phone\", \"vendors\".\"status\", \"vendor_types\".\"name_ko\", \"vendor_types\".\"name_en\", \"projects\".\"code\", \"projects\".\"name\", \"projects\".\"type\", \"vendor_pq_submissions\".\"submitted_at\", \"vendor_pq_submissions\".\"approved_at\" from \"vendors\" inner join \"vendor_pq_submissions\" on \"vendor_pq_submissions\".\"vendor_id\" = \"vendors\".\"id\" inner join \"projects\" on \"vendor_pq_submissions\".\"project_id\" = \"projects\".\"id\" left join \"vendor_types\" on \"vendors\".\"vendor_type_id\" = \"vendor_types\".\"id\" where \"vendor_pq_submissions\".\"status\" = 'APPROVED'", + "name": "project_approved_vendors", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_investigations_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pq_submission_id": { + "name": "pq_submission_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "requester_id": { + "name": "requester_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "qm_manager_id": { + "name": "qm_manager_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "investigation_status": { + "name": "investigation_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'PLANNED'" + }, + "evaluation_type": { + "name": "evaluation_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_address": { + "name": "investigation_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "investigation_method": { + "name": "investigation_method", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "scheduled_start_at": { + "name": "scheduled_start_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "scheduled_end_at": { + "name": "scheduled_end_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "forecasted_at": { + "name": "forecasted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "evaluation_score": { + "name": "evaluation_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluation_result": { + "name": "evaluation_result", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "investigation_notes": { + "name": "investigation_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"vendor_investigations\".\"id\", \"vendor_investigations\".\"vendor_id\", \"vendor_investigations\".\"pq_submission_id\", \"vendor_investigations\".\"requester_id\", \"vendor_investigations\".\"qm_manager_id\", \"vendor_investigations\".\"investigation_status\", \"vendor_investigations\".\"evaluation_type\", \"vendor_investigations\".\"investigation_address\", \"vendor_investigations\".\"investigation_method\", \"vendor_investigations\".\"scheduled_start_at\", \"vendor_investigations\".\"scheduled_end_at\", \"vendor_investigations\".\"forecasted_at\", \"vendor_investigations\".\"requested_at\", \"vendor_investigations\".\"confirmed_at\", \"vendor_investigations\".\"completed_at\", \"vendor_investigations\".\"evaluation_score\", \"vendor_investigations\".\"evaluation_result\", \"vendor_investigations\".\"investigation_notes\", \"vendor_investigations\".\"created_at\", \"vendor_investigations\".\"updated_at\", \"vendors\".\"vendor_name\", \"vendors\".\"vendor_code\", requester.name as \"requesterName\", requester.email as \"requesterEmail\", qm_manager.name as \"qmManagerName\", qm_manager.email as \"qmManagerEmail\", (\n CASE \n WHEN EXISTS (\n SELECT 1 FROM vendor_investigation_attachments via \n WHERE via.investigation_id = \"vendor_investigations\".\"id\"\n ) \n THEN true \n ELSE false \n END\n ) as \"hasAttachments\" from \"vendor_investigations\" left join \"vendors\" on \"vendor_investigations\".\"vendor_id\" = \"vendors\".\"id\" left join users AS requester on \"vendor_investigations\".\"requester_id\" = requester.id left join users AS qm_manager on \"vendor_investigations\".\"qm_manager_id\" = qm_manager.id", + "name": "vendor_investigations_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.cbe_view": { + "columns": {}, + "definition": "select \"cbe_evaluations\".\"id\" as \"cbe_id\", \"cbe_evaluations\".\"rfq_id\" as \"rfq_id\", \"cbe_evaluations\".\"vendor_id\" as \"vendor_id\", \"cbe_evaluations\".\"total_cost\" as \"total_cost\", \"cbe_evaluations\".\"currency\" as \"currency\", \"cbe_evaluations\".\"payment_terms\" as \"payment_terms\", \"cbe_evaluations\".\"incoterms\" as \"incoterms\", \"cbe_evaluations\".\"result\" as \"result\", \"cbe_evaluations\".\"notes\" as \"notes\", \"cbe_evaluations\".\"evaluated_by\" as \"evaluated_by\", \"cbe_evaluations\".\"evaluated_at\" as \"evaluated_at\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"rfq_description\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"users\".\"name\" as \"evaluator_name\", \"users\".\"email\" as \"evaluator_email\" from \"cbe_evaluations\" inner join \"rfqs\" on \"cbe_evaluations\".\"rfq_id\" = \"rfqs\".\"id\" inner join \"vendors\" on \"cbe_evaluations\".\"vendor_id\" = \"vendors\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"users\" on \"cbe_evaluations\".\"evaluated_by\" = \"users\".\"id\"", + "name": "cbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.rfqs_view": { + "columns": {}, + "definition": "select \"rfqs\".\"id\" as \"rfq_id\", \"rfqs\".\"status\" as \"status\", \"rfqs\".\"created_at\" as \"created_at\", \"rfqs\".\"updated_at\" as \"updated_at\", \"rfqs\".\"created_by\" as \"created_by\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"rfqs\".\"parent_rfq_id\" as \"parent_rfq_id\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"users\".\"email\" as \"user_email\", \"users\".\"name\" as \"user_name\", (\n SELECT COUNT(*) \n FROM \"rfq_items\" \n WHERE \"rfq_items\".\"rfq_id\" = \"rfqs\".\"id\"\n ) as \"item_count\", (\n SELECT COUNT(*) \n FROM \"rfq_attachments\" \n WHERE \"rfq_attachments\".\"rfq_id\" = \"rfqs\".\"id\"\n ) as \"attachment_count\" from \"rfqs\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"users\" on \"rfqs\".\"created_by\" = \"users\".\"id\"", + "name": "rfqs_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_cbe_view": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"email\" as \"email\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"vendor_status\", \"vendor_responses\".\"id\" as \"vendor_response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"response_status\" as \"rfq_vendor_status\", \"vendor_responses\".\"updated_at\" as \"rfq_vendor_updated\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"cbe_evaluations\".\"id\" as \"cbe_id\", \"cbe_evaluations\".\"result\" as \"cbe_result\", \"cbe_evaluations\".\"notes\" as \"cbe_note\", \"cbe_evaluations\".\"updated_at\" as \"cbe_updated\", \"cbe_evaluations\".\"total_cost\" as \"total_cost\", \"cbe_evaluations\".\"currency\" as \"currency\", \"cbe_evaluations\".\"payment_terms\" as \"payment_terms\", \"cbe_evaluations\".\"incoterms\" as \"incoterms\", \"cbe_evaluations\".\"delivery_schedule\" as \"delivery_schedule\" from \"vendors\" left join \"vendor_responses\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"cbe_evaluations\" on (\"cbe_evaluations\".\"vendor_id\" = \"vendors\".\"id\" and \"cbe_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\")", + "name": "vendor_cbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_response_cbe_view": { + "columns": {}, + "definition": "select \"vendor_responses\".\"id\" as \"response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"vendor_id\" as \"vendor_id\", \"vendor_responses\".\"response_status\" as \"response_status\", \"vendor_responses\".\"notes\" as \"response_notes\", \"vendor_responses\".\"responded_by\" as \"responded_by\", \"vendor_responses\".\"responded_at\" as \"responded_at\", \"vendor_responses\".\"updated_at\" as \"response_updated_at\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"rfq_description\", \"rfqs\".\"due_date\" as \"rfq_due_date\", \"rfqs\".\"status\" as \"rfq_status\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"status\" as \"vendor_status\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"vendor_commercial_responses\".\"id\" as \"commercial_response_id\", \"vendor_commercial_responses\".\"response_status\" as \"commercial_response_status\", \"vendor_commercial_responses\".\"total_price\" as \"total_price\", \"vendor_commercial_responses\".\"currency\" as \"currency\", \"vendor_commercial_responses\".\"payment_terms\" as \"payment_terms\", \"vendor_commercial_responses\".\"incoterms\" as \"incoterms\", \"vendor_commercial_responses\".\"delivery_period\" as \"delivery_period\", \"vendor_commercial_responses\".\"warranty_period\" as \"warranty_period\", \"vendor_commercial_responses\".\"validity_period\" as \"validity_period\", \"vendor_commercial_responses\".\"price_breakdown\" as \"price_breakdown\", \"vendor_commercial_responses\".\"commercial_notes\" as \"commercial_notes\", \"vendor_commercial_responses\".\"created_at\" as \"commercial_created_at\", \"vendor_commercial_responses\".\"updated_at\" as \"commercial_updated_at\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n ) as \"attachment_count\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"commercial_response_id\" = \"vendor_commercial_responses\".\"id\"\n ) as \"commercial_attachment_count\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n AND \"vendor_response_attachments\".\"attachment_type\" = 'TECHNICAL_SPEC'\n ) as \"technical_attachment_count\", (\n SELECT MAX(\"uploaded_at\") \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n ) as \"latest_attachment_date\" from \"vendor_responses\" inner join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" inner join \"vendors\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendor_commercial_responses\" on \"vendor_commercial_responses\".\"response_id\" = \"vendor_responses\".\"id\"", + "name": "vendor_response_cbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_responses_view": { + "columns": {}, + "definition": "select \"vendor_responses\".\"id\" as \"response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"vendor_id\" as \"vendor_id\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"rfq_description\", \"rfqs\".\"due_date\" as \"rfq_due_date\", \"rfqs\".\"status\" as \"rfq_status\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"created_at\" as \"rfq_created_at\", \"rfqs\".\"updated_at\" as \"rfq_updated_at\", \"rfqs\".\"created_by\" as \"rfq_created_by\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendor_responses\".\"response_status\" as \"response_status\", \"vendor_responses\".\"responded_at\" as \"responded_at\", CASE WHEN \"vendor_technical_responses\".\"id\" IS NOT NULL THEN TRUE ELSE FALSE END as \"has_technical_response\", \"vendor_technical_responses\".\"id\" as \"technical_response_id\", CASE WHEN \"vendor_commercial_responses\".\"id\" IS NOT NULL THEN TRUE ELSE FALSE END as \"has_commercial_response\", \"vendor_commercial_responses\".\"id\" as \"commercial_response_id\", \"vendor_commercial_responses\".\"total_price\" as \"total_price\", \"vendor_commercial_responses\".\"currency\" as \"currency\", \"rfq_evaluations\".\"id\" as \"tbe_id\", \"rfq_evaluations\".\"result\" as \"tbe_result\", \"cbe_evaluations\".\"id\" as \"cbe_id\", \"cbe_evaluations\".\"result\" as \"cbe_result\", (\n SELECT COUNT(*) \n FROM \"vendor_response_attachments\" \n WHERE \"vendor_response_attachments\".\"response_id\" = \"vendor_responses\".\"id\"\n ) as \"attachment_count\" from \"vendor_responses\" inner join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" inner join \"vendors\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendor_technical_responses\" on \"vendor_technical_responses\".\"response_id\" = \"vendor_responses\".\"id\" left join \"vendor_commercial_responses\" on \"vendor_commercial_responses\".\"response_id\" = \"vendor_responses\".\"id\" left join \"rfq_evaluations\" on (\"rfq_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\" and \"rfq_evaluations\".\"vendor_id\" = \"vendor_responses\".\"vendor_id\" and \"rfq_evaluations\".\"eval_type\" = 'TBE') left join \"cbe_evaluations\" on (\"cbe_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\" and \"cbe_evaluations\".\"vendor_id\" = \"vendor_responses\".\"vendor_id\")", + "name": "vendor_responses_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_rfq_view": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"email\" as \"email\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"vendor_status\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"response_status\" as \"rfq_vendor_status\", \"vendor_responses\".\"updated_at\" as \"rfq_vendor_updated\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\" from \"vendors\" left join \"vendor_responses\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\"", + "name": "vendor_rfq_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_tbe_view": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"email\" as \"email\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"vendor_status\", \"vendor_responses\".\"id\" as \"vendor_response_id\", \"vendor_responses\".\"rfq_id\" as \"rfq_id\", \"vendor_responses\".\"response_status\" as \"rfq_vendor_status\", \"vendor_responses\".\"updated_at\" as \"rfq_vendor_updated\", \"vendor_technical_responses\".\"id\" as \"technical_response_id\", \"vendor_technical_responses\".\"response_status\" as \"technical_response_status\", \"vendor_technical_responses\".\"summary\" as \"technical_summary\", \"vendor_technical_responses\".\"notes\" as \"technical_notes\", \"vendor_technical_responses\".\"updated_at\" as \"technical_updated\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"rfqs\".\"rfq_type\" as \"rfq_type\", \"rfqs\".\"status\" as \"rfq_status\", \"rfqs\".\"description\" as \"description\", \"rfqs\".\"due_date\" as \"due_date\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"rfq_evaluations\".\"id\" as \"tbe_id\", \"rfq_evaluations\".\"result\" as \"tbe_result\", \"rfq_evaluations\".\"notes\" as \"tbe_note\", \"rfq_evaluations\".\"updated_at\" as \"tbe_updated\" from \"vendors\" left join \"vendor_responses\" on \"vendor_responses\".\"vendor_id\" = \"vendors\".\"id\" left join \"rfqs\" on \"vendor_responses\".\"rfq_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendor_technical_responses\" on \"vendor_technical_responses\".\"response_id\" = \"vendor_responses\".\"id\" left join \"rfq_evaluations\" on (\"rfq_evaluations\".\"vendor_id\" = \"vendors\".\"id\" and \"rfq_evaluations\".\"eval_type\" = 'TBE' and \"rfq_evaluations\".\"rfq_id\" = \"vendor_responses\".\"rfq_id\")", + "name": "vendor_tbe_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.role_view": { + "columns": {}, + "definition": "select \"roles\".\"id\" as \"id\", \"roles\".\"name\" as \"name\", \"roles\".\"description\" as \"description\", \"roles\".\"domain\" as \"domain\", \"roles\".\"created_at\" as \"created_at\", \"vendors\".\"id\" as \"company_id\", \"vendors\".\"vendor_name\" as \"company_name\", COUNT(\"users\".\"id\") as \"user_count\" from \"roles\" left join \"user_roles\" on \"user_roles\".\"role_id\" = \"roles\".\"id\" left join \"users\" on \"users\".\"id\" = \"user_roles\".\"user_id\" left join \"vendors\" on \"roles\".\"company_id\" = \"vendors\".\"id\" group by \"roles\".\"id\", \"vendors\".\"id\"", + "name": "role_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.user_view": { + "columns": {}, + "definition": "select \"users\".\"id\" as \"user_id\", \"users\".\"name\" as \"user_name\", \"users\".\"email\" as \"user_email\", \"users\".\"domain\" as \"user_domain\", \"users\".\"image_url\" as \"user_image\", \"vendors\".\"id\" as \"company_id\", \"vendors\".\"vendor_name\" as \"company_name\", \n array_agg(\"roles\".\"name\")\n as \"roles\", \"users\".\"created_at\" as \"created_at\" from \"users\" left join \"vendors\" on \"users\".\"company_id\" = \"vendors\".\"id\" left join \"user_roles\" on \"users\".\"id\" = \"user_roles\".\"user_id\" left join \"roles\" on \"user_roles\".\"role_id\" = \"roles\".\"id\" group by \"users\".\"id\", \"vendors\".\"id\"", + "name": "user_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.form_lists_view": { + "columns": {}, + "definition": "select \"tag_type_class_form_mappings\".\"id\" as \"id\", \"tag_type_class_form_mappings\".\"project_id\" as \"project_id\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"tag_type_class_form_mappings\".\"tag_type_label\" as \"tag_type_label\", \"tag_type_class_form_mappings\".\"class_label\" as \"class_label\", \"tag_type_class_form_mappings\".\"form_code\" as \"form_code\", \"tag_type_class_form_mappings\".\"form_name\" as \"form_name\", \"tag_type_class_form_mappings\".\"ep\" as \"ep\", \"tag_type_class_form_mappings\".\"remark\" as \"remark\", \"tag_type_class_form_mappings\".\"created_at\" as \"created_at\", \"tag_type_class_form_mappings\".\"updated_at\" as \"updated_at\" from \"tag_type_class_form_mappings\" inner join \"projects\" on \"tag_type_class_form_mappings\".\"project_id\" = \"projects\".\"id\"", + "name": "form_lists_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.view_tag_subfields": { + "columns": { + "tag_type_code": { + "name": "tag_type_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "attributes_id": { + "name": "attributes_id", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "attributes_description": { + "name": "attributes_description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expression": { + "name": "expression", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "delimiter": { + "name": "delimiter", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "sort_order": { + "name": "sort_order", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "code": { + "name": "code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "definition": "select \"tag_subfields\".\"id\" as \"id\", \"tag_subfields\".\"tag_type_code\", \"tag_types\".\"description\", \"tag_subfields\".\"attributes_id\", \"tag_subfields\".\"attributes_description\", \"tag_subfields\".\"expression\", \"tag_subfields\".\"delimiter\", \"tag_subfields\".\"sort_order\", \"tag_subfields\".\"created_at\", \"tag_subfields\".\"updated_at\", \"projects\".\"id\" as \"project_id\", \"projects\".\"code\", \"projects\".\"name\" from \"tag_subfields\" inner join \"tag_types\" on (\"tag_subfields\".\"tag_type_code\" = \"tag_types\".\"code\" and \"tag_subfields\".\"project_id\" = \"tag_types\".\"project_id\") inner join \"projects\" on \"tag_subfields\".\"project_id\" = \"projects\".\"id\"", + "name": "view_tag_subfields", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.document_stages_view": { + "columns": { + "document_id": { + "name": "document_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stage_count": { + "name": "stage_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "stage_list": { + "name": "stage_list", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "definition": "\n SELECT\n d.id AS document_id,\n d.doc_number,\n d.title,\n d.status,\n d.issued_date,\n d.contract_id,\n (SELECT COUNT(*) FROM issue_stages WHERE document_id = d.id) AS stage_count,\n COALESCE( \n (SELECT json_agg(i.stage_name) FROM issue_stages i WHERE i.document_id = d.id), \n '[]'\n ) AS stage_list,\n d.created_at,\n d.updated_at\n FROM documents d\n", + "name": "document_stages_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.enhanced_documents_view": { + "columns": { + "document_id": { + "name": "document_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "drawing_kind": { + "name": "drawing_kind", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_doc_number": { + "name": "vendor_doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "pic": { + "name": "pic", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_code": { + "name": "project_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "c_gbn": { + "name": "c_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "d_gbn": { + "name": "d_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "degree_gbn": { + "name": "degree_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "dept_gbn": { + "name": "dept_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "j_gbn": { + "name": "j_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "s_gbn": { + "name": "s_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "current_stage_id": { + "name": "current_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "current_stage_name": { + "name": "current_stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "current_stage_status": { + "name": "current_stage_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "current_stage_order": { + "name": "current_stage_order", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "current_stage_plan_date": { + "name": "current_stage_plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "current_stage_actual_date": { + "name": "current_stage_actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "current_stage_assignee_name": { + "name": "current_stage_assignee_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "current_stage_priority": { + "name": "current_stage_priority", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "days_until_due": { + "name": "days_until_due", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "is_overdue": { + "name": "is_overdue", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "days_difference": { + "name": "days_difference", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "total_stages": { + "name": "total_stages", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "completed_stages": { + "name": "completed_stages", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "progress_percentage": { + "name": "progress_percentage", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_revision_id": { + "name": "latest_revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_revision": { + "name": "latest_revision", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_status": { + "name": "latest_revision_status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_uploader_name": { + "name": "latest_revision_uploader_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "latest_submitted_date": { + "name": "latest_submitted_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "all_stages": { + "name": "all_stages", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "attachment_count": { + "name": "attachment_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "definition": "\n WITH document_stats AS (\n SELECT \n d.id as document_id,\n COUNT(ist.id) as total_stages,\n COUNT(CASE WHEN ist.stage_status IN ('COMPLETED', 'APPROVED') THEN 1 END) as completed_stages,\n CASE \n WHEN COUNT(ist.id) > 0 \n THEN ROUND((COUNT(CASE WHEN ist.stage_status IN ('COMPLETED', 'APPROVED') THEN 1 END) * 100.0) / COUNT(ist.id))\n ELSE 0 \n END as progress_percentage\n FROM documents d\n LEFT JOIN issue_stages ist ON d.id = ist.document_id\n GROUP BY d.id\n ),\n current_stage_info AS (\n SELECT DISTINCT ON (document_id)\n document_id,\n id as current_stage_id,\n stage_name as current_stage_name,\n stage_status as current_stage_status,\n stage_order as current_stage_order,\n plan_date as current_stage_plan_date,\n actual_date as current_stage_actual_date,\n assignee_name as current_stage_assignee_name,\n priority as current_stage_priority,\n CASE \n WHEN actual_date IS NULL AND plan_date IS NOT NULL \n THEN plan_date - CURRENT_DATE\n ELSE NULL \n END as days_until_due,\n CASE \n WHEN actual_date IS NULL AND plan_date < CURRENT_DATE \n THEN true\n WHEN actual_date IS NOT NULL AND actual_date > plan_date \n THEN true\n ELSE false \n END as is_overdue,\n CASE \n WHEN actual_date IS NOT NULL AND plan_date IS NOT NULL \n THEN actual_date - plan_date\n ELSE NULL \n END as days_difference\n FROM issue_stages\n WHERE stage_status NOT IN ('COMPLETED', 'APPROVED')\n ORDER BY document_id, stage_order ASC, priority DESC\n ),\n latest_revision_info AS (\n SELECT DISTINCT ON (ist.document_id)\n ist.document_id,\n r.id as latest_revision_id,\n r.revision as latest_revision,\n r.revision_status as latest_revision_status,\n r.uploader_name as latest_revision_uploader_name,\n r.submitted_date as latest_submitted_date\n FROM revisions r\n JOIN issue_stages ist ON r.issue_stage_id = ist.id\n ORDER BY ist.document_id, r.created_at DESC\n ),\n -- 리비전별 첨부파일 집계\n revision_attachments AS (\n SELECT \n r.id as revision_id,\n COALESCE(\n json_agg(\n json_build_object(\n 'id', da.id,\n 'revisionId', da.revision_id,\n 'fileName', da.file_name,\n 'filePath', da.file_path,\n 'fileSize', da.file_size,\n 'fileType', da.file_type,\n 'createdAt', da.created_at,\n 'updatedAt', da.updated_at\n ) ORDER BY da.created_at\n ) FILTER (WHERE da.id IS NOT NULL),\n '[]'::json\n ) as attachments\n FROM revisions r\n LEFT JOIN document_attachments da ON r.id = da.revision_id\n GROUP BY r.id\n ),\n -- 스테이지별 리비전 집계 (첨부파일 포함)\n stage_revisions AS (\n SELECT \n ist.id as stage_id,\n COALESCE(\n json_agg(\n json_build_object(\n 'id', r.id,\n 'issueStageId', r.issue_stage_id,\n 'revision', r.revision,\n 'uploaderType', r.uploader_type,\n 'uploaderId', r.uploader_id,\n 'uploaderName', r.uploader_name,\n 'comment', r.comment,\n 'usage', r.usage,\n 'revisionStatus', r.revision_status,\n 'submittedDate', r.submitted_date,\n 'uploadedAt', r.uploaded_at,\n 'approvedDate', r.approved_date,\n 'reviewStartDate', r.review_start_date,\n 'rejectedDate', r.rejected_date,\n 'reviewerId', r.reviewer_id,\n 'reviewerName', r.reviewer_name,\n 'reviewComments', r.review_comments,\n 'createdAt', r.created_at,\n 'updatedAt', r.updated_at,\n 'attachments', ra.attachments\n ) ORDER BY r.created_at\n ) FILTER (WHERE r.id IS NOT NULL),\n '[]'::json\n ) as revisions\n FROM issue_stages ist\n LEFT JOIN revisions r ON ist.id = r.issue_stage_id\n LEFT JOIN revision_attachments ra ON r.id = ra.revision_id\n GROUP BY ist.id\n ),\n -- 문서별 스테이지 집계 (리비전 포함)\n stage_aggregation AS (\n SELECT \n ist.document_id,\n json_agg(\n json_build_object(\n 'id', ist.id,\n 'stageName', ist.stage_name,\n 'stageStatus', ist.stage_status,\n 'stageOrder', ist.stage_order,\n 'planDate', ist.plan_date,\n 'actualDate', ist.actual_date,\n 'assigneeName', ist.assignee_name,\n 'priority', ist.priority,\n 'revisions', sr.revisions\n ) ORDER BY ist.stage_order\n ) as all_stages\n FROM issue_stages ist\n LEFT JOIN stage_revisions sr ON ist.id = sr.stage_id\n GROUP BY ist.document_id\n ),\n attachment_counts AS (\n SELECT \n ist.document_id,\n COUNT(da.id) as attachment_count\n FROM issue_stages ist\n LEFT JOIN revisions r ON ist.id = r.issue_stage_id\n LEFT JOIN document_attachments da ON r.id = da.revision_id\n GROUP BY ist.document_id\n )\n \n SELECT \n d.id as document_id,\n d.doc_number,\n d.drawing_kind,\n d.vendor_doc_number, -- ✅ 벤더 문서 번호 추가\n d.title,\n d.pic,\n d.status,\n d.issued_date,\n d.contract_id,\n\n d.c_gbn,\n d.d_gbn,\n d.degree_gbn,\n d.dept_gbn,\n d.s_gbn,\n d.j_gbn,\n\n\n \n -- ✅ 프로젝트 및 벤더 정보 추가\n p.code as project_code,\n v.vendor_name as vendor_name,\n v.vendor_code as vendor_code,\n \n -- 현재 스테이지 정보\n csi.current_stage_id,\n csi.current_stage_name,\n csi.current_stage_status,\n csi.current_stage_order,\n csi.current_stage_plan_date,\n csi.current_stage_actual_date,\n csi.current_stage_assignee_name,\n csi.current_stage_priority,\n \n -- 계산 필드\n csi.days_until_due,\n csi.is_overdue,\n csi.days_difference,\n \n -- 진행률 정보\n ds.total_stages,\n ds.completed_stages,\n ds.progress_percentage,\n \n -- 최신 리비전 정보\n lri.latest_revision_id,\n lri.latest_revision,\n lri.latest_revision_status,\n lri.latest_revision_uploader_name,\n lri.latest_submitted_date,\n \n -- 전체 스테이지 (리비전 및 첨부파일 포함)\n COALESCE(sa.all_stages, '[]'::json) as all_stages,\n \n -- 기타\n COALESCE(ac.attachment_count, 0) as attachment_count,\n d.created_at,\n d.updated_at\n \n FROM documents d\n -- ✅ contracts, projects, vendors 테이블 JOIN 추가\n LEFT JOIN contracts c ON d.contract_id = c.id\n LEFT JOIN projects p ON c.project_id = p.id\n LEFT JOIN vendors v ON c.vendor_id = v.id\n \n LEFT JOIN document_stats ds ON d.id = ds.document_id\n LEFT JOIN current_stage_info csi ON d.id = csi.document_id\n LEFT JOIN latest_revision_info lri ON d.id = lri.document_id\n LEFT JOIN stage_aggregation sa ON d.id = sa.document_id\n LEFT JOIN attachment_counts ac ON d.id = ac.document_id\n \n ORDER BY d.created_at DESC\n", + "name": "enhanced_documents_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.simplified_documents_view": { + "columns": { + "document_id": { + "name": "document_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "drawing_kind": { + "name": "drawing_kind", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_doc_number": { + "name": "vendor_doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "pic": { + "name": "pic", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "project_code": { + "name": "project_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "c_gbn": { + "name": "c_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "d_gbn": { + "name": "d_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "degree_gbn": { + "name": "degree_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "dept_gbn": { + "name": "dept_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "j_gbn": { + "name": "j_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "s_gbn": { + "name": "s_gbn", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "first_stage_id": { + "name": "first_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "first_stage_name": { + "name": "first_stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "first_stage_plan_date": { + "name": "first_stage_plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "first_stage_actual_date": { + "name": "first_stage_actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "second_stage_id": { + "name": "second_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "second_stage_name": { + "name": "second_stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "second_stage_plan_date": { + "name": "second_stage_plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "second_stage_actual_date": { + "name": "second_stage_actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "all_stages": { + "name": "all_stages", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "attachment_count": { + "name": "attachment_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "definition": "\n WITH \n -- 리비전별 첨부파일 집계\n revision_attachments AS (\n SELECT \n r.id as revision_id,\n COALESCE(\n json_agg(\n json_build_object(\n 'id', da.id,\n 'revisionId', da.revision_id,\n 'fileName', da.file_name,\n 'filePath', da.file_path,\n 'fileSize', da.file_size,\n 'fileType', da.file_type,\n 'createdAt', da.created_at,\n 'updatedAt', da.updated_at\n ) ORDER BY da.created_at\n ) FILTER (WHERE da.id IS NOT NULL),\n '[]'::json\n ) as attachments\n FROM revisions r\n LEFT JOIN document_attachments da ON r.id = da.revision_id\n GROUP BY r.id\n ),\n -- 스테이지별 리비전 집계 (첨부파일 포함)\n stage_revisions AS (\n SELECT \n ist.id as stage_id,\n COALESCE(\n json_agg(\n json_build_object(\n 'id', r.id,\n 'issueStageId', r.issue_stage_id,\n 'revision', r.revision,\n 'uploaderType', r.uploader_type,\n 'uploaderId', r.uploader_id,\n 'uploaderName', r.uploader_name,\n 'comment', r.comment,\n 'usage', r.usage,\n 'revisionStatus', r.revision_status,\n 'submittedDate', r.submitted_date,\n 'uploadedAt', r.uploaded_at,\n 'approvedDate', r.approved_date,\n 'reviewStartDate', r.review_start_date,\n 'rejectedDate', r.rejected_date,\n 'reviewerId', r.reviewer_id,\n 'reviewerName', r.reviewer_name,\n 'reviewComments', r.review_comments,\n 'createdAt', r.created_at,\n 'updatedAt', r.updated_at,\n 'attachments', ra.attachments\n ) ORDER BY r.created_at\n ) FILTER (WHERE r.id IS NOT NULL),\n '[]'::json\n ) as revisions\n FROM issue_stages ist\n LEFT JOIN revisions r ON ist.id = r.issue_stage_id\n LEFT JOIN revision_attachments ra ON r.id = ra.revision_id\n GROUP BY ist.id\n ),\n -- 문서별 스테이지 집계 (리비전 포함)\n stage_aggregation AS (\n SELECT \n ist.document_id,\n json_agg(\n json_build_object(\n 'id', ist.id,\n 'stageName', ist.stage_name,\n 'stageStatus', ist.stage_status,\n 'stageOrder', ist.stage_order,\n 'planDate', ist.plan_date,\n 'actualDate', ist.actual_date,\n 'assigneeName', ist.assignee_name,\n 'priority', ist.priority,\n 'revisions', sr.revisions\n ) ORDER BY ist.stage_order\n ) as all_stages\n FROM issue_stages ist\n LEFT JOIN stage_revisions sr ON ist.id = sr.stage_id\n GROUP BY ist.document_id\n ),\n -- 첫 번째 스테이지 정보 (drawingKind에 따라 다른 조건)\n first_stage_info AS (\n SELECT DISTINCT ON (ist.document_id)\n ist.document_id,\n ist.id as first_stage_id,\n ist.stage_name as first_stage_name,\n ist.plan_date as first_stage_plan_date,\n ist.actual_date as first_stage_actual_date\n FROM issue_stages ist\n JOIN documents d ON ist.document_id = d.id\n WHERE \n (d.drawing_kind = 'B4' AND LOWER(ist.stage_name) LIKE '%pre%') OR\n (d.drawing_kind = 'B3' AND LOWER(ist.stage_name) LIKE '%approval%') OR\n (d.drawing_kind = 'B5' AND LOWER(ist.stage_name) LIKE '%first%')\n ORDER BY ist.document_id, ist.stage_order ASC\n ),\n -- 두 번째 스테이지 정보 (drawingKind에 따라 다른 조건)\n second_stage_info AS (\n SELECT DISTINCT ON (ist.document_id)\n ist.document_id,\n ist.id as second_stage_id,\n ist.stage_name as second_stage_name,\n ist.plan_date as second_stage_plan_date,\n ist.actual_date as second_stage_actual_date\n FROM issue_stages ist\n JOIN documents d ON ist.document_id = d.id\n WHERE \n (d.drawing_kind = 'B4' AND LOWER(ist.stage_name) LIKE '%work%') OR\n (d.drawing_kind = 'B3' AND LOWER(ist.stage_name) LIKE '%work%') OR\n (d.drawing_kind = 'B5' AND LOWER(ist.stage_name) LIKE '%second%')\n ORDER BY ist.document_id, ist.stage_order ASC\n ),\n -- 첨부파일 수 집계\n attachment_counts AS (\n SELECT \n ist.document_id,\n COUNT(da.id) as attachment_count\n FROM issue_stages ist\n LEFT JOIN revisions r ON ist.id = r.issue_stage_id\n LEFT JOIN document_attachments da ON r.id = da.revision_id\n GROUP BY ist.document_id\n )\n \n SELECT \n d.id as document_id,\n d.doc_number,\n d.drawing_kind,\n d.vendor_doc_number,\n d.title,\n d.pic,\n d.status,\n d.issued_date,\n d.contract_id,\n \n -- B4 전용 필드들\n d.c_gbn,\n d.d_gbn,\n d.degree_gbn,\n d.dept_gbn,\n d.s_gbn,\n d.j_gbn,\n \n -- 프로젝트 및 벤더 정보\n p.code as project_code,\n v.vendor_name as vendor_name,\n v.vendor_code as vendor_code,\n \n -- 첫 번째 스테이지 정보\n fsi.first_stage_id,\n fsi.first_stage_name,\n fsi.first_stage_plan_date,\n fsi.first_stage_actual_date,\n \n -- 두 번째 스테이지 정보\n ssi.second_stage_id,\n ssi.second_stage_name,\n ssi.second_stage_plan_date,\n ssi.second_stage_actual_date,\n \n -- 전체 스테이지 (리비전 및 첨부파일 포함)\n COALESCE(sa.all_stages, '[]'::json) as all_stages,\n \n -- 기타\n COALESCE(ac.attachment_count, 0) as attachment_count,\n d.created_at,\n d.updated_at\n \n FROM documents d\n -- contracts, projects, vendors 테이블 JOIN\n LEFT JOIN contracts c ON d.contract_id = c.id\n LEFT JOIN projects p ON c.project_id = p.id\n LEFT JOIN vendors v ON c.vendor_id = v.id\n \n -- 스테이지 정보 JOIN\n LEFT JOIN first_stage_info fsi ON d.id = fsi.document_id\n LEFT JOIN second_stage_info ssi ON d.id = ssi.document_id\n LEFT JOIN stage_aggregation sa ON d.id = sa.document_id\n LEFT JOIN attachment_counts ac ON d.id = ac.document_id\n \n ORDER BY d.created_at DESC\n", + "name": "simplified_documents_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.sync_status_view": { + "columns": { + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "target_system": { + "name": "target_system", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "total_changes": { + "name": "total_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "pending_changes": { + "name": "pending_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "synced_changes": { + "name": "synced_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "failed_changes": { + "name": "failed_changes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "next_sync_at": { + "name": "next_sync_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "sync_enabled": { + "name": "sync_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n WITH change_stats AS (\n SELECT \n cl.contract_id,\n sc.target_system,\n COUNT(*) as total_changes,\n COUNT(CASE WHEN cl.is_synced = false AND cl.sync_attempts < sc.retry_max_attempts THEN 1 END) as pending_changes,\n COUNT(CASE WHEN cl.is_synced = true THEN 1 END) as synced_changes,\n COUNT(CASE WHEN cl.sync_attempts >= sc.retry_max_attempts AND cl.is_synced = false THEN 1 END) as failed_changes,\n MAX(cl.synced_at) as last_sync_at\n FROM change_logs cl\n CROSS JOIN sync_configs sc \n WHERE cl.contract_id = sc.contract_id\n AND (cl.target_systems IS NULL OR cl.target_systems @> to_jsonb(sc.target_system))\n GROUP BY cl.contract_id, sc.target_system\n )\n SELECT \n cs.contract_id,\n cs.target_system,\n COALESCE(cs.total_changes, 0) as total_changes,\n COALESCE(cs.pending_changes, 0) as pending_changes,\n COALESCE(cs.synced_changes, 0) as synced_changes,\n COALESCE(cs.failed_changes, 0) as failed_changes,\n cs.last_sync_at,\n CASE \n WHEN sc.sync_enabled = true AND sc.last_successful_sync IS NOT NULL \n THEN sc.last_successful_sync + (sc.sync_interval_minutes || ' minutes')::interval\n ELSE NULL\n END as next_sync_at,\n sc.sync_enabled\n FROM sync_configs sc\n LEFT JOIN change_stats cs ON sc.contract_id = cs.contract_id AND sc.target_system = cs.target_system\n", + "name": "sync_status_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_documents_view": { + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc_number": { + "name": "doc_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "pic": { + "name": "pic", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "issued_date": { + "name": "issued_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "contract_id": { + "name": "contract_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "latest_stage_id": { + "name": "latest_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_stage_name": { + "name": "latest_stage_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "latest_stage_plan_date": { + "name": "latest_stage_plan_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "latest_stage_actual_date": { + "name": "latest_stage_actual_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "latest_revision_id": { + "name": "latest_revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "latest_revision": { + "name": "latest_revision", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_uploader_type": { + "name": "latest_revision_uploader_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "latest_revision_uploader_name": { + "name": "latest_revision_uploader_name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "attachment_count": { + "name": "attachment_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "definition": "\n SELECT \n d.id, \n d.doc_number,\n d.title,\n d.pic,\n d.status,\n d.issued_date,\n d.contract_id,\n \n (SELECT id FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_id,\n (SELECT stage_name FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_name,\n (SELECT plan_date FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_plan_date,\n (SELECT actual_date FROM issue_stages WHERE document_id = d.id ORDER BY created_at DESC LIMIT 1) AS latest_stage_actual_date,\n \n (SELECT r.id FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision_id,\n (SELECT r.revision FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision,\n (SELECT r.uploader_type FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision_uploader_type,\n (SELECT r.uploader_name FROM revisions r JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id ORDER BY r.created_at DESC LIMIT 1) AS latest_revision_uploader_name,\n \n (SELECT COUNT(*) FROM document_attachments a JOIN revisions r ON a.revision_id = r.id JOIN issue_stages i ON r.issue_stage_id = i.id WHERE i.document_id = d.id) AS attachment_count,\n \n d.created_at,\n d.updated_at\n FROM documents d\n JOIN contracts c ON d.contract_id = c.id\n ", + "name": "vendor_documents_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_candidates_with_vendor_info": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_name": { + "name": "company_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "contact_email": { + "name": "contact_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "contact_phone": { + "name": "contact_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'COLLECTED'" + }, + "items": { + "name": "items", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"vendor_candidates\".\"id\", \"vendor_candidates\".\"company_name\", \"vendor_candidates\".\"contact_email\", \"vendor_candidates\".\"contact_phone\", \"vendor_candidates\".\"tax_id\", \"vendor_candidates\".\"address\", \"vendor_candidates\".\"country\", \"vendor_candidates\".\"source\", \"vendor_candidates\".\"status\", \"vendor_candidates\".\"items\", \"vendor_candidates\".\"remark\", \"vendor_candidates\".\"created_at\", \"vendor_candidates\".\"updated_at\", \"vendors\".\"vendor_name\", \"vendors\".\"vendor_code\", \"vendors\".\"created_at\" as \"vendor_created_at\", (\n SELECT l2.\"created_at\"\n FROM \"vendor_candidate_logs\" l2\n WHERE l2.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l2.\"action\" = 'status_change'\n ORDER BY l2.\"created_at\" DESC\n LIMIT 1\n ) as \"last_status_change_at\", (\n SELECT u.\"name\"\n FROM \"users\" u\n JOIN \"vendor_candidate_logs\" l3\n ON l3.\"user_id\" = u.\"id\"\n WHERE l3.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l3.\"action\" = 'status_change'\n ORDER BY l3.\"created_at\" DESC\n LIMIT 1\n ) as \"last_status_change_by\", (\n SELECT l4.\"created_at\"\n FROM \"vendor_candidate_logs\" l4\n WHERE l4.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l4.\"action\" = 'invite_sent'\n ORDER BY l4.\"created_at\" DESC\n LIMIT 1\n ) as \"last_invitation_at\", (\n SELECT u2.\"name\"\n FROM \"users\" u2\n JOIN \"vendor_candidate_logs\" l5\n ON l5.\"user_id\" = u2.\"id\"\n WHERE l5.\"vendor_candidate_id\" = \"vendor_candidates\".\"id\"\n AND l5.\"action\" = 'invite_sent'\n ORDER BY l5.\"created_at\" DESC\n LIMIT 1\n ) as \"last_invitation_by\" from \"vendor_candidates\" left join \"vendors\" on \"vendor_candidates\".\"vendor_id\" = \"vendors\".\"id\"", + "name": "vendor_candidates_with_vendor_info", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_detail_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "tax_id": { + "name": "tax_id", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "business_size": { + "name": "business_size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "website": { + "name": "website", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true, + "default": "'PENDING_REVIEW'" + }, + "representative_name": { + "name": "representative_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_birth": { + "name": "representative_birth", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "representative_email": { + "name": "representative_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "representative_phone": { + "name": "representative_phone", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "corporate_registration_number": { + "name": "corporate_registration_number", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "credit_agency": { + "name": "credit_agency", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "credit_rating": { + "name": "credit_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "cash_flow_rating": { + "name": "cash_flow_rating", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"id\", \"vendor_name\", \"vendor_code\", \"tax_id\", \"address\", \"business_size\", \"country\", \"phone\", \"email\", \"website\", \"status\", \"representative_name\", \"representative_birth\", \"representative_email\", \"representative_phone\", \"corporate_registration_number\", \"credit_agency\", \"credit_rating\", \"cash_flow_rating\", \"created_at\", \"updated_at\", \n (SELECT COALESCE(\n json_agg(\n json_build_object(\n 'id', c.id,\n 'contactName', c.contact_name,\n 'contactPosition', c.contact_position,\n 'contactEmail', c.contact_email,\n 'contactPhone', c.contact_phone,\n 'isPrimary', c.is_primary\n )\n ),\n '[]'::json\n )\n FROM vendor_contacts c\n WHERE c.vendor_id = vendors.id)\n as \"contacts\", \n (SELECT COALESCE(\n json_agg(\n json_build_object(\n 'id', a.id,\n 'fileName', a.file_name,\n 'filePath', a.file_path,\n 'attachmentType', a.attachment_type,\n 'createdAt', a.created_at\n )\n ORDER BY a.attachment_type, a.created_at DESC\n ),\n '[]'::json\n )\n FROM vendor_attachments a\n WHERE a.vendor_id = vendors.id)\n as \"attachments\", \n (SELECT COUNT(*)\n FROM vendor_attachments a\n WHERE a.vendor_id = vendors.id)\n as \"attachment_count\", \n (SELECT COUNT(*) \n FROM vendor_contacts c\n WHERE c.vendor_id = vendors.id)\n as \"contact_count\" from \"vendors\"", + "name": "vendor_detail_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_items_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"vendor_possible_items\".\"id\", \"vendor_possible_items\".\"vendor_id\", \"items\".\"item_name\", \"items\".\"item_code\", \"items\".\"description\", \"vendor_possible_items\".\"created_at\", \"vendor_possible_items\".\"updated_at\" from \"vendor_possible_items\" left join \"items\" on \"vendor_possible_items\".\"item_code\" = \"items\".\"item_code\"", + "name": "vendor_items_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_materials_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "unit_of_measure": { + "name": "unit_of_measure", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false + }, + "steel_type": { + "name": "steel_type", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "grade_material": { + "name": "grade_material", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "definition": "select \"vendor_possible_materials\".\"id\", \"vendor_possible_materials\".\"vendor_id\", \"materials\".\"item_name\", \"materials\".\"item_code\", \"materials\".\"description\", \"materials\".\"unit_of_measure\", \"materials\".\"steel_type\", \"materials\".\"grade_material\", \"vendor_possible_materials\".\"created_at\", \"vendor_possible_materials\".\"updated_at\" from \"vendor_possible_materials\" left join \"materials\" on \"vendor_possible_materials\".\"item_code\" = \"materials\".\"item_code\"", + "name": "vendor_materials_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendors_with_types": { + "columns": {}, + "definition": "select \"vendors\".\"id\" as \"id\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"tax_id\" as \"tax_id\", \"vendors\".\"address\" as \"address\", \"vendors\".\"country\" as \"country\", \"vendors\".\"phone\" as \"phone\", \"vendors\".\"email\" as \"email\", \"vendors\".\"business_size\" as \"business_size\", \"vendors\".\"website\" as \"website\", \"vendors\".\"status\" as \"status\", \"vendors\".\"vendor_type_id\" as \"vendor_type_id\", \"vendors\".\"representative_name\" as \"representative_name\", \"vendors\".\"representative_birth\" as \"representative_birth\", \"vendors\".\"representative_email\" as \"representative_email\", \"vendors\".\"representative_phone\" as \"representative_phone\", \"vendors\".\"corporate_registration_number\" as \"corporate_registration_number\", \"vendors\".\"items\" as \"items\", \"vendors\".\"credit_agency\" as \"credit_agency\", \"vendors\".\"credit_rating\" as \"credit_rating\", \"vendors\".\"cash_flow_rating\" as \"cash_flow_rating\", \"vendors\".\"created_at\" as \"created_at\", \"vendors\".\"updated_at\" as \"updated_at\", \"vendor_types\".\"name_ko\" as \"vendor_type_name\", \"vendor_types\".\"name_en\" as \"vendor_type_name_en\", \"vendor_types\".\"code\" as \"vendor_type_code\", \n CASE\n WHEN \"vendors\".\"status\" = 'ACTIVE' THEN '정규업체'\n WHEN \"vendors\".\"status\" IN ('INACTIVE', 'BLACKLISTED', 'REJECTED') THEN ''\n ELSE '잠재업체'\n END\n as \"vendor_category\" from \"vendors\" left join \"vendor_types\" on \"vendors\".\"vendor_type_id\" = \"vendor_types\".\"id\"", + "name": "vendors_with_types", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.basic_contract_view": { + "columns": {}, + "definition": "select \"basic_contract\".\"id\" as \"id\", \"basic_contract\".\"template_id\" as \"template_id\", \"basic_contract\".\"vendor_id\" as \"vendor_id\", \"basic_contract\".\"requested_by\" as \"requested_by\", \"basic_contract\".\"status\" as \"basic_contract_status\", \"basic_contract\".\"created_at\" as \"created_at\", \"basic_contract\".\"updated_at\" as \"updated_at\", \"basic_contract\".\"updated_at\" as \"completed_at\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"email\" as \"vendor_email\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"users\".\"name\" as \"user_name\", \"basic_contract_templates\".\"template_name\" as \"template_name\", \"basic_contract_templates\".\"validity_period\" as \"validityPeriod\", \"basic_contract_templates\".\"file_path\" as \"file_path\", \"basic_contract_templates\".\"file_name\" as \"file_name\", \"basic_contract\".\"file_path\" as \"signed_file_path\" from \"basic_contract\" left join \"vendors\" on \"basic_contract\".\"vendor_id\" = \"vendors\".\"id\" left join \"users\" on \"basic_contract\".\"requested_by\" = \"users\".\"id\" left join \"basic_contract_templates\" on \"basic_contract\".\"template_id\" = \"basic_contract_templates\".\"id\"", + "name": "basic_contract_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.pr_items_view": { + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "procurement_rfqs_id": { + "name": "procurement_rfqs_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_item": { + "name": "rfq_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_item": { + "name": "pr_item", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pr_no": { + "name": "pr_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "material_code": { + "name": "material_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_category": { + "name": "material_category", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "acc": { + "name": "acc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "material_description": { + "name": "material_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "size": { + "name": "size", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "quantity": { + "name": "quantity", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "uom": { + "name": "uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "gross_weight": { + "name": "gross_weight", + "type": "numeric(12, 2)", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "gw_uom": { + "name": "gw_uom", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "spec_no": { + "name": "spec_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "spec_url": { + "name": "spec_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "tracking_no": { + "name": "tracking_no", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "major_yn": { + "name": "major_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "project_def": { + "name": "project_def", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_sc": { + "name": "project_sc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_kl": { + "name": "project_kl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_lc": { + "name": "project_lc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_dl": { + "name": "project_dl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "item_code": { + "name": "item_code", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "item_name": { + "name": "item_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select \"pr_items\".\"id\", \"pr_items\".\"procurement_rfqs_id\", \"pr_items\".\"rfq_item\", \"pr_items\".\"pr_item\", \"pr_items\".\"pr_no\", \"pr_items\".\"material_code\", \"pr_items\".\"material_category\", \"pr_items\".\"acc\", \"pr_items\".\"material_description\", \"pr_items\".\"size\", \"pr_items\".\"delivery_date\", \"pr_items\".\"quantity\", \"pr_items\".\"uom\", \"pr_items\".\"gross_weight\", \"pr_items\".\"gw_uom\", \"pr_items\".\"spec_no\", \"pr_items\".\"spec_url\", \"pr_items\".\"tracking_no\", \"pr_items\".\"major_yn\", \"pr_items\".\"project_def\", \"pr_items\".\"project_sc\", \"pr_items\".\"project_kl\", \"pr_items\".\"project_lc\", \"pr_items\".\"project_dl\", \"pr_items\".\"remark\", \"procurement_rfqs\".\"rfq_code\", \"procurement_rfqs\".\"item_code\", \"procurement_rfqs\".\"item_name\" from \"pr_items\" left join \"procurement_rfqs\" on \"pr_items\".\"procurement_rfqs_id\" = \"procurement_rfqs\".\"id\"", + "name": "pr_items_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.procurement_rfq_details_view": { + "columns": {}, + "definition": "select \"rfq_details\".\"id\" as \"detail_id\", \"rfqs\".\"id\" as \"rfq_id\", \"rfqs\".\"rfq_code\" as \"rfq_code\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"rfqs\".\"item_code\" as \"item_code\", \"rfqs\".\"item_name\" as \"item_name\", \"vendors\".\"vendor_name\" as \"vendor_name\", \"vendors\".\"vendor_code\" as \"vendor_code\", \"vendors\".\"id\" as \"vendor_id\", \"vendors\".\"country\" as \"vendor_country\", \"rfq_details\".\"currency\" as \"currency\", \"payment_terms\".\"code\" as \"payment_terms_code\", \"payment_terms\".\"description\" as \"payment_terms_description\", \"incoterms\".\"code\" as \"incoterms_code\", \"incoterms\".\"description\" as \"incoterms_description\", \"rfq_details\".\"incoterms_detail\" as \"incoterms_detail\", \"rfq_details\".\"delivery_date\" as \"delivery_date\", \"rfq_details\".\"tax_code\" as \"tax_code\", \"rfq_details\".\"place_of_shipping\" as \"place_of_shipping\", \"rfq_details\".\"place_of_destination\" as \"place_of_destination\", \"rfq_details\".\"material_price_related_yn\" as \"material_price_related_yn\", \"updated_by_user\".\"name\" as \"updated_by_user_name\", \"rfq_details\".\"updated_at\" as \"updated_at\", (\n SELECT COUNT(*) \n FROM pr_items \n WHERE procurement_rfqs_id = \"rfqs\".\"id\"\n ) as \"pr_items_count\", (\n SELECT COUNT(*) \n FROM pr_items \n WHERE procurement_rfqs_id = \"rfqs\".\"id\" \n AND major_yn = true\n ) as \"major_items_count\", (\n SELECT COUNT(*) \n FROM procurement_rfq_comments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"comment_count\", (\n SELECT created_at \n FROM procurement_rfq_comments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY created_at DESC LIMIT 1\n ) as \"last_comment_date\", (\n SELECT created_at \n FROM procurement_rfq_comments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\" AND is_vendor_comment = true\n ORDER BY created_at DESC LIMIT 1\n ) as \"last_vendor_comment_date\", (\n SELECT COUNT(*) \n FROM procurement_rfq_attachments \n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"attachment_count\", (\n SELECT COUNT(*) > 0\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"has_quotation\", (\n SELECT status\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY created_at DESC LIMIT 1\n ) as \"quotation_status\", (\n SELECT total_price\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY created_at DESC LIMIT 1\n ) as \"quotation_total_price\", (\n SELECT quotation_version\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY quotation_version DESC LIMIT 1\n ) as \"quotation_version\", (\n SELECT COUNT(DISTINCT quotation_version)\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ) as \"quotation_version_count\", (\n SELECT created_at\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"rfqs\".\"id\" AND vendor_id = \"rfq_details\".\"vendors_id\"\n ORDER BY quotation_version DESC LIMIT 1\n ) as \"last_quotation_date\" from \"procurement_rfq_details\" \"rfq_details\" left join \"procurement_rfqs\" \"rfqs\" on \"rfq_details\".\"procurement_rfqs_id\" = \"rfqs\".\"id\" left join \"projects\" on \"rfqs\".\"project_id\" = \"projects\".\"id\" left join \"vendors\" on \"rfq_details\".\"vendors_id\" = \"vendors\".\"id\" left join \"payment_terms\" on \"rfq_details\".\"payment_terms_code\" = \"payment_terms\".\"code\" left join \"incoterms\" on \"rfq_details\".\"incoterms_code\" = \"incoterms\".\"code\" left join \"users\" \"updated_by_user\" on \"rfq_details\".\"updated_by\" = \"updated_by_user\".\"id\"", + "name": "procurement_rfq_details_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.procurement_rfqs_view": { + "columns": {}, + "definition": "select \"procurement_rfqs\".\"id\" as \"id\", \"procurement_rfqs\".\"rfq_code\" as \"rfq_code\", \"procurement_rfqs\".\"series\" as \"series\", \"procurement_rfqs\".\"rfq_sealed_yn\" as \"rfq_sealed_yn\", \"projects\".\"code\" as \"project_code\", \"projects\".\"name\" as \"project_name\", \"procurement_rfqs\".\"item_code\" as \"item_code\", \"procurement_rfqs\".\"item_name\" as \"item_name\", \"procurement_rfqs\".\"status\" as \"status\", \"procurement_rfqs\".\"pic_code\" as \"pic_code\", \"procurement_rfqs\".\"rfq_send_date\" as \"rfq_send_date\", \"procurement_rfqs\".\"due_date\" as \"due_date\", (\n SELECT MIN(submitted_at)\n FROM procurement_vendor_quotations\n WHERE rfq_id = \"procurement_rfqs\".\"id\"\n AND submitted_at IS NOT NULL\n ) as \"earliest_quotation_submitted_at\", \"created_by_user\".\"name\" as \"created_by_user_name\", \"sent_by_user\".\"name\" as \"sent_by_user_name\", \"procurement_rfqs\".\"updated_at\" as \"updated_at\", \"updated_by_user\".\"name\" as \"updated_by_user_name\", \"procurement_rfqs\".\"remark\" as \"remark\", (\n SELECT material_code \n FROM pr_items \n WHERE procurement_rfqs_id = \"procurement_rfqs\".\"id\"\n AND major_yn = true\n LIMIT 1\n ) as \"major_item_material_code\", (\n SELECT pr_no \n FROM pr_items \n WHERE procurement_rfqs_id = \"procurement_rfqs\".\"id\"\n AND major_yn = true\n LIMIT 1\n ) as \"po_no\", (\n SELECT COUNT(*) \n FROM pr_items \n WHERE procurement_rfqs_id = \"procurement_rfqs\".\"id\"\n ) as \"pr_items_count\" from \"procurement_rfqs\" left join \"projects\" on \"procurement_rfqs\".\"project_id\" = \"projects\".\"id\" left join \"users\" \"created_by_user\" on \"procurement_rfqs\".\"created_by\" = \"created_by_user\".\"id\" left join \"users\" \"updated_by_user\" on \"procurement_rfqs\".\"updated_by\" = \"updated_by_user\".\"id\" left join \"users\" \"sent_by_user\" on \"procurement_rfqs\".\"sent_by\" = \"sent_by_user\".\"id\"", + "name": "procurement_rfqs_view", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.attachments_with_latest_revision": { + "columns": { + "attachment_id": { + "name": "attachment_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "attachment_type": { + "name": "attachment_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "serial_no": { + "name": "serial_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "current_revision": { + "name": "current_revision", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "revision_id": { + "name": "revision_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_name": { + "name": "file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "original_file_name": { + "name": "original_file_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "file_path": { + "name": "file_path", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "file_size": { + "name": "file_size", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "file_type": { + "name": "file_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "revision_comment": { + "name": "revision_comment", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_by_name": { + "name": "created_by_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n a.id as attachment_id,\n a.attachment_type,\n a.serial_no,\n a.rfq_id,\n a.description,\n a.current_revision,\n \n r.id as revision_id,\n r.file_name,\n r.original_file_name,\n r.file_path,\n r.file_size,\n r.file_type,\n r.revision_comment,\n \n a.created_by,\n u.name as created_by_name,\n a.created_at,\n a.updated_at\n FROM b_rfq_attachments a\n LEFT JOIN b_rfq_attachment_revisions r ON a.latest_revision_id = r.id\n LEFT JOIN users u ON a.created_by = u.id\n ", + "name": "attachments_with_latest_revision", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.b_rfqs_master": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pic_name": { + "name": "pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "eng_pic_name": { + "name": "eng_pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_no": { + "name": "package_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_name": { + "name": "package_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_id": { + "name": "project_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "project_code": { + "name": "project_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_name": { + "name": "project_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "project_type": { + "name": "project_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "project_company": { + "name": "project_company", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_flag": { + "name": "project_flag", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_site": { + "name": "project_site", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "total_attachments": { + "name": "total_attachments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.description,\n br.status,\n br.due_date,\n br.pic_code,\n br.pic_name,\n br.eng_pic_name,\n br.package_no,\n br.package_name,\n br.project_id,\n p.code as project_code,\n p.name as project_name,\n p.type as project_type,\n br.project_company,\n br.project_flag,\n br.project_site,\n COALESCE(att_count.total_attachments, 0) as total_attachments,\n br.created_at,\n br.updated_at\n FROM b_rfqs br\n LEFT JOIN projects p ON br.project_id = p.id\n LEFT JOIN (\n SELECT rfq_id, COUNT(*) as total_attachments\n FROM b_rfq_attachments\n GROUP BY rfq_id\n ) att_count ON br.id = att_count.rfq_id\n", + "name": "b_rfqs_master", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.final_rfq_detail": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_status": { + "name": "rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "final_rfq_id": { + "name": "final_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "final_rfq_status": { + "name": "final_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_country": { + "name": "vendor_country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "vendor_business_size": { + "name": "vendor_business_size", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "delivery_date": { + "name": "delivery_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_description": { + "name": "incoterms_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "payment_terms_code": { + "name": "payment_terms_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "payment_terms_description": { + "name": "payment_terms_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "currency": { + "name": "currency", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "tax_code": { + "name": "tax_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_shipping": { + "name": "place_of_shipping", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "place_of_destination": { + "name": "place_of_destination", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "firsttime_yn": { + "name": "firsttime_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "material_price_related_yn": { + "name": "material_price_related_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vendor_remark": { + "name": "vendor_remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.status as rfq_status,\n fr.id as final_rfq_id,\n fr.final_rfq_status,\n fr.vendor_id,\n v.vendor_code,\n v.vendor_name,\n v.country as vendor_country,\n v.business_size as vendor_business_size,\n fr.due_date,\n fr.valid_date,\n fr.delivery_date,\n fr.incoterms_code,\n inc.description as incoterms_description,\n fr.payment_terms_code,\n pt.description as payment_terms_description,\n fr.currency,\n fr.tax_code,\n fr.place_of_shipping,\n fr.place_of_destination,\n fr.short_list,\n fr.return_yn,\n fr.cp_request_yn,\n fr.prject_gtc_yn,\n fr.firsttime_yn,\n fr.material_price_related_yn,\n fr.return_revision,\n fr.gtc,\n fr.gtc_valid_date,\n fr.classification,\n fr.sparepart,\n fr.remark,\n fr.vendor_remark,\n fr.created_at,\n fr.updated_at\n FROM b_rfqs br\n JOIN final_rfq fr ON br.id = fr.rfq_id\n LEFT JOIN vendors v ON fr.vendor_id = v.id\n LEFT JOIN incoterms inc ON fr.incoterms_code = inc.code\n LEFT JOIN payment_terms pt ON fr.payment_terms_code = pt.code\n", + "name": "final_rfq_detail", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.initial_rfq_detail": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_status": { + "name": "rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "initial_rfq_id": { + "name": "initial_rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "initial_rfq_status": { + "name": "initial_rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_country": { + "name": "vendor_country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "vendor_business_size": { + "name": "vendor_business_size", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "valid_date": { + "name": "valid_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "incoterms_code": { + "name": "incoterms_code", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "incoterms_description": { + "name": "incoterms_description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "short_list": { + "name": "short_list", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_yn": { + "name": "return_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "cp_request_yn": { + "name": "cp_request_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "prject_gtc_yn": { + "name": "prject_gtc_yn", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "return_revision": { + "name": "return_revision", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "gtc": { + "name": "gtc", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gtc_valid_date": { + "name": "gtc_valid_date", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "classification": { + "name": "classification", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "sparepart": { + "name": "sparepart", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.status as rfq_status,\n ir.id as initial_rfq_id,\n ir.initial_rfq_status,\n ir.vendor_id,\n v.vendor_code,\n v.vendor_name,\n v.country as vendor_country,\n v.business_size as vendor_business_size,\n ir.due_date,\n ir.valid_date,\n ir.incoterms_code,\n inc.description as incoterms_description,\n ir.short_list,\n ir.return_yn,\n ir.cp_request_yn,\n ir.prject_gtc_yn,\n ir.return_revision,\n ir.gtc,\n ir.gtc_valid_date,\n ir.classification,\n ir.sparepart,\n ir.created_at,\n ir.updated_at\n FROM b_rfqs br\n JOIN initial_rfq ir ON br.id = ir.rfq_id\n LEFT JOIN vendors v ON ir.vendor_id = v.id\n LEFT JOIN incoterms inc ON ir.incoterms_code = inc.code\n", + "name": "initial_rfq_detail", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.rfq_dashboard": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "due_date": { + "name": "due_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "project_code": { + "name": "project_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_name": { + "name": "project_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "package_no": { + "name": "package_no", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "package_name": { + "name": "package_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "pic_code": { + "name": "pic_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "pic_name": { + "name": "pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "eng_pic_name": { + "name": "eng_pic_name", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "project_company": { + "name": "project_company", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_flag": { + "name": "project_flag", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "project_site": { + "name": "project_site", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "total_attachments": { + "name": "total_attachments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "initial_vendor_count": { + "name": "initial_vendor_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "final_vendor_count": { + "name": "final_vendor_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "initial_response_rate": { + "name": "initial_response_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "final_response_rate": { + "name": "final_response_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "overall_progress": { + "name": "overall_progress", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "days_to_deadline": { + "name": "days_to_deadline", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "remark": { + "name": "remark", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "updated_by_name": { + "name": "updated_by_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "updated_by_email": { + "name": "updated_by_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n -- ② SELECT 절 확장 -------------------------------------------\n SELECT\n br.id AS rfq_id,\n br.rfq_code,\n br.description,\n br.status,\n br.due_date,\n p.code AS project_code,\n p.name AS project_name,\n br.package_no,\n br.package_name,\n br.pic_code,\n br.pic_name,\n br.eng_pic_name,\n br.project_company,\n br.project_flag,\n br.project_site,\n br.remark,\n \n -- 첨부/벤더 요약 -----------------------\n COALESCE(att_count.total_attachments, 0) AS total_attachments,\n COALESCE(init_summary.vendor_count, 0) AS initial_vendor_count,\n COALESCE(final_summary.vendor_count, 0) AS final_vendor_count,\n COALESCE(init_summary.avg_response_rate, 0) AS initial_response_rate,\n COALESCE(final_summary.avg_response_rate, 0) AS final_response_rate,\n \n -- 진행률·마감까지 일수 --------------\n CASE \n WHEN br.status = 'DRAFT' THEN 0\n WHEN br.status = 'Doc. Received' THEN 10\n WHEN br.status = 'PIC Assigned' THEN 20\n WHEN br.status = 'Doc. Confirmed' THEN 30\n WHEN br.status = 'Init. RFQ Sent' THEN 40\n WHEN br.status = 'Init. RFQ Answered' THEN 50\n WHEN br.status = 'TBE started' THEN 60\n WHEN br.status = 'TBE finished' THEN 70\n WHEN br.status = 'Final RFQ Sent' THEN 80\n WHEN br.status = 'Quotation Received' THEN 90\n WHEN br.status = 'Vendor Selected' THEN 100\n ELSE 0\n END AS overall_progress,\n (br.due_date - CURRENT_DATE) AS days_to_deadline,\n \n br.created_at,\n br.updated_at,\n \n -- 💡 추가되는 컬럼 -------------------\n upd.name AS updated_by_name,\n upd.email AS updated_by_email\n FROM b_rfqs br\n LEFT JOIN projects p ON br.project_id = p.id\n \n -- ③ 사용자 정보 조인 --------------------\n LEFT JOIN users upd ON br.updated_by = upd.id\n \n -- (나머지 이미 있던 JOIN 들은 그대로) -----\n LEFT JOIN (\n SELECT rfq_id, COUNT(*) AS total_attachments\n FROM b_rfq_attachments\n GROUP BY rfq_id\n ) att_count ON br.id = att_count.rfq_id\n \n LEFT JOIN (\n SELECT \n rfq_id, \n COUNT(DISTINCT vendor_id) AS vendor_count,\n AVG(response_rate) AS avg_response_rate\n FROM vendor_response_summary\n WHERE rfq_type = 'INITIAL'\n GROUP BY rfq_id\n ) init_summary ON br.id = init_summary.rfq_id\n \n LEFT JOIN (\n SELECT \n rfq_id, \n COUNT(DISTINCT vendor_id) AS vendor_count,\n AVG(response_rate) AS avg_response_rate\n FROM vendor_response_summary\n WHERE rfq_type = 'FINAL'\n GROUP BY rfq_id\n ) final_summary ON br.id = final_summary.rfq_id\n ", + "name": "rfq_dashboard", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.vendor_response_summary": { + "columns": { + "rfq_id": { + "name": "rfq_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rfq_code": { + "name": "rfq_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_status": { + "name": "rfq_status", + "type": "varchar(30)", + "primaryKey": false, + "notNull": false + }, + "vendor_id": { + "name": "vendor_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vendor_code": { + "name": "vendor_code", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "vendor_name": { + "name": "vendor_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "vendor_country": { + "name": "vendor_country", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "vendor_business_size": { + "name": "vendor_business_size", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "rfq_type": { + "name": "rfq_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "total_attachments": { + "name": "total_attachments", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "responded_count": { + "name": "responded_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "pending_count": { + "name": "pending_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "waived_count": { + "name": "waived_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "revision_requested_count": { + "name": "revision_requested_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "response_rate": { + "name": "response_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + }, + "completion_rate": { + "name": "completion_rate", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT \n br.id as rfq_id,\n br.rfq_code,\n br.status as rfq_status,\n v.id as vendor_id,\n v.vendor_code,\n v.vendor_name,\n v.country as vendor_country,\n v.business_size as vendor_business_size,\n var.rfq_type,\n COUNT(var.id) as total_attachments,\n COUNT(CASE WHEN var.response_status = 'RESPONDED' THEN 1 END) as responded_count,\n COUNT(CASE WHEN var.response_status = 'NOT_RESPONDED' THEN 1 END) as pending_count,\n COUNT(CASE WHEN var.response_status = 'WAIVED' THEN 1 END) as waived_count,\n COUNT(CASE WHEN var.response_status = 'REVISION_REQUESTED' THEN 1 END) as revision_requested_count,\n ROUND(\n (COUNT(CASE WHEN var.response_status = 'RESPONDED' THEN 1 END) * 100.0 / \n NULLIF(COUNT(CASE WHEN var.response_status != 'WAIVED' THEN 1 END), 0)), \n 2\n ) as response_rate,\n ROUND(\n ((COUNT(CASE WHEN var.response_status = 'RESPONDED' THEN 1 END) + \n COUNT(CASE WHEN var.response_status = 'WAIVED' THEN 1 END)) * 100.0 / COUNT(var.id)), \n 2\n ) as completion_rate\n FROM b_rfqs br\n JOIN b_rfq_attachments bra ON br.id = bra.rfq_id\n JOIN vendor_attachment_responses var ON bra.id = var.attachment_id\n JOIN vendors v ON var.vendor_id = v.id\n GROUP BY br.id, br.rfq_code, br.status, v.id, v.vendor_code, v.vendor_name, v.country, v.business_size, var.rfq_type\n", + "name": "vendor_response_summary", + "schema": "public", + "isExisting": false, + "materialized": false + } + }, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +}
\ No newline at end of file diff --git a/db/migrations/meta/_journal.json b/db/migrations/meta/_journal.json index 5fdfde1f..99606a42 100644 --- a/db/migrations/meta/_journal.json +++ b/db/migrations/meta/_journal.json @@ -897,6 +897,27 @@ "when": 1749641778751, "tag": "0127_sweet_spiral", "breakpoints": true + }, + { + "idx": 128, + "version": "7", + "when": 1749693568396, + "tag": "0128_sad_vermin", + "breakpoints": true + }, + { + "idx": 129, + "version": "7", + "when": 1749700162121, + "tag": "0129_nifty_albert_cleary", + "breakpoints": true + }, + { + "idx": 130, + "version": "7", + "when": 1749716298952, + "tag": "0130_brown_nightmare", + "breakpoints": true } ] }
\ No newline at end of file diff --git a/db/schema/bRfq.ts b/db/schema/bRfq.ts index 5e211448..115d2c6e 100644 --- a/db/schema/bRfq.ts +++ b/db/schema/bRfq.ts @@ -168,52 +168,114 @@ export const bRfqsAttachments = pgTable( "b_rfq_attachments", { id: serial("id").primaryKey(), - attachmentType: varchar("attachment_type", { length: 50 }).notNull(), // '구매', '설계' + attachmentType: varchar("attachment_type", { length: 50 }).notNull(), serialNo: varchar("serial_no", { length: 50 }).notNull(), rfqId: integer("rfq_id") - .notNull() - .references(() => bRfqs.id), + .notNull() + .references(() => bRfqs.id), + + // 현재 리비전 정보 (빠른 접근용) + currentRevision: varchar("current_revision", { length: 10 }).notNull().default("Rev.0"), + latestRevisionId: integer("latest_revision_id"), // self-reference to bRfqAttachmentRevisions + + // 메타 정보 + description: varchar("description", { length: 500 }), + createdBy: integer("created_by") + .references(() => users.id, { onDelete: "set null" }) + .notNull(), + createdAt: timestamp("created_at").defaultNow().notNull(), + updatedAt: timestamp("updated_at").defaultNow().notNull(), + } + ) + + // 리비전 테이블 (모든 파일 버전 관리) + export const bRfqAttachmentRevisions = pgTable( + "b_rfq_attachment_revisions", + { + id: serial("id").primaryKey(), + attachmentId: integer("attachment_id") + .notNull() + .references(() => bRfqsAttachments.id, { onDelete: "cascade" }), + + // 리비전 정보 + revisionNo: varchar("revision_no", { length: 10 }).notNull(), // "Rev.0", "Rev.1", "Rev.2" + revisionComment: text("revision_comment"), + isLatest: boolean("is_latest").notNull().default(true), + + // 파일 정보 fileName: varchar("file_name", { length: 255 }).notNull(), originalFileName: varchar("original_file_name", { length: 255 }).notNull(), filePath: varchar("file_path", { length: 512 }).notNull(), fileSize: integer("file_size"), fileType: varchar("file_type", { length: 100 }), - description: varchar("description", { length: 500 }), + + // 리비전 생성 정보 createdBy: integer("created_by") .references(() => users.id, { onDelete: "set null" }) .notNull(), createdAt: timestamp("created_at").defaultNow().notNull(), - }, - ); -// 1. 첨부파일 리비전 관리 테이블 -export const bRfqAttachmentRevisions = pgTable( - "b_rfq_attachment_revisions", - { - id: serial("id").primaryKey(), - attachmentId: integer("attachment_id") - .notNull() - .references(() => bRfqsAttachments.id, { onDelete: "cascade" }), - - revisionNo: varchar("revision_no", { length: 10 }).notNull(), // "Rev.0", "Rev.1", "Rev.2" - fileName: varchar("file_name", { length: 255 }).notNull(), - originalFileName: varchar("original_file_name", { length: 255 }).notNull(), - filePath: varchar("file_path", { length: 512 }).notNull(), - fileSize: integer("file_size"), - fileType: varchar("file_type", { length: 100 }), - - isLatest: boolean("is_latest").notNull().default(true), - revisionComment: text("revision_comment"), - - createdBy: integer("created_by") - .references(() => users.id, { onDelete: "set null" }) - .notNull(), - createdAt: timestamp("created_at").defaultNow().notNull(), - }, (t) => ({ - latestRevisionIdx: uniqueIndex('latest_revision_idx').on( - t.attachmentId.asc(), - t.isLatest.asc(), - ), - })); + }, + (t) => ({ + // 첨부파일당 하나의 최신 리비전만 허용 + latestRevisionIdx: uniqueIndex('latest_revision_idx') + .on(t.attachmentId, t.isLatest) + .where(eq(t.isLatest, true)), + + // 첨부파일 + 리비전 번호 유니크 + attachmentRevisionIdx: uniqueIndex('attachment_revision_idx') + .on(t.attachmentId, t.revisionNo), + }) + ) + + // 첨부파일 + 최신 리비전 뷰 + export const attachmentsWithLatestRevisionView = pgView("attachments_with_latest_revision", { + // 메인 첨부파일 정보 + attachmentId: integer("attachment_id"), + attachmentType: varchar("attachment_type", { length: 50 }), + serialNo: varchar("serial_no", { length: 50 }), + rfqId: integer("rfq_id"), + description: varchar("description", { length: 500 }), + currentRevision: varchar("current_revision", { length: 10 }), + + // 최신 리비전 파일 정보 + revisionId: integer("revision_id"), + fileName: varchar("file_name", { length: 255 }), + originalFileName: varchar("original_file_name", { length: 255 }), + filePath: varchar("file_path", { length: 512 }), + fileSize: integer("file_size"), + fileType: varchar("file_type", { length: 100 }), + revisionComment: text("revision_comment"), + + // 생성/수정 정보 + createdBy: integer("created_by"), + createdByName: varchar("created_by_name", { length: 255 }), + createdAt: timestamp("created_at"), + updatedAt: timestamp("updated_at"), + }).as(sql` + SELECT + a.id as attachment_id, + a.attachment_type, + a.serial_no, + a.rfq_id, + a.description, + a.current_revision, + + r.id as revision_id, + r.file_name, + r.original_file_name, + r.file_path, + r.file_size, + r.file_type, + r.revision_comment, + + a.created_by, + u.name as created_by_name, + a.created_at, + a.updated_at + FROM b_rfq_attachments a + LEFT JOIN b_rfq_attachment_revisions r ON a.latest_revision_id = r.id + LEFT JOIN users u ON a.created_by = u.id + `) // 2. 벤더별 첨부파일 응답 현황 관리 export const vendorAttachmentResponses = pgTable( diff --git a/db/schema/vendorDocu.ts b/db/schema/vendorDocu.ts index a3138fd5..af48d74b 100644 --- a/db/schema/vendorDocu.ts +++ b/db/schema/vendorDocu.ts @@ -467,6 +467,7 @@ export const enhancedDocumentsView = pgView("enhanced_documents_view", { d.degree_gbn, d.dept_gbn, d.s_gbn, + d.j_gbn, @@ -758,3 +759,275 @@ export type ChangeLogInsert = typeof changeLogs.$inferInsert export type SyncBatch = typeof syncBatches.$inferSelect export type SyncBatchInsert = typeof syncBatches.$inferInsert export type SyncStatusView = typeof syncStatusView.$inferSelect + + +export const simplifiedDocumentsView = pgView("simplified_documents_view", { + // 기본 문서 정보 + documentId: integer("document_id").notNull(), + docNumber: varchar("doc_number", { length: 100 }).notNull(), + drawingKind: varchar("drawing_kind", { length: 50 }), + vendorDocNumber: varchar("vendor_doc_number", { length: 100 }), + title: varchar("title", { length: 255 }).notNull(), + pic: varchar("pic", { length: 50 }), + status: varchar("status", { length: 50 }).notNull(), + issuedDate: date("issued_date"), + contractId: integer("contract_id").notNull(), + + // 프로젝트 및 벤더 정보 + projectCode: varchar("project_code", { length: 50 }), + vendorName: varchar("vendor_name", { length: 255 }), + vendorCode: varchar("vendor_code", { length: 50 }), + + // B4 전용 필드들 + cGbn: varchar("c_gbn", { length: 50 }), + dGbn: varchar("d_gbn", { length: 50 }), + degreeGbn: varchar("degree_gbn", { length: 50 }), + deptGbn: varchar("dept_gbn", { length: 50 }), + jGbn: varchar("j_gbn", { length: 50 }), + sGbn: varchar("s_gbn", { length: 50 }), + + // 첫 번째 스테이지 날짜 정보 (drawingKind에 따라 다름) + firstStageId: integer("first_stage_id"), + firstStageName: varchar("first_stage_name", { length: 100 }), + firstStagePlanDate: date("first_stage_plan_date"), + firstStageActualDate: date("first_stage_actual_date"), + + // 두 번째 스테이지 날짜 정보 (drawingKind에 따라 다름) + secondStageId: integer("second_stage_id"), + secondStageName: varchar("second_stage_name", { length: 100 }), + secondStagePlanDate: date("second_stage_plan_date"), + secondStageActualDate: date("second_stage_actual_date"), + + // 전체 스테이지 목록 (기존과 동일) + allStages: jsonb("all_stages").$type<Array<{ + id: number; + stageName: string; + stageStatus: string; + stageOrder: number; + planDate: string | null; + actualDate: string | null; + assigneeName: string | null; + priority: string; + revisions: Array<{ + id: number; + issueStageId: number; + revision: string; + uploaderType: string; + uploaderId: number | null; + uploaderName: string | null; + comment: string | null; + usage: string | null; + revisionStatus: string; + submittedDate: string | null; + approvedDate: string | null; + uploadedAt: string | null; + reviewStartDate: string | null; + rejectedDate: string | null; + reviewerId: number | null; + reviewerName: string | null; + reviewComments: string | null; + createdAt: Date; + updatedAt: Date; + attachments: Array<{ + id: number; + revisionId: number; + fileName: string; + filePath: string; + fileSize: number | null; + fileType: string | null; + createdAt: Date; + updatedAt: Date; + }>; + }>; + }>>(), + + // 메타 정보 + attachmentCount: integer("attachment_count"), + createdAt: timestamp("created_at", { withTimezone: true }).notNull(), + updatedAt: timestamp("updated_at", { withTimezone: true }).notNull(), +}).as(sql` + WITH + -- 리비전별 첨부파일 집계 + revision_attachments AS ( + SELECT + r.id as revision_id, + COALESCE( + json_agg( + json_build_object( + 'id', da.id, + 'revisionId', da.revision_id, + 'fileName', da.file_name, + 'filePath', da.file_path, + 'fileSize', da.file_size, + 'fileType', da.file_type, + 'createdAt', da.created_at, + 'updatedAt', da.updated_at + ) ORDER BY da.created_at + ) FILTER (WHERE da.id IS NOT NULL), + '[]'::json + ) as attachments + FROM revisions r + LEFT JOIN document_attachments da ON r.id = da.revision_id + GROUP BY r.id + ), + -- 스테이지별 리비전 집계 (첨부파일 포함) + stage_revisions AS ( + SELECT + ist.id as stage_id, + COALESCE( + json_agg( + json_build_object( + 'id', r.id, + 'issueStageId', r.issue_stage_id, + 'revision', r.revision, + 'uploaderType', r.uploader_type, + 'uploaderId', r.uploader_id, + 'uploaderName', r.uploader_name, + 'comment', r.comment, + 'usage', r.usage, + 'revisionStatus', r.revision_status, + 'submittedDate', r.submitted_date, + 'uploadedAt', r.uploaded_at, + 'approvedDate', r.approved_date, + 'reviewStartDate', r.review_start_date, + 'rejectedDate', r.rejected_date, + 'reviewerId', r.reviewer_id, + 'reviewerName', r.reviewer_name, + 'reviewComments', r.review_comments, + 'createdAt', r.created_at, + 'updatedAt', r.updated_at, + 'attachments', ra.attachments + ) ORDER BY r.created_at + ) FILTER (WHERE r.id IS NOT NULL), + '[]'::json + ) as revisions + FROM issue_stages ist + LEFT JOIN revisions r ON ist.id = r.issue_stage_id + LEFT JOIN revision_attachments ra ON r.id = ra.revision_id + GROUP BY ist.id + ), + -- 문서별 스테이지 집계 (리비전 포함) + stage_aggregation AS ( + SELECT + ist.document_id, + json_agg( + json_build_object( + 'id', ist.id, + 'stageName', ist.stage_name, + 'stageStatus', ist.stage_status, + 'stageOrder', ist.stage_order, + 'planDate', ist.plan_date, + 'actualDate', ist.actual_date, + 'assigneeName', ist.assignee_name, + 'priority', ist.priority, + 'revisions', sr.revisions + ) ORDER BY ist.stage_order + ) as all_stages + FROM issue_stages ist + LEFT JOIN stage_revisions sr ON ist.id = sr.stage_id + GROUP BY ist.document_id + ), + -- 첫 번째 스테이지 정보 (drawingKind에 따라 다른 조건) + first_stage_info AS ( + SELECT DISTINCT ON (ist.document_id) + ist.document_id, + ist.id as first_stage_id, + ist.stage_name as first_stage_name, + ist.plan_date as first_stage_plan_date, + ist.actual_date as first_stage_actual_date + FROM issue_stages ist + JOIN documents d ON ist.document_id = d.id + WHERE + (d.drawing_kind = 'B4' AND LOWER(ist.stage_name) LIKE '%pre%') OR + (d.drawing_kind = 'B3' AND LOWER(ist.stage_name) LIKE '%approval%') OR + (d.drawing_kind = 'B5' AND LOWER(ist.stage_name) LIKE '%first%') + ORDER BY ist.document_id, ist.stage_order ASC + ), + -- 두 번째 스테이지 정보 (drawingKind에 따라 다른 조건) + second_stage_info AS ( + SELECT DISTINCT ON (ist.document_id) + ist.document_id, + ist.id as second_stage_id, + ist.stage_name as second_stage_name, + ist.plan_date as second_stage_plan_date, + ist.actual_date as second_stage_actual_date + FROM issue_stages ist + JOIN documents d ON ist.document_id = d.id + WHERE + (d.drawing_kind = 'B4' AND LOWER(ist.stage_name) LIKE '%work%') OR + (d.drawing_kind = 'B3' AND LOWER(ist.stage_name) LIKE '%work%') OR + (d.drawing_kind = 'B5' AND LOWER(ist.stage_name) LIKE '%second%') + ORDER BY ist.document_id, ist.stage_order ASC + ), + -- 첨부파일 수 집계 + attachment_counts AS ( + SELECT + ist.document_id, + COUNT(da.id) as attachment_count + FROM issue_stages ist + LEFT JOIN revisions r ON ist.id = r.issue_stage_id + LEFT JOIN document_attachments da ON r.id = da.revision_id + GROUP BY ist.document_id + ) + + SELECT + d.id as document_id, + d.doc_number, + d.drawing_kind, + d.vendor_doc_number, + d.title, + d.pic, + d.status, + d.issued_date, + d.contract_id, + + -- B4 전용 필드들 + d.c_gbn, + d.d_gbn, + d.degree_gbn, + d.dept_gbn, + d.s_gbn, + d.j_gbn, + + -- 프로젝트 및 벤더 정보 + p.code as project_code, + v.vendor_name as vendor_name, + v.vendor_code as vendor_code, + + -- 첫 번째 스테이지 정보 + fsi.first_stage_id, + fsi.first_stage_name, + fsi.first_stage_plan_date, + fsi.first_stage_actual_date, + + -- 두 번째 스테이지 정보 + ssi.second_stage_id, + ssi.second_stage_name, + ssi.second_stage_plan_date, + ssi.second_stage_actual_date, + + -- 전체 스테이지 (리비전 및 첨부파일 포함) + COALESCE(sa.all_stages, '[]'::json) as all_stages, + + -- 기타 + COALESCE(ac.attachment_count, 0) as attachment_count, + d.created_at, + d.updated_at + + FROM documents d + -- contracts, projects, vendors 테이블 JOIN + LEFT JOIN contracts c ON d.contract_id = c.id + LEFT JOIN projects p ON c.project_id = p.id + LEFT JOIN vendors v ON c.vendor_id = v.id + + -- 스테이지 정보 JOIN + LEFT JOIN first_stage_info fsi ON d.id = fsi.document_id + LEFT JOIN second_stage_info ssi ON d.id = ssi.document_id + LEFT JOIN stage_aggregation sa ON d.id = sa.document_id + LEFT JOIN attachment_counts ac ON d.id = ac.document_id + + ORDER BY d.created_at DESC +`); + +// 타입 추출 +export type SimplifiedDocumentsView = typeof simplifiedDocumentsView.$inferSelect diff --git a/lib/b-rfq/attachment/add-attachment-dialog.tsx b/lib/b-rfq/attachment/add-attachment-dialog.tsx new file mode 100644 index 00000000..665e0f88 --- /dev/null +++ b/lib/b-rfq/attachment/add-attachment-dialog.tsx @@ -0,0 +1,355 @@ +"use client" + +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import { z } from "zod" +import { Plus ,X} from "lucide-react" +import { toast } from "sonner" + +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { + Dropzone, + DropzoneDescription, + DropzoneInput, + DropzoneTitle, + DropzoneUploadIcon, + DropzoneZone, +} from "@/components/ui/dropzone" +import { + FileList, + FileListAction, + FileListDescription, + FileListHeader, + FileListIcon, + FileListInfo, + FileListItem, + FileListName, + FileListSize, +} from "@/components/ui/file-list" +import { Button } from "@/components/ui/button" +import { Textarea } from "@/components/ui/textarea" +import { addRfqAttachmentRecord } from "../service" + +// 첨부파일 추가 폼 스키마 (단일 파일) +const addAttachmentSchema = z.object({ + attachmentType: z.enum(["구매", "설계"], { + required_error: "문서 타입을 선택해주세요.", + }), + description: z.string().optional(), + file: z.instanceof(File, { + message: "파일을 선택해주세요.", + }), +}) + +type AddAttachmentFormData = z.infer<typeof addAttachmentSchema> + +interface AddAttachmentDialogProps { + rfqId: number +} + +export function AddAttachmentDialog({ rfqId }: AddAttachmentDialogProps) { + const [open, setOpen] = React.useState(false) + const [isSubmitting, setIsSubmitting] = React.useState(false) + const [uploadProgress, setUploadProgress] = React.useState<number>(0) + + const form = useForm<AddAttachmentFormData>({ + resolver: zodResolver(addAttachmentSchema), + defaultValues: { + attachmentType: undefined, + description: "", + file: undefined, + }, + }) + + const selectedFile = form.watch("file") + + // 다이얼로그 닫기 핸들러 + const handleOpenChange = (newOpen: boolean) => { + if (!newOpen && !isSubmitting) { + form.reset() + } + setOpen(newOpen) + } + + // 파일 선택 처리 + const handleFileChange = (files: File[]) => { + if (files.length === 0) return + + const file = files[0] // 첫 번째 파일만 사용 + + // 파일 크기 검증 + const maxFileSize = 10 * 1024 * 1024 // 10MB + if (file.size > maxFileSize) { + toast.error(`파일이 너무 큽니다. (최대 10MB)`) + return + } + + form.setValue("file", file) + form.clearErrors("file") + } + + // 파일 제거 + const removeFile = () => { + form.resetField("file") + } + + // 파일 업로드 API 호출 + const uploadFile = async (file: File): Promise<{ + fileName: string + originalFileName: string + filePath: string + fileSize: number + fileType: string + }> => { + const formData = new FormData() + formData.append("rfqId", rfqId.toString()) + formData.append("file", file) + + const response = await fetch("/api/upload/rfq-attachment", { + method: "POST", + body: formData, + }) + + if (!response.ok) { + const error = await response.json() + throw new Error(error.message || "파일 업로드 실패") + } + + return response.json() + } + + // 폼 제출 + const onSubmit = async (data: AddAttachmentFormData) => { + setIsSubmitting(true) + setUploadProgress(0) + + try { + // 1단계: 파일 업로드 + setUploadProgress(30) + const uploadedFile = await uploadFile(data.file) + + // 2단계: DB 레코드 생성 (시리얼 번호 자동 생성) + setUploadProgress(70) + const attachmentRecord = { + rfqId, + attachmentType: data.attachmentType, + description: data.description, + fileName: uploadedFile.fileName, + originalFileName: uploadedFile.originalFileName, + filePath: uploadedFile.filePath, + fileSize: uploadedFile.fileSize, + fileType: uploadedFile.fileType, + } + + const result = await addRfqAttachmentRecord(attachmentRecord) + + setUploadProgress(100) + + if (result.success) { + toast.success(result.message) + form.reset() + handleOpenChange(false) + } else { + toast.error(result.message) + } + + } catch (error) { + console.error("Upload error:", error) + toast.error(error instanceof Error ? error.message : "파일 업로드 중 오류가 발생했습니다.") + } finally { + setIsSubmitting(false) + setUploadProgress(0) + } + } + + return ( + <Dialog open={open} onOpenChange={handleOpenChange}> + <DialogTrigger asChild> + <Button variant="outline" size="sm" className="gap-2"> + <Plus className="size-4" aria-hidden="true" /> + <span className="hidden sm:inline">새 첨부</span> + </Button> + </DialogTrigger> + + <DialogContent className="sm:max-w-[500px]"> + <DialogHeader> + <DialogTitle>새 첨부파일 추가</DialogTitle> + <DialogDescription> + RFQ에 첨부할 문서를 업로드합니다. 시리얼 번호는 자동으로 부여됩니다. + </DialogDescription> + </DialogHeader> + + <Form {...form}> + <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> + {/* 문서 타입 선택 */} + <FormField + control={form.control} + name="attachmentType" + render={({ field }) => ( + <FormItem> + <FormLabel>문서 타입</FormLabel> + <Select onValueChange={field.onChange} value={field.value}> + <FormControl> + <SelectTrigger> + <SelectValue placeholder="문서 타입을 선택하세요" /> + </SelectTrigger> + </FormControl> + <SelectContent> + <SelectItem value="구매">구매</SelectItem> + <SelectItem value="설계">설계</SelectItem> + </SelectContent> + </Select> + <FormMessage /> + </FormItem> + )} + /> + + {/* 설명 */} + <FormField + control={form.control} + name="description" + render={({ field }) => ( + <FormItem> + <FormLabel>설명 (선택)</FormLabel> + <FormControl> + <Textarea + placeholder="첨부파일에 대한 설명을 입력하세요" + className="resize-none" + rows={3} + {...field} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 파일 선택 - Dropzone (단일 파일) */} + <FormField + control={form.control} + name="file" + render={({ field }) => ( + <FormItem> + <FormLabel>파일 선택</FormLabel> + <FormControl> + <div className="space-y-3"> + <Dropzone + onDrop={(acceptedFiles) => { + handleFileChange(acceptedFiles) + }} + accept={{ + 'application/pdf': ['.pdf'], + 'application/msword': ['.doc'], + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': ['.docx'], + 'application/vnd.ms-excel': ['.xls'], + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': ['.xlsx'], + 'application/vnd.ms-powerpoint': ['.ppt'], + 'application/vnd.openxmlformats-officedocument.presentationml.presentation': ['.pptx'], + 'application/zip': ['.zip'], + 'application/x-rar-compressed': ['.rar'] + }} + maxSize={10 * 1024 * 1024} // 10MB + multiple={false} // 단일 파일만 + disabled={isSubmitting} + > + <DropzoneZone> + <DropzoneUploadIcon /> + <DropzoneTitle>클릭하여 파일 선택 또는 드래그 앤 드롭</DropzoneTitle> + <DropzoneDescription> + PDF, DOC, XLS, PPT 등 (최대 10MB, 파일 1개) + </DropzoneDescription> + <DropzoneInput /> + </DropzoneZone> + </Dropzone> + + {/* 선택된 파일 표시 */} + {selectedFile && ( + <div className="space-y-2"> + <FileListHeader> + 선택된 파일 + </FileListHeader> + <FileList> + <FileListItem className="flex items-center justify-between gap-3"> + <FileListIcon /> + <FileListInfo> + <FileListName>{selectedFile.name}</FileListName> + <FileListDescription> + <FileListSize>{selectedFile.size}</FileListSize> + </FileListDescription> + </FileListInfo> + <FileListAction + onClick={removeFile} + disabled={isSubmitting} + > + <X className="h-4 w-4" /> + </FileListAction> + </FileListItem> + </FileList> + </div> + )} + + {/* 업로드 진행률 */} + {isSubmitting && uploadProgress > 0 && ( + <div className="space-y-2"> + <div className="flex justify-between text-sm"> + <span>업로드 진행률</span> + <span>{uploadProgress}%</span> + </div> + <div className="w-full bg-gray-200 rounded-full h-2"> + <div + className="bg-blue-600 h-2 rounded-full transition-all duration-300" + style={{ width: `${uploadProgress}%` }} + /> + </div> + </div> + )} + </div> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <DialogFooter> + <Button + type="button" + variant="outline" + onClick={() => handleOpenChange(false)} + disabled={isSubmitting} + > + 취소 + </Button> + <Button type="submit" disabled={isSubmitting || !selectedFile}> + {isSubmitting ? "업로드 중..." : "업로드"} + </Button> + </DialogFooter> + </form> + </Form> + </DialogContent> + </Dialog> + ) +}
\ No newline at end of file diff --git a/lib/b-rfq/attachment/add-revision-dialog.tsx b/lib/b-rfq/attachment/add-revision-dialog.tsx new file mode 100644 index 00000000..1abefb02 --- /dev/null +++ b/lib/b-rfq/attachment/add-revision-dialog.tsx @@ -0,0 +1,336 @@ +"use client" + +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import { z } from "zod" +import { Upload } from "lucide-react" +import { toast } from "sonner" + +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Dropzone, + DropzoneDescription, + DropzoneInput, + DropzoneTitle, + DropzoneUploadIcon, + DropzoneZone, +} from "@/components/ui/dropzone" +import { + FileList, + FileListAction, + FileListDescription, + FileListHeader, + FileListIcon, + FileListInfo, + FileListItem, + FileListName, + FileListSize, +} from "@/components/ui/file-list" +import { Button } from "@/components/ui/button" +import { Textarea } from "@/components/ui/textarea" +import { addRevisionToAttachment } from "../service" + +// 리비전 추가 폼 스키마 +const addRevisionSchema = z.object({ + revisionComment: z.string().optional(), + file: z.instanceof(File, { + message: "파일을 선택해주세요.", + }), +}) + +type AddRevisionFormData = z.infer<typeof addRevisionSchema> + +interface AddRevisionDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + attachmentId: number + currentRevision: string + originalFileName: string + onSuccess?: () => void +} + +export function AddRevisionDialog({ + open, + onOpenChange, + attachmentId, + currentRevision, + originalFileName, + onSuccess +}: AddRevisionDialogProps) { + const [isSubmitting, setIsSubmitting] = React.useState(false) + const [uploadProgress, setUploadProgress] = React.useState<number>(0) + + const form = useForm<AddRevisionFormData>({ + resolver: zodResolver(addRevisionSchema), + defaultValues: { + revisionComment: "", + file: undefined, + }, + }) + + const selectedFile = form.watch("file") + + // 다이얼로그 닫기 핸들러 + const handleOpenChange = (newOpen: boolean) => { + if (!newOpen && !isSubmitting) { + form.reset() + } + onOpenChange(newOpen) + } + + // 파일 선택 처리 + const handleFileChange = (files: File[]) => { + if (files.length === 0) return + + const file = files[0] + + // 파일 크기 검증 + const maxFileSize = 10 * 1024 * 1024 // 10MB + if (file.size > maxFileSize) { + toast.error(`파일이 너무 큽니다. (최대 10MB)`) + return + } + + form.setValue("file", file) + form.clearErrors("file") + } + + // 파일 제거 + const removeFile = () => { + form.resetField("file") + } + + // 파일 업로드 API 호출 + const uploadFile = async (file: File): Promise<{ + fileName: string + originalFileName: string + filePath: string + fileSize: number + fileType: string + }> => { + const formData = new FormData() + formData.append("attachmentId", attachmentId.toString()) + formData.append("file", file) + formData.append("isRevision", "true") + + const response = await fetch("/api/upload/rfq-attachment-revision", { + method: "POST", + body: formData, + }) + + if (!response.ok) { + const error = await response.json() + throw new Error(error.message || "파일 업로드 실패") + } + + return response.json() + } + + // 폼 제출 + const onSubmit = async (data: AddRevisionFormData) => { + setIsSubmitting(true) + setUploadProgress(0) + + try { + // 1단계: 파일 업로드 + setUploadProgress(30) + const uploadedFile = await uploadFile(data.file) + + // 2단계: DB 리비전 레코드 생성 + setUploadProgress(70) + const result = await addRevisionToAttachment(attachmentId, { + fileName: uploadedFile.fileName, + originalFileName: uploadedFile.originalFileName, + filePath: uploadedFile.filePath, + fileSize: uploadedFile.fileSize, + fileType: uploadedFile.fileType, + revisionComment: data.revisionComment, + }) + + setUploadProgress(100) + + if (result.success) { + toast.success(result.message) + form.reset() + handleOpenChange(false) + onSuccess?.() + } else { + toast.error(result.message) + } + + } catch (error) { + console.error("Upload error:", error) + toast.error(error instanceof Error ? error.message : "리비전 추가 중 오류가 발생했습니다.") + } finally { + setIsSubmitting(false) + setUploadProgress(0) + } + } + + // 다음 리비전 번호 계산 + const getNextRevision = (current: string) => { + const match = current.match(/Rev\.(\d+)/) + if (match) { + const num = parseInt(match[1]) + 1 + return `Rev.${num}` + } + return "Rev.1" + } + + const nextRevision = getNextRevision(currentRevision) + + return ( + <Dialog open={open} onOpenChange={handleOpenChange}> + <DialogContent className="sm:max-w-[500px]"> + <DialogHeader> + <DialogTitle className="flex items-center gap-2"> + <Upload className="h-5 w-5" /> + 새 리비전 추가 + </DialogTitle> + <DialogDescription> + "{originalFileName}"의 새 버전을 업로드합니다. + 현재 {currentRevision} → {nextRevision} + </DialogDescription> + </DialogHeader> + + <Form {...form}> + <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> + {/* 리비전 코멘트 */} + <FormField + control={form.control} + name="revisionComment" + render={({ field }) => ( + <FormItem> + <FormLabel>리비전 코멘트 (선택)</FormLabel> + <FormControl> + <Textarea + placeholder={`${nextRevision} 업데이트 내용을 입력하세요`} + className="resize-none" + rows={3} + {...field} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 파일 선택 - Dropzone (단일 파일) */} + <FormField + control={form.control} + name="file" + render={({ field }) => ( + <FormItem> + <FormLabel>새 파일 선택</FormLabel> + <FormControl> + <div className="space-y-3"> + <Dropzone + onDrop={(acceptedFiles) => { + handleFileChange(acceptedFiles) + }} + accept={{ + 'application/pdf': ['.pdf'], + 'application/msword': ['.doc'], + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': ['.docx'], + 'application/vnd.ms-excel': ['.xls'], + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': ['.xlsx'], + 'application/vnd.ms-powerpoint': ['.ppt'], + 'application/vnd.openxmlformats-officedocument.presentationml.presentation': ['.pptx'], + 'application/zip': ['.zip'], + 'application/x-rar-compressed': ['.rar'] + }} + maxSize={10 * 1024 * 1024} // 10MB + multiple={false} + disabled={isSubmitting} + > + <DropzoneZone> + <DropzoneUploadIcon /> + <DropzoneTitle>클릭하여 파일 선택 또는 드래그 앤 드롭</DropzoneTitle> + <DropzoneDescription> + PDF, DOC, XLS, PPT 등 (최대 10MB, 파일 1개) + </DropzoneDescription> + <DropzoneInput /> + </DropzoneZone> + </Dropzone> + + {/* 선택된 파일 표시 */} + {selectedFile && ( + <div className="space-y-2"> + <FileListHeader> + 선택된 파일 ({nextRevision}) + </FileListHeader> + <FileList> + <FileListItem> + <FileListIcon /> + <FileListInfo> + <FileListName>{selectedFile.name}</FileListName> + <FileListDescription> + <FileListSize>{selectedFile.size}</FileListSize> + </FileListDescription> + </FileListInfo> + <FileListAction + onClick={removeFile} + disabled={isSubmitting} + /> + </FileListItem> + </FileList> + </div> + )} + + {/* 업로드 진행률 */} + {isSubmitting && uploadProgress > 0 && ( + <div className="space-y-2"> + <div className="flex justify-between text-sm"> + <span>업로드 진행률</span> + <span>{uploadProgress}%</span> + </div> + <div className="w-full bg-gray-200 rounded-full h-2"> + <div + className="bg-blue-600 h-2 rounded-full transition-all duration-300" + style={{ width: `${uploadProgress}%` }} + /> + </div> + </div> + )} + </div> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <DialogFooter> + <Button + type="button" + variant="outline" + onClick={() => handleOpenChange(false)} + disabled={isSubmitting} + > + 취소 + </Button> + <Button type="submit" disabled={isSubmitting || !selectedFile}> + {isSubmitting ? "업로드 중..." : `${nextRevision} 추가`} + </Button> + </DialogFooter> + </form> + </Form> + </DialogContent> + </Dialog> + ) +}
\ No newline at end of file diff --git a/lib/b-rfq/attachment/attachment-columns.tsx b/lib/b-rfq/attachment/attachment-columns.tsx new file mode 100644 index 00000000..c611e06c --- /dev/null +++ b/lib/b-rfq/attachment/attachment-columns.tsx @@ -0,0 +1,290 @@ +"use client" + +import * as React from "react" +import { type ColumnDef } from "@tanstack/react-table" +import { + Ellipsis, FileText, Download, Eye, + MessageSquare, Upload +} from "lucide-react" + +import { formatDate, formatBytes } from "@/lib/utils" +import { Badge } from "@/components/ui/badge" +import { Button } from "@/components/ui/button" +import { Checkbox } from "@/components/ui/checkbox" +import { + DropdownMenu, DropdownMenuContent, DropdownMenuItem, + DropdownMenuSeparator, DropdownMenuTrigger +} from "@/components/ui/dropdown-menu" +import { Progress } from "@/components/ui/progress" +import { RevisionDialog } from "./revision-dialog" +import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" +import { AddRevisionDialog } from "./add-revision-dialog" + +interface GetAttachmentColumnsProps { + onSelectAttachment: (attachment: any) => void +} + +export function getAttachmentColumns({ + onSelectAttachment +}: GetAttachmentColumnsProps): ColumnDef<any>[] { + + return [ + /** ───────────── 체크박스 ───────────── */ + { + id: "select", + header: ({ table }) => ( + <Checkbox + checked={ + table.getIsAllPageRowsSelected() || + (table.getIsSomePageRowsSelected() && "indeterminate") + } + onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)} + aria-label="Select all" + className="translate-y-0.5" + /> + ), + cell: ({ row }) => ( + <Checkbox + checked={row.getIsSelected()} + onCheckedChange={(value) => row.toggleSelected(!!value)} + aria-label="Select row" + className="translate-y-0.5" + /> + ), + size: 40, + enableSorting: false, + enableHiding: false, + }, + + /** ───────────── 문서 정보 ───────────── */ + { + accessorKey: "serialNo", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="시리얼 번호" /> + ), + cell: ({ row }) => ( + <Button + variant="link" + className="p-0 h-auto font-medium text-blue-600 hover:text-blue-800" + onClick={() => onSelectAttachment(row.original)} + > + {row.getValue("serialNo") as string} + </Button> + ), + size: 100, + }, + { + accessorKey: "attachmentType", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="문서 타입" /> + ), + cell: ({ row }) => { + const type = row.getValue("attachmentType") as string + return ( + <Badge variant={type === "구매" ? "default" : "secondary"}> + {type} + </Badge> + ) + }, + size:100 + }, + { + accessorKey: "originalFileName", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="파일명" /> + ), + cell: ({ row }) => { + const fileName = row.getValue("originalFileName") as string + return ( + <div className="flex items-center gap-2"> + <FileText className="h-4 w-4 text-muted-foreground" /> + <div className="min-w-0 flex-1"> + <div className="truncate font-medium" title={fileName}> + {fileName} + </div> + </div> + </div> + ) + }, + size:250 + }, + { + id: "currentRevision", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="리비전" /> + ), + cell: ({ row }) => ( + <RevisionDialog + attachmentId={row.original.id} + currentRevision={row.original.currentRevision} + originalFileName={row.original.originalFileName} + /> + ), + size: 100, + }, + { + accessorKey: "description", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="설명" /> + ), + cell: ({ row }) => { + const description = row.getValue("description") as string + return description + ? <div className="max-w-[200px] truncate" title={description}>{description}</div> + : <span className="text-muted-foreground">-</span> + }, + }, + + /** ───────────── 파일 정보 ───────────── */ + // { + // accessorKey: "fileSize", + // header: ({ column }) => ( + // <DataTableColumnHeaderSimple column={column} title="파일 크기" /> + // ), + // cell: ({ row }) => { + // const size = row.getValue("fileSize") as number + // return size ? formatBytes(size) : "-" + // }, + // }, + { + accessorKey: "createdAt", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="등록일" /> + ), + cell: ({ row }) => { + const created = row.getValue("createdAt") as Date + const updated = row.original.updatedAt as Date + return ( + <div> + <div>{formatDate(created)}</div> + <div className="text-xs text-muted-foreground"> + {row.original.createdByName} + </div> + {updated && new Date(updated) > new Date(created) && ( + <div className="text-xs text-blue-600"> + 수정: {formatDate(updated)} + </div> + )} + </div> + ) + }, + maxSize:150 + }, + + /** ───────────── 벤더 응답 현황 ───────────── */ + { + id: "vendorCount", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="벤더 수" /> + ), + cell: ({ row }) => { + const stats = row.original.responseStats + return stats + ? ( + <div className="text-center"> + <div className="font-medium">{stats.totalVendors}</div> + <div className="text-xs text-muted-foreground"> + 활성: {stats.totalVendors - stats.waivedCount} + </div> + </div> + ) + : <span className="text-muted-foreground">-</span> + }, + }, + { + id: "responseStatus", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="응답 현황" /> + ), + cell: ({ row }) => { + const stats = row.original.responseStats + return stats + ? ( + <div className="space-y-1"> + <div className="flex items-center gap-2"> + <div className="flex-1"> + <Progress value={stats.responseRate} className="h-2" /> + </div> + <span className="text-sm font-medium"> + {stats.responseRate}% + </span> + </div> + <div className="flex gap-2 text-xs"> + <span className="text-green-600"> + 응답: {stats.respondedCount} + </span> + <span className="text-orange-600"> + 대기: {stats.pendingCount} + </span> + {stats.waivedCount > 0 && ( + <span className="text-gray-500"> + 면제: {stats.waivedCount} + </span> + )} + </div> + </div> + ) + : <span className="text-muted-foreground">-</span> + }, + }, + + /** ───────────── 액션 ───────────── */ + { + id: "actions", + enableHiding: false, + cell: ({ row }) => { + const [isAddRevisionOpen, setIsAddRevisionOpen] = React.useState(false) + + return ( + <> + <DropdownMenu> + <DropdownMenuTrigger asChild> + <Button + aria-label="Open menu" + variant="ghost" + className="flex size-8 p-0 data-[state=open]:bg-muted" + > + <Ellipsis className="size-4" aria-hidden="true" /> + </Button> + </DropdownMenuTrigger> + <DropdownMenuContent align="end" className="w-48"> + <DropdownMenuItem onClick={() => onSelectAttachment(row.original)}> + <MessageSquare className="mr-2 h-4 w-4" /> + 벤더 응답 보기 + </DropdownMenuItem> + <DropdownMenuItem> + <Eye className="mr-2 h-4 w-4" /> + 미리보기 + </DropdownMenuItem> + <DropdownMenuItem + onClick={() => row.original.filePath && window.open(row.original.filePath, "_blank")} + > + <Download className="mr-2 h-4 w-4" /> + 다운로드 + </DropdownMenuItem> + <DropdownMenuSeparator /> + <DropdownMenuItem onClick={() => setIsAddRevisionOpen(true)}> + <Upload className="mr-2 h-4 w-4" /> + 새 리비전 추가 + </DropdownMenuItem> + <DropdownMenuItem className="text-red-600"> + 삭제 + </DropdownMenuItem> + </DropdownMenuContent> + </DropdownMenu> + + <AddRevisionDialog + open={isAddRevisionOpen} + onOpenChange={setIsAddRevisionOpen} + attachmentId={row.original.id} + currentRevision={row.original.currentRevision} + originalFileName={row.original.originalFileName} + onSuccess={() => window.location.reload()} + /> + </> + ) + }, + size: 40, + }, + ] +} diff --git a/lib/b-rfq/attachment/attachment-table.tsx b/lib/b-rfq/attachment/attachment-table.tsx new file mode 100644 index 00000000..4c547000 --- /dev/null +++ b/lib/b-rfq/attachment/attachment-table.tsx @@ -0,0 +1,190 @@ +"use client" + +import * as React from "react" +import { type DataTableAdvancedFilterField, type DataTableFilterField } from "@/types/table" +import { useDataTable } from "@/hooks/use-data-table" +import { DataTable } from "@/components/data-table/data-table" +import { DataTableAdvancedToolbar } from "@/components/data-table/data-table-advanced-toolbar" +import { VendorResponsesPanel } from "./vendor-responses-panel" +import { Separator } from "@/components/ui/separator" +import { FileText } from "lucide-react" +import { getRfqAttachments, getVendorResponsesForAttachment } from "../service" +import { getAttachmentColumns } from "./attachment-columns" +import { RfqAttachmentsTableToolbarActions } from "./attachment-toolbar-action" + +interface RfqAttachmentsTableProps { + promises: Promise<Awaited<ReturnType<typeof getRfqAttachments>>> + rfqId: number +} + +export function RfqAttachmentsTable({ promises, rfqId }: RfqAttachmentsTableProps) { + const { data, pageCount } = React.use(promises) + + // 선택된 첨부파일과 벤더 응답 데이터 + const [selectedAttachment, setSelectedAttachment] = React.useState<any>(null) + const [vendorResponses, setVendorResponses] = React.useState<any[]>([]) + const [isLoadingResponses, setIsLoadingResponses] = React.useState(false) + + const columns = React.useMemo( + () => getAttachmentColumns({ + onSelectAttachment: setSelectedAttachment + }), + [] + ) + + // 첨부파일 선택 시 벤더 응답 데이터 로드 + React.useEffect(() => { + if (!selectedAttachment) { + setVendorResponses([]) + return + } + + const loadVendorResponses = async () => { + setIsLoadingResponses(true) + try { + const responses = await getVendorResponsesForAttachment( + selectedAttachment.id, + 'INITIAL' // 또는 현재 RFQ 상태에 따라 결정 + ) + setVendorResponses(responses) + } catch (error) { + console.error('Failed to load vendor responses:', error) + setVendorResponses([]) + } finally { + setIsLoadingResponses(false) + } + } + + loadVendorResponses() + }, [selectedAttachment]) + + /** + * 필터 필드 정의 + */ + const filterFields: DataTableFilterField<any>[] = [ + { + id: "fileName", + label: "파일명", + placeholder: "파일명으로 검색...", + }, + { + id: "attachmentType", + label: "문서 타입", + options: [ + { label: "구매 문서", value: "구매", count: 0 }, + { label: "설계 문서", value: "설계", count: 0 }, + ], + }, + { + id: "fileType", + label: "파일 형식", + options: [ + { label: "PDF", value: "pdf", count: 0 }, + { label: "Excel", value: "xlsx", count: 0 }, + { label: "Word", value: "docx", count: 0 }, + { label: "기타", value: "기타", count: 0 }, + ], + }, + ] + + /** + * 고급 필터 필드 + */ + const advancedFilterFields: DataTableAdvancedFilterField<any>[] = [ + { + id: "fileName", + label: "파일명", + type: "text", + }, + { + id: "originalFileName", + label: "원본 파일명", + type: "text", + }, + { + id: "serialNo", + label: "시리얼 번호", + type: "text", + }, + { + id: "description", + label: "설명", + type: "text", + }, + { + id: "attachmentType", + label: "문서 타입", + type: "multi-select", + options: [ + { label: "구매 문서", value: "구매" }, + { label: "설계 문서", value: "설계" }, + ], + }, + { + id: "fileType", + label: "파일 형식", + type: "multi-select", + options: [ + { label: "PDF", value: "pdf" }, + { label: "Excel", value: "xlsx" }, + { label: "Word", value: "docx" }, + { label: "기타", value: "기타" }, + ], + }, + { + id: "createdAt", + label: "등록일", + type: "date", + }, + ] + + const { table } = useDataTable({ + data, + columns, + pageCount, + filterFields, + enableAdvancedFilter: true, + initialState: { + sorting: [{ id: "createdAt", desc: true }], + columnPinning: { right: ["actions"] }, + }, + getRowId: (originalRow) => originalRow.id.toString(), + shallow: false, + clearOnDefault: true, + }) + + return ( + <div className="space-y-6"> + {/* 메인 테이블 */} + <div className="h-full w-full"> + <DataTable table={table} className="h-full"> + <DataTableAdvancedToolbar + table={table} + filterFields={advancedFilterFields} + shallow={false} + > + <RfqAttachmentsTableToolbarActions table={table} rfqId={rfqId} /> + </DataTableAdvancedToolbar> + </DataTable> + </div> + + {/* 벤더 응답 현황 패널 */} + {selectedAttachment && ( + <> + <Separator /> + <VendorResponsesPanel + attachment={selectedAttachment} + responses={vendorResponses} + isLoading={isLoadingResponses} + onRefresh={() => { + // 새로고침 로직 + if (selectedAttachment) { + setSelectedAttachment({ ...selectedAttachment }) + } + }} + /> + </> + )} + </div> + ) +}
\ No newline at end of file diff --git a/lib/b-rfq/attachment/attachment-toolbar-action.tsx b/lib/b-rfq/attachment/attachment-toolbar-action.tsx new file mode 100644 index 00000000..e078ea66 --- /dev/null +++ b/lib/b-rfq/attachment/attachment-toolbar-action.tsx @@ -0,0 +1,60 @@ +"use client" + +import * as React from "react" +import { type Table } from "@tanstack/react-table" + +import { AddAttachmentDialog } from "./add-attachment-dialog" +import { ConfirmDocumentsDialog } from "./confirm-documents-dialog" +import { TbeRequestDialog } from "./tbe-request-dialog" +import { DeleteAttachmentsDialog } from "./delete-attachment-dialog" + +interface RfqAttachmentsTableToolbarActionsProps { + table: Table<any> + rfqId: number +} + +export function RfqAttachmentsTableToolbarActions({ + table, + rfqId +}: RfqAttachmentsTableToolbarActionsProps) { + + // 선택된 행들 가져오기 + const selectedRows = table.getFilteredSelectedRowModel().rows + const selectedAttachments = selectedRows.map((row) => row.original) + const selectedCount = selectedRows.length + + return ( + <div className="flex items-center gap-2"> + {/** 선택된 로우가 있으면 삭제 다이얼로그 */} + {selectedCount > 0 && ( + <DeleteAttachmentsDialog + attachments={selectedAttachments} + onSuccess={() => table.toggleAllRowsSelected(false)} + /> + )} + + {/** 새 첨부 추가 다이얼로그 */} + <AddAttachmentDialog rfqId={rfqId} /> + + {/** 문서 확정 다이얼로그 */} + <ConfirmDocumentsDialog + rfqId={rfqId} + onSuccess={() => { + // 성공 후 필요한 작업 (예: 페이지 새로고침) + window.location.reload() + }} + /> + + {/** TBE 요청 다이얼로그 (선택된 행이 있을 때만 활성화) */} + <TbeRequestDialog + rfqId={rfqId} + attachments={selectedAttachments} + onSuccess={() => { + // 선택 해제 및 페이지 새로고침 + table.toggleAllRowsSelected(false) + window.location.reload() + }} + /> + </div> + ) +}
\ No newline at end of file diff --git a/lib/b-rfq/attachment/confirm-documents-dialog.tsx b/lib/b-rfq/attachment/confirm-documents-dialog.tsx new file mode 100644 index 00000000..fccb4123 --- /dev/null +++ b/lib/b-rfq/attachment/confirm-documents-dialog.tsx @@ -0,0 +1,141 @@ +"use client" + +import * as React from "react" +import { Loader, FileCheck } from "lucide-react" +import { toast } from "sonner" + +import { useMediaQuery } from "@/hooks/use-media-query" +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { + Drawer, + DrawerClose, + DrawerContent, + DrawerDescription, + DrawerFooter, + DrawerHeader, + DrawerTitle, + DrawerTrigger, +} from "@/components/ui/drawer" + +import { confirmDocuments } from "../service" + +interface ConfirmDocumentsDialogProps + extends React.ComponentPropsWithoutRef<typeof Dialog> { + rfqId: number + showTrigger?: boolean + onSuccess?: () => void +} + +export function ConfirmDocumentsDialog({ + rfqId, + showTrigger = true, + onSuccess, + ...props +}: ConfirmDocumentsDialogProps) { + const [isConfirmPending, startConfirmTransition] = React.useTransition() + const isDesktop = useMediaQuery("(min-width: 640px)") + + function onConfirm() { + startConfirmTransition(async () => { + const result = await confirmDocuments(rfqId) + + if (!result.success) { + toast.error(result.message) + return + } + + props.onOpenChange?.(false) + toast.success(result.message) + onSuccess?.() + }) + } + + if (isDesktop) { + return ( + <Dialog {...props}> + {showTrigger ? ( + <DialogTrigger asChild> + <Button variant="outline" size="sm" className="gap-2"> + <FileCheck className="size-4" aria-hidden="true" /> + <span className="hidden sm:inline">문서 확정</span> + </Button> + </DialogTrigger> + ) : null} + <DialogContent> + <DialogHeader> + <DialogTitle>문서를 확정하시겠습니까?</DialogTitle> + <DialogDescription> + 이 작업은 RFQ의 모든 첨부문서를 확정하고 상태를 "Doc. Confirmed"로 변경합니다. + 확정 후에는 문서 수정이 제한될 수 있습니다. + </DialogDescription> + </DialogHeader> + <DialogFooter className="gap-2 sm:space-x-0"> + <DialogClose asChild> + <Button variant="outline">취소</Button> + </DialogClose> + <Button + aria-label="Confirm documents" + onClick={onConfirm} + disabled={isConfirmPending} + > + {isConfirmPending && ( + <Loader + className="mr-2 size-4 animate-spin" + aria-hidden="true" + /> + )} + 문서 확정 + </Button> + </DialogFooter> + </DialogContent> + </Dialog> + ) + } + + return ( + <Drawer {...props}> + {showTrigger ? ( + <DrawerTrigger asChild> + <Button variant="outline" size="sm" className="gap-2"> + <FileCheck className="size-4" aria-hidden="true" /> + <span className="hidden sm:inline">문서 확정</span> + </Button> + </DrawerTrigger> + ) : null} + <DrawerContent> + <DrawerHeader> + <DrawerTitle>문서를 확정하시겠습니까?</DrawerTitle> + <DrawerDescription> + 이 작업은 RFQ의 모든 첨부문서를 확정하고 상태를 "Doc. Confirmed"로 변경합니다. + 확정 후에는 문서 수정이 제한될 수 있습니다. + </DrawerDescription> + </DrawerHeader> + <DrawerFooter className="gap-2 sm:space-x-0"> + <DrawerClose asChild> + <Button variant="outline">취소</Button> + </DrawerClose> + <Button + aria-label="Confirm documents" + onClick={onConfirm} + disabled={isConfirmPending} + > + {isConfirmPending && ( + <Loader className="mr-2 size-4 animate-spin" aria-hidden="true" /> + )} + 문서 확정 + </Button> + </DrawerFooter> + </DrawerContent> + </Drawer> + ) +}
\ No newline at end of file diff --git a/lib/b-rfq/attachment/delete-attachment-dialog.tsx b/lib/b-rfq/attachment/delete-attachment-dialog.tsx new file mode 100644 index 00000000..b5471520 --- /dev/null +++ b/lib/b-rfq/attachment/delete-attachment-dialog.tsx @@ -0,0 +1,182 @@ +"use client" + +import * as React from "react" +import { type Row } from "@tanstack/react-table" +import { Loader, Trash } from "lucide-react" +import { toast } from "sonner" + +import { useMediaQuery } from "@/hooks/use-media-query" +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { + Drawer, + DrawerClose, + DrawerContent, + DrawerDescription, + DrawerFooter, + DrawerHeader, + DrawerTitle, + DrawerTrigger, +} from "@/components/ui/drawer" +import { deleteRfqAttachments } from "../service" + + +// 첨부파일 타입 (실제 타입에 맞게 조정 필요) +type RfqAttachment = { + id: number + serialNo: string + originalFileName: string + attachmentType: string + currentRevision: string +} + +interface DeleteAttachmentsDialogProps + extends React.ComponentPropsWithoutRef<typeof Dialog> { + attachments: Row<RfqAttachment>["original"][] + showTrigger?: boolean + onSuccess?: () => void +} + +export function DeleteAttachmentsDialog({ + attachments, + showTrigger = true, + onSuccess, + ...props +}: DeleteAttachmentsDialogProps) { + const [isDeletePending, startDeleteTransition] = React.useTransition() + const isDesktop = useMediaQuery("(min-width: 640px)") + + function onDelete() { + startDeleteTransition(async () => { + const result = await deleteRfqAttachments({ + ids: attachments.map((attachment) => attachment.id), + }) + + if (!result.success) { + toast.error(result.message) + return + } + + props.onOpenChange?.(false) + toast.success(result.message) + onSuccess?.() + }) + } + + const attachmentText = attachments.length === 1 ? "첨부파일" : "첨부파일들" + const deleteWarning = `선택된 ${attachments.length}개의 ${attachmentText}과 모든 리비전이 영구적으로 삭제됩니다.` + + if (isDesktop) { + return ( + <Dialog {...props}> + {showTrigger ? ( + <DialogTrigger asChild> + <Button variant="outline" size="sm"> + <Trash className="mr-2 size-4" aria-hidden="true" /> + 삭제 ({attachments.length}) + </Button> + </DialogTrigger> + ) : null} + <DialogContent> + <DialogHeader> + <DialogTitle>정말로 삭제하시겠습니까?</DialogTitle> + <DialogDescription className="space-y-2"> + <div>이 작업은 되돌릴 수 없습니다.</div> + <div>{deleteWarning}</div> + {attachments.length <= 3 && ( + <div className="mt-3 p-2 bg-gray-50 rounded-md"> + <div className="font-medium text-sm">삭제될 파일:</div> + <ul className="text-sm text-gray-600 mt-1"> + {attachments.map((attachment) => ( + <li key={attachment.id} className="truncate"> + • {attachment.serialNo}: {attachment.originalFileName} ({attachment.currentRevision}) + </li> + ))} + </ul> + </div> + )} + </DialogDescription> + </DialogHeader> + <DialogFooter className="gap-2 sm:space-x-0"> + <DialogClose asChild> + <Button variant="outline">취소</Button> + </DialogClose> + <Button + aria-label="Delete selected attachments" + variant="destructive" + onClick={onDelete} + disabled={isDeletePending} + > + {isDeletePending && ( + <Loader + className="mr-2 size-4 animate-spin" + aria-hidden="true" + /> + )} + 삭제 + </Button> + </DialogFooter> + </DialogContent> + </Dialog> + ) + } + + return ( + <Drawer {...props}> + {showTrigger ? ( + <DrawerTrigger asChild> + <Button variant="outline" size="sm"> + <Trash className="mr-2 size-4" aria-hidden="true" /> + 삭제 ({attachments.length}) + </Button> + </DrawerTrigger> + ) : null} + <DrawerContent> + <DrawerHeader> + <DrawerTitle>정말로 삭제하시겠습니까?</DrawerTitle> + <DrawerDescription className="space-y-2"> + <div>이 작업은 되돌릴 수 없습니다.</div> + <div>{deleteWarning}</div> + {attachments.length <= 3 && ( + <div className="mt-3 p-2 bg-gray-50 rounded-md"> + <div className="font-medium text-sm">삭제될 파일:</div> + <ul className="text-sm text-gray-600 mt-1"> + {attachments.map((attachment) => ( + <li key={attachment.id} className="truncate"> + • {attachment.serialNo}: {attachment.originalFileName} ({attachment.currentRevision}) + </li> + ))} + </ul> + </div> + )} + </DrawerDescription> + </DrawerHeader> + <DrawerFooter className="gap-2 sm:space-x-0"> + <DrawerClose asChild> + <Button variant="outline">취소</Button> + </DrawerClose> + <Button + aria-label="Delete selected attachments" + variant="destructive" + onClick={onDelete} + disabled={isDeletePending} + > + {isDeletePending && ( + <Loader className="mr-2 size-4 animate-spin" aria-hidden="true" /> + )} + 삭제 + </Button> + </DrawerFooter> + </DrawerContent> + </Drawer> + ) +}
\ No newline at end of file diff --git a/lib/b-rfq/attachment/revision-dialog.tsx b/lib/b-rfq/attachment/revision-dialog.tsx new file mode 100644 index 00000000..b1fe1576 --- /dev/null +++ b/lib/b-rfq/attachment/revision-dialog.tsx @@ -0,0 +1,196 @@ +"use client" + +import * as React from "react" +import { Badge } from "@/components/ui/badge" +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table" +import { History, Download, Upload } from "lucide-react" +import { formatDate, formatBytes } from "@/lib/utils" +import { getAttachmentRevisions } from "../service" +import { AddRevisionDialog } from "./add-revision-dialog" + +interface RevisionDialogProps { + attachmentId: number + currentRevision: string + originalFileName: string +} + +export function RevisionDialog({ + attachmentId, + currentRevision, + originalFileName +}: RevisionDialogProps) { + const [open, setOpen] = React.useState(false) + const [revisions, setRevisions] = React.useState<any[]>([]) + const [isLoading, setIsLoading] = React.useState(false) + const [isAddRevisionOpen, setIsAddRevisionOpen] = React.useState(false) + + // 리비전 목록 로드 + const loadRevisions = async () => { + setIsLoading(true) + try { + const result = await getAttachmentRevisions(attachmentId) + + if (result.success) { + setRevisions(result.revisions) + } else { + console.error("Failed to load revisions:", result.message) + } + } catch (error) { + console.error("Failed to load revisions:", error) + } finally { + setIsLoading(false) + } + } + + React.useEffect(() => { + if (open) { + loadRevisions() + } + }, [open, attachmentId]) + + return ( + <> + <Dialog open={open} onOpenChange={setOpen}> + <DialogTrigger asChild> + <Button variant="ghost" size="sm" className="gap-2"> + <History className="h-4 w-4" /> + {currentRevision} + </Button> + </DialogTrigger> + + <DialogContent className="sm:max-w-[800px]" style={{maxWidth:800}}> + <DialogHeader> + <DialogTitle className="flex items-center gap-2"> + <History className="h-5 w-5" /> + 리비전 히스토리: {originalFileName} + </DialogTitle> + <DialogDescription> + 이 문서의 모든 버전을 확인하고 관리할 수 있습니다. + </DialogDescription> + </DialogHeader> + + <div className="space-y-4"> + {/* 새 리비전 추가 버튼 */} + <div className="flex justify-end"> + <Button + onClick={() => setIsAddRevisionOpen(true)} + className="gap-2" + > + <Upload className="h-4 w-4" /> + 새 리비전 추가 + </Button> + </div> + + {/* 리비전 목록 */} + {isLoading ? ( + <div className="text-center py-8">리비전을 불러오는 중...</div> + ) : ( + <div className="border rounded-lg"> + <Table> + <TableHeader> + <TableRow> + <TableHead>리비전</TableHead> + <TableHead>파일명</TableHead> + <TableHead>크기</TableHead> + <TableHead>업로드 일시</TableHead> + <TableHead>업로드자</TableHead> + <TableHead>코멘트</TableHead> + <TableHead>액션</TableHead> + </TableRow> + </TableHeader> + <TableBody> + {revisions.map((revision) => ( + <TableRow key={revision.id}> + <TableCell> + <div className="flex items-center gap-2"> + <Badge + variant={revision.isLatest ? "default" : "outline"} + > + {revision.revisionNo} + </Badge> + {revision.isLatest && ( + <Badge variant="secondary" className="text-xs"> + 최신 + </Badge> + )} + </div> + </TableCell> + + <TableCell> + <div> + <div className="font-medium">{revision.originalFileName}</div> + </div> + </TableCell> + + <TableCell> + {formatBytes(revision.fileSize)} + </TableCell> + + <TableCell> + {formatDate(revision.createdAt)} + </TableCell> + + <TableCell> + {revision.createdByName || "-"} + </TableCell> + + <TableCell> + <div className="max-w-[200px] truncate" title={revision.revisionComment}> + {revision.revisionComment || "-"} + </div> + </TableCell> + + <TableCell> + <Button + variant="ghost" + size="sm" + className="gap-2" + onClick={() => { + // 파일 다운로드 + window.open(revision.filePath, '_blank') + }} + > + <Download className="h-4 w-4" /> + 다운로드 + </Button> + </TableCell> + </TableRow> + ))} + </TableBody> + </Table> + </div> + )} + </div> + </DialogContent> + </Dialog> + + {/* 새 리비전 추가 다이얼로그 */} + <AddRevisionDialog + open={isAddRevisionOpen} + onOpenChange={setIsAddRevisionOpen} + attachmentId={attachmentId} + currentRevision={currentRevision} + originalFileName={originalFileName} + onSuccess={() => { + loadRevisions() // 리비전 목록 새로고침 + }} + /> + </> + ) + }
\ No newline at end of file diff --git a/lib/b-rfq/attachment/tbe-request-dialog.tsx b/lib/b-rfq/attachment/tbe-request-dialog.tsx new file mode 100644 index 00000000..80b20e6f --- /dev/null +++ b/lib/b-rfq/attachment/tbe-request-dialog.tsx @@ -0,0 +1,200 @@ +"use client" + +import * as React from "react" +import { Loader, Send } from "lucide-react" +import { toast } from "sonner" + +import { useMediaQuery } from "@/hooks/use-media-query" +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { + Drawer, + DrawerClose, + DrawerContent, + DrawerDescription, + DrawerFooter, + DrawerHeader, + DrawerTitle, + DrawerTrigger, +} from "@/components/ui/drawer" + +import { requestTbe } from "../service" + +// 첨부파일 타입 +type RfqAttachment = { + id: number + serialNo: string + originalFileName: string + attachmentType: string + currentRevision: string +} + +interface TbeRequestDialogProps + extends React.ComponentPropsWithoutRef<typeof Dialog> { + rfqId: number + attachments: RfqAttachment[] + showTrigger?: boolean + onSuccess?: () => void +} + +export function TbeRequestDialog({ + rfqId, + attachments, + showTrigger = true, + onSuccess, + ...props +}: TbeRequestDialogProps) { + const [isRequestPending, startRequestTransition] = React.useTransition() + const isDesktop = useMediaQuery("(min-width: 640px)") + + function onRequest() { + startRequestTransition(async () => { + const attachmentIds = attachments.map(attachment => attachment.id) + const result = await requestTbe(rfqId, attachmentIds) + + if (!result.success) { + toast.error(result.message) + return + } + + props.onOpenChange?.(false) + toast.success(result.message) + onSuccess?.() + }) + } + + const attachmentCount = attachments.length + const attachmentText = attachmentCount === 1 ? "문서" : "문서들" + + if (isDesktop) { + return ( + <Dialog {...props}> + {showTrigger ? ( + <DialogTrigger asChild> + <Button + variant="outline" + size="sm" + className="gap-2" + disabled={attachmentCount === 0} + > + <Send className="size-4" aria-hidden="true" /> + <span className="hidden sm:inline"> + TBE 요청 {attachmentCount > 0 && `(${attachmentCount})`} + </span> + </Button> + </DialogTrigger> + ) : null} + <DialogContent> + <DialogHeader> + <DialogTitle>TBE 요청을 전송하시겠습니까?</DialogTitle> + <DialogDescription className="space-y-2"> + <div> + 선택된 <span className="font-medium">{attachmentCount}개</span>의 {attachmentText}에 대해 + 벤더들에게 기술평가(TBE) 요청을 전송합니다. + </div> + <div>RFQ 상태가 "TBE started"로 변경됩니다.</div> + {attachmentCount <= 5 && ( + <div className="mt-3 p-2 bg-gray-50 rounded-md"> + <div className="font-medium text-sm">TBE 요청 대상:</div> + <ul className="text-sm text-gray-600 mt-1"> + {attachments.map((attachment) => ( + <li key={attachment.id} className="truncate"> + • {attachment.serialNo}: {attachment.originalFileName} ({attachment.currentRevision}) + </li> + ))} + </ul> + </div> + )} + </DialogDescription> + </DialogHeader> + <DialogFooter className="gap-2 sm:space-x-0"> + <DialogClose asChild> + <Button variant="outline">취소</Button> + </DialogClose> + <Button + aria-label="Request TBE" + onClick={onRequest} + disabled={isRequestPending} + > + {isRequestPending && ( + <Loader + className="mr-2 size-4 animate-spin" + aria-hidden="true" + /> + )} + TBE 요청 전송 + </Button> + </DialogFooter> + </DialogContent> + </Dialog> + ) + } + + return ( + <Drawer {...props}> + {showTrigger ? ( + <DrawerTrigger asChild> + <Button + variant="outline" + size="sm" + className="gap-2" + disabled={attachmentCount === 0} + > + <Send className="size-4" aria-hidden="true" /> + <span className="hidden sm:inline"> + TBE 요청 {attachmentCount > 0 && `(${attachmentCount})`} + </span> + </Button> + </DrawerTrigger> + ) : null} + <DrawerContent> + <DrawerHeader> + <DrawerTitle>TBE 요청을 전송하시겠습니까?</DrawerTitle> + <DrawerDescription className="space-y-2"> + <div> + 선택된 <span className="font-medium">{attachmentCount}개</span>의 {attachmentText}에 대해 + 벤더들에게 기술평가(TBE) 요청을 전송합니다. + </div> + <div>RFQ 상태가 "TBE started"로 변경됩니다.</div> + {attachmentCount <= 5 && ( + <div className="mt-3 p-2 bg-gray-50 rounded-md"> + <div className="font-medium text-sm">TBE 요청 대상:</div> + <ul className="text-sm text-gray-600 mt-1"> + {attachments.map((attachment) => ( + <li key={attachment.id} className="truncate"> + • {attachment.serialNo}: {attachment.originalFileName} ({attachment.currentRevision}) + </li> + ))} + </ul> + </div> + )} + </DrawerDescription> + </DrawerHeader> + <DrawerFooter className="gap-2 sm:space-x-0"> + <DrawerClose asChild> + <Button variant="outline">취소</Button> + </DrawerClose> + <Button + aria-label="Request TBE" + onClick={onRequest} + disabled={isRequestPending} + > + {isRequestPending && ( + <Loader className="mr-2 size-4 animate-spin" aria-hidden="true" /> + )} + TBE 요청 전송 + </Button> + </DrawerFooter> + </DrawerContent> + </Drawer> + ) +}
\ No newline at end of file diff --git a/lib/b-rfq/attachment/vendor-responses-panel.tsx b/lib/b-rfq/attachment/vendor-responses-panel.tsx new file mode 100644 index 00000000..901af3bf --- /dev/null +++ b/lib/b-rfq/attachment/vendor-responses-panel.tsx @@ -0,0 +1,205 @@ +import { Badge } from "@/components/ui/badge" +import { Button } from "@/components/ui/button" +import { Skeleton } from "@/components/ui/skeleton" +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" +import { RefreshCw, Download, MessageSquare, Clock, CheckCircle2, XCircle, AlertCircle } from "lucide-react" +import { formatDate } from "@/lib/utils" + +interface VendorResponsesPanelProps { + attachment: any + responses: any[] + isLoading: boolean + onRefresh: () => void +} + +export function VendorResponsesPanel({ + attachment, + responses, + isLoading, + onRefresh +}: VendorResponsesPanelProps) { + + const getStatusIcon = (status: string) => { + switch (status) { + case 'RESPONDED': + return <CheckCircle2 className="h-4 w-4 text-green-600" /> + case 'NOT_RESPONDED': + return <Clock className="h-4 w-4 text-orange-600" /> + case 'WAIVED': + return <XCircle className="h-4 w-4 text-gray-500" /> + case 'REVISION_REQUESTED': + return <AlertCircle className="h-4 w-4 text-yellow-600" /> + default: + return <Clock className="h-4 w-4 text-gray-400" /> + } + } + + const getStatusBadgeVariant = (status: string) => { + switch (status) { + case 'RESPONDED': + return 'default' + case 'NOT_RESPONDED': + return 'secondary' + case 'WAIVED': + return 'outline' + case 'REVISION_REQUESTED': + return 'destructive' + default: + return 'secondary' + } + } + + if (isLoading) { + return ( + <div className="space-y-4"> + <div className="flex items-center justify-between"> + <Skeleton className="h-6 w-48" /> + <Skeleton className="h-9 w-24" /> + </div> + <div className="space-y-3"> + {Array.from({ length: 3 }).map((_, i) => ( + <Skeleton key={i} className="h-12 w-full" /> + ))} + </div> + </div> + ) + } + + return ( + <div className="space-y-4"> + {/* 헤더 */} + <div className="flex items-center justify-between"> + <div className="space-y-1"> + <h3 className="text-lg font-medium flex items-center gap-2"> + <MessageSquare className="h-5 w-5" /> + 벤더 응답 현황: {attachment.originalFileName} + </h3> + <div className="flex flex-wrap gap-2 text-sm text-muted-foreground"> + <Badge variant="outline"> + {attachment.attachmentType} + </Badge> + <span>시리얼: {attachment.serialNo}</span> + <span>등록: {formatDate(attachment.createdAt)}</span> + {attachment.responseStats && ( + <Badge variant="secondary"> + 응답률: {attachment.responseStats.responseRate}% + </Badge> + )} + </div> + </div> + <Button + variant="outline" + size="sm" + onClick={onRefresh} + className="flex items-center gap-2" + > + <RefreshCw className="h-4 w-4" /> + 새로고침 + </Button> + </div> + + {/* 테이블 */} + {responses.length === 0 ? ( + <div className="text-center py-8 text-muted-foreground border rounded-lg"> + 이 문서에 대한 벤더 응답 정보가 없습니다. + </div> + ) : ( + <div className="border rounded-lg"> + <Table> + <TableHeader> + <TableRow> + <TableHead>벤더</TableHead> + <TableHead>국가</TableHead> + <TableHead>응답 상태</TableHead> + <TableHead>리비전</TableHead> + <TableHead>요청일</TableHead> + <TableHead>응답일</TableHead> + <TableHead>벤더 코멘트</TableHead> + <TableHead className="w-[100px]">액션</TableHead> + </TableRow> + </TableHeader> + <TableBody> + {responses.map((response) => ( + <TableRow key={response.id}> + <TableCell className="font-medium"> + <div> + <div>{response.vendorName}</div> + <div className="text-xs text-muted-foreground"> + {response.vendorCode} + </div> + </div> + </TableCell> + + <TableCell> + {response.vendorCountry} + </TableCell> + + <TableCell> + <div className="flex items-center gap-2"> + {getStatusIcon(response.responseStatus)} + <Badge variant={getStatusBadgeVariant(response.responseStatus)}> + {response.responseStatus} + </Badge> + </div> + </TableCell> + + <TableCell> + <div className="text-sm"> + <div>현재: {response.currentRevision}</div> + {response.respondedRevision && ( + <div className="text-muted-foreground"> + 응답: {response.respondedRevision} + </div> + )} + </div> + </TableCell> + + <TableCell> + {formatDate(response.requestedAt)} + </TableCell> + + <TableCell> + {response.respondedAt ? formatDate(response.respondedAt) : '-'} + </TableCell> + + <TableCell> + {response.vendorComment ? ( + <div className="max-w-[200px] truncate" title={response.vendorComment}> + {response.vendorComment} + </div> + ) : ( + '-' + )} + </TableCell> + + <TableCell> + <div className="flex items-center gap-1"> + {response.responseStatus === 'RESPONDED' && ( + <Button + variant="ghost" + size="sm" + className="h-8 w-8 p-0" + title="첨부파일 다운로드" + > + <Download className="h-4 w-4" /> + </Button> + )} + <Button + variant="ghost" + size="sm" + className="h-8 w-8 p-0" + title="상세 보기" + > + <MessageSquare className="h-4 w-4" /> + </Button> + </div> + </TableCell> + </TableRow> + ))} + </TableBody> + </Table> + </div> + )} + </div> + ) +}
\ No newline at end of file diff --git a/lib/b-rfq/service.ts b/lib/b-rfq/service.ts index f64eb46c..e60e446d 100644 --- a/lib/b-rfq/service.ts +++ b/lib/b-rfq/service.ts @@ -1,13 +1,27 @@ 'use server' import { revalidateTag, unstable_cache } from "next/cache" -import { count, desc, asc, and, or, gte, lte, ilike, eq } from "drizzle-orm" +import { count, desc, asc, and, or, gte, lte, ilike, eq, inArray, sql } from "drizzle-orm" import { filterColumns } from "@/lib/filter-columns" import db from "@/db/db" -import { RfqDashboardView, bRfqs, projects, users } from "@/db/schema" // 실제 스키마 import 경로에 맞게 수정 +import { RfqDashboardView, bRfqAttachmentRevisions, bRfqs, bRfqsAttachments, projects, users, vendorAttachmentResponses, vendors } from "@/db/schema" // 실제 스키마 import 경로에 맞게 수정 import { rfqDashboardView } from "@/db/schema" // 뷰 import import type { SQL } from "drizzle-orm" -import { CreateRfqInput, GetRFQDashboardSchema, createRfqServerSchema } from "./validations" +import { AttachmentRecord, CreateRfqInput, DeleteAttachmentsInput, GetRFQDashboardSchema, GetRfqAttachmentsSchema, attachmentRecordSchema, createRfqServerSchema, deleteAttachmentsSchema } from "./validations" +import { getServerSession } from "next-auth/next" +import { authOptions } from "@/app/api/auth/[...nextauth]/route" +import { unlink } from "fs/promises" + +const tag = { + rfqDashboard: 'rfq-dashboard', + rfq: (id: number) => `rfq-${id}`, + rfqAttachments: (rfqId: number) => `rfq-attachments-${rfqId}`, + attachmentRevisions: (attId: number) => `attachment-revisions-${attId}`, + vendorResponses: ( + attId: number, + type: 'INITIAL' | 'FINAL' = 'INITIAL', + ) => `vendor-responses-${attId}-${type}`, +} as const; export async function getRFQDashboard(input: GetRFQDashboardSchema) { return unstable_cache( @@ -46,30 +60,30 @@ export async function getRFQDashboard(input: GetRFQDashboardSchema) { let globalWhere: SQL<unknown> | undefined = undefined; if (input.search) { const s = `%${input.search}%`; - + const validSearchConditions: SQL<unknown>[] = []; - + const rfqCodeCondition = ilike(rfqDashboardView.rfqCode, s); if (rfqCodeCondition) validSearchConditions.push(rfqCodeCondition); - + const descriptionCondition = ilike(rfqDashboardView.description, s); if (descriptionCondition) validSearchConditions.push(descriptionCondition); - + const projectNameCondition = ilike(rfqDashboardView.projectName, s); if (projectNameCondition) validSearchConditions.push(projectNameCondition); - + const projectCodeCondition = ilike(rfqDashboardView.projectCode, s); if (projectCodeCondition) validSearchConditions.push(projectCodeCondition); - + const picNameCondition = ilike(rfqDashboardView.picName, s); if (picNameCondition) validSearchConditions.push(picNameCondition); - + const packageNoCondition = ilike(rfqDashboardView.packageNo, s); if (packageNoCondition) validSearchConditions.push(packageNoCondition); - + const packageNameCondition = ilike(rfqDashboardView.packageName, s); if (packageNameCondition) validSearchConditions.push(packageNameCondition); - + if (validSearchConditions.length > 0) { globalWhere = or(...validSearchConditions); } @@ -79,11 +93,11 @@ export async function getRFQDashboard(input: GetRFQDashboardSchema) { // 6) 최종 WHERE 조건 생성 const whereConditions: SQL<unknown>[] = []; - + if (advancedWhere) whereConditions.push(advancedWhere); if (basicWhere) whereConditions.push(basicWhere); if (globalWhere) whereConditions.push(globalWhere); - + const finalWhere = whereConditions.length > 0 ? and(...whereConditions) : undefined; // 7) 전체 데이터 수 조회 @@ -127,10 +141,8 @@ export async function getRFQDashboard(input: GetRFQDashboardSchema) { } }, [JSON.stringify(input)], - { - revalidate: 3600, - tags: ["rfq-dashboard"], - } + { revalidate: 3600, tags: [tag.rfqDashboard] }, + )(); } @@ -165,127 +177,844 @@ function getRFQJoinedTables() { // ================================================================ async function generateNextSerial(picCode: string): Promise<string> { - try { - // 해당 picCode로 시작하는 RFQ 개수 조회 - const existingCount = await db - .select({ count: count() }) - .from(bRfqs) - .where(eq(bRfqs.picCode, picCode)) - - const nextSerial = (existingCount[0]?.count || 0) + 1 - return nextSerial.toString().padStart(5, '0') // 5자리로 패딩 - } catch (error) { - console.error("시리얼 번호 생성 오류:", error) - return "00001" // 기본값 + try { + // 해당 picCode로 시작하는 RFQ 개수 조회 + const existingCount = await db + .select({ count: count() }) + .from(bRfqs) + .where(eq(bRfqs.picCode, picCode)) + + const nextSerial = (existingCount[0]?.count || 0) + 1 + return nextSerial.toString().padStart(5, '0') // 5자리로 패딩 + } catch (error) { + console.error("시리얼 번호 생성 오류:", error) + return "00001" // 기본값 + } +} +export async function createRfqAction(input: CreateRfqInput) { + try { + // 입력 데이터 검증 + const validatedData = createRfqServerSchema.parse(input) + + // RFQ 코드 자동 생성: N + picCode + 시리얼5자리 + const serialNumber = await generateNextSerial(validatedData.picCode) + const rfqCode = `N${validatedData.picCode}${serialNumber}` + + // 데이터베이스에 삽입 + const result = await db.insert(bRfqs).values({ + rfqCode, + projectId: validatedData.projectId, + dueDate: validatedData.dueDate, + status: "DRAFT", + picCode: validatedData.picCode, + picName: validatedData.picName || null, + EngPicName: validatedData.engPicName || null, + packageNo: validatedData.packageNo || null, + packageName: validatedData.packageName || null, + remark: validatedData.remark || null, + projectCompany: validatedData.projectCompany || null, + projectFlag: validatedData.projectFlag || null, + projectSite: validatedData.projectSite || null, + createdBy: validatedData.createdBy, + updatedBy: validatedData.updatedBy, + }).returning({ + id: bRfqs.id, + rfqCode: bRfqs.rfqCode, + }) + + // 관련 페이지 캐시 무효화 + revalidateTag(tag.rfqDashboard); + revalidateTag(tag.rfq(id)); + + + return { + success: true, + data: result[0], + message: "RFQ가 성공적으로 생성되었습니다", } + + } catch (error) { + console.error("RFQ 생성 오류:", error) + + + return { + success: false, + error: "RFQ 생성에 실패했습니다", + } + } +} + +// RFQ 코드 중복 확인 액션 +export async function checkRfqCodeExists(rfqCode: string) { + try { + const existing = await db.select({ id: bRfqs.id }) + .from(bRfqs) + .where(eq(bRfqs.rfqCode, rfqCode)) + .limit(1) + + return existing.length > 0 + } catch (error) { + console.error("RFQ 코드 확인 오류:", error) + return false + } +} + +// picCode별 다음 예상 RFQ 코드 미리보기 +export async function previewNextRfqCode(picCode: string) { + try { + const serialNumber = await generateNextSerial(picCode) + return `N${picCode}${serialNumber}` + } catch (error) { + console.error("RFQ 코드 미리보기 오류:", error) + return `N${picCode}00001` + } +} + +const getBRfqById = async (id: number): Promise<RfqDashboardView | null> => { + // 1) RFQ 단건 조회 + const rfqsRes = await db + .select() + .from(rfqDashboardView) + .where(eq(rfqDashboardView.rfqId, id)) + .limit(1); + + if (rfqsRes.length === 0) return null; + const rfqRow = rfqsRes[0]; + + // 3) RfqWithItems 형태로 반환 + const result: RfqDashboardView = { + ...rfqRow, + + }; + + return result; +}; + + +export const findBRfqById = async (id: number): Promise<RfqDashboardView | null> => { + try { + + const rfq = await getBRfqById(id); + + return rfq; + } catch (error) { + throw new Error('Failed to fetch user'); } - export async function createRfqAction(input: CreateRfqInput) { - try { - // 입력 데이터 검증 - const validatedData = createRfqServerSchema.parse(input) - - // RFQ 코드 자동 생성: N + picCode + 시리얼5자리 - const serialNumber = await generateNextSerial(validatedData.picCode) - const rfqCode = `N${validatedData.picCode}${serialNumber}` - - // 데이터베이스에 삽입 - const result = await db.insert(bRfqs).values({ - rfqCode, - projectId: validatedData.projectId, - dueDate: validatedData.dueDate, - status: "DRAFT", - picCode: validatedData.picCode, - picName: validatedData.picName || null, - EngPicName: validatedData.engPicName || null, - packageNo: validatedData.packageNo || null, - packageName: validatedData.packageName || null, - remark: validatedData.remark || null, - projectCompany: validatedData.projectCompany || null, - projectFlag: validatedData.projectFlag || null, - projectSite: validatedData.projectSite || null, - createdBy: validatedData.createdBy, - updatedBy: validatedData.updatedBy, - }).returning({ - id: bRfqs.id, - rfqCode: bRfqs.rfqCode, +}; + + +export async function getRfqAttachments( + input: GetRfqAttachmentsSchema, + rfqId: number +) { + return unstable_cache( + async () => { + try { + const offset = (input.page - 1) * input.perPage + + // Advanced Filter 처리 (메인 테이블 기준) + const advancedWhere = filterColumns({ + table: bRfqsAttachments, + filters: input.filters, + joinOperator: input.joinOperator, + }) + + // 전역 검색 (첨부파일 + 리비전 파일명 검색) + let globalWhere + if (input.search) { + const s = `%${input.search}%` + globalWhere = or( + ilike(bRfqsAttachments.serialNo, s), + ilike(bRfqsAttachments.description, s), + ilike(bRfqsAttachments.currentRevision, s), + ilike(bRfqAttachmentRevisions.fileName, s), + ilike(bRfqAttachmentRevisions.originalFileName, s) + ) + } + + // 기본 필터 + let basicWhere + if (input.attachmentType.length > 0 || input.fileType.length > 0) { + basicWhere = and( + input.attachmentType.length > 0 + ? inArray(bRfqsAttachments.attachmentType, input.attachmentType) + : undefined, + input.fileType.length > 0 + ? inArray(bRfqAttachmentRevisions.fileType, input.fileType) + : undefined + ) + } + + // 최종 WHERE 절 + const finalWhere = and( + eq(bRfqsAttachments.rfqId, rfqId), // RFQ ID 필수 조건 + advancedWhere, + globalWhere, + basicWhere + ) + + // 정렬 (메인 테이블 기준) + const orderBy = input.sort.length > 0 + ? input.sort.map((item) => + item.desc ? desc(bRfqsAttachments[item.id as keyof typeof bRfqsAttachments]) : asc(bRfqsAttachments[item.id as keyof typeof bRfqsAttachments]) + ) + : [desc(bRfqsAttachments.createdAt)] + + // 트랜잭션으로 데이터 조회 + const { data, total } = await db.transaction(async (tx) => { + // 메인 데이터 조회 (첨부파일 + 최신 리비전 조인) + const data = await tx + .select({ + // 첨부파일 메인 정보 + id: bRfqsAttachments.id, + attachmentType: bRfqsAttachments.attachmentType, + serialNo: bRfqsAttachments.serialNo, + rfqId: bRfqsAttachments.rfqId, + currentRevision: bRfqsAttachments.currentRevision, + latestRevisionId: bRfqsAttachments.latestRevisionId, + description: bRfqsAttachments.description, + createdBy: bRfqsAttachments.createdBy, + createdAt: bRfqsAttachments.createdAt, + updatedAt: bRfqsAttachments.updatedAt, + + // 최신 리비전 파일 정보 + fileName: bRfqAttachmentRevisions.fileName, + originalFileName: bRfqAttachmentRevisions.originalFileName, + filePath: bRfqAttachmentRevisions.filePath, + fileSize: bRfqAttachmentRevisions.fileSize, + fileType: bRfqAttachmentRevisions.fileType, + revisionComment: bRfqAttachmentRevisions.revisionComment, + + // 생성자 정보 + createdByName: users.name, + }) + .from(bRfqsAttachments) + .leftJoin( + bRfqAttachmentRevisions, + and( + eq(bRfqsAttachments.latestRevisionId, bRfqAttachmentRevisions.id), + eq(bRfqAttachmentRevisions.isLatest, true) + ) + ) + .leftJoin(users, eq(bRfqsAttachments.createdBy, users.id)) + .where(finalWhere) + .orderBy(...orderBy) + .limit(input.perPage) + .offset(offset) + + // 전체 개수 조회 + const totalResult = await tx + .select({ count: count() }) + .from(bRfqsAttachments) + .leftJoin( + bRfqAttachmentRevisions, + eq(bRfqsAttachments.latestRevisionId, bRfqAttachmentRevisions.id) + ) + .where(finalWhere) + + const total = totalResult[0]?.count ?? 0 + + return { data, total } + }) + + const pageCount = Math.ceil(total / input.perPage) + + // 각 첨부파일별 벤더 응답 통계 조회 + const attachmentIds = data.map(item => item.id) + let responseStatsMap: Record<number, any> = {} + + if (attachmentIds.length > 0) { + responseStatsMap = await getAttachmentResponseStats(attachmentIds) + } + + // 통계 데이터 병합 + const dataWithStats = data.map(attachment => ({ + ...attachment, + responseStats: responseStatsMap[attachment.id] || { + totalVendors: 0, + respondedCount: 0, + pendingCount: 0, + waivedCount: 0, + responseRate: 0 + } + })) + + return { data: dataWithStats, pageCount } + } catch (err) { + console.error("getRfqAttachments error:", err) + return { data: [], pageCount: 0 } + } + }, + [JSON.stringify(input), `${rfqId}`], + { revalidate: 300, tags: [tag.rfqAttachments(rfqId)] }, + )() +} + +// 첨부파일별 벤더 응답 통계 조회 +async function getAttachmentResponseStats(attachmentIds: number[]) { + try { + const stats = await db + .select({ + attachmentId: vendorAttachmentResponses.attachmentId, + totalVendors: count(), + respondedCount: sql<number>`count(case when ${vendorAttachmentResponses.responseStatus} = 'RESPONDED' then 1 end)`, + pendingCount: sql<number>`count(case when ${vendorAttachmentResponses.responseStatus} = 'NOT_RESPONDED' then 1 end)`, + waivedCount: sql<number>`count(case when ${vendorAttachmentResponses.responseStatus} = 'WAIVED' then 1 end)`, }) - - // 관련 페이지 캐시 무효화 - revalidateTag("rfq-dashboard") + .from(vendorAttachmentResponses) + .where(inArray(vendorAttachmentResponses.attachmentId, attachmentIds)) + .groupBy(vendorAttachmentResponses.attachmentId) - - return { - success: true, - data: result[0], - message: "RFQ가 성공적으로 생성되었습니다", + // 응답률 계산해서 객체로 변환 + const statsMap: Record<number, any> = {} + stats.forEach(stat => { + const activeVendors = stat.totalVendors - stat.waivedCount + const responseRate = activeVendors > 0 + ? Math.round((stat.respondedCount / activeVendors) * 100) + : 0 + + statsMap[stat.attachmentId] = { + totalVendors: stat.totalVendors, + respondedCount: stat.respondedCount, + pendingCount: stat.pendingCount, + waivedCount: stat.waivedCount, + responseRate } - - } catch (error) { - console.error("RFQ 생성 오류:", error) - - - return { - success: false, - error: "RFQ 생성에 실패했습니다", + }) + + return statsMap + } catch (error) { + console.error("getAttachmentResponseStats error:", error) + return {} + } +} + +// 특정 첨부파일에 대한 벤더 응답 현황 상세 조회 +export async function getVendorResponsesForAttachment( + attachmentId: number, + rfqType: 'INITIAL' | 'FINAL' = 'INITIAL' +) { + return unstable_cache( + async () => { + try { + const responses = await db + .select({ + id: vendorAttachmentResponses.id, + attachmentId: vendorAttachmentResponses.attachmentId, + vendorId: vendorAttachmentResponses.vendorId, + vendorCode: vendors.vendorCode, + vendorName: vendors.vendorName, + vendorCountry: vendors.country, + rfqType: vendorAttachmentResponses.rfqType, + rfqRecordId: vendorAttachmentResponses.rfqRecordId, + responseStatus: vendorAttachmentResponses.responseStatus, + currentRevision: vendorAttachmentResponses.currentRevision, + respondedRevision: vendorAttachmentResponses.respondedRevision, + responseComment: vendorAttachmentResponses.responseComment, + vendorComment: vendorAttachmentResponses.vendorComment, + requestedAt: vendorAttachmentResponses.requestedAt, + respondedAt: vendorAttachmentResponses.respondedAt, + updatedAt: vendorAttachmentResponses.updatedAt, + }) + .from(vendorAttachmentResponses) + .leftJoin(vendors, eq(vendorAttachmentResponses.vendorId, vendors.id)) + .where( + and( + eq(vendorAttachmentResponses.attachmentId, attachmentId), + eq(vendorAttachmentResponses.rfqType, rfqType) + ) + ) + .orderBy(vendors.vendorName) + + return responses + } catch (err) { + console.error("getVendorResponsesForAttachment error:", err) + return [] } + }, + [`${attachmentId}`, rfqType], + { revalidate: 180, tags: [tag.vendorResponses(attachmentId, rfqType)] }, + + )() +} + + +export async function confirmDocuments(rfqId: number) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.id) { + throw new Error("인증이 필요합니다.") + } + + // TODO: RFQ 상태를 "Doc. Confirmed"로 업데이트 + await db + .update(bRfqs) + .set({ + status: "Doc. Confirmed", + updatedBy: Number(session.user.id), + updatedAt: new Date(), + }) + .where(eq(bRfqs.id, rfqId)) + + revalidateTag(tag.rfq(rfqId)); + revalidateTag(tag.rfqDashboard); + revalidateTag(tag.rfqAttachments(rfqId)); + + return { + success: true, + message: "문서가 확정되었습니다.", + } + + } catch (error) { + console.error("confirmDocuments error:", error) + return { + success: false, + message: error instanceof Error ? error.message : "문서 확정 중 오류가 발생했습니다.", } } - - // RFQ 코드 중복 확인 액션 - export async function checkRfqCodeExists(rfqCode: string) { - try { - const existing = await db.select({ id: bRfqs.id }) - .from(bRfqs) - .where(eq(bRfqs.rfqCode, rfqCode)) - .limit(1) - - return existing.length > 0 - } catch (error) { - console.error("RFQ 코드 확인 오류:", error) - return false +} + +// TBE 요청 서버 액션 +export async function requestTbe(rfqId: number, attachmentIds?: number[]) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.id) { + throw new Error("인증이 필요합니다.") + } + + // attachmentIds가 제공된 경우 해당 첨부파일들만 처리 + let targetAttachments = [] + if (attachmentIds && attachmentIds.length > 0) { + // 선택된 첨부파일들 조회 + targetAttachments = await db + .select({ + id: bRfqsAttachments.id, + serialNo: bRfqsAttachments.serialNo, + attachmentType: bRfqsAttachments.attachmentType, + currentRevision: bRfqsAttachments.currentRevision, + }) + .from(bRfqsAttachments) + .where( + and( + eq(bRfqsAttachments.rfqId, rfqId), + inArray(bRfqsAttachments.id, attachmentIds) + ) + ) + + if (targetAttachments.length === 0) { + throw new Error("선택된 첨부파일을 찾을 수 없습니다.") + } + } else { + // 전체 RFQ의 모든 첨부파일 처리 + targetAttachments = await db + .select({ + id: bRfqsAttachments.id, + serialNo: bRfqsAttachments.serialNo, + attachmentType: bRfqsAttachments.attachmentType, + currentRevision: bRfqsAttachments.currentRevision, + }) + .from(bRfqsAttachments) + .where(eq(bRfqsAttachments.rfqId, rfqId)) + } + + if (targetAttachments.length === 0) { + throw new Error("TBE 요청할 첨부파일이 없습니다.") + } + + // TODO: TBE 요청 로직 구현 + // 1. RFQ 상태를 "TBE started"로 업데이트 (선택적) + // 2. 선택된 첨부파일들에 대해 벤더들에게 TBE 요청 이메일 발송 + // 3. vendorAttachmentResponses 테이블에 TBE 요청 레코드 생성 + // 4. TBE 관련 메타데이터 업데이트 + + + + // 예시: 선택된 첨부파일들에 대한 벤더 응답 레코드 생성 + await db.transaction(async (tx) => { + + const [updatedRfq] = await tx + .update(bRfqs) + .set({ + status: "TBE started", + updatedBy: Number(session.user.id), + updatedAt: new Date(), + }) + .where(eq(bRfqs.id, rfqId)) + .returning() + + // 각 첨부파일에 대해 벤더 응답 레코드 생성 또는 업데이트 + for (const attachment of targetAttachments) { + // TODO: 해당 첨부파일과 연관된 벤더들에게 TBE 요청 처리 + console.log(`TBE 요청 처리: ${attachment.serialNo} (${attachment.currentRevision})`) + } + }) + + // 캐시 무효화 + revalidateTag(`rfq-${rfqId}`) + revalidateTag(`rfq-attachments-${rfqId}`) + + const attachmentCount = targetAttachments.length + const attachmentList = targetAttachments + .map(a => `${a.serialNo} (${a.currentRevision})`) + .join(', ') + + return { + success: true, + message: `${attachmentCount}개 문서에 대한 TBE 요청이 전송되었습니다.\n대상: ${attachmentList}`, + targetAttachments, + } + + } catch (error) { + console.error("requestTbe error:", error) + return { + success: false, + message: error instanceof Error ? error.message : "TBE 요청 중 오류가 발생했습니다.", } } - - // picCode별 다음 예상 RFQ 코드 미리보기 - export async function previewNextRfqCode(picCode: string) { - try { - const serialNumber = await generateNextSerial(picCode) - return `N${picCode}${serialNumber}` - } catch (error) { - console.error("RFQ 코드 미리보기 오류:", error) - return `N${picCode}00001` +} + +// 다음 시리얼 번호 생성 +async function getNextSerialNo(rfqId: number): Promise<string> { + try { + // 해당 RFQ의 기존 첨부파일 개수 조회 + const [result] = await db + .select({ count: count() }) + .from(bRfqsAttachments) + .where(eq(bRfqsAttachments.rfqId, rfqId)) + + const nextNumber = (result?.count || 0) + 1 + + // 001, 002, 003... 형태로 포맷팅 + return nextNumber.toString().padStart(3, '0') + + } catch (error) { + console.error("getNextSerialNo error:", error) + // 에러 발생 시 타임스탬프 기반으로 fallback + return Date.now().toString().slice(-3) + } +} + +export async function addRfqAttachmentRecord(record: AttachmentRecord) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.id) { + throw new Error("인증이 필요합니다.") + } + + const validatedRecord = attachmentRecordSchema.parse(record) + const userId = Number(session.user.id) + + const result = await db.transaction(async (tx) => { + // 1. 시리얼 번호 생성 + const [countResult] = await tx + .select({ count: count() }) + .from(bRfqsAttachments) + .where(eq(bRfqsAttachments.rfqId, validatedRecord.rfqId)) + + const serialNo = (countResult.count + 1).toString().padStart(3, '0') + + // 2. 메인 첨부파일 레코드 생성 + const [attachment] = await tx + .insert(bRfqsAttachments) + .values({ + rfqId: validatedRecord.rfqId, + attachmentType: validatedRecord.attachmentType, + serialNo: serialNo, + currentRevision: "Rev.0", + description: validatedRecord.description, + createdBy: userId, + }) + .returning() + + // 3. 초기 리비전 (Rev.0) 생성 + const [revision] = await tx + .insert(bRfqAttachmentRevisions) + .values({ + attachmentId: attachment.id, + revisionNo: "Rev.0", + fileName: validatedRecord.fileName, + originalFileName: validatedRecord.originalFileName, + filePath: validatedRecord.filePath, + fileSize: validatedRecord.fileSize, + fileType: validatedRecord.fileType, + revisionComment: validatedRecord.revisionComment || "초기 업로드", + isLatest: true, + createdBy: userId, + }) + .returning() + + // 4. 메인 테이블의 latest_revision_id 업데이트 + await tx + .update(bRfqsAttachments) + .set({ + latestRevisionId: revision.id, + updatedAt: new Date(), + }) + .where(eq(bRfqsAttachments.id, attachment.id)) + + return { attachment, revision } + }) + + revalidateTag(tag.rfq(validatedRecord.rfqId)); + revalidateTag(tag.rfqDashboard); + revalidateTag(tag.rfqAttachments(validatedRecord.rfqId)); + + return { + success: true, + message: `파일이 성공적으로 등록되었습니다. (시리얼: ${result.attachment.serialNo}, 리비전: Rev.0)`, + attachment: result.attachment, + revision: result.revision, + } + + } catch (error) { + console.error("addRfqAttachmentRecord error:", error) + return { + success: false, + message: error instanceof Error ? error.message : "첨부파일 등록 중 오류가 발생했습니다.", } } +} -const getBRfqById = async (id: number): Promise<RfqDashboardView | null> => { - // 1) RFQ 단건 조회 - const rfqsRes = await db - .select() - .from(rfqDashboardView) - .where(eq(rfqDashboardView.rfqId, id)) +// 리비전 추가 (기존 첨부파일에 새 버전 추가) +export async function addRevisionToAttachment( + attachmentId: number, + revisionData: { + fileName: string; + originalFileName: string; + filePath: string; + fileSize: number; + fileType: string; + revisionComment?: string; + }, +) { + try { + const session = await getServerSession(authOptions); + if (!session?.user?.id) throw new Error('인증이 필요합니다.'); + + const userId = Number(session.user.id); + + // ──────────────────────────────────────────────────────────────────────────── + // 0. 첨부파일의 rfqId 사전 조회 (태그 무효화를 위해 필요) + // ──────────────────────────────────────────────────────────────────────────── + const [attInfo] = await db + .select({ rfqId: bRfqsAttachments.rfqId }) + .from(bRfqsAttachments) + .where(eq(bRfqsAttachments.id, attachmentId)) .limit(1); - - if (rfqsRes.length === 0) return null; - const rfqRow = rfqsRes[0]; - - // 3) RfqWithItems 형태로 반환 - const result: RfqDashboardView = { - ...rfqRow, + if (!attInfo) throw new Error('첨부파일을 찾을 수 없습니다.'); + const rfqId = attInfo.rfqId; + + // ──────────────────────────────────────────────────────────────────────────── + // 1‑5. 리비전 트랜잭션 + // ──────────────────────────────────────────────────────────────────────────── + const newRevision = await db.transaction(async (tx) => { + // 1. 현재 최신 리비전 조회 + const [latestRevision] = await tx + .select({ revisionNo: bRfqAttachmentRevisions.revisionNo }) + .from(bRfqAttachmentRevisions) + .where( + and( + eq(bRfqAttachmentRevisions.attachmentId, attachmentId), + eq(bRfqAttachmentRevisions.isLatest, true), + ), + ); + + if (!latestRevision) throw new Error('기존 첨부파일을 찾을 수 없습니다.'); + + // 2. 새 리비전 번호 생성 + const currentNum = parseInt(latestRevision.revisionNo.replace('Rev.', '')); + const newRevisionNo = `Rev.${currentNum + 1}`; + + // 3. 기존 리비전 isLatest → false + await tx + .update(bRfqAttachmentRevisions) + .set({ isLatest: false }) + .where( + and( + eq(bRfqAttachmentRevisions.attachmentId, attachmentId), + eq(bRfqAttachmentRevisions.isLatest, true), + ), + ); + + // 4. 새 리비전 INSERT + const [inserted] = await tx + .insert(bRfqAttachmentRevisions) + .values({ + attachmentId, + revisionNo: newRevisionNo, + fileName: revisionData.fileName, + originalFileName: revisionData.originalFileName, + filePath: revisionData.filePath, + fileSize: revisionData.fileSize, + fileType: revisionData.fileType, + revisionComment: revisionData.revisionComment ?? `${newRevisionNo} 업데이트`, + isLatest: true, + createdBy: userId, + }) + .returning(); + + // 5. 메인 첨부파일 row 업데이트 + await tx + .update(bRfqsAttachments) + .set({ + currentRevision: newRevisionNo, + latestRevisionId: inserted.id, + updatedAt: new Date(), + }) + .where(eq(bRfqsAttachments.id, attachmentId)); + + return inserted; + }); + + // ──────────────────────────────────────────────────────────────────────────── + // 6. 캐시 무효화 (rfqId 기준으로 수정) + // ──────────────────────────────────────────────────────────────────────────── + revalidateTag(tag.rfq(rfqId)); + revalidateTag(tag.rfqDashboard); + revalidateTag(tag.rfqAttachments(rfqId)); + revalidateTag(tag.attachmentRevisions(attachmentId)); + + return { + success: true, + message: `새 리비전(${newRevision.revisionNo})이 성공적으로 추가되었습니다.`, + revision: newRevision, }; - - return result; - }; - + } catch (error) { + console.error('addRevisionToAttachment error:', error); + return { + success: false, + message: error instanceof Error ? error.message : '리비전 추가 중 오류가 발생했습니다.', + }; + } +} + +// 특정 첨부파일의 모든 리비전 조회 +export async function getAttachmentRevisions(attachmentId: number) { + return unstable_cache( + async () => { + try { + const revisions = await db + .select({ + id: bRfqAttachmentRevisions.id, + revisionNo: bRfqAttachmentRevisions.revisionNo, + fileName: bRfqAttachmentRevisions.fileName, + originalFileName: bRfqAttachmentRevisions.originalFileName, + filePath: bRfqAttachmentRevisions.filePath, + fileSize: bRfqAttachmentRevisions.fileSize, + fileType: bRfqAttachmentRevisions.fileType, + revisionComment: bRfqAttachmentRevisions.revisionComment, + isLatest: bRfqAttachmentRevisions.isLatest, + createdBy: bRfqAttachmentRevisions.createdBy, + createdAt: bRfqAttachmentRevisions.createdAt, + createdByName: users.name, + }) + .from(bRfqAttachmentRevisions) + .leftJoin(users, eq(bRfqAttachmentRevisions.createdBy, users.id)) + .where(eq(bRfqAttachmentRevisions.attachmentId, attachmentId)) + .orderBy(desc(bRfqAttachmentRevisions.createdAt)) + + return { + success: true, + revisions, + } + } catch (error) { + console.error("getAttachmentRevisions error:", error) + return { + success: false, + message: "리비전 조회 중 오류가 발생했습니다.", + revisions: [], + } + } + }, + [`${attachmentId}`], + { revalidate: 180, tags: [tag.attachmentRevisions(attachmentId)] }, + + )() +} - export const findBRfqById = async (id: number): Promise<RfqDashboardView | null> => { - try { - - const rfq = await getBRfqById(id); - return rfq; - } catch (error) { - throw new Error('Failed to fetch user'); +// 첨부파일 삭제 (리비전 포함) +export async function deleteRfqAttachments(input: DeleteAttachmentsInput) { + try { + const session = await getServerSession(authOptions) + if (!session?.user?.id) { + throw new Error("인증이 필요합니다.") } - }; -
\ No newline at end of file + + const validatedInput = deleteAttachmentsSchema.parse(input) + + const result = await db.transaction(async (tx) => { + // 1. 삭제할 첨부파일들의 정보 조회 (파일 경로 포함) + const attachmentsToDelete = await tx + .select({ + id: bRfqsAttachments.id, + rfqId: bRfqsAttachments.rfqId, + serialNo: bRfqsAttachments.serialNo, + }) + .from(bRfqsAttachments) + .where(inArray(bRfqsAttachments.id, validatedInput.ids)) + + if (attachmentsToDelete.length === 0) { + throw new Error("삭제할 첨부파일을 찾을 수 없습니다.") + } + + // 2. 관련된 모든 리비전 파일 경로 조회 + const revisionFilePaths = await tx + .select({ filePath: bRfqAttachmentRevisions.filePath }) + .from(bRfqAttachmentRevisions) + .where(inArray(bRfqAttachmentRevisions.attachmentId, validatedInput.ids)) + + // 3. DB에서 리비전 삭제 (CASCADE로 자동 삭제되지만 명시적으로) + await tx + .delete(bRfqAttachmentRevisions) + .where(inArray(bRfqAttachmentRevisions.attachmentId, validatedInput.ids)) + + // 4. DB에서 첨부파일 삭제 + await tx + .delete(bRfqsAttachments) + .where(inArray(bRfqsAttachments.id, validatedInput.ids)) + + // 5. 실제 파일 삭제 (비동기로 처리) + Promise.all( + revisionFilePaths.map(async ({ filePath }) => { + try { + if (filePath) { + const fullPath = `${process.cwd()}/public${filePath}` + await unlink(fullPath) + } + } catch (fileError) { + console.warn(`Failed to delete file: ${filePath}`, fileError) + } + }) + ).catch(error => { + console.error("Some files failed to delete:", error) + }) + + return { + deletedCount: attachmentsToDelete.length, + rfqIds: [...new Set(attachmentsToDelete.map(a => a.rfqId))], + attachments: attachmentsToDelete, + } + }) + + // 캐시 무효화 + result.rfqIds.forEach(rfqId => { + revalidateTag(`rfq-attachments-${rfqId}`) + }) + + return { + success: true, + message: `${result.deletedCount}개의 첨부파일이 삭제되었습니다.`, + deletedAttachments: result.attachments, + } + + } catch (error) { + console.error("deleteRfqAttachments error:", error) + + return { + success: false, + message: error instanceof Error ? error.message : "첨부파일 삭제 중 오류가 발생했습니다.", + } + } +}
\ No newline at end of file diff --git a/lib/b-rfq/summary-table/summary-rfq-columns.tsx b/lib/b-rfq/summary-table/summary-rfq-columns.tsx index f620858a..40f143b2 100644 --- a/lib/b-rfq/summary-table/summary-rfq-columns.tsx +++ b/lib/b-rfq/summary-table/summary-rfq-columns.tsx @@ -37,7 +37,7 @@ function getStatusBadge(status: string) { case "PIC Assigned": return { variant: "secondary" as const, label: "담당자배정" }; case "Doc. Confirmed": - return { variant: "default" as const, label: "문서확인" }; + return { variant: "default" as const, label: "문서확정" }; case "Init. RFQ Sent": return { variant: "default" as const, label: "초기RFQ발송" }; case "Init. RFQ Answered": @@ -454,7 +454,7 @@ export function getRFQColumns({ setRowAction, router }: GetRFQColumnsProps): Col // enableHiding: false, cell: function Cell({ row }) { const rfq = row.original; - const detailUrl = `/b-rfq/${rfq.rfqId}/initial`; + const detailUrl = `/evcp/b-rfq/${rfq.rfqId}/initial`; return ( diff --git a/lib/b-rfq/summary-table/summary-rfq-table-toolbar-actions.tsx b/lib/b-rfq/summary-table/summary-rfq-table-toolbar-actions.tsx index 8ba95ce6..02ba4aaa 100644 --- a/lib/b-rfq/summary-table/summary-rfq-table-toolbar-actions.tsx +++ b/lib/b-rfq/summary-table/summary-rfq-table-toolbar-actions.tsx @@ -35,7 +35,7 @@ export function RFQTableToolbarActions({ table }: RFQTableToolbarActionsProps) { const rfqId = selectedRfq.rfqId // RFQ 첨부문서 확인 페이지로 이동 - router.push(`/b-rfq/${rfqId}`) + router.push(`/evcp/b-rfq/${rfqId}`) } } diff --git a/lib/b-rfq/validations.ts b/lib/b-rfq/validations.ts index df8dc6e6..df95b1d2 100644 --- a/lib/b-rfq/validations.ts +++ b/lib/b-rfq/validations.ts @@ -97,4 +97,71 @@ export const searchParamsRFQDashboardCache = createSearchParamsCache({ updatedBy: z.number(), }) - export type CreateRfqInput = z.infer<typeof createRfqServerSchema>
\ No newline at end of file + export type CreateRfqInput = z.infer<typeof createRfqServerSchema> + + + + export type RfqAttachment = { + id: number + attachmentType: string + serialNo: string + rfqId: number + fileName: string + originalFileName: string + filePath: string + fileSize: number | null + fileType: string | null + description: string | null + createdBy: number + createdAt: Date + createdByName?: string + responseStats?: { + totalVendors: number + respondedCount: number + pendingCount: number + waivedCount: number + responseRate: number + } + } + + // RFQ Attachments용 검색 파라미터 캐시 + export const searchParamsRfqAttachmentsCache = createSearchParamsCache({ + flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]), + page: parseAsInteger.withDefault(1), + perPage: parseAsInteger.withDefault(10), + sort: getSortingStateParser<RfqAttachment>().withDefault([ + { id: "createdAt", desc: true }, + ]), + // 기본 필터 + attachmentType: parseAsArrayOf(z.string()).withDefault([]), + fileType: parseAsArrayOf(z.string()).withDefault([]), + search: parseAsString.withDefault(""), + // advanced filter + filters: getFiltersStateParser().withDefault([]), + joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), + }) + + // 스키마 타입들 + export type GetRfqAttachmentsSchema = Awaited<ReturnType<typeof searchParamsRfqAttachmentsCache.parse>> + + + // 첨부파일 레코드 타입 +export const attachmentRecordSchema = z.object({ + rfqId: z.number().positive(), + attachmentType: z.enum(["구매", "설계"]), + // serialNo: z.string().min(1), + description: z.string().optional(), + fileName: z.string(), + originalFileName: z.string(), + filePath: z.string(), + fileSize: z.number(), + fileType: z.string(), +}) + +export type AttachmentRecord = z.infer<typeof attachmentRecordSchema> + +export const deleteAttachmentsSchema = z.object({ + ids: z.array(z.number()).min(1, "삭제할 첨부파일을 선택해주세요."), +}) + +export type DeleteAttachmentsInput = z.infer<typeof deleteAttachmentsSchema> diff --git a/lib/export_all.ts b/lib/export_all.ts index 6f925fbc..1da7f4de 100644 --- a/lib/export_all.ts +++ b/lib/export_all.ts @@ -56,7 +56,7 @@ export async function exportTableToExcel<TData>( const row2: string[] = [] columns.forEach((col) => { - const meta = col.columnDef.meta as any + const meta = col.columnDef?.meta as any // 1) group (그룹헤더) const groupKey = meta?.group let groupLabel = groupKey ?? "" diff --git a/lib/utils.ts b/lib/utils.ts index c09589d5..33b5a0c2 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -182,4 +182,16 @@ export function formatDateToQuarter(dateString: string | null | undefined): stri } return `${year} ${quarter}Q` +} + +export function formatBytes(bytes: number, decimals: number = 2): string { + if (bytes === 0) return "0 Bytes" + + const k = 1024 + const dm = decimals < 0 ? 0 : decimals + const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] + + const i = Math.floor(Math.log(bytes) / Math.log(k)) + + return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i] }
\ No newline at end of file diff --git a/lib/vendor-document-list/enhanced-document-service.ts b/lib/vendor-document-list/enhanced-document-service.ts index 66758b89..e01283dc 100644 --- a/lib/vendor-document-list/enhanced-document-service.ts +++ b/lib/vendor-document-list/enhanced-document-service.ts @@ -2,9 +2,9 @@ "use server" import { revalidatePath, unstable_cache } from "next/cache" -import { and, asc, desc, eq, ilike, or, count, avg } from "drizzle-orm" +import { and, asc, desc, eq, ilike, or, count, avg, inArray } from "drizzle-orm" import db from "@/db/db" -import { documentAttachments, documents, enhancedDocumentsView, issueStages, revisions, type EnhancedDocumentsView } from "@/db/schema/vendorDocu" +import { documentAttachments, documents, enhancedDocumentsView, issueStages, revisions, simplifiedDocumentsView, type EnhancedDocumentsView } from "@/db/schema/vendorDocu" import { filterColumns } from "@/lib/filter-columns" import type { CreateDocumentInput, @@ -19,6 +19,8 @@ import type { DocumentAttachment, Revision } from "@/types/enhanced-documents" +import { GetVendorShipDcoumentsSchema } from "./validations" +import { contracts, users } from "@/db/schema" // 스키마 타입 정의 export interface GetEnhancedDocumentsSchema { @@ -156,6 +158,225 @@ export async function getEnhancedDocuments( // )() } +export async function getEnhancedDocumentsShip( + input: GetVendorShipDcoumentsSchema, +) { + try { + const offset = (input.page - 1) * input.perPage + + // 고급 필터 처리 + const advancedWhere = filterColumns({ + table: simplifiedDocumentsView, + filters: input.filters || [], + joinOperator: input.joinOperator || "and", + }) + + // 전역 검색 처리 + let globalWhere + if (input.search) { + const searchTerm = `%${input.search}%` + globalWhere = or( + ilike(simplifiedDocumentsView.title, searchTerm), + ilike(simplifiedDocumentsView.docNumber, searchTerm), + ilike(simplifiedDocumentsView.projectCode, searchTerm), + ilike(simplifiedDocumentsView.vendorDocNumber, searchTerm), + ) + } + + // 최종 WHERE 조건 + const finalWhere = and( + advancedWhere, + globalWhere, + ) + + // 정렬 처리 + const orderBy = input.sort && input.sort.length > 0 + ? input.sort.map((item) => + item.desc + ? desc(simplifiedDocumentsView[item.id]) + : asc(simplifiedDocumentsView[item.id]) + ) + : [desc(simplifiedDocumentsView.createdAt)] + + // 트랜잭션 실행 + const { data, total } = await db.transaction(async (tx) => { + // 데이터 조회 + const data = await tx + .select() + .from(simplifiedDocumentsView) + .where(finalWhere) + .orderBy(...orderBy) + .limit(input.perPage) + .offset(offset) + + // 총 개수 조회 + const [{ total }] = await tx + .select({ + total: count() + }) + .from(simplifiedDocumentsView) + .where(finalWhere) + + return { data, total } + }) + + const pageCount = Math.ceil(total / input.perPage) + + return { data, pageCount, total } + } catch (err) { + console.error("Error fetching enhanced documents:", err) + return { data: [], pageCount: 0, total: 0 } + } +} + +// contractId로 필터링이 필요한 경우를 위한 추가 함수 +export async function getEnhancedDocumentsShipByContract( + input: GetVendorShipDcoumentsSchema, + contractId: number +) { + try { + const offset = (input.page - 1) * input.perPage + + // 고급 필터 처리 + const advancedWhere = filterColumns({ + table: simplifiedDocumentsView, + filters: input.filters || [], + joinOperator: input.joinOperator || "and", + }) + + // 전역 검색 처리 + let globalWhere + if (input.search) { + const searchTerm = `%${input.search}%` + globalWhere = or( + ilike(simplifiedDocumentsView.title, searchTerm), + ilike(simplifiedDocumentsView.docNumber, searchTerm), + ilike(simplifiedDocumentsView.projectCode, searchTerm), + ilike(simplifiedDocumentsView.vendorDocNumber, searchTerm), + ) + } + + // 최종 WHERE 조건 (contractId 포함) + const finalWhere = and( + eq(simplifiedDocumentsView.contractId, contractId), + advancedWhere, + globalWhere, + ) + + // 정렬 처리 + const orderBy = input.sort && input.sort.length > 0 + ? input.sort.map((item) => + item.desc + ? desc(simplifiedDocumentsView[item.id]) + : asc(simplifiedDocumentsView[item.id]) + ) + : [desc(simplifiedDocumentsView.createdAt)] + + // 트랜잭션 실행 + const { data, total } = await db.transaction(async (tx) => { + // 데이터 조회 + const data = await tx + .select() + .from(simplifiedDocumentsView) + .where(finalWhere) + .orderBy(...orderBy) + .limit(input.perPage) + .offset(offset) + + // 총 개수 조회 + const [{ total }] = await tx + .select({ + total: count() + }) + .from(simplifiedDocumentsView) + .where(finalWhere) + + return { data, total } + }) + + const pageCount = Math.ceil(total / input.perPage) + + return { data, pageCount, total } + } catch (err) { + console.error("Error fetching enhanced documents by contract:", err) + return { data: [], pageCount: 0, total: 0 } + } +} + +// drawingKind별로 문서를 조회하는 함수 +export async function getEnhancedDocumentsShipByDrawingKind( + input: GetVendorShipDcoumentsSchema, + drawingKind: 'B3' | 'B4' | 'B5' +) { + try { + const offset = (input.page - 1) * input.perPage + + // 고급 필터 처리 + const advancedWhere = filterColumns({ + table: simplifiedDocumentsView, + filters: input.filters || [], + joinOperator: input.joinOperator || "and", + }) + + // 전역 검색 처리 + let globalWhere + if (input.search) { + const searchTerm = `%${input.search}%` + globalWhere = or( + ilike(simplifiedDocumentsView.title, searchTerm), + ilike(simplifiedDocumentsView.docNumber, searchTerm), + ilike(simplifiedDocumentsView.projectCode, searchTerm), + ilike(simplifiedDocumentsView.vendorDocNumber, searchTerm), + ) + } + + // 최종 WHERE 조건 (drawingKind 포함) + const finalWhere = and( + eq(simplifiedDocumentsView.drawingKind, drawingKind), + advancedWhere, + globalWhere, + ) + + // 정렬 처리 + const orderBy = input.sort && input.sort.length > 0 + ? input.sort.map((item) => + item.desc + ? desc(simplifiedDocumentsView[item.id]) + : asc(simplifiedDocumentsView[item.id]) + ) + : [desc(simplifiedDocumentsView.createdAt)] + + // 트랜잭션 실행 + const { data, total } = await db.transaction(async (tx) => { + // 데이터 조회 + const data = await tx + .select() + .from(simplifiedDocumentsView) + .where(finalWhere) + .orderBy(...orderBy) + .limit(input.perPage) + .offset(offset) + + // 총 개수 조회 + const [{ total }] = await tx + .select({ + total: count() + }) + .from(simplifiedDocumentsView) + .where(finalWhere) + + return { data, total } + }) + + const pageCount = Math.ceil(total / input.perPage) + + return { data, pageCount, total } + } catch (err) { + console.error(`Error fetching enhanced documents for drawing kind ${drawingKind}:`, err) + return { data: [], pageCount: 0, total: 0 } + } +} + // 통계 데이터 가져오기 export async function getDocumentStatistics(contractId: number) { // return unstable_cache( @@ -779,4 +1000,179 @@ export async function getDocumentDetails(documentId: number) { error: "일괄 상태 업데이트 중 오류가 발생했습니다." } } + } + + + export async function getUserVendorDocuments( + userId: number, + input: GetVendorShipDcoumentsSchema + ) { + try { + const offset = (input.page - 1) * input.perPage + + // 1. 사용자의 벤더(회사) ID 조회 + const [user] = await db + .select({ companyId: users.companyId }) + .from(users) + .where(eq(users.id, userId)) + .limit(1) + + if (!user?.companyId) { + return { data: [], pageCount: 0, total: 0, drawingKind: null, vendorInfo: null } + } + + // 2. 해당 벤더의 모든 계약 ID들 조회 + const vendorContracts = await db + .select({ id: contracts.id }) + .from(contracts) + .where(eq(contracts.vendorId, user.companyId)) + + const contractIds = vendorContracts.map(c => c.id) + + if (contractIds.length === 0) { + return { data: [], pageCount: 0, total: 0, drawingKind: null, vendorInfo: null } + } + + // 3. 고급 필터 처리 + const advancedWhere = filterColumns({ + table: simplifiedDocumentsView, + filters: input.filters || [], + joinOperator: input.joinOperator || "and", + }) + + // 4. 전역 검색 처리 + let globalWhere + if (input.search) { + const searchTerm = `%${input.search}%` + globalWhere = or( + ilike(simplifiedDocumentsView.title, searchTerm), + ilike(simplifiedDocumentsView.docNumber, searchTerm), + ilike(simplifiedDocumentsView.vendorDocNumber, searchTerm), + ) + } + + // 5. 최종 WHERE 조건 (계약 ID들로 필터링) + const finalWhere = and( + inArray(simplifiedDocumentsView.contractId, contractIds), + advancedWhere, + globalWhere, + ) + + // 6. 정렬 처리 + const orderBy = input.sort && input.sort.length > 0 + ? input.sort.map((item) => + item.desc + ? desc(simplifiedDocumentsView[item.id]) + : asc(simplifiedDocumentsView[item.id]) + ) + : [desc(simplifiedDocumentsView.createdAt)] + + // 7. 트랜잭션 실행 + const { data, total, drawingKind, vendorInfo } = await db.transaction(async (tx) => { + // 데이터 조회 + const data = await tx + .select() + .from(simplifiedDocumentsView) + .where(finalWhere) + .orderBy(...orderBy) + .limit(input.perPage) + .offset(offset) + + // 총 개수 조회 + const [{ total }] = await tx + .select({ + total: count() + }) + .from(simplifiedDocumentsView) + .where(finalWhere) + + // DrawingKind 분석 (첫 번째 문서의 drawingKind 사용) + const drawingKind = data.length > 0 ? data[0].drawingKind : null + + // 벤더 정보 조회 + const [vendorInfo] = await tx + .select({ + vendorName: simplifiedDocumentsView.vendorName, + vendorCode: simplifiedDocumentsView.vendorCode, + }) + .from(simplifiedDocumentsView) + .where(eq(simplifiedDocumentsView.contractId, contractIds[0])) + .limit(1) + + return { data, total, drawingKind, vendorInfo } + }) + + const pageCount = Math.ceil(total / input.perPage) + + return { + data, + pageCount, + total, + drawingKind: drawingKind as 'B3' | 'B4' | 'B5' | null, + vendorInfo: vendorInfo || null + } + } catch (err) { + console.error("Error fetching user vendor documents:", err) + return { data: [], pageCount: 0, total: 0, drawingKind: null, vendorInfo: null } + } + } + + /** + * DrawingKind별 문서 통계 조회 + */ + export async function getUserVendorDocumentStats(userId: number) { + try { + // 사용자의 벤더 ID 조회 + const [user] = await db + .select({ companyId: users.companyId }) + .from(users) + .where(eq(users.id, userId)) + .limit(1) + + if (!user?.companyId) { + return { stats: {}, totalDocuments: 0, primaryDrawingKind: null } + } + + // 해당 벤더의 계약 ID들 조회 + const vendorContracts = await db + .select({ id: contracts.id }) + .from(contracts) + .where(eq(contracts.vendorId, user.companyId)) + + const contractIds = vendorContracts.map(c => c.id) + + if (contractIds.length === 0) { + return { stats: {}, totalDocuments: 0, primaryDrawingKind: null } + } + + // DrawingKind별 통계 조회 + const documents = await db + .select({ + drawingKind: simplifiedDocumentsView.drawingKind, + contractId: simplifiedDocumentsView.contractId, + }) + .from(simplifiedDocumentsView) + .where(inArray(simplifiedDocumentsView.contractId, contractIds)) + + // 통계 계산 + const stats = documents.reduce((acc, doc) => { + if (doc.drawingKind) { + acc[doc.drawingKind] = (acc[doc.drawingKind] || 0) + 1 + } + return acc + }, {} as Record<string, number>) + + // 가장 많은 DrawingKind 찾기 + const primaryDrawingKind = Object.entries(stats) + .sort(([,a], [,b]) => b - a)[0]?.[0] as 'B3' | 'B4' | 'B5' | undefined + + return { + stats, + totalDocuments: documents.length, + primaryDrawingKind: primaryDrawingKind || null + } + } catch (err) { + console.error("Error fetching user vendor document stats:", err) + return { stats: {}, totalDocuments: 0, primaryDrawingKind: null } + } }
\ No newline at end of file diff --git a/lib/vendor-document-list/ship/enhanced-doc-table-columns.tsx b/lib/vendor-document-list/ship/enhanced-doc-table-columns.tsx new file mode 100644 index 00000000..b80c0869 --- /dev/null +++ b/lib/vendor-document-list/ship/enhanced-doc-table-columns.tsx @@ -0,0 +1,427 @@ +// simplified-doc-table-columns.tsx +"use client" + +import * as React from "react" +import { ColumnDef } from "@tanstack/react-table" +import { formatDate, formatDateTime } from "@/lib/utils" +import { Checkbox } from "@/components/ui/checkbox" +import { DataTableColumnHeaderSimple } from "@/components/data-table/data-table-column-simple-header" +import { DataTableRowAction } from "@/types/table" +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuShortcut, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu" +import { Button } from "@/components/ui/button" +import { Badge } from "@/components/ui/badge" +import { + Ellipsis, + Calendar, + CalendarClock, + User, + FileText, + Eye, + Edit, + Trash2, + Building, + Code, + Settings +} from "lucide-react" +import { cn } from "@/lib/utils" +import { SimplifiedDocumentsView } from "@/db/schema" + +interface GetColumnsProps { + setRowAction: React.Dispatch<React.SetStateAction<DataTableRowAction<SimplifiedDocumentsView> | null>> +} + +// 유틸리티 함수들 +const getDrawingKindText = (drawingKind: string) => { + switch (drawingKind) { + case 'B3': return 'B3 도면' + case 'B4': return 'B4 도면' + case 'B5': return 'B5 도면' + default: return drawingKind + } +} + +const getDrawingKindColor = (drawingKind: string) => { + switch (drawingKind) { + case 'B3': return 'bg-blue-100 text-blue-800' + case 'B4': return 'bg-green-100 text-green-800' + case 'B5': return 'bg-purple-100 text-purple-800' + default: return 'bg-gray-100 text-gray-800' + } +} + +// 스테이지별 이름 표시 컴포넌트 +const StageNameDisplay = ({ + stageName, + drawingKind, + isFirst = true +}: { + stageName: string | null, + drawingKind: string | null, + isFirst?: boolean +}) => { + if (!stageName) return <span className="text-gray-400">-</span> + + const stageType = isFirst ? "1차" : "2차" + const getExpectedStage = () => { + if (drawingKind === 'B4') return isFirst ? 'Pre' : 'Work' + if (drawingKind === 'B3') return isFirst ? 'Approval' : 'Work' + if (drawingKind === 'B5') return isFirst ? 'First' : 'Second' + return '' + } + + return ( + <div className="flex flex-col gap-1"> + <div className="text-xs text-gray-500">{stageType} 스테이지</div> + <div className="text-sm font-medium">{stageName}</div> + {getExpectedStage() && ( + <div className="text-xs text-gray-400">({getExpectedStage()})</div> + )} + </div> + ) +} + +// 날짜 정보 표시 컴포넌트 +const StageDateInfo = ({ + planDate, + actualDate, + stageName +}: { + planDate: string | null + actualDate: string | null + stageName: string | null +}) => { + if (!planDate && !actualDate) { + return <span className="text-gray-400">날짜 미설정</span> + } + + const isCompleted = !!actualDate + const isLate = actualDate && planDate && new Date(actualDate) > new Date(planDate) + + return ( + <div className="flex flex-col gap-1"> + {planDate && ( + <div className="text-sm"> + <span className="text-gray-500">계획: </span> + <span>{formatDate(planDate)}</span> + </div> + )} + {actualDate && ( + <div className="text-sm"> + <span className="text-gray-500">실제: </span> + <span className={cn( + isLate ? "text-red-600 font-medium" : "text-green-600 font-medium" + )}> + {formatDate(actualDate)} + </span> + </div> + )} + {!actualDate && planDate && ( + <div className="text-xs text-orange-600"> + 진행중 + </div> + )} + {isCompleted && ( + <div className="text-xs text-green-600"> + ✓ 완료 + </div> + )} + </div> + ) +} + +export function getSimplifiedDocumentColumns({ + setRowAction, +}: GetColumnsProps): ColumnDef<SimplifiedDocumentsView>[] { + + // 기본 컬럼들 + const baseColumns: ColumnDef<SimplifiedDocumentsView>[] = [ + // 체크박스 선택 + { + id: "select", + header: ({ table }) => ( + <Checkbox + checked={ + table.getIsAllPageRowsSelected() || + (table.getIsSomePageRowsSelected() && "indeterminate") + } + onCheckedChange={(value) => table.toggleAllPageRowsSelected(!!value)} + aria-label="Select all" + className="translate-y-0.5" + /> + ), + cell: ({ row }) => ( + <Checkbox + checked={row.getIsSelected()} + onCheckedChange={(value) => row.toggleSelected(!!value)} + aria-label="Select row" + className="translate-y-0.5" + /> + ), + size: 40, + enableSorting: false, + enableHiding: false, + }, + + // 문서번호 + Drawing Kind + { + accessorKey: "docNumber", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="문서번호" /> + ), + cell: ({ row }) => { + const doc = row.original + return ( + <div className="flex flex-col gap-1 items-start"> + <span className="font-mono text-sm font-medium">{doc.docNumber}</span> + {doc.vendorDocNumber && ( + <span className="font-mono text-xs text-gray-500"> + 벤더: {doc.vendorDocNumber} + </span> + )} + {doc.drawingKind && ( + <Badge + variant="outline" + className={cn("text-xs", getDrawingKindColor(doc.drawingKind))} + > + {getDrawingKindText(doc.drawingKind)} + </Badge> + )} + </div> + ) + }, + size: 140, + enableResizing: true, + meta: { + excelHeader: "문서번호" + }, + }, + + // 문서명 + 프로젝트/벤더 정보 + { + accessorKey: "title", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="문서명" /> + ), + cell: ({ row }) => { + const doc = row.original + return ( + <div className="min-w-0 flex-1"> + <div className="font-medium text-gray-900 truncate" title={doc.title}> + {doc.title} + </div> + <div className="flex items-center gap-2 text-sm text-gray-500 mt-1"> + {doc.pic && ( + <span className="text-xs bg-gray-100 px-2 py-0.5 rounded"> + PIC: {doc.pic} + </span> + )} + {doc.projectCode && ( + <div className="flex items-center gap-1"> + <Building className="w-3 h-3" /> + <span>{doc.projectCode}</span> + </div> + )} + {doc.vendorName && ( + <div className="flex items-center gap-1"> + <Code className="w-3 h-3" /> + <span className="truncate max-w-[100px]">{doc.vendorName}</span> + </div> + )} + </div> + </div> + ) + }, + size: 200, + enableResizing: true, + meta: { + excelHeader: "문서명" + }, + }, + + // 첫 번째 스테이지 정보 + { + accessorKey: "firstStageName", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="1차 스테이지" /> + ), + cell: ({ row }) => { + const doc = row.original + return ( + <StageNameDisplay + stageName={doc.firstStageName} + drawingKind={doc.drawingKind} + isFirst={true} + /> + ) + }, + size: 130, + enableResizing: true, + meta: { + excelHeader: "1차 스테이지" + }, + }, + + // 첫 번째 스테이지 날짜 + { + accessorKey: "firstStagePlanDate", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="1차 일정" /> + ), + cell: ({ row }) => { + const doc = row.original + return ( + <StageDateInfo + planDate={doc.firstStagePlanDate} + actualDate={doc.firstStageActualDate} + stageName={doc.firstStageName} + /> + ) + }, + size: 140, + enableResizing: true, + meta: { + excelHeader: "1차 일정" + }, + }, + + // 두 번째 스테이지 정보 + { + accessorKey: "secondStageName", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="2차 스테이지" /> + ), + cell: ({ row }) => { + const doc = row.original + return ( + <StageNameDisplay + stageName={doc.secondStageName} + drawingKind={doc.drawingKind} + isFirst={false} + /> + ) + }, + size: 130, + enableResizing: true, + meta: { + excelHeader: "2차 스테이지" + }, + }, + + // 두 번째 스테이지 날짜 + { + accessorKey: "secondStagePlanDate", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="2차 일정" /> + ), + cell: ({ row }) => { + const doc = row.original + return ( + <StageDateInfo + planDate={doc.secondStagePlanDate} + actualDate={doc.secondStageActualDate} + stageName={doc.secondStageName} + /> + ) + }, + size: 140, + enableResizing: true, + meta: { + excelHeader: "2차 일정" + }, + }, + + // 첨부파일 수 + { + accessorKey: "attachmentCount", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="첨부파일" /> + ), + cell: ({ row }) => { + const count = row.original.attachmentCount || 0 + return ( + <div className="flex items-center gap-1"> + <FileText className="w-4 h-4 text-gray-400" /> + <span className="text-sm font-medium">{count}</span> + </div> + ) + }, + size: 80, + enableResizing: true, + meta: { + excelHeader: "첨부파일" + }, + }, + + // 업데이트 일시 + { + accessorKey: "updatedAt", + header: ({ column }) => ( + <DataTableColumnHeaderSimple column={column} title="업데이트" /> + ), + cell: ({ cell }) => ( + <span className="text-sm text-gray-600"> + {formatDateTime(cell.getValue() as Date)} + </span> + ), + size: 140, + enableResizing: true, + meta: { + excelHeader: "업데이트" + }, + }, + + // 액션 버튼 + { + id: "actions", + header: () => <span className="sr-only">Actions</span>, + cell: ({ row }) => { + const doc = row.original + return ( + <DropdownMenu> + <DropdownMenuTrigger asChild> + <Button variant="ghost" className="h-8 w-8 p-0"> + <span className="sr-only">Open menu</span> + <Ellipsis className="h-4 w-4" /> + </Button> + </DropdownMenuTrigger> + <DropdownMenuContent align="end"> + <DropdownMenuItem + onClick={() => setRowAction({ type: "view", row: doc })} + > + <Eye className="mr-2 h-4 w-4" /> + 보기 + </DropdownMenuItem> + <DropdownMenuItem + onClick={() => setRowAction({ type: "edit", row: doc })} + > + <Edit className="mr-2 h-4 w-4" /> + 편집 + </DropdownMenuItem> + <DropdownMenuSeparator /> + <DropdownMenuItem + onClick={() => setRowAction({ type: "delete", row: doc })} + className="text-red-600" + > + <Trash2 className="mr-2 h-4 w-4" /> + 삭제 + <DropdownMenuShortcut>⌫</DropdownMenuShortcut> + </DropdownMenuItem> + </DropdownMenuContent> + </DropdownMenu> + ) + }, + size: 50, + enableSorting: false, + enableHiding: false, + }, + ] + + return baseColumns +}
\ No newline at end of file diff --git a/lib/vendor-document-list/ship/enhanced-doc-table-toolbar-actions.tsx b/lib/vendor-document-list/ship/enhanced-doc-table-toolbar-actions.tsx new file mode 100644 index 00000000..3960bbce --- /dev/null +++ b/lib/vendor-document-list/ship/enhanced-doc-table-toolbar-actions.tsx @@ -0,0 +1,147 @@ +"use client" +import * as React from "react" +import { type Table } from "@tanstack/react-table" +import { Download, Upload, Plus, Files, RefreshCw } from "lucide-react" +import { toast } from "sonner" + +import { exportTableToExcel } from "@/lib/export" +import { Button } from "@/components/ui/button" +import { EnhancedDocumentsView } from "@/db/schema/vendorDocu" +import { AddDocumentListDialog } from "./add-doc-dialog" +import { DeleteDocumentsDialog } from "./delete-docs-dialog" +import { BulkUploadDialog } from "./bulk-upload-dialog" +import type { EnhancedDocument } from "@/types/enhanced-documents" +import { SendToSHIButton } from "./send-to-shi-button" +import { ImportFromDOLCEButton } from "./import-from-dolce-button" +import { SWPWorkflowPanel } from "./swp-workflow-panel" + +interface EnhancedDocTableToolbarActionsProps { + table: Table<EnhancedDocument> + projectType: "ship" | "plant" + selectedPackageId: number + onNewDocument: () => void + onBulkAction: (action: string, selectedRows: any[]) => Promise<void> +} + +export function EnhancedDocTableToolbarActions({ + table, + projectType, + selectedPackageId, + onNewDocument, + onBulkAction +}: EnhancedDocTableToolbarActionsProps) { + const [bulkUploadDialogOpen, setBulkUploadDialogOpen] = React.useState(false) + + // 현재 테이블의 모든 데이터 (필터링된 상태) + const allDocuments = table.getFilteredRowModel().rows.map(row => row.original) + + const handleSyncComplete = () => { + // 동기화 완료 후 테이블 새로고침 + table.resetRowSelection() + // 필요시 추가 액션 수행 + } + + const handleDocumentAdded = () => { + // 테이블 새로고침 + table.resetRowSelection() + + // 추가적인 새로고침 시도 + setTimeout(() => { + window.location.reload() // 강제 새로고침 + }, 500) + } + + const handleImportComplete = () => { + // 가져오기 완료 후 테이블 새로고침 + table.resetRowSelection() + setTimeout(() => { + window.location.reload() + }, 500) + } + + return ( + <div className="flex items-center gap-2"> + {/* 삭제 버튼 */} + {table.getFilteredSelectedRowModel().rows.length > 0 ? ( + <DeleteDocumentsDialog + documents={table + .getFilteredSelectedRowModel() + .rows.map((row) => row.original)} + onSuccess={() => table.toggleAllRowsSelected(false)} + /> + ) : null} + + {/* projectType에 따른 조건부 렌더링 */} + {projectType === "ship" ? ( + <> + {/* SHIP: DOLCE에서 목록 가져오기 */} + <ImportFromDOLCEButton + contractId={selectedPackageId} + onImportComplete={handleImportComplete} + /> + </> + ) : ( + <> + {/* PLANT: 수동 문서 추가 */} + <AddDocumentListDialog + projectType={projectType} + contractId={selectedPackageId} + onSuccess={handleDocumentAdded} + /> + </> + )} + + {/* 일괄 업로드 버튼 (공통) */} + <Button + variant="outline" + onClick={() => setBulkUploadDialogOpen(true)} + className="flex items-center gap-2" + > + <Files className="w-4 h-4" /> + 일괄 업로드 + </Button> + + {/* Export 버튼 (공통) */} + <Button + variant="outline" + size="sm" + onClick={() => + exportTableToExcel(table, { + filename: "Document-list", + excludeColumns: ["select", "actions"], + }) + } + className="gap-2" + > + <Download className="size-4" aria-hidden="true" /> + <span className="hidden sm:inline">Export</span> + </Button> + + {/* Send to SHI 버튼 (공통) - 내부 → 외부로 보내기 */} + <SendToSHIButton + contractId={selectedPackageId} + documents={allDocuments} + onSyncComplete={handleSyncComplete} + projectType={projectType} + /> + + {/* SWP 전용 워크플로우 패널 */} + {projectType === "plant" && ( + <SWPWorkflowPanel + contractId={selectedPackageId} + documents={allDocuments} + onWorkflowUpdate={handleSyncComplete} + /> + )} + + {/* 일괄 업로드 다이얼로그 */} + <BulkUploadDialog + open={bulkUploadDialogOpen} + onOpenChange={setBulkUploadDialogOpen} + documents={allDocuments} + projectType={projectType} + contractId={selectedPackageId} + /> + </div> + ) +}
\ No newline at end of file diff --git a/lib/vendor-document-list/ship/enhanced-document-sheet.tsx b/lib/vendor-document-list/ship/enhanced-document-sheet.tsx new file mode 100644 index 00000000..88e342c8 --- /dev/null +++ b/lib/vendor-document-list/ship/enhanced-document-sheet.tsx @@ -0,0 +1,939 @@ +// enhanced-document-sheet.tsx +"use client" + +import * as React from "react" +import { zodResolver } from "@hookform/resolvers/zod" +import { useForm } from "react-hook-form" +import { toast } from "sonner" +import { z } from "zod" +import { useRouter } from "next/navigation" +import { + Loader, + Save, + Upload, + Calendar, + User, + FileText, + AlertTriangle, + CheckCircle, + Clock, + Plus, + X +} from "lucide-react" + +import { Button } from "@/components/ui/button" +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { + Sheet, + SheetClose, + SheetContent, + SheetDescription, + SheetFooter, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet" +import { + Tabs, + TabsContent, + TabsList, + TabsTrigger, +} from "@/components/ui/tabs" +import { Input } from "@/components/ui/input" +import { Textarea } from "@/components/ui/textarea" +import { Badge } from "@/components/ui/badge" +import { Separator } from "@/components/ui/separator" +import { ScrollArea } from "@/components/ui/scroll-area" +import { Calendar as CalendarComponent } from "@/components/ui/calendar" +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" +import { cn } from "@/lib/utils" +import { format } from "date-fns" +import { ko } from "date-fns/locale" +import { EnhancedDocumentsView } from "@/db/schema/vendorDocu" + +// 드롭존과 파일 관련 컴포넌트들 +import { + Dropzone, + DropzoneDescription, + DropzoneInput, + DropzoneTitle, + DropzoneUploadIcon, + DropzoneZone, +} from "@/components/ui/dropzone" +import { + FileList, + FileListAction, + FileListDescription, + FileListHeader, + FileListIcon, + FileListInfo, + FileListItem, + FileListName, + FileListSize, +} from "@/components/ui/file-list" +import prettyBytes from "pretty-bytes" + +// 스키마 정의 +const enhancedDocumentSchema = z.object({ + // 기본 문서 정보 + docNumber: z.string().min(1, "문서번호는 필수입니다"), + title: z.string().min(1, "제목은 필수입니다"), + pic: z.string().optional(), + status: z.string().min(1, "상태는 필수입니다"), + issuedDate: z.date().optional(), + + // 스테이지 관리 (plant 타입에서만 수정 가능) + stages: z.array(z.object({ + id: z.number().optional(), + stageName: z.string().min(1, "스테이지명은 필수입니다"), + stageOrder: z.number(), + priority: z.enum(["HIGH", "MEDIUM", "LOW"]).default("MEDIUM"), + planDate: z.date().optional(), + assigneeName: z.string().optional(), + description: z.string().optional(), + })).optional(), + + // 리비전 업로드 (현재 스테이지에 대한) + newRevision: z.object({ + stage: z.string().optional(), + revision: z.string().optional(), + uploaderType: z.enum(["vendor", "client", "shi"]).default("vendor"), + uploaderName: z.string().optional(), + comment: z.string().optional(), + attachments: z.array(z.instanceof(File)).optional(), + }).optional(), +}) + +type EnhancedDocumentSchema = z.infer<typeof enhancedDocumentSchema> + +// 상태 옵션 정의 +const statusOptions = [ + { value: "ACTIVE", label: "활성" }, + { value: "INACTIVE", label: "비활성" }, + { value: "COMPLETED", label: "완료" }, + { value: "CANCELLED", label: "취소" }, +] + +const priorityOptions = [ + { value: "HIGH", label: "높음" }, + { value: "MEDIUM", label: "보통" }, + { value: "LOW", label: "낮음" }, +] + +const stageStatusOptions = [ + { value: "PLANNED", label: "계획됨" }, + { value: "IN_PROGRESS", label: "진행중" }, + { value: "SUBMITTED", label: "제출됨" }, + { value: "APPROVED", label: "승인됨" }, + { value: "REJECTED", label: "반려됨" }, + { value: "COMPLETED", label: "완료됨" }, +] + +interface EnhancedDocumentSheetProps + extends React.ComponentPropsWithRef<typeof Sheet> { + document: EnhancedDocumentsView | null + projectType: "ship" | "plant" + mode: "view" | "edit" | "upload" | "schedule" | "approve" +} + +export function EnhancedDocumentSheet({ + document, + projectType, + mode = "view", + ...props +}: EnhancedDocumentSheetProps) { + const [isUpdatePending, startUpdateTransition] = React.useTransition() + const [selectedFiles, setSelectedFiles] = React.useState<File[]>([]) + const [uploadProgress, setUploadProgress] = React.useState(0) + const [activeTab, setActiveTab] = React.useState("info") + const router = useRouter() + + // 권한 계산 + const permissions = React.useMemo(() => { + const canEdit = projectType === "plant" || mode === "edit" + const canUpload = mode === "upload" || mode === "edit" + const canApprove = mode === "approve" && projectType === "ship" + const canSchedule = mode === "schedule" || (projectType === "plant" && mode === "edit") + + return { canEdit, canUpload, canApprove, canSchedule } + }, [projectType, mode]) + + const form = useForm<EnhancedDocumentSchema>({ + resolver: zodResolver(enhancedDocumentSchema), + defaultValues: { + docNumber: "", + title: "", + pic: "", + status: "ACTIVE", + issuedDate: undefined, + stages: [], + newRevision: { + stage: "", + revision: "", + uploaderType: "vendor", + uploaderName: "", + comment: "", + attachments: [], + }, + }, + }) + + // 폼 초기화 + React.useEffect(() => { + if (document) { + form.reset({ + docNumber: document.docNumber, + title: document.title, + pic: document.pic || "", + status: document.status, + issuedDate: document.issuedDate ? new Date(document.issuedDate) : undefined, + stages: document.allStages?.map((stage, index) => ({ + id: stage.id, + stageName: stage.stageName, + stageOrder: stage.stageOrder || index, + priority: stage.priority as "HIGH" | "MEDIUM" | "LOW" || "MEDIUM", + planDate: stage.planDate ? new Date(stage.planDate) : undefined, + assigneeName: stage.assigneeName || "", + description: "", + })) || [], + newRevision: { + stage: document.currentStageName || "", + revision: "", + uploaderType: "vendor", + uploaderName: "", + comment: "", + attachments: [], + }, + }) + + // 모드에 따른 기본 탭 설정 + if (mode === "upload") { + setActiveTab("upload") + } else if (mode === "schedule") { + setActiveTab("schedule") + } else if (mode === "approve") { + setActiveTab("approve") + } + } + }, [document, form, mode]) + + // 파일 처리 + const handleDropAccepted = (acceptedFiles: File[]) => { + const newFiles = [...selectedFiles, ...acceptedFiles] + setSelectedFiles(newFiles) + form.setValue('newRevision.attachments', newFiles) + } + + const removeFile = (index: number) => { + const updatedFiles = [...selectedFiles] + updatedFiles.splice(index, 1) + setSelectedFiles(updatedFiles) + form.setValue('newRevision.attachments', updatedFiles) + } + + // 스테이지 추가/제거 + const addStage = () => { + const currentStages = form.getValues("stages") || [] + const newStage = { + stageName: "", + stageOrder: currentStages.length, + priority: "MEDIUM" as const, + planDate: undefined, + assigneeName: "", + description: "", + } + form.setValue("stages", [...currentStages, newStage]) + } + + const removeStage = (index: number) => { + const currentStages = form.getValues("stages") || [] + const updatedStages = currentStages.filter((_, i) => i !== index) + form.setValue("stages", updatedStages) + } + + // 제출 처리 + function onSubmit(input: EnhancedDocumentSchema) { + startUpdateTransition(async () => { + if (!document) return + + try { + // 모드에 따른 다른 처리 + switch (mode) { + case "edit": + // 문서 정보 업데이트 + 스테이지 관리 + await updateDocumentInfo(input) + break + case "upload": + // 리비전 업로드 + await uploadRevision(input) + break + case "approve": + // 승인 처리 + await approveRevision(input) + break + case "schedule": + // 스케줄 관리 + await updateSchedule(input) + break + } + + form.reset() + setSelectedFiles([]) + props.onOpenChange?.(false) + toast.success("성공적으로 처리되었습니다") + router.refresh() + } catch (error) { + toast.error("처리 중 오류가 발생했습니다") + console.error(error) + } + }) + } + + // 개별 처리 함수들 + const updateDocumentInfo = async (input: EnhancedDocumentSchema) => { + // 문서 기본 정보 업데이트 API 호출 + console.log("문서 정보 업데이트:", input) + } + + const uploadRevision = async (input: EnhancedDocumentSchema) => { + if (!input.newRevision?.attachments?.length) { + throw new Error("파일을 선택해주세요") + } + + // 파일 업로드 처리 + const formData = new FormData() + formData.append("documentId", String(document?.documentId)) + formData.append("stage", input.newRevision.stage || "") + formData.append("revision", input.newRevision.revision || "") + formData.append("uploaderType", input.newRevision.uploaderType) + + input.newRevision.attachments.forEach((file) => { + formData.append("attachments", file) + }) + + // API 호출 + console.log("리비전 업로드:", formData) + } + + const approveRevision = async (input: EnhancedDocumentSchema) => { + // 승인 처리 API 호출 + console.log("리비전 승인:", input) + } + + const updateSchedule = async (input: EnhancedDocumentSchema) => { + // 스케줄 업데이트 API 호출 + console.log("스케줄 업데이트:", input) + } + + // 제목 및 설명 생성 + const getSheetTitle = () => { + switch (mode) { + case "edit": return "문서 정보 수정" + case "upload": return "리비전 업로드" + case "approve": return "문서 승인" + case "schedule": return "일정 관리" + default: return "문서 상세" + } + } + + const getSheetDescription = () => { + const docInfo = document ? `${document.docNumber} - ${document.title}` : "" + switch (mode) { + case "edit": return `문서 정보를 수정합니다. ${docInfo}` + case "upload": return `새 리비전을 업로드합니다. ${docInfo}` + case "approve": return `문서를 검토하고 승인 처리합니다. ${docInfo}` + case "schedule": return `문서의 일정을 관리합니다. ${docInfo}` + default: return docInfo + } + } + + return ( + <Sheet {...props}> + <SheetContent className="flex flex-col gap-6 sm:max-w-2xl w-full"> + <SheetHeader className="text-left"> + <SheetTitle className="flex items-center gap-2"> + {mode === "upload" && <Upload className="w-5 h-5" />} + {mode === "approve" && <CheckCircle className="w-5 h-5" />} + {mode === "schedule" && <Calendar className="w-5 h-5" />} + {mode === "edit" && <FileText className="w-5 h-5" />} + {getSheetTitle()} + </SheetTitle> + <SheetDescription> + {getSheetDescription()} + </SheetDescription> + + {/* 프로젝트 타입 및 권한 표시 */} + <div className="flex items-center gap-2 pt-2"> + <Badge variant={projectType === "ship" ? "default" : "secondary"}> + {projectType === "ship" ? "조선 프로젝트" : "플랜트 프로젝트"} + </Badge> + {document?.isOverdue && ( + <Badge variant="destructive" className="flex items-center gap-1"> + <AlertTriangle className="w-3 h-3" /> + 지연 + </Badge> + )} + {document?.currentStagePriority === "HIGH" && ( + <Badge variant="destructive">높은 우선순위</Badge> + )} + </div> + </SheetHeader> + + <Form {...form}> + <form onSubmit={form.handleSubmit(onSubmit)} className="flex-1 flex flex-col"> + <Tabs value={activeTab} onValueChange={setActiveTab} className="flex-1 flex flex-col"> + <TabsList className="grid w-full grid-cols-4"> + <TabsTrigger value="info">기본정보</TabsTrigger> + <TabsTrigger value="schedule" disabled={!permissions.canSchedule}> + 일정관리 + </TabsTrigger> + <TabsTrigger value="upload" disabled={!permissions.canUpload}> + 리비전업로드 + </TabsTrigger> + <TabsTrigger value="approve" disabled={!permissions.canApprove}> + 승인처리 + </TabsTrigger> + </TabsList> + + {/* 기본 정보 탭 */} + <TabsContent value="info" className="flex-1 space-y-4"> + <ScrollArea className="h-full pr-4"> + <div className="space-y-4"> + <FormField + control={form.control} + name="docNumber" + render={({ field }) => ( + <FormItem> + <FormLabel>문서번호</FormLabel> + <FormControl> + <Input {...field} disabled={!permissions.canEdit} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="title" + render={({ field }) => ( + <FormItem> + <FormLabel>제목</FormLabel> + <FormControl> + <Input {...field} disabled={!permissions.canEdit} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <div className="grid grid-cols-2 gap-4"> + <FormField + control={form.control} + name="pic" + render={({ field }) => ( + <FormItem> + <FormLabel>담당자 (PIC)</FormLabel> + <FormControl> + <Input {...field} disabled={!permissions.canEdit} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="status" + render={({ field }) => ( + <FormItem> + <FormLabel>상태</FormLabel> + <Select + onValueChange={field.onChange} + value={field.value} + disabled={!permissions.canEdit} + > + <FormControl> + <SelectTrigger> + <SelectValue /> + </SelectTrigger> + </FormControl> + <SelectContent> + {statusOptions.map((option) => ( + <SelectItem key={option.value} value={option.value}> + {option.label} + </SelectItem> + ))} + </SelectContent> + </Select> + <FormMessage /> + </FormItem> + )} + /> + </div> + + <FormField + control={form.control} + name="issuedDate" + render={({ field }) => ( + <FormItem> + <FormLabel>발행일</FormLabel> + <Popover> + <PopoverTrigger asChild> + <FormControl> + <Button + variant="outline" + className={cn( + "w-full pl-3 text-left font-normal", + !field.value && "text-muted-foreground" + )} + disabled={!permissions.canEdit} + > + {field.value ? ( + format(field.value, "yyyy년 MM월 dd일", { locale: ko }) + ) : ( + <span>날짜를 선택하세요</span> + )} + <Calendar className="ml-auto h-4 w-4 opacity-50" /> + </Button> + </FormControl> + </PopoverTrigger> + <PopoverContent className="w-auto p-0" align="start"> + <CalendarComponent + mode="single" + selected={field.value} + onSelect={field.onChange} + disabled={(date) => date > new Date()} + initialFocus + /> + </PopoverContent> + </Popover> + <FormMessage /> + </FormItem> + )} + /> + + {/* 현재 상태 정보 표시 */} + {document && ( + <div className="space-y-3 p-4 bg-gray-50 rounded-lg"> + <h4 className="font-medium flex items-center gap-2"> + <Clock className="w-4 h-4" /> + 현재 진행 상황 + </h4> + <div className="grid grid-cols-2 gap-4 text-sm"> + <div> + <span className="text-gray-500">현재 스테이지:</span> + <p className="font-medium">{document.currentStageName || "-"}</p> + </div> + <div> + <span className="text-gray-500">진행률:</span> + <p className="font-medium">{document.progressPercentage || 0}%</p> + </div> + <div> + <span className="text-gray-500">최신 리비전:</span> + <p className="font-medium">{document.latestRevision || "-"}</p> + </div> + <div> + <span className="text-gray-500">담당자:</span> + <p className="font-medium">{document.currentStageAssigneeName || "-"}</p> + </div> + </div> + </div> + )} + </div> + </ScrollArea> + </TabsContent> + + {/* 일정 관리 탭 */} + <TabsContent value="schedule" className="flex-1 space-y-4"> + <ScrollArea className="h-full pr-4"> + <div className="space-y-4"> + <div className="flex items-center justify-between"> + <h4 className="font-medium">스테이지 일정 관리</h4> + {projectType === "plant" && ( + <Button + type="button" + variant="outline" + size="sm" + onClick={addStage} + className="flex items-center gap-1" + > + <Plus className="w-4 h-4" /> + 스테이지 추가 + </Button> + )} + </div> + + {form.watch("stages")?.map((stage, index) => ( + <div key={index} className="p-4 border rounded-lg space-y-3"> + <div className="flex items-center justify-between"> + <h5 className="font-medium">스테이지 {index + 1}</h5> + {projectType === "plant" && ( + <Button + type="button" + variant="ghost" + size="sm" + onClick={() => removeStage(index)} + > + <X className="w-4 h-4" /> + </Button> + )} + </div> + + <div className="grid grid-cols-2 gap-3"> + <FormField + control={form.control} + name={`stages.${index}.stageName`} + render={({ field }) => ( + <FormItem> + <FormLabel>스테이지명</FormLabel> + <FormControl> + <Input {...field} disabled={projectType === "ship"} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name={`stages.${index}.priority`} + render={({ field }) => ( + <FormItem> + <FormLabel>우선순위</FormLabel> + <Select onValueChange={field.onChange} value={field.value}> + <FormControl> + <SelectTrigger> + <SelectValue /> + </SelectTrigger> + </FormControl> + <SelectContent> + {priorityOptions.map((option) => ( + <SelectItem key={option.value} value={option.value}> + {option.label} + </SelectItem> + ))} + </SelectContent> + </Select> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name={`stages.${index}.planDate`} + render={({ field }) => ( + <FormItem> + <FormLabel>계획일</FormLabel> + <Popover> + <PopoverTrigger asChild> + <FormControl> + <Button + variant="outline" + className={cn( + "w-full text-left font-normal", + !field.value && "text-muted-foreground" + )} + > + {field.value ? ( + format(field.value, "MM/dd", { locale: ko }) + ) : ( + <span>날짜 선택</span> + )} + <Calendar className="ml-auto h-4 w-4 opacity-50" /> + </Button> + </FormControl> + </PopoverTrigger> + <PopoverContent className="w-auto p-0" align="start"> + <CalendarComponent + mode="single" + selected={field.value} + onSelect={field.onChange} + initialFocus + /> + </PopoverContent> + </Popover> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name={`stages.${index}.assigneeName`} + render={({ field }) => ( + <FormItem> + <FormLabel>담당자</FormLabel> + <FormControl> + <Input {...field} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + </div> + </div> + ))} + </div> + </ScrollArea> + </TabsContent> + + {/* 리비전 업로드 탭 */} + <TabsContent value="upload" className="flex-1 space-y-4"> + <ScrollArea className="h-full pr-4"> + <div className="space-y-4"> + <div className="grid grid-cols-2 gap-4"> + <FormField + control={form.control} + name="newRevision.stage" + render={({ field }) => ( + <FormItem> + <FormLabel>스테이지</FormLabel> + <FormControl> + <Input {...field} placeholder="예: Issued for Review" /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="newRevision.revision" + render={({ field }) => ( + <FormItem> + <FormLabel>리비전</FormLabel> + <FormControl> + <Input {...field} placeholder="예: A, B, 1, 2..." /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + </div> + + <FormField + control={form.control} + name="newRevision.uploaderName" + render={({ field }) => ( + <FormItem> + <FormLabel>업로더명 (선택)</FormLabel> + <FormControl> + <Input {...field} placeholder="업로더 이름을 입력하세요" /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="newRevision.comment" + render={({ field }) => ( + <FormItem> + <FormLabel>코멘트 (선택)</FormLabel> + <FormControl> + <Textarea {...field} placeholder="코멘트를 입력하세요" rows={3} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 파일 업로드 드롭존 */} + <FormField + control={form.control} + name="newRevision.attachments" + render={() => ( + <FormItem> + <FormLabel>파일 첨부</FormLabel> + <Dropzone + maxSize={3e9} // 3GB + multiple={true} + onDropAccepted={handleDropAccepted} + disabled={isUpdatePending} + > + <DropzoneZone className="flex justify-center"> + <FormControl> + <DropzoneInput /> + </FormControl> + <div className="flex items-center gap-6"> + <DropzoneUploadIcon /> + <div className="grid gap-0.5"> + <DropzoneTitle>파일을 여기에 드롭하세요</DropzoneTitle> + <DropzoneDescription> + 또는 클릭하여 파일을 선택하세요 + </DropzoneDescription> + </div> + </div> + </DropzoneZone> + </Dropzone> + <FormMessage /> + </FormItem> + )} + /> + + {/* 선택된 파일 목록 */} + {selectedFiles.length > 0 && ( + <div className="space-y-2"> + <div className="flex items-center justify-between"> + <h6 className="text-sm font-semibold"> + 선택된 파일 ({selectedFiles.length}) + </h6> + </div> + <FileList className="max-h-[200px]"> + {selectedFiles.map((file, index) => ( + <FileListItem key={index} className="p-3"> + <FileListHeader> + <FileListIcon /> + <FileListInfo> + <FileListName>{file.name}</FileListName> + <FileListDescription> + {prettyBytes(file.size)} + </FileListDescription> + </FileListInfo> + <FileListAction + onClick={() => removeFile(index)} + disabled={isUpdatePending} + > + <X className="h-4 w-4" /> + </FileListAction> + </FileListHeader> + </FileListItem> + ))} + </FileList> + </div> + )} + + {/* 업로드 진행 상태 */} + {isUpdatePending && uploadProgress > 0 && ( + <div className="space-y-2"> + <div className="flex items-center gap-2"> + <Loader className="h-4 w-4 animate-spin" /> + <span className="text-sm">{uploadProgress}% 업로드 중...</span> + </div> + <div className="h-2 w-full bg-muted rounded-full overflow-hidden"> + <div + className="h-full bg-primary rounded-full transition-all" + style={{ width: `${uploadProgress}%` }} + /> + </div> + </div> + )} + </div> + </ScrollArea> + </TabsContent> + + {/* 승인 처리 탭 */} + <TabsContent value="approve" className="flex-1 space-y-4"> + <ScrollArea className="h-full pr-4"> + <div className="space-y-4"> + <div className="p-4 bg-blue-50 rounded-lg"> + <h4 className="font-medium mb-2 flex items-center gap-2"> + <CheckCircle className="w-4 h-4 text-blue-600" /> + 승인 대상 문서 + </h4> + <div className="text-sm space-y-1"> + <p><span className="font-medium">문서:</span> {document?.docNumber} - {document?.title}</p> + <p><span className="font-medium">현재 스테이지:</span> {document?.currentStageName}</p> + <p><span className="font-medium">최신 리비전:</span> {document?.latestRevision}</p> + <p><span className="font-medium">업로더:</span> {document?.latestRevisionUploaderName}</p> + </div> + </div> + + <div className="space-y-3"> + <div className="flex gap-3"> + <Button + type="button" + className="flex-1 bg-green-600 hover:bg-green-700" + onClick={() => { + // 승인 처리 로직 + console.log("승인 처리") + }} + > + <CheckCircle className="w-4 h-4 mr-2" /> + 승인 + </Button> + <Button + type="button" + variant="destructive" + className="flex-1" + onClick={() => { + // 반려 처리 로직 + console.log("반려 처리") + }} + > + <X className="w-4 h-4 mr-2" /> + 반려 + </Button> + </div> + + <FormField + control={form.control} + name="newRevision.comment" + render={({ field }) => ( + <FormItem> + <FormLabel>검토 의견</FormLabel> + <FormControl> + <Textarea + {...field} + placeholder="승인/반려 사유를 입력하세요" + rows={4} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + </div> + </div> + </ScrollArea> + </TabsContent> + </Tabs> + + <Separator /> + + <SheetFooter className="gap-2 pt-4"> + <SheetClose asChild> + <Button type="button" variant="outline"> + 취소 + </Button> + </SheetClose> + <Button + type="submit" + disabled={isUpdatePending} + className={mode === "approve" ? "bg-green-600 hover:bg-green-700" : ""} + > + {isUpdatePending && <Loader className="mr-2 size-4 animate-spin" />} + {mode === "upload" && <Upload className="mr-2 size-4" />} + {mode === "approve" && <CheckCircle className="mr-2 size-4" />} + {mode === "schedule" && <Calendar className="mr-2 size-4" />} + {mode === "edit" && <Save className="mr-2 size-4" />} + + {mode === "upload" ? "업로드" : + mode === "approve" ? "승인 처리" : + mode === "schedule" ? "일정 저장" : "저장"} + </Button> + </SheetFooter> + </form> + </Form> + </SheetContent> + </Sheet> + ) +}
\ No newline at end of file diff --git a/lib/vendor-document-list/ship/enhanced-documents-table.tsx b/lib/vendor-document-list/ship/enhanced-documents-table.tsx new file mode 100644 index 00000000..47bce275 --- /dev/null +++ b/lib/vendor-document-list/ship/enhanced-documents-table.tsx @@ -0,0 +1,238 @@ +// simplified-documents-table.tsx +"use client" + +import React from "react" +import type { + DataTableAdvancedFilterField, + DataTableFilterField, + DataTableRowAction, +} from "@/types/table" + +import { useDataTable } from "@/hooks/use-data-table" +import { getEnhancedDocumentsShip } from "../enhanced-document-service" +import { DataTableAdvancedToolbar } from "@/components/data-table/data-table-advanced-toolbar" +import { toast } from "sonner" + +import { Label } from "@/components/ui/label" +import { DataTable } from "@/components/data-table/data-table" +import { SimplifiedDocumentsView } from "@/db/schema" +import { getSimplifiedDocumentColumns } from "./enhanced-doc-table-columns" + +interface SimplifiedDocumentsTableProps { + promises: Promise<{ + data: SimplifiedDocumentsView[], + pageCount: number, + total: number + }> +} + +export function SimplifiedDocumentsTable({ + promises, +}: SimplifiedDocumentsTableProps) { + // React.use()로 Promise 결과를 받고, 그 다음에 destructuring + const result = React.use(promises) + const { data, pageCount, total } = result + + // 기존 상태들 + const [rowAction, setRowAction] = React.useState<DataTableRowAction<SimplifiedDocumentsView> | null>(null) // ✅ 타입 변경 + const [expandedRows,] = React.useState<Set<string>>(new Set()) + + const columns = React.useMemo( + () => getSimplifiedDocumentColumns({ setRowAction }), + [setRowAction] + ) + + // ✅ SimplifiedDocumentsView에 맞게 필터 필드 업데이트 + const advancedFilterFields: DataTableAdvancedFilterField<SimplifiedDocumentsView>[] = [ + { + id: "docNumber", + label: "문서번호", + type: "text", + }, + { + id: "vendorDocNumber", + label: "벤더 문서번호", + type: "text", + }, + { + id: "title", + label: "문서제목", + type: "text", + }, + { + id: "drawingKind", + label: "문서종류", + type: "select", + options: [ + { label: "B3", value: "B3" }, + { label: "B4", value: "B4" }, + { label: "B5", value: "B5" }, + ], + }, + { + id: "projectCode", + label: "프로젝트 코드", + type: "text", + }, + { + id: "vendorName", + label: "벤더명", + type: "text", + }, + { + id: "vendorCode", + label: "벤더 코드", + type: "text", + }, + { + id: "pic", + label: "담당자", + type: "text", + }, + { + id: "status", + label: "문서 상태", + type: "select", + options: [ + { label: "활성", value: "ACTIVE" }, + { label: "비활성", value: "INACTIVE" }, + { label: "보류", value: "PENDING" }, + { label: "완료", value: "COMPLETED" }, + ], + }, + { + id: "firstStageName", + label: "1차 스테이지", + type: "text", + }, + { + id: "secondStageName", + label: "2차 스테이지", + type: "text", + }, + { + id: "firstStagePlanDate", + label: "1차 계획일", + type: "date", + }, + { + id: "firstStageActualDate", + label: "1차 실제일", + type: "date", + }, + { + id: "secondStagePlanDate", + label: "2차 계획일", + type: "date", + }, + { + id: "secondStageActualDate", + label: "2차 실제일", + type: "date", + }, + { + id: "issuedDate", + label: "발행일", + type: "date", + }, + { + id: "createdAt", + label: "생성일", + type: "date", + }, + { + id: "updatedAt", + label: "수정일", + type: "date", + }, + ] + + // ✅ B4 전용 필드들 (조건부로 추가) + const b4FilterFields: DataTableAdvancedFilterField<SimplifiedDocumentsView>[] = [ + { + id: "cGbn", + label: "C 구분", + type: "text", + }, + { + id: "dGbn", + label: "D 구분", + type: "text", + }, + { + id: "degreeGbn", + label: "Degree 구분", + type: "text", + }, + { + id: "deptGbn", + label: "Dept 구분", + type: "text", + }, + { + id: "jGbn", + label: "J 구분", + type: "text", + }, + { + id: "sGbn", + label: "S 구분", + type: "text", + }, + ] + + // B4 문서가 있는지 확인하여 B4 전용 필드 추가 + const hasB4Documents = data.some(doc => doc.drawingKind === 'B4') + const finalFilterFields = hasB4Documents + ? [...advancedFilterFields, ...b4FilterFields] + : advancedFilterFields + + const { table } = useDataTable({ + data: data, + columns, + pageCount, + enablePinning: true, + enableAdvancedFilter: true, + initialState: { + sorting: [{ id: "createdAt", desc: true }], + columnPinning: { right: ["actions"] }, + }, + getRowId: (originalRow) => String(originalRow.documentId), + shallow: false, + clearOnDefault: true, + columnResizeMode: "onEnd", + }) + + // ✅ 행 액션 처리 (필요에 따라 구현) + React.useEffect(() => { + if (rowAction?.type === "view") { + toast.info(`문서 조회: ${rowAction.row.docNumber}`) + setRowAction(null) + } else if (rowAction?.type === "edit") { + toast.info(`문서 편집: ${rowAction.row.docNumber}`) + setRowAction(null) + } else if (rowAction?.type === "delete") { + toast.error(`문서 삭제: ${rowAction.row.docNumber}`) + setRowAction(null) + } + }, [rowAction]) + + return ( + <div className="w-full" style={{maxWidth:'100%'}}> + <DataTable table={table}> + <DataTableAdvancedToolbar + table={table} + filterFields={finalFilterFields} + shallow={false} + > + {/* ✅ 추가 툴바 컨텐츠 (필요시) */} + <div className="flex items-center gap-2"> + <Label className="text-sm font-medium"> + 총 {total}개 문서 + </Label> + </div> + </DataTableAdvancedToolbar> + </DataTable> + </div> + ) +} diff --git a/lib/vendor-document-list/ship/import-from-dolce-button.tsx b/lib/vendor-document-list/ship/import-from-dolce-button.tsx new file mode 100644 index 00000000..519d40cb --- /dev/null +++ b/lib/vendor-document-list/ship/import-from-dolce-button.tsx @@ -0,0 +1,356 @@ +"use client" + +import * as React from "react" +import { RefreshCw, Download, Loader2, CheckCircle, AlertTriangle } from "lucide-react" +import { toast } from "sonner" + +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover" +import { Badge } from "@/components/ui/badge" +import { Progress } from "@/components/ui/progress" +import { Separator } from "@/components/ui/separator" + +interface ImportFromDOLCEButtonProps { + contractId: number + onImportComplete?: () => void +} + +interface ImportStatus { + lastImportAt?: string + availableDocuments: number + newDocuments: number + updatedDocuments: number + importEnabled: boolean +} + +export function ImportFromDOLCEButton({ + contractId, + onImportComplete +}: ImportFromDOLCEButtonProps) { + const [isDialogOpen, setIsDialogOpen] = React.useState(false) + const [importProgress, setImportProgress] = React.useState(0) + const [isImporting, setIsImporting] = React.useState(false) + const [importStatus, setImportStatus] = React.useState<ImportStatus | null>(null) + const [statusLoading, setStatusLoading] = React.useState(false) + + // DOLCE 상태 조회 + const fetchImportStatus = async () => { + setStatusLoading(true) + try { + const response = await fetch(`/api/sync/import/status?contractId=${contractId}&sourceSystem=DOLCE`) + if (!response.ok) { + const errorData = await response.json().catch(() => ({})) + throw new Error(errorData.message || 'Failed to fetch import status') + } + + const status = await response.json() + setImportStatus(status) + + // 프로젝트 코드가 없는 경우 에러 처리 + if (status.error) { + toast.error(`상태 확인 실패: ${status.error}`) + setImportStatus(null) + } + } catch (error) { + console.error('Failed to fetch import status:', error) + toast.error('DOLCE 상태를 확인할 수 없습니다. 프로젝트 설정을 확인해주세요.') + setImportStatus(null) + } finally { + setStatusLoading(false) + } + } + + // 컴포넌트 마운트 시 상태 조회 + React.useEffect(() => { + fetchImportStatus() + }, [contractId]) + + const handleImport = async () => { + if (!contractId) return + + setImportProgress(0) + setIsImporting(true) + + try { + // 진행률 시뮬레이션 + const progressInterval = setInterval(() => { + setImportProgress(prev => Math.min(prev + 15, 90)) + }, 300) + + const response = await fetch('/api/sync/import', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + contractId, + sourceSystem: 'DOLCE' + }) + }) + + if (!response.ok) { + const errorData = await response.json() + throw new Error(errorData.message || 'Import failed') + } + + const result = await response.json() + + clearInterval(progressInterval) + setImportProgress(100) + + setTimeout(() => { + setImportProgress(0) + setIsDialogOpen(false) + setIsImporting(false) + + if (result?.success) { + const { newCount = 0, updatedCount = 0, skippedCount = 0 } = result + toast.success( + `DOLCE 가져오기 완료`, + { + description: `신규 ${newCount}건, 업데이트 ${updatedCount}건, 건너뜀 ${skippedCount}건 (B3/B4/B5 포함)` + } + ) + } else { + toast.error( + `DOLCE 가져오기 부분 실패`, + { + description: result?.message || '일부 DrawingKind에서 가져오기에 실패했습니다.' + } + ) + } + + fetchImportStatus() // 상태 갱신 + onImportComplete?.() + }, 500) + + } catch (error) { + setImportProgress(0) + setIsImporting(false) + + toast.error('DOLCE 가져오기 실패', { + description: error instanceof Error ? error.message : '알 수 없는 오류가 발생했습니다.' + }) + } + } + + const getStatusBadge = () => { + if (statusLoading) { + return <Badge variant="secondary">DOLCE 연결 확인 중...</Badge> + } + + if (!importStatus) { + return <Badge variant="destructive">DOLCE 연결 오류</Badge> + } + + if (!importStatus.importEnabled) { + return <Badge variant="secondary">DOLCE 가져오기 비활성화</Badge> + } + + if (importStatus.newDocuments > 0 || importStatus.updatedDocuments > 0) { + return ( + <Badge variant="default" className="gap-1 bg-blue-500 hover:bg-blue-600"> + <AlertTriangle className="w-3 h-3" /> + 업데이트 가능 (B3/B4/B5) + </Badge> + ) + } + + return ( + <Badge variant="default" className="gap-1 bg-green-500 hover:bg-green-600"> + <CheckCircle className="w-3 h-3" /> + DOLCE와 동기화됨 + </Badge> + ) + } + + const canImport = importStatus?.importEnabled && + (importStatus?.newDocuments > 0 || importStatus?.updatedDocuments > 0) + + return ( + <> + <Popover> + <PopoverTrigger asChild> + <div className="flex items-center gap-3"> + <Button + variant="outline" + size="sm" + className="flex items-center border-blue-200 hover:bg-blue-50" + disabled={isImporting || statusLoading} + > + {isImporting ? ( + <Loader2 className="w-4 h-4 animate-spin" /> + ) : ( + <Download className="w-4 h-4" /> + )} + <span className="hidden sm:inline">DOLCE에서 가져오기</span> + {importStatus && (importStatus.newDocuments > 0 || importStatus.updatedDocuments > 0) && ( + <Badge + variant="default" + className="h-5 w-5 p-0 text-xs flex items-center justify-center bg-blue-500" + > + {importStatus.newDocuments + importStatus.updatedDocuments} + </Badge> + )} + </Button> + </div> + </PopoverTrigger> + + <PopoverContent className="w-80"> + <div className="space-y-4"> + <div className="space-y-2"> + <h4 className="font-medium">DOLCE 가져오기 상태</h4> + <div className="flex items-center justify-between"> + <span className="text-sm text-muted-foreground">현재 상태</span> + {getStatusBadge()} + </div> + </div> + + {importStatus && ( + <div className="space-y-3"> + <Separator /> + + <div className="grid grid-cols-2 gap-4 text-sm"> + <div> + <div className="text-muted-foreground">신규 문서</div> + <div className="font-medium">{importStatus.newDocuments || 0}건</div> + </div> + <div> + <div className="text-muted-foreground">업데이트</div> + <div className="font-medium">{importStatus.updatedDocuments || 0}건</div> + </div> + </div> + + <div className="text-sm"> + <div className="text-muted-foreground">DOLCE 전체 문서 (B3/B4/B5)</div> + <div className="font-medium">{importStatus.availableDocuments || 0}건</div> + </div> + + {importStatus.lastImportAt && ( + <div className="text-sm"> + <div className="text-muted-foreground">마지막 가져오기</div> + <div className="font-medium"> + {new Date(importStatus.lastImportAt).toLocaleString()} + </div> + </div> + )} + </div> + )} + + <Separator /> + + <div className="flex gap-2"> + <Button + onClick={() => setIsDialogOpen(true)} + disabled={!canImport || isImporting} + className="flex-1" + size="sm" + > + {isImporting ? ( + <> + <Loader2 className="w-4 h-4 mr-2 animate-spin" /> + 가져오는 중... + </> + ) : ( + <> + <Download className="w-4 h-4 mr-2" /> + 지금 가져오기 + </> + )} + </Button> + + <Button + variant="outline" + size="sm" + onClick={fetchImportStatus} + disabled={statusLoading} + > + {statusLoading ? ( + <Loader2 className="w-4 h-4 animate-spin" /> + ) : ( + <RefreshCw className="w-4 h-4" /> + )} + </Button> + </div> + </div> + </PopoverContent> + </Popover> + + {/* 가져오기 진행 다이얼로그 */} + <Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}> + <DialogContent className="sm:max-w-md"> + <DialogHeader> + <DialogTitle>DOLCE에서 문서 목록 가져오기</DialogTitle> + <DialogDescription> + 삼성중공업 DOLCE 시스템에서 최신 문서 목록을 가져옵니다. + </DialogDescription> + </DialogHeader> + + <div className="space-y-4"> + {importStatus && ( + <div className="rounded-lg border p-4 space-y-3"> + <div className="flex items-center justify-between text-sm"> + <span>가져올 항목</span> + <span className="font-medium"> + {(importStatus.newDocuments || 0) + (importStatus.updatedDocuments || 0)}건 + </span> + </div> + + <div className="text-xs text-muted-foreground"> + 신규 문서와 업데이트된 문서가 포함됩니다. (B3, B4, B5) + <br /> + B4 문서의 경우 GTTPreDwg, GTTWorkingDwg 이슈 스테이지가 자동 생성됩니다. + </div> + + {isImporting && ( + <div className="space-y-2"> + <div className="flex items-center justify-between text-sm"> + <span>진행률</span> + <span>{importProgress}%</span> + </div> + <Progress value={importProgress} className="h-2" /> + </div> + )} + </div> + )} + + <div className="flex justify-end gap-2"> + <Button + variant="outline" + onClick={() => setIsDialogOpen(false)} + disabled={isImporting} + > + 취소 + </Button> + <Button + onClick={handleImport} + disabled={isImporting || !canImport} + > + {isImporting ? ( + <> + <Loader2 className="w-4 h-4 mr-2 animate-spin" /> + 가져오는 중... + </> + ) : ( + <> + <Download className="w-4 h-4 mr-2" /> + 가져오기 시작 + </> + )} + </Button> + </div> + </div> + </DialogContent> + </Dialog> + </> + ) +}
\ No newline at end of file diff --git a/lib/vendor-document-list/ship/revision-upload-dialog.tsx b/lib/vendor-document-list/ship/revision-upload-dialog.tsx new file mode 100644 index 00000000..16fc9fbb --- /dev/null +++ b/lib/vendor-document-list/ship/revision-upload-dialog.tsx @@ -0,0 +1,629 @@ +"use client" + +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import { z } from "zod" +import { toast } from "sonner" +import { useRouter } from "next/navigation" +import { useSession } from "next-auth/react" +import { mutate } from "swr" // ✅ SWR mutate import 추가 + +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +import { Textarea } from "@/components/ui/textarea" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { + Dropzone, + DropzoneDescription, + DropzoneInput, + DropzoneTitle, + DropzoneUploadIcon, + DropzoneZone, +} from "@/components/ui/dropzone" +import { + FileList, + FileListAction, + FileListHeader, + FileListIcon, + FileListInfo, + FileListItem, + FileListName, + FileListSize, +} from "@/components/ui/file-list" +import { Badge } from "@/components/ui/badge" +import { ScrollArea } from "@/components/ui/scroll-area" +import { Upload, X, Loader2 } from "lucide-react" +import prettyBytes from "pretty-bytes" +import { EnhancedDocumentsView } from "@/db/schema/vendorDocu" + +// 리비전 업로드 스키마 +const revisionUploadSchema = z.object({ + stage: z.string().min(1, "스테이지는 필수입니다"), + revision: z.string().min(1, "리비전은 필수입니다"), + uploaderName: z.string().optional(), + comment: z.string().optional(), + attachments: z.array(z.instanceof(File)).min(1, "최소 1개 파일이 필요합니다"), + // ✅ B3 문서용 usage 필드 추가 + usage: z.string().optional(), +}).refine((data) => { + // B3 문서이고 특정 stage인 경우 usage 필수 + // 이 검증은 컴포넌트 내에서 조건부로 처리 + return true; +}, { + message: "Usage는 필수입니다", + path: ["usage"], +}); + +const getUsageOptions = (stageName: string): string[] => { + const stageNameLower = stageName.toLowerCase(); + + if (stageNameLower.includes('approval')) { + return ['Approval (Partial)', 'Approval (Full)']; + } else if (stageNameLower.includes('working')) { + return ['Working (Partial)', 'Working (Full)']; + } + + return []; +}; + + +type RevisionUploadSchema = z.infer<typeof revisionUploadSchema> + +interface RevisionUploadDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + document: EnhancedDocumentsView | null + projectType: "ship" | "plant" + presetStage?: string + presetRevision?: string + mode?: 'new' | 'append' + onUploadComplete?: () => void // ✅ 업로드 완료 콜백 추가 +} + +function getTargetSystem(projectType: "ship" | "plant") { + return projectType === "ship" ? "DOLCE" : "SWP" +} + +export function RevisionUploadDialog({ + open, + onOpenChange, + document, + projectType, + presetStage, + presetRevision, + mode = 'new', + onUploadComplete, +}: RevisionUploadDialogProps) { + + const targetSystem = React.useMemo( + () => getTargetSystem(projectType), + [projectType] + ) + + const [selectedFiles, setSelectedFiles] = React.useState<File[]>([]) + const [isUploading, setIsUploading] = React.useState(false) + const [uploadProgress, setUploadProgress] = React.useState(0) + const router = useRouter() + + const { data: session } = useSession() + + // 사용 가능한 스테이지 옵션 + const stageOptions = React.useMemo(() => { + if (document?.allStages) { + return document.allStages.map(stage => stage.stageName) + } + return ["Issued for Review", "AFC", "Final Issue"] + }, [document]) + + const form = useForm<RevisionUploadSchema>({ + resolver: zodResolver(revisionUploadSchema), + defaultValues: { + stage: presetStage || document?.currentStageName || "", + revision: presetRevision || "", + uploaderName: session?.user?.name || "", + comment: "", + attachments: [], + usage: "", // ✅ usage 기본값 추가 + }, + }) + + // ✅ 현재 선택된 stage 값을 watch + const currentStage = form.watch('stage') + + // ✅ B3 문서 여부 확인 + const isB3Document = document?.drawingKind === 'B3' + + // ✅ 현재 stage에 따른 usage 옵션 + const usageOptions = React.useMemo(() => { + if (!isB3Document || !currentStage) return [] + return getUsageOptions(currentStage) + }, [isB3Document, currentStage]) + + // ✅ usage 필드가 필요한지 확인 + const isUsageRequired = isB3Document && usageOptions.length > 0 + + // session이 로드되면 uploaderName 업데이트 + React.useEffect(() => { + if (session?.user?.name) { + form.setValue('uploaderName', session.user.name) + } + }, [session?.user?.name, form]) + + // presetStage와 presetRevision이 변경될 때 폼 값 업데이트 + React.useEffect(() => { + if (presetStage) { + form.setValue('stage', presetStage) + } + if (presetRevision) { + form.setValue('revision', presetRevision) + } + }, [presetStage, presetRevision, form]) + + // ✅ stage가 변경될 때 usage 값 리셋 + React.useEffect(() => { + if (isB3Document) { + const newUsageOptions = getUsageOptions(currentStage) + if (newUsageOptions.length === 0) { + form.setValue('usage', '') + } else { + // 기존 값이 새로운 옵션에 없으면 리셋 + const currentUsage = form.getValues('usage') + if (currentUsage && !newUsageOptions.includes(currentUsage)) { + form.setValue('usage', '') + } + } + } + }, [currentStage, isB3Document, form]) + + // 파일 드롭 처리 + const handleDropAccepted = (acceptedFiles: File[]) => { + const newFiles = [...selectedFiles, ...acceptedFiles] + setSelectedFiles(newFiles) + form.setValue('attachments', newFiles, { shouldValidate: true }) + } + + const removeFile = (index: number) => { + const updatedFiles = [...selectedFiles] + updatedFiles.splice(index, 1) + setSelectedFiles(updatedFiles) + form.setValue('attachments', updatedFiles, { shouldValidate: true }) + } + + // 캐시 갱신 함수 + const refreshCaches = async () => { + try { + router.refresh() + + if (document?.contractId) { + await mutate(`/api/sync/status/${document.contractId}/${targetSystem}`) + console.log('✅ Sync status cache refreshed') + } + + await mutate(key => + typeof key === 'string' && + key.includes('sync') && + key.includes(String(document?.contractId)) + ) + + onUploadComplete?.() + + console.log('✅ All caches refreshed after upload') + } catch (error) { + console.error('❌ Cache refresh failed:', error) + } + } + + // ✅ 업로드 처리 - usage 필드 검증 및 전송 + async function onSubmit(data: RevisionUploadSchema) { + if (!document) return + + // ✅ B3 문서에서 usage가 필요한 경우 검증 + if (isUsageRequired && !data.usage) { + form.setError('usage', { + type: 'required', + message: 'Usage 선택은 필수입니다' + }) + return + } + + setIsUploading(true) + setUploadProgress(0) + + try { + const formData = new FormData() + formData.append("documentId", String(document.documentId)) + formData.append("stage", data.stage) + formData.append("revision", data.revision) + formData.append("mode", mode) + formData.append("targetSystem", targetSystem) + + if (data.uploaderName) { + formData.append("uploaderName", data.uploaderName) + } + + if (data.comment) { + formData.append("comment", data.comment) + } + + // ✅ B3 문서인 경우 usage 추가 + if (isB3Document && data.usage) { + formData.append("usage", data.usage) + } + + // 파일들 추가 + data.attachments.forEach((file) => { + formData.append("attachments", file) + }) + + // 진행률 업데이트 시뮬레이션 + const updateProgress = (progress: number) => { + setUploadProgress(Math.min(progress, 95)) + } + + const totalSize = data.attachments.reduce((sum, file) => sum + file.size, 0) + let uploadedSize = 0 + + const progressInterval = setInterval(() => { + uploadedSize += totalSize * 0.1 + const progress = Math.min((uploadedSize / totalSize) * 100, 90) + updateProgress(progress) + }, 300) + + const response = await fetch('/api/revision-upload', { + method: 'POST', + body: formData, + }) + + clearInterval(progressInterval) + + if (!response.ok) { + const errorData = await response.json() + throw new Error(errorData.error || errorData.details || '업로드에 실패했습니다.') + } + + const result = await response.json() + setUploadProgress(100) + + toast.success( + result.message || + `리비전 ${data.revision}이 성공적으로 업로드되었습니다. (${result.data?.uploadedFiles?.length || 0}개 파일)` + ) + + console.log('✅ 업로드 성공:', result) + + setTimeout(async () => { + await refreshCaches() + handleDialogClose() + }, 1000) + + } catch (error) { + console.error('❌ 업로드 오류:', error) + toast.error(error instanceof Error ? error.message : "업로드 중 오류가 발생했습니다") + } finally { + setIsUploading(false) + setTimeout(() => setUploadProgress(0), 2000) + } + } + + const handleDialogClose = () => { + form.reset({ + stage: presetStage || document?.currentStageName || "", + revision: presetRevision || "", + uploaderName: session?.user?.name || "", + comment: "", + attachments: [], + usage: "", // ✅ usage 리셋 추가 + }) + setSelectedFiles([]) + setIsUploading(false) + setUploadProgress(0) + onOpenChange(false) + } + + return ( + <Dialog open={open} onOpenChange={handleDialogClose}> + <DialogContent className="sm:max-w-md"> + <DialogHeader> + <DialogTitle className="flex items-center gap-2"> + <Upload className="w-5 h-5" /> + {mode === 'new' ? '새 리비전 업로드' : '파일 추가'} + </DialogTitle> + <DialogDescription> + {document ? `${document.docNumber} - ${document.title}` : + mode === 'new' ? "문서에 새 리비전을 업로드합니다." : "기존 리비전에 파일을 추가합니다."} + </DialogDescription> + + <div className="flex items-center gap-2 pt-2 flex-wrap"> + <Badge variant={projectType === "ship" ? "default" : "secondary"}> + {projectType === "ship" ? "조선 프로젝트" : "플랜트 프로젝트"} + </Badge> + <Badge variant="outline" className="text-xs"> + → {targetSystem} + </Badge> + {/* ✅ B3 문서 표시 */} + {isB3Document && ( + <Badge variant="outline" className="text-xs bg-orange-50 text-orange-700 border-orange-200"> + B3 문서 + </Badge> + )} + {session?.user?.name && ( + <Badge variant="outline" className="text-xs"> + 업로더: {session.user.name} + </Badge> + )} + {mode === 'append' && presetRevision && ( + <Badge variant="outline" className="text-xs"> + 리비전 {presetRevision}에 파일 추가 + </Badge> + )} + {mode === 'new' && presetRevision && ( + <Badge variant="outline" className="text-xs"> + 다음 리비전: {presetRevision} + </Badge> + )} + </div> + </DialogHeader> + + <Form {...form}> + <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> + <div className="grid grid-cols-2 gap-4"> + <FormField + control={form.control} + name="stage" + render={({ field }) => ( + <FormItem> + <FormLabel>스테이지</FormLabel> + <Select onValueChange={field.onChange} value={field.value}> + <FormControl> + <SelectTrigger> + <SelectValue placeholder="스테이지 선택" /> + </SelectTrigger> + </FormControl> + <SelectContent> + {stageOptions.map((stage) => ( + <SelectItem key={stage} value={stage}> + {stage} + </SelectItem> + ))} + </SelectContent> + </Select> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="revision" + render={({ field }) => ( + <FormItem> + <FormLabel>리비전</FormLabel> + <FormControl> + <Input + {...field} + placeholder="예: A, B, 1, 2..." + readOnly={mode === 'append'} + className={mode === 'append' ? 'bg-gray-50' : ''} + /> + </FormControl> + <FormMessage /> + {mode === 'new' && presetRevision && ( + <p className="text-xs text-gray-500"> + 자동으로 계산된 다음 리비전입니다. + </p> + )} + {mode === 'append' && ( + <p className="text-xs text-gray-500"> + 기존 리비전에 파일을 추가합니다. + </p> + )} + </FormItem> + )} + /> + </div> + + {/* ✅ B3 문서용 Usage 필드 - 조건부 표시 */} + {isB3Document && usageOptions.length > 0 && ( + <FormField + control={form.control} + name="usage" + render={({ field }) => ( + <FormItem> + <FormLabel className="flex items-center gap-2"> + 용도 + {isUsageRequired && <span className="text-red-500">*</span>} + </FormLabel> + <Select onValueChange={field.onChange} value={field.value}> + <FormControl> + <SelectTrigger> + <SelectValue placeholder="용도를 선택하세요" /> + </SelectTrigger> + </FormControl> + <SelectContent> + {usageOptions.map((usage) => ( + <SelectItem key={usage} value={usage}> + {usage} + </SelectItem> + ))} + </SelectContent> + </Select> + <FormMessage /> + <p className="text-xs text-gray-500"> + {currentStage} 스테이지에 필요한 용도를 선택하세요. + </p> + </FormItem> + )} + /> + )} + + <FormField + control={form.control} + name="uploaderName" + render={({ field }) => ( + <FormItem> + <FormLabel>업로더명</FormLabel> + <FormControl> + <Input + {...field} + placeholder="업로더 이름을 입력하세요" + className="bg-gray-50" + /> + </FormControl> + <FormMessage /> + <p className="text-xs text-gray-500"> + 로그인된 사용자 정보가 자동으로 입력됩니다. + </p> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="comment" + render={({ field }) => ( + <FormItem> + <FormLabel>코멘트 (선택)</FormLabel> + <FormControl> + <Textarea {...field} placeholder="코멘트를 입력하세요" rows={3} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 파일 업로드 영역 */} + <FormField + control={form.control} + name="attachments" + render={() => ( + <FormItem> + <FormLabel>파일 첨부</FormLabel> + <Dropzone + maxSize={3e9} // 3GB + multiple={true} + onDropAccepted={handleDropAccepted} + disabled={isUploading} + > + <DropzoneZone className="flex justify-center"> + <FormControl> + <DropzoneInput /> + </FormControl> + <div className="flex items-center gap-6"> + <DropzoneUploadIcon /> + <div className="grid gap-0.5"> + <DropzoneTitle>파일을 여기에 드롭하세요</DropzoneTitle> + <DropzoneDescription> + 또는 클릭하여 파일을 선택하세요 + </DropzoneDescription> + </div> + </div> + </DropzoneZone> + </Dropzone> + <FormMessage /> + </FormItem> + )} + /> + + {/* 선택된 파일 목록 */} + {selectedFiles.length > 0 && ( + <div className="space-y-2"> + <div className="flex items-center justify-between"> + <h6 className="text-sm font-semibold"> + 선택된 파일 ({selectedFiles.length}) + </h6> + </div> + <ScrollArea className="max-h-[200px]"> + <FileList> + {selectedFiles.map((file, index) => ( + <FileListItem key={index} className="p-3"> + <FileListHeader> + <FileListIcon /> + <FileListInfo> + <FileListName>{file.name}</FileListName> + <FileListSize>{file.size}</FileListSize> + </FileListInfo> + <FileListAction + onClick={() => removeFile(index)} + disabled={isUploading} + > + <X className="h-4 w-4" /> + </FileListAction> + </FileListHeader> + </FileListItem> + ))} + </FileList> + </ScrollArea> + </div> + )} + + {/* 업로드 진행 상태 */} + {isUploading && ( + <div className="space-y-2"> + <div className="flex items-center gap-2"> + <Loader2 className="h-4 w-4 animate-spin" /> + <span className="text-sm">{uploadProgress}% 업로드 중...</span> + </div> + <div className="h-2 w-full bg-muted rounded-full overflow-hidden"> + <div + className="h-full bg-primary rounded-full transition-all" + style={{ width: `${uploadProgress}%` }} + /> + </div> + </div> + )} + + <DialogFooter> + <Button + type="button" + variant="outline" + onClick={handleDialogClose} + disabled={isUploading} + > + 취소 + </Button> + <Button + type="submit" + disabled={isUploading || selectedFiles.length === 0} + > + {isUploading ? ( + <> + <Loader2 className="mr-2 h-4 w-4 animate-spin" /> + 업로드 중... + </> + ) : ( + <> + <Upload className="mr-2 h-4 w-4" /> + 업로드 + </> + )} + </Button> + </DialogFooter> + </form> + </Form> + </DialogContent> + </Dialog> + ) +}
\ No newline at end of file diff --git a/lib/vendor-document-list/ship/send-to-shi-button.tsx b/lib/vendor-document-list/ship/send-to-shi-button.tsx new file mode 100644 index 00000000..1a27a794 --- /dev/null +++ b/lib/vendor-document-list/ship/send-to-shi-button.tsx @@ -0,0 +1,348 @@ +// components/sync/send-to-shi-button.tsx (최종 버전) +"use client" + +import * as React from "react" +import { Send, Loader2, CheckCircle, AlertTriangle, Settings } from "lucide-react" +import { toast } from "sonner" + +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover" +import { Badge } from "@/components/ui/badge" +import { Progress } from "@/components/ui/progress" +import { Separator } from "@/components/ui/separator" +import { useSyncStatus, useTriggerSync } from "@/hooks/use-sync-status" +import type { EnhancedDocument } from "@/types/enhanced-documents" + +interface SendToSHIButtonProps { + contractId: number + documents?: EnhancedDocument[] + onSyncComplete?: () => void + projectType: "ship" | "plant" +} + +export function SendToSHIButton({ + contractId, + documents = [], + onSyncComplete, + projectType +}: SendToSHIButtonProps) { + const [isDialogOpen, setIsDialogOpen] = React.useState(false) + const [syncProgress, setSyncProgress] = React.useState(0) + + const targetSystem = projectType === 'ship'?"DOLCE":"SWP" + + const { + syncStatus, + isLoading: statusLoading, + error: statusError, + refetch: refetchStatus + } = useSyncStatus(contractId, targetSystem) + + const { + triggerSync, + isLoading: isSyncing, + error: syncError + } = useTriggerSync() + + // 에러 상태 표시 + React.useEffect(() => { + if (statusError) { + console.warn('Failed to load sync status:', statusError) + } + }, [statusError]) + + const handleSync = async () => { + if (!contractId) return + + setSyncProgress(0) + + try { + // 진행률 시뮬레이션 + const progressInterval = setInterval(() => { + setSyncProgress(prev => Math.min(prev + 10, 90)) + }, 200) + + const result = await triggerSync({ + contractId, + targetSystem + }) + + clearInterval(progressInterval) + setSyncProgress(100) + + setTimeout(() => { + setSyncProgress(0) + setIsDialogOpen(false) + + if (result?.success) { + toast.success( + `동기화 완료: ${result.successCount || 0}건 성공`, + { + description: result.successCount > 0 + ? `${result.successCount}개 항목이 SHI 시스템으로 전송되었습니다.` + : '전송할 새로운 변경사항이 없습니다.' + } + ) + } else { + toast.error( + `동기화 부분 실패: ${result?.successCount || 0}건 성공, ${result?.failureCount || 0}건 실패`, + { + description: result?.errors?.[0] || '일부 항목 전송에 실패했습니다.' + } + ) + } + + refetchStatus() // SWR 캐시 갱신 + onSyncComplete?.() + }, 500) + + } catch (error) { + setSyncProgress(0) + + toast.error('동기화 실패', { + description: error instanceof Error ? error.message : '알 수 없는 오류가 발생했습니다.' + }) + } + } + + const getSyncStatusBadge = () => { + if (statusLoading) { + return <Badge variant="secondary">확인 중...</Badge> + } + + if (statusError) { + return <Badge variant="destructive">오류</Badge> + } + + if (!syncStatus) { + return <Badge variant="secondary">데이터 없음</Badge> + } + + if (syncStatus.pendingChanges > 0) { + return ( + <Badge variant="destructive" className="gap-1"> + <AlertTriangle className="w-3 h-3" /> + {syncStatus.pendingChanges}건 대기 + </Badge> + ) + } + + if (syncStatus.syncedChanges > 0) { + return ( + <Badge variant="default" className="gap-1 bg-green-500 hover:bg-green-600"> + <CheckCircle className="w-3 h-3" /> + 동기화됨 + </Badge> + ) + } + + return <Badge variant="secondary">변경사항 없음</Badge> + } + + const canSync = !statusError && syncStatus?.syncEnabled && syncStatus?.pendingChanges > 0 + + return ( + <> + <Popover> + <PopoverTrigger asChild> + <div className="flex items-center gap-3"> + <Button + variant="default" + size="sm" + className="flex items-center bg-blue-600 hover:bg-blue-700" + disabled={isSyncing || statusLoading} + > + {isSyncing ? ( + <Loader2 className="w-4 h-4 animate-spin" /> + ) : ( + <Send className="w-4 h-4" /> + )} + <span className="hidden sm:inline">Send to SHI</span> + {syncStatus?.pendingChanges > 0 && ( + <Badge + variant="destructive" + className="h-5 w-5 p-0 text-xs flex items-center justify-center" + > + {syncStatus.pendingChanges} + </Badge> + )} + </Button> + </div> + </PopoverTrigger> + + <PopoverContent className="w-80"> + <div className="space-y-4"> + <div className="space-y-2"> + <h4 className="font-medium">SHI 동기화 상태</h4> + <div className="flex items-center justify-between"> + <span className="text-sm text-muted-foreground">현재 상태</span> + {getSyncStatusBadge()} + </div> + </div> + + {syncStatus && !statusError && ( + <div className="space-y-3"> + <Separator /> + + <div className="grid grid-cols-2 gap-4 text-sm"> + <div> + <div className="text-muted-foreground">대기 중</div> + <div className="font-medium">{syncStatus.pendingChanges || 0}건</div> + </div> + <div> + <div className="text-muted-foreground">동기화됨</div> + <div className="font-medium">{syncStatus.syncedChanges || 0}건</div> + </div> + </div> + + {syncStatus.failedChanges > 0 && ( + <div className="text-sm"> + <div className="text-muted-foreground">실패</div> + <div className="font-medium text-red-600">{syncStatus.failedChanges}건</div> + </div> + )} + + {syncStatus.lastSyncAt && ( + <div className="text-sm"> + <div className="text-muted-foreground">마지막 동기화</div> + <div className="font-medium"> + {new Date(syncStatus.lastSyncAt).toLocaleString()} + </div> + </div> + )} + </div> + )} + + {statusError && ( + <div className="space-y-2"> + <Separator /> + <div className="text-sm text-red-600"> + <div className="font-medium">연결 오류</div> + <div className="text-xs">동기화 상태를 확인할 수 없습니다.</div> + </div> + </div> + )} + + <Separator /> + + <div className="flex gap-2"> + <Button + onClick={() => setIsDialogOpen(true)} + disabled={!canSync || isSyncing} + className="flex-1" + size="sm" + > + {isSyncing ? ( + <> + <Loader2 className="w-4 h-4 mr-2 animate-spin" /> + 동기화 중... + </> + ) : ( + <> + <Send className="w-4 h-4 mr-2" /> + 지금 동기화 + </> + )} + </Button> + + <Button + variant="outline" + size="sm" + onClick={() => refetchStatus()} + disabled={statusLoading} + > + {statusLoading ? ( + <Loader2 className="w-4 h-4 animate-spin" /> + ) : ( + <Settings className="w-4 h-4" /> + )} + </Button> + </div> + </div> + </PopoverContent> + </Popover> + + {/* 동기화 진행 다이얼로그 */} + <Dialog open={isDialogOpen} onOpenChange={setIsDialogOpen}> + <DialogContent className="sm:max-w-md"> + <DialogHeader> + <DialogTitle>SHI 시스템으로 동기화</DialogTitle> + <DialogDescription> + 변경된 문서 데이터를 SHI 시스템으로 전송합니다. + </DialogDescription> + </DialogHeader> + + <div className="space-y-4"> + {syncStatus && !statusError && ( + <div className="rounded-lg border p-4 space-y-3"> + <div className="flex items-center justify-between text-sm"> + <span>전송 대상</span> + <span className="font-medium">{syncStatus.pendingChanges || 0}건</span> + </div> + + <div className="text-xs text-muted-foreground"> + 문서, 리비전, 첨부파일의 변경사항이 포함됩니다. + </div> + + {isSyncing && ( + <div className="space-y-2"> + <div className="flex items-center justify-between text-sm"> + <span>진행률</span> + <span>{syncProgress}%</span> + </div> + <Progress value={syncProgress} className="h-2" /> + </div> + )} + </div> + )} + + {statusError && ( + <div className="rounded-lg border border-red-200 p-4"> + <div className="text-sm text-red-600"> + 동기화 상태를 확인할 수 없습니다. 네트워크 연결을 확인해주세요. + </div> + </div> + )} + + <div className="flex justify-end gap-2"> + <Button + variant="outline" + onClick={() => setIsDialogOpen(false)} + disabled={isSyncing} + > + 취소 + </Button> + <Button + onClick={handleSync} + disabled={isSyncing || !canSync} + > + {isSyncing ? ( + <> + <Loader2 className="w-4 h-4 mr-2 animate-spin" /> + 동기화 중... + </> + ) : ( + <> + <Send className="w-4 h-4 mr-2" /> + 동기화 시작 + </> + )} + </Button> + </div> + </div> + </DialogContent> + </Dialog> + </> + ) +}
\ No newline at end of file diff --git a/lib/vendor-document-list/ship/simplified-document-edit-dialog.tsx b/lib/vendor-document-list/ship/simplified-document-edit-dialog.tsx new file mode 100644 index 00000000..933df263 --- /dev/null +++ b/lib/vendor-document-list/ship/simplified-document-edit-dialog.tsx @@ -0,0 +1,287 @@ +"use client" + +import * as React from "react" +import { useForm } from "react-hook-form" +import { zodResolver } from "@hookform/resolvers/zod" +import { z } from "zod" +import { toast } from "sonner" + +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { Button } from "@/components/ui/button" +import { Input } from "@/components/ui/input" +import { Textarea } from "@/components/ui/textarea" +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { Calendar as CalendarComponent } from "@/components/ui/calendar" +import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" +import { Calendar, Edit, Loader2 } from "lucide-react" +import { format } from "date-fns" +import { ko } from "date-fns/locale" +import { cn } from "@/lib/utils" +import { EnhancedDocumentsView } from "@/db/schema/vendorDocu" + +// 단순화된 문서 편집 스키마 +const documentEditSchema = z.object({ + docNumber: z.string().min(1, "문서번호는 필수입니다"), + title: z.string().min(1, "제목은 필수입니다"), + pic: z.string().optional(), + status: z.string().min(1, "상태는 필수입니다"), + issuedDate: z.date().optional(), + description: z.string().optional(), +}) + +type DocumentEditSchema = z.infer<typeof documentEditSchema> + +const statusOptions = [ + { value: "ACTIVE", label: "활성" }, + { value: "INACTIVE", label: "비활성" }, + { value: "COMPLETED", label: "완료" }, + { value: "CANCELLED", label: "취소" }, +] + +interface SimplifiedDocumentEditDialogProps { + open: boolean + onOpenChange: (open: boolean) => void + document: EnhancedDocumentsView | null + projectType: "ship" | "plant" +} + +export function SimplifiedDocumentEditDialog({ + open, + onOpenChange, + document, + projectType, +}: SimplifiedDocumentEditDialogProps) { + const [isUpdating, setIsUpdating] = React.useState(false) + + const form = useForm<DocumentEditSchema>({ + resolver: zodResolver(documentEditSchema), + defaultValues: { + docNumber: "", + title: "", + pic: "", + status: "ACTIVE", + issuedDate: undefined, + description: "", + }, + }) + + // 폼 초기화 + React.useEffect(() => { + if (document) { + form.reset({ + docNumber: document.docNumber, + title: document.title, + pic: document.pic || "", + status: document.status, + issuedDate: document.issuedDate ? new Date(document.issuedDate) : undefined, + description: "", + }) + } + }, [document, form]) + + async function onSubmit(data: DocumentEditSchema) { + if (!document) return + + setIsUpdating(true) + try { + // 실제 업데이트 API 호출 (구현 필요) + // await updateDocumentInfo({ documentId: document.documentId, ...data }) + + toast.success("문서 정보가 업데이트되었습니다") + onOpenChange(false) + } catch (error) { + toast.error("업데이트 중 오류가 발생했습니다") + console.error(error) + } finally { + setIsUpdating(false) + } + } + + return ( + <Dialog open={open} onOpenChange={onOpenChange}> + <DialogContent className="sm:max-w-md"> + <DialogHeader> + <DialogTitle className="flex items-center gap-2"> + <Edit className="w-5 h-5" /> + 문서 정보 수정 + </DialogTitle> + <DialogDescription> + {document ? `${document.docNumber}의 기본 정보를 수정합니다.` : "문서 기본 정보를 수정합니다."} + </DialogDescription> + </DialogHeader> + + <Form {...form}> + <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4"> + <FormField + control={form.control} + name="docNumber" + render={({ field }) => ( + <FormItem> + <FormLabel>문서번호</FormLabel> + <FormControl> + <Input {...field} disabled={projectType === "ship"} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="title" + render={({ field }) => ( + <FormItem> + <FormLabel>제목</FormLabel> + <FormControl> + <Input {...field} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <div className="grid grid-cols-2 gap-4"> + <FormField + control={form.control} + name="pic" + render={({ field }) => ( + <FormItem> + <FormLabel>담당자 (PIC)</FormLabel> + <FormControl> + <Input {...field} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="status" + render={({ field }) => ( + <FormItem> + <FormLabel>상태</FormLabel> + <Select onValueChange={field.onChange} value={field.value}> + <FormControl> + <SelectTrigger> + <SelectValue /> + </SelectTrigger> + </FormControl> + <SelectContent> + {statusOptions.map((option) => ( + <SelectItem key={option.value} value={option.value}> + {option.label} + </SelectItem> + ))} + </SelectContent> + </Select> + <FormMessage /> + </FormItem> + )} + /> + </div> + + <FormField + control={form.control} + name="issuedDate" + render={({ field }) => ( + <FormItem> + <FormLabel>발행일</FormLabel> + <Popover> + <PopoverTrigger asChild> + <FormControl> + <Button + variant="outline" + className={cn( + "w-full pl-3 text-left font-normal", + !field.value && "text-muted-foreground" + )} + > + {field.value ? ( + format(field.value, "yyyy년 MM월 dd일", { locale: ko }) + ) : ( + <span>날짜를 선택하세요</span> + )} + <Calendar className="ml-auto h-4 w-4 opacity-50" /> + </Button> + </FormControl> + </PopoverTrigger> + <PopoverContent className="w-auto p-0" align="start"> + <CalendarComponent + mode="single" + selected={field.value} + onSelect={field.onChange} + disabled={(date) => date > new Date()} + initialFocus + /> + </PopoverContent> + </Popover> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="description" + render={({ field }) => ( + <FormItem> + <FormLabel>설명 (선택)</FormLabel> + <FormControl> + <Textarea {...field} placeholder="문서에 대한 설명을 입력하세요" rows={3} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <DialogFooter> + <Button + type="button" + variant="outline" + onClick={() => onOpenChange(false)} + disabled={isUpdating} + > + 취소 + </Button> + <Button type="submit" disabled={isUpdating}> + {isUpdating ? ( + <> + <Loader2 className="mr-2 h-4 w-4 animate-spin" /> + 저장 중... + </> + ) : ( + <> + <Edit className="mr-2 h-4 w-4" /> + 저장 + </> + )} + </Button> + </DialogFooter> + </form> + </Form> + </DialogContent> + </Dialog> + ) +}
\ No newline at end of file diff --git a/lib/vendor-document-list/ship/stage-revision-expanded-content.tsx b/lib/vendor-document-list/ship/stage-revision-expanded-content.tsx new file mode 100644 index 00000000..6b9cffb9 --- /dev/null +++ b/lib/vendor-document-list/ship/stage-revision-expanded-content.tsx @@ -0,0 +1,752 @@ +"use client" + +import * as React from "react" +import { WebViewerInstance } from "@pdftron/webviewer" +import { formatDate } from "@/lib/utils" +import { Badge } from "@/components/ui/badge" +import { Button } from "@/components/ui/button" +import { ScrollArea } from "@/components/ui/scroll-area" +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table" +import { + FileText, + User, + Calendar, + Clock, + CheckCircle, + AlertTriangle, + ChevronDown, + ChevronRight, + Upload, + Eye, + Download, + FileIcon, + MoreHorizontal, + Loader2 +} from "lucide-react" +import { cn } from "@/lib/utils" +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" +import type { EnhancedDocument } from "@/types/enhanced-documents" + +// 유틸리티 함수들 +const getStatusColor = (status: string) => { + switch (status) { + case 'COMPLETED': case 'APPROVED': return 'bg-green-100 text-green-800' + case 'IN_PROGRESS': return 'bg-blue-100 text-blue-800' + case 'SUBMITTED': case 'UNDER_REVIEW': return 'bg-purple-100 text-purple-800' + case 'REJECTED': return 'bg-red-100 text-red-800' + default: return 'bg-gray-100 text-gray-800' + } +} + +const getPriorityColor = (priority: string) => { + switch (priority) { + case 'HIGH': return 'bg-red-100 text-red-800 border-red-200' + case 'MEDIUM': return 'bg-yellow-100 text-yellow-800 border-yellow-200' + case 'LOW': return 'bg-green-100 text-green-800 border-green-200' + default: return 'bg-gray-100 text-gray-800 border-gray-200' + } +} + +const getStatusText = (status: string) => { + switch (status) { + case 'PLANNED': return '계획됨' + case 'IN_PROGRESS': return '진행중' + case 'SUBMITTED': return '제출됨' + case 'UPLOADED': return '등록됨' + case 'UNDER_REVIEW': return '검토중' + case 'APPROVED': return '승인됨' + case 'REJECTED': return '반려됨' + case 'COMPLETED': return '완료됨' + default: return status + } +} + +const getPriorityText = (priority: string) => { + switch (priority) { + case 'HIGH': return '높음' + case 'MEDIUM': return '보통' + case 'LOW': return '낮음' + default: return priority + } +} + +const getFileIconColor = (fileName: string) => { + const ext = fileName.split('.').pop()?.toLowerCase() + switch (ext) { + case 'pdf': return 'text-red-500' + case 'doc': case 'docx': return 'text-blue-500' + case 'xls': case 'xlsx': return 'text-green-500' + case 'dwg': return 'text-amber-500' + default: return 'text-gray-500' + } +} + +interface StageRevisionExpandedContentProps { + document: EnhancedDocument + onUploadRevision: (documentData: EnhancedDocument, stageName?: string, currentRevision?: string, mode?: 'new' | 'append') => void + onStageStatusUpdate?: (stageId: number, status: string) => void + onRevisionStatusUpdate?: (revisionId: number, status: string) => void + projectType: "ship" | "plant" + expandedStages?: Record<number, boolean> + onStageToggle?: (stageId: number) => void +} + +export const StageRevisionExpandedContent = ({ + document: documentData, + onUploadRevision, + onStageStatusUpdate, + onRevisionStatusUpdate, + projectType, + expandedStages = {}, + onStageToggle, +}: StageRevisionExpandedContentProps) => { + // 로컬 상태 관리 + const [localExpandedStages, setLocalExpandedStages] = React.useState<Record<number, boolean>>({}) + const [expandedRevisions, setExpandedRevisions] = React.useState<Set<number>>(new Set()) + + // ✅ 문서 뷰어 상태 관리 + const [viewerOpen, setViewerOpen] = React.useState(false) + const [selectedRevisions, setSelectedRevisions] = React.useState<any[]>([]) + const [instance, setInstance] = React.useState<WebViewerInstance | null>(null) + const [viewerLoading, setViewerLoading] = React.useState(true) + const [fileSetLoading, setFileSetLoading] = React.useState(true) + const viewer = React.useRef<HTMLDivElement>(null) + const initialized = React.useRef(false) + const isCancelled = React.useRef(false) + + // 상위에서 관리하는지 로컬에서 관리하는지 결정 + const isExternallyManaged = onStageToggle !== undefined + const currentExpandedStages = isExternallyManaged ? expandedStages : localExpandedStages + + const handleStageToggle = React.useCallback((stageId: number) => { + if (isExternallyManaged && onStageToggle) { + onStageToggle(stageId) + } else { + setLocalExpandedStages(prev => ({ + ...prev, + [stageId]: !prev[stageId] + })) + } + }, [isExternallyManaged, onStageToggle]) + + const toggleRevisionFiles = React.useCallback((revisionId: number) => { + setExpandedRevisions(prev => { + const newSet = new Set(prev) + if (newSet.has(revisionId)) { + newSet.delete(revisionId) + } else { + newSet.add(revisionId) + } + return newSet + }) + }, []) + + // ✅ PDF 뷰어 정리 함수 + const cleanupHtmlStyle = React.useCallback(() => { + const htmlElement = window.document.documentElement + const originalStyle = htmlElement.getAttribute("style") || "" + const colorSchemeStyle = originalStyle + .split(";") + .map((s) => s.trim()) + .find((s) => s.startsWith("color-scheme:")) + + if (colorSchemeStyle) { + htmlElement.setAttribute("style", colorSchemeStyle + ";") + } else { + htmlElement.removeAttribute("style") + } + }, []) + + // ✅ 문서 뷰어 열기 함수 + const handleViewRevision = React.useCallback((revisions: any[]) => { + setSelectedRevisions(revisions) + setViewerOpen(true) + setViewerLoading(true) + setFileSetLoading(true) + initialized.current = false + }, []) + + // ✅ 파일 다운로드 함수 - 새로운 document-download API 사용 + const handleDownloadFile = React.useCallback(async (attachment: any) => { + console.log(attachment) + try { + // ID를 우선으로 사용, 없으면 filePath 사용 + const queryParam = attachment.id + ? `id=${encodeURIComponent(attachment.id)}` + : `path=${encodeURIComponent(attachment.filePath)}` + + const response = await fetch(`/api/document-download?${queryParam}`) + + if (!response.ok) { + const errorData = await response.json() + throw new Error(errorData.error || '파일 다운로드에 실패했습니다.') + } + + const blob = await response.blob() + const url = window.URL.createObjectURL(blob) + const link = window.document.createElement('a') + link.href = url + link.download = attachment.fileName + window.document.body.appendChild(link) + link.click() + window.document.body.removeChild(link) + window.URL.revokeObjectURL(url) + + console.log('✅ 파일 다운로드 완료:', attachment.fileName) + } catch (error) { + console.error('❌ 파일 다운로드 오류:', error) + // 실제 앱에서는 toast나 alert로 에러 표시 + alert(`파일 다운로드 실패: ${error instanceof Error ? error.message : '알 수 없는 오류'}`) + } + }, []) + + // ✅ WebViewer 초기화 + React.useEffect(() => { + if (viewerOpen && !initialized.current) { + initialized.current = true + isCancelled.current = false + + requestAnimationFrame(() => { + if (viewer.current && !isCancelled.current) { + import("@pdftron/webviewer").then(({ default: WebViewer }) => { + if (isCancelled.current) { + console.log("📛 WebViewer 초기화 취소됨 (Dialog 닫힘)") + return + } + + WebViewer( + { + path: "/pdftronWeb", + licenseKey: "demo:1739264618684:616161d7030000000091db1c97c6f386d41d3506ab5b507381ef2ee2bd", + fullAPI: true, + css: "/globals.css", + }, + viewer.current as HTMLDivElement + ).then(async (instance: WebViewerInstance) => { + if (!isCancelled.current) { + setInstance(instance) + instance.UI.enableFeatures([instance.UI.Feature.MultiTab]) + instance.UI.disableElements(["addTabButton", "multiTabsEmptyPage"]) + setViewerLoading(false) + } + }) + }) + } + }) + } + + return () => { + if (instance) { + instance.UI.dispose() + } + setTimeout(() => cleanupHtmlStyle(), 500) + } + }, [viewerOpen, cleanupHtmlStyle]) + + // ✅ 문서 로드 + React.useEffect(() => { + const loadDocument = async () => { + if (instance && selectedRevisions.length > 0) { + const { UI } = instance + const optionsArray: any[] = [] + + selectedRevisions.forEach((revision) => { + const { attachments } = revision + attachments?.forEach((attachment: any) => { + const { fileName, filePath, fileType } = attachment + const fileTypeCur = fileType ?? "" + + const options = { + filename: fileName, + ...(fileTypeCur.includes("xlsx") && { + officeOptions: { + formatOptions: { + applyPageBreaksToSheet: true, + }, + }, + }), + } + + optionsArray.push({ filePath, options }) + }) + }) + + const tabIds = [] + for (const option of optionsArray) { + const { filePath, options } = option + try { + const response = await fetch(filePath) + const blob = await response.blob() + const tab = await UI.TabManager.addTab(blob, options) + tabIds.push(tab) + } catch (error) { + console.error("파일 로드 실패:", filePath, error) + } + } + + if (tabIds.length > 0) { + await UI.TabManager.setActiveTab(tabIds[0]) + } + + setFileSetLoading(false) + } + } + loadDocument() + }, [instance, selectedRevisions]) + + // ✅ 뷰어 닫기 + const handleCloseViewer = React.useCallback(async () => { + if (!fileSetLoading) { + isCancelled.current = true + + if (instance) { + try { + await instance.UI.dispose() + setInstance(null) + } catch (e) { + console.warn("dispose error", e) + } + } + + setViewerLoading(false) + setViewerOpen(false) + setTimeout(() => cleanupHtmlStyle(), 1000) + } + }, [fileSetLoading, instance, cleanupHtmlStyle]) + + // 뷰에서 가져온 allStages 데이터를 바로 사용 + const stagesWithRevisions = documentData.allStages || [] + + console.log(stagesWithRevisions) + + if (stagesWithRevisions.length === 0) { + return ( + <div className="p-6 text-center text-gray-500"> + <FileText className="w-12 h-12 mx-auto mb-4 text-gray-300" /> + <h4 className="font-medium mb-2">스테이지 정보가 없습니다</h4> + <p className="text-sm">이 문서에 대한 스테이지를 먼저 설정해주세요.</p> + </div> + ) + } + + return ( + <> + <div className="w-full max-w-none bg-gray-50" onClick={(e) => e.stopPropagation()}> + <div className="p-4"> + <div className="flex items-center justify-between mb-4"> + <div> + <h4 className="font-semibold flex items-center gap-2"> + <FileText className="w-4 h-4" /> + 스테이지별 리비전 현황 + </h4> + <p className="text-xs text-gray-600 mt-1"> + 총 {stagesWithRevisions.length}개 스테이지, {stagesWithRevisions.reduce((acc, stage) => acc + (stage.revisions?.length || 0), 0)}개 리비전 + </p> + </div> + {/* <Button + size="sm" + onClick={() => onUploadRevision(document, undefined, undefined, 'new')} + className="flex items-center gap-2" + > + <Upload className="w-3 h-3" /> + 새 리비전 업로드 + </Button> */} + </div> + + <ScrollArea className="h-[400px] w-full"> + <div className="space-y-3 pr-4"> + {stagesWithRevisions.map((stage) => { + const isExpanded = currentExpandedStages[stage.id] || false + const revisions = stage.revisions || [] + + return ( + <div key={stage.id} className="bg-white rounded border shadow-sm overflow-hidden"> + {/* 스테이지 헤더 - 전체 영역 클릭 가능 */} + <div + className="py-2 px-3 bg-gray-50 border-b cursor-pointer hover:bg-gray-100 transition-colors" + onClick={(e) => { + e.preventDefault() + e.stopPropagation() + handleStageToggle(stage.id) + }} + > + <div className="flex items-center justify-between"> + <div className="flex items-center gap-3"> + {/* 버튼 영역 - 이제 시각적 표시만 담당 */} + <div className="flex items-center gap-2"> + <div className="flex items-center gap-2"> + <div className="w-6 h-6 rounded-full bg-white border-2 border-gray-300 flex items-center justify-center text-xs font-medium"> + {stage.stageOrder || 1} + </div> + <div className={cn( + "w-2 h-2 rounded-full", + stage.stageStatus === 'COMPLETED' ? 'bg-green-500' : + stage.stageStatus === 'IN_PROGRESS' ? 'bg-blue-500' : + stage.stageStatus === 'SUBMITTED' ? 'bg-purple-500' : + 'bg-gray-300' + )} /> + {isExpanded ? + <ChevronDown className="w-3 h-3 text-gray-500" /> : + <ChevronRight className="w-3 h-3 text-gray-500" /> + } + </div> + </div> + + <div className="flex-1"> + <div className="flex items-center gap-2"> + <div className="font-medium text-sm">{stage.stageName}</div> + <Badge className={cn("text-xs", getStatusColor(stage.stageStatus))}> + {getStatusText(stage.stageStatus)} + </Badge> + <span className="text-xs text-gray-500"> + {revisions.length}개 리비전 + </span> + </div> + </div> + </div> + + <div className="flex items-center gap-4"> + <div className="grid grid-cols-2 gap-2 text-xs"> + <div> + <span className="text-gray-500">계획: </span> + <span className="font-medium">{stage.planDate ? formatDate(stage.planDate) : '-'}</span> + </div> + {stage.actualDate && ( + <div> + <span className="text-gray-500">완료: </span> + <span className="font-medium">{formatDate(stage.actualDate)}</span> + </div> + )} + {stage.assigneeName && ( + <div className="col-span-2 flex items-center gap-1 text-gray-600"> + <User className="w-3 h-3" /> + <span className="text-xs">{stage.assigneeName}</span> + </div> + )} + </div> + + {/* 스테이지 액션 메뉴 - 클릭 이벤트 전파 차단 */} + <div + onClick={(e) => { + e.stopPropagation() // 액션 메뉴 클릭 시 스테이지 토글 방지 + }} + > + <DropdownMenu> + <DropdownMenuTrigger asChild> + <Button + variant="ghost" + size="sm" + className="h-7 w-7 p-0" + > + <MoreHorizontal className="h-3 w-3" /> + </Button> + </DropdownMenuTrigger> + <DropdownMenuContent align="end"> + {onStageStatusUpdate && ( + <> + <DropdownMenuItem onClick={() => onStageStatusUpdate(stage.id, 'IN_PROGRESS')}> + 진행 시작 + </DropdownMenuItem> + <DropdownMenuItem onClick={() => onStageStatusUpdate(stage.id, 'COMPLETED')}> + 완료 처리 + </DropdownMenuItem> + </> + )} + <DropdownMenuItem onClick={() => onUploadRevision(documentData, stage.stageName)}> + 리비전 업로드 + </DropdownMenuItem> + {/* ✅ 스테이지에 첨부파일이 있는 리비전이 있을 때만 문서 보기 버튼 표시 */} + {revisions.some(rev => rev.attachments && rev.attachments.length > 0) && ( + <DropdownMenuItem onClick={() => handleViewRevision(revisions.filter(rev => rev.attachments && rev.attachments.length > 0))}> + <Eye className="w-3 h-3 mr-1" /> + 스테이지 문서 보기 + </DropdownMenuItem> + )} + </DropdownMenuContent> + </DropdownMenu> + </div> + </div> + </div> + </div> + + {/* 리비전 목록 - 테이블 형태 */} + {isExpanded && ( + <div className="max-h-72 overflow-y-auto"> + {revisions.length > 0 ? ( + <div className="border-t"> + <Table> + <TableHeader> + <TableRow className="bg-gray-50/50 h-8"> + <TableHead className="w-16 py-1 px-2 text-xs"></TableHead> + <TableHead className="w-16 py-1 px-2 text-xs">리비전</TableHead> + <TableHead className="w-20 py-1 px-2 text-xs">상태</TableHead> + {documentData.drawingKind === 'B3' && ( + <TableHead className="w-24 py-1 px-2 text-xs">용도</TableHead> + )} + <TableHead className="w-24 py-1 px-2 text-xs">업로더</TableHead> + <TableHead className="w-32 py-1 px-2 text-xs">등록일</TableHead> + <TableHead className="w-32 py-1 px-2 text-xs">제출일</TableHead> + <TableHead className="w-32 py-1 px-2 text-xs">승인/반려일</TableHead> + <TableHead className="min-w-[120px] py-1 px-2 text-xs">첨부파일</TableHead> + <TableHead className="w-16 py-1 px-2 text-xs">액션</TableHead> + <TableHead className="min-w-0 py-1 px-2 text-xs">코멘트</TableHead> + </TableRow> + </TableHeader> + <TableBody> + {revisions.map((revision) => { + const hasAttachments = revision.attachments && revision.attachments.length > 0 + + return ( + <TableRow key={revision.id} className="hover:bg-gray-50 h-10"> + {/* 리비전 */} + <TableCell className="py-1 px-2"> + <span className="text-xs font-semibold"> + {revision.uploaderType === "vendor" ? "To SHI" : "From SHI"} + </span> + </TableCell> + + <TableCell className="py-1 px-2"> + <span className="font-mono text-xs font-semibold bg-gray-100 px-1.5 py-0.5 rounded"> + {revision.revision} + </span> + </TableCell> + + {/* 상태 */} + <TableCell className="py-1 px-2"> + <Badge className={cn("text-xs px-1.5 py-0.5", getStatusColor(revision.revisionStatus))}> + {getStatusText(revision.revisionStatus)} + </Badge> + </TableCell> + + {/* ✅ B3 문서일 때만 Usage 셀 표시 */} + {documentData.drawingKind === 'B3' && ( + <TableCell className="py-1 px-2"> + {revision.usage ? ( + <span className="text-xs bg-blue-50 text-blue-700 px-1.5 py-0.5 rounded border border-blue-200"> + {revision.usage} + </span> + ) : ( + <span className="text-gray-400 text-xs">-</span> + )} + </TableCell> + )} + + {/* 업로더 */} + <TableCell className="py-1 px-2"> + <div className="flex items-center gap-1"> + <User className="w-3 h-3 text-gray-400" /> + <span className="text-xs truncate max-w-[60px]">{revision.uploaderName || '-'}</span> + </div> + </TableCell> + {/* 제출일 */} + <TableCell className="py-1 px-2"> + <span className="text-xs text-gray-600"> + {revision.uploadedAt ? formatDate(revision.uploadedAt) : '-'} + </span> + </TableCell> + + {/* 제출일 */} + <TableCell className="py-1 px-2"> + <span className="text-xs text-gray-600"> + {revision.externalSentDate ? formatDate(revision.externalSentDate) : '-'} + </span> + </TableCell> + + {/* 승인/반려일 */} + <TableCell className="py-1 px-2"> + <div className="text-xs text-gray-600"> + {revision.approvedDate && ( + <div className="flex items-center gap-1 text-green-600"> + <CheckCircle className="w-3 h-3" /> + <span className="text-xs">{formatDate(revision.approvedDate)}</span> + </div> + )} + {revision.rejectedDate && ( + <div className="flex items-center gap-1 text-red-600"> + <AlertTriangle className="w-3 h-3" /> + <span className="text-xs">{formatDate(revision.rejectedDate)}</span> + </div> + )} + {revision.reviewStartDate && !revision.approvedDate && !revision.rejectedDate && ( + <div className="flex items-center gap-1 text-blue-600"> + <Clock className="w-3 h-3" /> + <span className="text-xs">{formatDate(revision.reviewStartDate)}</span> + </div> + )} + {!revision.approvedDate && !revision.rejectedDate && !revision.reviewStartDate && ( + <span className="text-gray-400 text-xs">-</span> + )} + </div> + </TableCell> + + {/* ✅ 첨부파일 - 클릭 시 다운로드, 별도 뷰어 버튼 */} + <TableCell className="py-1 px-2"> + {hasAttachments ? ( + <div className="flex items-center gap-1 flex-wrap"> + {/* 파일 아이콘들 - 클릭 시 다운로드 */} + {revision.attachments.slice(0, 4).map((file: any) => ( + <Button + key={file.id} + variant="ghost" + size="sm" + onClick={() => handleDownloadFile(file)} + className="p-0.5 h-auto hover:bg-blue-50 rounded" + title={`${file.fileName} - 클릭해서 다운로드`} + > + <FileIcon className={cn("w-3 h-3", getFileIconColor(file.fileName))} /> + </Button> + ))} + {revision.attachments.length > 4 && ( + <span + className="text-xs text-gray-500 ml-0.5" + title={`총 ${revision.attachments.length}개 파일`} + > + +{revision.attachments.length - 4} + </span> + )} + {/* ✅ 모든 파일 보기 버튼 - 뷰어 열기 */} + <Button + variant="ghost" + size="sm" + onClick={() => handleViewRevision([revision])} + className="p-0.5 h-auto hover:bg-green-50 rounded ml-1" + title="모든 파일 보기" + > + <Eye className="w-3 h-3 text-green-600" /> + </Button> + </div> + ) : ( + <span className="text-gray-400 text-xs">-</span> + )} + </TableCell> + + {/* 액션 */} + <TableCell className="py-1 px-2"> + <div className="flex gap-0.5"> + {revision.revisionStatus === 'UNDER_REVIEW' && onRevisionStatusUpdate && ( + <> + <Button + size="sm" + variant="ghost" + onClick={() => onRevisionStatusUpdate(revision.id, 'APPROVED')} + className="text-green-600 hover:bg-green-50 h-6 px-1" + title="승인" + > + <CheckCircle className="w-3 h-3" /> + </Button> + <Button + size="sm" + variant="ghost" + onClick={() => onRevisionStatusUpdate(revision.id, 'REJECTED')} + className="text-red-600 hover:bg-red-50 h-6 px-1" + title="반려" + > + <AlertTriangle className="w-3 h-3" /> + </Button> + </> + )} + <Button + size="sm" + variant="ghost" + onClick={() => onUploadRevision(documentData, stage.stageName, revision.revision, 'append')} + className="text-blue-600 hover:bg-blue-50 h-6 px-1" + title="파일 추가" + > + <Upload className="w-3 h-3" /> + </Button> + </div> + </TableCell> + + {/* 코멘트 */} + <TableCell className="py-1 px-2"> + {revision.comment ? ( + <div className="max-w-24"> + <p className="text-xs text-gray-700 bg-gray-50 p-1 rounded truncate" title={revision.comment}> + {revision.comment} + </p> + </div> + ) : ( + <span className="text-gray-400 text-xs">-</span> + )} + </TableCell> + </TableRow> + ) + })} + </TableBody> + </Table> + </div> + ) : ( + <div className="p-6 text-center"> + <div className="flex flex-col items-center gap-3"> + <div className="w-12 h-12 rounded-full bg-gray-100 flex items-center justify-center"> + <FileText className="w-6 h-6 text-gray-300" /> + </div> + <div> + <h5 className="font-medium text-gray-700 mb-1 text-sm">리비전이 없습니다</h5> + <p className="text-xs text-gray-500 mb-3">아직 이 스테이지에 업로드된 리비전이 없습니다</p> + <Button + size="sm" + onClick={() => onUploadRevision(documentData, stage.stageName, undefined, 'new')} + className="text-xs" + > + <Upload className="w-3 h-3 mr-1" /> + 첫 리비전 업로드 + </Button> + </div> + </div> + </div> + )} + </div> + )} + </div> + ) + })} + </div> + </ScrollArea> + </div> + </div> + + {/* ✅ 통합된 문서 뷰어 다이얼로그 */} + <Dialog open={viewerOpen} onOpenChange={handleCloseViewer}> + <DialogContent className="w-[90vw] h-[90vh]" style={{ maxWidth: "none" }}> + <DialogHeader className="h-[38px]"> + <DialogTitle>문서 미리보기</DialogTitle> + <DialogDescription> + {selectedRevisions.length === 1 + ? `리비전 ${selectedRevisions[0]?.revision} 첨부파일` + : `${selectedRevisions.length}개 리비전 첨부파일` + } + </DialogDescription> + </DialogHeader> + <div + ref={viewer} + style={{ height: "calc(90vh - 20px - 38px - 1rem - 48px)" }} + > + {viewerLoading && ( + <div className="flex flex-col items-center justify-center py-12"> + <Loader2 className="h-8 w-8 text-blue-500 animate-spin mb-4" /> + <p className="text-sm text-muted-foreground"> + 문서 뷰어 로딩 중... + </p> + </div> + )} + </div> + </DialogContent> + </Dialog> + </> + ) +}
\ No newline at end of file diff --git a/lib/vendor-document-list/ship/stage-revision-sheet.tsx b/lib/vendor-document-list/ship/stage-revision-sheet.tsx new file mode 100644 index 00000000..2cc22cce --- /dev/null +++ b/lib/vendor-document-list/ship/stage-revision-sheet.tsx @@ -0,0 +1,86 @@ +// StageRevisionDrawer.tsx +// Slide‑up drawer (bottom) that shows StageRevisionExpandedContent. +// Requires shadcn/ui Drawer primitives already installed. + +"use client" + +import * as React from "react" +import { + Drawer, + DrawerContent, + DrawerHeader, + DrawerTitle, + DrawerDescription, +} from "@/components/ui/drawer" + +import type { EnhancedDocument } from "@/types/enhanced-documents" +import { StageRevisionExpandedContent } from "./stage-revision-expanded-content" + +export interface StageRevisionDrawerProps { + /** whether the drawer is open */ + open: boolean + /** callback invoked when the open state should change */ + onOpenChange: (open: boolean) => void + /** the document whose stages / revisions are displayed */ + document: EnhancedDocument | null + /** project type to propagate further */ + projectType: "ship" | "plant" + /** callbacks forwarded to StageRevisionExpandedContent */ + onUploadRevision: ( + doc: EnhancedDocument, + stageName?: string, + currentRevision?: string, + mode?: "new" | "append" + ) => void + onViewRevision: (revisions: any[]) => void + onStageStatusUpdate?: (stageId: number, status: string) => void + onRevisionStatusUpdate?: (revisionId: number, status: string) => void +} + +/** + * Bottom‑anchored Drawer that presents Stage / Revision details. + * Fills up to 85 vh and slides up from the bottom edge. + */ +export const StageRevisionDrawer: React.FC<StageRevisionDrawerProps> = ({ + open, + onOpenChange, + document, + projectType, + onUploadRevision, + onViewRevision, + onStageStatusUpdate, + onRevisionStatusUpdate, +}) => { + return ( + <Drawer open={open} onOpenChange={onOpenChange}> + {/* No trigger – controlled by parent */} + <DrawerContent className="h-[85vh] flex flex-col p-0"> + <DrawerHeader className="border-b p-4"> + <DrawerTitle>스테이지 / 리비전 상세</DrawerTitle> + {document && ( + <DrawerDescription className="text-xs text-muted-foreground truncate"> + {document.docNumber} — {document.title} + </DrawerDescription> + )} + </DrawerHeader> + + <div className="flex-1 overflow-auto"> + {document ? ( + <StageRevisionExpandedContent + document={document} + projectType={projectType} + onUploadRevision={onUploadRevision} + onViewRevision={onViewRevision} + onStageStatusUpdate={onStageStatusUpdate} + onRevisionStatusUpdate={onRevisionStatusUpdate} + /> + ) : ( + <div className="flex h-full items-center justify-center text-sm text-gray-500"> + 문서가 선택되지 않았습니다. + </div> + )} + </div> + </DrawerContent> + </Drawer> + ) +} diff --git a/lib/vendor-document-list/ship/swp-workflow-panel.tsx b/lib/vendor-document-list/ship/swp-workflow-panel.tsx new file mode 100644 index 00000000..ded306e7 --- /dev/null +++ b/lib/vendor-document-list/ship/swp-workflow-panel.tsx @@ -0,0 +1,370 @@ +"use client" + +import * as React from "react" +import { Send, Eye, CheckCircle, Clock, RefreshCw, AlertTriangle, Loader2 } from "lucide-react" +import { toast } from "sonner" + +import { Button } from "@/components/ui/button" +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover" +import { Badge } from "@/components/ui/badge" +import { Separator } from "@/components/ui/separator" +import { Progress } from "@/components/ui/progress" +import type { EnhancedDocument } from "@/types/enhanced-documents" + +interface SWPWorkflowPanelProps { + contractId: number + documents: EnhancedDocument[] + onWorkflowUpdate?: () => void +} + +type WorkflowStatus = + | 'IDLE' // 대기 상태 + | 'SUBMITTED' // 목록 전송됨 + | 'UNDER_REVIEW' // 검토 중 + | 'CONFIRMED' // 컨펌됨 + | 'REVISION_REQUIRED' // 수정 요청됨 + | 'RESUBMITTED' // 재전송됨 + | 'APPROVED' // 최종 승인됨 + +interface WorkflowState { + status: WorkflowStatus + lastUpdatedAt?: string + pendingActions: string[] + confirmationData?: any + revisionComments?: string[] + approvalData?: any +} + +export function SWPWorkflowPanel({ + contractId, + documents, + onWorkflowUpdate +}: SWPWorkflowPanelProps) { + const [workflowState, setWorkflowState] = React.useState<WorkflowState | null>(null) + const [isLoading, setIsLoading] = React.useState(false) + const [actionProgress, setActionProgress] = React.useState(0) + + // 워크플로우 상태 조회 + const fetchWorkflowStatus = async () => { + setIsLoading(true) + try { + const response = await fetch(`/api/sync/workflow/status?contractId=${contractId}&targetSystem=SWP`) + if (!response.ok) throw new Error('Failed to fetch workflow status') + + const status = await response.json() + setWorkflowState(status) + } catch (error) { + console.error('Failed to fetch workflow status:', error) + toast.error('워크플로우 상태를 확인할 수 없습니다') + } finally { + setIsLoading(false) + } + } + + // 컴포넌트 마운트 시 상태 조회 + React.useEffect(() => { + fetchWorkflowStatus() + }, [contractId]) + + // 워크플로우 액션 실행 + const executeWorkflowAction = async (action: string) => { + setActionProgress(0) + setIsLoading(true) + + try { + // 진행률 시뮬레이션 + const progressInterval = setInterval(() => { + setActionProgress(prev => Math.min(prev + 20, 90)) + }, 200) + + const response = await fetch('/api/sync/workflow/action', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + contractId, + targetSystem: 'SWP', + action, + documents: documents.map(doc => ({ id: doc.id, documentNo: doc.documentNo })) + }) + }) + + if (!response.ok) { + const errorData = await response.json() + throw new Error(errorData.message || 'Workflow action failed') + } + + const result = await response.json() + + clearInterval(progressInterval) + setActionProgress(100) + + setTimeout(() => { + setActionProgress(0) + + if (result?.success) { + toast.success( + `${getActionLabel(action)} 완료`, + { description: result?.message || '워크플로우가 성공적으로 진행되었습니다.' } + ) + } else { + toast.error( + `${getActionLabel(action)} 실패`, + { description: result?.message || '워크플로우 실행에 실패했습니다.' } + ) + } + + fetchWorkflowStatus() // 상태 갱신 + onWorkflowUpdate?.() + }, 500) + + } catch (error) { + setActionProgress(0) + + toast.error(`${getActionLabel(action)} 실패`, { + description: error instanceof Error ? error.message : '알 수 없는 오류가 발생했습니다.' + }) + } finally { + setIsLoading(false) + } + } + + const getActionLabel = (action: string): string => { + switch (action) { + case 'SUBMIT_LIST': return '목록 전송' + case 'CHECK_CONFIRMATION': return '컨펌 확인' + case 'RESUBMIT_REVISED': return '수정본 재전송' + case 'CHECK_APPROVAL': return '승인 확인' + default: return action + } + } + + const getStatusBadge = () => { + if (isLoading) { + return <Badge variant="secondary">확인 중...</Badge> + } + + if (!workflowState) { + return <Badge variant="destructive">오류</Badge> + } + + switch (workflowState.status) { + case 'IDLE': + return <Badge variant="secondary">대기</Badge> + case 'SUBMITTED': + return ( + <Badge variant="default" className="gap-1 bg-blue-500"> + <Clock className="w-3 h-3" /> + 전송됨 + </Badge> + ) + case 'UNDER_REVIEW': + return ( + <Badge variant="default" className="gap-1 bg-yellow-500"> + <Eye className="w-3 h-3" /> + 검토 중 + </Badge> + ) + case 'CONFIRMED': + return ( + <Badge variant="default" className="gap-1 bg-green-500"> + <CheckCircle className="w-3 h-3" /> + 컨펌됨 + </Badge> + ) + case 'REVISION_REQUIRED': + return ( + <Badge variant="destructive" className="gap-1"> + <AlertTriangle className="w-3 h-3" /> + 수정 요청 + </Badge> + ) + case 'RESUBMITTED': + return ( + <Badge variant="default" className="gap-1 bg-orange-500"> + <RefreshCw className="w-3 h-3" /> + 재전송됨 + </Badge> + ) + case 'APPROVED': + return ( + <Badge variant="default" className="gap-1 bg-green-600"> + <CheckCircle className="w-3 h-3" /> + 승인 완료 + </Badge> + ) + default: + return <Badge variant="secondary">알 수 없음</Badge> + } + } + + const getAvailableActions = (): string[] => { + if (!workflowState) return [] + + switch (workflowState.status) { + case 'IDLE': + return ['SUBMIT_LIST'] + case 'SUBMITTED': + return ['CHECK_CONFIRMATION'] + case 'UNDER_REVIEW': + return ['CHECK_CONFIRMATION'] + case 'CONFIRMED': + return [] // 컨펌되면 자동으로 다음 단계로 + case 'REVISION_REQUIRED': + return ['RESUBMIT_REVISED'] + case 'RESUBMITTED': + return ['CHECK_APPROVAL'] + case 'APPROVED': + return [] // 완료 상태 + default: + return [] + } + } + + const availableActions = getAvailableActions() + + return ( + <Popover> + <PopoverTrigger asChild> + <div className="flex items-center gap-3"> + <Button + variant="outline" + size="sm" + className="flex items-center border-orange-200 hover:bg-orange-50" + disabled={isLoading} + > + {isLoading ? ( + <Loader2 className="w-4 h-4 animate-spin" /> + ) : ( + <RefreshCw className="w-4 h-4" /> + )} + <span className="hidden sm:inline">SWP 워크플로우</span> + {workflowState?.pendingActions && workflowState.pendingActions.length > 0 && ( + <Badge + variant="destructive" + className="h-5 w-5 p-0 text-xs flex items-center justify-center" + > + {workflowState.pendingActions.length} + </Badge> + )} + </Button> + </div> + </PopoverTrigger> + + <PopoverContent className="w-80"> + <div className="space-y-4"> + <div className="space-y-2"> + <h4 className="font-medium">SWP 워크플로우 상태</h4> + <div className="flex items-center justify-between"> + <span className="text-sm text-muted-foreground">현재 상태</span> + {getStatusBadge()} + </div> + </div> + + {workflowState && ( + <div className="space-y-3"> + <Separator /> + + {/* 대기 중인 액션들 */} + {workflowState.pendingActions && workflowState.pendingActions.length > 0 && ( + <div className="space-y-2"> + <div className="text-sm font-medium">대기 중인 작업</div> + {workflowState.pendingActions.map((action, index) => ( + <Badge key={index} variant="outline" className="mr-1"> + {getActionLabel(action)} + </Badge> + ))} + </div> + )} + + {/* 수정 요청 사항 */} + {workflowState.revisionComments && workflowState.revisionComments.length > 0 && ( + <div className="space-y-2"> + <div className="text-sm font-medium text-red-600">수정 요청 사항</div> + <div className="text-xs text-muted-foreground space-y-1"> + {workflowState.revisionComments.map((comment, index) => ( + <div key={index} className="p-2 bg-red-50 rounded text-red-700"> + {comment} + </div> + ))} + </div> + </div> + )} + + {/* 마지막 업데이트 시간 */} + {workflowState.lastUpdatedAt && ( + <div className="text-sm"> + <div className="text-muted-foreground">마지막 업데이트</div> + <div className="font-medium"> + {new Date(workflowState.lastUpdatedAt).toLocaleString()} + </div> + </div> + )} + + {/* 진행률 표시 */} + {isLoading && actionProgress > 0 && ( + <div className="space-y-2"> + <div className="flex items-center justify-between text-sm"> + <span>진행률</span> + <span>{actionProgress}%</span> + </div> + <Progress value={actionProgress} className="h-2" /> + </div> + )} + </div> + )} + + <Separator /> + + {/* 액션 버튼들 */} + <div className="space-y-2"> + {availableActions.length > 0 ? ( + availableActions.map((action) => ( + <Button + key={action} + onClick={() => executeWorkflowAction(action)} + disabled={isLoading} + className="w-full justify-start" + size="sm" + variant={action.includes('SUBMIT') || action.includes('RESUBMIT') ? 'default' : 'outline'} + > + {isLoading ? ( + <Loader2 className="w-4 h-4 mr-2 animate-spin" /> + ) : ( + <Send className="w-4 h-4 mr-2" /> + )} + {getActionLabel(action)} + </Button> + )) + ) : ( + <div className="text-sm text-muted-foreground text-center py-2"> + {workflowState?.status === 'APPROVED' + ? '워크플로우가 완료되었습니다.' + : '실행 가능한 작업이 없습니다.'} + </div> + )} + + {/* 상태 새로고침 버튼 */} + <Button + variant="outline" + size="sm" + onClick={fetchWorkflowStatus} + disabled={isLoading} + className="w-full" + > + {isLoading ? ( + <Loader2 className="w-4 h-4 mr-2 animate-spin" /> + ) : ( + <RefreshCw className="w-4 h-4 mr-2" /> + )} + 상태 새로고침 + </Button> + </div> + </div> + </PopoverContent> + </Popover> + ) +}
\ No newline at end of file diff --git a/lib/vendor-document-list/ship/update-doc-sheet.tsx b/lib/vendor-document-list/ship/update-doc-sheet.tsx new file mode 100644 index 00000000..3e0ca225 --- /dev/null +++ b/lib/vendor-document-list/ship/update-doc-sheet.tsx @@ -0,0 +1,267 @@ +"use client" + +import * as React from "react" +import { zodResolver } from "@hookform/resolvers/zod" +import { Loader, Save } from "lucide-react" +import { useForm } from "react-hook-form" +import { toast } from "sonner" +import { z } from "zod" +import { useRouter } from "next/navigation" + +import { Button } from "@/components/ui/button" +import { + Form, + FormControl, + FormDescription, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form" +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select" +import { + Sheet, + SheetClose, + SheetContent, + SheetDescription, + SheetFooter, + SheetHeader, + SheetTitle, +} from "@/components/ui/sheet" +import { Input } from "@/components/ui/input" +import { Textarea } from "@/components/ui/textarea" +import { modifyDocument } from "../service" + +// Document 수정을 위한 Zod 스키마 정의 +const updateDocumentSchema = z.object({ + docNumber: z.string().min(1, "Document number is required"), + title: z.string().min(1, "Title is required"), + status: z.string().min(1, "Status is required"), + description: z.string().optional(), + remarks: z.string().optional() +}); + +type UpdateDocumentSchema = z.infer<typeof updateDocumentSchema>; + +// 상태 옵션 정의 +const statusOptions = [ + "pending", + "in-progress", + "completed", + "rejected" +]; + +interface UpdateDocumentSheetProps + extends React.ComponentPropsWithRef<typeof Sheet> { + document: { + id: number; + contractId: number; + docNumber: string; + title: string; + status: string; + description?: string | null; + remarks?: string | null; + } | null +} + +export function UpdateDocumentSheet({ document, ...props }: UpdateDocumentSheetProps) { + const [isUpdatePending, startUpdateTransition] = React.useTransition() + const router = useRouter() + + const form = useForm<UpdateDocumentSchema>({ + resolver: zodResolver(updateDocumentSchema), + defaultValues: { + docNumber: "", + title: "", + status: "", + description: "", + remarks: "", + }, + }) + + // 폼 초기화 (document가 변경될 때) + React.useEffect(() => { + if (document) { + form.reset({ + docNumber: document.docNumber, + title: document.title, + status: document.status, + description: document.description ?? "", + remarks: document.remarks ?? "", + }); + } + }, [document, form]); + + function onSubmit(input: UpdateDocumentSchema) { + startUpdateTransition(async () => { + if (!document) return + + const result = await modifyDocument({ + id: document.id, + contractId: document.contractId, + ...input, + }) + + if (!result.success) { + if ('error' in result) { + toast.error(result.error) + } else { + toast.error("Failed to update document") + } + return + } + + form.reset() + props.onOpenChange?.(false) + toast.success("Document updated successfully") + router.refresh() + }) + } + + return ( + <Sheet {...props}> + <SheetContent className="flex flex-col gap-6 sm:max-w-md"> + <SheetHeader className="text-left"> + <SheetTitle>Update Document</SheetTitle> + <SheetDescription> + Update the document details and save the changes + </SheetDescription> + </SheetHeader> + <Form {...form}> + <form + onSubmit={form.handleSubmit(onSubmit)} + className="flex flex-col gap-4" + > + {/* 문서 번호 필드 */} + <FormField + control={form.control} + name="docNumber" + render={({ field }) => ( + <FormItem> + <FormLabel>Document Number</FormLabel> + <FormControl> + <Input placeholder="Enter document number" {...field} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 문서 제목 필드 */} + <FormField + control={form.control} + name="title" + render={({ field }) => ( + <FormItem> + <FormLabel>Title</FormLabel> + <FormControl> + <Input placeholder="Enter document title" {...field} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 상태 필드 */} + <FormField + control={form.control} + name="status" + render={({ field }) => ( + <FormItem> + <FormLabel>Status</FormLabel> + <Select + onValueChange={field.onChange} + defaultValue={field.value} + value={field.value} + > + <FormControl> + <SelectTrigger> + <SelectValue placeholder="Select status" /> + </SelectTrigger> + </FormControl> + <SelectContent> + <SelectGroup> + {statusOptions.map((status) => ( + <SelectItem key={status} value={status}> + {status.charAt(0).toUpperCase() + status.slice(1)} + </SelectItem> + ))} + </SelectGroup> + </SelectContent> + </Select> + <FormMessage /> + </FormItem> + )} + /> + + {/* 설명 필드 */} + <FormField + control={form.control} + name="description" + render={({ field }) => ( + <FormItem> + <FormLabel>Description</FormLabel> + <FormControl> + <Textarea + placeholder="Enter document description" + className="min-h-[80px]" + {...field} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + {/* 비고 필드 */} + <FormField + control={form.control} + name="remarks" + render={({ field }) => ( + <FormItem> + <FormLabel>Remarks</FormLabel> + <FormControl> + <Textarea + placeholder="Enter additional remarks" + className="min-h-[80px]" + {...field} + /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <SheetFooter className="gap-2 pt-2 sm:space-x-0"> + <SheetClose asChild> + <Button + type="button" + variant="outline" + onClick={() => form.reset()} + > + Cancel + </Button> + </SheetClose> + <Button disabled={isUpdatePending}> + {isUpdatePending && ( + <Loader + className="mr-2 size-4 animate-spin" + aria-hidden="true" + /> + )} + <Save className="mr-2 size-4" /> Save + </Button> + </SheetFooter> + </form> + </Form> + </SheetContent> + </Sheet> + ) +}
\ No newline at end of file diff --git a/lib/vendor-document-list/table/bulk-upload-dialog.tsx b/lib/vendor-document-list/table/bulk-upload-dialog.tsx index b7021985..b28d3b3d 100644 --- a/lib/vendor-document-list/table/bulk-upload-dialog.tsx +++ b/lib/vendor-document-list/table/bulk-upload-dialog.tsx @@ -666,8 +666,9 @@ const canProceedToUpload = matchResult && matchResult.matched.length > 0 && matc return ( <Dialog open={open} onOpenChange={handleDialogClose}> - <DialogContent className="sm:max-w-6xl max-h-[90vh] overflow-y-auto"> - <DialogHeader> + <DialogContent className="sm:max-w-6xl max-h-[90vh] flex flex-col" style={{maxWidth:900}}> + {/* 고정 헤더 */} + <DialogHeader className="flex-shrink-0"> <DialogTitle className="flex items-center gap-2"> <Files className="w-5 h-5" /> 일괄 업로드 @@ -686,476 +687,481 @@ return ( </div> </DialogHeader> - {/* 단계별 진행 상태 */} - <div className="flex items-center gap-2 mb-4"> - {[ - { key: 'template', label: '템플릿' }, - { key: 'files', label: '파일 업로드' }, - { key: 'review', label: '검토' }, - { key: 'upload', label: '업로드' }, - ].map((step, index) => ( - <React.Fragment key={step.key}> - <div className={`flex items-center gap-1 px-2 py-1 rounded text-xs ${ - currentStep === step.key ? 'bg-primary text-primary-foreground' : - ['template', 'files', 'review'].indexOf(currentStep) > ['template', 'files', 'review'].indexOf(step.key) ? 'bg-green-100 text-green-700' : - 'bg-gray-100 text-gray-500' - }`}> - {step.label} - </div> - {index < 3 && <div className="w-2 h-px bg-gray-300" />} - </React.Fragment> - ))} - </div> + {/* 스크롤 가능한 메인 컨텐츠 영역 */} + <div className="flex-1 overflow-y-auto px-1"> + {/* 단계별 진행 상태 */} + <div className="flex items-center gap-2 mb-4"> + {[ + { key: 'template', label: '템플릿' }, + { key: 'files', label: '파일 업로드' }, + { key: 'review', label: '검토' }, + { key: 'upload', label: '업로드' }, + ].map((step, index) => ( + <React.Fragment key={step.key}> + <div className={`flex items-center gap-1 px-2 py-1 rounded text-xs ${ + currentStep === step.key ? 'bg-primary text-primary-foreground' : + ['template', 'files', 'review'].indexOf(currentStep) > ['template', 'files', 'review'].indexOf(step.key) ? 'bg-green-100 text-green-700' : + 'bg-gray-100 text-gray-500' + }`}> + {step.label} + </div> + {index < 3 && <div className="w-2 h-px bg-gray-300" />} + </React.Fragment> + ))} + </div> - <Form {...form}> - <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6"> - - {/* 1단계: 템플릿 다운로드 및 업로드 */} - {currentStep === 'template' && ( - <div className="space-y-4"> - <Card> - <CardHeader> - <CardTitle className="text-lg flex items-center gap-2"> - <Download className="w-4 h-4" /> - 1단계: 템플릿 다운로드 - </CardTitle> - </CardHeader> - <CardContent className="space-y-4"> - <p className="text-sm text-gray-600"> - 현재 문서 목록을 기반으로 업로드 템플릿을 생성합니다. - 마지막 "fileNames" 칼럼에 업로드할 파일명을 ';'로 구분하여 입력하세요. - </p> - <Button type="button" onClick={exportTemplate} className="gap-2"> - <Download className="w-4 h-4" /> - 템플릿 다운로드 ({documents.length}개 문서) - </Button> - </CardContent> - </Card> - - <Card> - <CardHeader> - <CardTitle className="text-lg flex items-center gap-2"> - <Upload className="w-4 h-4" /> - 작성된 템플릿 업로드 - </CardTitle> - </CardHeader> - <CardContent> - <Dropzone - maxSize={10e6} // 10MB - multiple={false} - accept={{ - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': ['.xlsx'], - 'application/vnd.ms-excel': ['.xls'] - }} - onDropAccepted={handleTemplateDropAccepted} - disabled={isUploading} - > - <DropzoneZone> - <FormControl> - <DropzoneInput /> - </FormControl> - <div className="flex items-center gap-6"> - <FileSpreadsheet className="w-8 h-8 text-gray-400" /> - <div className="grid gap-0.5"> - <DropzoneTitle>작성된 Excel 템플릿을 업로드하세요</DropzoneTitle> - <DropzoneDescription> - .xlsx, .xls 파일을 지원합니다 - </DropzoneDescription> - </div> - </div> - </DropzoneZone> - </Dropzone> - - {templateFile && ( - <div className="mt-4 p-3 bg-green-50 border border-green-200 rounded-lg"> - <div className="flex items-center gap-2"> - <CheckCircle2 className="w-4 h-4 text-green-600" /> - <span className="text-sm text-green-700"> - 템플릿 업로드 완료: {templateFile.name} - </span> - </div> - </div> - )} - </CardContent> - </Card> - </div> - )} - - {/* 2단계: 파일 업로드 */} - {currentStep === 'files' && ( - <div className="space-y-4"> - <Card> - <CardHeader> - <CardTitle className="text-lg flex items-center gap-2"> - <Files className="w-4 h-4" /> - 2단계: 실제 파일들 업로드 - </CardTitle> - </CardHeader> - <CardContent> - <div className="mb-4 p-3 bg-blue-50 border border-blue-200 rounded-lg"> - <p className="text-sm text-blue-700"> - 템플릿에서 {parsedData.length}개 항목, 총 {parsedData.reduce((sum, item) => sum + item.fileNames.length, 0)}개 파일이 필요합니다. + <Form {...form}> + <form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6"> + + {/* 1단계: 템플릿 다운로드 및 업로드 */} + {currentStep === 'template' && ( + <div className="space-y-4"> + <Card> + <CardHeader> + <CardTitle className="text-lg flex items-center gap-2"> + <Download className="w-4 h-4" /> + 1단계: 템플릿 다운로드 + </CardTitle> + </CardHeader> + <CardContent className="space-y-4"> + <p className="text-sm text-gray-600"> + 현재 문서 목록을 기반으로 업로드 템플릿을 생성합니다. + 마지막 "fileNames" 칼럼에 업로드할 파일명을 ';'로 구분하여 입력하세요. </p> - </div> - - <Dropzone - maxSize={3e9} // 3GB - multiple={true} - onDropAccepted={handleFilesDropAccepted} - disabled={isUploading} - > - <DropzoneZone> - <FormControl> - <DropzoneInput /> - </FormControl> - <div className="flex items-center gap-6"> - <DropzoneUploadIcon /> - <div className="grid gap-0.5"> - <DropzoneTitle>실제 파일들을 여기에 드롭하세요</DropzoneTitle> - <DropzoneDescription> - 또는 클릭하여 파일들을 선택하세요 - </DropzoneDescription> + <Button type="button" onClick={exportTemplate} className="gap-2"> + <Download className="w-4 h-4" /> + 템플릿 다운로드 ({documents.length}개 문서) + </Button> + </CardContent> + </Card> + + <Card> + <CardHeader> + <CardTitle className="text-lg flex items-center gap-2"> + <Upload className="w-4 h-4" /> + 작성된 템플릿 업로드 + </CardTitle> + </CardHeader> + <CardContent> + <Dropzone + maxSize={10e6} // 10MB + multiple={false} + accept={{ + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': ['.xlsx'], + 'application/vnd.ms-excel': ['.xls'] + }} + onDropAccepted={handleTemplateDropAccepted} + disabled={isUploading} + > + <DropzoneZone> + <FormControl> + <DropzoneInput /> + </FormControl> + <div className="flex items-center gap-6"> + <FileSpreadsheet className="w-8 h-8 text-gray-400" /> + <div className="grid gap-0.5"> + <DropzoneTitle>작성된 Excel 템플릿을 업로드하세요</DropzoneTitle> + <DropzoneDescription> + .xlsx, .xls 파일을 지원합니다 + </DropzoneDescription> + </div> + </div> + </DropzoneZone> + </Dropzone> + + {templateFile && ( + <div className="mt-4 p-3 bg-green-50 border border-green-200 rounded-lg"> + <div className="flex items-center gap-2"> + <CheckCircle2 className="w-4 h-4 text-green-600" /> + <span className="text-sm text-green-700"> + 템플릿 업로드 완료: {templateFile.name} + </span> </div> </div> - </DropzoneZone> - </Dropzone> - - {selectedFiles.length > 0 && ( - <div className="mt-4 space-y-2"> - <h6 className="text-sm font-semibold"> - 업로드된 파일 ({selectedFiles.length}) - </h6> - <ScrollArea className="max-h-[200px]"> - <FileList> - {selectedFiles.map((file, index) => ( - <FileListItem key={index} className="p-3"> - <FileListHeader> - <FileListIcon /> - <FileListInfo> - <FileListName>{file.name}</FileListName> - <FileListSize>{prettyBytes(file.size)}</FileListSize> - </FileListInfo> - <FileListAction - onClick={() => removeFile(index)} - disabled={isUploading} - > - <X className="h-4 w-4" /> - </FileListAction> - </FileListHeader> - </FileListItem> - ))} - </FileList> - </ScrollArea> - </div> - )} - </CardContent> - </Card> - </div> - )} - - {/* 3단계: 매칭 결과 검토 */} - {currentStep === 'review' && matchResult && ( - <div className="space-y-4"> - <Card> - <CardHeader> - <CardTitle className="text-lg flex items-center gap-2"> - <CheckCircle2 className="w-4 h-4" /> - 3단계: 매칭 결과 검토 - </CardTitle> - </CardHeader> - <CardContent className="space-y-6"> - - {/* 통합된 매칭 결과 요약 */} - <div className="grid grid-cols-3 gap-4"> - <div className="p-4 bg-green-50 border border-green-200 rounded-lg text-center"> - <div className="text-2xl font-bold text-green-600">{matchResult.matched.length}</div> - <div className="text-sm text-green-700">매칭 성공</div> - </div> - <div className="p-4 bg-yellow-50 border border-yellow-200 rounded-lg text-center"> - <div className="text-2xl font-bold text-yellow-600">{matchResult.unmatched.length}</div> - <div className="text-sm text-yellow-700">매칭 실패</div> - </div> - <div className="p-4 bg-red-50 border border-red-200 rounded-lg text-center"> - <div className="text-2xl font-bold text-red-600">{matchResult.missingFiles.length}</div> - <div className="text-sm text-red-700">누락된 파일</div> + )} + </CardContent> + </Card> + </div> + )} + + {/* 2단계: 파일 업로드 */} + {currentStep === 'files' && ( + <div className="space-y-4"> + <Card> + <CardHeader> + <CardTitle className="text-lg flex items-center gap-2"> + <Files className="w-4 h-4" /> + 2단계: 실제 파일들 업로드 + </CardTitle> + </CardHeader> + <CardContent> + <div className="mb-4 p-3 bg-blue-50 border border-blue-200 rounded-lg"> + <p className="text-sm text-blue-700"> + 템플릿에서 {parsedData.length}개 항목, 총 {parsedData.reduce((sum, item) => sum + item.fileNames.length, 0)}개 파일이 필요합니다. + </p> </div> - </div> - - {/* 통합된 상세 결과 */} - <div className="border border-gray-200 rounded-lg overflow-hidden"> - {/* 매칭 성공 섹션 */} - {matchResult.matched.length > 0 && ( - <div className="border-b border-gray-200"> - <div className="p-4 bg-green-50 flex items-center justify-between"> - <h6 className="font-semibold text-green-700 flex items-center gap-2"> - <CheckCircle2 className="w-4 h-4" /> - 매칭 성공 ({matchResult.matched.length}개) - </h6> - <Button - variant="ghost" - size="sm" - type="button" - onClick={(e) => { - e.preventDefault() - e.stopPropagation() - const element = document.getElementById('matched-details') - if (element) { - element.style.display = element.style.display === 'none' ? 'block' : 'none' - } - }} - > - {matchResult.matched.length <= 5 ? '모두보기' : '상세보기'} - </Button> - </div> - - {/* 미리보기 */} - <div className="p-4 bg-green-25"> - <div className="space-y-2"> - {matchResult.matched.slice(0, 5).map((match, index) => ( - <div key={index} className="flex items-center justify-between text-sm"> - <span className="font-mono text-green-600 truncate max-w-[300px]" title={match.file.name}> - {match.file.name} - </span> - <span className="text-green-700 ml-4 whitespace-nowrap flex-shrink-0"> - → {match.item.docNumber} Rev.{match.item.revision} - </span> - </div> - ))} - {matchResult.matched.length > 5 && ( - <div className="text-gray-500 text-center text-sm py-2 border-t border-green-200"> - ... 외 {matchResult.matched.length - 5}개 (상세보기로 확인) - </div> - )} - </div> - {/* 펼침 상세 내용 */} - <div id="matched-details" style={{ display: 'none' }} className="mt-4 pt-4 border-t border-green-200"> - <div className="max-h-64 overflow-y-auto"> - <div className="space-y-2"> - {matchResult.matched.map((match, index) => ( - <div key={index} className="flex items-center justify-between text-sm py-1"> - <span className="font-mono text-green-600 truncate max-w-[300px]" title={match.file.name}> - {match.file.name} - </span> - <span className="text-green-700 ml-4 whitespace-nowrap flex-shrink-0"> - → {match.item.docNumber} ({match.item.stage} Rev.{match.item.revision}) - </span> - </div> - ))} - </div> - </div> + <Dropzone + maxSize={3e9} // 3GB + multiple={true} + onDropAccepted={handleFilesDropAccepted} + disabled={isUploading} + > + <DropzoneZone> + <FormControl> + <DropzoneInput /> + </FormControl> + <div className="flex items-center gap-6"> + <DropzoneUploadIcon /> + <div className="grid gap-0.5"> + <DropzoneTitle>실제 파일들을 여기에 드롭하세요</DropzoneTitle> + <DropzoneDescription> + 또는 클릭하여 파일들을 선택하세요 + </DropzoneDescription> </div> </div> + </DropzoneZone> + </Dropzone> + + {selectedFiles.length > 0 && ( + <div className="mt-4 space-y-2"> + <h6 className="text-sm font-semibold"> + 업로드된 파일 ({selectedFiles.length}) + </h6> + <ScrollArea className="max-h-[200px]"> + <FileList> + {selectedFiles.map((file, index) => ( + <FileListItem key={index} className="p-3"> + <FileListHeader> + <FileListIcon /> + <FileListInfo> + <FileListName>{file.name}</FileListName> + <FileListSize>{prettyBytes(file.size)}</FileListSize> + </FileListInfo> + <FileListAction + onClick={() => removeFile(index)} + disabled={isUploading} + > + <X className="h-4 w-4" /> + </FileListAction> + </FileListHeader> + </FileListItem> + ))} + </FileList> + </ScrollArea> </div> )} + </CardContent> + </Card> + </div> + )} - {/* 매칭 실패 섹션 */} - {matchResult.unmatched.length > 0 && ( - <div className="border-b border-gray-200"> - <div className="p-4 bg-yellow-50 flex items-center justify-between"> - <h6 className="font-semibold text-yellow-700 flex items-center gap-2"> - <AlertCircle className="w-4 h-4" /> - 매칭되지 않은 파일 ({matchResult.unmatched.length}개) - </h6> - <Button - variant="ghost" - size="sm" - type="button" - onClick={() => { - const element = document.getElementById('unmatched-details') - if (element) { - element.style.display = element.style.display === 'none' ? 'block' : 'none' - } - }} - > - 상세보기 - </Button> - </div> - - <div className="p-4 bg-yellow-25"> - <div className="space-y-1"> - {matchResult.unmatched.slice(0, 3).map((file, index) => ( - <div key={index} className="text-sm text-yellow-600 font-mono truncate max-w-full" title={file.name}> - {file.name} - </div> - ))} - {matchResult.unmatched.length > 3 && ( - <div className="text-gray-500 text-center text-sm py-2"> - ... 외 {matchResult.unmatched.length - 3}개 - </div> - )} + {/* 3단계: 매칭 결과 검토 */} + {currentStep === 'review' && matchResult && ( + <div className="space-y-4"> + <Card> + <CardHeader> + <CardTitle className="text-lg flex items-center gap-2"> + <CheckCircle2 className="w-4 h-4" /> + 3단계: 매칭 결과 검토 + </CardTitle> + </CardHeader> + <CardContent className="space-y-6"> + + {/* 통합된 매칭 결과 요약 */} + <div className="grid grid-cols-3 gap-4"> + <div className="p-4 bg-green-50 border border-green-200 rounded-lg text-center"> + <div className="text-2xl font-bold text-green-600">{matchResult.matched.length}</div> + <div className="text-sm text-green-700">매칭 성공</div> + </div> + <div className="p-4 bg-yellow-50 border border-yellow-200 rounded-lg text-center"> + <div className="text-2xl font-bold text-yellow-600">{matchResult.unmatched.length}</div> + <div className="text-sm text-yellow-700">매칭 실패</div> + </div> + <div className="p-4 bg-red-50 border border-red-200 rounded-lg text-center"> + <div className="text-2xl font-bold text-red-600">{matchResult.missingFiles.length}</div> + <div className="text-sm text-red-700">누락된 파일</div> + </div> + </div> + + {/* 통합된 상세 결과 */} + <div className="border border-gray-200 rounded-lg overflow-hidden"> + {/* 매칭 성공 섹션 */} + {matchResult.matched.length > 0 && ( + <div className="border-b border-gray-200"> + <div className="p-4 bg-green-50 flex items-center justify-between"> + <h6 className="font-semibold text-green-700 flex items-center gap-2"> + <CheckCircle2 className="w-4 h-4" /> + 매칭 성공 ({matchResult.matched.length}개) + </h6> + <Button + variant="ghost" + size="sm" + type="button" + onClick={(e) => { + e.preventDefault() + e.stopPropagation() + const element = document.getElementById('matched-details') + if (element) { + element.style.display = element.style.display === 'none' ? 'block' : 'none' + } + }} + > + {matchResult.matched.length <= 5 ? '모두보기' : '상세보기'} + </Button> </div> + + {/* 미리보기 */} + <div className="p-4 bg-green-25"> + <div className="space-y-2"> + {matchResult.matched.slice(0, 5).map((match, index) => ( + <div key={index} className="flex items-center justify-between text-sm"> + <span className="font-mono text-green-600 truncate max-w-[300px]" title={match.file.name}> + {match.file.name} + </span> + <span className="text-green-700 ml-4 whitespace-nowrap flex-shrink-0"> + → {match.item.docNumber} Rev.{match.item.revision} + </span> + </div> + ))} + {matchResult.matched.length > 5 && ( + <div className="text-gray-500 text-center text-sm py-2 border-t border-green-200"> + ... 외 {matchResult.matched.length - 5}개 (상세보기로 확인) + </div> + )} + </div> - <div id="unmatched-details" style={{ display: 'none' }} className="mt-4 pt-4 border-t border-yellow-200"> - <div className="max-h-40 overflow-y-auto"> - <div className="space-y-1"> - {matchResult.unmatched.map((file, index) => ( - <div key={index} className="text-sm text-yellow-600 font-mono truncate max-w-full" title={file.name}> - {file.name} - </div> - ))} + {/* 펼침 상세 내용 */} + <div id="matched-details" style={{ display: 'none' }} className="mt-4 pt-4 border-t border-green-200"> + <div className="max-h-64 overflow-y-auto"> + <div className="space-y-2"> + {matchResult.matched.map((match, index) => ( + <div key={index} className="flex items-center justify-between text-sm py-1"> + <span className="font-mono text-green-600 truncate max-w-[300px]" title={match.file.name}> + {match.file.name} + </span> + <span className="text-green-700 ml-4 whitespace-nowrap flex-shrink-0"> + → {match.item.docNumber} ({match.item.stage} Rev.{match.item.revision}) + </span> + </div> + ))} + </div> </div> </div> </div> </div> - </div> - )} + )} + + {/* 매칭 실패 섹션 */} + {matchResult.unmatched.length > 0 && ( + <div className="border-b border-gray-200"> + <div className="p-4 bg-yellow-50 flex items-center justify-between"> + <h6 className="font-semibold text-yellow-700 flex items-center gap-2"> + <AlertCircle className="w-4 h-4" /> + 매칭되지 않은 파일 ({matchResult.unmatched.length}개) + </h6> + <Button + variant="ghost" + size="sm" + type="button" + onClick={() => { + const element = document.getElementById('unmatched-details') + if (element) { + element.style.display = element.style.display === 'none' ? 'block' : 'none' + } + }} + > + 상세보기 + </Button> + </div> + + <div className="p-4 bg-yellow-25"> + <div className="space-y-1"> + {matchResult.unmatched.slice(0, 3).map((file, index) => ( + <div key={index} className="text-sm text-yellow-600 font-mono truncate max-w-full" title={file.name}> + {file.name} + </div> + ))} + {matchResult.unmatched.length > 3 && ( + <div className="text-gray-500 text-center text-sm py-2"> + ... 외 {matchResult.unmatched.length - 3}개 + </div> + )} + </div> - {/* 누락된 파일 섹션 */} - {matchResult.missingFiles.length > 0 && ( - <div> - <div className="p-4 bg-red-50 flex items-center justify-between"> - <h6 className="font-semibold text-red-700 flex items-center gap-2"> - <X className="w-4 h-4" /> - 누락된 파일 ({matchResult.missingFiles.length}개) - </h6> - <Button - variant="ghost" - size="sm" - type="button" - onClick={() => { - const element = document.getElementById('missing-details') - if (element) { - element.style.display = element.style.display === 'none' ? 'block' : 'none' - } - }} - > - 상세보기 - </Button> - </div> - - <div className="p-4 bg-red-25"> - <div className="space-y-1"> - {matchResult.missingFiles.slice(0, 3).map((fileName, index) => ( - <div key={index} className="text-sm text-red-600 font-mono truncate max-w-full" title={fileName}> - {fileName} - </div> - ))} - {matchResult.missingFiles.length > 3 && ( - <div className="text-gray-500 text-center text-sm py-2"> - ... 외 {matchResult.missingFiles.length - 3}개 + <div id="unmatched-details" style={{ display: 'none' }} className="mt-4 pt-4 border-t border-yellow-200"> + <div className="max-h-40 overflow-y-auto"> + <div className="space-y-1"> + {matchResult.unmatched.map((file, index) => ( + <div key={index} className="text-sm text-yellow-600 font-mono truncate max-w-full" title={file.name}> + {file.name} + </div> + ))} + </div> </div> - )} + </div> + </div> + </div> + )} + + {/* 누락된 파일 섹션 */} + {matchResult.missingFiles.length > 0 && ( + <div> + <div className="p-4 bg-red-50 flex items-center justify-between"> + <h6 className="font-semibold text-red-700 flex items-center gap-2"> + <X className="w-4 h-4" /> + 누락된 파일 ({matchResult.missingFiles.length}개) + </h6> + <Button + variant="ghost" + size="sm" + type="button" + onClick={() => { + const element = document.getElementById('missing-details') + if (element) { + element.style.display = element.style.display === 'none' ? 'block' : 'none' + } + }} + > + 상세보기 + </Button> </div> + + <div className="p-4 bg-red-25"> + <div className="space-y-1"> + {matchResult.missingFiles.slice(0, 3).map((fileName, index) => ( + <div key={index} className="text-sm text-red-600 font-mono truncate max-w-full" title={fileName}> + {fileName} + </div> + ))} + {matchResult.missingFiles.length > 3 && ( + <div className="text-gray-500 text-center text-sm py-2"> + ... 외 {matchResult.missingFiles.length - 3}개 + </div> + )} + </div> - <div id="missing-details" style={{ display: 'none' }} className="mt-4 pt-4 border-t border-red-200"> - <div className="max-h-40 overflow-y-auto"> - <div className="space-y-1"> - {matchResult.missingFiles.map((fileName, index) => ( - <div key={index} className="text-sm text-red-600 font-mono truncate max-w-full" title={fileName}> - {fileName} - </div> - ))} + <div id="missing-details" style={{ display: 'none' }} className="mt-4 pt-4 border-t border-red-200"> + <div className="max-h-40 overflow-y-auto"> + <div className="space-y-1"> + {matchResult.missingFiles.map((fileName, index) => ( + <div key={index} className="text-sm text-red-600 font-mono truncate max-w-full" title={fileName}> + {fileName} + </div> + ))} + </div> </div> </div> </div> </div> + )} + </div> + + {/* 업로드 불가 경고 */} + {!canProceedToUpload && ( + <div className="p-4 bg-red-50 border border-red-200 rounded-lg"> + <div className="flex items-center gap-2"> + <AlertCircle className="w-5 h-5 text-red-600 flex-shrink-0" /> + <span className="text-sm text-red-700"> + 누락된 파일이 있어 업로드를 진행할 수 없습니다. 누락된 파일들을 추가해주세요. + </span> + </div> </div> )} - </div> + </CardContent> + </Card> + + {/* 추가 정보 입력 */} + <div className="grid grid-cols-1 gap-4"> + <FormField + control={form.control} + name="uploaderName" + render={({ field }) => ( + <FormItem> + <FormLabel>업로더명</FormLabel> + <FormControl> + <Input {...field} placeholder="업로더 이름" /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + + <FormField + control={form.control} + name="comment" + render={({ field }) => ( + <FormItem> + <FormLabel>코멘트 (선택)</FormLabel> + <FormControl> + <Textarea {...field} placeholder="일괄 업로드 코멘트" rows={2} /> + </FormControl> + <FormMessage /> + </FormItem> + )} + /> + </div> + </div> + )} - {/* 업로드 불가 경고 */} - {!canProceedToUpload && ( - <div className="p-4 bg-red-50 border border-red-200 rounded-lg"> + {/* 4단계: 업로드 진행 */} + {currentStep === 'upload' && ( + <div className="space-y-4"> + <Card> + <CardHeader> + <CardTitle className="text-lg flex items-center gap-2"> + <Upload className="w-4 h-4" /> + 4단계: 업로드 진행중 + </CardTitle> + </CardHeader> + <CardContent> + <div className="space-y-4"> <div className="flex items-center gap-2"> - <AlertCircle className="w-5 h-5 text-red-600 flex-shrink-0" /> - <span className="text-sm text-red-700"> - 누락된 파일이 있어 업로드를 진행할 수 없습니다. 누락된 파일들을 추가해주세요. - </span> + <Loader2 className="h-4 w-4 animate-spin" /> + <span className="text-sm">{uploadProgress}% 업로드 중...</span> + </div> + <div className="h-2 w-full bg-muted rounded-full overflow-hidden"> + <div + className="h-full bg-primary rounded-full transition-all" + style={{ width: `${uploadProgress}%` }} + /> </div> + {matchResult && ( + <p className="text-sm text-gray-600"> + {matchResult.matched.length}개 파일을 업로드하고 있습니다... + </p> + )} </div> - )} - </CardContent> - </Card> - - {/* 추가 정보 입력 */} - <div className="grid grid-cols-1 gap-4"> - <FormField - control={form.control} - name="uploaderName" - render={({ field }) => ( - <FormItem> - <FormLabel>업로더명</FormLabel> - <FormControl> - <Input {...field} placeholder="업로더 이름" /> - </FormControl> - <FormMessage /> - </FormItem> - )} - /> - - <FormField - control={form.control} - name="comment" - render={({ field }) => ( - <FormItem> - <FormLabel>코멘트 (선택)</FormLabel> - <FormControl> - <Textarea {...field} placeholder="일괄 업로드 코멘트" rows={2} /> - </FormControl> - <FormMessage /> - </FormItem> - )} - /> + </CardContent> + </Card> </div> - </div> - )} - - {/* 4단계: 업로드 진행 */} - {currentStep === 'upload' && ( - <div className="space-y-4"> - <Card> - <CardHeader> - <CardTitle className="text-lg flex items-center gap-2"> - <Upload className="w-4 h-4" /> - 4단계: 업로드 진행중 - </CardTitle> - </CardHeader> - <CardContent> - <div className="space-y-4"> - <div className="flex items-center gap-2"> - <Loader2 className="h-4 w-4 animate-spin" /> - <span className="text-sm">{uploadProgress}% 업로드 중...</span> - </div> - <div className="h-2 w-full bg-muted rounded-full overflow-hidden"> - <div - className="h-full bg-primary rounded-full transition-all" - style={{ width: `${uploadProgress}%` }} - /> - </div> - {matchResult && ( - <p className="text-sm text-gray-600"> - {matchResult.matched.length}개 파일을 업로드하고 있습니다... - </p> - )} - </div> - </CardContent> - </Card> - </div> - )} - - <DialogFooter> - <Button - type="button" - variant="outline" - onClick={handleDialogClose} - disabled={isUploading} - > - 취소 - </Button> - - {currentStep === 'review' && ( - <Button - type="submit" - disabled={!canProceedToUpload || isUploading} - > - <Upload className="mr-2 h-4 w-4" /> - 일괄 업로드 ({matchResult?.matched.length || 0}개 파일) - </Button> )} - </DialogFooter> - </form> - </Form> + </form> + </Form> + </div> + + {/* 고정 푸터 */} + <DialogFooter className="flex-shrink-0 pt-4 border-t bg-white"> + <Button + type="button" + variant="outline" + onClick={handleDialogClose} + disabled={isUploading} + > + 취소 + </Button> + + {currentStep === 'review' && ( + <Button + type="submit" + disabled={!canProceedToUpload || isUploading} + onClick={form.handleSubmit(onSubmit)} + > + <Upload className="mr-2 h-4 w-4" /> + 일괄 업로드 ({matchResult?.matched.length || 0}개 파일) + </Button> + )} + </DialogFooter> </DialogContent> </Dialog> ) diff --git a/lib/vendor-document-list/validations.ts b/lib/vendor-document-list/validations.ts index 036cc6c6..acd101ed 100644 --- a/lib/vendor-document-list/validations.ts +++ b/lib/vendor-document-list/validations.ts @@ -8,7 +8,7 @@ import { import * as z from "zod" import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers" -import { DocumentStagesView } from "@/db/schema/vendorDocu" +import { DocumentStagesView, SimplifiedDocumentsView } from "@/db/schema/vendorDocu" export const searchParamsCache = createSearchParamsCache({ flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault( @@ -31,3 +31,26 @@ export const searchParamsCache = createSearchParamsCache({ export type GetVendorDcoumentsSchema = Awaited<ReturnType<typeof searchParamsCache.parse>> + + +export const searchParamsShipDocuCache = createSearchParamsCache({ + flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault( + [] + ), + page: parseAsInteger.withDefault(1), + perPage: parseAsInteger.withDefault(10), + sort: getSortingStateParser<SimplifiedDocumentsView>().withDefault([ + { id: "createdAt", desc: true }, + ]), + title: parseAsString.withDefault(""), + docNumber: parseAsString.withDefault(""), + + // advanced filter + filters: getFiltersStateParser().withDefault([]), + joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"), + search: parseAsString.withDefault(""), + +}) + + +export type GetVendorShipDcoumentsSchema = Awaited<ReturnType<typeof searchParamsShipDocuCache.parse>> diff --git a/lib/welding/service.ts b/lib/welding/service.ts index b3a69c36..feb6272b 100644 --- a/lib/welding/service.ts +++ b/lib/welding/service.ts @@ -7,7 +7,7 @@ import { filterColumns } from "@/lib/filter-columns"; import { tagClasses } from "@/db/schema/vendorData"; import { asc, desc, ilike, inArray, and, gte, lte, not, or, eq } from "drizzle-orm"; import { GetOcrRowSchema, UpdateOcrRowSchema } from "./validation"; -import { ocrRows } from "@/db/schema"; +import { OcrRow, ocrRows, users } from "@/db/schema"; import { countOcrRows, selectOcrRows } from "./repository"; import { getServerSession } from "next-auth/next" import { authOptions } from "@/app/api/auth/[...nextauth]/route" @@ -153,4 +153,43 @@ export async function modifyOcrRow(input: ModifyOcrRowInput) { error: "OCR 행을 업데이트하는 중 오류가 발생했습니다." }; } +} + + +export async function getOcrAllRows(): Promise<OcrRow[]> { + try { + const allRows = await db + .select({ + // ocrRows의 모든 필드 + id: ocrRows.id, + tableId: ocrRows.tableId, + sessionId: ocrRows.sessionId, + rowIndex: ocrRows.rowIndex, + reportNo: ocrRows.reportNo, + no: ocrRows.no, + identificationNo: ocrRows.identificationNo, + tagNo: ocrRows.tagNo, + jointNo: ocrRows.jointNo, + jointType: ocrRows.jointType, + weldingDate: ocrRows.weldingDate, + confidence: ocrRows.confidence, + sourceTable: ocrRows.sourceTable, + sourceRow: ocrRows.sourceRow, + userId: ocrRows.userId, + createdAt: ocrRows.createdAt, + + // users 테이블의 필드 + userName: users.name, + userEmail: users.email, + }) + .from(ocrRows) + .leftJoin(users, eq(ocrRows.userId, users.id)) + .orderBy(desc(ocrRows.createdAt)) + + + return allRows + } catch (error) { + console.error("Error fetching all OCR rows:", error) + throw new Error("Failed to fetch all OCR data") + } }
\ No newline at end of file diff --git a/lib/welding/table/exporft-ocr-data.ts b/lib/welding/table/exporft-ocr-data.ts new file mode 100644 index 00000000..76856808 --- /dev/null +++ b/lib/welding/table/exporft-ocr-data.ts @@ -0,0 +1,90 @@ +// lib/export-ocr-data.ts +import ExcelJS from "exceljs" +import type { OcrRow } from "@/db/schema" + +/** + * OCR 데이터를 엑셀로 내보내는 단순한 함수 + */ +export async function exportOcrDataToExcel( + data: OcrRow[], + filename: string = "OCR Data" +): Promise<void> { + if (!data || data.length === 0) { + throw new Error("No data to export") + } + + // 워크북 생성 + const workbook = new ExcelJS.Workbook() + const worksheet = workbook.addWorksheet("OCR Data") + + // 컬럼 정의 (OCR 데이터에 맞게 설정) + const columns = [ + { key: "reportNo", header: "Report No", width: 15 }, + { key: "no", header: "No", width: 10 }, + { key: "identificationNo", header: "Identification No", width: 20 }, + { key: "tagNo", header: "Tag No", width: 15 }, + { key: "jointNo", header: "Joint No", width: 15 }, + { key: "jointType", header: "Joint Type", width: 15 }, + { key: "weldingDate", header: "Welding Date", width: 15 }, + { key: "confidence", header: "confidence", width: 15 }, + { key: "userName", header: "사용자 이름", width: 15 }, + { key: "userEmail", header: "사용자 이메일", width: 15 }, + { key: "createdAt", header: "생성일", width: 20 }, + // 필요한 다른 컬럼들도 추가 가능 + ] + + // 워크시트에 컬럼 설정 + worksheet.columns = columns + + // 헤더 스타일 설정 + const headerRow = worksheet.getRow(1) + headerRow.font = { bold: true } + headerRow.alignment = { horizontal: "center" } + headerRow.fill = { + type: "pattern", + pattern: "solid", + fgColor: { argb: "FFCCCCCC" }, + } + + // 데이터 추가 + data.forEach((row) => { + worksheet.addRow({ + reportNo: row.reportNo || "", + no: row.no || "", + identificationNo: row.identificationNo || "", + tagNo: row.tagNo || "", + jointNo: row.jointNo || "", + jointType: row.jointType || "", + confidence: row.confidence || "", + weldingDate: row.weldingDate ? new Date(row.weldingDate).toLocaleDateString() : "", + userName: row.userName || "", + userEmail: row.userEmail || "", + + createdAt: row.createdAt ? new Date(row.createdAt).toLocaleString() : "", + }) + }) + + // 모든 행에 테두리 추가 + worksheet.eachRow((row, rowNumber) => { + row.eachCell((cell) => { + cell.border = { + top: { style: "thin" }, + left: { style: "thin" }, + bottom: { style: "thin" }, + right: { style: "thin" }, + } + }) + }) + + // 파일 다운로드 + const buffer = await workbook.xlsx.writeBuffer() + const blob = new Blob([buffer], { + type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + }) + const url = URL.createObjectURL(blob) + const link = document.createElement("a") + link.href = url + link.download = `${filename}.xlsx` + link.click() + URL.revokeObjectURL(url) +}
\ No newline at end of file diff --git a/lib/welding/table/ocr-table-columns.tsx b/lib/welding/table/ocr-table-columns.tsx index d1aefe06..93ee1004 100644 --- a/lib/welding/table/ocr-table-columns.tsx +++ b/lib/welding/table/ocr-table-columns.tsx @@ -265,6 +265,7 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef<OcrRow> ) }, enableSorting: true, + size:100 }, // Created At 컬럼 { diff --git a/lib/welding/table/ocr-table-toolbar-actions.tsx b/lib/welding/table/ocr-table-toolbar-actions.tsx index 6c6d0637..120ff54f 100644 --- a/lib/welding/table/ocr-table-toolbar-actions.tsx +++ b/lib/welding/table/ocr-table-toolbar-actions.tsx @@ -2,9 +2,8 @@ import * as React from "react" import { type Table } from "@tanstack/react-table" -import { Download, RefreshCcw, Upload, FileText, Loader2 } from "lucide-react" +import { Download, RefreshCcw, Upload, FileText, Loader2, ChevronDown } from "lucide-react" -import { exportTableToExcel } from "@/lib/export" import { Button } from "@/components/ui/button" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" @@ -20,6 +19,16 @@ import { Progress } from "@/components/ui/progress" import { Badge } from "@/components/ui/badge" import { toast } from "sonner" import { OcrRow } from "@/db/schema" +import { exportTableToExcel } from "@/lib/export_all" +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu" +import { getOcrAllRows } from "../service" +import { exportOcrDataToExcel } from "./exporft-ocr-data" interface OcrTableToolbarActionsProps { table: Table<OcrRow> @@ -38,6 +47,7 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) { const [isUploadDialogOpen, setIsUploadDialogOpen] = React.useState(false) const [selectedFile, setSelectedFile] = React.useState<File | null>(null) const fileInputRef = React.useRef<HTMLInputElement>(null) + const [isExporting, setIsExporting] = React.useState(false) // 다이얼로그 닫기 핸들러 - 업로드 중에는 닫기 방지 const handleDialogOpenChange = (open: boolean) => { @@ -50,11 +60,11 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) { }) return // 다이얼로그를 닫지 않음 } - + // 업로드가 진행 중이 아니거나 완료되었으면 초기화 후 닫기 resetUpload() } - + setIsUploadDialogOpen(open) } @@ -75,12 +85,12 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) { const allowedTypes = [ 'application/pdf', 'image/jpeg', - 'image/jpg', + 'image/jpg', 'image/png', 'image/tiff', 'image/bmp' ] - + if (!allowedTypes.includes(file.type)) { return "Only PDF and image files (JPG, PNG, TIFF, BMP) are supported" } @@ -151,8 +161,8 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) { toast.success( `OCR completed! Extracted ${result.metadata.totalRows} rows from ${result.metadata.totalTables} tables`, { - description: result.warnings?.length - ? `Warnings: ${result.warnings.join(', ')}` + description: result.warnings?.length + ? `Warnings: ${result.warnings.join(', ')}` : undefined } ) @@ -161,7 +171,7 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) { setTimeout(() => { setIsUploadDialogOpen(false) resetUpload() - + // 테이블 새로고침 window.location.reload() }, 2000) @@ -205,6 +215,50 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) { } } + // 현재 페이지 데이터만 내보내기 + const exportCurrentPage = () => { + exportTableToExcel(table, { + filename: "OCR Result (Current Page)", + excludeColumns: ["select", "actions"], + }) + } + + // 전체 데이터 내보내기 + const exportAllData = async () => { + if (isExporting) return + + setIsExporting(true) + + try { + toast.loading("전체 데이터를 가져오는 중...", { + description: "잠시만 기다려주세요." + }) + + // 모든 데이터 가져오기 + const allData = await getOcrAllRows() + + toast.dismiss() + + if (allData.length === 0) { + toast.warning("내보낼 데이터가 없습니다.") + return + } + + console.log(allData) + + // 새로운 단순한 export 함수 사용 + await exportOcrDataToExcel(allData, `OCR Result (All Data - ${allData.length} rows)`) + + toast.success(`전체 데이터 ${allData.length}개 행이 성공적으로 내보내졌습니다.`) + + } catch (error) { + console.error('Error exporting all data:', error) + toast.error('전체 데이터 내보내기 중 오류가 발생했습니다.') + } finally { + setIsExporting(false) + } + } + return ( <div className="flex items-center gap-2"> {/* OCR 업로드 다이얼로그 */} @@ -215,7 +269,7 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) { <span className="hidden sm:inline">Upload OCR</span> </Button> </DialogTrigger> - <DialogContent + <DialogContent className="sm:max-w-md" // 업로드 중에는 ESC 키로도 닫기 방지 onEscapeKeyDown={(e) => { @@ -241,13 +295,13 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) { )} </DialogTitle> <DialogDescription> - {isUploading && uploadProgress?.stage !== "complete" + {isUploading && uploadProgress?.stage !== "complete" ? "Processing in progress. Please do not close this dialog." : "Upload a PDF or image file to extract table data using OCR technology." } </DialogDescription> </DialogHeader> - + <div className="space-y-4"> {/* 파일 선택 */} <div className="space-y-2"> @@ -292,7 +346,7 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) { <p className="text-xs text-muted-foreground"> {uploadProgress.message} </p> - + {/* 진행 중일 때 안내 메시지 */} {isUploading && uploadProgress.stage !== "complete" && ( <div className="flex items-center gap-2 p-2 bg-blue-50 dark:bg-blue-950/20 rounded-md"> @@ -332,22 +386,40 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) { </div> </DialogContent> </Dialog> - + {/* Export 버튼 */} - <Button - variant="outline" - size="sm" - onClick={() => - exportTableToExcel(table, { - filename: "OCR Result", - excludeColumns: ["select", "actions"], - }) - } - className="gap-2" - > - <Download className="size-4" aria-hidden="true" /> - <span className="hidden sm:inline">Export</span> - </Button> + {/* Export 드롭다운 메뉴 */} + <DropdownMenu> + <DropdownMenuTrigger asChild> + <Button + variant="outline" + size="sm" + className="gap-2" + disabled={isExporting} + > + {isExporting ? ( + <Loader2 className="size-4 animate-spin" aria-hidden="true" /> + ) : ( + <Download className="size-4" aria-hidden="true" /> + )} + <span className="hidden sm:inline"> + {isExporting ? "Exporting..." : "Export"} + </span> + <ChevronDown className="size-3" aria-hidden="true" /> + </Button> + </DropdownMenuTrigger> + <DropdownMenuContent align="end" className="w-[200px]"> + <DropdownMenuItem onClick={exportAllData} disabled={isExporting}> + <Download className="mr-2 size-4" /> + 전체 데이터 내보내기 + </DropdownMenuItem> + <DropdownMenuSeparator /> + <DropdownMenuItem onClick={exportCurrentPage} disabled={isExporting}> + <Download className="mr-2 size-4" /> + 현재 페이지 내보내기 + </DropdownMenuItem> + </DropdownMenuContent> + </DropdownMenu> </div> ) }
\ No newline at end of file |
