Add Asset Management app
Assets from purchase invoice lines, straight-line depreciation/amortization with salvage value, disposals, and [Asset Mgmt] sources in Batch GL Entries. Green third workspace with an app access guard.
This commit is contained in:
@@ -97,7 +97,7 @@ CREATE TABLE IF NOT EXISTS `user` (
|
||||
`language` varchar(3) NOT NULL DEFAULT 'th',
|
||||
`regis_date` timestamp NOT NULL DEFAULT current_timestamp(),
|
||||
`license` enum('owner','user') NOT NULL DEFAULT 'owner',
|
||||
`app_access` enum('all','wms','accounting') NOT NULL DEFAULT 'all',
|
||||
`app_access` enum('all','wms','accounting','asset') NOT NULL DEFAULT 'all',
|
||||
`active` varchar(255) NOT NULL DEFAULT 'yes',
|
||||
`phone` varchar(50) NOT NULL DEFAULT '',
|
||||
`verify_token` varchar(64) DEFAULT NULL,
|
||||
@@ -114,6 +114,9 @@ CREATE TABLE IF NOT EXISTS `user` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
", 'user');
|
||||
|
||||
// Existing databases were created before the Asset Management app existed.
|
||||
run($pdo, "ALTER TABLE `user` MODIFY `app_access` enum('all','wms','accounting','asset') NOT NULL DEFAULT 'all'", 'user.app_access includes asset');
|
||||
|
||||
run($pdo, "
|
||||
CREATE TABLE IF NOT EXISTS `company_list` (
|
||||
`company_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
@@ -1217,6 +1220,106 @@ CREATE TABLE IF NOT EXISTS `document_number_sequences` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
", 'document_number_sequences');
|
||||
|
||||
// ── Asset management ──────────────────────────────────────────────────────────
|
||||
// Categories carry the GL accounts; td_asset_depreciation holds one row per
|
||||
// asset per month and td_asset_run groups those rows into one GL entry.
|
||||
run($pdo, "
|
||||
CREATE TABLE IF NOT EXISTS `md_asset_category` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`company_id` int(11) NOT NULL,
|
||||
`category_code` varchar(20) NOT NULL,
|
||||
`category_name` varchar(255) NOT NULL,
|
||||
`asset_class` enum('tangible','intangible') NOT NULL DEFAULT 'tangible',
|
||||
`useful_life_months` int(11) NOT NULL DEFAULT 60,
|
||||
`cost_account_code` varchar(20) NOT NULL DEFAULT '',
|
||||
`accum_account_code` varchar(20) NOT NULL DEFAULT '',
|
||||
`expense_account_code` varchar(20) NOT NULL DEFAULT '',
|
||||
`gain_account_code` varchar(20) NOT NULL DEFAULT '',
|
||||
`loss_account_code` varchar(20) NOT NULL DEFAULT '',
|
||||
`description` text DEFAULT NULL,
|
||||
`status` tinyint(1) NOT NULL DEFAULT 1,
|
||||
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`updated_at` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uq_company_category` (`company_id`,`category_code`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
", 'md_asset_category');
|
||||
|
||||
run($pdo, "
|
||||
CREATE TABLE IF NOT EXISTS `td_asset` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`company_id` int(11) NOT NULL DEFAULT 0,
|
||||
`asset_number` varchar(50) NOT NULL DEFAULT '',
|
||||
`asset_name` varchar(255) NOT NULL DEFAULT '',
|
||||
`category_id` int(11) NOT NULL DEFAULT 0,
|
||||
`asset_class` enum('tangible','intangible') NOT NULL DEFAULT 'tangible',
|
||||
`description` text NOT NULL DEFAULT '',
|
||||
`source` varchar(20) NOT NULL DEFAULT 'manual' COMMENT 'manual | purchase_invoice',
|
||||
`invoice_id` int(11) unsigned NOT NULL DEFAULT 0,
|
||||
`invoice_item_id` int(11) unsigned NOT NULL DEFAULT 0,
|
||||
`contact_id` int(11) NOT NULL DEFAULT 0,
|
||||
`department_id` int(11) NOT NULL DEFAULT 0,
|
||||
`acquisition_date` date DEFAULT NULL,
|
||||
`in_service_date` date DEFAULT NULL,
|
||||
`cost` decimal(18,4) NOT NULL DEFAULT 0.0000,
|
||||
`salvage_value` decimal(18,4) NOT NULL DEFAULT 0.0000,
|
||||
`useful_life_months` int(11) NOT NULL DEFAULT 0,
|
||||
`clearing_account_code` varchar(20) NOT NULL DEFAULT '' COMMENT 'credited by the capitalization entry; empty = no entry',
|
||||
`status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '0 draft, 1 active, 2 fully depreciated, 3 disposed, 4 void',
|
||||
`disposal_date` date DEFAULT NULL,
|
||||
`sale_price` decimal(18,4) NOT NULL DEFAULT 0.0000,
|
||||
`proceeds_account_code` varchar(20) NOT NULL DEFAULT '',
|
||||
`disposal_notes` text NOT NULL DEFAULT '',
|
||||
`created_by` int(11) NOT NULL DEFAULT 0,
|
||||
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`updated_at` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `company_status` (`company_id`,`status`),
|
||||
KEY `company_invoice` (`company_id`,`invoice_id`),
|
||||
KEY `category_id` (`category_id`),
|
||||
KEY `asset_number` (`asset_number`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
", 'td_asset');
|
||||
|
||||
run($pdo, "
|
||||
CREATE TABLE IF NOT EXISTS `td_asset_run` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`company_id` int(11) NOT NULL DEFAULT 0,
|
||||
`run_number` varchar(50) NOT NULL DEFAULT '',
|
||||
`asset_class` enum('tangible','intangible') NOT NULL DEFAULT 'tangible',
|
||||
`period` varchar(7) NOT NULL DEFAULT '',
|
||||
`run_date` date NOT NULL,
|
||||
`asset_count` int(11) NOT NULL DEFAULT 0,
|
||||
`total_amount` decimal(18,4) NOT NULL DEFAULT 0.0000,
|
||||
`status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '1 active, 4 void',
|
||||
`created_by` int(11) NOT NULL DEFAULT 0,
|
||||
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
`voided_at` datetime DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `company_period` (`company_id`,`period`,`asset_class`),
|
||||
KEY `status` (`status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
", 'td_asset_run');
|
||||
|
||||
run($pdo, "
|
||||
CREATE TABLE IF NOT EXISTS `td_asset_depreciation` (
|
||||
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`company_id` int(11) NOT NULL DEFAULT 0,
|
||||
`asset_id` int(11) unsigned NOT NULL DEFAULT 0,
|
||||
`run_id` int(11) unsigned NOT NULL DEFAULT 0,
|
||||
`period` varchar(7) NOT NULL DEFAULT '',
|
||||
`category_id` int(11) NOT NULL DEFAULT 0 COMMENT 'snapshot at run time; GL lines group by it',
|
||||
`department_id` int(11) NOT NULL DEFAULT 0 COMMENT 'snapshot at run time; GL lines group by it',
|
||||
`amount` decimal(18,4) NOT NULL DEFAULT 0.0000,
|
||||
`accumulated_after` decimal(18,4) NOT NULL DEFAULT 0.0000,
|
||||
`book_value_after` decimal(18,4) NOT NULL DEFAULT 0.0000,
|
||||
`created_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uq_asset_period` (`company_id`,`asset_id`,`period`),
|
||||
KEY `run_id` (`company_id`,`run_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;
|
||||
", 'td_asset_depreciation');
|
||||
|
||||
// ── Summary ───────────────────────────────────────────────────────────────────
|
||||
$total = $ok_count + $skip_count + $err_count;
|
||||
echo "\n\033[1m=== Done ===\033[0m\n";
|
||||
|
||||
Reference in New Issue
Block a user