diff --git a/mifosng-db/0001a-mifos-platform-base-ddl-schema.sql b/mifosng-db/0001a-mifosplatform-core-ddl-latest.sql similarity index 65% rename from mifosng-db/0001a-mifos-platform-base-ddl-schema.sql rename to mifosng-db/0001a-mifosplatform-core-ddl-latest.sql index ee948b534..c436784b4 100644 --- a/mifosng-db/0001a-mifos-platform-base-ddl-schema.sql +++ b/mifosng-db/0001a-mifosplatform-core-ddl-latest.sql @@ -1,64 +1,60 @@ --- This script is the core DDL for mifos platform --- Its includes tables related to lookup/reference data, user administration, organisation modeling, client and loans --- and infrastructure tables needed for 'additional data' and 'screen based reporting' functionality. - --- It does not include DDL customisations needed for specific 'tenants' for 'additional data' functionality around clients/loans. - --- This script drops all tables and re-creates from scratch. - -- drop tables in base-schema - SET foreign_key_checks = 0; --- portfolio related tables -DROP TABLE IF EXISTS `m_note`; -DROP TABLE IF EXISTS `m_loan_transaction`; -DROP TABLE IF EXISTS `m_loan_charge`; -DROP TABLE IF EXISTS `m_loan_repayment_schedule`; -DROP TABLE IF EXISTS `m_loan`; -DROP TABLE IF EXISTS `m_deposit_account`; -DROP TABLE IF EXISTS `m_group_client`; -DROP TABLE IF EXISTS `m_client`; -DROP TABLE IF EXISTS `m_group`; -DROP TABLE IF EXISTS `m_product_loan`; -DROP TABLE IF EXISTS `m_product_savings`; -DROP TABLE IF EXISTS `m_product_deposit`; --- organisation related tables -DROP TABLE IF EXISTS `m_organisation_currency`; -DROP TABLE IF EXISTS `m_fund`; -DROP TABLE IF EXISTS `m_charge`; -DROP TABLE IF EXISTS `m_product_loan_charge`; -DROP TABLE IF EXISTS `m_office_transaction`; -DROP TABLE IF EXISTS `m_office`; -DROP TABLE IF EXISTS `m_staff`; +-- drop accounting subsystem +DROP TABLE IF EXISTS `m_acc_coa`; --- admin tables -DROP TABLE IF EXISTS `m_role_permission`; -DROP TABLE IF EXISTS `m_appuser_role`; +-- drop portfolio subsystem DROP TABLE IF EXISTS `m_appuser`; -DROP TABLE IF EXISTS `m_permission`; -DROP TABLE IF EXISTS `m_role`; - --- drop reference/lookup tables -DROP TABLE IF EXISTS `m_currency`; -DROP TABLE IF EXISTS `ref_loan_transaction_processing_strategy`; -DROP TABLE IF EXISTS `m_code_value`; +DROP TABLE IF EXISTS `m_appuser_role`; +DROP TABLE IF EXISTS `m_charge`; +DROP TABLE IF EXISTS `m_client`; +DROP TABLE IF EXISTS `m_client_identifier`; DROP TABLE IF EXISTS `m_code`; -DROP TABLE IF EXISTS `r_enum_value`; +DROP TABLE IF EXISTS `m_code_value`; +DROP TABLE IF EXISTS `m_currency`; +DROP TABLE IF EXISTS `m_deposit_account`; +DROP TABLE IF EXISTS `m_deposit_account_transaction`; +DROP TABLE IF EXISTS `m_document`; +DROP TABLE IF EXISTS `m_fund`; +DROP TABLE IF EXISTS `m_group`; +DROP TABLE IF EXISTS `m_group_client`; +DROP TABLE IF EXISTS `m_loan`; +DROP TABLE IF EXISTS `m_loan_charge`; +DROP TABLE IF EXISTS `m_loan_officer_assignment_history`; +DROP TABLE IF EXISTS `m_loan_repayment_schedule`; +DROP TABLE IF EXISTS `m_loan_transaction`; +DROP TABLE IF EXISTS `m_note`; +DROP TABLE IF EXISTS `m_office`; +DROP TABLE IF EXISTS `m_office_transaction`; +DROP TABLE IF EXISTS `m_organisation_currency`; +DROP TABLE IF EXISTS `m_permission`; +DROP TABLE IF EXISTS `m_portfolio_command_source`; +DROP TABLE IF EXISTS `m_product_deposit`; +DROP TABLE IF EXISTS `m_product_loan`; +DROP TABLE IF EXISTS `m_product_loan_charge`; +DROP TABLE IF EXISTS `m_product_savings`; +DROP TABLE IF EXISTS `m_role`; +DROP TABLE IF EXISTS `m_role_permission`; +DROP TABLE IF EXISTS `m_saving_account`; +DROP TABLE IF EXISTS `m_staff`; +DROP TABLE IF EXISTS `ref_loan_transaction_processing_strategy`; DROP TABLE IF EXISTS `x_registered_table`; --- additional data and report tables -DROP TABLE IF EXISTS `stretchydata_dataset_fields`; -DROP TABLE IF EXISTS `stretchydata_dataset`; -DROP TABLE IF EXISTS `stretchydata_datasettype`; -DROP TABLE IF EXISTS `stretchy_parameter`; -DROP TABLE IF EXISTS `stretchy_report_parameter`; -DROP TABLE IF EXISTS `stretchy_report`; +-- drop reporting related tables +DROP TABLE IF EXISTS `r_enum_value`; DROP TABLE IF EXISTS `rpt_sequence`; +DROP TABLE IF EXISTS `stretchy_parameter`; +DROP TABLE IF EXISTS `stretchy_report`; +DROP TABLE IF EXISTS `stretchy_report_parameter`; + +-- drop deprecated 'stretchydata tables' which were used previously for 'additional data' +DROP TABLE IF EXISTS `stretchydata_dataset`; +DROP TABLE IF EXISTS `stretchydata_dataset_fields`; +DROP TABLE IF EXISTS `stretchydata_datasettype`; SET foreign_key_checks = 1; - -- DDL for reference/lookup tables CREATE TABLE `m_currency` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, @@ -71,6 +67,20 @@ CREATE TABLE `m_currency` ( UNIQUE KEY `code` (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `m_organisation_currency` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `code` varchar(3) NOT NULL, + `decimal_places` smallint(5) NOT NULL, + `name` varchar(50) NOT NULL, + `display_symbol` varchar(10) DEFAULT NULL, + `internationalized_name_code` varchar(50) NOT NULL, + `createdby_id` bigint(20) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CREATE TABLE `ref_loan_transaction_processing_strategy` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `code` varchar(100) DEFAULT NULL, @@ -84,32 +94,49 @@ CREATE TABLE `ref_loan_transaction_processing_strategy` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `m_code` ( - `id` int NOT NULL AUTO_INCREMENT, + `id` int(11) NOT NULL AUTO_INCREMENT, `code_name` varchar(100) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `code_name` (`code_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `m_code_value` ( - `id` int NOT NULL AUTO_INCREMENT, - `code_id` int NOT NULL, + `id` int(11) NOT NULL AUTO_INCREMENT, + `code_id` int(11) NOT NULL, `code_value` varchar(100) DEFAULT NULL, - `order_position` int NOT NULL DEFAULT '0', + `order_position` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), - UNIQUE KEY `code_value` (`code_id`, `code_value`), + UNIQUE KEY `code_value` (`code_id`,`code_value`), KEY `FKCFCEA42640BE071Z` (`code_id`), CONSTRAINT `FKCFCEA42640BE071Z` FOREIGN KEY (`code_id`) REFERENCES `m_code` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `m_document` ( + `id` int(20) NOT NULL AUTO_INCREMENT, + `parent_entity_type` varchar(50) NOT NULL, + `parent_entity_id` int(20) NOT NULL DEFAULT '0', + `name` varchar(250) NOT NULL, + `file_name` varchar(250) NOT NULL, + `size` int(20) DEFAULT '0', + `type` varchar(50) DEFAULT NULL, + `description` varchar(1000) DEFAULT NULL, + `location` varchar(500) NOT NULL DEFAULT '0', + `createdby_id` int(20) NOT NULL, + `lastmodifiedby_id` int(20) NOT NULL, + `created_date` datetime NOT NULL, + `lastmodified_date` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + /*not a major table - just intended for database reporting use for enums and values that would be hidden in java*/ CREATE TABLE `r_enum_value` ( `enum_name` varchar(100) NOT NULL, - `enum_id` int NOT NULL, + `enum_id` int(11) NOT NULL, `enum_message_property` varchar(100) NOT NULL, `enum_value` varchar(100) NOT NULL, - PRIMARY KEY (`enum_name`, `enum_id`), - UNIQUE KEY `enum_message_property` (`enum_name`, `enum_message_property`), - UNIQUE KEY `enum_value` (`enum_name`, `enum_value`) + PRIMARY KEY (`enum_name`,`enum_id`), + UNIQUE KEY `enum_message_property` (`enum_name`,`enum_message_property`), + UNIQUE KEY `enum_value` (`enum_name`,`enum_value`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; /* used to link MySql tables to Mifos X application tables for additional data needs */ @@ -119,47 +146,9 @@ CREATE TABLE `x_registered_table` ( PRIMARY KEY (`registered_table_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- DDL for organisation wide related concepts -CREATE TABLE `m_fund` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `name` varchar(255) DEFAULT NULL, - `external_id` varchar(100) DEFAULT NULL, - `createdby_id` bigint(20) DEFAULT NULL, - `created_date` datetime DEFAULT NULL, - `lastmodifiedby_id` bigint(20) DEFAULT NULL, - `lastmodified_date` datetime DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `fund_name_org` (`name`), - UNIQUE KEY `fund_externalid_org` (`external_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE `m_charge` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `name` varchar(100) DEFAULT NULL, - `currency_code` varchar(3) NOT NULL, - `charge_applies_to_enum` smallint(5) NOT NULL, - `charge_time_enum` smallint(5) NOT NULL, - `charge_calculation_enum` smallint(5) NOT NULL, - `amount` decimal(19,6) NOT NULL, - `is_active` tinyint(1) NOT NULL, - `is_deleted` tinyint(1) NOT NULL DEFAULT '0', - `createdby_id` bigint(20) DEFAULT NULL, - `created_date` datetime DEFAULT NULL, - `lastmodifiedby_id` bigint(20) DEFAULT NULL, - `lastmodified_date` datetime DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE `m_staff` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `firstname` varchar(50) DEFAULT NULL, - `lastname` varchar(50) DEFAULT NULL, - `display_name` varchar(100) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `display_name` (`display_name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ================= end of reference/lookup tables ============= +-- DDL for office related tables CREATE TABLE `m_office` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `parent_id` bigint(20) DEFAULT NULL, @@ -198,28 +187,18 @@ CREATE TABLE `m_office_transaction` ( CONSTRAINT `FK1E37728B93C6C1B6` FOREIGN KEY (`to_office_id`) REFERENCES `m_office` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `m_organisation_currency` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `code` varchar(3) NOT NULL, - `decimal_places` smallint(5) NOT NULL, - `name` varchar(50) NOT NULL, - `display_symbol` varchar(10) DEFAULT NULL, - `internationalized_name_code` varchar(50) NOT NULL, - `createdby_id` bigint(20) DEFAULT NULL, - `created_date` datetime DEFAULT NULL, - `lastmodified_date` datetime DEFAULT NULL, - `lastmodifiedby_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ============ end of office related tables ========== -- DDL for admin tables CREATE TABLE `m_permission` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, - `group_enum` smallint(5) NOT NULL, + `grouping` varchar(45) DEFAULT NULL, + `order_in_grouping` int(11) DEFAULT NULL, `code` varchar(100) NOT NULL, `default_description` varchar(500) NOT NULL, `default_name` varchar(100) NOT NULL, - PRIMARY KEY (`id`) + PRIMARY KEY (`id`), + UNIQUE KEY `code` (`code`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `m_role` ( @@ -233,9 +212,19 @@ CREATE TABLE `m_role` ( PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `m_role_permission` ( + `role_id` bigint(20) NOT NULL, + `permission_id` bigint(20) NOT NULL, + PRIMARY KEY (`role_id`,`permission_id`), + KEY `FK8DEDB04815CEC7AB` (`role_id`), + KEY `FK8DEDB048103B544B` (`permission_id`), + CONSTRAINT `FK8DEDB048103B544B` FOREIGN KEY (`permission_id`) REFERENCES `m_permission` (`id`), + CONSTRAINT `FK8DEDB04815CEC7AB` FOREIGN KEY (`role_id`) REFERENCES `m_role` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CREATE TABLE `m_appuser` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, - `is_deleted` TINYINT(1) DEFAULT 0 NOT NULL, + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', `office_id` bigint(20) DEFAULT NULL, `username` varchar(100) NOT NULL, `firstname` varchar(100) NOT NULL, @@ -257,16 +246,6 @@ CREATE TABLE `m_appuser` ( CONSTRAINT `FKB3D587CE0DD567A` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `m_role_permission` ( - `role_id` bigint(20) NOT NULL, - `permission_id` bigint(20) NOT NULL, - PRIMARY KEY (`role_id`,`permission_id`), - KEY `FK8DEDB04815CEC7AB` (`role_id`), - KEY `FK8DEDB048103B544B` (`permission_id`), - CONSTRAINT `FK8DEDB048103B544B` FOREIGN KEY (`permission_id`) REFERENCES `m_permission` (`id`), - CONSTRAINT `FK8DEDB04815CEC7AB` FOREIGN KEY (`role_id`) REFERENCES `m_role` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - CREATE TABLE `m_appuser_role` ( `appuser_id` bigint(20) NOT NULL, `role_id` bigint(20) NOT NULL, @@ -277,9 +256,81 @@ CREATE TABLE `m_appuser_role` ( CONSTRAINT `FK7662CE59B4100309` FOREIGN KEY (`appuser_id`) REFERENCES `m_appuser` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- DDL for portfolio tables +-- ================ end of user admin tables =============== + +-- DDL for organisation wide related concepts +CREATE TABLE `m_portfolio_command_source` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `api_operation` varchar(20) NOT NULL, + `api_resource` varchar(20) NOT NULL, + `resource_id` bigint(20) DEFAULT NULL, + `command_as_json` varchar(1000) NOT NULL, + `maker_id` bigint(20) NOT NULL, + `made_on_date` date NOT NULL, + `checker_id` bigint(20) DEFAULT NULL, + `checked_on_date` date DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `FK_m_maker_m_appuser` (`maker_id`), + KEY `FK_m_checker_m_appuser` (`checker_id`), + CONSTRAINT `FK_m_checker_m_appuser` FOREIGN KEY (`checker_id`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_m_maker_m_appuser` FOREIGN KEY (`maker_id`) REFERENCES `m_appuser` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_charge` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(100) DEFAULT NULL, + `currency_code` varchar(3) NOT NULL, + `charge_applies_to_enum` smallint(5) NOT NULL, + `charge_time_enum` smallint(5) NOT NULL, + `charge_calculation_enum` smallint(5) NOT NULL, + `amount` decimal(19,6) NOT NULL, + `is_penalty` tinyint(1) NOT NULL DEFAULT '0', + `is_active` tinyint(1) NOT NULL, + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', + `createdby_id` bigint(20) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_fund` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(255) DEFAULT NULL, + `external_id` varchar(100) DEFAULT NULL, + `createdby_id` bigint(20) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `fund_name_org` (`name`), + UNIQUE KEY `fund_externalid_org` (`external_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_staff` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `is_loan_officer` tinyint(1) NOT NULL DEFAULT '0', + `office_id` bigint(20) DEFAULT NULL, + `firstname` varchar(50) DEFAULT NULL, + `lastname` varchar(50) DEFAULT NULL, + `display_name` varchar(100) NOT NULL, + `createdby_id` bigint(20) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `display_name` (`display_name`), + KEY `FK_m_staff_m_office` (`office_id`), + CONSTRAINT `FK_m_staff_m_office` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- ============ end of organisation wide related tables =========== + +-- DDL client/group related tables CREATE TABLE `m_group` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, + `office_id` bigint(20) NOT NULL, `name` varchar(100) DEFAULT NULL, `external_id` varchar(100) DEFAULT NULL, `is_deleted` tinyint(1) NOT NULL DEFAULT '0', @@ -292,26 +343,28 @@ CREATE TABLE `m_group` ( UNIQUE KEY `external_id` (`external_id`), KEY `FKJPWG000000000003` (`createdby_id`), KEY `FKJPWG000000000004` (`lastmodifiedby_id`), + KEY `office_id` (`office_id`), CONSTRAINT `FKJPWG000000000003` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`), - CONSTRAINT `FKJPWG000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`) + CONSTRAINT `FKJPWG000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `m_group_ibfk_1` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `m_client` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, - `is_deleted` tinyint(1) NOT NULL DEFAULT 0, `office_id` bigint(20) NOT NULL, `external_id` varchar(100) DEFAULT NULL, `firstname` varchar(50) DEFAULT NULL, `lastname` varchar(50) DEFAULT NULL, - `display_name` varchar(50) DEFAULT NULL, + `display_name` varchar(100) NOT NULL, + `image_key` varchar(500) DEFAULT NULL, `joining_date` date DEFAULT NULL, `createdby_id` bigint(20) DEFAULT NULL, `created_date` datetime DEFAULT NULL, `lastmodified_date` datetime DEFAULT NULL, `lastmodifiedby_id` bigint(20) DEFAULT NULL, + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `external_id` (`external_id`), - KEY `display_name` (`display_name`), KEY `FKCE00CAB3E0DD567A` (`office_id`), KEY `FKAUD0000000000001` (`createdby_id`), KEY `FKAUD0000000000002` (`lastmodifiedby_id`), @@ -320,6 +373,25 @@ CREATE TABLE `m_client` ( CONSTRAINT `FKCE00CAB3E0DD567A` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `m_client_identifier` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `client_id` bigint(20) NOT NULL, + `document_type_id` int(11) NOT NULL, + `document_key` varchar(50) NOT NULL, + `description` varchar(500) DEFAULT NULL, + `createdby_id` bigint(20) DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unique_identifier_key` (`document_type_id`,`document_key`), + UNIQUE KEY `unique_client_identifier` (`client_id`,`document_type_id`), + KEY `FK_m_client_document_m_client` (`client_id`), + KEY `FK_m_client_document_m_code_value` (`document_type_id`), + CONSTRAINT `FK_m_client_document_m_client` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`), + CONSTRAINT `FK_m_client_document_m_code_value` FOREIGN KEY (`document_type_id`) REFERENCES `m_code_value` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CREATE TABLE `m_group_client` ( `group_id` bigint(20) NOT NULL, `client_id` bigint(20) NOT NULL, @@ -329,16 +401,87 @@ CREATE TABLE `m_group_client` ( CONSTRAINT `m_group_client_ibfk_2` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ==== end of client/group related tables ========== + +-- DDL for financial products and related tables +CREATE TABLE `m_product_deposit` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL, + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', + `external_id` varchar(100) DEFAULT NULL, + `description` varchar(500) DEFAULT NULL, + `currency_code` varchar(3) NOT NULL, + `currency_digits` smallint(5) NOT NULL, + `minimum_balance` decimal(19,6) DEFAULT NULL, + `maximum_balance` decimal(19,6) DEFAULT NULL, + `tenure_months` int(11) NOT NULL, + `interest_compounded_every` smallint(5) NOT NULL DEFAULT '1', + `interest_compounded_every_period_enum` smallint(5) NOT NULL DEFAULT '2', + `maturity_default_interest_rate` decimal(19,6) NOT NULL, + `maturity_min_interest_rate` decimal(19,6) NOT NULL, + `maturity_max_interest_rate` decimal(19,6) NOT NULL, + `is_compounding_interest_allowed` tinyint(1) NOT NULL DEFAULT '0', + `is_renewal_allowed` tinyint(1) NOT NULL DEFAULT '0', + `is_preclosure_allowed` tinyint(1) NOT NULL DEFAULT '0', + `pre_closure_interest_rate` decimal(19,6) NOT NULL, + `is_lock_in_period_allowed` tinyint(1) NOT NULL DEFAULT '0', + `lock_in_period` bigint(20) DEFAULT NULL, + `lock_in_period_type` smallint(5) NOT NULL DEFAULT '2', + `createdby_id` bigint(20) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_deposit_product` (`name`), + UNIQUE KEY `externalid_deposit_product` (`external_id`), + KEY `FKJPW0000000000003` (`createdby_id`), + KEY `FKJPW0000000000004` (`lastmodifiedby_id`), + CONSTRAINT `FKJPX0000000000003` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FKJPX0000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_product_savings` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL, + `description` varchar(500) DEFAULT NULL, + `currency_code` varchar(3) DEFAULT NULL, + `currency_digits` smallint(5) DEFAULT NULL, + `interest_rate` decimal(19,6) DEFAULT NULL, + `min_interest_rate` decimal(19,6) DEFAULT NULL, + `max_interest_rate` decimal(19,6) DEFAULT NULL, + `savings_deposit_amount` decimal(19,6) NOT NULL, + `savings_product_type` smallint(5) DEFAULT NULL, + `tenure_type` smallint(5) DEFAULT NULL, + `tenure` int(11) DEFAULT NULL, + `frequency` int(11) DEFAULT NULL, + `interest_type` smallint(5) DEFAULT NULL, + `interest_calculation_method` smallint(5) DEFAULT NULL, + `min_bal_for_withdrawal` decimal(19,6) NOT NULL, + `is_partial_deposit_allowed` tinyint(1) NOT NULL DEFAULT '0', + `is_lock_in_period_allowed` tinyint(1) NOT NULL DEFAULT '0', + `lock_in_period` bigint(20) DEFAULT NULL, + `lock_in_period_type` smallint(5) NOT NULL DEFAULT '1', + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', + `createdby_id` bigint(20) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `FKJPW0000000000003` (`createdby_id`), + KEY `FKJPW0000000000004` (`lastmodifiedby_id`), + CONSTRAINT `FKJPW0000000000003` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FKJPW0000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CREATE TABLE `m_product_loan` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `currency_code` varchar(3) NOT NULL, `currency_digits` smallint(5) NOT NULL, `principal_amount` decimal(19,6) NOT NULL, - `arrearstolerance_amount` decimal(19,6) NOT NULL, + `arrearstolerance_amount` decimal(19,6) DEFAULT NULL, `name` varchar(100) NOT NULL, `description` varchar(500) DEFAULT NULL, `fund_id` bigint(20) DEFAULT NULL, - `loan_transaction_strategy_id` bigint(20) DEFAULT NULL, `nominal_interest_rate_per_period` decimal(19,6) NOT NULL, `interest_period_frequency_enum` smallint(5) NOT NULL, `annual_nominal_interest_rate` decimal(19,6) NOT NULL, @@ -348,12 +491,11 @@ CREATE TABLE `m_product_loan` ( `repayment_period_frequency_enum` smallint(5) NOT NULL, `number_of_repayments` smallint(5) NOT NULL, `amortization_method_enum` smallint(5) NOT NULL, - `flexible_repayment_schedule` bit(1) NOT NULL, - `interest_rebate` bit(1) NOT NULL, `createdby_id` bigint(20) DEFAULT NULL, `created_date` datetime DEFAULT NULL, `lastmodified_date` datetime DEFAULT NULL, `lastmodifiedby_id` bigint(20) DEFAULT NULL, + `loan_transaction_strategy_id` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`), KEY `FKAUD0000000000003` (`createdby_id`), KEY `FKAUD0000000000004` (`lastmodifiedby_id`), @@ -374,13 +516,17 @@ CREATE TABLE `m_product_loan_charge` ( CONSTRAINT `m_product_loan_charge_ibfk_2` FOREIGN KEY (`product_loan_id`) REFERENCES `m_product_loan` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ============ end of financial product related tables =========== + +-- DDL for loan and loan related tables CREATE TABLE `m_loan` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `external_id` varchar(100) DEFAULT NULL, - `client_id` bigint(20) NOT NULL, + `client_id` bigint(20) DEFAULT NULL, + `group_id` bigint(20) DEFAULT NULL, `product_id` bigint(20) DEFAULT NULL, `fund_id` bigint(20) DEFAULT NULL, - `loan_transaction_strategy_id` bigint(20) DEFAULT NULL, + `loan_officer_id` bigint(20) DEFAULT NULL, `loan_status_id` smallint(5) NOT NULL, `currency_code` varchar(3) NOT NULL, `currency_digits` smallint(5) NOT NULL, @@ -391,15 +537,13 @@ CREATE TABLE `m_loan` ( `annual_nominal_interest_rate` decimal(19,6) NOT NULL, `interest_method_enum` smallint(5) NOT NULL, `interest_calculated_in_period_enum` smallint(5) NOT NULL DEFAULT '1', - `term_frequency` smallint(5) NOT NULL, - `term_period_frequency_enum` smallint(5) NOT NULL, + `term_frequency` smallint(5) NOT NULL DEFAULT '0', + `term_period_frequency_enum` smallint(5) NOT NULL DEFAULT '2', `repay_every` smallint(5) NOT NULL, `repayment_period_frequency_enum` smallint(5) NOT NULL, `number_of_repayments` smallint(5) NOT NULL, `amortization_method_enum` smallint(5) NOT NULL, - `flexible_repayment_schedule` bit(1) NOT NULL, - `interest_rebate` bit(1) NOT NULL, - `interest_rebate_amount` decimal(19,6) DEFAULT NULL, + `total_charges_due_at_disbursement_derived` decimal(19,6) DEFAULT NULL, `submittedon_date` datetime DEFAULT NULL, `approvedon_date` datetime DEFAULT NULL, `expected_disbursedon_date` date DEFAULT NULL, @@ -417,45 +561,89 @@ CREATE TABLE `m_loan` ( `created_date` datetime DEFAULT NULL, `lastmodified_date` datetime DEFAULT NULL, `lastmodifiedby_id` bigint(20) DEFAULT NULL, + `loan_transaction_strategy_id` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`), - UNIQUE KEY `m_id` (`external_id`), + UNIQUE KEY `org_id` (`external_id`), KEY `FKB6F935D87179A0CB` (`client_id`), KEY `FKB6F935D8C8D4B434` (`product_id`), KEY `FK7C885877240145` (`fund_id`), KEY `FK_loan_ltp_strategy` (`loan_transaction_strategy_id`), - CONSTRAINT `FK_loan_ltp_strategy` FOREIGN KEY (`loan_transaction_strategy_id`) REFERENCES `ref_loan_transaction_processing_strategy` (`id`), + KEY `FK_m_loan_m_staff` (`loan_officer_id`), + KEY `group_id` (`group_id`), CONSTRAINT `FK7C885877240145` FOREIGN KEY (`fund_id`) REFERENCES `m_fund` (`id`), CONSTRAINT `FKB6F935D87179A0CB` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`), - CONSTRAINT `FKB6F935D8C8D4B434` FOREIGN KEY (`product_id`) REFERENCES `m_product_loan` (`id`) + CONSTRAINT `FKB6F935D8C8D4B434` FOREIGN KEY (`product_id`) REFERENCES `m_product_loan` (`id`), + CONSTRAINT `FK_loan_ltp_strategy` FOREIGN KEY (`loan_transaction_strategy_id`) REFERENCES `ref_loan_transaction_processing_strategy` (`id`), + CONSTRAINT `FK_m_loan_m_staff` FOREIGN KEY (`loan_officer_id`) REFERENCES `m_staff` (`id`), + CONSTRAINT `m_loan_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `m_group` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `m_loan_charge` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, `loan_id` bigint(20) NOT NULL, `charge_id` bigint(20) NOT NULL, + `is_penalty` tinyint(1) NOT NULL DEFAULT '0', `charge_time_enum` smallint(5) NOT NULL, + `due_for_collection_as_of_date` date DEFAULT NULL, `charge_calculation_enum` smallint(5) NOT NULL, + `calculation_percentage` decimal(19,6) DEFAULT NULL, + `calculation_on_amount` decimal(19,6) DEFAULT NULL, `amount` decimal(19,6) NOT NULL, - PRIMARY KEY (`loan_id`,`charge_id`), + `amount_paid_derived` decimal(19,6) DEFAULT NULL, + `amount_waived_derived` decimal(19,6) DEFAULT NULL, + `amount_writtenoff_derived` decimal(19,6) DEFAULT NULL, + `amount_outstanding_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `is_paid_derived` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), KEY `charge_id` (`charge_id`), + KEY `m_loan_charge_ibfk_2` (`loan_id`), CONSTRAINT `m_loan_charge_ibfk_1` FOREIGN KEY (`charge_id`) REFERENCES `m_charge` (`id`), CONSTRAINT `m_loan_charge_ibfk_2` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `m_loan_officer_assignment_history` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `loan_id` bigint(20) NOT NULL, + `loan_officer_id` bigint(20) DEFAULT NULL, + `start_date` date NOT NULL, + `end_date` date DEFAULT NULL, + `createdby_id` bigint(20) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_m_loan_officer_assignment_history_0001` (`loan_id`), + KEY `fk_m_loan_officer_assignment_history_0002` (`loan_officer_id`), + CONSTRAINT `fk_m_loan_officer_assignment_history_0001` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`), + CONSTRAINT `fk_m_loan_officer_assignment_history_0002` FOREIGN KEY (`loan_officer_id`) REFERENCES `m_staff` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + CREATE TABLE `m_loan_repayment_schedule` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `loan_id` bigint(20) NOT NULL, - `duedate` date DEFAULT NULL, - `installment` smallint(5) DEFAULT NULL, + `fromdate` date DEFAULT NULL, + `duedate` date NOT NULL, + `installment` smallint(5) NOT NULL, `principal_amount` decimal(19,6) DEFAULT NULL, `principal_completed_derived` decimal(19,6) DEFAULT NULL, + `principal_writtenoff_derived` decimal(19,6) DEFAULT NULL, `interest_amount` decimal(19,6) DEFAULT NULL, `interest_completed_derived` decimal(19,6) DEFAULT NULL, - `interest_waived_derived` decimal(19,6) DEFAULT NULL, + `interest_writtenoff_derived` decimal(19,6) DEFAULT NULL, + `fee_charges_amount` decimal(19,6) DEFAULT NULL, + `fee_charges_completed_derived` decimal(19,6) DEFAULT NULL, + `fee_charges_writtenoff_derived` decimal(19,6) DEFAULT NULL, + `fee_charges_waived_derived` decimal(19,6) DEFAULT NULL, + `penalty_charges_amount` decimal(19,6) DEFAULT NULL, + `penalty_charges_completed_derived` decimal(19,6) DEFAULT NULL, + `penalty_charges_writtenoff_derived` decimal(19,6) DEFAULT NULL, + `penalty_charges_waived_derived` decimal(19,6) DEFAULT NULL, `completed_derived` bit(1) NOT NULL, `createdby_id` bigint(20) DEFAULT NULL, `created_date` datetime DEFAULT NULL, `lastmodified_date` datetime DEFAULT NULL, `lastmodifiedby_id` bigint(20) DEFAULT NULL, + `interest_waived_derived` decimal(19,6) DEFAULT NULL, PRIMARY KEY (`id`), KEY `FK488B92AA40BE0710` (`loan_id`), CONSTRAINT `FK488B92AA40BE0710` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`) @@ -468,13 +656,14 @@ CREATE TABLE `m_loan_transaction` ( `contra_id` bigint(20) DEFAULT NULL, `transaction_date` date NOT NULL, `amount` decimal(19,6) NOT NULL, - `principal_portion_derived` decimal(19,6) NOT NULL, - `interest_portion_derived` decimal(19,6) NOT NULL, - `interest_waived_derived` decimal(19,6) NOT NULL, `createdby_id` bigint(20) DEFAULT NULL, `created_date` datetime DEFAULT NULL, `lastmodified_date` datetime DEFAULT NULL, `lastmodifiedby_id` bigint(20) DEFAULT NULL, + `principal_portion_derived` decimal(19,6) DEFAULT NULL, + `interest_portion_derived` decimal(19,6) DEFAULT NULL, + `fee_charges_portion_derived` decimal(19,6) DEFAULT NULL, + `penalty_charges_portion_derived` decimal(19,6) DEFAULT NULL, PRIMARY KEY (`id`), KEY `FKCFCEA42640BE0710` (`loan_id`), KEY `FKCFCEA426FC69F3F1` (`contra_id`), @@ -482,61 +671,9 @@ CREATE TABLE `m_loan_transaction` ( CONSTRAINT `FKCFCEA426FC69F3F1` FOREIGN KEY (`contra_id`) REFERENCES `m_loan_transaction` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ======== end of loan related tables ========== -CREATE TABLE `m_product_savings` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `name` varchar(100) NOT NULL, - `description` varchar(500) DEFAULT NULL, - `currency_code` varchar(3) DEFAULT NULL, - `currency_digits` smallint(5) DEFAULT NULL, - `interest_rate` decimal(19,6) DEFAULT NULL, - `minimum_balance` decimal(19,6) DEFAULT NULL, - `maximum_balance` decimal(19,6) DEFAULT NULL, - `is_deleted` tinyint(1) NOT NULL DEFAULT '0', - `createdby_id` bigint(20) DEFAULT NULL, - `created_date` datetime DEFAULT NULL, - `lastmodified_date` datetime DEFAULT NULL, - `lastmodifiedby_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `FKJPW0000000000003` (`createdby_id`), - KEY `FKJPW0000000000004` (`lastmodifiedby_id`), - CONSTRAINT `FKJPW0000000000003` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`), - CONSTRAINT `FKJPW0000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - - -CREATE TABLE `m_product_deposit` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `name` varchar(100) NOT NULL, - `is_deleted` tinyint(1) NOT NULL DEFAULT '0', - `external_id` varchar(100) DEFAULT NULL, - `description` varchar(500) DEFAULT NULL, - `currency_code` varchar(3) NOT NULL, - `currency_digits` smallint(5) NOT NULL, - `minimum_balance` decimal(19,6) DEFAULT NULL, - `maximum_balance` decimal(19,6) DEFAULT NULL, - `tenure_months` int(11) NOT NULL, - `interest_compounded_every` smallint(5) NOT NULL DEFAULT '1', - `interest_compounded_every_period_enum` smallint(5) NOT NULL DEFAULT '2', - `maturity_default_interest_rate` decimal(19,6) NOT NULL, - `maturity_min_interest_rate` decimal(19,6) NOT NULL, - `maturity_max_interest_rate` decimal(19,6) NOT NULL, - `is_renewal_allowed` tinyint(1) NOT NULL DEFAULT '0', - `is_preclosure_allowed` tinyint(1) NOT NULL DEFAULT '0', - `pre_closure_interest_rate` decimal(19,6) NOT NULL, - `createdby_id` bigint(20) DEFAULT NULL, - `created_date` datetime DEFAULT NULL, - `lastmodified_date` datetime DEFAULT NULL, - `lastmodifiedby_id` bigint(20) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name_deposit_product` (`name`), - UNIQUE KEY `externalid_deposit_product` (`external_id`), - KEY `FKJPW0000000000003` (`createdby_id`), - KEY `FKJPW0000000000004` (`lastmodifiedby_id`), - CONSTRAINT `FKJPX0000000000003` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`), - CONSTRAINT `FKJPX0000000000004` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - +-- DDL for deposit account related tables CREATE TABLE `m_deposit_account` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `is_deleted` tinyint(1) NOT NULL DEFAULT '0', @@ -553,16 +690,21 @@ CREATE TABLE `m_deposit_account` ( `interest_compounded_every_period_enum` smallint(5) NOT NULL DEFAULT '2', `projected_commencement_date` date NOT NULL, `actual_commencement_date` date DEFAULT NULL, - `projected_maturity_date` date NOT NULL, - `actual_maturity_date` date DEFAULT NULL, + `matures_on_date` datetime DEFAULT NULL, `projected_interest_accrued_on_maturity` decimal(19,6) NOT NULL, `actual_interest_accrued` decimal(19,6) DEFAULT NULL, `projected_total_maturity_amount` decimal(19,6) NOT NULL, `actual_total_amount` decimal(19,6) DEFAULT NULL, + `is_compounding_interest_allowed` tinyint(1) NOT NULL DEFAULT '0', + `interest_paid` decimal(19,6) NOT NULL DEFAULT '0.000000', + `is_interest_withdrawable` tinyint(1) NOT NULL DEFAULT '0', `is_renewal_allowed` tinyint(1) NOT NULL DEFAULT '0', `renewed_account_id` bigint(20) DEFAULT NULL, `is_preclosure_allowed` tinyint(1) NOT NULL DEFAULT '0', `pre_closure_interest_rate` decimal(19,6) NOT NULL, + `is_lock_in_period_allowed` tinyint(1) NOT NULL DEFAULT '0', + `lock_in_period` bigint(20) DEFAULT NULL, + `lock_in_period_type` smallint(5) NOT NULL DEFAULT '2', `withdrawnon_date` datetime DEFAULT NULL, `rejectedon_date` datetime DEFAULT NULL, `closedon_date` datetime DEFAULT NULL, @@ -580,11 +722,79 @@ CREATE TABLE `m_deposit_account` ( CONSTRAINT `FKKW0000000000003` FOREIGN KEY (`renewed_account_id`) REFERENCES `m_deposit_account` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `m_deposit_account_transaction` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `deposit_account_id` bigint(20) NOT NULL, + `transaction_type_enum` smallint(5) NOT NULL, + `contra_id` bigint(20) DEFAULT NULL, + `transaction_date` date NOT NULL, + `amount` decimal(19,6) NOT NULL, + `interest` decimal(19,6) NOT NULL, + `total` decimal(19,6) NOT NULL, + PRIMARY KEY (`id`), + KEY `FKKW00000000000005` (`deposit_account_id`), + KEY `FKKW00000000000006` (`contra_id`), + CONSTRAINT `FKKW00000000000005` FOREIGN KEY (`deposit_account_id`) REFERENCES `m_deposit_account` (`id`), + CONSTRAINT `FKKW00000000000006` FOREIGN KEY (`contra_id`) REFERENCES `m_deposit_account_transaction` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- ======= end of deposit account related tables + +-- DDL for savings account related tables +CREATE TABLE `m_saving_account` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', + `status_enum` smallint(5) NOT NULL DEFAULT '0', + `external_id` varchar(100) DEFAULT NULL, + `client_id` bigint(20) NOT NULL, + `product_id` bigint(20) NOT NULL, + `deposit_amount_per_period` decimal(19,6) NOT NULL, + `savings_product_type` smallint(5) DEFAULT NULL, + `currency_code` varchar(3) NOT NULL, + `currency_digits` smallint(5) NOT NULL, + `total_deposit_amount` decimal(19,6) NOT NULL, + `reccuring_nominal_interest_rate` decimal(19,6) NOT NULL, + `regular_saving_nominal_interest_rate` decimal(19,6) NOT NULL, + `tenure` int(11) NOT NULL, + `tenure_type` smallint(5) DEFAULT NULL, + `frequency` int(11) DEFAULT NULL, + `interest_type` smallint(5) DEFAULT NULL, + `interest_calculation_method` smallint(5) DEFAULT NULL, + `projected_commencement_date` date NOT NULL, + `actual_commencement_date` date DEFAULT NULL, + `matures_on_date` datetime DEFAULT NULL, + `projected_interest_accrued_on_maturity` decimal(19,6) NOT NULL, + `actual_interest_accrued` decimal(19,6) DEFAULT NULL, + `projected_total_maturity_amount` decimal(19,6) NOT NULL, + `actual_total_amount` decimal(19,6) DEFAULT NULL, + `is_preclosure_allowed` tinyint(1) NOT NULL DEFAULT '0', + `pre_closure_interest_rate` decimal(19,6) NOT NULL, + `is_lock_in_period_allowed` tinyint(1) NOT NULL DEFAULT '0', + `lock_in_period` bigint(20) DEFAULT NULL, + `lock_in_period_type` smallint(5) NOT NULL DEFAULT '1', + `withdrawnon_date` datetime DEFAULT NULL, + `rejectedon_date` datetime DEFAULT NULL, + `closedon_date` datetime DEFAULT NULL, + `createdby_id` bigint(20) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `deposit_acc_external_id` (`external_id`), + KEY `FKSA0000000000001` (`client_id`), + KEY `FKSA0000000000002` (`product_id`), + CONSTRAINT `FKSA0000000000001` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`), + CONSTRAINT `FKSA0000000000002` FOREIGN KEY (`product_id`) REFERENCES `m_product_savings` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- end of savings account related tables + +-- DDL for notes associated with all client/group and financial accounts CREATE TABLE `m_note` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `client_id` bigint(20) NOT NULL, `loan_id` bigint(20) DEFAULT NULL, `loan_transaction_id` bigint(20) DEFAULT NULL, + `deposit_account_id` bigint(20) DEFAULT NULL, `note_type_enum` smallint(5) NOT NULL, `note` varchar(1000) DEFAULT NULL, `created_date` datetime DEFAULT NULL, @@ -597,26 +807,41 @@ CREATE TABLE `m_note` ( KEY `FK7C970897179A0CB` (`client_id`), KEY `FK7C970898F889C3F` (`lastmodifiedby_id`), KEY `FK7C9708940BE0710` (`loan_id`), + KEY `FK_m_note_m_deposit_account` (`deposit_account_id`), CONSTRAINT `FK7C9708924D26803` FOREIGN KEY (`loan_transaction_id`) REFERENCES `m_loan_transaction` (`id`), CONSTRAINT `FK7C9708940BE0710` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`), CONSTRAINT `FK7C97089541F0A56` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`), CONSTRAINT `FK7C970897179A0CB` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`), - CONSTRAINT `FK7C970898F889C3F` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`) + CONSTRAINT `FK7C970898F889C3F` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_m_note_m_deposit_account` FOREIGN KEY (`deposit_account_id`) REFERENCES `m_deposit_account` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- DDL for additional data (aka stretchy data) tables + +-- DDL for accounting sub system related tables +CREATE TABLE `m_acc_coa` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `parent_id` bigint(20) DEFAULT NULL, + `gl_code` varchar(45) NOT NULL, + `is_disabled` tinyint(1) NOT NULL DEFAULT '0', + `manual_entries_allowed` tinyint(1) NOT NULL DEFAULT '0', + `category` varchar(45) NOT NULL, + `ledger_type` varchar(45) NOT NULL, + `description` varchar(500) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `acc_gl_code` (`gl_code`), + KEY `FK_ACC_0000000001` (`parent_id`), + CONSTRAINT `FK_ACC_0000000001` FOREIGN KEY (`parent_id`) REFERENCES `m_acc_coa` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- =========== end of accounting related tables ========== + +-- DDL for reporting related tables CREATE TABLE `rpt_sequence` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `stretchydata_datasettype` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(45) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `name` (`name`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - CREATE TABLE `stretchy_parameter` ( `parameter_id` int(11) NOT NULL AUTO_INCREMENT, `parameter_name` varchar(45) NOT NULL, @@ -633,30 +858,6 @@ CREATE TABLE `stretchy_parameter` ( UNIQUE KEY `name_UNIQUE` (`parameter_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `stretchydata_dataset` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(45) NOT NULL, - `datasettype_id` int(11) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `stretchydata_dataset_fk1` (`datasettype_id`,`name`), - CONSTRAINT `stretchydata_dataset` FOREIGN KEY (`datasettype_id`) REFERENCES `stretchydata_datasettype` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -CREATE TABLE `stretchydata_dataset_fields` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `name` varchar(45) NOT NULL, - `data_type` varchar(15) NOT NULL, - `data_length` int(11) DEFAULT NULL, - `display_type` varchar(45) DEFAULT NULL, - `dataset_id` int(11) NOT NULL, - `code_id` int(11) DEFAULT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `stretchydata_dataset_fields_fk1` (`dataset_id`,`name`), - KEY `stretchydata_dataset_fields_fk2` (`code_id`), - CONSTRAINT `stretchydata_dataset_fields_fk2` FOREIGN KEY (`code_id`) REFERENCES `m_code` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT `stretchydata_dataset_fields_fk1` FOREIGN KEY (`dataset_id`) REFERENCES `stretchydata_dataset` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - CREATE TABLE `stretchy_report` ( `report_id` int(11) NOT NULL AUTO_INCREMENT, `report_name` varchar(100) NOT NULL, @@ -677,5 +878,5 @@ CREATE TABLE `stretchy_report_parameter` ( `report_parameter_name` varchar(45) DEFAULT NULL, PRIMARY KEY (`report_id`,`parameter_id`), UNIQUE KEY `report_id_name_UNIQUE` (`report_id`,`report_parameter_name`) -) ENGINE=InnoDB CHARSET=utf8; - +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- =========== end of reporting related tables ============ \ No newline at end of file diff --git a/mifosng-db/0001b-demo-additional-data-ddl-schema.sql b/mifosng-db/0001b-demo-additional-data-ddl-schema.sql index beb70360c..fce7f8250 100644 --- a/mifosng-db/0001b-demo-additional-data-ddl-schema.sql +++ b/mifosng-db/0001b-demo-additional-data-ddl-schema.sql @@ -1,47 +1,42 @@ --- example of a DDL script to support customised 'additional data' for clients and loans. +DROP TABLE IF EXISTS `additional client fields data`; +DROP TABLE IF EXISTS `extra family details data`; +DROP TABLE IF EXISTS `additional loan fields data`; -DROP TABLE IF EXISTS `m_client_xAdditional Information`; -DROP TABLE IF EXISTS `m_client_xHighly Improbable Info`; -DROP TABLE IF EXISTS `m_loan_xAdditional Information`; +CREATE TABLE `additional client fields data` ( + `client_id` bigint(20) NOT NULL, + `Business Description` varchar(100) DEFAULT NULL, + `Years in Business` int(11) DEFAULT NULL, + `Gender_cd` int(11) DEFAULT NULL, + `Education_cv` varchar(60) DEFAULT NULL, + `Next Visit` date DEFAULT NULL, + `Highest Rate Paid` decimal(19,6) DEFAULT NULL, + `Comment` text, + PRIMARY KEY (`client_id`), + CONSTRAINT `FK_Additional Client Fields Data_1` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `m_client_xAdditional Information` ( +CREATE TABLE `extra family details data` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, - `Ethnic Group` varchar(50) DEFAULT NULL, - `Ethnic Group Other` varchar(50) DEFAULT NULL, - `Household Location` varchar(50) DEFAULT NULL, - `Household Location Other` varchar(50) DEFAULT NULL, - `Religion` varchar(50) DEFAULT NULL, - `Religion Other` varchar(50) DEFAULT NULL, - `Knowledge of Person` varchar(50) DEFAULT NULL, - `Gender` varchar(10) DEFAULT NULL, - `Whois` mediumtext, + `client_id` bigint(20) NOT NULL, + `Name` varchar(40) DEFAULT NULL, + `Date of Birth` date DEFAULT NULL, + `Points Score` int(11) DEFAULT NULL, + `Education_cdHighest` int(11) DEFAULT NULL, + `Other Notes` text, PRIMARY KEY (`id`), - CONSTRAINT `m_client_xAdditional Information_fk1` FOREIGN KEY (`id`) REFERENCES `m_client` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; + KEY `FK_Extra Family Details Data_1` (`client_id`), + CONSTRAINT `FK_Extra Family Details Data_1` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; -CREATE TABLE `m_client_xHighly Improbable Info` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `Fathers Favourite Team` varchar(50) DEFAULT NULL, - `Mothers Favourite Team` varchar(50) DEFAULT NULL, - `Fathers DOB` date DEFAULT NULL, - `Mothers DOB` date DEFAULT NULL, - `Fathers Education` varchar(50) DEFAULT NULL, - `Mothers Education` varchar(50) DEFAULT NULL, - `Number of Children` int(11) DEFAULT NULL, - `Favourite Town` varchar(30) DEFAULT NULL, - `Closing Comments` mediumtext, - `Annual Family Income` decimal(19,6) DEFAULT NULL, - PRIMARY KEY (`id`), - CONSTRAINT `m_client_xHighly Improbable Info_fk1` FOREIGN KEY (`id`) REFERENCES `m_client` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; - -CREATE TABLE `m_loan_xAdditional Information` ( - `id` bigint(20) NOT NULL AUTO_INCREMENT, - `Business Location` varchar(50) DEFAULT NULL, - `Business Location Other` varchar(50) DEFAULT NULL, - `Business` varchar(10) DEFAULT NULL, - `Business Description` mediumtext, - `Business Title` varchar(100) DEFAULT NULL, - PRIMARY KEY (`id`), - CONSTRAINT `m_loan_xAdditional Information_fk1` FOREIGN KEY (`id`) REFERENCES `m_loan` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; \ No newline at end of file +CREATE TABLE `additional loan fields data` ( + `loan_id` bigint(20) NOT NULL, + `Business Description` varchar(100) DEFAULT NULL, + `Years in Business` int(11) DEFAULT NULL, + `Gender_cd` int(11) DEFAULT NULL, + `Education_cv` varchar(60) DEFAULT NULL, + `Next Visit` date DEFAULT NULL, + `Highest Rate Paid` decimal(19,6) DEFAULT NULL, + `Comment` text, + PRIMARY KEY (`loan_id`), + CONSTRAINT `FK_Additional Loan Fields Data_1` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/mifosng-db/0001b-gk-datatables.sql b/mifosng-db/0001b-gk-datatables.sql new file mode 100644 index 000000000..63d463bd0 --- /dev/null +++ b/mifosng-db/0001b-gk-datatables.sql @@ -0,0 +1,39 @@ +DROP TABLE IF EXISTS `risk_analysis`; +CREATE TABLE `risk_analysis` ( + `client_id` bigint(20) NOT NULL, + `proposed_loan_amount` decimal(19,6) DEFAULT NULL, + `assets_cash` decimal(19,6) DEFAULT NULL, + `assets_bank_accounts` decimal(19,6) DEFAULT NULL, + `assets_accounts_receivable` decimal(19,6) DEFAULT NULL, + `assets_inventory` decimal(19,6) DEFAULT NULL, + `assets_total_fixed_business` decimal(19,6) DEFAULT NULL, + `assets_total_business` decimal(19,6) DEFAULT NULL, + `assets_total_household` decimal(19,6) DEFAULT NULL, + `liabilities_accounts_payable` decimal(19,6) DEFAULT NULL, + `liabilities_business_debts` decimal(19,6) DEFAULT NULL, + `liabilities_total_business` decimal(19,6) DEFAULT NULL, + `liabilities_equity_working_capital` decimal(19,6) DEFAULT NULL, + `liabilities_total_household` decimal(19,6) DEFAULT NULL, + `liabilities_household_equity` decimal(19,6) DEFAULT NULL, + `cashflow_cash_sales` decimal(19,6) DEFAULT NULL, + `cashflow_cash_sales2` decimal(19,6) DEFAULT NULL, + `cashflow_cost_goods_sold` decimal(19,6) DEFAULT NULL, + `cashflow_cost_goods_sold2` decimal(19,6) DEFAULT NULL, + `cashflow_gross_profit` decimal(19,6) DEFAULT NULL, + `cashflow_other_income1` decimal(19,6) DEFAULT NULL, + `cashflow_total_income2` decimal(19,6) DEFAULT NULL, + `cashflow_household_expense` decimal(19,6) DEFAULT NULL, + `cashflow_payments_to_savings` decimal(19,6) DEFAULT NULL, + `cashflow_operational_expenses` decimal(19,6) DEFAULT NULL, + `cashflow_disposable_income` decimal(19,6) DEFAULT NULL, + `cashflow_amount_loan_installment` decimal(19,6) DEFAULT NULL, + `cashflow_available_surplus` decimal(19,6) DEFAULT NULL, + `fi_inventory_turnover` decimal(19,6) DEFAULT NULL, + `fi_gross_margin` decimal(19,6) DEFAULT NULL, + `fi_indebtedness` decimal(19,6) DEFAULT NULL, + `fi_loan_recommendation` decimal(19,6) DEFAULT NULL, + `fi_roe` decimal(19,6) DEFAULT NULL, + `fi_repayment_capacity` decimal(19,6) DEFAULT NULL, + PRIMARY KEY (`client_id`), + CONSTRAINT `FK_risk_analysis_1` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/mifosng-db/0002-mifosng-base-reference-data.sql b/mifosng-db/0002-mifosng-base-reference-data.sql index 0b5395ab8..97e277f21 100644 --- a/mifosng-db/0002-mifosng-base-reference-data.sql +++ b/mifosng-db/0002-mifosng-base-reference-data.sql @@ -69,30 +69,14 @@ VALUES (163,'ZWD',2,NULL,'Zimbabwe Dollar','currency.ZWD'); -INSERT INTO `m_permission` (`id`, `group_enum`, `code`, `default_description`, `default_name`) +INSERT INTO `m_permission` (`id`, `code`, `default_description`, `default_name`) VALUES -(1,0,'ALL_FUNCTIONS','An application user will have permission to execute all read tasks.','ALL'), -(2,0,'ALL_FUNCTIONS_READ','An application user will have permission to execute all tasks.','ALL READ'), -(3,1,'USER_ADMINISTRATION_SUPER_USER_ROLE','An application user will have permission to execute all tasks related to user administration.','User administration ALL'), -(4,2,'ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE','An application user will have permission to execute all tasks related to organisation administration.','Organisation adminsitration ALL'), -(5,3,'PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE','An application user will have permission to execute all tasks related to portfolio management.','Portfolio management ALL'), -(6,4,'REPORTING_SUPER_USER_ROLE','An application user will have permission to execute and view all reports.','Reporting ALL'), -(7,3,'CAN_SUBMIT_NEW_LOAN_APPLICATION_ROLE','Allows an application user to sumit new loan application.','Can submit new loan application'), -(8,3,'CAN_SUBMIT_HISTORIC_LOAN_APPLICATION_ROLE','Allows an application user to sumit new loan application where the submitted on date is in the past.','Can submit historic loan application'), -(9,3,'CAN_APPROVE_LOAN_ROLE','Allows an application user to approve a loan application.','Can approve loan application'), -(10,3,'CAN_APPROVE_LOAN_IN_THE_PAST_ROLE','Allows an application user to approve a loan application where the approval date is in the past.','Can approve loan application in the past'), -(11,3,'CAN_REJECT_LOAN_ROLE','Allows an application user to reject a loan application.','Can reject loan application'), -(12,3,'CAN_REJECT_LOAN_IN_THE_PAST_ROLE','Allows an application user to reject a loan application where the rejected date is in the past.','Can reject loan application in the past'), -(13,3,'CAN_WITHDRAW_LOAN_ROLE','Allows an application user to mark loan application as withdrawn by client.','Can withdraw loan application'), -(14,3,'CAN_WITHDRAW_LOAN_IN_THE_PAST_ROLE','Allows an application user to mark loan application as withdrawn by client where the withdran on date is in the past.','Can withdraw loan application in the past'), -(15,3,'CAN_DELETE_LOAN_THAT_IS_SUBMITTED_AND_NOT_APPROVED','Allows an application user to complete delete the loan application if it is submitted but not approved.','Can delete submitted loan application'), -(16,3,'CAN_UNDO_LOAN_APPROVAL_ROLE','Allows an application user to undo a loan approval.','Can undo loan approval'), -(17,3,'CAN_DISBURSE_LOAN_ROLE','Allows an application user to disburse a loan application.','Can disburse loan'), -(18,3,'CAN_DISBURSE_LOAN_IN_THE_PAST_ROLE','Allows an application user to disburse a loan where the disbursement date is in the past.','Can disburse loan in the past'), -(19,3,'CAN_UNDO_LOAN_DISBURSAL_ROLE','Allows an application user to undo a loan disbursal if not payments already made.','Can undo loan disbursal'), -(20,3,'CAN_MAKE_LOAN_REPAYMENT_LOAN_ROLE','Allows an application user to enter a repayment on the loan.','Can enter a repayment against a loan'), -(21,3,'CAN_MAKE_LOAN_REPAYMENT_IN_THE_PAST_ROLE','Allows an application user to enter a repayment on the loan where the repayment date is in the past.','Can enter a repayment against a loan in the past'), -(22,3,'CAN_ENROLL_NEW_CLIENT_ROLE','Allows an application user to add a new client.','Can add a new client.'); +(1,'ALL_FUNCTIONS','An application user will have permission to execute all read tasks.','ALL'), +(2,'ALL_FUNCTIONS_READ','An application user will have permission to execute all tasks.','ALL READ'), +(3,'USER_ADMINISTRATION_SUPER_USER','An application user will have permission to execute all tasks related to user administration.','User administration ALL'), +(4,'ORGANISATION_ADMINISTRATION_SUPER_USER','An application user will have permission to execute all tasks related to organisation administration.','Organisation adminsitration ALL'), +(5,'PORTFOLIO_MANAGEMENT_SUPER_USER','An application user will have permission to execute all tasks related to portfolio management.','Portfolio management ALL'), +(6,'REPORTING_SUPER_USER','An application user will have permission to execute and view all reports.','Reporting ALL'); INSERT INTO `stretchy_parameter` VALUES (3,'FullReportList',NULL,'n/a','n/a','n/a','n/a','Y',NULL,NULL,'select r.report_id, r.report_name, r.report_type, r.report_subtype, r.report_category,\r\nrp.parameter_id, rp.report_parameter_name, p.parameter_name\r\nfrom stretchy_report r\r\nleft join stretchy_report_parameter rp on rp.report_id = r.report_id\r\nleft join stretchy_parameter p on p.parameter_id = rp.parameter_id\r\nwhere r.use_report is true\r\nand exists\r\n(select \'f\' \r\nfrom m_appuser_role ur \r\njoin m_role r on r.id = ur.role_id\r\nleft join m_role_permission rp on rp.role_id = r.id\r\nleft join m_permission p on p.id = rp.permission_id\r\nwhere ur.appuser_id = ${currentUserId}\r\nand (r.name = \'Super User\' or r.name = \'Read Only\') or p.code = concat(\"CAN_RUN_\", r.report_name))\r\norder by r.report_name, rp.parameter_id'),(4,'FullParameterList',NULL,'n/a','n/a','n/a','n/a','Y',NULL,NULL,'select parameter_name, parameter_variable, parameter_label, parameter_displayType, parameter_FormatType, parameter_default, selectOne, selectAll\r\nfrom stretchy_parameter p\r\nwhere special is null\r\norder by parameter_id'),(5,'selectOfficeId','officeId','Office','select','number','0',NULL,'Y',NULL,'select id, \r\nconcat(substring(\"........................................\", 1, \r\n ((LENGTH(`hierarchy`) - LENGTH(REPLACE(`hierarchy`, \'.\', \'\')) - 1) * 4)), \r\n `name`) as tc\r\nfrom m_office\r\nwhere hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\norder by hierarchy'),(6,'currencyIdSelectAll','currencyId','Currency','select','number','0',NULL,'Y','Y','select `code`, `name`\r\nfrom m_organisation_currency\r\norder by `code`'),(7,'currencyIdSelectOne','currencyId','Currency','select','number','0',NULL,'Y',NULL,'select `code`, `name`\r\nfrom m_organisation_currency\r\norder by `code`'),(10,'fundIdSelectAll','fundId','Fund','select','number','0',NULL,'Y','Y','(select id, `name`\r\nfrom m_fund\r\norder by `name`)\r\nunion all\r\n(select -10, \'-\')'),(80,'selectStartDate','startDate','startDate','date','date','today',NULL,NULL,NULL,NULL),(81,'selectEndDate','endDate','endDate','date','date','today',NULL,NULL,NULL,NULL),(82,'reportCategoryList',NULL,'n/a','n/a','n/a','n/a','Y',NULL,NULL,'select r.report_id, r.report_name, r.report_type, r.report_subtype, r.report_category,\r\nrp.parameter_id, rp.report_parameter_name, p.parameter_name\r\nfrom stretchy_report r\r\nleft join stretchy_report_parameter rp on rp.report_id = r.report_id\r\nleft join stretchy_parameter p on p.parameter_id = rp.parameter_id\r\nwhere r.report_category = \'${reportCategory}\'\r\nand r.use_report is true\r\nand exists\r\n(select \'f\' \r\nfrom m_appuser_role ur \r\njoin m_role r on r.id = ur.role_id\r\nleft join m_role_permission rp on rp.role_id = r.id\r\nleft join m_permission p on p.id = rp.permission_id\r\nwhere ur.appuser_id = ${currentUserId}\r\nand (r.name = \'Super User\' or r.name = \'Read Only\') or p.code = concat(\"CAN_RUN_\", r.report_name))\r\norder by r.report_name, rp.parameter_id'); @@ -125,4 +109,13 @@ INSERT INTO `m_appuser_role` (`appuser_id`, `role_id`) VALUES (1,1); INSERT INTO `m_organisation_currency` (`id`, `code`, `decimal_places`, `name`, `display_symbol`, `internationalized_name_code`, `createdby_id`, `created_date`, `lastmodified_date`, `lastmodifiedby_id`) VALUES -(21,'USD',2,'US Dollar','$','currency.USD',1,'2012-05-01 22:43:02','2012-05-01 22:43:02',1); \ No newline at end of file +(21,'USD',2,'US Dollar','$','currency.USD',1,'2012-05-01 22:43:02','2012-05-01 22:43:02',1); + +-- create single code and code value for client identifiers +INSERT INTO `m_code` +(`id`,`code_name`) VALUES (1,'Customer Identifier'); + +INSERT INTO `m_code_value` +(`id`,`code_id`,`code_value`,`order_position`) +VALUES +(1,1,'Passport number',0); \ No newline at end of file diff --git a/mifosng-db/0003-default-demo-data.sql b/mifosng-db/0003-default-demo-data.sql deleted file mode 100644 index deff53ac1..000000000 --- a/mifosng-db/0003-default-demo-data.sql +++ /dev/null @@ -1,98 +0,0 @@ --- create roles and associate with permissions -INSERT INTO `m_role` (`id`, `name`, `description`, `createdby_id`, `created_date`, `lastmodified_date`, `lastmodifiedby_id`) -VALUES -(3,'Field officer','A field officer role allows the user to add client and loans and view reports but nothing else.',1,'2012-04-12 15:59:48','2012-04-12 15:59:48',1), -(4,'Data Entry (Portfolio only)','This role allows a user full permissions around client and loan functionality but nothing else.',1,'2012-04-12 16:01:25','2012-04-12 16:01:25',1), -(5,'Credit Committe Member','This role allows a user to approve reject or withdraw loans (with reporting).',1,'2012-04-12 16:11:25','2012-04-12 16:11:25',1), -(6,'Manager','This role allows a manager to do anything related to portfolio management and also view all reports.',1,'2012-04-12 17:02:11','2012-04-12 17:02:11',1); - -INSERT INTO `m_role_permission` (`role_id`, `permission_id`) -VALUES -(3,6),(3,7),(3,8),(3,15),(3,22),(4,5),(5,6),(5,9),(5,10),(5,11),(5,12),(5,13),(5,14),(6,5),(6,6); - - -INSERT INTO `m_code` VALUES (1,'Business'),(2,'Education'),(3,'Ethnic Group'),(4,'Football Team'),(5,'Gender'),(6,'Knowledge of Person'),(7,'Location'),(8,'Religion'); -INSERT INTO `m_code_value` VALUES (1,1,'Existing',8),(2,1,'New',7),(3,2,'None',44),(4,2,'Primary',40),(5,2,'Secondary',41),(6,2,'Tertiary',42),(7,2,'Trade',43),(8,3,'Bedouin',15),(9,3,'Berber',16),(10,3,'Italian',17),(11,3,'Miknasa',18),(12,3,'Mrazig',19),(13,3,'Other',20),(14,3,'Unknown',46),(15,4,'AC Milan',36),(16,4,'Juventus',37),(17,4,'Manchester Utd',39),(18,4,'None, hates soccer',45),(19,4,'Sao Paulo',38),(20,5,'Female',21),(21,5,'Male',22),(22,6,'Friend of staff member',26),(23,6,'Not known by any staff member',27),(24,6,'Other',28),(25,6,'Son/daughter of staff member',25),(26,6,'Spouse of staff member',24),(27,6,'Staff member',23),(28,7,'East Sikkim',1),(29,7,'North Sikkim',2),(30,7,'Other',6),(31,7,'South Sikkim',3),(32,7,'West Sikkim',4),(33,8,'Animist',32),(34,8,'Atheist',33),(35,8,'Catholic',30),(36,8,'Muslim',31),(37,8,'Other',34),(38,8,'Protestant',29),(39,8,'Unknown',35); - -INSERT INTO `stretchy_report` VALUES (29,'Client Listing','Table',NULL,'Client','select ounder.`name` as \"Office/Branch\", concat(c.lastname, if(c.firstname > \"\", concat(\", \", c.firstname), \"\")) as \"Name\", \r\nc.joining_date as \"Joining Date\"\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\nwhere o.id = ${officeId}\r\nand c.is_deleted=0\r\norder by ounder.hierarchy','Simple sample screen report.\r\nNot really expected to be part of core reports.',0,1),(30,'Client Loans Listing','Table',NULL,'Client','select ounder.`name` as \"Office/Branch\", concat(c.lastname, if(c.firstname > \"\", concat(\", \", c.firstname), \"\")) as \"Name\",c.joining_date as \"Joining Date\",\r\np.name as Loan, st.enum_message_property as \"Status\", l.number_of_repayments as \"Expected No. Repayments\",\r\nl.annual_nominal_interest_rate as \" Annual Nominal Interest Rate\", \r\nifnull(cur.display_symbol, l.currency_code) as Currency, l.principal_amount,date( l.submittedon_date) as Submitted,\r\ndate(l.approvedon_date) Approved, l.expected_disbursedon_date As \"Expected Disbursal\",\r\ndate(l.expected_firstrepaymenton_date) as \"Expected First Repayment\",\r\ndate(l.expected_maturedon_date) \"Expected Maturity\",\r\ndate(l.disbursedon_date) as Disbursed, date(l.closedon_date) as Closed,\r\ndate(l.withdrawnon_date) as Withdrawn, date(l.rejectedon_date) as Rejected,\r\ndate(l.rescheduledon_date) Rescheduled, date(l.writtenoffon_date) \"Written Off\"\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\nleft join m_loan l on l.client_id = c.id\r\nleft join m_product_loan p on p.id = l.product_id\r\nleft join r_enum_value st on st.enum_name = \'loan_status_id\' and st.enum_id = l.loan_status_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nwhere o.id = ${officeId}\r\norder by ounder.hierarchy, \"Name\" , l.id','Can be a basic core loan report.',1,1),(31,'Loans Awaiting Disbursal','Table',NULL,'Loan Portfolio','SELECT ounder.`name` as \"Office/Branch\", concat(c.lastname, if(c.firstname > \"\", concat(\", \", c.firstname), \"\")) as \"Name\", \r\nl.id as \"Loan ID\", pl.`name` as \"Product\", \r\nifnull(cur.display_symbol, l.currency_code) as Currency, \r\nl.principal_amount as Principal, \r\ndate(l.approvedon_date) \"Approved\", l.expected_disbursedon_date \"Expected Disbursal\"\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\njoin m_loan l on l.client_id = c.id\r\njoin m_product_loan pl on pl.id = l.product_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nwhere o.id = ${officeId}\r\nand l.loan_status_id = 200\r\norder by ounder.hierarchy, l.expected_disbursedon_date, \"Name\"',NULL,0,1),(32,'Upcoming Repayments','Table',NULL,'Loan Portfolio','SELECT r.duedate \"Due Date\", ounder.`name` as \"Office/Branch\", ifnull(cur.display_symbol, l.currency_code) as Currency, \r\nc.id as \"Client ID\",\r\nconcat(c.lastname, if(c.firstname > \"\", concat(\", \", c.firstname), \"\")) as \"Name\", \r\nl.id as \"Loan ID\", pl.`name` as \"Product\", \r\n\r\n(select\r\n if(if(datediff(curdate(), min(r.duedate)) < 0, 0, datediff(curdate(), min(r.duedate))) > 90, \"High\", \r\n if (if(datediff(curdate(), min(r.duedate)) < 0, 0, datediff(curdate(), min(r.duedate))) > 30, \"Medium\", \r\n if (if(datediff(curdate(), min(r.duedate)) < 0, 0, datediff(curdate(), min(r.duedate))) = 0, \r\n if (min(r.installment) = 1, \"Low\", \"Very Low\"),\r\n if (min(r.installment), \"Medium\", \"Low\")))) \r\nfrom m_loan lr\r\nleft join m_loan_repayment_schedule r on r.loan_id = lr.id\r\n and r.completed_derived is false\r\nwhere lr.id = l.id) as \"Loan Risk\",\r\n\r\n r.installment as Installment, \r\n(r.principal_amount - ifnull(r.principal_completed_derived, 0)) as \"Principal Due\",\r\n(r.interest_amount - ifnull(r.interest_completed_derived, 0)) as \"Interest Due\" ,\r\n((r.principal_amount - ifnull(r.principal_completed_derived, 0)) +\r\n(r.interest_amount - ifnull(r.interest_completed_derived, 0))) as \"Total Due\"\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\njoin m_loan l on l.client_id = c.id\r\njoin m_product_loan pl on pl.id = l.product_id\r\njoin m_loan_repayment_schedule r on r.loan_id = l.id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\" )\r\nand l.loan_status_id = 300\r\nand r.duedate >= curdate()\r\norder by r.duedate, \"Name\"','Unlikely to be generally useful. Used as an example for Creocore',0,1),(34,'Loans - Active Loans Portfolio Status','Table',NULL,'Loan','select x.`Office/Branch`, x.Currency, x.`Name`, x.Loan, x.`Loan ID`, x.Disbursed, \r\nx.`Principal Outstanding`, x.`Interest Outstanding`, x.`Days Overdue`,\r\nx.`Principal Overdue`, x.`Interest Overdue`, \r\n\r\nif(x.`Days Overdue` > 90, \"High\", \r\n if (x.`Days Overdue` > 30, \"Medium\", \r\n if (`Days Overdue` = 0, \r\n if (`First Overdue Installment` = 1, \"Low\", \"Very Low\"),\r\n if (`First Overdue Installment` = 1, \"Medium\", \"Low\"))))\r\n\r\nas \"Loan Risk\", \r\nx.`First Overdue Installment`, x.`First Overdue Installment Date`\r\nfrom\r\n(select ounder.hierarchy, ounder.`name` as \"Office/Branch\", concat(c.lastname, if(c.firstname > \"\", concat(\", \", c.firstname), \"\")) as \"Name\", p.`name` as Loan,\r\nl.id as \"Loan ID\", l.disbursedon_date as Disbursed, ifnull(cur.display_symbol, l.currency_code) as Currency,\r\nsum(r.principal_amount - ifnull(r.principal_completed_derived, 0)) as \"Principal Outstanding\",\r\nsum(r.interest_amount - ifnull(r.interest_completed_derived, 0)) as \"Interest Outstanding\",\r\nif(datediff(curdate(), min(duedate)) < 0, 0, datediff(curdate(), min(duedate))) as \"Days Overdue\", \r\nmin(installment) as \"First Overdue Installment\",\r\nmin(duedate) as \"First Overdue Installment Date\",\r\nsum(if(r.duedate <= curdate(), \r\n (r.principal_amount - ifnull(r.principal_completed_derived, 0))\r\n , 0)) as \"Principal Overdue\",\r\nsum(if(r.duedate <= curdate(), \r\n (r.interest_amount - ifnull(r.interest_completed_derived, 0))\r\n , 0)) as \"Interest Overdue\"\r\n\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\njoin m_loan l on l.client_id = c.id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_product_loan p on p.id = l.product_id\r\nleft join m_loan_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand l.loan_status_id = 300\r\ngroup by l.id) x\r\norder by x.hierarchy, x.Currency, x.`Name`, x.Loan, x.`Loan ID`',NULL,0,1),(35,'Portfolio at Risk','Table',NULL,'Loan Portfolio','select \r\nifnull(cur.display_symbol, l.currency_code) as Currency, \r\nsum(r.principal_amount - ifnull(r.principal_completed_derived, 0)) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (r.principal_amount - ifnull(r.principal_completed_derived, 0))\r\n , 0)) as \"Principal Overdue\",\r\n \r\n cast(round(\r\n (sum(if(r.duedate <= curdate(), \r\n (r.principal_amount - ifnull(r.principal_completed_derived, 0))\r\n , 0)) * 100) / \r\n sum(r.principal_amount - ifnull(r.principal_completed_derived, 0))\r\n , 2) as char)\r\n as \"Portfolio at Risk %\"\r\n \r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\njoin m_loan l on l.client_id = c.id\r\nleft join m_product_loan p on p.id = l.product_id\r\nleft join m_loan_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nleft join m_currency cur on cur.code = l.currency_code\r\n\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand l.loan_status_id = 300\r\ngroup by l.currency_code\r\norder by l.currency_code',NULL,0,1),(38,'Upcoming Repayments Summary - Month, Currency, Loan Risk','Table',NULL,'Loan Portfolio','SELECT DATE_FORMAT(r.duedate,\'%Y-%m\') \"Due Month\", ifnull(cur.display_symbol, l.currency_code) as Currency, \r\n\r\n(select\r\n if(if(datediff(curdate(), min(r.duedate)) < 0, 0, datediff(curdate(), min(r.duedate))) > 90, \"4 High\", \r\n if (if(datediff(curdate(), min(r.duedate)) < 0, 0, datediff(curdate(), min(r.duedate))) > 30, \"3 Medium\", \r\n if (if(datediff(curdate(), min(r.duedate)) < 0, 0, datediff(curdate(), min(r.duedate))) = 0, \r\n if (min(r.installment) = 1, \"Low\", \"1 Very Low\"),\r\n if (min(r.installment), \"3 Medium\", \"2 Low\")))) \r\nfrom m_loan lr\r\nleft join m_loan_repayment_schedule r on r.loan_id = lr.id\r\n and r.completed_derived is false\r\nwhere lr.id = l.id) as \"Loan Risk\",\r\n\r\nsum(r.principal_amount - ifnull(r.principal_completed_derived, 0)) as \"Principal Due\",\r\nsum(r.interest_amount - ifnull(r.interest_completed_derived, 0)) as \"Interest Due\",\r\n\r\n(sum(r.principal_amount - ifnull(r.principal_completed_derived, 0)) +\r\nsum(r.interest_amount - ifnull(r.interest_completed_derived, 0))) as \"Total Due\"\r\n\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\njoin m_loan l on l.client_id = c.id\r\njoin m_loan_repayment_schedule r on r.loan_id = l.id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\" )\r\nand l.loan_status_id = 300\r\nand r.duedate >= curdate()\r\ngroup by `Due Month`, `Currency`, `Loan Risk`\r\norder by `Due Month`, `Loan Risk`',NULL,0,1),(39,'Loan Disbursals in Previous Year','Chart','Bar','Loan Portfolio','select prevYr.startMonth as \"Disbursed Month\", ifnull(monthlyDisb.disbursed,0) as Disbursed\r\nfrom\r\n(SELECT DATE_FORMAT(@startDate := date_add(@startDate, interval 1 Month),\'%Y-%m\') as startMonth\r\nFROM rpt_sequence s, (SELECT @startDate := date_add(curdate(), interval -13 Month)) d\r\nWHERE s.id <= 13) prevYr\r\nleft join \r\n(select DATE_FORMAT(lt.transaction_date,\'%Y-%m\') as txnMonth, sum(lt.amount) as disbursed\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\njoin m_loan l on l.client_id = c.id\r\njoin m_loan_transaction lt on lt.loan_id = l.id\r\nwhere o.id = ${officeId}\r\nand l.currency_code = \"${currencyId}\"\r\nand lt.transaction_type_enum = 1\r\ngroup by `txnMonth`) monthlyDisb on monthlyDisb.txnMonth = prevYr.startMonth',NULL,0,1),(40,'Loan Repayments in Previous Year','Chart','Bar','Loan Portfolio','select prevYr.startMonth as \"Repayment Month\", ifnull(monthlyR.repaid,0) as Repaid\r\nfrom\r\n(SELECT DATE_FORMAT(@startDate := date_add(@startDate, interval 1 Month),\'%Y-%m\') as startMonth\r\nFROM rpt_sequence s, (SELECT @startDate := date_add(curdate(), interval -13 Month)) d\r\nWHERE s.id <= 13) prevYr\r\nleft join \r\n(select DATE_FORMAT(lt.transaction_date,\'%Y-%m\') as txnMonth, sum(lt.amount) as repaid\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\njoin m_loan l on l.client_id = c.id\r\njoin m_loan_transaction lt on lt.loan_id = l.id\r\nwhere o.id = ${officeId}\r\nand l.currency_code = \"${currencyId}\"\r\nand lt.transaction_type_enum = 2 and lt.contra_id is null\r\ngroup by `txnMonth`) monthlyR on monthlyR.txnMonth = prevYr.startMonth\r\norder by prevYr.startMonth',NULL,0,1),(41,'Clients by Surname (a bit silly)','Chart','Pie','Client','select c.lastname, count(*) as thecount\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\nwhere o.id = ${officeId}\r\nand c.is_deleted=0\r\ngroup by c.lastname',NULL,0,1),(42,'Client Listing - Additional and Unlikely','Table',NULL,'Client','select ounder.`name` as \"Office/Branch\", concat(c.lastname, if(c.firstname > \"\", concat(\", \", c.firstname), \"\")) as \"Name\", \r\na1.`Ethnic Group`, a1.`Ethnic Group Other`, a1.`Household Location`, a1. `Household Location Other`,\r\na1.Religion, a1.`Religion Other`, a1.`Knowledge of Person`, a1.Gender, a1.whois,\r\na2.`Fathers Favourite Team`, a2.`Mothers Favourite Team`, a2.`Fathers DOB`, a2.`Mothers DOB`,\r\na2.`Fathers Education`, a2.`Mothers Education`, a2.`Number of Children`,\r\na2.`Favourite Town`, a2.`Closing Comments`, a2.`Annual Family Income`\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\nleft join `m_client_xAdditional Information` a1 on a1.id = c.id\r\nleft join `m_client_xHighly Improbable Info` a2 on a2.id = c.id\r\nwhere o.id = ${officeId}\r\nand c.is_deleted=0\r\norder by ounder.hierarchy',NULL,0,1),(43,'Client Loans Listing - Additional','Table',NULL,'Client','select ounder.`name` as \"Office/Branch\", concat(c.lastname, if(c.firstname > \"\", concat(\", \", c.firstname), \"\")) as \"Name\",\r\np.name as Loan, st.enum_message_property as \"Status\", \r\nl.annual_nominal_interest_rate as \" Annual Nominal Interest Rate\", \r\nifnull(cur.display_symbol, l.currency_code) as Currency, l.principal_amount,\r\nl1.`Business Location`, l1.`Business Location Other`, l1.`Business` as \"Business Type\", \r\nl1.`Business Description`, l1.`Business Title`\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\nleft join m_loan l on l.client_id = c.id\r\nleft join `m_loan_xAdditional Information` l1 on l1.id = l.id\r\nleft join m_product_loan p on p.id = l.product_id\r\nleft join r_enum_value st on st.enum_name = \'loan_status_id\' and st.enum_id = l.loan_status_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nwhere o.id = ${officeId}\r\norder by ounder.hierarchy, \"Name\" , l.id',NULL,0,1),(44,'Client Listing (Pentaho)','Pentaho',NULL,'Client',NULL,'Just a sample Pentaho report. \r\nNot production quality',0,1),(45,'Funds Disbursed Summary - Currency','Table',NULL,'Fund','select ifnull(f.`name`, \'-\') as Fund, ifnull(cur.display_symbol, l.currency_code) as Currency, round(sum(l.principal_amount), 4) as disbursed_amount\r\nfrom m_office ounder \r\njoin m_client c on c.office_id = ounder.id\r\njoin m_loan l on l.client_id = c.id\r\njoin m_currency cur on cur.`code` = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nwhere disbursedon_date between \'${startDate}\' and \'${endDate}\'\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (l.currency_code = \'${currencyId}\' or \'-1\' = \'${currencyId}\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\ngroup by ifnull(f.`name`, \'-\') , ifnull(cur.display_symbol, l.currency_code)\r\norder by ifnull(f.`name`, \'-\') , ifnull(cur.display_symbol, l.currency_code)',NULL,0,1),(46,'Funds Disbursed Summary - Office, Currency','Table',NULL,'Fund','select ounder.`name` as \"Office/Branch\", ifnull(f.`name`, \'-\') as Fund, ifnull(cur.display_symbol, l.currency_code) as Currency, round(sum(l.principal_amount), 4) as disbursed_amount\r\nfrom m_office o\r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on c.office_id = ounder.id\r\njoin m_loan l on l.client_id = c.id\r\njoin m_currency cur on cur.`code` = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nwhere disbursedon_date between \'${startDate}\' and \'${endDate}\'\r\nand o.id = ${officeId}\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (l.currency_code = \'${currencyId}\' or \'-1\' = \'${currencyId}\')\r\ngroup by ounder.`name`, ifnull(f.`name`, \'-\') , ifnull(cur.display_symbol, l.currency_code)\r\norder by ounder.`name`, ifnull(f.`name`, \'-\') , ifnull(cur.display_symbol, l.currency_code)',NULL,0,1); -INSERT INTO `stretchy_report_parameter` VALUES (29,5,NULL),(30,5,NULL),(31,5,NULL),(32,5,NULL),(32,6,NULL),(34,5,NULL),(34,6,NULL),(35,5,NULL),(35,6,NULL),(38,5,NULL),(38,6,NULL),(39,5,NULL),(39,7,NULL),(40,5,NULL),(40,7,NULL),(41,5,NULL),(42,5,NULL),(43,5,NULL),(44,5,'officeId'),(45,6,NULL),(45,10,NULL),(45,80,NULL),(45,81,NULL),(46,5,NULL),(46,6,NULL),(46,10,NULL),(46,80,NULL),(46,81,NULL); - -INSERT INTO `stretchydata_datasettype` VALUES (1,'m_client'),(2,'m_loan'); -INSERT INTO `stretchydata_dataset` VALUES (1,'Additional Information',1),(9,'Highly Improbable Info',1),(8,'Additional Information',2); -INSERT INTO `stretchydata_dataset_fields` VALUES (2,'Business Location','String',50,'List',8,7),(3,'Business Location Other','String',50,NULL,8,NULL),(4,'Business','String',10,'List',8,1),(5,'Business Description','Text',NULL,NULL,8,NULL),(6,'Ethnic Group','String',50,'List',1,3),(7,'Ethnic Group Other','String',50,NULL,1,NULL),(8,'Household Location','String',50,'List',1,7),(9,'Household Location Other','String',50,NULL,1,NULL),(10,'Religion','String',50,'List',1,8),(11,'Religion Other','String',50,NULL,1,NULL),(12,'Knowledge of Person','String',50,'List',1,6),(13,'Gender','String',10,'List',1,5),(14,'Business Title','String',100,NULL,8,NULL),(15,'Whois','Text',NULL,NULL,1,NULL),(60,'Fathers Favourite Team','String',50,'List',9,4),(61,'Mothers Favourite Team','String',50,'List',9,4),(62,'Fathers DOB','Date',NULL,NULL,9,NULL),(63,'Mothers DOB','Date',NULL,NULL,9,NULL),(64,'Fathers Education','String',50,'List',9,2),(65,'Mothers Education','String',50,'List',9,2),(67,'Number of Children','Integer',NULL,NULL,9,NULL),(68,'Favourite Town','String',30,NULL,9,NULL),(69,'Closing Comments','Text',NULL,NULL,9,NULL),(70,'Annual Family Income','Decimal',NULL,NULL,9,NULL); - -INSERT INTO `rpt_sequence` (`id`) VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20),(21),(22),(23),(24),(25),(26),(27),(28),(29),(30),(31),(32),(33),(34),(35),(36),(37),(38),(39),(40),(41),(42),(43),(44),(45),(46),(47),(48),(49),(50),(51),(52),(53),(54),(55),(56),(57),(58),(59),(60),(61),(62),(63),(64),(65),(66),(67),(68),(69),(70),(71),(72),(73),(74),(75),(76),(77),(78),(79),(80),(81),(82),(83),(84),(85),(86),(87),(88),(89),(90),(91),(92),(93),(94),(95),(96),(97),(98),(99),(100),(101),(102),(103),(104),(105),(106),(107),(108),(109),(110),(111),(112),(113),(114),(115),(116),(117),(118),(119),(120),(121),(122),(123),(124),(125),(126),(127),(128),(129),(130),(131),(132),(133),(134),(135),(136),(137),(138),(139),(140),(141),(142),(143),(144),(145),(146),(147),(148),(149),(150),(151),(152),(153),(154),(155),(156),(157),(158),(159),(160),(161),(162),(163),(164),(165),(166),(167),(168),(169),(170),(171),(172),(173),(174),(175),(176),(177),(178),(179),(180),(181),(182),(183),(184),(185),(186),(187),(188),(189),(190),(191),(192),(193),(194),(195),(196),(197),(198),(199),(200),(201),(202),(203),(204),(205),(206),(207),(208),(209),(210),(211),(212),(213),(214),(215),(216),(217),(218),(219),(220),(221),(222),(223),(224),(225),(226),(227),(228),(229),(230),(231),(232),(233),(234),(235),(236),(237),(238),(239),(240),(241),(242),(243),(244),(245),(246),(247),(248),(249),(250),(251),(252),(253),(254),(255),(256),(257),(258),(259),(260),(261),(262),(263),(264),(265),(266),(267),(268),(269),(270),(271),(272),(273),(274),(275),(276),(277),(278),(279),(280),(281),(282),(283),(284),(285),(286),(287),(288),(289),(290),(291),(292),(293),(294),(295),(296),(297),(298),(299),(300),(301),(302),(303),(304),(305),(306),(307),(308),(309),(310),(311),(312),(313),(314),(315),(316),(317),(318),(319),(320),(321),(322),(323),(324),(325),(326),(327),(328),(329),(330),(331),(332),(333),(334),(335),(336),(337),(338),(339),(340),(341),(342),(343),(344),(345),(346),(347),(348),(349),(350),(351),(352),(353),(354),(355),(356),(357),(358),(359),(360),(361),(362),(363),(364),(365),(366),(367),(368),(369),(370),(371),(372),(373),(374),(375),(376),(377),(378),(379),(380),(381),(382),(383),(384),(385),(386),(387),(388),(389),(390),(391),(392),(393),(394),(395),(396),(397),(398),(399),(400),(401),(402),(403),(404),(405),(406),(407),(408),(409),(410),(411),(412),(413),(414),(415),(416),(417),(418),(419),(420),(421),(422),(423),(424),(425),(426),(427),(428),(429),(430),(431),(432),(433),(434),(435),(436),(437),(438),(439),(440),(441),(442),(443),(444),(445),(446),(447),(448),(449),(450),(451),(452),(453),(454),(455),(456),(457),(458),(459),(460),(461),(462),(463),(464),(465),(466),(467),(468),(469),(470),(471),(472),(473),(474),(475),(476),(477),(478),(479),(480),(481),(482); - - -insert into m_permission (group_enum, code, default_description, default_name) -select 3, concat("CAN_RUN_", report_name), concat("CAN_RUN_", report_name), concat("CAN_RUN_", report_name) -from stretchy_report r -where not exists -(select 'f' from m_permission x -where x.code = concat("CAN_RUN_", r.report_name)); - -insert into m_permission (group_enum, code, default_description, default_name) -select 3, concat("CAN_READ_", t.`name`, "_x", d.`name`), concat("CAN_READ_", t.`name`, "_x", d.`name`), concat("CAN_READ_", t.`name`, "_x", d.`name`) -from stretchydata_dataset d -join stretchydata_datasettype t on t.id = d.datasettype_id -where not exists -(select 'f' from m_permission x -where x.code = concat("CAN_READ_", t.`name`, "_x", d.`name`)); - -insert into m_permission (group_enum, code, default_description, default_name) -select 3, concat("CAN_UPDATE_", t.`name`, "_x", d.`name`), concat("CAN_UPDATE_", t.`name`, "_x", d.`name`), concat("CAN_UPDATE_", t.`name`, "_x", d.`name`) -from stretchydata_dataset d -join stretchydata_datasettype t on t.id = d.datasettype_id -where not exists -(select 'f' from m_permission x -where x.code = concat("CAN_UPDATE_", t.`name`, "_x", d.`name`)); - - - - - --- insert office data required by appuser table/data -INSERT INTO `m_office` (`id`, `parent_id`, `hierarchy`, `external_id`, `name`, `opening_date`, `createdby_id`, `created_date`, `lastmodified_date`, `lastmodifiedby_id`) -VALUES -(2,1,'.2.','2','sub branch 1','2012-01-02',1,'2012-04-14 05:42:40','2012-04-16 11:47:05',1), -(3,1,'.3.','3','sub branch 2','2012-03-01',1,'2012-04-16 04:12:02','2012-04-16 11:47:14',1), -(4,1,'.4.',NULL,'sub branch 3','2012-04-17',1,'2012-04-17 06:01:10','2012-04-17 06:01:10',1); - - --- insert remaining fund/currencies/product data - -INSERT INTO `m_organisation_currency` (`id`, `code`, `decimal_places`, `name`, `display_symbol`, `internationalized_name_code`, `createdby_id`, `created_date`, `lastmodified_date`, `lastmodifiedby_id`) -VALUES -(17,'KES',2,'Kenyan Shilling','KSh','currency.KES',1,'2012-05-01 22:43:02','2012-05-01 22:43:02',1), -(18,'BND',2,'Brunei Dollar','BND','currency.BND',1,'2012-05-01 22:43:02','2012-05-01 22:43:02',1), -(19,'LBP',2,'Lebanese Pound','L','currency.LBP',1,'2012-05-01 22:43:02','2012-05-01 22:43:02',1), -(20,'GHC',2,'Ghana Cedi','GHC','currency.GHC',1,'2012-05-01 22:43:02','2012-05-01 22:43:02',1), -(22,'XOF',0,'CFA Franc BCEAO','CFA','currency.XOF',1,'2012-05-01 22:43:02','2012-05-01 22:43:02',1); - - -INSERT INTO `m_product_loan` (`id`, `currency_code`, `currency_digits`, `principal_amount`, `arrearstolerance_amount`, `name`, `description`, `nominal_interest_rate_per_period`, `interest_period_frequency_enum`, `annual_nominal_interest_rate`, `interest_method_enum`, `repay_every`, `repayment_period_frequency_enum`, `number_of_repayments`, `amortization_method_enum`, `flexible_repayment_schedule`, `interest_rebate`, `createdby_id`, `created_date`, `lastmodified_date`, `lastmodifiedby_id`, `interest_calculated_in_period_enum`, `fund_id`) -VALUES -(1,'XOF',0,'100000.000000','1000.000000','Agricultural Loan','An agricultural loan given to farmers to help buy crop, stock and machinery. With an arrears tolerance setting of 1,000 CFA, loans are not marked as \'in arrears\' or \'in bad standing\' if the amount outstanding is less than this. Interest rate is described using monthly percentage rate (MPR) even though the loan typically lasts a year and requires one repayment (typically at time when farmer sells crop)','1.750000',2,'21.000000',0,12,2,1,1,'\0','\0',1,'2012-04-12 22:14:34','2012-04-12 22:14:34',1,1,NULL); - - - --- inserting client - -INSERT INTO `m_client` (`id`, `office_id`, `external_id`, `firstname`, `lastname`, `joining_date`, `createdby_id`, `created_date`, `lastmodified_date`, `lastmodifiedby_id`) -VALUES -(1,1,NULL,'Willie','O\'Meara','2009-01-04',1,'2012-04-12 22:07:44','2012-04-12 22:07:44',1), -(2,1,NULL,'Declan','Browne','2009-01-04',1,'2012-04-12 22:15:39','2012-04-12 22:15:39',1), -(3,1,NULL,'Ja','Fallon','2009-01-11',1,'2012-04-12 22:16:30','2012-04-12 22:16:30',1), -(4,1,NULL,'Peter','Lambert','2009-01-11',1,'2012-04-12 22:17:01','2012-04-12 22:17:01',1), -(5,1,NULL,NULL,'Sunnyville vegetable growers Ltd','2009-01-24',1,'2012-04-12 22:19:18','2012-04-12 22:19:18',1), -(6,2,NULL,'Jacques','Lee','2012-04-03',1,'2012-04-14 06:09:22','2012-04-14 06:09:22',1), -(7,1,NULL,'Kalilou','Traor','2009-02-04',1,'2012-04-14 09:38:11','2012-04-14 09:38:11',1), -(8,1,NULL,'Sidi','Kon','2009-02-11',1,'2012-04-14 09:45:43','2012-04-14 09:45:43',1), -(9,1,NULL,'Moustapha','Yattabar','2009-02-18',1,'2012-04-14 10:24:20','2012-04-14 10:24:20',1), -(10,1,NULL,NULL,'Mali fruit sales ltd.','2009-02-18',1,'2012-04-14 10:25:37','2012-04-14 10:25:37',1), -(11,1,NULL,NULL,'Djenne co-op group','2009-02-25',1,'2012-04-14 10:31:03','2012-04-14 10:31:03',1); - - - -update m_client set display_name = concat_ws(' ',firstname,lastname); - diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/makerchecker/domain/CommandSource.java b/mifosng-provider/src/main/java/org/mifosng/platform/makerchecker/domain/CommandSource.java index 05faf1c0b..f63e13366 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/makerchecker/domain/CommandSource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/makerchecker/domain/CommandSource.java @@ -86,6 +86,10 @@ public class CommandSource extends AbstractPersistable { this.checkedOnDate = checkedOnDate.toDate(); } + public void updateResourceId(final Long resourceId) { + this.resourceId = resourceId; + } + public Long resourceId() { return this.resourceId; } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/makerchecker/service/PortfolioCommandSourceWriteServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/makerchecker/service/PortfolioCommandSourceWriteServiceImpl.java index 664e51c6a..51b81ad48 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/makerchecker/service/PortfolioCommandSourceWriteServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/makerchecker/service/PortfolioCommandSourceWriteServiceImpl.java @@ -53,6 +53,7 @@ public class PortfolioCommandSourceWriteServiceImpl implements PortfolioCommandS try { resourceId = this.clientWritePlatformService.createClient(command); entity.markAsChecked(maker, asToday); + entity.updateResourceId(resourceId); } catch (RollbackTransactionAsCommandIsNotApprovedByCheckerException e) { // swallow this rollback transaction by design } @@ -103,6 +104,8 @@ public class PortfolioCommandSourceWriteServiceImpl implements PortfolioCommandS } } + entity.updateResourceId(resourceId); + commandSourceRepository.save(entity); return EntityIdentifier.makerChecker(resourceId, entity.getId());