66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
import { MatSort } from '@angular/material/sort';
|
|
import { ActivatedRoute, Router } from '@angular/router';
|
|
import * as moment from 'moment';
|
|
|
|
import { NetTransactions } from './net-transactions';
|
|
import { NetTransactionsDataSource } from './net-transactions-datasource';
|
|
|
|
@Component({
|
|
selector: 'app-net-transactions',
|
|
templateUrl: './net-transactions.component.html',
|
|
styleUrls: ['./net-transactions.component.css'],
|
|
})
|
|
export class NetTransactionsComponent implements OnInit {
|
|
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
dataSource: NetTransactionsDataSource;
|
|
form: FormGroup;
|
|
info: NetTransactions;
|
|
selectedRowId: string;
|
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
|
displayedColumns = ['type', 'name', 'debit', 'credit'];
|
|
|
|
constructor(private route: ActivatedRoute, private router: Router, private fb: FormBuilder) {
|
|
this.form = this.fb.group({
|
|
startDate: '',
|
|
finishDate: '',
|
|
});
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.route.data.subscribe((value) => {
|
|
const data = value as { info: NetTransactions };
|
|
|
|
this.info = data.info;
|
|
this.form.setValue({
|
|
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
|
|
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate(),
|
|
});
|
|
this.dataSource = new NetTransactionsDataSource(this.paginator, this.sort, this.info.body);
|
|
});
|
|
}
|
|
|
|
show() {
|
|
const l = this.prepareSubmit();
|
|
this.router.navigate(['net-transactions'], {
|
|
queryParams: {
|
|
startDate: l.startDate,
|
|
finishDate: l.finishDate,
|
|
},
|
|
});
|
|
}
|
|
|
|
prepareSubmit(): NetTransactions {
|
|
const formModel = this.form.value;
|
|
|
|
return {
|
|
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
|
|
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
|
|
body: [],
|
|
};
|
|
}
|
|
}
|