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))