From 1f8b7186a75101d8c6ee3153420c68cf7219eef2 Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Tue, 5 Nov 2024 12:37:29 +0000 Subject: [PATCH 01/12] When to export selector for auto-sync for NetSuite --- src/CONST.ts | 5 ++ src/ROUTES.ts | 8 ++ src/SCREENS.ts | 2 + src/components/SelectionScreen.tsx | 1 + src/languages/en.ts | 14 ++++ src/languages/es.ts | 14 ++++ .../ModalStackNavigators/index.tsx | 3 + .../FULL_SCREEN_TO_RHP_MAPPING.ts | 2 + src/libs/Navigation/linkingConfig/config.ts | 6 ++ .../advanced/NetSuiteAccountingMethodPage.tsx | 74 +++++++++++++++++++ .../advanced/NetSuiteAdvancedPage.tsx | 23 +++--- .../advanced/NetSuiteAutoSyncPage.tsx | 69 +++++++++++++++++ src/types/onyx/Policy.ts | 3 + 13 files changed, 212 insertions(+), 12 deletions(-) create mode 100644 src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx create mode 100644 src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx diff --git a/src/CONST.ts b/src/CONST.ts index 437ee4e7fd42..4421e5d8d9cd 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1848,6 +1848,11 @@ const CONST = { NETSUITE_ADD_CUSTOM_SEGMENT_STEP_NAMES: ['1', '2,', '3', '4', '5', '6,'], }, + NETSUITE_ACCOUNTING_METHODS: { + ACCRUAL: 'ACCRUAL', + CASH: 'CASH', + }, + NETSUITE_CUSTOM_FIELD_SUBSTEP_INDEXES: { CUSTOM_LISTS: { CUSTOM_LIST_PICKER: 0, diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 45501bf46374..444f91d2c4e4 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -1626,6 +1626,14 @@ const ROUTES = { getRoute: (policyID: string, expenseType: ValueOf) => `settings/workspaces/${policyID}/connections/netsuite/advanced/custom-form-id/${expenseType}` as const, }, + POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC: { + route: 'settings/workspaces/:policyID/connections/netsuite/advanced/autosync', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/connections/netsuite/advanced/autosync` as const, + }, + POLICY_ACCOUNTING_NETSUITE_ACCOUNTING_METHOD: { + route: 'settings/workspaces/:policyID/connections/netsuite/advanced/autosync/accounting-method', + getRoute: (policyID: string) => `settings/workspaces/${policyID}/connections/netsuite/advanced/autosync/accounting-method` as const, + }, POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES: { route: 'settings/workspaces/:policyID/accounting/sage-intacct/prerequisites', getRoute: (policyID: string) => `settings/workspaces/${policyID}/accounting/sage-intacct/prerequisites` as const, diff --git a/src/SCREENS.ts b/src/SCREENS.ts index dea0f028e1a0..f66f5af066e9 100644 --- a/src/SCREENS.ts +++ b/src/SCREENS.ts @@ -405,6 +405,8 @@ const SCREENS = { NETSUITE_JOURNAL_ENTRY_APPROVAL_LEVEL_SELECT: 'Policy_Accounting_NetSuite_Journal_Entry_Approval_Level_Select', NETSUITE_APPROVAL_ACCOUNT_SELECT: 'Policy_Accounting_NetSuite_Approval_Account_Select', NETSUITE_CUSTOM_FORM_ID: 'Policy_Accounting_NetSuite_Custom_Form_ID', + NETSUITE_AUTO_SYNC: 'Policy_Accounting_NetSuite_Auto_Sync', + NETSUITE_ACCOUNTING_METHOD: 'Policy_Accounting_NetSuite_Accounting_Method', SAGE_INTACCT_PREREQUISITES: 'Policy_Accounting_Sage_Intacct_Prerequisites', ENTER_SAGE_INTACCT_CREDENTIALS: 'Policy_Enter_Sage_Intacct_Credentials', EXISTING_SAGE_INTACCT_CONNECTIONS: 'Policy_Existing_Sage_Intacct_Connections', diff --git a/src/components/SelectionScreen.tsx b/src/components/SelectionScreen.tsx index 8382029bc12f..1b90777a6296 100644 --- a/src/components/SelectionScreen.tsx +++ b/src/components/SelectionScreen.tsx @@ -159,6 +159,7 @@ function SelectionScreen({ sectionListStyle={!!sections.length && [styles.flexGrow0]} shouldSingleExecuteRowSelect={shouldSingleExecuteRowSelect} shouldUpdateFocusedIndex={shouldUpdateFocusedIndex} + isAlternateTextMultilineSupported > require('../../../../pages/workspace/accounting/netsuite/advanced/NetSuiteApprovalAccountSelectPage').default, [SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_CUSTOM_FORM_ID]: () => require('../../../../pages/workspace/accounting/netsuite/advanced/NetSuiteCustomFormIDPage').default, + [SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_AUTO_SYNC]: () => require('../../../../pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage').default, + [SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_ACCOUNTING_METHOD]: () => + require('../../../../pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage').default, [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_PREREQUISITES]: () => require('../../../../pages/workspace/accounting/intacct/SageIntacctPrerequisitesPage').default, [SCREENS.WORKSPACE.ACCOUNTING.ENTER_SAGE_INTACCT_CREDENTIALS]: () => require('../../../../pages/workspace/accounting/intacct/EnterSageIntacctCredentialsPage').default, diff --git a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts index d282bab770c6..d19b23f5c00c 100755 --- a/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts +++ b/src/libs/Navigation/linkingConfig/FULL_SCREEN_TO_RHP_MAPPING.ts @@ -124,6 +124,8 @@ const FULL_SCREEN_TO_RHP_MAPPING: Partial> = { SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_JOURNAL_ENTRY_APPROVAL_LEVEL_SELECT, SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_APPROVAL_ACCOUNT_SELECT, SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_CUSTOM_FORM_ID, + SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_AUTO_SYNC, + SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_ACCOUNTING_METHOD, SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_PREREQUISITES, SCREENS.WORKSPACE.ACCOUNTING.ENTER_SAGE_INTACCT_CREDENTIALS, SCREENS.WORKSPACE.ACCOUNTING.EXISTING_SAGE_INTACCT_CONNECTIONS, diff --git a/src/libs/Navigation/linkingConfig/config.ts b/src/libs/Navigation/linkingConfig/config.ts index 330d5f113503..4098fa9ceba0 100644 --- a/src/libs/Navigation/linkingConfig/config.ts +++ b/src/libs/Navigation/linkingConfig/config.ts @@ -529,6 +529,12 @@ const config: LinkingOptions['config'] = { [SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_CUSTOM_FORM_ID]: { path: ROUTES.POLICY_ACCOUNTING_NETSUITE_CUSTOM_FORM_ID.route, }, + [SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_AUTO_SYNC]: { + path: ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.route, + }, + [SCREENS.WORKSPACE.ACCOUNTING.NETSUITE_ACCOUNTING_METHOD]: { + path: ROUTES.POLICY_ACCOUNTING_NETSUITE_ACCOUNTING_METHOD.route, + }, [SCREENS.WORKSPACE.ACCOUNTING.SAGE_INTACCT_PREREQUISITES]: {path: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES.route}, [SCREENS.WORKSPACE.ACCOUNTING.ENTER_SAGE_INTACCT_CREDENTIALS]: {path: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_ENTER_CREDENTIALS.route}, [SCREENS.WORKSPACE.ACCOUNTING.EXISTING_SAGE_INTACCT_CONNECTIONS]: {path: ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXISTING_CONNECTIONS.route}, diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx new file mode 100644 index 000000000000..59a2524b455c --- /dev/null +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx @@ -0,0 +1,74 @@ +import React, {useCallback, useMemo} from 'react'; +import {View} from 'react-native'; +import type {ValueOf} from 'type-fest'; +import RadioListItem from '@components/SelectionList/RadioListItem'; +import type {ListItem} from '@components/SelectionList/types'; +import SelectionScreen from '@components/SelectionScreen'; +import type {SelectorType} from '@components/SelectionScreen'; +import Text from '@components/Text'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import Navigation from '@navigation/Navigation'; +import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; +import withPolicyConnections from '@pages/workspace/withPolicyConnections'; +import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; + +type MenuListItem = ListItem & { + value: ValueOf; +}; + +function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { + const {translate} = useLocalize(); + const policyID = policy?.id ?? '-1'; + const styles = useThemeStyles(); + const config = policy?.connections?.netsuite.options.config; + const accountingMehtod = config?.accountingMehtod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH; + const data: MenuListItem[] = Object.values(CONST.NETSUITE_ACCOUNTING_METHODS).map((accountingMehtodType) => ({ + value: accountingMehtodType, + text: translate(`workspace.netsuite.advancedConfig.accountingMethods.values.${accountingMehtodType}`), + alternateText: translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMehtodType}`), + keyForList: accountingMehtodType, + isSelected: accountingMehtod === accountingMehtodType, + })); + + const headerContent = useMemo( + () => ( + + {translate('workspace.netsuite.advancedConfig.accountingMethods.description')} + + ), + [translate, styles.pb5, styles.ph5], + ); + + const selectExpenseReportApprovalLevel = useCallback( + (row: MenuListItem) => { + // if (row.value !== config?.syncOptions.exportReportsTo) { + // Connections.updateNetSuiteExportReportsTo(policyID, row.value, config?.syncOptions.exportReportsTo ?? CONST.NETSUITE_REPORTS_APPROVAL_LEVEL.REPORTS_APPROVED_NONE); + // } + Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID)); + }, + [config?.syncOptions.exportReportsTo, policyID], + ); + + return ( + selectExpenseReportApprovalLevel(selection as MenuListItem)} + initiallyFocusedOptionKey={data.find((mode) => mode.isSelected)?.keyForList} + policyID={policyID} + accessVariants={[CONST.POLICY.ACCESS_VARIANTS.ADMIN]} + featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} + onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID))} + connectionName={CONST.POLICY.CONNECTIONS.NAME.NETSUITE} + /> + ); +} + +NetSuiteAccountingMethodPage.displayName = 'NetSuiteExpenseReportApprovalLevelSelectPage'; + +export default withPolicyConnections(NetSuiteAccountingMethodPage); diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx index 50b2b966c73b..bde4386fe3b6 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx @@ -31,7 +31,7 @@ import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; import ROUTES from '@src/ROUTES'; -type MenuItemWithSubscribedSettings = Pick & {subscribedSettings?: string[]}; +type MenuItemWithSubscribedSettings = Pick & {subscribedSettings?: string[]}; function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); @@ -40,7 +40,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { const config = policy?.connections?.netsuite?.options.config; const autoSyncConfig = policy?.connections?.netsuite?.config; - + const accountingMehtod = policy?.connections?.netsuite?.options.config.accountingMehtod; const {payableList} = policy?.connections?.netsuite?.options?.data ?? {}; const selectedReimbursementAccount = useMemo( @@ -63,16 +63,14 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { const menuItems: Array = [ { - type: 'toggle', - title: translate('workspace.accounting.autoSync'), - subtitle: translate('workspace.netsuite.advancedConfig.autoSyncDescription'), - isActive: !!autoSyncConfig?.autoSync.enabled, - switchAccessibilityLabel: translate('workspace.netsuite.advancedConfig.autoSyncDescription'), - shouldPlaceSubtitleBelowSwitch: true, - onCloseError: () => Policy.clearNetSuiteAutoSyncErrorField(policyID), - onToggle: (isEnabled) => Connections.updateNetSuiteAutoSync(policyID, isEnabled), - pendingAction: settingsPendingAction([CONST.NETSUITE_CONFIG.AUTO_SYNC], autoSyncConfig?.pendingFields), - errors: ErrorUtils.getLatestErrorField(autoSyncConfig, CONST.NETSUITE_CONFIG.AUTO_SYNC), + type: 'menuitem', + title: autoSyncConfig?.autoSync.enabled ? translate('common.enabled') : translate('common.disabled'), + description: translate('workspace.accounting.autoSync'), + onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID)), + hintText: (() => { + if (!autoSyncConfig?.autoSync.enabled) return undefined; + return translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMehtod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH}`); + })(), }, { type: 'divider', @@ -264,6 +262,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { shouldShowRightIcon onPress={item?.onPress} brickRoadIndicator={areSettingsInErrorFields(item.subscribedSettings, config?.errorFields) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} + hintText={item.hintText} /> ); diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx new file mode 100644 index 000000000000..554291fc9909 --- /dev/null +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx @@ -0,0 +1,69 @@ +import React from 'react'; +import HeaderWithBackButton from '@components/HeaderWithBackButton'; +import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; +import ScreenWrapper from '@components/ScreenWrapper'; +import useLocalize from '@hooks/useLocalize'; +import useThemeStyles from '@hooks/useThemeStyles'; +import * as Connections from '@libs/actions/connections/NetSuiteCommands'; +import * as ErrorUtils from '@libs/ErrorUtils'; +import Navigation from '@libs/Navigation/Navigation'; +import {settingsPendingAction} from '@libs/PolicyUtils'; +import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper'; +import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; +import withPolicyConnections from '@pages/workspace/withPolicyConnections'; +import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow'; +import * as Policy from '@userActions/Policy/Policy'; +import CONST from '@src/CONST'; +import ROUTES from '@src/ROUTES'; + +function NetSuiteAutoSyncPage({policy, route}: WithPolicyConnectionsProps) { + const styles = useThemeStyles(); + const {translate} = useLocalize(); + const autoSyncConfig = policy?.connections?.netsuite?.config; + const policyID = route.params.policyID ?? '-1'; + const accountingMethod = policy?.connections?.netsuite?.options.config.accountingMehtod; + + return ( + + + Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_ADVANCED.getRoute(policyID))} + /> + Policy.clearNetSuiteAutoSyncErrorField(policyID)} + onToggle={(isEnabled) => Connections.updateNetSuiteAutoSync(policyID, isEnabled)} + pendingAction={settingsPendingAction([CONST.NETSUITE_CONFIG.AUTO_SYNC], autoSyncConfig?.pendingFields)} + errors={ErrorUtils.getLatestErrorField(autoSyncConfig, CONST.NETSUITE_CONFIG.AUTO_SYNC)} + /> + {!!autoSyncConfig?.autoSync.enabled && ( + Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_ACCOUNTING_METHOD.getRoute(policyID))} + /> + )} + + + ); +} + +NetSuiteAutoSyncPage.displayName = 'NetSuiteAutoSyncPage'; + +export default withPolicyConnections(NetSuiteAutoSyncPage); diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index ecc5bd1f6606..cd81c7fab1f1 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -993,6 +993,9 @@ type NetSuiteConnectionConfig = OnyxCommon.OnyxValueWithOfflineFeedback< /** Whether this account is using the newer version of tax in NetSuite, SuiteTax */ suiteTaxEnabled?: boolean; + /** The accounting Method for NetSuite conenction config */ + accountingMehtod?: ValueOf; + /** Collection of errors coming from BE */ errors?: OnyxCommon.Errors; From 9be1a901b284c412e8b14fc391dc5b25f3e6456c Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Tue, 5 Nov 2024 13:08:27 +0000 Subject: [PATCH 02/12] Add API --- src/CONST.ts | 1 + .../UpdateNetSuiteAccountingMethodParams.ts | 9 +++++++++ src/libs/API/parameters/index.ts | 1 + src/libs/API/types.ts | 2 ++ src/libs/actions/connections/NetSuiteCommands.ts | 16 ++++++++++++++++ .../advanced/NetSuiteAccountingMethodPage.tsx | 11 ++++++----- .../netsuite/advanced/NetSuiteAutoSyncPage.tsx | 2 +- src/types/onyx/Policy.ts | 2 +- 8 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts diff --git a/src/CONST.ts b/src/CONST.ts index 4421e5d8d9cd..285f8b142e07 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1805,6 +1805,7 @@ const CONST = { EXPORT_TO_NEXT_OPEN_PERIOD: 'exportToNextOpenPeriod', IMPORT_FIELDS: ['departments', 'classes', 'locations'], AUTO_SYNC: 'autoSync', + ACCOUNTING_METHOD: 'accountingMethod', REIMBURSEMENT_ACCOUNT_ID: 'reimbursementAccountID', COLLECTION_ACCOUNT: 'collectionAccount', AUTO_CREATE_ENTITIES: 'autoCreateEntities', diff --git a/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts b/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts new file mode 100644 index 000000000000..33780e64342d --- /dev/null +++ b/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts @@ -0,0 +1,9 @@ +import type {ValueOf} from 'type-fest'; +import type CONST from '@src/CONST'; + +type UpdateNetSuiteAccountingMethodParams = { + policyID: string; + accountingMethod: ValueOf; +}; + +export default UpdateNetSuiteAccountingMethodParams; diff --git a/src/libs/API/parameters/index.ts b/src/libs/API/parameters/index.ts index 26da6b2f6f03..53059cfee248 100644 --- a/src/libs/API/parameters/index.ts +++ b/src/libs/API/parameters/index.ts @@ -19,6 +19,7 @@ export type {default as OpenPolicyInitialPageParams} from './OpenPolicyInitialPa export type {default as SyncPolicyToQuickbooksOnlineParams} from './SyncPolicyToQuickbooksOnlineParams'; export type {default as SyncPolicyToXeroParams} from './SyncPolicyToXeroParams'; export type {default as SyncPolicyToNetSuiteParams} from './SyncPolicyToNetSuiteParams'; +export type {default as UpdateNetSuiteAccountingMethodParams} from './UpdateNetSuiteAccountingMethodParams'; export type {default as SyncPolicyToQuickbooksDesktopParams} from './SyncPolicyToQuickbooksDesktopParams'; export type {default as DeleteContactMethodParams} from './DeleteContactMethodParams'; export type {default as DeletePaymentBankAccountParams} from './DeletePaymentBankAccountParams'; diff --git a/src/libs/API/types.ts b/src/libs/API/types.ts index 0350d59685ce..22f5673cd0e5 100644 --- a/src/libs/API/types.ts +++ b/src/libs/API/types.ts @@ -360,6 +360,7 @@ const WRITE_COMMANDS = { UPDATE_NETSUITE_COLLECTION_ACCOUNT: 'UpdateNetSuiteCollectionAccount', UPDATE_NETSUITE_EXPORT_REPORTS_TO: 'UpdateNetSuiteExportReportsTo', UPDATE_NETSUITE_VENDOR_BILLS_TO: 'UpdateNetSuiteExportVendorBillsTo', + UPDATE_NETSUITE_ACCOUNTING_METHOD: 'UpdateNetSuiteAccountingMethod', UPDATE_NETSUITE_JOURNALS_TO: 'UpdateNetSuiteExportJournalsTo', UPDATE_NETSUITE_APPROVAL_ACCOUNT: 'UpdateNetSuiteApprovalAccount', UPDATE_NETSUITE_CUSTOM_FORM_ID_OPTIONS_REIMBURSABLE: 'UpdateNetSuiteCustomFormIDOptionsReimbursable', @@ -831,6 +832,7 @@ type WriteCommandParameters = { [WRITE_COMMANDS.UPDATE_NETSUITE_COLLECTION_ACCOUNT]: Parameters.UpdateNetSuiteGenericTypeParams<'bankAccountID', string>; [WRITE_COMMANDS.UPDATE_NETSUITE_EXPORT_REPORTS_TO]: Parameters.UpdateNetSuiteGenericTypeParams<'value', ValueOf>; [WRITE_COMMANDS.UPDATE_NETSUITE_VENDOR_BILLS_TO]: Parameters.UpdateNetSuiteGenericTypeParams<'value', ValueOf>; + [WRITE_COMMANDS.UPDATE_NETSUITE_ACCOUNTING_METHOD]: Parameters.UpdateNetSuiteAccountingMethodParams; [WRITE_COMMANDS.UPDATE_NETSUITE_JOURNALS_TO]: Parameters.UpdateNetSuiteGenericTypeParams<'value', ValueOf>; [WRITE_COMMANDS.UPDATE_NETSUITE_APPROVAL_ACCOUNT]: Parameters.UpdateNetSuiteGenericTypeParams<'value', string>; [WRITE_COMMANDS.UPDATE_NETSUITE_CUSTOM_FORM_ID_OPTIONS_REIMBURSABLE]: Parameters.UpdateNetSuiteCustomFormIDParams; diff --git a/src/libs/actions/connections/NetSuiteCommands.ts b/src/libs/actions/connections/NetSuiteCommands.ts index ad3693ef3654..534e75c3625d 100644 --- a/src/libs/actions/connections/NetSuiteCommands.ts +++ b/src/libs/actions/connections/NetSuiteCommands.ts @@ -935,6 +935,21 @@ function updateNetSuiteExportReportsTo( API.write(WRITE_COMMANDS.UPDATE_NETSUITE_EXPORT_REPORTS_TO, parameters, onyxData); } +function updateNetSuiteAccountingMethod( + policyID: string, + accountingMethod: ValueOf, + oldAccountingMethod: ValueOf, +) { + const onyxData = updateNetSuiteOnyxData(policyID, CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD, accountingMethod, oldAccountingMethod); + + const parameters = { + policyID, + accountingMethod, + }; + + API.write(WRITE_COMMANDS.UPDATE_NETSUITE_ACCOUNTING_METHOD, parameters, onyxData); +} + function updateNetSuiteExportVendorBillsTo( policyID: string, approvalLevel: ValueOf, @@ -1037,4 +1052,5 @@ export { updateNetSuiteApprovalAccount, updateNetSuiteCustomFormIDOptions, updateNetSuiteCustomersJobsMapping, + updateNetSuiteAccountingMethod, }; diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx index 59a2524b455c..3baf6441612c 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx @@ -8,6 +8,7 @@ import type {SelectorType} from '@components/SelectionScreen'; import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; +import * as Connections from '@libs/actions/connections/NetSuiteCommands'; import Navigation from '@navigation/Navigation'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; @@ -23,7 +24,7 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { const policyID = policy?.id ?? '-1'; const styles = useThemeStyles(); const config = policy?.connections?.netsuite.options.config; - const accountingMehtod = config?.accountingMehtod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH; + const accountingMehtod = config?.accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH; const data: MenuListItem[] = Object.values(CONST.NETSUITE_ACCOUNTING_METHODS).map((accountingMehtodType) => ({ value: accountingMehtodType, text: translate(`workspace.netsuite.advancedConfig.accountingMethods.values.${accountingMehtodType}`), @@ -43,12 +44,12 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { const selectExpenseReportApprovalLevel = useCallback( (row: MenuListItem) => { - // if (row.value !== config?.syncOptions.exportReportsTo) { - // Connections.updateNetSuiteExportReportsTo(policyID, row.value, config?.syncOptions.exportReportsTo ?? CONST.NETSUITE_REPORTS_APPROVAL_LEVEL.REPORTS_APPROVED_NONE); - // } + if (row.value != config?.accountingMethod) { + Connections.updateNetSuiteAccountingMethod(policyID, row.value, config?.accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH); + } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID)); }, - [config?.syncOptions.exportReportsTo, policyID], + [config?.accountingMethod, policyID], ); return ( diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx index 554291fc9909..89a702ab48f2 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx @@ -21,7 +21,7 @@ function NetSuiteAutoSyncPage({policy, route}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const autoSyncConfig = policy?.connections?.netsuite?.config; const policyID = route.params.policyID ?? '-1'; - const accountingMethod = policy?.connections?.netsuite?.options.config.accountingMehtod; + const accountingMethod = policy?.connections?.netsuite?.options.config.accountingMethod; return ( ; + accountingMethod?: ValueOf; /** Collection of errors coming from BE */ errors?: OnyxCommon.Errors; From b39430260c2bc854680432187b93355bbd8aad8d Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Wed, 6 Nov 2024 04:15:58 +0000 Subject: [PATCH 03/12] Fix lint errors --- src/languages/en.ts | 4 ++-- src/languages/es.ts | 4 ++-- .../netsuite/advanced/NetSuiteAccountingMethodPage.tsx | 2 +- .../netsuite/advanced/NetSuiteAdvancedPage.tsx | 9 ++++++--- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 9c7b94f5ceab..7a0f1b77f855 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -2843,8 +2843,8 @@ const translations = { [CONST.NETSUITE_ACCOUNTING_METHODS.CASH]: 'Cash', }, alternateText: { - [CONST.NETSUITE_ACCOUNTING_METHODS.ACCRUAL]: 'Out of pocket expenses will export when final approved', - [CONST.NETSUITE_ACCOUNTING_METHODS.CASH]: 'Out of pocket expenses will export when paid', + [CONST.NETSUITE_ACCOUNTING_METHODS.ACCRUAL]: 'Out-of-pocket expenses will export when final approved', + [CONST.NETSUITE_ACCOUNTING_METHODS.CASH]: 'Out-of-pocket expenses will export when paid', }, }, exportVendorBillsTo: { diff --git a/src/languages/es.ts b/src/languages/es.ts index 8e9cbb41d47f..3bcd5d33325e 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -2880,8 +2880,8 @@ const translations = { [CONST.NETSUITE_ACCOUNTING_METHODS.CASH]: 'Efectivo', }, alternateText: { - [CONST.NETSUITE_ACCOUNTING_METHODS.ACCRUAL]: 'Los gastos personales se exportarán cuando sean aprobados definitivamente', - [CONST.NETSUITE_ACCOUNTING_METHODS.CASH]: 'Los gastos personales se exportarán cuando sean pagados', + [CONST.NETSUITE_ACCOUNTING_METHODS.ACCRUAL]: 'Los gastos por cuenta propia se exportarán cuando estén aprobados definitivamente', + [CONST.NETSUITE_ACCOUNTING_METHODS.CASH]: 'Los gastos por cuenta propia se exportarán cuando estén pagados', }, }, exportVendorBillsTo: { diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx index 3baf6441612c..c338d428602e 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx @@ -44,7 +44,7 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { const selectExpenseReportApprovalLevel = useCallback( (row: MenuListItem) => { - if (row.value != config?.accountingMethod) { + if (row.value !== config?.accountingMethod) { Connections.updateNetSuiteAccountingMethod(policyID, row.value, config?.accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID)); diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx index bde4386fe3b6..7f386f7af22a 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx @@ -40,7 +40,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { const config = policy?.connections?.netsuite?.options.config; const autoSyncConfig = policy?.connections?.netsuite?.config; - const accountingMehtod = policy?.connections?.netsuite?.options.config.accountingMehtod; + const accountingMethod = policy?.connections?.netsuite?.options.config.accountingMethod; const {payableList} = policy?.connections?.netsuite?.options?.data ?? {}; const selectedReimbursementAccount = useMemo( @@ -68,8 +68,11 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { description: translate('workspace.accounting.autoSync'), onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID)), hintText: (() => { - if (!autoSyncConfig?.autoSync.enabled) return undefined; - return translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMehtod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH}`); + if (!autoSyncConfig?.autoSync.enabled) + { + return undefined; + } + return translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH}`); })(), }, { From 08bfaab83014b45a31c235a3d2da0d0012ff3084 Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Wed, 6 Nov 2024 09:49:20 +0530 Subject: [PATCH 04/12] fix prettier --- .../accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx index 7f386f7af22a..3675e1631759 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx @@ -68,10 +68,9 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { description: translate('workspace.accounting.autoSync'), onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID)), hintText: (() => { - if (!autoSyncConfig?.autoSync.enabled) - { + if (!autoSyncConfig?.autoSync.enabled) { return undefined; - } + } return translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH}`); })(), }, From 2b105915eb4a9529e08b1a36a16ea103a9de8084 Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Thu, 7 Nov 2024 19:12:40 +0000 Subject: [PATCH 05/12] address comments --- .../advanced/NetSuiteAccountingMethodPage.tsx | 16 ++++++++-------- .../netsuite/advanced/NetSuiteAdvancedPage.tsx | 4 ++-- .../netsuite/advanced/NetSuiteAutoSyncPage.tsx | 14 +++++++++----- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx index c338d428602e..ef4825991cd4 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx @@ -23,14 +23,14 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id ?? '-1'; const styles = useThemeStyles(); - const config = policy?.connections?.netsuite.options.config; - const accountingMehtod = config?.accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH; - const data: MenuListItem[] = Object.values(CONST.NETSUITE_ACCOUNTING_METHODS).map((accountingMehtodType) => ({ - value: accountingMehtodType, - text: translate(`workspace.netsuite.advancedConfig.accountingMethods.values.${accountingMehtodType}`), - alternateText: translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMehtodType}`), - keyForList: accountingMehtodType, - isSelected: accountingMehtod === accountingMehtodType, + const config = policy?.connections?.netsuite?.options?.config; + const accountingMethod = config?.accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH; + const data: MenuListItem[] = Object.values(CONST.NETSUITE_ACCOUNTING_METHODS).map((accountingMethodType) => ({ + value: accountingMethodType, + text: translate(`workspace.netsuite.advancedConfig.accountingMethods.values.${accountingMethodType}`), + alternateText: translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMethodType}`), + keyForList: accountingMethodType, + isSelected: accountingMethod === accountingMethodType, })); const headerContent = useMemo( diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx index 3675e1631759..f508f247ba76 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx @@ -64,11 +64,11 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { const menuItems: Array = [ { type: 'menuitem', - title: autoSyncConfig?.autoSync.enabled ? translate('common.enabled') : translate('common.disabled'), + title: autoSyncConfig?.autoSync?.enabled ? translate('common.enabled') : translate('common.disabled'), description: translate('workspace.accounting.autoSync'), onPress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID)), hintText: (() => { - if (!autoSyncConfig?.autoSync.enabled) { + if (!autoSyncConfig?.autoSync?.enabled) { return undefined; } return translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH}`); diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx index 89a702ab48f2..bf5633549db9 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx @@ -21,7 +21,7 @@ function NetSuiteAutoSyncPage({policy, route}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const autoSyncConfig = policy?.connections?.netsuite?.config; const policyID = route.params.policyID ?? '-1'; - const accountingMethod = policy?.connections?.netsuite?.options.config.accountingMethod; + const accountingMethod = policy?.connections?.netsuite?.options?.config?.accountingMethod; return ( - {!!autoSyncConfig?.autoSync.enabled && ( + {!!autoSyncConfig?.autoSync?.enabled && ( Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_ACCOUNTING_METHOD.getRoute(policyID))} /> From 88abfb158ef7860389d708162125a4ca0c0aca80 Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Thu, 7 Nov 2024 19:50:37 +0000 Subject: [PATCH 06/12] Use const from expensify-common --- src/CONST.ts | 5 ----- src/languages/en.ts | 8 ++++---- src/languages/es.ts | 9 +++++---- .../UpdateNetSuiteAccountingMethodParams.ts | 4 ++-- src/libs/actions/connections/NetSuiteCommands.ts | 5 +++-- .../advanced/NetSuiteAccountingMethodPage.tsx | 16 +++++++++------- .../netsuite/advanced/NetSuiteAdvancedPage.tsx | 10 +++++++--- .../netsuite/advanced/NetSuiteAutoSyncPage.tsx | 8 +++++--- src/types/onyx/Policy.ts | 3 ++- 9 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/CONST.ts b/src/CONST.ts index d24a95d8d4e5..3cde3f877300 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -1863,11 +1863,6 @@ const CONST = { NETSUITE_ADD_CUSTOM_SEGMENT_STEP_NAMES: ['1', '2,', '3', '4', '5', '6,'], }, - NETSUITE_ACCOUNTING_METHODS: { - ACCRUAL: 'ACCRUAL', - CASH: 'CASH', - }, - NETSUITE_CUSTOM_FIELD_SUBSTEP_INDEXES: { CUSTOM_LISTS: { CUSTOM_LIST_PICKER: 0, diff --git a/src/languages/en.ts b/src/languages/en.ts index b8fbc507dc05..11ef4c1f86d2 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -2892,12 +2892,12 @@ const translations = { label: 'When to Export', description: 'Choose when to export the expenses:', values: { - [CONST.NETSUITE_ACCOUNTING_METHODS.ACCRUAL]: 'Accrual', - [CONST.NETSUITE_ACCOUNTING_METHODS.CASH]: 'Cash', + [COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.ACCRUAL]: 'Accrual', + [COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH]: 'Cash', }, alternateText: { - [CONST.NETSUITE_ACCOUNTING_METHODS.ACCRUAL]: 'Out-of-pocket expenses will export when final approved', - [CONST.NETSUITE_ACCOUNTING_METHODS.CASH]: 'Out-of-pocket expenses will export when paid', + [COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.ACCRUAL]: 'Out-of-pocket expenses will export when final approved', + [COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH]: 'Out-of-pocket expenses will export when paid', }, }, exportVendorBillsTo: { diff --git a/src/languages/es.ts b/src/languages/es.ts index f8e858f927a8..d00a53d91185 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -1,3 +1,4 @@ +import {CONST as COMMON_CONST} from 'expensify-common'; import CONST from '@src/CONST'; import type en from './en'; import type { @@ -2929,12 +2930,12 @@ const translations = { label: 'Cuándo Exportar', description: 'Elige cuándo exportar los gastos:', values: { - [CONST.NETSUITE_ACCOUNTING_METHODS.ACCRUAL]: 'Devengo', - [CONST.NETSUITE_ACCOUNTING_METHODS.CASH]: 'Efectivo', + [COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.ACCRUAL]: 'Devengo', + [COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH]: 'Efectivo', }, alternateText: { - [CONST.NETSUITE_ACCOUNTING_METHODS.ACCRUAL]: 'Los gastos por cuenta propia se exportarán cuando estén aprobados definitivamente', - [CONST.NETSUITE_ACCOUNTING_METHODS.CASH]: 'Los gastos por cuenta propia se exportarán cuando estén pagados', + [COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.ACCRUAL]: 'Los gastos por cuenta propia se exportarán cuando estén aprobados definitivamente', + [COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH]: 'Los gastos por cuenta propia se exportarán cuando estén pagados', }, }, exportVendorBillsTo: { diff --git a/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts b/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts index 33780e64342d..a8d1145cc921 100644 --- a/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts +++ b/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts @@ -1,9 +1,9 @@ +import {CONST as COMMON_CONST} from 'expensify-common'; import type {ValueOf} from 'type-fest'; -import type CONST from '@src/CONST'; type UpdateNetSuiteAccountingMethodParams = { policyID: string; - accountingMethod: ValueOf; + accountingMethod: ValueOf; }; export default UpdateNetSuiteAccountingMethodParams; diff --git a/src/libs/actions/connections/NetSuiteCommands.ts b/src/libs/actions/connections/NetSuiteCommands.ts index 534e75c3625d..7a8cf7ffebec 100644 --- a/src/libs/actions/connections/NetSuiteCommands.ts +++ b/src/libs/actions/connections/NetSuiteCommands.ts @@ -1,3 +1,4 @@ +import {CONST as COMMON_CONST} from 'expensify-common'; import isObject from 'lodash/isObject'; import type {OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; @@ -937,8 +938,8 @@ function updateNetSuiteExportReportsTo( function updateNetSuiteAccountingMethod( policyID: string, - accountingMethod: ValueOf, - oldAccountingMethod: ValueOf, + accountingMethod: ValueOf, + oldAccountingMethod: ValueOf, ) { const onyxData = updateNetSuiteOnyxData(policyID, CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD, accountingMethod, oldAccountingMethod); diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx index ef4825991cd4..bc7e0c311861 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx @@ -1,3 +1,4 @@ +import {CONST as COMMON_CONST} from 'expensify-common'; import React, {useCallback, useMemo} from 'react'; import {View} from 'react-native'; import type {ValueOf} from 'type-fest'; @@ -13,22 +14,23 @@ import Navigation from '@navigation/Navigation'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import CONST from '@src/CONST'; +import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; type MenuListItem = ListItem & { - value: ValueOf; + value: ValueOf; }; function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id ?? '-1'; const styles = useThemeStyles(); - const config = policy?.connections?.netsuite?.options?.config; - const accountingMethod = config?.accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH; - const data: MenuListItem[] = Object.values(CONST.NETSUITE_ACCOUNTING_METHODS).map((accountingMethodType) => ({ + const config = policy?.connections?.netsuite.options.config; + const accountingMethod = config?.accountingMethod ?? COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH; + const data: MenuListItem[] = Object.values(COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD).map((accountingMethodType) => ({ value: accountingMethodType, - text: translate(`workspace.netsuite.advancedConfig.accountingMethods.values.${accountingMethodType}`), - alternateText: translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMethodType}`), + text: translate(`workspace.netsuite.advancedConfig.accountingMethods.values.${accountingMethodType}` as TranslationPaths), + alternateText: translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMethodType}` as TranslationPaths), keyForList: accountingMethodType, isSelected: accountingMethod === accountingMethodType, })); @@ -45,7 +47,7 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { const selectExpenseReportApprovalLevel = useCallback( (row: MenuListItem) => { if (row.value !== config?.accountingMethod) { - Connections.updateNetSuiteAccountingMethod(policyID, row.value, config?.accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH); + Connections.updateNetSuiteAccountingMethod(policyID, row.value, config?.accountingMethod ?? COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH); } Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID)); }, diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx index f508f247ba76..af3add64f1a6 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx @@ -1,3 +1,4 @@ +import {CONST as COMMON_CONST} from 'expensify-common'; import React, {useMemo} from 'react'; import {View} from 'react-native'; import ConnectionLayout from '@components/ConnectionLayout'; @@ -29,6 +30,7 @@ import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow'; import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; +import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; type MenuItemWithSubscribedSettings = Pick & {subscribedSettings?: string[]}; @@ -38,9 +40,9 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { const styles = useThemeStyles(); const policyID = policy?.id ?? '-1'; - const config = policy?.connections?.netsuite?.options.config; + const config = policy?.connections?.netsuite?.options?.config; const autoSyncConfig = policy?.connections?.netsuite?.config; - const accountingMethod = policy?.connections?.netsuite?.options.config.accountingMethod; + const accountingMethod = policy?.connections?.netsuite?.options?.config?.accountingMethod; const {payableList} = policy?.connections?.netsuite?.options?.data ?? {}; const selectedReimbursementAccount = useMemo( @@ -71,7 +73,9 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { if (!autoSyncConfig?.autoSync?.enabled) { return undefined; } - return translate(`workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMethod ?? CONST.NETSUITE_ACCOUNTING_METHODS.CASH}`); + return translate( + `workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMethod ?? COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH}` as TranslationPaths, + ); })(), }, { diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx index bf5633549db9..59eefa342ec3 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx @@ -1,3 +1,4 @@ +import {CONST as COMMON_CONST} from 'expensify-common'; import React from 'react'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription'; @@ -14,6 +15,7 @@ import withPolicyConnections from '@pages/workspace/withPolicyConnections'; import ToggleSettingOptionRow from '@pages/workspace/workflows/ToggleSettingsOptionRow'; import * as Policy from '@userActions/Policy/Policy'; import CONST from '@src/CONST'; +import type {TranslationPaths} from '@src/languages/types'; import ROUTES from '@src/ROUTES'; function NetSuiteAutoSyncPage({policy, route}: WithPolicyConnectionsProps) { @@ -54,9 +56,9 @@ function NetSuiteAutoSyncPage({policy, route}: WithPolicyConnectionsProps) { {!!autoSyncConfig?.autoSync?.enabled && ( ; + accountingMethod?: ValueOf; /** Collection of errors coming from BE */ errors?: OnyxCommon.Errors; From 1fd9e9f024220f4f21786b3390840e971ad54504 Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Thu, 7 Nov 2024 19:55:46 +0000 Subject: [PATCH 07/12] Fix lint --- src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts | 2 +- src/libs/actions/connections/NetSuiteCommands.ts | 2 +- src/types/onyx/Policy.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts b/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts index a8d1145cc921..814a785b2c64 100644 --- a/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts +++ b/src/libs/API/parameters/UpdateNetSuiteAccountingMethodParams.ts @@ -1,4 +1,4 @@ -import {CONST as COMMON_CONST} from 'expensify-common'; +import type {CONST as COMMON_CONST} from 'expensify-common'; import type {ValueOf} from 'type-fest'; type UpdateNetSuiteAccountingMethodParams = { diff --git a/src/libs/actions/connections/NetSuiteCommands.ts b/src/libs/actions/connections/NetSuiteCommands.ts index 7a8cf7ffebec..bf5b2be4b4a0 100644 --- a/src/libs/actions/connections/NetSuiteCommands.ts +++ b/src/libs/actions/connections/NetSuiteCommands.ts @@ -1,4 +1,4 @@ -import {CONST as COMMON_CONST} from 'expensify-common'; +import type {CONST as COMMON_CONST} from 'expensify-common'; import isObject from 'lodash/isObject'; import type {OnyxUpdate} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index c2c3e2d33120..88e41aed5bb4 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -1,4 +1,4 @@ -import {CONST as COMMON_CONST} from 'expensify-common'; +import type {CONST as COMMON_CONST} from 'expensify-common'; import type {ValueOf} from 'type-fest'; import type CONST from '@src/CONST'; import type {Country} from '@src/CONST'; From 7040eec34a28a0bba82b48146c83fa3f1456898c Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Fri, 8 Nov 2024 18:05:38 +0530 Subject: [PATCH 08/12] add optional chaining --- .../netsuite/advanced/NetSuiteAccountingMethodPage.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx index bc7e0c311861..6d96b9d72301 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx @@ -25,7 +25,7 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { const {translate} = useLocalize(); const policyID = policy?.id ?? '-1'; const styles = useThemeStyles(); - const config = policy?.connections?.netsuite.options.config; + const config = policy?.connections?.netsuite?.options?.config; const accountingMethod = config?.accountingMethod ?? COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH; const data: MenuListItem[] = Object.values(COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD).map((accountingMethodType) => ({ value: accountingMethodType, From 96208e2dba8e4450adc148fdf9b91591fd76993e Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Mon, 11 Nov 2024 09:15:53 +0000 Subject: [PATCH 09/12] Apply offline feedback --- .../advanced/NetSuiteAccountingMethodPage.tsx | 2 ++ .../advanced/NetSuiteAdvancedPage.tsx | 6 ++++- .../advanced/NetSuiteAutoSyncPage.tsx | 24 +++++++++++-------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx index 6d96b9d72301..0b6055f096c3 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx @@ -10,6 +10,7 @@ import Text from '@components/Text'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import * as Connections from '@libs/actions/connections/NetSuiteCommands'; +import {settingsPendingAction} from '@libs/PolicyUtils'; import Navigation from '@navigation/Navigation'; import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections'; import withPolicyConnections from '@pages/workspace/withPolicyConnections'; @@ -68,6 +69,7 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID))} connectionName={CONST.POLICY.CONNECTIONS.NAME.NETSUITE} + pendingAction={settingsPendingAction([CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD], config?.pendingFields)} /> ); } diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx index af3add64f1a6..1d3d54e12ec3 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx @@ -77,6 +77,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { `workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMethod ?? COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH}` as TranslationPaths, ); })(), + subscribedSettings: [CONST.NETSUITE_CONFIG.AUTO_SYNC], }, { type: 'divider', @@ -260,7 +261,10 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { return ( {!!autoSyncConfig?.autoSync?.enabled && ( - Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_ACCOUNTING_METHOD.getRoute(policyID))} - /> + + Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_ACCOUNTING_METHOD.getRoute(policyID))} + /> + )} From 357da492c0ff0ddfee879e8747624d04037f7b5f Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Wed, 13 Nov 2024 11:19:58 +0000 Subject: [PATCH 10/12] Fix offline state --- .../advanced/NetSuiteAccountingMethodPage.tsx | 6 +- .../advanced/NetSuiteAdvancedPage.tsx | 9 +- .../advanced/NetSuiteAutoSyncPage.tsx | 12 +- .../workspace/accounting/netsuite/utils.ts | 427 ++++++++++++++---- 4 files changed, 368 insertions(+), 86 deletions(-) diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx index 0b6055f096c3..4a75c261c7cf 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx @@ -27,6 +27,7 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { const policyID = policy?.id ?? '-1'; const styles = useThemeStyles(); const config = policy?.connections?.netsuite?.options?.config; + const autoSyncConfig = policy?.connections?.netsuite?.config; const accountingMethod = config?.accountingMethod ?? COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH; const data: MenuListItem[] = Object.values(COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD).map((accountingMethodType) => ({ value: accountingMethodType, @@ -69,7 +70,10 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID))} connectionName={CONST.POLICY.CONNECTIONS.NAME.NETSUITE} - pendingAction={settingsPendingAction([CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD], config?.pendingFields)} + pendingAction={ + settingsPendingAction([CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD], config?.pendingFields) ?? + settingsPendingAction([CONST.NETSUITE_CONFIG.AUTO_SYNC], autoSyncConfig?.pendingFields) + } /> ); } diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx index 1d3d54e12ec3..c6da14d9efd1 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAdvancedPage.tsx @@ -77,7 +77,7 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { `workspace.netsuite.advancedConfig.accountingMethods.alternateText.${accountingMethod ?? COMMON_CONST.INTEGRATIONS.ACCOUNTING_METHOD.CASH}` as TranslationPaths, ); })(), - subscribedSettings: [CONST.NETSUITE_CONFIG.AUTO_SYNC], + subscribedSettings: [CONST.NETSUITE_CONFIG.AUTO_SYNC, CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD], }, { type: 'divider', @@ -261,10 +261,9 @@ function NetSuiteAdvancedPage({policy}: WithPolicyConnectionsProps) { return ( Policy.clearNetSuiteAutoSyncErrorField(policyID)} onToggle={(isEnabled) => Connections.updateNetSuiteAutoSync(policyID, isEnabled)} - pendingAction={settingsPendingAction([CONST.NETSUITE_CONFIG.AUTO_SYNC], autoSyncConfig?.pendingFields)} + pendingAction={ + settingsPendingAction([CONST.NETSUITE_CONFIG.AUTO_SYNC], autoSyncConfig?.pendingFields) ?? + settingsPendingAction([CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD], config?.pendingFields) + } errors={ErrorUtils.getLatestErrorField(autoSyncConfig, CONST.NETSUITE_CONFIG.AUTO_SYNC)} /> {!!autoSyncConfig?.autoSync?.enabled && ( - + subsidiary.internalID === netsuiteConfig?.subsidiaryID); -function shouldHideNonReimbursableJournalPostingAccount(isReimbursable: boolean, config?: NetSuiteConnectionConfig) { - return isReimbursable || config?.nonreimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY; -} + const getBackToAfterWorkspaceUpgradeRouteForQBD = () => { + if (integrationToDisconnect) { + return ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting); + } + if (isSmallScreenWidth) { + return ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_SETUP_REQUIRED_DEVICE_MODAL.getRoute(policyID); + } + return ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_SETUP_MODAL.getRoute(policyID); + }; -function shouldHideReimbursableJournalPostingAccount(isReimbursable: boolean, config?: NetSuiteConnectionConfig) { - return !isReimbursable || config?.reimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY; + switch (connectionName) { + case CONST.POLICY.CONNECTIONS.NAME.QBO: + return { + title: translate('workspace.accounting.qbo'), + icon: Expensicons.QBOSquare, + setupConnectionFlow: ( + + ), + onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_IMPORT.getRoute(policyID)), + subscribedImportSettings: [ + CONST.QUICKBOOKS_CONFIG.ENABLE_NEW_CATEGORIES, + CONST.QUICKBOOKS_CONFIG.SYNC_CLASSES, + CONST.QUICKBOOKS_CONFIG.SYNC_CUSTOMERS, + CONST.QUICKBOOKS_CONFIG.SYNC_LOCATIONS, + CONST.QUICKBOOKS_CONFIG.SYNC_TAX, + ], + onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT.getRoute(policyID)), + subscribedExportSettings: [ + CONST.QUICKBOOKS_CONFIG.EXPORT, + CONST.QUICKBOOKS_CONFIG.EXPORT_DATE, + CONST.QUICKBOOKS_CONFIG.REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, + CONST.QUICKBOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT, + CONST.QUICKBOOKS_CONFIG.RECEIVABLE_ACCOUNT, + CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, + CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_EXPENSE_ACCOUNT, + ...(qboConfig?.nonReimbursableExpensesExportDestination === CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.VENDOR_BILL + ? [CONST.QUICKBOOKS_CONFIG.AUTO_CREATE_VENDOR] + : []), + ...(qboConfig?.nonReimbursableExpensesExportDestination === CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.VENDOR_BILL && + policy?.connections?.quickbooksOnline?.config?.autoCreateVendor + ? [CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR] + : []), + ], + onCardReconciliationPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_CARD_RECONCILIATION.getRoute(policyID, CONST.POLICY.CONNECTIONS.ROUTE.QBO)), + onAdvancedPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_ADVANCED.getRoute(policyID)), + subscribedAdvancedSettings: [ + CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID, + CONST.QUICKBOOKS_CONFIG.AUTO_SYNC, + CONST.QUICKBOOKS_CONFIG.SYNC_PEOPLE, + CONST.QUICKBOOKS_CONFIG.AUTO_CREATE_VENDOR, + ...(qboConfig?.collectionAccountID ? [CONST.QUICKBOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID, CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID] : []), + ], + }; + case CONST.POLICY.CONNECTIONS.NAME.XERO: + return { + title: translate('workspace.accounting.xero'), + icon: Expensicons.XeroSquare, + setupConnectionFlow: ( + + ), + onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_IMPORT.getRoute(policyID)), + subscribedImportSettings: [ + CONST.XERO_CONFIG.ENABLE_NEW_CATEGORIES, + CONST.XERO_CONFIG.IMPORT_TRACKING_CATEGORIES, + CONST.XERO_CONFIG.IMPORT_CUSTOMERS, + CONST.XERO_CONFIG.IMPORT_TAX_RATES, + ...getTrackingCategories(policy).map((category) => `${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${category.id}`), + ], + onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)), + subscribedExportSettings: [CONST.XERO_CONFIG.EXPORTER, CONST.XERO_CONFIG.BILL_DATE, CONST.XERO_CONFIG.BILL_STATUS, CONST.XERO_CONFIG.NON_REIMBURSABLE_ACCOUNT], + onCardReconciliationPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_CARD_RECONCILIATION.getRoute(policyID, CONST.POLICY.CONNECTIONS.ROUTE.XERO)), + onAdvancedPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.getRoute(policyID)), + subscribedAdvancedSettings: [ + CONST.XERO_CONFIG.ENABLED, + CONST.XERO_CONFIG.SYNC_REIMBURSED_REPORTS, + CONST.XERO_CONFIG.REIMBURSEMENT_ACCOUNT_ID, + CONST.XERO_CONFIG.INVOICE_COLLECTIONS_ACCOUNT_ID, + ], + pendingFields: policy?.connections?.xero?.config?.pendingFields, + errorFields: policy?.connections?.xero?.config?.errorFields, + }; + case CONST.POLICY.CONNECTIONS.NAME.NETSUITE: + return { + title: translate('workspace.accounting.netsuite'), + icon: Expensicons.NetSuiteSquare, + setupConnectionFlow: ( + + ), + onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_IMPORT.getRoute(policyID)), + subscribedImportSettings: [ + ...CONST.NETSUITE_CONFIG.IMPORT_FIELDS, + CONST.NETSUITE_CONFIG.SYNC_OPTIONS.CUSTOMER_MAPPINGS.CUSTOMERS, + CONST.NETSUITE_CONFIG.SYNC_OPTIONS.CUSTOMER_MAPPINGS.JOBS, + CONST.NETSUITE_CONFIG.SYNC_OPTIONS.CROSS_SUBSIDIARY_CUSTOMERS, + ...(canUseTaxNetSuite(canUseNetSuiteUSATax, netsuiteSelectedSubsidiary?.country) ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_TAX] : []), + ...getImportCustomFieldsSettings(CONST.NETSUITE_CONFIG.IMPORT_CUSTOM_FIELDS.CUSTOM_SEGMENTS, netsuiteConfig), + ...getImportCustomFieldsSettings(CONST.NETSUITE_CONFIG.IMPORT_CUSTOM_FIELDS.CUSTOM_LISTS, netsuiteConfig), + ], + onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_EXPORT.getRoute(policyID)), + subscribedExportSettings: [ + CONST.NETSUITE_CONFIG.EXPORTER, + CONST.NETSUITE_CONFIG.EXPORT_DATE, + CONST.NETSUITE_CONFIG.REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, + ...(!shouldHideReimbursableDefaultVendor(true, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.DEFAULT_VENDOR] : []), + ...(!shouldHideNonReimbursableJournalPostingAccount(true, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.PAYABLE_ACCT] : []), + ...(!shouldHideReimbursableJournalPostingAccount(true, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.REIMBURSABLE_PAYABLE_ACCOUNT] : []), + ...(!shouldHideJournalPostingPreference(true, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.JOURNAL_POSTING_PREFERENCE] : []), + CONST.NETSUITE_CONFIG.NON_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, + ...(!shouldHideReimbursableDefaultVendor(false, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.DEFAULT_VENDOR] : []), + ...(!shouldHideNonReimbursableJournalPostingAccount(false, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.PAYABLE_ACCT] : []), + ...(!shouldHideReimbursableJournalPostingAccount(false, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.REIMBURSABLE_PAYABLE_ACCOUNT] : []), + ...(!shouldHideJournalPostingPreference(false, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.JOURNAL_POSTING_PREFERENCE] : []), + CONST.NETSUITE_CONFIG.RECEIVABLE_ACCOUNT, + CONST.NETSUITE_CONFIG.INVOICE_ITEM_PREFERENCE, + ...(shouldShowInvoiceItemMenuItem(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.INVOICE_ITEM] : []), + ...(!shouldHideProvincialTaxPostingAccountSelect(netsuiteSelectedSubsidiary, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.PROVINCIAL_TAX_POSTING_ACCOUNT] : []), + ...(!shouldHideTaxPostingAccountSelect(canUseNetSuiteUSATax, netsuiteSelectedSubsidiary, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.TAX_POSTING_ACCOUNT] : []), + ...(!shouldHideExportForeignCurrencyAmount(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.ALLOW_FOREIGN_CURRENCY] : []), + CONST.NETSUITE_CONFIG.EXPORT_TO_NEXT_OPEN_PERIOD, + ], + onCardReconciliationPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_CARD_RECONCILIATION.getRoute(policyID, CONST.POLICY.CONNECTIONS.ROUTE.NETSUITE)), + onAdvancedPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_ADVANCED.getRoute(policyID)), + subscribedAdvancedSettings: [ + CONST.NETSUITE_CONFIG.AUTO_SYNC, + CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD, + ...(!shouldHideReimbursedReportsSection(netsuiteConfig) + ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_REIMBURSED_REPORTS, CONST.NETSUITE_CONFIG.REIMBURSEMENT_ACCOUNT_ID, CONST.NETSUITE_CONFIG.COLLECTION_ACCOUNT] + : []), + CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_PEOPLE, + CONST.NETSUITE_CONFIG.AUTO_CREATE_ENTITIES, + CONST.NETSUITE_CONFIG.SYNC_OPTIONS.ENABLE_NEW_CATEGORIES, + ...(!shouldHideReportsExportTo(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.EXPORT_REPORTS_TO] : []), + ...(!shouldHideExportVendorBillsTo(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.EXPORT_VENDOR_BILLS_TO] : []), + ...(!shouldHideExportJournalsTo(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.EXPORT_JOURNALS_TO] : []), + CONST.NETSUITE_CONFIG.APPROVAL_ACCOUNT, + CONST.NETSUITE_CONFIG.CUSTOM_FORM_ID_ENABLED, + ...(!shouldHideCustomFormIDOptions(netsuiteConfig) + ? [CONST.NETSUITE_CONFIG.CUSTOM_FORM_ID_TYPE.REIMBURSABLE, CONST.NETSUITE_CONFIG.CUSTOM_FORM_ID_TYPE.NON_REIMBURSABLE] + : []), + ], + workspaceUpgradeNavigationDetails: { + integrationAlias: CONST.UPGRADE_FEATURE_INTRO_MAPPING.netsuite.alias, + backToAfterWorkspaceUpgradeRoute: integrationToDisconnect + ? ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting) + : ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID), + }, + pendingFields: {...netsuiteConfig?.pendingFields, ...policy?.connections?.netsuite?.config?.pendingFields, ...policy?.connections?.netsuite?.options?.config?.pendingFields}, + errorFields: {...netsuiteConfig?.errorFields, ...policy?.connections?.netsuite?.config?.errorFields, ...policy?.connections?.netsuite?.options?.config?.errorFields}, + }; + case CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT: + return { + title: translate('workspace.accounting.intacct'), + icon: Expensicons.IntacctSquare, + setupConnectionFlow: ( + + ), + onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_IMPORT.getRoute(policyID)), + subscribedImportSettings: [ + CONST.SAGE_INTACCT_CONFIG.SYNC_ITEMS, + ...Object.values(CONST.SAGE_INTACCT_CONFIG.MAPPINGS), + CONST.SAGE_INTACCT_CONFIG.TAX, + ...(policy?.connections?.intacct?.config?.mappings?.dimensions ?? []).map((dimension) => `${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${dimension.dimension}`), + ], + onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID)), + subscribedExportSettings: [ + CONST.SAGE_INTACCT_CONFIG.EXPORTER, + CONST.SAGE_INTACCT_CONFIG.EXPORT_DATE, + CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE, + CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, + CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE, + CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_ACCOUNT, + policy?.connections?.intacct?.config?.export?.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL + ? CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_VENDOR + : CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, + ], + onCardReconciliationPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_CARD_RECONCILIATION.getRoute(policyID, CONST.POLICY.CONNECTIONS.ROUTE.SAGE_INTACCT)), + onAdvancedPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_ADVANCED.getRoute(policyID)), + subscribedAdvancedSettings: [ + CONST.SAGE_INTACCT_CONFIG.AUTO_SYNC_ENABLED, + CONST.SAGE_INTACCT_CONFIG.IMPORT_EMPLOYEES, + CONST.SAGE_INTACCT_CONFIG.APPROVAL_MODE, + CONST.SAGE_INTACCT_CONFIG.SYNC_REIMBURSED_REPORTS, + CONST.SAGE_INTACCT_CONFIG.REIMBURSEMENT_ACCOUNT_ID, + ], + workspaceUpgradeNavigationDetails: { + integrationAlias: CONST.UPGRADE_FEATURE_INTRO_MAPPING.intacct.alias, + backToAfterWorkspaceUpgradeRoute: integrationToDisconnect + ? ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting) + : ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES.getRoute(policyID), + }, + pendingFields: policy?.connections?.intacct?.config?.pendingFields, + errorFields: policy?.connections?.intacct?.config?.errorFields, + }; + case CONST.POLICY.CONNECTIONS.NAME.QBD: + return { + title: translate('workspace.accounting.qbd'), + icon: Expensicons.QBDSquare, + setupConnectionFlow: ( + + ), + onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_IMPORT.getRoute(policyID)), + onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT.getRoute(policyID)), + onCardReconciliationPagePress: () => {}, + onAdvancedPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_DESKTOP_ADVANCED.getRoute(policyID)), + subscribedImportSettings: [ + CONST.QUICKBOOKS_DESKTOP_CONFIG.ENABLE_NEW_CATEGORIES, + CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CLASSES, + CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CUSTOMERS, + CONST.QUICKBOOKS_DESKTOP_CONFIG.IMPORT_ITEMS, + ], + subscribedExportSettings: [ + CONST.QUICKBOOKS_DESKTOP_CONFIG.EXPORT_DATE, + CONST.QUICKBOOKS_DESKTOP_CONFIG.EXPORTER, + CONST.QUICKBOOKS_DESKTOP_CONFIG.REIMBURSABLE, + CONST.QUICKBOOKS_DESKTOP_CONFIG.REIMBURSABLE_ACCOUNT, + CONST.QUICKBOOKS_DESKTOP_CONFIG.MARK_CHECKS_TO_BE_PRINTED, + CONST.QUICKBOOKS_DESKTOP_CONFIG.NON_REIMBURSABLE, + CONST.QUICKBOOKS_DESKTOP_CONFIG.NON_REIMBURSABLE_ACCOUNT, + CONST.QUICKBOOKS_DESKTOP_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR, + CONST.QUICKBOOKS_DESKTOP_CONFIG.SHOULD_AUTO_CREATE_VENDOR, + ], + subscribedAdvancedSettings: [CONST.QUICKBOOKS_DESKTOP_CONFIG.SHOULD_AUTO_CREATE_VENDOR, CONST.QUICKBOOKS_DESKTOP_CONFIG.AUTO_SYNC], + workspaceUpgradeNavigationDetails: { + integrationAlias: CONST.UPGRADE_FEATURE_INTRO_MAPPING.quickbooksDesktop.alias, + backToAfterWorkspaceUpgradeRoute: getBackToAfterWorkspaceUpgradeRouteForQBD(), + }, + }; + default: + return undefined; + } } -function shouldHideJournalPostingPreference(isReimbursable: boolean, config?: NetSuiteConnectionConfig) { - return config?.[exportExpensesDestinationSettingName(isReimbursable)] !== CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY; -} +function getSynchronizationErrorMessage( + policy: OnyxEntry, + connectionName: PolicyConnectionName, + isSyncInProgress: boolean, + translate: LocaleContextProps['translate'], + styles?: ThemeStyles, +): React.ReactNode | undefined { + if (isAuthenticationError(policy, connectionName)) { + return ( + + {translate('workspace.common.authenticationError', {connectionName: CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[connectionName]})} + {connectionName in CONST.POLICY.CONNECTIONS.AUTH_HELP_LINKS && ( + + {translate('workspace.common.learnMore')} + + )} + + ); + } -function shouldShowInvoiceItemMenuItem(config?: NetSuiteConnectionConfig) { - return config?.invoiceItemPreference === CONST.NETSUITE_INVOICE_ITEM_PREFERENCE.SELECT; -} + const syncError = Localize.translateLocal('workspace.accounting.syncError', {connectionName}); -function shouldHideProvincialTaxPostingAccountSelect(selectedSubsidiary?: NetSuiteSubsidiary, config?: NetSuiteConnectionConfig) { - return !!config?.suiteTaxEnabled || !config?.syncOptions.syncTax || !canUseProvincialTaxNetSuite(selectedSubsidiary?.country); -} + const connection = policy?.connections?.[connectionName]; + if (isSyncInProgress || isEmptyObject(connection?.lastSync) || connection?.lastSync?.isSuccessful !== false || !connection?.lastSync?.errorDate) { + return; + } -function shouldHideTaxPostingAccountSelect(canUseNetSuiteUSATax?: boolean, selectedSubsidiary?: NetSuiteSubsidiary, config?: NetSuiteConnectionConfig) { - return !!config?.suiteTaxEnabled || !config?.syncOptions.syncTax || !canUseTaxNetSuite(canUseNetSuiteUSATax, selectedSubsidiary?.country); + return `${syncError} ("${connection?.lastSync?.errorMessage}")`; } -function shouldHideExportForeignCurrencyAmount(config?: NetSuiteConnectionConfig) { - return ( - config?.reimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT && - config?.nonreimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT - ); -} +function getQBDReimbursableAccounts( + quickbooksDesktop?: Connections[typeof CONST.POLICY.CONNECTIONS.NAME.QBD], + reimbursable?: QBDReimbursableExportAccountType | QBDNonReimbursableExportAccountType, +) { + const {bankAccounts, journalEntryAccounts, payableAccounts, creditCardAccounts} = quickbooksDesktop?.data ?? {}; -function getImportCustomFieldsSettings(importField: ValueOf, config?: NetSuiteConnectionConfig) { - const data = config?.syncOptions?.[importField] ?? []; - return data.map((_, index) => `${importField}_${index}`); + let accounts: Account[]; + switch (reimbursable ?? quickbooksDesktop?.config?.export.reimbursable) { + case CONST.QUICKBOOKS_DESKTOP_REIMBURSABLE_ACCOUNT_TYPE.CHECK: + accounts = bankAccounts ?? []; + break; + case CONST.QUICKBOOKS_DESKTOP_REIMBURSABLE_ACCOUNT_TYPE.JOURNAL_ENTRY: + // Journal entry accounts include payable accounts, other current liabilities, and other current assets + accounts = [...(payableAccounts ?? []), ...(journalEntryAccounts ?? [])]; + break; + case CONST.QUICKBOOKS_DESKTOP_REIMBURSABLE_ACCOUNT_TYPE.VENDOR_BILL: + accounts = payableAccounts ?? []; + break; + case CONST.QUICKBOOKS_DESKTOP_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.CREDIT_CARD: + accounts = creditCardAccounts ?? []; + break; + default: + accounts = []; + } + return accounts; } -export { - shouldHideReimbursedReportsSection, - shouldHideReportsExportTo, - shouldHideExportVendorBillsTo, - shouldHideExportJournalsTo, - shouldHideCustomFormIDOptions, - exportExpensesDestinationSettingName, - shouldHideReimbursableDefaultVendor, - shouldHideNonReimbursableJournalPostingAccount, - shouldHideReimbursableJournalPostingAccount, - shouldHideJournalPostingPreference, - shouldShowInvoiceItemMenuItem, - shouldHideProvincialTaxPostingAccountSelect, - shouldHideTaxPostingAccountSelect, - shouldHideExportForeignCurrencyAmount, - getImportCustomFieldsSettings, -}; +export {getAccountingIntegrationData, getSynchronizationErrorMessage, getQBDReimbursableAccounts}; From 06f1170cf0eebf77ac291a7e9a4cbbbb3806e36e Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Wed, 13 Nov 2024 11:22:13 +0000 Subject: [PATCH 11/12] fix wrong file push --- .../workspace/accounting/netsuite/utils.ts | 427 ++++-------------- src/pages/workspace/accounting/utils.tsx | 5 +- 2 files changed, 81 insertions(+), 351 deletions(-) diff --git a/src/pages/workspace/accounting/netsuite/utils.ts b/src/pages/workspace/accounting/netsuite/utils.ts index 3ed4d6077417..6ee461504053 100644 --- a/src/pages/workspace/accounting/netsuite/utils.ts +++ b/src/pages/workspace/accounting/netsuite/utils.ts @@ -1,363 +1,92 @@ -import React from 'react'; -import type {OnyxEntry} from 'react-native-onyx'; -import ConnectToNetSuiteFlow from '@components/ConnectToNetSuiteFlow'; -import ConnectToQuickbooksDesktopFlow from '@components/ConnectToQuickbooksDesktopFlow'; -import ConnectToQuickbooksOnlineFlow from '@components/ConnectToQuickbooksOnlineFlow'; -import ConnectToSageIntacctFlow from '@components/ConnectToSageIntacctFlow'; -import ConnectToXeroFlow from '@components/ConnectToXeroFlow'; -import * as Expensicons from '@components/Icon/Expensicons'; -import type {LocaleContextProps} from '@components/LocaleContextProvider'; -import Text from '@components/Text'; -import TextLink from '@components/TextLink'; -import {isAuthenticationError} from '@libs/actions/connections'; -import * as Localize from '@libs/Localize'; -import {canUseTaxNetSuite} from '@libs/PolicyUtils'; -import Navigation from '@navigation/Navigation'; -import type {ThemeStyles} from '@styles/index'; -import {getTrackingCategories} from '@userActions/connections/Xero'; +import type {ValueOf} from 'type-fest'; +import {canUseProvincialTaxNetSuite, canUseTaxNetSuite} from '@libs/PolicyUtils'; import CONST from '@src/CONST'; -import ROUTES from '@src/ROUTES'; -import type {Policy} from '@src/types/onyx'; -import type {Account, ConnectionName, Connections, PolicyConnectionName, QBDNonReimbursableExportAccountType, QBDReimbursableExportAccountType} from '@src/types/onyx/Policy'; -import {isEmptyObject} from '@src/types/utils/EmptyObject'; -import { - getImportCustomFieldsSettings, - shouldHideCustomFormIDOptions, - shouldHideExportForeignCurrencyAmount, - shouldHideExportJournalsTo, - shouldHideExportVendorBillsTo, - shouldHideJournalPostingPreference, - shouldHideNonReimbursableJournalPostingAccount, - shouldHideProvincialTaxPostingAccountSelect, - shouldHideReimbursableDefaultVendor, - shouldHideReimbursableJournalPostingAccount, - shouldHideReimbursedReportsSection, - shouldHideReportsExportTo, - shouldHideTaxPostingAccountSelect, - shouldShowInvoiceItemMenuItem, -} from './netsuite/utils'; -import type {AccountingIntegration} from './types'; +import type {NetSuiteConnectionConfig, NetSuiteSubsidiary} from '@src/types/onyx/Policy'; + +function shouldHideReimbursedReportsSection(config?: NetSuiteConnectionConfig) { + return config?.reimbursableExpensesExportDestination === CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY; +} + +function shouldHideReportsExportTo(config?: NetSuiteConnectionConfig) { + return config?.reimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT; +} + +function shouldHideExportVendorBillsTo(config?: NetSuiteConnectionConfig) { + return ( + config?.reimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.VENDOR_BILL && + config?.nonreimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.VENDOR_BILL + ); +} + +function shouldHideExportJournalsTo(config?: NetSuiteConnectionConfig) { + return ( + config?.reimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY && + config?.nonreimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY + ); +} + +function shouldHideCustomFormIDOptions(config?: NetSuiteConnectionConfig) { + return !config?.customFormIDOptions?.enabled; +} + +function exportExpensesDestinationSettingName(isReimbursable: boolean) { + return isReimbursable ? CONST.NETSUITE_CONFIG.REIMBURSABLE_EXPENSES_EXPORT_DESTINATION : CONST.NETSUITE_CONFIG.NON_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION; +} -function getAccountingIntegrationData( - connectionName: PolicyConnectionName, - policyID: string, - translate: LocaleContextProps['translate'], - policy?: Policy, - key?: number, - integrationToDisconnect?: ConnectionName, - shouldDisconnectIntegrationBeforeConnecting?: boolean, - canUseNetSuiteUSATax?: boolean, - isSmallScreenWidth?: boolean, -): AccountingIntegration | undefined { - const qboConfig = policy?.connections?.quickbooksOnline?.config; - const netsuiteConfig = policy?.connections?.netsuite?.options?.config; - const netsuiteSelectedSubsidiary = (policy?.connections?.netsuite?.options?.data?.subsidiaryList ?? []).find((subsidiary) => subsidiary.internalID === netsuiteConfig?.subsidiaryID); +function shouldHideReimbursableDefaultVendor(isReimbursable: boolean, config?: NetSuiteConnectionConfig) { + return isReimbursable || config?.nonreimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.VENDOR_BILL; +} - const getBackToAfterWorkspaceUpgradeRouteForQBD = () => { - if (integrationToDisconnect) { - return ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting); - } - if (isSmallScreenWidth) { - return ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_SETUP_REQUIRED_DEVICE_MODAL.getRoute(policyID); - } - return ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_SETUP_MODAL.getRoute(policyID); - }; +function shouldHideNonReimbursableJournalPostingAccount(isReimbursable: boolean, config?: NetSuiteConnectionConfig) { + return isReimbursable || config?.nonreimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY; +} - switch (connectionName) { - case CONST.POLICY.CONNECTIONS.NAME.QBO: - return { - title: translate('workspace.accounting.qbo'), - icon: Expensicons.QBOSquare, - setupConnectionFlow: ( - - ), - onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_IMPORT.getRoute(policyID)), - subscribedImportSettings: [ - CONST.QUICKBOOKS_CONFIG.ENABLE_NEW_CATEGORIES, - CONST.QUICKBOOKS_CONFIG.SYNC_CLASSES, - CONST.QUICKBOOKS_CONFIG.SYNC_CUSTOMERS, - CONST.QUICKBOOKS_CONFIG.SYNC_LOCATIONS, - CONST.QUICKBOOKS_CONFIG.SYNC_TAX, - ], - onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_ONLINE_EXPORT.getRoute(policyID)), - subscribedExportSettings: [ - CONST.QUICKBOOKS_CONFIG.EXPORT, - CONST.QUICKBOOKS_CONFIG.EXPORT_DATE, - CONST.QUICKBOOKS_CONFIG.REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, - CONST.QUICKBOOKS_CONFIG.REIMBURSABLE_EXPENSES_ACCOUNT, - CONST.QUICKBOOKS_CONFIG.RECEIVABLE_ACCOUNT, - CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, - CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_EXPENSE_ACCOUNT, - ...(qboConfig?.nonReimbursableExpensesExportDestination === CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.VENDOR_BILL - ? [CONST.QUICKBOOKS_CONFIG.AUTO_CREATE_VENDOR] - : []), - ...(qboConfig?.nonReimbursableExpensesExportDestination === CONST.QUICKBOOKS_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.VENDOR_BILL && - policy?.connections?.quickbooksOnline?.config?.autoCreateVendor - ? [CONST.QUICKBOOKS_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR] - : []), - ], - onCardReconciliationPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_CARD_RECONCILIATION.getRoute(policyID, CONST.POLICY.CONNECTIONS.ROUTE.QBO)), - onAdvancedPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_ONLINE_ADVANCED.getRoute(policyID)), - subscribedAdvancedSettings: [ - CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID, - CONST.QUICKBOOKS_CONFIG.AUTO_SYNC, - CONST.QUICKBOOKS_CONFIG.SYNC_PEOPLE, - CONST.QUICKBOOKS_CONFIG.AUTO_CREATE_VENDOR, - ...(qboConfig?.collectionAccountID ? [CONST.QUICKBOOKS_CONFIG.REIMBURSEMENT_ACCOUNT_ID, CONST.QUICKBOOKS_CONFIG.COLLECTION_ACCOUNT_ID] : []), - ], - }; - case CONST.POLICY.CONNECTIONS.NAME.XERO: - return { - title: translate('workspace.accounting.xero'), - icon: Expensicons.XeroSquare, - setupConnectionFlow: ( - - ), - onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_IMPORT.getRoute(policyID)), - subscribedImportSettings: [ - CONST.XERO_CONFIG.ENABLE_NEW_CATEGORIES, - CONST.XERO_CONFIG.IMPORT_TRACKING_CATEGORIES, - CONST.XERO_CONFIG.IMPORT_CUSTOMERS, - CONST.XERO_CONFIG.IMPORT_TAX_RATES, - ...getTrackingCategories(policy).map((category) => `${CONST.XERO_CONFIG.TRACKING_CATEGORY_PREFIX}${category.id}`), - ], - onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_EXPORT.getRoute(policyID)), - subscribedExportSettings: [CONST.XERO_CONFIG.EXPORTER, CONST.XERO_CONFIG.BILL_DATE, CONST.XERO_CONFIG.BILL_STATUS, CONST.XERO_CONFIG.NON_REIMBURSABLE_ACCOUNT], - onCardReconciliationPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_CARD_RECONCILIATION.getRoute(policyID, CONST.POLICY.CONNECTIONS.ROUTE.XERO)), - onAdvancedPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_XERO_ADVANCED.getRoute(policyID)), - subscribedAdvancedSettings: [ - CONST.XERO_CONFIG.ENABLED, - CONST.XERO_CONFIG.SYNC_REIMBURSED_REPORTS, - CONST.XERO_CONFIG.REIMBURSEMENT_ACCOUNT_ID, - CONST.XERO_CONFIG.INVOICE_COLLECTIONS_ACCOUNT_ID, - ], - pendingFields: policy?.connections?.xero?.config?.pendingFields, - errorFields: policy?.connections?.xero?.config?.errorFields, - }; - case CONST.POLICY.CONNECTIONS.NAME.NETSUITE: - return { - title: translate('workspace.accounting.netsuite'), - icon: Expensicons.NetSuiteSquare, - setupConnectionFlow: ( - - ), - onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_IMPORT.getRoute(policyID)), - subscribedImportSettings: [ - ...CONST.NETSUITE_CONFIG.IMPORT_FIELDS, - CONST.NETSUITE_CONFIG.SYNC_OPTIONS.CUSTOMER_MAPPINGS.CUSTOMERS, - CONST.NETSUITE_CONFIG.SYNC_OPTIONS.CUSTOMER_MAPPINGS.JOBS, - CONST.NETSUITE_CONFIG.SYNC_OPTIONS.CROSS_SUBSIDIARY_CUSTOMERS, - ...(canUseTaxNetSuite(canUseNetSuiteUSATax, netsuiteSelectedSubsidiary?.country) ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_TAX] : []), - ...getImportCustomFieldsSettings(CONST.NETSUITE_CONFIG.IMPORT_CUSTOM_FIELDS.CUSTOM_SEGMENTS, netsuiteConfig), - ...getImportCustomFieldsSettings(CONST.NETSUITE_CONFIG.IMPORT_CUSTOM_FIELDS.CUSTOM_LISTS, netsuiteConfig), - ], - onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_EXPORT.getRoute(policyID)), - subscribedExportSettings: [ - CONST.NETSUITE_CONFIG.EXPORTER, - CONST.NETSUITE_CONFIG.EXPORT_DATE, - CONST.NETSUITE_CONFIG.REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, - ...(!shouldHideReimbursableDefaultVendor(true, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.DEFAULT_VENDOR] : []), - ...(!shouldHideNonReimbursableJournalPostingAccount(true, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.PAYABLE_ACCT] : []), - ...(!shouldHideReimbursableJournalPostingAccount(true, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.REIMBURSABLE_PAYABLE_ACCOUNT] : []), - ...(!shouldHideJournalPostingPreference(true, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.JOURNAL_POSTING_PREFERENCE] : []), - CONST.NETSUITE_CONFIG.NON_REIMBURSABLE_EXPENSES_EXPORT_DESTINATION, - ...(!shouldHideReimbursableDefaultVendor(false, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.DEFAULT_VENDOR] : []), - ...(!shouldHideNonReimbursableJournalPostingAccount(false, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.PAYABLE_ACCT] : []), - ...(!shouldHideReimbursableJournalPostingAccount(false, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.REIMBURSABLE_PAYABLE_ACCOUNT] : []), - ...(!shouldHideJournalPostingPreference(false, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.JOURNAL_POSTING_PREFERENCE] : []), - CONST.NETSUITE_CONFIG.RECEIVABLE_ACCOUNT, - CONST.NETSUITE_CONFIG.INVOICE_ITEM_PREFERENCE, - ...(shouldShowInvoiceItemMenuItem(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.INVOICE_ITEM] : []), - ...(!shouldHideProvincialTaxPostingAccountSelect(netsuiteSelectedSubsidiary, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.PROVINCIAL_TAX_POSTING_ACCOUNT] : []), - ...(!shouldHideTaxPostingAccountSelect(canUseNetSuiteUSATax, netsuiteSelectedSubsidiary, netsuiteConfig) ? [CONST.NETSUITE_CONFIG.TAX_POSTING_ACCOUNT] : []), - ...(!shouldHideExportForeignCurrencyAmount(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.ALLOW_FOREIGN_CURRENCY] : []), - CONST.NETSUITE_CONFIG.EXPORT_TO_NEXT_OPEN_PERIOD, - ], - onCardReconciliationPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_CARD_RECONCILIATION.getRoute(policyID, CONST.POLICY.CONNECTIONS.ROUTE.NETSUITE)), - onAdvancedPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_ADVANCED.getRoute(policyID)), - subscribedAdvancedSettings: [ - CONST.NETSUITE_CONFIG.AUTO_SYNC, - CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD, - ...(!shouldHideReimbursedReportsSection(netsuiteConfig) - ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_REIMBURSED_REPORTS, CONST.NETSUITE_CONFIG.REIMBURSEMENT_ACCOUNT_ID, CONST.NETSUITE_CONFIG.COLLECTION_ACCOUNT] - : []), - CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_PEOPLE, - CONST.NETSUITE_CONFIG.AUTO_CREATE_ENTITIES, - CONST.NETSUITE_CONFIG.SYNC_OPTIONS.ENABLE_NEW_CATEGORIES, - ...(!shouldHideReportsExportTo(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.EXPORT_REPORTS_TO] : []), - ...(!shouldHideExportVendorBillsTo(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.EXPORT_VENDOR_BILLS_TO] : []), - ...(!shouldHideExportJournalsTo(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.EXPORT_JOURNALS_TO] : []), - CONST.NETSUITE_CONFIG.APPROVAL_ACCOUNT, - CONST.NETSUITE_CONFIG.CUSTOM_FORM_ID_ENABLED, - ...(!shouldHideCustomFormIDOptions(netsuiteConfig) - ? [CONST.NETSUITE_CONFIG.CUSTOM_FORM_ID_TYPE.REIMBURSABLE, CONST.NETSUITE_CONFIG.CUSTOM_FORM_ID_TYPE.NON_REIMBURSABLE] - : []), - ], - workspaceUpgradeNavigationDetails: { - integrationAlias: CONST.UPGRADE_FEATURE_INTRO_MAPPING.netsuite.alias, - backToAfterWorkspaceUpgradeRoute: integrationToDisconnect - ? ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting) - : ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID), - }, - pendingFields: {...netsuiteConfig?.pendingFields, ...policy?.connections?.netsuite?.config?.pendingFields, ...policy?.connections?.netsuite?.options?.config?.pendingFields}, - errorFields: {...netsuiteConfig?.errorFields, ...policy?.connections?.netsuite?.config?.errorFields, ...policy?.connections?.netsuite?.options?.config?.errorFields}, - }; - case CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT: - return { - title: translate('workspace.accounting.intacct'), - icon: Expensicons.IntacctSquare, - setupConnectionFlow: ( - - ), - onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_IMPORT.getRoute(policyID)), - subscribedImportSettings: [ - CONST.SAGE_INTACCT_CONFIG.SYNC_ITEMS, - ...Object.values(CONST.SAGE_INTACCT_CONFIG.MAPPINGS), - CONST.SAGE_INTACCT_CONFIG.TAX, - ...(policy?.connections?.intacct?.config?.mappings?.dimensions ?? []).map((dimension) => `${CONST.SAGE_INTACCT_CONFIG.DIMENSION_PREFIX}${dimension.dimension}`), - ], - onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_EXPORT.getRoute(policyID)), - subscribedExportSettings: [ - CONST.SAGE_INTACCT_CONFIG.EXPORTER, - CONST.SAGE_INTACCT_CONFIG.EXPORT_DATE, - CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE, - CONST.SAGE_INTACCT_CONFIG.REIMBURSABLE_VENDOR, - CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE, - CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_ACCOUNT, - policy?.connections?.intacct?.config?.export?.nonReimbursable === CONST.SAGE_INTACCT_NON_REIMBURSABLE_EXPENSE_TYPE.VENDOR_BILL - ? CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_VENDOR - : CONST.SAGE_INTACCT_CONFIG.NON_REIMBURSABLE_CREDIT_CARD_VENDOR, - ], - onCardReconciliationPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_CARD_RECONCILIATION.getRoute(policyID, CONST.POLICY.CONNECTIONS.ROUTE.SAGE_INTACCT)), - onAdvancedPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_ADVANCED.getRoute(policyID)), - subscribedAdvancedSettings: [ - CONST.SAGE_INTACCT_CONFIG.AUTO_SYNC_ENABLED, - CONST.SAGE_INTACCT_CONFIG.IMPORT_EMPLOYEES, - CONST.SAGE_INTACCT_CONFIG.APPROVAL_MODE, - CONST.SAGE_INTACCT_CONFIG.SYNC_REIMBURSED_REPORTS, - CONST.SAGE_INTACCT_CONFIG.REIMBURSEMENT_ACCOUNT_ID, - ], - workspaceUpgradeNavigationDetails: { - integrationAlias: CONST.UPGRADE_FEATURE_INTRO_MAPPING.intacct.alias, - backToAfterWorkspaceUpgradeRoute: integrationToDisconnect - ? ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting) - : ROUTES.POLICY_ACCOUNTING_SAGE_INTACCT_PREREQUISITES.getRoute(policyID), - }, - pendingFields: policy?.connections?.intacct?.config?.pendingFields, - errorFields: policy?.connections?.intacct?.config?.errorFields, - }; - case CONST.POLICY.CONNECTIONS.NAME.QBD: - return { - title: translate('workspace.accounting.qbd'), - icon: Expensicons.QBDSquare, - setupConnectionFlow: ( - - ), - onImportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_IMPORT.getRoute(policyID)), - onExportPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_QUICKBOOKS_DESKTOP_EXPORT.getRoute(policyID)), - onCardReconciliationPagePress: () => {}, - onAdvancedPagePress: () => Navigation.navigate(ROUTES.WORKSPACE_ACCOUNTING_QUICKBOOKS_DESKTOP_ADVANCED.getRoute(policyID)), - subscribedImportSettings: [ - CONST.QUICKBOOKS_DESKTOP_CONFIG.ENABLE_NEW_CATEGORIES, - CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CLASSES, - CONST.QUICKBOOKS_DESKTOP_CONFIG.MAPPINGS.CUSTOMERS, - CONST.QUICKBOOKS_DESKTOP_CONFIG.IMPORT_ITEMS, - ], - subscribedExportSettings: [ - CONST.QUICKBOOKS_DESKTOP_CONFIG.EXPORT_DATE, - CONST.QUICKBOOKS_DESKTOP_CONFIG.EXPORTER, - CONST.QUICKBOOKS_DESKTOP_CONFIG.REIMBURSABLE, - CONST.QUICKBOOKS_DESKTOP_CONFIG.REIMBURSABLE_ACCOUNT, - CONST.QUICKBOOKS_DESKTOP_CONFIG.MARK_CHECKS_TO_BE_PRINTED, - CONST.QUICKBOOKS_DESKTOP_CONFIG.NON_REIMBURSABLE, - CONST.QUICKBOOKS_DESKTOP_CONFIG.NON_REIMBURSABLE_ACCOUNT, - CONST.QUICKBOOKS_DESKTOP_CONFIG.NON_REIMBURSABLE_BILL_DEFAULT_VENDOR, - CONST.QUICKBOOKS_DESKTOP_CONFIG.SHOULD_AUTO_CREATE_VENDOR, - ], - subscribedAdvancedSettings: [CONST.QUICKBOOKS_DESKTOP_CONFIG.SHOULD_AUTO_CREATE_VENDOR, CONST.QUICKBOOKS_DESKTOP_CONFIG.AUTO_SYNC], - workspaceUpgradeNavigationDetails: { - integrationAlias: CONST.UPGRADE_FEATURE_INTRO_MAPPING.quickbooksDesktop.alias, - backToAfterWorkspaceUpgradeRoute: getBackToAfterWorkspaceUpgradeRouteForQBD(), - }, - }; - default: - return undefined; - } +function shouldHideReimbursableJournalPostingAccount(isReimbursable: boolean, config?: NetSuiteConnectionConfig) { + return !isReimbursable || config?.reimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY; } -function getSynchronizationErrorMessage( - policy: OnyxEntry, - connectionName: PolicyConnectionName, - isSyncInProgress: boolean, - translate: LocaleContextProps['translate'], - styles?: ThemeStyles, -): React.ReactNode | undefined { - if (isAuthenticationError(policy, connectionName)) { - return ( - - {translate('workspace.common.authenticationError', {connectionName: CONST.POLICY.CONNECTIONS.NAME_USER_FRIENDLY[connectionName]})} - {connectionName in CONST.POLICY.CONNECTIONS.AUTH_HELP_LINKS && ( - - {translate('workspace.common.learnMore')} - - )} - - ); - } +function shouldHideJournalPostingPreference(isReimbursable: boolean, config?: NetSuiteConnectionConfig) { + return config?.[exportExpensesDestinationSettingName(isReimbursable)] !== CONST.NETSUITE_EXPORT_DESTINATION.JOURNAL_ENTRY; +} - const syncError = Localize.translateLocal('workspace.accounting.syncError', {connectionName}); +function shouldShowInvoiceItemMenuItem(config?: NetSuiteConnectionConfig) { + return config?.invoiceItemPreference === CONST.NETSUITE_INVOICE_ITEM_PREFERENCE.SELECT; +} - const connection = policy?.connections?.[connectionName]; - if (isSyncInProgress || isEmptyObject(connection?.lastSync) || connection?.lastSync?.isSuccessful !== false || !connection?.lastSync?.errorDate) { - return; - } +function shouldHideProvincialTaxPostingAccountSelect(selectedSubsidiary?: NetSuiteSubsidiary, config?: NetSuiteConnectionConfig) { + return !!config?.suiteTaxEnabled || !config?.syncOptions.syncTax || !canUseProvincialTaxNetSuite(selectedSubsidiary?.country); +} - return `${syncError} ("${connection?.lastSync?.errorMessage}")`; +function shouldHideTaxPostingAccountSelect(canUseNetSuiteUSATax?: boolean, selectedSubsidiary?: NetSuiteSubsidiary, config?: NetSuiteConnectionConfig) { + return !!config?.suiteTaxEnabled || !config?.syncOptions.syncTax || !canUseTaxNetSuite(canUseNetSuiteUSATax, selectedSubsidiary?.country); } -function getQBDReimbursableAccounts( - quickbooksDesktop?: Connections[typeof CONST.POLICY.CONNECTIONS.NAME.QBD], - reimbursable?: QBDReimbursableExportAccountType | QBDNonReimbursableExportAccountType, -) { - const {bankAccounts, journalEntryAccounts, payableAccounts, creditCardAccounts} = quickbooksDesktop?.data ?? {}; +function shouldHideExportForeignCurrencyAmount(config?: NetSuiteConnectionConfig) { + return ( + config?.reimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT && + config?.nonreimbursableExpensesExportDestination !== CONST.NETSUITE_EXPORT_DESTINATION.EXPENSE_REPORT + ); +} - let accounts: Account[]; - switch (reimbursable ?? quickbooksDesktop?.config?.export.reimbursable) { - case CONST.QUICKBOOKS_DESKTOP_REIMBURSABLE_ACCOUNT_TYPE.CHECK: - accounts = bankAccounts ?? []; - break; - case CONST.QUICKBOOKS_DESKTOP_REIMBURSABLE_ACCOUNT_TYPE.JOURNAL_ENTRY: - // Journal entry accounts include payable accounts, other current liabilities, and other current assets - accounts = [...(payableAccounts ?? []), ...(journalEntryAccounts ?? [])]; - break; - case CONST.QUICKBOOKS_DESKTOP_REIMBURSABLE_ACCOUNT_TYPE.VENDOR_BILL: - accounts = payableAccounts ?? []; - break; - case CONST.QUICKBOOKS_DESKTOP_NON_REIMBURSABLE_EXPORT_ACCOUNT_TYPE.CREDIT_CARD: - accounts = creditCardAccounts ?? []; - break; - default: - accounts = []; - } - return accounts; +function getImportCustomFieldsSettings(importField: ValueOf, config?: NetSuiteConnectionConfig) { + const data = config?.syncOptions?.[importField] ?? []; + return data.map((_, index) => `${importField}_${index}`); } -export {getAccountingIntegrationData, getSynchronizationErrorMessage, getQBDReimbursableAccounts}; +export { + shouldHideReimbursedReportsSection, + shouldHideReportsExportTo, + shouldHideExportVendorBillsTo, + shouldHideExportJournalsTo, + shouldHideCustomFormIDOptions, + exportExpensesDestinationSettingName, + shouldHideReimbursableDefaultVendor, + shouldHideNonReimbursableJournalPostingAccount, + shouldHideReimbursableJournalPostingAccount, + shouldHideJournalPostingPreference, + shouldShowInvoiceItemMenuItem, + shouldHideProvincialTaxPostingAccountSelect, + shouldHideTaxPostingAccountSelect, + shouldHideExportForeignCurrencyAmount, + getImportCustomFieldsSettings, +}; diff --git a/src/pages/workspace/accounting/utils.tsx b/src/pages/workspace/accounting/utils.tsx index 5b20b522ac23..3ed4d6077417 100644 --- a/src/pages/workspace/accounting/utils.tsx +++ b/src/pages/workspace/accounting/utils.tsx @@ -186,6 +186,7 @@ function getAccountingIntegrationData( onAdvancedPagePress: () => Navigation.navigate(ROUTES.POLICY_ACCOUNTING_NETSUITE_ADVANCED.getRoute(policyID)), subscribedAdvancedSettings: [ CONST.NETSUITE_CONFIG.AUTO_SYNC, + CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD, ...(!shouldHideReimbursedReportsSection(netsuiteConfig) ? [CONST.NETSUITE_CONFIG.SYNC_OPTIONS.SYNC_REIMBURSED_REPORTS, CONST.NETSUITE_CONFIG.REIMBURSEMENT_ACCOUNT_ID, CONST.NETSUITE_CONFIG.COLLECTION_ACCOUNT] : []), @@ -207,8 +208,8 @@ function getAccountingIntegrationData( ? ROUTES.POLICY_ACCOUNTING.getRoute(policyID, connectionName, integrationToDisconnect, shouldDisconnectIntegrationBeforeConnecting) : ROUTES.POLICY_ACCOUNTING_NETSUITE_TOKEN_INPUT.getRoute(policyID), }, - pendingFields: {...netsuiteConfig?.pendingFields, ...policy?.connections?.netsuite?.config?.pendingFields}, - errorFields: {...netsuiteConfig?.errorFields, ...policy?.connections?.netsuite?.config?.errorFields}, + pendingFields: {...netsuiteConfig?.pendingFields, ...policy?.connections?.netsuite?.config?.pendingFields, ...policy?.connections?.netsuite?.options?.config?.pendingFields}, + errorFields: {...netsuiteConfig?.errorFields, ...policy?.connections?.netsuite?.config?.errorFields, ...policy?.connections?.netsuite?.options?.config?.errorFields}, }; case CONST.POLICY.CONNECTIONS.NAME.SAGE_INTACCT: return { From 4d1245b357a05bc8dab06d695cf2ff8dfd697e31 Mon Sep 17 00:00:00 2001 From: Rutika Pawar Date: Wed, 13 Nov 2024 11:31:00 +0000 Subject: [PATCH 12/12] improve code redability --- .../advanced/NetSuiteAccountingMethodPage.tsx | 8 ++++---- .../netsuite/advanced/NetSuiteAutoSyncPage.tsx | 14 ++++---------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx index 4a75c261c7cf..a5c1872158e9 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAccountingMethodPage.tsx @@ -37,6 +37,9 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { isSelected: accountingMethod === accountingMethodType, })); + const pendingAction = + settingsPendingAction([CONST.NETSUITE_CONFIG.AUTO_SYNC], autoSyncConfig?.pendingFields) ?? settingsPendingAction([CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD], config?.pendingFields); + const headerContent = useMemo( () => ( @@ -70,10 +73,7 @@ function NetSuiteAccountingMethodPage({policy}: WithPolicyConnectionsProps) { featureName={CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED} onBackButtonPress={() => Navigation.goBack(ROUTES.POLICY_ACCOUNTING_NETSUITE_AUTO_SYNC.getRoute(policyID))} connectionName={CONST.POLICY.CONNECTIONS.NAME.NETSUITE} - pendingAction={ - settingsPendingAction([CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD], config?.pendingFields) ?? - settingsPendingAction([CONST.NETSUITE_CONFIG.AUTO_SYNC], autoSyncConfig?.pendingFields) - } + pendingAction={pendingAction} /> ); } diff --git a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx index 83fb40fdc038..e75496caa451 100644 --- a/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx +++ b/src/pages/workspace/accounting/netsuite/advanced/NetSuiteAutoSyncPage.tsx @@ -26,6 +26,8 @@ function NetSuiteAutoSyncPage({policy, route}: WithPolicyConnectionsProps) { const autoSyncConfig = policy?.connections?.netsuite?.config; const policyID = route.params.policyID ?? '-1'; const accountingMethod = policy?.connections?.netsuite?.options?.config?.accountingMethod; + const pendingAction = + settingsPendingAction([CONST.NETSUITE_CONFIG.AUTO_SYNC], autoSyncConfig?.pendingFields) ?? settingsPendingAction([CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD], config?.pendingFields); return ( Policy.clearNetSuiteAutoSyncErrorField(policyID)} onToggle={(isEnabled) => Connections.updateNetSuiteAutoSync(policyID, isEnabled)} - pendingAction={ - settingsPendingAction([CONST.NETSUITE_CONFIG.AUTO_SYNC], autoSyncConfig?.pendingFields) ?? - settingsPendingAction([CONST.NETSUITE_CONFIG.ACCOUNTING_METHOD], config?.pendingFields) - } + pendingAction={pendingAction} errors={ErrorUtils.getLatestErrorField(autoSyncConfig, CONST.NETSUITE_CONFIG.AUTO_SYNC)} /> {!!autoSyncConfig?.autoSync?.enabled && ( - +