Subversion Repositories SmartDukaan

Rev

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