From 0ae03ff2f0fc140258021937ced13f4d9e01c82b Mon Sep 17 00:00:00 2001 From: Nirbighna2000 Date: Mon, 12 Feb 2024 17:55:09 +0530 Subject: [PATCH] ALR-907 --- .../default/classes/ManageUnitsController.cls | 4 +- .../default/lwc/manageUnits/manageUnits.js | 53 ++++++++++--------- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/main/default/classes/ManageUnitsController.cls b/src/main/default/classes/ManageUnitsController.cls index 7dc48877..00bf7e0d 100644 --- a/src/main/default/classes/ManageUnitsController.cls +++ b/src/main/default/classes/ManageUnitsController.cls @@ -6,7 +6,7 @@ * @last modified by : ChangeMeIn@UserSettingsUnder.SFDoc **/ public class ManageUnitsController { - Public static String VALIDATE_QTY = 'Updated Quantity cannot be equal,null, negative or greater than the existing quantity.'; + Public static String VALIDATE_QTY = 'Updated Quantity cannot be equal, null, negative or greater than the existing quantity.'; public static final String UNITREQUEST_RECTYPEID_NAME = 'Unit_Request_Record_Type'; Public static String NEW_UNIT_NAME='UnitRequest'; Public static String UNIT_FEE='Full Unit Fee'; @@ -49,7 +49,7 @@ public class ManageUnitsController { newunit.Type__c = existingUnits.get(unit.Id).Type__c; newunit.Status = UNITREQUEST_STATUS; system.debug('unit.Quantity'+unit.Quantity); - if(unit.Quantity >= existingUnits.get(unit.Id).Quantity || unit.Quantity < 0 || unit.Quantity == null) + if(unit.Quantity >= existingUnits.get(unit.Id).Quantity || unit.Quantity < 0 || unit.Quantity == null) { throw new MyException(VALIDATE_QTY); }else{ diff --git a/src/main/default/lwc/manageUnits/manageUnits.js b/src/main/default/lwc/manageUnits/manageUnits.js index 2d08515e..2aa02c86 100644 --- a/src/main/default/lwc/manageUnits/manageUnits.js +++ b/src/main/default/lwc/manageUnits/manageUnits.js @@ -44,7 +44,8 @@ const columns = [ } ]; export default class ManageUnits extends NavigationMixin(LightningElement) { - + + @api recordId; draftValues = []; datatableHeight; @@ -58,7 +59,7 @@ type; @track objectInfo; @track recordTypeId; @track isReloadFromHandleSave = false; - + @wire(getObjectInfo, { objectApiName: ASSET_OBJECT }) wiredObjectInfo({ error, data }) { if (error) { @@ -125,7 +126,6 @@ fetchTableData() { this.showToastMessage("Error", error.body.message, "error"); }); } - async handleSave(event) { debugger; const updatedFields = event.detail.draftValues; @@ -134,18 +134,17 @@ async handleSave(event) { record.GenerateRenewalInvoice__c = this.refs.renewed.checked; record.Amount__c = 'Full Unit Fee'; record.AccountId = this.recordId;//ALR-726 + const newQuantity = record.Quantity; // New value + const oldQuantity = this.initialRecords.find(item => item.Id === record.Id).Quantity; // Old value + + if (newQuantity === '' || newQuantity< 0 || newQuantity >= oldQuantity ) { + isValidInput = false; + return; + } }); - console.log(JSON.stringify(event.detail.draftValues)); - try { - // Pass edited fields to the updateUnits Apex controller - updatedFields.forEach((element) => { - if (element.Quantity === '') { - isValidInput = false; - return; - } - }); - if (isValidInput) { + if (isValidInput) { + try{ await updateUnits({ data: updatedFields }); this.showToastMessage("Success", 'Unit(s) has been successfully updated.', "success"); // Clear all draft values in the datatable @@ -153,20 +152,22 @@ async handleSave(event) { await this.fetchTableData(); this.refs.renewed.checked = false; this.draftValues = []; - localStorage.setItem('isReloadFromHandleSave', 'true'); - this.dispatchEvent(new CloseActionScreenEvent()); - window.location.reload(); - await refreshApex(this.wiredRecordResult); - } else { - this.showToastMessage("Error", 'Updated Quantity cannot be equal,null, negative or greater than the existing quantity.', "error"); - } + localStorage.setItem('isReloadFromHandleSave', 'true'); + this.dispatchEvent(new CloseActionScreenEvent()); + window.location.reload(); + await refreshApex(this.wiredRecordResult); + } - } catch (error) {a - let message = error.body.message.includes('FIELD_CUSTOM_VALIDATION_EXCEPTION') ? - error.body.message.split('EXCEPTION, ')[1].split(': [')[0] : error.body.message; - this.showToastMessage('Error', message, 'error'); - }; -} + catch (error) {a + let message = error.body.message.includes('FIELD_CUSTOM_VALIDATION_EXCEPTION') ? + error.body.message.split('EXCEPTION, ')[1].split(': [')[0] : error.body.message; + this.showToastMessage('Error', message, 'error'); + } + } + else { + this.showToastMessage("Error", 'Updated Quantity cannot be equal, null, negative or greater than the existing quantity.', "error"); + } +}; handleTypeChange(event) { this.type = event.target.value; }