Subversion Repositories SmartDukaan

Rev

Rev 26846 | Rev 26951 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23405 amit.gupta 1
package com.spice.profitmandi.web.controller;
2
 
24824 govind 3
import java.io.Serializable;
25721 tejbeer 4
import java.time.LocalDate;
5
import java.time.LocalDateTime;
26131 tejbeer 6
import java.time.LocalTime;
23785 amit.gupta 7
import java.util.ArrayList;
23405 amit.gupta 8
import java.util.Arrays;
23796 amit.gupta 9
import java.util.Collections;
10
import java.util.Comparator;
11
import java.util.HashMap;
24406 amit.gupta 12
import java.util.HashSet;
23785 amit.gupta 13
import java.util.Iterator;
23405 amit.gupta 14
import java.util.List;
15
import java.util.Map;
23785 amit.gupta 16
import java.util.Set;
25721 tejbeer 17
import java.util.function.Function;
23405 amit.gupta 18
import java.util.stream.Collectors;
19
 
20
import javax.servlet.http.HttpServletRequest;
21
 
24231 amit.gupta 22
import org.apache.commons.io.output.ByteArrayOutputStream;
23717 amit.gupta 23
import org.apache.logging.log4j.LogManager;
23568 govind 24
import org.apache.logging.log4j.Logger;
23796 amit.gupta 25
import org.apache.thrift.TException;
24349 amit.gupta 26
import org.json.JSONArray;
23779 amit.gupta 27
import org.json.JSONObject;
23405 amit.gupta 28
import org.springframework.beans.factory.annotation.Autowired;
24231 amit.gupta 29
import org.springframework.core.io.ByteArrayResource;
30
import org.springframework.http.HttpHeaders;
31
import org.springframework.http.HttpStatus;
32
import org.springframework.http.ResponseEntity;
25721 tejbeer 33
import org.springframework.mail.javamail.JavaMailSender;
23405 amit.gupta 34
import org.springframework.stereotype.Controller;
35
import org.springframework.transaction.annotation.Transactional;
36
import org.springframework.ui.Model;
37
import org.springframework.web.bind.annotation.RequestBody;
38
import org.springframework.web.bind.annotation.RequestMapping;
39
import org.springframework.web.bind.annotation.RequestMethod;
23779 amit.gupta 40
import org.springframework.web.bind.annotation.RequestParam;
23405 amit.gupta 41
 
25736 tejbeer 42
import com.mongodb.DBObject;
26846 tejbeer 43
import com.mysql.fabric.xmlrpc.base.Array;
23785 amit.gupta 44
import com.spice.profitmandi.common.enumuration.CounterSize;
26846 tejbeer 45
import com.spice.profitmandi.common.enumuration.MessageType;
23405 amit.gupta 46
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
25798 tejbeer 47
import com.spice.profitmandi.common.model.BrandStockPrice;
25796 tejbeer 48
import com.spice.profitmandi.common.model.CatalogIdAggregateValue;
24231 amit.gupta 49
import com.spice.profitmandi.common.model.CatalogListingModel;
23785 amit.gupta 50
import com.spice.profitmandi.common.model.CustomRetailer;
26846 tejbeer 51
import com.spice.profitmandi.common.model.SuggestedPoIdModel;
52
import com.spice.profitmandi.common.model.SuggestedPoModel;
53
import com.spice.profitmandi.common.model.NotifyOrderModel;
25721 tejbeer 54
import com.spice.profitmandi.common.model.PlannedModel;
26846 tejbeer 55
import com.spice.profitmandi.common.model.SendNotificationModel;
23779 amit.gupta 56
import com.spice.profitmandi.common.model.StockAllocationModel;
24231 amit.gupta 57
import com.spice.profitmandi.common.util.FileUtil;
25721 tejbeer 58
import com.spice.profitmandi.common.util.Utils;
59
import com.spice.profitmandi.common.util.Utils.Attachment;
26721 tejbeer 60
import com.spice.profitmandi.dao.entity.auth.AuthUser;
25721 tejbeer 61
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
23785 amit.gupta 62
import com.spice.profitmandi.dao.entity.catalog.Item;
23405 amit.gupta 63
import com.spice.profitmandi.dao.entity.catalog.TagListing;
25796 tejbeer 64
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
65
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
23785 amit.gupta 66
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
25721 tejbeer 67
import com.spice.profitmandi.dao.entity.fofo.MonthlyPlanned;
26846 tejbeer 68
import com.spice.profitmandi.dao.entity.fofo.SuggestedPo;
69
import com.spice.profitmandi.dao.entity.fofo.SuggestedPoDetail;
25721 tejbeer 70
import com.spice.profitmandi.dao.entity.fofo.PlannedDetail;
23796 amit.gupta 71
import com.spice.profitmandi.dao.entity.transaction.Order;
26846 tejbeer 72
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
23796 amit.gupta 73
import com.spice.profitmandi.dao.entity.user.User;
26721 tejbeer 74
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
25721 tejbeer 75
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
23405 amit.gupta 76
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
77
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
25721 tejbeer 78
import com.spice.profitmandi.dao.repository.cs.CsService;
23779 amit.gupta 79
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
25736 tejbeer 80
import com.spice.profitmandi.dao.repository.dtr.Mongo;
26846 tejbeer 81
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
23405 amit.gupta 82
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
25732 tejbeer 83
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
25721 tejbeer 84
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
85
import com.spice.profitmandi.dao.repository.fofo.MonthlyPlannedRepository;
26846 tejbeer 86
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
87
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
25721 tejbeer 88
import com.spice.profitmandi.dao.repository.fofo.PlannedDetailRepository;
23796 amit.gupta 89
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
90
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
91
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
92
import com.spice.profitmandi.dao.repository.user.UserRepository;
26846 tejbeer 93
import com.spice.profitmandi.service.NotificationService;
23798 amit.gupta 94
import com.spice.profitmandi.service.authentication.RoleManager;
25736 tejbeer 95
import com.spice.profitmandi.service.inventory.InventoryService;
23779 amit.gupta 96
import com.spice.profitmandi.service.inventory.StockAllocationService;
97
import com.spice.profitmandi.service.user.RetailerService;
25547 amit.gupta 98
import com.spice.profitmandi.service.wallet.WalletService;
23796 amit.gupta 99
import com.spice.profitmandi.thrift.clients.PaymentClient;
100
import com.spice.profitmandi.thrift.clients.TransactionClient;
101
import com.spice.profitmandi.thrift.clients.UserClient;
23405 amit.gupta 102
import com.spice.profitmandi.web.model.LoginDetails;
103
import com.spice.profitmandi.web.util.CookiesProcessor;
104
import com.spice.profitmandi.web.util.MVCResponseSender;
105
 
23796 amit.gupta 106
import in.shop2020.logistics.PickUpType;
107
import in.shop2020.model.v1.order.LineItem;
108
import in.shop2020.model.v1.order.OrderSource;
109
import in.shop2020.model.v1.order.OrderStatus;
110
import in.shop2020.model.v1.order.OrderType;
111
import in.shop2020.model.v1.order.Transaction;
112
import in.shop2020.model.v1.order.TransactionService;
113
import in.shop2020.model.v1.order.TransactionStatus;
114
import in.shop2020.model.v1.user.ItemPriceQuantity;
115
import in.shop2020.model.v1.user.ShoppingCartException;
116
import in.shop2020.model.v1.user.UserContextService.Client;
117
import in.shop2020.payments.Attribute;
118
import in.shop2020.payments.PaymentException;
119
import in.shop2020.payments.PaymentStatus;
120
 
