202 lines
7.3 KiB
TypeScript
202 lines
7.3 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';
|
|
|
|
/**
|
|
* Recurring Deposits Service.
|
|
*/
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class RecurringDepositsService {
|
|
private http = inject(HttpClient);
|
|
|
|
/**
|
|
* @params recurringDepositAccountId
|
|
* Returns the details of a particular Recurring Deposit Account
|
|
*/
|
|
getRecurringDepositsAccountData(recurringDepositAccountId: any): Observable<any> {
|
|
const httpParams = new HttpParams().set('associations', 'all');
|
|
return this.http.get(`/recurringdepositaccounts/${recurringDepositAccountId}`, { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* Loans this recurring deposit currently secures (lien), with the amount each one holds.
|
|
* Returns { totalLienAmount, liens: [{ loanId, loanAccountNo, loanStatus, amount }] }.
|
|
*/
|
|
getRecurringDepositLiens(recurringDepositAccountId: any): Observable<any> {
|
|
return this.http.get(`/recurringdepositaccounts/${recurringDepositAccountId}/liens`);
|
|
}
|
|
|
|
/**
|
|
* This deposit's installment position as of the business date (next due date, overdue count/amount), from the
|
|
* RD Dashboard endpoint - the same paid/overdue rule the auto-debit and penalty jobs use. Older backends ignore
|
|
* `accountId` and return every RD, so callers pick the row by id.
|
|
*/
|
|
getRecurringDepositInstallmentPosition(recurringDepositAccountId: any): Observable<any> {
|
|
const httpParams = new HttpParams().set('accountId', recurringDepositAccountId);
|
|
return this.http.get('/recurringdepositaccounts/dashboard', { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* @param clientId Client Id
|
|
* @param clientName Client Name
|
|
* @param fromAccountId Account Id
|
|
* @param locale Locale
|
|
* @param dateFormat Date Format
|
|
* @returns {Observable<any>} Standing Instructions
|
|
*/
|
|
getStandingInstructions(
|
|
clientId: string,
|
|
clientName: string,
|
|
fromAccountId: string,
|
|
locale: string,
|
|
dateFormat: string
|
|
): Observable<any> {
|
|
const httpParams = new HttpParams()
|
|
.set('clientId', clientId)
|
|
.set('clientName', clientName)
|
|
.set('fromAccountId', fromAccountId)
|
|
.set('fromAccountType', '2')
|
|
.set('locale', locale)
|
|
.set('dateFormat', dateFormat);
|
|
return this.http.get(`/standinginstructions`, { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* Returns Recurring Deposit Account Template Data
|
|
* @param clientId Client ID
|
|
* @param productId Product ID
|
|
*/
|
|
getRecurringDepositsAccountTemplate(clientId: any, productId?: any): Observable<any> {
|
|
let httpParams = new HttpParams().set('clientId', clientId);
|
|
httpParams = productId ? httpParams.set('productId', productId) : httpParams;
|
|
return this.http.get(`/recurringdepositaccounts/template`, { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* Post Request to create a recurring deposit account
|
|
* @param recurringAccountData Recurring Deposit Account Data
|
|
*/
|
|
createRecurringDepositAccount(recurringAccountData: any): Observable<any> {
|
|
return this.http.post(`/recurringdepositaccounts`, recurringAccountData);
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId Savings Account Id
|
|
* @param {string} command Command
|
|
* @param {any} data Data
|
|
* @returns {Observable<any>}
|
|
*/
|
|
executeRecurringDepositsAccountCommand(accountId: string, command: string, data: any): Observable<any> {
|
|
const httpParams = new HttpParams().set('command', command);
|
|
if (command === 'deposit' || command === 'withdrawal') {
|
|
return this.http.post(`/recurringdepositaccounts/${accountId}/transactions`, data, { params: httpParams });
|
|
}
|
|
return this.http.post(`/recurringdepositaccounts/${accountId}`, data, { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId recurring deposits account Id
|
|
* @returns {Observable<any>}
|
|
*/
|
|
deleteRecurringDepositsAccount(accountId: string): Observable<any> {
|
|
return this.http.delete(`/recurringdepositaccounts/${accountId}`);
|
|
}
|
|
|
|
/**
|
|
* Get Recurring Deposits Account and Template Data
|
|
* @param accountId Account ID
|
|
*/
|
|
getRecurringDepositsAccountAndTemplate(accountId: any) {
|
|
const httpParams = new HttpParams().set('associations', 'charges').set('template', 'true');
|
|
return this.http.get(`/recurringdepositaccounts/${accountId}`, { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* @param {any} accountId Account Id
|
|
* @param {any} recurringDepositAccountData Recurring Deposit Account Data
|
|
* @returns {Observable<any>}
|
|
*/
|
|
updateRecurringDepositAccount(accountId: any, recurringDepositAccountData: any): Observable<any> {
|
|
return this.http.put(`/recurringdepositaccounts/${accountId}`, recurringDepositAccountData);
|
|
}
|
|
|
|
/**
|
|
* Returns the template for the recurring deposits action
|
|
* @param accountId Account Id
|
|
* @param command Command
|
|
*/
|
|
getRecurringDepositAccountActionResource(accountId: any, command: string): Observable<any> {
|
|
const httpParams = new HttpParams().set('command', command);
|
|
return this.http.get(`/recurringdepositaccounts/${accountId}/template`, { params: httpParams });
|
|
}
|
|
|
|
/**
|
|
* Returns the transaction template for the recurring deposits action
|
|
* @param accountId Account Id
|
|
* @param command Command
|
|
*/
|
|
getRecurringDepositAccountTransactionTemplateResource(accountId: any, command: string): Observable<any> {
|
|
const httpParams = new HttpParams().set('command', command);
|
|
return this.http.get(`/recurringdepositaccounts/${accountId}/transactions/template`, { params: httpParams });
|
|
}
|
|
/*
|
|
* @param {string} accountId Recurring Deposits Account Id
|
|
* @param {string} transactionId Transaction Id
|
|
* @returns {Observable<any>}
|
|
*/
|
|
getRecurringDepositsAccountTransaction(accountId: string, transactionId: string): Observable<any> {
|
|
return this.http.get(`/recurringdepositaccounts/${accountId}/transactions/${transactionId}`);
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId Recuring Deposits Account Id
|
|
* @param {string} transactionId Transaction Id
|
|
* @returns {Observable<any>}
|
|
*/
|
|
getRecurringDepositsAccountTransactionTemplate(accountId: string, transactionId: string): Observable<any> {
|
|
const httpParams = new HttpParams().set('template', 'true');
|
|
return this.http.get(`/recurringdepositaccounts/${accountId}/transactions/${transactionId}`, {
|
|
params: httpParams
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @param {string} accountId Recurring Deposits Account Id
|
|
* @param {string} command Command
|
|
* @param {any} data Data
|
|
* @param {string} transactionId Transaction Id
|
|
* @returns {Observable<any>}
|
|
*/
|
|
executeRecurringDepositsAccountTransactionsCommand(
|
|
accountId: string,
|
|
command: string,
|
|
data: any,
|
|
transactionId?: any
|
|
): Observable<any> {
|
|
const httpParams = new HttpParams().set('command', command);
|
|
return this.http.post(`/recurringdepositaccounts/${accountId}/transactions/${transactionId}`, data, {
|
|
params: httpParams
|
|
});
|
|
}
|
|
/**
|
|
* Calculates the interest for a recurring deposit account
|
|
* @param data Calculation data
|
|
*/
|
|
calculateRecurringDepositInterest(data: any): Observable<any> {
|
|
return this.http.post(`/recurringdepositaccounts/calculate-rd-interest`, data);
|
|
}
|
|
}
|