Switched on the @typescript-eslint/no-non-null-assertion rule in eslint.

Fixed the errors it threw up.
This commit is contained in:
Amritanshu Agrawal 2022-07-17 09:17:20 +05:30
parent c76696e022
commit 9f70ec2917
29 changed files with 144 additions and 111 deletions

@ -16,7 +16,8 @@
}, },
"extends": [ "extends": [
"plugin:@angular-eslint/recommended", "plugin:@angular-eslint/recommended",
"plugin:@angular-eslint/template/process-inline-templates" "plugin:@angular-eslint/template/process-inline-templates",
"plugin:@angular-eslint/recommended--extra"
], ],
"plugins": [ "plugins": [
"import", "import",

@ -69,7 +69,7 @@ export class AccountDetailComponent implements OnInit, AfterViewInit {
type: this.item.type, type: this.item.type,
isActive: this.item.isActive, isActive: this.item.isActive,
isReconcilable: this.item.isReconcilable, isReconcilable: this.item.isReconcilable,
costCentre: this.item.costCentre.id!, costCentre: this.item.costCentre.id ?? '',
}); });
} }
@ -120,11 +120,11 @@ export class AccountDetailComponent implements OnInit, AfterViewInit {
getItem(): Account { getItem(): Account {
const formModel = this.form.value; const formModel = this.form.value;
this.item.name = formModel.name!; this.item.name = formModel.name ?? '';
this.item.type = formModel.type!; this.item.type = formModel.type ?? 0;
this.item.isActive = formModel.isActive!; this.item.isActive = formModel.isActive ?? true;
this.item.isReconcilable = formModel.isReconcilable!; this.item.isReconcilable = formModel.isReconcilable ?? false;
this.item.costCentre.id = formModel.costCentre!; this.item.costCentre.id = formModel.costCentre ?? '';
return this.item; return this.item;
} }
} }

@ -50,7 +50,7 @@ export class AccountListComponent implements OnInit, AfterViewInit {
const data = value as { list: Account[]; accountTypes: AccountType[] }; const data = value as { list: Account[]; accountTypes: AccountType[] };
this.accountTypes = data.accountTypes; this.accountTypes = data.accountTypes;
data.list.forEach( data.list.forEach(
(x) => (x.typeName = this.accountTypes.find((y) => y.id === x.type)?.name!), (x) => (x.typeName = this.accountTypes.find((y) => y.id === x.type)?.name ?? ''),
); );
this.list = data.list; this.list = data.list;
}); });

@ -96,10 +96,12 @@ export class AttendanceComponent implements OnInit {
getAttendance(): Attendance { getAttendance(): Attendance {
const formModel = this.form.value; const formModel = this.form.value;
this.info.date = moment(formModel.date).format('DD-MMM-YYYY'); this.info.date = moment(formModel.date).format('DD-MMM-YYYY');
const array = this.form.controls.attendances!; const array = this.form.controls.attendances;
this.info.body.forEach((item, index) => { if (array) {
item.attendanceType.id = array.controls[index].value.attendanceType!; this.info.body.forEach((item, index) => {
}); item.attendanceType.id = array.controls[index].value.attendanceType ?? 0;
});
}
return this.info; return this.info;
} }
} }

