Skip to content
This repository has been archived by the owner on Jun 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #41 from johanngoltz/dev/michael
Browse files Browse the repository at this point in the history
Dev/michael
  • Loading branch information
johanngoltz authored Jul 5, 2018
2 parents 9bbf1cb + e343df4 commit b30ef90
Show file tree
Hide file tree
Showing 25 changed files with 372 additions and 95 deletions.
8 changes: 4 additions & 4 deletions src/app/accounting-data/accounting-data.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@
</tr>
</thead>
<tbody>
<ng-container *ngFor="let ctrl of keys(paramData)">
<tr class="mat-row" *ngIf="[undefined, formGroup.value.calculateFcf].indexOf(paramData[ctrl].showOnCalculation) > -1">
<ng-container *ngFor="let ctrl of keys(accountingDataParams)">
<tr class="mat-row" *ngIf="[undefined, formGroup.value.calculateFcf].indexOf(accountingDataParams[ctrl].showOnCalculation) > -1">
<th class="mat-header-cell" [formGroup]="formGroup.controls[ctrl]">
{{paramData[ctrl].displayName}}
{{accountingDataParams[ctrl].displayName}}
<mat-checkbox formControlName="isHistoric" *ngIf="_editable">Prognostizieren</mat-checkbox>
<div *ngIf="!_editable" class="no-bold">&nbsp;{{formGroup.controls[ctrl].value.isHistoric ? 'Wird prognostiziert' : ''}}</div>
</th>
<td class="mat-cell" *ngFor="let element of formGroup.controls[ctrl].controls.timeSeries.controls; trackBy: trackByYearQuarter">
<ng-container *ngIf="_timeSeriesMethodsService.checkVisibility(element.value, formGroup.controls[ctrl].controls.isHistoric.value, formGroup.controls.quarterly.value, base, formGroup.controls.end.value, paramData[ctrl].shiftDeterministic)">
<ng-container *ngIf="_timeSeriesMethodsService.checkVisibility(element.value, formGroup.controls[ctrl].controls.isHistoric.value, formGroup.controls.quarterly.value, base, formGroup.controls.end.value, accountingDataParams[ctrl].shiftDeterministic)">
<span class="table-data" *ngIf="!_editable">{{element.value.amount}}</span>
<mat-form-field class="table-input-right" [formGroup]="element" *ngIf="_editable">
<input type="text" matInput formControlName="amount" appToDouble required>
Expand Down
36 changes: 20 additions & 16 deletions src/app/accounting-data/accounting-data.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormGroup, FormArray, FormBuilder, Validators, AbstractControl, FormCon
import { debounceTime, map, first } from 'rxjs/operators';
import { Scenario } from '../api/scenario';
import { Observable } from 'rxjs';
import { paramData } from '../api/paramData';
import { AccountingDataParams } from '../api/paramData';
import { TimeSeriesMethodsService } from '../service/time-series-methods.service';

