summaryrefslogtreecommitdiff
path: root/db/migrations/0320_aberrant_grim_reaper.sql
diff options
context:
space:
mode:
Diffstat (limited to 'db/migrations/0320_aberrant_grim_reaper.sql')
-rw-r--r--db/migrations/0320_aberrant_grim_reaper.sql42
1 files changed, 42 insertions, 0 deletions
diff --git a/db/migrations/0320_aberrant_grim_reaper.sql b/db/migrations/0320_aberrant_grim_reaper.sql
new file mode 100644
index 00000000..7f7eee5e
--- /dev/null
+++ b/db/migrations/0320_aberrant_grim_reaper.sql
@@ -0,0 +1,42 @@
+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 rfq_last_vendor_responses.rfqs_last_id = "rfqs_last"."id"
+ AND submitted_at IS NOT NULL
+ ) as "earliest_quotation_submitted_at", (
+ SELECT COUNT(*)
+ FROM rfq_last_details
+ WHERE rfq_last_vendor_responses.rfqs_last_id = "rfqs_last"."id"
+ ) as "vendor_count", (
+ SELECT COUNT(*)
+ FROM rfq_last_details
+ WHERE rfq_last_vendor_responses.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 rfq_last_vendor_responses.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 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