+
+
Calculate loan repayment schedule
+
+
+ Mandatory Fields |
+
+
+ | productId, principal, loanTermFrequency,
+ loanTermFrequencyType, numberOfRepayments, repaymentEvery,
+ repaymentFrequencyType, interestRatePerPeriod,
+ interestRateFrequencyType, amortizationType, interestType,
+ interestCalculationPeriodType, expectedDisbursementDate,
+ transactionProcessingStrategyId |
+
+
+
+
+
+POST https://DomainName/api/v1/loans?command=calculateLoanSchedule
+
+
+POST loans?command=calculateLoanSchedule
+Content-Type: application/json
+Request Body:
+{
+ "dateFormat": "dd MMMM yyyy",
+ "locale": "en_GB",
+ "productId": 1,
+ "principal": "100,000.00",
+ "loanTermFrequency": 12,
+ "loanTermFrequencyType": 2,
"numberOfRepayments": 12,
"repaymentEvery": 1,
- "repaymentFrequencyType": {
- "id": 2,
- "code": "repaymentFrequency.periodFrequencyType.months",
- "value": "Months"
- },
- "transactionProcessingStrategyId": 1,
- "amortizationType": {
- "id": 1,
- "code": "amortizationType.equal.installments",
- "value": "Equal installments"
- },
+ "repaymentFrequencyType": 2,
"interestRatePerPeriod": 2,
- "interestRateFrequencyType": {
- "id": 2,
- "code": "interestRateFrequency.periodFrequencyType.months",
- "value": "Per month"
+ "interestRateFrequencyType": 2,
+ "amortizationType": 1,
+ "interestType": 0,
+ "interestCalculationPeriodType": 1,
+ "expectedDisbursementDate": "20 September 2011",
+ "transactionProcessingStrategyId": 2
+}
+
+
+{
+ "loanTermInDays": 366,
+ "currency": {
+ "code": "UGX",
+ "name": "Uganda Shilling",
+ "decimalPlaces": 2,
+ "displaySymbol": "USh",
+ "nameCode": "currency.UGX",
+ "displayLabel": "Uganda Shilling (USh)"
+ },
+ "cumulativePrincipalDisbursed": 100000,
+ "cumulativePrincipalDue": 100000,
+ "cumulativePrincipalOutstanding": 0,
+ "cumulativeInterestExpected": 13471.52,
+ "cumulativeFeeChargesToDate": 0,
+ "totalCostOfLoan": 13471.52,
+ "totalExpectedRepayment": 113471.52,
+ "totalPaidToDate": 0,
+ "totalWaivedToDate": 0,
+ "totalWrittenOffToDate": 0,
+ "totalOutstanding": 113471.52,
+ "totalInArrears": 0,
+ "periods": [
+ {
+ "period": 0,
+ "dueDate": [
+ 2011,
+ 9,
+ 20
+ ],
+ "principalDisbursed": 100000,
+ "principalLoanBalanceOutstanding": 100000,
+ "feeChargesDue": 0,
+ "feeChargesOutstanding": 0,
+ "totalOriginalDueForPeriod": 0,
+ "totalDueForPeriod": 0,
+ "totalOutstandingForPeriod": 0,
+ "totalOverdue": 0,
+ "totalActualCostOfLoanForPeriod": 0
},
- "annualInterestRate": 24,
- "interestType": {
- "id": 0,
- "code": "interestType.declining.balance",
- "value": "Declining Balance"
+ {
+ "period": 1,
+ "fromDate": [
+ 2011,
+ 9,
+ 20
+ ],
+ "dueDate": [
+ 2011,
+ 10,
+ 20
+ ],
+ "daysInPeriod": 30,
+ "principalOriginalDue": 7455.96,
+ "principalDue": 7455.96,
+ "principalOutstanding": 7455.96,
+ "principalLoanBalanceOutstanding": 92544.04,
+ "interestOriginalDue": 2000,
+ "interestDue": 2000,
+ "interestOutstanding": 2000,
+ "feeChargesDue": 0,
+ "penaltyChargesDue": 0,
+ "totalOriginalDueForPeriod": 9455.96,
+ "totalDueForPeriod": 9455.96,
+ "totalPaidForPeriod": 0,
+ "totalOutstandingForPeriod": 9455.96,
+ "totalOverdue": 9455.96,
+ "totalActualCostOfLoanForPeriod": 2000
},
- "interestCalculationPeriodType": {
- "id": 1,
- "code": "interestCalculationPeriodType.same.as.repayment.period",
- "value": "Same as repayment period"
- },
- "submittedOnDate": [2011,9,20],
- "expectedDisbursementDate": [2011,9,20],
- "expectedMaturityDate": [2011,9,20],
- "lifeCycleStatusDate": [2011,9,20]
+ ...
+ {
+ "period": 12,
+ "fromDate": [2012,8,20],
+ "dueDate": [2012,9,20],
+ "daysInPeriod": 31,
+ "principalOriginalDue": 9270.56,
+ "principalDue": 9270.56,
+ "principalOutstanding": 9270.56,
+ "principalLoanBalanceOutstanding": 0,
+ "interestOriginalDue": 185.4,
+ "interestDue": 185.4,
+ "interestOutstanding": 185.4,
+ "feeChargesDue": 0,
+ "penaltyChargesDue": 0,
+ "totalOriginalDueForPeriod": 9455.96,
+ "totalDueForPeriod": 9455.96,
+ "totalPaidForPeriod": 0,
+ "totalOutstandingForPeriod": 9455.96,
+ "totalOverdue": 9455.96,
+ "totalActualCostOfLoanForPeriod": 185.4
+ }
+ ]
}
@@ -2902,24 +3120,7 @@ GET https://DomainName/api/v1/loans/{loanId}
-
Create a New Loan / Submit a Loan Application
-
Arguments
-
- - command
- -
- String Optional, case-insensitive
-
- -
- The default action is to Submit a New Loan Application
- ("Submitted and awaiting approval" status).
-
- - If "?command=calculateLoanSchedule" is added to the URL
- then no update is made but the loan schedule (as would have been
- if the loan had been submitted) is returned. This gives the
- ability to try out various loan options and 'preview' the
- schedule before committing to it.
-
-
+
Submit a new Loan Application
Mandatory Fields |
@@ -2974,40 +3175,23 @@ Request Body:
-
+
+
-
Approve, Undo Approval, Disburse, Undo Disbursal, Reject
- or Withdraw a Loan Application
-
Arguments
-
- - command
- -
- String Mandatory, case-insensitive
-
- - 'approve' : Approve Loan
- - 'disburse' : Disburse Loan
- - 'reject' : Reject Loan
- - 'withdrewbyclient' : Client Withdrew Loan Application
- - 'undoapproval' : Undo Loan Approval
- - 'undodisbursal' : Undo Loan Disbursal
- - 'assignloanofficer' : Assign Loan Officer
- - 'unassignloanofficer' : Unassign Loan Officer as of today or in past but not beyond assigned date. Does not support unassigning in future date
-
-
+
Approve Loan Application
Mandatory Fields |
- | eventDate |
+ approvedOnDate |
-POST https://DomainName/api/v1/loans/{loanId}
+POST https://DomainName/api/v1/loans/{loanId}?command=approve
POST loans/1?command=approve
@@ -3016,31 +3200,293 @@ Request Body:
{
"locale": "en",
"dateFormat": "dd MMMM yyyy",
- "eventDate": "20 September 2011",
- "note": "and event note is added"
+ "approvedOnDate": "20 September 2011",
+ "note": "Loan approval note"
}
{
- "officeId": 1,
- "clientId": 1,
- "loanId": 2,
- "resourceId": 2,
- "changes": {
- "status": {
- "id": 200,
- "code": "loanStatusType.approved",
- "value": "Approved"
- },
- "locale": "en",
- "dateFormat": "dd MMMM yyyy",
- "approvedOnDate": "20 September 2011",
- "note": "and event note is added"
- }
+ "officeId": 1,
+ "clientId": 1,
+ "loanId": 1,
+ "resourceId": 1,
+ "changes": {
+ "status": {
+ "id": 200,
+ "code": "loanStatusType.approved",
+ "value": "Approved",
+ "pendingApproval": false,
+ "waitingForDisbursal": true,
+ "active": false,
+ "closedObligationsMet": false,
+ "closedWrittenOff": false,
+ "closedRescheduled": false,
+ "closed": false,
+ "overpaid": false
+ },
+ "locale": "en",
+ "dateFormat": "dd MMMM yyyy",
+ "approvedOnDate": "20 September 2011",
+ "note": "Loan approval note"
+ }
}
+
+
+
+
+
Undo Loan Application Approval
+
+
+
+POST https://DomainName/api/v1/loans/{loanId}?command=undoApproval
+
+
+POST loans/1?command=approve
+Content-Type: application/json
+
+
+{
+ "officeId": 1,
+ "clientId": 1,
+ "loanId": 1,
+ "resourceId": 1,
+ "changes": {
+ "status": {
+ "id": 100,
+ "code": "loanStatusType.submitted.and.pending.approval",
+ "value": "Submitted and pending approval",
+ "pendingApproval": true,
+ "waitingForDisbursal": false,
+ "active": false,
+ "closedObligationsMet": false,
+ "closedWrittenOff": false,
+ "closedRescheduled": false,
+ "closed": false,
+ "overpaid": false
+ },
+ "approvedOnDate": ""
+ }
+}
+
+
+
+
+
+
+
+
Reject Loan Application
+
+
+ Mandatory Fields |
+
+
+ | rejectedOnDate |
+
+
+
+
+
+POST https://DomainName/api/v1/loans/{loanId}?command=reject
+
+
+POST loans/1?command=reject
+Content-Type: application/json
+Request Body:
+{
+ "locale": "en",
+ "dateFormat": "dd MMMM yyyy",
+ "rejectedOnDate": "20 September 2011",
+ "note": "Loan rejection reason."
+}
+
+
+{
+ "officeId": 1,
+ "clientId": 1,
+ "loanId": 1,
+ "resourceId": 1,
+ "changes": {
+ "status": {
+ "id": 500,
+ "code": "loanStatusType.rejected",
+ "value": "Rejected",
+ "pendingApproval": false,
+ "waitingForDisbursal": false,
+ "active": false,
+ "closedObligationsMet": false,
+ "closedWrittenOff": false,
+ "closedRescheduled": false,
+ "closed": false,
+ "overpaid": false
+ },
+ "locale": "en",
+ "dateFormat": "dd MMMM yyyy",
+ "rejectedOnDate": "20 September 2011",
+ "closedOnDate": "20 September 2011"
+ }
+}
+
+
+
+
+
+
+
+
Applicant Withdraws from Loan Application
+
+
+ Mandatory Fields |
+
+
+ | withdrawnOnDate |
+
+
+
+
+
+POST https://DomainName/api/v1/loans/{loanId}?command=withdrawnByApplicant
+
+
+POST loans/1?command=withdrawnByApplicant
+Content-Type: application/json
+Request Body:
+{
+ "locale": "en",
+ "dateFormat": "dd MMMM yyyy",
+ "withdrawnOnDate": "20 September 2011",
+ "note": "Reason loan applicant withdrew from application."
+}
+
+
+{
+ "officeId": 1,
+ "clientId": 1,
+ "loanId": 2,
+ "resourceId": 2,
+ "changes": {
+ "status": {
+ "id": 400,
+ "code": "loanStatusType.withdrawn.by.client",
+ "value": "Withdrawn by applicant",
+ "pendingApproval": false,
+ "waitingForDisbursal": false,
+ "active": false,
+ "closedObligationsMet": false,
+ "closedWrittenOff": false,
+ "closedRescheduled": false,
+ "closed": false,
+ "overpaid": false
+ },
+ "locale": "en",
+ "dateFormat": "dd MMMM yyyy",
+ "withdrawnOnDate": "20 September 2011",
+ "closedOnDate": "20 September 2011"
+ }
+}
+
+
+
+
+
+
+
+
Disburse Loan
+
+
+ Mandatory Fields |
+
+
+ | actualDisbursementDate |
+
+
+
+
+
+POST https://DomainName/api/v1/loans/{loanId}?command=disburse
+
+
+POST loans/1?command=disburse
+Content-Type: application/json
+Request Body:
+{
+ "locale": "en",
+ "dateFormat": "dd MMMM yyyy",
+ "actualDisbursementDate": "20 September 2011",
+ "note": "Any additional info related to disbursement of funds to applicant."
+}
+
+
+{
+ "officeId": 1,
+ "clientId": 1,
+ "loanId": 4,
+ "resourceId": 4,
+ "changes": {
+ "status": {
+ "id": 300,
+ "code": "loanStatusType.active",
+ "value": "Active",
+ "pendingApproval": false,
+ "waitingForDisbursal": false,
+ "active": true,
+ "closedObligationsMet": false,
+ "closedWrittenOff": false,
+ "closedRescheduled": false,
+ "closed": false,
+ "overpaid": false
+ },
+ "locale": "en",
+ "dateFormat": "dd MMMM yyyy",
+ "actualDisbursementDate": "20 September 2011"
+ }
+}
+
+
+
+
+
+
+
+
Undo Loan Disbursal
+
+
+
+POST https://DomainName/api/v1/loans/{loanId}?command=undoDisbursal
+
+
+POST loans/1?command=undoDisbursal
+Content-Type: application/json
+
+
+{
+ "officeId": 1,
+ "clientId": 1,
+ "loanId": 4,
+ "resourceId": 4,
+ "changes": {
+ "status": {
+ "id": 200,
+ "code": "loanStatusType.approved",
+ "value": "Approved",
+ "pendingApproval": false,
+ "waitingForDisbursal": true,
+ "active": false,
+ "closedObligationsMet": false,
+ "closedWrittenOff": false,
+ "closedRescheduled": false,
+ "closed": false,
+ "overpaid": false
+ },
+ "actualDisbursementDate": ""
+ }
+}
+
+
+
+
-
+
| LOAN |
+ loans?calculateLoanSchedule |
+ Calculate Loan Repayment Schedule |
+ |
+ |
+ |
+
+
+ |
loans |
- Create a New Loan / Submit a
- Loan Application |
+ Submit a new Loan Application |
|
|
|
@@ -10162,13 +10615,59 @@ Content-Type: application/json
|
loans/{loanId} |
- Approve, Undo Approval,
- Disburse, Undo Disbursal, Reject a Loan or Withdraw a Loan
- Application |
+ |
Retrieve a Loan |
|
Delete a Loan |
+
+ |
+ loans/{loanId}?command=approve |
+ Approve Loan Application |
+ |
+ |
+ |
+
+
+ |
+ loans/{loanId}?command=undoApproval |
+ Undo Loan Application Approval |
+ |
+ |
+ |
+
+
+ |
+ loans/{loanId}?command=reject |
+ Reject Loan Application |
+ |
+ |
+ |
+
+
+ |
+ loans/{loanId}?command=withdraw |
+ Withdraw Loan Application |
+ |
+ |
+ |
+
+
+ |
+ loans/{loanId}?command=disburse |
+ Disburse Loan |
+ |
+ |
+ |
+
+
+ |
+ loans/{loanId}?command=undoDisbursal |
+ Undo Loan Application Disbursal |
+ |
+ |
+ |
+
|
loans/{loanId}/transactions |
diff --git a/mifosng-db/0002-mifosx-base-reference-data-utf8.sql b/mifosng-db/0002-mifosx-base-reference-data-utf8.sql
index 70ca81bd1..587f1bc3a 100644
--- a/mifosng-db/0002-mifosx-base-reference-data-utf8.sql
+++ b/mifosng-db/0002-mifosx-base-reference-data-utf8.sql
@@ -206,8 +206,8 @@ INSERT INTO `m_office` (`id`, `parent_id`, `hierarchy`, `external_id`, `name`, `
VALUES
(1,NULL,'.','1','Head Office','2009-01-01');
-INSERT INTO `m_group_level` (`id`, `parent_id`, `is_super_parent`, `level_name`, `recursable`, `can_have_clients`) VALUES (1, NULL, 1, 'Center', 1, 0);
-INSERT INTO `m_group_level` (`id`, `parent_id`, `is_super_parent`, `level_name`, `recursable`, `can_have_clients`) VALUES (2, 1, 0, 'Group', 0, 1);
+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);
-- ========= roles and permissions =========
/*
@@ -496,13 +496,8 @@ VALUES
INSERT INTO `m_appuser_role` (`appuser_id`, `role_id`) VALUES (1,1);
--- Add in permissions for any special datatables or reports added in base reference data
+-- Add in permissions for any special datatables added in base reference data
-- This needs to always happen at end of the script
-/* add a read permission for each defined report */
-insert into m_permission(grouping, `code`, entity_name, action_name)
-select 'report', concat('READ_', sr.report_name),
-sr.report_name, 'READ'
-from stretchy_report sr;
/* add a create, read, update and delete permission for each registered datatable */
insert into m_permission(grouping, `code`, entity_name, action_name)
diff --git a/mifosng-db/0003-mifosx-core-reports-utf8.sql b/mifosng-db/0003-mifosx-core-reports-utf8.sql
index fc60fb0e6..4d583af0f 100644
--- a/mifosng-db/0003-mifosx-core-reports-utf8.sql
+++ b/mifosng-db/0003-mifosx-core-reports-utf8.sql
@@ -1,9 +1,17 @@
--- MySQL dump 10.13 Distrib 5.1.45, for Win32 (ia32)
-truncate table stretchy_report;
+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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0), l.id, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.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\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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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\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\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\n(sum(ifnull(r.principal_completed_derived, 0)) + \r\n sum(ifnull(r.interest_completed_derived, 0)) + \r\n sum(ifnull(r.fee_charges_completed_derived, 0)) + \r\n sum(ifnull(r.penalty_charges_completed_derived, 0))) 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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) 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\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 (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\n\"wait for derived field\" as \"Total Principal Repaid\",\r\n\"wait for derived field\" as \"Total Interest Repaid\",\r\n\"wait for derived field\" as \"Total Fees Repaid\",\r\n\"wait for derived field\" as \"Total Interest Waived\",\r\n\"wait for derived field\" as \"Total Fees Waived\",\r\n\"wait for derived field\" 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\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 (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 o.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(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_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_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.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\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_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_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.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,0),(49,'Income Statement','Pentaho',NULL,'Accounting',NULL,'Profit and Loss Statement',1,0),(50,'Trial Balance','Pentaho',NULL,'Accounting',NULL,'Trial Balance Report',1,0),(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 Summary (Arrears in weeks) - review','Table',NULL,'Loan','SELECT \r\n arr.clientName AS \"Client Name\",\r\n arr.accNo AS \"Account Number\",\r\n arr.loanAmt AS \"Loan Amount\",\r\n loan.principal AS \"Original Principal\",\r\n loan.interest AS \"Original Interest\",\r\n loan.prinPaid AS \"Principal Paid\",\r\n loan.intPaid AS \"Interest Paid\",\r\n arr.prinOverdue AS \"Principal Overdue\",\r\n arr.intOverdue AS \"Interest Overdue\",\r\n arr.arrWeek AS \"Weeks In Arrears\"\r\nFROM \r\n (SELECT mr.loan_id loanId,\r\n mc.display_name AS clientName,\r\n ml.account_no AS accNo,\r\n ml.principal_amount AS loanAmt,\r\n SUM(mr.principal_amount - IFNULL(mr.principal_completed_derived, 0)) AS prinOverdue, \r\n SUM(mr.interest_amount - IFNULL(mr.interest_completed_derived, 0)) AS intOverdue,\r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<7, \'Less than a week in arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<8, \'1 Week in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<15, \'2 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<22, \'3 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<29, \'4 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<36, \'5 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<43, \'6 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<50, \'7 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<57, \'8 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<64, \'9 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<71, \'10 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<78, \'11 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<85, \'12 Weeks in Arrears\', \'12+ Weeks in Arrears\'))))))))))))) AS arrWeek\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_repayment_schedule mr ON mr.loan_id=ml.id\r\n WHERE mr.completed_derived=0 \r\n AND mr.duedate <= CURDATE() \r\n AND ml.loan_status_id=300\r\n AND mo.id=${officeId}\r\n GROUP BY mr.loan_id\r\n ORDER BY mc.display_name) arr\r\nINNER JOIN \r\n (SELECT mr.loan_id loanId, \r\n SUM(mr.principal_amount) principal,\r\n SUM(mr.interest_amount) interest,\r\n SUM(IFNULL(mr.principal_completed_derived,0)) prinPaid,\r\n SUM(IFNULL(mr.interest_completed_derived,0)) intPaid\r\n FROM m_loan_repayment_schedule mr\r\n GROUP BY mr.loan_id) loan ON arr.loanId=loan.loanId','Loan arrears aging (Weeks)',1,1),(53,'Amount In Arrears','Table',NULL,'Loan','SELECT \r\n IFNULL(weeks.currencyName, weeks.currency) as currency, \r\n weeks.week_no \'Weeks 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 weeks/currencies used combo to ensure each line represented */\r\n (SELECT curs.code as currency, curs.name as currencyName, wks.* from\r\n (SELECT \'On Schedule\' week_no,0 wid UNION\r\n SELECT \'0 to 6 days arrears\',1 UNION\r\n SELECT \'1 Week in Arrears\',2 UNION\r\n SELECT \'2 Weeks in Arrears\',3 UNION\r\n SELECT \'3 Weeks in Arrears\',4 UNION\r\n SELECT \'4 Weeks in Arrears\',5 UNION\r\n SELECT \'5 Weeks in Arrears\',6 UNION\r\n SELECT \'6 Weeks in Arrears\',7 UNION\r\n SELECT \'7 Weeks in Arrears\',8 UNION\r\n SELECT \'8 Weeks in Arrears\',9 UNION\r\n SELECT \'9 Weeks in Arrears\',10 UNION\r\n SELECT \'10 Weeks in Arrears\',11 UNION\r\n SELECT \'11 Weeks in Arrears\',12 UNION\r\n SELECT \'12 Weeks in Arrears\',13 UNION\r\n SELECT \'12+ Weeks in Arrears\',14) wks,\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}) curs) weeks\r\n\r\n\r\nLEFT JOIN /* table of aging weeks per currency with gaps if no applicable loans */\r\n(SELECT \r\n z.currency, z.arrWeek, \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 arrWeek value (was much slower to\r\n duplicate calc of minOverdueDate in inner query) */\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)<0, \'On Schedule\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<7, \'0 to 6 days arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<8, \'1 Week in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<15, \'2 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<22, \'3 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<29, \'4 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<36, \'5 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<43, \'6 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<50, \'7 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<57, \'8 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<64, \'9 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<71, \'10 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<78, \'11 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<85, \'12 Weeks in Arrears\',\r\n \'12+ Weeks in Arrears\')))))))))))))) AS arrWeek\r\n\r\n FROM /* get the individual loan details */\r\n (SELECT ml.id AS loanId, ml.currency_code as currency,\r\n SUM(mr.principal_amount) principal, \r\n SUM(mr.interest_amount) interest, \r\n SUM(IFNULL(mr.principal_completed_derived,0)) prinPaid, \r\n SUM(IFNULL(mr.interest_completed_derived,0)) intPaid,\r\n\r\n SUM(IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), \r\n (mr.principal_amount - ifnull(mr.principal_completed_derived, 0))\r\n , 0)) as prinOverdue,\r\n SUM(IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), \r\n (mr.interest_amount - ifnull(mr.interest_completed_derived, 0))\r\n , 0)) as intOverdue,\r\n\r\n CAST(MIN(\r\n IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), mr.duedate, CURDATE() + 1)) as date) 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 INNER JOIN m_loan_repayment_schedule mr on mr.loan_id = ml.id\r\n WHERE ml.loan_status_id=300 /* active */\r\n AND mo.id=${officeId}\r\n GROUP BY ml.id) x\r\n ) z \r\nGROUP BY z.currency, z.arrWeek ) ars ON ars.arrWeek=weeks.week_no and ars.currency = weeks.currency\r\nORDER BY weeks.currency, weeks.wid','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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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\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 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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0), l.id, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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, 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_repayment_schedule r on r.loan_id = lastInstallment.loanId\r\ngroup by lastInstallment.loanId\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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0),lastInstallment.loanId, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.loan_id = lastInstallment.loanId\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(sum(ifnull(r.principal_amount, 0)) + sum(ifnull(r.interest_amount, 0)) + \r\nsum(ifnull(r.fee_charges_amount, 0)) + sum(ifnull(r.penalty_charges_amount, 0))) as \"Total Loan (P+I+F+Pen)\",\r\n\r\n(sum(ifnull(r.principal_completed_derived, 0)) + sum(ifnull(r.interest_completed_derived, 0)) +\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) + sum(ifnull(r.penalty_charges_completed_derived, 0))) 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_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.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);
INSERT INTO `stretchy_parameter` VALUES (1,'startDateSelect','startDate','startDate','date','date','today',NULL,NULL,NULL,NULL),(2,'endDateSelect','endDate','endDate','date','date','today',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`'),(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'),(6,'loanOfficerIdSelectAll','loanOfficerId','Loan Officer','select','number','0',NULL,NULL,'Y','(select id, \n\ndisplay_name as `Name` from m_staff\nwhere is_loan_officer = true)\r\nunion all\r\n(select -10, \'-\')\r\norder by 2'),(10,'currencyIdSelectAll','currencyId','Currency','select','number','0',NULL,NULL,'Y','select `code`, `name`\r\nfrom m_organisation_currency\r\norder by `code`'),(11,'currencyIdSelectOne','currencyId','Currency','select','number','0',NULL,'Y',NULL,'select `code`, `name`\r\nfrom m_organisation_currency\r\norder by `code`'),(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'),(25,'loanProductIdSelectAll','loanProductId','Product','select','number','0',NULL,NULL,'Y','select id, `name`\r\nfrom m_product_loan\r\norder by 2'),(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'),(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`'),(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'),(1002,'FullParameterList',NULL,'n/a','n/a','n/a','n/a','Y',NULL,NULL,'select parameter_name, parameter_variable, \n\nparameter_label, parameter_displayType, \r\nparameter_FormatType, parameter_default, selectOne, selectAll\r\nfrom stretchy_parameter p\r\nwhere special is null\r\n\n\norder by parameter_id'),(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');
+
+
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),(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);
+
+-- === Report permissions
+/* add a read permission for each defined report */
+insert into m_permission(grouping, `code`, entity_name, action_name)
+select 'report', concat('READ_', sr.report_name),
+sr.report_name, 'READ'
+from stretchy_report sr;
diff --git a/mifosng-db/multi-tenant-demo-backups/bare-bones-demo/bk_bare_bones_demo.sql b/mifosng-db/multi-tenant-demo-backups/bare-bones-demo/bk_bare_bones_demo.sql
index 5f31aad6f..c0d2316ac 100644
--- a/mifosng-db/multi-tenant-demo-backups/bare-bones-demo/bk_bare_bones_demo.sql
+++ b/mifosng-db/multi-tenant-demo-backups/bare-bones-demo/bk_bare_bones_demo.sql
@@ -680,7 +680,7 @@ CREATE TABLE `m_group_level` (
PRIMARY KEY (`id`),
KEY `Parent_levelId_reference` (`parent_id`),
CONSTRAINT `Parent_levelId_reference` FOREIGN KEY (`parent_id`) REFERENCES `m_group_level` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -689,6 +689,7 @@ CREATE TABLE `m_group_level` (
LOCK TABLES `m_group_level` WRITE;
/*!40000 ALTER TABLE `m_group_level` DISABLE KEYS */;
+INSERT INTO `m_group_level` VALUES (1,NULL,1,'Center',1,0),(2,1,0,'Group',0,1);
/*!40000 ALTER TABLE `m_group_level` ENABLE KEYS */;
UNLOCK TABLES;
@@ -1170,7 +1171,7 @@ CREATE TABLE `m_permission` (
`can_maker_checker` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`)
-) ENGINE=InnoDB AUTO_INCREMENT=256 DEFAULT CHARSET=utf8;
+) ENGINE=InnoDB AUTO_INCREMENT=272 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -1179,7 +1180,7 @@ CREATE TABLE `m_permission` (
LOCK TABLES `m_permission` WRITE;
/*!40000 ALTER TABLE `m_permission` DISABLE KEYS */;
-INSERT INTO `m_permission` VALUES (1,'special','ALL_FUNCTIONS',NULL,NULL,0),(2,'special','ALL_FUNCTIONS_READ',NULL,NULL,0),(3,'special','CHECKER_SUPER_USER',NULL,NULL,0),(4,'special','REPORTING_SUPER_USER',NULL,NULL,0),(5,'authorisation','READ_PERMISSION','PERMISSION','READ',0),(6,'authorisation','PERMISSIONS_ROLE','ROLE','PERMISSIONS',1),(7,'authorisation','CREATE_ROLE','ROLE','CREATE',1),(8,'authorisation','CREATE_ROLE_CHECKER','ROLE','CREATE',1),(9,'authorisation','READ_ROLE','ROLE','READ',0),(10,'authorisation','UPDATE_ROLE','ROLE','UPDATE',1),(11,'authorisation','UPDATE_ROLE_CHECKER','ROLE','UPDATE',1),(12,'authorisation','DELETE_ROLE','ROLE','DELETE',1),(13,'authorisation','DELETE_ROLE_CHECKER','ROLE','DELETE',1),(14,'authorisation','CREATE_USER','USER','CREATE',1),(15,'authorisation','CREATE_USER_CHECKER','USER','CREATE',1),(16,'authorisation','READ_USER','USER','READ',0),(17,'authorisation','UPDATE_USER','USER','UPDATE',1),(18,'authorisation','UPDATE_USER_CHECKER','USER','UPDATE',1),(19,'authorisation','DELETE_USER','USER','DELETE',1),(20,'authorisation','DELETE_USER_CHECKER','USER','DELETE',1),(21,'configuration','READ_CONFIGURATION','CONFIGURATION','READ',1),(22,'configuration','UPDATE_CONFIGURATION','CONFIGURATION','UPDATE',1),(23,'configuration','UPDATE_CONFIGURATION_CHECKER','CONFIGURATION','UPDATE',1),(24,'configuration','READ_CODE','CODE','READ',0),(25,'configuration','CREATE_CODE','CODE','CREATE',1),(26,'configuration','CREATE_CODE_CHECKER','CODE','CREATE',1),(27,'configuration','UPDATE_CODE','CODE','UPDATE',1),(28,'configuration','UPDATE_CODE_CHECKER','CODE','UPDATE',1),(29,'configuration','DELETE_CODE','CODE','DELETE',1),(30,'configuration','DELETE_CODE_CHECKER','CODE','DELETE',1),(31,'configuration','READ_CODEVALUE','CODEVALUE','READ',0),(32,'configuration','CREATE_CODEVALUE','CODEVALUE','CREATE',1),(33,'configuration','CREATE_CODEVALUE_CHECKER','CODEVALUE','CREATE',1),(34,'configuration','UPDATE_CODEVALUE','CODEVALUE','UPDATE',1),(35,'configuration','UPDATE_CODEVALUE_CHECKER','CODEVALUE','UPDATE',1),(36,'configuration','DELETE_CODEVALUE','CODEVALUE','DELETE',1),(37,'configuration','DELETE_CODEVALUE_CHECKER','CODEVALUE','DELETE',1),(38,'configuration','READ_CURRENCY','CURRENCY','READ',0),(39,'configuration','UPDATE_CURRENCY','CURRENCY','UPDATE',1),(40,'configuration','UPDATE_CURRENCY_CHECKER','CURRENCY','UPDATE',1),(41,'configuration','UPDATE_PERMISSION','PERMISSION','UPDATE',1),(42,'configuration','UPDATE_PERMISSION_CHECKER','PERMISSION','UPDATE',1),(43,'configuration','READ_DATATABLE','DATATABLE','READ',0),(44,'configuration','REGISTER_DATATABLE','DATATABLE','REGISTER',1),(45,'configuration','REGISTER_DATATABLE_CHECKER','DATATABLE','REGISTER',1),(46,'configuration','DEREGISTER_DATATABLE','DATATABLE','DEREGISTER',1),(47,'configuration','DEREGISTER_DATATABLE_CHECKER','DATATABLE','DEREGISTER',1),(48,'configuration','READ_AUDIT','AUDIT','READ',0),(49,'organisation','READ_MAKERCHECKER','MAKERCHECKER','READ',0),(50,'organisation','READ_CHARGE','CHARGE','READ',0),(51,'organisation','CREATE_CHARGE','CHARGE','CREATE',1),(52,'organisation','CREATE_CHARGE_CHECKER','CHARGE','CREATE',1),(53,'organisation','UPDATE_CHARGE','CHARGE','UPDATE',1),(54,'organisation','UPDATE_CHARGE_CHECKER','CHARGE','UPDATE',1),(55,'organisation','DELETE_CHARGE','CHARGE','DELETE',1),(56,'organisation','DELETE_CHARGE_CHECKER','CHARGE','DELETE',1),(57,'organisation','READ_FUND','FUND','READ',0),(58,'organisation','CREATE_FUND','FUND','CREATE',1),(59,'organisation','CREATE_FUND_CHECKER','FUND','CREATE',1),(60,'organisation','UPDATE_FUND','FUND','UPDATE',1),(61,'organisation','UPDATE_FUND_CHECKER','FUND','UPDATE',1),(62,'organisation','DELETE_FUND','FUND','DELETE',1),(63,'organisation','DELETE_FUND_CHECKER','FUND','DELETE',1),(64,'organisation','READ_LOANPRODUCT','LOANPRODUCT','READ',0),(65,'organisation','CREATE_LOANPRODUCT','LOANPRODUCT','CREATE',1),(66,'organisation','CREATE_LOANPRODUCT_CHECKER','LOANPRODUCT','CREATE',1),(67,'organisation','UPDATE_LOANPRODUCT','LOANPRODUCT','UPDATE',1),(68,'organisation','UPDATE_LOANPRODUCT_CHECKER','LOANPRODUCT','UPDATE',1),(69,'organisation','DELETE_LOANPRODUCT','LOANPRODUCT','DELETE',1),(70,'organisation','DELETE_LOANPRODUCT_CHECKER','LOANPRODUCT','DELETE',1),(71,'organisation','READ_OFFICE','OFFICE','READ',0),(72,'organisation','CREATE_OFFICE','OFFICE','CREATE',1),(73,'organisation','CREATE_OFFICE_CHECKER','OFFICE','CREATE',1),(74,'organisation','UPDATE_OFFICE','OFFICE','UPDATE',1),(75,'organisation','UPDATE_OFFICE_CHECKER','OFFICE','UPDATE',1),(76,'organisation','READ_OFFICETRANSACTION','OFFICETRANSACTION','READ',0),(77,'organisation','DELETE_OFFICE_CHECKER','OFFICE','DELETE',1),(78,'organisation','CREATE_OFFICETRANSACTION','OFFICETRANSACTION','CREATE',1),(79,'organisation','CREATE_OFFICETRANSACTION_CHECKER','OFFICETRANSACTION','CREATE',1),(80,'organisation','DELETE_OFFICETRANSACTION','OFFICETRANSACTION','DELETE',1),(81,'organisation','DELETE_OFFICETRANSACTION_CHECKER','OFFICETRANSACTION','DELETE',1),(82,'organisation','READ_STAFF','STAFF','READ',0),(83,'organisation','CREATE_STAFF','STAFF','CREATE',1),(84,'organisation','CREATE_STAFF_CHECKER','STAFF','CREATE',1),(85,'organisation','UPDATE_STAFF','STAFF','UPDATE',1),(86,'organisation','UPDATE_STAFF_CHECKER','STAFF','UPDATE',1),(87,'organisation','DELETE_STAFF','STAFF','DELETE',1),(88,'organisation','DELETE_STAFF_CHECKER','STAFF','DELETE',1),(89,'organisation','READ_SAVINGSPRODUCT','SAVINGSPRODUCT','READ',0),(90,'organisation','CREATE_SAVINGSPRODUCT','SAVINGSPRODUCT','CREATE',1),(91,'organisation','CREATE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','CREATE',1),(92,'organisation','UPDATE_SAVINGSPRODUCT','SAVINGSPRODUCT','UPDATE',1),(93,'organisation','UPDATE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','UPDATE',1),(94,'organisation','DELETE_SAVINGSPRODUCT','SAVINGSPRODUCT','DELETE',1),(95,'organisation','DELETE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','DELETE',1),(96,'organisation','READ_DEPOSITPRODUCT','DEPOSITPRODUCT','READ',0),(97,'organisation','CREATE_DEPOSITPRODUCT','DEPOSITPRODUCT','CREATE',1),(98,'organisation','CREATE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','CREATE',1),(99,'organisation','UPDATE_DEPOSITPRODUCT','DEPOSITPRODUCT','UPDATE',1),(100,'organisation','UPDATE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','UPDATE',1),(101,'organisation','DELETE_DEPOSITPRODUCT','DEPOSITPRODUCT','DELETE',1),(102,'organisation','DELETE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','DELETE',1),(103,'portfolio','READ_LOAN','LOAN','READ',0),(104,'portfolio','CREATE_LOAN','LOAN','CREATE',1),(105,'portfolio','CREATE_LOAN_CHECKER','LOAN','CREATE',1),(106,'portfolio','UPDATE_LOAN','LOAN','UPDATE',1),(107,'portfolio','UPDATE_LOAN_CHECKER','LOAN','UPDATE',1),(108,'portfolio','DELETE_LOAN','LOAN','DELETE',1),(109,'portfolio','DELETE_LOAN_CHECKER','LOAN','DELETE',1),(110,'portfolio','READ_CLIENT','CLIENT','READ',0),(111,'portfolio','CREATE_CLIENT','CLIENT','CREATE',1),(112,'portfolio','CREATE_CLIENT_CHECKER','CLIENT','CREATE',1),(113,'portfolio','UPDATE_CLIENT','CLIENT','UPDATE',1),(114,'portfolio','UPDATE_CLIENT_CHECKER','CLIENT','UPDATE',1),(115,'portfolio','DELETE_CLIENT','CLIENT','DELETE',1),(116,'portfolio','DELETE_CLIENT_CHECKER','CLIENT','DELETE',1),(117,'portfolio','READ_CLIENTIMAGE','CLIENTIMAGE','READ',0),(118,'portfolio','CREATE_CLIENTIMAGE','CLIENTIMAGE','CREATE',1),(119,'portfolio','CREATE_CLIENTIMAGE_CHECKER','CLIENTIMAGE','CREATE',1),(120,'portfolio','DELETE_CLIENTIMAGE','CLIENTIMAGE','DELETE',1),(121,'portfolio','DELETE_CLIENTIMAGE_CHECKER','CLIENTIMAGE','DELETE',1),(122,'portfolio','READ_CLIENTNOTE','CLIENTNOTE','READ',0),(123,'portfolio','CREATE_CLIENTNOTE','CLIENTNOTE','CREATE',1),(124,'portfolio','CREATE_CLIENTNOTE_CHECKER','CLIENTNOTE','CREATE',1),(125,'portfolio','UPDATE_CLIENTNOTE','CLIENTNOTE','UPDATE',1),(126,'portfolio','UPDATE_CLIENTNOTE_CHECKER','CLIENTNOTE','UPDATE',1),(127,'portfolio','DELETE_CLIENTNOTE','CLIENTNOTE','DELETE',1),(128,'portfolio','DELETE_CLIENTNOTE_CHECKER','CLIENTNOTE','DELETE',1),(129,'portfolio','READ_CLIENTIDENTIFIER','CLIENTIDENTIFIER','READ',0),(130,'portfolio','CREATE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','CREATE',1),(131,'portfolio','CREATE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','CREATE',1),(132,'portfolio','UPDATE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','UPDATE',1),(133,'portfolio','UPDATE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','UPDATE',1),(134,'portfolio','DELETE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','DELETE',1),(135,'portfolio','DELETE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','DELETE',1),(136,'portfolio','READ_DOCUMENT','DOCUMENT','READ',0),(137,'portfolio','CREATE_DOCUMENT','DOCUMENT','CREATE',1),(138,'portfolio','CREATE_DOCUMENT_CHECKER','DOCUMENT','CREATE',1),(139,'portfolio','UPDATE_DOCUMENT','DOCUMENT','UPDATE',1),(140,'portfolio','UPDATE_DOCUMENT_CHECKER','DOCUMENT','UPDATE',1),(141,'portfolio','DELETE_DOCUMENT','DOCUMENT','DELETE',1),(142,'portfolio','DELETE_DOCUMENT_CHECKER','DOCUMENT','DELETE',1),(143,'portfolio','READ_GROUP','GROUP','READ',0),(144,'portfolio','CREATE_GROUP','GROUP','CREATE',1),(145,'portfolio','CREATE_GROUP_CHECKER','GROUP','CREATE',1),(146,'portfolio','UPDATE_GROUP','GROUP','UPDATE',1),(147,'portfolio','UPDATE_GROUP_CHECKER','GROUP','UPDATE',1),(148,'portfolio','DELETE_GROUP','GROUP','DELETE',1),(149,'portfolio','DELETE_GROUP_CHECKER','GROUP','DELETE',1),(150,'portfolio','CREATE_LOANCHARGE','LOANCHARGE','CREATE',1),(151,'portfolio','CREATE_LOANCHARGE_CHECKER','LOANCHARGE','CREATE',1),(152,'portfolio','UPDATE_LOANCHARGE','LOANCHARGE','UPDATE',1),(153,'portfolio','UPDATE_LOANCHARGE_CHECKER','LOANCHARGE','UPDATE',1),(154,'portfolio','DELETE_LOANCHARGE','LOANCHARGE','DELETE',1),(155,'portfolio','DELETE_LOANCHARGE_CHECKER','LOANCHARGE','DELETE',1),(156,'portfolio','WAIVE_LOANCHARGE','LOANCHARGE','WAIVE',1),(157,'portfolio','WAIVE_LOANCHARGE_CHECKER','LOANCHARGE','WAIVE',1),(158,'portfolio','READ_DEPOSITACCOUNT','DEPOSITACCOUNT','READ',0),(159,'portfolio','CREATE_DEPOSITACCOUNT','DEPOSITACCOUNT','CREATE',1),(160,'portfolio','CREATE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','CREATE',1),(161,'portfolio','UPDATE_DEPOSITACCOUNT','DEPOSITACCOUNT','UPDATE',1),(162,'portfolio','UPDATE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','UPDATE',1),(163,'portfolio','DELETE_DEPOSITACCOUNT','DEPOSITACCOUNT','DELETE',1),(164,'portfolio','DELETE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','DELETE',1),(165,'portfolio','READ_SAVINGSACCOUNT','SAVINGSACCOUNT','READ',0),(166,'portfolio','CREATE_SAVINGSACCOUNT','SAVINGSACCOUNT','CREATE',1),(167,'portfolio','CREATE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','CREATE',1),(168,'portfolio','UPDATE_SAVINGSACCOUNT','SAVINGSACCOUNT','UPDATE',1),(169,'portfolio','UPDATE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','UPDATE',1),(170,'portfolio','DELETE_SAVINGSACCOUNT','SAVINGSACCOUNT','DELETE',1),(171,'portfolio','DELETE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','DELETE',1),(172,'portfolio','READ_GUARANTOR','GUARANTOR','READ',0),(173,'portfolio','CREATE_GUARANTOR','GUARANTOR','CREATE',1),(174,'portfolio','CREATE_GUARANTOR_CHECKER','GUARANTOR','CREATE',1),(175,'portfolio','UPDATE_GUARANTOR','GUARANTOR','UPDATE',1),(176,'portfolio','UPDATE_GUARANTOR_CHECKER','GUARANTOR','UPDATE',1),(177,'portfolio','DELETE_GUARANTOR','GUARANTOR','DELETE',1),(178,'portfolio','DELETE_GUARANTOR_CHECKER','GUARANTOR','DELETE',1),(179,'transaction_loan','APPROVE_LOAN','LOAN','APPROVE',1),(180,'transaction_loan','APPROVEINPAST_LOAN','LOAN','APPROVEINPAST',1),(181,'transaction_loan','REJECT_LOAN','LOAN','REJECT',1),(182,'transaction_loan','REJECTINPAST_LOAN','LOAN','REJECTINPAST',1),(183,'transaction_loan','WITHDRAW_LOAN','LOAN','WITHDRAW',1),(184,'transaction_loan','WITHDRAWINPAST_LOAN','LOAN','WITHDRAWINPAST',1),(185,'transaction_loan','APPROVALUNDO_LOAN','LOAN','APPROVALUNDO',1),(186,'transaction_loan','DISBURSE_LOAN','LOAN','DISBURSE',1),(187,'transaction_loan','DISBURSEINPAST_LOAN','LOAN','DISBURSEINPAST',1),(188,'transaction_loan','DISBURSALUNDO_LOAN','LOAN','DISBURSALUNDO',1),(189,'transaction_loan','REPAYMENT_LOAN','LOAN','REPAYMENT',1),(190,'transaction_loan','REPAYMENTINPAST_LOAN','LOAN','REPAYMENTINPAST',1),(191,'transaction_loan','ADJUST_LOAN','LOAN','ADJUST',1),(192,'transaction_loan','WAIVEINTERESTPORTION_LOAN','LOAN','WAIVEINTERESTPORTION',1),(193,'transaction_loan','WRITEOFF_LOAN','LOAN','WRITEOFF',1),(194,'transaction_loan','CLOSE_LOAN','LOAN','CLOSE',1),(195,'transaction_loan','CLOSEASRESCHEDULED_LOAN','LOAN','CLOSEASRESCHEDULED',1),(196,'transaction_loan','UPDATELOANOFFICER_LOAN','LOAN','UPDATELOANOFFICER',1),(197,'transaction_loan','UPDATELOANOFFICER_LOAN_CHECKER','LOAN','UPDATELOANOFFICER',1),(198,'transaction_loan','REMOVELOANOFFICER_LOAN','LOAN','REMOVELOANOFFICER',1),(199,'transaction_loan','REMOVELOANOFFICER_LOAN_CHECKER','LOAN','REMOVELOANOFFICER',1),(200,'transaction_loan','BULKREASSIGN_LOAN','LOAN','BULKREASSIGN',1),(201,'transaction_loan','BULKREASSIGN_LOAN_CHECKER','LOAN','BULKREASSIGN',1),(202,'transaction_loan','APPROVE_LOAN_CHECKER','LOAN','APPROVE',1),(203,'transaction_loan','APPROVEINPAST_LOAN_CHECKER','LOAN','APPROVEINPAST',1),(204,'transaction_loan','REJECT_LOAN_CHECKER','LOAN','REJECT',1),(205,'transaction_loan','REJECTINPAST_LOAN_CHECKER','LOAN','REJECTINPAST',1),(206,'transaction_loan','WITHDRAW_LOAN_CHECKER','LOAN','WITHDRAW',1),(207,'transaction_loan','WITHDRAWINPAST_LOAN_CHECKER','LOAN','WITHDRAWINPAST',1),(208,'transaction_loan','APPROVALUNDO_LOAN_CHECKER','LOAN','APPROVALUNDO',1),(209,'transaction_loan','DISBURSE_LOAN_CHECKER','LOAN','DISBURSE',1),(210,'transaction_loan','DISBURSEINPAST_LOAN_CHECKER','LOAN','DISBURSEINPAST',1),(211,'transaction_loan','DISBURSALUNDO_LOAN_CHECKER','LOAN','DISBURSALUNDO',1),(212,'transaction_loan','REPAYMENT_LOAN_CHECKER','LOAN','REPAYMENT',1),(213,'transaction_loan','REPAYMENTINPAST_LOAN_CHECKER','LOAN','REPAYMENTINPAST',1),(214,'transaction_loan','ADJUST_LOAN_CHECKER','LOAN','ADJUST',1),(215,'transaction_loan','WAIVEINTERESTPORTION_LOAN_CHECKER','LOAN','WAIVEINTERESTPORTION',1),(216,'transaction_loan','WRITEOFF_LOAN_CHECKER','LOAN','WRITEOFF',1),(217,'transaction_loan','CLOSE_LOAN_CHECKER','LOAN','CLOSE',1),(218,'transaction_loan','CLOSEASRESCHEDULED_LOAN_CHECKER','LOAN','CLOSEASRESCHEDULED',1),(219,'transaction_deposit','APPROVE_DEPOSITACCOUNT','DEPOSITACCOUNT','APPROVE',1),(220,'transaction_deposit','REJECT_DEPOSITACCOUNT','DEPOSITACCOUNT','REJECT',1),(221,'transaction_deposit','WITHDRAW_DEPOSITACCOUNT','DEPOSITACCOUNT','WITHDRAW',1),(222,'transaction_deposit','APPROVALUNDO_DEPOSITACCOUNT','DEPOSITACCOUNT','APPROVALUNDO',1),(223,'transaction_deposit','WITHDRAWAL_DEPOSITACCOUNT','DEPOSITACCOUNT','WITHDRAWAL',1),(224,'transaction_deposit','INTEREST_DEPOSITACCOUNT','DEPOSITACCOUNT','INTEREST',1),(225,'transaction_deposit','RENEW_DEPOSITACCOUNT','DEPOSITACCOUNT','RENEW',1),(226,'transaction_deposit','APPROVE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','APPROVE',1),(227,'transaction_deposit','REJECT_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','REJECT',1),(228,'transaction_deposit','WITHDRAW_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','WITHDRAW',1),(229,'transaction_deposit','APPROVALUNDO_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','APPROVALUNDO',1),(230,'transaction_deposit','WITHDRAWAL_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','WITHDRAWAL',1),(231,'transaction_deposit','INTEREST_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','INTEREST',1),(232,'transaction_deposit','RENEW_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','RENEW',1),(233,'accounting','CREATE_GLACCOUNT','GLACCOUNT','CREATE',1),(234,'accounting','UPDATE_GLACCOUNT','GLACCOUNT','UPDATE',1),(235,'accounting','DELETE_GLACCOUNT','GLACCOUNT','DELETE',1),(236,'accounting','CREATE_GLCLOSURE','GLCLOSURE','CREATE',1),(237,'accounting','UPDATE_GLCLOSURE','GLCLOSURE','UPDATE',1),(238,'accounting','DELETE_GLCLOSURE','GLCLOSURE','DELETE',1),(239,'accounting','CREATE_JOURNALENTRY','JOURNALENTRY','CREATE',1),(240,'accounting','REVERSE_JOURNALENTRY','JOURNALENTRY','REVERSE',1),(241,'report','READ_Active Loans Portfolio Status','Active Loans Portfolio Status','READ',1),(242,'report','READ_Active Loans Summary per Branch','Active Loans Summary per Branch','READ',1),(243,'report','READ_Balance Sheet','Balance Sheet','READ',1),(244,'report','READ_Client Listing','Client Listing','READ',1),(245,'report','READ_Client Loans Listing','Client Loans Listing','READ',1),(246,'report','READ_Funds Disbursed Between Dates Summary','Funds Disbursed Between Dates Summary','READ',1),(247,'report','READ_Funds Disbursed Between Dates Summary by Office','Funds Disbursed Between Dates Summary by Office','READ',1),(248,'report','READ_Income Statement','Income Statement','READ',1),(249,'report','READ_Loans Awaiting Disbursal','Loans Awaiting Disbursal','READ',1),(250,'report','READ_Loans Awaiting Disbursal Summary','Loans Awaiting Disbursal Summary','READ',1),(251,'report','READ_Loans Awaiting Disbursal Summary by Month','Loans Awaiting Disbursal Summary by Month','READ',1),(252,'report','READ_Portfolio at Risk','Portfolio at Risk','READ',1),(253,'report','READ_Portfolio at Risk by Branch','Portfolio at Risk by Branch','READ',1),(254,'report','READ_Trial Balance','Trial Balance','READ',1);
+INSERT INTO `m_permission` VALUES (1,'special','ALL_FUNCTIONS',NULL,NULL,0),(2,'special','ALL_FUNCTIONS_READ',NULL,NULL,0),(3,'special','CHECKER_SUPER_USER',NULL,NULL,0),(4,'special','REPORTING_SUPER_USER',NULL,NULL,0),(5,'authorisation','READ_PERMISSION','PERMISSION','READ',0),(6,'authorisation','PERMISSIONS_ROLE','ROLE','PERMISSIONS',1),(7,'authorisation','CREATE_ROLE','ROLE','CREATE',1),(8,'authorisation','CREATE_ROLE_CHECKER','ROLE','CREATE',1),(9,'authorisation','READ_ROLE','ROLE','READ',0),(10,'authorisation','UPDATE_ROLE','ROLE','UPDATE',1),(11,'authorisation','UPDATE_ROLE_CHECKER','ROLE','UPDATE',1),(12,'authorisation','DELETE_ROLE','ROLE','DELETE',1),(13,'authorisation','DELETE_ROLE_CHECKER','ROLE','DELETE',1),(14,'authorisation','CREATE_USER','USER','CREATE',1),(15,'authorisation','CREATE_USER_CHECKER','USER','CREATE',1),(16,'authorisation','READ_USER','USER','READ',0),(17,'authorisation','UPDATE_USER','USER','UPDATE',1),(18,'authorisation','UPDATE_USER_CHECKER','USER','UPDATE',1),(19,'authorisation','DELETE_USER','USER','DELETE',1),(20,'authorisation','DELETE_USER_CHECKER','USER','DELETE',1),(21,'configuration','READ_CONFIGURATION','CONFIGURATION','READ',1),(22,'configuration','UPDATE_CONFIGURATION','CONFIGURATION','UPDATE',1),(23,'configuration','UPDATE_CONFIGURATION_CHECKER','CONFIGURATION','UPDATE',1),(24,'configuration','READ_CODE','CODE','READ',0),(25,'configuration','CREATE_CODE','CODE','CREATE',1),(26,'configuration','CREATE_CODE_CHECKER','CODE','CREATE',1),(27,'configuration','UPDATE_CODE','CODE','UPDATE',1),(28,'configuration','UPDATE_CODE_CHECKER','CODE','UPDATE',1),(29,'configuration','DELETE_CODE','CODE','DELETE',1),(30,'configuration','DELETE_CODE_CHECKER','CODE','DELETE',1),(31,'configuration','READ_CODEVALUE','CODEVALUE','READ',0),(32,'configuration','CREATE_CODEVALUE','CODEVALUE','CREATE',1),(33,'configuration','CREATE_CODEVALUE_CHECKER','CODEVALUE','CREATE',1),(34,'configuration','UPDATE_CODEVALUE','CODEVALUE','UPDATE',1),(35,'configuration','UPDATE_CODEVALUE_CHECKER','CODEVALUE','UPDATE',1),(36,'configuration','DELETE_CODEVALUE','CODEVALUE','DELETE',1),(37,'configuration','DELETE_CODEVALUE_CHECKER','CODEVALUE','DELETE',1),(38,'configuration','READ_CURRENCY','CURRENCY','READ',0),(39,'configuration','UPDATE_CURRENCY','CURRENCY','UPDATE',1),(40,'configuration','UPDATE_CURRENCY_CHECKER','CURRENCY','UPDATE',1),(41,'configuration','UPDATE_PERMISSION','PERMISSION','UPDATE',1),(42,'configuration','UPDATE_PERMISSION_CHECKER','PERMISSION','UPDATE',1),(43,'configuration','READ_DATATABLE','DATATABLE','READ',0),(44,'configuration','REGISTER_DATATABLE','DATATABLE','REGISTER',1),(45,'configuration','REGISTER_DATATABLE_CHECKER','DATATABLE','REGISTER',1),(46,'configuration','DEREGISTER_DATATABLE','DATATABLE','DEREGISTER',1),(47,'configuration','DEREGISTER_DATATABLE_CHECKER','DATATABLE','DEREGISTER',1),(48,'configuration','READ_AUDIT','AUDIT','READ',0),(49,'organisation','READ_MAKERCHECKER','MAKERCHECKER','READ',0),(50,'organisation','READ_CHARGE','CHARGE','READ',0),(51,'organisation','CREATE_CHARGE','CHARGE','CREATE',1),(52,'organisation','CREATE_CHARGE_CHECKER','CHARGE','CREATE',1),(53,'organisation','UPDATE_CHARGE','CHARGE','UPDATE',1),(54,'organisation','UPDATE_CHARGE_CHECKER','CHARGE','UPDATE',1),(55,'organisation','DELETE_CHARGE','CHARGE','DELETE',1),(56,'organisation','DELETE_CHARGE_CHECKER','CHARGE','DELETE',1),(57,'organisation','READ_FUND','FUND','READ',0),(58,'organisation','CREATE_FUND','FUND','CREATE',1),(59,'organisation','CREATE_FUND_CHECKER','FUND','CREATE',1),(60,'organisation','UPDATE_FUND','FUND','UPDATE',1),(61,'organisation','UPDATE_FUND_CHECKER','FUND','UPDATE',1),(62,'organisation','DELETE_FUND','FUND','DELETE',1),(63,'organisation','DELETE_FUND_CHECKER','FUND','DELETE',1),(64,'organisation','READ_LOANPRODUCT','LOANPRODUCT','READ',0),(65,'organisation','CREATE_LOANPRODUCT','LOANPRODUCT','CREATE',1),(66,'organisation','CREATE_LOANPRODUCT_CHECKER','LOANPRODUCT','CREATE',1),(67,'organisation','UPDATE_LOANPRODUCT','LOANPRODUCT','UPDATE',1),(68,'organisation','UPDATE_LOANPRODUCT_CHECKER','LOANPRODUCT','UPDATE',1),(69,'organisation','DELETE_LOANPRODUCT','LOANPRODUCT','DELETE',1),(70,'organisation','DELETE_LOANPRODUCT_CHECKER','LOANPRODUCT','DELETE',1),(71,'organisation','READ_OFFICE','OFFICE','READ',0),(72,'organisation','CREATE_OFFICE','OFFICE','CREATE',1),(73,'organisation','CREATE_OFFICE_CHECKER','OFFICE','CREATE',1),(74,'organisation','UPDATE_OFFICE','OFFICE','UPDATE',1),(75,'organisation','UPDATE_OFFICE_CHECKER','OFFICE','UPDATE',1),(76,'organisation','READ_OFFICETRANSACTION','OFFICETRANSACTION','READ',0),(77,'organisation','DELETE_OFFICE_CHECKER','OFFICE','DELETE',1),(78,'organisation','CREATE_OFFICETRANSACTION','OFFICETRANSACTION','CREATE',1),(79,'organisation','CREATE_OFFICETRANSACTION_CHECKER','OFFICETRANSACTION','CREATE',1),(80,'organisation','DELETE_OFFICETRANSACTION','OFFICETRANSACTION','DELETE',1),(81,'organisation','DELETE_OFFICETRANSACTION_CHECKER','OFFICETRANSACTION','DELETE',1),(82,'organisation','READ_STAFF','STAFF','READ',0),(83,'organisation','CREATE_STAFF','STAFF','CREATE',1),(84,'organisation','CREATE_STAFF_CHECKER','STAFF','CREATE',1),(85,'organisation','UPDATE_STAFF','STAFF','UPDATE',1),(86,'organisation','UPDATE_STAFF_CHECKER','STAFF','UPDATE',1),(87,'organisation','DELETE_STAFF','STAFF','DELETE',1),(88,'organisation','DELETE_STAFF_CHECKER','STAFF','DELETE',1),(89,'organisation','READ_SAVINGSPRODUCT','SAVINGSPRODUCT','READ',0),(90,'organisation','CREATE_SAVINGSPRODUCT','SAVINGSPRODUCT','CREATE',1),(91,'organisation','CREATE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','CREATE',1),(92,'organisation','UPDATE_SAVINGSPRODUCT','SAVINGSPRODUCT','UPDATE',1),(93,'organisation','UPDATE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','UPDATE',1),(94,'organisation','DELETE_SAVINGSPRODUCT','SAVINGSPRODUCT','DELETE',1),(95,'organisation','DELETE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','DELETE',1),(96,'organisation','READ_DEPOSITPRODUCT','DEPOSITPRODUCT','READ',0),(97,'organisation','CREATE_DEPOSITPRODUCT','DEPOSITPRODUCT','CREATE',1),(98,'organisation','CREATE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','CREATE',1),(99,'organisation','UPDATE_DEPOSITPRODUCT','DEPOSITPRODUCT','UPDATE',1),(100,'organisation','UPDATE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','UPDATE',1),(101,'organisation','DELETE_DEPOSITPRODUCT','DEPOSITPRODUCT','DELETE',1),(102,'organisation','DELETE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','DELETE',1),(103,'portfolio','READ_LOAN','LOAN','READ',0),(104,'portfolio','CREATE_LOAN','LOAN','CREATE',1),(105,'portfolio','CREATE_LOAN_CHECKER','LOAN','CREATE',1),(106,'portfolio','UPDATE_LOAN','LOAN','UPDATE',1),(107,'portfolio','UPDATE_LOAN_CHECKER','LOAN','UPDATE',1),(108,'portfolio','DELETE_LOAN','LOAN','DELETE',1),(109,'portfolio','DELETE_LOAN_CHECKER','LOAN','DELETE',1),(110,'portfolio','READ_CLIENT','CLIENT','READ',0),(111,'portfolio','CREATE_CLIENT','CLIENT','CREATE',1),(112,'portfolio','CREATE_CLIENT_CHECKER','CLIENT','CREATE',1),(113,'portfolio','UPDATE_CLIENT','CLIENT','UPDATE',1),(114,'portfolio','UPDATE_CLIENT_CHECKER','CLIENT','UPDATE',1),(115,'portfolio','DELETE_CLIENT','CLIENT','DELETE',1),(116,'portfolio','DELETE_CLIENT_CHECKER','CLIENT','DELETE',1),(117,'portfolio','READ_CLIENTIMAGE','CLIENTIMAGE','READ',0),(118,'portfolio','CREATE_CLIENTIMAGE','CLIENTIMAGE','CREATE',1),(119,'portfolio','CREATE_CLIENTIMAGE_CHECKER','CLIENTIMAGE','CREATE',1),(120,'portfolio','DELETE_CLIENTIMAGE','CLIENTIMAGE','DELETE',1),(121,'portfolio','DELETE_CLIENTIMAGE_CHECKER','CLIENTIMAGE','DELETE',1),(122,'portfolio','READ_CLIENTNOTE','CLIENTNOTE','READ',0),(123,'portfolio','CREATE_CLIENTNOTE','CLIENTNOTE','CREATE',1),(124,'portfolio','CREATE_CLIENTNOTE_CHECKER','CLIENTNOTE','CREATE',1),(125,'portfolio','UPDATE_CLIENTNOTE','CLIENTNOTE','UPDATE',1),(126,'portfolio','UPDATE_CLIENTNOTE_CHECKER','CLIENTNOTE','UPDATE',1),(127,'portfolio','DELETE_CLIENTNOTE','CLIENTNOTE','DELETE',1),(128,'portfolio','DELETE_CLIENTNOTE_CHECKER','CLIENTNOTE','DELETE',1),(129,'portfolio','READ_CLIENTIDENTIFIER','CLIENTIDENTIFIER','READ',0),(130,'portfolio','CREATE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','CREATE',1),(131,'portfolio','CREATE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','CREATE',1),(132,'portfolio','UPDATE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','UPDATE',1),(133,'portfolio','UPDATE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','UPDATE',1),(134,'portfolio','DELETE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','DELETE',1),(135,'portfolio','DELETE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','DELETE',1),(136,'portfolio','READ_DOCUMENT','DOCUMENT','READ',0),(137,'portfolio','CREATE_DOCUMENT','DOCUMENT','CREATE',1),(138,'portfolio','CREATE_DOCUMENT_CHECKER','DOCUMENT','CREATE',1),(139,'portfolio','UPDATE_DOCUMENT','DOCUMENT','UPDATE',1),(140,'portfolio','UPDATE_DOCUMENT_CHECKER','DOCUMENT','UPDATE',1),(141,'portfolio','DELETE_DOCUMENT','DOCUMENT','DELETE',1),(142,'portfolio','DELETE_DOCUMENT_CHECKER','DOCUMENT','DELETE',1),(143,'portfolio','READ_GROUP','GROUP','READ',0),(144,'portfolio','CREATE_GROUP','GROUP','CREATE',1),(145,'portfolio','CREATE_GROUP_CHECKER','GROUP','CREATE',1),(146,'portfolio','UPDATE_GROUP','GROUP','UPDATE',1),(147,'portfolio','UPDATE_GROUP_CHECKER','GROUP','UPDATE',1),(148,'portfolio','DELETE_GROUP','GROUP','DELETE',1),(149,'portfolio','DELETE_GROUP_CHECKER','GROUP','DELETE',1),(150,'portfolio','CREATE_LOANCHARGE','LOANCHARGE','CREATE',1),(151,'portfolio','CREATE_LOANCHARGE_CHECKER','LOANCHARGE','CREATE',1),(152,'portfolio','UPDATE_LOANCHARGE','LOANCHARGE','UPDATE',1),(153,'portfolio','UPDATE_LOANCHARGE_CHECKER','LOANCHARGE','UPDATE',1),(154,'portfolio','DELETE_LOANCHARGE','LOANCHARGE','DELETE',1),(155,'portfolio','DELETE_LOANCHARGE_CHECKER','LOANCHARGE','DELETE',1),(156,'portfolio','WAIVE_LOANCHARGE','LOANCHARGE','WAIVE',1),(157,'portfolio','WAIVE_LOANCHARGE_CHECKER','LOANCHARGE','WAIVE',1),(158,'portfolio','READ_DEPOSITACCOUNT','DEPOSITACCOUNT','READ',0),(159,'portfolio','CREATE_DEPOSITACCOUNT','DEPOSITACCOUNT','CREATE',1),(160,'portfolio','CREATE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','CREATE',1),(161,'portfolio','UPDATE_DEPOSITACCOUNT','DEPOSITACCOUNT','UPDATE',1),(162,'portfolio','UPDATE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','UPDATE',1),(163,'portfolio','DELETE_DEPOSITACCOUNT','DEPOSITACCOUNT','DELETE',1),(164,'portfolio','DELETE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','DELETE',1),(165,'portfolio','READ_SAVINGSACCOUNT','SAVINGSACCOUNT','READ',0),(166,'portfolio','CREATE_SAVINGSACCOUNT','SAVINGSACCOUNT','CREATE',1),(167,'portfolio','CREATE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','CREATE',1),(168,'portfolio','UPDATE_SAVINGSACCOUNT','SAVINGSACCOUNT','UPDATE',1),(169,'portfolio','UPDATE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','UPDATE',1),(170,'portfolio','DELETE_SAVINGSACCOUNT','SAVINGSACCOUNT','DELETE',1),(171,'portfolio','DELETE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','DELETE',1),(172,'portfolio','READ_GUARANTOR','GUARANTOR','READ',0),(173,'portfolio','CREATE_GUARANTOR','GUARANTOR','CREATE',1),(174,'portfolio','CREATE_GUARANTOR_CHECKER','GUARANTOR','CREATE',1),(175,'portfolio','UPDATE_GUARANTOR','GUARANTOR','UPDATE',1),(176,'portfolio','UPDATE_GUARANTOR_CHECKER','GUARANTOR','UPDATE',1),(177,'portfolio','DELETE_GUARANTOR','GUARANTOR','DELETE',1),(178,'portfolio','DELETE_GUARANTOR_CHECKER','GUARANTOR','DELETE',1),(179,'transaction_loan','APPROVE_LOAN','LOAN','APPROVE',1),(180,'transaction_loan','APPROVEINPAST_LOAN','LOAN','APPROVEINPAST',1),(181,'transaction_loan','REJECT_LOAN','LOAN','REJECT',1),(182,'transaction_loan','REJECTINPAST_LOAN','LOAN','REJECTINPAST',1),(183,'transaction_loan','WITHDRAW_LOAN','LOAN','WITHDRAW',1),(184,'transaction_loan','WITHDRAWINPAST_LOAN','LOAN','WITHDRAWINPAST',1),(185,'transaction_loan','APPROVALUNDO_LOAN','LOAN','APPROVALUNDO',1),(186,'transaction_loan','DISBURSE_LOAN','LOAN','DISBURSE',1),(187,'transaction_loan','DISBURSEINPAST_LOAN','LOAN','DISBURSEINPAST',1),(188,'transaction_loan','DISBURSALUNDO_LOAN','LOAN','DISBURSALUNDO',1),(189,'transaction_loan','REPAYMENT_LOAN','LOAN','REPAYMENT',1),(190,'transaction_loan','REPAYMENTINPAST_LOAN','LOAN','REPAYMENTINPAST',1),(191,'transaction_loan','ADJUST_LOAN','LOAN','ADJUST',1),(192,'transaction_loan','WAIVEINTERESTPORTION_LOAN','LOAN','WAIVEINTERESTPORTION',1),(193,'transaction_loan','WRITEOFF_LOAN','LOAN','WRITEOFF',1),(194,'transaction_loan','CLOSE_LOAN','LOAN','CLOSE',1),(195,'transaction_loan','CLOSEASRESCHEDULED_LOAN','LOAN','CLOSEASRESCHEDULED',1),(196,'transaction_loan','UPDATELOANOFFICER_LOAN','LOAN','UPDATELOANOFFICER',1),(197,'transaction_loan','UPDATELOANOFFICER_LOAN_CHECKER','LOAN','UPDATELOANOFFICER',1),(198,'transaction_loan','REMOVELOANOFFICER_LOAN','LOAN','REMOVELOANOFFICER',1),(199,'transaction_loan','REMOVELOANOFFICER_LOAN_CHECKER','LOAN','REMOVELOANOFFICER',1),(200,'transaction_loan','BULKREASSIGN_LOAN','LOAN','BULKREASSIGN',1),(201,'transaction_loan','BULKREASSIGN_LOAN_CHECKER','LOAN','BULKREASSIGN',1),(202,'transaction_loan','APPROVE_LOAN_CHECKER','LOAN','APPROVE',1),(203,'transaction_loan','APPROVEINPAST_LOAN_CHECKER','LOAN','APPROVEINPAST',1),(204,'transaction_loan','REJECT_LOAN_CHECKER','LOAN','REJECT',1),(205,'transaction_loan','REJECTINPAST_LOAN_CHECKER','LOAN','REJECTINPAST',1),(206,'transaction_loan','WITHDRAW_LOAN_CHECKER','LOAN','WITHDRAW',1),(207,'transaction_loan','WITHDRAWINPAST_LOAN_CHECKER','LOAN','WITHDRAWINPAST',1),(208,'transaction_loan','APPROVALUNDO_LOAN_CHECKER','LOAN','APPROVALUNDO',1),(209,'transaction_loan','DISBURSE_LOAN_CHECKER','LOAN','DISBURSE',1),(210,'transaction_loan','DISBURSEINPAST_LOAN_CHECKER','LOAN','DISBURSEINPAST',1),(211,'transaction_loan','DISBURSALUNDO_LOAN_CHECKER','LOAN','DISBURSALUNDO',1),(212,'transaction_loan','REPAYMENT_LOAN_CHECKER','LOAN','REPAYMENT',1),(213,'transaction_loan','REPAYMENTINPAST_LOAN_CHECKER','LOAN','REPAYMENTINPAST',1),(214,'transaction_loan','ADJUST_LOAN_CHECKER','LOAN','ADJUST',1),(215,'transaction_loan','WAIVEINTERESTPORTION_LOAN_CHECKER','LOAN','WAIVEINTERESTPORTION',1),(216,'transaction_loan','WRITEOFF_LOAN_CHECKER','LOAN','WRITEOFF',1),(217,'transaction_loan','CLOSE_LOAN_CHECKER','LOAN','CLOSE',1),(218,'transaction_loan','CLOSEASRESCHEDULED_LOAN_CHECKER','LOAN','CLOSEASRESCHEDULED',1),(219,'transaction_deposit','APPROVE_DEPOSITACCOUNT','DEPOSITACCOUNT','APPROVE',1),(220,'transaction_deposit','REJECT_DEPOSITACCOUNT','DEPOSITACCOUNT','REJECT',1),(221,'transaction_deposit','WITHDRAW_DEPOSITACCOUNT','DEPOSITACCOUNT','WITHDRAW',1),(222,'transaction_deposit','APPROVALUNDO_DEPOSITACCOUNT','DEPOSITACCOUNT','APPROVALUNDO',1),(223,'transaction_deposit','WITHDRAWAL_DEPOSITACCOUNT','DEPOSITACCOUNT','WITHDRAWAL',1),(224,'transaction_deposit','INTEREST_DEPOSITACCOUNT','DEPOSITACCOUNT','INTEREST',1),(225,'transaction_deposit','RENEW_DEPOSITACCOUNT','DEPOSITACCOUNT','RENEW',1),(226,'transaction_deposit','APPROVE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','APPROVE',1),(227,'transaction_deposit','REJECT_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','REJECT',1),(228,'transaction_deposit','WITHDRAW_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','WITHDRAW',1),(229,'transaction_deposit','APPROVALUNDO_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','APPROVALUNDO',1),(230,'transaction_deposit','WITHDRAWAL_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','WITHDRAWAL',1),(231,'transaction_deposit','INTEREST_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','INTEREST',1),(232,'transaction_deposit','RENEW_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','RENEW',1),(233,'accounting','CREATE_GLACCOUNT','GLACCOUNT','CREATE',1),(234,'accounting','UPDATE_GLACCOUNT','GLACCOUNT','UPDATE',1),(235,'accounting','DELETE_GLACCOUNT','GLACCOUNT','DELETE',1),(236,'accounting','CREATE_GLCLOSURE','GLCLOSURE','CREATE',1),(237,'accounting','UPDATE_GLCLOSURE','GLCLOSURE','UPDATE',1),(238,'accounting','DELETE_GLCLOSURE','GLCLOSURE','DELETE',1),(239,'accounting','CREATE_JOURNALENTRY','JOURNALENTRY','CREATE',1),(240,'accounting','REVERSE_JOURNALENTRY','JOURNALENTRY','REVERSE',1),(241,'report','READ_Active Loans Details','Active Loans Details','READ',1),(242,'report','READ_Active Loans in last installment','Active Loans in last installment','READ',1),(243,'report','READ_Active Loans in last installment Summary','Active Loans in last installment Summary','READ',1),(244,'report','READ_Active Loans Passed Final Maturity','Active Loans Passed Final Maturity','READ',1),(245,'report','READ_Active Loans Passed Final Maturity Summary','Active Loans Passed Final Maturity Summary','READ',1),(246,'report','READ_Active Loans Summary','Active Loans Summary','READ',1),(247,'report','READ_Aging Summary (Arrears in weeks) - review','Aging Summary (Arrears in weeks) - review','READ',1),(248,'report','READ_Amount In Arrears','Amount In Arrears','READ',1),(249,'report','READ_Balance Sheet','Balance Sheet','READ',1),(250,'report','READ_Client Listing','Client Listing','READ',1),(251,'report','READ_Client Loans Listing','Client Loans Listing','READ',1),(252,'report','READ_Funds Disbursed Between Dates Summary','Funds Disbursed Between Dates Summary','READ',1),(253,'report','READ_Funds Disbursed Between Dates Summary by Office','Funds Disbursed Between Dates Summary by Office','READ',1),(254,'report','READ_Income Statement','Income Statement','READ',1),(255,'report','READ_Loans Awaiting Disbursal','Loans Awaiting Disbursal','READ',1),(256,'report','READ_Loans Awaiting Disbursal Summary','Loans Awaiting Disbursal Summary','READ',1),(257,'report','READ_Loans Awaiting Disbursal Summary by Month','Loans Awaiting Disbursal Summary by Month','READ',1),(258,'report','READ_Loans Pending Approval','Loans Pending Approval','READ',1),(259,'report','READ_Obligation Met Loans Details','Obligation Met Loans Details','READ',1),(260,'report','READ_Obligation Met Loans Summary','Obligation Met Loans Summary','READ',1),(261,'report','READ_Portfolio at Risk','Portfolio at Risk','READ',1),(262,'report','READ_Portfolio at Risk by Branch','Portfolio at Risk by Branch','READ',1),(263,'report','READ_Rescheduled Loans','Rescheduled Loans','READ',1),(264,'report','READ_Trial Balance','Trial Balance','READ',1),(265,'report','READ_Written-Off Loans','Written-Off Loans','READ',1);
/*!40000 ALTER TABLE `m_permission` ENABLE KEYS */;
UNLOCK TABLES;
@@ -1765,7 +1766,7 @@ CREATE TABLE `stretchy_report` (
`use_report` tinyint(1) DEFAULT '0',
PRIMARY KEY (`report_id`),
UNIQUE KEY `report_name_UNIQUE` (`report_name`)
-) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8;
+) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -1774,7 +1775,7 @@ CREATE TABLE `stretchy_report` (
LOCK TABLES `stretchy_report` WRITE;
/*!40000 ALTER TABLE `stretchy_report` DISABLE KEYS */;
-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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0), l.id, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.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\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 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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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\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\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 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\n(sum(ifnull(r.principal_completed_derived, 0)) + \r\n sum(ifnull(r.interest_completed_derived, 0)) + \r\n sum(ifnull(r.fee_charges_completed_derived, 0)) + \r\n sum(ifnull(r.penalty_charges_completed_derived, 0))) 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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) 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\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 (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 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\n\"wait for derived field\" as \"Total Principal Repaid\",\r\n\"wait for derived field\" as \"Total Interest Repaid\",\r\n\"wait for derived field\" as \"Total Fees Repaid\",\r\n\"wait for derived field\" as \"Total Interest Waived\",\r\n\"wait for derived field\" as \"Total Fees Waived\",\r\n\"wait for derived field\" 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\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 (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 o.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(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_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_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.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\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_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_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.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,0),(49,'Income Statement','Pentaho',NULL,'Accounting',NULL,'Profit and Loss Statement',1,0),(50,'Trial Balance','Pentaho',NULL,'Accounting',NULL,'Trial Balance Report',1,0),(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 Summary (Arrears in weeks) - review','Table',NULL,'Loan','SELECT \r\n arr.clientName AS \"Client Name\",\r\n arr.accNo AS \"Account Number\",\r\n arr.loanAmt AS \"Loan Amount\",\r\n loan.principal AS \"Original Principal\",\r\n loan.interest AS \"Original Interest\",\r\n loan.prinPaid AS \"Principal Paid\",\r\n loan.intPaid AS \"Interest Paid\",\r\n arr.prinOverdue AS \"Principal Overdue\",\r\n arr.intOverdue AS \"Interest Overdue\",\r\n arr.arrWeek AS \"Weeks In Arrears\"\r\nFROM \r\n (SELECT mr.loan_id loanId,\r\n mc.display_name AS clientName,\r\n ml.account_no AS accNo,\r\n ml.principal_amount AS loanAmt,\r\n SUM(mr.principal_amount - IFNULL(mr.principal_completed_derived, 0)) AS prinOverdue, \r\n SUM(mr.interest_amount - IFNULL(mr.interest_completed_derived, 0)) AS intOverdue,\r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<7, \'Less than a week in arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<8, \'1 Week in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<15, \'2 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<22, \'3 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<29, \'4 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<36, \'5 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<43, \'6 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<50, \'7 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<57, \'8 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<64, \'9 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<71, \'10 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<78, \'11 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<85, \'12 Weeks in Arrears\', \'12+ Weeks in Arrears\'))))))))))))) AS arrWeek\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_repayment_schedule mr ON mr.loan_id=ml.id\r\n WHERE mr.completed_derived=0 \r\n AND mr.duedate <= CURDATE() \r\n AND ml.loan_status_id=300\r\n AND mo.id=${officeId}\r\n GROUP BY mr.loan_id\r\n ORDER BY mc.display_name) arr\r\nINNER JOIN \r\n (SELECT mr.loan_id loanId, \r\n SUM(mr.principal_amount) principal,\r\n SUM(mr.interest_amount) interest,\r\n SUM(IFNULL(mr.principal_completed_derived,0)) prinPaid,\r\n SUM(IFNULL(mr.interest_completed_derived,0)) intPaid\r\n FROM m_loan_repayment_schedule mr\r\n GROUP BY mr.loan_id) loan ON arr.loanId=loan.loanId','Loan arrears aging (Weeks)',1,1),(53,'Amount In Arrears','Table',NULL,'Loan','SELECT \r\n IFNULL(weeks.currencyName, weeks.currency) as currency, \r\n weeks.week_no \'Weeks 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 weeks/currencies used combo to ensure each line represented */\r\n (SELECT curs.code as currency, curs.name as currencyName, wks.* from\r\n (SELECT \'On Schedule\' week_no,0 wid UNION\r\n SELECT \'0 to 6 days arrears\',1 UNION\r\n SELECT \'1 Week in Arrears\',2 UNION\r\n SELECT \'2 Weeks in Arrears\',3 UNION\r\n SELECT \'3 Weeks in Arrears\',4 UNION\r\n SELECT \'4 Weeks in Arrears\',5 UNION\r\n SELECT \'5 Weeks in Arrears\',6 UNION\r\n SELECT \'6 Weeks in Arrears\',7 UNION\r\n SELECT \'7 Weeks in Arrears\',8 UNION\r\n SELECT \'8 Weeks in Arrears\',9 UNION\r\n SELECT \'9 Weeks in Arrears\',10 UNION\r\n SELECT \'10 Weeks in Arrears\',11 UNION\r\n SELECT \'11 Weeks in Arrears\',12 UNION\r\n SELECT \'12 Weeks in Arrears\',13 UNION\r\n SELECT \'12+ Weeks in Arrears\',14) wks,\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}) curs) weeks\r\n\r\n\r\nLEFT JOIN /* table of aging weeks per currency with gaps if no applicable loans */\r\n(SELECT \r\n z.currency, z.arrWeek, \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 arrWeek value (was much slower to\r\n duplicate calc of minOverdueDate in inner query) */\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)<0, \'On Schedule\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<7, \'0 to 6 days arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<8, \'1 Week in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<15, \'2 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<22, \'3 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<29, \'4 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<36, \'5 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<43, \'6 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<50, \'7 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<57, \'8 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<64, \'9 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<71, \'10 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<78, \'11 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<85, \'12 Weeks in Arrears\',\r\n \'12+ Weeks in Arrears\')))))))))))))) AS arrWeek\r\n\r\n FROM /* get the individual loan details */\r\n (SELECT ml.id AS loanId, ml.currency_code as currency,\r\n SUM(mr.principal_amount) principal, \r\n SUM(mr.interest_amount) interest, \r\n SUM(IFNULL(mr.principal_completed_derived,0)) prinPaid, \r\n SUM(IFNULL(mr.interest_completed_derived,0)) intPaid,\r\n\r\n SUM(IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), \r\n (mr.principal_amount - ifnull(mr.principal_completed_derived, 0))\r\n , 0)) as prinOverdue,\r\n SUM(IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), \r\n (mr.interest_amount - ifnull(mr.interest_completed_derived, 0))\r\n , 0)) as intOverdue,\r\n\r\n CAST(MIN(\r\n IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), mr.duedate, CURDATE() + 1)) as date) 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 INNER JOIN m_loan_repayment_schedule mr on mr.loan_id = ml.id\r\n WHERE ml.loan_status_id=300 /* active */\r\n AND mo.id=${officeId}\r\n GROUP BY ml.id) x\r\n ) z \r\nGROUP BY z.currency, z.arrWeek ) ars ON ars.arrWeek=weeks.week_no and ars.currency = weeks.currency\r\nORDER BY weeks.currency, weeks.wid','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);
+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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0), l.id, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.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\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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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\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\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\n(sum(ifnull(r.principal_completed_derived, 0)) + \r\n sum(ifnull(r.interest_completed_derived, 0)) + \r\n sum(ifnull(r.fee_charges_completed_derived, 0)) + \r\n sum(ifnull(r.penalty_charges_completed_derived, 0))) 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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) 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\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 (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\n\"wait for derived field\" as \"Total Principal Repaid\",\r\n\"wait for derived field\" as \"Total Interest Repaid\",\r\n\"wait for derived field\" as \"Total Fees Repaid\",\r\n\"wait for derived field\" as \"Total Interest Waived\",\r\n\"wait for derived field\" as \"Total Fees Waived\",\r\n\"wait for derived field\" 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\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 (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 o.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(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_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_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.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\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_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_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.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,0),(49,'Income Statement','Pentaho',NULL,'Accounting',NULL,'Profit and Loss Statement',1,0),(50,'Trial Balance','Pentaho',NULL,'Accounting',NULL,'Trial Balance Report',1,0),(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 Summary (Arrears in weeks) - review','Table',NULL,'Loan','SELECT \r\n arr.clientName AS \"Client Name\",\r\n arr.accNo AS \"Account Number\",\r\n arr.loanAmt AS \"Loan Amount\",\r\n loan.principal AS \"Original Principal\",\r\n loan.interest AS \"Original Interest\",\r\n loan.prinPaid AS \"Principal Paid\",\r\n loan.intPaid AS \"Interest Paid\",\r\n arr.prinOverdue AS \"Principal Overdue\",\r\n arr.intOverdue AS \"Interest Overdue\",\r\n arr.arrWeek AS \"Weeks In Arrears\"\r\nFROM \r\n (SELECT mr.loan_id loanId,\r\n mc.display_name AS clientName,\r\n ml.account_no AS accNo,\r\n ml.principal_amount AS loanAmt,\r\n SUM(mr.principal_amount - IFNULL(mr.principal_completed_derived, 0)) AS prinOverdue, \r\n SUM(mr.interest_amount - IFNULL(mr.interest_completed_derived, 0)) AS intOverdue,\r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<7, \'Less than a week in arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<8, \'1 Week in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<15, \'2 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<22, \'3 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<29, \'4 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<36, \'5 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<43, \'6 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<50, \'7 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<57, \'8 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<64, \'9 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<71, \'10 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<78, \'11 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<85, \'12 Weeks in Arrears\', \'12+ Weeks in Arrears\'))))))))))))) AS arrWeek\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_repayment_schedule mr ON mr.loan_id=ml.id\r\n WHERE mr.completed_derived=0 \r\n AND mr.duedate <= CURDATE() \r\n AND ml.loan_status_id=300\r\n AND mo.id=${officeId}\r\n GROUP BY mr.loan_id\r\n ORDER BY mc.display_name) arr\r\nINNER JOIN \r\n (SELECT mr.loan_id loanId, \r\n SUM(mr.principal_amount) principal,\r\n SUM(mr.interest_amount) interest,\r\n SUM(IFNULL(mr.principal_completed_derived,0)) prinPaid,\r\n SUM(IFNULL(mr.interest_completed_derived,0)) intPaid\r\n FROM m_loan_repayment_schedule mr\r\n GROUP BY mr.loan_id) loan ON arr.loanId=loan.loanId','Loan arrears aging (Weeks)',1,1),(53,'Amount In Arrears','Table',NULL,'Loan','SELECT \r\n IFNULL(weeks.currencyName, weeks.currency) as currency, \r\n weeks.week_no \'Weeks 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 weeks/currencies used combo to ensure each line represented */\r\n (SELECT curs.code as currency, curs.name as currencyName, wks.* from\r\n (SELECT \'On Schedule\' week_no,0 wid UNION\r\n SELECT \'0 to 6 days arrears\',1 UNION\r\n SELECT \'1 Week in Arrears\',2 UNION\r\n SELECT \'2 Weeks in Arrears\',3 UNION\r\n SELECT \'3 Weeks in Arrears\',4 UNION\r\n SELECT \'4 Weeks in Arrears\',5 UNION\r\n SELECT \'5 Weeks in Arrears\',6 UNION\r\n SELECT \'6 Weeks in Arrears\',7 UNION\r\n SELECT \'7 Weeks in Arrears\',8 UNION\r\n SELECT \'8 Weeks in Arrears\',9 UNION\r\n SELECT \'9 Weeks in Arrears\',10 UNION\r\n SELECT \'10 Weeks in Arrears\',11 UNION\r\n SELECT \'11 Weeks in Arrears\',12 UNION\r\n SELECT \'12 Weeks in Arrears\',13 UNION\r\n SELECT \'12+ Weeks in Arrears\',14) wks,\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}) curs) weeks\r\n\r\n\r\nLEFT JOIN /* table of aging weeks per currency with gaps if no applicable loans */\r\n(SELECT \r\n z.currency, z.arrWeek, \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 arrWeek value (was much slower to\r\n duplicate calc of minOverdueDate in inner query) */\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)<0, \'On Schedule\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<7, \'0 to 6 days arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<8, \'1 Week in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<15, \'2 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<22, \'3 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<29, \'4 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<36, \'5 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<43, \'6 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<50, \'7 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<57, \'8 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<64, \'9 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<71, \'10 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<78, \'11 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<85, \'12 Weeks in Arrears\',\r\n \'12+ Weeks in Arrears\')))))))))))))) AS arrWeek\r\n\r\n FROM /* get the individual loan details */\r\n (SELECT ml.id AS loanId, ml.currency_code as currency,\r\n SUM(mr.principal_amount) principal, \r\n SUM(mr.interest_amount) interest, \r\n SUM(IFNULL(mr.principal_completed_derived,0)) prinPaid, \r\n SUM(IFNULL(mr.interest_completed_derived,0)) intPaid,\r\n\r\n SUM(IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), \r\n (mr.principal_amount - ifnull(mr.principal_completed_derived, 0))\r\n , 0)) as prinOverdue,\r\n SUM(IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), \r\n (mr.interest_amount - ifnull(mr.interest_completed_derived, 0))\r\n , 0)) as intOverdue,\r\n\r\n CAST(MIN(\r\n IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), mr.duedate, CURDATE() + 1)) as date) 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 INNER JOIN m_loan_repayment_schedule mr on mr.loan_id = ml.id\r\n WHERE ml.loan_status_id=300 /* active */\r\n AND mo.id=${officeId}\r\n GROUP BY ml.id) x\r\n ) z \r\nGROUP BY z.currency, z.arrWeek ) ars ON ars.arrWeek=weeks.week_no and ars.currency = weeks.currency\r\nORDER BY weeks.currency, weeks.wid','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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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\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 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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0), l.id, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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, 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_repayment_schedule r on r.loan_id = lastInstallment.loanId\r\ngroup by lastInstallment.loanId\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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0),lastInstallment.loanId, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.loan_id = lastInstallment.loanId\r\ngroup by lastInstallment.branchId) x on x.branchId = mo.id\r\norder by mo.hierarchy, x.Currency','Individual Client \n\nReport',1,1);
/*!40000 ALTER TABLE `stretchy_report` ENABLE KEYS */;
UNLOCK TABLES;
@@ -1800,7 +1801,7 @@ CREATE TABLE `stretchy_report_parameter` (
LOCK TABLES `stretchy_report_parameter` WRITE;
/*!40000 ALTER TABLE `stretchy_report_parameter` DISABLE KEYS */;
-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),(54,1,NULL),(54,2,NULL),(54,5,NULL),(54,10,NULL),(54,25,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),(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);
/*!40000 ALTER TABLE `stretchy_report_parameter` ENABLE KEYS */;
UNLOCK TABLES;
@@ -1836,4 +1837,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2013-02-21 1:34:26
+-- Dump completed on 2013-02-22 11:59:04
diff --git a/mifosng-db/multi-tenant-demo-backups/default-demo/bk_mifostenant-default.sql b/mifosng-db/multi-tenant-demo-backups/default-demo/bk_mifostenant-default.sql
index 69c00aaa6..1974df9db 100644
--- a/mifosng-db/multi-tenant-demo-backups/default-demo/bk_mifostenant-default.sql
+++ b/mifosng-db/multi-tenant-demo-backups/default-demo/bk_mifostenant-default.sql
@@ -770,7 +770,7 @@ CREATE TABLE `m_group_level` (
PRIMARY KEY (`id`),
KEY `Parent_levelId_reference` (`parent_id`),
CONSTRAINT `Parent_levelId_reference` FOREIGN KEY (`parent_id`) REFERENCES `m_group_level` (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -779,6 +779,7 @@ CREATE TABLE `m_group_level` (
LOCK TABLES `m_group_level` WRITE;
/*!40000 ALTER TABLE `m_group_level` DISABLE KEYS */;
+INSERT INTO `m_group_level` VALUES (1,NULL,1,'Center',1,0),(2,1,0,'Group',0,1);
/*!40000 ALTER TABLE `m_group_level` ENABLE KEYS */;
UNLOCK TABLES;
@@ -1260,7 +1261,7 @@ CREATE TABLE `m_permission` (
`can_maker_checker` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`),
UNIQUE KEY `code` (`code`)
-) ENGINE=InnoDB AUTO_INCREMENT=268 DEFAULT CHARSET=utf8;
+) ENGINE=InnoDB AUTO_INCREMENT=284 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -1269,7 +1270,7 @@ CREATE TABLE `m_permission` (
LOCK TABLES `m_permission` WRITE;
/*!40000 ALTER TABLE `m_permission` DISABLE KEYS */;
-INSERT INTO `m_permission` VALUES (1,'special','ALL_FUNCTIONS',NULL,NULL,0),(2,'special','ALL_FUNCTIONS_READ',NULL,NULL,0),(3,'special','CHECKER_SUPER_USER',NULL,NULL,0),(4,'special','REPORTING_SUPER_USER',NULL,NULL,0),(5,'authorisation','READ_PERMISSION','PERMISSION','READ',0),(6,'authorisation','PERMISSIONS_ROLE','ROLE','PERMISSIONS',1),(7,'authorisation','CREATE_ROLE','ROLE','CREATE',1),(8,'authorisation','CREATE_ROLE_CHECKER','ROLE','CREATE',1),(9,'authorisation','READ_ROLE','ROLE','READ',0),(10,'authorisation','UPDATE_ROLE','ROLE','UPDATE',1),(11,'authorisation','UPDATE_ROLE_CHECKER','ROLE','UPDATE',1),(12,'authorisation','DELETE_ROLE','ROLE','DELETE',1),(13,'authorisation','DELETE_ROLE_CHECKER','ROLE','DELETE',1),(14,'authorisation','CREATE_USER','USER','CREATE',1),(15,'authorisation','CREATE_USER_CHECKER','USER','CREATE',1),(16,'authorisation','READ_USER','USER','READ',0),(17,'authorisation','UPDATE_USER','USER','UPDATE',1),(18,'authorisation','UPDATE_USER_CHECKER','USER','UPDATE',1),(19,'authorisation','DELETE_USER','USER','DELETE',1),(20,'authorisation','DELETE_USER_CHECKER','USER','DELETE',1),(21,'configuration','READ_CONFIGURATION','CONFIGURATION','READ',1),(22,'configuration','UPDATE_CONFIGURATION','CONFIGURATION','UPDATE',1),(23,'configuration','UPDATE_CONFIGURATION_CHECKER','CONFIGURATION','UPDATE',1),(24,'configuration','READ_CODE','CODE','READ',0),(25,'configuration','CREATE_CODE','CODE','CREATE',1),(26,'configuration','CREATE_CODE_CHECKER','CODE','CREATE',1),(27,'configuration','UPDATE_CODE','CODE','UPDATE',1),(28,'configuration','UPDATE_CODE_CHECKER','CODE','UPDATE',1),(29,'configuration','DELETE_CODE','CODE','DELETE',1),(30,'configuration','DELETE_CODE_CHECKER','CODE','DELETE',1),(31,'configuration','READ_CODEVALUE','CODEVALUE','READ',0),(32,'configuration','CREATE_CODEVALUE','CODEVALUE','CREATE',1),(33,'configuration','CREATE_CODEVALUE_CHECKER','CODEVALUE','CREATE',1),(34,'configuration','UPDATE_CODEVALUE','CODEVALUE','UPDATE',1),(35,'configuration','UPDATE_CODEVALUE_CHECKER','CODEVALUE','UPDATE',1),(36,'configuration','DELETE_CODEVALUE','CODEVALUE','DELETE',1),(37,'configuration','DELETE_CODEVALUE_CHECKER','CODEVALUE','DELETE',1),(38,'configuration','READ_CURRENCY','CURRENCY','READ',0),(39,'configuration','UPDATE_CURRENCY','CURRENCY','UPDATE',1),(40,'configuration','UPDATE_CURRENCY_CHECKER','CURRENCY','UPDATE',1),(41,'configuration','UPDATE_PERMISSION','PERMISSION','UPDATE',1),(42,'configuration','UPDATE_PERMISSION_CHECKER','PERMISSION','UPDATE',1),(43,'configuration','READ_DATATABLE','DATATABLE','READ',0),(44,'configuration','REGISTER_DATATABLE','DATATABLE','REGISTER',1),(45,'configuration','REGISTER_DATATABLE_CHECKER','DATATABLE','REGISTER',1),(46,'configuration','DEREGISTER_DATATABLE','DATATABLE','DEREGISTER',1),(47,'configuration','DEREGISTER_DATATABLE_CHECKER','DATATABLE','DEREGISTER',1),(48,'configuration','READ_AUDIT','AUDIT','READ',0),(49,'organisation','READ_MAKERCHECKER','MAKERCHECKER','READ',0),(50,'organisation','READ_CHARGE','CHARGE','READ',0),(51,'organisation','CREATE_CHARGE','CHARGE','CREATE',1),(52,'organisation','CREATE_CHARGE_CHECKER','CHARGE','CREATE',1),(53,'organisation','UPDATE_CHARGE','CHARGE','UPDATE',1),(54,'organisation','UPDATE_CHARGE_CHECKER','CHARGE','UPDATE',1),(55,'organisation','DELETE_CHARGE','CHARGE','DELETE',1),(56,'organisation','DELETE_CHARGE_CHECKER','CHARGE','DELETE',1),(57,'organisation','READ_FUND','FUND','READ',0),(58,'organisation','CREATE_FUND','FUND','CREATE',1),(59,'organisation','CREATE_FUND_CHECKER','FUND','CREATE',1),(60,'organisation','UPDATE_FUND','FUND','UPDATE',1),(61,'organisation','UPDATE_FUND_CHECKER','FUND','UPDATE',1),(62,'organisation','DELETE_FUND','FUND','DELETE',1),(63,'organisation','DELETE_FUND_CHECKER','FUND','DELETE',1),(64,'organisation','READ_LOANPRODUCT','LOANPRODUCT','READ',0),(65,'organisation','CREATE_LOANPRODUCT','LOANPRODUCT','CREATE',1),(66,'organisation','CREATE_LOANPRODUCT_CHECKER','LOANPRODUCT','CREATE',1),(67,'organisation','UPDATE_LOANPRODUCT','LOANPRODUCT','UPDATE',1),(68,'organisation','UPDATE_LOANPRODUCT_CHECKER','LOANPRODUCT','UPDATE',1),(69,'organisation','DELETE_LOANPRODUCT','LOANPRODUCT','DELETE',1),(70,'organisation','DELETE_LOANPRODUCT_CHECKER','LOANPRODUCT','DELETE',1),(71,'organisation','READ_OFFICE','OFFICE','READ',0),(72,'organisation','CREATE_OFFICE','OFFICE','CREATE',1),(73,'organisation','CREATE_OFFICE_CHECKER','OFFICE','CREATE',1),(74,'organisation','UPDATE_OFFICE','OFFICE','UPDATE',1),(75,'organisation','UPDATE_OFFICE_CHECKER','OFFICE','UPDATE',1),(76,'organisation','READ_OFFICETRANSACTION','OFFICETRANSACTION','READ',0),(77,'organisation','DELETE_OFFICE_CHECKER','OFFICE','DELETE',1),(78,'organisation','CREATE_OFFICETRANSACTION','OFFICETRANSACTION','CREATE',1),(79,'organisation','CREATE_OFFICETRANSACTION_CHECKER','OFFICETRANSACTION','CREATE',1),(80,'organisation','DELETE_OFFICETRANSACTION','OFFICETRANSACTION','DELETE',1),(81,'organisation','DELETE_OFFICETRANSACTION_CHECKER','OFFICETRANSACTION','DELETE',1),(82,'organisation','READ_STAFF','STAFF','READ',0),(83,'organisation','CREATE_STAFF','STAFF','CREATE',1),(84,'organisation','CREATE_STAFF_CHECKER','STAFF','CREATE',1),(85,'organisation','UPDATE_STAFF','STAFF','UPDATE',1),(86,'organisation','UPDATE_STAFF_CHECKER','STAFF','UPDATE',1),(87,'organisation','DELETE_STAFF','STAFF','DELETE',1),(88,'organisation','DELETE_STAFF_CHECKER','STAFF','DELETE',1),(89,'organisation','READ_SAVINGSPRODUCT','SAVINGSPRODUCT','READ',0),(90,'organisation','CREATE_SAVINGSPRODUCT','SAVINGSPRODUCT','CREATE',1),(91,'organisation','CREATE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','CREATE',1),(92,'organisation','UPDATE_SAVINGSPRODUCT','SAVINGSPRODUCT','UPDATE',1),(93,'organisation','UPDATE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','UPDATE',1),(94,'organisation','DELETE_SAVINGSPRODUCT','SAVINGSPRODUCT','DELETE',1),(95,'organisation','DELETE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','DELETE',1),(96,'organisation','READ_DEPOSITPRODUCT','DEPOSITPRODUCT','READ',0),(97,'organisation','CREATE_DEPOSITPRODUCT','DEPOSITPRODUCT','CREATE',1),(98,'organisation','CREATE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','CREATE',1),(99,'organisation','UPDATE_DEPOSITPRODUCT','DEPOSITPRODUCT','UPDATE',1),(100,'organisation','UPDATE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','UPDATE',1),(101,'organisation','DELETE_DEPOSITPRODUCT','DEPOSITPRODUCT','DELETE',1),(102,'organisation','DELETE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','DELETE',1),(103,'portfolio','READ_LOAN','LOAN','READ',0),(104,'portfolio','CREATE_LOAN','LOAN','CREATE',1),(105,'portfolio','CREATE_LOAN_CHECKER','LOAN','CREATE',1),(106,'portfolio','UPDATE_LOAN','LOAN','UPDATE',1),(107,'portfolio','UPDATE_LOAN_CHECKER','LOAN','UPDATE',1),(108,'portfolio','DELETE_LOAN','LOAN','DELETE',1),(109,'portfolio','DELETE_LOAN_CHECKER','LOAN','DELETE',1),(110,'portfolio','READ_CLIENT','CLIENT','READ',0),(111,'portfolio','CREATE_CLIENT','CLIENT','CREATE',1),(112,'portfolio','CREATE_CLIENT_CHECKER','CLIENT','CREATE',1),(113,'portfolio','UPDATE_CLIENT','CLIENT','UPDATE',1),(114,'portfolio','UPDATE_CLIENT_CHECKER','CLIENT','UPDATE',1),(115,'portfolio','DELETE_CLIENT','CLIENT','DELETE',1),(116,'portfolio','DELETE_CLIENT_CHECKER','CLIENT','DELETE',1),(117,'portfolio','READ_CLIENTIMAGE','CLIENTIMAGE','READ',0),(118,'portfolio','CREATE_CLIENTIMAGE','CLIENTIMAGE','CREATE',1),(119,'portfolio','CREATE_CLIENTIMAGE_CHECKER','CLIENTIMAGE','CREATE',1),(120,'portfolio','DELETE_CLIENTIMAGE','CLIENTIMAGE','DELETE',1),(121,'portfolio','DELETE_CLIENTIMAGE_CHECKER','CLIENTIMAGE','DELETE',1),(122,'portfolio','READ_CLIENTNOTE','CLIENTNOTE','READ',0),(123,'portfolio','CREATE_CLIENTNOTE','CLIENTNOTE','CREATE',1),(124,'portfolio','CREATE_CLIENTNOTE_CHECKER','CLIENTNOTE','CREATE',1),(125,'portfolio','UPDATE_CLIENTNOTE','CLIENTNOTE','UPDATE',1),(126,'portfolio','UPDATE_CLIENTNOTE_CHECKER','CLIENTNOTE','UPDATE',1),(127,'portfolio','DELETE_CLIENTNOTE','CLIENTNOTE','DELETE',1),(128,'portfolio','DELETE_CLIENTNOTE_CHECKER','CLIENTNOTE','DELETE',1),(129,'portfolio','READ_CLIENTIDENTIFIER','CLIENTIDENTIFIER','READ',0),(130,'portfolio','CREATE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','CREATE',1),(131,'portfolio','CREATE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','CREATE',1),(132,'portfolio','UPDATE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','UPDATE',1),(133,'portfolio','UPDATE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','UPDATE',1),(134,'portfolio','DELETE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','DELETE',1),(135,'portfolio','DELETE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','DELETE',1),(136,'portfolio','READ_DOCUMENT','DOCUMENT','READ',0),(137,'portfolio','CREATE_DOCUMENT','DOCUMENT','CREATE',1),(138,'portfolio','CREATE_DOCUMENT_CHECKER','DOCUMENT','CREATE',1),(139,'portfolio','UPDATE_DOCUMENT','DOCUMENT','UPDATE',1),(140,'portfolio','UPDATE_DOCUMENT_CHECKER','DOCUMENT','UPDATE',1),(141,'portfolio','DELETE_DOCUMENT','DOCUMENT','DELETE',1),(142,'portfolio','DELETE_DOCUMENT_CHECKER','DOCUMENT','DELETE',1),(143,'portfolio','READ_GROUP','GROUP','READ',0),(144,'portfolio','CREATE_GROUP','GROUP','CREATE',1),(145,'portfolio','CREATE_GROUP_CHECKER','GROUP','CREATE',1),(146,'portfolio','UPDATE_GROUP','GROUP','UPDATE',1),(147,'portfolio','UPDATE_GROUP_CHECKER','GROUP','UPDATE',1),(148,'portfolio','DELETE_GROUP','GROUP','DELETE',1),(149,'portfolio','DELETE_GROUP_CHECKER','GROUP','DELETE',1),(150,'portfolio','CREATE_LOANCHARGE','LOANCHARGE','CREATE',1),(151,'portfolio','CREATE_LOANCHARGE_CHECKER','LOANCHARGE','CREATE',1),(152,'portfolio','UPDATE_LOANCHARGE','LOANCHARGE','UPDATE',1),(153,'portfolio','UPDATE_LOANCHARGE_CHECKER','LOANCHARGE','UPDATE',1),(154,'portfolio','DELETE_LOANCHARGE','LOANCHARGE','DELETE',1),(155,'portfolio','DELETE_LOANCHARGE_CHECKER','LOANCHARGE','DELETE',1),(156,'portfolio','WAIVE_LOANCHARGE','LOANCHARGE','WAIVE',1),(157,'portfolio','WAIVE_LOANCHARGE_CHECKER','LOANCHARGE','WAIVE',1),(158,'portfolio','READ_DEPOSITACCOUNT','DEPOSITACCOUNT','READ',0),(159,'portfolio','CREATE_DEPOSITACCOUNT','DEPOSITACCOUNT','CREATE',1),(160,'portfolio','CREATE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','CREATE',1),(161,'portfolio','UPDATE_DEPOSITACCOUNT','DEPOSITACCOUNT','UPDATE',1),(162,'portfolio','UPDATE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','UPDATE',1),(163,'portfolio','DELETE_DEPOSITACCOUNT','DEPOSITACCOUNT','DELETE',1),(164,'portfolio','DELETE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','DELETE',1),(165,'portfolio','READ_SAVINGSACCOUNT','SAVINGSACCOUNT','READ',0),(166,'portfolio','CREATE_SAVINGSACCOUNT','SAVINGSACCOUNT','CREATE',1),(167,'portfolio','CREATE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','CREATE',1),(168,'portfolio','UPDATE_SAVINGSACCOUNT','SAVINGSACCOUNT','UPDATE',1),(169,'portfolio','UPDATE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','UPDATE',1),(170,'portfolio','DELETE_SAVINGSACCOUNT','SAVINGSACCOUNT','DELETE',1),(171,'portfolio','DELETE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','DELETE',1),(172,'portfolio','READ_GUARANTOR','GUARANTOR','READ',0),(173,'portfolio','CREATE_GUARANTOR','GUARANTOR','CREATE',1),(174,'portfolio','CREATE_GUARANTOR_CHECKER','GUARANTOR','CREATE',1),(175,'portfolio','UPDATE_GUARANTOR','GUARANTOR','UPDATE',1),(176,'portfolio','UPDATE_GUARANTOR_CHECKER','GUARANTOR','UPDATE',1),(177,'portfolio','DELETE_GUARANTOR','GUARANTOR','DELETE',1),(178,'portfolio','DELETE_GUARANTOR_CHECKER','GUARANTOR','DELETE',1),(179,'transaction_loan','APPROVE_LOAN','LOAN','APPROVE',1),(180,'transaction_loan','APPROVEINPAST_LOAN','LOAN','APPROVEINPAST',1),(181,'transaction_loan','REJECT_LOAN','LOAN','REJECT',1),(182,'transaction_loan','REJECTINPAST_LOAN','LOAN','REJECTINPAST',1),(183,'transaction_loan','WITHDRAW_LOAN','LOAN','WITHDRAW',1),(184,'transaction_loan','WITHDRAWINPAST_LOAN','LOAN','WITHDRAWINPAST',1),(185,'transaction_loan','APPROVALUNDO_LOAN','LOAN','APPROVALUNDO',1),(186,'transaction_loan','DISBURSE_LOAN','LOAN','DISBURSE',1),(187,'transaction_loan','DISBURSEINPAST_LOAN','LOAN','DISBURSEINPAST',1),(188,'transaction_loan','DISBURSALUNDO_LOAN','LOAN','DISBURSALUNDO',1),(189,'transaction_loan','REPAYMENT_LOAN','LOAN','REPAYMENT',1),(190,'transaction_loan','REPAYMENTINPAST_LOAN','LOAN','REPAYMENTINPAST',1),(191,'transaction_loan','ADJUST_LOAN','LOAN','ADJUST',1),(192,'transaction_loan','WAIVEINTERESTPORTION_LOAN','LOAN','WAIVEINTERESTPORTION',1),(193,'transaction_loan','WRITEOFF_LOAN','LOAN','WRITEOFF',1),(194,'transaction_loan','CLOSE_LOAN','LOAN','CLOSE',1),(195,'transaction_loan','CLOSEASRESCHEDULED_LOAN','LOAN','CLOSEASRESCHEDULED',1),(196,'transaction_loan','UPDATELOANOFFICER_LOAN','LOAN','UPDATELOANOFFICER',1),(197,'transaction_loan','UPDATELOANOFFICER_LOAN_CHECKER','LOAN','UPDATELOANOFFICER',1),(198,'transaction_loan','REMOVELOANOFFICER_LOAN','LOAN','REMOVELOANOFFICER',1),(199,'transaction_loan','REMOVELOANOFFICER_LOAN_CHECKER','LOAN','REMOVELOANOFFICER',1),(200,'transaction_loan','BULKREASSIGN_LOAN','LOAN','BULKREASSIGN',1),(201,'transaction_loan','BULKREASSIGN_LOAN_CHECKER','LOAN','BULKREASSIGN',1),(202,'transaction_loan','APPROVE_LOAN_CHECKER','LOAN','APPROVE',1),(203,'transaction_loan','APPROVEINPAST_LOAN_CHECKER','LOAN','APPROVEINPAST',1),(204,'transaction_loan','REJECT_LOAN_CHECKER','LOAN','REJECT',1),(205,'transaction_loan','REJECTINPAST_LOAN_CHECKER','LOAN','REJECTINPAST',1),(206,'transaction_loan','WITHDRAW_LOAN_CHECKER','LOAN','WITHDRAW',1),(207,'transaction_loan','WITHDRAWINPAST_LOAN_CHECKER','LOAN','WITHDRAWINPAST',1),(208,'transaction_loan','APPROVALUNDO_LOAN_CHECKER','LOAN','APPROVALUNDO',1),(209,'transaction_loan','DISBURSE_LOAN_CHECKER','LOAN','DISBURSE',1),(210,'transaction_loan','DISBURSEINPAST_LOAN_CHECKER','LOAN','DISBURSEINPAST',1),(211,'transaction_loan','DISBURSALUNDO_LOAN_CHECKER','LOAN','DISBURSALUNDO',1),(212,'transaction_loan','REPAYMENT_LOAN_CHECKER','LOAN','REPAYMENT',1),(213,'transaction_loan','REPAYMENTINPAST_LOAN_CHECKER','LOAN','REPAYMENTINPAST',1),(214,'transaction_loan','ADJUST_LOAN_CHECKER','LOAN','ADJUST',1),(215,'transaction_loan','WAIVEINTERESTPORTION_LOAN_CHECKER','LOAN','WAIVEINTERESTPORTION',1),(216,'transaction_loan','WRITEOFF_LOAN_CHECKER','LOAN','WRITEOFF',1),(217,'transaction_loan','CLOSE_LOAN_CHECKER','LOAN','CLOSE',1),(218,'transaction_loan','CLOSEASRESCHEDULED_LOAN_CHECKER','LOAN','CLOSEASRESCHEDULED',1),(219,'transaction_deposit','APPROVE_DEPOSITACCOUNT','DEPOSITACCOUNT','APPROVE',1),(220,'transaction_deposit','REJECT_DEPOSITACCOUNT','DEPOSITACCOUNT','REJECT',1),(221,'transaction_deposit','WITHDRAW_DEPOSITACCOUNT','DEPOSITACCOUNT','WITHDRAW',1),(222,'transaction_deposit','APPROVALUNDO_DEPOSITACCOUNT','DEPOSITACCOUNT','APPROVALUNDO',1),(223,'transaction_deposit','WITHDRAWAL_DEPOSITACCOUNT','DEPOSITACCOUNT','WITHDRAWAL',1),(224,'transaction_deposit','INTEREST_DEPOSITACCOUNT','DEPOSITACCOUNT','INTEREST',1),(225,'transaction_deposit','RENEW_DEPOSITACCOUNT','DEPOSITACCOUNT','RENEW',1),(226,'transaction_deposit','APPROVE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','APPROVE',1),(227,'transaction_deposit','REJECT_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','REJECT',1),(228,'transaction_deposit','WITHDRAW_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','WITHDRAW',1),(229,'transaction_deposit','APPROVALUNDO_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','APPROVALUNDO',1),(230,'transaction_deposit','WITHDRAWAL_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','WITHDRAWAL',1),(231,'transaction_deposit','INTEREST_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','INTEREST',1),(232,'transaction_deposit','RENEW_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','RENEW',1),(233,'accounting','CREATE_GLACCOUNT','GLACCOUNT','CREATE',1),(234,'accounting','UPDATE_GLACCOUNT','GLACCOUNT','UPDATE',1),(235,'accounting','DELETE_GLACCOUNT','GLACCOUNT','DELETE',1),(236,'accounting','CREATE_GLCLOSURE','GLCLOSURE','CREATE',1),(237,'accounting','UPDATE_GLCLOSURE','GLCLOSURE','UPDATE',1),(238,'accounting','DELETE_GLCLOSURE','GLCLOSURE','DELETE',1),(239,'accounting','CREATE_JOURNALENTRY','JOURNALENTRY','CREATE',1),(240,'accounting','REVERSE_JOURNALENTRY','JOURNALENTRY','REVERSE',1),(241,'report','READ_Active Loans Portfolio Status','Active Loans Portfolio Status','READ',1),(242,'report','READ_Active Loans Summary per Branch','Active Loans Summary per Branch','READ',1),(243,'report','READ_Balance Sheet','Balance Sheet','READ',1),(244,'report','READ_Client Listing','Client Listing','READ',1),(245,'report','READ_Client Loans Listing','Client Loans Listing','READ',1),(246,'report','READ_Funds Disbursed Between Dates Summary','Funds Disbursed Between Dates Summary','READ',1),(247,'report','READ_Funds Disbursed Between Dates Summary by Office','Funds Disbursed Between Dates Summary by Office','READ',1),(248,'report','READ_Income Statement','Income Statement','READ',1),(249,'report','READ_Loans Awaiting Disbursal','Loans Awaiting Disbursal','READ',1),(250,'report','READ_Loans Awaiting Disbursal Summary','Loans Awaiting Disbursal Summary','READ',1),(251,'report','READ_Loans Awaiting Disbursal Summary by Month','Loans Awaiting Disbursal Summary by Month','READ',1),(252,'report','READ_Portfolio at Risk','Portfolio at Risk','READ',1),(253,'report','READ_Portfolio at Risk by Branch','Portfolio at Risk by Branch','READ',1),(254,'report','READ_Trial Balance','Trial Balance','READ',1),(256,'datatable','CREATE_extra_client_details','extra_client_details','CREATE',1),(257,'datatable','CREATE_extra_family_details','extra_family_details','CREATE',1),(258,'datatable','CREATE_extra_loan_details','extra_loan_details','CREATE',1),(259,'datatable','READ_extra_client_details','extra_client_details','READ',1),(260,'datatable','READ_extra_family_details','extra_family_details','READ',1),(261,'datatable','READ_extra_loan_details','extra_loan_details','READ',1),(262,'datatable','UPDATE_extra_client_details','extra_client_details','UPDATE',1),(263,'datatable','UPDATE_extra_family_details','extra_family_details','UPDATE',1),(264,'datatable','UPDATE_extra_loan_details','extra_loan_details','UPDATE',1),(265,'datatable','DELETE_extra_client_details','extra_client_details','DELETE',1),(266,'datatable','DELETE_extra_family_details','extra_family_details','DELETE',1),(267,'datatable','DELETE_extra_loan_details','extra_loan_details','DELETE',1);
+INSERT INTO `m_permission` VALUES (1,'special','ALL_FUNCTIONS',NULL,NULL,0),(2,'special','ALL_FUNCTIONS_READ',NULL,NULL,0),(3,'special','CHECKER_SUPER_USER',NULL,NULL,0),(4,'special','REPORTING_SUPER_USER',NULL,NULL,0),(5,'authorisation','READ_PERMISSION','PERMISSION','READ',0),(6,'authorisation','PERMISSIONS_ROLE','ROLE','PERMISSIONS',1),(7,'authorisation','CREATE_ROLE','ROLE','CREATE',1),(8,'authorisation','CREATE_ROLE_CHECKER','ROLE','CREATE',1),(9,'authorisation','READ_ROLE','ROLE','READ',0),(10,'authorisation','UPDATE_ROLE','ROLE','UPDATE',1),(11,'authorisation','UPDATE_ROLE_CHECKER','ROLE','UPDATE',1),(12,'authorisation','DELETE_ROLE','ROLE','DELETE',1),(13,'authorisation','DELETE_ROLE_CHECKER','ROLE','DELETE',1),(14,'authorisation','CREATE_USER','USER','CREATE',1),(15,'authorisation','CREATE_USER_CHECKER','USER','CREATE',1),(16,'authorisation','READ_USER','USER','READ',0),(17,'authorisation','UPDATE_USER','USER','UPDATE',1),(18,'authorisation','UPDATE_USER_CHECKER','USER','UPDATE',1),(19,'authorisation','DELETE_USER','USER','DELETE',1),(20,'authorisation','DELETE_USER_CHECKER','USER','DELETE',1),(21,'configuration','READ_CONFIGURATION','CONFIGURATION','READ',1),(22,'configuration','UPDATE_CONFIGURATION','CONFIGURATION','UPDATE',1),(23,'configuration','UPDATE_CONFIGURATION_CHECKER','CONFIGURATION','UPDATE',1),(24,'configuration','READ_CODE','CODE','READ',0),(25,'configuration','CREATE_CODE','CODE','CREATE',1),(26,'configuration','CREATE_CODE_CHECKER','CODE','CREATE',1),(27,'configuration','UPDATE_CODE','CODE','UPDATE',1),(28,'configuration','UPDATE_CODE_CHECKER','CODE','UPDATE',1),(29,'configuration','DELETE_CODE','CODE','DELETE',1),(30,'configuration','DELETE_CODE_CHECKER','CODE','DELETE',1),(31,'configuration','READ_CODEVALUE','CODEVALUE','READ',0),(32,'configuration','CREATE_CODEVALUE','CODEVALUE','CREATE',1),(33,'configuration','CREATE_CODEVALUE_CHECKER','CODEVALUE','CREATE',1),(34,'configuration','UPDATE_CODEVALUE','CODEVALUE','UPDATE',1),(35,'configuration','UPDATE_CODEVALUE_CHECKER','CODEVALUE','UPDATE',1),(36,'configuration','DELETE_CODEVALUE','CODEVALUE','DELETE',1),(37,'configuration','DELETE_CODEVALUE_CHECKER','CODEVALUE','DELETE',1),(38,'configuration','READ_CURRENCY','CURRENCY','READ',0),(39,'configuration','UPDATE_CURRENCY','CURRENCY','UPDATE',1),(40,'configuration','UPDATE_CURRENCY_CHECKER','CURRENCY','UPDATE',1),(41,'configuration','UPDATE_PERMISSION','PERMISSION','UPDATE',1),(42,'configuration','UPDATE_PERMISSION_CHECKER','PERMISSION','UPDATE',1),(43,'configuration','READ_DATATABLE','DATATABLE','READ',0),(44,'configuration','REGISTER_DATATABLE','DATATABLE','REGISTER',1),(45,'configuration','REGISTER_DATATABLE_CHECKER','DATATABLE','REGISTER',1),(46,'configuration','DEREGISTER_DATATABLE','DATATABLE','DEREGISTER',1),(47,'configuration','DEREGISTER_DATATABLE_CHECKER','DATATABLE','DEREGISTER',1),(48,'configuration','READ_AUDIT','AUDIT','READ',0),(49,'organisation','READ_MAKERCHECKER','MAKERCHECKER','READ',0),(50,'organisation','READ_CHARGE','CHARGE','READ',0),(51,'organisation','CREATE_CHARGE','CHARGE','CREATE',1),(52,'organisation','CREATE_CHARGE_CHECKER','CHARGE','CREATE',1),(53,'organisation','UPDATE_CHARGE','CHARGE','UPDATE',1),(54,'organisation','UPDATE_CHARGE_CHECKER','CHARGE','UPDATE',1),(55,'organisation','DELETE_CHARGE','CHARGE','DELETE',1),(56,'organisation','DELETE_CHARGE_CHECKER','CHARGE','DELETE',1),(57,'organisation','READ_FUND','FUND','READ',0),(58,'organisation','CREATE_FUND','FUND','CREATE',1),(59,'organisation','CREATE_FUND_CHECKER','FUND','CREATE',1),(60,'organisation','UPDATE_FUND','FUND','UPDATE',1),(61,'organisation','UPDATE_FUND_CHECKER','FUND','UPDATE',1),(62,'organisation','DELETE_FUND','FUND','DELETE',1),(63,'organisation','DELETE_FUND_CHECKER','FUND','DELETE',1),(64,'organisation','READ_LOANPRODUCT','LOANPRODUCT','READ',0),(65,'organisation','CREATE_LOANPRODUCT','LOANPRODUCT','CREATE',1),(66,'organisation','CREATE_LOANPRODUCT_CHECKER','LOANPRODUCT','CREATE',1),(67,'organisation','UPDATE_LOANPRODUCT','LOANPRODUCT','UPDATE',1),(68,'organisation','UPDATE_LOANPRODUCT_CHECKER','LOANPRODUCT','UPDATE',1),(69,'organisation','DELETE_LOANPRODUCT','LOANPRODUCT','DELETE',1),(70,'organisation','DELETE_LOANPRODUCT_CHECKER','LOANPRODUCT','DELETE',1),(71,'organisation','READ_OFFICE','OFFICE','READ',0),(72,'organisation','CREATE_OFFICE','OFFICE','CREATE',1),(73,'organisation','CREATE_OFFICE_CHECKER','OFFICE','CREATE',1),(74,'organisation','UPDATE_OFFICE','OFFICE','UPDATE',1),(75,'organisation','UPDATE_OFFICE_CHECKER','OFFICE','UPDATE',1),(76,'organisation','READ_OFFICETRANSACTION','OFFICETRANSACTION','READ',0),(77,'organisation','DELETE_OFFICE_CHECKER','OFFICE','DELETE',1),(78,'organisation','CREATE_OFFICETRANSACTION','OFFICETRANSACTION','CREATE',1),(79,'organisation','CREATE_OFFICETRANSACTION_CHECKER','OFFICETRANSACTION','CREATE',1),(80,'organisation','DELETE_OFFICETRANSACTION','OFFICETRANSACTION','DELETE',1),(81,'organisation','DELETE_OFFICETRANSACTION_CHECKER','OFFICETRANSACTION','DELETE',1),(82,'organisation','READ_STAFF','STAFF','READ',0),(83,'organisation','CREATE_STAFF','STAFF','CREATE',1),(84,'organisation','CREATE_STAFF_CHECKER','STAFF','CREATE',1),(85,'organisation','UPDATE_STAFF','STAFF','UPDATE',1),(86,'organisation','UPDATE_STAFF_CHECKER','STAFF','UPDATE',1),(87,'organisation','DELETE_STAFF','STAFF','DELETE',1),(88,'organisation','DELETE_STAFF_CHECKER','STAFF','DELETE',1),(89,'organisation','READ_SAVINGSPRODUCT','SAVINGSPRODUCT','READ',0),(90,'organisation','CREATE_SAVINGSPRODUCT','SAVINGSPRODUCT','CREATE',1),(91,'organisation','CREATE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','CREATE',1),(92,'organisation','UPDATE_SAVINGSPRODUCT','SAVINGSPRODUCT','UPDATE',1),(93,'organisation','UPDATE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','UPDATE',1),(94,'organisation','DELETE_SAVINGSPRODUCT','SAVINGSPRODUCT','DELETE',1),(95,'organisation','DELETE_SAVINGSPRODUCT_CHECKER','SAVINGSPRODUCT','DELETE',1),(96,'organisation','READ_DEPOSITPRODUCT','DEPOSITPRODUCT','READ',0),(97,'organisation','CREATE_DEPOSITPRODUCT','DEPOSITPRODUCT','CREATE',1),(98,'organisation','CREATE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','CREATE',1),(99,'organisation','UPDATE_DEPOSITPRODUCT','DEPOSITPRODUCT','UPDATE',1),(100,'organisation','UPDATE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','UPDATE',1),(101,'organisation','DELETE_DEPOSITPRODUCT','DEPOSITPRODUCT','DELETE',1),(102,'organisation','DELETE_DEPOSITPRODUCT_CHECKER','DEPOSITPRODUCT','DELETE',1),(103,'portfolio','READ_LOAN','LOAN','READ',0),(104,'portfolio','CREATE_LOAN','LOAN','CREATE',1),(105,'portfolio','CREATE_LOAN_CHECKER','LOAN','CREATE',1),(106,'portfolio','UPDATE_LOAN','LOAN','UPDATE',1),(107,'portfolio','UPDATE_LOAN_CHECKER','LOAN','UPDATE',1),(108,'portfolio','DELETE_LOAN','LOAN','DELETE',1),(109,'portfolio','DELETE_LOAN_CHECKER','LOAN','DELETE',1),(110,'portfolio','READ_CLIENT','CLIENT','READ',0),(111,'portfolio','CREATE_CLIENT','CLIENT','CREATE',1),(112,'portfolio','CREATE_CLIENT_CHECKER','CLIENT','CREATE',1),(113,'portfolio','UPDATE_CLIENT','CLIENT','UPDATE',1),(114,'portfolio','UPDATE_CLIENT_CHECKER','CLIENT','UPDATE',1),(115,'portfolio','DELETE_CLIENT','CLIENT','DELETE',1),(116,'portfolio','DELETE_CLIENT_CHECKER','CLIENT','DELETE',1),(117,'portfolio','READ_CLIENTIMAGE','CLIENTIMAGE','READ',0),(118,'portfolio','CREATE_CLIENTIMAGE','CLIENTIMAGE','CREATE',1),(119,'portfolio','CREATE_CLIENTIMAGE_CHECKER','CLIENTIMAGE','CREATE',1),(120,'portfolio','DELETE_CLIENTIMAGE','CLIENTIMAGE','DELETE',1),(121,'portfolio','DELETE_CLIENTIMAGE_CHECKER','CLIENTIMAGE','DELETE',1),(122,'portfolio','READ_CLIENTNOTE','CLIENTNOTE','READ',0),(123,'portfolio','CREATE_CLIENTNOTE','CLIENTNOTE','CREATE',1),(124,'portfolio','CREATE_CLIENTNOTE_CHECKER','CLIENTNOTE','CREATE',1),(125,'portfolio','UPDATE_CLIENTNOTE','CLIENTNOTE','UPDATE',1),(126,'portfolio','UPDATE_CLIENTNOTE_CHECKER','CLIENTNOTE','UPDATE',1),(127,'portfolio','DELETE_CLIENTNOTE','CLIENTNOTE','DELETE',1),(128,'portfolio','DELETE_CLIENTNOTE_CHECKER','CLIENTNOTE','DELETE',1),(129,'portfolio','READ_CLIENTIDENTIFIER','CLIENTIDENTIFIER','READ',0),(130,'portfolio','CREATE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','CREATE',1),(131,'portfolio','CREATE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','CREATE',1),(132,'portfolio','UPDATE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','UPDATE',1),(133,'portfolio','UPDATE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','UPDATE',1),(134,'portfolio','DELETE_CLIENTIDENTIFIER','CLIENTIDENTIFIER','DELETE',1),(135,'portfolio','DELETE_CLIENTIDENTIFIER_CHECKER','CLIENTIDENTIFIER','DELETE',1),(136,'portfolio','READ_DOCUMENT','DOCUMENT','READ',0),(137,'portfolio','CREATE_DOCUMENT','DOCUMENT','CREATE',1),(138,'portfolio','CREATE_DOCUMENT_CHECKER','DOCUMENT','CREATE',1),(139,'portfolio','UPDATE_DOCUMENT','DOCUMENT','UPDATE',1),(140,'portfolio','UPDATE_DOCUMENT_CHECKER','DOCUMENT','UPDATE',1),(141,'portfolio','DELETE_DOCUMENT','DOCUMENT','DELETE',1),(142,'portfolio','DELETE_DOCUMENT_CHECKER','DOCUMENT','DELETE',1),(143,'portfolio','READ_GROUP','GROUP','READ',0),(144,'portfolio','CREATE_GROUP','GROUP','CREATE',1),(145,'portfolio','CREATE_GROUP_CHECKER','GROUP','CREATE',1),(146,'portfolio','UPDATE_GROUP','GROUP','UPDATE',1),(147,'portfolio','UPDATE_GROUP_CHECKER','GROUP','UPDATE',1),(148,'portfolio','DELETE_GROUP','GROUP','DELETE',1),(149,'portfolio','DELETE_GROUP_CHECKER','GROUP','DELETE',1),(150,'portfolio','CREATE_LOANCHARGE','LOANCHARGE','CREATE',1),(151,'portfolio','CREATE_LOANCHARGE_CHECKER','LOANCHARGE','CREATE',1),(152,'portfolio','UPDATE_LOANCHARGE','LOANCHARGE','UPDATE',1),(153,'portfolio','UPDATE_LOANCHARGE_CHECKER','LOANCHARGE','UPDATE',1),(154,'portfolio','DELETE_LOANCHARGE','LOANCHARGE','DELETE',1),(155,'portfolio','DELETE_LOANCHARGE_CHECKER','LOANCHARGE','DELETE',1),(156,'portfolio','WAIVE_LOANCHARGE','LOANCHARGE','WAIVE',1),(157,'portfolio','WAIVE_LOANCHARGE_CHECKER','LOANCHARGE','WAIVE',1),(158,'portfolio','READ_DEPOSITACCOUNT','DEPOSITACCOUNT','READ',0),(159,'portfolio','CREATE_DEPOSITACCOUNT','DEPOSITACCOUNT','CREATE',1),(160,'portfolio','CREATE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','CREATE',1),(161,'portfolio','UPDATE_DEPOSITACCOUNT','DEPOSITACCOUNT','UPDATE',1),(162,'portfolio','UPDATE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','UPDATE',1),(163,'portfolio','DELETE_DEPOSITACCOUNT','DEPOSITACCOUNT','DELETE',1),(164,'portfolio','DELETE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','DELETE',1),(165,'portfolio','READ_SAVINGSACCOUNT','SAVINGSACCOUNT','READ',0),(166,'portfolio','CREATE_SAVINGSACCOUNT','SAVINGSACCOUNT','CREATE',1),(167,'portfolio','CREATE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','CREATE',1),(168,'portfolio','UPDATE_SAVINGSACCOUNT','SAVINGSACCOUNT','UPDATE',1),(169,'portfolio','UPDATE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','UPDATE',1),(170,'portfolio','DELETE_SAVINGSACCOUNT','SAVINGSACCOUNT','DELETE',1),(171,'portfolio','DELETE_SAVINGSACCOUNT_CHECKER','SAVINGSACCOUNT','DELETE',1),(172,'portfolio','READ_GUARANTOR','GUARANTOR','READ',0),(173,'portfolio','CREATE_GUARANTOR','GUARANTOR','CREATE',1),(174,'portfolio','CREATE_GUARANTOR_CHECKER','GUARANTOR','CREATE',1),(175,'portfolio','UPDATE_GUARANTOR','GUARANTOR','UPDATE',1),(176,'portfolio','UPDATE_GUARANTOR_CHECKER','GUARANTOR','UPDATE',1),(177,'portfolio','DELETE_GUARANTOR','GUARANTOR','DELETE',1),(178,'portfolio','DELETE_GUARANTOR_CHECKER','GUARANTOR','DELETE',1),(179,'transaction_loan','APPROVE_LOAN','LOAN','APPROVE',1),(180,'transaction_loan','APPROVEINPAST_LOAN','LOAN','APPROVEINPAST',1),(181,'transaction_loan','REJECT_LOAN','LOAN','REJECT',1),(182,'transaction_loan','REJECTINPAST_LOAN','LOAN','REJECTINPAST',1),(183,'transaction_loan','WITHDRAW_LOAN','LOAN','WITHDRAW',1),(184,'transaction_loan','WITHDRAWINPAST_LOAN','LOAN','WITHDRAWINPAST',1),(185,'transaction_loan','APPROVALUNDO_LOAN','LOAN','APPROVALUNDO',1),(186,'transaction_loan','DISBURSE_LOAN','LOAN','DISBURSE',1),(187,'transaction_loan','DISBURSEINPAST_LOAN','LOAN','DISBURSEINPAST',1),(188,'transaction_loan','DISBURSALUNDO_LOAN','LOAN','DISBURSALUNDO',1),(189,'transaction_loan','REPAYMENT_LOAN','LOAN','REPAYMENT',1),(190,'transaction_loan','REPAYMENTINPAST_LOAN','LOAN','REPAYMENTINPAST',1),(191,'transaction_loan','ADJUST_LOAN','LOAN','ADJUST',1),(192,'transaction_loan','WAIVEINTERESTPORTION_LOAN','LOAN','WAIVEINTERESTPORTION',1),(193,'transaction_loan','WRITEOFF_LOAN','LOAN','WRITEOFF',1),(194,'transaction_loan','CLOSE_LOAN','LOAN','CLOSE',1),(195,'transaction_loan','CLOSEASRESCHEDULED_LOAN','LOAN','CLOSEASRESCHEDULED',1),(196,'transaction_loan','UPDATELOANOFFICER_LOAN','LOAN','UPDATELOANOFFICER',1),(197,'transaction_loan','UPDATELOANOFFICER_LOAN_CHECKER','LOAN','UPDATELOANOFFICER',1),(198,'transaction_loan','REMOVELOANOFFICER_LOAN','LOAN','REMOVELOANOFFICER',1),(199,'transaction_loan','REMOVELOANOFFICER_LOAN_CHECKER','LOAN','REMOVELOANOFFICER',1),(200,'transaction_loan','BULKREASSIGN_LOAN','LOAN','BULKREASSIGN',1),(201,'transaction_loan','BULKREASSIGN_LOAN_CHECKER','LOAN','BULKREASSIGN',1),(202,'transaction_loan','APPROVE_LOAN_CHECKER','LOAN','APPROVE',1),(203,'transaction_loan','APPROVEINPAST_LOAN_CHECKER','LOAN','APPROVEINPAST',1),(204,'transaction_loan','REJECT_LOAN_CHECKER','LOAN','REJECT',1),(205,'transaction_loan','REJECTINPAST_LOAN_CHECKER','LOAN','REJECTINPAST',1),(206,'transaction_loan','WITHDRAW_LOAN_CHECKER','LOAN','WITHDRAW',1),(207,'transaction_loan','WITHDRAWINPAST_LOAN_CHECKER','LOAN','WITHDRAWINPAST',1),(208,'transaction_loan','APPROVALUNDO_LOAN_CHECKER','LOAN','APPROVALUNDO',1),(209,'transaction_loan','DISBURSE_LOAN_CHECKER','LOAN','DISBURSE',1),(210,'transaction_loan','DISBURSEINPAST_LOAN_CHECKER','LOAN','DISBURSEINPAST',1),(211,'transaction_loan','DISBURSALUNDO_LOAN_CHECKER','LOAN','DISBURSALUNDO',1),(212,'transaction_loan','REPAYMENT_LOAN_CHECKER','LOAN','REPAYMENT',1),(213,'transaction_loan','REPAYMENTINPAST_LOAN_CHECKER','LOAN','REPAYMENTINPAST',1),(214,'transaction_loan','ADJUST_LOAN_CHECKER','LOAN','ADJUST',1),(215,'transaction_loan','WAIVEINTERESTPORTION_LOAN_CHECKER','LOAN','WAIVEINTERESTPORTION',1),(216,'transaction_loan','WRITEOFF_LOAN_CHECKER','LOAN','WRITEOFF',1),(217,'transaction_loan','CLOSE_LOAN_CHECKER','LOAN','CLOSE',1),(218,'transaction_loan','CLOSEASRESCHEDULED_LOAN_CHECKER','LOAN','CLOSEASRESCHEDULED',1),(219,'transaction_deposit','APPROVE_DEPOSITACCOUNT','DEPOSITACCOUNT','APPROVE',1),(220,'transaction_deposit','REJECT_DEPOSITACCOUNT','DEPOSITACCOUNT','REJECT',1),(221,'transaction_deposit','WITHDRAW_DEPOSITACCOUNT','DEPOSITACCOUNT','WITHDRAW',1),(222,'transaction_deposit','APPROVALUNDO_DEPOSITACCOUNT','DEPOSITACCOUNT','APPROVALUNDO',1),(223,'transaction_deposit','WITHDRAWAL_DEPOSITACCOUNT','DEPOSITACCOUNT','WITHDRAWAL',1),(224,'transaction_deposit','INTEREST_DEPOSITACCOUNT','DEPOSITACCOUNT','INTEREST',1),(225,'transaction_deposit','RENEW_DEPOSITACCOUNT','DEPOSITACCOUNT','RENEW',1),(226,'transaction_deposit','APPROVE_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','APPROVE',1),(227,'transaction_deposit','REJECT_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','REJECT',1),(228,'transaction_deposit','WITHDRAW_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','WITHDRAW',1),(229,'transaction_deposit','APPROVALUNDO_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','APPROVALUNDO',1),(230,'transaction_deposit','WITHDRAWAL_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','WITHDRAWAL',1),(231,'transaction_deposit','INTEREST_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','INTEREST',1),(232,'transaction_deposit','RENEW_DEPOSITACCOUNT_CHECKER','DEPOSITACCOUNT','RENEW',1),(233,'accounting','CREATE_GLACCOUNT','GLACCOUNT','CREATE',1),(234,'accounting','UPDATE_GLACCOUNT','GLACCOUNT','UPDATE',1),(235,'accounting','DELETE_GLACCOUNT','GLACCOUNT','DELETE',1),(236,'accounting','CREATE_GLCLOSURE','GLCLOSURE','CREATE',1),(237,'accounting','UPDATE_GLCLOSURE','GLCLOSURE','UPDATE',1),(238,'accounting','DELETE_GLCLOSURE','GLCLOSURE','DELETE',1),(239,'accounting','CREATE_JOURNALENTRY','JOURNALENTRY','CREATE',1),(240,'accounting','REVERSE_JOURNALENTRY','JOURNALENTRY','REVERSE',1),(241,'report','READ_Active Loans Details','Active Loans Details','READ',1),(242,'report','READ_Active Loans in last installment','Active Loans in last installment','READ',1),(243,'report','READ_Active Loans in last installment Summary','Active Loans in last installment Summary','READ',1),(244,'report','READ_Active Loans Passed Final Maturity','Active Loans Passed Final Maturity','READ',1),(245,'report','READ_Active Loans Passed Final Maturity Summary','Active Loans Passed Final Maturity Summary','READ',1),(246,'report','READ_Active Loans Summary','Active Loans Summary','READ',1),(247,'report','READ_Aging Summary (Arrears in weeks) - review','Aging Summary (Arrears in weeks) - review','READ',1),(248,'report','READ_Amount In Arrears','Amount In Arrears','READ',1),(249,'report','READ_Balance Sheet','Balance Sheet','READ',1),(250,'report','READ_Client Listing','Client Listing','READ',1),(251,'report','READ_Client Loans Listing','Client Loans Listing','READ',1),(252,'report','READ_Funds Disbursed Between Dates Summary','Funds Disbursed Between Dates Summary','READ',1),(253,'report','READ_Funds Disbursed Between Dates Summary by Office','Funds Disbursed Between Dates Summary by Office','READ',1),(254,'report','READ_Income Statement','Income Statement','READ',1),(255,'report','READ_Loans Awaiting Disbursal','Loans Awaiting Disbursal','READ',1),(256,'report','READ_Loans Awaiting Disbursal Summary','Loans Awaiting Disbursal Summary','READ',1),(257,'report','READ_Loans Awaiting Disbursal Summary by Month','Loans Awaiting Disbursal Summary by Month','READ',1),(258,'report','READ_Loans Pending Approval','Loans Pending Approval','READ',1),(259,'report','READ_Obligation Met Loans Details','Obligation Met Loans Details','READ',1),(260,'report','READ_Obligation Met Loans Summary','Obligation Met Loans Summary','READ',1),(261,'report','READ_Portfolio at Risk','Portfolio at Risk','READ',1),(262,'report','READ_Portfolio at Risk by Branch','Portfolio at Risk by Branch','READ',1),(263,'report','READ_Rescheduled Loans','Rescheduled Loans','READ',1),(264,'report','READ_Trial Balance','Trial Balance','READ',1),(265,'report','READ_Written-Off Loans','Written-Off Loans','READ',1),(272,'datatable','CREATE_extra_client_details','extra_client_details','CREATE',1),(273,'datatable','CREATE_extra_family_details','extra_family_details','CREATE',1),(274,'datatable','CREATE_extra_loan_details','extra_loan_details','CREATE',1),(275,'datatable','READ_extra_client_details','extra_client_details','READ',1),(276,'datatable','READ_extra_family_details','extra_family_details','READ',1),(277,'datatable','READ_extra_loan_details','extra_loan_details','READ',1),(278,'datatable','UPDATE_extra_client_details','extra_client_details','UPDATE',1),(279,'datatable','UPDATE_extra_family_details','extra_family_details','UPDATE',1),(280,'datatable','UPDATE_extra_loan_details','extra_loan_details','UPDATE',1),(281,'datatable','DELETE_extra_client_details','extra_client_details','DELETE',1),(282,'datatable','DELETE_extra_family_details','extra_family_details','DELETE',1),(283,'datatable','DELETE_extra_loan_details','extra_loan_details','DELETE',1);
/*!40000 ALTER TABLE `m_permission` ENABLE KEYS */;
UNLOCK TABLES;
@@ -1855,7 +1856,7 @@ CREATE TABLE `stretchy_report` (
`use_report` tinyint(1) DEFAULT '0',
PRIMARY KEY (`report_id`),
UNIQUE KEY `report_name_UNIQUE` (`report_name`)
-) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=utf8;
+) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
@@ -1864,7 +1865,7 @@ CREATE TABLE `stretchy_report` (
LOCK TABLES `stretchy_report` WRITE;
/*!40000 ALTER TABLE `stretchy_report` DISABLE KEYS */;
-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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0), l.id, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.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\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 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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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\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\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 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\n(sum(ifnull(r.principal_completed_derived, 0)) + \r\n sum(ifnull(r.interest_completed_derived, 0)) + \r\n sum(ifnull(r.fee_charges_completed_derived, 0)) + \r\n sum(ifnull(r.penalty_charges_completed_derived, 0))) 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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) 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\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 (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 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\n\"wait for derived field\" as \"Total Principal Repaid\",\r\n\"wait for derived field\" as \"Total Interest Repaid\",\r\n\"wait for derived field\" as \"Total Fees Repaid\",\r\n\"wait for derived field\" as \"Total Interest Waived\",\r\n\"wait for derived field\" as \"Total Fees Waived\",\r\n\"wait for derived field\" 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\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 (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 o.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(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_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_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.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\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_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_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.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,0),(49,'Income Statement','Pentaho',NULL,'Accounting',NULL,'Profit and Loss Statement',1,0),(50,'Trial Balance','Pentaho',NULL,'Accounting',NULL,'Trial Balance Report',1,0),(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 Summary (Arrears in weeks) - review','Table',NULL,'Loan','SELECT \r\n arr.clientName AS \"Client Name\",\r\n arr.accNo AS \"Account Number\",\r\n arr.loanAmt AS \"Loan Amount\",\r\n loan.principal AS \"Original Principal\",\r\n loan.interest AS \"Original Interest\",\r\n loan.prinPaid AS \"Principal Paid\",\r\n loan.intPaid AS \"Interest Paid\",\r\n arr.prinOverdue AS \"Principal Overdue\",\r\n arr.intOverdue AS \"Interest Overdue\",\r\n arr.arrWeek AS \"Weeks In Arrears\"\r\nFROM \r\n (SELECT mr.loan_id loanId,\r\n mc.display_name AS clientName,\r\n ml.account_no AS accNo,\r\n ml.principal_amount AS loanAmt,\r\n SUM(mr.principal_amount - IFNULL(mr.principal_completed_derived, 0)) AS prinOverdue, \r\n SUM(mr.interest_amount - IFNULL(mr.interest_completed_derived, 0)) AS intOverdue,\r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<7, \'Less than a week in arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<8, \'1 Week in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<15, \'2 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<22, \'3 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<29, \'4 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<36, \'5 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<43, \'6 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<50, \'7 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<57, \'8 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<64, \'9 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<71, \'10 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<78, \'11 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<85, \'12 Weeks in Arrears\', \'12+ Weeks in Arrears\'))))))))))))) AS arrWeek\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_repayment_schedule mr ON mr.loan_id=ml.id\r\n WHERE mr.completed_derived=0 \r\n AND mr.duedate <= CURDATE() \r\n AND ml.loan_status_id=300\r\n AND mo.id=${officeId}\r\n GROUP BY mr.loan_id\r\n ORDER BY mc.display_name) arr\r\nINNER JOIN \r\n (SELECT mr.loan_id loanId, \r\n SUM(mr.principal_amount) principal,\r\n SUM(mr.interest_amount) interest,\r\n SUM(IFNULL(mr.principal_completed_derived,0)) prinPaid,\r\n SUM(IFNULL(mr.interest_completed_derived,0)) intPaid\r\n FROM m_loan_repayment_schedule mr\r\n GROUP BY mr.loan_id) loan ON arr.loanId=loan.loanId','Loan arrears aging (Weeks)',1,1),(53,'Amount In Arrears','Table',NULL,'Loan','SELECT \r\n IFNULL(weeks.currencyName, weeks.currency) as currency, \r\n weeks.week_no \'Weeks 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 weeks/currencies used combo to ensure each line represented */\r\n (SELECT curs.code as currency, curs.name as currencyName, wks.* from\r\n (SELECT \'On Schedule\' week_no,0 wid UNION\r\n SELECT \'0 to 6 days arrears\',1 UNION\r\n SELECT \'1 Week in Arrears\',2 UNION\r\n SELECT \'2 Weeks in Arrears\',3 UNION\r\n SELECT \'3 Weeks in Arrears\',4 UNION\r\n SELECT \'4 Weeks in Arrears\',5 UNION\r\n SELECT \'5 Weeks in Arrears\',6 UNION\r\n SELECT \'6 Weeks in Arrears\',7 UNION\r\n SELECT \'7 Weeks in Arrears\',8 UNION\r\n SELECT \'8 Weeks in Arrears\',9 UNION\r\n SELECT \'9 Weeks in Arrears\',10 UNION\r\n SELECT \'10 Weeks in Arrears\',11 UNION\r\n SELECT \'11 Weeks in Arrears\',12 UNION\r\n SELECT \'12 Weeks in Arrears\',13 UNION\r\n SELECT \'12+ Weeks in Arrears\',14) wks,\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}) curs) weeks\r\n\r\n\r\nLEFT JOIN /* table of aging weeks per currency with gaps if no applicable loans */\r\n(SELECT \r\n z.currency, z.arrWeek, \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 arrWeek value (was much slower to\r\n duplicate calc of minOverdueDate in inner query) */\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)<0, \'On Schedule\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<7, \'0 to 6 days arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<8, \'1 Week in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<15, \'2 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<22, \'3 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<29, \'4 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<36, \'5 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<43, \'6 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<50, \'7 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<57, \'8 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<64, \'9 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<71, \'10 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<78, \'11 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<85, \'12 Weeks in Arrears\',\r\n \'12+ Weeks in Arrears\')))))))))))))) AS arrWeek\r\n\r\n FROM /* get the individual loan details */\r\n (SELECT ml.id AS loanId, ml.currency_code as currency,\r\n SUM(mr.principal_amount) principal, \r\n SUM(mr.interest_amount) interest, \r\n SUM(IFNULL(mr.principal_completed_derived,0)) prinPaid, \r\n SUM(IFNULL(mr.interest_completed_derived,0)) intPaid,\r\n\r\n SUM(IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), \r\n (mr.principal_amount - ifnull(mr.principal_completed_derived, 0))\r\n , 0)) as prinOverdue,\r\n SUM(IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), \r\n (mr.interest_amount - ifnull(mr.interest_completed_derived, 0))\r\n , 0)) as intOverdue,\r\n\r\n CAST(MIN(\r\n IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), mr.duedate, CURDATE() + 1)) as date) 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 INNER JOIN m_loan_repayment_schedule mr on mr.loan_id = ml.id\r\n WHERE ml.loan_status_id=300 /* active */\r\n AND mo.id=${officeId}\r\n GROUP BY ml.id) x\r\n ) z \r\nGROUP BY z.currency, z.arrWeek ) ars ON ars.arrWeek=weeks.week_no and ars.currency = weeks.currency\r\nORDER BY weeks.currency, weeks.wid','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);
+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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0), l.id, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.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\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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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\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\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\n(sum(ifnull(r.principal_completed_derived, 0)) + \r\n sum(ifnull(r.interest_completed_derived, 0)) + \r\n sum(ifnull(r.fee_charges_completed_derived, 0)) + \r\n sum(ifnull(r.penalty_charges_completed_derived, 0))) 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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) 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\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 (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\n\"wait for derived field\" as \"Total Principal Repaid\",\r\n\"wait for derived field\" as \"Total Interest Repaid\",\r\n\"wait for derived field\" as \"Total Fees Repaid\",\r\n\"wait for derived field\" as \"Total Interest Waived\",\r\n\"wait for derived field\" as \"Total Fees Waived\",\r\n\"wait for derived field\" 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\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 (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 o.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(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_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_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.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\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_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_repayment_schedule r on r.loan_id = l.id\r\n and r.completed_derived is false\r\nwhere o.id = ${officeId}\r\nand (l.currency_code = \"${currencyId}\" or \"-1\" = \"${currencyId}\")\r\nand (l.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,0),(49,'Income Statement','Pentaho',NULL,'Accounting',NULL,'Profit and Loss Statement',1,0),(50,'Trial Balance','Pentaho',NULL,'Accounting',NULL,'Trial Balance Report',1,0),(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 Summary (Arrears in weeks) - review','Table',NULL,'Loan','SELECT \r\n arr.clientName AS \"Client Name\",\r\n arr.accNo AS \"Account Number\",\r\n arr.loanAmt AS \"Loan Amount\",\r\n loan.principal AS \"Original Principal\",\r\n loan.interest AS \"Original Interest\",\r\n loan.prinPaid AS \"Principal Paid\",\r\n loan.intPaid AS \"Interest Paid\",\r\n arr.prinOverdue AS \"Principal Overdue\",\r\n arr.intOverdue AS \"Interest Overdue\",\r\n arr.arrWeek AS \"Weeks In Arrears\"\r\nFROM \r\n (SELECT mr.loan_id loanId,\r\n mc.display_name AS clientName,\r\n ml.account_no AS accNo,\r\n ml.principal_amount AS loanAmt,\r\n SUM(mr.principal_amount - IFNULL(mr.principal_completed_derived, 0)) AS prinOverdue, \r\n SUM(mr.interest_amount - IFNULL(mr.interest_completed_derived, 0)) AS intOverdue,\r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<7, \'Less than a week in arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<8, \'1 Week in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<15, \'2 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<22, \'3 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<29, \'4 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<36, \'5 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<43, \'6 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<50, \'7 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<57, \'8 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<64, \'9 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<71, \'10 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<78, \'11 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), MIN(mr.duedate))<85, \'12 Weeks in Arrears\', \'12+ Weeks in Arrears\'))))))))))))) AS arrWeek\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_repayment_schedule mr ON mr.loan_id=ml.id\r\n WHERE mr.completed_derived=0 \r\n AND mr.duedate <= CURDATE() \r\n AND ml.loan_status_id=300\r\n AND mo.id=${officeId}\r\n GROUP BY mr.loan_id\r\n ORDER BY mc.display_name) arr\r\nINNER JOIN \r\n (SELECT mr.loan_id loanId, \r\n SUM(mr.principal_amount) principal,\r\n SUM(mr.interest_amount) interest,\r\n SUM(IFNULL(mr.principal_completed_derived,0)) prinPaid,\r\n SUM(IFNULL(mr.interest_completed_derived,0)) intPaid\r\n FROM m_loan_repayment_schedule mr\r\n GROUP BY mr.loan_id) loan ON arr.loanId=loan.loanId','Loan arrears aging (Weeks)',1,1),(53,'Amount In Arrears','Table',NULL,'Loan','SELECT \r\n IFNULL(weeks.currencyName, weeks.currency) as currency, \r\n weeks.week_no \'Weeks 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 weeks/currencies used combo to ensure each line represented */\r\n (SELECT curs.code as currency, curs.name as currencyName, wks.* from\r\n (SELECT \'On Schedule\' week_no,0 wid UNION\r\n SELECT \'0 to 6 days arrears\',1 UNION\r\n SELECT \'1 Week in Arrears\',2 UNION\r\n SELECT \'2 Weeks in Arrears\',3 UNION\r\n SELECT \'3 Weeks in Arrears\',4 UNION\r\n SELECT \'4 Weeks in Arrears\',5 UNION\r\n SELECT \'5 Weeks in Arrears\',6 UNION\r\n SELECT \'6 Weeks in Arrears\',7 UNION\r\n SELECT \'7 Weeks in Arrears\',8 UNION\r\n SELECT \'8 Weeks in Arrears\',9 UNION\r\n SELECT \'9 Weeks in Arrears\',10 UNION\r\n SELECT \'10 Weeks in Arrears\',11 UNION\r\n SELECT \'11 Weeks in Arrears\',12 UNION\r\n SELECT \'12 Weeks in Arrears\',13 UNION\r\n SELECT \'12+ Weeks in Arrears\',14) wks,\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}) curs) weeks\r\n\r\n\r\nLEFT JOIN /* table of aging weeks per currency with gaps if no applicable loans */\r\n(SELECT \r\n z.currency, z.arrWeek, \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 arrWeek value (was much slower to\r\n duplicate calc of minOverdueDate in inner query) */\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)<0, \'On Schedule\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<7, \'0 to 6 days arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<8, \'1 Week in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<15, \'2 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<22, \'3 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<29, \'4 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<36, \'5 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<43, \'6 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<50, \'7 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<57, \'8 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<64, \'9 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<71, \'10 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<78, \'11 Weeks in Arrears\', \r\n IF(DATEDIFF(CURDATE(), minOverdueDate)<85, \'12 Weeks in Arrears\',\r\n \'12+ Weeks in Arrears\')))))))))))))) AS arrWeek\r\n\r\n FROM /* get the individual loan details */\r\n (SELECT ml.id AS loanId, ml.currency_code as currency,\r\n SUM(mr.principal_amount) principal, \r\n SUM(mr.interest_amount) interest, \r\n SUM(IFNULL(mr.principal_completed_derived,0)) prinPaid, \r\n SUM(IFNULL(mr.interest_completed_derived,0)) intPaid,\r\n\r\n SUM(IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), \r\n (mr.principal_amount - ifnull(mr.principal_completed_derived, 0))\r\n , 0)) as prinOverdue,\r\n SUM(IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), \r\n (mr.interest_amount - ifnull(mr.interest_completed_derived, 0))\r\n , 0)) as intOverdue,\r\n\r\n CAST(MIN(\r\n IF((mr.completed_derived is false) AND (mr.duedate <= CURDATE()), mr.duedate, CURDATE() + 1)) as date) 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 INNER JOIN m_loan_repayment_schedule mr on mr.loan_id = ml.id\r\n WHERE ml.loan_status_id=300 /* active */\r\n AND mo.id=${officeId}\r\n GROUP BY ml.id) x\r\n ) z \r\nGROUP BY z.currency, z.arrWeek ) ars ON ars.arrWeek=weeks.week_no and ars.currency = weeks.currency\r\nORDER BY weeks.currency, weeks.wid','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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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\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 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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0), l.id, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.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\nsum(ifnull(r.principal_completed_derived, 0)) as \"Principal Repaid\",\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as \"Principal Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as \"Principal Overdue\",\r\n\r\nsum(ifnull(r.interest_completed_derived, 0)) as \"Interest Repaid\",\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as \"Interest Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as \"Interest Overdue\",\r\n\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as \"Fees Repaid\",\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as \"Fees Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as \"Fees Overdue\",\r\n\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as \"Penalties Repaid\",\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as \"Penalties Outstanding\",\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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, 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_repayment_schedule r on r.loan_id = lastInstallment.loanId\r\ngroup by lastInstallment.loanId\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. principal_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(if(r.duedate <= curdate(), \r\n if(ifnull(r.principal_amount,0) - ifnull(r.principal_completed_derived, 0),lastInstallment.loanId, null), null) )) as principal_arrears_loan_count,\r\n\r\nsum(ifnull(r.principal_amount,0)) as principal,\r\nsum(ifnull(r.principal_completed_derived, 0)) as principal_repaid,\r\nsum(ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0))) as principal_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.principal_amount,0) - (ifnull(r.principal_completed_derived, 0) + ifnull(r.principal_writtenoff_derived, 0)))\r\n , 0)) as principal_overdue,\r\n\r\nsum(ifnull(r.interest_amount,0)) as interest,\r\nsum(ifnull(r.interest_completed_derived, 0)) as interest_repaid,\r\nsum(ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0))) as interest_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.interest_amount,0) - (ifnull(r.interest_completed_derived, 0) + ifnull(r.interest_waived_derived, 0) + ifnull(r.interest_writtenoff_derived, 0)))\r\n , 0)) as interest_overdue,\r\n\r\nsum(ifnull(r.fee_charges_amount,0)) as fees,\r\nsum(ifnull(r.fee_charges_completed_derived, 0)) as fees_repaid,\r\nsum(ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0))) as fees_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.fee_charges_amount,0) - (ifnull(r.fee_charges_completed_derived, 0) + ifnull(r.fee_charges_waived_derived, 0) + ifnull(r.fee_charges_writtenoff_derived, 0)))\r\n , 0)) as fees_overdue,\r\n\r\nsum(ifnull(r.penalty_charges_amount,0)) as penalties,\r\nsum(ifnull(r.penalty_charges_completed_derived, 0)) as penalties_repaid,\r\nsum(ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0))) as penalties_outstanding,\r\nsum(if(r.duedate <= curdate(), \r\n (ifnull(r.penalty_charges_amount,0) - (ifnull(r.penalty_charges_completed_derived, 0) + ifnull(r.penalty_charges_waived_derived, 0) + ifnull(r.penalty_charges_writtenoff_derived, 0)))\r\n , 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_repayment_schedule r on r.loan_id = lastInstallment.loanId\r\ngroup by lastInstallment.branchId) x on x.branchId = mo.id\r\norder by mo.hierarchy, x.Currency','Individual Client \n\nReport',1,1);
/*!40000 ALTER TABLE `stretchy_report` ENABLE KEYS */;
UNLOCK TABLES;
@@ -1890,7 +1891,7 @@ CREATE TABLE `stretchy_report_parameter` (
LOCK TABLES `stretchy_report_parameter` WRITE;
/*!40000 ALTER TABLE `stretchy_report_parameter` DISABLE KEYS */;
-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),(54,1,NULL),(54,2,NULL),(54,5,NULL),(54,10,NULL),(54,25,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),(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);
/*!40000 ALTER TABLE `stretchy_report_parameter` ENABLE KEYS */;
UNLOCK TABLES;
@@ -1927,4 +1928,4 @@ UNLOCK TABLES;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
--- Dump completed on 2013-02-21 1:37:07
+-- Dump completed on 2013-02-22 11:59:48
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java
index b11d5a7b0..6960ca376 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/api/LoansApiResource.java
@@ -234,8 +234,7 @@ public class LoansApiResource {
if (!associationParameters.isEmpty()) {
if (associationParameters.contains("all")) {
- associationParameters.addAll(Arrays.asList("repaymentSchedule", "transactions", "permissions", "charges", "guarantors",
- "collateral"));
+ associationParameters.addAll(Arrays.asList("repaymentSchedule", "transactions", "charges", "guarantors", "collateral"));
}
if (associationParameters.contains("guarantors")) {
@@ -254,11 +253,8 @@ public class LoansApiResource {
}
}
- if (associationParameters.contains("repaymentSchedule") || associationParameters.contains("permissions")) {
-
- if (associationParameters.contains("repaymentSchedule")) {
- mandatoryResponseParameters.add("repaymentSchedule");
- }
+ if (associationParameters.contains("repaymentSchedule")) {
+ mandatoryResponseParameters.add("repaymentSchedule");
final RepaymentScheduleRelatedLoanData repaymentScheduleRelatedData = loanBasicDetails.repaymentScheduleRelatedData();
repaymentSchedule = this.loanReadPlatformService.retrieveRepaymentSchedule(loanId, repaymentScheduleRelatedData);
@@ -393,7 +389,7 @@ public class LoansApiResource {
if (is(commandParam, "reject")) {
final CommandWrapper commandRequest = builder.rejectLoanApplication(loanId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
- } else if (is(commandParam, "withdrewbyclient")) {
+ } else if (is(commandParam, "withdrawnByApplicant")) {
final CommandWrapper commandRequest = builder.withdrawLoanApplication(loanId).build();
result = this.commandsSourceWritePlatformService.logCommandSource(commandRequest);
} else if (is(commandParam, "approve")) {
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/command/LoanStateTransitionCommand.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/command/LoanStateTransitionCommand.java
deleted file mode 100644
index 7daf9971b..000000000
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/command/LoanStateTransitionCommand.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/**
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-package org.mifosplatform.portfolio.loanaccount.command;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.joda.time.LocalDate;
-import org.mifosplatform.infrastructure.core.data.ApiParameterError;
-import org.mifosplatform.infrastructure.core.data.DataValidatorBuilder;
-import org.mifosplatform.infrastructure.core.exception.PlatformApiDataValidationException;
-
-/**
- * Immutable command for any of the loan state transitions eg. reject, withdrawn
- * by client, approve, disburse
- */
-public class LoanStateTransitionCommand {
-
- private final LocalDate eventDate;
- private final String note;
- private final LocalDate approvedOnDate;
- private final LocalDate rejectedOnDate;
- private final LocalDate withdrawnOnDate;
- private final LocalDate disbursedOnDate;
-
- public LoanStateTransitionCommand(final LocalDate eventDate, final String note, final LocalDate approvedOnDate,
- final LocalDate rejectedOnDate, final LocalDate withdrawnOnDate, final LocalDate disbursedOnDate) {
- this.eventDate = eventDate;
- this.note = note;
- this.approvedOnDate = approvedOnDate;
- this.rejectedOnDate = rejectedOnDate;
- this.withdrawnOnDate = withdrawnOnDate;
- this.disbursedOnDate = disbursedOnDate;
- }
-
- public LocalDate getApprovedOnDate() {
- LocalDate dateValue = this.approvedOnDate;
- if (this.approvedOnDate == null) {
- dateValue = eventDate;
- }
- return dateValue;
- }
-
- public LocalDate getRejectedOnDate() {
- LocalDate dateValue = this.rejectedOnDate;
- if (this.rejectedOnDate == null) {
- dateValue = eventDate;
- }
- return dateValue;
- }
-
- public LocalDate getWithdrawnOnDate() {
- LocalDate dateValue = this.withdrawnOnDate;
- if (this.withdrawnOnDate == null) {
- dateValue = eventDate;
- }
- return dateValue;
- }
-
- public LocalDate getDisbursedOnDate() {
- LocalDate dateValue = this.disbursedOnDate;
- if (this.disbursedOnDate == null) {
- dateValue = eventDate;
- }
- return dateValue;
- }
-
- public void validate() {
- List dataValidationErrors = new ArrayList();
-
- DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("loan.transition");
-
- baseDataValidator.reset().parameter("eventDate").value(this.eventDate).notNull();
- baseDataValidator.reset().parameter("note").value(this.note).notExceedingLengthOf(1000);
-
- if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
- "Validation errors exist.", dataValidationErrors); }
- }
-}
\ No newline at end of file
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java
index ebad29111..b9ec40b4c 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/domain/Loan.java
@@ -931,9 +931,6 @@ public class Loan extends AbstractAuditableCustom {
actualChanges.put("status", LoanEnumerations.status(this.loanStatus));
LocalDate rejectedOn = command.localDateValueOfParameterNamed("rejectedOnDate");
- if (rejectedOn == null) {
- rejectedOn = command.localDateValueOfParameterNamed("eventDate");
- }
final Locale locale = new Locale(command.locale());
final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/CalculateLoanScheduleQueryFromApiJsonHelper.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/CalculateLoanScheduleQueryFromApiJsonHelper.java
index 8e91f7f78..d3bddd2fb 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/CalculateLoanScheduleQueryFromApiJsonHelper.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/CalculateLoanScheduleQueryFromApiJsonHelper.java
@@ -146,6 +146,12 @@ public final class CalculateLoanScheduleQueryFromApiJsonHelper {
validateRepaymentsStartingFromDateAndInterestChargedFromDate(dataValidationErrors, expectedDisbursementDate,
repaymentsStartingFromDate, interestChargedFromDate);
+ final String transactionProcessingStrategyIdParameterName = "transactionProcessingStrategyId";
+ final Long transactionProcessingStrategyId = fromApiJsonHelper.extractLongNamed(transactionProcessingStrategyIdParameterName,
+ element);
+ baseDataValidator.reset().parameter(transactionProcessingStrategyIdParameterName).value(transactionProcessingStrategyId).notNull()
+ .integerGreaterThanZero();
+
// charges
final String chargesParameterName = "charges";
if (element.isJsonObject() && fromApiJsonHelper.parameterExists(chargesParameterName, element)) {
diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
index e88f16c38..cf7069d84 100644
--- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
+++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/serialization/LoanApplicationCommandFromApiJsonHelper.java
@@ -547,4 +547,25 @@ public final class LoanApplicationCommandFromApiJsonHelper {
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist",
"Validation errors exist.", dataValidationErrors); }
}
+
+ public void validateForUndo(final String json) {
+ if (StringUtils.isBlank(json)) { throw new InvalidJsonException(); }
+
+ final Set undoSupportedParameters = new HashSet(Arrays.asList("note"));
+ final Type typeOfMap = new TypeToken