@@ -177,37 +177,38 @@ export class CreateGlimAccountComponent {
177177 } ;
178178 }
179179
180- setData ( client : any , totalLoan : number ) : any {
180+ setData ( client : any , totalLoan : number , isParent ?: boolean ) : any {
181181 const locale = this . settingsService . language . code ;
182182 const dateFormat = this . settingsService . dateFormat ;
183183 // const monthDayFormat = 'dd MMMM';
184- const data = {
184+ const data : any = {
185185 ...this . loansAccount ,
186186 charges : this . loansAccount . charges . map ( ( charge : any ) => ( {
187187 chargeId : charge . id ,
188- amount : charge . amount
188+ amount : charge . amount ,
189+ currency : charge . currency
189190 } ) ) ,
190191 clientId : client . id ,
191- totalLoan : totalLoan ,
192192 loanType : 'glim' ,
193193 amortizationType : 1 ,
194- isParentAccount : true ,
195194 principal : client . principal ,
196195 syncDisbursementWithMeeting : false ,
197196 expectedDisbursementDate : this . dateUtils . formatDate ( this . loansAccount . expectedDisbursementDate , dateFormat ) ,
198197 submittedOnDate : this . dateUtils . formatDate ( this . loansAccount . submittedOnDate , dateFormat ) ,
199- dateFormat,
200- // monthDayFormat ,
201- locale
198+ dateFormat : dateFormat ,
199+ locale : locale ,
200+ groupId : this . loansAccountTemplate . group . id
202201 } ;
203- data . groupId = this . loansAccountTemplate . group . id ;
204-
202+ if ( isParent ) {
203+ data . totalLoan = totalLoan ;
204+ data . isParentAccount = true ;
205+ }
205206 delete data . principalAmount ;
206- // TODO: 2025-03-17: Apparently (?!) unsupported for GLIM
207207 delete data . allowPartialPeriodInterestCalculation ;
208208 delete data . multiDisburseLoan ;
209209 delete data . isFloatingInterestRate ;
210-
210+ delete data . moratoriumPrincipal ;
211+ delete data . moratoriumInterest ;
211212 return JSON . stringify ( data ) ;
212213 }
213214
@@ -216,12 +217,22 @@ export class CreateGlimAccountComponent {
216217 const requestData = [ ] ;
217218 const memberSelected = this . selectedMembers ?. selectedMembers ?? [ ] ;
218219 const totalLoan = this . totalLoanAmount ( ) ;
220+ requestData . push ( {
221+ requestId : '0' ,
222+ method : 'POST' ,
223+ relativeUrl : 'loans' ,
224+ body : this . setData (
225+ { id : this . loansAccountTemplate . group . id , principal : totalLoan , isParentAccount : true } ,
226+ totalLoan ,
227+ true
228+ )
229+ } ) ;
219230 for ( let index = 0 ; index < memberSelected . length ; index ++ ) {
220231 requestData . push ( {
221- requestId : index . toString ( ) ,
232+ requestId : ( index + 1 ) . toString ( ) ,
222233 method : 'POST' ,
223234 relativeUrl : 'loans' ,
224- body : this . setData ( memberSelected [ index ] , totalLoan )
235+ body : this . setData ( memberSelected [ index ] , totalLoan , false )
225236 } ) ;
226237 }
227238 return requestData ;
@@ -236,57 +247,10 @@ export class CreateGlimAccountComponent {
236247 return total ;
237248 }
238249
239- /**
240- * Creates a new GLIM account.
241- */
242- submit ( ) {
243- this . selectedMembers = this . loansActiveClientMembers ?. selectedClientMembers ;
244- const memberSelected = this . loansActiveClientMembers ?. selectedClientMembers ?. selectedMembers ?? [ ] ;
245- if ( ! memberSelected . length ) return ;
246- const gsimMemberIds = new Set ( this . dataSource . map ( ( m : any ) => Number ( m . id ) ) ) ;
247- for ( const member of memberSelected ) {
248- const memberId = Number ( member . id ) ;
249- // Validate savings account ownership
250- const ownerId = Number ( member . linkAccountOwnerId ) ;
251- if ( member . linkAccountId && member . linkAccountOwnerId && ownerId !== memberId ) {
252- this . i18nService . translate ( 'errors.linkedSavingsAccountOwnership' ) . subscribe ( ( msg : string ) => {
253- this . notify ( { defaultUserMessage : msg , errors : [ ] } , { memberId } ) ;
254- } ) ;
255- return ;
256- }
257- // Validate GSIM membership
258- if ( ! gsimMemberIds . has ( memberId ) ) {
259- this . i18nService . translate ( 'errors.clientNotInGSIM' , { id : memberId } ) . subscribe ( ( msg : string ) => {
260- this . notify ( { defaultUserMessage : msg , errors : [ ] } , { memberId } ) ;
261- } ) ;
262- return ;
263- }
264- }
265-
266- // Use date format from settingsService for interestChargedFromDate
267- const data = this . buildRequestData ( ) ;
268- this . loansService . createGlimAccount ( data ) . subscribe ( ( response : any ) => {
269- const body = JSON . parse ( response [ 0 ] . body ) ;
270- if ( body . glimId ) {
271- this . router . navigate (
272- [
273- '../' ,
274- body . glimId
275- ] ,
276- { relativeTo : this . route }
277- ) ;
278- } else {
279- this . notify ( body , { batchSize : data . length } ) ;
280- }
281- } ) ;
282- }
283-
284- notify ( body : any , context ?: { [ k : string ] : unknown } ) {
285- const parts : string [ ] = [ String ( body ?. defaultUserMessage ?? '' ) ] ;
286- if ( Array . isArray ( body ?. errors ) ) {
287- for ( const e of body . errors ) parts . push ( String ( e ?. developerMessage ?? '' ) ) ;
288- }
289- if ( context ) parts . push ( `Context: ${ JSON . stringify ( context ) } ` ) ;
290- console . error ( parts . join ( ' ' ) . trim ( ) ) ;
250+ notify ( body : any , data : any ) {
251+ let message = body . defaultUserMessage + ' ' ;
252+ body . errors ?. forEach ( ( error : any ) => ( message += error . developerMessage + ' ' ) ) ;
253+ message += 'Data: ' + JSON . stringify ( data ) ;
254+ console . error ( message ) ;
291255 }
292256}
0 commit comments