23405 amit.gupta 121
@Controller
122
@Transactional(rollbackFor = Throwable.class)
123
public class IndentController {
124
 
23568 govind 125
	private static final Logger LOGGER = LogManager.getLogger(IndentController.class);
23796 amit.gupta 126
	private static final int WALLET_GATEWAY_ID = 8;
24406 amit.gupta 127
	private static final Set<Integer> defaultTags = new HashSet<Integer>(Arrays.asList(4));
23405 amit.gupta 128
 
23796 amit.gupta 129
	private final List<OrderStatus> validOrderStatusList = Arrays.asList(OrderStatus.ACCEPTED,
130
			OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH,
131
			OrderStatus.DELIVERY_SUCCESS, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.SHIPPED_TO_LOGST,
132
			OrderStatus.REACHED_DESTINATION_CITY);
133
 
24231 amit.gupta 134
	private final List<OrderStatus> partnerPendingOrderList = Arrays.asList(OrderStatus.ACCEPTED,
135
			OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH,
136
			OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.SHIPPED_TO_LOGST,
137
			OrderStatus.REACHED_DESTINATION_CITY);
25721 tejbeer 138
 
25547 amit.gupta 139
	@Autowired
140
	WalletService walletService;
24231 amit.gupta 141
 
23405 amit.gupta 142
	@Autowired
25721 tejbeer 143
	private JavaMailSender googleMailSender;
144
 
145
	@Autowired
23405 amit.gupta 146
	private CookiesProcessor cookiesProcessor;
24231 amit.gupta 147
 
23796 amit.gupta 148
	@Autowired
149
	private UserWalletRepository userWalletRepository;
23785 amit.gupta 150
 
23779 amit.gupta 151
	@Autowired
23796 amit.gupta 152
	private UserRepository userRepository;
153
 
154
	@Autowired
23779 amit.gupta 155
	FofoStoreRepository fofoStoreRepository;
23405 amit.gupta 156
 
157
	@Autowired
23796 amit.gupta 158
	private OrderRepository orderRepository;
159
 
160
	@Autowired
26846 tejbeer 161
	private UserAccountRepository userAccountRepository;
162
 
163
	@Autowired
23405 amit.gupta 164
	private ItemRepository itemRepository;
165
 
166
	@Autowired
23779 amit.gupta 167
	private StockAllocationService stockAllocationService;
168
 
169
	@Autowired
170
	private RetailerService retailerService;
23405 amit.gupta 171
 
172
	@Autowired
173
	private TagListingRepository tagListingRepository;
174
 
175
	@Autowired
176
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
177
 
178
	@Autowired
23796 amit.gupta 179
	private PurchaseRepository purchaseRepository;
180
 
181
	@Autowired
23405 amit.gupta 182
	private MVCResponseSender mvcResponseSender;
183
 
23785 amit.gupta 184
	@Autowired
25721 tejbeer 185
	private FocusedModelRepository focusedModelRepository;
186
 
187
	@Autowired
188
	private MonthlyPlannedRepository monthlyPlannedRepository;
189
 
190
	@Autowired
191
	private FofoOrderRepository fofoOrderRepository;
25732 tejbeer 192
 
25721 tejbeer 193
	@Autowired
25732 tejbeer 194
	private FofoOrderItemRepository fofoOrderItemRepository;
195
 
196
	@Autowired
25721 tejbeer 197
	private PlannedDetailRepository plannedDetailRepository;
25732 tejbeer 198
 
25721 tejbeer 199
	@Autowired
23785 amit.gupta 200
	RoleManager roleManager;
23405 amit.gupta 201
 
25721 tejbeer 202
	@Autowired
25736 tejbeer 203
	private Mongo mongoClient;
204
 
205
	@Autowired
206
	private InventoryService inventoryService;
207
 
208
	@Autowired
26721 tejbeer 209
	private CsService csService;
25721 tejbeer 210
 
26721 tejbeer 211
	@Autowired
212
	private AuthRepository authRepository;
213
 
26846 tejbeer 214
	@Autowired
215
	private SuggestedPoRepository monthlyPoRepository;
216
 
217
	@Autowired
218
	private SuggestedPoDetailRepository monthlyPoDetailRepository;
219
 
220
	@Autowired
221
	private NotificationService notificationService;
222
 
25721 tejbeer 223
	/*
224
	 * @RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
225
	 * public String saveOpenIndent(HttpServletRequest request, Model model,
226
	 * 
227
	 * @RequestBody List<StockAllocationModel>
228
	 * stockAllocationModelList, @RequestParam int fofoId,
229
	 * 
230
	 * @RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws
231
	 * Exception { LoginDetails loginDetails =
232
	 * cookiesProcessor.getCookiesObject(request); boolean response = false; if
233
	 * (fofoId > 0) { FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
234
	 * stockAllocationModelList.forEach(x -> { x.setFofoId(fofoId);
235
	 * x.setCounterSize(fs.getCounterSize()); }); } else {
236
	 * stockAllocationModelList.forEach(x -> { x.setFofoId(fofoId);
237
	 * x.setCounterSize(counterSize); }); } if
238
	 * (roleManager.isAdmin(loginDetails.getRoleIds())) { response =
239
	 * stockAllocationService.addToAllocation(stockAllocationModelList);
240
	 * model.addAttribute("response",
241
	 * mvcResponseSender.createResponseString(response)); } return "response"; }
242
	 */
23779 amit.gupta 243
	@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
25721 tejbeer 244
	public String saveOpenIndent(HttpServletRequest request, Model model, @RequestParam int catalogId,
245
			@RequestParam int itemQty) throws Exception {
23405 amit.gupta 246
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
26082 tejbeer 247
		LocalDate currentMonthDate = LocalDate.now();
248
		MonthlyPlanned monthlyPlanned = null;
25721 tejbeer 249
 
26082 tejbeer 250
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(25))
251
				&& LocalDate.now().isBefore(LocalDate.now().plusMonths(1).withDayOfMonth(8))) {
252
			currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
253
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(loginDetails.getFofoId(),
254
					currentMonthDate);
25721 tejbeer 255
 
26082 tejbeer 256
			saveMonthlyPlanned(monthlyPlanned, loginDetails.getFofoId(), currentMonthDate, catalogId, itemQty);
257
		} else if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(8))
258
				&& (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(26)))) {
259
			// freezed code;
260
		} else if (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(8))) {
261
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
262
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(loginDetails.getFofoId(),
263
					currentMonthDate);
264
 
265
			saveMonthlyPlanned(monthlyPlanned, loginDetails.getFofoId(), currentMonthDate, catalogId, itemQty);
266
		}
267
 
268
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
269
 
270
		model.addAttribute("response", mvcResponseSender.createResponseString(false));
271
 
272
		return "response";
273
	}
274
 
275
	private void saveMonthlyPlanned(MonthlyPlanned monthlyPlanned, int fofoId, LocalDate currentMonthDate,
276
			int catalogId, int itemQty) {
25721 tejbeer 277
		if (monthlyPlanned == null) {
278
			monthlyPlanned = new MonthlyPlanned();
26082 tejbeer 279
			monthlyPlanned.setFofoId(fofoId);
280
			monthlyPlanned.setYearMonth(currentMonthDate);
25721 tejbeer 281
			monthlyPlannedRepository.persist(monthlyPlanned);
282
			PlannedDetail pd = new PlannedDetail();
283
			pd.setCatalogId(catalogId);
284
			pd.setPlannedId(monthlyPlanned.getId());
285
			pd.setQuantity(itemQty);
286
			pd.setUpdatedTimestamp(LocalDateTime.now());
287
			plannedDetailRepository.persist(pd);
288
 
23786 amit.gupta 289
		} else {
25721 tejbeer 290
			PlannedDetail plannedDetail = plannedDetailRepository.selectByPlannedIdCatalogId(monthlyPlanned.getId(),
291
					catalogId);
292
			if (plannedDetail == null) {
293
				plannedDetail = new PlannedDetail();
294
				plannedDetail.setCatalogId(catalogId);
295
				plannedDetail.setPlannedId(monthlyPlanned.getId());
296
				plannedDetail.setQuantity(itemQty);
297
				plannedDetail.setUpdatedTimestamp(LocalDateTime.now());
298
				plannedDetailRepository.persist(plannedDetail);
299
			} else if (itemQty == 0) {
300
				plannedDetailRepository.delete(plannedDetail);
301
 
302
			} else {
303
				plannedDetail.setCatalogId(catalogId);
304
				plannedDetail.setQuantity(itemQty);
305
				plannedDetail.setUpdatedTimestamp(LocalDateTime.now());
306
			}
307
 
23785 amit.gupta 308
		}
25721 tejbeer 309
 
310
	}
311
 
312
	@RequestMapping(value = "/open-indent/confirm", method = RequestMethod.POST)
26748 tejbeer 313
	public String confirmOpenIndent(HttpServletRequest request,
314
			@RequestParam(required = false, defaultValue = "0") int fofoId, Model model) throws Exception {
315
 
316
		if (fofoId == 0) {
317
			LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
318
			fofoId = loginDetails.getFofoId();
319
		}
25721 tejbeer 320
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
26748 tejbeer 321
 
26082 tejbeer 322
		LocalDate currentMonthDate = LocalDate.now();
323
		MonthlyPlanned monthlyPlanned = null;
324
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(25))
325
				&& LocalDate.now().isBefore(LocalDate.now().plusMonths(1).withDayOfMonth(8))) {
326
			currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
327
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
25721 tejbeer 328
 
26082 tejbeer 329
			confirmMonthlyPlanned(monthlyPlanned, customRetailer, fofoId);
330
		} else if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(8))
331
				&& (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(26)))) {
332
			// freezed code;
333
		} else if (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(8))) {
334
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
335
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
336
 
337
			confirmMonthlyPlanned(monthlyPlanned, customRetailer, fofoId);
338
		}
339
 
340
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
341
 
342
		return "response";
343
	}
344
 
345
	private void confirmMonthlyPlanned(MonthlyPlanned monthlyPlanned, CustomRetailer customRetailer, int fofoId)
346
			throws Exception {
25721 tejbeer 347
		List<PlannedDetail> plannedDetails = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId());
348
 
349
		List<PlannedModel> plannedModel = new ArrayList<>();
350
		for (PlannedDetail plannedDetail : plannedDetails) {
351
 
352
			List<Item> items = itemRepository.selectAllByCatalogItemId(plannedDetail.getCatalogId());
353
			String itemDesription = items.get(0).getItemDescriptionNoColor();
354
			PlannedModel pm = new PlannedModel();
355
			pm.setItemDescription(itemDesription);
356
			pm.setStoreName(customRetailer.getBusinessName());
357
			pm.setQty(plannedDetail.getQuantity());
26082 tejbeer 358
			pm.setFofoId(fofoId);
25721 tejbeer 359
			plannedModel.add(pm);
360
			LOGGER.info("plannedModel" + plannedModel);
361
 
23785 amit.gupta 362
		}
25732 tejbeer 363
		List<String> emails = csService.getAuthUserByPartnerId(fofoId);
364
		emails.add(customRetailer.getEmail());
25727 tejbeer 365
 
25721 tejbeer 366
		LOGGER.info("emails" + emails);
26082 tejbeer 367
 
25721 tejbeer 368
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
369
				Arrays.asList("Partner Id", "Partner Name", "Model Name", "Qty"),
370
				plannedModel.stream()
371
						.map(x -> Arrays.asList(x.getFofoId(), x.getStoreName(), x.getItemDescription(), x.getQty()))
372
						.collect(Collectors.toList()));
373
		LOGGER.info("baos" + baos);
374
		Utils.sendMailWithAttachments(googleMailSender, emails.toArray(new String[emails.size()]), null,
375
				"Planned Indent", "PFA",
376
				new Attachment[] { new Attachment("PlannedIndent.csv", new ByteArrayResource(baos.toByteArray())), });
377
 
23405 amit.gupta 378
	}
379
 
24231 amit.gupta 380
	@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
381
	public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
382
			@RequestParam(required = false, defaultValue = "0") int fofoId,
383
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
25702 amit.gupta 384
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
385
		Set<Integer> roleIds = loginDetails.getRoleIds();
24231 amit.gupta 386
		LOGGER.info("Counter size is {}", counterSize);
387
		LOGGER.info("Fofo Id is {}", fofoId);
25721 tejbeer 388
		if (roleManager.isAdmin(roleIds) || loginDetails.getFofoId() == fofoId) {
24231 amit.gupta 389
			List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
390
					.collect(Collectors.toList());
391
			Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
23415 amit.gupta 392
 
24232 amit.gupta 393
			List<StockAllocationModel> stockAllocationList = stockAllocationService.getStockAllocation(counterSize,
394
					true);
395
			Map<Integer, Integer> modelStockAllocationMap = stockAllocationList.stream()
396
					.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
23405 amit.gupta 397
 
24232 amit.gupta 398
			Map<String, Integer> catalogUserQtyMap = new HashMap<>();
25702 amit.gupta 399
			currentInventorySnapshotRepository.selectByFofoId(fofoId).stream().forEach(x -> {
24232 amit.gupta 400
				int retailerId = x.getFofoId();
401
				int catalogId;
402
				try {
403
					catalogId = itemRepository.selectById(x.getItemId()).getCatalogItemId();
404
					String key = catalogId + "-" + retailerId;
405
					if (!catalogUserQtyMap.containsKey(key)) {
406
						catalogUserQtyMap.put(key, 0);
407
					}
408
					catalogUserQtyMap.put(key, catalogUserQtyMap.get(key) + x.getAvailability());
409
				} catch (ProfitMandiBusinessException e) {
410
					// TODO Auto-generated catch block
411
					throw new RuntimeException(e);
24231 amit.gupta 412
				}
413
			});
23779 amit.gupta 414
 
24231 amit.gupta 415
			List<Order> inTransitOrders = orderRepository.selectOrders(fofoIds, partnerPendingOrderList);
24232 amit.gupta 416
			Map<String, Integer> catalogUserInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> {
417
				try {
418
					return itemRepository.selectById(x.getLineItem().getItemId()).getCatalogItemId() + "-"
419
							+ x.getRetailerId();
420
				} catch (ProfitMandiBusinessException e) {
421
					// TODO Auto-generated catch block
422
					return "";
423
				}
424
			}, Collectors.summingInt(x -> x.getLineItem().getQuantity())));
23779 amit.gupta 425
 
24232 amit.gupta 426
			Map<String, CatalogListingModel> catalogListingMap = new HashMap<>();
427
 
428
			List<TagListing> tagListings = tagListingRepository.selectAll(true);
429
			Iterator<TagListing> iterator = tagListings.iterator();
24231 amit.gupta 430
			while (iterator.hasNext()) {
431
				TagListing tagListing = iterator.next();
432
				Item item = itemRepository.selectById(tagListing.getItemId());
24232 amit.gupta 433
				int catalogId = item.getCatalogItemId();
24231 amit.gupta 434
				if (item.getCategoryId() != 10006) {
435
					continue;
436
				}
23779 amit.gupta 437
 
24232 amit.gupta 438
				int catalogStockAllocationQuantity = modelStockAllocationMap.containsKey(catalogId)
439
						? modelStockAllocationMap.get(catalogId)
440
						: 0;
441
				for (int retailerId : fofoIds) {
442
					String key = catalogId + "-" + retailerId;
443
					if (catalogListingMap.containsKey(key)) {
444
						continue;
24231 amit.gupta 445
					}
24232 amit.gupta 446
					int catalogInTransit = catalogUserInTransit.containsKey(key) ? catalogUserInTransit.get(key) : 0;
447
					int catalogInStock = catalogUserQtyMap.containsKey(key) ? catalogUserQtyMap.get(key) : 0;
448
					if (catalogInTransit + catalogInStock == 0 && catalogStockAllocationQuantity == 0) {
449
						continue;
450
					}
451
					CatalogListingModel catalogListingModel = new CatalogListingModel();
452
					catalogListingModel.setFofoId(retailerId);
453
					catalogListingModel.setModelName(item.getModelName());
454
					catalogListingModel.setModelNumber(item.getModelNumber());
455
					catalogListingModel.setCatalogId(catalogId);
456
					catalogListingModel.setDp(tagListing.getSellingPrice());
457
					catalogListingModel.setMop(tagListing.getMop());
458
					catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
459
					catalogListingModel.setAllocatedQuantity(catalogStockAllocationQuantity);
460
					catalogListingModel.setInTransitQuantity(catalogInTransit);
461
					catalogListingModel
462
							.setToBeOrdered(catalogStockAllocationQuantity - catalogInTransit - catalogInStock);
24233 amit.gupta 463
					catalogListingModel.setStockInHand(catalogInStock);
24232 amit.gupta 464
					catalogListingModel.setBrand(item.getBrand());
465
					catalogListingModel.setModelName(item.getModelName());
466
					catalogListingModel.setModelNumber(item.getModelNumber());
467
					catalogListingModel.setCategoryId(item.getCategoryId());
468
					catalogListingMap.put(key, catalogListingModel);
23405 amit.gupta 469
				}
470
			}
25853 amit.gupta 471
			List<List<?>> listOfRows = new ArrayList<>();
24231 amit.gupta 472
			for (CatalogListingModel clm : catalogListingMap.values()) {
473
				CustomRetailer cr = customRetailersMap.get(clm.getFofoId());
24349 amit.gupta 474
				listOfRows.add(Arrays.asList(cr.getPartnerId(), cr.getBusinessName(), clm.getCatalogId(),
475
						clm.getBrand(), clm.getModelName(), clm.getModelNumber(), clm.getDp(), clm.getMop(),
476
						clm.getAllocatedQuantity(), clm.getInTransitQuantity(), clm.getStockInHand(),
477
						clm.getToBeOrdered()));
24231 amit.gupta 478
			}
24349 amit.gupta 479
			ByteArrayOutputStream baos = FileUtil
