From e46b7ccad4db812dfc8455b20425469afad61788 Mon Sep 17 00:00:00 2001
From: dujinkim <dujin.kim@dtsolution.co.kr>
Date: Tue, 13 May 2025 03:07:39 +0000
Subject: (대표님) drizzle-kit migrations and snapshots
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 db/migrations/0057_good_reaper.sql | 43 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 db/migrations/0057_good_reaper.sql

(limited to 'db/migrations/0057_good_reaper.sql')

diff --git a/db/migrations/0057_good_reaper.sql b/db/migrations/0057_good_reaper.sql
new file mode 100644
index 00000000..9232850c
--- /dev/null
+++ b/db/migrations/0057_good_reaper.sql
@@ -0,0 +1,43 @@
+DROP VIEW "public"."procurement_rfq_details_view";--> statement-breakpoint
+CREATE VIEW "public"."procurement_rfq_details_view" AS (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", "items"."item_code" as "item_code", "items"."item_name" as "item_name", "vendors"."vendor_name" as "vendor_name", "vendors"."vendor_code" as "vendor_code", "vendors"."id" as "vendor_id", "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", (
+              SELECT COUNT(*) 
+              FROM pr_items 
+              WHERE procurement_rfqs_id = "rfqs"."id"
+          ) as "pr_items_count", (
+              SELECT COUNT(*) 
+              FROM pr_items 
+              WHERE procurement_rfqs_id = "rfqs"."id" 
+              AND major_yn = true
+          ) as "major_items_count", (
+                SELECT COUNT(*) 
+                FROM procurement_rfq_comments 
+                WHERE rfq_id = "rfqs"."id" AND vendor_id = "rfq_details"."vendors_id"
+            ) as "comment_count", (
+                SELECT created_at 
+                FROM procurement_rfq_comments 
+                WHERE rfq_id = "rfqs"."id" AND vendor_id = "rfq_details"."vendors_id"
+                ORDER BY created_at DESC LIMIT 1
+            ) as "last_comment_date", (
+                SELECT created_at 
+                FROM procurement_rfq_comments 
+                WHERE rfq_id = "rfqs"."id" AND vendor_id = "rfq_details"."vendors_id" AND is_vendor_comment = true
+                ORDER BY created_at DESC LIMIT 1
+            ) as "last_vendor_comment_date", (
+                SELECT COUNT(*) 
+                FROM procurement_rfq_attachments 
+                WHERE rfq_id = "rfqs"."id" AND vendor_id = "rfq_details"."vendors_id"
+            ) as "attachment_count", (
+                SELECT COUNT(*) > 0
+                FROM procurement_vendor_quotations
+                WHERE rfq_id = "rfqs"."id" AND vendor_id = "rfq_details"."vendors_id"
+            ) as "has_quotation", (
+                SELECT status
+                FROM procurement_vendor_quotations
+                WHERE rfq_id = "rfqs"."id" AND vendor_id = "rfq_details"."vendors_id"
+                ORDER BY created_at DESC LIMIT 1
+            ) as "quotation_status", (
+                SELECT total_price
+                FROM procurement_vendor_quotations
+                WHERE rfq_id = "rfqs"."id" AND vendor_id = "rfq_details"."vendors_id"
+                ORDER BY created_at DESC LIMIT 1
+            ) as "quotation_total_price" 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 "items" on "rfqs"."item_id" = "items"."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");
\ No newline at end of file
-- 
cgit v1.2.3

