| 22860 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 23020 |
ashik.ali |
3 |
import java.io.ByteArrayInputStream;
|
|
|
4 |
import java.io.ByteArrayOutputStream;
|
|
|
5 |
import java.io.InputStream;
|
| 26674 |
tejbeer |
6 |
import java.time.LocalDate;
|
| 23020 |
ashik.ali |
7 |
import java.time.LocalDateTime;
|
| 28916 |
amit.gupta |
8 |
import java.time.LocalTime;
|
| 29585 |
manish |
9 |
import java.time.Month;
|
| 27897 |
amit.gupta |
10 |
import java.util.ArrayList;
|
| 23556 |
amit.gupta |
11 |
import java.util.Arrays;
|
| 23914 |
govind |
12 |
import java.util.HashMap;
|
| 23556 |
amit.gupta |
13 |
import java.util.HashSet;
|
| 22860 |
ashik.ali |
14 |
import java.util.List;
|
| 23020 |
ashik.ali |
15 |
import java.util.Map;
|
| 25368 |
amit.gupta |
16 |
import java.util.Set;
|
| 28491 |
amit.gupta |
17 |
import java.util.stream.Collectors;
|
| 22860 |
ashik.ali |
18 |
|
|
|
19 |
import javax.servlet.http.HttpServletRequest;
|
| 25368 |
amit.gupta |
20 |
import javax.transaction.Transactional;
|
| 22860 |
ashik.ali |
21 |
|
| 23784 |
ashik.ali |
22 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
23 |
import org.apache.logging.log4j.Logger;
|
| 22860 |
ashik.ali |
24 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23784 |
ashik.ali |
25 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 23020 |
ashik.ali |
26 |
import org.springframework.core.io.InputStreamResource;
|
|
|
27 |
import org.springframework.http.HttpHeaders;
|
|
|
28 |
import org.springframework.http.HttpStatus;
|
|
|
29 |
import org.springframework.http.ResponseEntity;
|
| 22860 |
ashik.ali |
30 |
import org.springframework.stereotype.Controller;
|
|
|
31 |
import org.springframework.ui.Model;
|
|
|
32 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
33 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
34 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
35 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
36 |
|
| 23020 |
ashik.ali |
37 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
| 29585 |
manish |
38 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 22860 |
ashik.ali |
39 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 29585 |
manish |
40 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 23914 |
govind |
41 |
import com.spice.profitmandi.common.model.MapWrapper;
|
| 22860 |
ashik.ali |
42 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23557 |
amit.gupta |
43 |
import com.spice.profitmandi.common.model.SchemeItems;
|
| 23020 |
ashik.ali |
44 |
import com.spice.profitmandi.common.model.SchemeModel;
|
| 29585 |
manish |
45 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 23020 |
ashik.ali |
46 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 29585 |
manish |
47 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 27394 |
amit.gupta |
48 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 23020 |
ashik.ali |
49 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 28924 |
amit.gupta |
50 |
import com.spice.profitmandi.common.util.Utils;
|
| 23784 |
ashik.ali |
51 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 29585 |
manish |
52 |
import com.spice.profitmandi.dao.entity.catalog.EvaluateSchemeInvestmentPayoutModel;
|
| 28492 |
amit.gupta |
53 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 22860 |
ashik.ali |
54 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 27389 |
amit.gupta |
55 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 28136 |
tejbeer |
56 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 28795 |
tejbeer |
57 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 29585 |
manish |
58 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 25505 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 28795 |
tejbeer |
60 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 23556 |
amit.gupta |
61 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| 28795 |
tejbeer |
62 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
|
|
63 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
| 27389 |
amit.gupta |
64 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 28491 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 29585 |
manish |
66 |
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
|
| 27876 |
amit.gupta |
67 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 25505 |
amit.gupta |
68 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
| 26674 |
tejbeer |
69 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 22860 |
ashik.ali |
70 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 27389 |
amit.gupta |
71 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
| 23556 |
amit.gupta |
72 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 26588 |
tejbeer |
73 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
74 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 28795 |
tejbeer |
75 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 29585 |
manish |
76 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 26674 |
tejbeer |
77 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 28795 |
tejbeer |
78 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 23556 |
amit.gupta |
79 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| 28795 |
tejbeer |
80 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
|
|
81 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 23798 |
amit.gupta |
82 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23020 |
ashik.ali |
83 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 27876 |
amit.gupta |
84 |
import com.spice.profitmandi.service.offers.OfferService;
|
| 22860 |
ashik.ali |
85 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 26588 |
tejbeer |
86 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 29585 |
manish |
87 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 22860 |
ashik.ali |
88 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
89 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 23570 |
amit.gupta |
90 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 22860 |
ashik.ali |
91 |
|
| 29585 |
manish |
92 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
|
|
93 |
|
| 22860 |
ashik.ali |
94 |
@Controller
|
| 25369 |
amit.gupta |
95 |
@Transactional(rollbackOn = Throwable.class)
|
| 22860 |
ashik.ali |
96 |
public class SchemeController {
|
|
|
97 |
|
| 23568 |
govind |
98 |
private static final Logger LOGGER = LogManager.getLogger(SchemeController.class);
|
| 22860 |
ashik.ali |
99 |
|
|
|
100 |
@Autowired
|
| 22927 |
ashik.ali |
101 |
private SchemeService schemeService;
|
| 27897 |
amit.gupta |
102 |
|
| 27876 |
amit.gupta |
103 |
@Autowired
|
|
|
104 |
private OfferService offerService;
|
| 23786 |
amit.gupta |
105 |
|
| 22860 |
ashik.ali |
106 |
@Autowired
|
| 27389 |
amit.gupta |
107 |
private StateGstRateRepository stateGstRateRepository;
|
| 27612 |
tejbeer |
108 |
|
| 27389 |
amit.gupta |
109 |
@Autowired
|
| 27416 |
amit.gupta |
110 |
private ItemRepository itemRepository;
|
| 29585 |
manish |
111 |
|
|
|
112 |
|
|
|
113 |
@Autowired
|
|
|
114 |
private ReporticoService reporticoService;
|
| 27612 |
tejbeer |
115 |
|
| 27416 |
amit.gupta |
116 |
@Autowired
|
| 22927 |
ashik.ali |
117 |
private SchemeRepository schemeRepository;
|
| 22860 |
ashik.ali |
118 |
|
|
|
119 |
@Autowired
|
| 23556 |
amit.gupta |
120 |
private SchemeItemRepository schemeItemRepository;
|
| 23786 |
amit.gupta |
121 |
|
| 23556 |
amit.gupta |
122 |
@Autowired
|
| 23570 |
amit.gupta |
123 |
private MVCResponseSender mvcResponseSender;
|
| 23786 |
amit.gupta |
124 |
|
| 23570 |
amit.gupta |
125 |
@Autowired
|
| 22927 |
ashik.ali |
126 |
private CookiesProcessor cookiesProcessor;
|
| 23786 |
amit.gupta |
127 |
|
| 23020 |
ashik.ali |
128 |
@Autowired
|
| 23784 |
ashik.ali |
129 |
@Qualifier("fofoInventoryService")
|
| 23020 |
ashik.ali |
130 |
private InventoryService inventoryService;
|
| 23556 |
amit.gupta |
131 |
|
|
|
132 |
@Autowired
|
|
|
133 |
private TagListingRepository tagListingRepository;
|
| 23914 |
govind |
134 |
|
| 23798 |
amit.gupta |
135 |
@Autowired
|
|
|
136 |
private RoleManager roleManager;
|
| 23786 |
amit.gupta |
137 |
|
| 23506 |
amit.gupta |
138 |
@Autowired
|
| 27394 |
amit.gupta |
139 |
private ResponseSender<?> responseSender;
|
| 23786 |
amit.gupta |
140 |
|
| 23784 |
ashik.ali |
141 |
@Autowired
|
| 27394 |
amit.gupta |
142 |
private FofoStoreRepository fofoStoreRepository;
|
| 23786 |
amit.gupta |
143 |
|
| 23784 |
ashik.ali |
144 |
@Autowired
|
| 27394 |
amit.gupta |
145 |
private RetailerService retailerService;
|
| 22860 |
ashik.ali |
146 |
|
| 27394 |
amit.gupta |
147 |
@Autowired
|
|
|
148 |
private Mongo mongoClient;
|
| 29585 |
manish |
149 |
|
|
|
150 |
@Autowired
|
|
|
151 |
WalletService walletService;
|
| 26588 |
tejbeer |
152 |
|
|
|
153 |
@Autowired
|
| 29585 |
manish |
154 |
PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
|
|
155 |
|
|
|
156 |
|
|
|
157 |
@Autowired
|
| 26674 |
tejbeer |
158 |
private PartnerTypeChangeService partnerTypeChangeService;
|
|
|
159 |
|
| 28795 |
tejbeer |
160 |
@Autowired
|
|
|
161 |
InventoryItemRepository inventoryItemRepository;
|
|
|
162 |
|
|
|
163 |
@Autowired
|
|
|
164 |
PriceDropIMEIRepository priceDropIMEIRepository;
|
|
|
165 |
|
|
|
166 |
@Autowired
|
|
|
167 |
PriceDropRepository priceDropRepository;
|
|
|
168 |
|
|
|
169 |
@Autowired
|
|
|
170 |
SchemeInOutRepository schemeInOutRepository;
|
|
|
171 |
|
| 22860 |
ashik.ali |
172 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
173 |
public String createScheme(HttpServletRequest request, Model model) {
|
| 29585 |
manish |
174 |
|
|
|
175 |
LocalDate currentdate = LocalDate.now();
|
|
|
176 |
Month month = currentdate.getMonth().minus(1);
|
|
|
177 |
model.addAttribute("month", month);
|
|
|
178 |
|
| 23786 |
amit.gupta |
179 |
// Map<Integer, String> itemIdItemDescriptionMap =
|
|
|
180 |
// inventoryService.getAllItemIdItemDescriptionMap();
|
|
|
181 |
// model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| 25368 |
amit.gupta |
182 |
Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
|
|
|
183 |
brands.addAll(inventoryService.getAllTagListingBrands(14206));
|
|
|
184 |
model.addAttribute("brands", brands);
|
| 25505 |
amit.gupta |
185 |
model.addAttribute("retailerTypes", PartnerType.values());
|
| 22860 |
ashik.ali |
186 |
return "create-scheme";
|
|
|
187 |
}
|
| 29585 |
manish |
188 |
|
|
|
189 |
|
| 23786 |
amit.gupta |
190 |
|
| 23914 |
govind |
191 |
@RequestMapping(value = "/getTagListingItemsByBrand", method = RequestMethod.POST)
|
|
|
192 |
public String getTagListingItemsByBrand(HttpServletRequest request, @RequestBody List<String> brands, Model model) {
|
|
|
193 |
Map<Integer, String> itemIdItemDescriptionMap = new HashMap<>();
|
|
|
194 |
LOGGER.info("brands" + brands);
|
|
|
195 |
|
|
|
196 |
List<MapWrapper<Integer, String>> itemIdItemDescriptionMaplist = inventoryService
|
|
|
197 |
.getAllTagListingItemIdItemDescriptionMap(new HashSet<>(brands));
|
|
|
198 |
for (MapWrapper<Integer, String> mapWrapper : itemIdItemDescriptionMaplist) {
|
|
|
199 |
itemIdItemDescriptionMap.put(mapWrapper.getKey(), mapWrapper.getValue());
|
|
|
200 |
}
|
| 23020 |
ashik.ali |
201 |
model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| 23786 |
amit.gupta |
202 |
// model.addAttribute("brands", inventoryService.getAllBrands());
|
| 23914 |
govind |
203 |
|
| 23419 |
ashik.ali |
204 |
return "tag-listing-items-description";
|
| 23020 |
ashik.ali |
205 |
}
|
| 23556 |
amit.gupta |
206 |
|
|
|
207 |
@RequestMapping(value = "/schemes/update-schemes-page", method = RequestMethod.GET)
|
|
|
208 |
public String updateShcemes(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
209 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23799 |
amit.gupta |
210 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23556 |
amit.gupta |
211 |
throw new ProfitMandiBusinessException("User", loginDetails.getEmailId(), "Unauthorised access");
|
|
|
212 |
}
|
|
|
213 |
return "update-schemes-page";
|
|
|
214 |
}
|
| 29585 |
manish |
215 |
|
|
|
216 |
|
|
|
217 |
@RequestMapping(value = "/payMonthlyInvestment", method = RequestMethod.POST)
|
|
|
218 |
public void payMonthlyInvestment(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
219 |
|
|
|
220 |
LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
|
|
|
221 |
LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
|
|
|
222 |
int referenceId = Integer.parseInt(FormattingUtils.getYearMonth(startOfPreviousMonth.atStartOfDay()));
|
|
|
223 |
LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
|
|
|
224 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
|
|
|
225 |
.selectAll(startOfPreviousMonth, lastOfPreviousMonth);
|
|
|
226 |
Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream()
|
|
|
227 |
.filter(x -> x.getShortPercentage() <= 10)
|
|
|
228 |
.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
|
|
|
229 |
LOGGER.info("investmentMaintainedDaysMap {}", investmentMaintainedDaysMap);
|
|
|
230 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAllPending(SchemeType.INVESTMENT,
|
|
|
231 |
startOfPreviousMonth.atStartOfDay(), firstDateOfCurrentMonth.atStartOfDay());
|
|
|
232 |
|
|
|
233 |
if(schemeInOuts.isEmpty())
|
|
|
234 |
{
|
|
|
235 |
throw new ProfitMandiBusinessException("Investment Payout", "",
|
|
|
236 |
"No data Found");
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
Map<Integer, List<SchemeInOut>> inventoryItemIdSchemeMap = schemeInOuts.stream()
|
|
|
240 |
.collect(Collectors.groupingBy(x -> x.getInventoryItemId()));
|
|
|
241 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
|
|
|
242 |
Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream().collect(
|
|
|
243 |
Collectors.groupingBy(x -> x.getFofoId(), Collectors.mapping(x -> x.getId(), Collectors.toList())));
|
|
|
244 |
System.out.println("Fofo Id\tInvestment Maintained Days\tEligible payout");
|
|
|
245 |
for (Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
|
|
|
246 |
int fofoId = retailerEntry.getKey();
|
|
|
247 |
long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
|
|
|
248 |
: investmentMaintainedDaysMap.get(fofoId);
|
| 25256 |
amit.gupta |
249 |
|
| 29585 |
manish |
250 |
List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
|
|
|
251 |
.flatMap(List::stream).filter(x -> x.getRolledBackTimestamp() == null).collect(Collectors.toList());
|
|
|
252 |
float totalAmount = 0;
|
|
|
253 |
for(SchemeInOut sio : schemeInouts) {
|
|
|
254 |
|
|
|
255 |
if (investmentMaintainedDays < 8) {
|
|
|
256 |
sio.setStatus(SchemePayoutStatus.REJECTED);
|
|
|
257 |
//sio.setRolledBackTimestamp(LocalDateTime.now());
|
|
|
258 |
sio.setStatusDescription("Investment maintained for " + investmentMaintainedDays + "(< 8) days");
|
|
|
259 |
} else if (investmentMaintainedDays < 12) {
|
|
|
260 |
sio.setStatus(SchemePayoutStatus.CREDITED);
|
|
|
261 |
sio.setAmount(sio.getAmount()/2);
|
|
|
262 |
sio.setCreditTimestamp(LocalDateTime.now());
|
|
|
263 |
sio.setStatusDescription("Investment maintained for " + investmentMaintainedDays + "(< 12) days");
|
|
|
264 |
totalAmount += sio.getAmount();
|
|
|
265 |
} else {
|
|
|
266 |
sio.setStatus(SchemePayoutStatus.CREDITED);
|
|
|
267 |
sio.setCreditTimestamp(LocalDateTime.now());
|
|
|
268 |
totalAmount += sio.getAmount();
|
|
|
269 |
}
|
|
|
270 |
}
|
|
|
271 |
if(totalAmount > 0) {
|
|
|
272 |
String description = "Investment margin paid for " + FormattingUtils.formatYearMonth(startOfPreviousMonth.atStartOfDay());
|
|
|
273 |
if(investmentMaintainedDays < 12) {
|
|
|
274 |
description += ", as maintained for " + investmentMaintainedDays + "(< 12) days";
|
|
|
275 |
}
|
|
|
276 |
walletService.addAmountToWallet(fofoId,referenceId, WalletReferenceType.INVESTMENT_PAYOUT, description, totalAmount, lastOfPreviousMonth.atTime(LocalTime.MAX));
|
|
|
277 |
}
|
|
|
278 |
System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
@RequestMapping(value = "/evaluateActualInvestmentPayout", method = RequestMethod.GET)
|
|
|
285 |
public ResponseEntity<?> evaluateActualInvestmentPayout(HttpServletRequest request,Model model) throws Exception {
|
|
|
286 |
|
|
|
287 |
List<List<?>> rows = new ArrayList<>();
|
|
|
288 |
LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
|
|
|
289 |
LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
|
|
|
290 |
LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
|
|
|
291 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
|
|
|
292 |
.selectAll(startOfPreviousMonth, lastOfPreviousMonth);
|
|
|
293 |
Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream()
|
|
|
294 |
.filter(x -> x.getShortPercentage() <= 10)
|
|
|
295 |
.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
|
|
|
296 |
LOGGER.info("investmentMaintainedDaysMap {}", investmentMaintainedDaysMap);
|
|
|
297 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAllPending(SchemeType.INVESTMENT,
|
|
|
298 |
startOfPreviousMonth.atStartOfDay(), firstDateOfCurrentMonth.atStartOfDay());
|
|
|
299 |
Map<Integer, List<SchemeInOut>> inventoryItemIdSchemeMap = schemeInOuts.stream()
|
|
|
300 |
.collect(Collectors.groupingBy(x -> x.getInventoryItemId()));
|
|
|
301 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
|
|
|
302 |
Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream().collect(
|
|
|
303 |
Collectors.groupingBy(x -> x.getFofoId(), Collectors.mapping(x -> x.getId(), Collectors.toList())));
|
|
|
304 |
System.out.println("Fofo Id\tInvestment Maintained Days\tEligible payout");
|
|
|
305 |
for (Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
|
|
|
306 |
int fofoId = retailerEntry.getKey();
|
|
|
307 |
List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
|
|
|
308 |
.flatMap(List::stream).collect(Collectors.toList());
|
|
|
309 |
double totalAmount = schemeInouts.stream().filter(x -> x.getRolledBackTimestamp() == null)
|
|
|
310 |
.collect(Collectors.summingDouble(x -> x.getAmount()));
|
|
|
311 |
long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
|
|
|
312 |
: investmentMaintainedDaysMap.get(fofoId);
|
|
|
313 |
if (investmentMaintainedDays < 8) {
|
|
|
314 |
totalAmount = 0;
|
|
|
315 |
} else if (investmentMaintainedDays < 12) {
|
|
|
316 |
totalAmount = totalAmount / 2;
|
|
|
317 |
}
|
|
|
318 |
System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
|
|
|
319 |
CustomRetailer customRetailer= retailerService.getFofoRetailer(fofoId);
|
|
|
320 |
|
|
|
321 |
rows.add(Arrays.asList(fofoId,customRetailer.getBusinessName(),customRetailer.getCode(),investmentMaintainedDays,totalAmount));
|
|
|
322 |
}
|
|
|
323 |
|
|
|
324 |
|
|
|
325 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
|
|
326 |
.getCSVByteStream(Arrays.asList("fofoId","Name", "Code", "investmentMaintainedDays","totalAmount"), rows);
|
|
|
327 |
|
|
|
328 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
329 |
headers.set("Content-Type", "text/csv");
|
|
|
330 |
headers.set("Content-disposition", "inline; filename=investmentMaintainedDays.csv");
|
|
|
331 |
headers.setContentLength(baos.toByteArray().length);
|
|
|
332 |
|
|
|
333 |
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
|
|
|
334 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
335 |
|
|
|
336 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
337 |
|
|
|
338 |
}
|
|
|
339 |
|
|
|
340 |
@RequestMapping(value = "/processInvestmentDryRun", method = RequestMethod.GET)
|
|
|
341 |
public ResponseEntity<?> processInvestmentDryRun(HttpServletRequest request,Model model) throws Exception {
|
|
|
342 |
|
|
|
343 |
LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
|
|
|
344 |
LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
|
|
|
345 |
LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
|
|
|
346 |
List<List<?>> rows = new ArrayList<>();
|
|
|
347 |
|
|
|
348 |
Map<String, String> params = new HashMap<>();
|
|
|
349 |
|
|
|
350 |
params.put("MANUAL_datesBetween_FROMDATE",firstDateOfCurrentMonth.toString());
|
|
|
351 |
params.put("MANUAL_datesBetween_TODATE",firstDateOfCurrentMonth.plusDays(9).toString());
|
|
|
352 |
|
|
|
353 |
params.put("type","INVESTMENT");
|
|
|
354 |
|
|
|
355 |
List<EvaluateSchemeInvestmentPayoutModel> evaluateSchemeInvestmentPayouts = reporticoService.getReports(EvaluateSchemeInvestmentPayoutModel.class,
|
|
|
356 |
ReporticoProject.FOCO, "schemepayout.xml", params);
|
|
|
357 |
LOGGER.info("reportResponse {}", evaluateSchemeInvestmentPayouts);
|
|
|
358 |
|
|
|
359 |
|
|
|
360 |
|
|
|
361 |
int referenceId = Integer.parseInt(FormattingUtils.getYearMonth(startOfPreviousMonth.atStartOfDay()));
|
|
|
362 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
|
|
|
363 |
.selectAll(startOfPreviousMonth, lastOfPreviousMonth);
|
|
|
364 |
Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream()
|
|
|
365 |
.filter(x -> x.getShortPercentage() <= 10)
|
|
|
366 |
.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
|
|
|
367 |
|
|
|
368 |
for (EvaluateSchemeInvestmentPayoutModel esip : evaluateSchemeInvestmentPayouts) {
|
|
|
369 |
|
|
|
370 |
long investmentMaintainedDays = investmentMaintainedDaysMap.get(esip.getFofoId()) == null ? 0
|
|
|
371 |
: investmentMaintainedDaysMap.get(esip.getFofoId());
|
|
|
372 |
|
|
|
373 |
esip.setInvestmentDays(investmentMaintainedDays);
|
|
|
374 |
|
|
|
375 |
float processAmount = esip.getPaidAmount()/2;
|
|
|
376 |
|
|
|
377 |
esip.setProcessAmount(processAmount);
|
|
|
378 |
|
|
|
379 |
rows.add(Arrays.asList(esip.getCode(),esip.getStoreName(),esip.getFofoId(),esip.getItemId(),esip.getBrand(),esip.getModelName(),esip.getModelNumber(),
|
|
|
380 |
esip.getColor(),esip.getSchemeInDp(),esip.getSchemeOutDp(),esip.getSchemeId(),
|
|
|
381 |
esip.getName(),esip.getType(),esip.getPartnerType(),esip.getAmountType(),esip.getAmount(),esip.getPurchaseInvoice(),esip.getSaleInovoice(),
|
|
|
382 |
esip.getPaidAmount(),esip.getCreateTimestamp(),esip.getRolledBackTimestamp(),esip.getSerialNumber(),esip.getInRef(),esip.getOutRef()
|
|
|
383 |
,esip.getBusinessDate(),esip.getStatus(),esip.getDescription(),esip.getProcessAmount(),esip.getInvestmentDays()));
|
|
|
384 |
}
|
|
|
385 |
|
|
|
386 |
|
|
|
387 |
|
|
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
|
391 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
|
|
392 |
.getCSVByteStream(Arrays.asList("Code","Store Name","Fofo Id","Item Id","Brand","Model Name",
|
|
|
393 |
"Model Number","Color","Scheme In Dp","Scheme Out Dp","Scheme Id",
|
|
|
394 |
"Name","Type","Partner Type","Amount Type","Amount","Purchase Invoice","Sale Inovoice",
|
|
|
395 |
"Paid Amount","Create Timestamp","Rolled Back Timestamp",
|
|
|
396 |
"Serial Number","In Ref","Out Ref","Business Date","Status","Description","Process Amount","Investment Days"), rows);
|
|
|
397 |
|
|
|
398 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
399 |
headers.set("Content-Type", "text/csv");
|
|
|
400 |
headers.set("Content-disposition", "inline; filename=schemePayout.csv");
|
|
|
401 |
headers.setContentLength(baos.toByteArray().length);
|
|
|
402 |
|
|
|
403 |
final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
|
|
|
404 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
405 |
|
|
|
406 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
407 |
|
|
|
408 |
}
|
|
|
409 |
|
| 23556 |
amit.gupta |
410 |
@RequestMapping(value = "/schemes/update", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
411 |
public String updateShcemes(HttpServletRequest request, @RequestBody SchemeItems schemeItems, Model model)
|
|
|
412 |
throws Exception {
|
|
|
413 |
for (int schemeId : schemeItems.getSchemeIds()) {
|
| 23928 |
govind |
414 |
if (schemeRepository.selectById(schemeId) != null)
|
|
|
415 |
for (int itemId : schemeItems.getItemIds()) {
|
|
|
416 |
if (tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(Arrays.asList(itemId)),
|
|
|
417 |
new HashSet<>(Arrays.asList(4, 7))).size() > 0) {
|
|
|
418 |
SchemeItem si = new SchemeItem();
|
|
|
419 |
si.setItemId(itemId);
|
|
|
420 |
si.setSchemeId(schemeId);
|
|
|
421 |
try {
|
|
|
422 |
schemeItemRepository.persist(si);
|
|
|
423 |
} catch (Exception e) {
|
|
|
424 |
LOGGER.info("Scheme aleady exist");
|
|
|
425 |
}
|
|
|
426 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
427 |
} else {
|
|
|
428 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
429 |
throw new ProfitMandiBusinessException("ItemId", itemId, "Invalid Item Id");
|
|
|
430 |
}
|
|
|
431 |
}
|
|
|
432 |
}
|
|
|
433 |
return "response";
|
|
|
434 |
}
|
| 25256 |
amit.gupta |
435 |
|
| 23928 |
govind |
436 |
@RequestMapping(value = "/addItemToScheme", method = RequestMethod.POST)
|
|
|
437 |
public String updateScheme(HttpServletRequest request, @RequestBody SchemeItems schemeItems, Model model)
|
|
|
438 |
throws Exception {
|
|
|
439 |
for (int schemeId : schemeItems.getSchemeIds()) {
|
| 23914 |
govind |
440 |
List<Integer> itemIds = schemeItemRepository.selectItemIdsBySchemeId(schemeId);
|
| 23786 |
amit.gupta |
441 |
if (schemeRepository.selectById(schemeId) != null)
|
|
|
442 |
for (int itemId : schemeItems.getItemIds()) {
|
|
|
443 |
if (tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(Arrays.asList(itemId)),
|
| 23914 |
govind |
444 |
new HashSet<>(Arrays.asList(4, 7))).size() > 0 && (!(itemIds.contains(itemId)))) {
|
| 23786 |
amit.gupta |
445 |
SchemeItem si = new SchemeItem();
|
|
|
446 |
si.setItemId(itemId);
|
|
|
447 |
si.setSchemeId(schemeId);
|
|
|
448 |
try {
|
|
|
449 |
schemeItemRepository.persist(si);
|
|
|
450 |
} catch (Exception e) {
|
| 23914 |
govind |
451 |
LOGGER.info("Scheme already exist");
|
| 23786 |
amit.gupta |
452 |
}
|
|
|
453 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
454 |
} else {
|
|
|
455 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
| 23556 |
amit.gupta |
456 |
}
|
|
|
457 |
}
|
|
|
458 |
}
|
|
|
459 |
return "response";
|
|
|
460 |
}
|
| 23914 |
govind |
461 |
|
|
|
462 |
@RequestMapping(value = "/schemes/delete", method = RequestMethod.DELETE)
|
|
|
463 |
public String deleteShcemes(HttpServletRequest request,
|
|
|
464 |
@RequestParam(name = "schemeId", required = false, defaultValue = "0") int schemeId,
|
|
|
465 |
@RequestParam(name = "itemId", required = false, defaultValue = "0") int itemId, Model model)
|
| 23819 |
govind |
466 |
throws Exception {
|
| 23914 |
govind |
467 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
468 |
if (!(schemeId == 0 && itemId == 0) || (!(schemeId == 0 || itemId == 0))) {
|
|
|
469 |
schemeItemRepository.deletebyItemIdsandSchemeIds(itemId, schemeId);
|
|
|
470 |
|
|
|
471 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
472 |
|
|
|
473 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
|
|
474 |
|
|
|
475 |
}
|
|
|
476 |
return "response";
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
@RequestMapping(value = "/extendAllSchemes", method = RequestMethod.POST)
|
|
|
480 |
public String extendAllScheme(HttpServletRequest request, @RequestBody LocalDateTime extendDatetime, Model model)
|
|
|
481 |
throws Exception {
|
| 28924 |
amit.gupta |
482 |
extendDatetime = LocalDateTime.of(extendDatetime.toLocalDate(), Utils.MAX_TIME);
|
| 23914 |
govind |
483 |
List<Scheme> schemes = schemeRepository.selectActiveAll();
|
|
|
484 |
if (schemes.size() > 0) {
|
|
|
485 |
for (Scheme scheme : schemes) {
|
| 25261 |
amit.gupta |
486 |
if (scheme.getExpireTimestamp() == null) {
|
| 23914 |
govind |
487 |
scheme.setEndDateTime(extendDatetime);
|
|
|
488 |
schemeRepository.persist(scheme);
|
| 23819 |
govind |
489 |
}
|
|
|
490 |
}
|
| 23914 |
govind |
491 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
492 |
return "response";
|
| 23819 |
govind |
493 |
}
|
| 23914 |
govind |
494 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
| 23819 |
govind |
495 |
return "response";
|
|
|
496 |
}
|
| 23786 |
amit.gupta |
497 |
|
| 23914 |
govind |
498 |
@RequestMapping(value = "/extendSchemeById", method = RequestMethod.POST)
|
|
|
499 |
public String extendSchemeById(HttpServletRequest request,
|
| 23819 |
govind |
500 |
|
| 23914 |
govind |
501 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
|
|
502 |
@RequestBody LocalDateTime extendDatetime, Model model) throws Exception {
|
| 28924 |
amit.gupta |
503 |
extendDatetime = LocalDateTime.of(extendDatetime.toLocalDate(), Utils.MAX_TIME);
|
| 23914 |
govind |
504 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
|
|
505 |
if ((!(scheme.getActiveTimestamp() == null)) && scheme.getExpireTimestamp() == null) {
|
|
|
506 |
scheme.setEndDateTime(extendDatetime);
|
|
|
507 |
schemeRepository.persist(scheme);
|
|
|
508 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
509 |
return "response";
|
|
|
510 |
}
|
|
|
511 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
512 |
return "response";
|
|
|
513 |
}
|
|
|
514 |
|
| 22860 |
ashik.ali |
515 |
@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
|
| 23715 |
govind |
516 |
public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest,
|
|
|
517 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 23752 |
govind |
518 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
519 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
520 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
| 23715 |
govind |
521 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
522 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
523 |
LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
|
| 22927 |
ashik.ali |
524 |
schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
|
|
|
525 |
LOGGER.info("Scheme saved successfully");
|
| 23271 |
ashik.ali |
526 |
long size = schemeRepository.selectAllCount();
|
| 22927 |
ashik.ali |
527 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
528 |
model.addAttribute("schemes", schemes);
|
|
|
529 |
model.addAttribute("start", offset + 1);
|
| 23271 |
ashik.ali |
530 |
model.addAttribute("size", size);
|
| 23752 |
govind |
531 |
model.addAttribute("searchItem", searchItem);
|
|
|
532 |
model.addAttribute("searchTerm", searchTerm);
|
| 23914 |
govind |
533 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23715 |
govind |
534 |
if (schemes.size() < limit) {
|
| 22927 |
ashik.ali |
535 |
model.addAttribute("end", offset + schemes.size());
|
| 23786 |
amit.gupta |
536 |
} else {
|
| 22927 |
ashik.ali |
537 |
model.addAttribute("end", offset + limit);
|
|
|
538 |
}
|
|
|
539 |
return "schemes";
|
| 23786 |
amit.gupta |
540 |
|
| 22860 |
ashik.ali |
541 |
}
|
| 23786 |
amit.gupta |
542 |
|
| 22860 |
ashik.ali |
543 |
@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
|
| 23715 |
govind |
544 |
public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 27876 |
amit.gupta |
545 |
@RequestParam(required = false) LocalDate date,
|
| 23752 |
govind |
546 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 27897 |
amit.gupta |
547 |
@RequestParam(name = "searchItem", required = false, defaultValue = "0") int searchItem,
|
| 26802 |
tejbeer |
548 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
549 |
@RequestParam(name = "partnerType", required = false, defaultValue = "") PartnerType partnerType,
|
| 28795 |
tejbeer |
550 |
@RequestParam(name = "searchImei", required = false, defaultValue = "") String searchImei, Model model)
|
|
|
551 |
throws ProfitMandiBusinessException {
|
| 23343 |
ashik.ali |
552 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26802 |
tejbeer |
553 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| 27876 |
amit.gupta |
554 |
if (date == null) {
|
|
|
555 |
date = LocalDate.now();
|
|
|
556 |
}
|
|
|
557 |
model.addAttribute("date", date);
|
| 26802 |
tejbeer |
558 |
|
| 23343 |
ashik.ali |
559 |
List<Scheme> schemes = null;
|
| 28796 |
tejbeer |
560 |
List<SchemeInOut> schemeInOut = null;
|
|
|
561 |
|
| 23343 |
ashik.ali |
562 |
long size = 0;
|
| 28980 |
amit.gupta |
563 |
date = date.isAfter(LocalDate.now()) ? LocalDate.now() : date;
|
| 26802 |
tejbeer |
564 |
if (partnerType == null) {
|
| 28980 |
amit.gupta |
565 |
//TODO - SCHEME
|
|
|
566 |
/*
|
|
|
567 |
* partnerType =
|
|
|
568 |
* partnerTypeChangeService.getTypeOnMonth(loginDetails.getFofoId(),
|
|
|
569 |
* YearMonth.of(date.getYear(), date.getMonth()));
|
|
|
570 |
*/
|
|
|
571 |
partnerType = partnerTypeChangeService.getTypeOnDate(loginDetails.getFofoId(), date);
|
| 23343 |
ashik.ali |
572 |
}
|
| 27394 |
amit.gupta |
573 |
if (!(searchTerm.equals(""))) {
|
| 26802 |
tejbeer |
574 |
schemes = schemeRepository.selectBySearchTerm(searchTerm, offset, limit);
|
| 27612 |
tejbeer |
575 |
for (Scheme scheme : schemes) {
|
|
|
576 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
| 27394 |
amit.gupta |
577 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
578 |
} else {
|
|
|
579 |
scheme.setAmountModel(scheme.getAmount() + "");
|
|
|
580 |
}
|
|
|
581 |
}
|
| 27876 |
amit.gupta |
582 |
if (schemes.size() > 0) {
|
| 26802 |
tejbeer |
583 |
size = schemeRepository.selectAllCount();
|
|
|
584 |
LOGGER.info("schemes" + schemes);
|
|
|
585 |
model.addAttribute("schemes", schemes);
|
|
|
586 |
model.addAttribute("start", offset + 1);
|
|
|
587 |
model.addAttribute("size", size);
|
|
|
588 |
if (schemes.size() < limit) {
|
|
|
589 |
model.addAttribute("end", offset + schemes.size());
|
| 27876 |
amit.gupta |
590 |
} else {
|
| 26802 |
tejbeer |
591 |
model.addAttribute("end", offset + limit);
|
|
|
592 |
}
|
| 27612 |
tejbeer |
593 |
}
|
|
|
594 |
|
|
|
595 |
else {
|
| 26802 |
tejbeer |
596 |
throw new ProfitMandiBusinessException("SchemeId", searchTerm, "SchemeId Not Found");
|
|
|
597 |
}
|
| 27612 |
tejbeer |
598 |
}
|
|
|
599 |
|
| 27897 |
amit.gupta |
600 |
else if (searchItem > 0) {
|
| 27394 |
amit.gupta |
601 |
TagListing tagListing = null;
|
| 28134 |
tejbeer |
602 |
tagListing = tagListingRepository.selectByItemId(searchItem);
|
| 28492 |
amit.gupta |
603 |
Item item = itemRepository.selectById(searchItem);
|
| 28134 |
tejbeer |
604 |
if (tagListing != null) {
|
|
|
605 |
model.addAttribute("dp", tagListing.getSellingPrice());
|
|
|
606 |
model.addAttribute("mop", tagListing.getMop());
|
| 26802 |
tejbeer |
607 |
}
|
| 27897 |
amit.gupta |
608 |
schemes = schemeService.selectSchemeByPartnerType(partnerType, date, searchItem, isAdmin, offset, limit);
|
| 27424 |
tejbeer |
609 |
model.addAttribute("schemes", schemes);
|
| 27612 |
tejbeer |
610 |
if (schemes.size() == 0) {
|
| 28795 |
tejbeer |
611 |
if (isAdmin)
|
|
|
612 |
return "schemes";
|
|
|
613 |
else {
|
| 27612 |
tejbeer |
614 |
|
| 28795 |
tejbeer |
615 |
return "schemes-partner";
|
| 27389 |
amit.gupta |
616 |
}
|
|
|
617 |
}
|
| 28795 |
tejbeer |
618 |
// For 7720(HR) remove investment
|
|
|
619 |
int nlc = this.getNlc(item, loginDetails.getFofoId(), schemes, tagListing, searchItem);
|
| 27897 |
amit.gupta |
620 |
size = schemeService.selectSchemeCount(partnerType, date, searchItem, isAdmin);
|
| 26802 |
tejbeer |
621 |
model.addAttribute("start", offset + 1);
|
|
|
622 |
model.addAttribute("size", size);
|
|
|
623 |
if (schemes.size() < limit) {
|
|
|
624 |
model.addAttribute("end", offset + schemes.size());
|
|
|
625 |
} else {
|
|
|
626 |
model.addAttribute("end", offset + limit);
|
|
|
627 |
}
|
| 28547 |
amit.gupta |
628 |
model.addAttribute("nlc", Math.round(nlc));
|
| 28795 |
tejbeer |
629 |
} else if (!(searchImei.equals(""))) {
|
|
|
630 |
|
|
|
631 |
LOGGER.info("searchImei" + searchImei);
|
|
|
632 |
|
|
|
633 |
InventoryItem inventoryItem = inventoryItemRepository.selectBySerialNumberFofoId(searchImei,
|
|
|
634 |
loginDetails.getFofoId());
|
| 28802 |
tejbeer |
635 |
Item item = itemRepository.selectById(inventoryItem.getItemId());
|
| 28795 |
tejbeer |
636 |
Map<Integer, Scheme> schemeMap = new HashMap<>();
|
|
|
637 |
if (inventoryItem != null) {
|
|
|
638 |
|
|
|
639 |
LOGGER.info("inventoryItem" + inventoryItem);
|
|
|
640 |
|
|
|
641 |
schemeInOut = schemeInOutRepository
|
|
|
642 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItem.getId())));
|
|
|
643 |
|
|
|
644 |
LOGGER.info("schemeInOut" + schemeInOut);
|
|
|
645 |
|
|
|
646 |
if (!schemeInOut.isEmpty()) {
|
|
|
647 |
|
|
|
648 |
List<Integer> schemeIds = schemeInOut.stream().map(x -> x.getSchemeId())
|
|
|
649 |
.collect(Collectors.toList());
|
|
|
650 |
|
|
|
651 |
schemes = schemeRepository.selectBySchemeIds(schemeIds);
|
|
|
652 |
for (Scheme scheme : schemes) {
|
|
|
653 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
|
|
654 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
655 |
} else {
|
|
|
656 |
scheme.setAmountModel(scheme.getAmount() + "");
|
|
|
657 |
}
|
|
|
658 |
}
|
|
|
659 |
|
|
|
660 |
schemeMap = schemes.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
661 |
}
|
|
|
662 |
}
|
|
|
663 |
|
|
|
664 |
model.addAttribute("schemeMap", schemeMap);
|
| 28802 |
tejbeer |
665 |
model.addAttribute("item", item);
|
| 28795 |
tejbeer |
666 |
|
| 28796 |
tejbeer |
667 |
}
|
|
|
668 |
model.addAttribute("schemeInOut", schemeInOut);
|
| 28795 |
tejbeer |
669 |
|
| 27876 |
amit.gupta |
670 |
model.addAttribute("searchItem", searchItem);
|
|
|
671 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
672 |
model.addAttribute("partnerType", partnerType);
|
|
|
673 |
model.addAttribute("isAdmin", isAdmin);
|
| 27612 |
tejbeer |
674 |
model.addAttribute("schemes", schemes);
|
| 27876 |
amit.gupta |
675 |
LOGGER.info("schemes" + schemes);
|
| 23786 |
amit.gupta |
676 |
// model.addAttribute("roleTypes", loginDetails.getRoleTypes());
|
| 27876 |
amit.gupta |
677 |
if (isAdmin)
|
|
|
678 |
return "schemes";
|
|
|
679 |
else {
|
| 27897 |
amit.gupta |
680 |
List<CreateOfferRequest> offers = new ArrayList<>();
|
| 28795 |
tejbeer |
681 |
List<PriceDropIMEI> priceDropImeis = new ArrayList<>();
|
| 28134 |
tejbeer |
682 |
if (searchItem > 0) {
|
| 27897 |
amit.gupta |
683 |
offers = offerService.getPublishedOffers(date, loginDetails.getFofoId(), searchItem);
|
|
|
684 |
}
|
| 28795 |
tejbeer |
685 |
if (!(searchImei.equals(""))) {
|
|
|
686 |
InventoryItem inventoryItem = inventoryItemRepository.selectBySerialNumberFofoId(searchImei,
|
|
|
687 |
loginDetails.getFofoId());
|
|
|
688 |
|
|
|
689 |
priceDropImeis = priceDropIMEIRepository.selectByFofoIdImei(loginDetails.getFofoId(), searchImei);
|
|
|
690 |
for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
|
|
|
691 |
int priceDropId = priceDropIMEI.getPriceDropId();
|
|
|
692 |
PriceDrop pd = priceDropRepository.selectById(priceDropId);
|
|
|
693 |
|
|
|
694 |
priceDropIMEI.setPriceDrop(pd);
|
|
|
695 |
}
|
|
|
696 |
}
|
| 28136 |
tejbeer |
697 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
|
|
698 |
|
| 27876 |
amit.gupta |
699 |
model.addAttribute("offers", offers);
|
| 28136 |
tejbeer |
700 |
model.addAttribute("partnerCode", fs.getCode());
|
| 28795 |
tejbeer |
701 |
model.addAttribute("fofoId", fs.getId());
|
|
|
702 |
model.addAttribute("priceDropImeis", priceDropImeis);
|
| 27876 |
amit.gupta |
703 |
return "schemes-partner";
|
|
|
704 |
}
|
| 22860 |
ashik.ali |
705 |
}
|
| 23786 |
amit.gupta |
706 |
|
| 28795 |
tejbeer |
707 |
private int getNlc(Item item, int fofoId, List<Scheme> schemes, TagListing tagListing, int itemId)
|
|
|
708 |
throws ProfitMandiBusinessException {
|
|
|
709 |
|
|
|
710 |
if (item.getBrand().equals("Vivo") && fofoStoreRepository.getWarehousePartnerMap().get(7720).stream()
|
|
|
711 |
.filter(x -> x.getId() == fofoId).count() > 0) {
|
|
|
712 |
schemes = schemes.stream().filter(x -> !x.getType().equals(SchemeType.INVESTMENT))
|
|
|
713 |
.collect(Collectors.toList());
|
|
|
714 |
}
|
|
|
715 |
float nlc = tagListing.getSellingPrice();
|
|
|
716 |
for (Scheme scheme : schemes) {
|
|
|
717 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
|
|
718 |
if (tagListing != null) {
|
|
|
719 |
float taxRate = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId)).get(itemId);
|
|
|
720 |
float taxableSellingPrice = tagListing.getSellingPrice() / (1 + taxRate / 100);
|
|
|
721 |
float amount = taxableSellingPrice * scheme.getAmount() / 100;
|
|
|
722 |
scheme.setAmountModel(
|
|
|
723 |
FormattingUtils.formatDecimalTwoDigits(amount) + " (" + scheme.getAmount() + "%)");
|
|
|
724 |
nlc -= amount;
|
|
|
725 |
}
|
|
|
726 |
|
|
|
727 |
else {
|
|
|
728 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
729 |
}
|
|
|
730 |
} else {
|
|
|
731 |
scheme.setAmountModel(scheme.getAmount() + "");
|
|
|
732 |
nlc -= scheme.getAmount();
|
|
|
733 |
}
|
|
|
734 |
}
|
|
|
735 |
|
|
|
736 |
return Math.round(nlc);
|
|
|
737 |
|
|
|
738 |
}
|
|
|
739 |
|
| 22860 |
ashik.ali |
740 |
@RequestMapping(value = "/getPaginatedSchemes", method = RequestMethod.GET)
|
| 27876 |
amit.gupta |
741 |
public String getPaginatedSchemes(HttpServletRequest request, @RequestParam(required = false) LocalDate date,
|
| 23786 |
amit.gupta |
742 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 26802 |
tejbeer |
743 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 27876 |
amit.gupta |
744 |
@RequestParam(name = "partnerType", required = false, defaultValue = "ALL") PartnerType partnerType,
|
| 26802 |
tejbeer |
745 |
Model model) throws ProfitMandiBusinessException {
|
|
|
746 |
|
| 23343 |
ashik.ali |
747 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26802 |
tejbeer |
748 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| 27876 |
amit.gupta |
749 |
if (date == null) {
|
|
|
750 |
date = LocalDate.now();
|
|
|
751 |
}
|
| 23271 |
ashik.ali |
752 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
| 27876 |
amit.gupta |
753 |
List<Scheme> schemes = schemeRepository.selectAll();
|
| 26802 |
tejbeer |
754 |
int itemId = 0;
|
| 27394 |
amit.gupta |
755 |
TagListing tagListing = null;
|
| 27897 |
amit.gupta |
756 |
|
| 27612 |
tejbeer |
757 |
for (Scheme scheme : schemes) {
|
|
|
758 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
|
|
759 |
if (itemId > 0) {
|
| 27394 |
amit.gupta |
760 |
float taxRate = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId)).get(itemId);
|
|
|
761 |
float taxableSellingPrice = tagListing.getSellingPrice() / (1 + taxRate / 100);
|
|
|
762 |
float amount = taxableSellingPrice * scheme.getAmount() / 100;
|
| 27612 |
tejbeer |
763 |
scheme.setAmountModel(
|
|
|
764 |
FormattingUtils.formatDecimalTwoDigits(amount) + " (" + scheme.getAmount() + "%)");
|
| 27394 |
amit.gupta |
765 |
} else {
|
|
|
766 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
767 |
}
|
|
|
768 |
} else {
|
| 27876 |
amit.gupta |
769 |
scheme.setAmountModel("" + scheme.getAmount());
|
| 27394 |
amit.gupta |
770 |
}
|
|
|
771 |
}
|
| 26802 |
tejbeer |
772 |
|
| 22860 |
ashik.ali |
773 |
model.addAttribute("schemes", schemes);
|
| 26912 |
tejbeer |
774 |
model.addAttribute("partnerType", partnerType);
|
| 23914 |
govind |
775 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 22860 |
ashik.ali |
776 |
return "schemes-paginated";
|
|
|
777 |
}
|
| 23786 |
amit.gupta |
778 |
|
| 23020 |
ashik.ali |
779 |
@RequestMapping(value = "/schemes/downloadPage", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
780 |
public String downloadPage(HttpServletRequest request, Model model) {
|
| 23020 |
ashik.ali |
781 |
return "schemes-download";
|
|
|
782 |
}
|
| 23786 |
amit.gupta |
783 |
|
| 23020 |
ashik.ali |
784 |
@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
785 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
|
| 23914 |
govind |
786 |
@RequestParam(name = ProfitMandiConstants.START_DATE_TIME) String startDateTimeString,
|
|
|
787 |
@RequestParam(name = ProfitMandiConstants.END_DATE_TIME) String endDateTimeString, Model model)
|
| 23786 |
amit.gupta |
788 |
throws ProfitMandiBusinessException {
|
| 23914 |
govind |
789 |
LocalDateTime startDateTime = StringUtils.toDateTime(startDateTimeString,
|
| 24406 |
amit.gupta |
790 |
DateTimePattern.DD_MM_yyyy_T_HH_MM_SS);
|
|
|
791 |
LocalDateTime endDateTime = StringUtils.toDateTime(endDateTimeString, DateTimePattern.DD_MM_yyyy_T_HH_MM_SS);
|
| 23914 |
govind |
792 |
|
| 23020 |
ashik.ali |
793 |
List<SchemeModel> schemeModels = schemeService.getAllSchemeModels(startDateTime, endDateTime);
|
| 23786 |
amit.gupta |
794 |
|
| 23020 |
ashik.ali |
795 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
796 |
ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
| 23786 |
amit.gupta |
797 |
|
|
|
798 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
799 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
| 23020 |
ashik.ali |
800 |
headers.set("Content-disposition", "inline; filename=SchemesReport.xlsx");
|
| 23786 |
amit.gupta |
801 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
802 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
803 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
804 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 23020 |
ashik.ali |
805 |
}
|
| 23786 |
amit.gupta |
806 |
|
| 22860 |
ashik.ali |
807 |
@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
808 |
public String getSchemeById(HttpServletRequest request,
|
|
|
809 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)
|
|
|
810 |
throws ProfitMandiBusinessException {
|
| 23343 |
ashik.ali |
811 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
812 |
Scheme scheme = schemeService.getSchemeById(schemeId);
|
|
|
813 |
model.addAttribute("scheme", scheme);
|
| 24445 |
amit.gupta |
814 |
model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 22860 |
ashik.ali |
815 |
return "scheme-details";
|
| 23914 |
govind |
816 |
|
| 22860 |
ashik.ali |
817 |
}
|
| 23786 |
amit.gupta |
818 |
|
| 22860 |
ashik.ali |
819 |
@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
|
| 23786 |
amit.gupta |
820 |
public String activeSchemeById(HttpServletRequest request,
|
|
|
821 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
|
|
822 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
823 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
824 |
throws ProfitMandiBusinessException {
|
| 22860 |
ashik.ali |
825 |
schemeService.activeSchemeById(schemeId);
|
|
|
826 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
827 |
model.addAttribute("schemes", schemes);
|
|
|
828 |
return "schemes-paginated";
|
|
|
829 |
}
|
| 23786 |
amit.gupta |
830 |
|
| 22860 |
ashik.ali |
831 |
@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
|
| 23786 |
amit.gupta |
832 |
public String expireSchemeById(HttpServletRequest request,
|
|
|
833 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
| 25069 |
amit.gupta |
834 |
@RequestParam(name = ProfitMandiConstants.EXPIRE_TIMESTAMP) LocalDateTime expiryTimestamp,
|
| 23786 |
amit.gupta |
835 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
836 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
837 |
throws ProfitMandiBusinessException {
|
| 28924 |
amit.gupta |
838 |
expiryTimestamp = LocalDateTime.of(expiryTimestamp.toLocalDate(), Utils.MAX_TIME);
|
| 25069 |
amit.gupta |
839 |
schemeService.expireSchemeById(schemeId, expiryTimestamp);
|
| 22860 |
ashik.ali |
840 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
841 |
model.addAttribute("schemes", schemes);
|
|
|
842 |
return "schemes-paginated";
|
|
|
843 |
}
|
| 23786 |
amit.gupta |
844 |
|
| 23784 |
ashik.ali |
845 |
@RequestMapping(value = "/getSchemesJson", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
846 |
public ResponseEntity<?> getSchemesJson(HttpServletRequest request,
|
|
|
847 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
848 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
849 |
throws ProfitMandiBusinessException {
|
| 23784 |
ashik.ali |
850 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
851 |
return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
|
|
|
852 |
}
|
| 26802 |
tejbeer |
853 |
|
| 26763 |
tejbeer |
854 |
@RequestMapping(value = "/searchSchemeByCategory")
|
|
|
855 |
public String getSchemeByCategory(HttpServletRequest request,
|
|
|
856 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
857 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
858 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
859 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
860 |
@RequestParam(name = "category", required = true, defaultValue = "") PartnerType category, Model model)
|
|
|
861 |
throws ProfitMandiBusinessException {
|
|
|
862 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
863 |
List<Scheme> schemes = null;
|
|
|
864 |
long size = 0;
|
| 26802 |
tejbeer |
865 |
|
|
|
866 |
schemes = schemeRepository.selectByPartnerType(category, offset, limit);
|
|
|
867 |
|
|
|
868 |
if (!(schemes.size() == 0)) {
|
|
|
869 |
size = schemeRepository.selectAllCount();
|
|
|
870 |
LOGGER.info("schemes" + schemes);
|
|
|
871 |
model.addAttribute("schemes", schemes);
|
|
|
872 |
model.addAttribute("start", offset + 1);
|
|
|
873 |
model.addAttribute("size", size);
|
|
|
874 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
875 |
model.addAttribute("searchItem", searchItem);
|
|
|
876 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
|
|
877 |
if (schemes.size() < limit) {
|
|
|
878 |
model.addAttribute("end", offset + schemes.size());
|
|
|
879 |
} else {
|
|
|
880 |
model.addAttribute("end", offset + limit);
|
| 26763 |
tejbeer |
881 |
}
|
| 26802 |
tejbeer |
882 |
}
|
|
|
883 |
|
| 26763 |
tejbeer |
884 |
return "schemes";
|
|
|
885 |
}
|
| 26802 |
tejbeer |
886 |
|
| 26763 |
tejbeer |
887 |
@RequestMapping(value = "/getSchemeByCategoryPaginated")
|
|
|
888 |
public String getSchemeByCategoryPaginated(HttpServletRequest request,
|
|
|
889 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
890 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
891 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
892 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
893 |
@RequestParam(name = "category", required = true, defaultValue = "") PartnerType category, Model model)
|
|
|
894 |
throws ProfitMandiBusinessException {
|
|
|
895 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
896 |
LOGGER.info("In search Item....");
|
|
|
897 |
List<Scheme> schemes = null;
|
| 26802 |
tejbeer |
898 |
|
| 26763 |
tejbeer |
899 |
schemes = schemeRepository.selectByPartnerType(category, offset, limit);
|
| 23506 |
amit.gupta |
900 |
|
| 26763 |
tejbeer |
901 |
model.addAttribute("schemes", schemes);
|
|
|
902 |
model.addAttribute("searchItem", searchItem);
|
|
|
903 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
|
|
904 |
return "schemes-paginated";
|
|
|
905 |
}
|
|
|
906 |
|
| 23752 |
govind |
907 |
@RequestMapping(value = "/searchScheme")
|
|
|
908 |
public String getSchemeBySchemeId(HttpServletRequest request,
|
|
|
909 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
910 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
911 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
912 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
|
|
|
913 |
throws ProfitMandiBusinessException {
|
|
|
914 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
915 |
List<Scheme> schemes = null;
|
|
|
916 |
long size = 0;
|
|
|
917 |
if (!(searchTerm.equals("")) && searchItem.equals("")) {
|
|
|
918 |
schemes = schemeRepository.selectBySearchTerm(searchTerm, offset, limit);
|
| 23786 |
amit.gupta |
919 |
if (!(schemes.size() == 0)) {
|
|
|
920 |
size = schemeRepository.selectAllCount();
|
|
|
921 |
LOGGER.info("schemes" + schemes);
|
|
|
922 |
model.addAttribute("schemes", schemes);
|
|
|
923 |
model.addAttribute("start", offset + 1);
|
|
|
924 |
model.addAttribute("size", size);
|
|
|
925 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
926 |
model.addAttribute("searchItem", searchItem);
|
| 23914 |
govind |
927 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23786 |
amit.gupta |
928 |
if (schemes.size() < limit) {
|
|
|
929 |
model.addAttribute("end", offset + schemes.size());
|
|
|
930 |
} else {
|
|
|
931 |
model.addAttribute("end", offset + limit);
|
|
|
932 |
}
|
| 23752 |
govind |
933 |
} else {
|
| 23786 |
amit.gupta |
934 |
throw new ProfitMandiBusinessException("SchemeId", searchTerm, "SchemeId Not Found");
|
| 23752 |
govind |
935 |
}
|
|
|
936 |
} else if (!(searchItem.equals("")) && searchTerm.equals("")) {
|
|
|
937 |
List<Integer> schemeIds = schemeItemRepository.selectSchemeIdByItemId(Integer.parseInt(searchItem));
|
| 23786 |
amit.gupta |
938 |
if (!(schemeIds.size() == 0)) {
|
| 23752 |
govind |
939 |
LOGGER.info("schemeIds in searchItemScheme" + schemeIds);
|
|
|
940 |
schemes = schemeRepository.selectBySchemeIds(schemeIds, offset, limit);
|
|
|
941 |
size = schemeIds.size();
|
|
|
942 |
LOGGER.info("Size" + size);
|
|
|
943 |
model.addAttribute("schemes", schemes);
|
|
|
944 |
model.addAttribute("start", offset + 1);
|
|
|
945 |
model.addAttribute("size", size);
|
|
|
946 |
model.addAttribute("searchItem", searchItem);
|
|
|
947 |
model.addAttribute("searchTerm", searchTerm);
|
| 23914 |
govind |
948 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23752 |
govind |
949 |
if (schemes.size() < limit) {
|
|
|
950 |
model.addAttribute("end", offset + schemes.size());
|
|
|
951 |
} else {
|
|
|
952 |
model.addAttribute("end", offset + limit);
|
|
|
953 |
}
|
|
|
954 |
|
|
|
955 |
} else {
|
|
|
956 |
throw new ProfitMandiBusinessException("SchemeIds", searchItem, "SchemeId Not Found");
|
|
|
957 |
}
|
|
|
958 |
} else {
|
| 23798 |
amit.gupta |
959 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23752 |
govind |
960 |
schemes = schemeRepository.selectAll(offset, limit);
|
|
|
961 |
size = schemeRepository.selectAllCount();
|
|
|
962 |
} else {
|
|
|
963 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
|
|
964 |
size = schemeRepository.selectAllActiveCount();
|
|
|
965 |
}
|
|
|
966 |
model.addAttribute("schemes", schemes);
|
|
|
967 |
model.addAttribute("start", offset + 1);
|
|
|
968 |
model.addAttribute("size", size);
|
|
|
969 |
model.addAttribute("searchItem", searchItem);
|
|
|
970 |
model.addAttribute("searchTerm", searchTerm);
|
| 23914 |
govind |
971 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23752 |
govind |
972 |
if (schemes.size() < limit) {
|
|
|
973 |
model.addAttribute("end", offset + schemes.size());
|
|
|
974 |
} else {
|
|
|
975 |
model.addAttribute("end", offset + limit);
|
|
|
976 |
}
|
|
|
977 |
}
|
|
|
978 |
return "schemes";
|
|
|
979 |
}
|
|
|
980 |
|
|
|
981 |
@RequestMapping(value = "/searchItemSchemePanigated")
|
|
|
982 |
public String getSchemeByItemPanigated(HttpServletRequest request,
|
|
|
983 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
984 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
985 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
|
|
|
986 |
throws ProfitMandiBusinessException {
|
| 23914 |
govind |
987 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23752 |
govind |
988 |
LOGGER.info("In search Item....");
|
|
|
989 |
List<Scheme> schemes = null;
|
|
|
990 |
if (!searchItem.equals("")) {
|
|
|
991 |
List<Integer> schemeIds = schemeItemRepository.selectSchemeIdByItemId(Integer.parseInt(searchItem));
|
|
|
992 |
if (schemeIds != null) {
|
|
|
993 |
LOGGER.info(schemeIds);
|
|
|
994 |
schemes = schemeRepository.selectBySchemeIds(schemeIds, offset, limit);
|
|
|
995 |
|
|
|
996 |
}
|
|
|
997 |
}
|
|
|
998 |
model.addAttribute("schemes", schemes);
|
|
|
999 |
model.addAttribute("searchItem", searchItem);
|
| 23914 |
govind |
1000 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23752 |
govind |
1001 |
return "schemes-paginated";
|
|
|
1002 |
|
|
|
1003 |
}
|
| 22860 |
ashik.ali |
1004 |
}
|