Aman-Mittal commented on code in PR #70:
URL:
https://github.com/apache/fineract-backoffice-ui/pull/70#discussion_r3333626275
##########
src/app/features/loans/loan-form.component.ts:
##########
@@ -274,71 +396,79 @@ export class LoanFormComponent implements OnInit {
});
}
- loadProducts() {
- this.productService.retrieveAllLoanProducts().subscribe((products) => {
- this.products = products;
+ /**
+ * Fetches loan products from the API.
+ */
+ private loadProducts() {
+ this.productService.retrieveAllLoanProducts().subscribe({
+ next: (data: GetLoanProductsResponse[]) => (this.products = data || []),
+ error: (err: unknown) => console.error('Failed to load products', err),
});
}
- loadLoanData() {
+ /**
+ * Loads existing loan data for editing.
+ */
+ private loadLoanData() {
if (!this.loanId) return;
- this.loansService.retrieveLoan(this.loanId).subscribe((loanData) => {
- const subArray = loanData.timeline?.submittedOnDate as unknown as
number[];
- const disbArray = loanData.timeline?.expectedDisbursementDate as unknown
as number[];
-
- if (subArray) this.submittedOnDate = new Date(subArray[0], subArray[1] -
1, subArray[2]);
- if (disbArray)
- this.expectedDisbursementDate = new Date(disbArray[0], disbArray[1] -
1, disbArray[2]);
-
- this.loan = {
- clientId: loanData.clientId,
- productId: loanData.loanProductId,
- principal: loanData.principal,
- externalId: loanData.externalId,
- loanTermFrequency: loanData.termFrequency,
- loanTermFrequencyType: loanData.termPeriodFrequencyType?.id,
- numberOfRepayments: loanData.numberOfRepayments,
- repaymentEvery: loanData.repaymentEvery,
- };
+ this.loansService.retrieveLoan(this.loanId).subscribe({
+ next: (data: GetLoansLoanIdResponse) => {
+ this.loan = {
+ clientId: data.clientId,
+ productId: data.loanProductId,
+ principal: data.principal,
+ externalId: data.externalId,
+ loanTermFrequency: data.termFrequency,
+ loanTermFrequencyType: data.termPeriodFrequencyType?.id,
+ numberOfRepayments: data.numberOfRepayments,
+ repaymentEvery: data.repaymentEvery,
+ repaymentFrequencyType: data.repaymentFrequencyType?.id,
+ interestRatePerPeriod: data.interestRatePerPeriod,
+ interestType: data.interestType?.id,
+ amortizationType: data.amortizationType?.id,
+ interestCalculationPeriodType:
data.interestCalculationPeriodType?.id,
+ };
+ },
+ error: (err: unknown) => console.error('Failed to load loan details',
err),
});
}
+ /**
+ * Handles form submission.
+ */
onSubmit() {
this.isSaving = true;
- const formattedSubDate = `${this.submittedOnDate.getFullYear()}-${String(
- this.submittedOnDate.getMonth() + 1,
- ).padStart(2, '0')}-${String(this.submittedOnDate.getDate()).padStart(2,
'0')}`;
- const formattedDisbDate =
`${this.expectedDisbursementDate.getFullYear()}-${String(
- this.expectedDisbursementDate.getMonth() + 1,
- ).padStart(2,
'0')}-${String(this.expectedDisbursementDate.getDate()).padStart(2, '0')}`;
+ // Format dates for Fineract API
+ const formatDate = (date: Date) =>
+ `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2,
'0')}-${String(
+ date.getDate(),
+ ).padStart(2, '0')}`;
+
+ this.loan.submittedOnDate = formatDate(this.submittedOnDate);
+ this.loan.expectedDisbursementDate =
formatDate(this.expectedDisbursementDate);
+ this.loan.dateFormat = 'yyyy-MM-dd';
+ this.loan.locale = 'en';
+ this.loan.transactionProcessingStrategyCode = 'mifos-standard-strategy';
Review Comment:
Thanks for pointing it out will fix this.
Need to also handle this in Loan Product Creation too.
My fix:
Add the Repayment strategy in Loan Product Creation
And then extract here as transactionProcessingStrategy code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]