480
					.getCSVByteStream(
481
							Arrays.asList("StoreId", "StoreName", "Catalog Id", "Brand", "Model Name", "Model Number",
482
									"DP", "MOP", "Allocated Quantity", "In Transit", "Stock In hand", "Shortage"),
483
							listOfRows);
24231 amit.gupta 484
			HttpHeaders headers = new HttpHeaders();
485
			headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
486
			headers.set("Content-disposition", "inline; filename=retailer-allocation.csv");
24232 amit.gupta 487
			return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(baos.toByteArray()), headers,
488
					HttpStatus.OK);
23405 amit.gupta 489
		}
24231 amit.gupta 490
		return null;
24232 amit.gupta 491
 
23405 amit.gupta 492
	}
493
 
24349 amit.gupta 494
	@RequestMapping(value = "/itemsByCatalogId")
495
	public String getItemsByCatalogId(HttpServletRequest request, Model model,
24410 amit.gupta 496
			@RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
25378 tejbeer 497
			throws ProfitMandiBusinessException {
24410 amit.gupta 498
		if (catalogId == 0) {
499
			catalogId = itemRepository.selectById(itemId).getCatalogItemId();
500
		}
24349 amit.gupta 501
		List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
24414 amit.gupta 502
		LOGGER.info("Items {}", items);
25378 tejbeer 503
		Map<Integer, String> itemsColorMap = items.stream().filter(x -> x.getColorNatural().startsWith("f_"))
504
				.collect(Collectors.toMap(Item::getId, Item::getColor));
24413 amit.gupta 505
		Map<Integer, TagListing> tagsMap = tagListingRepository
506
				.selectByItemIdsAndTagIds(items.stream().map(x -> x.getId()).collect(Collectors.toSet()), defaultTags)
25378 tejbeer 507
				.stream().collect(Collectors.toMap(TagListing::getItemId, x -> x));
24414 amit.gupta 508
		LOGGER.info("Items color map {}", itemsColorMap);
24349 amit.gupta 509
		JSONArray response = new JSONArray();
24413 amit.gupta 510
		itemsColorMap.keySet().stream().forEach(x -> {
25378 tejbeer 511
			response.put(new JSONObject().put("color", itemsColorMap.get(x)).put("id", x).put("active",
512
					tagsMap.get(x) == null ? false : tagsMap.get(x).isActive()));
24349 amit.gupta 513
		});
514
		model.addAttribute("response", response.toString());
515
		return "response";
24410 amit.gupta 516
 
24349 amit.gupta 517
	}
518
 
23405 amit.gupta 519
	@RequestMapping(value = "/indent/loadIndent")
23785 amit.gupta 520
	public String loadOpenIndent(HttpServletRequest request, Model model,
521
			@RequestParam(required = false, defaultValue = "0") int fofoId,
25736 tejbeer 522
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
25702 amit.gupta 523
 
524
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
525
		Set<Integer> roleIds = loginDetails.getRoleIds();
23785 amit.gupta 526
		LOGGER.info("Counter size is {}", counterSize);
527
		LOGGER.info("Fofo Id is {}", fofoId);
25736 tejbeer 528
		boolean isAdmin = roleManager.isAdmin(roleIds);
25796 tejbeer 529
 
25797 tejbeer 530
		List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
531
				.collect(Collectors.toList());
532
 
25796 tejbeer 533
		Map<String, Object> equalsMap = new HashMap<>();
534
		equalsMap.put("categoryId", 10006);
25797 tejbeer 535
		equalsMap.put("brand", brands);
25796 tejbeer 536
		Map<String, List<?>> notEqualsMap = new HashMap<>();
537
 
538
		Map<String, List<?>> notEqualsJoinMap = new HashMap<>();
539
		Map<Integer, Integer> currentStockMap;
540
 
25721 tejbeer 541
		if (!isAdmin && fofoId == 0) {
23786 amit.gupta 542
			fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
25796 tejbeer 543
			Map<String, Object> equalsStockJoinMap = new HashMap<>();
544
			equalsStockJoinMap.put("fofoId", fofoId);
545
			currentStockMap = itemRepository
25800 tejbeer 546
					.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
547
							equalsStockJoinMap, notEqualsJoinMap, "availability")
25796 tejbeer 548
					.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
25797 tejbeer 549
			LOGGER.info("currentStock");
23786 amit.gupta 550
		} else {
551
			if (fofoId == 0) {
25796 tejbeer 552
 
553
				Map<String, Object> equalsStockJoinMap = new HashMap<>();
554
				equalsStockJoinMap.put("fofoId", fofoId);
555
 
556
				currentStockMap = itemRepository
25800 tejbeer 557
						.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
25796 tejbeer 558
								equalsStockJoinMap, notEqualsJoinMap, "availability")
559
						.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
560
 
23779 amit.gupta 561
			} else {
25796 tejbeer 562
 
563
				Map<String, Object> equalsStockJoinMap = new HashMap<>();
564
				equalsStockJoinMap.put("fofoId", fofoId);
565
 
566
				currentStockMap = itemRepository
25800 tejbeer 567
						.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
25796 tejbeer 568
								equalsStockJoinMap, notEqualsJoinMap, "availability")
569
						.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
570
 
23405 amit.gupta 571
			}
23786 amit.gupta 572
		}
25796 tejbeer 573
 
574
		LOGGER.info("currentStock" + currentStockMap);
25797 tejbeer 575
 
23796 amit.gupta 576
		Map<Integer, Integer> itemsInTransit = null;
23855 amit.gupta 577
		List<TagListing> tagListings = tagListingRepository.selectAll(true);
25702 amit.gupta 578
		if (!isAdmin) {
23786 amit.gupta 579
			tagListings = new ArrayList<>(tagListings);
25797 tejbeer 580
			List<Order> inTransitOrders = orderRepository.selectPendingGrnOrder(fofoId, validOrderStatusList);
23796 amit.gupta 581
			inTransitOrders = this.filterValidOrders(inTransitOrders);
582
			itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
583
					Collectors.summingInt(x -> x.getLineItem().getQuantity())));
584
		} else {
585
			itemsInTransit = new HashMap<>();
23786 amit.gupta 586
		}
25797 tejbeer 587
 
23796 amit.gupta 588
		int totalPcs = 0;
25797 tejbeer 589
 
23796 amit.gupta 590
		float totalAmount = 0;
24231 amit.gupta 591
		Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
25796 tejbeer 592
 
25721 tejbeer 593
		Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAll().stream()
594
				.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
25728 tejbeer 595
 
26082 tejbeer 596
		LocalDate currentMonthDate = LocalDate.now();
597
		MonthlyPlanned monthlyPlanned = null;
26176 tejbeer 598
		List<Integer> fofoOrderIds = null;
26082 tejbeer 599
		LOGGER.info("localDate" + LocalDate.now());
600
		if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(25))
601
				&& LocalDate.now().isBefore(LocalDate.now().plusMonths(1).withDayOfMonth(8))) {
602
			currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
603
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
604
			LOGGER.info("monthlyPlanned2" + monthlyPlanned);
26176 tejbeer 605
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
606
					LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
607
					.collect(Collectors.toList());
26082 tejbeer 608
 
609
			model.addAttribute("planningMonth", LocalDate.now().plusMonths(1).getMonth());
610
		} else if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(8))
611
				&& (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(26)))) {
612
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
26176 tejbeer 613
			LocalDateTime curDate = LocalDate.now().atStartOfDay();
26082 tejbeer 614
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
26131 tejbeer 615
			model.addAttribute("planningMonth", currentMonthDate.getMonth());
26176 tejbeer 616
			model.addAttribute("mtd", true);
26131 tejbeer 617
			model.addAttribute("freezed", true);
26176 tejbeer 618
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
619
					curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX)).stream().map(x -> x.getId())
620
					.collect(Collectors.toList());
26082 tejbeer 621
			LOGGER.info("monthlyPlanned1" + monthlyPlanned);
622
		} else if (LocalDate.now().isBefore(LocalDate.now().withDayOfMonth(8))) {
623
			currentMonthDate = LocalDate.now().withDayOfMonth(1);
624
			monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
625
			LOGGER.info("monthlyPlanned3" + monthlyPlanned);
26176 tejbeer 626
			fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
627
					LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
628
					.collect(Collectors.toList());
26082 tejbeer 629
			model.addAttribute("planningMonth", LocalDate.now().getMonth());
630
		}
631
 
25721 tejbeer 632
		Map<Integer, Integer> plannedDetailMap = null;
