1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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");
|