arti-angular-app/src/app/assets/asset.ts

140 lines
2.9 KiB
TypeScript

export enum TypeDepreciation{
linear, digressive
}
export class YearMonth{
static from( year_month : string) {
const [year, month] = year_month.split('-').map(Number);
return new YearMonth( year, month );
}
readonly year : number ;
readonly month : number ;
constructor( year:number, month : number ){
this.year = year;
this.month = month;
}
static today( ):YearMonth{
const today = new Date();
return new YearMonth( today.getFullYear() , today.getMonth()+1 );
}
static todayTxt( ):string{
const today = new Date();
return YearMonth.toTxt ( YearMonth.today());
}
static toTxt( ym : YearMonth ):string{
return ym.year + '-' + String(ym.month).padStart(2, '0');;
}
toJSON() {
return { year: this.year, month: this.month };
}
static fromJSON(json: { year: number; month: number }): YearMonth {
return new YearMonth(json.year, json.month);
}
}
export class AssetLifeChange{
readonly when : YearMonth;
readonly initial : number;
readonly residual : number;
readonly depreciation : number;
constructor( when : YearMonth,
initial : number,
residual : number,
depreciation: number ){
this.when = when;
this.initial = initial;
this.residual = residual;
this.depreciation = depreciation;
}
}
export class AssetDepreciationMethod{
readonly year : number;
readonly type : TypeDepreciation;
readonly rate : number ;
readonly factor : number;
constructor( year : number,
rate : number,
type : TypeDepreciation,
factor : number ){
this.year = year;
this.rate = rate;
this.type = type;
this.factor = factor;
}
}
export class Asset {
start : YearMonth ;
life : AssetLifeChange[]=[];
depreciationMethods : AssetDepreciationMethod[]=[];
addChange( change : AssetLifeChange ){
this.life.push( change );
}
addMethod( method : AssetDepreciationMethod ){
this.depreciationMethods.push( method );
}
constructor( start : YearMonth ){
this.start = start;
}
}
export class AssetsContainer{
assets: Map<string,Asset> = new Map<string,Asset> ();
delete( nrInv: string ){
this.assets.delete(nrInv);
}
put( invNumber:string, asset: Asset ){
this.assets.set( invNumber, asset );
}
get( invNumber:string ){
return this.assets.get( invNumber );
}
getNrAssets( ){
return Array.from( this.assets.entries() );
}
}
export class AssetPlanPosition{
when : YearMonth = new YearMonth(0,0);
calculatedDepreciation = 0;
sum = 0;
sumThisYear = 0;
}