better handling of presets

This commit is contained in:
Wolfgang Hottgenroth 2022-04-01 15:05:06 +02:00
parent 74d0a6084b
commit 3e32613a78
Signed by: wn
GPG Key ID: E49AF3B9EF6DD469
2 changed files with 23 additions and 17 deletions

View File

@ -10,9 +10,9 @@
<mat-label>Jahr</mat-label> <mat-label>Jahr</mat-label>
<input matInput type="number" name="fiscalYear" [formControl]="presetFiscalYear" ngModel/> <input matInput type="number" name="fiscalYear" [formControl]="presetFiscalYear" ngModel/>
</mat-form-field> </mat-form-field>
<mat-form-field appearance="outline" *ngIf="!shallBeRentPayment"> <mat-form-field appearance="outline">
<mat-label>Kategorie</mat-label> <mat-label>Kategorie</mat-label>
<mat-select ngModel name="category" [disabled]="shallBeRentPayment"> <mat-select ngModel name="category" [formControl]="presetCategory" >
<mat-option *ngFor="let p of accountEntryCategories" [value]="p.id">{{p.description}}</mat-option> <mat-option *ngFor="let p of accountEntryCategories" [value]="p.id">{{p.description}}</mat-option>
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
@ -22,7 +22,7 @@
</mat-form-field> </mat-form-field>
<mat-form-field appearance="outline"> <mat-form-field appearance="outline">
<mat-label>Beschreibung</mat-label> <mat-label>Beschreibung</mat-label>
<input matInput name="description" ngModel/> <input matInput name="description" [formControl]="presetDescription" ngModel/>
</mat-form-field> </mat-form-field>
<button #addAccountEntryButton type="submit" mat-raised-button color="primary">Buchung speichern</button> <button #addAccountEntryButton type="submit" mat-raised-button color="primary">Buchung speichern</button>
</form> </form>
@ -52,7 +52,7 @@ Saldo: {{saldo?.saldo | number:'1.2-2'}} €
<th mat-header-cell *matHeaderCellDef>Betrag</th> <th mat-header-cell *matHeaderCellDef>Betrag</th>
<td mat-cell *matCellDef="let element" class="rightaligned">{{element.rawAccountEntry.amount | number:'1.2-2'}} €</td> <td mat-cell *matCellDef="let element" class="rightaligned">{{element.rawAccountEntry.amount | number:'1.2-2'}} €</td>
</ng-container> </ng-container>
<ng-container matColumnDef="accountEntryCategory"> <ng-container matColumnDef="category">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Kategorie</th> <th mat-header-cell *matHeaderCellDef mat-sort-header>Kategorie</th>
<td mat-cell *matCellDef="let element">{{element.accountEntryCategory}}</td> <td mat-cell *matCellDef="let element">{{element.accountEntryCategory}}</td>
</ng-container> </ng-container>

View File

@ -37,7 +37,7 @@ export class AccountComponent implements OnInit {
account: Account account: Account
accountEntries: DN_AccountEntry[] accountEntries: DN_AccountEntry[]
accountEntriesDataSource: MatTableDataSource<DN_AccountEntry> accountEntriesDataSource: MatTableDataSource<DN_AccountEntry>
accountEntriesDisplayedColumns: string[] = [ "description", "document_no", "amount", "createdAt", "fiscalYear", "accountEntryCategory", "overhead_relevant" ] accountEntriesDisplayedColumns: string[] = [ "description", "document_no", "amount", "createdAt", "fiscalYear", "category", "overhead_relevant" ]
saldo: Saldo saldo: Saldo
accountEntryCategories: AccountEntryCategory[] accountEntryCategories: AccountEntryCategory[]
@ -45,6 +45,8 @@ export class AccountComponent implements OnInit {
accountEntryCategoriesInverseMap: Map<string, AccountEntryCategory> accountEntryCategoriesInverseMap: Map<string, AccountEntryCategory>
presetFiscalYear: FormControl presetFiscalYear: FormControl
presetCategory: FormControl
presetDescription: FormControl
constructor( constructor(
private accountService: AccountService, private accountService: AccountService,
@ -99,23 +101,14 @@ export class AccountComponent implements OnInit {
let uniquenumber: UniqueNumber = await this.extApiService.getUniqueNumber(); let uniquenumber: UniqueNumber = await this.extApiService.getUniqueNumber();
this.messageService.add(`Got unique number as document_no: ${uniquenumber.number}`) this.messageService.add(`Got unique number as document_no: ${uniquenumber.number}`)
let newAccountEntry: AccountEntry = { let newAccountEntry: AccountEntry = {
description: formData.value.description, description: this.presetDescription.value,
account: this.account.id, account: this.account.id,
created_at: formData.value.createdAt, created_at: formData.value.createdAt,
fiscal_year: this.presetFiscalYear.value, fiscal_year: this.presetFiscalYear.value,
amount: formData.value.amount, amount: formData.value.amount,
id: 0, id: 0,
document_no: uniquenumber.number, document_no: uniquenumber.number,
account_entry_category: 0 account_entry_category: this.presetCategory.value
}
if (this.shallBeRentPayment) {
newAccountEntry.account_entry_category = this.accountEntryCategoriesInverseMap.get('Mietzahlung').id
newAccountEntry.description = "Miete"
this.messageService.add(`shall be rentpayment, category is ${newAccountEntry.account_entry_category}`)
} else {
newAccountEntry.account_entry_category = formData.value.category
this.messageService.add(`category is ${newAccountEntry.account_entry_category}`)
} }
this.messageService.add(`addAccountEntry: ${ JSON.stringify(newAccountEntry, undefined, 4) }`) this.messageService.add(`addAccountEntry: ${ JSON.stringify(newAccountEntry, undefined, 4) }`)
@ -149,12 +142,25 @@ export class AccountComponent implements OnInit {
} }
private async init(): Promise<void> { private async init(): Promise<void> {
this.messageService.add(`AccountComponent.init start, account: ${this.selectedAccountId}`)
let currentDate = new Date() let currentDate = new Date()
let y = currentDate.getFullYear() let y = currentDate.getFullYear()
this.presetFiscalYear = new FormControl(y) this.presetFiscalYear = new FormControl(y)
this.messageService.add(`AccountComponent.init a, account: ${this.selectedAccountId}`)
await this.getAccountEntryCategories()
if (this.shallBeRentPayment) {
this.messageService.add(`AccountComponent.init b, account: ${this.selectedAccountId}`)
this.presetCategory = new FormControl(this.accountEntryCategoriesInverseMap.get('Mietzahlung').id)
this.messageService.add(`AccountComponent.init c, account: ${this.selectedAccountId}`)
this.presetDescription = new FormControl("Miete")
this.messageService.add(`shall be rentpayment`)
this.messageService.add(`AccountComponent.init d, account: ${this.selectedAccountId}`)
}
this.messageService.add(`AccountComponent.init, account: ${this.selectedAccountId}`) this.messageService.add(`AccountComponent.init, account: ${this.selectedAccountId}`)
this.getAccount() this.getAccount()
await this.getAccountEntryCategories()
} }