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,5 +1,5 @@
|
||||
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';
|
||||
|
||||
@ -17,7 +17,17 @@ import { ProductService } from '../product.service';
|
||||
})
|
||||
export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('name', { static: true }) nameElement?: ElementRef;
|
||||
form: UntypedFormGroup;
|
||||
form: FormGroup<{
|
||||
name: FormControl<string>;
|
||||
units: FormControl<string>;
|
||||
menuCategory: FormControl<string>;
|
||||
saleCategory: FormControl<string>;
|
||||
price: FormControl<number>;
|
||||
hasHappyHour: FormControl<boolean>;
|
||||
isNotAvailable: FormControl<boolean>;
|
||||
quantity: FormControl<number>;
|
||||
}>;
|
||||
|
||||
menuCategories: MenuCategory[] = [];
|
||||
saleCategories: SaleCategory[] = [];
|
||||
item: Product = new Product();
|
||||
@ -26,20 +36,19 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private fb: UntypedFormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: ProductService,
|
||||
) {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
units: '',
|
||||
menuCategory: '',
|
||||
saleCategory: '',
|
||||
price: '',
|
||||
hasHappyHour: '',
|
||||
isNotAvailable: '',
|
||||
quantity: '',
|
||||
this.form = new FormGroup({
|
||||
name: new FormControl<string>('', { nonNullable: true }),
|
||||
units: new FormControl<string>('', { nonNullable: true }),
|
||||
menuCategory: new FormControl<string>('', { nonNullable: true }),
|
||||
saleCategory: new FormControl<string>('', { nonNullable: true }),
|
||||
price: new FormControl<number>(0, { nonNullable: true }),
|
||||
hasHappyHour: new FormControl<boolean>(false, { nonNullable: true }),
|
||||
isNotAvailable: new FormControl<boolean>(false, { nonNullable: true }),
|
||||
quantity: new FormControl<number>(0, { nonNullable: true }),
|
||||
});
|
||||
}
|
||||
|
||||
@ -59,14 +68,14 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
showItem(item: Product) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
name: this.item.name || '',
|
||||
units: this.item.units || '',
|
||||
menuCategory: this.item.menuCategory ? this.item.menuCategory.id : '',
|
||||
saleCategory: this.item.saleCategory ? this.item.saleCategory.id : '',
|
||||
price: this.item.price || '',
|
||||
name: this.item.name ?? '',
|
||||
units: this.item.units ?? '',
|
||||
menuCategory: this.item.menuCategory?.id ?? '',
|
||||
saleCategory: this.item.saleCategory?.id ?? '',
|
||||
price: this.item.price ?? 0,
|
||||
hasHappyHour: this.item.hasHappyHour,
|
||||
isNotAvailable: this.item.isNotAvailable,
|
||||
quantity: this.item.quantity || '',
|
||||
quantity: this.item.quantity ?? 0,
|
||||
});
|
||||
}
|
||||
|
||||
@ -117,8 +126,8 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
getItem(): Product {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
this.item.units = formModel.units;
|
||||
this.item.name = formModel.name ?? '';
|
||||
this.item.units = formModel.units ?? '';
|
||||
if (this.item.menuCategory === null || this.item.menuCategory === undefined) {
|
||||
this.item.menuCategory = new MenuCategory();
|
||||
}
|
||||
@ -127,10 +136,10 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
this.item.saleCategory = new SaleCategory();
|
||||
}
|
||||
this.item.saleCategory.id = formModel.saleCategory;
|
||||
this.item.price = +formModel.price;
|
||||
this.item.hasHappyHour = formModel.hasHappyHour;
|
||||
this.item.isNotAvailable = formModel.isNotAvailable;
|
||||
this.item.quantity = +formModel.quantity;
|
||||
this.item.price = formModel.price ?? 0;
|
||||
this.item.hasHappyHour = formModel.hasHappyHour ?? false;
|
||||
this.item.isNotAvailable = formModel.isNotAvailable ?? false;
|
||||
this.item.quantity = formModel.quantity ?? 0;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
|
||||
import { FormControl, FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { Observable } from 'rxjs';
|
||||
import { debounceTime, distinctUntilChanged, startWith } from 'rxjs/operators';
|
||||
import { debounceTime, distinctUntilChanged } from 'rxjs/operators';
|
||||
|
||||
import { MenuCategory } from '../../core/menu-category';
|
||||
import { Product } from '../../core/product';
|
||||
@ -29,7 +29,11 @@ export class ProductListComponent implements OnInit {
|
||||
this.data,
|
||||
);
|
||||
|
||||
form: UntypedFormGroup;
|
||||
form: FormGroup<{
|
||||
menuCategory: FormControl<string | null>;
|
||||
filter: FormControl<string>;
|
||||
}>;
|
||||
|
||||
list: Product[] = [];
|
||||
menuCategories: MenuCategory[] = [];
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
@ -44,20 +48,18 @@ export class ProductListComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private fb: UntypedFormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private toCsv: ToCsvService,
|
||||
private ser: ProductService,
|
||||
) {
|
||||
this.form = this.fb.group({
|
||||
menuCategory: '',
|
||||
filter: '',
|
||||
this.form = new FormGroup({
|
||||
menuCategory: new FormControl<string | null>(''),
|
||||
filter: new FormControl<string>('', { nonNullable: true }),
|
||||
});
|
||||
this.data.subscribe((data: Product[]) => {
|
||||
this.list = data;
|
||||
});
|
||||
this.searchFilter = (this.form.get('filter') as UntypedFormControl).valueChanges.pipe(
|
||||
startWith(''),
|
||||
this.searchFilter = this.form.controls.filter.valueChanges.pipe(
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user