@ -107,8 +107,8 @@ export class ClientDetailComponent implements OnInit, AfterViewInit {
getItem(): Client { getItem(): Client {
const formModel = this.form.value; const formModel = this.form.value;
this.item.name = formModel.name!; this.item.name = formModel.name ?? '';
this.item.enabled = formModel.enabled!; this.item.enabled = formModel.enabled ?? false;
this.item.otp = formModel.otp || undefined; this.item.otp = formModel.otp || undefined;
return this.item; return this.item;
} }

@ -118,7 +118,7 @@ export class ClosingStockComponent implements OnInit {
this.info.date = moment(formModel.date).format('DD-MMM-YYYY'); this.info.date = moment(formModel.date).format('DD-MMM-YYYY');
const array = this.form.controls.stocks; const array = this.form.controls.stocks;
this.info.items.forEach((item, index) => { this.info.items.forEach((item, index) => {
item.physical = +array.controls[index].value.physical!; item.physical = +(array.controls[index].value.physical ?? '');
item.costCentre = item.costCentre =
array.controls[index].value.costCentre == null array.controls[index].value.costCentre == null
? undefined ? undefined
@ -132,7 +132,7 @@ export class ClosingStockComponent implements OnInit {
return new ClosingStock({ return new ClosingStock({
date: moment(formModel.date).format('DD-MMM-YYYY'), date: moment(formModel.date).format('DD-MMM-YYYY'),
costCentre: new CostCentre({ id: formModel.costCentre! }), costCentre: new CostCentre({ id: formModel.costCentre ?? '' }),
}); });
} }

@ -67,7 +67,7 @@ export class CostCentreDetailComponent implements OnInit, AfterViewInit {
getItem(): CostCentre { getItem(): CostCentre {
const formModel = this.form.value; const formModel = this.form.value;
this.item.name = formModel.name!; this.item.name = formModel.name ?? '';
return this.item; return this.item;
} }
} }

@ -145,10 +145,12 @@ export class EmployeeAttendanceComponent implements OnInit, AfterViewInit {
const formValue = this.form.value; const formValue = this.form.value;
this.info.startDate = moment(formValue.startDate).format('DD-MMM-YYYY'); this.info.startDate = moment(formValue.startDate).format('DD-MMM-YYYY');
this.info.finishDate = moment(formValue.finishDate).format('DD-MMM-YYYY'); this.info.finishDate = moment(formValue.finishDate).format('DD-MMM-YYYY');
const array = this.form.value.attendances!; const array = this.form.value.attendances;
this.info.body.forEach((item, index) => { if (array) {
item.attendanceType.id = array[index].attendanceType!; this.info.body.forEach((item, index) => {
}); item.attendanceType.id = array[index].attendanceType ?? 0;
});
}
return this.info; return this.info;
} }
} }

@ -151,10 +151,13 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
return; return;
} }
const formValue = this.form.value.addRow!; const formValue = this.form.value.addRow;
const grossSalary = +formValue.grossSalary!; if (formValue === undefined) {
const daysWorked = +formValue.daysWorked!; return;
const date = this.form.value.date!; }
const grossSalary = +(formValue.grossSalary ?? '0');
const daysWorked = +(formValue.daysWorked ?? '0');
const date = this.form.value.date ?? new Date();
const daysInMonth = moment(date).daysInMonth(); const daysInMonth = moment(date).daysInMonth();
const esi = EmployeeBenefitsComponent.getEsi(grossSalary, daysWorked, daysInMonth); const esi = EmployeeBenefitsComponent.getEsi(grossSalary, daysWorked, daysInMonth);
const pf = EmployeeBenefitsComponent.getPf(grossSalary, daysWorked, daysInMonth); const pf = EmployeeBenefitsComponent.getPf(grossSalary, daysWorked, daysInMonth);

