Feature: Tax Regimes are added so that different bills with different series can be printed for Different regimes such as VAT and GST
Chore: Model relationships updated to make them simpler Chore: Bill printing majorly refactored for it Due to the sheer depth of the changes. There can be showstoppers. Please test it carefully
This commit is contained in:
109
bookie/src/app/regimes/regime-detail/regime-detail.component.ts
Normal file
109
bookie/src/app/regimes/regime-detail/regime-detail.component.ts
Normal file
@ -0,0 +1,109 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import { Regime } from '../../core/regime';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { RegimeService } from '../regime.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-regime-detail',
|
||||
templateUrl: './regime-detail.component.html',
|
||||
styleUrls: ['./regime-detail.component.css'],
|
||||
})
|
||||
export class RegimeDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: FormGroup<{
|
||||
name: FormControl<string>;
|
||||
header: FormControl<string>;
|
||||
prefix: FormControl<string>;
|
||||
}>;
|
||||
|
||||
item: Regime = new Regime();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private toaster: ToasterService,
|
||||
private ser: RegimeService,
|
||||
) {
|
||||
// Create form
|
||||
this.form = new FormGroup({
|
||||
name: new FormControl<string>('', { nonNullable: true }),
|
||||
header: new FormControl<string>('', { nonNullable: true }),
|
||||
prefix: new FormControl<string>('', { nonNullable: true }),
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: Regime };
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: Regime) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
name: this.item.name ?? '',
|
||||
header: this.item.header ?? '',
|
||||
prefix: this.item.prefix ?? '',
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
if (this.nameElement !== undefined) {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/regimes');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Error', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id as number).subscribe(
|
||||
() => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/regimes');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Error', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: { title: 'Delete Regime?', content: 'Are you sure? This cannot be undone.' },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
if (result) {
|
||||
this.delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getItem(): Regime {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name ?? '';
|
||||
this.item.header = formModel.header ?? '';
|
||||
this.item.prefix = formModel.prefix ?? '';
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user