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';
|
||||
import * as moment from 'moment';
|
||||
@ -18,7 +18,20 @@ import { TemporalProductService } from '../temporal-product.service';
|
||||
})
|
||||
export class TemporalProductDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('name', { static: true }) nameElement?: ElementRef;
|
||||
form: UntypedFormGroup;
|
||||
form: FormGroup<{
|
||||
id: FormControl<string>;
|
||||
name: FormControl<string>;
|
||||
units: FormControl<string>;
|
||||
menuCategory: FormControl<string>;
|
||||
saleCategory: FormControl<string>;
|
||||
price: FormControl<number>;
|
||||
hasHappyHour: FormControl<boolean>;
|
||||
isNotAvailable: FormControl<boolean>;
|
||||
quantity: FormControl<number>;
|
||||
validFrom: FormControl<Date | null>;
|
||||
validTill: FormControl<Date | null>;
|
||||
}>;
|
||||
|
||||
menuCategories: MenuCategory[] = [];
|
||||
saleCategories: SaleCategory[] = [];
|
||||
item: Product = new Product();
|
||||
@ -27,23 +40,22 @@ export class TemporalProductDetailComponent implements OnInit, AfterViewInit {
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private fb: UntypedFormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: TemporalProductService,
|
||||
) {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
id: '',
|
||||
name: '',
|
||||
units: '',
|
||||
menuCategory: '',
|
||||
saleCategory: '',
|
||||
price: '',
|
||||
hasHappyHour: '',
|
||||
isNotAvailable: '',
|
||||
quantity: '',
|
||||
validFrom: '',
|
||||
validTill: '',
|
||||
this.form = new FormGroup({
|
||||
id: new FormControl<string>('', { nonNullable: true }),
|
||||
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 }),
|
||||
validFrom: new FormControl(new Date()),
|
||||
validTill: new FormControl(new Date()),
|
||||
});
|
||||
}
|
||||
|
||||
@ -63,19 +75,19 @@ export class TemporalProductDetailComponent implements OnInit, AfterViewInit {
|
||||
showItem(item: Product) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
id: this.item.id,
|
||||
id: this.item.id ?? '',
|
||||
name: this.item.name,
|
||||
units: this.item.units,
|
||||
menuCategory: this.item.menuCategory?.id,
|
||||
saleCategory: this.item.saleCategory?.id,
|
||||
menuCategory: this.item.menuCategory?.id ?? '',
|
||||
saleCategory: this.item.saleCategory?.id ?? '',
|
||||
price: this.item.price,
|
||||
hasHappyHour: this.item.hasHappyHour,
|
||||
isNotAvailable: this.item.isNotAvailable,
|
||||
quantity: this.item.quantity,
|
||||
validFrom:
|
||||
this.item.validFrom === null ? '' : moment(this.item.validFrom, 'DD-MMM-YYYY').toDate(),
|
||||
this.item.validFrom === null ? null : moment(this.item.validFrom, 'DD-MMM-YYYY').toDate(),
|
||||
validTill:
|
||||
this.item.validTill === null ? '' : moment(this.item.validTill, 'DD-MMM-YYYY').toDate(),
|
||||
this.item.validTill === null ? null : moment(this.item.validTill, 'DD-MMM-YYYY').toDate(),
|
||||
});
|
||||
}
|
||||
|
||||
@ -127,8 +139,8 @@ export class TemporalProductDetailComponent implements OnInit, AfterViewInit {
|
||||
getItem(): Product {
|
||||
const formModel = this.form.value;
|
||||
this.item.id = formModel.id;
|
||||
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();
|
||||
}
|
||||
@ -137,10 +149,10 @@ export class TemporalProductDetailComponent 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;
|
||||
this.item.validFrom = !formModel.validFrom
|
||||
? null
|
||||
: moment(formModel.validFrom).format('DD-MMM-YYYY');
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
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';
|
||||
@ -28,7 +28,12 @@ export class TemporalProductListComponent implements OnInit {
|
||||
this.data,
|
||||
);
|
||||
|
||||
form: UntypedFormGroup;
|
||||
form: FormGroup<{
|
||||
filter: FormControl<string>;
|
||||
menuCategory: FormControl<string | null>;
|
||||
saleCategory: FormControl<string | null>;
|
||||
}>;
|
||||
|
||||
list: Product[][] = [];
|
||||
menuCategories: MenuCategory[] = [];
|
||||
saleCategories: SaleCategory[] = [];
|
||||
@ -42,17 +47,16 @@ export class TemporalProductListComponent implements OnInit {
|
||||
'quantity',
|
||||
];
|
||||
|
||||
constructor(private route: ActivatedRoute, private fb: UntypedFormBuilder) {
|
||||
this.form = this.fb.group({
|
||||
filter: '',
|
||||
menuCategory: '',
|
||||
saleCategory: '',
|
||||
constructor(private route: ActivatedRoute) {
|
||||
this.form = new FormGroup({
|
||||
filter: new FormControl<string>('', { nonNullable: true }),
|
||||
menuCategory: new FormControl<string | null>(''),
|
||||
saleCategory: new FormControl<string | null>(''),
|
||||
});
|
||||
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