| 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;
|
| 28980 |
amit.gupta |
9 |
import java.time.YearMonth;
|
| 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;
|
| 22860 |
ashik.ali |
38 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23914 |
govind |
39 |
import com.spice.profitmandi.common.model.MapWrapper;
|
| 22860 |
ashik.ali |
40 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23557 |
amit.gupta |
41 |
import com.spice.profitmandi.common.model.SchemeItems;
|
| 23020 |
ashik.ali |
42 |
import com.spice.profitmandi.common.model.SchemeModel;
|
|
|
43 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 27394 |
amit.gupta |
44 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 23020 |
ashik.ali |
45 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 28924 |
amit.gupta |
46 |
import com.spice.profitmandi.common.util.Utils;
|
| 23784 |
ashik.ali |
47 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 28492 |
amit.gupta |
48 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 22860 |
ashik.ali |
49 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 27389 |
amit.gupta |
50 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 28136 |
tejbeer |
51 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 28795 |
tejbeer |
52 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 25505 |
amit.gupta |
53 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 28795 |
tejbeer |
54 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 23556 |
amit.gupta |
55 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| 28795 |
tejbeer |
56 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
|
|
57 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
| 27389 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 28491 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 28795 |
tejbeer |
60 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
| 27876 |
amit.gupta |
61 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 25505 |
amit.gupta |
62 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
| 26674 |
tejbeer |
63 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 22860 |
ashik.ali |
64 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 27389 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
| 23556 |
amit.gupta |
66 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 26588 |
tejbeer |
67 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
68 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 28795 |
tejbeer |
69 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 26674 |
tejbeer |
70 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 28795 |
tejbeer |
71 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 23556 |
amit.gupta |
72 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| 28795 |
tejbeer |
73 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
|
|
74 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 23798 |
amit.gupta |
75 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23020 |
ashik.ali |
76 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 27876 |
amit.gupta |
77 |
import com.spice.profitmandi.service.offers.OfferService;
|
| 22860 |
ashik.ali |
78 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 26588 |
tejbeer |
79 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22860 |
ashik.ali |
80 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
81 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 23570 |
amit.gupta |
82 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 22860 |
ashik.ali |
83 |
|
|
|
84 |
@Controller
|
| 25369 |
amit.gupta |
85 |
@Transactional(rollbackOn = Throwable.class)
|
| 22860 |
ashik.ali |
86 |
public class SchemeController {
|
|
|
87 |
|
| 23568 |
govind |
88 |
private static final Logger LOGGER = LogManager.getLogger(SchemeController.class);
|
| 22860 |
ashik.ali |
89 |
|
|
|
90 |
@Autowired
|
| 22927 |
ashik.ali |
91 |
private SchemeService schemeService;
|
| 27897 |
amit.gupta |
92 |
|
| 27876 |
amit.gupta |
93 |
@Autowired
|
|
|
94 |
private OfferService offerService;
|
| 23786 |
amit.gupta |
95 |
|
| 22860 |
ashik.ali |
96 |
@Autowired
|
| 27389 |
amit.gupta |
97 |
private StateGstRateRepository stateGstRateRepository;
|
| 27612 |
tejbeer |
98 |
|
| 27389 |
amit.gupta |
99 |
@Autowired
|
| 27416 |
amit.gupta |
100 |
private ItemRepository itemRepository;
|
| 27612 |
tejbeer |
101 |
|
| 27416 |
amit.gupta |
102 |
@Autowired
|
| 22927 |
ashik.ali |
103 |
private SchemeRepository schemeRepository;
|
| 22860 |
ashik.ali |
104 |
|
|
|
105 |
@Autowired
|
| 23556 |
amit.gupta |
106 |
private SchemeItemRepository schemeItemRepository;
|
| 23786 |
amit.gupta |
107 |
|
| 23556 |
amit.gupta |
108 |
@Autowired
|
| 23570 |
amit.gupta |
109 |
private MVCResponseSender mvcResponseSender;
|
| 23786 |
amit.gupta |
110 |
|
| 23570 |
amit.gupta |
111 |
@Autowired
|
| 22927 |
ashik.ali |
112 |
private CookiesProcessor cookiesProcessor;
|
| 23786 |
amit.gupta |
113 |
|
| 23020 |
ashik.ali |
114 |
@Autowired
|
| 23784 |
ashik.ali |
115 |
@Qualifier("fofoInventoryService")
|
| 23020 |
ashik.ali |
116 |
private InventoryService inventoryService;
|
| 23556 |
amit.gupta |
117 |
|
|
|
118 |
@Autowired
|
|
|
119 |
private TagListingRepository tagListingRepository;
|
| 23914 |
govind |
120 |
|
| 23798 |
amit.gupta |
121 |
@Autowired
|
|
|
122 |
private RoleManager roleManager;
|
| 23786 |
amit.gupta |
123 |
|
| 23506 |
amit.gupta |
124 |
@Autowired
|
| 27394 |
amit.gupta |
125 |
private ResponseSender<?> responseSender;
|
| 23786 |
amit.gupta |
126 |
|
| 23784 |
ashik.ali |
127 |
@Autowired
|
| 27394 |
amit.gupta |
128 |
private FofoStoreRepository fofoStoreRepository;
|
| 23786 |
amit.gupta |
129 |
|
| 23784 |
ashik.ali |
130 |
@Autowired
|
| 27394 |
amit.gupta |
131 |
private RetailerService retailerService;
|
| 22860 |
ashik.ali |
132 |
|
| 27394 |
amit.gupta |
133 |
@Autowired
|
|
|
134 |
private Mongo mongoClient;
|
| 26588 |
tejbeer |
135 |
|
|
|
136 |
@Autowired
|
| 26674 |
tejbeer |
137 |
private PartnerTypeChangeService partnerTypeChangeService;
|
|
|
138 |
|
| 28795 |
tejbeer |
139 |
@Autowired
|
|
|
140 |
InventoryItemRepository inventoryItemRepository;
|
|
|
141 |
|
|
|
142 |
@Autowired
|
|
|
143 |
PriceDropIMEIRepository priceDropIMEIRepository;
|
|
|
144 |
|
|
|
145 |
@Autowired
|
|
|
146 |
PriceDropRepository priceDropRepository;
|
|
|
147 |
|
|
|
148 |
@Autowired
|
|
|
149 |
SchemeInOutRepository schemeInOutRepository;
|
|
|
150 |
|
| 22860 |
ashik.ali |
151 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
152 |
public String createScheme(HttpServletRequest request, Model model) {
|
|
|
153 |
// Map<Integer, String> itemIdItemDescriptionMap =
|
|
|
154 |
// inventoryService.getAllItemIdItemDescriptionMap();
|
|
|
155 |
// model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| 25368 |
amit.gupta |
156 |
Set<String> brands = inventoryService.getAllTagListingBrands(ProfitMandiConstants.MOBILE_CATEGORY_ID);
|
|
|
157 |
brands.addAll(inventoryService.getAllTagListingBrands(14206));
|
|
|
158 |
model.addAttribute("brands", brands);
|
| 25505 |
amit.gupta |
159 |
model.addAttribute("retailerTypes", PartnerType.values());
|
| 22860 |
ashik.ali |
160 |
return "create-scheme";
|
|
|
161 |
}
|
| 23786 |
amit.gupta |
162 |
|
| 23914 |
govind |
163 |
@RequestMapping(value = "/getTagListingItemsByBrand", method = RequestMethod.POST)
|
|
|
164 |
public String getTagListingItemsByBrand(HttpServletRequest request, @RequestBody List<String> brands, Model model) {
|
|
|
165 |
Map<Integer, String> itemIdItemDescriptionMap = new HashMap<>();
|
|
|
166 |
LOGGER.info("brands" + brands);
|
|
|
167 |
|
|
|
168 |
List<MapWrapper<Integer, String>> itemIdItemDescriptionMaplist = inventoryService
|
|
|
169 |
.getAllTagListingItemIdItemDescriptionMap(new HashSet<>(brands));
|
|
|
170 |
for (MapWrapper<Integer, String> mapWrapper : itemIdItemDescriptionMaplist) {
|
|
|
171 |
itemIdItemDescriptionMap.put(mapWrapper.getKey(), mapWrapper.getValue());
|
|
|
172 |
}
|
| 23020 |
ashik.ali |
173 |
model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| 23786 |
amit.gupta |
174 |
// model.addAttribute("brands", inventoryService.getAllBrands());
|
| 23914 |
govind |
175 |
|
| 23419 |
ashik.ali |
176 |
return "tag-listing-items-description";
|
| 23020 |
ashik.ali |
177 |
}
|
| 23556 |
amit.gupta |
178 |
|
|
|
179 |
@RequestMapping(value = "/schemes/update-schemes-page", method = RequestMethod.GET)
|
|
|
180 |
public String updateShcemes(HttpServletRequest request) throws ProfitMandiBusinessException {
|
|
|
181 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23799 |
amit.gupta |
182 |
if (!roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23556 |
amit.gupta |
183 |
throw new ProfitMandiBusinessException("User", loginDetails.getEmailId(), "Unauthorised access");
|
|
|
184 |
}
|
|
|
185 |
return "update-schemes-page";
|
|
|
186 |
}
|
| 25256 |
amit.gupta |
187 |
|
| 23556 |
amit.gupta |
188 |
@RequestMapping(value = "/schemes/update", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
189 |
public String updateShcemes(HttpServletRequest request, @RequestBody SchemeItems schemeItems, Model model)
|
|
|
190 |
throws Exception {
|
|
|
191 |
for (int schemeId : schemeItems.getSchemeIds()) {
|
| 23928 |
govind |
192 |
if (schemeRepository.selectById(schemeId) != null)
|
|
|
193 |
for (int itemId : schemeItems.getItemIds()) {
|
|
|
194 |
if (tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(Arrays.asList(itemId)),
|
|
|
195 |
new HashSet<>(Arrays.asList(4, 7))).size() > 0) {
|
|
|
196 |
SchemeItem si = new SchemeItem();
|
|
|
197 |
si.setItemId(itemId);
|
|
|
198 |
si.setSchemeId(schemeId);
|
|
|
199 |
try {
|
|
|
200 |
schemeItemRepository.persist(si);
|
|
|
201 |
} catch (Exception e) {
|
|
|
202 |
LOGGER.info("Scheme aleady exist");
|
|
|
203 |
}
|
|
|
204 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
205 |
} else {
|
|
|
206 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
207 |
throw new ProfitMandiBusinessException("ItemId", itemId, "Invalid Item Id");
|
|
|
208 |
}
|
|
|
209 |
}
|
|
|
210 |
}
|
|
|
211 |
return "response";
|
|
|
212 |
}
|
| 25256 |
amit.gupta |
213 |
|
| 23928 |
govind |
214 |
@RequestMapping(value = "/addItemToScheme", method = RequestMethod.POST)
|
|
|
215 |
public String updateScheme(HttpServletRequest request, @RequestBody SchemeItems schemeItems, Model model)
|
|
|
216 |
throws Exception {
|
|
|
217 |
for (int schemeId : schemeItems.getSchemeIds()) {
|
| 23914 |
govind |
218 |
List<Integer> itemIds = schemeItemRepository.selectItemIdsBySchemeId(schemeId);
|
| 23786 |
amit.gupta |
219 |
if (schemeRepository.selectById(schemeId) != null)
|
|
|
220 |
for (int itemId : schemeItems.getItemIds()) {
|
|
|
221 |
if (tagListingRepository.selectByItemIdsAndTagIds(new HashSet<>(Arrays.asList(itemId)),
|
| 23914 |
govind |
222 |
new HashSet<>(Arrays.asList(4, 7))).size() > 0 && (!(itemIds.contains(itemId)))) {
|
| 23786 |
amit.gupta |
223 |
SchemeItem si = new SchemeItem();
|
|
|
224 |
si.setItemId(itemId);
|
|
|
225 |
si.setSchemeId(schemeId);
|
|
|
226 |
try {
|
|
|
227 |
schemeItemRepository.persist(si);
|
|
|
228 |
} catch (Exception e) {
|
| 23914 |
govind |
229 |
LOGGER.info("Scheme already exist");
|
| 23786 |
amit.gupta |
230 |
}
|
|
|
231 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
232 |
} else {
|
|
|
233 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
| 23556 |
amit.gupta |
234 |
}
|
|
|
235 |
}
|
|
|
236 |
}
|
|
|
237 |
return "response";
|
|
|
238 |
}
|
| 23914 |
govind |
239 |
|
|
|
240 |
@RequestMapping(value = "/schemes/delete", method = RequestMethod.DELETE)
|
|
|
241 |
public String deleteShcemes(HttpServletRequest request,
|
|
|
242 |
@RequestParam(name = "schemeId", required = false, defaultValue = "0") int schemeId,
|
|
|
243 |
@RequestParam(name = "itemId", required = false, defaultValue = "0") int itemId, Model model)
|
| 23819 |
govind |
244 |
throws Exception {
|
| 23914 |
govind |
245 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
246 |
if (!(schemeId == 0 && itemId == 0) || (!(schemeId == 0 || itemId == 0))) {
|
|
|
247 |
schemeItemRepository.deletebyItemIdsandSchemeIds(itemId, schemeId);
|
|
|
248 |
|
|
|
249 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
250 |
|
|
|
251 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
|
|
252 |
|
|
|
253 |
}
|
|
|
254 |
return "response";
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
@RequestMapping(value = "/extendAllSchemes", method = RequestMethod.POST)
|
|
|
258 |
public String extendAllScheme(HttpServletRequest request, @RequestBody LocalDateTime extendDatetime, Model model)
|
|
|
259 |
throws Exception {
|
| 28924 |
amit.gupta |
260 |
extendDatetime = LocalDateTime.of(extendDatetime.toLocalDate(), Utils.MAX_TIME);
|
| 23914 |
govind |
261 |
List<Scheme> schemes = schemeRepository.selectActiveAll();
|
|
|
262 |
if (schemes.size() > 0) {
|
|
|
263 |
for (Scheme scheme : schemes) {
|
| 25261 |
amit.gupta |
264 |
if (scheme.getExpireTimestamp() == null) {
|
| 23914 |
govind |
265 |
scheme.setEndDateTime(extendDatetime);
|
|
|
266 |
schemeRepository.persist(scheme);
|
| 23819 |
govind |
267 |
}
|
|
|
268 |
}
|
| 23914 |
govind |
269 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
270 |
return "response";
|
| 23819 |
govind |
271 |
}
|
| 23914 |
govind |
272 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
| 23819 |
govind |
273 |
return "response";
|
|
|
274 |
}
|
| 23786 |
amit.gupta |
275 |
|
| 23914 |
govind |
276 |
@RequestMapping(value = "/extendSchemeById", method = RequestMethod.POST)
|
|
|
277 |
public String extendSchemeById(HttpServletRequest request,
|
| 23819 |
govind |
278 |
|
| 23914 |
govind |
279 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
|
|
280 |
@RequestBody LocalDateTime extendDatetime, Model model) throws Exception {
|
| 28924 |
amit.gupta |
281 |
extendDatetime = LocalDateTime.of(extendDatetime.toLocalDate(), Utils.MAX_TIME);
|
| 23914 |
govind |
282 |
Scheme scheme = schemeRepository.selectById(schemeId);
|
|
|
283 |
if ((!(scheme.getActiveTimestamp() == null)) && scheme.getExpireTimestamp() == null) {
|
|
|
284 |
scheme.setEndDateTime(extendDatetime);
|
|
|
285 |
schemeRepository.persist(scheme);
|
|
|
286 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
287 |
return "response";
|
|
|
288 |
}
|
|
|
289 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
290 |
return "response";
|
|
|
291 |
}
|
|
|
292 |
|
| 22860 |
ashik.ali |
293 |
@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
|
| 23715 |
govind |
294 |
public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest,
|
|
|
295 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 23752 |
govind |
296 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
297 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
298 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
| 23715 |
govind |
299 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
300 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
301 |
LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
|
| 22927 |
ashik.ali |
302 |
schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
|
|
|
303 |
LOGGER.info("Scheme saved successfully");
|
| 23271 |
ashik.ali |
304 |
long size = schemeRepository.selectAllCount();
|
| 22927 |
ashik.ali |
305 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
306 |
model.addAttribute("schemes", schemes);
|
|
|
307 |
model.addAttribute("start", offset + 1);
|
| 23271 |
ashik.ali |
308 |
model.addAttribute("size", size);
|
| 23752 |
govind |
309 |
model.addAttribute("searchItem", searchItem);
|
|
|
310 |
model.addAttribute("searchTerm", searchTerm);
|
| 23914 |
govind |
311 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23715 |
govind |
312 |
if (schemes.size() < limit) {
|
| 22927 |
ashik.ali |
313 |
model.addAttribute("end", offset + schemes.size());
|
| 23786 |
amit.gupta |
314 |
} else {
|
| 22927 |
ashik.ali |
315 |
model.addAttribute("end", offset + limit);
|
|
|
316 |
}
|
|
|
317 |
return "schemes";
|
| 23786 |
amit.gupta |
318 |
|
| 22860 |
ashik.ali |
319 |
}
|
| 23786 |
amit.gupta |
320 |
|
| 22860 |
ashik.ali |
321 |
@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
|
| 23715 |
govind |
322 |
public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 27876 |
amit.gupta |
323 |
@RequestParam(required = false) LocalDate date,
|
| 23752 |
govind |
324 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 27897 |
amit.gupta |
325 |
@RequestParam(name = "searchItem", required = false, defaultValue = "0") int searchItem,
|
| 26802 |
tejbeer |
326 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
327 |
@RequestParam(name = "partnerType", required = false, defaultValue = "") PartnerType partnerType,
|
| 28795 |
tejbeer |
328 |
@RequestParam(name = "searchImei", required = false, defaultValue = "") String searchImei, Model model)
|
|
|
329 |
throws ProfitMandiBusinessException {
|
| 23343 |
ashik.ali |
330 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26802 |
tejbeer |
331 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| 27876 |
amit.gupta |
332 |
if (date == null) {
|
|
|
333 |
date = LocalDate.now();
|
|
|
334 |
}
|
|
|
335 |
model.addAttribute("date", date);
|
| 26802 |
tejbeer |
336 |
|
| 23343 |
ashik.ali |
337 |
List<Scheme> schemes = null;
|
| 28796 |
tejbeer |
338 |
List<SchemeInOut> schemeInOut = null;
|
|
|
339 |
|
| 23343 |
ashik.ali |
340 |
long size = 0;
|
| 28980 |
amit.gupta |
341 |
date = date.isAfter(LocalDate.now()) ? LocalDate.now() : date;
|
| 26802 |
tejbeer |
342 |
if (partnerType == null) {
|
| 28980 |
amit.gupta |
343 |
//TODO - SCHEME
|
|
|
344 |
/*
|
|
|
345 |
* partnerType =
|
|
|
346 |
* partnerTypeChangeService.getTypeOnMonth(loginDetails.getFofoId(),
|
|
|
347 |
* YearMonth.of(date.getYear(), date.getMonth()));
|
|
|
348 |
*/
|
|
|
349 |
partnerType = partnerTypeChangeService.getTypeOnDate(loginDetails.getFofoId(), date);
|
| 23343 |
ashik.ali |
350 |
}
|
| 27394 |
amit.gupta |
351 |
if (!(searchTerm.equals(""))) {
|
| 26802 |
tejbeer |
352 |
schemes = schemeRepository.selectBySearchTerm(searchTerm, offset, limit);
|
| 27612 |
tejbeer |
353 |
for (Scheme scheme : schemes) {
|
|
|
354 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
| 27394 |
amit.gupta |
355 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
356 |
} else {
|
|
|
357 |
scheme.setAmountModel(scheme.getAmount() + "");
|
|
|
358 |
}
|
|
|
359 |
}
|
| 27876 |
amit.gupta |
360 |
if (schemes.size() > 0) {
|
| 26802 |
tejbeer |
361 |
size = schemeRepository.selectAllCount();
|
|
|
362 |
LOGGER.info("schemes" + schemes);
|
|
|
363 |
model.addAttribute("schemes", schemes);
|
|
|
364 |
model.addAttribute("start", offset + 1);
|
|
|
365 |
model.addAttribute("size", size);
|
|
|
366 |
if (schemes.size() < limit) {
|
|
|
367 |
model.addAttribute("end", offset + schemes.size());
|
| 27876 |
amit.gupta |
368 |
} else {
|
| 26802 |
tejbeer |
369 |
model.addAttribute("end", offset + limit);
|
|
|
370 |
}
|
| 27612 |
tejbeer |
371 |
}
|
|
|
372 |
|
|
|
373 |
else {
|
| 26802 |
tejbeer |
374 |
throw new ProfitMandiBusinessException("SchemeId", searchTerm, "SchemeId Not Found");
|
|
|
375 |
}
|
| 27612 |
tejbeer |
376 |
}
|
|
|
377 |
|
| 27897 |
amit.gupta |
378 |
else if (searchItem > 0) {
|
| 27394 |
amit.gupta |
379 |
TagListing tagListing = null;
|
| 28134 |
tejbeer |
380 |
tagListing = tagListingRepository.selectByItemId(searchItem);
|
| 28492 |
amit.gupta |
381 |
Item item = itemRepository.selectById(searchItem);
|
| 28134 |
tejbeer |
382 |
if (tagListing != null) {
|
|
|
383 |
model.addAttribute("dp", tagListing.getSellingPrice());
|
|
|
384 |
model.addAttribute("mop", tagListing.getMop());
|
| 26802 |
tejbeer |
385 |
}
|
| 27897 |
amit.gupta |
386 |
schemes = schemeService.selectSchemeByPartnerType(partnerType, date, searchItem, isAdmin, offset, limit);
|
| 27424 |
tejbeer |
387 |
model.addAttribute("schemes", schemes);
|
| 27612 |
tejbeer |
388 |
if (schemes.size() == 0) {
|
| 28795 |
tejbeer |
389 |
if (isAdmin)
|
|
|
390 |
return "schemes";
|
|
|
391 |
else {
|
| 27612 |
tejbeer |
392 |
|
| 28795 |
tejbeer |
393 |
return "schemes-partner";
|
| 27389 |
amit.gupta |
394 |
}
|
|
|
395 |
}
|
| 28795 |
tejbeer |
396 |
// For 7720(HR) remove investment
|
|
|
397 |
int nlc = this.getNlc(item, loginDetails.getFofoId(), schemes, tagListing, searchItem);
|
| 27897 |
amit.gupta |
398 |
size = schemeService.selectSchemeCount(partnerType, date, searchItem, isAdmin);
|
| 26802 |
tejbeer |
399 |
model.addAttribute("start", offset + 1);
|
|
|
400 |
model.addAttribute("size", size);
|
|
|
401 |
if (schemes.size() < limit) {
|
|
|
402 |
model.addAttribute("end", offset + schemes.size());
|
|
|
403 |
} else {
|
|
|
404 |
model.addAttribute("end", offset + limit);
|
|
|
405 |
}
|
| 28547 |
amit.gupta |
406 |
model.addAttribute("nlc", Math.round(nlc));
|
| 28795 |
tejbeer |
407 |
} else if (!(searchImei.equals(""))) {
|
|
|
408 |
|
|
|
409 |
LOGGER.info("searchImei" + searchImei);
|
|
|
410 |
|
|
|
411 |
InventoryItem inventoryItem = inventoryItemRepository.selectBySerialNumberFofoId(searchImei,
|
|
|
412 |
loginDetails.getFofoId());
|
| 28802 |
tejbeer |
413 |
Item item = itemRepository.selectById(inventoryItem.getItemId());
|
| 28795 |
tejbeer |
414 |
Map<Integer, Scheme> schemeMap = new HashMap<>();
|
|
|
415 |
if (inventoryItem != null) {
|
|
|
416 |
|
|
|
417 |
LOGGER.info("inventoryItem" + inventoryItem);
|
|
|
418 |
|
|
|
419 |
schemeInOut = schemeInOutRepository
|
|
|
420 |
.selectByInventoryItemIds(new HashSet<>(Arrays.asList(inventoryItem.getId())));
|
|
|
421 |
|
|
|
422 |
LOGGER.info("schemeInOut" + schemeInOut);
|
|
|
423 |
|
|
|
424 |
if (!schemeInOut.isEmpty()) {
|
|
|
425 |
|
|
|
426 |
List<Integer> schemeIds = schemeInOut.stream().map(x -> x.getSchemeId())
|
|
|
427 |
.collect(Collectors.toList());
|
|
|
428 |
|
|
|
429 |
schemes = schemeRepository.selectBySchemeIds(schemeIds);
|
|
|
430 |
for (Scheme scheme : schemes) {
|
|
|
431 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
|
|
432 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
433 |
} else {
|
|
|
434 |
scheme.setAmountModel(scheme.getAmount() + "");
|
|
|
435 |
}
|
|
|
436 |
}
|
|
|
437 |
|
|
|
438 |
schemeMap = schemes.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
439 |
}
|
|
|
440 |
}
|
|
|
441 |
|
|
|
442 |
model.addAttribute("schemeMap", schemeMap);
|
| 28802 |
tejbeer |
443 |
model.addAttribute("item", item);
|
| 28795 |
tejbeer |
444 |
|
| 28796 |
tejbeer |
445 |
}
|
|
|
446 |
model.addAttribute("schemeInOut", schemeInOut);
|
| 28795 |
tejbeer |
447 |
|
| 27876 |
amit.gupta |
448 |
model.addAttribute("searchItem", searchItem);
|
|
|
449 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
450 |
model.addAttribute("partnerType", partnerType);
|
|
|
451 |
model.addAttribute("isAdmin", isAdmin);
|
| 27612 |
tejbeer |
452 |
model.addAttribute("schemes", schemes);
|
| 27876 |
amit.gupta |
453 |
LOGGER.info("schemes" + schemes);
|
| 23786 |
amit.gupta |
454 |
// model.addAttribute("roleTypes", loginDetails.getRoleTypes());
|
| 27876 |
amit.gupta |
455 |
if (isAdmin)
|
|
|
456 |
return "schemes";
|
|
|
457 |
else {
|
| 27897 |
amit.gupta |
458 |
List<CreateOfferRequest> offers = new ArrayList<>();
|
| 28795 |
tejbeer |
459 |
List<PriceDropIMEI> priceDropImeis = new ArrayList<>();
|
| 28134 |
tejbeer |
460 |
if (searchItem > 0) {
|
| 27897 |
amit.gupta |
461 |
offers = offerService.getPublishedOffers(date, loginDetails.getFofoId(), searchItem);
|
|
|
462 |
}
|
| 28795 |
tejbeer |
463 |
if (!(searchImei.equals(""))) {
|
|
|
464 |
InventoryItem inventoryItem = inventoryItemRepository.selectBySerialNumberFofoId(searchImei,
|
|
|
465 |
loginDetails.getFofoId());
|
|
|
466 |
|
|
|
467 |
priceDropImeis = priceDropIMEIRepository.selectByFofoIdImei(loginDetails.getFofoId(), searchImei);
|
|
|
468 |
for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
|
|
|
469 |
int priceDropId = priceDropIMEI.getPriceDropId();
|
|
|
470 |
PriceDrop pd = priceDropRepository.selectById(priceDropId);
|
|
|
471 |
|
|
|
472 |
priceDropIMEI.setPriceDrop(pd);
|
|
|
473 |
}
|
|
|
474 |
}
|
| 28136 |
tejbeer |
475 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
|
|
476 |
|
| 27876 |
amit.gupta |
477 |
model.addAttribute("offers", offers);
|
| 28136 |
tejbeer |
478 |
model.addAttribute("partnerCode", fs.getCode());
|
| 28795 |
tejbeer |
479 |
model.addAttribute("fofoId", fs.getId());
|
|
|
480 |
model.addAttribute("priceDropImeis", priceDropImeis);
|
| 27876 |
amit.gupta |
481 |
return "schemes-partner";
|
|
|
482 |
}
|
| 22860 |
ashik.ali |
483 |
}
|
| 23786 |
amit.gupta |
484 |
|
| 28795 |
tejbeer |
485 |
private int getNlc(Item item, int fofoId, List<Scheme> schemes, TagListing tagListing, int itemId)
|
|
|
486 |
throws ProfitMandiBusinessException {
|
|
|
487 |
|
|
|
488 |
if (item.getBrand().equals("Vivo") && fofoStoreRepository.getWarehousePartnerMap().get(7720).stream()
|
|
|
489 |
.filter(x -> x.getId() == fofoId).count() > 0) {
|
|
|
490 |
schemes = schemes.stream().filter(x -> !x.getType().equals(SchemeType.INVESTMENT))
|
|
|
491 |
.collect(Collectors.toList());
|
|
|
492 |
}
|
|
|
493 |
float nlc = tagListing.getSellingPrice();
|
|
|
494 |
for (Scheme scheme : schemes) {
|
|
|
495 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
|
|
496 |
if (tagListing != null) {
|
|
|
497 |
float taxRate = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId)).get(itemId);
|
|
|
498 |
float taxableSellingPrice = tagListing.getSellingPrice() / (1 + taxRate / 100);
|
|
|
499 |
float amount = taxableSellingPrice * scheme.getAmount() / 100;
|
|
|
500 |
scheme.setAmountModel(
|
|
|
501 |
FormattingUtils.formatDecimalTwoDigits(amount) + " (" + scheme.getAmount() + "%)");
|
|
|
502 |
nlc -= amount;
|
|
|
503 |
}
|
|
|
504 |
|
|
|
505 |
else {
|
|
|
506 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
507 |
}
|
|
|
508 |
} else {
|
|
|
509 |
scheme.setAmountModel(scheme.getAmount() + "");
|
|
|
510 |
nlc -= scheme.getAmount();
|
|
|
511 |
}
|
|
|
512 |
}
|
|
|
513 |
|
|
|
514 |
return Math.round(nlc);
|
|
|
515 |
|
|
|
516 |
}
|
|
|
517 |
|
| 22860 |
ashik.ali |
518 |
@RequestMapping(value = "/getPaginatedSchemes", method = RequestMethod.GET)
|
| 27876 |
amit.gupta |
519 |
public String getPaginatedSchemes(HttpServletRequest request, @RequestParam(required = false) LocalDate date,
|
| 23786 |
amit.gupta |
520 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 26802 |
tejbeer |
521 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 27876 |
amit.gupta |
522 |
@RequestParam(name = "partnerType", required = false, defaultValue = "ALL") PartnerType partnerType,
|
| 26802 |
tejbeer |
523 |
Model model) throws ProfitMandiBusinessException {
|
|
|
524 |
|
| 23343 |
ashik.ali |
525 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26802 |
tejbeer |
526 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| 27876 |
amit.gupta |
527 |
if (date == null) {
|
|
|
528 |
date = LocalDate.now();
|
|
|
529 |
}
|
| 23271 |
ashik.ali |
530 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
| 27876 |
amit.gupta |
531 |
List<Scheme> schemes = schemeRepository.selectAll();
|
| 26802 |
tejbeer |
532 |
int itemId = 0;
|
| 27394 |
amit.gupta |
533 |
TagListing tagListing = null;
|
| 27897 |
amit.gupta |
534 |
|
| 27612 |
tejbeer |
535 |
for (Scheme scheme : schemes) {
|
|
|
536 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
|
|
537 |
if (itemId > 0) {
|
| 27394 |
amit.gupta |
538 |
float taxRate = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId)).get(itemId);
|
|
|
539 |
float taxableSellingPrice = tagListing.getSellingPrice() / (1 + taxRate / 100);
|
|
|
540 |
float amount = taxableSellingPrice * scheme.getAmount() / 100;
|
| 27612 |
tejbeer |
541 |
scheme.setAmountModel(
|
|
|
542 |
FormattingUtils.formatDecimalTwoDigits(amount) + " (" + scheme.getAmount() + "%)");
|
| 27394 |
amit.gupta |
543 |
} else {
|
|
|
544 |
scheme.setAmountModel(scheme.getAmount() + "%");
|
|
|
545 |
}
|
|
|
546 |
} else {
|
| 27876 |
amit.gupta |
547 |
scheme.setAmountModel("" + scheme.getAmount());
|
| 27394 |
amit.gupta |
548 |
}
|
|
|
549 |
}
|
| 26802 |
tejbeer |
550 |
|
| 22860 |
ashik.ali |
551 |
model.addAttribute("schemes", schemes);
|
| 26912 |
tejbeer |
552 |
model.addAttribute("partnerType", partnerType);
|
| 23914 |
govind |
553 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 22860 |
ashik.ali |
554 |
return "schemes-paginated";
|
|
|
555 |
}
|
| 23786 |
amit.gupta |
556 |
|
| 23020 |
ashik.ali |
557 |
@RequestMapping(value = "/schemes/downloadPage", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
558 |
public String downloadPage(HttpServletRequest request, Model model) {
|
| 23020 |
ashik.ali |
559 |
return "schemes-download";
|
|
|
560 |
}
|
| 23786 |
amit.gupta |
561 |
|
| 23020 |
ashik.ali |
562 |
@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
563 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
|
| 23914 |
govind |
564 |
@RequestParam(name = ProfitMandiConstants.START_DATE_TIME) String startDateTimeString,
|
|
|
565 |
@RequestParam(name = ProfitMandiConstants.END_DATE_TIME) String endDateTimeString, Model model)
|
| 23786 |
amit.gupta |
566 |
throws ProfitMandiBusinessException {
|
| 23914 |
govind |
567 |
LocalDateTime startDateTime = StringUtils.toDateTime(startDateTimeString,
|
| 24406 |
amit.gupta |
568 |
DateTimePattern.DD_MM_yyyy_T_HH_MM_SS);
|
|
|
569 |
LocalDateTime endDateTime = StringUtils.toDateTime(endDateTimeString, DateTimePattern.DD_MM_yyyy_T_HH_MM_SS);
|
| 23914 |
govind |
570 |
|
| 23020 |
ashik.ali |
571 |
List<SchemeModel> schemeModels = schemeService.getAllSchemeModels(startDateTime, endDateTime);
|
| 23786 |
amit.gupta |
572 |
|
| 23020 |
ashik.ali |
573 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
574 |
ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
|
| 23786 |
amit.gupta |
575 |
|
|
|
576 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
577 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
| 23020 |
ashik.ali |
578 |
headers.set("Content-disposition", "inline; filename=SchemesReport.xlsx");
|
| 23786 |
amit.gupta |
579 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
580 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
581 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
582 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 23020 |
ashik.ali |
583 |
}
|
| 23786 |
amit.gupta |
584 |
|
| 22860 |
ashik.ali |
585 |
@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
586 |
public String getSchemeById(HttpServletRequest request,
|
|
|
587 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)
|
|
|
588 |
throws ProfitMandiBusinessException {
|
| 23343 |
ashik.ali |
589 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
590 |
Scheme scheme = schemeService.getSchemeById(schemeId);
|
|
|
591 |
model.addAttribute("scheme", scheme);
|
| 24445 |
amit.gupta |
592 |
model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 22860 |
ashik.ali |
593 |
return "scheme-details";
|
| 23914 |
govind |
594 |
|
| 22860 |
ashik.ali |
595 |
}
|
| 23786 |
amit.gupta |
596 |
|
| 22860 |
ashik.ali |
597 |
@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
|
| 23786 |
amit.gupta |
598 |
public String activeSchemeById(HttpServletRequest request,
|
|
|
599 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
|
|
600 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
601 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
602 |
throws ProfitMandiBusinessException {
|
| 22860 |
ashik.ali |
603 |
schemeService.activeSchemeById(schemeId);
|
|
|
604 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
605 |
model.addAttribute("schemes", schemes);
|
|
|
606 |
return "schemes-paginated";
|
|
|
607 |
}
|
| 23786 |
amit.gupta |
608 |
|
| 22860 |
ashik.ali |
609 |
@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
|
| 23786 |
amit.gupta |
610 |
public String expireSchemeById(HttpServletRequest request,
|
|
|
611 |
@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
|
| 25069 |
amit.gupta |
612 |
@RequestParam(name = ProfitMandiConstants.EXPIRE_TIMESTAMP) LocalDateTime expiryTimestamp,
|
| 23786 |
amit.gupta |
613 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
614 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
615 |
throws ProfitMandiBusinessException {
|
| 28924 |
amit.gupta |
616 |
expiryTimestamp = LocalDateTime.of(expiryTimestamp.toLocalDate(), Utils.MAX_TIME);
|
| 25069 |
amit.gupta |
617 |
schemeService.expireSchemeById(schemeId, expiryTimestamp);
|
| 22860 |
ashik.ali |
618 |
List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
|
|
|
619 |
model.addAttribute("schemes", schemes);
|
|
|
620 |
return "schemes-paginated";
|
|
|
621 |
}
|
| 23786 |
amit.gupta |
622 |
|
| 23784 |
ashik.ali |
623 |
@RequestMapping(value = "/getSchemesJson", method = RequestMethod.GET)
|
| 23786 |
amit.gupta |
624 |
public ResponseEntity<?> getSchemesJson(HttpServletRequest request,
|
|
|
625 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
626 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
627 |
throws ProfitMandiBusinessException {
|
| 23784 |
ashik.ali |
628 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
629 |
return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
|
|
|
630 |
}
|
| 26802 |
tejbeer |
631 |
|
| 26763 |
tejbeer |
632 |
@RequestMapping(value = "/searchSchemeByCategory")
|
|
|
633 |
public String getSchemeByCategory(HttpServletRequest request,
|
|
|
634 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
635 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
636 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
637 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
638 |
@RequestParam(name = "category", required = true, defaultValue = "") PartnerType category, Model model)
|
|
|
639 |
throws ProfitMandiBusinessException {
|
|
|
640 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
641 |
List<Scheme> schemes = null;
|
|
|
642 |
long size = 0;
|
| 26802 |
tejbeer |
643 |
|
|
|
644 |
schemes = schemeRepository.selectByPartnerType(category, offset, limit);
|
|
|
645 |
|
|
|
646 |
if (!(schemes.size() == 0)) {
|
|
|
647 |
size = schemeRepository.selectAllCount();
|
|
|
648 |
LOGGER.info("schemes" + schemes);
|
|
|
649 |
model.addAttribute("schemes", schemes);
|
|
|
650 |
model.addAttribute("start", offset + 1);
|
|
|
651 |
model.addAttribute("size", size);
|
|
|
652 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
653 |
model.addAttribute("searchItem", searchItem);
|
|
|
654 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
|
|
655 |
if (schemes.size() < limit) {
|
|
|
656 |
model.addAttribute("end", offset + schemes.size());
|
|
|
657 |
} else {
|
|
|
658 |
model.addAttribute("end", offset + limit);
|
| 26763 |
tejbeer |
659 |
}
|
| 26802 |
tejbeer |
660 |
}
|
|
|
661 |
|
| 26763 |
tejbeer |
662 |
return "schemes";
|
|
|
663 |
}
|
| 26802 |
tejbeer |
664 |
|
| 26763 |
tejbeer |
665 |
@RequestMapping(value = "/getSchemeByCategoryPaginated")
|
|
|
666 |
public String getSchemeByCategoryPaginated(HttpServletRequest request,
|
|
|
667 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
668 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
669 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
|
|
|
670 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
671 |
@RequestParam(name = "category", required = true, defaultValue = "") PartnerType category, Model model)
|
|
|
672 |
throws ProfitMandiBusinessException {
|
|
|
673 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
674 |
LOGGER.info("In search Item....");
|
|
|
675 |
List<Scheme> schemes = null;
|
| 26802 |
tejbeer |
676 |
|
| 26763 |
tejbeer |
677 |
schemes = schemeRepository.selectByPartnerType(category, offset, limit);
|
| 23506 |
amit.gupta |
678 |
|
| 26763 |
tejbeer |
679 |
model.addAttribute("schemes", schemes);
|
|
|
680 |
model.addAttribute("searchItem", searchItem);
|
|
|
681 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
|
|
682 |
return "schemes-paginated";
|
|
|
683 |
}
|
|
|
684 |
|
| 23752 |
govind |
685 |
@RequestMapping(value = "/searchScheme")
|
|
|
686 |
public String getSchemeBySchemeId(HttpServletRequest request,
|
|
|
687 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
688 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
689 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
|
|
|
690 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
|
|
|
691 |
throws ProfitMandiBusinessException {
|
|
|
692 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
693 |
List<Scheme> schemes = null;
|
|
|
694 |
long size = 0;
|
|
|
695 |
if (!(searchTerm.equals("")) && searchItem.equals("")) {
|
|
|
696 |
schemes = schemeRepository.selectBySearchTerm(searchTerm, offset, limit);
|
| 23786 |
amit.gupta |
697 |
if (!(schemes.size() == 0)) {
|
|
|
698 |
size = schemeRepository.selectAllCount();
|
|
|
699 |
LOGGER.info("schemes" + schemes);
|
|
|
700 |
model.addAttribute("schemes", schemes);
|
|
|
701 |
model.addAttribute("start", offset + 1);
|
|
|
702 |
model.addAttribute("size", size);
|
|
|
703 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
704 |
model.addAttribute("searchItem", searchItem);
|
| 23914 |
govind |
705 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23786 |
amit.gupta |
706 |
if (schemes.size() < limit) {
|
|
|
707 |
model.addAttribute("end", offset + schemes.size());
|
|
|
708 |
} else {
|
|
|
709 |
model.addAttribute("end", offset + limit);
|
|
|
710 |
}
|
| 23752 |
govind |
711 |
} else {
|
| 23786 |
amit.gupta |
712 |
throw new ProfitMandiBusinessException("SchemeId", searchTerm, "SchemeId Not Found");
|
| 23752 |
govind |
713 |
}
|
|
|
714 |
} else if (!(searchItem.equals("")) && searchTerm.equals("")) {
|
|
|
715 |
List<Integer> schemeIds = schemeItemRepository.selectSchemeIdByItemId(Integer.parseInt(searchItem));
|
| 23786 |
amit.gupta |
716 |
if (!(schemeIds.size() == 0)) {
|
| 23752 |
govind |
717 |
LOGGER.info("schemeIds in searchItemScheme" + schemeIds);
|
|
|
718 |
schemes = schemeRepository.selectBySchemeIds(schemeIds, offset, limit);
|
|
|
719 |
size = schemeIds.size();
|
|
|
720 |
LOGGER.info("Size" + size);
|
|
|
721 |
model.addAttribute("schemes", schemes);
|
|
|
722 |
model.addAttribute("start", offset + 1);
|
|
|
723 |
model.addAttribute("size", size);
|
|
|
724 |
model.addAttribute("searchItem", searchItem);
|
|
|
725 |
model.addAttribute("searchTerm", searchTerm);
|
| 23914 |
govind |
726 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23752 |
govind |
727 |
if (schemes.size() < limit) {
|
|
|
728 |
model.addAttribute("end", offset + schemes.size());
|
|
|
729 |
} else {
|
|
|
730 |
model.addAttribute("end", offset + limit);
|
|
|
731 |
}
|
|
|
732 |
|
|
|
733 |
} else {
|
|
|
734 |
throw new ProfitMandiBusinessException("SchemeIds", searchItem, "SchemeId Not Found");
|
|
|
735 |
}
|
|
|
736 |
} else {
|
| 23798 |
amit.gupta |
737 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 23752 |
govind |
738 |
schemes = schemeRepository.selectAll(offset, limit);
|
|
|
739 |
size = schemeRepository.selectAllCount();
|
|
|
740 |
} else {
|
|
|
741 |
schemes = schemeRepository.selectActiveAll(offset, limit);
|
|
|
742 |
size = schemeRepository.selectAllActiveCount();
|
|
|
743 |
}
|
|
|
744 |
model.addAttribute("schemes", schemes);
|
|
|
745 |
model.addAttribute("start", offset + 1);
|
|
|
746 |
model.addAttribute("size", size);
|
|
|
747 |
model.addAttribute("searchItem", searchItem);
|
|
|
748 |
model.addAttribute("searchTerm", searchTerm);
|
| 23914 |
govind |
749 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23752 |
govind |
750 |
if (schemes.size() < limit) {
|
|
|
751 |
model.addAttribute("end", offset + schemes.size());
|
|
|
752 |
} else {
|
|
|
753 |
model.addAttribute("end", offset + limit);
|
|
|
754 |
}
|
|
|
755 |
}
|
|
|
756 |
return "schemes";
|
|
|
757 |
}
|
|
|
758 |
|
|
|
759 |
@RequestMapping(value = "/searchItemSchemePanigated")
|
|
|
760 |
public String getSchemeByItemPanigated(HttpServletRequest request,
|
|
|
761 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
762 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
763 |
@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
|
|
|
764 |
throws ProfitMandiBusinessException {
|
| 23914 |
govind |
765 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23752 |
govind |
766 |
LOGGER.info("In search Item....");
|
|
|
767 |
List<Scheme> schemes = null;
|
|
|
768 |
if (!searchItem.equals("")) {
|
|
|
769 |
List<Integer> schemeIds = schemeItemRepository.selectSchemeIdByItemId(Integer.parseInt(searchItem));
|
|
|
770 |
if (schemeIds != null) {
|
|
|
771 |
LOGGER.info(schemeIds);
|
|
|
772 |
schemes = schemeRepository.selectBySchemeIds(schemeIds, offset, limit);
|
|
|
773 |
|
|
|
774 |
}
|
|
|
775 |
}
|
|
|
776 |
model.addAttribute("schemes", schemes);
|
|
|
777 |
model.addAttribute("searchItem", searchItem);
|
| 23914 |
govind |
778 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23752 |
govind |
779 |
return "schemes-paginated";
|
|
|
780 |
|
|
|
781 |
}
|
| 22860 |
ashik.ali |
782 |
}
|