633
		if (monthlyPlanned != null) {
634
			plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
635
					.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
636
 
637
		}
25797 tejbeer 638
		LOGGER.info("plannedDetailMap" + plannedDetailMap);
26176 tejbeer 639
 
25796 tejbeer 640
		LOGGER.info("fofoOrderIds" + fofoOrderIds);
641
		Map<String, Object> equalsJoinMap = new HashMap<>();
26618 tejbeer 642
 
25796 tejbeer 643
		equalsJoinMap.put("orderId", fofoOrderIds);
26618 tejbeer 644
		Map<Integer, Integer> last15daysMap = null;
26748 tejbeer 645
		if (fofoOrderIds != null && !fofoOrderIds.isEmpty()) {
24231 amit.gupta 646
 
26618 tejbeer 647
			last15daysMap = itemRepository
648
					.selectItems(FofoOrderItem.class, "id", "itemId", equalsMap, notEqualsMap, equalsJoinMap,
649
							notEqualsJoinMap, "quantity")
650
					.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
651
		}
25796 tejbeer 652
		LOGGER.info("last15daysMap" + last15daysMap);
25721 tejbeer 653
 
25796 tejbeer 654
		Map<Integer, TagListing> taglistingMap = tagListings.stream()
655
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
656
		List<Item> items = itemRepository.selectByIds(taglistingMap.keySet());
657
		Map<Integer, List<Item>> catalogIdItemMap = items.stream().collect(
658
				Collectors.groupingBy(x -> x.getCatalogItemId(), Collectors.mapping(y -> y, Collectors.toList())));
25797 tejbeer 659
		LOGGER.info("catalogIdItemMap");
24231 amit.gupta 660
 
25796 tejbeer 661
		Map<String, Object> equalsItemJoinMap = new HashMap<>();
25797 tejbeer 662
		equalsItemJoinMap.put("active", 1);
25800 tejbeer 663
		List<CatalogIdAggregateValue> tagListingCatalogIds = itemRepository.selectItems(TagListing.class, "id",
664
				"itemId", equalsMap, notEqualsMap, equalsItemJoinMap, notEqualsJoinMap, "tagId");
25797 tejbeer 665
		LOGGER.info("tagListingCatalogIds");
25796 tejbeer 666
		for (CatalogIdAggregateValue catalogIdAggregateValue : tagListingCatalogIds) {
667
			int catalogId = catalogIdAggregateValue.getCatalogId();
668
			Item item = catalogIdItemMap.get(catalogId).get(0);
669
			TagListing tagListing = taglistingMap.get(item.getId());
24231 amit.gupta 670
			CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
671
			if (!catalogListingMap.containsKey(catalogId)) {
672
				catalogListingModel = new CatalogListingModel();
673
				catalogListingModel.setCatalogId(catalogId);
674
				catalogListingModel.setDp(tagListing.getSellingPrice());
675
				catalogListingModel.setMop(tagListing.getMop());
676
				catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
25721 tejbeer 677
				if (plannedDetailMap != null) {
678
 
679
					Integer quantity = plannedDetailMap.get(catalogId);
680
					if (quantity != null) {
681
						catalogListingModel.setAllocatedQuantity(quantity);
682
					}
683
				}
684
 
25796 tejbeer 685
				if (last15daysMap != null) {
686
					Integer last15DaysSale = last15daysMap.get(catalogId);
687
 
25721 tejbeer 688
					if (last15DaysSale != null) {
689
						catalogListingModel.setLast15DaysSale(last15DaysSale);
690
					} else {
691
						catalogListingModel.setLast15DaysSale(0);
692
					}
693
				} else {
694
					catalogListingModel.setLast15DaysSale(0);
695
				}
696
 
24231 amit.gupta 697
				catalogListingModel.setBrand(item.getBrand());
698
				if (item.getCategoryId() == 10006) {
699
					catalogListingModel.setCategoryId(item.getCategoryId());
700
				}
25721 tejbeer 701
 
702
				FocusedModel fm = focusedModelMap.get(catalogId);
703
				if (fm != null) {
704
					catalogListingModel.setRecommendedQty(fm.getRecommendedQty());
705
					catalogListingModel.setMinimumQty(fm.getMinimumQty());
706
 
707
				} else {
708
					catalogListingModel.setRecommendedQty(0);
709
					catalogListingModel.setMinimumQty(0);
710
				}
711
 
24231 amit.gupta 712
				catalogListingMap.put(catalogId, catalogListingModel);
25721 tejbeer 713
 
24231 amit.gupta 714
			}
25736 tejbeer 715
			int itemAvailability = 0;
25796 tejbeer 716
			if (currentStockMap != null) {
717
				Integer qty = currentStockMap.get(catalogId);
25736 tejbeer 718
				itemAvailability = qty == null ? 0 : qty;
719
				catalogListingModel.setStockInHand(itemAvailability);
720
			} else {
721
				catalogListingModel.setStockInHand(0);
722
			}
24231 amit.gupta 723
			Integer inTransitQuantity = itemsInTransit.get(item.getId());
724
			int inTransitQty = (inTransitQuantity == null ? 0 : inTransitQuantity);
725
			catalogListingModel.setInTransitQuantity(catalogListingModel.getInTransitQuantity() + inTransitQty);
26179 tejbeer 726
			if (plannedDetailMap != null) {
26177 tejbeer 727
				if (plannedDetailMap.get(catalogId) != null) {
24231 amit.gupta 728
 
26177 tejbeer 729
					int remaining = plannedDetailMap.get(catalogId) - catalogListingModel.getLast15DaysSale()
730
							+ catalogListingModel.getStockInHand() + catalogListingModel.getInTransitQuantity();
731
					LOGGER.info("remaning" + remaining);
26176 tejbeer 732
 
26177 tejbeer 733
					if (remaining != 0) {
734
						catalogListingModel.setRemaining(remaining);
735
					} else {
736
						catalogListingModel.setRemaining(0);
737
					}
26176 tejbeer 738
				}
739
			}
23786 amit.gupta 740
		}
25721 tejbeer 741
 
25702 amit.gupta 742
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers();
23786 amit.gupta 743
		if (fofoId > 0) {
744
			CustomRetailer customRetailer = customRetailersMap.get(fofoId);
745
			model.addAttribute("retailerName",
746
					customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
747
			FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
748
			model.addAttribute("retailerId", customRetailer.getPartnerId());
749
			model.addAttribute("counterSize", fs.getCounterSize().toString());
23779 amit.gupta 750
		} else {
23786 amit.gupta 751
			model.addAttribute("counterSize", counterSize.toString());
23405 amit.gupta 752
		}
23786 amit.gupta 753
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
25702 amit.gupta 754
 
755
		List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
756
 
25721 tejbeer 757
		Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getMinimumQty,
24231 amit.gupta 758
				Comparator.reverseOrder());
25721 tejbeer 759
		LOGGER.info("monthlyPlanned" + monthlyPlanned);
25796 tejbeer 760
		model.addAttribute("catalogTagListings",
761
				catalogModelList.stream().sorted(firstCmp).collect(Collectors.toList()));
25702 amit.gupta 762
		model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
26177 tejbeer 763
		model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
26131 tejbeer 764
		model.addAttribute("previousPlanningMonth", LocalDate.now().minusMonths(1).getMonth());
765
		model.addAttribute("currentPlanningMonth", LocalDate.now().getMonth());
766
 
23786 amit.gupta 767
		model.addAttribute("customRetailers", customRetailers);
23796 amit.gupta 768
		model.addAttribute("totalAmount", totalAmount);
25721 tejbeer 769
		model.addAttribute("monthlyPlanned", monthlyPlanned);
23796 amit.gupta 770
		model.addAttribute("totalPcs", totalPcs);
23786 amit.gupta 771
		return "open-indent";
25796 tejbeer 772
 
23405 amit.gupta 773
	}
23796 amit.gupta 774
 
26131 tejbeer 775
	@RequestMapping(value = "/indent/loadIndentPreviousMonth")
