| Line 170... |
Line 170... |
| 170 |
|
170 |
|
| 171 |
@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
|
171 |
@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
|
| 172 |
public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
|
172 |
public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
|
| 173 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
173 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
| 174 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
|
174 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
|
| 175 |
Set<Integer> roleIds = cookiesProcessor.getCookiesObject(request).getRoleIds();
|
175 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
176 |
Set<Integer> roleIds = loginDetails.getRoleIds();
|
| 176 |
LOGGER.info("Counter size is {}", counterSize);
|
177 |
LOGGER.info("Counter size is {}", counterSize);
|
| 177 |
LOGGER.info("Fofo Id is {}", fofoId);
|
178 |
LOGGER.info("Fofo Id is {}", fofoId);
|
| 178 |
if (roleManager.isAdmin(roleIds)) {
|
179 |
if (roleManager.isAdmin(roleIds) || loginDetails.getFofoId()==fofoId) {
|
| 179 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
180 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
| 180 |
.collect(Collectors.toList());
|
181 |
.collect(Collectors.toList());
|
| 181 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
182 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
| 182 |
|
183 |
|
| 183 |
List<StockAllocationModel> stockAllocationList = stockAllocationService.getStockAllocation(counterSize,
|
184 |
List<StockAllocationModel> stockAllocationList = stockAllocationService.getStockAllocation(counterSize,
|
| 184 |
true);
|
185 |
true);
|
| 185 |
Map<Integer, Integer> modelStockAllocationMap = stockAllocationList.stream()
|
186 |
Map<Integer, Integer> modelStockAllocationMap = stockAllocationList.stream()
|
| 186 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
|
187 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
|
| 187 |
|
188 |
|
| 188 |
Map<String, Integer> catalogUserQtyMap = new HashMap<>();
|
189 |
Map<String, Integer> catalogUserQtyMap = new HashMap<>();
|
| 189 |
currentInventorySnapshotRepository.selectAll(Optional.of(true)).stream().forEach(x -> {
|
190 |
currentInventorySnapshotRepository.selectByFofoId(fofoId).stream().forEach(x -> {
|
| 190 |
int retailerId = x.getFofoId();
|
191 |
int retailerId = x.getFofoId();
|
| 191 |
int catalogId;
|
192 |
int catalogId;
|
| 192 |
try {
|
193 |
try {
|
| 193 |
catalogId = itemRepository.selectById(x.getItemId()).getCatalogItemId();
|
194 |
catalogId = itemRepository.selectById(x.getItemId()).getCatalogItemId();
|
| 194 |
String key = catalogId + "-" + retailerId;
|
195 |
String key = catalogId + "-" + retailerId;
|
| Line 308... |
Line 309... |
| 308 |
|
309 |
|
| 309 |
@RequestMapping(value = "/indent/loadIndent")
|
310 |
@RequestMapping(value = "/indent/loadIndent")
|
| 310 |
public String loadOpenIndent(HttpServletRequest request, Model model,
|
311 |
public String loadOpenIndent(HttpServletRequest request, Model model,
|
| 311 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
312 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
| 312 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws ProfitMandiBusinessException {
|
313 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws ProfitMandiBusinessException {
|
| - |
|
314 |
|
| 313 |
Set<Integer> roleIds = cookiesProcessor.getCookiesObject(request).getRoleIds();
|
315 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
316 |
Set<Integer> roleIds = loginDetails.getRoleIds();
|
| 314 |
LOGGER.info("Counter size is {}", counterSize);
|
317 |
LOGGER.info("Counter size is {}", counterSize);
|
| 315 |
LOGGER.info("Fofo Id is {}", fofoId);
|
318 |
LOGGER.info("Fofo Id is {}", fofoId);
|
| 316 |
|
- |
|
| - |
|
319 |
boolean isAdmin = !roleManager.isAdmin(roleIds);
|
| 317 |
Map<Integer, ItemIdAvailability> itemCisMap = null;
|
320 |
Map<Integer, ItemIdAvailability> itemCisMap = null;
|
| 318 |
if (!roleManager.isAdmin(roleIds)) {
|
321 |
if (!isAdmin && fofoId==0) {
|
| 319 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
322 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
| 320 |
List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
|
323 |
List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
|
| 321 |
.selectItemsStock(fofoId);
|
324 |
.selectItemsStock(fofoId);
|
| 322 |
itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
|
325 |
itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
|
| 323 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
326 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| Line 332... |
Line 335... |
| 332 |
.selectItemsStock(fofoId);
|
335 |
.selectItemsStock(fofoId);
|
| 333 |
itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
|
336 |
itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
|
| 334 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
337 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 335 |
}
|
338 |
}
|
| 336 |
}
|
339 |
}
|
| 337 |
List<BrandPerformance> brandPerformanceList = new ArrayList<>();
|
- |
|
| 338 |
List<BrandPerformance> accsBrandPerformanceList = new ArrayList<>();
|
- |
|
| - |
|
340 |
|
| 339 |
List<StockAllocationModel> stockAllocationList;
|
341 |
List<StockAllocationModel> stockAllocationList;
|
| 340 |
if (fofoId > 0) {
|
342 |
if (fofoId > 0) {
|
| 341 |
stockAllocationList = stockAllocationService.getStockAllocation(fofoId, true);
|
343 |
stockAllocationList = stockAllocationService.getStockAllocation(fofoId, true);
|
| 342 |
} else {
|
344 |
} else {
|
| 343 |
stockAllocationList = stockAllocationService.getStockAllocation(counterSize, true);
|
345 |
stockAllocationList = stockAllocationService.getStockAllocation(counterSize, true);
|
| Line 347... |
Line 349... |
| 347 |
Map<Integer, StockAllocationModel> itemStockAllocationMap = stockAllocationList.stream()
|
349 |
Map<Integer, StockAllocationModel> itemStockAllocationMap = stockAllocationList.stream()
|
| 348 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
|
350 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
|
| 349 |
Map<Integer, Integer> itemsInTransit = null;
|
351 |
Map<Integer, Integer> itemsInTransit = null;
|
| 350 |
LOGGER.info("Item Stock Allocation Model Map {}", itemStockAllocationMap);
|
352 |
LOGGER.info("Item Stock Allocation Model Map {}", itemStockAllocationMap);
|
| 351 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
353 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
| 352 |
if (!roleManager.isAdmin(roleIds)) {
|
354 |
if (!isAdmin) {
|
| 353 |
tagListings = new ArrayList<>(tagListings);
|
355 |
tagListings = new ArrayList<>(tagListings);
|
| 354 |
List<Order> inTransitOrders = orderRepository.selectOrders(fofoId, validOrderStatusList);
|
356 |
List<Order> inTransitOrders = orderRepository.selectOrders(fofoId, validOrderStatusList);
|
| 355 |
inTransitOrders = this.filterValidOrders(inTransitOrders);
|
357 |
inTransitOrders = this.filterValidOrders(inTransitOrders);
|
| 356 |
itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
358 |
itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
| 357 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
359 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
| Line 361... |
Line 363... |
| 361 |
Iterator<TagListing> iterator = tagListings.iterator();
|
363 |
Iterator<TagListing> iterator = tagListings.iterator();
|
| 362 |
int totalPcs = 0;
|
364 |
int totalPcs = 0;
|
| 363 |
int toBeOrdered = 0;
|
365 |
int toBeOrdered = 0;
|
| 364 |
float totalAmount = 0;
|
366 |
float totalAmount = 0;
|
| 365 |
Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
|
367 |
Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
|
| - |
|
368 |
|
| - |
|
369 |
Map<Integer, Item> items = itemRepository.selectByIds(tagListings.stream().map(x->x.getItemId()).collect(Collectors.toSet())).stream().
|
| - |
|
370 |
collect(Collectors.toMap(x->x.getId(), x->x));
|
| 366 |
while (iterator.hasNext()) {
|
371 |
while (iterator.hasNext()) {
|
| 367 |
TagListing tagListing = iterator.next();
|
372 |
TagListing tagListing = iterator.next();
|
| 368 |
|
373 |
|
| 369 |
Item item = itemRepository.selectById(tagListing.getItemId());
|
374 |
Item item = items.get(tagListing.getItemId());
|
| 370 |
// itemRepository.select
|
375 |
// itemRepository.select
|
| 371 |
// catalogTagListingMap
|
376 |
// catalogTagListingMap
|
| 372 |
if (roleManager.isAdmin(roleIds)) {
|
377 |
if (isAdmin) {
|
| 373 |
if (item.getBrand() == null || item.getCategoryId() != 10006) {
|
378 |
if (item.getBrand() == null || item.getCategoryId() != 10006) {
|
| 374 |
iterator.remove();
|
379 |
iterator.remove();
|
| 375 |
continue;
|
380 |
continue;
|
| 376 |
}
|
381 |
}
|
| 377 |
} else {
|
382 |
} else {
|
| Line 412... |
Line 417... |
| 412 |
if (catalogListingModel.getAllocatedQuantity() > 0) {
|
417 |
if (catalogListingModel.getAllocatedQuantity() > 0) {
|
| 413 |
toBeOrdered = Math.max(catalogListingModel.getToBeOrdered() - inTransitQty - itemAvailability, 0);
|
418 |
toBeOrdered = Math.max(catalogListingModel.getToBeOrdered() - inTransitQty - itemAvailability, 0);
|
| 414 |
catalogListingModel.setToBeOrdered(toBeOrdered);
|
419 |
catalogListingModel.setToBeOrdered(toBeOrdered);
|
| 415 |
}
|
420 |
}
|
| 416 |
}
|
421 |
}
|
| 417 |
List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
|
- |
|
| 418 |
|
- |
|
| 419 |
Map<Boolean, List<CatalogListingModel>> performanceMap = catalogModelList.stream()
|
- |
|
| 420 |
.collect(Collectors.groupingBy(x -> x.getCategoryId() == 10006));
|
- |
|
| 421 |
List<CatalogListingModel> mobileListing = performanceMap.get(true) == null ? new ArrayList<>()
|
- |
|
| 422 |
: performanceMap.get(true);
|
- |
|
| 423 |
List<CatalogListingModel> accsListing = performanceMap.get(false) == null ? new ArrayList<>()
|
- |
|
| 424 |
: performanceMap.get(false);
|
- |
|
| 425 |
|
- |
|
| 426 |
Map<String, DoubleSummaryStatistics> accsStats = accsListing.stream().collect(Collectors.groupingBy(
|
- |
|
| 427 |
x -> x.getBrand(), Collectors.summarizingDouble(x -> x.getAllocatedQuantity() * x.getMop())));
|
- |
|
| 428 |
Map<String, DoubleSummaryStatistics> mobStats = mobileListing.stream().collect(Collectors.groupingBy(
|
- |
|
| 429 |
x -> x.getBrand(), Collectors.summarizingDouble(x -> x.getAllocatedQuantity() * x.getMop())));
|
- |
|
| 430 |
|
- |
|
| 431 |
for (Map.Entry<String, DoubleSummaryStatistics> entry : mobStats.entrySet()) {
|
- |
|
| 432 |
DoubleSummaryStatistics dss = entry.getValue();
|
- |
|
| 433 |
BrandPerformance bp = new BrandPerformance();
|
- |
|
| 434 |
bp.setTarget((float) dss.getSum());
|
- |
|
| 435 |
bp.setBrandName(entry.getKey());
|
- |
|
| 436 |
brandPerformanceList.add(bp);
|
- |
|
| 437 |
}
|
422 |
|
| 438 |
for (Map.Entry<String, DoubleSummaryStatistics> entry : accsStats.entrySet()) {
|
- |
|
| 439 |
DoubleSummaryStatistics dss = entry.getValue();
|
- |
|
| 440 |
BrandPerformance bp = new BrandPerformance();
|
- |
|
| 441 |
bp.setTarget((float) dss.getSum());
|
- |
|
| 442 |
bp.setBrandName(entry.getKey());
|
- |
|
| 443 |
accsBrandPerformanceList.add(bp);
|
- |
|
| 444 |
}
|
- |
|
| 445 |
brandPerformanceList = brandPerformanceList.stream().filter(x -> x.getTarget() > 0)
|
- |
|
| 446 |
.sorted(Comparator.comparing(x -> x.getTarget())).collect(Collectors.toList());
|
- |
|
| 447 |
accsBrandPerformanceList = accsBrandPerformanceList.stream().filter(x -> x.getTarget() > 0)
|
- |
|
| 448 |
.sorted(Comparator.comparing(x -> x.getTarget())).collect(Collectors.toList());
|
- |
|
| 449 |
|
- |
|
| 450 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
- |
|
| 451 |
.collect(Collectors.toList());
|
- |
|
| 452 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
423 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers();
|
| 453 |
if (fofoId > 0) {
|
424 |
if (fofoId > 0) {
|
| 454 |
CustomRetailer customRetailer = customRetailersMap.get(fofoId);
|
425 |
CustomRetailer customRetailer = customRetailersMap.get(fofoId);
|
| 455 |
model.addAttribute("retailerName",
|
426 |
model.addAttribute("retailerName",
|
| 456 |
customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
|
427 |
customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
|
| 457 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
428 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
| Line 459... |
Line 430... |
| 459 |
model.addAttribute("counterSize", fs.getCounterSize().toString());
|
430 |
model.addAttribute("counterSize", fs.getCounterSize().toString());
|
| 460 |
} else {
|
431 |
} else {
|
| 461 |
model.addAttribute("counterSize", counterSize.toString());
|
432 |
model.addAttribute("counterSize", counterSize.toString());
|
| 462 |
}
|
433 |
}
|
| 463 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
434 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
| - |
|
435 |
|
| 464 |
LOGGER.info("Custom retailers {}", customRetailers);
|
436 |
List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
|
| 465 |
// Lits<CatalogTagListing> catalog
|
- |
|
| - |
|
437 |
|
| 466 |
Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getToBeOrdered,
|
438 |
Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getToBeOrdered,
|
| 467 |
Comparator.reverseOrder());
|
439 |
Comparator.reverseOrder());
|
| 468 |
model.addAttribute("catalogTagListings",
|
440 |
model.addAttribute("catalogTagListings",
|
| 469 |
catalogModelList.stream().sorted(firstCmp).collect(Collectors.toList()));
|
441 |
catalogModelList.stream().sorted(firstCmp).collect(Collectors.toList()));
|
| 470 |
model.addAttribute("customRetailers", customRetailers);
|
- |
|
| 471 |
model.addAttribute("brandPerformanceList", brandPerformanceList);
|
- |
|
| 472 |
model.addAttribute("accsBrandPerformanceList", accsBrandPerformanceList);
|
- |
|
| 473 |
model.addAttribute("counterSizes", CounterSize.values());
|
- |
|
| 474 |
model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
|
442 |
model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
|
| - |
|
443 |
model.addAttribute("customRetailers", customRetailers);
|
| 475 |
model.addAttribute("totalAmount", totalAmount);
|
444 |
model.addAttribute("totalAmount", totalAmount);
|
| 476 |
model.addAttribute("totalPcs", totalPcs);
|
445 |
model.addAttribute("totalPcs", totalPcs);
|
| 477 |
model.addAttribute("walletAmount", walletService.getWalletAmount(fofoId));
|
- |
|
| 478 |
// model.addAttribute("itemCisMap", itemCisMap);
|
- |
|
| 479 |
return "open-indent";
|
446 |
return "open-indent";
|
| 480 |
}
|
447 |
}
|
| 481 |
|
448 |
|
| 482 |
private List<Order> filterValidOrders(List<Order> lastOrdersList) {
|
449 |
private List<Order> filterValidOrders(List<Order> lastOrdersList) {
|
| 483 |
Iterator<Order> orderIterator = lastOrdersList.iterator();
|
450 |
Iterator<Order> orderIterator = lastOrdersList.iterator();
|