diff options
Diffstat (limited to 'db/migrations/0057_good_reaper.sql')
| -rw-r--r-- | db/migrations/0057_good_reaper.sql | 43 |
1 files changed, 43 insertions, 0 deletions
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 |