776
	public String previousMonthLoadOpenIndent(HttpServletRequest request, Model model,
777
			@RequestParam(required = false, defaultValue = "0") int fofoId,
778
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
779
 
780
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
781
		Set<Integer> roleIds = loginDetails.getRoleIds();
782
		LOGGER.info("Counter size is {}", counterSize);
783
		LOGGER.info("Fofo Id is {}", fofoId);
784
		boolean isAdmin = roleManager.isAdmin(roleIds);
785
 
786
		List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
787
				.collect(Collectors.toList());
788
 
789
		Map<String, Object> equalsMap = new HashMap<>();
790
		equalsMap.put("categoryId", 10006);
791
		equalsMap.put("brand", brands);
792
		Map<String, List<?>> notEqualsMap = new HashMap<>();
793
 
794
		Map<String, List<?>> notEqualsJoinMap = new HashMap<>();
795
		Map<Integer, Integer> currentStockMap;
796
 
797
		if (!isAdmin && fofoId == 0) {
798
			fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
799
			Map<String, Object> equalsStockJoinMap = new HashMap<>();
800
			equalsStockJoinMap.put("fofoId", fofoId);
801
			currentStockMap = itemRepository
802
					.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
803
							equalsStockJoinMap, notEqualsJoinMap, "availability")
804
					.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
805
			LOGGER.info("currentStock");
806
		} else {
807
			if (fofoId == 0) {
808
 
809
				Map<String, Object> equalsStockJoinMap = new HashMap<>();
810
				equalsStockJoinMap.put("fofoId", fofoId);
811
 
812
				currentStockMap = itemRepository
813
						.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
814
								equalsStockJoinMap, notEqualsJoinMap, "availability")
815
						.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
816
 
817
			} else {
818
 
819
				Map<String, Object> equalsStockJoinMap = new HashMap<>();
820
				equalsStockJoinMap.put("fofoId", fofoId);
821
 
822
				currentStockMap = itemRepository
823
						.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
824
								equalsStockJoinMap, notEqualsJoinMap, "availability")
825
						.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
826
 
827
			}
828
		}
829
 
830
		LOGGER.info("currentStock" + currentStockMap);
831
 
832
		Map<Integer, Integer> itemsInTransit = null;
833
		List<TagListing> tagListings = tagListingRepository.selectAll(true);
834
		if (!isAdmin) {
835
			tagListings = new ArrayList<>(tagListings);
836
			List<Order> inTransitOrders = orderRepository.selectPendingGrnOrder(fofoId, validOrderStatusList);
837
			inTransitOrders = this.filterValidOrders(inTransitOrders);
838
			itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
839
					Collectors.summingInt(x -> x.getLineItem().getQuantity())));
840
		} else {
841
			itemsInTransit = new HashMap<>();
842
		}
843
 
844
		int totalPcs = 0;
845
 
846
		float totalAmount = 0;
847
		Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
848
 
849
		Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAll().stream()
850
				.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
851
 
852
		LocalDate currentMonthDate = LocalDate.now().minusMonths(1).withDayOfMonth(1);
853
		MonthlyPlanned monthlyPlanned = null;
854
		monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
855
		LOGGER.info("monthlyPlanned2" + monthlyPlanned);
856
		model.addAttribute("planningMonth", LocalDate.now().minusMonths(1).getMonth());
857
		model.addAttribute("previousPlanningMonth", LocalDate.now().minusMonths(1).getMonth());
858
		model.addAttribute("currentPlanningMonth", LocalDate.now().getMonth());
859
 
860
		Map<Integer, Integer> plannedDetailMap = null;
861
		if (monthlyPlanned != null) {
862
			plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
863
					.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
864
 
865
		}
866
 
867
		LOGGER.info("plannedDetailMap" + plannedDetailMap);
868
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
869
		List<Integer> fofoOrderIds = fofoOrderRepository
870
				.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
871
						curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1))
872
				.stream().map(x -> x.getId()).collect(Collectors.toList());
26721 tejbeer 873
 
26131 tejbeer 874
		LOGGER.info("fofoOrderIds" + fofoOrderIds);
875
		Map<String, Object> equalsJoinMap = new HashMap<>();
876
		equalsJoinMap.put("orderId", fofoOrderIds);
26721 tejbeer 877
		Map<Integer, Integer> lastMonthSaleMap = null;
878
		if (!fofoOrderIds.isEmpty()) {
879
			lastMonthSaleMap = itemRepository
880
					.selectItems(FofoOrderItem.class, "id", "itemId", equalsMap, notEqualsMap, equalsJoinMap,
881
							notEqualsJoinMap, "quantity")
882
					.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
883
		}
26131 tejbeer 884
		LOGGER.info("lastMonthSaleMap" + lastMonthSaleMap);
885
 
886
		Map<Integer, TagListing> taglistingMap = tagListings.stream()
887
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
888
		List<Item> items = itemRepository.selectByIds(taglistingMap.keySet());
889
		Map<Integer, List<Item>> catalogIdItemMap = items.stream().collect(
890
				Collectors.groupingBy(x -> x.getCatalogItemId(), Collectors.mapping(y -> y, Collectors.toList())));
891
		LOGGER.info("catalogIdItemMap");
892
 
893
		Map<String, Object> equalsItemJoinMap = new HashMap<>();
894
		equalsItemJoinMap.put("active", 1);
895
		List<CatalogIdAggregateValue> tagListingCatalogIds = itemRepository.selectItems(TagListing.class, "id",
896
				"itemId", equalsMap, notEqualsMap, equalsItemJoinMap, notEqualsJoinMap, "tagId");
897
		LOGGER.info("tagListingCatalogIds");
898
		for (CatalogIdAggregateValue catalogIdAggregateValue : tagListingCatalogIds) {
899
			int catalogId = catalogIdAggregateValue.getCatalogId();
900
			Item item = catalogIdItemMap.get(catalogId).get(0);
901
			TagListing tagListing = taglistingMap.get(item.getId());
902
			CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
903
			if (!catalogListingMap.containsKey(catalogId)) {
904
				catalogListingModel = new CatalogListingModel();
905
				catalogListingModel.setCatalogId(catalogId);
906
				catalogListingModel.setDp(tagListing.getSellingPrice());
907
				catalogListingModel.setMop(tagListing.getMop());
908
				catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
909
				if (plannedDetailMap != null) {
910
 
911
					Integer quantity = plannedDetailMap.get(catalogId);
912
					if (quantity != null) {
913
						catalogListingModel.setAllocatedQuantity(quantity);
914
					}
915
				}
916
 
917
				if (lastMonthSaleMap != null) {
918
					Integer lastMonthSale = lastMonthSaleMap.get(catalogId);
919
 
920
					if (lastMonthSale != null) {
921
						catalogListingModel.setLastMonthSaleMap(lastMonthSale);
922
					} else {
923
						catalogListingModel.setLastMonthSaleMap(0);
924
					}
925
				} else {
926
					catalogListingModel.setLast15DaysSale(0);
927
				}
928
 
929
				catalogListingModel.setBrand(item.getBrand());
930
				if (item.getCategoryId() == 10006) {
931
					catalogListingModel.setCategoryId(item.getCategoryId());
932
				}
933
 
934
				FocusedModel fm = focusedModelMap.get(catalogId);
935
				if (fm != null) {
936
					catalogListingModel.setRecommendedQty(fm.getRecommendedQty());
937
					catalogListingModel.setMinimumQty(fm.getMinimumQty());
938
 
939
				} else {
940
					catalogListingModel.setRecommendedQty(0);
941
					catalogListingModel.setMinimumQty(0);
942
				}
943
 
944
				catalogListingMap.put(catalogId, catalogListingModel);
945
 
946
			}
947
			int itemAvailability = 0;
948
			if (currentStockMap != null) {
949
				Integer qty = currentStockMap.get(catalogId);
950
				itemAvailability = qty == null ? 0 : qty;
951
				catalogListingModel.setStockInHand(itemAvailability);
952
			} else {
953
				catalogListingModel.setStockInHand(0);
954
			}
955
			Integer inTransitQuantity = itemsInTransit.get(item.getId());
956
			int inTransitQty = (inTransitQuantity == null ? 0 : inTransitQuantity);
957
			catalogListingModel.setInTransitQuantity(catalogListingModel.getInTransitQuantity() + inTransitQty);
958
 
959
		}
960
 
961
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers();
962
		if (fofoId > 0) {
963
			CustomRetailer customRetailer = customRetailersMap.get(fofoId);
964
			model.addAttribute("retailerName",
965
					customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
966
			FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
967
			model.addAttribute("retailerId", customRetailer.getPartnerId());
968
			model.addAttribute("counterSize", fs.getCounterSize().toString());
969
		} else {
970
			model.addAttribute("counterSize", counterSize.toString());
971
		}
972
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
973
 
974
		List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
975
 
976
		Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getMinimumQty,
977
				Comparator.reverseOrder());
978
		LOGGER.info("monthlyPlanned" + monthlyPlanned);
979
		model.addAttribute("catalogTagListings",
980
				catalogModelList.stream().sorted(firstCmp).collect(Collectors.toList()));
981
		model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
