Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALR-907 #503

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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