194 lines
6.6 KiB
TypeScript
194 lines
6.6 KiB
TypeScript
/**
|
|
* 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/.
|
|
*/
|
|
|
|
/** Angular Imports */
|
|
import { Injectable, inject } from '@angular/core';
|
|
import { HttpClient, HttpParams } from '@angular/common/http';
|
|
|
|
/** rxjs Imports */
|
|
import { Observable } from 'rxjs';
|
|
|
|
/**
|
|
* Shares Service.
|
|
*/
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class SharesService {
|
|
private http = inject(HttpClient);
|
|
|
|
/**
|
|
* @param {any} params Optional HTTP params (like offset, limit, search)
|
|
* @returns {Observable<any>} List of all share accounts
|
|
*/
|
|
getSharesAccounts(params?: any): Observable<any> {
|
|
return this.http.get('/accounts/share', { params });
|
|
}
|
|
|
|
/**
|
|
* @returns {Observable<any>} List of all share accounts with client details summary
|
|
*/
|
|
getShareAccountSummaries(searchTerm?: string): Observable<any> {
|
|
let params = new HttpParams();
|
|
if (searchTerm) {
|
|
params = params.set('searchTerm', searchTerm);
|
|
}
|
|
return this.http.get('/shareaccounts/summary', { params });
|
|
}
|
|
|
|
/**
|
|
* @returns {Observable<any>} List of all offices
|
|
*/
|
|
getOffices(): Observable<any> {
|
|
return this.http.get('/offices');
|
|
}
|
|
|
|
/**
|
|
* @returns {Observable<any>} List of all share products
|
|
*/
|
|
getShareProducts(): Observable<any> {
|
|
return this.http.get('/products/share');
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId Shares Account Id of account to get data for.
|
|
* @param {boolean} template Shares account template required?.
|
|
* @returns {Observable<any>} Shares data.
|
|
*/
|
|
getSharesAccountData(accountId: string, template: boolean): Observable<any> {
|
|
const httpParams = new HttpParams().set('template', template.toString());
|
|
return this.http.get(`/accounts/share/${accountId}`, { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* @param {number} offset Paging offset.
|
|
* @param {number} limit Paging size limit.
|
|
* @returns {Observable<any>} A page of all (active) share accounts, backed by m_share_account.
|
|
*/
|
|
getAllShareAccounts(offset: number = 0, limit: number = 200): Observable<any> {
|
|
const httpParams = new HttpParams().set('offset', offset.toString()).set('limit', limit.toString());
|
|
return this.http.get('/accounts/share', { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* @param {string} clientId Client Id assosciated with shares account.
|
|
* @param {string} productId Product Id
|
|
* @returns {Observable<any>} Shares account template.
|
|
*/
|
|
getSharesAccountTemplate(clientId: string, productId?: string): Observable<any> {
|
|
let httpParams = new HttpParams().set('clientId', clientId);
|
|
httpParams = productId ? httpParams.set('productId', productId) : httpParams;
|
|
return this.http.get('/accounts/share/template', { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* @param {any} sharesAccount Shares Account
|
|
* @returns {Observable<any>}
|
|
*/
|
|
createSharesAccount(sharesAccount: any): Observable<any> {
|
|
return this.http.post('/accounts/share', sharesAccount);
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId: Shares account Id.
|
|
* @param {any} sharesAccount Shares Account
|
|
* @returns {Observable<any>}
|
|
*/
|
|
updateSharesAccount(accountId: string, sharesAccount: any): Observable<any> {
|
|
return this.http.put(`/accounts/share/${accountId}`, sharesAccount);
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId shares account Id
|
|
* @returns {Observable<any>}
|
|
*/
|
|
deleteSharesAccount(accountId: string): Observable<any> {
|
|
return this.http.delete(`/accounts/share/${accountId}`);
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId Shares Account Id
|
|
* @param {string} command Command
|
|
* @param {any} data Data
|
|
* @returns {Observable<any>} Shares data.
|
|
*/
|
|
executeSharesAccountCommand(accountId: string, command: string, data: any): Observable<any> {
|
|
const httpParams = new HttpParams().set('command', command);
|
|
return this.http.post(`/accounts/share/${accountId}`, data, { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* Whether a new additional-share tranche can be funded from the member's linked savings.
|
|
*
|
|
* Tranche-scoped, unlike `/sharesavingsdebit/eligibility`: that one values an account's first
|
|
* application by summing every purchase on the account, which for a further tranche would quote
|
|
* the member's whole holding history and call an already-settled account ineligible.
|
|
*
|
|
* @returns {Observable<any>} `{ eligible, reason, requestedShares, unitPrice, amount,
|
|
* savingsAccountNo, savingsBalance }`.
|
|
*/
|
|
getAdditionalSharesSavingsEligibility(accountId: string, requestedShares: number): Observable<any> {
|
|
const httpParams = new HttpParams().set('requestedShares', String(requestedShares));
|
|
return this.http.get(`/shareaccounts/${accountId}/additionalshares/savings-eligibility`, { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId Shares Account Id.
|
|
* @param {any} data Details edit payload.
|
|
* @returns {Observable<any>}
|
|
*/
|
|
submitShareAccountEdit(accountId: string, data: any): Observable<any> {
|
|
return this.http.post(`/shareaccounts/${accountId}/edit`, data);
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId Shares Account Id.
|
|
* @returns {Observable<any>} The pending details edit for this account, if any.
|
|
*/
|
|
getPendingShareAccountEdit(accountId: string): Observable<any> {
|
|
return this.http.get(`/shareaccounts/${accountId}/edit/pending`);
|
|
}
|
|
|
|
/**
|
|
* @returns {Observable<any>} All Share Account details edits pending approval.
|
|
*/
|
|
getAllPendingShareAccountEdits(): Observable<any> {
|
|
return this.http.get(`/shareaccounts/edit/pending`);
|
|
}
|
|
|
|
/**
|
|
* Share accounts submitted and awaiting a checker's approval.
|
|
*
|
|
* Its own endpoint rather than `/accounts/share`, which only lists ACTIVE accounts and returns the
|
|
* whole account graph per row; this returns just the member, product, requested shares and value a
|
|
* checker decides on.
|
|
*
|
|
* @returns {Observable<any>} One row per pending account.
|
|
*/
|
|
getPendingShareAccounts(): Observable<any> {
|
|
return this.http.get('/shareaccounts/pending');
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId Shares Account Id.
|
|
* @returns {Observable<any>}
|
|
*/
|
|
approveShareAccountEdit(accountId: string): Observable<any> {
|
|
return this.http.post(`/shareaccounts/${accountId}/edit/approve`, {});
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId Shares Account Id.
|
|
* @param {string} rejectReason Optional reason for rejection.
|
|
* @returns {Observable<any>}
|
|
*/
|
|
rejectShareAccountEdit(accountId: string, rejectReason?: string): Observable<any> {
|
|
return this.http.post(`/shareaccounts/${accountId}/edit/reject`, { rejectReason: rejectReason || '' });
|
|
}
|
|
}
|