Subversion Repositories SmartDukaan

Rev

Rev 30796 | Rev 30927 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30796 Rev 30897
Line 10... Line 10...
10
import com.spice.profitmandi.common.util.FormattingUtils;
10
import com.spice.profitmandi.common.util.FormattingUtils;
11
import com.spice.profitmandi.common.util.StringUtils;
11
import com.spice.profitmandi.common.util.StringUtils;
12
import com.spice.profitmandi.common.util.Utils;
12
import com.spice.profitmandi.common.util.Utils;
13
import com.spice.profitmandi.dao.entity.catalog.Item;
13
import com.spice.profitmandi.dao.entity.catalog.Item;
14
import com.spice.profitmandi.dao.entity.catalog.Scheme;
14
import com.spice.profitmandi.dao.entity.catalog.Scheme;
-
 
15
import com.spice.profitmandi.dao.entity.catalog.SchemesImeisModel;
15
import com.spice.profitmandi.dao.entity.fofo.*;
16
import com.spice.profitmandi.dao.entity.fofo.*;
16
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
17
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
17
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
18
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
18
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
19
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
19
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
20
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
Line 494... Line 495...
494
				}
495
				}
495
				if (amountToCredit > amountCredited + 1f) {
496
				if (amountToCredit > amountCredited + 1f) {
496
					for (SchemeInOut sio : sios) {
497
					for (SchemeInOut sio : sios) {
497
						sio.setRolledBackTimestamp(LocalDateTime.now());
498
						sio.setRolledBackTimestamp(LocalDateTime.now());
498
						sio.setStatus(SchemePayoutStatus.REJECTED);
499
						sio.setStatus(SchemePayoutStatus.REJECTED);
499
						sio.setStatusDescription("Partner Category upgraded, new entry added");
500
						sio.setStatusDescription("Partner Category upgraded to " + scheme.getPartnerType() + ", new entry for margin added");
500
					}
501
					}
501
					actualCredit = amountToCredit - amountCredited;
502
					actualCredit = amountToCredit - amountCredited;
502
				} else {
503
				} else {
503
					return 0;
504
					return 0;
504
				}
505
				}
Line 716... Line 717...
716
							"Special support adjusted against overall margin gains for Imei - " + inventoryItem.getSerialNumber(), amountToCredit - schemeInOut.getAmount(),
717
							"Special support adjusted against overall margin gains for Imei - " + inventoryItem.getSerialNumber(), amountToCredit - schemeInOut.getAmount(),
717
							fofoOrder.getCreateTimestamp());
718
							fofoOrder.getCreateTimestamp());
718
 
719
 
719
				}
720
				}
720
				schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
721
				schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
721
				schemeInOut.setStatusDescription("Special support changed due to update in total margin");
722
				schemeInOut.setStatusDescription("Failed!!, New Margin Entry added");
722
				schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
723
				schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
723
			}
724
			}
724
 
725
 
725
		}
726
		}
726
 
727
 
Line 833... Line 834...
833
						sioNew.setInventoryItemId(schemeInOut.getInventoryItemId());
834
						sioNew.setInventoryItemId(schemeInOut.getInventoryItemId());
834
						sioNew.setSchemeId(schemeInOut.getSchemeId());
835
						sioNew.setSchemeId(schemeInOut.getSchemeId());
835
						schemeInOutRepository.persist(sioNew);
836
						schemeInOutRepository.persist(sioNew);
836
 
837
 
837
						schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
838
						schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
838
						schemeInOut.setStatusDescription("Pricedrop processed, new entries added");
839
						schemeInOut.setStatusDescription("Change in margins due to price drop");
839
						// IF not credited then dont consider any credit/debit for that sio entry
840
						// IF not credited then dont consider any credit/debit for that sio entry
840
						if (schemeInOut.getCreditTimestamp() != null) {
841
						if (schemeInOut.getCreditTimestamp() != null) {
841
							amountToCredit += sioNew.getAmount();
842
							amountToCredit += sioNew.getAmount();
842
							amountToDebit += schemeInOut.getAmount();
843
							amountToDebit += schemeInOut.getAmount();
843
						}
844
						}
