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:
2023-03-05 23:50:41 +05:30
parent 802eded568
commit e46fe7f90e
141 changed files with 2197 additions and 892 deletions

View File

@ -1,10 +1,5 @@
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import {
AbstractControl,
UntypedFormArray,
UntypedFormBuilder,
UntypedFormGroup,
} from '@angular/forms';
import { FormArray, FormControl, FormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
@ -20,25 +15,34 @@ import { UserService } from '../user.service';
})
export class UserDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
form: UntypedFormGroup;
form: FormGroup<{
name: FormControl<string | null>;
password: FormControl<string | null>;
lockedOut: FormControl<boolean>;
roles: FormArray<
FormGroup<{
role: FormControl<boolean>;
}>
>;
}>;
item: User = new User();
hide: boolean;
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: UntypedFormBuilder,
private toaster: ToasterService,
private dialog: MatDialog,
private ser: UserService,
) {
this.hide = true;
// Create form
this.form = this.fb.group({
name: '',
password: '',
lockedOut: '',
roles: this.fb.array([]),
this.form = new FormGroup({
name: new FormControl<string | null>(null),
password: new FormControl<string | null>(null),
lockedOut: new FormControl<boolean>(false, { nonNullable: true }),
roles: new FormArray<FormGroup<{ role: FormControl<boolean> }>>([]),
});
}
@ -51,17 +55,15 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
showItem(item: User) {
this.item = item;
(this.form.get('name') as AbstractControl).setValue(item.name);
(this.form.get('password') as AbstractControl).setValue('');
(this.form.get('lockedOut') as AbstractControl).setValue(item.lockedOut);
this.form.setControl(
'roles',
this.fb.array(
item.roles.map((x) =>
this.fb.group({
role: x.enabled,
}),
),
this.form.controls.name.setValue(item.name);
this.form.controls.password.setValue('');
this.form.controls.lockedOut.setValue(item.lockedOut);
this.form.controls.roles.clear();
this.item.roles.forEach((x) =>
this.form.controls.roles.push(
new FormGroup({
role: new FormControl<boolean>(x.enabled, { nonNullable: true }),
}),
),
);
}
@ -118,15 +120,13 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
getItem(): User {
const formModel = this.form.value;
this.item.name = formModel.name;
this.item.password = formModel.password;
this.item.lockedOut = formModel.lockedOut;
const array = this.form.get('roles') as UntypedFormArray;
if (this.item.roles !== undefined) {
this.item.roles.forEach((item, index) => {
item.enabled = array.controls[index].value.role;
});
}
this.item.name = formModel.name ?? '';
this.item.password = formModel.password ?? '';
this.item.lockedOut = formModel.lockedOut ?? true;
const array = this.form.controls.roles;
this.item.roles.forEach((item, index) => {
item.enabled = array.controls[index].value.role ?? false;
});
return this.item;
}
}