WEB-342: Advance Accounting rule can not be edited for classification type

This commit is contained in:
Jose Alberto Hernandez
2025-10-10 12:09:56 +02:00
committed by Adam Saghy
parent 0f37f0fecf
commit 0a46b58ce7
2 changed files with 64 additions and 9 deletions
@@ -24,8 +24,8 @@
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef>{{ 'labels.inputs.Actions' | translate }}</th>
<td mat-cell *matCellDef="let chargeOffReasonExpense; let i = index">
<button mat-icon-button color="primary" (click)="edit(i)">
<td mat-cell *matCellDef="let item; let i = index">
<button mat-icon-button color="primary" (click)="edit(item, i)">
<fa-icon icon="edit"></fa-icon>
</button>
<button mat-icon-button color="warn" (click)="delete(i)">
@@ -133,6 +133,14 @@ export class AdvancedAccountingMappingRuleComponent implements OnInit {
this.tableData = newData;
}
updateTableData(updatedData: AccountingMappingDTO, index: number): void {
let newData = [
...this.tableData.slice(0, index),
updatedData,
...this.tableData.slice(index + 1)];
this.tableData = newData;
}
delete(index: number) {
const dialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: this.translateService.instant('labels.text.this') }
@@ -145,6 +153,51 @@ export class AdvancedAccountingMappingRuleComponent implements OnInit {
});
}
edit(record: AccountingMappingDTO, index: number) {
const data = { ...this.getData(this.formType, record), pristine: false, layout: { addButtonText: 'Edit' } };
const dialogRef = this.dialog.open(FormDialogComponent, { data });
dialogRef.afterClosed().subscribe((response: any) => {
if (response.data) {
let updateData: AccountingMappingDTO;
if ([
'ChargeOffReasonExpense',
'WriteOffReasonToExpense'
].includes(this.formType)) {
updateData = {
value: this.getValueData(response.data.value.chargeOffReasonCodeValueId),
glAccount: this.getGlAccountData(response.data.value.expenseAccountId)
};
} else if ([
'BuydownFeeClassificationToIncome',
'CapitalizedIncomeClassificationToIncome'
].includes(this.formType)) {
updateData = {
value: this.getValueData(response.data.value.valueId),
glAccount: this.getGlAccountData(response.data.value.glAccountId)
};
} else if (this.formType === 'PaymentFundSource') {
updateData = {
value: this.getValueData(response.data.paymentTypeId),
glAccount: this.getGlAccountData(response.data.fundSourceAccountId)
};
} else if (this.formType === 'FeesIncome') {
updateData = {
value: this.getValueData(response.data.chargeId),
glAccount: this.getGlAccountData(response.data.incomeAccountId)
};
} else if (this.formType === 'PenaltyIncome') {
updateData = {
value: this.getValueData(response.data.chargeId),
glAccount: this.getGlAccountData(response.data.incomeAccountId)
};
}
this.updateTableData(updateData, index);
this.sendParentData();
}
});
}
sendParentData() {
const advancedMappingDTO: AdvancedMappingDTO = {
formType: this.formType,
@@ -267,7 +320,7 @@ export class AdvancedAccountingMappingRuleComponent implements OnInit {
new SelectBase({
controlName: 'chargeOffReasonCodeValueId',
label: 'Charge-off reason',
value: values ? values.chargeOffReasonCodeValueId : reasonOptions[0].id,
value: values ? values.value.id : reasonOptions[0].id,
options: { label: 'name', value: 'id', data: reasonOptions },
required: true,
order: 1
@@ -275,7 +328,7 @@ export class AdvancedAccountingMappingRuleComponent implements OnInit {
new SelectBase({
controlName: 'expenseAccountId',
label: 'Expense Account',
value: values ? values.expenseAccountId : this.expenseAccountData[0].id,
value: values ? values.glAccount.id : this.expenseAccountData[0].id,
options: { label: 'name', value: 'id', data: this.expenseAccountData },
required: true,
order: 2
@@ -293,7 +346,7 @@ export class AdvancedAccountingMappingRuleComponent implements OnInit {
new SelectBase({
controlName: 'valueId',
label: 'Classification',
value: values ? values.chargeOffReasonCodeValueId : classificationOptions[0].id,
value: values ? values.value.id : classificationOptions[0].id,
options: { label: 'name', value: 'id', data: classificationOptions },
required: true,
order: 1
@@ -301,7 +354,7 @@ export class AdvancedAccountingMappingRuleComponent implements OnInit {
new SelectBase({
controlName: 'glAccountId',
label: 'Income Account',
value: values ? values.incomeAccountId : this.incomeAccountData[0].id,
value: values ? values.glAccount.id : this.incomeAccountData[0].id,
options: { label: 'name', value: 'id', data: this.incomeAccountData },
required: true,
order: 2
@@ -325,9 +378,11 @@ export class AdvancedAccountingMappingRuleComponent implements OnInit {
this.liabilityAccountData
];
for (const glAccountData of glAccountDatas) {
const glAccount = glAccountData.find((i: GLAccount) => i.id === valueId);
if (glAccount) {
return glAccount;
if (glAccountData) {
const glAccount = glAccountData.find((i: GLAccount) => i.id === valueId);
if (glAccount) {
return glAccount;
}
}
}
return null;