diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 800ea59..ccfc2cc 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -5,7 +5,14 @@ import { RouterOutlet, RouterLink, RouterLinkActive } from '@angular/router'; selector: 'app-root', standalone: true, imports: [RouterOutlet, RouterLink, RouterLinkActive], - templateUrl: './app.component.html', + template: ` + + + `, styleUrl: './app.component.css' }) export class AppComponent { diff --git a/src/app/app.routes.ts b/src/app/app.routes.ts index 0b560cc..46a5c19 100644 --- a/src/app/app.routes.ts +++ b/src/app/app.routes.ts @@ -1,8 +1,15 @@ import { Routes } from '@angular/router'; -import { CommodityComponent } from './components/commodity/commodity.component'; import { DashboardComponent } from './components/dashboard/dashboard.component'; +import { AssetCalculatorComponent } from './asset-calculator/asset-calculator.component'; export const routes: Routes = [ - { path: "", component:DashboardComponent }, - { path: "group/:group", component: DashboardComponent } + { path: "", + title:"Kalkulator", + component: AssetCalculatorComponent }, + { path: "asset-calculator", + title: "Kalkulator", + component:AssetCalculatorComponent }, + { path: "quotes", + title:"Kursy!", + component: DashboardComponent } ]; diff --git a/src/app/asset-calculator/asset-calculator.component.css b/src/app/asset-calculator/asset-calculator.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/asset-calculator/asset-calculator.component.html b/src/app/asset-calculator/asset-calculator.component.html new file mode 100644 index 0000000..d5f2157 --- /dev/null +++ b/src/app/asset-calculator/asset-calculator.component.html @@ -0,0 +1 @@ +

asset-calculator works!

diff --git a/src/app/asset-calculator/asset-calculator.component.spec.ts b/src/app/asset-calculator/asset-calculator.component.spec.ts new file mode 100644 index 0000000..716509b --- /dev/null +++ b/src/app/asset-calculator/asset-calculator.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AssetCalculatorComponent } from './asset-calculator.component'; + +describe('AssetCalculatorComponent', () => { + let component: AssetCalculatorComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [AssetCalculatorComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(AssetCalculatorComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/asset-calculator/asset-calculator.component.ts b/src/app/asset-calculator/asset-calculator.component.ts new file mode 100644 index 0000000..c7d1e77 --- /dev/null +++ b/src/app/asset-calculator/asset-calculator.component.ts @@ -0,0 +1,125 @@ +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 {AssetService} from './assets/service/asset.service' + +@Component({ + selector: 'app-asset-calculator', + standalone: true, + imports: [FormsModule, CurrencyPipe, DecimalPipe, PercentPipe, AssetsModule], + template: ` +

Kalkulator amortyzacyjny

+ + + + + + + + + + + + + + + + + + + + + + + +
Wartość początkowa środka trwałego:
Stawka amortyzacyjna %
Miesiąc rozpoczęcia amortyzacjii + + +
Metoda amortyzacji + +
+
+ + + + + + + + + + + + @for (position of positions.positions; track $index) { + + + + + + + + + + + } + +
LpRokMiesiącKwota odpisuLączny odpis
{{$index+1}}{{position.when.year}}{{position.when.month}}{{ position.calculatedDepreciation | number:'1.2-2' }}{{ position.sum | number:'1.2-2' }}
+
+ `, + styleUrl: './asset-calculator.component.css' +}) +export class AssetCalculatorComponent implements OnInit{ + + constructor(private assetService : AssetService ){ + + } + + + asset = new Asset(); + positions = new Positions(); + + calculate() { + this.assetService.calculate(this.asset).subscribe( positions => { this.positions=positions; this.calculateToValues() }); + } + + calculateToValues() { + let sum :number = 0; + for(let position of this.positions.positions ){ + position.calculatedDepreciation = position.calculatedDepreciation *0.01; + sum += position.calculatedDepreciation; + position.sum = sum; + } + } + + clazz(pos : AssetPlanPosition ){ + return pos.when.year % 2 === 0 ? "table-light" : "table-dark"; + } + + ngOnInit(): void{ + this.calculate(); + } + +} diff --git a/src/app/asset-calculator/assets/asset.spec.ts b/src/app/asset-calculator/assets/asset.spec.ts new file mode 100644 index 0000000..38ec928 --- /dev/null +++ b/src/app/asset-calculator/assets/asset.spec.ts @@ -0,0 +1,7 @@ +import { Asset } from './asset'; + +describe('Asset', () => { + it('should create an instance', () => { + expect(new Asset()).toBeTruthy(); + }); +}); diff --git a/src/app/asset-calculator/assets/asset.ts b/src/app/asset-calculator/assets/asset.ts new file mode 100644 index 0000000..c6138d9 --- /dev/null +++ b/src/app/asset-calculator/assets/asset.ts @@ -0,0 +1,23 @@ +export class Asset { + initialValueAsset = 2000; + depreciationRate = 20; + year = 2024; + month = 10; + factorValue = 2; +} + +export class YearMonth{ + year : number = 0; + month :number = 0; +} + +export class AssetPlanPosition{ + when : YearMonth = new YearMonth(); + calculatedDepreciation : number = 0; + sum:number = 0; + +} + +export class Positions { + positions : AssetPlanPosition[]=[]; +} \ No newline at end of file diff --git a/src/app/asset-calculator/assets/assets.module.ts b/src/app/asset-calculator/assets/assets.module.ts new file mode 100644 index 0000000..0f977e0 --- /dev/null +++ b/src/app/asset-calculator/assets/assets.module.ts @@ -0,0 +1,12 @@ +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; + + + +@NgModule({ + declarations: [], + imports: [ + CommonModule + ] +}) +export class AssetsModule { } diff --git a/src/app/asset-calculator/assets/service/asset.service.spec.ts b/src/app/asset-calculator/assets/service/asset.service.spec.ts new file mode 100644 index 0000000..10cf0c6 --- /dev/null +++ b/src/app/asset-calculator/assets/service/asset.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { AssetService } from './asset.service'; + +describe('AssetService', () => { + let service: AssetService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(AssetService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/asset-calculator/assets/service/asset.service.ts b/src/app/asset-calculator/assets/service/asset.service.ts new file mode 100644 index 0000000..66c5bd4 --- /dev/null +++ b/src/app/asset-calculator/assets/service/asset.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@angular/core'; + +import { HttpClient,HttpErrorResponse } from '@angular/common/http'; +import { Asset, Positions } from '../asset'; +import { Observable } from 'rxjs'; + + +let assetUrl: string ='http://localhost:8181/rest-api/assets/calculate'; + + +@Injectable({ + providedIn: 'root' +}) +export class AssetService { + + constructor(private http: HttpClient) { } + + calculate(asset: Asset) : Observable{ + return this.http.post(assetUrl, asset) ; + } + +} + diff --git a/src/app/components/commodity/commodity.component.ts b/src/app/components/commodity/commodity.component.ts index c5dafd7..faa6d5b 100644 --- a/src/app/components/commodity/commodity.component.ts +++ b/src/app/components/commodity/commodity.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, Injectable, Input } from '@angular/core'; +import { Component, OnInit, Injectable, Input, inject } from '@angular/core'; import { CommodityService } from './services/commodity.service'; @Component({ @@ -8,7 +8,7 @@ import { CommodityService } from './services/commodity.service'; styleUrl: './commodity.component.css' }) -@Injectable() + export class CommodityComponent implements OnInit { @Input() @@ -16,7 +16,6 @@ export class CommodityComponent implements OnInit { info: any; - constructor(private commodityService: CommodityService) { } diff --git a/src/app/components/dashboard/dashboard.component.html b/src/app/components/dashboard/dashboard.component.html index 57ba60e..cdc8499 100644 --- a/src/app/components/dashboard/dashboard.component.html +++ b/src/app/components/dashboard/dashboard.component.html @@ -4,13 +4,11 @@ diff --git a/src/app/components/dashboard/dashboard.component.ts b/src/app/components/dashboard/dashboard.component.ts index d5b082e..0443cbc 100644 --- a/src/app/components/dashboard/dashboard.component.ts +++ b/src/app/components/dashboard/dashboard.component.ts @@ -17,32 +17,16 @@ export class DashboardComponent implements OnInit { commodities: Array = [ "AU" ] - group: string = "all"; - symbols : Array = this.commodities.concat(this.currency); - getSymbolsForGroup(group: string): Array { - switch (group) { - case "all": - return this.commodities.concat(this.currency); - case "currency": - return this.currency; - case "commodities": - return this.commodities - default: - return this.currency.concat( this.commodities ); - } - } - constructor(private route: ActivatedRoute) { } ngOnInit(): void { this.route.params.subscribe((params: Params) => { - let group = params["group"]; - this.symbols = this.getSymbolsForGroup(group) - }); + + }); // this.route.paramMap. }