From 04d8b2bc7f382ac5daf6083fb261ca0a04098200 Mon Sep 17 00:00:00 2001 From: gkbishnoi07 Date: Mon, 14 Sep 2026 09:22:47 +0000 Subject: [PATCH] fix(inventory): validate mandatory fields before save physical stock entry, store consumption, stock transfer and indent request declare Validators.required but their save handlers never checked validity, so an empty/incomplete form was sent to the backend (raw error) or created an empty row. guard each save: - physical stock, consumption, transfer: return early with a validation alert when the form is invalid (markAllAsTouched) - indent request: rows carry no validators and the array starts empty, so require the header fields plus at least one real item (item + positive qty) same class of fix as the stock-adjustment guard; covers main and sub store. --- .../indent-request.component.ts | 23 +++++++++++++++++++ .../physical-stock-entry.component.ts | 9 ++++++++ .../store-self-consumption.component.ts | 9 ++++++++ .../store-stock-transfer.component.ts | 9 ++++++++ 4 files changed, 50 insertions(+) diff --git a/src/app/app-modules/inventory/indent/indent-order-worklist/sub-store-indent-order-worklist/indent-request/indent-request.component.ts b/src/app/app-modules/inventory/indent/indent-order-worklist/sub-store-indent-order-worklist/indent-request/indent-request.component.ts index 5db69f2..0ac6ff6 100644 --- a/src/app/app-modules/inventory/indent/indent-order-worklist/sub-store-indent-order-worklist/indent-request/indent-request.component.ts +++ b/src/app/app-modules/inventory/indent/indent-order-worklist/sub-store-indent-order-worklist/indent-request/indent-request.component.ts @@ -313,6 +313,29 @@ export class IndentRequestComponent implements OnInit, DoCheck { this.indentRequestForm.reset({ requestDate: new Date() }); } submitIndentRequest(indentRequestForm: FormGroup) { + // indentItemList rows carry no validators and the array can be empty, so + // guard manually: require the header fields and at least one real item + // (item selected + a positive required quantity). Prevents saving an empty + // request / an empty row. + const validItems = (indentRequestForm.value.indentItemList || []).filter( + (item: any) => + !item.deleted && + (item.itemID || `${item.itemName ?? ''}`.trim()) && + Number(item.requiredQty) > 0, + ); + if ( + indentRequestForm.get('referenceNumber')?.invalid || + indentRequestForm.get('indentReason')?.invalid || + validItems.length === 0 + ) { + indentRequestForm.markAllAsTouched(); + this.confirmationService.alert( + this.currentLanguageSet?.inventory?.pleaseFillMandatoryFields || + 'Please fill all mandatory fields.', + 'error', + ); + return; + } const indentRequest = JSON.parse( JSON.stringify(indentRequestForm.value.indentItemList), ); diff --git a/src/app/app-modules/inventory/physical-stock-entry/physical-stock-entry.component.ts b/src/app/app-modules/inventory/physical-stock-entry/physical-stock-entry.component.ts index b545d1b..6a59f32 100644 --- a/src/app/app-modules/inventory/physical-stock-entry/physical-stock-entry.component.ts +++ b/src/app/app-modules/inventory/physical-stock-entry/physical-stock-entry.component.ts @@ -235,6 +235,15 @@ export class PhysicalStockEntryComponent implements OnInit, OnChanges, DoCheck { } savePhysicalStock() { + if (this.physicalStockEntryForm.invalid) { + this.physicalStockEntryForm.markAllAsTouched(); + this.dialogService.alert( + this.currentLanguageSet?.inventory?.pleaseFillMandatoryFields || + 'Please fill all mandatory fields.', + 'error', + ); + return; + } console.log('FORMSTOCK', this.physicalStockEntryForm); const physicalStockEntry = JSON.parse( JSON.stringify(this.physicalStockEntryForm.value), diff --git a/src/app/app-modules/inventory/store-self-consumption/store-self-consumption.component.ts b/src/app/app-modules/inventory/store-self-consumption/store-self-consumption.component.ts index de67cb5..b148209 100644 --- a/src/app/app-modules/inventory/store-self-consumption/store-self-consumption.component.ts +++ b/src/app/app-modules/inventory/store-self-consumption/store-self-consumption.component.ts @@ -219,6 +219,15 @@ export class StoreSelfConsumptionComponent implements OnInit, DoCheck { } saveSelfConsumptionStock() { + if (this.storeSelfConsumptionForm.invalid) { + this.storeSelfConsumptionForm.markAllAsTouched(); + this.alertService.alert( + this.currentLanguageSet?.inventory?.pleaseFillMandatoryFields || + 'Please fill all mandatory fields.', + 'error', + ); + return; + } const temp = JSON.parse( JSON.stringify(this.storeSelfConsumptionForm.value), ); diff --git a/src/app/app-modules/inventory/store-stock-transfer/store-stock-transfer.component.ts b/src/app/app-modules/inventory/store-stock-transfer/store-stock-transfer.component.ts index db189e5..67148ae 100644 --- a/src/app/app-modules/inventory/store-stock-transfer/store-stock-transfer.component.ts +++ b/src/app/app-modules/inventory/store-stock-transfer/store-stock-transfer.component.ts @@ -297,6 +297,15 @@ export class StoreStockTransferComponent implements OnInit, DoCheck { } submitTransfers() { + if (this.stockTransferForm.invalid) { + this.stockTransferForm.markAllAsTouched(); + this.confirmationService.alert( + this.currentLanguageSet?.inventory?.pleaseFillMandatoryFields || + 'Please fill all mandatory fields.', + 'error', + ); + return; + } console.log(this.stockTransferForm.value); this.inventoryService .saveStockTransfer(this.serviceDataMapper(this.stockTransferForm.value))