/** * 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 } from '@angular/common/http'; import { Observable } from 'rxjs'; import { SILENT_HTTP_ERROR } from '../core/http/silent-error.token'; /** * HTTP service for the maker-checker "claim my dividend early" workflow — a clerk submits a claim * against a still-locked dividend on the member's behalf, a Bank Manager approves (only possible * when the client has no overdue loan) or rejects it. */ @Injectable({ providedIn: 'root' }) export class DividendClaimRequestService { private http = inject(HttpClient); /** * Records a claim for an unclaimed dividend, collected as a Demand Draft. * * A dividend is only ever paid out as a draft — the savings-credit, cash and loan-set-off routes * this endpoint once accepted are retired, so the payload carries just what a draft needs: how * much, drawn in whose favour, and payable where. */ submit( lockId: number, claim: { ddApplyAmount: number; ddBeneficiaryName: string; ddPayableAtBranch: string; ddPayableAtCity: string; } ): Observable { return this.http.post('/clerk/dividend-claim-requests', { lockId, ddApplyAmount: String(claim.ddApplyAmount), ddBeneficiaryName: claim.ddBeneficiaryName, ddPayableAtBranch: claim.ddPayableAtBranch, ddPayableAtCity: claim.ddPayableAtCity }); } // Silenced: onTokNoBlur() in Transaction Entry probes this only after the withdrawal-request // token pool 404s, and shows its own tailored message either way. getByToken(token: string): Observable { return this.http.get(`/clerk/dividend-claim-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/dividend-claim-requests/${id}/disburse`, { denominationData, transactionAmount: transactionAmount != null ? String(transactionAmount) : null }); } list(status = 'PENDING'): Observable { return this.http.get('/clerk/dividend-claim-requests', { params: { status } }); } approve(id: number): Observable { return this.http.post(`/clerk/dividend-claim-requests/${id}/approve`, {}); } reject(id: number, reason: string): Observable { return this.http.post(`/clerk/dividend-claim-requests/${id}/reject`, { reason }); } }