@ -50,14 +50,14 @@ export class EmployeeFunctionsComponent {
} }
chosenYearHandler(normalizedYear: Moment) { chosenYearHandler(normalizedYear: Moment) {
const ctrlValue = this.creditSalaryForm.value.date!; const ctrlValue = this.creditSalaryForm.value.date ?? moment();
ctrlValue.year(normalizedYear.year()); ctrlValue.year(normalizedYear.year());
ctrlValue.date(ctrlValue.daysInMonth()); ctrlValue.date(ctrlValue.daysInMonth());
this.creditSalaryForm.setValue({ date: ctrlValue }); this.creditSalaryForm.setValue({ date: ctrlValue });
} }
chosenMonthHandler(normlizedMonth: Moment, datepicker: MatDatepicker<Moment>) { chosenMonthHandler(normlizedMonth: Moment, datepicker: MatDatepicker<Moment>) {
const ctrlValue = this.creditSalaryForm.value.date!; const ctrlValue = this.creditSalaryForm.value.date ?? moment();
ctrlValue.month(normlizedMonth.month()); ctrlValue.month(normlizedMonth.month());
ctrlValue.date(ctrlValue.daysInMonth()); ctrlValue.date(ctrlValue.daysInMonth());
this.creditSalaryForm.setValue({ date: ctrlValue }); this.creditSalaryForm.setValue({ date: ctrlValue });
@ -65,7 +65,7 @@ export class EmployeeFunctionsComponent {
} }
creditSalary() { creditSalary() {
const date = this.creditSalaryForm.value.date!.format('DD-MMM-YYYY'); const date = (this.creditSalaryForm.value.date ?? moment()).format('DD-MMM-YYYY');
if (!date) { if (!date) {
this.toaster.show('Danger', 'Please choose a valid date.'); this.toaster.show('Danger', 'Please choose a valid date.');
return; return;
@ -81,8 +81,10 @@ export class EmployeeFunctionsComponent {
} }
attendanceRecordUrl() { attendanceRecordUrl() {
const startDate = this.attendanceRecordForm.value.startDate!.format('DD-MMM-YYYY'); const startDate = (this.attendanceRecordForm.value.startDate ?? moment()).format('DD-MMM-YYYY');
const finishDate = this.attendanceRecordForm.value.finishDate!.format('DD-MMM-YYYY'); const finishDate = (this.attendanceRecordForm.value.finishDate ?? moment()).format(
'DD-MMM-YYYY',
);
if (!startDate || !finishDate) { if (!startDate || !finishDate) {
// this.toaster.show('Danger', 'Please choose a start and finish date.'); // this.toaster.show('Danger', 'Please choose a start and finish date.');
return ''; return '';
@ -91,8 +93,10 @@ export class EmployeeFunctionsComponent {
} }
fingerPrintUrl() { fingerPrintUrl() {
const startDate = this.attendanceRecordForm.value.startDate!.format('DD-MMM-YYYY'); const startDate = (this.attendanceRecordForm.value.startDate ?? moment()).format('DD-MMM-YYYY');
const finishDate = this.attendanceRecordForm.value.finishDate!.format('DD-MMM-YYYY'); const finishDate = (this.attendanceRecordForm.value.finishDate ?? moment()).format(
'DD-MMM-YYYY',
);
if (!startDate || !finishDate) { if (!startDate || !finishDate) {
// this.toaster.show('Danger', 'Please choose a start and finish date.'); // this.toaster.show('Danger', 'Please choose a start and finish date.');
return ''; return '';

@ -74,7 +74,7 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit {
salary: this.item.salary || '', salary: this.item.salary || '',
points: this.item.points || '', points: this.item.points || '',
isActive: this.item.isActive, isActive: this.item.isActive,
costCentre: this.item.costCentre.id!, costCentre: this.item.costCentre.id ?? '',
joiningDate: this.item.joiningDate joiningDate: this.item.joiningDate
? moment(this.item.joiningDate, 'DD-MMM-YYYY').toDate() ? moment(this.item.joiningDate, 'DD-MMM-YYYY').toDate()
: new Date(), : new Date(),
@ -130,17 +130,17 @@ export class EmployeeDetailComponent implements OnInit, AfterViewInit {
} }
getItem(): Employee { getItem(): Employee {
const formModel = this.form.value; const formValue = this.form.value;
this.item.name = formModel.name!; this.item.name = formValue.name ?? '';
this.item.designation = formModel.designation!; this.item.designation = formValue.designation ?? '';
this.item.salary = +formModel.salary!; this.item.salary = +(formValue.salary ?? '0');
this.item.points = +formModel.points!; this.item.points = +(formValue.points ?? '0');
this.item.isActive = formModel.isActive!; this.item.isActive = formValue.isActive ?? true;
this.item.costCentre.id = formModel.costCentre!; this.item.costCentre.id = formValue.costCentre ?? '';
this.item.joiningDate = moment(formModel.joiningDate).format('DD-MMM-YYYY'); this.item.joiningDate = moment(formValue.joiningDate).format('DD-MMM-YYYY');
this.item.leavingDate = this.item.isActive this.item.leavingDate = this.item.isActive
? null ? null
: moment(formModel.leavingDate).format('DD-MMM-YYYY'); : moment(formValue.leavingDate).format('DD-MMM-YYYY');
return this.item; return this.item;
} }
} }

@ -37,7 +37,7 @@ export class EntriesComponent implements OnInit {
]; ];
posted: boolean | null = null; posted: boolean | null = null;
issue: boolean = false; issue = false;
constructor(private route: ActivatedRoute, private router: Router) { constructor(private route: ActivatedRoute, private router: Router) {
this.form = new FormGroup({ this.form = new FormGroup({
startDate: new FormControl(new Date(), { nonNullable: true }), startDate: new FormControl(new Date(), { nonNullable: true }),

@ -108,7 +108,7 @@ export class IncentiveComponent implements OnInit {
} }
change(row: Incentive, i: number) { change(row: Incentive, i: number) {
row.points = this.form.controls.incentives.controls[i].value.points!; row.points = this.form.controls.incentives.controls[i].value.points ?? 0;
this.form.controls.incentives.controls[i].setValue({ points: row.points }); this.form.controls.incentives.controls[i].setValue({ points: row.points });
} }
@ -168,7 +168,7 @@ export class IncentiveComponent implements OnInit {
const array = this.form.controls.incentives; const array = this.form.controls.incentives;
this.voucher.incentives.forEach((item, index) => { this.voucher.incentives.forEach((item, index) => {
item.points = array.controls[index].value.points!; item.points = array.controls[index].value.points ?? 0;
}); });
return this.voucher; return this.voucher;
} }

@ -147,8 +147,8 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
this.voucher = voucher; this.voucher = voucher;
this.form.setValue({ this.form.setValue({
date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(), date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(),
source: (this.voucher.source as CostCentre).id!, source: (this.voucher.source as CostCentre).id ?? '',
destination: (this.voucher.destination as CostCentre).id!, destination: (this.voucher.destination as CostCentre).id ?? '',
amount: Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)), amount: Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)),
addRow: { addRow: {
batch: '', batch: '',
@ -169,7 +169,10 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
} }
addRow() { addRow() {
const formValue = this.form.value.addRow!; const formValue = this.form.value.addRow;
if (formValue === undefined) {
return;
}
const quantity = this.math.parseAmount(formValue.quantity, 2); const quantity = this.math.parseAmount(formValue.quantity, 2);
const isConsumption = this.form.value.source === '7b845f95-dfef-fa4a-897c-f0baf15284a3'; const isConsumption = this.form.value.source === '7b845f95-dfef-fa4a-897c-f0baf15284a3';
if (this.batch === null || quantity <= 0) { if (this.batch === null || quantity <= 0) {
@ -288,9 +291,9 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
getVoucher(): Voucher { getVoucher(): Voucher {
const formModel = this.form.value; const formModel = this.form.value;
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY');
(this.voucher.source as CostCentre).id = formModel.source!; (this.voucher.source as CostCentre).id = formModel.source ?? '';
(this.voucher.destination as CostCentre).id = formModel.destination!; (this.voucher.destination as CostCentre).id = formModel.destination ?? '';
this.voucher.narration = formModel.narration!; this.voucher.narration = formModel.narration ?? '';
return this.voucher; return this.voucher;
} }

@ -71,7 +71,7 @@ export class JournalDialogComponent implements OnInit {
accept(): void { accept(): void {
const formValue = this.form.value; const formValue = this.form.value;
const amount = this.math.journalAmount(formValue.amount, formValue.debit!); const amount = this.math.journalAmount(formValue.amount, formValue.debit ?? 1);
this.data.journal.debit = amount.debit; this.data.journal.debit = amount.debit;
this.data.journal.account = this.account; this.data.journal.account = this.account;
this.data.journal.amount = amount.amount; this.data.journal.amount = amount.amount;

@ -165,8 +165,11 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
} }
addRow() { addRow() {
const formValue = this.form.value.addRow!; const formValue = this.form.value.addRow;
const amount = this.math.journalAmount(formValue.amount!, formValue.debit!); if (formValue === undefined) {
return;
}
const amount = this.math.journalAmount(formValue.amount, formValue.debit ?? 1);
if (this.account === null || amount.amount === 0) { if (this.account === null || amount.amount === 0) {
return; return;
} }
@ -292,7 +295,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
getVoucher(): Voucher { getVoucher(): Voucher {
const formModel = this.form.value; const formModel = this.form.value;
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY');
this.voucher.narration = formModel.narration!; this.voucher.narration = formModel.narration ?? '';
return this.voucher; return this.voucher;
} }

@ -159,7 +159,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
[this.paymentJournal] = this.voucher.journals.filter((x) => x.debit === -1); [this.paymentJournal] = this.voucher.journals.filter((x) => x.debit === -1);
this.form.setValue({ this.form.setValue({
date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(), date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(),
paymentAccount: this.paymentJournal.account.id!, paymentAccount: this.paymentJournal.account.id ?? '',
paymentAmount: this.paymentJournal.amount, paymentAmount: this.paymentJournal.amount,
addRow: { addRow: {
account: '', account: '',
@ -180,7 +180,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
} }
addRow() { addRow() {
const amount = this.math.parseAmount(this.form.value.addRow?.amount!, 2); const amount = this.math.parseAmount(this.form.value.addRow?.amount ?? '0', 2);
const debit = 1; const debit = 1;
if (this.account === null || amount <= 0) { if (this.account === null || amount <= 0) {
return; return;
@ -305,7 +305,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
const formModel = this.form.value; const formModel = this.form.value;
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY');
this.paymentJournal.account.id = formModel.paymentAccount; this.paymentJournal.account.id = formModel.paymentAccount;
this.voucher.narration = formModel.narration!; this.voucher.narration = formModel.narration ?? '';
return this.voucher; return this.voucher;
} }

@ -67,7 +67,7 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
getItem(): ProductGroup { getItem(): ProductGroup {
const formModel = this.form.value; const formModel = this.form.value;
this.item.name = formModel.name!; this.item.name = formModel.name ?? '';
return this.item; return this.item;
} }
} }

@ -44,23 +44,23 @@ export class ProductDetailDialogComponent implements OnInit {
accept(): void { accept(): void {
const formValue = this.form.value; const formValue = this.form.value;
const fraction = formValue.fraction!; const fraction = formValue.fraction ?? 0;
if (fraction < 1) { if (fraction < 1) {
return; return;
} }
const productYield = formValue.productYield!; const productYield = formValue.productYield ?? 0;
if (productYield < 0 || productYield > 1) { if (productYield < 0 || productYield > 1) {
return; return;
} }
const costPrice = formValue.costPrice!; const costPrice = formValue.costPrice ?? 0;
if (costPrice < 0) { if (costPrice < 0) {
return; return;
} }
const salePrice = formValue.salePrice!; const salePrice = formValue.salePrice ?? 0;
if (salePrice < 0) { if (salePrice < 0) {
return; return;
} }
this.data.item.units = formValue.units!; this.data.item.units = formValue.units ?? '';
this.data.item.fraction = fraction; this.data.item.fraction = fraction;
this.data.item.productYield = productYield; this.data.item.productYield = productYield;
this.data.item.costPrice = costPrice; this.data.item.costPrice = costPrice;

@ -85,7 +85,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
this.form.setValue({ this.form.setValue({
code: this.item.code || '(Auto)', code: this.item.code || '(Auto)',
name: this.item.name, name: this.item.name,
fractionUnits: this.item.fractionUnits!, fractionUnits: this.item.fractionUnits ?? '',
addRow: { addRow: {
units: '', units: '',
fraction: '', fraction: '',
@ -96,7 +96,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
isPurchased: this.item.isPurchased, isPurchased: this.item.isPurchased,
isSold: this.item.isSold, isSold: this.item.isSold,
isActive: this.item.isActive, isActive: this.item.isActive,
productGroup: this.item.productGroup ? this.item.productGroup.id! : '', productGroup: this.item.productGroup ? this.item.productGroup.id ?? '' : '',
}); });
} }
@ -109,30 +109,33 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
} }
addRow() { addRow() {
const formValue = this.form.value.addRow!; const formValue = this.form.value.addRow;
const fraction = +formValue.fraction!; if (formValue === undefined) {
return;
}
const fraction = +(formValue.fraction ?? '0');
if (fraction < 1) { if (fraction < 1) {
this.toaster.show('Danger', 'Fraction has to be >= 1'); this.toaster.show('Danger', 'Fraction has to be >= 1');
return; return;
} }
const productYield = +formValue.productYield!; const productYield = +(formValue.productYield ?? '0');
if (productYield < 0 || productYield > 1) { if (productYield < 0 || productYield > 1) {
this.toaster.show('Danger', 'Product Yield has to be > 0 and <= 1'); this.toaster.show('Danger', 'Product Yield has to be > 0 and <= 1');
return; return;
} }
const costPrice = +formValue.costPrice!; const costPrice = +(formValue.costPrice ?? '0');
if (costPrice < 0) { if (costPrice < 0) {
this.toaster.show('Danger', 'Price has to be >= 0'); this.toaster.show('Danger', 'Price has to be >= 0');
return; return;
} }
const salePrice = +formValue.salePrice!; const salePrice = +(formValue.salePrice ?? '0');
if (salePrice < 0) { if (salePrice < 0) {
this.toaster.show('Danger', 'Sale Price has to be >= 0'); this.toaster.show('Danger', 'Sale Price has to be >= 0');
return; return;
} }
this.item.skus.push( this.item.skus.push(
new StockKeepingUnit({ new StockKeepingUnit({
units: formValue.units!, units: formValue.units ?? '',
fraction, fraction,
productYield, productYield,
costPrice, costPrice,
@ -212,15 +215,15 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
getItem(): Product { getItem(): Product {
const formModel = this.form.value; const formModel = this.form.value;
this.item.name = formModel.name!; this.item.name = formModel.name ?? '';
this.item.fractionUnits = formModel.fractionUnits!; this.item.fractionUnits = formModel.fractionUnits ?? '';
this.item.isPurchased = formModel.isPurchased!; this.item.isPurchased = formModel.isPurchased ?? true;
this.item.isSold = formModel.isSold!; this.item.isSold = formModel.isSold ?? false;
this.item.isActive = formModel.isActive!; this.item.isActive = formModel.isActive ?? true;
if (this.item.productGroup === null || this.item.productGroup === undefined) { if (this.item.productGroup === null || this.item.productGroup === undefined) {
this.item.productGroup = new ProductGroup(); this.item.productGroup = new ProductGroup();
} }
this.item.productGroup.id = formModel.productGroup!; this.item.productGroup.id = formModel.productGroup ?? '';
return this.item; return this.item;
} }
} }

@ -182,7 +182,10 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
} }
addRow() { addRow() {
const formValue = this.form.value.addRow!; const formValue = this.form.value.addRow;
if (formValue === undefined) {
return;
}
const quantity = this.math.parseAmount(formValue.quantity, 2); const quantity = this.math.parseAmount(formValue.quantity, 2);
if (this.batch === null || quantity <= 0 || this.batch.quantityRemaining < quantity) { if (this.batch === null || quantity <= 0 || this.batch.quantityRemaining < quantity) {
return; return;
@ -301,7 +304,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
if (formModel.account !== null && typeof formModel.account !== 'string') { if (formModel.account !== null && typeof formModel.account !== 'string') {
this.voucher.vendor = formModel.account; this.voucher.vendor = formModel.account;
} }
this.voucher.narration = formModel.narration!; this.voucher.narration = formModel.narration ?? '';
return this.voucher; return this.voucher;
} }

@ -201,7 +201,10 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
} }
addRow() { addRow() {
const formValue = this.form.value.addRow!; const formValue = this.form.value.addRow;
if (formValue === undefined) {
return;
}
const quantity = this.math.parseAmount(formValue.quantity, 2); const quantity = this.math.parseAmount(formValue.quantity, 2);
if (this.product === null || quantity <= 0) { if (this.product === null || quantity <= 0) {
return; return;
@ -332,7 +335,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
if (formModel.account !== null && typeof formModel.account !== 'string') { if (formModel.account !== null && typeof formModel.account !== 'string') {
this.voucher.vendor = formModel.account; this.voucher.vendor = formModel.account;
} }
this.voucher.narration = formModel.narration!; this.voucher.narration = formModel.narration ?? '';
return this.voucher; return this.voucher;
} }

@ -122,7 +122,10 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
} }
addRow() { addRow() {
const formValue = this.form.value.addRow!; const formValue = this.form.value.addRow;
if (formValue === undefined) {
return;
}
const price = this.math.parseAmount(formValue.price, 2); const price = this.math.parseAmount(formValue.price, 2);
if (this.product === null || price <= 0) { if (this.product === null || price <= 0) {
return; return;
@ -215,10 +218,10 @@ export class RateContractDetailComponent implements OnInit, AfterViewInit {
this.item.date = moment(formModel.date).format('DD-MMM-YYYY'); this.item.date = moment(formModel.date).format('DD-MMM-YYYY');
this.item.validFrom = moment(formModel.validFrom).format('DD-MMM-YYYY'); this.item.validFrom = moment(formModel.validFrom).format('DD-MMM-YYYY');
this.item.validTill = moment(formModel.validTill).format('DD-MMM-YYYY'); this.item.validTill = moment(formModel.validTill).format('DD-MMM-YYYY');
if (formModel.account !== null && typeof formModel.account !== 'string') { if (formModel.account && typeof formModel.account !== 'string') {
this.item.vendor = formModel.account!; this.item.vendor = formModel.account;
} }
this.item.narration = formModel.narration!; this.item.narration = formModel.narration ?? '';
return this.item; return this.item;
} }
} }

@ -158,7 +158,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
[this.receiptJournal] = this.voucher.journals.filter((x) => x.debit === 1); [this.receiptJournal] = this.voucher.journals.filter((x) => x.debit === 1);
this.form.setValue({ this.form.setValue({
date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(), date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(),
receiptAccount: this.receiptJournal.account.id!, receiptAccount: this.receiptJournal.account.id ?? '',
receiptAmount: this.receiptJournal.amount, receiptAmount: this.receiptJournal.amount,
addRow: { addRow: {
account: '', account: '',
@ -179,7 +179,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
} }
addRow() { addRow() {
const amount = this.math.parseAmount(this.form.value.addRow?.amount!, 2); const amount = this.math.parseAmount(this.form.value.addRow?.amount ?? '0', 2);
const debit = -1; const debit = -1;
if (this.account === null || amount <= 0) { if (this.account === null || amount <= 0) {
return; return;
@ -304,7 +304,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
const formModel = this.form.value; const formModel = this.form.value;
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY'); this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY');
this.receiptJournal.account.id = formModel.receiptAccount; this.receiptJournal.account.id = formModel.receiptAccount;
this.voucher.narration = formModel.narration!; this.voucher.narration = formModel.narration ?? '';
return this.voucher; return this.voucher;
} }

@ -157,7 +157,10 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
} }
addRow() { addRow() {
const formValue = this.form.value.addRow!; const formValue = this.form.value.addRow;
if (formValue === undefined) {
return;
}
const quantity = this.math.parseAmount(formValue.quantity, 2); const quantity = this.math.parseAmount(formValue.quantity, 2);
const rate = this.math.parseAmount(formValue.rate, 2); const rate = this.math.parseAmount(formValue.rate, 2);
if (this.ingredient === null || quantity <= 0 || rate <= 0) { if (this.ingredient === null || quantity <= 0 || rate <= 0) {
@ -198,7 +201,7 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
2, 2,
); );
this.form.controls.costPrice.setValue(`${costPrice}`); this.form.controls.costPrice.setValue(`${costPrice}`);
const salePrice = this.math.parseAmount(this.form.value.salePrice!, 2); const salePrice = this.math.parseAmount(this.form.value.salePrice ?? '0', 2);
if (salePrice < 0) { if (salePrice < 0) {
return; return;
} }
@ -252,9 +255,9 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
const formModel = this.form.value; const formModel = this.form.value;
this.item.validFrom = moment(formModel.validFrom).format('DD-MMM-YYYY'); this.item.validFrom = moment(formModel.validFrom).format('DD-MMM-YYYY');
this.item.validTill = moment(formModel.validTill).format('DD-MMM-YYYY'); this.item.validTill = moment(formModel.validTill).format('DD-MMM-YYYY');
this.item.recipeYield = this.math.parseAmount(formModel.recipeYield!, 2); this.item.recipeYield = this.math.parseAmount(formModel.recipeYield ?? '1', 2);
this.item.salePrice = this.math.parseAmount(formModel.salePrice!, 2); this.item.salePrice = this.math.parseAmount(formModel.salePrice ?? '0', 2);
this.item.costPrice = this.math.parseAmount(formModel.costPrice!, 2); this.item.costPrice = this.math.parseAmount(formModel.costPrice ?? '0', 2);
return this.item; return this.item;
} }
} }

@ -58,7 +58,7 @@ export class RecipeService {
startDate: string | null, startDate: string | null,
finishDate: string | null, finishDate: string | null,
): Observable<ProductSku> { ): Observable<ProductSku> {
const getUrl: string = `${url}/ingredient-details/${id}`; const getUrl = `${url}/ingredient-details/${id}`;
const options = { const options = {
params: new HttpParams(), params: new HttpParams(),
}; };

@ -103,10 +103,10 @@ export class RoleDetailComponent implements OnInit, AfterViewInit {
getItem(): Role { getItem(): Role {
const formModel = this.form.value; const formModel = this.form.value;
this.item.name = formModel.name!; this.item.name = formModel.name ?? '';
const array = this.form.controls.permissions; const array = this.form.controls.permissions;
this.item.permissions.forEach((item, index) => { this.item.permissions.forEach((item, index) => {
item.enabled = array.controls[index].value.permission!; item.enabled = array.controls[index].value.permission ?? false;
}); });
return this.item; return this.item;
} }

@ -44,10 +44,10 @@ export class SettingsComponent implements OnInit {
}>; }>;
lockInformation: LockInfo[]; lockInformation: LockInfo[];
lockOlder: boolean = false; lockOlder = false;
olderRolling: boolean = false; olderRolling = false;
lockNewer: boolean = false; lockNewer = false;
newerRolling: boolean = false; newerRolling = false;
rebaseDataForm: FormGroup<{ rebaseDataForm: FormGroup<{
date: FormControl<moment.Moment>; date: FormControl<moment.Moment>;
@ -149,15 +149,15 @@ export class SettingsComponent implements OnInit {
saveLock() { saveLock() {
const item = new LockInfo(); const item = new LockInfo();
if (this.lockOlder && this.olderRolling) { if (this.lockOlder && this.olderRolling) {
item.start.days = +this.lockInfoForm.value.olderDays!; item.start.days = this.lockInfoForm.value.olderDays ?? 0;
} else if (this.lockOlder && !this.olderRolling) { } else if (this.lockOlder && !this.olderRolling) {
item.start.date = this.lockInfoForm.value.olderDate!.format('DD-MMM-YYYY'); item.start.date = (this.lockInfoForm.value.olderDate ?? moment()).format('DD-MMM-YYYY');
} }
if (this.lockNewer && this.newerRolling) { if (this.lockNewer && this.newerRolling) {
item.finish.days = +this.lockInfoForm.value.newerDays!; item.finish.days = this.lockInfoForm.value.newerDays ?? 0;
} }
if (this.lockNewer && !this.newerRolling) { if (this.lockNewer && !this.newerRolling) {
item.finish.date = this.lockInfoForm.value.newerDate!.format('DD-MMM-YYYY'); item.finish.date = (this.lockInfoForm.value.newerDate ?? moment()).format('DD-MMM-YYYY');
} }
const atArray = this.lockInfoForm.controls.accountTypes; const atArray = this.lockInfoForm.controls.accountTypes;
this.accountTypes.forEach((at, index) => { this.accountTypes.forEach((at, index) => {
@ -182,7 +182,7 @@ export class SettingsComponent implements OnInit {
if (validTill) { if (validTill) {
item.validTill = moment(validTill).format('DD-MMM-YYYY'); item.validTill = moment(validTill).format('DD-MMM-YYYY');
} }
item.index = +this.lockInfoForm.value.index!; item.index = this.lockInfoForm.value.index ?? 0;
this.ser.setLockInformation(item).subscribe( this.ser.setLockInformation(item).subscribe(
(result) => { (result) => {
@ -202,7 +202,7 @@ export class SettingsComponent implements OnInit {
} }
confirmRebase(): void { confirmRebase(): void {
const rebaseDate = this.rebaseDataForm.value.date!.format('DD-MMM-YYYY'); const rebaseDate = (this.rebaseDataForm.value.date ?? moment()).format('DD-MMM-YYYY');
const dialogRef = this.dialog.open(ConfirmDialogComponent, { const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px', width: '250px',
data: { data: {

@ -126,12 +126,12 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
getItem(): User { getItem(): User {
const formModel = this.form.value; const formModel = this.form.value;
this.item.name = formModel.name!; this.item.name = formModel.name ?? '';
this.item.password = formModel.password!; this.item.password = formModel.password ?? '';
this.item.lockedOut = formModel.lockedOut!; this.item.lockedOut = formModel.lockedOut ?? true;
const array = this.form.controls.roles; const array = this.form.controls.roles;
this.item.roles.forEach((item, index) => { this.item.roles.forEach((item, index) => {
item.enabled = array.controls[index].value.role!; item.enabled = array.controls[index].value.role ?? false;
}); });
return this.item; return this.item;
} }