Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ankit | Test | View financial reports of multiple company together with currency filter #14363

Merged
merged 17 commits into from
Jan 1, 2025
1 change: 1 addition & 0 deletions apps/web-giddh/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export const ROUTES: Routes = [
{ path: 'vouchers', loadChildren: () => import('./vouchers/vouchers.module').then(module => module.VouchersModule), canActivate: [NeedsAuthorization] },
{ path: 'group-name', loadChildren: () => import('./group-name/group-name.module').then(module => module.GroupNameModule), canActivate: [NeedsAuthorization] },
{ path: 'auth-hmrc', loadChildren: () => import('./auth-hmrc/auth-hmrc.module').then(module => module.AuthHMRCModule), canActivate: [NeedsAuthorization] },
{ path: 'multi-currency-report', loadChildren: () => import('./multi-currency-reports/multi-currency-reports.module').then(module => module.MultiCurrencyReportsModule), canActivate: [NeedsAuthorization] },
{ path: '**', redirectTo: 'home', pathMatch: 'full' }
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class FinancialReportsFilterComponent implements OnInit, OnDestroy {
description: []
});

this.universalDate$ = this.store.pipe(select(p => p.session.applicationDate), distinctUntilChanged(), takeUntil(this.destroyed$));
this.universalDate$ = this.store.pipe(select(p => p.session.applicationDate),distinctUntilChanged(), takeUntil(this.destroyed$));
}

public get selectedCompany() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ToasterService } from '../../../services/toaster.service';
import { AppState } from '../../../store';
import { TrialBalanceGridComponent } from './components/trial-balance-grid/trial-balance-grid.component';


@Component({
selector: 'trial-balance',
templateUrl: './trial-balance.component.html'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ import { AccountsFilterPipe } from './pipes/accounts-filter.pipe';
BalanceSheetGridComponent,
BalanceSheetGridRowComponent,
FinancialAccordionDirective,
FinancialSearchPipe,
AccountsFilterPipe
],
exports: [
Expand Down Expand Up @@ -102,7 +101,8 @@ import { AccountsFilterPipe } from './pipes/accounts-filter.pipe';
AmountFieldComponentModule,
DatepickerWrapperModule,
PopoverModule.forRoot(),
AsideMenuAccountModule
AsideMenuAccountModule,
FinancialSearchPipe
],
})
export class FinancialReportsModule {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<ng-container
appTranslate
[file]="'trial-profit-balance/balance-sheet'"
(localeData)="localeData = $event"
(commonLocaleData)="commonLocaleData = $event"
>
<filter-multi-currency
#filter
(filterValue)="searchData($event)"
(onPropertyChanged)="filterData()"
(lastSyncDate)="lastDate($event)"
(seachChange)="searchChanged($event)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(seachChange)="searchChanged($event)"
(searchChange)="searchChanged($event)"

(expandAllChange)="expandAllEvent()"
[(expandAll)]="expandAll"
></filter-multi-currency>
dvCodeWorld marked this conversation as resolved.
Show resolved Hide resolved
<div *ngIf="showLoader | async">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove div and add condition directly in loader

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<giddh-page-loader [cssClass]="'mt-0 mb-0'"></giddh-page-loader>
</div>
<div *ngIf="!(showLoader | async) && data">
<balance-sheet-report-grid
#bsGrid
[search]="search"
[from]="from"
[to]="to"
(searchChange)="searchChanged($event)"
[expandAll]="expandAll"
[bsData]="data"
[lastSyncDate]="lastSyncDate"
></balance-sheet-report-grid>
</div>
<div *ngIf="!(showLoader | async) && !data" class="d-flex align-items-center justify-content-center tb-pl-bs-data">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<div *ngIf="!(showLoader | async) && !data" class="d-flex align-items-center justify-content-center tb-pl-bs-data">
<div *ngIf="!(showLoader | async) && !data" class="text-center tb-pl-bs-data">
<h2>{{ localeData?.no_data_found }}</h2>
</div>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

<div class="d-flex">
<h2>{{ localeData?.no_data_found }}</h2>
</div>
</div>
</ng-container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
import {
AfterViewInit,
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
EventEmitter,
Input,
OnDestroy,
Output,
ViewChild,
} from '@angular/core';
import { select, Store } from '@ngrx/store';
import { Observable, ReplaySubject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { CompanyResponse } from '../../models/api-models/Company';
import { BalanceSheetData, ProfitLossRequest } from '../../models/api-models/tb-pl-bs';
import { BalanceSheetReportGridComponent } from './components/balance-sheet-grid/balance-sheet-report-grid.component';
import { AppState } from '../../store';
import { TBPlBsActions } from '../../actions/tl-pl.actions';
import { ToasterService } from '../../services/toaster.service';
import { cloneDeep, each } from '../../lodash-optimized';
import { Account, ChildGroup } from '../../models/api-models/Search';
import { ReportType } from '../multi-currency.const';
import { MultiCurrencyReportsComponentStore } from '../multi-currency-reports.store';
import { prepareBalanceSheetData } from '../../store/tl-pl/tl-pl.reducer';

dvCodeWorld marked this conversation as resolved.
Show resolved Hide resolved

@Component({
selector: 'balance-sheet-report',
templateUrl: './balance-sheet-report.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
providers: [MultiCurrencyReportsComponentStore]
})
export class BalanceSheetReportComponent implements AfterViewInit, OnDestroy {
/**
* Retrieves the selected company
*
* @returns {CompanyResponse} The currently selected company
* @memberof BalanceSheetReportComponent
*/
public get selectedCompany(): CompanyResponse {
return this._selectedCompany;
}

/**
* Sets the selected company and fetches its data
*
* @param {CompanyResponse} value The company to set
* @memberof BalanceSheetReportComponent
*/
@Input()
public set selectedCompany(value: CompanyResponse) {
this._selectedCompany = value;
if (value && value.activeFinancialYear && value.financialYears && !this.isDateSelected) {
let index = this.findIndex(value.activeFinancialYear, value.financialYears);
this.request = {
refresh: false,
fy: index,
from: value.activeFinancialYear.financialYearStarts,
to: value.activeFinancialYear.financialYearEnds
};
}
}
/** Holds the local JSON data */
public localeData: any = {};
/** Holds the common JSON data */
public commonLocaleData: any = {};
/** Observable to indicate if the loader is visible */
public showLoader: Observable<boolean>;
/** Stores the balance sheet data */
public data: BalanceSheetData;
/** Stores the profit and loss request parameters */
public request: ProfitLossRequest;
/** Indicates whether all items are expanded */
public expandAll: boolean;
/** Holds the search text */
public search: string;
/** Stores the start date of the range */
public from: string;
/** Stores the end date of the range */
public to: string;
/** Stores the last sync date */
public lastSyncDate: string = "";
/** Indicates whether a date has been selected */
@Input() public isDateSelected: boolean = false;
/** Reference to the balance sheet grid component */
@ViewChild('bsGrid', { static: true }) public bsGrid: BalanceSheetReportGridComponent;
/** Subject to handle component destruction */
private destroyed$: ReplaySubject<boolean> = new ReplaySubject(1);
/** Stores the selected company data */
private _selectedCompany: CompanyResponse;

constructor(public tlPlActions: TBPlBsActions, private cd: ChangeDetectorRef, private toaster: ToasterService, private componentStore: MultiCurrencyReportsComponentStore) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
constructor(public tlPlActions: TBPlBsActions, private cd: ChangeDetectorRef, private toaster: ToasterService, private componentStore: MultiCurrencyReportsComponentStore) {
constructor(public tlPlActions: TBPlBsActions, private changeDetectionRef: ChangeDetectorRef, private toaster: ToasterService, private componentStore: MultiCurrencyReportsComponentStore) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

this.showLoader = this.componentStore.inProgressReport$;
this.componentStore.reportDataList$.pipe(takeUntil(this.destroyed$)).subscribe((response) => {
if (response) {
let data = prepareBalanceSheetData(cloneDeep(response));
if (data && data.message) {
setTimeout(() => {
this.toaster.clearAllToaster();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.toaster.clearAllToaster();

this.toaster.infoToast(data.message);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use showSnackbar

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

}, 100);
}
if (data && data.liabilities) {
this.InitData(data.liabilities);
data.liabilities.forEach(childGroup => {
childGroup['isVisible'] = true;
childGroup['isCreated'] = true;
childGroup['isIncludedInSearch'] = true;
});
}
if (data && data.assets) {
this.InitData(data.assets);
data.assets.forEach(childGroup => {
childGroup['isVisible'] = true;
childGroup['isCreated'] = true;
childGroup['isIncludedInSearch'] = true;
});
}
this.data = data;
this.cd.detectChanges();
} else {
this.data = null;
}
});
}

/**
* Initializes data for the balance sheet groups
*
* @param {ChildGroup[]} groupList The list of child groups
* @memberof BalanceSheetReportComponent
*/
public InitData(groupList: ChildGroup[]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public InitData(groupList: ChildGroup[]) {
public initData(groupList: ChildGroup[]) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also give meaning full name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

each(groupList, (childGroup: ChildGroup) => {
childGroup['isVisible'] = false;
childGroup['isCreated'] = false;
childGroup['isIncludedInSearch'] = true;
each(childGroup.accounts, (account: Account) => {
account['isIncludedInSearch'] = true;
account['isCreated'] = false;
account['isVisible'] = false;
});
if (childGroup.childGroups) {
this.InitData(childGroup.childGroups);
}
});
}

/**
* Detects changes after the view is initialized
*
* @memberof BalanceSheetReportComponent
*/
public ngAfterViewInit() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add return type in over all function

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

this.cd.detectChanges();
}

/**
* Filters data based on the given request
*
*
* @memberof BalanceSheetReportComponent
*/
public filterData() {
this.componentStore.getMultiCurrencyReport(ReportType.BalanceSheet);
}
/**
* Updates the last sync date
*
* @param {*} event The event containing the sync date
* @memberof BalanceSheetReportComponent
*/
public lastDate(event: any){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format all files in this pr

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

this.lastSyncDate = event ;
}

/**
* Searches and updates data based on the provided criteria
*
* @param {*} event The event containing search criteria
* @memberof BalanceSheetReportComponent
*/
public searchData(event: any) {
this.componentStore.creatMultiCurrencyReport({ reportType: ReportType.BalanceSheet, payload: event });
}

/**
* Cleans up resources when the component is destroyed
*
* @memberof BalanceSheetReportComponent
*/
public ngOnDestroy(): void {
this.destroyed$.next(true);
this.destroyed$.complete();
}

/**
* Finds the index of the active financial year in the list of financial years
*
* @param {*} activeFY The active financial year
* @param {*} financialYears The list of financial years
* @returns {number} The index of the active financial year
* @memberof BalanceSheetReportComponent
*/
public findIndex(activeFY, financialYears) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add type of function parameter

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

let tempFYIndex = 0;
each(financialYears, (fy: any, index: number) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use forEach loop and remove its import -> each

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (fy?.uniqueName === activeFY?.uniqueName) {
if (index === 0) {
tempFYIndex = index;
} else {
tempFYIndex = index * -1;
}
}
});
return tempFYIndex;
}

/**
* Expands all items in the balance sheet
*
* @memberof BalanceSheetReportComponent
*/
public expandAllEvent() {
setTimeout(() => {
this.cd.detectChanges();
}, 1);
dvCodeWorld marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Updates the search text and handles search functionality
*
* @param {string} event The new search text
* @memberof BalanceSheetReportComponent
*/
public searchChanged(event: string) {
this.search = event;
if (!this.search) {
this.expandAll = false;
}
this.cd.detectChanges();
}

}
Loading