-- Opening Balance Master
CREATE TABLE opening_balance_master (
balance_id INT PRIMARY KEY AUTO_INCREMENT,
company_id INT NOT NULL,
fiscal_year_id INT NOT NULL,
entry_date DATE NOT NULL,
status ENUM('draft', 'posted', 'approved') DEFAULT 'draft',
created_by INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
approved_by INT,
approved_at TIMESTAMP
FOREIGN KEY (company_id) REFERENCES companies(company_id),
FOREIGN KEY (fiscal_year_id) REFERENCES fiscal_years(fiscal_year_id)
);
-- Account Opening Balances
CREATE TABLE account_opening_balances (
entry_id INT PRIMARY KEY AUTO_INCREMENT,
balance_id INT NOT NULL,
account_id INT NOT NULL,
debit_amount DECIMAL(18,2) DEFAULT 0.00,
credit_amount DECIMAL(18,2) DEFAULT 0.00,
notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (balance_id) REFERENCES opening_balance_master(balance_id),
FOREIGN KEY (account_id) REFERENCES chart_of_accounts(account_id)
);
-- Inventory Opening Balances
CREATE TABLE inventory_opening_balances (
entry_id INT PRIMARY KEY AUTO_INCREMENT,
balance_id INT NOT NULL,
item_id INT NOT NULL,
quantity DECIMAL(12,3) NOT NULL,
rate DECIMAL(18,2) NOT NULL,
value DECIMAL(18,2) NOT NULL,
batch_number VARCHAR(50),
manufacturing_date DATE,
expiry_date DATE,
warehouse_id INT,
notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (balance_id) REFERENCES opening_balance_master(balance_id),
FOREIGN KEY (item_id) REFERENCES inventory_items(item_id),
FOREIGN KEY (warehouse_id) REFERENCES warehouses(warehouse_id)
);
-- Party Opening Balances
CREATE TABLE party_opening_balances (
entry_id INT PRIMARY KEY AUTO_INCREMENT,
balance_id INT NOT NULL,
party_id INT NOT NULL,
balance_type ENUM('receivable', 'payable') NOT NULL,
invoice_number VARCHAR(50),
invoice_date DATE,
amount DECIMAL(18,2) NOT NULL,
due_date DATE,
notes TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (balance_id) REFERENCES opening_balance_master(balance_id),
FOREIGN KEY (party_id) REFERENCES parties(party_id)
);
-- Opening Balance Attachments
CREATE TABLE opening_balance_attachments (
attachment_id INT PRIMARY KEY AUTO_INCREMENT,
balance_id INT NOT NULL,
file_name VARCHAR(255) NOT NULL,
file_path VARCHAR(255) NOT NULL,
file_type VARCHAR(50) NOT NULL,
upload_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (balance_id) REFERENCES opening_balance_master(balance_id)
);3 errors were found during analysis.
A comma or a closing bracket was expected. (near "FOREIGN KEY" at position 410)
Unexpected beginning of statement. (near "company_id" at position 423)
Unrecognized statement type. (near "REFERENCES" at position 435)
SQL query: Copy
-- Opening Balance Master CREATE TABLE opening_balance_master ( balance_id INT PRIMARY KEY AUTO_INCREMENT, company_id INT NOT NULL, fiscal_year_id INT NOT NULL, entry_date DATE NOT NULL, status ENUM('draft', 'posted', 'approved') DEFAULT 'draft', created_by INT NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, approved_by INT, approved_at TIMESTAMP FOREIGN KEY (company_id) REFERENCES companies(company_id), FOREIGN KEY (fiscal_year_id) REFERENCES fiscal_years(fiscal_year_id) );