Files
brewman/overlord/src/app/profit-loss/profit-loss.component.ts
T
tanshu 4571b31fc0 Chore: Check for deprecations using eslint plugin
Chore: environment file replacement stopped.
Chore: All components are now standalone and removed all modules
Chore: App routing is now in app.routes and similarly for all submodules
Chore: Http interceptors are now functional and split refresh interceptor into a separate one.
2024-05-31 22:54:41 +05:30

128 lines
3.5 KiB
TypeScript

import { CurrencyPipe } from '@angular/common';
import { Component, OnInit, ViewChild } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { MatButton } from '@angular/material/button';
import { MatCard, MatCardHeader, MatCardTitle, MatCardContent } from '@angular/material/card';
import { MatDatepickerInput, MatDatepickerToggle, MatDatepicker } from '@angular/material/datepicker';
import { MatFormField, MatLabel, MatSuffix } from '@angular/material/form-field';
import { MatInput } from '@angular/material/input';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort, MatSortHeader } from '@angular/material/sort';
import {
MatTable,
MatColumnDef,
MatHeaderCellDef,
MatHeaderCell,
MatCellDef,
MatCell,
MatFooterCellDef,
MatFooterCell,
MatHeaderRowDef,
MatHeaderRow,
MatRowDef,
MatRow,
MatFooterRowDef,
MatFooterRow,
} from '@angular/material/table';
import { ActivatedRoute, Router } from '@angular/router';
import moment from 'moment';
import { ProfitLoss } from './profit-loss';
import { ProfitLossDataSource } from './profit-loss-datasource';
@Component({
selector: 'app-profit-loss',
templateUrl: './profit-loss.component.html',
styleUrls: ['./profit-loss.component.css'],
standalone: true,
imports: [
MatCard,
MatCardHeader,
MatCardTitle,
MatCardContent,
ReactiveFormsModule,
MatFormField,
MatLabel,
MatInput,
MatDatepickerInput,
MatDatepickerToggle,
MatSuffix,
MatDatepicker,
MatButton,
MatTable,
MatSort,
MatColumnDef,
MatHeaderCellDef,
MatHeaderCell,
MatSortHeader,
MatCellDef,
MatCell,
MatFooterCellDef,
MatFooterCell,
MatHeaderRowDef,
MatHeaderRow,
MatRowDef,
MatRow,
MatFooterRowDef,
MatFooterRow,
MatPaginator,
CurrencyPipe,
],
})
export class ProfitLossComponent implements OnInit {
@ViewChild(MatPaginator, { static: true }) paginator?: MatPaginator;
@ViewChild(MatSort, { static: true }) sort?: MatSort;
info: ProfitLoss = new ProfitLoss();
dataSource: ProfitLossDataSource = new ProfitLossDataSource(this.info.body);
form: FormGroup<{
startDate: FormControl<Date>;
finishDate: FormControl<Date>;
}>;
selectedRowId = '';
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['group', 'name', 'amount', 'total'];
constructor(
private route: ActivatedRoute,
private router: Router,
) {
this.form = new FormGroup({
startDate: new FormControl(new Date(), { nonNullable: true }),
finishDate: new FormControl(new Date(), { nonNullable: true }),
});
}
ngOnInit() {
this.route.data.subscribe((value) => {
const data = value as { info: ProfitLoss };
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 ProfitLossDataSource(this.info.body, this.paginator, this.sort);
});
}
show() {
const l = this.prepareSubmit();
this.router.navigate(['profit-loss'], {
queryParams: {
startDate: l.startDate,
finishDate: l.finishDate,
},
});
}
prepareSubmit(): ProfitLoss {
const formModel = this.form.value;
return new ProfitLoss({
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY'),
});
}
}