mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
Merge branch 'development' of https://gitlab.com/mbugroup/lti-api into dev/ragil
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
CREATE TABLE expenses (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
reference_number VARCHAR, -- format => BOP-LTI-0001 = 0001 is increment
|
||||
reference_number VARCHAR(50) UNIQUE NOT NULL,
|
||||
supplier_id BIGINT NULL,
|
||||
category VARCHAR(50) NOT NULL CHECK (
|
||||
category IN ('BOP', 'NON-BOP')
|
||||
),
|
||||
po_number VARCHAR(50) UNIQUE NOT NULL,
|
||||
po_number VARCHAR(50) NULL,
|
||||
document_path JSON,
|
||||
realization_document_path JSON,
|
||||
expense_date DATE NOT NULL,
|
||||
realization_date DATE,
|
||||
grand_total NUMERIC(15, 3) DEFAULT 0,
|
||||
note TEXT,
|
||||
created_by BIGINT,
|
||||
@@ -16,6 +18,8 @@ CREATE TABLE expenses (
|
||||
deleted_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
CREATE SEQUENCE expenses_ref_seq INCREMENT BY 1 START WITH 1;
|
||||
|
||||
-- Tambahkan Foreign Key ke suppliers
|
||||
DO $$
|
||||
BEGIN
|
||||
@@ -23,7 +27,9 @@ BEGIN
|
||||
ALTER TABLE expenses
|
||||
ADD CONSTRAINT fk_expenses_supplier_id
|
||||
FOREIGN KEY (supplier_id) REFERENCES suppliers(id);
|
||||
END IF;
|
||||
|
||||
END IF;
|
||||
|
||||
END $$;
|
||||
|
||||
-- Tambahkan Foreign Key ke users (created_by)
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
DROP TABLE IF EXISTS expense_nonstocks;
|
||||
DROP TABLE IF EXISTS expense_nonstocks;
|
||||
|
||||
DROP SEQUENCE expenses_ref_seq;
|
||||
@@ -1,15 +1,13 @@
|
||||
CREATE TABLE expense_nonstocks (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
expense_id BIGINT,
|
||||
project_flock_kandang_id BIGINT,
|
||||
expense_id BIGINT NOT NULL,
|
||||
project_flock_kandang_id BIGINT NULL,
|
||||
kandang_id BIGINT NULL,
|
||||
nonstock_id BIGINT,
|
||||
qty NUMERIC(15, 3) NOT NULL,
|
||||
unit_price NUMERIC(15, 3) NOT NULL,
|
||||
total_price NUMERIC(15, 3) NOT NULL,
|
||||
note TEXT NULL,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now(),
|
||||
deleted_at TIMESTAMPTZ
|
||||
note TEXT NULL
|
||||
);
|
||||
|
||||
-- Tambahkan Foreign Key ke expenses
|
||||
@@ -32,6 +30,16 @@ BEGIN
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Tambahkan Foreign key ke kandang_id
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'kandangs') THEN
|
||||
ALTER TABLE expense_nonstocks
|
||||
ADD CONSTRAINT fk_expense_nonstocks_kandang_id_2
|
||||
FOREIGN KEY (kandang_id) REFERENCES kandangs(id);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Tambahkan Foreign Key ke nonstocks
|
||||
DO $$
|
||||
BEGIN
|
||||
@@ -45,6 +53,4 @@ END $$;
|
||||
-- Index
|
||||
CREATE INDEX idx_expense_nonstocks_expense_id ON expense_nonstocks (expense_id);
|
||||
|
||||
CREATE INDEX idx_expense_nonstocks_nonstock_id ON expense_nonstocks (nonstock_id);
|
||||
|
||||
CREATE INDEX idx_expense_nonstocks_deleted_at ON expense_nonstocks (deleted_at);
|
||||
CREATE INDEX idx_expense_nonstocks_nonstock_id ON expense_nonstocks (nonstock_id);
|
||||
+3
-8
@@ -1,15 +1,12 @@
|
||||
CREATE TABLE expense_realizations (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
expense_nonstock_id BIGINT,
|
||||
expense_nonstock_id BIGINT UNIQUE,
|
||||
realization_qty NUMERIC(15, 3) NOT NULL,
|
||||
realization_unit_price NUMERIC(15, 3) NOT NULL,
|
||||
realization_total_price NUMERIC(15, 3) NOT NULL,
|
||||
realization_date DATE NOT NULL,
|
||||
note TEXT,
|
||||
created_by BIGINT,
|
||||
created_at TIMESTAMPTZ DEFAULT now(),
|
||||
updated_at TIMESTAMPTZ DEFAULT now(),
|
||||
deleted_at TIMESTAMPTZ
|
||||
created_by BIGINT
|
||||
);
|
||||
|
||||
-- Tambahkan Foreign Key ke expense_nonstocks
|
||||
@@ -35,6 +32,4 @@ END $$;
|
||||
-- Index
|
||||
CREATE INDEX idx_expense_realizations_nonstock_id ON expense_realizations (expense_nonstock_id);
|
||||
|
||||
CREATE INDEX idx_expense_realizations_date ON expense_realizations (realization_date);
|
||||
|
||||
CREATE INDEX idx_expense_realizations_deleted_at ON expense_realizations (deleted_at);
|
||||
CREATE INDEX idx_expense_realizations_date ON expense_realizations (realization_date);
|
||||
Reference in New Issue
Block a user