| Line 39... |
Line 39... |
| 39 |
import org.springframework.web.bind.annotation.RequestParam;
|
39 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 40 |
|
40 |
|
| 41 |
import com.mongodb.DBObject;
|
41 |
import com.mongodb.DBObject;
|
| 42 |
import com.spice.profitmandi.common.enumuration.CounterSize;
|
42 |
import com.spice.profitmandi.common.enumuration.CounterSize;
|
| 43 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
43 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 44 |
import com.spice.profitmandi.common.model.BrandStockPrice;
|
- |
|
| 45 |
import com.spice.profitmandi.common.model.CatalogIdAggregateValue;
|
44 |
import com.spice.profitmandi.common.model.CatalogIdAggregateValue;
|
| 46 |
import com.spice.profitmandi.common.model.CatalogListingModel;
|
45 |
import com.spice.profitmandi.common.model.CatalogListingModel;
|
| 47 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
46 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 48 |
import com.spice.profitmandi.common.model.ItemIdAvailability;
|
- |
|
| 49 |
import com.spice.profitmandi.common.model.PlannedModel;
|
47 |
import com.spice.profitmandi.common.model.PlannedModel;
|
| 50 |
import com.spice.profitmandi.common.model.StockAllocationModel;
|
48 |
import com.spice.profitmandi.common.model.StockAllocationModel;
|
| 51 |
import com.spice.profitmandi.common.util.FileUtil;
|
49 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 52 |
import com.spice.profitmandi.common.util.Utils;
|
50 |
import com.spice.profitmandi.common.util.Utils;
|
| 53 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
51 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
| Line 453... |
Line 451... |
| 453 |
Set<Integer> roleIds = loginDetails.getRoleIds();
|
451 |
Set<Integer> roleIds = loginDetails.getRoleIds();
|
| 454 |
LOGGER.info("Counter size is {}", counterSize);
|
452 |
LOGGER.info("Counter size is {}", counterSize);
|
| 455 |
LOGGER.info("Fofo Id is {}", fofoId);
|
453 |
LOGGER.info("Fofo Id is {}", fofoId);
|
| 456 |
boolean isAdmin = roleManager.isAdmin(roleIds);
|
454 |
boolean isAdmin = roleManager.isAdmin(roleIds);
|
| 457 |
|
455 |
|
| - |
|
456 |
List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
| - |
|
457 |
.collect(Collectors.toList());
|
| - |
|
458 |
|
| 458 |
Map<String, Object> equalsMap = new HashMap<>();
|
459 |
Map<String, Object> equalsMap = new HashMap<>();
|
| 459 |
equalsMap.put("categoryId", 10006);
|
460 |
equalsMap.put("categoryId", 10006);
|
| 460 |
|
- |
|
| - |
|
461 |
equalsMap.put("brand", brands);
|
| 461 |
Map<String, List<?>> notEqualsMap = new HashMap<>();
|
462 |
Map<String, List<?>> notEqualsMap = new HashMap<>();
|
| 462 |
|
463 |
|
| 463 |
Map<String, List<?>> notEqualsJoinMap = new HashMap<>();
|
464 |
Map<String, List<?>> notEqualsJoinMap = new HashMap<>();
|
| 464 |
Map<Integer, Integer> currentStockMap;
|
465 |
Map<Integer, Integer> currentStockMap;
|
| 465 |
|
466 |
|
| Line 469... |
Line 470... |
| 469 |
equalsStockJoinMap.put("fofoId", fofoId);
|
470 |
equalsStockJoinMap.put("fofoId", fofoId);
|
| 470 |
currentStockMap = itemRepository
|
471 |
currentStockMap = itemRepository
|
| 471 |
.selectItems(CurrentInventorySnapshot.class, "itemId", equalsMap, notEqualsMap, equalsStockJoinMap,
|
472 |
.selectItems(CurrentInventorySnapshot.class, "itemId", equalsMap, notEqualsMap, equalsStockJoinMap,
|
| 472 |
notEqualsJoinMap, "availability")
|
473 |
notEqualsJoinMap, "availability")
|
| 473 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
474 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
| 474 |
|
- |
|
| - |
|
475 |
LOGGER.info("currentStock");
|
| 475 |
} else {
|
476 |
} else {
|
| 476 |
if (fofoId == 0) {
|
477 |
if (fofoId == 0) {
|
| 477 |
|
478 |
|
| 478 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
479 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
| 479 |
equalsStockJoinMap.put("fofoId", fofoId);
|
480 |
equalsStockJoinMap.put("fofoId", fofoId);
|
| Line 495... |
Line 496... |
| 495 |
|
496 |
|
| 496 |
}
|
497 |
}
|
| 497 |
}
|
498 |
}
|
| 498 |
|
499 |
|
| 499 |
LOGGER.info("currentStock" + currentStockMap);
|
500 |
LOGGER.info("currentStock" + currentStockMap);
|
| 500 |
List<StockAllocationModel> stockAllocationList;
|
- |
|
| 501 |
if (fofoId > 0) {
|
- |
|
| 502 |
stockAllocationList = stockAllocationService.getStockAllocation(fofoId, true);
|
- |
|
| 503 |
} else {
|
- |
|
| 504 |
stockAllocationList = stockAllocationService.getStockAllocation(counterSize, true);
|
- |
|
| 505 |
}
|
- |
|
| 506 |
Map<Integer, StockAllocationModel> itemStockAllocationMap = stockAllocationList.stream()
|
- |
|
| 507 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
|
- |
|
| 508 |
Map<Integer, Integer> itemsInTransit = null;
|
- |
|
| 509 |
|
501 |
|
| - |
|
502 |
Map<Integer, Integer> itemsInTransit = null;
|
| 510 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
503 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
| 511 |
if (!isAdmin) {
|
504 |
if (!isAdmin) {
|
| 512 |
tagListings = new ArrayList<>(tagListings);
|
505 |
tagListings = new ArrayList<>(tagListings);
|
| 513 |
List<Order> inTransitOrders = orderRepository.selectOrders(fofoId, validOrderStatusList);
|
506 |
List<Order> inTransitOrders = orderRepository.selectPendingGrnOrder(fofoId, validOrderStatusList);
|
| 514 |
inTransitOrders = this.filterValidOrders(inTransitOrders);
|
507 |
inTransitOrders = this.filterValidOrders(inTransitOrders);
|
| 515 |
itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
508 |
itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
| 516 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
509 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
| 517 |
} else {
|
510 |
} else {
|
| 518 |
itemsInTransit = new HashMap<>();
|
511 |
itemsInTransit = new HashMap<>();
|
| 519 |
}
|
512 |
}
|
| 520 |
Iterator<TagListing> iterator = tagListings.iterator();
|
- |
|
| - |
|
513 |
|
| 521 |
int totalPcs = 0;
|
514 |
int totalPcs = 0;
|
| 522 |
int toBeOrdered = 0;
|
- |
|
| - |
|
515 |
|
| 523 |
float totalAmount = 0;
|
516 |
float totalAmount = 0;
|
| 524 |
Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
|
517 |
Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
|
| 525 |
|
518 |
|
| 526 |
Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAll().stream()
|
519 |
Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAll().stream()
|
| 527 |
.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
|
520 |
.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
|
| 528 |
|
521 |
|
| 529 |
MonthlyPlanned monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(loginDetails.getFofoId(),
|
522 |
MonthlyPlanned monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(loginDetails.getFofoId(),
|
| 530 |
LocalDate.now().withDayOfMonth(1));
|
523 |
LocalDate.now().withDayOfMonth(1));
|
| - |
|
524 |
LOGGER.info("monthlyPlanned" + monthlyPlanned);
|
| 531 |
Map<Integer, Integer> plannedDetailMap = null;
|
525 |
Map<Integer, Integer> plannedDetailMap = null;
|
| 532 |
if (monthlyPlanned != null) {
|
526 |
if (monthlyPlanned != null) {
|
| 533 |
plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
|
527 |
plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
|
| 534 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
|
528 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
|
| 535 |
|
529 |
|
| 536 |
}
|
530 |
}
|
| 537 |
|
- |
|
| - |
|
531 |
LOGGER.info("plannedDetailMap" + plannedDetailMap);
|
| 538 |
List<Integer> fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
|
532 |
List<Integer> fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
|
| 539 |
LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
|
533 |
LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
|
| 540 |
.collect(Collectors.toList());
|
534 |
.collect(Collectors.toList());
|
| 541 |
LOGGER.info("fofoOrderIds" + fofoOrderIds);
|
535 |
LOGGER.info("fofoOrderIds" + fofoOrderIds);
|
| 542 |
Map<String, Object> equalsJoinMap = new HashMap<>();
|
536 |
Map<String, Object> equalsJoinMap = new HashMap<>();
|
| Line 544... |
Line 538... |
| 544 |
|
538 |
|
| 545 |
Map<Integer, Integer> last15daysMap = itemRepository
|
539 |
Map<Integer, Integer> last15daysMap = itemRepository
|
| 546 |
.selectItems(FofoOrderItem.class, "itemId", equalsMap, notEqualsMap, equalsJoinMap, notEqualsJoinMap,
|
540 |
.selectItems(FofoOrderItem.class, "itemId", equalsMap, notEqualsMap, equalsJoinMap, notEqualsJoinMap,
|
| 547 |
"quantity")
|
541 |
"quantity")
|
| 548 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
542 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
| 549 |
|
- |
|
| - |
|
543 |
LOGGER.info("last15daysMap");
|
| 550 |
LOGGER.info("last15daysMap" + last15daysMap);
|
544 |
LOGGER.info("last15daysMap" + last15daysMap);
|
| 551 |
|
545 |
|
| 552 |
Map<Integer, TagListing> taglistingMap = tagListings.stream()
|
546 |
Map<Integer, TagListing> taglistingMap = tagListings.stream()
|
| 553 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
547 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 554 |
List<Item> items = itemRepository.selectByIds(taglistingMap.keySet());
|
548 |
List<Item> items = itemRepository.selectByIds(taglistingMap.keySet());
|
| 555 |
Map<Integer, List<Item>> catalogIdItemMap = items.stream().collect(
|
549 |
Map<Integer, List<Item>> catalogIdItemMap = items.stream().collect(
|
| 556 |
Collectors.groupingBy(x -> x.getCatalogItemId(), Collectors.mapping(y -> y, Collectors.toList())));
|
550 |
Collectors.groupingBy(x -> x.getCatalogItemId(), Collectors.mapping(y -> y, Collectors.toList())));
|
| - |
|
551 |
LOGGER.info("catalogIdItemMap");
|
| 557 |
|
552 |
|
| 558 |
LOGGER.info("itemId" + new ArrayList<>(taglistingMap.keySet()));
|
- |
|
| 559 |
Map<String, Object> equalsItemJoinMap = new HashMap<>();
|
553 |
Map<String, Object> equalsItemJoinMap = new HashMap<>();
|
| 560 |
equalsItemJoinMap.put("itemId", new ArrayList<>(taglistingMap.keySet()));
|
554 |
equalsItemJoinMap.put("active", 1);
|
| 561 |
|
- |
|
| 562 |
List<CatalogIdAggregateValue> tagListingCatalogIds = itemRepository.selectItems(TagListing.class, "itemId",
|
555 |
List<CatalogIdAggregateValue> tagListingCatalogIds = itemRepository.selectItems(TagListing.class, "itemId",
|
| 563 |
equalsMap, notEqualsMap, equalsItemJoinMap, notEqualsJoinMap, "tagId");
|
556 |
equalsMap, notEqualsMap, equalsItemJoinMap, notEqualsJoinMap, "tagId");
|
| 564 |
|
- |
|
| - |
|
557 |
LOGGER.info("tagListingCatalogIds");
|
| 565 |
for (CatalogIdAggregateValue catalogIdAggregateValue : tagListingCatalogIds) {
|
558 |
for (CatalogIdAggregateValue catalogIdAggregateValue : tagListingCatalogIds) {
|
| 566 |
int catalogId = catalogIdAggregateValue.getCatalogId();
|
559 |
int catalogId = catalogIdAggregateValue.getCatalogId();
|
| 567 |
Item item = catalogIdItemMap.get(catalogId).get(0);
|
560 |
Item item = catalogIdItemMap.get(catalogId).get(0);
|
| 568 |
TagListing tagListing = taglistingMap.get(item.getId());
|
561 |
TagListing tagListing = taglistingMap.get(item.getId());
|
| 569 |
CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
|
562 |
CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
|
| Line 571... |
Line 564... |
| 571 |
catalogListingModel = new CatalogListingModel();
|
564 |
catalogListingModel = new CatalogListingModel();
|
| 572 |
catalogListingModel.setCatalogId(catalogId);
|
565 |
catalogListingModel.setCatalogId(catalogId);
|
| 573 |
catalogListingModel.setDp(tagListing.getSellingPrice());
|
566 |
catalogListingModel.setDp(tagListing.getSellingPrice());
|
| 574 |
catalogListingModel.setMop(tagListing.getMop());
|
567 |
catalogListingModel.setMop(tagListing.getMop());
|
| 575 |
catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
|
568 |
catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
|
| 576 |
StockAllocationModel stockAllocationModel = itemStockAllocationMap.get(item.getCatalogItemId());
|
- |
|
| 577 |
int stockAllocationQuantity = stockAllocationModel == null ? 0 : stockAllocationModel.getQuantity();
|
- |
|
| 578 |
if (plannedDetailMap != null) {
|
569 |
if (plannedDetailMap != null) {
|
| 579 |
|
570 |
|
| 580 |
Integer quantity = plannedDetailMap.get(catalogId);
|
571 |
Integer quantity = plannedDetailMap.get(catalogId);
|
| 581 |
if (quantity != null) {
|
572 |
if (quantity != null) {
|
| 582 |
catalogListingModel.setAllocatedQuantity(quantity);
|
573 |
catalogListingModel.setAllocatedQuantity(quantity);
|
| 583 |
} else {
|
- |
|
| 584 |
|
- |
|
| 585 |
catalogListingModel.setAllocatedQuantity(stockAllocationQuantity);
|
- |
|
| 586 |
}
|
574 |
}
|
| 587 |
} else {
|
- |
|
| 588 |
catalogListingModel.setAllocatedQuantity(stockAllocationQuantity);
|
- |
|
| 589 |
}
|
575 |
}
|
| 590 |
|
576 |
|
| 591 |
if (last15daysMap != null) {
|
577 |
if (last15daysMap != null) {
|
| 592 |
Integer last15DaysSale = last15daysMap.get(catalogId);
|
578 |
Integer last15DaysSale = last15daysMap.get(catalogId);
|
| 593 |
|
579 |
|
| Line 598... |
Line 584... |
| 598 |
}
|
584 |
}
|
| 599 |
} else {
|
585 |
} else {
|
| 600 |
catalogListingModel.setLast15DaysSale(0);
|
586 |
catalogListingModel.setLast15DaysSale(0);
|
| 601 |
}
|
587 |
}
|
| 602 |
|
588 |
|
| 603 |
catalogListingModel.setToBeOrdered(stockAllocationQuantity);
|
- |
|
| 604 |
catalogListingModel.setBrand(item.getBrand());
|
589 |
catalogListingModel.setBrand(item.getBrand());
|
| 605 |
if (item.getCategoryId() == 10006) {
|
590 |
if (item.getCategoryId() == 10006) {
|
| 606 |
catalogListingModel.setCategoryId(item.getCategoryId());
|
591 |
catalogListingModel.setCategoryId(item.getCategoryId());
|
| 607 |
}
|
592 |
}
|
| 608 |
|
593 |
|