Skip to content

Commit

Permalink
fix(intacct): update expense group fields' values in export settings …
Browse files Browse the repository at this point in the history
…payload (#907)

* fix(intacct): update expense group fields' values in export settings payload

* fix: edge case

refactor: camelCase
  • Loading branch information
1 parent 7e9ee2f commit 804a9c4
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,40 @@ export interface IntacctExportSettingOptionSearch extends ExportSettingOptionSea
const getValueOrDefault = (control: AbstractControl | null, defaultValue: any = null) => {
return control?.value ? control.value : defaultValue;
};

const getExpenseGroupFields = (exportGroupValue: ExpenseGroupingFieldOption) => {
// "Expense"
if (exportGroupValue === ExpenseGroupingFieldOption.EXPENSE_ID) {
return ['expense_id', 'expense_number'];

// "Report"
} else if (exportGroupValue === ExpenseGroupingFieldOption.CLAIM_NUMBER || exportGroupValue === ExpenseGroupingFieldOption.REPORT_ID) {
return ['report_id', 'claim_number'];
}
return null;
};

const emptyDestinationAttribute = { id: null, name: null };

const cccExportType = getValueOrDefault(exportSettingsForm.get('cccExportType'));
let cccExportGroup = exportSettingsForm.get('cccExportGroup')?.value ? [exportSettingsForm.value.cccExportGroup] : null;
const cccExportGroup = exportSettingsForm.get('cccExportGroup')?.value;
let corporateCreditCardExpenseGroupFields = getExpenseGroupFields(cccExportGroup);

if (cccExportType === IntacctCorporateCreditCardExpensesObject.CHARGE_CARD_TRANSACTION) {
cccExportGroup = [ExpenseGroupingFieldOption.EXPENSE_ID];
corporateCreditCardExpenseGroupFields = [ExpenseGroupingFieldOption.EXPENSE_ID];
}

const reimbursableExportGroup = exportSettingsForm.get('reimbursableExportGroup')?.value;
const reimbursableExpenseGroupFields = getExpenseGroupFields(reimbursableExportGroup);


const exportSettingPayload: ExportSettingPost = {
expense_group_settings: {
expense_state: getValueOrDefault(exportSettingsForm.get('reimbursableExpenseState')),
ccc_expense_state: getValueOrDefault(exportSettingsForm.get('cccExpenseState')),
reimbursable_expense_group_fields: exportSettingsForm.get('reimbursableExportGroup')?.value ? [exportSettingsForm.value.reimbursableExportGroup] : null,
reimbursable_expense_group_fields: reimbursableExpenseGroupFields,
reimbursable_export_date_type: exportSettingsForm.get('reimbursableExportDate')?.value ? exportSettingsForm.get('reimbursableExportDate')?.value : null,
corporate_credit_card_expense_group_fields: cccExportGroup,
corporate_credit_card_expense_group_fields: corporateCreditCardExpenseGroupFields,
ccc_export_date_type: getValueOrDefault(exportSettingsForm.get('cccExportDate')) === 'Spend Date' ? 'spent_at' : getValueOrDefault(exportSettingsForm.get('cccExportDate')),
split_expense_grouping: exportSettingsForm.get('splitExpenseGrouping')?.value ? exportSettingsForm.get('splitExpenseGrouping')?.value : SplitExpenseGrouping.MULTIPLE_LINE_ITEM
},
Expand Down

0 comments on commit 804a9c4

Please sign in to comment.