Created
September 17, 2011 18:38
-
-
Save vinodkd/1224214 to your computer and use it in GitHub Desktop.
Proc to reward points
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
| /** | |
| * If applicable, deducts the rewards amount from the current price, | |
| * rewards points on the booking and returns the charge amount for the user's card. | |
| */ | |
| public CCAmt doRewards(String pos, CCAmt currentCCAmt, | |
| rewardsInfo rewardsInfo, | |
| String PNR, | |
| XFactor xFactor, | |
| boolean isSpecialInventory, | |
| Money sellRateForSpecialInventory | |
| ) { | |
| Money redeemableRewardsPointsInPurCurrency = rewardsInfo.getRewardsAmount(); | |
| boolean hasrewardsPointsToRedeem = redeemableRewardsPointsInPurCurrency != null; | |
| if (log.isDebugEnabled()) { | |
| log.debug("rewardsPointsRedeemable :" + redeemableRewardsPointsInPurCurrency); | |
| } | |
| //use rewards points only if xFactor is a particular enum value | |
| boolean useRewardsPoints = XFactor.FA == xFactor; | |
| if (hasrewardsPointsToRedeem) { | |
| // We may need to create the CCAmt object again since its children are not updated with the Credit Card CCAmt. | |
| if (!useRewardsPoints) { | |
| // In previous stage, currentCCAmt.getPurchaseCCAmt() | |
| // returns the Total current price and not (Total current price minus Redeemed points). | |
| Money purCCAmt = currentCCAmt.getPurchaseCCAmt(). | |
| minus(redeemableRewardsPointsInPurCurrency); | |
| if (isGreaterThanZero(purCCAmt)) { | |
| CCAmt ccAmtWithrewards; | |
| Money posCCAmt = cpx.changeCurrency(purCCAmt); | |
| ccAmtWithrewards = new CCAmt(posCCAmt, purCCAmt, currentCCAmt.getPNR(), | |
| // other params here); | |
| if (log.isDebugEnabled()) { | |
| log.debug("purCCAmt :" + purCCAmt + " posCCAmt :" + posCCAmt); | |
| } | |
| currentCCAmt = ccAmtWithrewards; | |
| } else { | |
| if (log.isDebugEnabled()) { | |
| log.debug("Redeemed points and current price are equal. Setting CCAmt to null"); | |
| } | |
| redeemableRewardsPointsInPurCurrency = currentCCAmt.getPurchaseCCAmt(); | |
| currentCCAmt = null; | |
| } | |
| } | |
| if (useRewardsPoints && hasrewardsPointsToRedeem) { | |
| if (log.isDebugEnabled()) { | |
| log.debug("Using up rewards points"); | |
| } | |
| debitRewardsPoints(...,redeemableRewardsPointsInPurCurrency.getCurrency()),..., PNR, ...); | |
| } | |
| } | |
| // Purchase CCAmt Amount will be 0 if Available points >= current price. | |
| // The CCAmt amount must be made null so that we don't make another debit call | |
| if (useRewardsPoints && hasrewardsPointsToRedeem && currentCCAmt != null && | |
| isZero(currentCCAmt.getPurchaseCCAmt())) { | |
| currentCCAmt = null; | |
| } | |
| if (isSpecialInventory || useRewardsPoints && currentCCAmt != null && | |
| currentCCAmt.getPurchaseCCAmt() != null) { | |
| Money ccAmountWithRewards; | |
| if (isSpecialInventory && isGreaterThanZero(sellRateForSpecialInventory)) { | |
| ccAmountWithRewards = redeemableRewardsPointsInPurCurrency != null ? | |
| sellRateForSpecialInventory.minus(redeemableRewardsPointsInPurCurrency.getCurrency()) : sellRateForSpecialInventory; | |
| } else { | |
| ccAmountWithRewards = currentCCAmt.getPurchaseCCAmt(); | |
| } | |
| if (log.isDebugEnabled()) { | |
| log.debug("Rewarding points for this sale"); | |
| } | |
| if (isGreaterThanZero(ccAmountWithRewards)) { | |
| rewardPoints(..., ccAmountWithRewards,.., PNR, ...); | |
| } | |
| } | |
| return currentCCAmt; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment