Commit 7f2668b8 authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov

fixed:

Bug 24953 - Не игнорируются текстовые значения, логические или пустые ячейки при расчете формулы MIRR 

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56924 954022d7-b5bf-4e40-9824-e11837661b57
parent 44a1fec8
...@@ -3098,18 +3098,22 @@ function cMIRR() { ...@@ -3098,18 +3098,22 @@ function cMIRR() {
cMIRR.prototype = Object.create( cBaseFunction.prototype ); cMIRR.prototype = Object.create( cBaseFunction.prototype );
cMIRR.prototype.Calculate = function ( arg ) { cMIRR.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], fRate1_invest = arg[1], fRate1_reinvest = arg[2]; var arg0 = arg[0], invest = arg[1], reinvest = arg[2];
var valueArray = []; var valueArray = [];
if ( arg0 instanceof cArea ) { if ( arg0 instanceof cArea ) {
arg0.foreach2( function ( c ) { arg0.foreach2( function ( c ) {
valueArray.push( c.tocNumber() ); if( c instanceof cNumber || c instanceof cError ){
valueArray.push( c );
}
} ) } )
} }
else if ( arg0 instanceof cArray ) { else if ( arg0 instanceof cArray ) {
arg0.foreach( function ( c ) { arg0.foreach( function ( c ) {
valueArray.push( c.tocNumber() ); if( c instanceof cNumber || c instanceof cError ){
valueArray.push( c );
}
} ) } )
} }
else if ( arg0 instanceof cArea3D ) { else if ( arg0 instanceof cArea3D ) {
...@@ -3120,69 +3124,70 @@ cMIRR.prototype.Calculate = function ( arg ) { ...@@ -3120,69 +3124,70 @@ cMIRR.prototype.Calculate = function ( arg ) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError( cErrorType.wrong_value_type );
} }
else { else {
arg0 = arg0.tocNumber();
if ( arg0 instanceof cError ) { if ( arg0 instanceof cError ) {
return this.value = new cError( cErrorType.not_numeric ) return this.value = new cError( cErrorType.not_numeric )
} }
else else if( arg0 instanceof cNumber ){
valueArray.push( arg0 ); valueArray.push( arg0 );
}
} }
if ( fRate1_invest instanceof cArea || fRate1_invest instanceof cArea3D ) { if ( invest instanceof cArea || invest instanceof cArea3D ) {
fRate1_invest = fRate1_invest.cross( arguments[1].first ); invest = invest.cross( arguments[1].first );
} }
else if ( fRate1_invest instanceof cArray ) { else if ( invest instanceof cArray ) {
fRate1_invest = fRate1_invest.getElementRowCol( 0, 0 ); invest = invest.getElementRowCol( 0, 0 );
} }
if ( fRate1_reinvest instanceof cArea || fRate1_reinvest instanceof cArea3D ) { if ( reinvest instanceof cArea || reinvest instanceof cArea3D ) {
fRate1_reinvest = fRate1_reinvest.cross( arguments[1].first ); reinvest = reinvest.cross( arguments[1].first );
} }
else if ( fRate1_reinvest instanceof cArray ) { else if ( reinvest instanceof cArray ) {
fRate1_reinvest = fRate1_reinvest.getElementRowCol( 0, 0 ); reinvest = reinvest.getElementRowCol( 0, 0 );
} }
fRate1_invest = fRate1_invest.tocNumber(); invest = invest.tocNumber();
fRate1_reinvest = fRate1_reinvest.tocNumber(); reinvest = reinvest.tocNumber();
if ( fRate1_invest instanceof cError ) return this.value = fRate1_invest; if ( invest instanceof cError ) return this.value = invest;
if ( fRate1_reinvest instanceof cError ) return this.value = fRate1_reinvest; if ( reinvest instanceof cError ) return this.value = reinvest;
fRate1_invest = fRate1_invest.getValue() + 1; invest = invest.getValue() + 1;
fRate1_reinvest = fRate1_reinvest.getValue() + 1; reinvest = reinvest.getValue() + 1;
var fNPV_reinvest = 0, fPow_reinvest = 1, fNPV_invest = 0, fPow_invest = 1, fCellValue, var NPVreinvest = 0, POWreinvest = 1, NPVinvest = 0, POWinvest = 1, cellValue,
wasNegative = false, wasPositive = false; wasNegative = false, wasPositive = false;
for ( var i = 0; i < valueArray.length; i++ ) { for ( var i = 0; i < valueArray.length; i++ ) {
fCellValue = valueArray[i]; cellValue = valueArray[i];
if ( fCellValue instanceof cError ) if ( cellValue instanceof cError )
return this.value = fCellValue; return this.value = cellValue;
fCellValue = valueArray[i].getValue(); cellValue = valueArray[i].getValue();
if ( fCellValue > 0 ) { // reinvestments if ( cellValue > 0 ) { // reinvestments
wasPositive = true; wasPositive = true;
fNPV_reinvest += fCellValue * fPow_reinvest; NPVreinvest += cellValue * POWreinvest;
} }
else if ( fCellValue < 0 ) { // investments else if ( cellValue < 0 ) { // investments
wasNegative = true; wasNegative = true;
fNPV_invest += fCellValue * fPow_invest; NPVinvest += cellValue * POWinvest;
} }
fPow_reinvest /= fRate1_reinvest; POWreinvest /= reinvest;
fPow_invest /= fRate1_invest; POWinvest /= invest;
} }
if ( !( wasNegative && wasPositive ) ) if ( !( wasNegative && wasPositive ) )
return this.value = new cError( cErrorType.division_by_zero ); return this.value = new cError( cErrorType.division_by_zero );
var fResult = -fNPV_reinvest / fNPV_invest; var res = -NPVreinvest / NPVinvest;
fResult *= Math.pow( fRate1_reinvest, valueArray.length - 1 ); res *= Math.pow( reinvest, valueArray.length - 1 );
fResult = Math.pow( fResult, 1 / (valueArray.length - 1) ); res = Math.pow( res, 1 / (valueArray.length - 1) );
this.value = new cNumber( fResult - 1 ); this.value = new cNumber( res - 1 );
this.value.numFormat = 9; this.value.numFormat = 9;
return this.value; return this.value;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment