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 );
function findDepr( countedPeriod, depr, rate, cost ){
if (countedPeriod > period) {
return new cNumber(Math.round(depr));
} }
else if ( per >= 3 && per <= 4 ) { else{
coeff = 1.5; countedPeriod++;
} }
else if ( per >= 5 && per <= 6 ) {
coeff = 2; 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 if ( per > 6 ) {
coeff = 2.5;
} }
else { else {
return this.value = new cError( cErrorType.not_numeric ); depr = deprTemp;
} }
rate *= coeff; cost -= depr;
var val0 = Date.prototype.getDateFromExcel( datePurch ), return findDepr( countedPeriod, depr, rate, cost );
val1 = Date.prototype.getDateFromExcel( firstPer ); }
var _rate = Math.round( yearFrac( val0, val1, basis ) * rate * cost ), rest; function firstDeprLinc( cost, datePurch, firstP, salvage, rate, per, basis){
cost -= _rate; function fix29February (d){
rest = cost - salvage; 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;
}
}
for ( var n = 0; n < period; n++ ) { var firstLen = diffDate( fix29February (datePurch), fix29February(firstP), basis),
_rate = Math.round( rate * cost ); firstDeprTemp = firstLen / daysInYear( datePurch, basis ) * rate * cost,
rest -= _rate; firstDepr = firstDeprTemp == 0 ? cost * rate : firstDeprTemp,
period = firstDeprTemp == 0 ? per : per + 1,
availDepr = cost - salvage;
if ( rest < 0 ) { if (firstDepr > availDepr) {
switch ( period - n ) { return [availDepr,period];
case 0: }
case 1: else {
return this.value = new cNumber( Math.round( cost * 0.5 ) ); return [firstDepr,period];
default:
return this.value = new cNumber( 0 );
} }
} }
cost -= _rate; var per = Math.ceil(1 / rate ), coeff;
if (cost == salvage || period > per){
this.value = new cNumber(0);
} }
else{
return this.value = new cNumber( _rate ) if ( per >= 3 && per < 5 ) {
coeff = 1.5;
}
else if ( per >= 5 && per < 6 ) {
coeff = 2;
}
else if ( per >= 6 ) {
coeff = 2.5;
}
else{
this.value = new cError( cErrorType.not_numeric );
}
var deprR = rate * coeff,
o = firstDeprLinc(cost, datePurch, firstPer, salvage, deprR, per, basis);
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;
}; };
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