/** * Copyright since 2025 Mifos Initiative * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { Component, OnInit, inject } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { MatIcon } from '@angular/material/icon'; import { MatProgressSpinner } from '@angular/material/progress-spinner'; import { ClientsService } from '../../clients.service'; @Component({ selector: 'mifosx-entity-classification-tab', templateUrl: './entity-classification-tab.component.html', styleUrls: ['./entity-classification-tab.component.scss'], imports: [ ...STANDALONE_SHARED_IMPORTS, FaIconComponent, MatIcon, MatProgressSpinner ] }) export class EntityClassificationTabComponent implements OnInit { private route = inject(ActivatedRoute); private clientsService = inject(ClientsService); clientId: string = ''; loading = true; data: any = null; /** Category metadata for display */ categories = [ { key: 'msme', label: 'MSME', tag: 'Udyam / MSME', tagColor: '#0A5C6B', tagBg: '#E6F4F6', icon: 'cogs' }, { key: 'startup', label: 'Startup India', tag: 'DPIIT', tagColor: '#1A5FAB', tagBg: '#EAF2FB', icon: 'rocket' }, { key: 'mudra', label: 'Mudra Borrower', tag: 'PMMY', tagColor: '#8A5A00', tagBg: '#FEF3DC', icon: 'hand-holding-usd' }, { key: 'eou', label: 'Export Oriented Unit', tag: 'EOU', tagColor: '#1B7A4A', tagBg: '#E8F5EE', icon: 'ship' }, { key: 'importexport', label: 'Import Export', tag: 'DGFT / IEC', tagColor: '#5B3A8A', tagBg: '#F0EBF8', icon: 'exchange-alt' }, { key: 'psl', label: 'Priority Sector', tag: 'RBI PSL', tagColor: '#7B1F1F', tagBg: '#FCEAEA', icon: 'bullseye' }, { key: 'nps', label: 'Non-Priority Sector', tag: 'General', tagColor: '#444441', tagBg: '#F1EFE8', icon: 'building' } ]; ngOnInit() { this.clientId = this.route.parent?.snapshot.paramMap.get('clientId') || ''; if (this.clientId) { this.clientsService.getEntityClassifications(this.clientId).subscribe({ next: (res: any) => { this.data = res; this.loading = false; }, error: () => { this.loading = false; } }); } else { this.loading = false; } } get enabledCategories(): any[] { if (!this.data) return []; return this.categories.filter((c) => this.data[c.key]?.enabled); } getCategoryData(key: string): any { return this.data?.[key] || {}; } getFieldPairs(catData: any): { label: string; value: any }[] { if (!catData) return []; const skip = [ 'id', 'clientId', 'enabled', 'locale', 'dateFormat' ]; return Object.keys(catData) .filter((k) => !skip.includes(k) && catData[k] != null && catData[k] !== '' && catData[k] !== false) .map((k) => ({ label: this.formatLabel(k), value: this.formatValue(catData[k]) })); } private formatLabel(key: string): string { return key .replace(/([A-Z])/g, ' $1') .replace(/^./, (s) => s.toUpperCase()) .replace(/Id$/, '') .trim(); } private formatValue(val: any): string { if (Array.isArray(val) && val.length === 3) { return `${val[2]}/${val[1]}/${val[0]}`; } if (val === true) return 'Yes'; if (typeof val === 'number') return val.toLocaleString('en-IN'); return String(val); } }