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

fix: update default bank a/c options in BC #1098

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
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"
JustARatherRidiculouslyLongUsername marked this conversation as resolved.
Show resolved Hide resolved
[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[];
JustARatherRidiculouslyLongUsername marked this conversation as resolved.
Show resolved Hide resolved

vendorOptions: DestinationAttribute[];

isLoading: boolean = true;
Expand Down Expand Up @@ -168,39 +170,63 @@ 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 || ''));
JustARatherRidiculouslyLongUsername marked this conversation as resolved.
Show resolved Hide resolved
this.isOptionSearchInProgress = false;
JustARatherRidiculouslyLongUsername marked this conversation as resolved.
Show resolved Hide resolved
});

} 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 +266,19 @@ export class BusinessCentralExportSettingsComponent implements OnInit {
this.mappingService.getPaginatedDestinationAttributes(destinationAttribute).pipe(filter(response => !!response))
);

// For reimbursable default bank account options
const reimbursableBankAccountAttributes = [
JustARatherRidiculouslyLongUsername marked this conversation as resolved.
Show resolved Hide resolved
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 +301,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 || ''));

JustARatherRidiculouslyLongUsername marked this conversation as resolved.
Show resolved Hide resolved
this.setupCustomWatchers();
this.optionSearchWatcher();
this.isLoading = false;
Expand Down
Loading