Commit d63ac7ad authored by Dmitry.Shahtanov's avatar Dmitry.Shahtanov Committed by Alexander.Trofimov

полностью переписана функция AMORDEGRC

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@59762 954022d7-b5bf-4e40-9824-e11837661b57
parent bbf7a5b4
...@@ -883,55 +883,102 @@ cAMORDEGRC.prototype.Calculate = function ( arg ) { ...@@ -883,55 +883,102 @@ cAMORDEGRC.prototype.Calculate = function ( arg ) {
return this.value = new cError( cErrorType.not_numeric ); return this.value = new cError( cErrorType.not_numeric );
} }
var per = 1 / rate, coeff;
if ( cost == salvage /*|| period > per*/ ) { if ( cost == salvage /*|| period > per*/ ) {
return this.value = new cNumber( 0 ); return this.value = new cNumber( 0 );
} }
if( per < 3){ datePurch = Date.prototype.getDateFromExcel( datePurch );
coeff = 1; firstPer = Date.prototype.getDateFromExcel( firstPer );
}
else if ( per >= 3 && per <= 4 ) { function findDepr( countedPeriod, depr, rate, cost ){
coeff = 1.5;
} if (countedPeriod > period) {
else if ( per >= 5 && per <= 6 ) { return new cNumber(Math.round(depr));
coeff = 2; }
} else{
else if ( per > 6 ) { countedPeriod++;
coeff = 2.5; }
var calcT = assetLife - countedPeriod, deprTemp = calcT == 2 ? cost * 0.5 : rate * cost;
rate = (calcT == 2 ? 1 : rate);
if (cost < salvage){
if (cost - salvage < 0) {
depr = 0;
}
else {
depr = cost - salvage;
}
}
else {
depr = deprTemp;
}
cost -= depr;
return findDepr( countedPeriod, depr, rate, cost );
} }
else {
return this.value = new cError( cErrorType.not_numeric ); function firstDeprLinc( cost, datePurch, firstP, salvage, rate, per, basis){
function fix29February (d){
if ( (basis == DayCountBasis.ActualActual || basis == DayCountBasis.Actual365) && d.isLeapYear() && d.getUTCMonth() == 2 && d.getUTCDate() >= 28){
return new Date(d.getUTCFullYear(), d.getUTCMonth(), 28);
}
else{
return d;
}
}
var firstLen = diffDate( fix29February (datePurch), fix29February(firstP), basis),
firstDeprTemp = firstLen / daysInYear( datePurch, basis ) * rate * cost,
firstDepr = firstDeprTemp == 0 ? cost * rate : firstDeprTemp,
period = firstDeprTemp == 0 ? per : per + 1,
availDepr = cost - salvage;
if (firstDepr > availDepr) {
return [availDepr,period];
}
else {
return [firstDepr,period];
}
} }
rate *= coeff; var per = Math.ceil(1 / rate ), coeff;
var val0 = Date.prototype.getDateFromExcel( datePurch ), if (cost == salvage || period > per){
val1 = Date.prototype.getDateFromExcel( firstPer ); this.value = new cNumber(0);
}
else{
var _rate = Math.round( yearFrac( val0, val1, basis ) * rate * cost ), rest; if ( per >= 3 && per < 5 ) {
cost -= _rate; coeff = 1.5;
rest = cost - salvage; }
else if ( per >= 5 && per < 6 ) {
for ( var n = 0; n < period; n++ ) { coeff = 2;
_rate = Math.round( rate * cost ); }
rest -= _rate; else if ( per >= 6 ) {
coeff = 2.5;
if ( rest < 0 ) {
switch ( period - n ) {
case 0:
case 1:
return this.value = new cNumber( Math.round( cost * 0.5 ) );
default:
return this.value = new cNumber( 0 );
}
} }
else{
this.value = new cError( cErrorType.not_numeric );
}
var deprR = rate * coeff,
o = firstDeprLinc(cost, datePurch, firstPer, salvage, deprR, per, basis);
cost -= _rate; var firstDeprLinc = o[0], assetLife = o[1],
firstDepr = Math.round(firstDeprLinc);//round excelComplaint firstDeprLinc
if ( period == 0 ){
this.value = new cNumber( firstDepr );
}
else{
this.value = findDepr(1, 0, deprR,(cost - firstDepr));
}
} }
return this.value = new cNumber( _rate ) return this.value;
}; };
cAMORDEGRC.prototype.getInfo = function () { cAMORDEGRC.prototype.getInfo = function () {
......
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