From 943d0c1a7cc3270418632c297fa251ab0967e091 Mon Sep 17 00:00:00 2001 From: Viswas Date: Tue, 10 Dec 2024 02:19:34 +0530 Subject: [PATCH] fix: update default bank a/c options in BC We now show `ACCOUNT` as well as `BANK_ACCOUNT` attributes as options for default bank accounts. Only `ACCOUNT`s of category 'Assets' or 'Liabilities' are shown --- src/app/core/models/enum/enum.model.ts | 3 +- .../core/services/common/mapping.service.ts | 8 +- ...ess-central-export-settings.component.html | 4 +- ...iness-central-export-settings.component.ts | 87 +++++++++++++------ 4 files changed, 72 insertions(+), 30 deletions(-) diff --git a/src/app/core/models/enum/enum.model.ts b/src/app/core/models/enum/enum.model.ts index bf3851ea0..dc3af1dfa 100644 --- a/src/app/core/models/enum/enum.model.ts +++ b/src/app/core/models/enum/enum.model.ts @@ -702,7 +702,8 @@ export enum Sage300ExportSettingDestinationOptionKey { export enum BCExportSettingDestinationOptionKey { ACCOUNT = 'ACCOUNT', - VENDOR = 'VENDOR' + VENDOR = 'VENDOR', + REIMBURSABLE_BANK_ACCOUNT = 'REIMBURSABLE_BANK_ACCOUNT' } export enum QbdDirectExportSettingDestinationOptionKey { diff --git a/src/app/core/services/common/mapping.service.ts b/src/app/core/services/common/mapping.service.ts index 61d53fe8b..a63cf935b 100644 --- a/src/app/core/services/common/mapping.service.ts +++ b/src/app/core/services/common/mapping.service.ts @@ -170,9 +170,9 @@ export class MappingService { return this.apiService.post(`/workspaces/${this.workspaceService.getWorkspaceId()}/mappings/`, mapping); } - getPaginatedDestinationAttributes(attributeType: string, value?: string, display_name?: string, appName?: string, detailed_accout_type?: string[]): Observable { + getPaginatedDestinationAttributes(attributeType: string, value?: string, display_name?: string, appName?: string, detailed_accout_type?: string[], categories?: string[]): Observable { const workspaceId = this.workspaceService.getWorkspaceId(); - const params: {limit: number, offset: number, attribute_type: string, active?: boolean, value__icontains?: string, value?: string, display_name__in?: string, detail__account_type__in?: string[]} = { + const params: {limit: number, offset: number, attribute_type: string, active?: boolean, value__icontains?: string, value?: string, display_name__in?: string, detail__account_type__in?: string[], detail__category__in?: string[]} = { limit: 100, offset: 0, attribute_type: attributeType, @@ -195,6 +195,10 @@ export class MappingService { params.detail__account_type__in = detailed_accout_type; } + if (categories) { + params.detail__category__in = categories; + } + return this.apiService.get(`/workspaces/${workspaceId}/mappings/paginated_destination_attributes/`, params); } diff --git a/src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.html b/src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.html index edd23ddc1..d4ec92e13 100644 --- a/src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.html +++ b/src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.html @@ -91,8 +91,8 @@ [mandatoryErrorListName]="'Default Bank Account Name'" [label]="'Set the Default Bank Account as?'" [subLabel]="'The integration will assign the Expenses that is exported as Journal Entry to the Bank Account selected here.'" - [destinationAttributes]="bankOptions" - [destinationOptionKey]="BCExportSettingDestinationOptionKey.ACCOUNT" + [destinationAttributes]="reimbursableBankOptions" + [destinationOptionKey]="BCExportSettingDestinationOptionKey.REIMBURSABLE_BANK_ACCOUNT" [isOptionSearchInProgress]="isOptionSearchInProgress" [isAdvanceSearchEnabled]="true" (searchOptionsDropdown)="searchOptionsDropdown($event)" diff --git a/src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts b/src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts index 6e2c066c7..6cceb25be 100644 --- a/src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts +++ b/src/app/integrations/business-central/business-central-shared/business-central-export-settings/business-central-export-settings.component.ts @@ -31,6 +31,8 @@ export class BusinessCentralExportSettingsComponent implements OnInit { bankOptions: DestinationAttribute[]; + reimbursableBankOptions: DestinationAttribute[]; + vendorOptions: DestinationAttribute[]; isLoading: boolean = true; @@ -168,39 +170,62 @@ export class BusinessCentralExportSettingsComponent implements OnInit { debounceTime(1000) ).subscribe((event: ExportSettingOptionSearch) => { - let existingOptions: DestinationAttribute[]; - switch (event.destinationOptionKey) { - case BCExportSettingDestinationOptionKey.ACCOUNT: - existingOptions = this.bankOptions; - break; - case BCExportSettingDestinationOptionKey.VENDOR: - existingOptions = this.vendorOptions; - break; - } - - this.mappingService.getPaginatedDestinationAttributes(event.destinationOptionKey, event.searchTerm).subscribe((response) => { - - // Insert new options to existing options - response.results.forEach((option) => { - if (!existingOptions.find((existingOption) => existingOption.destination_id === option.destination_id)) { - existingOptions.push(option); - } + if (event.destinationOptionKey === BCExportSettingDestinationOptionKey.REIMBURSABLE_BANK_ACCOUNT) { + const observables = [ + this.mappingService.getPaginatedDestinationAttributes('BANK_ACCOUNT', event.searchTerm), + this.mappingService.getPaginatedDestinationAttributes( + 'ACCOUNT', event.searchTerm, undefined, undefined, undefined, ['Assets', 'Liabilities'] + ) + ]; + + forkJoin(observables).subscribe(([bankAccounts, accounts]) => { + // Insert new options (if any) to existing options, and sort them + const newOptions = [...bankAccounts.results, ...accounts.results]; + newOptions.forEach((newOption) => { + if (!this.reimbursableBankOptions.find((existingOption) => existingOption.destination_id === newOption.destination_id)) { + this.reimbursableBankOptions.push(newOption); + } + }); + + this.reimbursableBankOptions.sort((a, b) => (a.value || '').localeCompare(b.value || '')); }); + } else { + let existingOptions: DestinationAttribute[]; switch (event.destinationOptionKey) { case BCExportSettingDestinationOptionKey.ACCOUNT: - this.bankOptions = existingOptions.concat(); - this.bankOptions.sort((a, b) => (a.value || '').localeCompare(b.value || '')); + existingOptions = this.bankOptions; break; case BCExportSettingDestinationOptionKey.VENDOR: - this.vendorOptions = existingOptions.concat(); - this.vendorOptions.sort((a, b) => (a.value || '').localeCompare(b.value || '')); + existingOptions = this.vendorOptions; break; } - this.isOptionSearchInProgress = false; - }); + this.mappingService.getPaginatedDestinationAttributes(event.destinationOptionKey, event.searchTerm).subscribe((response) => { + + // Insert new options to existing options + response.results.forEach((option) => { + if (!existingOptions.find((existingOption) => existingOption.destination_id === option.destination_id)) { + existingOptions.push(option); + } + }); + + + switch (event.destinationOptionKey) { + case BCExportSettingDestinationOptionKey.ACCOUNT: + this.bankOptions = existingOptions.concat(); + this.bankOptions.sort((a, b) => (a.value || '').localeCompare(b.value || '')); + break; + case BCExportSettingDestinationOptionKey.VENDOR: + this.vendorOptions = existingOptions.concat(); + this.vendorOptions.sort((a, b) => (a.value || '').localeCompare(b.value || '')); + break; + } + + this.isOptionSearchInProgress = false; + }); + } }); } @@ -240,10 +265,19 @@ export class BusinessCentralExportSettingsComponent implements OnInit { this.mappingService.getPaginatedDestinationAttributes(destinationAttribute).pipe(filter(response => !!response)) ); + // For reimbursable default bank account options + const reimbursableBankAccountAttributes = [ + this.mappingService.getPaginatedDestinationAttributes('BANK_ACCOUNT'), + this.mappingService.getPaginatedDestinationAttributes( + 'ACCOUNT', undefined, undefined, undefined, undefined, ['Assets', 'Liabilities'] + ) + ]; + forkJoin([ this.exportSettingService.getExportSettings().pipe(catchError(() => of(null))), - ...groupedAttributes - ]).subscribe(([exportSettingsResponse, accounts, vendors]) => { + ...groupedAttributes, + ...reimbursableBankAccountAttributes + ]).subscribe(([exportSettingsResponse, accounts, vendors, reimbursableBankAccounts, reimbursableAccounts]) => { this.exportSettings = exportSettingsResponse; if (exportSettingsResponse) { @@ -266,6 +300,9 @@ export class BusinessCentralExportSettingsComponent implements OnInit { this.helper.setExportTypeValidatorsAndWatchers(exportModuleRule, this.exportSettingForm, commonFormFields); this.bankOptions = accounts.results; this.vendorOptions = vendors.results; + this.reimbursableBankOptions = [...reimbursableBankAccounts.results, ...reimbursableAccounts.results]; + this.reimbursableBankOptions.sort((a, b) => (a.value || '').localeCompare(b.value || '')); + this.setupCustomWatchers(); this.optionSearchWatcher(); this.isLoading = false;