Updated ruff and mypy, accepted all changes Central exception management and injected the Session. This removed a lot of duplicated boilerplate code. Added health check Updated to Angular 21
90 lines
2.9 KiB
TypeScript
90 lines
2.9 KiB
TypeScript
import { CurrencyPipe } from '@angular/common';
|
|
import { Component, ElementRef, HostListener, inject, OnInit, ViewChild } from '@angular/core';
|
|
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
import { MatButtonModule } from '@angular/material/button';
|
|
import { MatDatepickerModule } from '@angular/material/datepicker';
|
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
|
import { MatInputModule } from '@angular/material/input';
|
|
import { MatPaginator, MatPaginatorModule } from '@angular/material/paginator';
|
|
import { MatSort, MatSortModule } from '@angular/material/sort';
|
|
import { MatTableModule } from '@angular/material/table';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import moment from 'moment';
|
|
|
|
import { AccountingPipe } from '../shared/accounting.pipe';
|
|
import { TrialBalance } from './trial-balance';
|
|
import { TrialBalanceDataSource } from './trial-balance-datasource';
|
|
|
|
@Component({
|
|
selector: 'app-trial-balance',
|
|
templateUrl: './trial-balance.component.html',
|
|
styleUrls: ['./trial-balance.component.css'],
|
|
imports: [
|
|
ReactiveFormsModule,
|
|
MatFormFieldModule,
|
|
MatInputModule,
|
|
MatDatepickerModule,
|
|
MatButtonModule,
|
|
MatTableModule,
|
|
MatSortModule,
|
|
MatPaginatorModule,
|
|
CurrencyPipe,
|
|
AccountingPipe,
|
|
],
|
|
})
|
|
export class TrialBalanceComponent implements OnInit {
|
|
private route = inject(ActivatedRoute);
|
|
private router = inject(Router);
|
|
|
|
@ViewChild(MatPaginator, { static: true }) paginator!: MatPaginator;
|
|
@ViewChild(MatSort, { static: true }) sort!: MatSort;
|
|
@ViewChild('dateElement', { static: true }) dateElement!: ElementRef<HTMLInputElement>;
|
|
info: TrialBalance = new TrialBalance();
|
|
dataSource: TrialBalanceDataSource = new TrialBalanceDataSource(this.info.body, this.paginator, this.sort);
|
|
form: FormGroup<{
|
|
date: FormControl<moment.Moment>;
|
|
}>;
|
|
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
|
displayedColumns = ['type', 'name', 'debit', 'credit'];
|
|
|
|
@HostListener('window:keydown.f2', ['$event'])
|
|
focusDate(event: Event) {
|
|
event.preventDefault();
|
|
|
|
this.dateElement.nativeElement.focus();
|
|
this.dateElement.nativeElement.select();
|
|
}
|
|
|
|
constructor() {
|
|
this.form = new FormGroup({
|
|
date: new FormControl(moment(new Date()), { nonNullable: true }),
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.route.data.subscribe((value) => {
|
|
const data = value as { info: TrialBalance };
|
|
|
|
this.info = data.info;
|
|
this.form.setValue({
|
|
date: moment(this.info.date, 'DD-MMM-YYYY'),
|
|
});
|
|
this.dataSource = new TrialBalanceDataSource(this.info.body, this.paginator, this.sort);
|
|
});
|
|
}
|
|
|
|
show() {
|
|
const info = this.getInfo();
|
|
this.router.navigate(['trial-balance', info.date]);
|
|
}
|
|
|
|
getInfo(): TrialBalance {
|
|
const formModel = this.form.value;
|
|
|
|
return new TrialBalance({
|
|
date: moment(formModel.date).format('DD-MMM-YYYY'),
|
|
});
|
|
}
|
|
}
|