Some changes with comunications WS <--> Angular

This commit is contained in:
Artur 2024-10-11 14:01:40 +02:00
parent 199c02ab14
commit 6fa03e080c
3 changed files with 31 additions and 16 deletions

View File

@ -2,7 +2,7 @@ import {Component, OnInit } from '@angular/core';
import {FormsModule} from '@angular/forms';
import {CurrencyPipe,DecimalPipe,PercentPipe} from '@angular/common';
import {AssetsModule} from './assets/assets.module'
import {Asset, Positions, AssetPlanPosition } from './assets/asset';
import {Asset, Positions, AssetPlanPosition, TypeDepreciation } from './assets/asset';
import {AssetService} from './assets/service/asset.service'
@Component({
@ -37,6 +37,7 @@ import {AssetService} from './assets/service/asset.service'
[ngModel]="asset.year "
(ngModelChange)="asset.year=$event;calculate()"
/>
<input type="number" id="month" name="month"
[ngModel]="asset.month"
(ngModelChange)="asset.month=$event;calculate()"
@ -46,17 +47,21 @@ import {AssetService} from './assets/service/asset.service'
</tr>
<tr>
<td>Metoda amortyzacji</td>
<td><select onchange="hideWskaznik()" id="rodzajAmortyzacji" name="metodaAmortyzacji" >
<option value="0" selected="selected"
>Liniowa</option>
<option value="1"
>Dygresywna</option>
</select></td>
<td id="wskaznik" style="display: block">
<input type="text" id="factor" name="factor"
[ngModel]="asset.factorValue | number:'1.2-2' "
(ngModelChange)="asset.factorValue=$event"/>
</td>
<td><select [ngModel]=asset.type
(ngModelChange)="asset.type=$event;calculate() ">
<option [ngValue]="TypeDepreciation.linear" selected="selected">Liniowa</option>
<option [ngValue]="TypeDepreciation.digressive" >Dygresywna</option>
</select>
</td>
@if( TypeDepreciation.digressive === asset.type ){
<td id="wskaznik" style="display: block">
<input type="text" id="factor" name="factor"
[ngModel]="asset.factorValue | number:'1.2-2' "
(ngModelChange)="asset.factorValue=$event;calculate()"/>
</td>
}
</tr>
<input class="btn btn-primary" name="calculate" (click)=calculate() type="button" value="Wylicz ">
@ -79,8 +84,8 @@ import {AssetService} from './assets/service/asset.service'
<tr [class]="clazz(position)" >
<th scope="row">{{$index+1}}</th>
<td>{{position.when.year}}</td>
<td>{{position.when.month}}</td>
<td>{{ position.when.year }}</td>
<td>{{ position.when.month }}</td>
<td>{{ position.calculatedDepreciation | number:'1.2-2' }}</td>
<td>{{ position.sum | number:'1.2-2' }}</td>
</tr>
@ -97,7 +102,7 @@ export class AssetCalculatorComponent implements OnInit{
}
TypeDepreciation = TypeDepreciation;
asset = new Asset();
positions = new Positions();
@ -115,6 +120,7 @@ export class AssetCalculatorComponent implements OnInit{
}
clazz(pos : AssetPlanPosition ){
return pos.when.year % 2 === 0 ? "table-light" : "table-dark";
}

View File

@ -1,8 +1,16 @@
export enum TypeDepreciation{
linear, digressive
}
export class Asset {
initialValueAsset = 2000;
depreciationRate = 20;
year = 2024;
month = 10;
type = TypeDepreciation.linear;
depreciationRate = 20;
factorValue = 2;
}

View File

@ -6,6 +6,7 @@ import { Observable } from 'rxjs';
let assetUrl: string ='https://api.arti24.eu/rest-api/assets/calculate';
//let assetUrl: string ='http://localhost:8801/rest-api/assets/calculate';
@Injectable({