982
		model.addAttribute("previousMonth", true);
983
		model.addAttribute("freezed", true);
26177 tejbeer 984
		model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
26131 tejbeer 985
		model.addAttribute("customRetailers", customRetailers);
986
		model.addAttribute("totalAmount", totalAmount);
987
		model.addAttribute("monthlyPlanned", monthlyPlanned);
988
		model.addAttribute("totalPcs", totalPcs);
989
		return "open-indent";
990
 
991
	}
992
 
23796 amit.gupta 993
	private List<Order> filterValidOrders(List<Order> lastOrdersList) {
25812 amit.gupta 994
		int orderRemovedCount = 0;
23796 amit.gupta 995
		Iterator<Order> orderIterator = lastOrdersList.iterator();
996
		while (orderIterator.hasNext()) {
997
			Order o = orderIterator.next();
998
			if (o.getInvoiceNumber() != null) {
999
				try {
1000
					purchaseRepository.selectByPurchaseReferenceAndFofoId(o.getInvoiceNumber(), o.getRetailerId());
1001
					orderIterator.remove();
25812 amit.gupta 1002
					orderRemovedCount++;
23796 amit.gupta 1003
				} catch (Exception e) {
1004
 
1005
				}
1006
			}
1007
		}
25812 amit.gupta 1008
		LOGGER.info("Order removed count is {}", orderRemovedCount);
23796 amit.gupta 1009
		return lastOrdersList;
1010
	}
1011
 
24406 amit.gupta 1012
	@RequestMapping(value = "/indent/confirm-pause", method = RequestMethod.POST)
24410 amit.gupta 1013
	public String raisePO(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
1014
			throws Exception {
24406 amit.gupta 1015
		JSONArray jsonArray = new JSONArray(jsonArrayString);
24410 amit.gupta 1016
		for (int i = 0; i < jsonArray.length(); i++) {
24406 amit.gupta 1017
			JSONObject obj = jsonArray.getJSONObject(i);
25378 tejbeer 1018
 
24406 amit.gupta 1019
			TagListing tl = tagListingRepository.selectByItemId(obj.getInt("id"));
25378 tejbeer 1020
			if (tl == null) {
1021
				continue;
1022
			} else {
1023
				tl.setActive(obj.getBoolean("active"));
1024
				tagListingRepository.persist(tl);
1025
			}
24406 amit.gupta 1026
		}
24410 amit.gupta 1027
		model.addAttribute("response", true);
23855 amit.gupta 1028
		return "response";
1029
	}
24231 amit.gupta 1030
 
1031
	@RequestMapping(value = "/indent/create-po", method = RequestMethod.POST)
23796 amit.gupta 1032
	public String raisePO(HttpServletRequest request, Model model) throws Exception {
1033
		boolean success = false;
1034
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1035
		int fofoId = loginDetails.getFofoId();
1036
		List<ItemPriceQuantity> itemQuantities = this.getItemQuantities(fofoId);
1037
		CustomRetailer customRetailer = retailerService.getFofoRetailers(Arrays.asList(fofoId)).get(fofoId);
1038
		Client userClient = new UserClient().getClient();
24231 amit.gupta 1039
		double totalAmount = itemQuantities.stream().mapToDouble(x -> x.getQty() * x.getPrice()).sum();
23796 amit.gupta 1040
 
24231 amit.gupta 1041
		if (totalAmount > 0) {
23796 amit.gupta 1042
			userClient.addItemPricingToCart(customRetailer.getCartId(), itemQuantities);
1043
			User user = userRepository.selectById(loginDetails.getFofoId());
1044
			userClient = new UserClient().getClient();
1045
			LOGGER.info("Setting wallet amount in cart");
24231 amit.gupta 1046
			long transactionId = userClient.createOrders(user.getActiveCartId(), "", 0, "", 0, loginDetails.getFofoId(),
1047
					7890, OrderSource.WEBSITE.getValue(), true);
23796 amit.gupta 1048
			LOGGER.info("Creating wallet payment for transactionId - {}", transactionId);
1049
			createPayment(user, totalAmount, transactionId);
24231 amit.gupta 1050
			TransactionService.Client transactionClient = new TransactionClient().getClient();
23796 amit.gupta 1051
			transactionClient.changeTransactionStatus(transactionId, TransactionStatus.AUTHORIZED,
24231 amit.gupta 1052
					"Payment received for the order", PickUpType.RUNNER.getValue(), OrderType.B2B, OrderSource.WEBSITE);
23796 amit.gupta 1053
			transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
24231 amit.gupta 1054
					"Paid fully through wallet", PickUpType.RUNNER.getValue(), OrderType.B2B, OrderSource.WEBSITE);
23796 amit.gupta 1055
			LOGGER.info("Successfully created transaction: " + transactionId + " for amount: " + totalAmount);
1056
			transactionClient = new TransactionClient().getClient();
1057
			transactionClient.markOrderForRegisteredGstInvoice(Collections.singletonList(Long.valueOf(transactionId)));
1058
			try {
1059
				transactionClient.enqueueTransactionInfoEmail(transactionId);
1060
			} catch (Exception e1) {
1061
				e1.printStackTrace();
1062
				LOGGER.error("Unable to update status of transaction. Thrift Exception:", e1);
1063
			}
1064
			resetCart(transactionClient.getTransaction(transactionId));
1065
		}
1066
		model.addAttribute("response", mvcResponseSender.createResponseString(success));
1067
		return "response";
1068
	}
24231 amit.gupta 1069
 
1070
	private void createPayment(User user, double totalAmount, long transactionId)
1071
			throws NumberFormatException, PaymentException, TException {
23796 amit.gupta 1072
		List<Attribute> paymentAttributes = new ArrayList<Attribute>();
1073
		in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
1074
		paymentAttributes.add(new Attribute("payMethod", "7890"));
24231 amit.gupta 1075
		long paymentId = paymentClient.createPayment(user.getId(), totalAmount, WALLET_GATEWAY_ID, transactionId,
1076
				false);
1077
		paymentClient.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null,
1078
				PaymentStatus.SUCCESS, null, paymentAttributes);
23796 amit.gupta 1079
	}
24231 amit.gupta 1080
 
23796 amit.gupta 1081
	private List<ItemPriceQuantity> getItemQuantities(int fofoId) throws ProfitMandiBusinessException {
1082
		List<ItemPriceQuantity> itemQuantities = new ArrayList<>();
24231 amit.gupta 1083
		/*
1084
		 * Map<Integer, ItemIdAvailability> itemCisMap = null; List<ItemIdAvailability>
1085
		 * currentInventorySnapshots = currentInventorySnapshotRepository
1086
		 * .selectItemsStock(fofoId); itemCisMap =
1087
		 * currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
1088
		 * .collect(Collectors.toMap(x -> x.getItemId(), x -> x));
1089
		 * List<StockAllocationModel> stockAllocationList =
1090
		 * stockAllocationService.getStockAllocation(fofoId, true);
1091
		 * 
1092
		 * Map<Integer, StockAllocationModel> itemStockAllocationMap =
1093
		 * stockAllocationList.stream() .collect(Collectors.toMap(x -> x.catalogId(), x
1094
		 * -> x)); Map<Integer, Integer> itemsInTransit = null;
1095
		 * LOGGER.info("Item Stock Allocation Model Map {}", itemStockAllocationMap);
1096
		 * List<TagListing> tagListings = tagListingRepository.selectAll(false);
1097
		 * List<Order> inTransitOrders = orderRepository.selectOrders(fofoId,
1098
		 * validOrderStatusList); inTransitOrders =
1099
		 * this.filterValidOrders(inTransitOrders); itemsInTransit =
1100
		 * inTransitOrders.stream().collect(Collectors.groupingBy(x ->
1101
		 * x.getLineItem().getItemId(), Collectors.summingInt(x ->
1102
		 * x.getLineItem().getQuantity())));
1103
		 * 
1104
		 * Iterator<TagListing> iterator = tagListings.iterator();
1105
		 * 
1106
		 * int toBeOrdered = 0; while (iterator.hasNext()) { TagListing tagListing =
1107
		 * iterator.next(); LOGGER.info(" tagListing.setAllocatedQuantity {}",
1108
		 * tagListing.getAllocatedQuantity()); if
1109
		 * (!itemCisMap.containsKey(tagListing.getItemId()) &&
1110
		 * !itemStockAllocationMap.containsKey(tagListing.getItemId())) {
1111
		 * iterator.remove(); continue; } ItemIdAvailability itemIdAvailability =
1112
		 * itemCisMap.get(tagListing.getItemId());
1113
		 * tagListing.setStockInHand(itemIdAvailability == null ? 0 :
1114
		 * itemIdAvailability.getAvailability()); StockAllocationModel
1115
		 * stockAllocationModel = itemStockAllocationMap.get(tagListing.getItemId());
1116
		 * 
1117
		 * if (itemsInTransit.containsKey(tagListing.getItemId())) {
1118
		 * tagListing.setInTransitQuantity(itemsInTransit.get(tagListing.getItemId()));
1119
		 * } else { tagListing.setInTransitQuantity(0); } if (stockAllocationModel !=
1120
		 * null) { tagListing.setAllocatedQuantity(stockAllocationModel.getQuantity());
1121
		 * toBeOrdered = Math.max(tagListing.getAllocatedQuantity() -
1122
		 * tagListing.getInTransitQuantity() - tagListing.getStockInHand(), 0); if
1123
		 * (toBeOrdered > 0) { ItemPriceQuantity ipq = new ItemPriceQuantity();
1124
		 * ipq.setItemId(tagListing.getItemId()); ipq.setQty((long) toBeOrdered);
1125
		 * ipq.setPrice(tagListing.getSellingPrice()); itemQuantities.add(ipq); } } }
1126
		 */
23796 amit.gupta 1127
		return itemQuantities;
1128
 
1129
	}
