One Hat Cyber Team
Your IP :
216.73.216.55
Server IP :
5.189.175.239
Server :
Linux panel.gemx-ai.com 5.14.0-570.19.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 4 04:00:24 EDT 2025 x86_64
Server Software :
LiteSpeed
PHP Version :
8.2.28
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
farmersapp
/
loans.farmersapp.store
/
View File Name :
dd.sql
-- database_complete.sql -- Farmers Loan Management System - Complete Database Schema -- Version: 1.0.0 -- Created: 2024-01-15 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; -- -------------------------------------------------------- -- Database: farmersapp_loans -- -------------------------------------------------------- CREATE DATABASE IF NOT EXISTS `farmersapp_loans` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; USE `farmersapp_loans`; -- -------------------------------------------------------- -- Table structure for table `users` -- -------------------------------------------------------- CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `email` varchar(100) NOT NULL, `password` varchar(255) NOT NULL, `first_name` varchar(50) NOT NULL, `last_name` varchar(50) NOT NULL, `phone` varchar(20) DEFAULT NULL, `role_id` int(11) NOT NULL, `branch_id` int(11) DEFAULT NULL, `profile_image` varchar(255) DEFAULT NULL, `status` enum('active','inactive','suspended','pending') DEFAULT 'active', `last_login` datetime DEFAULT NULL, `login_attempts` int(11) DEFAULT 0, `password_reset_token` varchar(100) DEFAULT NULL, `password_reset_expiry` datetime DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`), UNIQUE KEY `email` (`email`), KEY `role_id` (`role_id`), KEY `branch_id` (`branch_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `roles` -- -------------------------------------------------------- CREATE TABLE `roles` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `description` text DEFAULT NULL, `permissions` text DEFAULT NULL, `is_system` tinyint(1) DEFAULT 0, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `branches` -- -------------------------------------------------------- CREATE TABLE `branches` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `code` varchar(20) NOT NULL, `address` text DEFAULT NULL, `phone` varchar(20) DEFAULT NULL, `email` varchar(100) DEFAULT NULL, `manager_id` int(11) DEFAULT NULL, `status` enum('active','inactive') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`), KEY `manager_id` (`manager_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `borrowers` -- -------------------------------------------------------- CREATE TABLE `borrowers` ( `id` int(11) NOT NULL AUTO_INCREMENT, `borrower_no` varchar(20) NOT NULL, `first_name` varchar(50) NOT NULL, `last_name` varchar(50) NOT NULL, `gender` enum('male','female','other') DEFAULT NULL, `date_of_birth` date DEFAULT NULL, `marital_status` enum('single','married','divorced','widowed') DEFAULT NULL, `national_id` varchar(50) DEFAULT NULL, `phone` varchar(20) NOT NULL, `email` varchar(100) DEFAULT NULL, `address` text NOT NULL, `city` varchar(50) DEFAULT NULL, `state` varchar(50) DEFAULT NULL, `country` varchar(50) DEFAULT 'Malawi', `postal_code` varchar(20) DEFAULT NULL, `occupation` varchar(100) DEFAULT NULL, `monthly_income` decimal(15,2) DEFAULT 0.00, `employer_name` varchar(100) DEFAULT NULL, `employer_address` text DEFAULT NULL, `employer_phone` varchar(20) DEFAULT NULL, `next_of_kin_name` varchar(100) DEFAULT NULL, `next_of_kin_phone` varchar(20) DEFAULT NULL, `next_of_kin_relationship` varchar(50) DEFAULT NULL, `bank_name` varchar(100) DEFAULT NULL, `bank_account` varchar(50) DEFAULT NULL, `bank_branch` varchar(100) DEFAULT NULL, `credit_score` int(11) DEFAULT 0, `risk_level` enum('low','medium','high') DEFAULT 'medium', `status` enum('active','inactive','blacklisted','pending') DEFAULT 'active', `created_by` int(11) DEFAULT NULL, `branch_id` int(11) DEFAULT NULL, `profile_image` varchar(255) DEFAULT NULL, `notes` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `borrower_no` (`borrower_no`), UNIQUE KEY `national_id` (`national_id`), UNIQUE KEY `phone` (`phone`), KEY `created_by` (`created_by`), KEY `branch_id` (`branch_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_products` -- -------------------------------------------------------- CREATE TABLE `loan_products` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `code` varchar(20) NOT NULL, `description` text DEFAULT NULL, `min_amount` decimal(15,2) NOT NULL, `max_amount` decimal(15,2) NOT NULL, `interest_rate` decimal(5,2) NOT NULL, `interest_type` enum('flat','reducing','compound') DEFAULT 'reducing', `term_period` enum('days','weeks','months','years') DEFAULT 'months', `min_term` int(11) NOT NULL, `max_term` int(11) NOT NULL, `penalty_rate` decimal(5,2) DEFAULT 0.00, `penalty_type` enum('fixed','percentage') DEFAULT 'percentage', `grace_period` int(11) DEFAULT 0, `processing_fee` decimal(5,2) DEFAULT 0.00, `processing_fee_type` enum('fixed','percentage') DEFAULT 'percentage', `insurance_fee` decimal(5,2) DEFAULT 0.00, `insurance_fee_type` enum('fixed','percentage') DEFAULT 'percentage', `requires_collateral` tinyint(1) DEFAULT 0, `requires_guarantor` tinyint(1) DEFAULT 0, `min_guarantors` int(11) DEFAULT 0, `max_guarantors` int(11) DEFAULT 0, `eligibility_criteria` text DEFAULT NULL, `status` enum('active','inactive') DEFAULT 'active', `created_by` int(11) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`), KEY `created_by` (`created_by`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loans` -- -------------------------------------------------------- CREATE TABLE `loans` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_no` varchar(20) NOT NULL, `borrower_id` int(11) NOT NULL, `loan_product_id` int(11) NOT NULL, `principal_amount` decimal(15,2) NOT NULL, `interest_rate` decimal(5,2) NOT NULL, `interest_amount` decimal(15,2) NOT NULL, `total_amount` decimal(15,2) NOT NULL, `paid_amount` decimal(15,2) DEFAULT 0.00, `due_amount` decimal(15,2) NOT NULL, `processing_fee` decimal(15,2) DEFAULT 0.00, `insurance_fee` decimal(15,2) DEFAULT 0.00, `other_fees` decimal(15,2) DEFAULT 0.00, `term` int(11) NOT NULL, `term_period` enum('days','weeks','months','years') DEFAULT 'months', `disbursement_date` date DEFAULT NULL, `first_payment_date` date DEFAULT NULL, `maturity_date` date NOT NULL, `payment_frequency` enum('daily','weekly','bi-weekly','monthly','quarterly','yearly') DEFAULT 'monthly', `payment_day` int(11) DEFAULT NULL, `purpose` text DEFAULT NULL, `collateral_description` text DEFAULT NULL, `status` enum('pending','approved','rejected','disbursed','active','completed','defaulted','written_off') DEFAULT 'pending', `approved_by` int(11) DEFAULT NULL, `approved_date` datetime DEFAULT NULL, `rejected_by` int(11) DEFAULT NULL, `rejected_date` datetime DEFAULT NULL, `rejection_reason` text DEFAULT NULL, `disbursed_by` int(11) DEFAULT NULL, `disbursed_date` datetime DEFAULT NULL, `created_by` int(11) DEFAULT NULL, `branch_id` int(11) DEFAULT NULL, `notes` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `loan_no` (`loan_no`), KEY `borrower_id` (`borrower_id`), KEY `loan_product_id` (`loan_product_id`), KEY `approved_by` (`approved_by`), KEY `created_by` (`created_by`), KEY `branch_id` (`branch_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_installments` -- -------------------------------------------------------- CREATE TABLE `loan_installments` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `installment_no` int(11) NOT NULL, `due_date` date NOT NULL, `principal_amount` decimal(15,2) NOT NULL, `interest_amount` decimal(15,2) NOT NULL, `total_amount` decimal(15,2) NOT NULL, `paid_amount` decimal(15,2) DEFAULT 0.00, `paid_date` datetime DEFAULT NULL, `penalty_amount` decimal(15,2) DEFAULT 0.00, `paid_penalty` decimal(15,2) DEFAULT 0.00, `status` enum('pending','paid','partial','overdue','waived') DEFAULT 'pending', `days_overdue` int(11) DEFAULT 0, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `loan_installment` (`loan_id`,`installment_no`), KEY `due_date` (`due_date`), KEY `status` (`status`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `repayments` -- -------------------------------------------------------- CREATE TABLE `repayments` ( `id` int(11) NOT NULL AUTO_INCREMENT, `repayment_no` varchar(20) NOT NULL, `loan_id` int(11) NOT NULL, `borrower_id` int(11) NOT NULL, `installment_id` int(11) DEFAULT NULL, `amount` decimal(15,2) NOT NULL, `principal_amount` decimal(15,2) NOT NULL, `interest_amount` decimal(15,2) NOT NULL, `penalty_amount` decimal(15,2) DEFAULT 0.00, `payment_method` enum('cash','bank_transfer','mobile_money','cheque','card','other') DEFAULT 'cash', `payment_reference` varchar(100) DEFAULT NULL, `received_by` int(11) NOT NULL, `branch_id` int(11) DEFAULT NULL, `notes` text DEFAULT NULL, `status` enum('pending','completed','reversed') DEFAULT 'completed', `payment_date` datetime NOT NULL, `reversed_by` int(11) DEFAULT NULL, `reversed_date` datetime DEFAULT NULL, `reversal_reason` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `repayment_no` (`repayment_no`), KEY `loan_id` (`loan_id`), KEY `borrower_id` (`borrower_id`), KEY `installment_id` (`installment_id`), KEY `received_by` (`received_by`), KEY `payment_date` (`payment_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `guarantors` -- -------------------------------------------------------- CREATE TABLE `guarantors` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `borrower_id` int(11) NOT NULL, `first_name` varchar(50) NOT NULL, `last_name` varchar(50) NOT NULL, `relationship` varchar(50) DEFAULT NULL, `phone` varchar(20) NOT NULL, `email` varchar(100) DEFAULT NULL, `address` text NOT NULL, `national_id` varchar(50) DEFAULT NULL, `occupation` varchar(100) DEFAULT NULL, `monthly_income` decimal(15,2) DEFAULT 0.00, `guarantee_amount` decimal(15,2) NOT NULL, `status` enum('active','released') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`), KEY `borrower_id` (`borrower_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `collaterals` -- -------------------------------------------------------- CREATE TABLE `collaterals` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `name` varchar(100) NOT NULL, `type` enum('land','vehicle','equipment','livestock','building','other') DEFAULT 'other', `description` text DEFAULT NULL, `value` decimal(15,2) NOT NULL, `condition` enum('excellent','good','fair','poor') DEFAULT 'good', `location` text DEFAULT NULL, `document_path` varchar(255) DEFAULT NULL, `status` enum('active','released','seized') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `savings_accounts` -- -------------------------------------------------------- CREATE TABLE `savings_accounts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `account_no` varchar(20) NOT NULL, `borrower_id` int(11) NOT NULL, `product_id` int(11) NOT NULL, `account_name` varchar(100) NOT NULL, `balance` decimal(15,2) DEFAULT 0.00, `available_balance` decimal(15,2) DEFAULT 0.00, `interest_rate` decimal(5,2) DEFAULT 0.00, `interest_accrued` decimal(15,2) DEFAULT 0.00, `last_interest_date` date DEFAULT NULL, `minimum_balance` decimal(15,2) DEFAULT 0.00, `status` enum('active','inactive','dormant','closed') DEFAULT 'active', `opened_date` date NOT NULL, `closed_date` date DEFAULT NULL, `closed_by` int(11) DEFAULT NULL, `created_by` int(11) DEFAULT NULL, `branch_id` int(11) DEFAULT NULL, `notes` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `account_no` (`account_no`), KEY `borrower_id` (`borrower_id`), KEY `product_id` (`product_id`), KEY `branch `branch_id` (`branch_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `savings_products` -- -------------------------------------------------------- CREATE TABLE `savings_products` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `code` varchar(20) NOT NULL, `description` text DEFAULT NULL, `min_balance` decimal(15,2) DEFAULT 0.00, `interest_rate` decimal(5,2) NOT NULL, `interest_calculation` enum('daily','monthly','quarterly','yearly') DEFAULT 'monthly', `interest_posting` enum('monthly','quarterly','yearly','at_maturity') DEFAULT 'monthly', `withdrawal_fee` decimal(5,2) DEFAULT 0.00, `monthly_fee` decimal(5,2) DEFAULT 0.00, `opening_fee` decimal(5,2) DEFAULT 0.00, `status` enum('active','inactive') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `savings_transactions` -- -------------------------------------------------------- CREATE TABLE `savings_transactions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `transaction_no` varchar(20) NOT NULL, `account_id` int(11) NOT NULL, `type` enum('deposit','withdrawal','interest','fee','transfer') NOT NULL, `amount` decimal(15,2) NOT NULL, `balance_before` decimal(15,2) NOT NULL, `balance_after` decimal(15,2) NOT NULL, `description` text DEFAULT NULL, `payment_method` enum('cash','bank_transfer','mobile_money','cheque','other') DEFAULT 'cash', `reference` varchar(100) DEFAULT NULL, `performed_by` int(11) NOT NULL, `branch_id` int(11) DEFAULT NULL, `transaction_date` datetime NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `transaction_no` (`transaction_no`), KEY `account_id` (`account_id`), KEY `type` (`type`), KEY `transaction_date` (`transaction_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `accounting_chart_of_accounts` -- -------------------------------------------------------- CREATE TABLE `accounting_chart_of_accounts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `code` varchar(20) NOT NULL, `name` varchar(100) NOT NULL, `type` enum('asset','liability','equity','income','expense') NOT NULL, `subtype` varchar(50) DEFAULT NULL, `description` text DEFAULT NULL, `parent_id` int(11) DEFAULT NULL, `balance` decimal(15,2) DEFAULT 0.00, `status` enum('active','inactive') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`), KEY `parent_id` (`parent_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `accounting_journal_entries` -- -------------------------------------------------------- CREATE TABLE `accounting_journal_entries` ( `id` int(11) NOT NULL AUTO_INCREMENT, `entry_no` varchar(20) NOT NULL, `date` date NOT NULL, `description` text DEFAULT NULL, `reference_type` enum('loan','repayment','savings','expense','income','adjustment','other') DEFAULT 'other', `reference_id` int(11) DEFAULT NULL, `total_debit` decimal(15,2) NOT NULL, `total_credit` decimal(15,2) NOT NULL, `status` enum('draft','posted','reversed') DEFAULT 'draft', `posted_by` int(11) DEFAULT NULL, `posted_date` datetime DEFAULT NULL, `created_by` int(11) NOT NULL, `branch_id` int(11) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `entry_no` (`entry_no`), KEY `date` (`date`), KEY `reference_type` (`reference_type`,`reference_id`), KEY `created_by` (`created_by`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `accounting_journal_items` -- -------------------------------------------------------- CREATE TABLE `accounting_journal_items` ( `id` int(11) NOT NULL AUTO_INCREMENT, `journal_entry_id` int(11) NOT NULL, `account_id` int(11) NOT NULL, `debit` decimal(15,2) DEFAULT 0.00, `credit` decimal(15,2) DEFAULT 0.00, `description` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `journal_entry_id` (`journal_entry_id`), KEY `account_id` (`account_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `expenses` -- -------------------------------------------------------- CREATE TABLE `expenses` ( `id` int(11) NOT NULL AUTO_INCREMENT, `expense_no` varchar(20) NOT NULL, `category_id` int(11) NOT NULL, `amount` decimal(15,2) NOT NULL, `description` text DEFAULT NULL, `payment_method` enum('cash','bank_transfer','cheque','mobile_money','other') DEFAULT 'cash', `reference` varchar(100) DEFAULT NULL, `paid_to` varchar(100) DEFAULT NULL, `approved_by` int(11) DEFAULT NULL, `paid_by` int(11) NOT NULL, `branch_id` int(11) DEFAULT NULL, `expense_date` date NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `expense_no` (`expense_no`), KEY `category_id` (`category_id`), KEY `expense_date` (`expense_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `expense_categories` -- -------------------------------------------------------- CREATE TABLE `expense_categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `description` text DEFAULT NULL, `status` enum('active','inactive') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `payroll` -- -------------------------------------------------------- CREATE TABLE `payroll` ( `id` int(11) NOT NULL AUTO_INCREMENT, `payroll_no` varchar(20) NOT NULL, `employee_id` int(11) NOT NULL, `period_from` date NOT NULL, `period_to` date NOT NULL, `basic_salary` decimal(15,2) NOT NULL, `allowances` decimal(15,2) DEFAULT 0.00, `deductions` decimal(15,2) DEFAULT 0.00, `net_salary` decimal(15,2) NOT NULL, `payment_method` enum('cash','bank_transfer','cheque','mobile_money') DEFAULT 'bank_transfer', `bank_account` varchar(50) DEFAULT NULL, `bank_name` varchar(100) DEFAULT NULL, `status` enum('draft','approved','paid','cancelled') DEFAULT 'draft', `approved_by` int(11) DEFAULT NULL, `paid_by` int(11) DEFAULT NULL, `paid_date` date DEFAULT NULL, `created_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `payroll_no` (`payroll_no`), KEY `employee_id` (`employee_id`), KEY `period_from` (`period_from`,`period_to`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `notifications` -- -------------------------------------------------------- CREATE TABLE `notifications` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `title` varchar(255) NOT NULL, `message` text NOT NULL, `type` enum('info','success','warning','error','system') DEFAULT 'info', `is_read` tinyint(1) DEFAULT 0, `action_url` varchar(255) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `is_read` (`is_read`), KEY `created_at` (`created_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `audit_logs` -- -------------------------------------------------------- CREATE TABLE `audit_logs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) DEFAULT NULL, `action` varchar(100) NOT NULL, `table_name` varchar(50) DEFAULT NULL, `record_id` int(11) DEFAULT NULL, `old_values` text DEFAULT NULL, `new_values` text DEFAULT NULL, `ip_address` varchar(45) DEFAULT NULL, `user_agent` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `user_id` (`user_id`), KEY `action` (`action`), KEY `table_name` (`table_name`,`record_id`), KEY `created_at` (`created_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `plugins` -- -------------------------------------------------------- CREATE TABLE `plugins` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `slug` varchar(100) NOT NULL, `version` varchar(20) NOT NULL, `author` varchar(100) DEFAULT NULL, `description` text DEFAULT NULL, `plugin_path` varchar(255) NOT NULL, `settings` text DEFAULT NULL, `is_active` tinyint(1) DEFAULT 0, `is_system` tinyint(1) DEFAULT 0, `installed_at` timestamp NULL DEFAULT NULL, `activated_at` timestamp NULL DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `slug` (`slug`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `plugin_hooks` -- -------------------------------------------------------- CREATE TABLE `plugin_hooks` ( `id` int(11) NOT NULL AUTO_INCREMENT, `plugin_id` int(11) NOT NULL, `hook_name` varchar(100) NOT NULL, `callback` varchar(255) NOT NULL, `priority` int(11) DEFAULT 10, `is_active` tinyint(1) DEFAULT 1, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `plugin_id` (`plugin_id`), KEY `hook_name` (`hook_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `settings` -- -------------------------------------------------------- CREATE TABLE `settings` ( `id` int(11) NOT NULL AUTO_INCREMENT, `setting_key` varchar(100) NOT NULL, `setting_value` text DEFAULT NULL, `setting_group` varchar(50) DEFAULT 'general', `setting_type` enum('text','number','textarea','select','checkbox','radio','password','email') DEFAULT 'text', `options` text DEFAULT NULL, `description` text DEFAULT NULL, `is_public` tinyint(1) DEFAULT 0, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `setting_key` (`setting_key`), KEY `setting_group` (`setting_group`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `sms_templates` -- -------------------------------------------------------- CREATE TABLE `sms_templates` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `slug` varchar(100) NOT NULL, `subject` varchar(255) DEFAULT NULL, `message` text NOT NULL, `variables` text DEFAULT NULL, `is_active` tinyint(1) DEFAULT 1, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `slug` (`slug`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `email_templates` -- -------------------------------------------------------- CREATE TABLE `email_templates` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `slug` varchar(100) NOT NULL, `subject` varchar(255) NOT NULL, `body` text NOT NULL, `variables` text DEFAULT NULL, `is_active` tinyint(1) DEFAULT 1, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `slug` (`slug`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `reports` -- -------------------------------------------------------- CREATE TABLE `reports` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `slug` varchar(100) NOT NULL, `description` text DEFAULT NULL, `query` text NOT NULL, `parameters` text DEFAULT NULL, `category` varchar(50) DEFAULT 'general', `is_active` tinyint(1) DEFAULT 1, `created_by` int(11) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `slug` (`slug`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `document_templates` -- -------------------------------------------------------- CREATE TABLE `document_templates` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `type` enum('loan_agreement','receipt','statement','certificate','other') DEFAULT 'other', `content` text NOT NULL, `variables` text DEFAULT NULL, `is_active` tinyint(1) DEFAULT 1, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `documents` -- -------------------------------------------------------- CREATE TABLE `documents` ( `id` int(11) NOT NULL AUTO_INCREMENT, `document_no` varchar(20) NOT NULL, `borrower_id` int(11) DEFAULT NULL, `loan_id` int(11) DEFAULT NULL, `type` varchar(50) NOT NULL, `title` varchar(255) NOT NULL, `file_path` varchar(255) NOT NULL, `file_size` int(11) DEFAULT NULL, `file_type` varchar(50) DEFAULT NULL, `uploaded_by` int(11) NOT NULL, `description` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `document_no` (`document_no`), KEY `borrower_id` (`borrower_id`), KEY `loan_id` (`loan_id`), KEY `type` (`type`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `holidays` -- -------------------------------------------------------- CREATE TABLE `holidays` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `date` date NOT NULL, `year` int(11) DEFAULT NULL, `recurring` tinyint(1) DEFAULT 0, `branch_id` int(11) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `date` (`date`), KEY `branch_id` (`branch_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `backups` -- -------------------------------------------------------- CREATE TABLE `backups` `backups` ( `id` int(11) NOT NULL AUTO_INCREMENT, `filename` varchar(255) NOT NULL, `size` int(11) DEFAULT NULL, `type` enum('full','partial','auto','manual') DEFAULT 'manual', `created_by` int(11) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `created_at` (`created_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `api_keys` -- -------------------------------------------------------- CREATE TABLE `api_keys` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `api_key` varchar(64) NOT NULL, `secret_key` varchar(64) NOT NULL, `permissions` text DEFAULT NULL, `expires_at` datetime DEFAULT NULL, `last_used` datetime DEFAULT NULL, `status` enum('active','inactive','expired') DEFAULT 'active', `created_by` int(11) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `api_key` (`api_key`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `queued_jobs` -- -------------------------------------------------------- CREATE TABLE `queued_jobs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `queue` varchar(50) NOT NULL, `payload` text NOT NULL, `attempts` int(11) DEFAULT 0, `reserved_at` datetime DEFAULT NULL, `available_at` datetime NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `queue` (`queue`), KEY `available_at` (`available_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `failed_jobs` -- -------------------------------------------------------- CREATE TABLE `failed_jobs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `queue` varchar(50) NOT NULL, `payload` text NOT NULL, `exception` text DEFAULT NULL, `failed_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `system_logs` -- -------------------------------------------------------- CREATE TABLE `system_logs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `level` enum('emergency','alert','critical','error','warning','notice','info','debug') DEFAULT 'info', `message` text NOT NULL, `context` text DEFAULT NULL, `ip_address` varchar(45) DEFAULT NULL, `user_agent` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `level` (`level`), KEY `created_at` (`created_at`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_approval_workflow` -- -------------------------------------------------------- CREATE TABLE `loan_approval_workflow` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `level` int(11) NOT NULL, `approver_id` int(11) NOT NULL, `status` enum('pending','approved','rejected','cancelled') DEFAULT 'pending', `comments` text DEFAULT NULL, `approved_at` datetime DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`), KEY `approver_id` (`approver_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_application_questions` -- -------------------------------------------------------- CREATE TABLE `loan_application_questions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_product_id` int(11) DEFAULT NULL, `question` text NOT NULL, `type` enum('text','textarea','select','radio','checkbox','number','date') DEFAULT 'text', `options` text DEFAULT NULL, `is_required` tinyint(1) DEFAULT 0, `order` int(11) DEFAULT 0, `status` enum('active','inactive') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_product_id` (`loan_product_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_application_answers` -- -------------------------------------------------------- CREATE TABLE `loan_application_answers` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `question_id` int(11) NOT NULL, `answer` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `loan_question` (`loan_id`,`question_id`), KEY `question_id` (`question_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_insurance` -- -------------------------------------------------------- CREATE TABLE `loan_insurance` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `insurance_provider` varchar(100) DEFAULT NULL, `policy_number` varchar(50) DEFAULT NULL, `premium_amount` decimal(15,2) DEFAULT 0.00, `coverage_amount` decimal(15,2) DEFAULT 0.00, `start_date` date DEFAULT NULL, `end_date` date DEFAULT NULL, `status` enum('active','expired','cancelled','claimed') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_rescheduling` -- -------------------------------------------------------- CREATE TABLE `loan_rescheduling` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `old_maturity_date` date NOT NULL, `new_maturity_date` date NOT NULL, `reason` text NOT NULL, `approved_by` int(11) DEFAULT NULL, `approved_date` datetime DEFAULT NULL, `status` enum('pending','approved','rejected') DEFAULT 'pending', `created_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_write_offs` -- -------------------------------------------------------- CREATE TABLE `loan_write_offs` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `write_off_amount` decimal(15,2) NOT NULL, `reason` text NOT NULL, `approved_by` int(11) DEFAULT NULL, `approved_date` datetime DEFAULT NULL, `recovery_amount` decimal(15,2) DEFAULT 0.00, `recovery_date` date DEFAULT NULL, `status` enum('written_off','partially_recovered','fully_recovered') DEFAULT 'written_off', `created_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_arrears_management` -- -------------------------------------------------------- CREATE TABLE `loan_arrears_management` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `days_overdue` int(11) NOT NULL, `arrears_amount` decimal(15,2) NOT NULL, `action_taken` enum('reminder_sent','phone_call','visit','legal_action','restructured') DEFAULT 'reminder_sent', `action_by` int(11) DEFAULT NULL, `action_date` datetime DEFAULT NULL, `next_action_date` date DEFAULT NULL, `notes` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`), KEY `days_overdue` (`days_overdue`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `mobile_app_users` -- -------------------------------------------------------- CREATE TABLE `mobile_app_users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `borrower_id` int(11) NOT NULL, `device_id` varchar(255) DEFAULT NULL, `device_type` enum('android','ios','web') DEFAULT NULL, `app_version` varchar(20) DEFAULT NULL, `fcm_token` text DEFAULT NULL, `last_login` datetime DEFAULT NULL, `status` enum('active','inactive','blocked') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `borrower_id` (`borrower_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `mobile_transactions` -- -------------------------------------------------------- CREATE TABLE `mobile_transactions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `transaction_id` varchar(50) NOT NULL, `borrower_id` int(11) NOT NULL, `type` enum('loan_payment','savings_deposit','savings_withdrawal','balance_check','statement_request') NOT NULL, `amount` decimal(15,2) DEFAULT NULL, `status` enum('pending','completed','failed','cancelled') DEFAULT 'pending', `provider` enum('mpesa','airtel_money','tnm_mpamba','other') DEFAULT 'mpesa', `provider_reference` varchar(100) DEFAULT NULL, `response_message` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `transaction_id` (`transaction_id`), KEY `borrower_id` (`borrower_id`), KEY `status` (`status`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_portfolio_analysis` -- -------------------------------------------------------- CREATE TABLE `loan_portfolio_analysis` ( `id` int(11) NOT NULL AUTO_INCREMENT, `analysis_date` date NOT NULL, `total_loans` int(11) DEFAULT 0, `total_portfolio` decimal(15,2) DEFAULT 0.00, `active_loans` int(11) DEFAULT 0, `active_portfolio` decimal(15,2) DEFAULT 0.00, `overdue_loans` int(11) DEFAULT 0, `overdue_amount` decimal(15,2) DEFAULT 0.00, `par_30` decimal(5,2) DEFAULT 0.00, `par_60` decimal(5,2) DEFAULT 0.00, `par_90` decimal(5,2) DEFAULT 0.00, `write_off_amount` decimal(15,2) DEFAULT 0.00, `recovery_rate` decimal(5,2) DEFAULT 0.00, `branch_id` int(11) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `analysis_date_branch` (`analysis_date`,`branch_id`), KEY `branch_id` (`branch_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_performance_indicators` -- -------------------------------------------------------- CREATE TABLE `loan_performance_indicators` ( `id` int(11) NOT NULL AUTO_INCREMENT, `indicator_date` date NOT NULL, `portfolio_at_risk` decimal(5,2) DEFAULT 0.00, `collection_efficiency` decimal(5,2) DEFAULT 0.00, `loan_loss_reserve` decimal(15,2) DEFAULT 0.00, `average_loan_size` decimal(15,2) DEFAULT 0.00, `average_interest_rate` decimal(5,2) DEFAULT 0.00, `branch_id` int(11) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `indicator_date_branch` (`indicator_date`,`branch_id`), KEY `branch_id` (`branch_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_officer_performance` -- -------------------------------------------------------- CREATE TABLE `loan_officer_performance` ( `id` int(11) NOT NULL AUTO_INCREMENT, `officer_id` int(11) NOT NULL, `period` enum('daily','weekly','monthly','quarterly','yearly') DEFAULT 'monthly', `period_date` date NOT NULL, `loans_disbursed` int(11) DEFAULT 0, `amount_disbursed` decimal(15,2) DEFAULT 0.00, `collections_received` decimal(15,2) DEFAULT 0.00, `collections_target` decimal(15,2) DEFAULT 0.00, `arrears_amount` decimal(15,2) DEFAULT 0.00, `portfolio_at_risk` decimal(5,2) DEFAULT 0.00, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `officer_period` (`officer_id`,`period`,`period_date`), KEY `period_date` (`period_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_product_performance` -- -------------------------------------------------------- CREATE TABLE `loan_product_performance` ( `id` int(11) NOT NULL AUTO_INCREMENT, `product_id` int(11) NOT NULL, `analysis_date` date NOT NULL, `active_loans` int(11) DEFAULT 0, `total_disbursed` decimal(15,2) DEFAULT 0.00, `total_repaid` decimal(15,2) DEFAULT 0.00, `total_outstanding` decimal(15,2) DEFAULT 0.00, `overdue_amount` decimal(15,2) DEFAULT 0.00, `par_30` decimal(5,2) DEFAULT 0.00, `average_loan_size` decimal(15,2) DEFAULT 0.00, `branch_id` int(11) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `product_analysis` (`product_id`,`analysis_date`,`branch_id`), KEY `analysis_date` (`analysis_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `borrower_credit_history` -- -------------------------------------------------------- CREATE TABLE `borrower_credit_history` ( `id` int(11) NOT NULL AUTO_INCREMENT, `borrower_id` int(11) NOT NULL, `loan_id` int(11) DEFAULT NULL, `event_type` enum('loan_taken','loan_repaid','loan_defaulted','credit_score_update','blacklist','whitelist') NOT NULL, `description` text DEFAULT NULL, `old_credit_score` int(11) DEFAULT NULL, `new_credit_score` int(11) DEFAULT NULL, `created_by` int(11) DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `borrower_id` (`borrower_id`), KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_fee_types` -- -------------------------------------------------------- CREATE TABLE `loan_fee_types` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `code` varchar(20) NOT NULL, `description` text DEFAULT NULL, `calculation_type` enum('fixed','percentage','tiered') DEFAULT 'fixed', `amount` decimal(15,2) DEFAULT 0.00, `percentage` decimal(5,2) DEFAULT 0.00, `gl_account_id` int(11) DEFAULT NULL, `status` enum('active','inactive') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `code` (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLL ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_fees` -- -------------------------------------------------------- CREATE TABLE `loan_fees` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `fee_type_id` int(11) NOT NULL, `amount` decimal(15,2) NOT NULL, `paid_amount` decimal(15,2) DEFAULT 0.00, `due_date` date DEFAULT NULL, `paid_date` datetime DEFAULT NULL, `status` enum('pending','paid','waived','cancelled') DEFAULT 'pending', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`), KEY `fee_type_id` (`fee_type_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_calculations` -- -------------------------------------------------------- CREATE TABLE `loan_calculations` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `calculation_type` enum('amortization','interest_only','bullet','custom') DEFAULT 'amortization', `schedule_data` text NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_documents_checklist` -- -------------------------------------------------------- CREATE TABLE `loan_documents_checklist` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_product_id` int(11) DEFAULT NULL, `document_name` varchar(100) NOT NULL, `is_required` tinyint(1) DEFAULT 0, `description` text DEFAULT NULL, `order` int(11) DEFAULT 0, `status` enum('active','inactive') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_product_id` (`loan_product_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_documents_submitted` -- -------------------------------------------------------- CREATE TABLE `loan_documents_submitted` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `checklist_id` int(11) NOT NULL, `document_path` varchar(255) NOT NULL, `verified_by` int(11) DEFAULT NULL, `verified_date` datetime DEFAULT NULL, `status` enum('pending','verified','rejected') DEFAULT 'pending', `rejection_reason` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `loan_checklist` (`loan_id`,`checklist_id`), KEY `checklist_id` (`checklist_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_committee_meetings` -- -------------------------------------------------------- CREATE TABLE `loan_committee_meetings` ( `id` int(11) NOT NULL AUTO_INCREMENT, `meeting_date` date NOT NULL, `start_time` time NOT NULL, `end_time` time DEFAULT NULL, `location` varchar(255) DEFAULT NULL, `agenda` text DEFAULT NULL, `minutes` text DEFAULT NULL, `status` enum('scheduled','in_progress','completed','cancelled') DEFAULT 'scheduled', `created_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `meeting_date` (`meeting_date`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_committee_attendees` -- -------------------------------------------------------- CREATE TABLE `loan_committee_attendees` ( `id` int(11) NOT NULL AUTO_INCREMENT, `meeting_id` int(11) NOT NULL, `user_id` int(11) NOT NULL, `role` enum('chairperson','member','secretary','observer') DEFAULT 'member', `attended` tinyint(1) DEFAULT 0, `arrival_time` time DEFAULT NULL, `departure_time` time DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `meeting_user` (`meeting_id`,`user_id`), KEY `user_id` (`user_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_committee_decisions` -- -------------------------------------------------------- CREATE TABLE `loan_committee_decisions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `meeting_id` int(11) NOT NULL, `loan_id` int(11) NOT NULL, `decision` enum('approved','rejected','deferred','referred') DEFAULT 'deferred', `comments` text DEFAULT NULL, `conditions` text DEFAULT NULL, `approved_amount` decimal(15,2) DEFAULT NULL, `approved_term` int(11) DEFAULT NULL, `approved_by` int(11) DEFAULT NULL, `decision_date` datetime DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `meeting_loan` (`meeting_id`,`loan_id`), KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_risk_assessment` -- -------------------------------------------------------- CREATE TABLE `loan_risk_assessment` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `assessment_date` date NOT NULL, `risk_score` int(11) DEFAULT 0, `risk_level` enum('low','medium','high','critical') DEFAULT 'medium', `factors` text DEFAULT NULL, `recommendations` text DEFAULT NULL, `assessed_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_risk_factors` -- -------------------------------------------------------- CREATE TABLE `loan_risk_factors` ( `id` int(11) NOT NULL AUTO_INCREMENT, `factor_name` varchar(100) NOT NULL, `factor_type` enum('borrower','loan','collateral','external') DEFAULT 'borrower', `weight` decimal(5,2) DEFAULT 0.00, `description` text DEFAULT NULL, `status` enum('active','inactive') DEFAULT 'active', `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_risk_scores` -- -------------------------------------------------------- CREATE TABLE `loan_risk_scores` ( `id` int(11) NOT NULL AUTO_INCREMENT, `risk_assessment_id` int(11) NOT NULL, `risk_factor_id` int(11) NOT NULL, `score` int(11) DEFAULT 0, `comments` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `assessment_factor` (`risk_assessment_id`,`risk_factor_id`), KEY `risk_factor_id` (`risk_factor_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_insurance_claims` -- -------------------------------------------------------- CREATE TABLE `loan_insurance_claims` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_insurance_id` int(11) NOT NULL, `claim_date` date NOT NULL, `claim_amount` decimal(15,2) NOT NULL, `reason` text NOT NULL, `status` enum('submitted','under_review','approved','rejected','paid') DEFAULT 'submitted', `reviewed_by` int(11) DEFAULT NULL, `reviewed_date` datetime DEFAULT NULL, `paid_date` date DEFAULT NULL, `payment_reference` varchar(100) DEFAULT NULL, `created_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_insurance_id` (`loan_insurance_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_collateral_valuation` -- -------------------------------------------------------- CREATE TABLE `loan_collateral_valuation` ( `id` int(11) NOT NULL AUTO_INCREMENT, `collateral_id` int(11) NOT NULL, `valuation_date` date NOT NULL, `valued_by` varchar(100) DEFAULT NULL, `valuation_method` varchar(50) DEFAULT NULL, `current_value` decimal(15,2) NOT NULL, `depreciation_rate` decimal(5,2) DEFAULT 0.00, `next_valuation_date` date DEFAULT NULL, `notes` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `collateral_id` (`collateral_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_collateral_inspections` -- -------------------------------------------------------- CREATE TABLE `loan_collateral_inspections` ( `id` int(11) NOT NULL AUTO_INCREMENT, `collateral_id` int(11) NOT NULL, `inspection_date` date NOT NULL, `inspected_by` int(11) NOT NULL, `condition` enum('excellent','good','fair','poor','damaged') DEFAULT 'good', `findings` text DEFAULT NULL, `recommendations` text DEFAULT NULL, `next_inspection_date` date DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `collateral_id` (`collateral_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_guarantor_assessment` -- -------------------------------------------------------- CREATE TABLE `loan_guarantor_assessment` ( `id` int(11) NOT NULL AUTO_INCREMENT, `guarantor_id` int(11) NOT NULL, `assessment_date` date NOT NULL, `net_worth` decimal(15,2) DEFAULT 0.00, `monthly_income` decimal(15,2) DEFAULT 0.00, `credit_score` int(11) DEFAULT 0, `risk_level` enum('low','medium','high') DEFAULT 'medium', `assessment_by` int(11) NOT NULL, `comments` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), UNIQUE KEY `guarantor_id` (`guarantor_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_repayment_reminders` -- -------------------------------------------------------- CREATE TABLE `loan_repayment_reminders` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `installment_id` int(11) DEFAULT NULL, `reminder_type` enum('sms','email','phone_call','in_person') DEFAULT 'sms', `reminder_date` date NOT NULL, `due_date` date NOT NULL, `amount_due` decimal(15,2) NOT NULL, `sent_by` int(11) DEFAULT NULL, `status` enum('pending','sent','failed','cancelled') DEFAULT 'pending', `response` text DEFAULT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`), KEY `installment_id` (`installment_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_penalty_waivers` -- -------------------------------------------------------- CREATE TABLE `loan_penalty_waivers` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `installment_id` int(11) DEFAULT NULL, `penalty_amount` decimal(15,2) NOT NULL, `waived_amount` decimal(15,2) NOT NULL, `reason` text NOT NULL, `approved_by` int(11) DEFAULT NULL, `approved_date` datetime DEFAULT NULL, `status` enum('pending','approved','rejected') DEFAULT 'pending', `created_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`), KEY `installment_id` (`installment_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_interest_waivers` -- -------------------------------------------------------- CREATE TABLE `loan_interest_waivers` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `interest_amount` decimal(15,2) NOT NULL, `waived_amount` decimal(15,2) NOT NULL, `reason` text NOT NULL, `approved_by` int(11) DEFAULT NULL, `approved_date` datetime DEFAULT NULL, `status` enum('pending','approved','rejected') DEFAULT 'pending', `created_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_restructuring` -- -------------------------------------------------------- CREATE TABLE `loan_restructuring` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `restructure_date` date NOT NULL, `old_principal` decimal(15,2) NOT NULL, `new_principal` decimal(15,2) NOT NULL, `old_interest_rate` decimal(5,2) NOT NULL, `new_interest_rate` decimal(5,2) NOT NULL, `old_term` int(11) NOT NULL, `new_term` int(11) NOT NULL, `old_maturity_date` date NOT NULL, `new_maturity_date` date NOT NULL, `reason` text NOT NULL, `approved_by` int(11) DEFAULT NULL, `approved_date` datetime DEFAULT NULL, `status` enum('pending','approved','rejected','implemented') DEFAULT 'pending', `created_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_syndication` -- -------------------------------------------------------- CREATE TABLE `loan_syndication` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `syndication_date` date NOT NULL, `total_amount` decimal(15,2) NOT NULL, `participation_amount` decimal(15,2) NOT NULL, `partner_name` varchar(100) NOT NULL, `partner_share` decimal(5,2) NOT NULL, `agreement_path` varchar(255) DEFAULT NULL, `status` enum('active','completed','terminated') DEFAULT 'active', `created_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -------------------------------------------------------- -- Table structure for table `loan_securitization` -- -------------------------------------------------------- CREATE TABLE `loan_securitization` ( `id` int(11) NOT NULL AUTO_INCREMENT, `loan_id` int(11) NOT NULL, `securitization_date` date NOT NULL, `security_amount` decimal(15,2) NOT NULL, `security_type` varchar(50) DEFAULT NULL, `issuer` varchar(100) DEFAULT NULL, `maturity_date` date DEFAULT NULL, `coupon_rate` decimal(5,2) DEFAULT 0.00, `status` enum('active','matured','redeemed','defaulted') DEFAULT 'active', `created_by` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT current_timestamp(), PRIMARY KEY (`id`), KEY `loan_id` (`loan_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8