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:
@ -1,8 +1,9 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { round } from 'mathjs';
|
||||
import { Regime } from 'src/app/core/regime';
|
||||
|
||||
import { Tax } from '../../core/tax';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
@ -16,27 +17,34 @@ import { TaxService } from '../tax.service';
|
||||
})
|
||||
export class TaxDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: UntypedFormGroup;
|
||||
form: FormGroup<{
|
||||
name: FormControl<string>;
|
||||
rate: FormControl<number>;
|
||||
regime: FormControl<number>;
|
||||
}>;
|
||||
|
||||
item: Tax = new Tax();
|
||||
regimes: Regime[] = [];
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private fb: UntypedFormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: TaxService,
|
||||
) {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
rate: '',
|
||||
this.form = new FormGroup({
|
||||
name: new FormControl<string>('', { nonNullable: true }),
|
||||
rate: new FormControl<number>(100, { nonNullable: true }),
|
||||
regime: new FormControl<number>(0, { nonNullable: true }),
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: Tax };
|
||||
const data = value as { item: Tax; regimes: Regime[] };
|
||||
this.regimes = data.regimes;
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
@ -44,8 +52,9 @@ export class TaxDetailComponent implements OnInit, AfterViewInit {
|
||||
showItem(item: Tax) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
name: this.item.name || '',
|
||||
name: this.item.name ?? '',
|
||||
rate: this.item.rate * 100,
|
||||
regime: this.item.regime?.id ?? 0,
|
||||
});
|
||||
}
|
||||
|
||||
@ -96,8 +105,9 @@ export class TaxDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
getItem(): Tax {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
this.item.rate = round(+formModel.rate / 100, 5);
|
||||
this.item.name = formModel.name ?? '';
|
||||
this.item.rate = round((formModel.rate ?? 0) / 100, 5);
|
||||
this.item.regime.id = formModel.regime;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user