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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
CREATE TABLE "general_contract_attachments" (
"id" serial PRIMARY KEY NOT NULL,
"contract_id" integer NOT NULL,
"document_name" varchar(255) NOT NULL,
"file_name" varchar(255) NOT NULL,
"file_path" varchar(512) NOT NULL,
"shi_comment" text,
"vendor_comment" text,
"legal_review" boolean DEFAULT false NOT NULL,
"uploaded_at" timestamp DEFAULT now() NOT NULL,
"uploaded_by_id" integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE "general_contract_items" (
"id" serial PRIMARY KEY NOT NULL,
"contract_id" integer NOT NULL,
"project" varchar(255),
"item_code" varchar(100),
"item_info" varchar(500),
"specification" varchar(500),
"quantity" numeric(15, 3),
"quantity_unit" varchar(50),
"contract_delivery_date" date,
"contract_unit_price" numeric(15, 2),
"contract_amount" numeric(15, 2),
"contract_currency" varchar(10),
"created_at" timestamp DEFAULT now() NOT NULL,
"updated_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE "general_contract_templates" (
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "general_contract_templates_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
"contract_template_type" varchar(2) NOT NULL,
"contract_template_name" text NOT NULL,
"revision" integer DEFAULT 1 NOT NULL,
"status" varchar(20) DEFAULT 'ACTIVE' NOT NULL,
"file_name" varchar(255),
"file_path" varchar(1024),
"legal_review_required" boolean DEFAULT false NOT NULL,
"created_at" timestamp DEFAULT now(),
"created_by" integer,
"updated_at" timestamp DEFAULT now(),
"updated_by" integer,
"disposed_at" timestamp,
"restored_at" timestamp
);
--> statement-breakpoint
CREATE TABLE "general_contracts" (
"id" serial PRIMARY KEY NOT NULL,
"contract_number" varchar(255) NOT NULL,
"revision" integer DEFAULT 0 NOT NULL,
"status" varchar(50) NOT NULL,
"category" varchar(50) NOT NULL,
"type" varchar(50) NOT NULL,
"execution_method" varchar(50) NOT NULL,
"name" varchar(255) NOT NULL,
"selection_method" varchar(50),
"vendor_id" integer NOT NULL,
"start_date" date NOT NULL,
"end_date" date NOT NULL,
"validity_end_date" date NOT NULL,
"linked_rfq_or_itb" varchar(255),
"linked_po_number" varchar(255),
"linked_bid_number" varchar(255),
"contract_scope" varchar(50),
"warranty_period" jsonb DEFAULT '{}'::jsonb,
"specification_type" varchar(50),
"specification_manual_text" text,
"unit_price_type" varchar(50),
"contract_amount" numeric(15, 2),
"currency" varchar(10),
"total_amount" numeric(15, 2),
"available_budget" numeric(15, 2),
"payment_before_delivery" jsonb DEFAULT '{}'::jsonb,
"payment_delivery" varchar(50),
"payment_after_delivery" jsonb DEFAULT '{}'::jsonb,
"contract_currency" varchar(10),
"payment_term" varchar(50),
"tax_type" varchar(50),
"liquidated_damages" numeric(15, 2),
"liquidated_damages_percent" numeric(5, 2),
"claim_amount" jsonb DEFAULT '{}'::jsonb,
"delivery_type" varchar(50),
"delivery_term" varchar(50),
"shipping_location" varchar(100),
"discharge_location" varchar(100),
"contract_delivery_date" date,
"contract_establishment_conditions" jsonb DEFAULT '{}'::jsonb,
"interlocking_system" varchar(10),
"mandatory_documents" jsonb DEFAULT '{}'::jsonb,
"contract_termination_conditions" jsonb DEFAULT '{}'::jsonb,
"terms" jsonb DEFAULT '{}'::jsonb,
"compliance_checklist" jsonb DEFAULT '{}'::jsonb,
"communication_channels" jsonb DEFAULT '{}'::jsonb,
"locations" jsonb DEFAULT '{}'::jsonb,
"field_service_rates" jsonb DEFAULT '{}'::jsonb,
"offset_details" jsonb DEFAULT '{}'::jsonb,
"registered_by_id" integer NOT NULL,
"registered_at" timestamp DEFAULT now() NOT NULL,
"signed_at" timestamp,
"last_updated_by_id" integer NOT NULL,
"last_updated_at" timestamp DEFAULT now() NOT NULL,
"notes" text,
CONSTRAINT "general_contracts_contract_number_unique" UNIQUE("contract_number")
);
--> statement-breakpoint
DROP VIEW "public"."basic_contract_view";--> statement-breakpoint
ALTER TABLE "basic_contract" ADD COLUMN "bidding_company_id" integer;--> statement-breakpoint
ALTER TABLE "basic_contract" ADD COLUMN "rfq_company_id" integer;--> statement-breakpoint
ALTER TABLE "basic_contract" ADD COLUMN "general_contract_id" integer;--> statement-breakpoint
ALTER TABLE "general_contract_attachments" ADD CONSTRAINT "general_contract_attachments_contract_id_general_contracts_id_fk" FOREIGN KEY ("contract_id") REFERENCES "public"."general_contracts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "general_contract_attachments" ADD CONSTRAINT "general_contract_attachments_uploaded_by_id_users_id_fk" FOREIGN KEY ("uploaded_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "general_contract_items" ADD CONSTRAINT "general_contract_items_contract_id_general_contracts_id_fk" FOREIGN KEY ("contract_id") REFERENCES "public"."general_contracts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "general_contract_templates" ADD CONSTRAINT "general_contract_templates_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "general_contract_templates" ADD CONSTRAINT "general_contract_templates_updated_by_users_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "general_contracts" ADD CONSTRAINT "general_contracts_vendor_id_vendors_id_fk" FOREIGN KEY ("vendor_id") REFERENCES "public"."vendors"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "general_contracts" ADD CONSTRAINT "general_contracts_registered_by_id_users_id_fk" FOREIGN KEY ("registered_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "general_contracts" ADD CONSTRAINT "general_contracts_last_updated_by_id_users_id_fk" FOREIGN KEY ("last_updated_by_id") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "basic_contract" ADD CONSTRAINT "basic_contract_bidding_company_id_bidding_companies_id_fk" FOREIGN KEY ("bidding_company_id") REFERENCES "public"."bidding_companies"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "basic_contract" ADD CONSTRAINT "basic_contract_rfq_company_id_rfq_last_details_id_fk" FOREIGN KEY ("rfq_company_id") REFERENCES "public"."rfq_last_details"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "basic_contract" ADD CONSTRAINT "basic_contract_general_contract_id_general_contracts_id_fk" FOREIGN KEY ("general_contract_id") REFERENCES "public"."general_contracts"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
CREATE VIEW "public"."basic_contract_view" AS (select "basic_contract"."id" as "id", "basic_contract"."template_id" as "template_id", "basic_contract"."vendor_id" as "vendor_id", "basic_contract"."requested_by" as "requested_by", "basic_contract"."status" as "basic_contract_status", "basic_contract"."rfq_company_id" as "rfq_ompany_id", "basic_contract"."bidding_company_id" as "bidding_company_id", "basic_contract"."general_contract_id" as "general_contract_id", "basic_contract"."deadline" as "deadline", "basic_contract"."vendor_signed_at" as "vendor_signed_at", "basic_contract"."buyer_signed_at" as "buyer_signed_at", "basic_contract"."legal_review_requested_at" as "legal_review_requested_at", "basic_contract"."legal_review_completed_at" as "legal_review_completed_at", "basic_contract"."created_at" as "created_at", "basic_contract"."updated_at" as "updated_at", "basic_contract"."completed_at" as "completed_at", "vendors"."vendor_code" as "vendor_code", "vendors"."email" as "vendor_email", "vendors"."vendor_name" as "vendor_name", "users"."name" as "requested_by_name", "basic_contract_templates"."template_name" as "template_name", "basic_contract_templates"."revision" as "template_revision", "basic_contract_templates"."status" as "template_status", "basic_contract_templates"."validity_period" as "validity_period", "basic_contract_templates"."legal_review_required" as "legal_review_required", "basic_contract_templates"."file_path" as "template_file_path", "basic_contract_templates"."file_name" as "template_file_name", "basic_contract"."file_path" as "signed_file_path", "basic_contract"."file_name" as "signed_file_name", "basic_contract_templates"."created_at" as "template_created_at", "basic_contract_templates"."created_by" as "template_created_by", "basic_contract_templates"."updated_at" as "template_updated_at", "basic_contract_templates"."updated_by" as "template_updated_by", "basic_contract_templates"."disposed_at" as "template_disposed_at", "basic_contract_templates"."restored_at" as "template_restored_at" from "basic_contract" left join "vendors" on "basic_contract"."vendor_id" = "vendors"."id" left join "users" on "basic_contract"."requested_by" = "users"."id" left join "basic_contract_templates" on "basic_contract"."template_id" = "basic_contract_templates"."id");
|