Skip to content

Commit

Permalink
Merge pull request #503 from bcgov/Hypercare-ALR-907
Browse files Browse the repository at this point in the history
ALR-907
  • Loading branch information
GandlojuVishwantha authored Feb 12, 2024
2 parents 209c44a + 0ae03ff commit 9f5acb1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/main/default/classes/ManageUnitsController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @last modified by : [email protected]
**/
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';
Expand Down Expand Up @@ -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{
Expand Down
53 changes: 27 additions & 26 deletions src/main/default/lwc/manageUnits/manageUnits.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const columns = [
}
];
export default class ManageUnits extends NavigationMixin(LightningElement) {



@api recordId;
draftValues = [];
datatableHeight;
Expand All @@ -58,7 +59,7 @@ type;
@track objectInfo;
@track recordTypeId;
@track isReloadFromHandleSave = false;

@wire(getObjectInfo, { objectApiName: ASSET_OBJECT })
wiredObjectInfo({ error, data }) {
if (error) {
Expand Down Expand Up @@ -125,7 +126,6 @@ fetchTableData() {
this.showToastMessage("Error", error.body.message, "error");
});
}

async handleSave(event) {
debugger;
const updatedFields = event.detail.draftValues;
Expand All @@ -134,39 +134,40 @@ 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
this.isLoading = true;
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;
}
Expand Down

0 comments on commit 9f5acb1

Please sign in to comment.