DROP VIEW "public"."procurement_rfqs_view";--> statement-breakpoint
CREATE VIEW "public"."procurement_rfqs_view" AS (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", "items"."item_code" as "item_code", "items"."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", "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", (
                SELECT material_code 
                FROM pr_items 
                WHERE procurement_rfqs_id = "procurement_rfqs"."id"
                AND major_yn = true
                LIMIT 1
            ) as "major_item_material_code", (
                SELECT pr_no 
                FROM pr_items 
                WHERE procurement_rfqs_id = "procurement_rfqs"."id"
                AND major_yn = true
                LIMIT 1
            ) as "po_no", (
                SELECT COUNT(*) 
                FROM pr_items 
                WHERE procurement_rfqs_id = "procurement_rfqs"."id"
            ) as "pr_items_count" from "procurement_rfqs" left join "projects" on "procurement_rfqs"."project_id" = "projects"."id" left join "items" on "procurement_rfqs"."item_id" = "items"."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");