From e2ee6d1f5ef9afbc76fdb2d9d528d9e72980461f Mon Sep 17 00:00:00 2001 From: Madhukar Date: Wed, 19 Mar 2014 21:31:41 +0530 Subject: [PATCH] #MIFOSX-886,#MIFOSX-835,#MIFOSX-996,#MIFOSX-990,#MIFOSX-957 --- api-docs/apiLive.htm | 17 +++++++++++++++-- .../V155__dashboard_and_navigation_queries.sql | 17 +++++++++++++++++ .../CollectionSheetReadPlatformServiceImpl.java | 2 +- ...onWritePlatformServiceJpaRepositoryImpl.java | 9 +++++++-- 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 mifosng-db/migrations/core_db/V155__dashboard_and_navigation_queries.sql diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 80b10685a..da9d7db10 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -6014,8 +6014,21 @@ GET https://DomainName/mifosng-provider/api/v1/loans Content-Type: application/json No Request Body: { - "locale": "en", + "locale": "en", + "dateFormat": "dd MMMM yyyy", + "productId": 1, "principal": "5000", + "loanTermFrequency": 10, + "loanTermFrequencyType": 0, + "numberOfRepayments": 10, + "repaymentEvery": 1, + "repaymentFrequencyType": 0, + "interestRatePerPeriod": 2, + "interestType": 0, + "interestCalculationPeriodType": 0, + "amortizationType": 1, + "expectedDisbursementDate": "04 March 2014", + "transactionProcessingStrategyId": 1 } @@ -15510,7 +15523,7 @@ Content-Type: application/json No Request Body: { "locale": "en", - "nominalAnnualInterestRate": "5.9999999999", + "nominalAnnualInterestRate": "5.9999999999" } diff --git a/mifosng-db/migrations/core_db/V155__dashboard_and_navigation_queries.sql b/mifosng-db/migrations/core_db/V155__dashboard_and_navigation_queries.sql new file mode 100644 index 000000000..4c0d04fc0 --- /dev/null +++ b/mifosng-db/migrations/core_db/V155__dashboard_and_navigation_queries.sql @@ -0,0 +1,17 @@ +INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('GroupNamesByStaff', 'Table', '', '', 'Select gr.id as id, gr.display_name as name from m_group gr where gr.level_id=1 and gr.staff_id = ${staffId}', '', 0, 1); +INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('ClientTrendsByDay', 'Table', '', 'Client', 'SELECT COUNT(cl.id) AS count, \n cl.activation_date AS days\nFROM m_office of \n LEFT JOIN m_client cl on of.id = cl.office_id\nWHERE of.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),"%" ) \n AND (cl.activation_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 12 DAY) AND DATE(NOW()- INTERVAL 1 DAY))\nGROUP BY days', 'Retrieves the number of clients joined in last 12 days', 0, 1); +INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('ClientTrendsByWeek', 'Table', '', 'Client', 'SELECT COUNT(cl.id) AS count, \n WEEK(cl.activation_date) AS Weeks\nFROM m_office of \n LEFT JOIN m_client cl on of.id = cl.office_id\nWHERE of.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),"%" ) \n AND (cl.activation_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 12 WEEK) AND DATE(NOW()))\nGROUP BY Weeks', '', 0, 1); +INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('ClientTrendsByMonth', 'Table', '', 'Client', 'SELECT COUNT(cl.id) AS count, \n MONTHNAME(cl.activation_date) AS Months\nFROM m_office of \n LEFT JOIN m_client cl on of.id = cl.office_id\nWHERE of.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),"%" ) \n AND (cl.activation_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 12 MONTH) AND DATE(NOW()))\nGROUP BY Months', '', 0, 1); +INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('LoanTrendsByDay', 'Table', '', 'Loan', 'SELECT COUNT(ln.id) AS lcount, \n ln.disbursedon_date AS days\nFROM m_office of \n LEFT JOIN m_client cl on of.id = cl.office_id\n LEFT JOIN m_loan ln on cl.id = ln.client_id\nWHERE of.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),"%" ) \n AND (ln.disbursedon_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 12 DAY) AND DATE(NOW()- INTERVAL 1 DAY))\nGROUP BY days', 'Retrieves Number of loans disbursed for last 12 days', 0, 1); +INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('LoanTrendsByWeek', 'Table', '', 'Loan', 'SELECT COUNT(ln.id) AS lcount, \n WEEK(ln.disbursedon_date) AS Weeks\nFROM m_office of \n LEFT JOIN m_client cl on of.id = cl.office_id\n LEFT JOIN m_loan ln on cl.id = ln.client_id\nWHERE of.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),"%" ) \n AND (ln.disbursedon_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 12 WEEK) AND DATE(NOW()))\nGROUP BY Weeks', '', 0, 1); +INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('LoanTrendsByMonth', 'Table', '', 'Loan', 'SELECT COUNT(ln.id) AS lcount, \n MONTHNAME(ln.disbursedon_date) AS Months\nFROM m_office of \n LEFT JOIN m_client cl on of.id = cl.office_id\n LEFT JOIN m_loan ln on cl.id = ln.client_id\nWHERE of.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),"%" ) \n AND (ln.disbursedon_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 12 MONTH) AND DATE(NOW()))\nGROUP BY Months', '', 0, 1); +INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('Demand_Vs_Collection', 'Table', '', 'Loan', 'select amount.AmountDue-amount.AmountPaid as AmountDue, amount.AmountPaid as AmountPaid from\n(SELECT \n(IFNULL(SUM(ls.principal_amount),0) - IFNULL(SUM(ls.principal_writtenoff_derived),0)\n + IFNULL(SUM(ls.interest_amount),0) - IFNULL(SUM(ls.interest_writtenoff_derived),0) \n - IFNULL(SUM(ls.interest_waived_derived),0)\n + IFNULL(SUM(ls.fee_charges_amount),0) - IFNULL(SUM(ls.fee_charges_writtenoff_derived),0) \n - IFNULL(SUM(ls.fee_charges_waived_derived),0)\n + IFNULL(SUM(ls.penalty_charges_amount),0) - IFNULL(SUM(ls.penalty_charges_writtenoff_derived),0) \n - IFNULL(SUM(ls.penalty_charges_waived_derived),0)\n) AS AmountDue, \n\n(IFNULL(SUM(ls.principal_completed_derived),0) - IFNULL(SUM(ls.principal_writtenoff_derived),0) + IFNULL(SUM(ls.interest_completed_derived),0) - IFNULL(SUM(ls.interest_writtenoff_derived),0) \n - IFNULL(SUM(ls.interest_waived_derived),0)\n + IFNULL(SUM(ls.fee_charges_completed_derived),0) - IFNULL(SUM(ls.fee_charges_writtenoff_derived),0) \n - IFNULL(SUM(ls.fee_charges_waived_derived),0)\n + IFNULL(SUM(ls.penalty_charges_completed_derived),0) - IFNULL(SUM(ls.penalty_charges_writtenoff_derived),0) \n - IFNULL(SUM(ls.penalty_charges_waived_derived),0)\n) AS AmountPaid\nFROM m_office of\nLEFT JOIN m_client cl ON of.id = cl.office_id\nLEFT JOIN m_loan ln ON cl.id = ln.client_id\nLEFT JOIN m_loan_repayment_schedule ls ON ln.id = ls.loan_id\nWHERE ls.duedate = DATE(NOW()) AND \n (of.hierarchy LIKE CONCAT((\nSELECT ino.hierarchy\nFROM m_office ino\nWHERE ino.id = ${officeId}),"%"))) as amount', 'Demand Vs Collection', 0, 1); +INSERT INTO `stretchy_report` (`report_name`, `report_type`, `report_subtype`, `report_category`, `report_sql`, `description`, `core_report`, `use_report`) VALUES ('Disbursal_Vs_Awaitingdisbursal', 'Table', '', 'Loan', 'select awaitinddisbursal.amount-disbursedAmount.amount as amountToBeDisburse, disbursedAmount.amount as disbursedAmount from \n(\nSELECT COUNT(ln.id) AS noOfLoans, \n IFNULL(SUM(ln.principal_amount),0) AS amount\nFROM \nm_office of\nLEFT JOIN m_client cl ON cl.office_id = of.id\nLEFT JOIN m_loan ln ON cl.id = ln.client_id\nWHERE \nln.expected_disbursedon_date = DATE(NOW()) AND \n(ln.loan_status_id=200 OR ln.loan_status_id=300) AND\n of.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),"%" )\n) awaitinddisbursal,\n(\nSELECT COUNT(ltrxn.id) as count, \n IFNULL(SUM(ltrxn.amount),0) as amount \nFROM \nm_office of\nLEFT JOIN m_client cl ON cl.office_id = of.id\nLEFT JOIN m_loan ln ON cl.id = ln.client_id\nLEFT JOIN m_loan_transaction ltrxn ON ln.id = ltrxn.loan_id\nWHERE \nltrxn.transaction_date = DATE(NOW()) AND \nltrxn.transaction_type_enum=1 AND\n of.hierarchy like concat((select ino.hierarchy from m_office ino where ino.id = ${officeId}),"%" ) \n) disbursedAmount', 'Disbursal_Vs_Awaitingdisbursal', 0, 1); +INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select sr.id from stretchy_report sr where sr.report_name = 'ClientTrendsByDay'), (select sp.id from stretchy_parameter sp where sp.parameter_name = 'OfficeIdSelectOne'), ''); +INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select sr.id from stretchy_report sr where sr.report_name = 'ClientTrendsByWeek'), (select sp.id from stretchy_parameter sp where sp.parameter_name = 'OfficeIdSelectOne'), ''); +INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select sr.id from stretchy_report sr where sr.report_name = 'ClientTrendsByMonth'), (select sp.id from stretchy_parameter sp where sp.parameter_name = 'OfficeIdSelectOne'), ''); +INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select sr.id from stretchy_report sr where sr.report_name = 'LoanTrendsByDay'), (select sp.id from stretchy_parameter sp where sp.parameter_name = 'OfficeIdSelectOne'), ''); +INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select sr.id from stretchy_report sr where sr.report_name = 'LoanTrendsByWeek'), (select sp.id from stretchy_parameter sp where sp.parameter_name = 'OfficeIdSelectOne'), ''); +INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select sr.id from stretchy_report sr where sr.report_name = 'LoanTrendsByMonth'), (select sp.id from stretchy_parameter sp where sp.parameter_name = 'OfficeIdSelectOne'), ''); +INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select sr.id from stretchy_report sr where sr.report_name = 'Demand_Vs_Collection'), (select sp.id from stretchy_parameter sp where sp.parameter_name = 'OfficeIdSelectOne'), ''); +INSERT INTO `stretchy_report_parameter` (`report_id`, `parameter_id`, `report_parameter_name`) VALUES ((select sr.id from stretchy_report sr where sr.report_name = 'Disbursal_Vs_Awaitingdisbursal'), (select sp.id from stretchy_parameter sp where sp.parameter_name = 'OfficeIdSelectOne'), ''); diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java index 98e5d2fc8..19582312a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/collectionsheet/service/CollectionSheetReadPlatformServiceImpl.java @@ -200,7 +200,7 @@ public class CollectionSheetReadPlatformServiceImpl implements CollectionSheetRe .append("LEFT JOIN m_staff sf ON sf.id = gp.staff_id ") .append("JOIN m_group_client gc ON gc.group_id = gp.id ") .append("JOIN m_client cl ON cl.id = gc.client_id ") - .append("LEFT JOIN m_loan ln ON cl.id = ln.client_id AND ln.group_id is not null AND ( ln.loan_status_id = 300 OR ( ln.loan_status_id =200 AND ln.expected_disbursedon_date <= :dueDate )) ") + .append("LEFT JOIN m_loan ln ON cl.id = ln.client_id and ln.group_id=gp.id AND ln.group_id is not null AND ( ln.loan_status_id = 300 OR ( ln.loan_status_id =200 AND ln.expected_disbursedon_date <= :dueDate )) ") .append("LEFT JOIN m_product_loan pl ON pl.id = ln.product_id ") .append("LEFT JOIN m_currency rc on rc.`code` = ln.currency_code ") .append("LEFT JOIN m_loan_repayment_schedule ls ON ls.loan_id = ln.id AND ls.completed_derived = 0 AND ls.duedate <= :dueDate ") diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java index 37e458436..4c303cc2a 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/loanaccount/service/LoanApplicationWritePlatformServiceJpaRepositoryImpl.java @@ -421,14 +421,19 @@ public class LoanApplicationWritePlatformServiceJpaRepositoryImpl implements Loa existingLoanApplication.updateLoanSchedule(loanSchedule); } + this.loanRepository.saveAndFlush(existingLoanApplication); + + // FIXME: adding loan installment charges along with the other + // charges, + // is trying to add extra entries with null values. Because of that + // persisting charges separately final String chargesParamName = "charges"; if (changes.containsKey(chargesParamName)) { final Set loanCharges = this.loanChargeAssembler.fromParsedJson(command.parsedJson()); existingLoanApplication.updateLoanCharges(loanCharges); + this.loanRepository.saveAndFlush(existingLoanApplication); } - this.loanRepository.saveAndFlush(existingLoanApplication); - final String submittedOnNote = command.stringValueOfParameterNamed("submittedOnNote"); if (StringUtils.isNotBlank(submittedOnNote)) { final Note note = Note.loanNote(existingLoanApplication, submittedOnNote);