Skip to content

Commit

Permalink
fix: advanced search fields not persisting/sorting values (#911)
Browse files Browse the repository at this point in the history
* fix: advanced search fields not persisting values in bc

* fix: advanced search fields not persisting values in qbo

* fix: advanced search fields not persisting values in xero

* fix: advanced search fields not persisting values in sage300

* fix: advanced search fields not persisting values in netsuite

* fix: invalid option being added CCC account options

* fix: sort all options in all advanced search fields

* refactor: remove console.logs

(cherry picked from commit 4835c3d)
  • Loading branch information
JustARatherRidiculouslyLongUsername committed Aug 20, 2024
1 parent 7d91cf7 commit 1e5468b
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/app/core/services/common/helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { StorageService } from './storage.service';
import { brandingConfig } from 'src/app/branding/branding-config';
import { SentenceCasePipe } from 'src/app/shared/pipes/sentence-case.pipe';
import { TitleCasePipe } from '@angular/common';
import { DefaultDestinationAttribute, DestinationAttribute } from '../../models/db/destination-attribute.model';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -247,4 +248,42 @@ export class HelperService {
return brandingConfig.brandId === 'co' ? new SentenceCasePipe().transform(content) : content;
}

/**
* If the destination attribute with `destination_id` does not exist in `options`, add it
*/
addDestinationAttributeIfNotExists(
{options, destination_id, value}: {options: DestinationAttribute[]; destination_id?: string | null; value?: string | null}
) {
if (
destination_id &&
options &&
!options.find((option) => option.destination_id === destination_id)
) {
options.push({
value: value || '',
destination_id
} as DestinationAttribute);

}

options.sort((a, b) => (a.value || '').localeCompare(b.value || ''));
}

/**
* If the default destination attribute with `destination_id` does not exist in `options`, add it
*/
addDefaultDestinationAttributeIfNotExists(
{options, newOption}: {options: DefaultDestinationAttribute[]; newOption: DefaultDestinationAttribute}
) {
if (
newOption.id && options &&
!options.find((option) => option.id === newOption.id)
) {
options.push(newOption);

}

options.sort((a, b) => (a.name || '').localeCompare(b.name || ''));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,20 @@ export class BusinessCentralExportSettingsComponent implements OnInit {
...groupedAttributes
]).subscribe(([exportSettingsResponse, accounts, vendors]) => {
this.exportSettings = exportSettingsResponse;

this.helperService.addDestinationAttributeIfNotExists({
options: accounts.results,
value: exportSettingsResponse?.default_bank_account_name,
destination_id: exportSettingsResponse?.default_bank_account_id
});


this.helperService.addDestinationAttributeIfNotExists({
options: vendors.results,
value: exportSettingsResponse?.default_vendor_name,
destination_id: exportSettingsResponse?.default_vendor_id
});

this.exportSettingForm = BusinessCentralExportSettingModel.mapAPIResponseToFormGroup(this.exportSettings, accounts.results, vendors.results);
this.helperService.addExportSettingFormValidator(this.exportSettingForm);
this.helper.setConfigurationSettingValidatorsAndWatchers(exportSettingValidatorRule, this.exportSettingForm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ export class NetsuiteExportSettingsComponent implements OnInit {
}
}

addMissingOptions() {
this.helperService.addDefaultDestinationAttributeIfNotExists({options: this.bankAccounts, newOption: this.exportSettings.general_mappings.reimbursable_account});
this.helperService.addDefaultDestinationAttributeIfNotExists({options: this.cccAccounts, newOption: this.exportSettings.general_mappings.default_ccc_account});
this.helperService.addDefaultDestinationAttributeIfNotExists({options: this.accountsPayables, newOption: this.exportSettings.general_mappings.accounts_payable});
this.helperService.addDefaultDestinationAttributeIfNotExists({options: this.creditCardVendors, newOption: this.exportSettings.general_mappings.default_ccc_vendor});
}

private getSettingsAndSetupForm(): void {
this.isOnboarding = this.windowReference.location.pathname.includes('onboarding');
Expand All @@ -363,6 +369,7 @@ export class NetsuiteExportSettingsComponent implements OnInit {
this.reimbursableExportTypes = NetSuiteExportSettingModel.getReimbursableExportTypeOptions();
this.showNameInJournalOption = this.exportSettings.configuration?.corporate_credit_card_expenses_object === NetSuiteCorporateCreditCardExpensesObject.JOURNAL_ENTRY ? true : false;

this.addMissingOptions();
this.exportSettingForm = NetSuiteExportSettingModel.mapAPIResponseToFormGroup(this.exportSettings);
if (!this.brandingFeatureConfig.featureFlags.exportSettings.reimbursableExpenses) {
this.exportSettingForm.controls.creditCardExpense.patchValue(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,17 @@ export class QboExportSettingsComponent implements OnInit {
}
}

private addMissingOptions() {
// Since pagination call doesn't return all results for options, we're making use of the export settings API to fill in options
this.helperService.addDefaultDestinationAttributeIfNotExists({options: this.bankAccounts, newOption: this.exportSettings.general_mappings.bank_account});
this.helperService.addDefaultDestinationAttributeIfNotExists({options: this.expenseAccounts, newOption: this.exportSettings.general_mappings.qbo_expense_account});
this.helperService.addDefaultDestinationAttributeIfNotExists({options: this.accountsPayables, newOption: this.exportSettings.general_mappings.accounts_payable});

this.helperService.addDefaultDestinationAttributeIfNotExists({options: this.cccAccounts, newOption: this.exportSettings.general_mappings.default_ccc_account});
this.helperService.addDefaultDestinationAttributeIfNotExists({options: this.bankAccounts, newOption: this.exportSettings.general_mappings.default_debit_card_account});
this.helperService.addDefaultDestinationAttributeIfNotExists({options: this.vendors, newOption: this.exportSettings.general_mappings.default_ccc_vendor});
}

private getSettingsAndSetupForm(): void {
this.isOnboarding = this.windowReference.location.pathname.includes('onboarding');
const destinationAttributes = ['BANK_ACCOUNT', 'CREDIT_CARD_ACCOUNT', 'ACCOUNTS_PAYABLE', 'VENDOR'];
Expand Down Expand Up @@ -413,6 +424,7 @@ export class QboExportSettingsComponent implements OnInit {
this.reimbursableExportTypes = QBOExportSettingModel.getReimbursableExportTypeOptions(this.employeeFieldMapping);
this.showNameInJournalOption = this.exportSettings.workspace_general_settings?.corporate_credit_card_expenses_object === QBOCorporateCreditCardExpensesObject.JOURNAL_ENTRY ? true : false;

this.addMissingOptions();
this.exportSettingForm = QBOExportSettingModel.mapAPIResponseToFormGroup(this.exportSettings, this.employeeFieldMapping);

if (!this.brandingFeatureConfig.featureFlags.exportSettings.reimbursableExpenses) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,56 @@ export class Sage300ExportSettingsComponent implements OnInit {
}
}

private addMissingOptions() {

// Reimbursable
this.helper.addDestinationAttributeIfNotExists({
options: this.creditCardAccountOptions,
destination_id: this.exportSettings?.default_reimbursable_credit_card_account_id,
value: this.exportSettings?.default_reimbursable_credit_card_account_name
});

this.helper.addDestinationAttributeIfNotExists({
options: this.debitCardAccountOptions,
destination_id: this.exportSettings?.default_debit_card_account_id,
value: this.exportSettings?.default_debit_card_account_name
});

this.helper.addDestinationAttributeIfNotExists({
options: this.sage300Jobs,
destination_id: this.exportSettings?.default_job_id,
value: this.exportSettings?.default_job_name
});

this.helper.addDestinationAttributeIfNotExists({
options: this.accountsPayableOptions,
destination_id: this.exportSettings?.default_reimbursable_account_payable_id,
value: this.exportSettings?.default_reimbursable_account_payable_name
});

// CCC
this.helper.addDestinationAttributeIfNotExists({
options: this.creditCardAccountOptions,
destination_id: this.exportSettings?.default_ccc_credit_card_account_id,
value: this.exportSettings?.default_ccc_credit_card_account_name
});

// Debit card account added in call #2
// Jobs added in call #3

this.helper.addDestinationAttributeIfNotExists({
options: this.accountsPayableOptions,
destination_id: this.exportSettings?.default_ccc_account_payable_id,
value: this.exportSettings?.default_ccc_account_payable_name
});

this.helper.addDestinationAttributeIfNotExists({
options: this.vendorOptions,
destination_id: this.exportSettings?.default_vendor_id,
value: this.exportSettings?.default_vendor_name
});
}

private setupPage(): void {
this.isOnboarding = this.router.url.includes('onboarding');
const exportSettingValidatorRule: ExportSettingValidatorRule = {
Expand Down Expand Up @@ -286,6 +336,8 @@ export class Sage300ExportSettingsComponent implements OnInit {
this.vendorOptions = vendors.results;
this.creditCardAccountOptions = this.debitCardAccountOptions = this.accountsPayableOptions = accounts.results;
this.sage300Jobs = jobs.results;

this.addMissingOptions();
this.exportSettingForm = ExportSettingModel.mapAPIResponseToFormGroup(this.exportSettings, vendors.results, accounts.results, jobs.results);

this.helperService.addExportSettingFormValidator(this.exportSettingForm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ export class XeroExportSettingsComponent implements OnInit {
]).subscribe(([exportSettings, bankAccounts]) => {
this.exportSettings = exportSettings;
this.bankAccounts = bankAccounts.results;

this.helperService.addDestinationAttributeIfNotExists({
options: this.bankAccounts,
destination_id: this.exportSettings.general_mappings.bank_account.id,
value: this.exportSettings.general_mappings.bank_account.name
});
this.exportSettingForm = XeroExportSettingModel.mapAPIResponseToFormGroup(this.exportSettings, this.bankAccounts);
if (!this.brandingFeatureConfig.featureFlags.exportSettings.reimbursableExpenses) {
this.exportSettingForm.controls.creditCardExpense.patchValue(true);
Expand Down

0 comments on commit 1e5468b

Please sign in to comment.