0
Hỏi về truy vấn và hiển thị Balance Sheet
Xin chào mọi người, mình có những bảng như bên dưới, mình có thể viết câu lệnh truy vấn như nào để hiển thị được bảng như trong hình ?! Rất mong nhận được sự giúp đỡ của mọi người.
Mình đã viết hàm lấy dữ liệu như hình dưới này mà không thể nào hiển thị được bảng như ảnh trên
DROP TABLE IF EXISTS `accounting_assets`;
CREATE TABLE `accounting_assets` (
`asset_id` int(11) NOT NULL AUTO_INCREMENT,
`asset_name` varchar(100) NOT NULL,
`finance_type_id` int(11) NOT NULL,
`purchase_date` date DEFAULT NULL,
`purchase_price` decimal(10,2) NOT NULL,
`current_value` decimal(10,2) NOT NULL,
`depreciation_rate` decimal(4,2) NOT NULL,
`description` varchar(200) NOT NULL,
`date_created` datetime DEFAULT NULL,
`date_updated` datetime DEFAULT NULL,
`status` tinyint(4) NOT NULL,
PRIMARY KEY (`asset_id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `accounting_assets_entries`;
CREATE TABLE `accounting_assets_entries` (
`asset_entry_id` int(11) NOT NULL AUTO_INCREMENT,
`asset_id` int(11) NOT NULL,
`add_amount` decimal(10,2) NOT NULL,
`less_amount` decimal(10,2) NOT NULL,
`transaction_date` date DEFAULT NULL,
`date_created` datetime DEFAULT NULL,
`date_updated` datetime DEFAULT NULL,
PRIMARY KEY (`asset_entry_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `accounting_equity`;
CREATE TABLE `accounting_equity` (
`equity_id` int(11) NOT NULL AUTO_INCREMENT,
`equity_name` varchar(100) NOT NULL,
`finance_type_id` int(11) NOT NULL,
`issuance_date` date DEFAULT NULL,
`issuance_price` decimal(10,2) NOT NULL,
`current_value` decimal(10,2) NOT NULL,
`description` varchar(200) NOT NULL,
`date_created` datetime NOT NULL,
`date_updated` datetime NOT NULL,
`status` tinyint(4) NOT NULL,
PRIMARY KEY (`equity_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `accounting_equity_entries`;
CREATE TABLE `accounting_equity_entries` (
`equity_entry_id` int(11) NOT NULL AUTO_INCREMENT,
`equity_id` int(11) NOT NULL,
`add_amount` decimal(10,2) NOT NULL,
`less_amount` decimal(10,2) NOT NULL,
`transaction_date` date DEFAULT NULL,
`date_created` datetime DEFAULT NULL,
`date_updated` datetime DEFAULT NULL,
PRIMARY KEY (`equity_entry_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `accounting_finance_category`;
CREATE TABLE `accounting_finance_category` (
`category_type_id` int(11) NOT NULL AUTO_INCREMENT,
`category_type_name` varchar(100) NOT NULL,
`date_created` datetime DEFAULT NULL,
`date_updated` datetime DEFAULT NULL,
PRIMARY KEY (`category_type_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `accounting_finance_type`;
CREATE TABLE `accounting_finance_type` (
`finance_type_id` int(11) NOT NULL AUTO_INCREMENT,
`finance_category_id` int(11) NOT NULL,
`finance_type_name` varchar(100) NOT NULL,
`date_created` datetime DEFAULT NULL,
`date_updated` datetime DEFAULT NULL,
`status` tinyint(4) NOT NULL,
PRIMARY KEY (`finance_type_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `accounting_liabilities`;
CREATE TABLE `accounting_liabilities` (
`liability_id` int(11) NOT NULL AUTO_INCREMENT,
`liability_name` varchar(100) NOT NULL,
`finance_type_id` int(11) NOT NULL,
`incurred_date` date DEFAULT NULL,
`original_amount` decimal(10,2) NOT NULL,
`current_balance` decimal(10,2) NOT NULL,
`interest_rate` decimal(4,2) NOT NULL,
`description` varchar(200) NOT NULL,
`date_created` datetime DEFAULT NULL,
`date_updated` datetime DEFAULT NULL,
`status` tinyint(4) NOT NULL,
PRIMARY KEY (`liability_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;
DROP TABLE IF EXISTS `accounting_liabilities_entries`;
CREATE TABLE `accounting_liabilities_entries` (
`liability_entry_id` int(11) NOT NULL AUTO_INCREMENT,
`liability_id` int(11) NOT NULL,
`add_amount` decimal(10,2) NOT NULL,
`less_amount` decimal(10,2) NOT NULL,
`transaction_date` date DEFAULT NULL,
`date_created` datetime DEFAULT NULL,
`date_updated` datetime DEFAULT NULL,
PRIMARY KEY (`liability_entry_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `accounting_assets` (`asset_id`, `asset_name`, `finance_type_id`, `purchase_date`, `purchase_price`, `current_value`, `depreciation_rate`, `description`, `date_created`, `date_updated`, `status`) VALUES
(1, 'Cash and cash equivalents', 1, NULL, 0.00, 160000.00, 0.00, 'TEST', '2023-03-24 16:11:14', '2023-03-24 16:15:43', 0),
(2, 'Accounts receivable', 1, NULL, 0.00, 45000.00, 0.00, '', '2023-03-24 16:12:23', '2023-03-24 16:12:23', 0),
(3, 'Prepaid expenses', 1, NULL, 0.00, 55000.00, 0.00, '', '2023-03-24 16:13:05', '2023-03-24 16:13:05', 0),
(4, 'Investments', 2, NULL, 0.00, 150000.00, 0.00, '', '2023-03-24 16:13:36', '2023-03-24 16:13:36', 0),
(5, 'Buildings and faclitities', 2, NULL, 0.00, 1000000.00, 0.00, '', '2023-03-24 16:14:04', '2023-03-24 16:14:04', 0),
(6, 'Land', 2, NULL, 0.00, 500000.00, 0.00, '', '2023-03-24 16:14:24', '2023-03-24 16:14:24', 0),
(7, 'Equipment abd supplies', 2, NULL, 0.00, 250000.00, 0.00, '', '2023-03-24 16:15:10', '2023-03-24 16:15:10', 0);
INSERT INTO `accounting_assets_entries` (`asset_entry_id`, `asset_id`, `add_amount`, `less_amount`, `transaction_date`, `date_created`, `date_updated`) VALUES
(1, 1, 10000.00, 0.00, '2019-01-01', '2023-03-25 21:49:42', '2023-03-25 21:49:42'),
(2, 2, 20000.00, 0.00, '2020-03-02', '2023-03-25 21:50:03', '2023-03-25 21:50:03'),
(3, 3, 30000.00, 0.00, '2021-05-07', '2023-03-25 21:50:40', '2023-03-25 21:50:40'),
(4, 4, 50000.00, 0.00, '2018-12-16', '2023-03-25 21:59:59', '2023-03-25 21:59:59'),
(5, 3, 15000.00, 0.00, '2018-12-16', '2023-03-25 22:01:05', '2023-03-25 22:01:05');
INSERT INTO `accounting_equity` (`equity_id`, `equity_name`, `finance_type_id`, `issuance_date`, `issuance_price`, `current_value`, `description`, `date_created`, `date_updated`, `status`) VALUES
(1, 'Retained earnings', 5, NULL, 0.00, 610000.00, '', '2023-03-24 17:59:44', '2023-03-24 17:59:44', 0),
(2, 'Capital contributions', 5, NULL, 0.00, 400000.00, '', '2023-03-24 18:00:16', '2023-03-24 18:00:16', 0);
INSERT INTO `accounting_finance_category` (`category_type_id`, `category_type_name`, `date_created`, `date_updated`) VALUES
(1, 'Asset', NULL, NULL),
(2, 'Equity', NULL, NULL),
(3, 'Liability', NULL, NULL);
INSERT INTO `accounting_finance_type` (`finance_type_id`, `finance_category_id`, `finance_type_name`, `date_created`, `date_updated`, `status`) VALUES
(1, 1, 'Curent Assets', '2023-03-24 10:27:15', '2023-03-24 10:27:15', 0),
(2, 1, 'Non Curent Assets', '2023-03-24 10:27:25', '2023-03-24 10:27:25', 0),
(3, 3, 'Current Liability', '2023-03-24 16:16:25', '2023-03-24 16:16:25', 0),
(4, 3, 'Non Current Liability', '2023-03-24 16:16:30', '2023-03-24 16:16:30', 0),
(5, 2, 'Default Equity', '2023-03-24 17:54:31', '2023-03-24 17:54:31', 0);
INSERT INTO `accounting_liabilities` (`liability_id`, `liability_name`, `finance_type_id`, `incurred_date`, `original_amount`, `current_balance`, `interest_rate`, `description`, `date_created`, `date_updated`, `status`) VALUES
(1, 'Accounts Payable', 3, NULL, 0.00, 20000.00, 0.00, '', '2023-03-24 16:16:48', '2023-03-24 16:16:48', 0),
(2, 'Accrued Expense', 3, NULL, 0.00, 15000.00, 0.00, '', '2023-03-24 16:17:24', '2023-03-24 16:17:24', 0),
(3, 'Short-term loans', 3, NULL, 0.00, 50000.00, 0.00, '', '2023-03-24 16:17:57', '2023-03-24 16:17:57', 0),
(4, 'Deferred revenue', 3, NULL, 0.00, 40000.00, 0.00, '', '2023-03-24 16:18:48', '2023-03-24 16:18:48', 0),
(5, 'Long-term loans', 4, NULL, 0.00, 800000.00, 0.00, '', '2023-03-24 16:19:55', '2023-03-24 16:19:55', 0);
1 CÂU TRẢ LỜI
0
Từng bước theo thứ tự:
- Viết store procedure (trong thực tế, tôi đang làm, dài 1_166 dòng code SQL)
- Đổ dữ liệu ra bảng (table) tạm. Bảng tạm này có cấu trúc tương tự như hình ảnh trực quan nhìn thấy.
- Dùng thư viện reporting (ví dụ trong Java có BIRT reporting), để hiển thị dữ liệu.
bạn sử dụng union nhé