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