Line 1058... Line 1059...
1058
				} else {
1059
				} else {
1059
					walletService.addAmountToWallet(fofoId, orderId, WalletReferenceType.SPECIAL_SUPPORT,
1060
					walletService.addAmountToWallet(fofoId, orderId, WalletReferenceType.SPECIAL_SUPPORT,
1060
							"Special Support for " + ii.getItem().getItemDescriptionNoColor() + ", Imei - " + serialNumber, pendingPayout.getAmount(),
1061
							"Special Support for " + ii.getItem().getItemDescriptionNoColor() + ", Imei - " + serialNumber, pendingPayout.getAmount(),
1061
							fofoOrder.getCreateTimestamp());
1062
							fofoOrder.getCreateTimestamp());
1062
					pendingPayout.setStatusDescription("Special support credited");
1063
					pendingPayout.setStatusDescription("Special support credited");
1063
 
-
 
1064
				}
1064
				}
1065
				pendingPayout.setCreditTimestamp(LocalDateTime.now());
1065
				pendingPayout.setCreditTimestamp(LocalDateTime.now());
1066
				pendingPayout.setStatus(SchemePayoutStatus.CREDITED);
1066
				pendingPayout.setStatus(SchemePayoutStatus.CREDITED);
1067
			} else {
1067
			} else {
1068
				pendingPayout.setStatus(SchemePayoutStatus.REJECTED);
1068
				pendingPayout.setStatus(SchemePayoutStatus.REJECTED);
Line 1072... Line 1072...
1072
						"Rejected, activated on " + FormattingUtils.formatDate(activatedImei.getActivationTimestamp()));
1072
						"Rejected, activated on " + FormattingUtils.formatDate(activatedImei.getActivationTimestamp()));
1073
			}
1073
			}
1074
		}
1074
		}
1075
	}
1075
	}
1076
 
1076
 
-
 
1077
	@Override
-
 
1078
	public void processActivatedImeisForSchemes() throws ProfitMandiBusinessException {
-
 
1079
		List<SchemesImeisModel> schemesImeisModels = schemeRepository.selectSelectUnpaidSchemes();
-
 
1080
		LOGGER.info("Total Size - " + schemesImeisModels.size());
-
 
1081
		List<Integer> orderIds = schemesImeisModels.stream().map(x -> x.getOrderId()).collect(Collectors.toList());
-
 
1082
		List<FofoOrder> fofoOrders = fofoOrderRepository.selectAllByOrderIds(orderIds);
-
 
1083
		Map<Integer, FofoOrder> validOrdersMap = fofoOrders.stream().filter(x -> x.getCancelledTimestamp() == null).collect(Collectors.toMap(x -> x.getId(), x -> x));
-
 
1084
		Map<String, List<SchemesImeisModel>> validImeiSchemesModelMap = schemesImeisModels.stream().filter(x -> validOrdersMap.containsKey(x.getOrderId())).collect(Collectors.groupingBy(x -> x.getImei()));
-
 
1085
		for (Map.Entry<String, List<SchemesImeisModel>> imeiListEntry : validImeiSchemesModelMap.entrySet()) {
-
 
1086
			SchemesImeisModel schemesImeisModel = imeiListEntry.getValue().get(0);
-
 
1087
			List<Integer> schemeIds = imeiListEntry.getValue().stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
-
 
1088
			LOGGER.info("Serial Number  - {}, Scheme IDs - {}", schemesImeisModel.getImei(), schemeIds);
-
 
1089
			InventoryItem inventoryItem = inventoryItemRepository.selectById(schemesImeisModel.getInventoryItemId());
-
 
1090
			List<Scheme> schemes = schemeRepository.selectBySchemeIds(schemeIds);
-
 
1091
			List<Scheme> activationSchemes = schemes.stream().filter(x -> x.getType().equals(SchemeType.ACTIVATION)).collect(Collectors.toList());
-
 
1092
			List<Scheme> supportSchemes = schemes.stream().filter(x -> x.getType().equals(SchemeType.SPECIAL_SUPPORT)).collect(Collectors.toList());
-
 
1093
			for (Scheme scheme : activationSchemes) {
-
 
1094
				this.createSchemeInOut(scheme, inventoryItem);
-
 
1095
			}
-
 
1096
			if (supportSchemes.size() > 0) {
-
 
1097
				FofoOrder fofoOrder = validOrdersMap.get(schemesImeisModel.getOrderId());
-
 
1098
				PartnerType partnerType = partnerTypeChangeService.getTypeOnMonth(fofoOrder.getFofoId(),
-
 
1099
						YearMonth.from(fofoOrder.getCreateTimestamp()));
-
 
1100
				this.processSpecialSupport(fofoOrder, supportSchemes, inventoryItem, partnerType, fofoOrder.getCreateTimestamp());
-
 
1101
			}
-
 
1102
 
-
 
1103
		}
-
 
1104
 
-
 
1105
 
-
 
1106
	}
-
 
1107
 
1077
}
1108
}