@Component({
Expand All @@ -22,7 +22,7 @@ export class AccountingDataComponent implements OnInit {
base: { year: number, quarter: number };
start: { year: number, quarter: number }; // debounced values
end: { year: number, quarter: number };
paramData = paramData;
accountingDataParams = AccountingDataParams.prototype;

constructor(private _formBuilder: FormBuilder, private _timeSeriesMethodsService: TimeSeriesMethodsService) {
}
Expand Down Expand Up @@ -83,7 +83,7 @@ export class AccountingDataComponent implements OnInit {
}

calculateInterval(scenario: Scenario) {
const params = Object.keys(this.paramData);
const params = Object.keys(this.accountingDataParams);
this.start = undefined;
this.end = undefined;
this.base = undefined;
Expand All @@ -101,7 +101,7 @@ export class AccountingDataComponent implements OnInit {
accountingFigure.timeSeries[accountingFigure.timeSeries.length - 1].quarter : 1,
};
} else if (!this.end && !accountingFigure.isHistoric) {
const shiftDeterministic = this.paramData[params[i]].shiftDeterministic;
const shiftDeterministic = this.accountingDataParams[params[i]].shiftDeterministic;
let dataPoint = accountingFigure.timeSeries[accountingFigure.timeSeries.length - 1];
let year = dataPoint.year +
((shiftDeterministic && (!dataPoint.quarter || dataPoint.quarter === 4)) ? 1 : 0);
Expand Down Expand Up @@ -138,11 +138,11 @@ export class AccountingDataComponent implements OnInit {
}

buildParamFormGroups(formGroup: FormGroup, scenario?: Scenario) {
Object.keys(this.paramData).forEach(param => {
Object.keys(this.accountingDataParams).forEach(param => {
const timeSeries = [];
if (scenario && scenario[param] && scenario[param].timeSeries) {
const items = scenario[param].timeSeries.filter(dataPoint => this._timeSeriesMethodsService.isInsideBounds(
this.formGroup.controls.quarterly.value,
formGroup.controls.quarterly.value,
this.start,
this.end,
dataPoint
Expand All @@ -165,12 +165,16 @@ export class AccountingDataComponent implements OnInit {
}

get timeSeriesControls() {
return ((this.formGroup.controls.liabilities as FormGroup).controls.timeSeries as FormArray).controls;
try {
return ((this.formGroup.controls.liabilities as FormGroup).controls.timeSeries as FormArray).controls;
} catch (err) {
return undefined;
}
}

quarterlyChanged() {
const quarterly = this.formGroup.controls.quarterly.value;
Object.keys(this.paramData).forEach(param => {
Object.keys(this.accountingDataParams).forEach(param => {
const newTimeSeries = [];
const timeSeries = <FormArray>(<FormGroup>this.formGroup.controls[param]).controls.timeSeries;
if (quarterly) {
Expand All @@ -190,14 +194,14 @@ export class AccountingDataComponent implements OnInit {
});
} else {
while (timeSeries.length > 0) {
const values = [];
const valuesOfYear = [];
do {
values.push(timeSeries.value[0]);
valuesOfYear.push(timeSeries.value[0]);
timeSeries.removeAt(0);
} while (timeSeries.length > 0 && timeSeries.value[0].year === values[0].year);
} while (timeSeries.length > 0 && timeSeries.value[0].year === valuesOfYear[0].year);
newTimeSeries.push(this._formBuilder.group({
year: values[0].year,
amount: values.reduce((a, b) => a ? a : 0 + b ? b : 0, 0),
year: valuesOfYear[0].year,
amount: valuesOfYear.reduce((a, b) => a + b.amount, 0),
}));
}
}
Expand Down Expand Up @@ -249,7 +253,7 @@ export class AccountingDataComponent implements OnInit {
updateTable() {
const start = this.formGroup.controls.start.value;
const end = this.formGroup.controls.end.value;
Object.keys(this.paramData).forEach((param) => {
Object.keys(this.accountingDataParams).forEach((param) => {
const timeSeries = <FormArray>(<FormGroup>this.formGroup.controls[param]).controls.timeSeries;
// Remove values outside bounds
for (let i = 0; i < timeSeries.length; i++) {
Expand All @@ -275,7 +279,7 @@ export class AccountingDataComponent implements OnInit {
}

validateForm(formGroup: FormGroup) {
const params = Object.keys(this.paramData).map(param => {
const params = Object.keys(this.accountingDataParams).map(param => {
const paramFormGroup = (<FormGroup>formGroup.controls[param]);
if (paramFormGroup) {
const timeSeries = (<FormArray>paramFormGroup.controls.timeSeries).controls;
Expand All @@ -292,7 +296,7 @@ export class AccountingDataComponent implements OnInit {
this.formGroup.controls.quarterly.value,
this.formGroup.controls.base.value,
this.end,
this.paramData[param].shiftDeterministic))
this.accountingDataParams[param].shiftDeterministic))
.map(dataPoint => dataPoint.valid)
.filter(valid => valid === false)
.length === 0;
Expand Down
28 changes: 18 additions & 10 deletions src/app/api/paramData.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
export let paramData = {
revenue: { displayName: 'Umsatzerlöse', showOnCalculation: true },
additionalIncome: { displayName: 'Sonstige Erlöse', showOnCalculation: true },
costOfMaterial: { displayName: 'Materialkosten', showOnCalculation: true },
costOfStaff: { displayName: 'Personalkosten', showOnCalculation: true },
additionalCosts: { displayName: 'Sonstige Kosten', showOnCalculation: true },
investments: { displayName: 'Investitionen', showOnCalculation: true },
divestments: { displayName: 'Desinvestitionen', showOnCalculation: true },
freeCashFlows: { displayName: 'Free Cash Flow', showOnCalculation: false },
liabilities: { displayName: 'Fremdkapital', shiftDeterministic: true },
export abstract class AccountingDataParams {
revenue: { displayName: 'Umsatzerlöse', showOnCalculation: true };
additionalIncome: { displayName: 'Sonstige Erlöse', showOnCalculation: true };
costOfMaterial: { displayName: 'Materialkosten', showOnCalculation: true };
costOfStaff: { displayName: 'Personalkosten', showOnCalculation: true };
additionalCosts: { displayName: 'Sonstige Kosten', showOnCalculation: true };
investments: { displayName: 'Investitionen', showOnCalculation: true };
divestments: { displayName: 'Desinvestitionen', showOnCalculation: true };
freeCashFlows: { displayName: 'Free Cash Flow', showOnCalculation: false };
liabilities: { displayName: 'Fremdkapital', showOnCalculation: undefined, shiftDeterministic: true };
}

export const environmentParams = {
equityInterestRate: {},
interestOnLiabilitiesRate: {},
businessTaxRate: {},
corporateTaxRate: {},
solidaryTaxRate: {},
};
4 changes: 4 additions & 0 deletions src/app/app.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ mat-toolbar {
::ng-deep .content-conatiner {
display: block;
}

::ng-deep mat-dialog-container {
position: relative;
}
1 change: 1 addition & 0 deletions src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
</button>
</mat-menu>
<mat-menu #ellipsisMenu="matMenu">
<button mat-menu-item (click)="openImportDialog()">Szenario importieren</button>
<button mat-menu-item routerLink="/credits">Lizenzen</button>
</mat-menu>
19 changes: 13 additions & 6 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ import { Component } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';

import { AuthenticationService } from './service/authentication.service';
import { MatDialog } from '@angular/material';
import { ImportScenarioComponent } from './import-scenario/import-scenario.component';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
animations: [
trigger('routerTransition', [
transition('projects => create', [
transition('scenarios => create', [
query(':enter', style({ position: 'fixed', opacity: 0, transform: 'translateY(25px)', zIndex: 7 })
, { optional: true }),
group([
Expand Down Expand Up @@ -64,20 +66,25 @@ export class AppComponent {
title = 'SUMZ';

constructor(
private router: Router,
private authenticationService: AuthenticationService,
private _router: Router,
private _authenticationService: AuthenticationService,
private _dialog: MatDialog,
) { }

getState(outlet) {
return outlet.activatedRouteData.state;
}

openImportDialog() {
this._dialog.open(ImportScenarioComponent).afterClosed().subscribe();
}

logout() {
this.authenticationService.logout();
this.router.navigateByUrl('/login');
this._authenticationService.logout();
this._router.navigateByUrl('/login');
}

change() {
this.router.navigateByUrl('changepassword');
this._router.navigateByUrl('changepassword');
}
}
6 changes: 5 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { SelectScenarioComponent } from './select-scenario/select-scenario.compo
import { ScenariosService } from './service/scenarios.service';
import { ScenariosServiceMock } from './service/scenarios.service.mock';
import { ToDoubleDirective } from './to-double.directive';
import { ExportScenarioComponent } from './export-scenario/export-scenario.component';
import { ImportScenarioComponent } from './import-scenario/import-scenario.component';


@NgModule({
Expand All @@ -47,6 +49,8 @@ import { ToDoubleDirective } from './to-double.directive';
NewPasswordEmailComponent,
AlertComponent,
CreditsComponent,
ExportScenarioComponent,
ImportScenarioComponent,
],
imports: [
BrowserModule,
Expand All @@ -65,6 +69,6 @@ import { ToDoubleDirective } from './to-double.directive';
AuthGuard,
],
bootstrap: [AppComponent],
entryComponents: [SelectScenarioComponent, DeleteDialogComponent, AlertComponent],
entryComponents: [SelectScenarioComponent, DeleteDialogComponent, AlertComponent, ExportScenarioComponent, ImportScenarioComponent],
})
export class AppModule { }
1 change: 0 additions & 1 deletion src/app/create-scenario/create-scenario.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ <h4>Aus bestehendem Szenario erstellen</h4>
Nur Zahlen erlaubt
</mat-error>
</mat-form-field>
{{formGroup2.controls.businessTaxRate.value}}
<mat-form-field floatLabel="always">
<input matInput type="text" appToDouble placeholder="Körperschaftssteuersatz" formControlName="corporateTaxRate" />
<span matPrefix>% &nbsp;</span>
Expand Down
20 changes: 9 additions & 11 deletions src/app/create-scenario/create-scenario.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, EventEmitter, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';
import { MatBottomSheet } from '@angular/material';
import { Router } from '@angular/router';
import { paramData } from '../api/paramData';
import { AccountingDataParams } from '../api/paramData';
import { Scenario } from '../api/scenario';
import { SelectScenarioComponent } from '../select-scenario/select-scenario.component';
import { AlertService } from '../service/alert.service';
Expand All @@ -20,7 +20,7 @@ export class CreateScenarioComponent implements OnInit {
formGroup3: FormGroup;
busy: Boolean;
importedScenario: EventEmitter<Scenario>;
paramData = paramData;
accountingDataParams = AccountingDataParams.prototype;

constructor(private _formBuilder: FormBuilder,
private _scenariosService: ScenariosService,
Expand Down Expand Up @@ -49,6 +49,7 @@ export class CreateScenarioComponent implements OnInit {

createScenario() {
if (this.formGroup3.valid) {
Object.values(this.formGroup2.controls).forEach(control => control.setValue(control.value / 100));
this.busy = true;
const scenario = {
id: null,
Expand All @@ -61,8 +62,9 @@ export class CreateScenarioComponent implements OnInit {
const base = this.formGroup3.controls.base.value;
const end = this.formGroup3.controls.end.value;
const quarterly = this.formGroup3.controls.quarterly.value;
Object.keys(this.paramData)
.filter(param => [undefined, this.formGroup3.value.calculateFcf].indexOf(this.paramData[param].showOnCalculation) > -1)
Object.keys(this.accountingDataParams)
.filter((param: keyof AccountingDataParams) => this._timeSeriesMethodsService.shouldDisplayAccountingDataParam(
this.accountingDataParams, this.formGroup3.controls.calculateFcf.value, param))
.forEach((param) => {
const paramFormGroup = this.formGroup3.controls[param];
if (paramFormGroup.value.isHistoric && !scenario.stochastic) {
Expand All @@ -73,7 +75,7 @@ export class CreateScenarioComponent implements OnInit {
timeSeries: paramFormGroup.value.timeSeries.filter(dataPoint =>
this._timeSeriesMethodsService.isInsideBounds(quarterly, start, end, dataPoint)
&& this._timeSeriesMethodsService.checkVisibility(dataPoint, paramFormGroup.value.isHistoric, quarterly, base, end,
this.paramData[param].shiftDeterministic)),
this.accountingDataParams[param].shiftDeterministic)),
};
});
this._scenariosService.addScenario(scenario)
Expand Down Expand Up @@ -102,11 +104,7 @@ export class CreateScenarioComponent implements OnInit {
if (this.formGroup1.value.description.length === 0) {
this.formGroup1.controls.description.setValue(scenario.description);
}
this.formGroup2.controls.equityInterestRate.setValue(scenario.equityInterestRate);
this.formGroup2.controls.interestOnLiabilitiesRate.setValue(scenario.interestOnLiabilitiesRate);
this.formGroup2.controls.businessTaxRate.setValue(scenario.businessTaxRate);
this.formGroup2.controls.corporateTaxRate.setValue(scenario.corporateTaxRate);
this.formGroup2.controls.solidaryTaxRate.setValue(scenario.solidaryTaxRate);
Object.entries(this.formGroup2.controls).forEach(([key, control]) => control.setValue(scenario[key] * 100));
this.importedScenario.emit(scenario);
this._alertService.success(`Die Daten des Szenarios "${scenario.name}" wurden erfolgreich übernommen`);
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/delete-dialog/delete-dialog.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 mat-dialog-title>{{data.project ? 'Szenario' : data.scenario ? 'Szenario' : ''}} löschen?</h1>
<h1 mat-dialog-title>Szenario löschen?</h1>
<div mat-dialog-content>
<p>{{data.project ? 'Das Szenario ' + data.project.name : data.scenario ? 'Das Szenario ' + data.scenario.name : ''}} kann danach nicht mehr wiederhergestellt werden.</p>
<p>Das Szenario kann danach nicht mehr wiederhergestellt werden.</p>
</div>
<div mat-dialog-actions>
<button mat-button (click)="onNoClick()" cdkFocusInitial>Abbrechen</button>
Expand Down
3 changes: 1 addition & 2 deletions src/app/delete-dialog/delete-dialog.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
})
export class DeleteDialogComponent {
constructor(
public dialogRef: MatDialogRef<DeleteDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
public dialogRef: MatDialogRef<DeleteDialogComponent>) { }

onNoClick(): void {
this.dialogRef.close(false);
Expand Down
Empty file.
10 changes: 10 additions & 0 deletions src/app/export-scenario/export-scenario.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<mat-nav-list>
<h3 matSubheader>Dateiformat wählen</h3>
<!--<a [href]="csvBlobUrl" download="scenario.csv" mat-list-item>
<div class="title" matLine>.csv (Comma seperated value)</div>
</a>-->
<a [href]="jsonBlobUrl" download="scenario.json" mat-list-item>
<div class="title" matLine>.json (JavaScript Object notation)</div>
<div class="description" matLine>kann später wieder importiert werden.</div>
</a>
</mat-nav-list>
42 changes: 42 additions & 0 deletions src/app/export-scenario/export-scenario.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';

import { ExportScenarioComponent } from './export-scenario.component';
import { MaterialModule } from '../material.module';
import { MatBottomSheetRef, MAT_BOTTOM_SHEET_DATA } from '@angular/material';
import { Scenario } from '../api/scenario';

describe('ExportScenarioComponent', () => {
let component: ExportScenarioComponent;
let fixture: ComponentFixture<ExportScenarioComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ExportScenarioComponent],
imports: [MaterialModule],
providers: [
{ provide: MatBottomSheetRef, useValue: { dismiss() { } } },
{
provide: MAT_BOTTOM_SHEET_DATA,
useValue: {
scenario:
{
name: 'Eins',
description: 'Eine Beschreibung',
} as Scenario,
},
},
],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(ExportScenarioComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Loading

0 comments on commit b30ef90

Please sign in to comment.