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,10 +1,5 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import {
|
||||
AbstractControl,
|
||||
UntypedFormArray,
|
||||
UntypedFormBuilder,
|
||||
UntypedFormGroup,
|
||||
} from '@angular/forms';
|
||||
import { FormArray, FormControl, FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { map } from 'rxjs/operators';
|
||||
@ -25,7 +20,16 @@ import { UpdateProductPricesService } from './update-product-prices.service';
|
||||
export class UpdateProductPricesComponent implements OnInit {
|
||||
info: UpdateProductPrices = new UpdateProductPrices();
|
||||
dataSource: UpdateProductPricesDataSource = new UpdateProductPricesDataSource(this.info.items);
|
||||
form: UntypedFormGroup;
|
||||
form: FormGroup<{
|
||||
date: FormControl<Date>;
|
||||
menuCategory: FormControl<string>;
|
||||
prices: FormArray<
|
||||
FormGroup<{
|
||||
newPrice: FormControl<number | null>;
|
||||
}>
|
||||
>;
|
||||
}>;
|
||||
|
||||
menuCategories: MenuCategory[] = [];
|
||||
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
@ -34,16 +38,19 @@ export class UpdateProductPricesComponent implements OnInit {
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: UntypedFormBuilder,
|
||||
private toCsv: ToCsvService,
|
||||
private toaster: ToasterService,
|
||||
private ser: UpdateProductPricesService,
|
||||
) {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
date: '',
|
||||
menuCategory: '',
|
||||
prices: this.fb.array([]),
|
||||
this.form = new FormGroup({
|
||||
date: new FormControl(new Date(), { nonNullable: true }),
|
||||
menuCategory: new FormControl('', { nonNullable: true }),
|
||||
prices: new FormArray<
|
||||
FormGroup<{
|
||||
newPrice: FormControl<number | null>;
|
||||
}>
|
||||
>([]),
|
||||
});
|
||||
}
|
||||
|
||||
@ -66,23 +73,20 @@ export class UpdateProductPricesComponent implements OnInit {
|
||||
|
||||
loadData(info: UpdateProductPrices) {
|
||||
this.info = info;
|
||||
(this.form.get('date') as AbstractControl).setValue(
|
||||
moment(this.info.date, 'DD-MMM-YYYY').toDate(),
|
||||
);
|
||||
(this.form.get('menuCategory') as AbstractControl).setValue(
|
||||
this.form.controls.date.setValue(moment(this.info.date, 'DD-MMM-YYYY').toDate());
|
||||
this.form.controls.menuCategory.setValue(
|
||||
this.info.menuCategoryId !== undefined ? this.info.menuCategoryId : '',
|
||||
);
|
||||
this.form.setControl(
|
||||
'prices',
|
||||
this.fb.array(
|
||||
this.info.items.map((x) =>
|
||||
this.fb.group({
|
||||
newPrice: x.newPrice,
|
||||
}),
|
||||
),
|
||||
this.form.controls.prices.clear();
|
||||
|
||||
this.info.items.forEach((x) =>
|
||||
this.form.controls.prices.push(
|
||||
new FormGroup({
|
||||
newPrice: new FormControl<number | null>(x.newPrice),
|
||||
}),
|
||||
),
|
||||
);
|
||||
this.dataSource = new UpdateProductPricesDataSource(this.info.items);
|
||||
),
|
||||
(this.dataSource = new UpdateProductPricesDataSource(this.info.items));
|
||||
}
|
||||
|
||||
show() {
|
||||
@ -100,9 +104,9 @@ export class UpdateProductPricesComponent implements OnInit {
|
||||
|
||||
getInfo(): UpdateProductPrices {
|
||||
const formModel = this.form.value;
|
||||
const array = this.form.get('prices') as UntypedFormArray;
|
||||
const array = this.form.controls.prices;
|
||||
this.info.items.forEach((item, index) => {
|
||||
item.newPrice = array.controls[index].value.newPrice;
|
||||
item.newPrice = array.controls[index].value.newPrice ?? null;
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user