### Description

The NPV/IRR calculations in demands are not working properly.

**Steps to reproduce**:

- Create new demand
- Create demand budget
- Create cost and benefit plans
- Set the discount % value
- No calculations are done

NPV and IRR fields are not populated

### Cause

Conditions for populating NPV and IRR need to be met. A cost plan for a fiscal year must exist to calculate NPV.

IRR is the discount rate that would cause the net present value (NPV) of a project to be 0. So, in order to calculate IRR we need to have Cash flow values with at least one positive value and one negative value.

Cash flow from a cost plan is considered a negative value and cash flow from a benefit plan are considered as a positive value. If, at least, one positive and one negative value exists, then calculate IR.

### Resolution

For NPV to be populated, the following condition must be met:

A cost plan must be created that spans a fiscal year.

For IRR to be populated, the following conditions must be met:

- Cost plan and/or benefit plan records should be present for at least two Fiscal years
- There should be at least one fiscal year with a positive value (Sum of benefit plan breakdown values for the fiscal period is greater than sum of cost plan breakdown values)
- There should be at least one fiscal year with a negative value (Sum of cost plan breakdown values for the fiscal period is greater than sum of benefit plan breakdown values)

The logic for the above is implemented in the Script Include - **IRRAndNPVAPI**: /nav_to.do?uri=sys_script_include.do?sys_id=c8fa147f0b372200a6acc93563673a40

For example:

- Create a Demand
- Navigate to Related List: Benefit Plans

- Create one Benefit Plan
- Create a new Benefit Plan ( Fiscal Year FY20: M01-Jan to FY20: M01-Dec, set 'entered benefit' to 2000)
- Navigate to Related List: Cost Plans
- Create two Cost Plans:
- Fiscal Year FY20: M01-Jan to FY20: M01-Dec (ensure Total Planned Cost is 0 by setting unit cost to 0 on the cost plan)
- Fiscal Year FY21: M01-Jan to FY21: M01-Dec (ensure Total Planned Cost 1000 e.g set unit cost to 100 and quantity to 10 on the cost plan)

- NPV and IRR will be populated.

Please note for better user experience, if the IRR calculation could not be done, a message is displayed: **Unable to calculate IRR**

Also, please note that the Internal Rate of Return does not calculate if the financial return value is greater than 100,000. (see: PRB1322063).