24231 amit.gupta 1130
 
23796 amit.gupta 1131
	private long resetCart(Transaction transaction) {
1132
		long sum = 0;
1133
		Map<Long, Double> items = new HashMap<Long, Double>();
1134
		for (in.shop2020.model.v1.order.Order order : transaction.getOrders()) {
1135
			sum += order.getGvAmount();
1136
			for (LineItem lineitem : order.getLineitems()) {
1137
				Long itemId = lineitem.getItem_id();
1138
				Double quantity = items.get(itemId);
1139
				if (quantity == null) {
1140
					quantity = lineitem.getQuantity();
1141
				} else {
1142
					quantity = quantity + lineitem.getQuantity();
1143
				}
1144
				items.put(itemId, quantity);
1145
			}
1146
		}
1147
 
1148
		LOGGER.debug("Items to reset in cart are: " + items);
1149
 
1150
		try {
1151
			Client userClient = new UserClient().getClient();
1152
			userClient.resetCart(transaction.getShoppingCartid(), items);
1153
		} catch (TException e) {
1154
			LOGGER.error("Error while updating information in payment database.", e);
1155
		} catch (ShoppingCartException e) {
1156
			LOGGER.error("Error while reseting the cart in cart database.", e);
1157
		} catch (Exception e) {
1158
			LOGGER.error("Unexpected exception", e);
1159
		}
1160
		return sum;
1161
	}
1162
 
25721 tejbeer 1163
	@RequestMapping(value = "/getFocusedModel", method = RequestMethod.GET)
1164
	public String getFocusedModel(HttpServletRequest request,
1165
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1166
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1167
			throws ProfitMandiBusinessException {
25736 tejbeer 1168
 
1169
		long size = 0;
25721 tejbeer 1170
		List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
25736 tejbeer 1171
		size = focusedModelRepository.selectAllCount();
25721 tejbeer 1172
 
25736 tejbeer 1173
		if (!focusedModels.isEmpty()) {
1174
			Map<Integer, Item> itemMap = this.getItemByCatalogId(focusedModels);
25721 tejbeer 1175
 
25736 tejbeer 1176
			model.addAttribute("focusedModels", focusedModels);
1177
			model.addAttribute("itemMap", itemMap);
25721 tejbeer 1178
 
25736 tejbeer 1179
			model.addAttribute("start", offset + 1);
1180
			model.addAttribute("size", size);
1181
			model.addAttribute("url", "/getPaginatedFocusedModel");
1182
 
1183
			if (focusedModels.size() < limit) {
1184
				model.addAttribute("end", offset + focusedModels.size());
1185
			} else {
1186
				model.addAttribute("end", offset + limit);
1187
			}
1188
		} else {
1189
 
1190
			model.addAttribute("walletRequest", focusedModels);
1191
			model.addAttribute("size", size);
1192
 
1193
		}
1194
 
25721 tejbeer 1195
		return "focused_model";
1196
	}
1197
 
25736 tejbeer 1198
	@RequestMapping(value = "/getPaginatedFocusedModel", method = RequestMethod.GET)
1199
	public String getPaginatedFocusedModel(HttpServletRequest request,
1200
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1201
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1202
			throws ProfitMandiBusinessException {
1203
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
1204
		List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
1205
 
1206
		if (!focusedModels.isEmpty()) {
1207
			Map<Integer, Item> itemMap = this.getItemByCatalogId(focusedModels);
1208
 
1209
			model.addAttribute("focusedModels", focusedModels);
1210
			model.addAttribute("itemMap", itemMap);
1211
 
1212
			model.addAttribute("url", "/getPaginatedFocusedModel");
1213
		} else {
1214
			model.addAttribute("focusedModels", focusedModels);
1215
 
1216
		}
1217
		return "focused-model-paginated";
1218
	}
1219
 
25721 tejbeer 1220
	private Map<Integer, Item> getItemByCatalogId(List<FocusedModel> focusedModels) {
1221
		Map<Integer, Item> itemMap = new HashMap<>();
1222
		for (FocusedModel focusedModel : focusedModels) {
1223
			List<Item> items = itemRepository.selectAllByCatalogItemId(focusedModel.getCatalogId());
1224
			itemMap.put(items.get(0).getCatalogItemId(), items.get(0));
1225
		}
1226
 
1227
		return itemMap;
1228
	}
1229
 
1230
	@RequestMapping(value = "/focusedModel", method = RequestMethod.POST)
1231
	public String focusedModel(HttpServletRequest request, @RequestParam int catalogId, @RequestParam int recommended,
1232
			@RequestParam int minimumQty, Model model) throws ProfitMandiBusinessException {
1233
 
1234
		FocusedModel fm = new FocusedModel();
1235
		fm.setCatalogId(catalogId);
1236
		fm.setMinimumQty(minimumQty);
1237
		fm.setRecommendedQty(recommended);
1238
		fm.setCreatedTimestamp(LocalDateTime.now());
1239
		focusedModelRepository.persist(fm);
1240
		return "focused_model";
1241
	}
1242
 
1243
	@RequestMapping(value = "/removeItem", method = RequestMethod.DELETE)
1244
	public String removeFocusedModelItem(HttpServletRequest request,
1245
			@RequestParam(name = "catalogId", defaultValue = "0") int catalogId, Model model) throws Exception {
1246
 
1247
		focusedModelRepository.deleteById(catalogId);
1248
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
1249
		return "response";
1250
	}
25736 tejbeer 1251
 
25798 tejbeer 1252
	private List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
1253
		Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
25736 tejbeer 1254
 
25798 tejbeer 1255
		List<DBObject> mobileBrands = mongoClient.getMongoBrands(fofoId, "", 3);
1256
		List<BrandStockPrice> brandStockPrices = new ArrayList<>();
1257
 
1258
		mobileBrands.stream().forEach(x -> {
1259
			String brand = (String) x.get("name");
1260
			if (brandStockPricesMap.containsKey(brand)) {
1261
				BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
1262
				brandStockPrice.setBrandUrl((String) x.get("url"));
1263
				brandStockPrice.setRank(((Double) x.get("rank")).intValue());
1264
				brandStockPrices.add(brandStockPrice);
1265
			}
1266
		});
1267
 
1268
		return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted((x, y) -> x.getRank() - y.getRank())
1269
				.collect(Collectors.toList());
1270
	}
1271
 
26721 tejbeer 1272
	@RequestMapping(value = "/getPartnerAllocation")
1273
	public String getPartnerAllocation(HttpServletRequest request, Model model) throws Exception {
1274
 
1275
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1276
		AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
1277
 
1278
		Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
1279
 
1280
		List<Integer> fofoIds = pp.get(authUser.getId());
1281
 
1282
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
1283
		Map<Integer, FofoStore> fofoStoreMap = fofoStoreRepository.selectByRetailerIds(fofoIds).stream()
1284
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
1285
 
1286
		model.addAttribute("customRetailersMap", customRetailersMap);
1287
		model.addAttribute("fofoStoreMap", fofoStoreMap);
1288
		return "partners_allocation";
1289
 
1290
	}
1291
 
26846 tejbeer 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");
26853 tejbeer 1595
		sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/partnerPo/"+mp.getId());
26846 tejbeer 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
 
25721 tejbeer 1628
}