diff --git a/mifosng-db/migrations/V1__mifosplatform-core-ddl-latest.sql b/mifosng-db/migrations/V1__mifosplatform-core-ddl-latest.sql new file mode 100644 index 000000000..54a24d01b --- /dev/null +++ b/mifosng-db/migrations/V1__mifosplatform-core-ddl-latest.sql @@ -0,0 +1,943 @@ +-- drop tables in base-schema +SET foreign_key_checks = 0; + +-- drop accounting subsystem +DROP TABLE IF EXISTS `acc_gl_account`; +DROP TABLE IF EXISTS `acc_gl_closure`; +DROP TABLE IF EXISTS `acc_gl_journal_entry`; +DROP TABLE IF EXISTS `acc_product_mapping`; + +-- drop portfolio subsystem +DROP TABLE IF EXISTS `c_configuration`; +DROP TABLE IF EXISTS `m_appuser`; +DROP TABLE IF EXISTS `m_appuser_role`; +DROP TABLE IF EXISTS `m_calendar`; +DROP TABLE IF EXISTS `m_calendar_instance`; +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 `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_level`; +DROP TABLE IF EXISTS `m_group_client`; +DROP TABLE IF EXISTS `m_guarantor`; +DROP TABLE IF EXISTS `m_loan`; +DROP TABLE IF EXISTS `m_loan_charge`; +DROP TABLE IF EXISTS `m_loan_arrears_aging`; +DROP TABLE IF EXISTS `m_loan_collateral`; +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_role`; +DROP TABLE IF EXISTS `m_role_permission`; +DROP TABLE IF EXISTS `m_savings_account`; +DROP TABLE IF EXISTS `m_savings_account_transaction`; +DROP TABLE IF EXISTS `m_savings_product`; +DROP TABLE IF EXISTS `m_staff`; +DROP TABLE IF EXISTS `ref_loan_transaction_processing_strategy`; +DROP TABLE IF EXISTS `x_registered_table`; + +-- 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`; + +SET foreign_key_checks = 1; + +-- DDL for reference/lookup tables +CREATE TABLE `m_currency` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `code` varchar(3) NOT NULL, + `decimal_places` smallint(5) NOT NULL, + `display_symbol` varchar(10) DEFAULT NULL, + `name` varchar(50) NOT NULL, + `internationalized_name_code` varchar(50) NOT NULL, + PRIMARY KEY (`id`), + 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, + 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, + `name` varchar(255) 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 `ltp_strategy_code` (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `c_configuration` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + `enabled` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_code` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `code_name` varchar(100) DEFAULT NULL, + `is_system_defined` TINYINT(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `code_name` (`code_name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_code_value` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `code_id` int(11) NOT NULL, + `code_value` varchar(100) DEFAULT NULL, + `order_position` int(11) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + 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', + 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(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`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +/* used to link MySql tables to Mifos X application tables for additional data needs */ +CREATE TABLE `x_registered_table` ( + `registered_table_name` varchar(50) NOT NULL, + `application_table_name` varchar(50) NOT NULL, + PRIMARY KEY (`registered_table_name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `m_calendar` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `title` varchar(50) NOT NULL, + `description` varchar(100) DEFAULT NULL, + `location` varchar(50) DEFAULT NULL, + `start_date` date NOT NULL, + `end_date` date DEFAULT NULL, + `duration` smallint(6) DEFAULT NULL, + `calendar_type_enum` smallint(5) NOT NULL, + `repeating` tinyint(1) NOT NULL DEFAULT '0', + `recurrence` varchar(100) DEFAULT NULL, + `remind_by_enum` smallint(5) DEFAULT NULL, + `first_reminder` smallint(11) DEFAULT NULL, + `second_reminder` smallint(11) 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`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `m_calendar_instance` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `calendar_id` bigint(20) NOT NULL, + `entity_id` bigint(20) NOT NULL, + `entity_type_enum` smallint(5) NOT NULL, + PRIMARY KEY (`id`), + KEY `FK_m_calendar_m_calendar_instance` (`calendar_id`), + CONSTRAINT `FK_m_calendar_m_calendar_instance` FOREIGN KEY (`calendar_id`) REFERENCES `m_calendar` (`id`) +) 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, + `hierarchy` varchar(100) DEFAULT NULL, + `external_id` varchar(100) DEFAULT NULL, + `name` varchar(50) NOT NULL, + `opening_date` date NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `name_org` (`name`), + UNIQUE KEY `externalid_org` (`external_id`), + KEY `FK2291C477E2551DCC` (`parent_id`), + CONSTRAINT `FK2291C477E2551DCC` FOREIGN KEY (`parent_id`) REFERENCES `m_office` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_office_transaction` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `from_office_id` bigint(20) DEFAULT NULL, + `to_office_id` bigint(20) DEFAULT NULL, + `currency_code` varchar(3) NOT NULL, + `currency_digits` int(11) NOT NULL, + `transaction_amount` decimal(19,6) NOT NULL, + `transaction_date` date NOT NULL, + `description` varchar(100) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `FK1E37728B93C6C1B6` (`to_office_id`), + KEY `FK1E37728B783C5C25` (`from_office_id`), + CONSTRAINT `FK1E37728B783C5C25` FOREIGN KEY (`from_office_id`) REFERENCES `m_office` (`id`), + CONSTRAINT `FK1E37728B93C6C1B6` FOREIGN KEY (`to_office_id`) REFERENCES `m_office` (`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, + `grouping` varchar(45) DEFAULT NULL, + `code` varchar(100) NOT NULL, + `entity_name` varchar(100) DEFAULT NULL, + `action_name` varchar(100) DEFAULT NULL, + `can_maker_checker` tinyint(1) NOT NULL DEFAULT '1', + PRIMARY KEY (`id`), + UNIQUE KEY `code` (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_role` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL, + `description` varchar(500) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unq_name` (`name`) +) 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) NOT NULL DEFAULT '0', + `office_id` bigint(20) DEFAULT NULL, + `username` varchar(100) NOT NULL, + `firstname` varchar(100) NOT NULL, + `lastname` varchar(100) NOT NULL, + `password` varchar(255) NOT NULL, + `email` varchar(100) NOT NULL, + `firsttime_login_remaining` bit(1) NOT NULL, + `nonexpired` bit(1) NOT NULL, + `nonlocked` bit(1) NOT NULL, + `nonexpired_credentials` bit(1) NOT NULL, + `enabled` bit(1) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `username_org` (`username`), + KEY `FKB3D587CE0DD567A` (`office_id`), + CONSTRAINT `FKB3D587CE0DD567A` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_appuser_role` ( + `appuser_id` bigint(20) NOT NULL, + `role_id` bigint(20) NOT NULL, + PRIMARY KEY (`appuser_id`,`role_id`), + KEY `FK7662CE59B4100309` (`appuser_id`), + KEY `FK7662CE5915CEC7AB` (`role_id`), + CONSTRAINT `FK7662CE5915CEC7AB` FOREIGN KEY (`role_id`) REFERENCES `m_role` (`id`), + CONSTRAINT `FK7662CE59B4100309` FOREIGN KEY (`appuser_id`) REFERENCES `m_appuser` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- ================ end of user admin tables =============== + +-- DDL for organisation wide related concepts +CREATE TABLE `m_portfolio_command_source` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `action_name` varchar(50) NOT NULL, + `entity_name` varchar(50) NOT NULL, + `office_id` bigint(20) DEFAULT NULL, + `group_id` bigint(20) DEFAULT NULL, + `client_id` bigint(20) DEFAULT NULL, + `loan_id` bigint(20) DEFAULT NULL, + `savings_account_id` bigint(20) DEFAULT NULL, + `api_get_url` varchar(100) NOT NULL, + `resource_id` bigint(20) DEFAULT NULL, + `subresource_id` bigint(20) DEFAULT NULL, + `command_as_json` text NOT NULL, + `maker_id` bigint(20) NOT NULL, + `made_on_date` datetime NOT NULL, + `checker_id` bigint(20) DEFAULT NULL, + `checked_on_date` datetime DEFAULT NULL, + `processing_result_enum` smallint(5) NOT NULL, + PRIMARY KEY (`id`), + KEY `FK_m_maker_m_appuser` (`maker_id`), + KEY `FK_m_checker_m_appuser` (`checker_id`), + KEY `action_name` (`action_name`), + KEY `entity_name` (`entity_name`,`resource_id`), + KEY `made_on_date` (`made_on_date`), + KEY `checked_on_date` (`checked_on_date`), + KEY `processing_result_enum` (`processing_result_enum`), + KEY `office_id` (`office_id`), + KEY `group_id` (`office_id`), + KEY `client_id` (`office_id`), + KEY `loan_id` (`office_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', + 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, + 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, + 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_level` ( +`id` INT(11) NOT NULL AUTO_INCREMENT, +`parent_id` INT(11) NULL DEFAULT NULL, +`super_parent` TINYINT(1) NOT NULL, +`level_name` VARCHAR(100) NOT NULL, +`recursable` TINYINT(1) NOT NULL, +`can_have_clients` TINYINT(1) NOT NULL, +PRIMARY KEY (`id`), +INDEX `Parent_levelId_reference` (`parent_id`), +CONSTRAINT `Parent_levelId_reference` FOREIGN KEY (`parent_id`) REFERENCES `m_group_level` (`id`) +)ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_group` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `office_id` bigint(20) NOT NULL, + `staff_id` BIGINT(20) DEFAULT NULL, + `parent_id` BIGINT(20) NULL DEFAULT NULL, + `level_Id` INT(11) NOT NULL, + `hierarchy` VARCHAR(100) NULL DEFAULT NULL, + `name` varchar(100) NOT NULL, + `external_id` varchar(100) DEFAULT NULL, + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`, `level_id`), + UNIQUE KEY `external_id` (`external_id`, `level_Id`), + KEY `office_id` (`office_id`), + KEY `staff_id` (`staff_id`), + CONSTRAINT `m_group_ibfk_1` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`), + CONSTRAINT `Parent_Id_reference` FOREIGN KEY (`parent_id`) REFERENCES `m_group` (`id`), + CONSTRAINT `FK_m_group_level` FOREIGN KEY (`level_Id`) REFERENCES `m_group_level` (`id`), + CONSTRAINT `FK_m_group_m_staff` FOREIGN KEY (`staff_id`) REFERENCES `m_staff` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_client` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `account_no` varchar(20) NOT NULL, + `office_id` bigint(20) NOT NULL, + `external_id` varchar(100) DEFAULT NULL, + `firstname` varchar(50) DEFAULT NULL, + `middlename` varchar(50) DEFAULT NULL, + `lastname` varchar(50) DEFAULT NULL, + `fullname` varchar(100) DEFAULT NULL, + `display_name` varchar(100) NOT NULL, + `image_key` varchar(500) DEFAULT NULL, + `joined_date` date DEFAULT NULL, + `is_deleted` tinyint(1) NOT NULL DEFAULT '0', + PRIMARY KEY (`id`), + UNIQUE KEY `account_no_UNIQUE` (`account_no`), + UNIQUE KEY `external_id` (`external_id`), + KEY `FKCE00CAB3E0DD567A` (`office_id`), + 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, + PRIMARY KEY (`group_id`,`client_id`), + KEY `client_id` (`client_id`), + CONSTRAINT `m_group_client_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `m_group` (`id`), + 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 loan and loan related tables +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) DEFAULT NULL, + `name` varchar(100) NOT NULL, + `description` varchar(500) DEFAULT NULL, + `fund_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, + `interest_method_enum` smallint(5) NOT NULL, + `interest_calculated_in_period_enum` smallint(5) NOT NULL DEFAULT '1', + `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, + `accounting_type` smallint(5) NOT NULL, + `loan_transaction_strategy_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `unq_name` (`name`), + KEY `FKA6A8A7D77240145` (`fund_id`), + KEY `FK_ltp_strategy` (`loan_transaction_strategy_id`), + CONSTRAINT `FKA6A8A7D77240145` FOREIGN KEY (`fund_id`) REFERENCES `m_fund` (`id`), + CONSTRAINT `FK_ltp_strategy` FOREIGN KEY (`loan_transaction_strategy_id`) REFERENCES `ref_loan_transaction_processing_strategy` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_product_loan_charge` ( + `product_loan_id` bigint(20) NOT NULL, + `charge_id` bigint(20) NOT NULL, + PRIMARY KEY (`product_loan_id`,`charge_id`), + KEY `charge_id` (`charge_id`), + CONSTRAINT `m_product_loan_charge_ibfk_1` FOREIGN KEY (`charge_id`) REFERENCES `m_charge` (`id`), + CONSTRAINT `m_product_loan_charge_ibfk_2` FOREIGN KEY (`product_loan_id`) REFERENCES `m_product_loan` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_loan` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `account_no` varchar(20) NOT NULL, + `external_id` varchar(100) DEFAULT 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_officer_id` bigint(20) DEFAULT NULL, + `loanpurpose_cv_id` int(11) DEFAULT NULL, + `loan_status_id` smallint(5) NOT NULL, + `currency_code` varchar(3) NOT NULL, + `currency_digits` smallint(5) NOT NULL, + `principal_amount` decimal(19,6) NOT NULL, + `arrearstolerance_amount` decimal(19,6) 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, + `interest_method_enum` smallint(5) NOT NULL, + `interest_calculated_in_period_enum` smallint(5) NOT NULL DEFAULT '1', + `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, + `submittedon_date` date DEFAULT NULL, + `submittedon_userid` bigint(20) DEFAULT NULL, + `approvedon_date` date DEFAULT NULL, + `approvedon_userid` bigint(20) DEFAULT NULL, + `expected_disbursedon_date` date DEFAULT NULL, + `expected_firstrepaymenton_date` date DEFAULT NULL, + `interest_calculated_from_date` date DEFAULT NULL, + `disbursedon_date` date DEFAULT NULL, + `disbursedon_userid` bigint(20) DEFAULT NULL, + `expected_maturedon_date` date DEFAULT NULL, + `maturedon_date` date DEFAULT NULL, + `closedon_date` date DEFAULT NULL, + `closedon_userid` bigint(20) DEFAULT NULL, + `total_charges_due_at_disbursement_derived` decimal(19,6) DEFAULT NULL, + `principal_disbursed_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `principal_repaid_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `principal_writtenoff_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `principal_outstanding_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `interest_charged_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `interest_repaid_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `interest_waived_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `interest_writtenoff_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `interest_outstanding_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `fee_charges_charged_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `fee_charges_repaid_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `fee_charges_waived_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `fee_charges_writtenoff_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `fee_charges_outstanding_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `penalty_charges_charged_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `penalty_charges_repaid_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `penalty_charges_waived_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `penalty_charges_writtenoff_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `penalty_charges_outstanding_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `total_expected_repayment_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `total_repayment_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `total_expected_costofloan_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `total_costofloan_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `total_waived_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `total_writtenoff_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `total_outstanding_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `rejectedon_date` date DEFAULT NULL, + `rejectedon_userid` bigint(20) DEFAULT NULL, + `rescheduledon_date` date DEFAULT NULL, + `withdrawnon_date` date DEFAULT NULL, + `withdrawnon_userid` bigint(20) DEFAULT NULL, + `writtenoffon_date` date DEFAULT NULL, + `loan_transaction_strategy_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `loan_account_no_UNIQUE` (`account_no`), + UNIQUE KEY `loan_externalid_UNIQUE` (`external_id`), + KEY `FKB6F935D87179A0CB` (`client_id`), + KEY `FKB6F935D8C8D4B434` (`product_id`), + KEY `FK7C885877240145` (`fund_id`), + KEY `FK_loan_ltp_strategy` (`loan_transaction_strategy_id`), + KEY `FK_m_loan_m_staff` (`loan_officer_id`), + KEY `group_id` (`group_id`), + KEY `FK_m_loanpurpose_codevalue` (`loanpurpose_cv_id`), + KEY `FK_submittedon_userid` (`submittedon_userid`), + KEY `FK_approvedon_userid` (`approvedon_userid`), + KEY `FK_rejectedon_userid` (`rejectedon_userid`), + KEY `FK_withdrawnon_userid` (`withdrawnon_userid`), + KEY `FK_disbursedon_userid` (`disbursedon_userid`), + KEY `FK_closedon_userid` (`closedon_userid`), + 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 `FK_approvedon_userid` FOREIGN KEY (`approvedon_userid`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_closedon_userid` FOREIGN KEY (`closedon_userid`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_disbursedon_userid` FOREIGN KEY (`disbursedon_userid`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_loan_ltp_strategy` FOREIGN KEY (`loan_transaction_strategy_id`) REFERENCES `ref_loan_transaction_processing_strategy` (`id`), + CONSTRAINT `FK_m_loanpurpose_codevalue` FOREIGN KEY (`loanpurpose_cv_id`) REFERENCES `m_code_value` (`id`), + CONSTRAINT `FK_m_loan_m_staff` FOREIGN KEY (`loan_officer_id`) REFERENCES `m_staff` (`id`), + CONSTRAINT `FK_rejectedon_userid` FOREIGN KEY (`rejectedon_userid`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_submittedon_userid` FOREIGN KEY (`submittedon_userid`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_withdrawnon_userid` FOREIGN KEY (`withdrawnon_userid`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `m_loan_ibfk_1` FOREIGN KEY (`group_id`) REFERENCES `m_group` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_loan_arrears_aging` ( + `loan_id` bigint(20) NOT NULL AUTO_INCREMENT, + `principal_overdue_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `interest_overdue_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `fee_charges_overdue_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `penalty_charges_overdue_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `total_overdue_derived` decimal(19,6) NOT NULL DEFAULT '0.000000', + `overdue_since_date_derived` date DEFAULT NULL, + PRIMARY KEY (`loan_id`), + CONSTRAINT `m_loan_arrears_aging_ibfk_1` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_guarantor` ( + `id` BIGINT(20) NOT NULL AUTO_INCREMENT, + `loan_id` BIGINT(20) NOT NULL, + `type_enum` SMALLINT(5) NOT NULL, + `entity_id` BIGINT(20) NULL DEFAULT NULL, + `firstname` VARCHAR(50) NULL DEFAULT NULL, + `lastname` VARCHAR(50) NULL DEFAULT NULL, + `dob` DATE NULL DEFAULT NULL, + `address_line_1` VARCHAR(500) NULL DEFAULT NULL, + `address_line_2` VARCHAR(500) NULL DEFAULT NULL, + `city` VARCHAR(50) NULL DEFAULT NULL, + `state` VARCHAR(50) NULL DEFAULT NULL, + `country` VARCHAR(50) NULL DEFAULT NULL, + `zip` VARCHAR(20) NULL DEFAULT NULL, + `house_phone_number` VARCHAR(20) NULL DEFAULT NULL, + `mobile_number` VARCHAR(20) NULL DEFAULT NULL, + `comment` VARCHAR(500) NULL DEFAULT NULL, + PRIMARY KEY (`id`), + INDEX `FK_m_guarantor_m_loan` (`loan_id`), + CONSTRAINT `FK_m_guarantor_m_loan` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`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, + `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', + `waived` 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_collateral` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `loan_id` bigint(20) NOT NULL, + `type_cv_id` int(11) NOT NULL, + `description` varchar(500) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `FK_collateral_m_loan` (`loan_id`), + KEY `FK_collateral_code_value` (`type_cv_id`), + CONSTRAINT `FK_collateral_m_loan` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`), + CONSTRAINT `FK_collateral_code_value` FOREIGN KEY (`type_cv_id`) REFERENCES `m_code_value` (`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, + `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_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`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_loan_transaction` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `loan_id` bigint(20) NOT NULL, + `is_reversed` TINYINT(1) NOT NULL, + `transaction_type_enum` smallint(5) NOT NULL, + `transaction_date` date NOT NULL, + `amount` decimal(19,6) NOT 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`), + CONSTRAINT `FKCFCEA42640BE0710` FOREIGN KEY (`loan_id`) REFERENCES `m_loan` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- ======== end of loan related tables ========== + +CREATE TABLE `m_savings_product` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL, + `description` varchar(500) NOT NULL, + `currency_code` varchar(3) NOT NULL, + `currency_digits` smallint(5) NOT NULL, + `nominal_interest_rate_per_period` decimal(19,6) NOT NULL, + `nominal_interest_rate_period_frequency_enum` smallint(5) NOT NULL, + `interest_period_enum` SMALLINT(5) NOT NULL, + `interest_calculation_type_enum` SMALLINT(5) NOT NULL, + `interest_calculation_days_in_year_type_enum` SMALLINT(5) NOT NULL, + `min_required_opening_balance` decimal(19,6) DEFAULT NULL, + `lockin_period_frequency` decimal(19,6) DEFAULT NULL, + `lockin_period_frequency_enum` smallint(5) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `sp_unq_name` (`name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_savings_account` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `account_no` varchar(20) NOT NULL, + `external_id` varchar(100) DEFAULT NULL, + `client_id` bigint(20) DEFAULT NULL, + `group_id` bigint(20) DEFAULT NULL, + `product_id` bigint(20) DEFAULT NULL, + `status_enum` SMALLINT(5) NOT NULL DEFAULT 300, + `activation_date` DATE DEFAULT NULL, + `currency_code` varchar(3) NOT NULL, + `currency_digits` smallint(5) NOT NULL, + `nominal_interest_rate_per_period` decimal(19,6) NOT NULL, + `nominal_interest_rate_period_frequency_enum` smallint(5) NOT NULL, + `annual_nominal_interest_rate` decimal(19,6) NOT NULL, + `interest_period_enum` SMALLINT(5) NOT NULL, + `interest_calculation_type_enum` SMALLINT(5) NOT NULL, + `interest_calculation_days_in_year_type_enum` SMALLINT(5) NOT NULL, + `min_required_opening_balance` decimal(19,6) DEFAULT NULL, + `lockin_period_frequency` decimal(19,6) DEFAULT NULL, + `lockin_period_frequency_enum` smallint(5) DEFAULT NULL, + `lockedin_until_date_derived` DATE DEFAULT NULL, + `total_deposits_derived` decimal(19,6) DEFAULT NULL, + `total_withdrawals_derived` decimal(19,6) DEFAULT NULL, + `total_interest_earned_derived` decimal(19,6) DEFAULT NULL, + `total_interest_posted_derived` decimal(19,6) DEFAULT NULL, + `account_balance_derived` decimal(19,6) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + UNIQUE KEY `sa_account_no_UNIQUE` (`account_no`), + UNIQUE KEY `sa_externalid_UNIQUE` (`external_id`), + KEY `FKSA00000000000001` (`client_id`), + KEY `FKSA00000000000002` (`group_id`), + KEY `FKSA00000000000003` (`product_id`), + CONSTRAINT `FKSA00000000000001` FOREIGN KEY (`client_id`) REFERENCES `m_client` (`id`), + CONSTRAINT `FKSA00000000000002` FOREIGN KEY (`group_id`) REFERENCES `m_group` (`id`), + CONSTRAINT `FKSA00000000000003` FOREIGN KEY (`product_id`) REFERENCES `m_savings_product` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `m_savings_account_transaction` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `savings_account_id` bigint(20) NOT NULL, + `transaction_type_enum` smallint(5) NOT NULL, + `transaction_date` date NOT NULL, + `amount` decimal(19,6) NOT NULL, + `is_reversed` tinyint(1) NOT NULL, + `running_balance_derived` DECIMAL(19,6) NULL, + `balance_number_of_days_derived` INT NULL, + `balance_end_date_derived` DATE NULL, + `cumulative_balance_derived` DECIMAL(19,6) NULL, + PRIMARY KEY (`id`), + KEY `FKSAT0000000001` (`savings_account_id`), + CONSTRAINT `FKSAT0000000001` FOREIGN KEY (`savings_account_id`) REFERENCES `m_savings_account` (`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) DEFAULT NULL, + `group_id` bigint(20) DEFAULT NULL, + `loan_id` bigint(20) DEFAULT NULL, + `loan_transaction_id` bigint(20) DEFAULT NULL, + `note_type_enum` smallint(5) NOT NULL, + `note` varchar(1000) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `createdby_id` bigint(20) DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `FK7C9708924D26803` (`loan_transaction_id`), + KEY `FK7C97089541F0A56` (`createdby_id`), + KEY `FK7C970897179A0CB` (`client_id`), + KEY `FK_m_note_m_group` (`group_id`), + KEY `FK7C970898F889C3F` (`lastmodifiedby_id`), + KEY `FK7C9708940BE0710` (`loan_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 `FK_m_note_m_group` FOREIGN KEY (`group_id`) REFERENCES `m_group` (`id`), + CONSTRAINT `FK7C970898F889C3F` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- DDL for accounting sub system related tables +CREATE TABLE `acc_gl_account` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `parent_id` bigint(20) DEFAULT NULL, + `gl_code` varchar(45) NOT NULL, + `disabled` tinyint(1) NOT NULL DEFAULT '0', + `manual_journal_entries_allowed` tinyint(1) NOT NULL DEFAULT '1', + `account_usage` tinyint(1) NOT NULL DEFAULT '2', + `classification_enum` smallint(5) NOT NULL, + `description` varchar(500) DEFAULT 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 `acc_gl_account` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `acc_gl_closure` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `office_id` bigint(20) NOT NULL, + `closing_date` date NOT NULL, + `is_deleted` int(20) NOT NULL DEFAULT '0', + `createdby_id` bigint(20) DEFAULT NULL, + `lastmodifiedby_id` bigint(20) DEFAULT NULL, + `created_date` datetime DEFAULT NULL, + `lastmodified_date` datetime DEFAULT NULL, + `comments` varchar(500) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `office_id_closing_date` (`office_id`,`closing_date`), + KEY `FK_acc_gl_closure_m_office` (`office_id`), + KEY `FK_acc_gl_closure_m_appuser` (`createdby_id`), + KEY `FK_acc_gl_closure_m_appuser_2` (`lastmodifiedby_id`), + CONSTRAINT `FK_acc_gl_closure_m_appuser` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_acc_gl_closure_m_appuser_2` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_acc_gl_closure_m_office` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `acc_gl_journal_entry` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `account_id` bigint(20) NOT NULL, + `office_id` bigint(20) NOT NULL, + `reversal_id` bigint(20) DEFAULT NULL, + `transaction_id` varchar(50) NOT NULL, + `reversed` tinyint(1) NOT NULL DEFAULT '0', + `manual_entry` TINYINT(1) NOT NULL DEFAULT '0', + `entry_date` date NOT NULL, + `type_enum` smallint(5) NOT NULL, + `amount` decimal(19,6) NOT NULL, + `description` varchar(500) DEFAULT NULL, + `entity_type_enum` smallint(5) DEFAULT NULL, + `entity_id` bigint(20) DEFAULT NULL, + `createdby_id` bigint(20) NOT NULL, + `lastmodifiedby_id` bigint(20) NOT NULL, + `created_date` datetime NOT NULL, + `lastmodified_date` datetime NOT NULL, + PRIMARY KEY (`id`), + KEY `FK_acc_gl_journal_entry_m_office` (`office_id`), + KEY `FK_acc_gl_journal_entry_m_appuser` (`createdby_id`), + KEY `FK_acc_gl_journal_entry_m_appuser_2` (`lastmodifiedby_id`), + KEY `FK_acc_gl_journal_entry_acc_gl_journal_entry` (`reversal_id`), + KEY `FK_acc_gl_journal_entry_acc_gl_account` (`account_id`), + CONSTRAINT `FK_acc_gl_journal_entry_acc_gl_account` FOREIGN KEY (`account_id`) REFERENCES `acc_gl_account` (`id`), + CONSTRAINT `FK_acc_gl_journal_entry_acc_gl_journal_entry` FOREIGN KEY (`reversal_id`) REFERENCES `acc_gl_journal_entry` (`id`), + CONSTRAINT `FK_acc_gl_journal_entry_m_appuser` FOREIGN KEY (`createdby_id`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_acc_gl_journal_entry_m_appuser_2` FOREIGN KEY (`lastmodifiedby_id`) REFERENCES `m_appuser` (`id`), + CONSTRAINT `FK_acc_gl_journal_entry_m_office` FOREIGN KEY (`office_id`) REFERENCES `m_office` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `acc_product_mapping` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `gl_account_id` bigint(20) DEFAULT NULL, + `product_id` bigint(20) DEFAULT NULL, + `product_type` smallint(5) DEFAULT NULL, + `financial_account_type` smallint(5) DEFAULT NULL, + PRIMARY KEY (`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 `stretchy_parameter` ( + `parameter_id` int(11) NOT NULL AUTO_INCREMENT, + `parameter_name` varchar(45) NOT NULL, + `parameter_variable` varchar(45) DEFAULT NULL, + `parameter_label` varchar(45) NOT NULL, + `parameter_displayType` varchar(45) NOT NULL, + `parameter_FormatType` varchar(10) NOT NULL, + `parameter_default` varchar(45) NOT NULL, + `special` varchar(1) DEFAULT NULL, + `selectOne` varchar(1) DEFAULT NULL, + `selectAll` varchar(1) DEFAULT NULL, + `parameter_sql` text, + `parent_parameter_id` int(11) NULL DEFAULT NULL, + PRIMARY KEY (`parameter_id`), + UNIQUE KEY `name_UNIQUE` (`parameter_name`), + INDEX `fk_stretchy_parameter_0001_idx` (`parent_parameter_id`), + CONSTRAINT `fk_stretchy_parameter_0001` FOREIGN KEY (`parent_parameter_id`) REFERENCES `stretchy_parameter` (`parameter_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `stretchy_report` ( + `report_id` int(11) NOT NULL AUTO_INCREMENT, + `report_name` varchar(100) NOT NULL, + `report_type` varchar(20) NOT NULL, + `report_subtype` varchar(20) DEFAULT NULL, + `report_category` varchar(45) DEFAULT NULL, + `report_sql` text, + `description` text, + `core_report` tinyint(1) DEFAULT '0', + `use_report` tinyint(1) DEFAULT '0', + PRIMARY KEY (`report_id`), + UNIQUE KEY `report_name_UNIQUE` (`report_name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE `stretchy_report_parameter` ( + `report_id` int(11) NOT NULL, + `parameter_id` int(11) NOT NULL, + `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 DEFAULT CHARSET=utf8; +-- =========== end of reporting related tables ============ \ No newline at end of file diff --git a/mifosng-db/migrations/V2__mifosx-base-reference-data-utf8.sql b/mifosng-db/migrations/V2__mifosx-base-reference-data-utf8.sql new file mode 100644 index 000000000..80a68352d --- /dev/null +++ b/mifosng-db/migrations/V2__mifosx-base-reference-data-utf8.sql @@ -0,0 +1,294 @@ +-- currency symbols may not apply through command line on windows so use a different client like mysql workbench + +INSERT INTO `ref_loan_transaction_processing_strategy` +(`id`,`code`,`name`) +VALUES +(1, 'mifos-standard-strategy', 'Mifos style'), +(2, 'heavensfamily-strategy', 'Heavensfamily'), +(3, 'creocore-strategy', 'Creocore'), +(4, 'rbi-india-strategy', 'RBI (India)'); + +INSERT INTO `c_configuration` +(`name`, `enabled`) +VALUES +('maker-checker', 0); + +INSERT INTO `r_enum_value` +VALUES +('amortization_method_enum',0,'Equal principle payments','Equal principle payments'), +('amortization_method_enum',1,'Equal installments','Equal installments'), +('interest_calculated_in_period_enum',0,'Daily','Daily'), +('interest_calculated_in_period_enum',1,'Same as repayment period','Same as repayment period'), +('interest_method_enum',0,'Declining Balance','Declining Balance'), +('interest_method_enum',1,'Flat','Flat'), +('interest_period_frequency_enum',2,'Per month','Per month'), +('interest_period_frequency_enum',3,'Per year','Per year'), +('loan_status_id',100,'Submitted and awaiting approval','Submitted and awaiting approval'), +('loan_status_id',200,'Approved','Approved'), +('loan_status_id',300,'Active','Active'), +('loan_status_id',400,'Withdrawn by client','Withdrawn by client'), +('loan_status_id',500,'Rejected','Rejected'), +('loan_status_id',600,'Closed','Closed'), +('loan_status_id',601,'Written-Off','Written-Off'), +('loan_status_id',602,'Rescheduled','Rescheduled'), +('loan_status_id',700,'Overpaid','Overpaid'), +('loan_transaction_strategy_id',1,'mifos-standard-strategy','Mifos style'), +('loan_transaction_strategy_id',2,'heavensfamily-strategy','Heavensfamily'), +('loan_transaction_strategy_id',3,'creocore-strategy','Creocore'), +('loan_transaction_strategy_id',4,'rbi-india-strategy','RBI (India)'), +('processing_result_enum',0,'invalid','Invalid'), +('processing_result_enum',1,'processed','Processed'), +('processing_result_enum',2,'awaiting.approval','Awaiting Approval'), +('processing_result_enum',3,'rejected','Rejected'), +('repayment_period_frequency_enum',0,'Days','Days'), +('repayment_period_frequency_enum',1,'Weeks','Weeks'), +('repayment_period_frequency_enum',2,'Months','Months'), +('term_period_frequency_enum',0,'Days','Days'), +('term_period_frequency_enum',1,'Weeks','Weeks'), +('term_period_frequency_enum',2,'Months','Months'), +('term_period_frequency_enum',3,'Years','Years'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '1', 'Disbursement', 'Disbursement'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '2', 'Repayment', 'Repayment'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '3', 'Contra', 'Contra'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '4', 'Waive Interest', 'Waive Interest'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '5', 'Repayment At Disbursement', 'Repayment At Disbursement'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '6', 'Write-Off', 'Write-Off'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '7', 'Marked for Rescheduling', 'Marked for Rescheduling'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '8', 'Recovery Repayment', 'Recovery Repayment'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '9', 'Waive Charges', 'Waive Charges'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '10', 'Apply Charges', 'Apply Charges'); + +INSERT INTO `r_enum_value` (`enum_name`, `enum_id`, `enum_message_property`, `enum_value`) +VALUES ('transaction_type_enum', '11', 'Apply Interest', 'Apply Interest'); + +INSERT INTO `m_currency` +(`id`,`code`,`decimal_places`,`display_symbol`,`name`, `internationalized_name_code`) +VALUES +(1,'AED',2,NULL,'UAE Dirham','currency.AED'), +(2,'AFN',2,NULL,'Afghanistan Afghani','currency.AFN'), +(3,'ALL',2,NULL,'Albanian Lek','currency.ALL'), +(4,'AMD',2,NULL,'Armenian Dram','currency.AMD'), +(5,'ANG',2,NULL,'Netherlands Antillian Guilder','currency.ANG'), +(6,'AOA',2,NULL,'Angolan Kwanza','currency.AOA'), +(7,'ARS',2,'$','Argentine Peso','currency.ARS'), +(8,'AUD',2,'A$','Australian Dollar','currency.AUD'), +(9,'AWG',2,NULL,'Aruban Guilder','currency.AWG'), +(10,'AZM',2,NULL,'Azerbaijanian Manat','currency.AZM'), +(11,'BAM',2,NULL,'Bosnia and Herzegovina Convertible Marks','currency.BAM'), +(12,'BBD',2,NULL,'Barbados Dollar','currency.BBD'), +(13,'BDT',2,NULL,'Bangladesh Taka','currency.BDT'), +(14,'BGN',2,NULL,'Bulgarian Lev','currency.BGN'), +(15,'BHD',3,NULL,'Bahraini Dinar','currency.BHD'), +(16,'BIF',0,NULL,'Burundi Franc','currency.BIF'), +(17,'BMD',2,NULL,'Bermudian Dollar','currency.BMD'), +(18,'BND',2,'B$','Brunei Dollar','currency.BND'), +(19,'BOB',2,'Bs.','Bolivian Boliviano','currency.BOB'), +(20,'BRL',2,'R$','Brazilian Real','currency.BRL'), +(21,'BSD',2,NULL,'Bahamian Dollar','currency.BSD'), +(22,'BTN',2,NULL,'Bhutan Ngultrum','currency.BTN'), +(23,'BWP',2,NULL,'Botswana Pula','currency.BWP'), +(24,'BYR',0,NULL,'Belarussian Ruble','currency.BYR'), +(25,'BZD',2,'BZ$','Belize Dollar','currency.BZD'), +(26,'CAD',2,NULL,'Canadian Dollar','currency.CAD'), +(27,'CDF',2,NULL,'Franc Congolais','currency.CDF'), +(28,'CHF',2,NULL,'Swiss Franc','currency.CHF'), +(29,'CLP',0,'$','Chilean Peso','currency.CLP'), +(30,'CNY',2,NULL,'Chinese Yuan Renminbi','currency.CNY'), +(31,'COP',2,'$','Colombian Peso','currency.COP'), +(32,'CRC',2,'₡','Costa Rican Colon','currency.CRC'), +(33,'CSD',2,NULL,'Serbian Dinar','currency.CSD'), +(34,'CUP',2,'$MN','Cuban Peso','currency.CUP'), +(35,'CVE',2,NULL,'Cape Verde Escudo','currency.CVE'), +(36,'CYP',2,NULL,'Cyprus Pound','currency.CYP'), +(37,'CZK',2,NULL,'Czech Koruna','currency.CZK'), +(38,'DJF',0,NULL,'Djibouti Franc','currency.DJF'), +(39,'DKK',2,NULL,'Danish Krone','currency.DKK'), +(40,'DOP',2,'RD$','Dominican Peso','currency.DOP'), +(41,'DZD',2,NULL,'Algerian Dinar','currency.DZD'), +(42,'EEK',2,NULL,'Estonian Kroon','currency.EEK'), +(43,'EGP',2,NULL,'Egyptian Pound','currency.EGP'), +(44,'ERN',2,NULL,'Eritrea Nafka','currency.ERN'), +(45,'ETB',2,NULL,'Ethiopian Birr','currency.ETB'), +(46,'EUR',2,'€','Euro','currency.EUR'), +(47,'FJD',2,NULL,'Fiji Dollar','currency.FJD'), +(48,'FKP',2,NULL,'Falkland Islands Pound','currency.FKP'), +(49,'GBP',2,NULL,'Pound Sterling','currency.GBP'), +(50,'GEL',2,NULL,'Georgian Lari','currency.GEL'), +(51,'GHC',2,'GHc','Ghana Cedi','currency.GHC'), +(52,'GIP',2,NULL,'Gibraltar Pound','currency.GIP'), +(53,'GMD',2,NULL,'Gambian Dalasi','currency.GMD'), +(54,'GNF',0,NULL,'Guinea Franc','currency.GNF'), +(55,'GTQ',2,'Q','Guatemala Quetzal','currency.GTQ'), +(56,'GYD',2,NULL,'Guyana Dollar','currency.GYD'), +(57,'HKD',2,NULL,'Hong Kong Dollar','currency.HKD'), +(58,'HNL',2,'L','Honduras Lempira','currency.HNL'), +(59,'HRK',2,NULL,'Croatian Kuna','currency.HRK'), +(60,'HTG',2,'G','Haiti Gourde','currency.HTG'), +(61,'HUF',2,NULL,'Hungarian Forint','currency.HUF'), +(62,'IDR',2,NULL,'Indonesian Rupiah','currency.IDR'), +(63,'ILS',2,NULL,'New Israeli Shekel','currency.ILS'), +(64,'INR',2,'₹','Indian Rupee','currency.INR'), +(65,'IQD',3,NULL,'Iraqi Dinar','currency.IQD'), +(66,'IRR',2,NULL,'Iranian Rial','currency.IRR'), +(67,'ISK',0,NULL,'Iceland Krona','currency.ISK'), +(68,'JMD',2,NULL,'Jamaican Dollar','currency.JMD'), +(69,'JOD',3,NULL,'Jordanian Dinar','currency.JOD'), +(70,'JPY',0,NULL,'Japanese Yen','currency.JPY'), +(71,'KES',2,'KSh','Kenyan Shilling','currency.KES'), +(72,'KGS',2,NULL,'Kyrgyzstan Som','currency.KGS'), +(73,'KHR',2,NULL,'Cambodia Riel','currency.KHR'), +(74,'KMF',0,NULL,'Comoro Franc','currency.KMF'), +(75,'KPW',2,NULL,'North Korean Won','currency.KPW'), +(76,'KRW',0,NULL,'Korean Won','currency.KRW'), +(77,'KWD',3,NULL,'Kuwaiti Dinar','currency.KWD'), +(78,'KYD',2,NULL,'Cayman Islands Dollar','currency.KYD'), +(79,'KZT',2,NULL,'Kazakhstan Tenge','currency.KZT'), +(80,'LAK',2,NULL,'Lao Kip','currency.LAK'), +(81,'LBP',2,'L£','Lebanese Pound','currency.LBP'), +(82,'LKR',2,NULL,'Sri Lanka Rupee','currency.LKR'), +(83,'LRD',2,NULL,'Liberian Dollar','currency.LRD'), +(84,'LSL',2,NULL,'Lesotho Loti','currency.LSL'), +(85,'LTL',2,NULL,'Lithuanian Litas','currency.LTL'), +(86,'LVL',2,NULL,'Latvian Lats','currency.LVL'), +(87,'LYD',3,NULL,'Libyan Dinar','currency.LYD'), +(88,'MAD',2,NULL,'Moroccan Dirham','currency.MAD'), +(89,'MDL',2,NULL,'Moldovan Leu','currency.MDL'), +(90,'MGA',2,NULL,'Malagasy Ariary','currency.MGA'), +(91,'MKD',2,NULL,'Macedonian Denar','currency.MKD'), +(92,'MMK',2,'K','Myanmar Kyat','currency.MMK'), +(93,'MNT',2,NULL,'Mongolian Tugrik','currency.MNT'), +(94,'MOP',2,NULL,'Macau Pataca','currency.MOP'), +(95,'MRO',2,NULL,'Mauritania Ouguiya','currency.MRO'), +(96,'MTL',2,NULL,'Maltese Lira','currency.MTL'), +(97,'MUR',2,NULL,'Mauritius Rupee','currency.MUR'), +(98,'MVR',2,NULL,'Maldives Rufiyaa','currency.MVR'), +(99,'MWK',2,NULL,'Malawi Kwacha','currency.MWK'), +(100,'MXN',2,'$','Mexican Peso','currency.MXN'), +(101,'MYR',2,NULL,'Malaysian Ringgit','currency.MYR'), +(102,'MZM',2,NULL,'Mozambique Metical','currency.MZM'), +(103,'NAD',2,NULL,'Namibia Dollar','currency.NAD'), +(104,'NGN',2,NULL,'Nigerian Naira','currency.NGN'), +(105,'NIO',2,'C$','Nicaragua Cordoba Oro','currency.NIO'), +(106,'NOK',2,NULL,'Norwegian Krone','currency.NOK'), +(107,'NPR',2,NULL,'Nepalese Rupee','currency.NPR'), +(108,'NZD',2,NULL,'New Zealand Dollar','currency.NZD'), +(109,'OMR',3,NULL,'Rial Omani','currency.OMR'), +(110,'PAB',2,'B/.','Panama Balboa','currency.PAB'), +(111,'PEN',2,'S/.','Peruvian Nuevo Sol','currency.PEN'), +(112,'PGK',2,NULL,'Papua New Guinea Kina','currency.PGK'), +(113,'PHP',2,NULL,'Philippine Peso','currency.PHP'), +(114,'PKR',2,NULL,'Pakistan Rupee','currency.PKR'), +(115,'PLN',2,NULL,'Polish Zloty','currency.PLN'), +(116,'PYG',0,'₲','Paraguayan Guarani','currency.PYG'), +(117,'QAR',2,NULL,'Qatari Rial','currency.QAR'), +(118,'RON',2,NULL,'Romanian Leu','currency.RON'), +(119,'RUB',2,NULL,'Russian Ruble','currency.RUB'), +(120,'RWF',0,NULL,'Rwanda Franc','currency.RWF'), +(121,'SAR',2,NULL,'Saudi Riyal','currency.SAR'), +(122,'SBD',2,NULL,'Solomon Islands Dollar','currency.SBD'), +(123,'SCR',2,NULL,'Seychelles Rupee','currency.SCR'), +(124,'SDD',2,NULL,'Sudanese Dinar','currency.SDD'), +(125,'SEK',2,NULL,'Swedish Krona','currency.SEK'), +(126,'SGD',2,NULL,'Singapore Dollar','currency.SGD'), +(127,'SHP',2,NULL,'St Helena Pound','currency.SHP'), +(128,'SIT',2,NULL,'Slovenian Tolar','currency.SIT'), +(129,'SKK',2,NULL,'Slovak Koruna','currency.SKK'), +(130,'SLL',2,NULL,'Sierra Leone Leone','currency.SLL'), +(131,'SOS',2,NULL,'Somali Shilling','currency.SOS'), +(132,'SRD',2,NULL,'Surinam Dollar','currency.SRD'), +(133,'STD',2,NULL,'Sao Tome and Principe Dobra','currency.STD'), +(134,'SVC',2,NULL,'El Salvador Colon','currency.SVC'), +(135,'SYP',2,NULL,'Syrian Pound','currency.SYP'), +(136,'SZL',2,NULL,'Swaziland Lilangeni','currency.SZL'), +(137,'THB',2,NULL,'Thai Baht','currency.THB'), +(138,'TJS',2,NULL,'Tajik Somoni','currency.TJS'), +(139,'TMM',2,NULL,'Turkmenistan Manat','currency.TMM'), +(140,'TND',3,'DT','Tunisian Dinar','currency.TND'), +(141,'TOP',2,NULL,'Tonga Pa\'anga','currency.TOP'), +(142,'TRY',2,NULL,'Turkish Lira','currency.TRY'), +(143,'TTD',2,NULL,'Trinidad and Tobago Dollar','currency.TTD'), +(144,'TWD',2,NULL,'New Taiwan Dollar','currency.TWD'), +(145,'TZS',2,NULL,'Tanzanian Shilling','currency.TZS'), +(146,'UAH',2,NULL,'Ukraine Hryvnia','currency.UAH'), +(147,'UGX',2,'USh','Uganda Shilling','currency.UGX'), +(148,'USD',2,'$','US Dollar','currency.USD'), +(149,'UYU',2,'$U','Peso Uruguayo','currency.UYU'), +(150,'UZS',2,NULL,'Uzbekistan Sum','currency.UZS'), +(151,'VEB',2,'Bs.F.','Venezuelan Bolivar','currency.VEB'), +(152,'VND',2,NULL,'Vietnamese Dong','currency.VND'), +(153,'VUV',0,NULL,'Vanuatu Vatu','currency.VUV'), +(154,'WST',2,NULL,'Samoa Tala','currency.WST'), +(155,'XAF',0,NULL,'CFA Franc BEAC','currency.XAF'), +(156,'XCD',2,NULL,'East Caribbean Dollar','currency.XCD'), +(157,'XDR',5,NULL,'SDR (Special Drawing Rights)','currency.XDR'), +(158,'XOF',0, 'CFA','CFA Franc BCEAO','currency.XOF'), +(159,'XPF',0,NULL,'CFP Franc','currency.XPF'), +(160,'YER',2,NULL,'Yemeni Rial','currency.YER'), +(161,'ZAR',2, 'R','South African Rand','currency.ZAR'), +(162,'ZMK',2,NULL,'Zambian Kwacha','currency.ZMK'), +(163,'ZWD',2,NULL,'Zimbabwe Dollar','currency.ZWD'); +-- ======== end of currencies == + +INSERT INTO `m_organisation_currency` (`id`, `code`, `decimal_places`, `name`, `display_symbol`, `internationalized_name_code`) +VALUES (21,'USD',2,'US Dollar','$','currency.USD'); + +INSERT INTO `m_office` (`id`, `parent_id`, `hierarchy`, `external_id`, `name`, `opening_date`) +VALUES +(1,NULL,'.','1','Head Office','2009-01-01'); + +INSERT INTO `m_group_level` (`id`, `parent_id`, `super_parent`, `level_name`, `recursable`, `can_have_clients`) +VALUES (1, NULL, 1, 'Center', 1, 0); +INSERT INTO `m_group_level` (`id`, `parent_id`, `super_parent`, `level_name`, `recursable`, `can_have_clients`) +VALUES (2, 1, 0, 'Group', 0, 1); + + + +-- create single code and code value for client identifiers +INSERT INTO `m_code` +(`code_name`, `is_system_defined`) +VALUES +('Customer Identifier',1), +('LoanCollateral',1), +('LoanPurpose',1), +('Gender',1), +('YesNo',1); + +INSERT INTO `m_code_value`(`code_id`,`code_value`,`order_position`) +select mc.id, 'Passport', 1 +from m_code mc +where mc.`code_name` = "Customer Identifier"; + +INSERT INTO `m_code_value`(`code_id`,`code_value`,`order_position`) +select mc.id, 'Id', 2 +from m_code mc +where mc.`code_name` = "Customer Identifier"; + +INSERT INTO `m_code_value`(`code_id`,`code_value`,`order_position`) +select mc.id, 'Drivers License', 3 +from m_code mc +where mc.`code_name` = "Customer Identifier"; + +INSERT INTO `m_code_value`(`code_id`,`code_value`,`order_position`) +select mc.id, 'Any Other Id Type', 4 +from m_code mc +where mc.`code_name` = "Customer Identifier"; \ No newline at end of file diff --git a/mifosng-db/migrations/V3__mifosx-permissions-and-authorisation-utf8.sql b/mifosng-db/migrations/V3__mifosx-permissions-and-authorisation-utf8.sql new file mode 100644 index 000000000..971065a42 --- /dev/null +++ b/mifosng-db/migrations/V3__mifosx-permissions-and-authorisation-utf8.sql @@ -0,0 +1,327 @@ + +-- ========= roles and permissions ========= + +/* +this scripts removes all current m_role_permission and m_permission entries +and then inserts new m_permission entries and just one m_role_permission entry +which gives the role (id 1 - super user) an ALL_FUNCTIONS permission + +If you had other roles set up with specific permissions you will have to set up their permissions again. +*/ + +-- truncate `m_role_permission`; +-- truncate `m_permission`; +-- truncate `x_registered_table`; + +INSERT INTO `m_permission` +(`grouping`,`code`,`entity_name`,`action_name`,`can_maker_checker`) VALUES +('special','ALL_FUNCTIONS',NULL,NULL,0), +('special','ALL_FUNCTIONS_READ',NULL,NULL,0), +('special', 'CHECKER_SUPER_USER', NULL, NULL, '0'), +('special','REPORTING_SUPER_USER',NULL,NULL,0), +('authorisation','READ_PERMISSION','PERMISSION','READ',0), +('authorisation','PERMISSIONS_ROLE','ROLE','PERMISSIONS',1), +('authorisation','CREATE_ROLE','ROLE','CREATE',1), +('authorisation','CREATE_ROLE_CHECKER','ROLE','CREATE',0), +('authorisation','READ_ROLE','ROLE','READ',0), +('authorisation','UPDATE_ROLE','ROLE','UPDATE',1), +('authorisation','UPDATE_ROLE_CHECKER','ROLE','UPDATE',0), +('authorisation','DELETE_ROLE','ROLE','DELETE',1), +('authorisation','DELETE_ROLE_CHECKER','ROLE','DELETE',0), +('authorisation','CREATE_USER','USER','CREATE',1), +('authorisation','CREATE_USER_CHECKER','USER','CREATE',0), +('authorisation','READ_USER','USER','READ',0), +('authorisation','UPDATE_USER','USER','UPDATE',1), +('authorisation','UPDATE_USER_CHECKER','USER','UPDATE',0), +('authorisation','DELETE_USER','USER','DELETE',1), +('authorisation','DELETE_USER_CHECKER','USER','DELETE',0), +('configuration','READ_CONFIGURATION','CONFIGURATION','READ',1), +('configuration','UPDATE_CONFIGURATION','CONFIGURATION','UPDATE',1), +('configuration','UPDATE_CONFIGURATION_CHECKER','CONFIGURATION','UPDATE',0), +('configuration','READ_CODE','CODE','READ',0), +('configuration','CREATE_CODE','CODE','CREATE',1), +('configuration','CREATE_CODE_CHECKER','CODE','CREATE',0), +('configuration','UPDATE_CODE','CODE','UPDATE',1), +('configuration','UPDATE_CODE_CHECKER','CODE','UPDATE',0), +('configuration','DELETE_CODE','CODE','DELETE',1), +('configuration','DELETE_CODE_CHECKER','CODE','DELETE',0), +('configuration', 'READ_CODEVALUE', 'CODEVALUE', 'READ', '0'), +('configuration', 'CREATE_CODEVALUE', 'CODEVALUE', 'CREATE', '1'), +('configuration', 'CREATE_CODEVALUE_CHECKER', 'CODEVALUE', 'CREATE', '0'), +('configuration', 'UPDATE_CODEVALUE', 'CODEVALUE', 'UPDATE', '1'), +('configuration', 'UPDATE_CODEVALUE_CHECKER', 'CODEVALUE', 'UPDATE', '0'), +('configuration', 'DELETE_CODEVALUE', 'CODEVALUE', 'DELETE', '1'), +('configuration', 'DELETE_CODEVALUE_CHECKER', 'CODEVALUE', 'DELETE', '0'), +('configuration','READ_CURRENCY','CURRENCY','READ',0), +('configuration','UPDATE_CURRENCY','CURRENCY','UPDATE',1), +('configuration','UPDATE_CURRENCY_CHECKER','CURRENCY','UPDATE',0), +('configuration', 'UPDATE_PERMISSION', 'PERMISSION', 'UPDATE', '1'), +('configuration', 'UPDATE_PERMISSION_CHECKER', 'PERMISSION', 'UPDATE', '0'), +('configuration', 'READ_DATATABLE', 'DATATABLE', 'READ', '0'), +('configuration', 'REGISTER_DATATABLE', 'DATATABLE', 'REGISTER', '1'), +('configuration', 'REGISTER_DATATABLE_CHECKER', 'DATATABLE', 'REGISTER', '0'), +('configuration', 'DEREGISTER_DATATABLE', 'DATATABLE', 'DEREGISTER', '1'), +('configuration', 'DEREGISTER_DATATABLE_CHECKER', 'DATATABLE', 'DEREGISTER', '0'), +('configuration', 'READ_AUDIT', 'AUDIT', 'READ', '0'), +('configuration', 'CREATE_CALENDAR', 'CALENDAR', 'CREATE', '0'), +('configuration', 'READ_CALENDAR', 'CALENDAR', 'READ', '0'), +('configuration', 'UPDATE_CALENDAR', 'CALENDAR', 'UPDATE', '0'), +('configuration', 'DELETE_CALENDAR', 'CALENDAR', 'DELETE', '0'), +('configuration', 'CREATE_CALENDAR_CHECKER', 'CALENDAR', 'CREATE', '0'), +('configuration', 'UPDATE_CALENDAR_CHECKER', 'CALENDAR', 'UPDATE', '0'), +('configuration', 'DELETE_CALENDAR_CHECKER', 'CALENDAR', 'DELETE', '0'), +('organisation', 'READ_MAKERCHECKER', 'MAKERCHECKER', 'READ', '0'), +('organisation', 'READ_CHARGE', 'CHARGE', 'READ', '0'), +('organisation', 'CREATE_CHARGE', 'CHARGE', 'CREATE', '1'), +('organisation', 'CREATE_CHARGE_CHECKER', 'CHARGE', 'CREATE', '0'), +('organisation', 'UPDATE_CHARGE', 'CHARGE', 'UPDATE', '1'), +('organisation', 'UPDATE_CHARGE_CHECKER', 'CHARGE', 'UPDATE', '0'), +('organisation', 'DELETE_CHARGE', 'CHARGE', 'DELETE', '1'), +('organisation', 'DELETE_CHARGE_CHECKER', 'CHARGE', 'DELETE', '0'), +('organisation', 'READ_FUND', 'FUND', 'READ', '0'), +('organisation', 'CREATE_FUND', 'FUND', 'CREATE', '1'), +('organisation', 'CREATE_FUND_CHECKER', 'FUND', 'CREATE', '0'), +('organisation', 'UPDATE_FUND', 'FUND', 'UPDATE', '1'), +('organisation', 'UPDATE_FUND_CHECKER', 'FUND', 'UPDATE', '0'), +('organisation', 'DELETE_FUND', 'FUND', 'DELETE', '1'), +('organisation', 'DELETE_FUND_CHECKER', 'FUND', 'DELETE', '0'), +('organisation', 'READ_LOANPRODUCT', 'LOANPRODUCT', 'READ', '0'), +('organisation', 'CREATE_LOANPRODUCT', 'LOANPRODUCT', 'CREATE', '1'), +('organisation', 'CREATE_LOANPRODUCT_CHECKER', 'LOANPRODUCT', 'CREATE', '0'), +('organisation', 'UPDATE_LOANPRODUCT', 'LOANPRODUCT', 'UPDATE', '1'), +('organisation', 'UPDATE_LOANPRODUCT_CHECKER', 'LOANPRODUCT', 'UPDATE', '0'), +('organisation', 'DELETE_LOANPRODUCT', 'LOANPRODUCT', 'DELETE', '1'), +('organisation', 'DELETE_LOANPRODUCT_CHECKER', 'LOANPRODUCT', 'DELETE', '0'), +('organisation', 'READ_OFFICE', 'OFFICE', 'READ', '0'), +('organisation', 'CREATE_OFFICE', 'OFFICE', 'CREATE', '1'), +('organisation', 'CREATE_OFFICE_CHECKER', 'OFFICE', 'CREATE', '0'), +('organisation', 'UPDATE_OFFICE', 'OFFICE', 'UPDATE', '1'), +('organisation', 'UPDATE_OFFICE_CHECKER', 'OFFICE', 'UPDATE', '0'), +('organisation', 'READ_OFFICETRANSACTION', 'OFFICETRANSACTION', 'READ', '0'), +('organisation', 'DELETE_OFFICE_CHECKER', 'OFFICE', 'DELETE', '0'), +('organisation', 'CREATE_OFFICETRANSACTION', 'OFFICETRANSACTION', 'CREATE', '1'), +('organisation', 'CREATE_OFFICETRANSACTION_CHECKER', 'OFFICETRANSACTION', 'CREATE', '0'), +('organisation', 'DELETE_OFFICETRANSACTION', 'OFFICETRANSACTION', 'DELETE', 1), +('organisation', 'DELETE_OFFICETRANSACTION_CHECKER', 'OFFICETRANSACTION', 'DELETE', 0), +('organisation', 'READ_STAFF', 'STAFF', 'READ', '0'), +('organisation', 'CREATE_STAFF', 'STAFF', 'CREATE', '1'), +('organisation', 'CREATE_STAFF_CHECKER', 'STAFF', 'CREATE', '0'), +('organisation', 'UPDATE_STAFF', 'STAFF', 'UPDATE', '1'), +('organisation', 'UPDATE_STAFF_CHECKER', 'STAFF', 'UPDATE', '0'), +('organisation', 'DELETE_STAFF', 'STAFF', 'DELETE', '1'), +('organisation', 'DELETE_STAFF_CHECKER', 'STAFF', 'DELETE', '0'), +('organisation', 'READ_SAVINGSPRODUCT', 'SAVINGSPRODUCT', 'READ', '0'), +('organisation', 'CREATE_SAVINGSPRODUCT', 'SAVINGSPRODUCT', 'CREATE', '1'), +('organisation', 'CREATE_SAVINGSPRODUCT_CHECKER', 'SAVINGSPRODUCT', 'CREATE', '0'), +('organisation', 'UPDATE_SAVINGSPRODUCT', 'SAVINGSPRODUCT', 'UPDATE', '1'), +('organisation', 'UPDATE_SAVINGSPRODUCT_CHECKER', 'SAVINGSPRODUCT', 'UPDATE', '0'), +('organisation', 'DELETE_SAVINGSPRODUCT', 'SAVINGSPRODUCT', 'DELETE', '1'), +('organisation', 'DELETE_SAVINGSPRODUCT_CHECKER', 'SAVINGSPRODUCT', 'DELETE', '0'), +('portfolio', 'READ_LOAN', 'LOAN', 'READ', '0'), +('portfolio', 'CREATE_LOAN', 'LOAN', 'CREATE', '1'), +('portfolio', 'CREATE_LOAN_CHECKER', 'LOAN', 'CREATE', '0'), +('portfolio', 'UPDATE_LOAN', 'LOAN', 'UPDATE', '1'), +('portfolio', 'UPDATE_LOAN_CHECKER', 'LOAN', 'UPDATE', '0'), +('portfolio', 'DELETE_LOAN', 'LOAN', 'DELETE', '1'), +('portfolio', 'DELETE_LOAN_CHECKER', 'LOAN', 'DELETE', '0'), +-- ('portfolio', 'CREATEHISTORIC_LOAN', 'LOAN', 'CREATEHISTORIC', '1'), +-- ('portfolio', 'CREATEHISTORIC_LOAN_CHECKER', 'LOAN', 'CREATEHISTORIC', '0'), +-- ('portfolio', 'UPDATEHISTORIC_LOAN', 'LOAN', 'UPDATEHISTORIC', '1'), +-- ('portfolio', 'UPDATEHISTORIC_LOAN_CHECKER', 'LOAN', 'UPDATEHISTORIC', '0'), +('portfolio', 'READ_CLIENT', 'CLIENT', 'READ', '0'), +('portfolio', 'CREATE_CLIENT', 'CLIENT', 'CREATE', '1'), +('portfolio', 'CREATE_CLIENT_CHECKER', 'CLIENT', 'CREATE', '0'), +('portfolio', 'UPDATE_CLIENT', 'CLIENT', 'UPDATE', '1'), +('portfolio', 'UPDATE_CLIENT_CHECKER', 'CLIENT', 'UPDATE', '0'), +('portfolio', 'DELETE_CLIENT', 'CLIENT', 'DELETE', '1'), +('portfolio', 'DELETE_CLIENT_CHECKER', 'CLIENT', 'DELETE', '0'), +('portfolio', 'READ_CLIENTIMAGE', 'CLIENTIMAGE', 'READ', '0'), +('portfolio', 'CREATE_CLIENTIMAGE', 'CLIENTIMAGE', 'CREATE', '1'), +('portfolio', 'CREATE_CLIENTIMAGE_CHECKER', 'CLIENTIMAGE', 'CREATE', '0'), +('portfolio', 'DELETE_CLIENTIMAGE', 'CLIENTIMAGE', 'DELETE', '1'), +('portfolio', 'DELETE_CLIENTIMAGE_CHECKER', 'CLIENTIMAGE', 'DELETE', '0'), +('portfolio', 'READ_CLIENTNOTE', 'CLIENTNOTE', 'READ', '0'), +('portfolio', 'CREATE_CLIENTNOTE', 'CLIENTNOTE', 'CREATE', '1'), +('portfolio', 'CREATE_CLIENTNOTE_CHECKER', 'CLIENTNOTE', 'CREATE', '0'), +('portfolio', 'UPDATE_CLIENTNOTE', 'CLIENTNOTE', 'UPDATE', '1'), +('portfolio', 'UPDATE_CLIENTNOTE_CHECKER', 'CLIENTNOTE', 'UPDATE', '0'), +('portfolio', 'DELETE_CLIENTNOTE', 'CLIENTNOTE', 'DELETE', '1'), +('portfolio', 'DELETE_CLIENTNOTE_CHECKER', 'CLIENTNOTE', 'DELETE', '0'), +('portfolio', 'READ_GROUPNOTE', 'GROUPNOTE', 'READ', '0'), +('portfolio', 'CREATE_GROUPNOTE', 'GROUPNOTE', 'CREATE', '1'), +('portfolio', 'UPDATE_GROUPNOTE', 'GROUPNOTE', 'UPDATE', '1'), +('portfolio', 'DELETE_GROUPNOTE', 'GROUPNOTE', 'DELETE', '1'), +('portfolio', 'CREATE_GROUPNOTE_CHECKER', 'GROUPNOTE', 'CREATE', '0'), +('portfolio', 'UPDATE_GROUPNOTE_CHECKER', 'GROUPNOTE', 'UPDATE', '0'), +('portfolio', 'DELETE_GROUPNOTE_CHECKER', 'GROUPNOTE', 'DELETE', '0'), +('portfolio', 'READ_LOANNOTE', 'LOANNOTE', 'READ', '0'), +('portfolio', 'CREATE_LOANNOTE', 'LOANNOTE', 'CREATE', '1'), +('portfolio', 'UPDATE_LOANNOTE', 'LOANNOTE', 'UPDATE', '1'), +('portfolio', 'DELETE_LOANNOTE', 'LOANNOTE', 'DELETE', '1'), +('portfolio', 'CREATE_LOANNOTE_CHECKER', 'LOANNOTE', 'CREATE', '0'), +('portfolio', 'UPDATE_LOANNOTE_CHECKER', 'LOANNOTE', 'UPDATE', '0'), +('portfolio', 'DELETE_LOANNOTE_CHECKER', 'LOANNOTE', 'DELETE', '0'), +('portfolio', 'READ_LOANTRANSACTIONNOTE', 'LOANTRANSACTIONNOTE', 'READ', '0'), +('portfolio', 'CREATE_LOANTRANSACTIONNOTE', 'LOANTRANSACTIONNOTE', 'CREATE', '1'), +('portfolio', 'UPDATE_LOANTRANSACTIONNOTE', 'LOANTRANSACTIONNOTE', 'UPDATE', '1'), +('portfolio', 'DELETE_LOANTRANSACTIONNOTE', 'LOANTRANSACTIONNOTE', 'DELETE', '1'), +('portfolio', 'CREATE_LOANTRANSACTIONNOTE_CHECKER', 'LOANTRANSACTIONNOTE', 'CREATE', '0'), +('portfolio', 'UPDATE_LOANTRANSACTIONNOTE_CHECKER', 'LOANTRANSACTIONNOTE', 'UPDATE', '0'), +('portfolio', 'DELETE_LOANTRANSACTIONNOTE_CHECKER', 'LOANTRANSACTIONNOTE', 'DELETE', '0'), +('portfolio', 'READ_SAVINGNOTE', 'SAVINGNOTE', 'READ', '0'), +('portfolio', 'CREATE_SAVINGNOTE', 'SAVINGNOTE', 'CREATE', '1'), +('portfolio', 'UPDATE_SAVINGNOTE', 'SAVINGNOTE', 'UPDATE', '1'), +('portfolio', 'DELETE_SAVINGNOTE', 'SAVINGNOTE', 'DELETE', '1'), +('portfolio', 'CREATE_SAVINGNOTE_CHECKER', 'SAVINGNOTE', 'CREATE', '0'), +('portfolio', 'UPDATE_SAVINGNOTE_CHECKER', 'SAVINGNOTE', 'UPDATE', '0'), +('portfolio', 'DELETE_SAVINGNOTE_CHECKER', 'SAVINGNOTE', 'DELETE', '0'), +('portfolio', 'READ_CLIENTIDENTIFIER', 'CLIENTIDENTIFIER', 'READ', '0'), +('portfolio', 'CREATE_CLIENTIDENTIFIER', 'CLIENTIDENTIFIER', 'CREATE', '1'), +('portfolio', 'CREATE_CLIENTIDENTIFIER_CHECKER', 'CLIENTIDENTIFIER', 'CREATE', '0'), +('portfolio', 'UPDATE_CLIENTIDENTIFIER', 'CLIENTIDENTIFIER', 'UPDATE', '1'), +('portfolio', 'UPDATE_CLIENTIDENTIFIER_CHECKER', 'CLIENTIDENTIFIER', 'UPDATE', '0'), +('portfolio', 'DELETE_CLIENTIDENTIFIER', 'CLIENTIDENTIFIER', 'DELETE', '1'), +('portfolio', 'DELETE_CLIENTIDENTIFIER_CHECKER', 'CLIENTIDENTIFIER', 'DELETE', '0'), +('portfolio', 'READ_DOCUMENT', 'DOCUMENT', 'READ', '0'), +('portfolio', 'CREATE_DOCUMENT', 'DOCUMENT', 'CREATE', '1'), +('portfolio', 'CREATE_DOCUMENT_CHECKER', 'DOCUMENT', 'CREATE', '0'), +('portfolio', 'UPDATE_DOCUMENT', 'DOCUMENT', 'UPDATE', '1'), +('portfolio', 'UPDATE_DOCUMENT_CHECKER', 'DOCUMENT', 'UPDATE', '0'), +('portfolio', 'DELETE_DOCUMENT', 'DOCUMENT', 'DELETE', '1'), +('portfolio', 'DELETE_DOCUMENT_CHECKER', 'DOCUMENT', 'DELETE', '0'), +('portfolio', 'READ_GROUP', 'GROUP', 'READ', '0'), +('portfolio', 'CREATE_GROUP', 'GROUP', 'CREATE', '1'), +('portfolio', 'CREATE_GROUP_CHECKER', 'GROUP', 'CREATE', '0'), +('portfolio', 'UPDATE_GROUP', 'GROUP', 'UPDATE', '1'), +('portfolio', 'UPDATE_GROUP_CHECKER', 'GROUP', 'UPDATE', '0'), +('portfolio', 'DELETE_GROUP', 'GROUP', 'DELETE', '1'), +('portfolio', 'DELETE_GROUP_CHECKER', 'GROUP', 'DELETE', '0'), +('portfolio', 'UNASSIGNSTAFF_GROUP', 'GROUP', 'UNASSIGNSTAFF', 1), +('portfolio', 'UNASSIGNSTAFF_GROUP_CHECKER', 'GROUP', 'UNASSIGNSTAFF', 0), +('portfolio', 'CREATE_LOANCHARGE', 'LOANCHARGE', 'CREATE', '1'), +('portfolio', 'CREATE_LOANCHARGE_CHECKER', 'LOANCHARGE', 'CREATE', '0'), +('portfolio', 'UPDATE_LOANCHARGE', 'LOANCHARGE', 'UPDATE', '1'), +('portfolio', 'UPDATE_LOANCHARGE_CHECKER', 'LOANCHARGE', 'UPDATE', '0'), +('portfolio', 'DELETE_LOANCHARGE', 'LOANCHARGE', 'DELETE', '1'), +('portfolio', 'DELETE_LOANCHARGE_CHECKER', 'LOANCHARGE', 'DELETE', '0'), +('portfolio', 'WAIVE_LOANCHARGE', 'LOANCHARGE', 'WAIVE', '1'), +('portfolio', 'WAIVE_LOANCHARGE_CHECKER', 'LOANCHARGE', 'WAIVE', '0'), +('portfolio', 'READ_SAVINGSACCOUNT', 'SAVINGSACCOUNT', 'READ', '0'), +('portfolio', 'CREATE_SAVINGSACCOUNT', 'SAVINGSACCOUNT', 'CREATE', '1'), +('portfolio', 'CREATE_SAVINGSACCOUNT_CHECKER', 'SAVINGSACCOUNT', 'CREATE', '0'), +('portfolio', 'UPDATE_SAVINGSACCOUNT', 'SAVINGSACCOUNT', 'UPDATE', '1'), +('portfolio', 'UPDATE_SAVINGSACCOUNT_CHECKER', 'SAVINGSACCOUNT', 'UPDATE', '0'), +('portfolio', 'DELETE_SAVINGSACCOUNT', 'SAVINGSACCOUNT', 'DELETE', '1'), +('portfolio', 'DELETE_SAVINGSACCOUNT_CHECKER', 'SAVINGSACCOUNT', 'DELETE', '0'), +('portfolio', 'READ_GUARANTOR', 'GUARANTOR', 'READ', 0), +('portfolio', 'CREATE_GUARANTOR', 'GUARANTOR', 'CREATE', 1), +('portfolio', 'CREATE_GUARANTOR_CHECKER', 'GUARANTOR', 'CREATE', 0), +('portfolio', 'UPDATE_GUARANTOR', 'GUARANTOR', 'UPDATE', 1), +('portfolio', 'UPDATE_GUARANTOR_CHECKER', 'GUARANTOR', 'UPDATE', 0), +('portfolio', 'DELETE_GUARANTOR', 'GUARANTOR', 'DELETE', 1), +('portfolio', 'DELETE_GUARANTOR_CHECKER', 'GUARANTOR', 'DELETE', 0), +('transaction_loan', 'APPROVE_LOAN', 'LOAN', 'APPROVE', '1'), +('transaction_loan', 'APPROVEINPAST_LOAN', 'LOAN', 'APPROVEINPAST', '1'), +('transaction_loan', 'REJECT_LOAN', 'LOAN', 'REJECT', '1'), +('transaction_loan', 'REJECTINPAST_LOAN', 'LOAN', 'REJECTINPAST', '1'), +('transaction_loan', 'WITHDRAW_LOAN', 'LOAN', 'WITHDRAW', '1'), +('transaction_loan', 'WITHDRAWINPAST_LOAN', 'LOAN', 'WITHDRAWINPAST', '1'), +('transaction_loan', 'APPROVALUNDO_LOAN', 'LOAN', 'APPROVALUNDO', '1'), +('transaction_loan', 'DISBURSE_LOAN', 'LOAN', 'DISBURSE', '1'), +('transaction_loan', 'DISBURSEINPAST_LOAN', 'LOAN', 'DISBURSEINPAST', '1'), +('transaction_loan', 'DISBURSALUNDO_LOAN', 'LOAN', 'DISBURSALUNDO', '1'), +('transaction_loan', 'REPAYMENT_LOAN', 'LOAN', 'REPAYMENT', '1'), +('transaction_loan', 'REPAYMENTINPAST_LOAN', 'LOAN', 'REPAYMENTINPAST', '1'), +('transaction_loan', 'ADJUST_LOAN', 'LOAN', 'ADJUST', '1'), +('transaction_loan', 'WAIVEINTERESTPORTION_LOAN', 'LOAN', 'WAIVEINTERESTPORTION', '1'), +('transaction_loan', 'WRITEOFF_LOAN', 'LOAN', 'WRITEOFF', '1'), +('transaction_loan', 'CLOSE_LOAN', 'LOAN', 'CLOSE', '1'), +('transaction_loan', 'CLOSEASRESCHEDULED_LOAN', 'LOAN', 'CLOSEASRESCHEDULED', '1'), +('transaction_loan', 'UPDATELOANOFFICER_LOAN', 'LOAN', 'UPDATELOANOFFICER', 1), +('transaction_loan', 'UPDATELOANOFFICER_LOAN_CHECKER', 'LOAN', 'UPDATELOANOFFICER', 0), +('transaction_loan', 'REMOVELOANOFFICER_LOAN', 'LOAN', 'REMOVELOANOFFICER', 1), +('transaction_loan', 'REMOVELOANOFFICER_LOAN_CHECKER', 'LOAN', 'REMOVELOANOFFICER', 0), +('transaction_loan', 'BULKREASSIGN_LOAN', 'LOAN', 'BULKREASSIGN', '1'), +('transaction_loan', 'BULKREASSIGN_LOAN_CHECKER', 'LOAN', 'BULKREASSIGN', '0'), +('transaction_loan', 'APPROVE_LOAN_CHECKER', 'LOAN', 'APPROVE', '0'), +('transaction_loan', 'APPROVEINPAST_LOAN_CHECKER', 'LOAN', 'APPROVEINPAST', '0'), +('transaction_loan', 'REJECT_LOAN_CHECKER', 'LOAN', 'REJECT', '0'), +('transaction_loan', 'REJECTINPAST_LOAN_CHECKER', 'LOAN', 'REJECTINPAST', '0'), +('transaction_loan', 'WITHDRAW_LOAN_CHECKER', 'LOAN', 'WITHDRAW', '0'), +('transaction_loan', 'WITHDRAWINPAST_LOAN_CHECKER', 'LOAN', 'WITHDRAWINPAST', '0'), +('transaction_loan', 'APPROVALUNDO_LOAN_CHECKER', 'LOAN', 'APPROVALUNDO', '0'), +('transaction_loan', 'DISBURSE_LOAN_CHECKER', 'LOAN', 'DISBURSE', '0'), +('transaction_loan', 'DISBURSEINPAST_LOAN_CHECKER', 'LOAN', 'DISBURSEINPAST', '0'), +('transaction_loan', 'DISBURSALUNDO_LOAN_CHECKER', 'LOAN', 'DISBURSALUNDO', '0'), +('transaction_loan', 'REPAYMENT_LOAN_CHECKER', 'LOAN', 'REPAYMENT', '0'), +('transaction_loan', 'REPAYMENTINPAST_LOAN_CHECKER', 'LOAN', 'REPAYMENTINPAST', '0'), +('transaction_loan', 'ADJUST_LOAN_CHECKER', 'LOAN', 'ADJUST', '0'), +('transaction_loan', 'WAIVEINTERESTPORTION_LOAN_CHECKER', 'LOAN', 'WAIVEINTERESTPORTION', '0'), +('transaction_loan', 'WRITEOFF_LOAN_CHECKER', 'LOAN', 'WRITEOFF', '0'), +('transaction_loan', 'CLOSE_LOAN_CHECKER', 'LOAN', 'CLOSE', '0'), +('transaction_loan', 'CLOSEASRESCHEDULED_LOAN_CHECKER', 'LOAN', 'CLOSEASRESCHEDULED', '0'), +('transaction_savings', 'DEPOSIT_SAVINGSACCOUNT', 'SAVINGSACCOUNT', 'DEPOSIT', '1'), +('transaction_savings', 'DEPOSIT_SAVINGSACCOUNT_CHECKER', 'SAVINGSACCOUNT', 'DEPOSIT', '0'), +('transaction_savings', 'WITHDRAWAL_SAVINGSACCOUNT', 'SAVINGSACCOUNT', 'WITHDRAWAL', '1'), +('transaction_savings', 'WITHDRAWAL_SAVINGSACCOUNT_CHECKER', 'SAVINGSACCOUNT', 'WITHDRAWAL', '0'), +('transaction_savings', 'ACTIVATE_SAVINGSACCOUNT', 'SAVINGSACCOUNT', 'ACTIVATE', '1'), +('transaction_savings', 'ACTIVATE_SAVINGSACCOUNT_CHECKER', 'SAVINGSACCOUNT', 'ACTIVATE', '0'), +('transaction_savings', 'CALCULATEINTEREST_SAVINGSACCOUNT', 'SAVINGSACCOUNT', 'CALCULATEINTEREST', '1'), +('transaction_savings', 'CALCULATEINTEREST_SAVINGSACCOUNT_CHECKER', 'SAVINGSACCOUNT', 'CALCULATEINTEREST', '0'); + +-- == accounting related permissions +INSERT INTO `m_permission` (`grouping`, `code`, `entity_name`, `action_name`, `can_maker_checker`) VALUES +('accounting', 'CREATE_GLACCOUNT', 'GLACCOUNT', 'CREATE', 1), +('accounting', 'UPDATE_GLACCOUNT', 'GLACCOUNT', 'UPDATE', 1), +('accounting', 'DELETE_GLACCOUNT', 'GLACCOUNT', 'DELETE', 1), +('accounting', 'CREATE_GLCLOSURE', 'GLCLOSURE', 'CREATE', 1), +('accounting', 'UPDATE_GLCLOSURE', 'GLCLOSURE', 'UPDATE', 1), +('accounting', 'DELETE_GLCLOSURE', 'GLCLOSURE', 'DELETE', 1), +('accounting', 'CREATE_JOURNALENTRY', 'JOURNALENTRY', 'CREATE', 1), +('accounting', 'REVERSE_JOURNALENTRY', 'JOURNALENTRY', 'REVERSE', 1); + + +INSERT INTO `m_role` (`id`, `name`, `description`) +VALUES +(1,'Super user','This role provides all application permissions.'); + +/* role 1 is super user, give it ALL_FUNCTIONS */ +INSERT INTO m_role_permission(role_id, permission_id) +select 1, id +from m_permission +where code = 'ALL_FUNCTIONS'; + +INSERT INTO `m_appuser` (`id`, `office_id`, `username`, `firstname`, `lastname`, `password`, `email`, +`firsttime_login_remaining`, `nonexpired`, `nonlocked`, `nonexpired_credentials`, `enabled`) +VALUES +(1,1,'mifos','App','Administrator','5787039480429368bf94732aacc771cd0a3ea02bcf504ffe1185ab94213bc63a','demomfi@mifos.org','\0','','','',''); + + +INSERT INTO `m_appuser_role` (`appuser_id`, `role_id`) VALUES (1,1); + + +-- Add in permissions for any special datatables added in base reference data +-- This needs to always happen at end of the script + +/* add a create, read, update and delete permission for each registered datatable */ +insert into m_permission(grouping, `code`, entity_name, action_name) +select 'datatable', concat('CREATE_', r.registered_table_name), r.registered_table_name, 'CREATE' +from x_registered_table r; + +insert into m_permission(grouping, `code`, entity_name, action_name) +select 'datatable', concat('READ_', r.registered_table_name), r.registered_table_name, 'READ' +from x_registered_table r; + +insert into m_permission(grouping, `code`, entity_name, action_name) +select 'datatable', concat('UPDATE_', r.registered_table_name), r.registered_table_name, 'UPDATE' +from x_registered_table r; + +insert into m_permission(grouping, `code`, entity_name, action_name) +select 'datatable', concat('DELETE_', r.registered_table_name), r.registered_table_name, 'DELETE' +from x_registered_table r; + + +/* regardless of inserted permission settings above, no permissions (transactions) are preselected as being part of the maker-checker process +so, just set the flag to false... the end-user can decide which permissions should be maker-checkerable +*/ +update m_permission set can_maker_checker = false; \ No newline at end of file diff --git a/mifosng-db/migrations/V4__mifosx-core-reports-utf8.sql b/mifosng-db/migrations/V4__mifosx-core-reports-utf8.sql new file mode 100644 index 000000000..b6a728bd3 --- /dev/null +++ b/mifosng-db/migrations/V4__mifosx-core-reports-utf8.sql @@ -0,0 +1,12 @@ +truncate table stretchy_report; +truncate table stretchy_parameter; +truncate table stretchy_report_parameter; + +INSERT INTO `stretchy_report` VALUES (1,'Client Listing','Table',NULL,'Client','select \r\nconcat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\n c.account_no as \"Client Account No.\", \r\nc.display_name as \"Name\", \n\nc.joined_date as \"Joined\", c.external_id as \"External Id\"\r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand \n\nounder.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\n\n\norder by ounder.hierarchy, c.account_no','Individual Client Report\r\n\r\nLists the small number of defined fields on the client table. Would expect to copy this \n\nreport and add any \'one to one\' additional data for specific tenant needs.\r\n\r\nCan be run for any size MFI but you\'d expect it only to be run within a branch for \n\nlarger ones. Depending on how many columns are displayed, there is probably is a limit of about 20/50k clients returned for html display (export to excel doesn\'t \n\nhave that client browser/memory impact).',1,1),(2,'Client Loans Listing','Table',NULL,'Client','select \r\nconcat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nc.account_no as \"Client \n\nAccount No.\", \r\nc.display_name as \"Name\", \r\nlo.display_name as \"Loan Officer\", l.account_no as \"Loan Account No.\", l.external_id as \"External Id\", \r\n\n\np.name as Loan, st.enum_message_property as \"Status\", \r\nf.`name` as Fund, purp.code_value as \"Loan Purpose\",\r\nifnull(cur.display_symbol, l.currency_code) as Currency, \r\nl.principal_amount,\n\n\r\nl.arrearstolerance_amount as \"Arrears Tolerance Amount\",\r\nl.number_of_repayments as \"Expected No. Repayments\",\r\nl.annual_nominal_interest_rate as \" Annual \n\nNominal Interest Rate\", \r\nl.nominal_interest_rate_per_period as \"Nominal Interest Rate Per Period\",\r\n\r\nipf.enum_message_property as \"Interest Rate Frequency\n\n\",\r\nim.enum_message_property as \"Interest Method\",\r\nicp.enum_message_property as \"Interest Calculated in Period\",\r\nl.term_frequency as \"Term Frequency\",\n\n\r\ntf.enum_message_property as \"Term Frequency Period\",\r\nl.repay_every as \"Repayment Frequency\",\r\nrf.enum_message_property as \"Repayment Frequency Period\",\n\n\r\nam.enum_message_property as \"Amortization\",\r\n\r\nl.total_charges_due_at_disbursement_derived as \"Total Charges Due At Disbursement\",\r\n\r\ndate( \n\nl.submittedon_date) as Submitted, date(l.approvedon_date) Approved, l.expected_disbursedon_date As \"Expected Disbursal\",\r\ndate(l.expected_firstrepaymenton_date) as \n\n\"Expected First Repayment\", date(l.interest_calculated_from_date) as \"Interest Calculated From\" ,\r\ndate(l.disbursedon_date) as Disbursed, date\n\n(l.expected_maturedon_date) \"Expected Maturity\",\r\ndate(l.maturedon_date) as \"Matured On\", date(l.closedon_date) as Closed,\r\ndate(l.rejectedon_date) as \n\nRejected, date(l.rescheduledon_date) as Rescheduled, \r\ndate(l.withdrawnon_date) as Withdrawn, date(l.writtenoffon_date) \"Written Off\"\r\nfrom m_office o \r\njoin \n\nm_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c on \n\nc.office_id = ounder.id\r\nleft join m_loan l on l.client_id = c.id\r\nleft join m_staff lo on lo.id = l.loan_officer_id\r\nleft join m_product_loan p on p.id = \n\nl.product_id\r\nleft join m_fund f on f.id = l.fund_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 \n\nr_enum_value ipf on ipf.enum_name = \"interest_period_frequency_enum\" and ipf.enum_id = l.interest_period_frequency_enum\r\nleft join r_enum_value im on im.enum_name \n\n= \"interest_method_enum\" and im.enum_id = l.interest_method_enum\r\nleft join r_enum_value tf on tf.enum_name = \"term_period_frequency_enum\" and tf.enum_id = \n\nl.term_period_frequency_enum\r\nleft join r_enum_value icp on icp.enum_name = \"interest_calculated_in_period_enum\" and icp.enum_id = \n\nl.interest_calculated_in_period_enum\r\nleft join r_enum_value rf on rf.enum_name = \"repayment_period_frequency_enum\" and rf.enum_id = \n\nl.repayment_period_frequency_enum\r\nleft join r_enum_value am on am.enum_name = \"amortization_method_enum\" and am.enum_id = l.amortization_method_enum\r\nleft join m_code_value purp on purp.id = l.loanpurpose_cv_id\r\n\r\nleft \n\njoin 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 \n\n(l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \n\n\"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\norder by ounder.hierarchy, 2 , l.id','Individual Client Report\r\n\r\nPretty \n\nwide report that lists the basic details of client loans. \r\n\r\nCan be run for any size MFI but you\'d expect it only to be run within a branch for larger ones. \n\nThere is probably is a limit of about 20/50k clients returned for html display (export to excel doesn\'t have that client browser/memory impact).',1,1),(5,'Loans Awaiting Disbursal','Table',NULL,'Loan','SELECT \r\nconcat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nc.account_no as \"Client Account No\", c.display_name as \"Name\", l.account_no as \"Loan Account No.\", pl.`name` as \"Product\", \r\nf.`name` as Fund, ifnull(cur.display_symbol, l.currency_code) as Currency, \r\nl.principal_amount as Principal, \r\nl.term_frequency as \"Term Frequency\",\n\n\r\ntf.enum_message_property as \"Term Frequency Period\",\r\nl.annual_nominal_interest_rate as \" Annual Nominal Interest Rate\",\r\ndate(l.approvedon_date) \"Approved\",\r\ndatediff(l.expected_disbursedon_date, curdate()) as \"Days to Disbursal\",\r\ndate(l.expected_disbursedon_date) \"Expected Disbursal\",\r\npurp.code_value as \"Loan Purpose\",\r\n lo.display_name as \"Loan Officer\"\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_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nleft join m_code_value purp on purp.id = l.loanpurpose_cv_id\r\nleft join r_enum_value tf on tf.enum_name = \"term_period_frequency_enum\" and tf.enum_id = l.term_period_frequency_enum\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 200\r\norder by ounder.hierarchy, datediff(l.expected_disbursedon_date, curdate()), c.account_no','Individual Client Report',1,1),(6,'Loans Awaiting Disbursal Summary','Table',NULL,'Loan','SELECT \r\nconcat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\npl.`name` as \"Product\", \r\nifnull(cur.display_symbol, l.currency_code) as Currency, f.`name` as Fund,\r\nsum(l.principal_amount) as Principal\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_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nleft join m_code_value purp on purp.id = l.loanpurpose_cv_id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 200\r\ngroup by ounder.hierarchy, pl.`name`, l.currency_code, f.`name`\r\norder by ounder.hierarchy, pl.`name`, l.currency_code, f.`name`','Individual Client Report',1,1),(7,'Loans Awaiting Disbursal Summary by Month','Table',NULL,'Loan','SELECT \r\nconcat(repeat(\"..\", ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\npl.`name` as \"Product\", \r\nifnull(cur.display_symbol, l.currency_code) as Currency, \r\nyear(l.expected_disbursedon_date) as \"Year\", \r\nmonthname(l.expected_disbursedon_date) as \"Month\",\r\nsum(l.principal_amount) as Principal\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_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nleft join m_code_value purp on purp.id = l.loanpurpose_cv_id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 200\r\ngroup by ounder.hierarchy, pl.`name`, l.currency_code, year(l.expected_disbursedon_date), month(l.expected_disbursedon_date)\r\norder by ounder.hierarchy, pl.`name`, l.currency_code, year(l.expected_disbursedon_date), month(l.expected_disbursedon_date)','Individual Client Report',1,1),(8,'Loans Pending Approval','Table',NULL,'Loan','SELECT \r\nconcat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nc.account_no as \"Client Account No.\", c.display_name as \"Client Name\", \r\nifnull(cur.display_symbol, l.currency_code) as Currency, pl.`name` as \"Product\", \r\nl.account_no as \"Loan Account No.\", \r\nl.principal_amount as \"Loan Amount\", \r\nl.term_frequency as \"Term Frequency\",\n\n\r\ntf.enum_message_property as \"Term Frequency Period\",\r\nl.annual_nominal_interest_rate as \" Annual \n\nNominal Interest Rate\", \r\ndatediff(curdate(), l.submittedon_date) \"Days Pending Approval\", \r\npurp.code_value as \"Loan Purpose\",\r\nlo.display_name as \"Loan Officer\"\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_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_code_value purp on purp.id = l.loanpurpose_cv_id\r\nleft join r_enum_value tf on tf.enum_name = \"term_period_frequency_enum\" and tf.enum_id = l.term_period_frequency_enum\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 100 /*Submitted and awaiting approval */\r\norder by ounder.hierarchy, l.submittedon_date, l.account_no','Individual Client Report',1,1),(11,'Active Loans - Summary','Table',NULL,'Loan','select concat(repeat(\"..\", \r\n ((LENGTH(mo.`hierarchy`) - LENGTH(REPLACE(mo.`hierarchy`, \'.\', \'\')) - 1))), mo.`name`) as \"Office/Branch\", x.currency as Currency,\r\n x.client_count as \"No. of Clients\", x.active_loan_count as \"No. Active Loans\", x. loans_in_arrears_count as \"No. of Loans in Arrears\",\r\nx.principal as \"Total Loans Disbursed\", x.principal_repaid as \"Principal Repaid\", x.principal_outstanding as \"Principal Outstanding\", x.principal_overdue as \"Principal Overdue\",\r\nx.interest as \"Total Interest\", x.interest_repaid as \"Interest Repaid\", x.interest_outstanding as \"Interest Outstanding\", x.interest_overdue as \"Interest Overdue\",\r\nx.fees as \"Total Fees\", x.fees_repaid as \"Fees Repaid\", x.fees_outstanding as \"Fees Outstanding\", x.fees_overdue as \"Fees Overdue\",\r\nx.penalties as \"Total Penalties\", x.penalties_repaid as \"Penalties Repaid\", x.penalties_outstanding as \"Penalties Outstanding\", x.penalties_overdue as \"Penalties Overdue\",\r\n\r\n (case\r\n when ${parType} = 1 then\r\n cast(round((x.principal_overdue * 100) / x.principal_outstanding, 2) as char)\r\n when ${parType} = 2 then\r\n cast(round(((x.principal_overdue + x.interest_overdue) * 100) / (x.principal_outstanding + x.interest_outstanding), 2) as char)\r\n when ${parType} = 3 then\r\n cast(round(((x.principal_overdue + x.interest_overdue + x.fees_overdue) * 100) / (x.principal_outstanding + x.interest_outstanding + x.fees_outstanding), 2) as char)\r\n when ${parType} = 4 then\r\n cast(round(((x.principal_overdue + x.interest_overdue + x.fees_overdue + x.penalties_overdue) * 100) / (x.principal_outstanding + x.interest_outstanding + x.fees_outstanding + x.penalties_overdue), 2) as char)\r\n else \"invalid PAR Type\"\r\n end) as \"Portfolio at Risk %\"\r\n from m_office mo\r\njoin \r\n(select ounder.id as branch,\r\nifnull(cur.display_symbol, l.currency_code) as currency,\r\ncount(distinct(c.id)) as client_count, \r\ncount(distinct(l.id)) as active_loan_count,\r\ncount(distinct(if(laa.loan_id is not null, l.id, null) )) as loans_in_arrears_count,\r\n\r\nsum(l.principal_disbursed_derived) as principal,\r\nsum(l.principal_repaid_derived) as principal_repaid,\r\nsum(l.principal_outstanding_derived) as principal_outstanding,\r\nsum(laa.principal_overdue_derived) as principal_overdue,\r\n\r\nsum(l.interest_charged_derived) as interest,\r\nsum(l.interest_repaid_derived) as interest_repaid,\r\nsum(l.interest_outstanding_derived) as interest_outstanding,\r\nsum(laa.interest_overdue_derived) as interest_overdue,\r\n\r\nsum(l.fee_charges_charged_derived) as fees,\r\nsum(l.fee_charges_repaid_derived) as fees_repaid,\r\nsum(l.fee_charges_outstanding_derived) as fees_outstanding,\r\nsum(laa.fee_charges_overdue_derived) as fees_overdue,\r\n\r\nsum(l.penalty_charges_charged_derived) as penalties,\r\nsum(l.penalty_charges_repaid_derived) as penalties_repaid,\r\nsum(l.penalty_charges_outstanding_derived) as penalties_outstanding,\r\nsum(laa.penalty_charges_overdue_derived) as penalties_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_loan_arrears_aging laa on laa.loan_id = l.id\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.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 300\r\ngroup by ounder.id, l.currency_code) x on x.branch = mo.id\r\norder by mo.hierarchy, x.Currency',NULL,1,1),(12,'Active Loans - Details','Table',NULL,'Loan','select concat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nifnull(cur.display_symbol, l.currency_code) as Currency,\r\nlo.display_name as \"Loan Officer\", \r\nc.display_name as \"Client\", l.account_no as \"Loan Account No.\", pl.`name` as \"Product\", \r\nf.`name` as Fund, \r\nl.principal_amount as \"Loan Amount\", \r\nl.annual_nominal_interest_rate as \" Annual Nominal Interest Rate\", \r\ndate(l.disbursedon_date) as \"Disbursed Date\", \r\ndate(l.expected_maturedon_date) as \"Expected Matured On\",\r\n\r\nl.principal_repaid_derived as \"Principal Repaid\",\r\nl.principal_outstanding_derived as \"Principal Outstanding\",\r\nlaa.principal_overdue_derived as \"Principal Overdue\",\r\n\r\nl.interest_repaid_derived as \"Interest Repaid\",\r\nl.interest_outstanding_derived as \"Interest Outstanding\",\r\nlaa.interest_overdue_derived as \"Interest Overdue\",\r\n\r\nl.fee_charges_repaid_derived as \"Fees Repaid\",\r\nl.fee_charges_outstanding_derived as \"Fees Outstanding\",\r\nlaa.fee_charges_overdue_derived as \"Fees Overdue\",\r\n\r\nl.penalty_charges_repaid_derived as \"Penalties Repaid\",\r\nl.penalty_charges_outstanding_derived as \"Penalties Outstanding\",\r\npenalty_charges_overdue_derived as \"Penalties 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\njoin m_product_loan pl on pl.id = l.product_id\r\nleft join m_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nleft join m_loan_arrears_aging laa on laa.loan_id = l.id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 300\r\ngroup by l.id\r\norder by ounder.hierarchy, l.currency_code, c.account_no, l.account_no','Individual Client \n\nReport',1,1),(13,'Obligation Met Loans Details','Table',NULL,'Loan','select concat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nifnull(cur.display_symbol, l.currency_code) as Currency,\r\nc.account_no as \"Client Account No.\", c.display_name as \"Client\",\r\nl.account_no as \"Loan Account No.\", pl.`name` as \"Product\", \r\nf.`name` as Fund, \r\nl.principal_amount as \"Loan Amount\", \r\nl.total_repayment_derived as \"Total Repaid\", \r\nl.annual_nominal_interest_rate as \" Annual Nominal Interest Rate\", \r\ndate(l.disbursedon_date) as \"Disbursed\", \r\ndate(l.closedon_date) as \"Closed\",\r\n\r\nl.principal_repaid_derived as \"Principal Repaid\",\r\nl.interest_repaid_derived as \"Interest Repaid\",\r\nl.fee_charges_repaid_derived as \"Fees Repaid\",\r\nl.penalty_charges_repaid_derived as \"Penalties Repaid\",\r\nlo.display_name as \"Loan Officer\"\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_product_loan pl on pl.id = l.product_id\r\nleft join m_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand (case\r\n when ${obligDateType} = 1 then\r\n l.closedon_date between \'${startDate}\' and \'${endDate}\'\r\n when ${obligDateType} = 2 then\r\n l.disbursedon_date between \'${startDate}\' and \'${endDate}\'\r\n else 1 = 1\r\n end)\r\nand l.loan_status_id = 600\r\ngroup by l.id\r\norder by ounder.hierarchy, l.currency_code, c.account_no, l.account_no','Individual Client \n\nReport',1,1),(14,'Obligation Met Loans Summary','Table',NULL,'Loan','select concat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nifnull(cur.display_symbol, l.currency_code) as Currency,\r\ncount(distinct(c.id)) as \"No. of Clients\",\r\ncount(distinct(l.id)) as \"No. of Loans\",\r\nsum(l.principal_amount) as \"Total Loan Amount\", \r\nsum(l.principal_repaid_derived) as \"Total Principal Repaid\",\r\nsum(l.interest_repaid_derived) as \"Total Interest Repaid\",\r\nsum(l.fee_charges_repaid_derived) as \"Total Fees Repaid\",\r\nsum(l.penalty_charges_repaid_derived) as \"Total Penalties Repaid\",\r\nsum(l.interest_waived_derived) as \"Total Interest Waived\",\r\nsum(l.fee_charges_waived_derived) as \"Total Fees Waived\",\r\nsum(l.penalty_charges_waived_derived) as \"Total Penalties Waived\"\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_product_loan pl on pl.id = l.product_id\r\nleft join m_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand (case\r\n when ${obligDateType} = 1 then\r\n l.closedon_date between \'${startDate}\' and \'${endDate}\'\r\n when ${obligDateType} = 2 then\r\n l.disbursedon_date between \'${startDate}\' and \'${endDate}\'\r\n else 1 = 1\r\n end)\r\nand l.loan_status_id = 600\r\ngroup by ounder.hierarchy, l.currency_code\r\norder by ounder.hierarchy, l.currency_code','Individual Client \n\nReport',1,1),(15,'Portfolio at Risk','Table',NULL,'Loan','select x.Currency, x.`Principal Outstanding`, x.`Principal Overdue`, x.`Interest Outstanding`, x.`Interest Overdue`, \r\nx.`Fees Outstanding`, x.`Fees Overdue`, x.`Penalties Outstanding`, x.`Penalties Overdue`,\r\n\r\n (case\r\n when ${parType} = 1 then\r\n cast(round((x.`Principal Overdue` * 100) / x.`Principal Outstanding`, 2) as char)\r\n when ${parType} = 2 then\r\n cast(round(((x.`Principal Overdue` + x.`Interest Overdue`) * 100) / (x.`Principal Outstanding` + x.`Interest Outstanding`), 2) as char)\r\n when ${parType} = 3 then\r\n cast(round(((x.`Principal Overdue` + x.`Interest Overdue` + x.`Fees Overdue`) * 100) / (x.`Principal Outstanding` + x.`Interest Outstanding` + x.`Fees Outstanding`), 2) as char)\r\n when ${parType} = 4 then\r\n cast(round(((x.`Principal Overdue` + x.`Interest Overdue` + x.`Fees Overdue` + x.`Penalties Overdue`) * 100) / (x.`Principal Outstanding` + x.`Interest Outstanding` + x.`Fees Outstanding` + x.`Penalties Overdue`), 2) as char)\r\n else \"invalid PAR Type\"\r\n end) as \"Portfolio at Risk %\"\r\n from \r\n(select ifnull(cur.display_symbol, l.currency_code) as Currency, \r\nsum(l.principal_outstanding_derived) as \"Principal Outstanding\",\r\nsum(laa.principal_overdue_derived) as \"Principal Overdue\",\r\n\r\nsum(l.interest_outstanding_derived) as \"Interest Outstanding\",\r\nsum(laa.interest_overdue_derived) as \"Interest Overdue\",\r\n\r\nsum(l.fee_charges_outstanding_derived) as \"Fees Outstanding\",\r\nsum(laa.fee_charges_overdue_derived) as \"Fees Overdue\",\r\n\r\nsum(penalty_charges_outstanding_derived) as \"Penalties Outstanding\",\r\nsum(laa.penalty_charges_overdue_derived) as \"Penalties 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_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nleft join m_code_value purp on purp.id = l.loanpurpose_cv_id\r\nleft join m_product_loan p on p.id = l.product_id\r\nleft join m_loan_arrears_aging laa on laa.loan_id = l.id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 300\r\ngroup by l.currency_code\r\norder by l.currency_code) x','Covers all loans.\r\n\r\nFor larger MFIs … we should add some derived fields on loan (or a 1:1 loan related table like mifos 2.x does)\r\nPrinciple, Interest, Fees, Penalties Outstanding and Overdue (possibly waived and written off too)',1,1),(16,'Portfolio at Risk by Branch','Table',NULL,'Loan','select concat(repeat(\"..\", \r\n ((LENGTH(mo.`hierarchy`) - LENGTH(REPLACE(mo.`hierarchy`, \'.\', \'\')) - 1))), mo.`name`) as \"Office/Branch\",\r\nx.Currency, x.`Principal Outstanding`, x.`Principal Overdue`, x.`Interest Outstanding`, x.`Interest Overdue`, \r\nx.`Fees Outstanding`, x.`Fees Overdue`, x.`Penalties Outstanding`, x.`Penalties Overdue`,\r\n\r\n (case\r\n when ${parType} = 1 then\r\n cast(round((x.`Principal Overdue` * 100) / x.`Principal Outstanding`, 2) as char)\r\n when ${parType} = 2 then\r\n cast(round(((x.`Principal Overdue` + x.`Interest Overdue`) * 100) / (x.`Principal Outstanding` + x.`Interest Outstanding`), 2) as char)\r\n when ${parType} = 3 then\r\n cast(round(((x.`Principal Overdue` + x.`Interest Overdue` + x.`Fees Overdue`) * 100) / (x.`Principal Outstanding` + x.`Interest Outstanding` + x.`Fees Outstanding`), 2) as char)\r\n when ${parType} = 4 then\r\n cast(round(((x.`Principal Overdue` + x.`Interest Overdue` + x.`Fees Overdue` + x.`Penalties Overdue`) * 100) / (x.`Principal Outstanding` + x.`Interest Outstanding` + x.`Fees Outstanding` + x.`Penalties Overdue`), 2) as char)\r\n else \"invalid PAR Type\"\r\n end) as \"Portfolio at Risk %\"\r\n from m_office mo\r\njoin \r\n(select ounder.id as \"branch\", ifnull(cur.display_symbol, l.currency_code) as Currency, \r\n\r\nsum(l.principal_outstanding_derived) as \"Principal Outstanding\",\r\nsum(laa.principal_overdue_derived) as \"Principal Overdue\",\r\n\r\nsum(l.interest_outstanding_derived) as \"Interest Outstanding\",\r\nsum(laa.interest_overdue_derived) as \"Interest Overdue\",\r\n\r\nsum(l.fee_charges_outstanding_derived) as \"Fees Outstanding\",\r\nsum(laa.fee_charges_overdue_derived) as \"Fees Overdue\",\r\n\r\nsum(penalty_charges_outstanding_derived) as \"Penalties Outstanding\",\r\nsum(laa.penalty_charges_overdue_derived) as \"Penalties 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_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nleft join m_code_value purp on purp.id = l.loanpurpose_cv_id\r\nleft join m_product_loan p on p.id = l.product_id\r\nleft join m_loan_arrears_aging laa on laa.loan_id = l.id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 300\r\ngroup by ounder.id, l.currency_code) x on x.branch = mo.id\r\norder by mo.hierarchy, x.Currency','Covers all loans.\r\n\r\nFor larger MFIs … we should add some derived fields on loan (or a 1:1 loan related table like mifos 2.x does)\r\nPrinciple, Interest, Fees, Penalties Outstanding and Overdue (possibly waived and written off too)',1,1),(20,'Funds Disbursed Between Dates Summary','Table',NULL,'Fund','select ifnull(f.`name`, \'-\') as Fund, ifnull(cur.display_symbol, l.currency_code) as Currency, \r\nround(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,1,1),(21,'Funds Disbursed Between Dates Summary by Office','Table',NULL,'Fund','select \r\nconcat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\n \n\nifnull(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\n\n\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\nand ounder.hierarchy like concat(\'${currentUserHierarchy}\', \'%\')\r\njoin m_client c \n\non 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\n\n\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 \n\n(l.currency_code = \'${currencyId}\' or \'-1\' = \'${currencyId}\')\r\ngroup by ounder.`name`, ifnull(f.`name`, \'-\') , ifnull(cur.display_symbol, \n\nl.currency_code)\r\norder by ounder.`name`, ifnull(f.`name`, \'-\') , ifnull(cur.display_symbol, l.currency_code)',NULL,1,1),(48,'Balance Sheet','Pentaho',NULL,'Accounting',NULL,'Balance Sheet',1,1),(49,'Income Statement','Pentaho',NULL,'Accounting',NULL,'Profit and Loss Statement',1,1),(50,'Trial Balance','Pentaho',NULL,'Accounting',NULL,'Trial Balance Report',1,1),(51,'Written-Off Loans','Table',NULL,'Loan','SELECT \r\nconcat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nifnull(cur.display_symbol, ml.currency_code) as Currency, \r\nc.account_no as \"Client Account No.\",\r\nc.display_name AS \'Client Name\',\r\nml.account_no AS \'Loan Account No.\',\r\nmpl.name AS \'Product Name\',\r\nml.disbursedon_date AS \'Disbursed Date\',\r\nlt.transaction_date AS \'Written Off date\',\r\nml.principal_amount as \"Loan Amount\",\r\nifnull(lt.principal_portion_derived, 0) AS \'Written-Off Principal\',\r\nifnull(lt.interest_portion_derived, 0) AS \'Written-Off Interest\',\r\nifnull(lt.fee_charges_portion_derived,0) AS \'Written-Off Fees\',\r\nifnull(lt.penalty_charges_portion_derived,0) AS \'Written-Off Penalties\',\r\nn.note AS \'Reason For Write-Off\',\r\nIFNULL(ms.display_name,\'-\') AS \'Loan Officer Name\'\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 ml ON ml.client_id = c.id\r\nJOIN m_product_loan mpl ON mpl.id=ml.product_id\r\nLEFT JOIN m_staff ms ON ms.id=ml.loan_officer_id\r\nJOIN m_loan_transaction lt ON lt.loan_id = ml.id\r\nLEFT JOIN m_note n ON n.loan_transaction_id = lt.id\r\nLEFT JOIN m_currency cur on cur.code = ml.currency_code\r\nWHERE lt.transaction_type_enum = 6 /*write-off */\r\nAND lt.is_reversed is false \r\nAND ml.loan_status_id=601\r\nAND o.id=${officeId}\r\nAND (mpl.id=${loanProductId} OR ${loanProductId}=-1)\r\nAND lt.transaction_date BETWEEN \'${startDate}\' AND \'${endDate}\'\r\nAND (ml.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\") \r\nORDER BY ounder.hierarchy, ifnull(cur.display_symbol, ml.currency_code), ml.account_no','Individual Lending Report. Written Off Loans',1,1),(52,'Aging Detail','Table',NULL,'Loan','SELECT \r\nconcat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nifnull(cur.display_symbol, ml.currency_code) as Currency, \r\nmc.account_no as \"Client Account No.\",\r\n mc.display_name AS \"Client Name\",\r\n ml.account_no AS \"Account Number\",\r\n ml.principal_amount AS \"Loan Amount\",\r\n ml.principal_disbursed_derived AS \"Original Principal\",\r\n ml.interest_charged_derived AS \"Original Interest\",\r\n ml.principal_repaid_derived AS \"Principal Paid\",\r\n ml.interest_repaid_derived AS \"Interest Paid\",\r\n laa.principal_overdue_derived AS \"Principal Overdue\",\r\n laa.interest_overdue_derived AS \"Interest Overdue\",\r\nDATEDIFF(CURDATE(), laa.overdue_since_date_derived) as \"Days in Arrears\",\r\n\r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<7, \'<1\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<8, \' 1\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<15, \'2\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<22, \' 3\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<29, \' 4\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<36, \' 5\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<43, \' 6\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<50, \' 7\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<57, \' 8\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<64, \' 9\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<71, \'10\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<78, \'11\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<85, \'12\', \'12+\')))))))))))) )AS \"Weeks In Arrears Band\",\r\n\r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<31, \'0 - 30\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<61, \'30 - 60\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<91, \'60 - 90\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<181, \'90 - 180\', \r\n IF(DATEDIFF(CURDATE(), laa.overdue_since_date_derived)<361, \'180 - 360\', \r\n \'> 360\'))))) AS \"Days in Arrears Band\"\r\n\r\n FROM m_office mo \r\n JOIN m_office ounder ON ounder.hierarchy like concat(mo.hierarchy, \'%\')\r\n AND ounder.hierarchy like CONCAT(\'${currentUserHierarchy}\', \'%\')\r\n INNER JOIN m_client mc ON mc.office_id=ounder.id\r\n INNER JOIN m_loan ml ON ml.client_id = mc.id\r\n INNER JOIN r_enum_value rev ON rev.enum_id=ml.loan_status_id\r\n INNER JOIN m_loan_arrears_aging laa ON laa.loan_id=ml.id\r\n left join m_currency cur on cur.code = ml.currency_code\r\n WHERE ml.loan_status_id=300\r\n AND mo.id=${officeId}\r\nORDER BY ounder.hierarchy, ifnull(cur.display_symbol, ml.currency_code), ml.account_no','Loan arrears aging (Weeks)',1,1),(53,'Aging Summary (Arrears in Weeks)','Table',NULL,'Loan','SELECT \r\n IFNULL(periods.currencyName, periods.currency) as currency, \r\n periods.period_no \'Weeks In Arrears (Up To)\', \r\n IFNULL(ars.loanId, 0) \'No Of Loans\', \r\n IFNULL(ars.principal,0.0) \'Original Principal\', \r\n IFNULL(ars.interest,0.0) \'Original Interest\', \r\n IFNULL(ars.prinPaid,0.0) \'Principal Paid\', \r\n IFNULL(ars.intPaid,0.0) \'Interest Paid\', \r\n IFNULL(ars.prinOverdue,0.0) \'Principal Overdue\', \r\n IFNULL(ars.intOverdue,0.0)\'Interest Overdue\'\r\nFROM \r\n /* full table of aging periods/currencies used combo to ensure each line represented */\r\n (SELECT curs.code as currency, curs.name as currencyName, pers.* from\r\n (SELECT \'On Schedule\' period_no,1 pid UNION\r\n SELECT \'1\',2 UNION\r\n SELECT \'2\',3 UNION\r\n SELECT \'3\',4 UNION\r\n SELECT \'4\',5 UNION\r\n SELECT \'5\',6 UNION\r\n SELECT \'6\',7 UNION\r\n SELECT \'7\',8 UNION\r\n SELECT \'8\',9 UNION\r\n SELECT \'9\',10 UNION\r\n SELECT \'10\',11 UNION\r\n SELECT \'11\',12 UNION\r\n SELECT \'12\',13 UNION\r\n SELECT \'12+\',14) pers,\r\n (SELECT distinctrow moc.code, moc.name\r\n FROM m_office mo2\r\n INNER JOIN m_office ounder2 ON ounder2.hierarchy \r\n LIKE CONCAT(mo2.hierarchy, \'%\')\r\nAND ounder2.hierarchy like CONCAT(\'${currentUserHierarchy}\', \'%\')\r\n INNER JOIN m_client mc2 ON mc2.office_id=ounder2.id\r\n INNER JOIN m_loan ml2 ON ml2.client_id = mc2.id\r\n INNER JOIN m_organisation_currency moc ON moc.code = ml2.currency_code\r\n WHERE ml2.loan_status_id=300 /* active */\r\n AND mo2.id=${officeId}\r\nAND (ml2.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")) curs) periods\r\n\r\n\r\nLEFT JOIN /* table of aging periods per currency with gaps if no applicable loans */\r\n(SELECT \r\n z.currency, z.arrPeriod, \r\n COUNT(z.loanId) as loanId, SUM(z.principal) as principal, SUM(z.interest) as interest, \r\n SUM(z.prinPaid) as prinPaid, SUM(z.intPaid) as intPaid, \r\n SUM(z.prinOverdue) as prinOverdue, SUM(z.intOverdue) as intOverdue\r\nFROM\r\n /*derived table just used to get arrPeriod value (was much slower to\r\n duplicate calc of minOverdueDate in inner query)\r\nmight not be now with derived fields but didn’t check */\r\n (SELECT x.loanId, x.currency, x.principal, x.interest, x.prinPaid, x.intPaid, x.prinOverdue, x.intOverdue,\r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<1, \'On Schedule\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<8, \'1\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<15, \'2\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<22, \'3\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<29, \'4\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<36, \'5\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<43, \'6\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<50, \'7\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<57, \'8\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<64, \'9\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<71, \'10\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<78, \'11\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<85, \'12\',\r\n \'12+\'))))))))))))) AS arrPeriod\r\n\r\n FROM /* get the individual loan details */\r\n (SELECT ml.id AS loanId, ml.currency_code as currency,\r\n ml.principal_disbursed_derived as principal, \r\n ml.interest_charged_derived as interest, \r\n ml.principal_repaid_derived as prinPaid, \r\n ml.interest_repaid_derived intPaid,\r\n\r\n laa.principal_overdue_derived as prinOverdue,\r\n laa.interest_overdue_derived as intOverdue,\r\n\r\n IFNULL(laa.overdue_since_date_derived, curdate()) as minOverdueDate\r\n \r\n FROM m_office mo\r\n INNER JOIN m_office ounder ON ounder.hierarchy \r\n LIKE CONCAT(mo.hierarchy, \'%\')\r\nAND ounder.hierarchy like CONCAT(\'${currentUserHierarchy}\', \'%\')\r\n INNER JOIN m_client mc ON mc.office_id=ounder.id\r\n INNER JOIN m_loan ml ON ml.client_id = mc.id\r\n LEFT JOIN m_loan_arrears_aging laa on laa.loan_id = ml.id\r\n WHERE ml.loan_status_id=300 /* active */\r\n AND mo.id=${officeId}\r\n AND (ml.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\n GROUP BY ml.id) x\r\n ) z \r\nGROUP BY z.currency, z.arrPeriod ) ars ON ars.arrPeriod=periods.period_no and ars.currency = periods.currency\r\nORDER BY periods.currency, periods.pid','Loan amount in arrears by branch',1,1),(54,'Rescheduled Loans','Table',NULL,'Loan','SELECT \r\nconcat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nifnull(cur.display_symbol, ml.currency_code) as Currency, \r\nc.account_no as \"Client Account No.\",\r\nc.display_name AS \'Client Name\',\r\nml.account_no AS \'Loan Account No.\',\r\nmpl.name AS \'Product Name\',\r\nml.disbursedon_date AS \'Disbursed Date\',\r\nlt.transaction_date AS \'Written Off date\',\r\nml.principal_amount as \"Loan Amount\",\r\nifnull(lt.principal_portion_derived, 0) AS \'Rescheduled Principal\',\r\nifnull(lt.interest_portion_derived, 0) AS \'Rescheduled Interest\',\r\nifnull(lt.fee_charges_portion_derived,0) AS \'Rescheduled Fees\',\r\nifnull(lt.penalty_charges_portion_derived,0) AS \'Rescheduled Penalties\',\r\nn.note AS \'Reason For Rescheduling\',\r\nIFNULL(ms.display_name,\'-\') AS \'Loan Officer Name\'\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 ml ON ml.client_id = c.id\r\nJOIN m_product_loan mpl ON mpl.id=ml.product_id\r\nLEFT JOIN m_staff ms ON ms.id=ml.loan_officer_id\r\nJOIN m_loan_transaction lt ON lt.loan_id = ml.id\r\nLEFT JOIN m_note n ON n.loan_transaction_id = lt.id\r\nLEFT JOIN m_currency cur on cur.code = ml.currency_code\r\nWHERE lt.transaction_type_enum = 7 /*marked for rescheduling */\r\nAND lt.is_reversed is false \r\nAND ml.loan_status_id=602\r\nAND o.id=${officeId}\r\nAND (mpl.id=${loanProductId} OR ${loanProductId}=-1)\r\nAND lt.transaction_date BETWEEN \'${startDate}\' AND \'${endDate}\'\r\nAND (ml.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nORDER BY ounder.hierarchy, ifnull(cur.display_symbol, ml.currency_code), ml.account_no','Individual Lending Report. Rescheduled Loans. The ability to reschedule (or mark that you have rescheduled the loan elsewhere) is a legacy of the older Mifos product. Needed for migration.',1,1),(55,'Active Loans Passed Final Maturity','Table',NULL,'Loan','select concat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nifnull(cur.display_symbol, l.currency_code) as Currency,\r\nlo.display_name as \"Loan Officer\", \r\nc.display_name as \"Client\", l.account_no as \"Loan Account No.\", pl.`name` as \"Product\", \r\nf.`name` as Fund, \r\nl.principal_amount as \"Loan Amount\", \r\nl.annual_nominal_interest_rate as \" Annual Nominal Interest Rate\", \r\ndate(l.disbursedon_date) as \"Disbursed Date\", \r\ndate(l.expected_maturedon_date) as \"Expected Matured On\",\r\n\r\nl.principal_repaid_derived as \"Principal Repaid\",\r\nl.principal_outstanding_derived as \"Principal Outstanding\",\r\nlaa.principal_overdue_derived as \"Principal Overdue\",\r\n\r\nl.interest_repaid_derived as \"Interest Repaid\",\r\nl.interest_outstanding_derived as \"Interest Outstanding\",\r\nlaa.interest_overdue_derived as \"Interest Overdue\",\r\n\r\nl.fee_charges_repaid_derived as \"Fees Repaid\",\r\nl.fee_charges_outstanding_derived as \"Fees Outstanding\",\r\nlaa.fee_charges_overdue_derived as \"Fees Overdue\",\r\n\r\nl.penalty_charges_repaid_derived as \"Penalties Repaid\",\r\nl.penalty_charges_outstanding_derived as \"Penalties Outstanding\",\r\nlaa.penalty_charges_overdue_derived as \"Penalties 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\njoin m_product_loan pl on pl.id = l.product_id\r\nleft join m_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nleft join m_loan_arrears_aging laa on laa.loan_id = l.id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 300\r\nand l.expected_maturedon_date < curdate()\r\ngroup by l.id\r\norder by ounder.hierarchy, l.currency_code, c.account_no, l.account_no','Individual Client \n\nReport',1,1),(56,'Active Loans Passed Final Maturity Summary','Table',NULL,'Loan','select concat(repeat(\"..\", \r\n ((LENGTH(mo.`hierarchy`) - LENGTH(REPLACE(mo.`hierarchy`, \'.\', \'\')) - 1))), mo.`name`) as \"Office/Branch\", x.currency as Currency,\r\n x.client_count as \"No. of Clients\", x.active_loan_count as \"No. Active Loans\", x. arrears_loan_count as \"No. of Loans in Arrears\",\r\nx.principal as \"Total Loans Disbursed\", x.principal_repaid as \"Principal Repaid\", x.principal_outstanding as \"Principal Outstanding\", x.principal_overdue as \"Principal Overdue\",\r\nx.interest as \"Total Interest\", x.interest_repaid as \"Interest Repaid\", x.interest_outstanding as \"Interest Outstanding\", x.interest_overdue as \"Interest Overdue\",\r\nx.fees as \"Total Fees\", x.fees_repaid as \"Fees Repaid\", x.fees_outstanding as \"Fees Outstanding\", x.fees_overdue as \"Fees Overdue\",\r\nx.penalties as \"Total Penalties\", x.penalties_repaid as \"Penalties Repaid\", x.penalties_outstanding as \"Penalties Outstanding\", x.penalties_overdue as \"Penalties Overdue\",\r\n\r\n (case\r\n when ${parType} = 1 then\r\n cast(round((x.principal_overdue * 100) / x.principal_outstanding, 2) as char)\r\n when ${parType} = 2 then\r\n cast(round(((x.principal_overdue + x.interest_overdue) * 100) / (x.principal_outstanding + x.interest_outstanding), 2) as char)\r\n when ${parType} = 3 then\r\n cast(round(((x.principal_overdue + x.interest_overdue + x.fees_overdue) * 100) / (x.principal_outstanding + x.interest_outstanding + x.fees_outstanding), 2) as char)\r\n when ${parType} = 4 then\r\n cast(round(((x.principal_overdue + x.interest_overdue + x.fees_overdue + x.penalties_overdue) * 100) / (x.principal_outstanding + x.interest_outstanding + x.fees_outstanding + x.penalties_overdue), 2) as char)\r\n else \"invalid PAR Type\"\r\n end) as \"Portfolio at Risk %\"\r\n from m_office mo\r\njoin \r\n(select ounder.id as branch,\r\nifnull(cur.display_symbol, l.currency_code) as currency,\r\ncount(distinct(c.id)) as client_count, \r\ncount(distinct(l.id)) as active_loan_count,\r\ncount(distinct(laa.loan_id) ) as arrears_loan_count,\r\n\r\nsum(l.principal_disbursed_derived) as principal,\r\nsum(l.principal_repaid_derived) as principal_repaid,\r\nsum(l.principal_outstanding_derived) as principal_outstanding,\r\nsum(ifnull(laa.principal_overdue_derived,0)) as principal_overdue,\r\n\r\nsum(l.interest_charged_derived) as interest,\r\nsum(l.interest_repaid_derived) as interest_repaid,\r\nsum(l.interest_outstanding_derived) as interest_outstanding,\r\nsum(ifnull(laa.interest_overdue_derived,0)) as interest_overdue,\r\n\r\nsum(l.fee_charges_charged_derived) as fees,\r\nsum(l.fee_charges_repaid_derived) as fees_repaid,\r\nsum(l.fee_charges_outstanding_derived) as fees_outstanding,\r\nsum(ifnull(laa.fee_charges_overdue_derived,0)) as fees_overdue,\r\n\r\nsum(l.penalty_charges_charged_derived) as penalties,\r\nsum(l.penalty_charges_repaid_derived) as penalties_repaid,\r\nsum(l.penalty_charges_outstanding_derived) as penalties_outstanding,\r\nsum(ifnull(laa.penalty_charges_overdue_derived,0)) as penalties_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_loan_arrears_aging laa on laa.loan_id = l.id\r\n\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 300\r\nand l.expected_maturedon_date < curdate()\r\ngroup by ounder.id, l.currency_code) x on x.branch = mo.id\r\norder by mo.hierarchy, x.Currency',NULL,1,1),(57,'Active Loans in last installment','Table',NULL,'Loan','select concat(repeat(\"..\", \r\n ((LENGTH(lastInstallment.`hierarchy`) - LENGTH(REPLACE(lastInstallment.`hierarchy`, \'.\', \'\')) - 1))), lastInstallment.branch) as \"Office/Branch\",\r\nlastInstallment.Currency,\r\nlastInstallment.`Loan Officer`, \r\nlastInstallment.`Client Account No`, lastInstallment.`Client`, \r\nlastInstallment.`Loan Account No`, lastInstallment.`Product`, \r\nlastInstallment.`Fund`, lastInstallment.`Loan Amount`, \r\nlastInstallment.`Annual Nominal Interest Rate`, \r\nlastInstallment.`Disbursed`, lastInstallment.`Expected Matured On` ,\r\n\r\nl.principal_repaid_derived as \"Principal Repaid\",\r\nl.principal_outstanding_derived as \"Principal Outstanding\",\r\nlaa.principal_overdue_derived as \"Principal Overdue\",\r\n\r\nl.interest_repaid_derived as \"Interest Repaid\",\r\nl.interest_outstanding_derived as \"Interest Outstanding\",\r\nlaa.interest_overdue_derived as \"Interest Overdue\",\r\n\r\nl.fee_charges_repaid_derived as \"Fees Repaid\",\r\nl.fee_charges_outstanding_derived as \"Fees Outstanding\",\r\nlaa.fee_charges_overdue_derived as \"Fees Overdue\",\r\n\r\nl.penalty_charges_repaid_derived as \"Penalties Repaid\",\r\nl.penalty_charges_outstanding_derived as \"Penalties Outstanding\",\r\nlaa.penalty_charges_overdue_derived as \"Penalties Overdue\"\r\n\r\nfrom \r\n(select l.id as loanId, l.number_of_repayments, min(r.installment), \r\nounder.id, ounder.hierarchy, ounder.`name` as branch, \r\nifnull(cur.display_symbol, l.currency_code) as Currency,\r\nlo.display_name as \"Loan Officer\", c.account_no as \"Client Account No\",\r\nc.display_name as \"Client\", l.account_no as \"Loan Account No\", pl.`name` as \"Product\", \r\nf.`name` as Fund, l.principal_amount as \"Loan Amount\", \r\nl.annual_nominal_interest_rate as \"Annual Nominal Interest Rate\", \r\ndate(l.disbursedon_date) as \"Disbursed\", date(l.expected_maturedon_date) as \"Expected Matured On\"\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_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nleft join m_loan_repayment_schedule r on r.loan_id = l.id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 300\r\nand r.completed_derived is false\r\nand r.duedate >= curdate()\r\ngroup by l.id\r\nhaving l.number_of_repayments = min(r.installment)) lastInstallment\r\njoin m_loan l on l.id = lastInstallment.loanId\r\nleft join m_loan_arrears_aging laa on laa.loan_id = l.id\r\norder by lastInstallment.hierarchy, lastInstallment.Currency, lastInstallment.`Client Account No`, lastInstallment.`Loan Account No`','Individual Client \n\nReport',1,1),(58,'Active Loans in last installment Summary','Table',NULL,'Loan','select concat(repeat(\"..\", \r\n ((LENGTH(mo.`hierarchy`) - LENGTH(REPLACE(mo.`hierarchy`, \'.\', \'\')) - 1))), mo.`name`) as \"Office/Branch\", x.currency as Currency,\r\n x.client_count as \"No. of Clients\", x.active_loan_count as \"No. Active Loans\", x. arrears_loan_count as \"No. of Loans in Arrears\",\r\nx.principal as \"Total Loans Disbursed\", x.principal_repaid as \"Principal Repaid\", x.principal_outstanding as \"Principal Outstanding\", x.principal_overdue as \"Principal Overdue\",\r\nx.interest as \"Total Interest\", x.interest_repaid as \"Interest Repaid\", x.interest_outstanding as \"Interest Outstanding\", x.interest_overdue as \"Interest Overdue\",\r\nx.fees as \"Total Fees\", x.fees_repaid as \"Fees Repaid\", x.fees_outstanding as \"Fees Outstanding\", x.fees_overdue as \"Fees Overdue\",\r\nx.penalties as \"Total Penalties\", x.penalties_repaid as \"Penalties Repaid\", x.penalties_outstanding as \"Penalties Outstanding\", x.penalties_overdue as \"Penalties Overdue\",\r\n\r\n (case\r\n when ${parType} = 1 then\r\n cast(round((x.principal_overdue * 100) / x.principal_outstanding, 2) as char)\r\n when ${parType} = 2 then\r\n cast(round(((x.principal_overdue + x.interest_overdue) * 100) / (x.principal_outstanding + x.interest_outstanding), 2) as char)\r\n when ${parType} = 3 then\r\n cast(round(((x.principal_overdue + x.interest_overdue + x.fees_overdue) * 100) / (x.principal_outstanding + x.interest_outstanding + x.fees_outstanding), 2) as char)\r\n when ${parType} = 4 then\r\n cast(round(((x.principal_overdue + x.interest_overdue + x.fees_overdue + x.penalties_overdue) * 100) / (x.principal_outstanding + x.interest_outstanding + x.fees_outstanding + x.penalties_overdue), 2) as char)\r\n else \"invalid PAR Type\"\r\n end) as \"Portfolio at Risk %\"\r\n from m_office mo\r\njoin \r\n(select lastInstallment.branchId as branchId,\r\nlastInstallment.Currency,\r\ncount(distinct(lastInstallment.clientId)) as client_count, \r\ncount(distinct(lastInstallment.loanId)) as active_loan_count,\r\ncount(distinct(laa.loan_id) ) as arrears_loan_count,\r\n\r\nsum(l.principal_disbursed_derived) as principal,\r\nsum(l.principal_repaid_derived) as principal_repaid,\r\nsum(l.principal_outstanding_derived) as principal_outstanding,\r\nsum(ifnull(laa.principal_overdue_derived,0)) as principal_overdue,\r\n\r\nsum(l.interest_charged_derived) as interest,\r\nsum(l.interest_repaid_derived) as interest_repaid,\r\nsum(l.interest_outstanding_derived) as interest_outstanding,\r\nsum(ifnull(laa.interest_overdue_derived,0)) as interest_overdue,\r\n\r\nsum(l.fee_charges_charged_derived) as fees,\r\nsum(l.fee_charges_repaid_derived) as fees_repaid,\r\nsum(l.fee_charges_outstanding_derived) as fees_outstanding,\r\nsum(ifnull(laa.fee_charges_overdue_derived,0)) as fees_overdue,\r\n\r\nsum(l.penalty_charges_charged_derived) as penalties,\r\nsum(l.penalty_charges_repaid_derived) as penalties_repaid,\r\nsum(l.penalty_charges_outstanding_derived) as penalties_outstanding,\r\nsum(ifnull(laa.penalty_charges_overdue_derived,0)) as penalties_overdue\r\n\r\nfrom \r\n(select l.id as loanId, l.number_of_repayments, min(r.installment), \r\nounder.id as branchId, ounder.hierarchy, ounder.`name` as branch, \r\nifnull(cur.display_symbol, l.currency_code) as Currency,\r\nlo.display_name as \"Loan Officer\", c.id as clientId, c.account_no as \"Client Account No\",\r\nc.display_name as \"Client\", l.account_no as \"Loan Account No\", pl.`name` as \"Product\", \r\nf.`name` as Fund, l.principal_amount as \"Loan Amount\", \r\nl.annual_nominal_interest_rate as \"Annual Nominal Interest Rate\", \r\ndate(l.disbursedon_date) as \"Disbursed\", date(l.expected_maturedon_date) as \"Expected Matured On\"\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_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nleft join m_loan_repayment_schedule r on r.loan_id = l.id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.loan_status_id = 300\r\nand r.completed_derived is false\r\nand r.duedate >= curdate()\r\ngroup by l.id\r\nhaving l.number_of_repayments = min(r.installment)) lastInstallment\r\njoin m_loan l on l.id = lastInstallment.loanId\r\nleft join m_loan_arrears_aging laa on laa.loan_id = l.id\r\ngroup by lastInstallment.branchId) x on x.branchId = mo.id\r\norder by mo.hierarchy, x.Currency','Individual Client \n\nReport',1,1),(59,'Active Loans by Disbursal Period','Table',NULL,'Loan','select concat(repeat(\"..\", \r\n ((LENGTH(ounder.`hierarchy`) - LENGTH(REPLACE(ounder.`hierarchy`, \'.\', \'\')) - 1))), ounder.`name`) as \"Office/Branch\",\r\nifnull(cur.display_symbol, l.currency_code) as Currency,\r\nc.account_no as \"Client Account No\", c.display_name as \"Client\", l.account_no as \"Loan Account No\", pl.`name` as \"Product\", \r\nf.`name` as Fund, \r\nl.principal_amount as \"Loan Principal Amount\", \r\nl.annual_nominal_interest_rate as \" Annual Nominal Interest Rate\", \r\ndate(l.disbursedon_date) as \"Disbursed Date\", \r\n\r\nl.total_expected_repayment_derived as \"Total Loan (P+I+F+Pen)\",\r\nl.total_repayment_derived as \"Total Repaid (P+I+F+Pen)\",\r\nlo.display_name as \"Loan Officer\"\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_product_loan pl on pl.id = l.product_id\r\nleft join m_staff lo on lo.id = l.loan_officer_id\r\nleft join m_currency cur on cur.code = l.currency_code\r\nleft join m_fund f on f.id = l.fund_id\r\nleft join m_loan_arrears_aging laa on laa.loan_id = l.id\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.product_id = \"${loanProductId}\" or \"-1\" = \"${loanProductId}\")\r\nand (ifnull(l.loan_officer_id, -10) = \"${loanOfficerId}\" or \"-1\" = \"${loanOfficerId}\")\r\nand (ifnull(l.fund_id, -10) = ${fundId} or -1 = ${fundId})\r\nand (ifnull(l.loanpurpose_cv_id, -10) = ${loanPurposeId} or -1 = ${loanPurposeId})\r\nand l.disbursedon_date between \'${startDate}\' and \'${endDate}\'\r\nand l.loan_status_id = 300\r\ngroup by l.id\r\norder by ounder.hierarchy, l.currency_code, c.account_no, l.account_no','Individual Client \n\nReport',1,1),(61,'Aging Summary (Arrears in Months)','Table',NULL,'Loan','SELECT \r\n IFNULL(periods.currencyName, periods.currency) as currency, \r\n periods.period_no \'Days In Arrears\', \r\n IFNULL(ars.loanId, 0) \'No Of Loans\', \r\n IFNULL(ars.principal,0.0) \'Original Principal\', \r\n IFNULL(ars.interest,0.0) \'Original Interest\', \r\n IFNULL(ars.prinPaid,0.0) \'Principal Paid\', \r\n IFNULL(ars.intPaid,0.0) \'Interest Paid\', \r\n IFNULL(ars.prinOverdue,0.0) \'Principal Overdue\', \r\n IFNULL(ars.intOverdue,0.0)\'Interest Overdue\'\r\nFROM \r\n /* full table of aging periods/currencies used combo to ensure each line represented */\r\n (SELECT curs.code as currency, curs.name as currencyName, pers.* from\r\n (SELECT \'On Schedule\' period_no,1 pid UNION\r\n SELECT \'0 - 30\',2 UNION\r\n SELECT \'30 - 60\',3 UNION\r\n SELECT \'60 - 90\',4 UNION\r\n SELECT \'90 - 180\',5 UNION\r\n SELECT \'180 - 360\',6 UNION\r\n SELECT \'> 360\',7 ) pers,\r\n (SELECT distinctrow moc.code, moc.name\r\n FROM m_office mo2\r\n INNER JOIN m_office ounder2 ON ounder2.hierarchy \r\n LIKE CONCAT(mo2.hierarchy, \'%\')\r\nAND ounder2.hierarchy like CONCAT(\'${currentUserHierarchy}\', \'%\')\r\n INNER JOIN m_client mc2 ON mc2.office_id=ounder2.id\r\n INNER JOIN m_loan ml2 ON ml2.client_id = mc2.id\r\n INNER JOIN m_organisation_currency moc ON moc.code = ml2.currency_code\r\n WHERE ml2.loan_status_id=300 /* active */\r\n AND mo2.id=${officeId}\r\nAND (ml2.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")) curs) periods\r\n\r\n\r\nLEFT JOIN /* table of aging periods per currency with gaps if no applicable loans */\r\n(SELECT \r\n z.currency, z.arrPeriod, \r\n COUNT(z.loanId) as loanId, SUM(z.principal) as principal, SUM(z.interest) as interest, \r\n SUM(z.prinPaid) as prinPaid, SUM(z.intPaid) as intPaid, \r\n SUM(z.prinOverdue) as prinOverdue, SUM(z.intOverdue) as intOverdue\r\nFROM\r\n /*derived table just used to get arrPeriod value (was much slower to\r\n duplicate calc of minOverdueDate in inner query)\r\nmight not be now with derived fields but didn’t check */\r\n (SELECT x.loanId, x.currency, x.principal, x.interest, x.prinPaid, x.intPaid, x.prinOverdue, x.intOverdue,\r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<1, \'On Schedule\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<31, \'0 - 30\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<61, \'30 - 60\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<91, \'60 - 90\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<181, \'90 - 180\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<361, \'180 - 360\', \r\n \'> 360\')))))) AS arrPeriod\r\n\r\n FROM /* get the individual loan details */\r\n (SELECT ml.id AS loanId, ml.currency_code as currency,\r\n ml.principal_disbursed_derived as principal, \r\n ml.interest_charged_derived as interest, \r\n ml.principal_repaid_derived as prinPaid, \r\n ml.interest_repaid_derived intPaid,\r\n\r\n laa.principal_overdue_derived as prinOverdue,\r\n laa.interest_overdue_derived as intOverdue,\r\n\r\n IFNULL(laa.overdue_since_date_derived, curdate()) as minOverdueDate\r\n \r\n FROM m_office mo\r\n INNER JOIN m_office ounder ON ounder.hierarchy \r\n LIKE CONCAT(mo.hierarchy, \'%\')\r\nAND ounder.hierarchy like CONCAT(\'${currentUserHierarchy}\', \'%\')\r\n INNER JOIN m_client mc ON mc.office_id=ounder.id\r\n INNER JOIN m_loan ml ON ml.client_id = mc.id\r\n LEFT JOIN m_loan_arrears_aging laa on laa.loan_id = ml.id\r\n WHERE ml.loan_status_id=300 /* active */\r\n AND mo.id=${officeId}\r\n AND (ml.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\n GROUP BY ml.id) x\r\n ) z \r\nGROUP BY z.currency, z.arrPeriod ) ars ON ars.arrPeriod=periods.period_no and ars.currency = periods.currency\r\nORDER BY periods.currency, periods.pid','Loan amount in arrears by branch',1,1),(91,'Loan Account Schedule','Pentaho',NULL,'Loan',NULL,NULL,1,0),(92,'Branch Expected Cash Flow','Pentaho',NULL,'Loan',NULL,NULL,1,1),(93,'Expected Payments By Date - Basic','Table',NULL,'Loan','SELECT \r\n ounder.name \'Office\', \r\n IFNULL(ms.display_name,\'-\') \'Loan Officer\',\r\n mc.account_no \'Client Account Number\',\r\n mc.display_name \'Name\',\r\n mp.name \'Product\',\r\n ml.account_no \'Loan Account Number\',\r\n mr.duedate \'Due Date\',\r\n mr.installment \'Installment\',\r\n cu.display_symbol \'Currency\',\r\n mr.principal_amount- IFNULL(mr.principal_completed_derived,0) \'Principal Due\',\r\n mr.interest_amount- IFNULL(IFNULL(mr.interest_completed_derived,mr.interest_waived_derived),0) \'Interest Due\', \r\n IFNULL(mr.fee_charges_amount,0)- IFNULL(IFNULL(mr.fee_charges_completed_derived,mr.fee_charges_waived_derived),0) \'Fees Due\', \r\n IFNULL(mr.penalty_charges_amount,0)- IFNULL(IFNULL(mr.penalty_charges_completed_derived,mr.penalty_charges_waived_derived),0) \'Penalty Due\',\r\n (mr.principal_amount- IFNULL(mr.principal_completed_derived,0)) +\r\n (mr.interest_amount- IFNULL(IFNULL(mr.interest_completed_derived,mr.interest_waived_derived),0)) + \r\n (IFNULL(mr.fee_charges_amount,0)- IFNULL(IFNULL(mr.fee_charges_completed_derived,mr.fee_charges_waived_derived),0)) + \r\n (IFNULL(mr.penalty_charges_amount,0)- IFNULL(IFNULL(mr.penalty_charges_completed_derived,mr.penalty_charges_waived_derived),0)) \'Total Due\', \r\n mlaa.total_overdue_derived \'Total Overdue\'\r\n \r\n FROM m_office mo\r\n JOIN m_office ounder ON ounder.hierarchy LIKE CONCAT(mo.hierarchy, \'%\')\r\n \r\n AND ounder.hierarchy like CONCAT(\'${currentUserHierarchy}\', \'%\')\r\n \r\n LEFT JOIN m_client mc ON mc.office_id=ounder.id\r\n LEFT JOIN m_loan ml ON ml.client_id=mc.id AND ml.loan_status_id=300\r\n LEFT JOIN m_loan_arrears_aging mlaa ON mlaa.loan_id=ml.id\r\n LEFT JOIN m_loan_repayment_schedule mr ON mr.loan_id=ml.id AND mr.completed_derived=0\r\n LEFT JOIN m_product_loan mp ON mp.id=ml.product_id\r\n LEFT JOIN m_staff ms ON ms.id=ml.loan_officer_id\r\n LEFT JOIN m_currency cu ON cu.code=ml.currency_code\r\n WHERE mo.id=${officeId}\r\n AND (IFNULL(ml.loan_officer_id, -10) = \"${loanOfficerId}\" OR \"-1\" = \"${loanOfficerId}\")\r\n AND mr.duedate BETWEEN \'${startDate}\' AND \'${endDate}\'\r\n ORDER BY ounder.id,mr.duedate,ml.account_no','Test',1,1),(94,'Expected Payments By Date - Formatted','Pentaho',NULL,'Loan',NULL,NULL,1,1); +INSERT INTO `stretchy_parameter` VALUES (1,'startDateSelect','startDate','startDate','date','date','today',NULL,NULL,NULL,NULL,NULL),(2,'endDateSelect','endDate','endDate','date','date','today',NULL,NULL,NULL,NULL,NULL),(3,'obligDateTypeSelect','obligDateType','obligDateType','select','number','0',NULL,NULL,NULL,'select * from\r\n(select 1 as id, \"Closed\" as `name` union all\r\nselect 2, \"Disbursal\" ) x\r\norder by x.`id`',NULL),(5,'OfficeIdSelectOne','officeId','Office','select','number','0',NULL,'Y',NULL,'select id, \r\nconcat(substring(\"........................................\", 1, \r\n \n\n((LENGTH(`hierarchy`) - LENGTH(REPLACE(`hierarchy`, \'.\', \'\')) - 1) * 4)), \r\n `name`) as tc\r\nfrom m_office\r\nwhere hierarchy like concat\n\n(\'${currentUserHierarchy}\', \'%\')\r\norder by hierarchy',NULL),(6,'loanOfficerIdSelectAll','loanOfficerId','Loan Officer','select','number','0',NULL,NULL,'Y','(select lo.id, lo.display_name as `Name` \r\nfrom m_office o \r\njoin m_office ounder on ounder.hierarchy like concat(o.hierarchy, \'%\')\r\njoin m_staff lo on lo.office_id = ounder.id\r\nwhere lo.is_loan_officer = true\r\nand o.id = ${officeId})\r\nunion all\r\n(select -10, \'-\')\r\norder by 2',5),(10,'currencyIdSelectAll','currencyId','Currency','select','number','0',NULL,NULL,'Y','select `code`, `name`\r\nfrom m_organisation_currency\r\norder by `code`',NULL),(20,'fundIdSelectAll','fundId','Fund','select','number','0',NULL,NULL,'Y','(select id, `name`\r\nfrom m_fund)\r\nunion all\r\n(select -10, \'-\')\r\norder by 2',NULL),(25,'loanProductIdSelectAll','loanProductId','Product','select','number','0',NULL,NULL,'Y','select p.id, p.`name`\r\nfrom m_product_loan p\r\nwhere p.currency_code = \'${currencyId}\'\r\norder by 2',10),(26,'loanPurposeIdSelectAll','loanPurposeId','Loan Purpose','select','number','0',NULL,NULL,'Y','select -10 as id, \'-\' as code_value\r\nunion all\r\nselect * from (select v.id, v.code_value\r\nfrom m_code c\r\njoin m_code_value v on v.code_id = c.id\r\nwhere c.code_name = \"loanPurpose\"\r\norder by v.order_position) x',NULL),(100,'parTypeSelect','parType','parType','select','number','0',NULL,NULL,NULL,'select * from\r\n(select 1 as id, \"Principal Only\" as `name` union all\r\nselect 2, \"Principal + Interest\" union all\r\nselect 3, \"Principal + Interest + Fees\" union all\r\nselect 4, \"Principal + Interest + Fees + Penalties\") x\r\norder by x.`id`',NULL),(1001,'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\n \n\nrp.parameter_id, rp.report_parameter_name, p.parameter_name\r\n from stretchy_report r\r\n left join stretchy_report_parameter rp on rp.report_id = r.report_id\r\n \n\nleft join stretchy_parameter p on p.parameter_id = rp.parameter_id\r\n where r.use_report is true\r\n and exists\r\n (\r\n select \'f\'\r\n from m_appuser_role ur \n\n\r\n join m_role r on r.id = ur.role_id\r\n join m_role_permission rp on rp.role_id = r.id\r\n join m_permission p on p.id = rp.permission_id\r\n where \n\nur.appuser_id = ${currentUserId}\r\n and (p.code in (\'ALL_FUNCTIONS_READ\', \'ALL_FUNCTIONS\') or p.code = concat(\"READ_\", r.report_name))\r\n )\r\n order by \n\nr.report_category, r.report_name, rp.parameter_id',NULL),(1002,'FullParameterList',NULL,'n/a','n/a','n/a','n/a','Y',NULL,NULL,'select sp.parameter_name, sp.parameter_variable, sp.parameter_label, sp.parameter_displayType, \r\nsp.parameter_FormatType, sp.parameter_default, sp.selectOne, sp.selectAll, spp.parameter_name as parentParameterName\r\nfrom stretchy_parameter sp\r\nleft join stretchy_parameter spp on spp.parameter_id = sp.parent_parameter_id\r\nwhere sp.special is null\r\nand exists \r\n (select \'f\' \r\n from stretchy_report sr\r\n join stretchy_report_parameter srp on srp.report_id = sr.report_id\r\n where sr.report_name in(${reportListing})\r\n and srp.parameter_id = sp.parameter_id\r\n )\r\norder by sp.parameter_id',NULL),(1003,'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, \n\nr.report_category,\r\n rp.parameter_id, rp.report_parameter_name, p.parameter_name\r\n from stretchy_report r\r\n left join stretchy_report_parameter rp on \n\nrp.report_id = r.report_id\r\n left join stretchy_parameter p on p.parameter_id = rp.parameter_id\r\n where r.report_category = \'${reportCategory}\'\r\n and \n\nr.use_report is true\r\n and exists\r\n (\r\n select \'f\'\r\n from m_appuser_role ur \r\n join m_role r on r.id = ur.role_id\r\n join m_role_permission rp on \n\nrp.role_id = r.id\r\n join m_permission p on p.id = rp.permission_id\r\n where ur.appuser_id = ${currentUserId}\r\n and (p.code in (\'ALL_FUNCTIONS_READ\', \n\n\'ALL_FUNCTIONS\') or p.code = concat(\"READ_\", r.report_name))\r\n )\r\n order by r.report_category, r.report_name, rp.parameter_id',NULL); +INSERT INTO `stretchy_report_parameter` VALUES (1,5,NULL),(2,5,NULL),(2,6,NULL),(2,10,NULL),(2,20,NULL),(2,25,NULL),(2,26,NULL),(5,5,NULL),(5,6,NULL),(5,10,NULL),(5,20,NULL),(5,25,NULL),(5,26,NULL),(6,5,NULL),(6,6,NULL),(6,10,NULL),(6,20,NULL),(6,25,NULL),(6,26,NULL),(7,5,NULL),(7,6,NULL),(7,10,NULL),(7,20,NULL),(7,25,NULL),(7,26,NULL),(8,5,NULL),(8,6,NULL),(8,10,NULL),(8,25,NULL),(8,26,NULL),(11,5,NULL),(11,6,NULL),(11,10,NULL),(11,20,NULL),(11,25,NULL),(11,26,NULL),(11,100,NULL),(12,5,NULL),(12,6,NULL),(12,10,NULL),(12,20,NULL),(12,25,NULL),(12,26,NULL),(13,1,NULL),(13,2,NULL),(13,3,NULL),(13,5,NULL),(13,6,NULL),(13,10,NULL),(13,20,NULL),(13,25,NULL),(13,26,NULL),(14,1,NULL),(14,2,NULL),(14,3,NULL),(14,5,NULL),(14,6,NULL),(14,10,NULL),(14,20,NULL),(14,25,NULL),(14,26,NULL),(15,5,NULL),(15,6,NULL),(15,10,NULL),(15,20,NULL),(15,25,NULL),(15,26,NULL),(15,100,NULL),(16,5,NULL),(16,6,NULL),(16,10,NULL),(16,20,NULL),(16,25,NULL),(16,26,NULL),(16,100,NULL),(20,1,NULL),(20,2,NULL),(20,10,NULL),(20,20,NULL),(21,1,NULL),(21,2,NULL),(21,5,NULL),(21,10,NULL),(21,20,NULL),(48,5,'branch'),(48,2,'date'),(49,5,'branch'),(49,1,'fromDate'),(49,2,'toDate'),(50,5,'branch'),(50,1,'fromDate'),(50,2,'toDate'),(51,1,NULL),(51,2,NULL),(51,5,NULL),(51,10,NULL),(51,25,NULL),(52,5,NULL),(53,5,NULL),(53,10,NULL),(54,1,NULL),(54,2,NULL),(54,5,NULL),(54,10,NULL),(54,25,NULL),(55,5,NULL),(55,6,NULL),(55,10,NULL),(55,20,NULL),(55,25,NULL),(55,26,NULL),(56,5,NULL),(56,6,NULL),(56,10,NULL),(56,20,NULL),(56,25,NULL),(56,26,NULL),(56,100,NULL),(57,5,NULL),(57,6,NULL),(57,10,NULL),(57,20,NULL),(57,25,NULL),(57,26,NULL),(58,5,NULL),(58,6,NULL),(58,10,NULL),(58,20,NULL),(58,25,NULL),(58,26,NULL),(58,100,NULL),(59,1,NULL),(59,2,NULL),(59,5,NULL),(59,6,NULL),(59,10,NULL),(59,20,NULL),(59,25,NULL),(59,26,NULL),(61,5,NULL),(61,10,NULL),(92,1,'fromDate'),(92,5,'selectOffice'),(92,2,'toDate'),(93,1,NULL),(93,2,NULL),(93,5,NULL),(93,6,NULL),(94,2,'endDate'),(94,6,'loanOfficerId'),(94,5,'officeId'),(94,1,'startDate'); + +insert into m_permission(grouping, `code`, entity_name, action_name, can_maker_checker) +select 'report', concat('READ_', r.report_name), r.report_name, 'READ', false +from stretchy_report r; + diff --git a/mifosng-provider/build.gradle b/mifosng-provider/build.gradle index 4df413d56..26b2b42ce 100644 --- a/mifosng-provider/build.gradle +++ b/mifosng-provider/build.gradle @@ -156,6 +156,7 @@ dependencies { [group: 'com.lowagie', name: 'itext', version: '2.1.7'], [group: 'com.lowagie', name: 'itext-rtf', version: '2.1.7'], [group: 'org.mnode.ical4j', name: 'ical4j', version: '1.0.4'], + [group: 'com.googlecode.flyway', name: 'flyway-maven-plugin', version: '2.1.1'] ) testCompile 'junit:junit:4.10', @@ -229,6 +230,32 @@ task integrationTest(type:Test){ } +apply plugin: 'flyway' +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath 'com.github.ben-manes:gradle-flyway-plugin:0.2' + classpath 'mysql:mysql-connector-java:5.1.22' + } +} + + +flyway { + url = "jdbc:mysql://localhost:3306/mifostenant-default" + user = 'root' + password = 'mysql' + locations = [ + 'filesystem:../mifosng-db/migrations', + ] + + //$dbName $dbUser $dbPassword + +} + + /* * Support publication of artifacts versioned by topic branch. * CI builds supply `-P BRANCH_NAME=` to gradle at build time.