/** * 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 { Injectable, inject } from '@angular/core'; import { HttpClient, HttpContext, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; import { SILENT_HTTP_ERROR } from '../core/http/silent-error.token'; /** HTTP service for the Clerk Closure Request maker-checker workflow (Cash-only savings account * closure). Mirrors ClerkWithdrawalService's shape against the /clerk/closure-requests endpoints. */ @Injectable({ providedIn: 'root' }) export class ClerkClosureRequestService { private http = inject(HttpClient); submit(data: any): Observable { return this.http.post('/clerk/closure-requests', data); } getMyRequests(status?: string, offset = 0, limit = 20, fromDate?: string, toDate?: string): Observable { let params = new HttpParams().set('offset', String(offset)).set('limit', String(limit)); if (status) params = params.set('status', status); if (fromDate) params = params.set('fromDate', fromDate); if (toDate) params = params.set('toDate', toDate); return this.http.get('/clerk/closure-requests/my', { params }); } getPendingRequests( status = 'PENDING', offset = 0, limit = 20, fromDate?: string, toDate?: string, search?: string ): Observable { let params = new HttpParams().set('status', status).set('offset', String(offset)).set('limit', String(limit)); if (fromDate) params = params.set('fromDate', fromDate); if (toDate) params = params.set('toDate', toDate); if (search) params = params.set('search', search); return this.http.get('/clerk/closure-requests', { params }); } getById(id: number): Observable { return this.http.get(`/clerk/closure-requests/${id}`); } /** Posts every rupee of interest the member has earned up to today straight onto the account — * the same posting close() itself performs — and returns the resulting real balance. Not a dry * run: ticking "Close this account" is meant to credit the interest immediately, not estimate it. */ postClosureInterest(savingsAccountId: number): Observable { return this.http.post(`/clerk/closure-requests/post-interest/${savingsAccountId}`, {}); } approve(id: number): Observable { return this.http.post(`/clerk/closure-requests/${id}/approve`, {}); } reject(id: number, reason: string): Observable { return this.http.post(`/clerk/closure-requests/${id}/reject`, { reason }); } // Silenced: onTokNoBlur() probes this expecting a possible legitimate 404 (token not from this // pool, could be a withdrawal/dividend claim's instead) and shows its own tailored message either way. getByToken(token: string): Observable { return this.http.get(`/clerk/closure-requests/by-token/${encodeURIComponent(token)}`, { context: new HttpContext().set(SILENT_HTTP_ERROR, true) }); } disburse(id: number, denominationData: string | null, transactionAmount?: number): Observable { return this.http.post(`/clerk/closure-requests/${id}/disburse`, { denominationData, transactionAmount: transactionAmount != null ? String(transactionAmount) : null }); } }