Skip to content

Commit

Permalink
fix: update default bank a/c options in BC
Browse files Browse the repository at this point in the history
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
  • Loading branch information
1 parent 80fb1e1 commit 943d0c1
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 30 deletions.
3 changes: 2 additions & 1 deletion src/app/core/models/enum/enum.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions src/app/core/services/common/mapping.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PaginatedDestinationAttribute> {
getPaginatedDestinationAttributes(attributeType: string, value?: string, display_name?: string, appName?: string, detailed_accout_type?: string[], categories?: string[]): Observable<PaginatedDestinationAttribute> {
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,
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class BusinessCentralExportSettingsComponent implements OnInit {

bankOptions: DestinationAttribute[];

reimbursableBankOptions: DestinationAttribute[];

vendorOptions: DestinationAttribute[];

isLoading: boolean = true;
Expand Down Expand Up @@ -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;
});
}
});
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 943d0c1

Please sign in to comment.