Created
February 5, 2025 00:26
-
-
Save arhyth/ac0eaa536754dfd9576a526ad4da7b32 to your computer and use it in GitHub Desktop.
credit line computation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public Result<DealerQualificationResult> computeCreditLineBySubmittedDocs(Dealer dealer) { | |
Result<DealerQualificationResult> result = new Result<>(); | |
DealerQualificationResult dqr = new DealerQualificationResult(); | |
LevelRequirementResult req = null; | |
Boolean qualified = null; | |
Double minCreditLine = 0D; | |
Double computedCreditLine = 0D; | |
Double totalBasicDocCl = 0D; | |
Double totalSourceOutDocCl = 0D; | |
Double registeredCellNoCl = 0D; | |
Double orientedByCl = 0D; | |
String orientedBy = dealer.getProfile().getOrientedBy(); | |
DealerLevel desiredLevel = refRepository.findDealerLevelByCode(dealer.getProfile().getLevel()); | |
if (desiredLevel != null) { | |
minCreditLine = desiredLevel.getMinCreditLine(); | |
// Basic Documents | |
Map<String, DealerBasicDocs> basicDocsMap = new HashMap<>(); | |
for (DealerBasicDocs bd : dealer.getBasicDocsList()) { | |
req = refRepository.findRequirementByParams(bd.getCategory(), bd.getDocType(), desiredLevel.getCode()); | |
if (req != null) { | |
bd.setEquivalentCl(req.getEquivalentCl()); | |
if (basicDocsMap.containsKey(bd.getCategory())) { | |
if (basicDocsMap.get(bd.getCategory()).getEquivalentCl() < bd.getEquivalentCl()) { | |
basicDocsMap.replace(bd.getCategory(), bd); | |
} | |
} else { | |
basicDocsMap.put(bd.getCategory(), bd); | |
} | |
} | |
} | |
// Source Out Documents | |
Map<String, DealerSourceOutDocs> sourceOutDocsMap = new HashMap<>(); | |
for (DealerSourceOutDocs sd : dealer.getSourceOutDocsList()) { | |
req = refRepository.findRequirementByParams(sd.getCategory(), sd.getDocType(), | |
dealer.getProfile().getLevel()); | |
if (req != null) { | |
sd.setEquivalentCl(req.getEquivalentCl()); | |
if (sourceOutDocsMap.containsKey(sd.getCategory())) { | |
if (sourceOutDocsMap.get(sd.getCategory()).getEquivalentCl() < sd.getEquivalentCl()) { | |
sourceOutDocsMap.replace(sd.getCategory(), sd); | |
} | |
} else { | |
sourceOutDocsMap.put(sd.getCategory(), sd); | |
} | |
} | |
} | |
for (Entry<String, DealerBasicDocs> entry : basicDocsMap.entrySet()) { | |
totalBasicDocCl += entry.getValue().getEquivalentCl(); | |
} | |
for (Entry<String, DealerSourceOutDocs> entry : sourceOutDocsMap.entrySet()) { | |
totalSourceOutDocCl += entry.getValue().getEquivalentCl(); | |
} | |
if (StringUtils.equalsIgnoreCase(dealer.getProfile().getLevel(), DealerLevelEnum.FB.name())) { | |
registeredCellNoCl = 300D; | |
} else if (StringUtils.equalsIgnoreCase(dealer.getProfile().getLevel(), DealerLevelEnum.FM.name())) { | |
registeredCellNoCl = 750D; | |
} else if (StringUtils.equalsIgnoreCase(dealer.getProfile().getLevel(), DealerLevelEnum.FD.name())) { | |
registeredCellNoCl = 825D; | |
} else if (StringUtils.equalsIgnoreCase(dealer.getProfile().getLevel(), DealerLevelEnum.MD.name())) { | |
registeredCellNoCl = 1500D; | |
} | |
if (!StringUtils.equalsIgnoreCase(dealer.getProfile().getLevel(), DealerLevelEnum.FB.name())) { | |
computedCreditLine = totalSourceOutDocCl; | |
} | |
computedCreditLine = totalBasicDocCl + registeredCellNoCl + orientedByCl; | |
qualified = computedCreditLine < minCreditLine ? false : true; | |
} | |
LOGGER.info("MAX CREDIT LIMIT : " + desiredLevel.getMaxCreditLine()); | |
LOGGER.info("COMPUTED CREDIT LINE : " + computedCreditLine); | |
// added for max CL during registration - July 17, 2020 : debangj | |
computedCreditLine = computedCreditLine > desiredLevel.getMaxCreditLine() ? desiredLevel.getMaxCreditLine() | |
: computedCreditLine; | |
// end | |
LOGGER.info("QUALIFIED : " + qualified); | |
LOGGER.info("MIN CREDIT LINE : " + minCreditLine); | |
dqr.setComputedCreditLine(computedCreditLine); | |
dqr.setMinCreditLine(minCreditLine); | |
dqr.setQualified(qualified); | |
result.setResultObject(dqr); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment