Subversion Repositories SmartDukaan

Rev

Rev 26748 | Rev 26853 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 26748 Rev 26846
Line 38... Line 38...
38
import org.springframework.web.bind.annotation.RequestMapping;
38
import org.springframework.web.bind.annotation.RequestMapping;
39
import org.springframework.web.bind.annotation.RequestMethod;
39
import org.springframework.web.bind.annotation.RequestMethod;
40
import org.springframework.web.bind.annotation.RequestParam;
40
import org.springframework.web.bind.annotation.RequestParam;
41
 
41
 
42
import com.mongodb.DBObject;
42
import com.mongodb.DBObject;
-
 
43
import com.mysql.fabric.xmlrpc.base.Array;
43
import com.spice.profitmandi.common.enumuration.CounterSize;
44
import com.spice.profitmandi.common.enumuration.CounterSize;
-
 
45
import com.spice.profitmandi.common.enumuration.MessageType;
44
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
46
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
45
import com.spice.profitmandi.common.model.BrandStockPrice;
47
import com.spice.profitmandi.common.model.BrandStockPrice;
46
import com.spice.profitmandi.common.model.CatalogIdAggregateValue;
48
import com.spice.profitmandi.common.model.CatalogIdAggregateValue;
47
import com.spice.profitmandi.common.model.CatalogListingModel;
49
import com.spice.profitmandi.common.model.CatalogListingModel;
48
import com.spice.profitmandi.common.model.CustomRetailer;
50
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
51
import com.spice.profitmandi.common.model.SuggestedPoIdModel;
-
 
52
import com.spice.profitmandi.common.model.SuggestedPoModel;
-
 
53
import com.spice.profitmandi.common.model.NotifyOrderModel;
49
import com.spice.profitmandi.common.model.PlannedModel;
54
import com.spice.profitmandi.common.model.PlannedModel;
-
 
55
import com.spice.profitmandi.common.model.SendNotificationModel;
50
import com.spice.profitmandi.common.model.StockAllocationModel;
56
import com.spice.profitmandi.common.model.StockAllocationModel;
51
import com.spice.profitmandi.common.util.FileUtil;
57
import com.spice.profitmandi.common.util.FileUtil;
52
import com.spice.profitmandi.common.util.Utils;
58
import com.spice.profitmandi.common.util.Utils;
53
import com.spice.profitmandi.common.util.Utils.Attachment;
59
import com.spice.profitmandi.common.util.Utils.Attachment;
54
import com.spice.profitmandi.dao.entity.auth.AuthUser;
60
import com.spice.profitmandi.dao.entity.auth.AuthUser;
Line 57... Line 63...
57
import com.spice.profitmandi.dao.entity.catalog.TagListing;
63
import com.spice.profitmandi.dao.entity.catalog.TagListing;
58
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
64
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
59
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
65
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
60
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
66
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
61
import com.spice.profitmandi.dao.entity.fofo.MonthlyPlanned;
67
import com.spice.profitmandi.dao.entity.fofo.MonthlyPlanned;
-
 
68
import com.spice.profitmandi.dao.entity.fofo.SuggestedPo;
-
 
69
import com.spice.profitmandi.dao.entity.fofo.SuggestedPoDetail;
62
import com.spice.profitmandi.dao.entity.fofo.PlannedDetail;
70
import com.spice.profitmandi.dao.entity.fofo.PlannedDetail;
63
import com.spice.profitmandi.dao.entity.transaction.Order;
71
import com.spice.profitmandi.dao.entity.transaction.Order;
-
 
72
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
64
import com.spice.profitmandi.dao.entity.user.User;
73
import com.spice.profitmandi.dao.entity.user.User;
65
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
74
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
66
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
75
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
67
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
76
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
68
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
77
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
69
import com.spice.profitmandi.dao.repository.cs.CsService;
78
import com.spice.profitmandi.dao.repository.cs.CsService;
70
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
79
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
71
import com.spice.profitmandi.dao.repository.dtr.Mongo;
80
import com.spice.profitmandi.dao.repository.dtr.Mongo;
-
 
81
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
72
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
82
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
73
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
83
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
74
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
84
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
75
import com.spice.profitmandi.dao.repository.fofo.MonthlyPlannedRepository;
85
import com.spice.profitmandi.dao.repository.fofo.MonthlyPlannedRepository;
-
 
86
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
-
 
87
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
76
import com.spice.profitmandi.dao.repository.fofo.PlannedDetailRepository;
88
import com.spice.profitmandi.dao.repository.fofo.PlannedDetailRepository;
77
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
89
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
78
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
90
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
79
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
91
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
80
import com.spice.profitmandi.dao.repository.user.UserRepository;
92
import com.spice.profitmandi.dao.repository.user.UserRepository;
-
 
93
import com.spice.profitmandi.service.NotificationService;
81
import com.spice.profitmandi.service.authentication.RoleManager;
94
import com.spice.profitmandi.service.authentication.RoleManager;
82
import com.spice.profitmandi.service.inventory.InventoryService;
95
import com.spice.profitmandi.service.inventory.InventoryService;
83
import com.spice.profitmandi.service.inventory.StockAllocationService;
96
import com.spice.profitmandi.service.inventory.StockAllocationService;
84
import com.spice.profitmandi.service.user.RetailerService;
97
import com.spice.profitmandi.service.user.RetailerService;
85
import com.spice.profitmandi.service.wallet.WalletService;
98
import com.spice.profitmandi.service.wallet.WalletService;
Line 143... Line 156...
143
 
156
 
144
	@Autowired
157
	@Autowired
145
	private OrderRepository orderRepository;
158
	private OrderRepository orderRepository;
146
 
159
 
147
	@Autowired
160
	@Autowired
-
 
161
	private UserAccountRepository userAccountRepository;
-
 
162
 
-
 
163
	@Autowired
148
	private ItemRepository itemRepository;
164
	private ItemRepository itemRepository;
149
 
165
 
150
	@Autowired
166
	@Autowired
151
	private StockAllocationService stockAllocationService;
167
	private StockAllocationService stockAllocationService;
152
 
168
 
Line 193... Line 209...
193
	private CsService csService;
209
	private CsService csService;
194
 
210
 
195
	@Autowired
211
	@Autowired
196
	private AuthRepository authRepository;
212
	private AuthRepository authRepository;
197
 
213
 
-
 
214
	@Autowired
-
 
215
	private SuggestedPoRepository monthlyPoRepository;
-
 
216
 
-
 
217
	@Autowired
-
 
218
	private SuggestedPoDetailRepository monthlyPoDetailRepository;
-
 
219
 
-
 
220
	@Autowired
-
 
221
	private NotificationService notificationService;
-
 
222
 
198
	/*
223
	/*
199
	 * @RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
224
	 * @RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
200
	 * public String saveOpenIndent(HttpServletRequest request, Model model,
225
	 * public String saveOpenIndent(HttpServletRequest request, Model model,
201
	 * 
226
	 * 
202
	 * @RequestBody List<StockAllocationModel>
227
	 * @RequestBody List<StockAllocationModel>
Line 1262... Line 1287...
1262
		model.addAttribute("fofoStoreMap", fofoStoreMap);
1287
		model.addAttribute("fofoStoreMap", fofoStoreMap);
1263
		return "partners_allocation";
1288
		return "partners_allocation";
1264
 
1289
 
1265
	}
1290
	}
1266
 
1291
 
-
 
1292
	@RequestMapping(value = "/partnerPendingOrder")
-
 
1293
	public String partnerPendingOrder(HttpServletRequest request, Model model) throws Exception {
-
 
1294
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1295
		AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
-
 
1296
 
-
 
1297
		Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
-
 
1298
 
-
 
1299
		List<Integer> fofoIds = pp.get(authUser.getId());
-
 
1300
 
-
 
1301
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
-
 
1302
 
-
 
1303
		model.addAttribute("customRetailersMap", customRetailersMap);
-
 
1304
 
-
 
1305
		return "partner-po";
-
 
1306
 
-
 
1307
	}
-
 
1308
 
-
 
1309
	@RequestMapping(value = "/getPartnerloadContent")
-
 
1310
	public String getPartnerloadContent(HttpServletRequest request, Model model,
-
 
1311
			@RequestParam(required = false, defaultValue = "0") int fofoId,
-
 
1312
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
-
 
1313
 
-
 
1314
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1315
		Set<Integer> roleIds = loginDetails.getRoleIds();
-
 
1316
		LOGGER.info("Counter size is {}", counterSize);
-
 
1317
		LOGGER.info("Fofo Id is {}", fofoId);
-
 
1318
		boolean isAdmin = roleManager.isAdmin(roleIds);
-
 
1319
 
-
 
1320
		List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
-
 
1321
				.collect(Collectors.toList());
-
 
1322
 
-
 
1323
		Map<String, Object> equalsMap = new HashMap<>();
-
 
1324
		equalsMap.put("categoryId", 10006);
-
 
1325
		equalsMap.put("brand", brands);
-
 
1326
		Map<String, List<?>> notEqualsMap = new HashMap<>();
-
 
1327
 
-
 
1328
		Map<String, List<?>> notEqualsJoinMap = new HashMap<>();
-
 
1329
		Map<Integer, Integer> currentStockMap;
-
 
1330
 
-
 
1331
		if (!isAdmin && fofoId == 0) {
-
 
1332
			fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
-
 
1333
			Map<String, Object> equalsStockJoinMap = new HashMap<>();
-
 
1334
			equalsStockJoinMap.put("fofoId", fofoId);
-
 
1335
			currentStockMap = itemRepository
-
 
1336
					.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
-
 
1337
							equalsStockJoinMap, notEqualsJoinMap, "availability")
-
 
1338
					.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
-
 
1339
			LOGGER.info("currentStock");
-
 
1340
		} else {
-
 
1341
			if (fofoId == 0) {
-
 
1342
 
-
 
1343
				Map<String, Object> equalsStockJoinMap = new HashMap<>();
-
 
1344
				equalsStockJoinMap.put("fofoId", fofoId);
-
 
1345
 
-
 
1346
				currentStockMap = itemRepository
-
 
1347
						.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
-
 
1348
								equalsStockJoinMap, notEqualsJoinMap, "availability")
-
 
1349
						.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
-
 
1350
 
-
 
1351
			} else {
-
 
1352
 
-
 
1353
				Map<String, Object> equalsStockJoinMap = new HashMap<>();
-
 
1354
				equalsStockJoinMap.put("fofoId", fofoId);
-
 
1355
 
-
 
1356
				currentStockMap = itemRepository
-
 
1357
						.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
-
 
1358
								equalsStockJoinMap, notEqualsJoinMap, "availability")
-
 
1359
						.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
-
 
1360
 
-
 
1361
			}
-
 
1362
		}
-
 
1363
 
-
 
1364
		LOGGER.info("currentStock" + currentStockMap);
-
 
1365
 
-
 
1366
		Map<Integer, Integer> itemsInTransit = null;
-
 
1367
		List<TagListing> tagListings = tagListingRepository.selectAll(true);
-
 
1368
		if (!isAdmin) {
-
 
1369
			tagListings = new ArrayList<>(tagListings);
-
 
1370
			List<Order> inTransitOrders = orderRepository.selectPendingGrnOrder(fofoId, validOrderStatusList);
-
 
1371
			inTransitOrders = this.filterValidOrders(inTransitOrders);
-
 
1372
			itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
-
 
1373
					Collectors.summingInt(x -> x.getLineItem().getQuantity())));
-
 
1374
		} else {
-
 
1375
			itemsInTransit = new HashMap<>();
-
 
1376
		}
-
 
1377
 
-
 
1378
		int totalPcs = 0;
-
 
1379
 
-
 
1380
		float totalAmount = 0;
-
 
1381
		Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
-
 
1382
 
-
 
1383
		Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAll().stream()
-
 
1384
				.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
-
 
1385
 
-
 
1386
		LocalDate currentMonthDate = LocalDate.now();
-
 
1387
		MonthlyPlanned monthlyPlanned = null;
-
 
1388
		List<Integer> fofoOrderIds = null;
-
 
1389
		LOGGER.info("localDate" + LocalDate.now());
-
 
1390
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(25))
-
 
1391
				&& LocalDate.now().isBefore(LocalDate.now().plusMonths(1).withDayOfMonth(8))) {
-
 
1392
			currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
-
 
1393
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
-
 
1394
			LOGGER.info("monthlyPlanned2" + monthlyPlanned);
-
 
1395
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
-
 
1396
					LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
-
 
1397
					.collect(Collectors.toList());
-
 
1398
 
-
 
1399
			model.addAttribute("planningMonth", LocalDate.now().plusMonths(1).getMonth());
-
 
1400
		} else if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(8))
-
 
1401
				&& (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(26)))) {
-
 
1402
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
-
 
1403
			LocalDateTime curDate = LocalDate.now().atStartOfDay();
-
 
1404
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
-
 
1405
			model.addAttribute("planningMonth", currentMonthDate.getMonth());
-
 
1406
			model.addAttribute("mtd", true);
-
 
1407
			model.addAttribute("freezed", true);
-
 
1408
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
-
 
1409
					curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX)).stream().map(x -> x.getId())
-
 
1410
					.collect(Collectors.toList());
-
 
1411
			LOGGER.info("monthlyPlanned1" + monthlyPlanned);
-
 
1412
		} else if (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(8))) {
-
 
1413
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
-
 
1414
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
-
 
1415
			LOGGER.info("monthlyPlanned3" + monthlyPlanned);
-
 
1416
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
-
 
1417
					LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
-
 
1418
					.collect(Collectors.toList());
-
 
1419
			model.addAttribute("planningMonth", LocalDate.now().getMonth());
-
 
1420
		}
-
 
1421
 
-
 
1422
		Map<Integer, Integer> plannedDetailMap = null;
-
 
1423
		if (monthlyPlanned != null) {
-
 
1424
			plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
-
 
1425
					.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
-
 
1426
 
-
 
1427
		}
-
 
1428
		LOGGER.info("plannedDetailMap" + plannedDetailMap);
-
 
1429
 
-
 
1430
		LOGGER.info("fofoOrderIds" + fofoOrderIds);
-
 
1431
		Map<String, Object> equalsJoinMap = new HashMap<>();
-
 
1432
 
-
 
1433
		equalsJoinMap.put("orderId", fofoOrderIds);
-
 
1434
		Map<Integer, Integer> last15daysMap = null;
-
 
1435
		if (fofoOrderIds != null && !fofoOrderIds.isEmpty()) {
-
 
1436
 
-
 
1437
			last15daysMap = itemRepository
-
 
1438
					.selectItems(FofoOrderItem.class, "id", "itemId", equalsMap, notEqualsMap, equalsJoinMap,
-
 
1439
							notEqualsJoinMap, "quantity")
-
 
1440
					.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
-
 
1441
		}
-
 
1442
		LOGGER.info("last15daysMap" + last15daysMap);
-
 
1443
 
-
 
1444
		Map<Integer, TagListing> taglistingMap = tagListings.stream()
-
 
1445
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
-
 
1446
		List<Item> items = itemRepository.selectByIds(taglistingMap.keySet());
-
 
1447
		Map<Integer, List<Item>> catalogIdItemMap = items.stream().collect(
-
 
1448
				Collectors.groupingBy(x -> x.getCatalogItemId(), Collectors.mapping(y -> y, Collectors.toList())));
-
 
1449
		LOGGER.info("catalogIdItemMap");
-
 
1450
 
-
 
1451
		Map<String, Object> equalsItemJoinMap = new HashMap<>();
-
 
1452
		equalsItemJoinMap.put("active", 1);
-
 
1453
		List<CatalogIdAggregateValue> tagListingCatalogIds = itemRepository.selectItems(TagListing.class, "id",
-
 
1454
				"itemId", equalsMap, notEqualsMap, equalsItemJoinMap, notEqualsJoinMap, "tagId");
-
 
1455
		LOGGER.info("tagListingCatalogIds");
-
 
1456
		for (CatalogIdAggregateValue catalogIdAggregateValue : tagListingCatalogIds) {
-
 
1457
			int catalogId = catalogIdAggregateValue.getCatalogId();
-
 
1458
			Item item = catalogIdItemMap.get(catalogId).get(0);
-
 
1459
			TagListing tagListing = taglistingMap.get(item.getId());
-
 
1460
			CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
-
 
1461
			if (!catalogListingMap.containsKey(catalogId)) {
-
 
1462
				catalogListingModel = new CatalogListingModel();
-
 
1463
				catalogListingModel.setCatalogId(catalogId);
-
 
1464
				catalogListingModel.setDp(tagListing.getSellingPrice());
-
 
1465
				catalogListingModel.setMop(tagListing.getMop());
-
 
1466
				catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
-
 
1467
				if (plannedDetailMap != null) {
-
 
1468
 
-
 
1469
					Integer quantity = plannedDetailMap.get(catalogId);
-
 
1470
					if (quantity != null) {
-
 
1471
						catalogListingModel.setAllocatedQuantity(quantity);
-
 
1472
					}
-
 
1473
				}
-
 
1474
 
-
 
1475
				if (last15daysMap != null) {
-
 
1476
					Integer last15DaysSale = last15daysMap.get(catalogId);
-
 
1477
 
-
 
1478
					if (last15DaysSale != null) {
-
 
1479
						catalogListingModel.setLast15DaysSale(last15DaysSale);
-
 
1480
					} else {
-
 
1481
						catalogListingModel.setLast15DaysSale(0);
-
 
1482
					}
-
 
1483
				} else {
-
 
1484
					catalogListingModel.setLast15DaysSale(0);
-
 
1485
				}
-
 
1486
 
-
 
1487
				catalogListingModel.setBrand(item.getBrand());
-
 
1488
				if (item.getCategoryId() == 10006) {
-
 
1489
					catalogListingModel.setCategoryId(item.getCategoryId());
-
 
1490
				}
-
 
1491
 
-
 
1492
				FocusedModel fm = focusedModelMap.get(catalogId);
-
 
1493
				if (fm != null) {
-
 
1494
					catalogListingModel.setRecommendedQty(fm.getRecommendedQty());
-
 
1495
					catalogListingModel.setMinimumQty(fm.getMinimumQty());
-
 
1496
 
-
 
1497
				} else {
-
 
1498
					catalogListingModel.setRecommendedQty(0);
-
 
1499
					catalogListingModel.setMinimumQty(0);
-
 
1500
				}
-
 
1501
 
-
 
1502
				catalogListingMap.put(catalogId, catalogListingModel);
-
 
1503
 
-
 
1504
			}
-
 
1505
			int itemAvailability = 0;
-
 
1506
			if (currentStockMap != null) {
-
 
1507
				Integer qty = currentStockMap.get(catalogId);
-
 
1508
				itemAvailability = qty == null ? 0 : qty;
-
 
1509
				catalogListingModel.setStockInHand(itemAvailability);
-
 
1510
			} else {
-
 
1511
				catalogListingModel.setStockInHand(0);
-
 
1512
			}
-
 
1513
			Integer inTransitQuantity = itemsInTransit.get(item.getId());
-
 
1514
			int inTransitQty = (inTransitQuantity == null ? 0 : inTransitQuantity);
-
 
1515
			catalogListingModel.setInTransitQuantity(catalogListingModel.getInTransitQuantity() + inTransitQty);
-
 
1516
			if (plannedDetailMap != null) {
-
 
1517
				if (plannedDetailMap.get(catalogId) != null) {
-
 
1518
 
-
 
1519
					int remaining = plannedDetailMap.get(catalogId) - catalogListingModel.getLast15DaysSale()
-
 
1520
							+ catalogListingModel.getStockInHand() + catalogListingModel.getInTransitQuantity();
-
 
1521
					LOGGER.info("remaning" + remaining);
-
 
1522
 
-
 
1523
					if (remaining != 0) {
-
 
1524
						catalogListingModel.setRemaining(remaining);
-
 
1525
					} else {
-
 
1526
						catalogListingModel.setRemaining(0);
-
 
1527
					}
-
 
1528
				}
-
 
1529
			}
-
 
1530
		}
-
 
1531
 
-
 
1532
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers();
-
 
1533
		if (fofoId > 0) {
-
 
1534
			CustomRetailer customRetailer = customRetailersMap.get(fofoId);
-
 
1535
			model.addAttribute("retailerName",
-
 
1536
					customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
-
 
1537
			FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
1538
			model.addAttribute("retailerId", customRetailer.getPartnerId());
-
 
1539
			model.addAttribute("counterSize", fs.getCounterSize().toString());
-
 
1540
		} else {
-
 
1541
			model.addAttribute("counterSize", counterSize.toString());
-
 
1542
		}
-
 
1543
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
-
 
1544
 
-
 
1545
		List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
-
 
1546
 
-
 
1547
		Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getMinimumQty,
-
 
1548
				Comparator.reverseOrder());
-
 
1549
		LOGGER.info("monthlyPlanned" + monthlyPlanned);
-
 
1550
		model.addAttribute("catalogTagListings",
-
 
1551
				catalogModelList.stream().sorted(firstCmp).collect(Collectors.toList()));
-
 
1552
		model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
-
 
1553
		model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
-
 
1554
		model.addAttribute("previousPlanningMonth", LocalDate.now().minusMonths(1).getMonth());
-
 
1555
		model.addAttribute("currentPlanningMonth", LocalDate.now().getMonth());
-
 
1556
 
-
 
1557
		model.addAttribute("customRetailers", customRetailers);
-
 
1558
		model.addAttribute("totalAmount", totalAmount);
-
 
1559
		model.addAttribute("monthlyPlanned", monthlyPlanned);
-
 
1560
		model.addAttribute("totalPcs", totalPcs);
-
 
1561
 
-
 
1562
		UserWallet userWallet = walletService.getUserWallet(fofoId);
-
 
1563
 
-
 
1564
		model.addAttribute("userWallet", userWallet);
-
 
1565
 
-
 
1566
		return "create-partner-po";
-
 
1567
 
-
 
1568
	}
-
 
1569
 
-
 
1570
	@RequestMapping(value = "/createPo", method = RequestMethod.POST)
-
 
1571
	public String createPo(HttpServletRequest request, @RequestBody SuggestedPoModel monthlyPoModel, Model model)
-
 
1572
			throws Exception {
-
 
1573
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1574
		SuggestedPo mp = new SuggestedPo();
-
 
1575
		mp.setFofoId(monthlyPoModel.getFofoId());
-
 
1576
		mp.setCreateTimestamp(LocalDateTime.now());
-
 
1577
		mp.setStatus("open");
-
 
1578
		mp.setAuthId(loginDetails.getEmailId());
-
 
1579
		monthlyPoRepository.persist(mp);
-
 
1580
 
-
 
1581
		for (SuggestedPoIdModel poId : monthlyPoModel.getPoIds()) {
-
 
1582
			SuggestedPoDetail mpd = new SuggestedPoDetail();
-
 
1583
			mpd.setItemId(poId.getItemId());
-
 
1584
			mpd.setQuantity(poId.getQty());
-
 
1585
			mpd.setUpdatedTimestamp(LocalDateTime.now());
-
 
1586
			mpd.setPoId(mp.getId());
-
 
1587
			monthlyPoDetailRepository.persist(mpd);
-
 
1588
		}
-
 
1589
 
-
 
1590
		SendNotificationModel sendNotificationModel = new SendNotificationModel();
-
 
1591
		sendNotificationModel.setCampaignName("Alert");
-
 
1592
		sendNotificationModel.setMessage("Suggested Po");
-
 
1593
		sendNotificationModel.setType("url");
-
 
1594
		sendNotificationModel.setTitle("Alert");
-
 
1595
		sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/partnerPo/" + mp.getId());
-
 
1596
		sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
-
 
1597
		sendNotificationModel.setMessageType(MessageType.notification);
-
 
1598
		int userId = userAccountRepository.selectUserIdByRetailerId(monthlyPoModel.getFofoId());
-
 
1599
 
-
 
1600
		sendNotificationModel.setUserIds(Arrays.asList(userId));
-
 
1601
		notificationService.sendNotification(sendNotificationModel);
-
 
1602
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
1603
 
-
 
1604
		return "response";
-
 
1605
	}
-
 
1606
 
-
 
1607
	@RequestMapping(value = "/selectItemColor", method = RequestMethod.GET)
-
 
1608
	public String selectItemColor(HttpServletRequest request, @RequestParam int catalogId, Model model)
-
 
1609
			throws Exception {
-
 
1610
 
-
 
1611
		List<Item> selecteditems = itemRepository.selectAllByCatalogItemId(catalogId);
-
 
1612
 
-
 
1613
		List<Item> items = new ArrayList<>();
-
 
1614
		for (Item item : selecteditems) {
-
 
1615
 
-
 
1616
			TagListing tagListing = tagListingRepository.selectByItemId(item.getId(), true);
-
 
1617
 
-
 
1618
			if (tagListing != null) {
-
 
1619
				items.add(item);
-
 
1620
			}
-
 
1621
 
-
 
1622
		}
-
 
1623
		model.addAttribute("items", items);
-
 
1624
		LOGGER.info("itemIdAndColorMap" + items);
-
 
1625
		return "select-item-color";
-
 
1626
	}
-
 
1627
 
1267
}
1628
}
1268
1629