Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Reimbursable Expense Non Mandatory (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
anishfyle authored Jun 21, 2023
1 parent b256650 commit f9fb597
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 57 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app/si/dashboard/dashboard.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class DashboardComponent implements OnInit {
getEmployeeMappings() {
const that = this;
// TODO: remove promises and do with rxjs observables
if (that.configuration && that.configuration.auto_create_destination_entity) {
if (that.configuration && (that.configuration.auto_create_destination_entity || !that.configuration.reimbursable_expenses_object)) {
that.currentState = onboardingStates.employeeMappingsDone;
return;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export class CategoryMappingsDialogComponent implements OnInit {
showSeparateCCCField() {
const that = this;
const settings = that.configuration;
if (settings.corporate_credit_card_expenses_object && settings.corporate_credit_card_expenses_object !== 'EXPENSE_REPORT' && settings.reimbursable_expenses_object === 'EXPENSE_REPORT') {
if (settings.corporate_credit_card_expenses_object && settings.corporate_credit_card_expenses_object !== 'EXPENSE_REPORT' && !(settings.reimbursable_expenses_object === 'BILL' || settings.reimbursable_expenses_object === 'JOURNAL_ENTRY' )) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class GeneralMappingsComponent implements OnInit {
const that = this;

that.route.queryParams.subscribe(params => {
if (params.redirect_to_employee_mappings) {
if (params.redirect_to_employee_mappings && that.configuration.reimbursable_expenses_object) {
setTimeout(() => {
const destination = that.configuration.employee_field_mapping.toLowerCase().replace(/\b(\w)/g, s => s.toUpperCase());
that.snackBar.open(`To ensure successful export, map Fyle Employees to ${destination}s in SageIntacct`, '', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ <h2 mat-dialog-title>
</div>
<div fxFlex="60">
<div fxFlex="45">
<button mat-stroked-button [autofocus]="false" [disableRipple]="true" class="configurations-dialog--btn">{{updatedConfiguration.reimburseExpense.oldValue | titlecase}}</button>
</div>
<button *ngIf="updatedConfiguration.reimburseExpense.oldValue" mat-stroked-button [autofocus]="false" [disableRipple]="true" class="configurations-dialog--btn">{{updatedConfiguration.reimburseExpense.oldValue | titlecase}}</button>
<button *ngIf="!updatedConfiguration.reimburseExpense.oldValue" mat-stroked-button [autofocus]="false" [disableRipple]="true" class="configurations-dialog--btn">None</button>
</div>
<div fxFlex="10" class="configurations-dialog--update-text" [ngStyle]="customStyle">to</div>
<div fxFlex="45">
<button mat-stroked-button [autofocus]="false" [disableRipple]="true" class="configurations-dialog--btn-update">{{updatedConfiguration.reimburseExpense.newValue | titlecase}}</button>
</div>
<button *ngIf="updatedConfiguration.reimburseExpense.newValue" mat-stroked-button [autofocus]="false" [disableRipple]="true" class="configurations-dialog--btn-update">{{updatedConfiguration.reimburseExpense.newValue | titlecase}}</button>
<button *ngIf="!updatedConfiguration.reimburseExpense.newValue" mat-stroked-button [autofocus]="false" [disableRipple]="true" class="configurations-dialog--btn-update">None</button>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@
<div fxLayout="column" fxLayoutAlign="start stretch">
<div class="configurations--label">
Map reimbursable Expenses from Fyle to
<mandatory-field></mandatory-field>
</div>
<mat-form-field floatLabel="always" appearance="outline" required>
<mat-select placeholder="Choose Sage Intacct equivalent of Reimbursable Expenses"
formControlName="reimburExpense">
<mat-option>
None
</mat-option>
<mat-option *ngFor="let option of expenseOptions" [value]="option.value">
{{option.label}}
</mat-option>
</mat-select>
</mat-form-field>
<mandatory-error-message listName="export type" *ngIf="configurationForm.controls.reimburExpense.touched && !configurationForm.controls.reimburExpense.valid"></mandatory-error-message>

<div class="configurations--label" *ngIf="configurationForm.controls.reimburExpense.value === 'JOURNAL_ENTRY'">
<div class="configurations--label" *ngIf="configurationForm.controls.reimburExpense.value === 'JOURNAL_ENTRY' || (!configurationForm.controls.reimburExpense.value && configurationForm.controls.cccExpense.value === 'JOURNAL_ENTRY')">
Map Employees from Fyle to
<mandatory-field></mandatory-field>
</div>
<mat-form-field floatLabel="always" appearance="outline" required *ngIf="configurationForm.controls.reimburExpense.value === 'JOURNAL_ENTRY'">
<mat-form-field floatLabel="always" appearance="outline" required *ngIf="configurationForm.controls.reimburExpense.value === 'JOURNAL_ENTRY' || (!configurationForm.controls.reimburExpense.value && configurationForm.controls.cccExpense.value === 'JOURNAL_ENTRY')">
<mat-select placeholder="Choose Sage Intacct equivalent of Employees" formControlName="employeeFieldMapping">
<mat-option value="VENDOR">
Vendor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,13 @@ export class ConfigurationComponent implements OnInit {
label: 'Journal Entry',
value: 'JOURNAL_ENTRY'
},
];

if (employeesMappedTo === 'VENDOR') {
cccExpenseOptions.push({
label: 'Bill',
value: 'BILL'
});
{
label: 'Bill',
value: 'BILL'
}
];

if (reimburExpenseMappedTo === 'EXPENSE_REPORT' || (reimburExpenseMappedTo === 'JOURNAL_ENTRY' && employeesMappedTo === 'EMPLOYEE')) {
if (reimburExpenseMappedTo === 'EXPENSE_REPORT') {
cccExpenseOptions.push({
label: 'Expense Report',
value: 'EXPENSE_REPORT'
Expand Down Expand Up @@ -142,10 +139,52 @@ export class ConfigurationComponent implements OnInit {
}
}

updateEmployeeFieldMapping(reimbursableExpenseMappedTo, cccExpenseMappedTo, reimburExpenseControl, configurationForm) {
const employeeFieldMappingControl = configurationForm.controls.employeeFieldMapping;

if (reimbursableExpenseMappedTo === 'JOURNAL_ENTRY' || (cccExpenseMappedTo === 'JOURNAL_ENTRY' && !reimburExpenseControl.value)) {
employeeFieldMappingControl.reset();
employeeFieldMappingControl.setValidators([Validators.required]);
employeeFieldMappingControl.updateValueAndValidity();
} else {
employeeFieldMappingControl.reset();
employeeFieldMappingControl.clearValidators();
employeeFieldMappingControl.updateValueAndValidity();
}
}

setupReimbursableFieldWatcher() {
const that = this;
that.configurationForm.controls.reimburExpense.valueChanges.subscribe((reimbursableExpenseMappedTo) => {
that.configurationForm.controls.cccExpense.reset();
const cccExpenseControl = this.configurationForm.controls.cccExpense;
const reimburExpenseControl = this.configurationForm.controls.reimburExpense;
let programmaticChange = false;

cccExpenseControl.valueChanges.subscribe((cccExpenseMappedTo) => {
if (!programmaticChange) {
programmaticChange = true;
if (!cccExpenseMappedTo && !reimburExpenseControl.value) {
reimburExpenseControl.setValidators([Validators.required]);
} else {
reimburExpenseControl.clearValidators();
}
reimburExpenseControl.updateValueAndValidity();
programmaticChange = false;
}

this.updateEmployeeFieldMapping(reimburExpenseControl.value, cccExpenseMappedTo, reimburExpenseControl, this.configurationForm);
});

reimburExpenseControl.valueChanges.subscribe((reimbursableExpenseMappedTo) => {
if (!programmaticChange) {
programmaticChange = true;
if (!reimbursableExpenseMappedTo && !cccExpenseControl.value) {
cccExpenseControl.setValidators([Validators.required]);
} else {
cccExpenseControl.clearValidators();
}
cccExpenseControl.updateValueAndValidity();
programmaticChange = false;
}
that.cccExpenseOptions = that.getCCCExpenseOptions(reimbursableExpenseMappedTo);

if (reimbursableExpenseMappedTo) {
Expand All @@ -156,22 +195,7 @@ export class ConfigurationComponent implements OnInit {
that.showImportCategories = true;
}

if (reimbursableExpenseMappedTo === 'JOURNAL_ENTRY') {
that.configurationForm.controls.employeeFieldMapping.reset();
// Add validators for the 'employeeFieldMapping' form control
that.configurationForm.controls.employeeFieldMapping.setValidators([Validators.required]);

// Update the form control's value and validation state
that.configurationForm.controls.employeeFieldMapping.updateValueAndValidity();
} else {
that.configurationForm.controls.employeeFieldMapping.reset();

// Clear validators for the 'employeeFieldMapping' form control
that.configurationForm.controls.employeeFieldMapping.clearValidators();

// Update the form control's value and validation state
that.configurationForm.controls.employeeFieldMapping.updateValueAndValidity();
}
this.updateEmployeeFieldMapping(reimbursableExpenseMappedTo, cccExpenseControl.value, reimburExpenseControl, this.configurationForm);

if (that.configuration && that.configuration.reimbursable_expenses_object === 'EXPENSE_REPORT' && reimbursableExpenseMappedTo !== 'EXPENSE_REPORT') {
// turn off the import categories toggle when the user switches from EXPENSE REPORT to something else
Expand All @@ -184,7 +208,6 @@ export class ConfigurationComponent implements OnInit {
setupEmployeesFieldWatcher(reimbursableExpense) {
const that = this;
that.configurationForm.controls.employeeFieldMapping.valueChanges.subscribe((employeesMappedTo) => {
that.configurationForm.controls.cccExpense.reset();
that.cccExpenseOptions = that.getCCCExpenseOptions(reimbursableExpense, employeesMappedTo);
});
}
Expand Down Expand Up @@ -255,7 +278,7 @@ export class ConfigurationComponent implements OnInit {
}

that.configurationForm = that.formBuilder.group({
reimburExpense: [that.configuration ? that.configuration.reimbursable_expenses_object : '', Validators.required],
reimburExpense: [that.configuration ? that.configuration.reimbursable_expenses_object : ''],
employeeFieldMapping: [that.configuration ? that.configuration.employee_field_mapping : ''],
cccExpense: [that.configuration ? that.configuration.corporate_credit_card_expenses_object : ''],
importProjects: [importProjects],
Expand Down Expand Up @@ -401,10 +424,10 @@ export class ConfigurationComponent implements OnInit {
constructConfigurationsPayload(): Configuration {
const that = this;

const reimbursableExpensesObject = that.configurationForm.getRawValue().reimburExpense;
const reimbursableExpensesObject = that.configurationForm.getRawValue().reimburExpense ? that.configurationForm.getRawValue().reimburExpense : null;
const cccExpensesObject = that.configurationForm.getRawValue().cccExpense ? that.configurationForm.getRawValue().cccExpense : null;
const categoryMappingObject = that.getCategory(reimbursableExpensesObject)[0].value;
const employeeMappingsObject = that.getEmployee(reimbursableExpensesObject)[0].value;
const categoryMappingObject = reimbursableExpensesObject ? that.getCategory(reimbursableExpensesObject)[0].value : null;
const employeeMappingsObject = reimbursableExpensesObject ? that.getEmployee(reimbursableExpensesObject)[0].value : (cccExpensesObject === 'JOURNAL_ENTRY' ? that.getEmployee(cccExpensesObject)[0].value : null);
const importProjects = that.configurationForm.value.importProjects;
const importCategories = that.configurationForm.value.importCategories;
const autoMapEmployees = that.configurationForm.value.autoMapEmployees ? that.configurationForm.value.autoMapEmployees : null;
Expand Down Expand Up @@ -442,14 +465,11 @@ export class ConfigurationComponent implements OnInit {
constructMappingSettingsPayload(): MappingSetting[] {
const that = this;

const reimbursableExpensesObject = that.configurationForm.getRawValue().reimburExpense;
const employeeMappingsObject = that.getEmployee(reimbursableExpensesObject)[0].value;
const categoryMappingObject = that.getCategory(reimbursableExpensesObject)[0].value;
const reimbursableExpensesObject = that.configurationForm.getRawValue().reimburExpense ? that.configurationForm.getRawValue().reimburExpense : null;
const employeeMappingsObject = reimbursableExpensesObject ? that.getEmployee(reimbursableExpensesObject)[0].value : null;
const categoryMappingObject = reimbursableExpensesObject ? that.getCategory(reimbursableExpensesObject)[0].value : null;

const mappingsSettingsPayload: MappingSetting[] = [{
source_field: 'EMPLOYEE',
destination_field: employeeMappingsObject
}];
const mappingsSettingsPayload: MappingSetting[] = [];

const importProjects = that.configurationForm.value.importProjects ? that.configurationForm.value.importProjects : false;
const importTaxCodes = that.configurationForm.value.importTaxCodes ? that.configurationForm.value.importTaxCodes : false;
Expand All @@ -462,11 +482,6 @@ export class ConfigurationComponent implements OnInit {
});
}

mappingsSettingsPayload.push({
source_field: 'CATEGORY',
destination_field: categoryMappingObject
});

if (importProjects) {
mappingsSettingsPayload.push({
source_field: 'PROJECT',
Expand Down
2 changes: 1 addition & 1 deletion src/app/si/si.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
routerLink="{{workspace.id}}/settings/general/mappings/" routerLinkActive="active" (click)="onGeneralMappingsPageVisit()">
General Mappings
</a>
<a class="mat-h3 si-sidenav--nav-sub-item" [ngClass]="{'si-sidenav--nav-sub-item__disabled': navDisabled}" mat-list-item
<a class="mat-h3 si-sidenav--nav-sub-item" *ngIf = "showEmployeeMapping" [ngClass]="{'si-sidenav--nav-sub-item__disabled': navDisabled}" mat-list-item
routerLink="{{workspace.id}}/settings/employee/mappings/" routerLinkActive="active" (click)="onEmployeeMappingsPageVisit()">
Employee Mappings
</a>
Expand Down
16 changes: 14 additions & 2 deletions src/app/si/si.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class SiComponent implements OnInit {
windowReference: Window;
connectSageIntacct = true;
showRefreshIcon: boolean;
showEmployeeMapping = true;

constructor(
private workspaceService: WorkspaceService,
Expand All @@ -58,6 +59,7 @@ export class SiComponent implements OnInit {
return name.replace(/_/g, ' ');
}


refreshDashboardMappingSettings(mappingSettings: MappingSetting[]) {
const that = this;

Expand Down Expand Up @@ -117,15 +119,25 @@ export class SiComponent implements OnInit {

setupAccessiblePathWatchers() {
const that = this;
that.getConfigurations().subscribe(() => {
that.getConfigurations().subscribe((response) => {
that.navDisabled = false;
if (response[0].reimbursable_expenses_object != null || response[0].corporate_credit_card_expenses_object === 'JOURNAL_ENTRY') {
this.showEmployeeMapping = true;
} else {
this.showEmployeeMapping = false;
}
});

that.router.events.subscribe(() => {
const onboarded = that.storageService.get('onboarded');
if (onboarded !== true) {
that.getConfigurations().subscribe(() => {
that.getConfigurations().subscribe((response) => {
that.navDisabled = false;
if (response[0].reimbursable_expenses_object != null || response[0].corporate_credit_card_expenses_object === 'JOURNAL_ENTRY') {
this.showEmployeeMapping = true;
} else {
this.showEmployeeMapping = false;
}
});
}
});
Expand Down

0 comments on commit f9fb597

Please sign in to comment.