From b67e36df49f067cbd5ba899f9fbcc755f38d4b4f Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Thu, 4 Sep 2025 08:31:31 +0000
Subject: (대표님, 최겸, 임수민) 작업사항 커밋
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/migrations/0329_chunky_sentry.sql | 54 ++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 db/migrations/0329_chunky_sentry.sql

(limited to 'db/migrations/0329_chunky_sentry.sql')

diff --git a/db/migrations/0329_chunky_sentry.sql b/db/migrations/0329_chunky_sentry.sql
new file mode 100644
index 00000000..414aa68e
--- /dev/null
+++ b/db/migrations/0329_chunky_sentry.sql
@@ -0,0 +1,54 @@
+DROP VIEW "public"."rfqs_last_view";--> statement-breakpoint
+CREATE VIEW "public"."rfqs_last_view" AS (select "rfqs_last"."id" as "id", "rfqs_last"."rfq_code" as "rfq_code", "rfqs_last"."series" as "series", "rfqs_last"."rfq_sealed_yn" as "rfq_sealed_yn", "rfqs_last"."rfq_type" as "rfq_type", "rfqs_last"."rfq_title" as "rfq_title", "rfqs_last"."project_company" as "project_company", "rfqs_last"."project_flag" as "project_flag", "rfqs_last"."project_site" as "project_site", "rfqs_last"."sm_code" as "sm_code", "rfqs_last"."pr_number" as "pr_number", "rfqs_last"."pr_issue_date" as "pr_issue_date", "rfqs_last"."project_id" as "project_id", "projects"."code" as "project_code", "projects"."name" as "project_name", "rfqs_last"."item_code" as "item_code", "rfqs_last"."item_name" as "item_name", "rfqs_last"."package_no" as "package_no", "rfqs_last"."package_name" as "package_name", "rfqs_last"."eng_pic_name" as "eng_pic_name", "rfqs_last"."status" as "status", "rfqs_last"."rfq_send_date" as "rfq_send_date", "rfqs_last"."due_date" as "due_date", "rfqs_last"."pic" as "pic_id", "rfqs_last"."pic_code" as "pic_code", "rfqs_last"."pic_name" as "pic_name", "pic_user"."name" as "pic_user_name", (
+                SELECT MIN(submitted_at)
+                FROM rfq_last_vendor_responses
+                WHERE rfqs_last_id = "rfqs_last"."id"
+                AND submitted_at IS NOT NULL
+            ) as "earliest_quotation_submitted_at", (
+                SELECT COUNT(*)
+                FROM rfq_last_details
+                WHERE rfqs_last_id = "rfqs_last"."id"
+            ) as "vendor_count", (
+                SELECT COUNT(*)
+                FROM rfq_last_details
+                WHERE rfqs_last_id = "rfqs_last"."id"
+                AND short_list = true
+            ) as "short_listed_vendor_count", (
+                SELECT COUNT(DISTINCT vendor_id)
+                FROM rfq_last_vendor_responses
+                WHERE rfqs_last_id  = "rfqs_last"."id"
+                AND submitted_at IS NOT NULL
+            ) as "quotation_received_count", "rfqs_last"."created_by" as "created_by", "created_by_user"."name" as "created_by_user_name", "rfqs_last"."created_at" as "created_at", "rfqs_last"."sent_by" as "sent_by", "sent_by_user"."name" as "sent_by_user_name", "rfqs_last"."updated_by" as "updated_by", "updated_by_user"."name" as "updated_by_user_name", "rfqs_last"."updated_at" as "updated_at", "rfqs_last"."remark" as "remark", (
+                SELECT material_code 
+                FROM rfq_pr_items 
+                WHERE rfqs_last_id = "rfqs_last"."id"
+                AND major_yn = true
+                LIMIT 1
+            ) as "major_item_material_code", (
+                SELECT material_description 
+                FROM rfq_pr_items 
+                WHERE rfqs_last_id = "rfqs_last"."id"
+                AND major_yn = true
+                LIMIT 1
+            ) as "major_item_materialD_description", (
+                SELECT material_category 
+                FROM rfq_pr_items 
+                WHERE rfqs_last_id = "rfqs_last"."id"
+                AND major_yn = true
+                LIMIT 1
+            ) as "major_item_material_category", (
+                SELECT pr_no 
+                FROM rfq_pr_items 
+                WHERE rfqs_last_id = "rfqs_last"."id"
+                AND major_yn = true
+                LIMIT 1
+            ) as "major_item_pr_no", (
+                SELECT COUNT(*) 
+                FROM rfq_pr_items 
+                WHERE rfqs_last_id = "rfqs_last"."id"
+            ) as "pr_items_count", (
+                SELECT COUNT(*) 
+                FROM rfq_pr_items 
+                WHERE rfqs_last_id = "rfqs_last"."id"
+                AND major_yn = true
+            ) as "major_items_count" from "rfqs_last" left join "projects" on "rfqs_last"."project_id" = "projects"."id" left join "users" "created_by_user" on "rfqs_last"."created_by" = "created_by_user"."id" left join "users" "updated_by_user" on "rfqs_last"."updated_by" = "updated_by_user"."id" left join "users" "sent_by_user" on "rfqs_last"."sent_by" = "sent_by_user"."id" left join "users" "pic_user" on "rfqs_last"."pic" = "pic_user"."id");
\ No newline at end of file
-- 
cgit v1.2.3

