15
15
*/
16
16
package io .mifos .individuallending ;
17
17
18
- import com .google .common .collect .Sets ;
19
18
import com .google .gson .Gson ;
20
19
import io .mifos .core .lang .ServiceException ;
21
20
import io .mifos .customer .api .v1 .client .CustomerManager ;
30
29
import io .mifos .individuallending .internal .service .CostComponentService ;
31
30
import io .mifos .individuallending .internal .service .DataContextOfAction ;
32
31
import io .mifos .individuallending .internal .service .DataContextService ;
33
- import io .mifos .portfolio .api .v1 .domain .Case ;
34
- import io .mifos .portfolio .api .v1 .domain .ChargeDefinition ;
35
- import io .mifos .portfolio .api .v1 .domain .CostComponent ;
36
- import io .mifos .portfolio .api .v1 .domain .Pattern ;
32
+ import io .mifos .individuallending .internal .service .PaymentBuilder ;
33
+ import io .mifos .portfolio .api .v1 .domain .*;
37
34
import io .mifos .portfolio .service .ServiceConstants ;
38
35
import io .mifos .products .spi .PatternFactory ;
39
36
import io .mifos .products .spi .ProductCommandDispatcher ;
47
44
import java .time .temporal .ChronoUnit ;
48
45
import java .util .*;
49
46
import java .util .stream .Collectors ;
50
- import java .util .stream .Stream ;
51
47
52
48
import static io .mifos .individuallending .api .v1 .domain .product .AccountDesignators .*;
53
49
import static io .mifos .individuallending .api .v1 .domain .product .ChargeIdentifiers .*;
@@ -88,8 +84,8 @@ public Pattern pattern() {
88
84
89
85
final Set <String > individualLendingRequiredAccounts = new HashSet <>();
90
86
individualLendingRequiredAccounts .add (CUSTOMER_LOAN );
91
- individualLendingRequiredAccounts .add (PENDING_DISBURSAL );
92
- individualLendingRequiredAccounts . add ( LOAN_FUNDS_SOURCE ) ;
87
+ //TODO: fix in migration individualLendingRequiredAccounts.add(PENDING_DISBURSAL);
88
+ //was String PENDING_DISBURSAL = "pending-disbursal" ;
93
89
individualLendingRequiredAccounts .add (LOAN_FUNDS_SOURCE );
94
90
individualLendingRequiredAccounts .add (PROCESSING_FEE_INCOME );
95
91
individualLendingRequiredAccounts .add (ORIGINATION_FEE_INCOME );
@@ -111,60 +107,64 @@ public List<ChargeDefinition> charges() {
111
107
public static List <ChargeDefinition > defaultIndividualLoanCharges () {
112
108
final List <ChargeDefinition > ret = new ArrayList <>();
113
109
final ChargeDefinition processingFee = charge (
114
- PROCESSING_FEE_NAME ,
115
- Action . OPEN ,
116
- BigDecimal .ONE ,
117
- ENTRY ,
118
- PROCESSING_FEE_INCOME );
110
+ PROCESSING_FEE_NAME ,
111
+ Action . DISBURSE , //TODO: fix existing charges in migration
112
+ BigDecimal .ONE ,
113
+ CUSTOMER_LOAN , //TODO: fix existing charges in migration
114
+ PROCESSING_FEE_INCOME );
119
115
processingFee .setReadOnly (false );
120
116
121
117
final ChargeDefinition loanOriginationFee = charge (
122
- LOAN_ORIGINATION_FEE_NAME ,
123
- Action . APPROVE ,
124
- BigDecimal .ONE ,
125
- ENTRY ,
126
- ORIGINATION_FEE_INCOME );
118
+ LOAN_ORIGINATION_FEE_NAME ,
119
+ Action . DISBURSE , //TODO: fix existing charges in migration
120
+ BigDecimal .ONE ,
121
+ CUSTOMER_LOAN , //TODO: fix existing charges in migration
122
+ ORIGINATION_FEE_INCOME );
127
123
loanOriginationFee .setReadOnly (false );
128
124
129
- final ChargeDefinition loanFundsAllocation = charge (
125
+ /* final ChargeDefinition loanFundsAllocation = charge(
130
126
LOAN_FUNDS_ALLOCATION_ID,
131
127
Action.APPROVE,
132
128
BigDecimal.valueOf(100),
133
129
LOAN_FUNDS_SOURCE,
134
130
PENDING_DISBURSAL);
135
- loanFundsAllocation .setReadOnly (true );
131
+ loanFundsAllocation.setReadOnly(true);*/
132
+ //TODO: handle removing this extraneous charge in migration.
136
133
137
134
final ChargeDefinition disbursementFee = charge (
138
- DISBURSEMENT_FEE_NAME ,
139
- Action .DISBURSE ,
140
- BigDecimal .valueOf (0.1 ),
141
- ENTRY ,
142
- DISBURSEMENT_FEE_INCOME );
135
+ DISBURSEMENT_FEE_NAME ,
136
+ Action .DISBURSE ,
137
+ BigDecimal .valueOf (0.1 ),
138
+ CUSTOMER_LOAN , //TODO: fix existing charges in migration
139
+ DISBURSEMENT_FEE_INCOME );
140
+ disbursementFee .setProportionalTo (ChargeProportionalDesignator .REQUESTED_DISBURSEMENT_DESIGNATOR .getValue ()); //TODO: fix existing charges in migration
143
141
disbursementFee .setReadOnly (false );
144
142
145
143
final ChargeDefinition disbursePayment = new ChargeDefinition ();
146
144
disbursePayment .setChargeAction (Action .DISBURSE .name ());
147
145
disbursePayment .setIdentifier (DISBURSE_PAYMENT_ID );
148
146
disbursePayment .setName (DISBURSE_PAYMENT_NAME );
149
147
disbursePayment .setDescription (DISBURSE_PAYMENT_NAME );
150
- disbursePayment .setFromAccountDesignator (LOANS_PAYABLE );
148
+ disbursePayment .setFromAccountDesignator (CUSTOMER_LOAN ); //TODO: fix existing charges in migration
151
149
disbursePayment .setToAccountDesignator (ENTRY );
152
- disbursePayment .setProportionalTo (ChargeProportionalDesignator .PRINCIPAL_ADJUSTMENT_DESIGNATOR .getValue ());
150
+ disbursePayment .setProportionalTo (ChargeProportionalDesignator .REQUESTED_DISBURSEMENT_DESIGNATOR .getValue ());
153
151
disbursePayment .setChargeMethod (ChargeDefinition .ChargeMethod .PROPORTIONAL );
154
152
disbursePayment .setAmount (BigDecimal .valueOf (100 ));
155
153
disbursePayment .setReadOnly (true );
156
154
155
+ /*
157
156
final ChargeDefinition trackPrincipalDisbursePayment = new ChargeDefinition();
158
157
trackPrincipalDisbursePayment.setChargeAction(Action.DISBURSE.name());
159
158
trackPrincipalDisbursePayment.setIdentifier(TRACK_DISBURSAL_PAYMENT_ID);
160
159
trackPrincipalDisbursePayment.setName(TRACK_DISBURSAL_PAYMENT_NAME);
161
160
trackPrincipalDisbursePayment.setDescription(TRACK_DISBURSAL_PAYMENT_NAME);
162
161
trackPrincipalDisbursePayment.setFromAccountDesignator(PENDING_DISBURSAL);
163
162
trackPrincipalDisbursePayment.setToAccountDesignator(CUSTOMER_LOAN);
164
- trackPrincipalDisbursePayment .setProportionalTo (ChargeProportionalDesignator .PRINCIPAL_ADJUSTMENT_DESIGNATOR .getValue ());
163
+ trackPrincipalDisbursePayment.setProportionalTo(ChargeProportionalDesignator.REQUESTED_DISBURSEMENT_DESIGNATOR .getValue());
165
164
trackPrincipalDisbursePayment.setChargeMethod(ChargeDefinition.ChargeMethod.PROPORTIONAL);
166
165
trackPrincipalDisbursePayment.setAmount(BigDecimal.valueOf(100));
167
- trackPrincipalDisbursePayment .setReadOnly (true );
166
+ trackPrincipalDisbursePayment.setReadOnly(true);*/
167
+ //TODO: handle removing this extraneous charge in migration.
168
168
169
169
final ChargeDefinition lateFee = charge (
170
170
LATE_FEE_NAME ,
@@ -174,17 +174,17 @@ public static List<ChargeDefinition> defaultIndividualLoanCharges() {
174
174
LATE_FEE_INCOME );
175
175
lateFee .setAccrueAction (Action .MARK_LATE .name ());
176
176
lateFee .setAccrualAccountDesignator (LATE_FEE_ACCRUAL );
177
- lateFee .setProportionalTo (ChargeProportionalDesignator .REPAYMENT_DESIGNATOR .getValue ());
177
+ lateFee .setProportionalTo (ChargeProportionalDesignator .CONTRACTUAL_REPAYMENT_DESIGNATOR .getValue ());
178
178
lateFee .setChargeOnTop (true );
179
179
lateFee .setReadOnly (false );
180
180
181
181
//TODO: Make multiple write off allowance charges.
182
182
final ChargeDefinition writeOffAllowanceCharge = charge (
183
- ALLOW_FOR_WRITE_OFF_NAME ,
184
- Action .MARK_LATE ,
185
- BigDecimal .valueOf (30 ),
186
- PENDING_DISBURSAL ,
187
- ARREARS_ALLOWANCE );
183
+ ALLOW_FOR_WRITE_OFF_NAME ,
184
+ Action .MARK_LATE ,
185
+ BigDecimal .valueOf (30 ),
186
+ LOAN_FUNDS_SOURCE , //TODO: this and previous value ("pending-disbursal") are not correct and will require migration.
187
+ ARREARS_ALLOWANCE );
188
188
writeOffAllowanceCharge .setProportionalTo (ChargeProportionalDesignator .RUNNING_BALANCE_DESIGNATOR .getValue ());
189
189
writeOffAllowanceCharge .setReadOnly (true );
190
190
@@ -206,46 +206,48 @@ public static List<ChargeDefinition> defaultIndividualLoanCharges() {
206
206
customerRepaymentCharge .setIdentifier (REPAYMENT_ID );
207
207
customerRepaymentCharge .setName (REPAYMENT_NAME );
208
208
customerRepaymentCharge .setDescription (REPAYMENT_NAME );
209
- customerRepaymentCharge .setFromAccountDesignator (CUSTOMER_LOAN );
210
- customerRepaymentCharge .setToAccountDesignator (ENTRY );
211
- customerRepaymentCharge .setProportionalTo (ChargeProportionalDesignator .REPAYMENT_DESIGNATOR .getValue ());
209
+ customerRepaymentCharge .setFromAccountDesignator (ENTRY ); //TODO: fix existing charges in migration
210
+ customerRepaymentCharge .setToAccountDesignator (CUSTOMER_LOAN ); //TODO: fix existing charges in migration
211
+ customerRepaymentCharge .setProportionalTo (ChargeProportionalDesignator .REQUESTED_REPAYMENT_DESIGNATOR .getValue ());
212
212
customerRepaymentCharge .setChargeMethod (ChargeDefinition .ChargeMethod .PROPORTIONAL );
213
213
customerRepaymentCharge .setAmount (BigDecimal .valueOf (100 ));
214
214
customerRepaymentCharge .setReadOnly (true );
215
215
216
- final ChargeDefinition trackReturnPrincipalCharge = new ChargeDefinition ();
216
+ /* final ChargeDefinition trackReturnPrincipalCharge = new ChargeDefinition();
217
217
trackReturnPrincipalCharge.setChargeAction(Action.ACCEPT_PAYMENT.name());
218
218
trackReturnPrincipalCharge.setIdentifier(TRACK_RETURN_PRINCIPAL_ID);
219
219
trackReturnPrincipalCharge.setName(TRACK_RETURN_PRINCIPAL_NAME);
220
220
trackReturnPrincipalCharge.setDescription(TRACK_RETURN_PRINCIPAL_NAME);
221
221
trackReturnPrincipalCharge.setFromAccountDesignator(LOAN_FUNDS_SOURCE);
222
222
trackReturnPrincipalCharge.setToAccountDesignator(LOANS_PAYABLE);
223
- trackReturnPrincipalCharge .setProportionalTo (ChargeProportionalDesignator .PRINCIPAL_ADJUSTMENT_DESIGNATOR .getValue ());
223
+ trackReturnPrincipalCharge.setProportionalTo(ChargeProportionalDesignator.REQUESTED_DISBURSEMENT_DESIGNATOR .getValue());
224
224
trackReturnPrincipalCharge.setChargeMethod(ChargeDefinition.ChargeMethod.PROPORTIONAL);
225
225
trackReturnPrincipalCharge.setAmount(BigDecimal.valueOf(100));
226
- trackReturnPrincipalCharge .setReadOnly (true );
226
+ trackReturnPrincipalCharge.setReadOnly(true);*/
227
+ //TODO: handle removing this extraneous charge in migration.
227
228
228
- final ChargeDefinition disbursementReturnCharge = charge (
229
+ /* final ChargeDefinition disbursementReturnCharge = charge(
229
230
RETURN_DISBURSEMENT_NAME,
230
231
Action.CLOSE,
231
232
BigDecimal.valueOf(100),
232
233
PENDING_DISBURSAL,
233
234
LOAN_FUNDS_SOURCE);
234
235
disbursementReturnCharge.setProportionalTo(ChargeProportionalDesignator.RUNNING_BALANCE_DESIGNATOR.getValue());
235
- disbursementReturnCharge .setReadOnly (true );
236
+ disbursementReturnCharge.setReadOnly(true);*/
237
+ //TODO: handle removing this extraneous charge in migration.
236
238
237
239
ret .add (processingFee );
238
240
ret .add (loanOriginationFee );
239
- ret .add (loanFundsAllocation );
241
+ //TODO: ret.add(loanFundsAllocation);
240
242
ret .add (disbursementFee );
241
243
ret .add (disbursePayment );
242
- ret .add (trackPrincipalDisbursePayment );
244
+ //TODO: ret.add(trackPrincipalDisbursePayment);
243
245
ret .add (lateFee );
244
246
ret .add (writeOffAllowanceCharge );
245
247
ret .add (interestCharge );
246
248
ret .add (customerRepaymentCharge );
247
- ret .add (trackReturnPrincipalCharge );
248
- ret .add (disbursementReturnCharge );
249
+ //TODO: ret.add(trackReturnPrincipalCharge);
250
+ //TODO: ret.add(disbursementReturnCharge);
249
251
250
252
return ret ;
251
253
}
@@ -344,7 +346,7 @@ public Set<String> getNextActionsForState(final Case.State state) {
344
346
}
345
347
346
348
@ Override
347
- public List < CostComponent > getCostComponentsForAction (
349
+ public Payment getCostComponentsForAction (
348
350
final String productIdentifier ,
349
351
final String caseIdentifier ,
350
352
final String actionIdentifier ,
@@ -356,35 +358,13 @@ public List<CostComponent> getCostComponentsForAction(
356
358
final Case .State caseState = Case .State .valueOf (dataContextOfAction .getCustomerCaseEntity ().getCurrentState ());
357
359
checkActionCanBeExecuted (caseState , action );
358
360
359
- Stream < Map . Entry < ChargeDefinition , CostComponent >> costComponentStream = costComponentService .getCostComponentsForAction (
361
+ final PaymentBuilder paymentBuilder = costComponentService .getCostComponentsForAction (
360
362
action ,
361
363
dataContextOfAction ,
362
364
forPaymentSize ,
363
- forDateTime .toLocalDate ())
364
- .stream ();
365
-
366
- if (!forAccountDesignators .isEmpty ()) {
367
- costComponentStream = costComponentStream
368
- .filter (costComponentEntry -> chargeReferencesAccountDesignators (costComponentEntry .getKey (), action , forAccountDesignators ));
369
- }
370
-
371
- return costComponentStream
372
- .map (costComponentEntry -> new CostComponent (costComponentEntry .getKey ().getIdentifier (), costComponentEntry .getValue ().getAmount ()))
373
- .collect (Collectors .toList ());
374
- }
365
+ forDateTime .toLocalDate ());
375
366
376
- private boolean chargeReferencesAccountDesignators (
377
- final ChargeDefinition chargeDefinition ,
378
- final Action action ,
379
- final Set <String > forAccountDesignators ) {
380
- final Set <String > accountsToCompare = Sets .newHashSet (
381
- chargeDefinition .getFromAccountDesignator (),
382
- chargeDefinition .getToAccountDesignator ()
383
- );
384
- if (chargeDefinition .getAccrualAccountDesignator () != null )
385
- accountsToCompare .add (chargeDefinition .getAccrualAccountDesignator ());
386
-
387
- return !Sets .intersection (accountsToCompare , forAccountDesignators ).isEmpty ();
367
+ return paymentBuilder .buildPayment (action , forAccountDesignators );
388
368
}
389
369
390
370
public static void checkActionCanBeExecuted (final Case .State state , final Action action ) {
0 commit comments