| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service.scheme;
|
1 |
package com.spice.profitmandi.service.scheme;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.time.LocalDateTime;
|
| - |
|
4 |
import java.util.ArrayList;
|
| 3 |
import java.util.HashMap;
|
5 |
import java.util.HashMap;
|
| - |
|
6 |
import java.util.HashSet;
|
| 4 |
import java.util.List;
|
7 |
import java.util.List;
|
| 5 |
import java.util.Map;
|
8 |
import java.util.Map;
|
| 6 |
import java.util.Set;
|
9 |
import java.util.Set;
|
| 7 |
import java.util.function.Predicate;
|
- |
|
| 8 |
|
10 |
|
| - |
|
11 |
import org.slf4j.Logger;
|
| - |
|
12 |
import org.slf4j.LoggerFactory;
|
| 9 |
import org.springframework.beans.factory.annotation.Autowired;
|
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 10 |
import org.springframework.stereotype.Component;
|
14 |
import org.springframework.stereotype.Component;
|
| 11 |
|
15 |
|
| - |
|
16 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
| 12 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
18 |
import com.spice.profitmandi.common.model.CreateSchemeRequest;
|
| 13 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
19 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
20 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 14 |
import com.spice.profitmandi.dao.entity.catalog.RetailerScheme;
|
21 |
import com.spice.profitmandi.dao.entity.catalog.RetailerScheme;
|
| 15 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
22 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 16 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
23 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| - |
|
24 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 17 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
25 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 18 |
import com.spice.profitmandi.dao.entity.fofo.SchemeIn;
|
- |
|
| 19 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInId;
|
- |
|
| 20 |
import com.spice.profitmandi.dao.entity.fofo.SchemeOut;
|
26 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 21 |
import com.spice.profitmandi.dao.entity.fofo.SchemeOutId;
|
27 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| 22 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeAmountType;
|
28 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeAmountType;
|
| 23 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
29 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| - |
|
30 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24 |
import com.spice.profitmandi.dao.repository.catalog.RetailerSchemeRepository;
|
31 |
import com.spice.profitmandi.dao.repository.catalog.RetailerSchemeRepository;
|
| 25 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
32 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 26 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
33 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 27 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
34 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 28 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInRepository;
|
35 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 29 |
import com.spice.profitmandi.dao.repository.fofo.SchemeOutRepository;
|
36 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| - |
|
37 |
import com.spice.profitmandi.service.sale.FofoOrderItemService;
|
| - |
|
38 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| - |
|
39 |
|
| - |
|
40 |
import in.shop2020.model.v1.catalog.ItemType;
|
| - |
|
41 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 30 |
|
42 |
|
| 31 |
@Component
|
43 |
@Component
|
| 32 |
public class SchemeServiceImpl implements SchemeService {
|
44 |
public class SchemeServiceImpl implements SchemeService {
|
| 33 |
|
45 |
|
| - |
|
46 |
private static final Logger LOGGER = LoggerFactory.getLogger(SchemeServiceImpl.class);
|
| - |
|
47 |
|
| 34 |
@Autowired
|
48 |
@Autowired
|
| 35 |
private InventoryItemRepository inventoryItemRepository;
|
49 |
private InventoryItemRepository inventoryItemRepository;
|
| 36 |
|
50 |
|
| 37 |
@Autowired
|
51 |
@Autowired
|
| 38 |
private FofoLineItemRepository fofoLineItemRepository;
|
52 |
private FofoOrderItemService fofoOrderItemService;
|
| 39 |
|
53 |
|
| 40 |
@Autowired
|
54 |
@Autowired
|
| 41 |
private SchemeRepository schemeRepository;
|
55 |
private SchemeRepository schemeRepository;
|
| 42 |
|
56 |
|
| 43 |
@Autowired
|
57 |
@Autowired
|
| - |
|
58 |
private RetailerRepository retailerRepository;
|
| - |
|
59 |
|
| - |
|
60 |
@Autowired
|
| 44 |
private RetailerSchemeRepository retailerSchemeRepository;
|
61 |
private RetailerSchemeRepository retailerSchemeRepository;
|
| 45 |
|
62 |
|
| 46 |
@Autowired
|
63 |
@Autowired
|
| 47 |
private SchemeInRepository schemeInRepository;
|
64 |
private SchemeInOutRepository schemeInOutRepository;
|
| 48 |
|
65 |
|
| 49 |
@Autowired
|
66 |
@Autowired
|
| - |
|
67 |
private ItemRepository itemRepository;
|
| - |
|
68 |
|
| - |
|
69 |
@Autowired
|
| 50 |
private SchemeOutRepository schemeOutRepository;
|
70 |
private SchemeItemRepository schemeItemRepository;
|
| - |
|
71 |
|
| - |
|
72 |
@Autowired
|
| - |
|
73 |
private WalletService walletService;
|
| 51 |
|
74 |
|
| 52 |
@Override
|
75 |
@Override
|
| 53 |
public void saveScheme(Scheme scheme, Set<Integer> retailerIds) throws ProfitMandiBusinessException {
|
76 |
public void saveScheme(int creatorId, CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException {
|
| 54 |
if(scheme.getExpireTimestamp() != null){
|
- |
|
| 55 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(), "");
|
- |
|
| 56 |
}
|
- |
|
| 57 |
if(!scheme.isAll() && retailerIds.isEmpty()){
|
- |
|
| 58 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, retailerIds, "");
|
- |
|
| 59 |
}
|
77 |
|
| 60 |
if(scheme.getName().isEmpty()){
|
78 |
if(createSchemeRequest.getName().isEmpty()){
|
| 61 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.NAME, scheme.getName(), "");
|
79 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.NAME, createSchemeRequest.getName(), "");
|
| 62 |
}
|
80 |
}
|
| 63 |
if(scheme.getAmount() <= 0){
|
81 |
if(createSchemeRequest.getAmount() <= 0){
|
| 64 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, scheme.getAmount(), "");
|
82 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(), "");
|
| 65 |
}
|
83 |
}
|
| 66 |
|
84 |
|
| 67 |
if(scheme.getAmountType() == SchemeAmountType.PERCENTAGE && scheme.getAmount() > 100){
|
85 |
if(SchemeAmountType.valueOf(createSchemeRequest.getAmountType()) == SchemeAmountType.PERCENTAGE && createSchemeRequest.getAmount() > 100){
|
| 68 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, scheme.getAmount(), "");
|
86 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.AMOUNT, createSchemeRequest.getAmount(), "");
|
| 69 |
}
|
87 |
}
|
| 70 |
|
88 |
|
| 71 |
if(scheme.getStartDate() == null){
|
89 |
if(createSchemeRequest.getStartDateString() == null || createSchemeRequest.getStartDateString().isEmpty()){
|
| 72 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.START_DATE, scheme.getStartDate(), "");
|
90 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.START_DATE, createSchemeRequest.getStartDateString(), "");
|
| 73 |
}
|
91 |
}
|
| 74 |
|
92 |
|
| 75 |
if(scheme.getEndDate() == null){
|
93 |
if(createSchemeRequest.getEndDateString() == null || createSchemeRequest.getStartDateString().isEmpty()){
|
| 76 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.END_DATE, scheme.getEndDate(), "");
|
94 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.END_DATE, createSchemeRequest.getEndDateString(), "");
|
| 77 |
}
|
95 |
}
|
| 78 |
|
96 |
|
| - |
|
97 |
Scheme scheme = this.toScheme(creatorId, createSchemeRequest);
|
| - |
|
98 |
|
| 79 |
if(scheme.getStartDate().isAfter(scheme.getEndDate())){
|
99 |
if(scheme.getStartDate().isAfter(scheme.getEndDate())){
|
| 80 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.START_DATE + ", " + ProfitMandiConstants.END_DATE, scheme.getStartDate() + ", " + scheme.getEndDate(), "");
|
100 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.START_DATE + ", " + ProfitMandiConstants.END_DATE, scheme.getStartDate() + ", " + scheme.getEndDate(), "");
|
| 81 |
}
|
101 |
}
|
| 82 |
|
102 |
|
| 83 |
if(scheme.getEndDate().isAfter(scheme.getEndDate())){
|
103 |
this.validateItemIds(createSchemeRequest);
|
| 84 |
|
- |
|
| 85 |
}
|
- |
|
| 86 |
schemeRepository.persist(scheme);
|
104 |
schemeRepository.persist(scheme);
|
| - |
|
105 |
if(!createSchemeRequest.isRetailerAll()){
|
| - |
|
106 |
this.validateRetailerIds(createSchemeRequest);
|
| - |
|
107 |
for(int retailerId : createSchemeRequest.getRetailerIds()){
|
| - |
|
108 |
RetailerScheme retailerScheme = new RetailerScheme();
|
| - |
|
109 |
retailerScheme.setRetailerId(retailerId);
|
| - |
|
110 |
retailerScheme.setSchemeId(scheme.getId());
|
| - |
|
111 |
retailerSchemeRepository.persist(retailerScheme);
|
| - |
|
112 |
}
|
| - |
|
113 |
}
|
| - |
|
114 |
for(int itemId : createSchemeRequest.getItemIds()){
|
| - |
|
115 |
SchemeItem schemeItem = new SchemeItem();
|
| - |
|
116 |
schemeItem.setSchemeId(scheme.getId());
|
| - |
|
117 |
schemeItem.setItemId(itemId);
|
| - |
|
118 |
schemeItemRepository.persist(schemeItem);
|
| - |
|
119 |
}
|
| - |
|
120 |
|
| - |
|
121 |
}
|
| - |
|
122 |
|
| - |
|
123 |
private Scheme toScheme(int creatorId, CreateSchemeRequest createSchemeRequest){
|
| - |
|
124 |
Scheme scheme = new Scheme();
|
| - |
|
125 |
scheme.setName(createSchemeRequest.getName());
|
| - |
|
126 |
scheme.setDescription(createSchemeRequest.getDescription());
|
| - |
|
127 |
scheme.setType(SchemeType.valueOf(createSchemeRequest.getType()));
|
| - |
|
128 |
scheme.setAmountType(SchemeAmountType.valueOf(createSchemeRequest.getAmountType()));
|
| - |
|
129 |
scheme.setAmount(createSchemeRequest.getAmount());
|
| - |
|
130 |
scheme.setStartDate(StringUtils.toDateTime(createSchemeRequest.getStartDateString(), DateTimePattern.YYYY_MM_DD_T_HH_MM));
|
| - |
|
131 |
scheme.setEndDate(StringUtils.toDateTime(createSchemeRequest.getEndDateString(), DateTimePattern.YYYY_MM_DD_T_HH_MM));
|
| - |
|
132 |
if(createSchemeRequest.isActive()){
|
| - |
|
133 |
scheme.setActiveTimestamp(LocalDateTime.now());
|
| - |
|
134 |
}
|
| - |
|
135 |
scheme.setCreatedBy(creatorId);
|
| - |
|
136 |
scheme.setRetailerAll(createSchemeRequest.isRetailerAll());
|
| - |
|
137 |
return scheme;
|
| - |
|
138 |
}
|
| - |
|
139 |
|
| - |
|
140 |
private void validateRetailerIds(CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException{
|
| - |
|
141 |
if(createSchemeRequest.getRetailerIds().isEmpty()){
|
| - |
|
142 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, createSchemeRequest.getRetailerIds(), "");
|
| - |
|
143 |
}
|
| - |
|
144 |
List<Integer> foundRetailerIds = retailerRepository.selectIdsByIds(new ArrayList<>(createSchemeRequest.getRetailerIds()));
|
| - |
|
145 |
if(foundRetailerIds.size() != createSchemeRequest.getRetailerIds().size()){
|
| - |
|
146 |
createSchemeRequest.getRetailerIds().removeAll(foundRetailerIds);
|
| - |
|
147 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RETAILER_ID, createSchemeRequest.getRetailerIds(), "");
|
| - |
|
148 |
}
|
| - |
|
149 |
}
|
| - |
|
150 |
|
| - |
|
151 |
private void validateItemIds(CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException{
|
| - |
|
152 |
if(createSchemeRequest.getItemIds() == null || createSchemeRequest.getItemIds().isEmpty()){
|
| - |
|
153 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID, createSchemeRequest.getItemIds(), "");
|
| - |
|
154 |
}
|
| - |
|
155 |
List<Integer> foundItemIds = itemRepository.selectIdsByIdsAndType(createSchemeRequest.getItemIds(), ItemType.SERIALIZED);
|
| - |
|
156 |
if(foundItemIds.size() != createSchemeRequest.getItemIds().size()){
|
| - |
|
157 |
createSchemeRequest.getItemIds().removeAll(foundItemIds);
|
| - |
|
158 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ITEM_ID, createSchemeRequest.getItemIds(), "");
|
| - |
|
159 |
}
|
| - |
|
160 |
}
|
| 87 |
|
161 |
|
| - |
|
162 |
@Override
|
| - |
|
163 |
public Scheme getSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
| - |
|
164 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
| - |
|
165 |
if(!scheme.isRetailerAll()){
|
| - |
|
166 |
List<RetailerScheme> retailerSchemes = retailerSchemeRepository.selectBySchemeId(scheme.getId());
|
| - |
|
167 |
for(RetailerScheme retailerScheme : retailerSchemes){
|
| - |
|
168 |
scheme.getRetailerIds().add(retailerScheme.getRetailerId());
|
| - |
|
169 |
}
|
| - |
|
170 |
}
|
| - |
|
171 |
List<Integer> itemIds = schemeItemRepository.selectItemIdsBySchemeId(scheme.getId());
|
| - |
|
172 |
scheme.setItemIds(new HashSet<>(itemIds));
|
| - |
|
173 |
return scheme;
|
| 88 |
}
|
174 |
}
|
| 89 |
|
175 |
|
| 90 |
@Override
|
176 |
@Override
|
| 91 |
public void activeSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
177 |
public void activeSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
| 92 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
178 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
| Line 94... |
Line 180... |
| 94 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ACTIVE_TIMESTAMP, scheme.getActiveTimestamp(), "");
|
180 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ACTIVE_TIMESTAMP, scheme.getActiveTimestamp(), "");
|
| 95 |
}
|
181 |
}
|
| 96 |
if(scheme.getExpireTimestamp() != null){
|
182 |
if(scheme.getExpireTimestamp() != null){
|
| 97 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(), "");
|
183 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(), "");
|
| 98 |
}
|
184 |
}
|
| - |
|
185 |
scheme.setActiveTimestamp(LocalDateTime.now());
|
| 99 |
schemeRepository.updateActiveTimestampById(schemeId);
|
186 |
schemeRepository.persist(scheme);
|
| 100 |
}
|
187 |
}
|
| 101 |
|
188 |
|
| 102 |
@Override
|
189 |
@Override
|
| 103 |
public void expireSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
190 |
public void expireSchemeById(int schemeId) throws ProfitMandiBusinessException {
|
| 104 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
191 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
| Line 106... |
Line 193... |
| 106 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ACTIVE_TIMESTAMP, scheme.getActiveTimestamp(), "");
|
193 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.ACTIVE_TIMESTAMP, scheme.getActiveTimestamp(), "");
|
| 107 |
}
|
194 |
}
|
| 108 |
if(scheme.getExpireTimestamp() != null){
|
195 |
if(scheme.getExpireTimestamp() != null){
|
| 109 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(), "");
|
196 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(), "");
|
| 110 |
}
|
197 |
}
|
| - |
|
198 |
scheme.setExpireTimestamp(LocalDateTime.now());
|
| 111 |
schemeRepository.updateExpireTimestampById(schemeId);
|
199 |
schemeRepository.persist(scheme);
|
| - |
|
200 |
}
|
| - |
|
201 |
|
| - |
|
202 |
private Map<Integer, Scheme> toSchemeIdSchemesMap(List<Scheme> schemes){
|
| - |
|
203 |
Map<Integer, Scheme> schemeIdSchemesMap = new HashMap<>();
|
| - |
|
204 |
for(Scheme scheme : schemes){
|
| - |
|
205 |
schemeIdSchemesMap.put(scheme.getId(), scheme);
|
| - |
|
206 |
}
|
| - |
|
207 |
return schemeIdSchemesMap;
|
| - |
|
208 |
}
|
| - |
|
209 |
|
| - |
|
210 |
private Set<Integer> inventoryItemSchemesMapToSchemeIds(Map<InventoryItem, Set<Scheme>> inventoryItemSchemesMap){
|
| - |
|
211 |
Set<Integer> schemeIds = new HashSet<>();
|
| - |
|
212 |
for(Map.Entry<InventoryItem, Set<Scheme>> inventoryItemSchemesEntry : inventoryItemSchemesMap.entrySet()){
|
| - |
|
213 |
for(Scheme scheme : inventoryItemSchemesEntry.getValue()){
|
| - |
|
214 |
schemeIds.add(scheme.getId());
|
| - |
|
215 |
}
|
| - |
|
216 |
}
|
| - |
|
217 |
return schemeIds;
|
| - |
|
218 |
}
|
| - |
|
219 |
|
| - |
|
220 |
private Set<Integer> fofoLineItemSchemesMapToSchemeIds(Map<FofoOrderItem, Set<Scheme>> fofoLineItemSchemesMap){
|
| - |
|
221 |
Set<Integer> schemeIds = new HashSet<>();
|
| - |
|
222 |
for(Map.Entry<FofoOrderItem, Set<Scheme>> inventoryItemSchemesEntry : fofoLineItemSchemesMap.entrySet()){
|
| - |
|
223 |
for(Scheme scheme : inventoryItemSchemesEntry.getValue()){
|
| - |
|
224 |
schemeIds.add(scheme.getId());
|
| - |
|
225 |
}
|
| - |
|
226 |
}
|
| - |
|
227 |
return schemeIds;
|
| - |
|
228 |
}
|
| - |
|
229 |
|
| - |
|
230 |
private Set<Integer> inventoryItemsToItemIds(List<InventoryItem> inventoryItems){
|
| - |
|
231 |
Set<Integer> itemIds = new HashSet<>();
|
| - |
|
232 |
for(InventoryItem inventoryItem : inventoryItems){
|
| - |
|
233 |
itemIds.add(inventoryItem.getItemId());
|
| - |
|
234 |
}
|
| - |
|
235 |
return itemIds;
|
| - |
|
236 |
}
|
| - |
|
237 |
|
| - |
|
238 |
private Set<Integer> fofoOrderItemsToItemIds(List<FofoOrderItem> fofoOrderItems){
|
| - |
|
239 |
Set<Integer> itemIds = new HashSet<>();
|
| - |
|
240 |
for(FofoOrderItem fofoOrderItem : fofoOrderItems){
|
| - |
|
241 |
itemIds.add(fofoOrderItem.getItemId());
|
| - |
|
242 |
}
|
| - |
|
243 |
return itemIds;
|
| - |
|
244 |
}
|
| 112 |
|
245 |
|
| - |
|
246 |
private Map<Integer, Set<Scheme>> toItemIdSchemesMap(List<SchemeItem> schemeItems, List<Scheme> schemes){
|
| - |
|
247 |
Map<Integer, Scheme> schemeIdSchemesMap = this.toSchemeIdSchemesMap(schemes);
|
| - |
|
248 |
Map<Integer, Set<Scheme>> itemIdSchemesMap = new HashMap<>();
|
| - |
|
249 |
for(SchemeItem schemeItem : schemeItems){
|
| - |
|
250 |
if(!itemIdSchemesMap.containsKey(schemeItem.getItemId())){
|
| - |
|
251 |
Set<Scheme> schemesSet = new HashSet<>();
|
| - |
|
252 |
schemesSet.add(schemeIdSchemesMap.get(schemeItem.getSchemeId()));
|
| - |
|
253 |
itemIdSchemesMap.put(schemeItem.getItemId(), schemesSet);
|
| - |
|
254 |
}else{
|
| - |
|
255 |
itemIdSchemesMap.get(schemeItem.getItemId()).add(schemeIdSchemesMap.get(schemeItem.getSchemeId()));
|
| - |
|
256 |
}
|
| - |
|
257 |
}
|
| - |
|
258 |
return itemIdSchemesMap;
|
| 113 |
}
|
259 |
}
|
| 114 |
|
260 |
|
| 115 |
@Override
|
- |
|
| 116 |
public void processSchemeIn(int inventoryItemId) throws ProfitMandiBusinessException {
|
261 |
private Map<InventoryItem, Set<Scheme>> toInventoryItemSchemesMap(List<Scheme> schemes, List<InventoryItem> inventoryItems){
|
| 117 |
InventoryItem inventoryItem = inventoryItemRepository.selectById(inventoryItemId);
|
262 |
Set<Integer> schemeIds = new HashSet<>();
|
| 118 |
List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.IN);
|
263 |
for(Scheme scheme : schemes){
|
| - |
|
264 |
schemeIds.add(scheme.getId());
|
| - |
|
265 |
}
|
| 119 |
Map<Integer, Scheme> notAllSchemeIdSchemeMap = new HashMap<>();
|
266 |
Set<Integer> itemIds = this.inventoryItemsToItemIds(inventoryItems);
|
| 120 |
Map<Integer, Scheme> allSchemeIdSchemeMap = new HashMap<>();
|
267 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIdsAndItemIds(schemeIds, itemIds);
|
| 121 |
|
268 |
|
| - |
|
269 |
Map<Integer, Set<Scheme>> itemIdSchemesMap = this.toItemIdSchemesMap(schemeItems, schemes);
|
| - |
|
270 |
Map<InventoryItem, Set<Scheme>> inventoryItemSchemsMap = new HashMap<>();
|
| - |
|
271 |
for(InventoryItem inventoryItem : inventoryItems){
|
| - |
|
272 |
if(itemIdSchemesMap.containsKey(inventoryItem.getItemId())){
|
| - |
|
273 |
inventoryItemSchemsMap.put(inventoryItem, itemIdSchemesMap.get(inventoryItem.getItemId()));
|
| - |
|
274 |
}
|
| - |
|
275 |
}
|
| - |
|
276 |
return inventoryItemSchemsMap;
|
| - |
|
277 |
}
|
| - |
|
278 |
|
| - |
|
279 |
private Map<FofoOrderItem, Set<Scheme>> toFofoOrderItemSchemesMap(List<Scheme> schemes, List<FofoOrderItem> fofoOrderItems){
|
| - |
|
280 |
Set<Integer> schemeIds = new HashSet<>();
|
| 122 |
for(Scheme scheme : schemes){
|
281 |
for(Scheme scheme : schemes){
|
| 123 |
if(!scheme.isAll()){
|
282 |
schemeIds.add(scheme.getId());
|
| - |
|
283 |
}
|
| - |
|
284 |
Set<Integer> itemIds = this.fofoOrderItemsToItemIds(fofoOrderItems);
|
| - |
|
285 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIdsAndItemIds(schemeIds, itemIds);
|
| - |
|
286 |
|
| 124 |
notAllSchemeIdSchemeMap.put(scheme.getId(), scheme);
|
287 |
Map<FofoOrderItem, Set<Scheme>> fofoOrderItemSchemsMap = new HashMap<>();
|
| 125 |
}else{
|
288 |
|
| - |
|
289 |
if(!schemeItems.isEmpty()){
|
| - |
|
290 |
Map<Integer, Set<Scheme>> itemIdSchemesMap = this.toItemIdSchemesMap(schemeItems, schemes);
|
| - |
|
291 |
for(FofoOrderItem fofoOrderItem : fofoOrderItems){
|
| 126 |
allSchemeIdSchemeMap.put(scheme.getId(), scheme);
|
292 |
if(itemIdSchemesMap.containsKey(fofoOrderItem.getItemId())){
|
| - |
|
293 |
fofoOrderItemSchemsMap.put(fofoOrderItem, itemIdSchemesMap.get(fofoOrderItem.getItemId()));
|
| - |
|
294 |
}
|
| 127 |
}
|
295 |
}
|
| 128 |
}
|
296 |
}
|
| - |
|
297 |
return fofoOrderItemSchemsMap;
|
| - |
|
298 |
}
|
| - |
|
299 |
|
| - |
|
300 |
@Override
|
| 129 |
for(Map.Entry<Integer, Scheme> entry : allSchemeIdSchemeMap.entrySet()){
|
301 |
public float processSchemeIn(int purchaseId, int retailerId) throws ProfitMandiBusinessException {
|
| 130 |
this.createSchemeIn(entry.getValue(), inventoryItem.getUnitPrice(), inventoryItemId, entry.getKey());
|
302 |
List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.IN, LocalDateTime.now());
|
| - |
|
303 |
float totalCashback = 0;
|
| - |
|
304 |
if(schemes.isEmpty()){
|
| - |
|
305 |
return 0;
|
| 131 |
}
|
306 |
}
|
| - |
|
307 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchaseId);
|
| - |
|
308 |
LOGGER.info("SchemeIn filter inventoryItems {}", inventoryItems);
|
| 132 |
|
309 |
|
| - |
|
310 |
Map<InventoryItem, Set<Scheme>> inventoryItemSchemesMap = this.toInventoryItemSchemesMap(schemes, inventoryItems);
|
| - |
|
311 |
|
| 133 |
if(!notAllSchemeIdSchemeMap.isEmpty()){
|
312 |
if(inventoryItemSchemesMap.isEmpty()){
|
| - |
|
313 |
return 0;
|
| - |
|
314 |
}
|
| 134 |
List<RetailerScheme> retailerSchemes = retailerSchemeRepository.selectBySchemeIds(notAllSchemeIdSchemeMap.keySet());
|
315 |
Map<InventoryItem, Set<Scheme>> notAllInventoryItemSchemesMap = new HashMap<>();
|
| - |
|
316 |
Map<InventoryItem, Set<Scheme>> allInventoryItemSchemesMap = new HashMap<>();
|
| - |
|
317 |
|
| 135 |
for(Map.Entry<Integer, Scheme> entry : notAllSchemeIdSchemeMap.entrySet()){
|
318 |
for(Map.Entry<InventoryItem, Set<Scheme>> inventoryItemSchemesEntry : inventoryItemSchemesMap.entrySet()){
|
| 136 |
Predicate<RetailerScheme> retailerIdSchemeIdPredicate = new Predicate<RetailerScheme>()
|
319 |
Set<Scheme> notAllSchemes = new HashSet<>();
|
| - |
|
320 |
Set<Scheme> allSchemes = new HashSet<>();
|
| - |
|
321 |
for(Scheme scheme : inventoryItemSchemesEntry.getValue()){
|
| - |
|
322 |
if(!scheme.isRetailerAll()){
|
| - |
|
323 |
notAllSchemes.add(scheme);
|
| - |
|
324 |
}else{
|
| - |
|
325 |
allSchemes.add(scheme);
|
| 137 |
{
|
326 |
}
|
| 138 |
@Override
|
327 |
}
|
| - |
|
328 |
notAllInventoryItemSchemesMap.put(inventoryItemSchemesEntry.getKey(), notAllSchemes);
|
| 139 |
public boolean test(RetailerScheme retailerScheme) {
|
329 |
allInventoryItemSchemesMap.put(inventoryItemSchemesEntry.getKey(), allSchemes);
|
| - |
|
330 |
}
|
| - |
|
331 |
|
| 140 |
if(retailerScheme.getRetailerId() == inventoryItem.getFofoId() && retailerScheme.getSchemeId() == entry.getKey()){
|
332 |
for(Map.Entry<InventoryItem, Set<Scheme>> allInventoryItemSchemesEntry : allInventoryItemSchemesMap.entrySet()){
|
| - |
|
333 |
for(Scheme scheme : allInventoryItemSchemesEntry.getValue()){
|
| - |
|
334 |
float cashback = this.createSchemeInOut(scheme, allInventoryItemSchemesEntry.getKey());
|
| 141 |
return true;
|
335 |
totalCashback = totalCashback + cashback;
|
| 142 |
}
|
336 |
}
|
| - |
|
337 |
}
|
| - |
|
338 |
|
| - |
|
339 |
Set<Integer> schemeIds = this.inventoryItemSchemesMapToSchemeIds(notAllInventoryItemSchemesMap);
|
| 143 |
return false;
|
340 |
if(!schemeIds.isEmpty()){
|
| - |
|
341 |
List<Integer> foundSchemeIds = retailerSchemeRepository.selectSchemeIds(schemeIds, retailerId);
|
| - |
|
342 |
|
| - |
|
343 |
for(Map.Entry<InventoryItem, Set<Scheme>> notAllInventoryItemSchemesEntry : notAllInventoryItemSchemesMap.entrySet()){
|
| - |
|
344 |
for(Scheme scheme : notAllInventoryItemSchemesEntry.getValue()){
|
| - |
|
345 |
if(foundSchemeIds.contains(scheme.getId())){
|
| - |
|
346 |
float cashback = this.createSchemeInOut(scheme, notAllInventoryItemSchemesEntry.getKey());
|
| - |
|
347 |
totalCashback = totalCashback + cashback;
|
| 144 |
}
|
348 |
}
|
| 145 |
};
|
- |
|
| 146 |
if(!retailerSchemes.isEmpty() && retailerSchemes.stream().anyMatch(retailerIdSchemeIdPredicate)){
|
- |
|
| 147 |
this.createSchemeIn(entry.getValue(), inventoryItem.getUnitPrice(), inventoryItemId, entry.getKey());
|
- |
|
| 148 |
}
|
349 |
}
|
| 149 |
}
|
350 |
}
|
| 150 |
}
|
351 |
}
|
| - |
|
352 |
if(totalCashback > 0){
|
| - |
|
353 |
walletService.addAmountToWallet(retailerId, purchaseId, WalletReferenceType.SCHEME_IN, "Added for SCHEME_IN", totalCashback);
|
| - |
|
354 |
}
|
| - |
|
355 |
return totalCashback;
|
| 151 |
}
|
356 |
}
|
| 152 |
|
357 |
|
| 153 |
private void createSchemeIn(Scheme scheme, float unitPrice, int inventoryItemId, int schemeId){
|
358 |
private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem){
|
| - |
|
359 |
float amount = this.getAmount(inventoryItem, scheme);
|
| - |
|
360 |
SchemeInOut schemeInOut = new SchemeInOut();
|
| - |
|
361 |
schemeInOut.setSchemeId(scheme.getId());
|
| - |
|
362 |
schemeInOut.setInventoryItemId(inventoryItem.getId());
|
| - |
|
363 |
schemeInOut.setAmount(amount);
|
| - |
|
364 |
schemeInOutRepository.persist(schemeInOut);
|
| - |
|
365 |
return amount;
|
| - |
|
366 |
}
|
| - |
|
367 |
|
| - |
|
368 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme){
|
| 154 |
float amount = 0;
|
369 |
float amount = 0;
|
| - |
|
370 |
float totalTaxRate = inventoryItem.getIgstRate() + inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
|
| - |
|
371 |
float taxableSellingPrice = inventoryItem.getUnitPrice() / (1 + totalTaxRate / 100);
|
| - |
|
372 |
|
| 155 |
if(scheme.getAmountType() == SchemeAmountType.PERCENTAGE){
|
373 |
if(scheme.getAmountType() == SchemeAmountType.PERCENTAGE){
|
| 156 |
amount = unitPrice * scheme.getAmount() / 100;
|
374 |
amount = taxableSellingPrice * scheme.getAmount() / 100;
|
| 157 |
}else{
|
375 |
}else{
|
| 158 |
amount = scheme.getAmount();
|
376 |
amount = scheme.getAmount();
|
| 159 |
}
|
377 |
}
|
| 160 |
SchemeIn schemeIn = new SchemeIn();
|
- |
|
| 161 |
SchemeInId schemeInId = new SchemeInId();
|
- |
|
| 162 |
schemeInId.setInventoryItemId(inventoryItemId);
|
- |
|
| 163 |
schemeInId.setSchemeId(schemeId);
|
- |
|
| 164 |
schemeIn.setId(schemeInId);
|
- |
|
| 165 |
schemeIn.setAmount(amount);
|
378 |
return amount;
|
| 166 |
schemeInRepository.persist(schemeIn);
|
- |
|
| 167 |
}
|
379 |
}
|
| 168 |
|
380 |
|
| 169 |
private void createSchemeOut(Scheme scheme, float unitPrice, int fofoLineItemId, int schemeId){
|
381 |
private Map<Integer, InventoryItem> toInventoryItemIdInventoryItemMap(List<InventoryItem> inventoryItems){
|
| - |
|
382 |
Map<Integer, InventoryItem> itemIdInventoryItemMap = new HashMap<>();
|
| - |
|
383 |
for(InventoryItem inventoryItem : inventoryItems){
|
| - |
|
384 |
itemIdInventoryItemMap.put(inventoryItem.getId(), inventoryItem);
|
| - |
|
385 |
}
|
| - |
|
386 |
return itemIdInventoryItemMap;
|
| - |
|
387 |
}
|
| - |
|
388 |
|
| - |
|
389 |
/*private Set<Integer> toFofoOrderItemIds(Set<FofoOrderItem> fofoOrderItems){
|
| - |
|
390 |
Set<Integer> fofoOrderItemIds = new HashSet<>();
|
| - |
|
391 |
for(FofoOrderItem fofoOrderItem : fofoOrderItems){
|
| - |
|
392 |
fofoOrderItemIds.add(fofoOrderItem.getId());
|
| - |
|
393 |
}
|
| 170 |
float amount = 0;
|
394 |
return fofoOrderItemIds;
|
| - |
|
395 |
}*/
|
| - |
|
396 |
|
| - |
|
397 |
/*private Map<Integer, Set<FofoLineItem>> toFofoOrderItemIdFofoLineItems(Set<FofoOrderItem> fofoOrderItems){
|
| - |
|
398 |
Set<Integer> fofoOrderItemIds = this.toFofoOrderItemIds(fofoOrderItems);
|
| - |
|
399 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByFofoOrderItemIds(fofoOrderItemIds);
|
| - |
|
400 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = new HashMap<>();
|
| - |
|
401 |
for(FofoLineItem fofoLineItem : fofoLineItems){
|
| - |
|
402 |
if(!fofoOrderItemIdFofoLineItemsMap.containsKey(fofoLineItem.getFofoOrderItemId())){
|
| 171 |
if(scheme.getAmountType() == SchemeAmountType.PERCENTAGE){
|
403 |
Set<FofoLineItem> fofoLineItems2 = new HashSet<>();
|
| 172 |
amount = unitPrice * scheme.getAmount() / 100;
|
404 |
fofoLineItems.add(fofoLineItem);
|
| - |
|
405 |
fofoOrderItemIdFofoLineItemsMap.put(fofoLineItem.getFofoOrderItemId(), fofoLineItems2);
|
| 173 |
}else{
|
406 |
}else{
|
| - |
|
407 |
fofoOrderItemIdFofoLineItemsMap.get(fofoLineItem.getFofoOrderItemId()).add(fofoLineItem);
|
| - |
|
408 |
}
|
| - |
|
409 |
}
|
| 174 |
amount = scheme.getAmount();
|
410 |
return fofoOrderItemIdFofoLineItemsMap;
|
| - |
|
411 |
}*/
|
| - |
|
412 |
|
| - |
|
413 |
private Set<Integer> toInventoryItemIds(Set<FofoOrderItem> fofoOrderItems){
|
| - |
|
414 |
Set<Integer> inventoryItemIds = new HashSet<>();
|
| - |
|
415 |
//Map<Integer, Set<FofoLineItem>> fofoOrderItemIdFofoLineItemsMap = this.toFofoOrderItemIdFofoLineItems(fofoOrderItems);
|
| - |
|
416 |
for(FofoOrderItem fofoOrderItem : fofoOrderItems){
|
| - |
|
417 |
for(FofoLineItem fofoLineItem : fofoOrderItem.getFofoLineItems()){
|
| - |
|
418 |
inventoryItemIds.add(fofoLineItem.getInventoryItemId());
|
| - |
|
419 |
}
|
| 175 |
}
|
420 |
}
|
| 176 |
SchemeOut schemeOut = new SchemeOut();
|
- |
|
| 177 |
SchemeOutId schemeOutId = new SchemeOutId();
|
- |
|
| 178 |
schemeOutId.setFofoLineItemId(fofoLineItemId);
|
- |
|
| 179 |
schemeOutId.setSchemeId(schemeId);
|
- |
|
| 180 |
schemeOut.setId(schemeOutId);
|
421 |
return inventoryItemIds;
|
| 181 |
schemeOut.setAmount(amount);
|
- |
|
| 182 |
schemeOutRepository.persist(schemeOut);
|
- |
|
| 183 |
}
|
422 |
}
|
| 184 |
|
423 |
|
| 185 |
@Override
|
424 |
@Override
|
| 186 |
public void processSchemeOut(int fofoLineItemId) throws ProfitMandiBusinessException {
|
425 |
public float processSchemeOut(int fofoOrderId, int retailerId) throws ProfitMandiBusinessException {
|
| 187 |
FofoLineItem fofoLineItem = fofoLineItemRepository.selectById(fofoLineItemId);
|
- |
|
| 188 |
List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.OUT);
|
426 |
List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.OUT, LocalDateTime.now());
|
| 189 |
Map<Integer, Scheme> notAllSchemeSchemeMap = new HashMap<>();
|
427 |
LOGGER.info("Active Schemes {}", schemes);
|
| 190 |
Map<Integer, Scheme> allSchemeSchemeMap = new HashMap<>();
|
428 |
float totalCashback = 0;
|
| - |
|
429 |
if(schemes.isEmpty()){
|
| - |
|
430 |
return 0;
|
| - |
|
431 |
}
|
| 191 |
|
432 |
|
| - |
|
433 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemService.getByOrderId(fofoOrderId);
|
| - |
|
434 |
//LOGGER.info("fofoOrderItems {}", fofoOrderItems);
|
| - |
|
435 |
|
| - |
|
436 |
Map<FofoOrderItem, Set<Scheme>> fofoOrderItemSchemesMap = this.toFofoOrderItemSchemesMap(schemes, fofoOrderItems);
|
| - |
|
437 |
|
| - |
|
438 |
LOGGER.info("fofoOrderItemSchemesMap {}", fofoOrderItemSchemesMap);
|
| - |
|
439 |
|
| - |
|
440 |
if(fofoOrderItemSchemesMap.isEmpty()){
|
| - |
|
441 |
return 0;
|
| - |
|
442 |
}
|
| - |
|
443 |
|
| - |
|
444 |
Set<Integer> inventoryItemIds = this.toInventoryItemIds(fofoOrderItemSchemesMap.keySet());
|
| - |
|
445 |
|
| - |
|
446 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIds);
|
| - |
|
447 |
|
| - |
|
448 |
Map<Integer, InventoryItem> inventoryItemIdInventoryItemMap = this.toInventoryItemIdInventoryItemMap(inventoryItems);
|
| - |
|
449 |
|
| - |
|
450 |
Map<FofoOrderItem, Set<Scheme>> notAllFofoOrderItemSchemesMap = new HashMap<>();
|
| - |
|
451 |
Map<FofoOrderItem, Set<Scheme>> allFofoOrderItemSchemesMap = new HashMap<>();
|
| - |
|
452 |
|
| - |
|
453 |
for(Map.Entry<FofoOrderItem, Set<Scheme>> fofoOrderItemSchemesEntry : fofoOrderItemSchemesMap.entrySet()){
|
| - |
|
454 |
Set<Scheme> notAllSchemes = new HashSet<>();
|
| 192 |
for(Scheme scheme : schemes){
|
455 |
Set<Scheme> allSchemes = new HashSet<>();
|
| - |
|
456 |
for(Scheme scheme : fofoOrderItemSchemesEntry.getValue()){
|
| 193 |
if(!scheme.isAll()){
|
457 |
if(!scheme.isRetailerAll()){
|
| 194 |
notAllSchemeSchemeMap.put(scheme.getId(), scheme);
|
458 |
notAllSchemes.add(scheme);
|
| 195 |
}else{
|
459 |
}else{
|
| 196 |
allSchemeSchemeMap.put(scheme.getId(), scheme);
|
460 |
allSchemes.add(scheme);
|
| - |
|
461 |
}
|
| 197 |
}
|
462 |
}
|
| - |
|
463 |
notAllFofoOrderItemSchemesMap.put(fofoOrderItemSchemesEntry.getKey(), notAllSchemes);
|
| - |
|
464 |
allFofoOrderItemSchemesMap.put(fofoOrderItemSchemesEntry.getKey(), allSchemes);
|
| 198 |
}
|
465 |
}
|
| - |
|
466 |
|
| - |
|
467 |
//Map<Integer, Set<FofoLineItem>> allFofoOrderItemIdFofoLineItemsMap = this.toFofoOrderItemIdFofoLineItems(allFofoOrderItemSchemesMap.keySet());
|
| - |
|
468 |
|
| 199 |
for(Map.Entry<Integer, Scheme> entry : allSchemeSchemeMap.entrySet()){
|
469 |
for(Map.Entry<FofoOrderItem, Set<Scheme>> allFofoOrderItemSchemesEntry : allFofoOrderItemSchemesMap.entrySet()){
|
| - |
|
470 |
for(FofoLineItem fofoLineItem : allFofoOrderItemSchemesEntry.getKey().getFofoLineItems()){
|
| - |
|
471 |
for(Scheme scheme : allFofoOrderItemSchemesEntry.getValue()){
|
| 200 |
this.createSchemeOut(entry.getValue(), fofoLineItem.getSellingPrice(), fofoLineItemId, entry.getKey());
|
472 |
float cashback = this.createSchemeInOut(scheme, inventoryItemIdInventoryItemMap.get(fofoLineItem.getInventoryItemId()));
|
| - |
|
473 |
totalCashback = totalCashback + cashback;
|
| - |
|
474 |
}
|
| - |
|
475 |
}
|
| 201 |
}
|
476 |
}
|
| 202 |
|
477 |
|
| - |
|
478 |
Set<Integer> schemeIds = this.fofoLineItemSchemesMapToSchemeIds(notAllFofoOrderItemSchemesMap);
|
| - |
|
479 |
|
| 203 |
if(!notAllSchemeSchemeMap.isEmpty()){
|
480 |
if(!schemeIds.isEmpty()){
|
| 204 |
List<RetailerScheme> retailerSchemes = retailerSchemeRepository.selectBySchemeIds(notAllSchemeSchemeMap.keySet());
|
481 |
List<Integer> foundSchemeIds = retailerSchemeRepository.selectSchemeIds(schemeIds, retailerId);
|
| 205 |
for(Map.Entry<Integer, Scheme> entry : notAllSchemeSchemeMap.entrySet()){
|
- |
|
| - |
|
482 |
|
| 206 |
Predicate<RetailerScheme> retailerIdSchemeIdPredicate = new Predicate<RetailerScheme>()
|
483 |
//Map<Integer, Set<FofoLineItem>> notAllFofoOrderItemIdFofoLineItemsMap = this.toFofoOrderItemIdFofoLineItems(allFofoOrderItemSchemesMap.keySet());
|
| 207 |
{
|
484 |
|
| - |
|
485 |
for(Map.Entry<FofoOrderItem, Set<Scheme>> notAllFofoOrderItemSchemesEntry : notAllFofoOrderItemSchemesMap.entrySet()){
|
| - |
|
486 |
for(FofoLineItem fofoLineItem : notAllFofoOrderItemSchemesEntry.getKey().getFofoLineItems()){
|
| 208 |
@Override
|
487 |
for(Scheme scheme : notAllFofoOrderItemSchemesEntry.getValue()){
|
| 209 |
public boolean test(RetailerScheme retailerScheme) {
|
488 |
if(foundSchemeIds.contains(scheme.getId())){
|
| 210 |
if(retailerScheme.getRetailerId() == fofoLineItem.getOrder().getFofoId() && retailerScheme.getSchemeId() == entry.getKey()){
|
489 |
float cashback = this.createSchemeInOut(scheme, inventoryItemIdInventoryItemMap.get(fofoLineItem.getInventoryItemId()));
|
| 211 |
return true;
|
490 |
totalCashback = totalCashback + cashback;
|
| 212 |
}
|
491 |
}
|
| 213 |
return false;
|
- |
|
| 214 |
}
|
492 |
}
|
| 215 |
};
|
- |
|
| 216 |
if(!retailerSchemes.isEmpty() && retailerSchemes.stream().anyMatch(retailerIdSchemeIdPredicate)){
|
- |
|
| 217 |
this.createSchemeIn(entry.getValue(), fofoLineItem.getSellingPrice(), fofoLineItemId, entry.getKey());
|
- |
|
| 218 |
}
|
493 |
}
|
| 219 |
}
|
494 |
}
|
| 220 |
|
495 |
}
|
| - |
|
496 |
if(totalCashback > 0){
|
| - |
|
497 |
walletService.addAmountToWallet(retailerId, fofoOrderId, WalletReferenceType.SCHEME_OUT, "Added for SCHEME_OUT", totalCashback);
|
| 221 |
}
|
498 |
}
|
| - |
|
499 |
return totalCashback;
|
| 222 |
}
|
500 |
}
|
| 223 |
|
501 |
|
| 224 |
}
|
502 |
}
|