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,11 +1,5 @@
import { Component, Inject } from '@angular/core';
import {
UntypedFormArray,
UntypedFormBuilder,
UntypedFormControl,
UntypedFormGroup,
Validators,
} from '@angular/forms';
import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { round } from 'mathjs';
import { Observable } from 'rxjs';
@ -20,52 +14,58 @@ import { DiscountItem } from './discount-item';
})
export class DiscountComponent {
list: DiscountItem[] = [];
form: UntypedFormGroup;
form: FormGroup<{
discounts: FormArray<
FormGroup<{
name: FormControl<string>;
discount: FormControl<number>;
}>
>;
}>;
dataSource: DiscountDataSource = new DiscountDataSource([]);
displayedColumns = ['name', 'discount'];
constructor(
public dialogRef: MatDialogRef<DiscountComponent>,
private fb: UntypedFormBuilder,
@Inject(MAT_DIALOG_DATA)
public data: Observable<DiscountItem[]>,
) {
this.form = this.fb.group({
discounts: '',
this.form = new FormGroup({
discounts: new FormArray<
FormGroup<{
name: FormControl<string>;
discount: FormControl<number>;
}>
>([]),
});
this.data.subscribe((list: DiscountItem[]) => {
this.list = list;
this.form.setControl(
'discounts',
this.fb.array(
this.list.map((x) =>
this.fb.group({
name: [x.name],
discount: [
'' + (x.discount !== 0 ? x.discount * 100 : ''),
[Validators.min(0), Validators.max(x.discountLimit * 100)],
],
this.form.controls.discounts.clear();
this.list.forEach((x) =>
this.form.controls.discounts.push(
new FormGroup({
name: new FormControl(x.name, { nonNullable: true }),
discount: new FormControl(x.discount * 100, {
validators: [Validators.min(0), Validators.max(x.discountLimit * 100)],
nonNullable: true,
}),
),
}),
),
);
this.dataSource = new DiscountDataSource(this.list);
),
(this.dataSource = new DiscountDataSource(this.list));
});
}
accept(): void {
const array = this.form.get('discounts') as UntypedFormArray;
const array = this.form.controls.discounts;
for (let i = this.list.length - 1; i >= 0; i--) {
const item = this.list[i];
const control = (array.controls[i] as UntypedFormGroup).controls[
'discount'
] as UntypedFormControl;
if (
control.value === null ||
control.value === '' ||
(control.pristine && control.value === '0')
) {
const control = array.controls[i].controls.discount;
if (control.pristine && control.value === 0) {
this.list.splice(i, 1);
} else {
item.discount = Math.max(Math.min(round(control.value / 100, 5), item.discountLimit), 0);