@@ -177,37 +177,36 @@ 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 ,
188188 amount : charge . amount
189189 } ) ) ,
190190 clientId : client . id ,
191- totalLoan : totalLoan ,
192191 loanType : 'glim' ,
193192 amortizationType : 1 ,
194- isParentAccount : true ,
195193 principal : client . principal ,
196194 syncDisbursementWithMeeting : false ,
197195 expectedDisbursementDate : this . dateUtils . formatDate ( this . loansAccount . expectedDisbursementDate , dateFormat ) ,
198196 submittedOnDate : this . dateUtils . formatDate ( this . loansAccount . submittedOnDate , dateFormat ) ,
199- dateFormat,
200- // monthDayFormat ,
201- locale
197+ dateFormat : dateFormat ,
198+ locale : locale ,
199+ groupId : this . loansAccountTemplate . group . id
202200 } ;
203- data . groupId = this . loansAccountTemplate . group . id ;
204-
201+ if ( isParent ) {
202+ data . totalLoan = totalLoan ;
203+ data . isParentAccount = true ;
204+ }
205205 delete data . principalAmount ;
206206 // TODO: 2025-03-17: Apparently (?!) unsupported for GLIM
207207 delete data . allowPartialPeriodInterestCalculation ;
208208 delete data . multiDisburseLoan ;
209209 delete data . isFloatingInterestRate ;
210-
211210 return JSON . stringify ( data ) ;
212211 }
213212
@@ -216,12 +215,22 @@ export class CreateGlimAccountComponent {
216215 const requestData = [ ] ;
217216 const memberSelected = this . selectedMembers ?. selectedMembers ?? [ ] ;
218217 const totalLoan = this . totalLoanAmount ( ) ;
218+ requestData . push ( {
219+ requestId : '0' ,
220+ method : 'POST' ,
221+ relativeUrl : 'loans' ,
222+ body : this . setData (
223+ { id : this . loansAccountTemplate . group . id , principal : totalLoan , isParentAccount : true } ,
224+ totalLoan ,
225+ true
226+ )
227+ } ) ;
219228 for ( let index = 0 ; index < memberSelected . length ; index ++ ) {
220229 requestData . push ( {
221- requestId : index . toString ( ) ,
230+ requestId : ( index + 1 ) . toString ( ) ,
222231 method : 'POST' ,
223232 relativeUrl : 'loans' ,
224- body : this . setData ( memberSelected [ index ] , totalLoan )
233+ body : this . setData ( memberSelected [ index ] , totalLoan , false )
225234 } ) ;
226235 }
227236 return requestData ;
@@ -236,57 +245,10 @@ export class CreateGlimAccountComponent {
236245 return total ;
237246 }
238247
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 ( ) ) ;
248+ notify ( body : any , data : any ) {
249+ let message = body . defaultUserMessage + ' ' ;
250+ body . errors ?. forEach ( ( error : any ) => ( message += error . developerMessage + ' ' ) ) ;
251+ message += 'Data: ' + JSON . stringify ( data ) ;
252+ console . error ( message ) ;
291253 }
292254}
0 commit comments