Subversion Repositories SmartDukaan

Rev

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

Rev 25702 Rev 25721
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.Serializable;
3
import java.io.Serializable;
-
 
4
import java.time.LocalDate;
-
 
5
import java.time.LocalDateTime;
4
import java.util.ArrayList;
6
import java.util.ArrayList;
5
import java.util.Arrays;
7
import java.util.Arrays;
6
import java.util.Collections;
8
import java.util.Collections;
7
import java.util.Comparator;
9
import java.util.Comparator;
8
import java.util.DoubleSummaryStatistics;
-
 
9
import java.util.HashMap;
10
import java.util.HashMap;
10
import java.util.HashSet;
11
import java.util.HashSet;
11
import java.util.Iterator;
12
import java.util.Iterator;
12
import java.util.List;
13
import java.util.List;
13
import java.util.Map;
14
import java.util.Map;
14
import java.util.Optional;
-
 
15
import java.util.Set;
15
import java.util.Set;
-
 
16
import java.util.function.Function;
16
import java.util.stream.Collectors;
17
import java.util.stream.Collectors;
17
 
18
 
18
import javax.servlet.http.HttpServletRequest;
19
import javax.servlet.http.HttpServletRequest;
19
 
20
 
20
import org.apache.commons.io.output.ByteArrayOutputStream;
21
import org.apache.commons.io.output.ByteArrayOutputStream;
Line 22... Line 23...
22
import org.apache.logging.log4j.Logger;
23
import org.apache.logging.log4j.Logger;
23
import org.apache.thrift.TException;
24
import org.apache.thrift.TException;
24
import org.json.JSONArray;
25
import org.json.JSONArray;
25
import org.json.JSONObject;
26
import org.json.JSONObject;
26
import org.springframework.beans.factory.annotation.Autowired;
27
import org.springframework.beans.factory.annotation.Autowired;
-
 
28
import org.springframework.beans.factory.annotation.Qualifier;
27
import org.springframework.core.io.ByteArrayResource;
29
import org.springframework.core.io.ByteArrayResource;
28
import org.springframework.http.HttpHeaders;
30
import org.springframework.http.HttpHeaders;
29
import org.springframework.http.HttpStatus;
31
import org.springframework.http.HttpStatus;
30
import org.springframework.http.ResponseEntity;
32
import org.springframework.http.ResponseEntity;
-
 
33
import org.springframework.mail.javamail.JavaMailSender;
31
import org.springframework.stereotype.Controller;
34
import org.springframework.stereotype.Controller;
32
import org.springframework.transaction.annotation.Transactional;
35
import org.springframework.transaction.annotation.Transactional;
33
import org.springframework.ui.Model;
36
import org.springframework.ui.Model;
34
import org.springframework.web.bind.annotation.RequestBody;
37
import org.springframework.web.bind.annotation.RequestBody;
35
import org.springframework.web.bind.annotation.RequestMapping;
38
import org.springframework.web.bind.annotation.RequestMapping;
36
import org.springframework.web.bind.annotation.RequestMethod;
39
import org.springframework.web.bind.annotation.RequestMethod;
37
import org.springframework.web.bind.annotation.RequestParam;
40
import org.springframework.web.bind.annotation.RequestParam;
38
 
41
 
39
import com.spice.profitmandi.common.enumuration.CounterSize;
42
import com.spice.profitmandi.common.enumuration.CounterSize;
40
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
43
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
41
import com.spice.profitmandi.common.model.BrandPerformance;
-
 
42
import com.spice.profitmandi.common.model.CatalogListingModel;
44
import com.spice.profitmandi.common.model.CatalogListingModel;
43
import com.spice.profitmandi.common.model.CustomRetailer;
45
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
46
import com.spice.profitmandi.common.model.FocusedModelShortageModel;
44
import com.spice.profitmandi.common.model.ItemIdAvailability;
47
import com.spice.profitmandi.common.model.ItemIdAvailability;
-
 
48
import com.spice.profitmandi.common.model.PlannedModel;
45
import com.spice.profitmandi.common.model.StockAllocationModel;
49
import com.spice.profitmandi.common.model.StockAllocationModel;
46
import com.spice.profitmandi.common.util.FileUtil;
50
import com.spice.profitmandi.common.util.FileUtil;
-
 
51
import com.spice.profitmandi.common.util.FormattingUtils;
-
 
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;
47
import com.spice.profitmandi.dao.entity.catalog.Item;
55
import com.spice.profitmandi.dao.entity.catalog.Item;
48
import com.spice.profitmandi.dao.entity.catalog.TagListing;
56
import com.spice.profitmandi.dao.entity.catalog.TagListing;
49
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
57
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
58
import com.spice.profitmandi.dao.entity.fofo.MonthlyPlanned;
-
 
59
import com.spice.profitmandi.dao.entity.fofo.PlannedDetail;
50
import com.spice.profitmandi.dao.entity.transaction.Order;
60
import com.spice.profitmandi.dao.entity.transaction.Order;
51
import com.spice.profitmandi.dao.entity.user.User;
61
import com.spice.profitmandi.dao.entity.user.User;
-
 
62
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
52
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
63
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
53
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
64
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
-
 
65
import com.spice.profitmandi.dao.repository.cs.CsService;
54
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
66
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
55
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
67
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
-
 
68
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
-
 
69
import com.spice.profitmandi.dao.repository.fofo.MonthlyPlannedRepository;
-
 
70
import com.spice.profitmandi.dao.repository.fofo.PlannedDetailRepository;
56
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
71
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
57
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
72
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
58
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
73
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
59
import com.spice.profitmandi.dao.repository.user.UserRepository;
74
import com.spice.profitmandi.dao.repository.user.UserRepository;
60
import com.spice.profitmandi.service.authentication.RoleManager;
75
import com.spice.profitmandi.service.authentication.RoleManager;
Line 98... Line 113...
98
 
113
 
99
	private final List<OrderStatus> partnerPendingOrderList = Arrays.asList(OrderStatus.ACCEPTED,
114
	private final List<OrderStatus> partnerPendingOrderList = Arrays.asList(OrderStatus.ACCEPTED,
100
			OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH,
115
			OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH,
101
			OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.SHIPPED_TO_LOGST,
116
			OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.SHIPPED_TO_LOGST,
102
			OrderStatus.REACHED_DESTINATION_CITY);
117
			OrderStatus.REACHED_DESTINATION_CITY);
103
	
118
 
104
	@Autowired
119
	@Autowired
105
	WalletService walletService;
120
	WalletService walletService;
106
 
121
 
107
	@Autowired
122
	@Autowired
-
 
123
	private JavaMailSender googleMailSender;
-
 
124
 
-
 
125
	@Autowired
108
	private CookiesProcessor cookiesProcessor;
126
	private CookiesProcessor cookiesProcessor;
109
 
127
 
110
	@Autowired
128
	@Autowired
111
	private UserWalletRepository userWalletRepository;
129
	private UserWalletRepository userWalletRepository;
112
 
130
 
Line 139... Line 157...
139
 
157
 
140
	@Autowired
158
	@Autowired
141
	private MVCResponseSender mvcResponseSender;
159
	private MVCResponseSender mvcResponseSender;
142
 
160
 
143
	@Autowired
161
	@Autowired
-
 
162
	private FocusedModelRepository focusedModelRepository;
-
 
163
 
-
 
164
	@Autowired
-
 
165
	private MonthlyPlannedRepository monthlyPlannedRepository;
-
 
166
 
-
 
167
	@Autowired
-
 
168
	private FofoOrderRepository fofoOrderRepository;
-
 
169
	@Autowired
-
 
170
	private PlannedDetailRepository plannedDetailRepository;
-
 
171
	@Autowired
144
	RoleManager roleManager;
172
	RoleManager roleManager;
145
 
173
 
-
 
174
	@Autowired
-
 
175
	CsService csService;
-
 
176
 
-
 
177
	/*
-
 
178
	 * @RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
-
 
179
	 * public String saveOpenIndent(HttpServletRequest request, Model model,
-
 
180
	 * 
-
 
181
	 * @RequestBody List<StockAllocationModel>
-
 
182
	 * stockAllocationModelList, @RequestParam int fofoId,
-
 
183
	 * 
-
 
184
	 * @RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws
-
 
185
	 * Exception { LoginDetails loginDetails =
-
 
186
	 * cookiesProcessor.getCookiesObject(request); boolean response = false; if
-
 
187
	 * (fofoId > 0) { FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
188
	 * stockAllocationModelList.forEach(x -> { x.setFofoId(fofoId);
-
 
189
	 * x.setCounterSize(fs.getCounterSize()); }); } else {
-
 
190
	 * stockAllocationModelList.forEach(x -> { x.setFofoId(fofoId);
-
 
191
	 * x.setCounterSize(counterSize); }); } if
-
 
192
	 * (roleManager.isAdmin(loginDetails.getRoleIds())) { response =
-
 
193
	 * stockAllocationService.addToAllocation(stockAllocationModelList);
-
 
194
	 * model.addAttribute("response",
-
 
195
	 * mvcResponseSender.createResponseString(response)); } return "response"; }
-
 
196
	 */
146
	@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
197
	@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
147
	public String saveOpenIndent(HttpServletRequest request, Model model,
198
	public String saveOpenIndent(HttpServletRequest request, Model model, @RequestParam int catalogId,
148
			@RequestBody List<StockAllocationModel> stockAllocationModelList, @RequestParam int fofoId,
-
 
149
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
199
			@RequestParam int itemQty) throws Exception {
150
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
200
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
201
		LocalDate currentMonthdate = LocalDate.now().withDayOfMonth(1);
-
 
202
		LOGGER.info("currentMonthdate" + currentMonthdate);
-
 
203
		LOGGER.info("catalogId" + catalogId);
-
 
204
		LOGGER.info("itemQty" + itemQty);
-
 
205
 
-
 
206
		MonthlyPlanned monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(loginDetails.getFofoId(),
151
		boolean response = false;
207
				currentMonthdate);
-
 
208
 
152
		if (fofoId > 0) {
209
		if (monthlyPlanned == null) {
-
 
210
			monthlyPlanned = new MonthlyPlanned();
153
			FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
211
			monthlyPlanned.setFofoId(loginDetails.getFofoId());
-
 
212
			monthlyPlanned.setYearMonth(currentMonthdate);
154
			stockAllocationModelList.forEach(x -> {
213
			monthlyPlannedRepository.persist(monthlyPlanned);
-
 
214
			PlannedDetail pd = new PlannedDetail();
155
				x.setFofoId(fofoId);
215
			pd.setCatalogId(catalogId);
-
 
216
			pd.setPlannedId(monthlyPlanned.getId());
-
 
217
			pd.setQuantity(itemQty);
156
				x.setCounterSize(fs.getCounterSize());
218
			pd.setUpdatedTimestamp(LocalDateTime.now());
-
 
219
			plannedDetailRepository.persist(pd);
157
			});
220
 
158
		} else {
221
		} else {
-
 
222
			PlannedDetail plannedDetail = plannedDetailRepository.selectByPlannedIdCatalogId(monthlyPlanned.getId(),
-
 
223
					catalogId);
159
			stockAllocationModelList.forEach(x -> {
224
			if (plannedDetail == null) {
-
 
225
				plannedDetail = new PlannedDetail();
160
				x.setFofoId(fofoId);
226
				plannedDetail.setCatalogId(catalogId);
-
 
227
				plannedDetail.setPlannedId(monthlyPlanned.getId());
161
				x.setCounterSize(counterSize);
228
				plannedDetail.setQuantity(itemQty);
-
 
229
				plannedDetail.setUpdatedTimestamp(LocalDateTime.now());
-
 
230
				plannedDetailRepository.persist(plannedDetail);
162
			});
231
			} else if (itemQty == 0) {
-
 
232
				plannedDetailRepository.delete(plannedDetail);
163
		}
233
 
-
 
234
			} else {
164
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
235
				plannedDetail.setCatalogId(catalogId);
165
			response = stockAllocationService.addToAllocation(stockAllocationModelList);
236
				plannedDetail.setQuantity(itemQty);
166
			model.addAttribute("response", mvcResponseSender.createResponseString(response));
237
				plannedDetail.setUpdatedTimestamp(LocalDateTime.now());
-
 
238
			}
-
 
239
 
167
		}
240
		}
-
 
241
 
-
 
242
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
243
 
-
 
244
		return "response";
-
 
245
	}
-
 
246
 
-
 
247
	@RequestMapping(value = "/open-indent/confirm", method = RequestMethod.POST)
-
 
248
	public String confirmOpenIndent(HttpServletRequest request, Model model) throws Exception {
-
 
249
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
250
		int fofoId = loginDetails.getFofoId();
-
 
251
		CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
-
 
252
		MonthlyPlanned monthlyPlanned = monthlyPlannedRepository.selectByFofoId(fofoId);
-
 
253
 
-
 
254
		LOGGER.info("monthlyPlanned" + monthlyPlanned);
-
 
255
		List<PlannedDetail> plannedDetails = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId());
-
 
256
 
-
 
257
		List<PlannedModel> plannedModel = new ArrayList<>();
-
 
258
		for (PlannedDetail plannedDetail : plannedDetails) {
-
 
259
 
-
 
260
			List<Item> items = itemRepository.selectAllByCatalogItemId(plannedDetail.getCatalogId());
-
 
261
			String itemDesription = items.get(0).getItemDescriptionNoColor();
-
 
262
			PlannedModel pm = new PlannedModel();
-
 
263
			pm.setItemDescription(itemDesription);
-
 
264
			pm.setStoreName(customRetailer.getBusinessName());
-
 
265
			pm.setQty(plannedDetail.getQuantity());
-
 
266
			pm.setFofoId(loginDetails.getFofoId());
-
 
267
			plannedModel.add(pm);
-
 
268
			LOGGER.info("plannedModel" + plannedModel);
-
 
269
 
-
 
270
		}
-
 
271
		List<String> emails = csService.getAuthUserByPartnerId(fofoId);
-
 
272
		emails.add(customRetailer.getEmail());
-
 
273
		LOGGER.info("emails" + emails);
-
 
274
		ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
-
 
275
				Arrays.asList("Partner Id", "Partner Name", "Model Name", "Qty"),
-
 
276
				plannedModel.stream()
-
 
277
						.map(x -> Arrays.asList(x.getFofoId(), x.getStoreName(), x.getItemDescription(), x.getQty()))
-
 
278
						.collect(Collectors.toList()));
-
 
279
		LOGGER.info("baos" + baos);
-
 
280
		Utils.sendMailWithAttachments(googleMailSender, emails.toArray(new String[emails.size()]), null,
-
 
281
				"Planned Indent", "PFA",
-
 
282
				new Attachment[] { new Attachment("PlannedIndent.csv", new ByteArrayResource(baos.toByteArray())), });
-
 
283
 
-
 
284
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
168
		return "response";
285
		return "response";
169
	}
286
	}
170
 
287
 
171
	@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
288
	@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
172
	public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
289
	public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
Line 174... Line 291...
174
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
291
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
175
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
292
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
176
		Set<Integer> roleIds = loginDetails.getRoleIds();
293
		Set<Integer> roleIds = loginDetails.getRoleIds();
177
		LOGGER.info("Counter size is {}", counterSize);
294
		LOGGER.info("Counter size is {}", counterSize);
178
		LOGGER.info("Fofo Id is {}", fofoId);
295
		LOGGER.info("Fofo Id is {}", fofoId);
179
		if (roleManager.isAdmin(roleIds) || loginDetails.getFofoId()==fofoId) {
296
		if (roleManager.isAdmin(roleIds) || loginDetails.getFofoId() == fofoId) {
180
			List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
297
			List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
181
					.collect(Collectors.toList());
298
					.collect(Collectors.toList());
182
			Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
299
			Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
183
 
300
 
184
			List<StockAllocationModel> stockAllocationList = stockAllocationService.getStockAllocation(counterSize,
301
			List<StockAllocationModel> stockAllocationList = stockAllocationService.getStockAllocation(counterSize,
Line 316... Line 433...
316
		Set<Integer> roleIds = loginDetails.getRoleIds();
433
		Set<Integer> roleIds = loginDetails.getRoleIds();
317
		LOGGER.info("Counter size is {}", counterSize);
434
		LOGGER.info("Counter size is {}", counterSize);
318
		LOGGER.info("Fofo Id is {}", fofoId);
435
		LOGGER.info("Fofo Id is {}", fofoId);
319
		boolean isAdmin = !roleManager.isAdmin(roleIds);
436
		boolean isAdmin = !roleManager.isAdmin(roleIds);
320
		Map<Integer, ItemIdAvailability> itemCisMap = null;
437
		Map<Integer, ItemIdAvailability> itemCisMap = null;
321
		if (!isAdmin && fofoId==0) {
438
		if (!isAdmin && fofoId == 0) {
322
			fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
439
			fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
323
			List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
440
			List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
324
					.selectItemsStock(fofoId);
441
					.selectItemsStock(fofoId);
325
			itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
442
			itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
326
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
443
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
Line 363... Line 480...
363
		Iterator<TagListing> iterator = tagListings.iterator();
480
		Iterator<TagListing> iterator = tagListings.iterator();
364
		int totalPcs = 0;
481
		int totalPcs = 0;
365
		int toBeOrdered = 0;
482
		int toBeOrdered = 0;
366
		float totalAmount = 0;
483
		float totalAmount = 0;
367
		Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
484
		Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
-
 
485
		Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAll().stream()
-
 
486
				.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
368
		
487
 
-
 
488
		Map<Integer, Item> items = itemRepository
369
		Map<Integer, Item> items = itemRepository.selectByIds(tagListings.stream().map(x->x.getItemId()).collect(Collectors.toSet())).stream().
489
				.selectByIds(tagListings.stream().map(x -> x.getItemId()).collect(Collectors.toSet())).stream()
370
				collect(Collectors.toMap(x->x.getId(), x->x));
490
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
-
 
491
 
-
 
492
		Map<Integer, Integer> fofoOrderMap = fofoOrderRepository
-
 
493
				.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(), LocalDateTime.now().minusDays(15),
-
 
494
						LocalDateTime.now())
-
 
495
				.stream()
-
 
496
				.collect(Collectors.toMap(x -> x.getOrderItem().getItemId(), x -> x.getOrderItem().getQuantity()));
-
 
497
		Map<Integer, Integer> last15DaysMap = null;
-
 
498
		if (!fofoOrderMap.isEmpty()) {
-
 
499
			last15DaysMap = itemRepository.selectByIds(fofoOrderMap.keySet()).stream().collect(Collectors
-
 
500
					.groupingBy(x -> x.getCatalogItemId(), Collectors.summingInt(x -> fofoOrderMap.get(x.getId()))));
-
 
501
		}
-
 
502
 
-
 
503
		MonthlyPlanned monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(loginDetails.getFofoId(),
-
 
504
				LocalDate.now().withDayOfMonth(1));
-
 
505
		Map<Integer, Integer> plannedDetailMap = null;
-
 
506
		if (monthlyPlanned != null) {
-
 
507
			plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
-
 
508
					.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
-
 
509
 
-
 
510
		}
-
 
511
 
371
		while (iterator.hasNext()) {
512
		while (iterator.hasNext()) {
372
			TagListing tagListing = iterator.next();
513
			TagListing tagListing = iterator.next();
373
 
514
 
374
			Item item = items.get(tagListing.getItemId());
515
			Item item = items.get(tagListing.getItemId());
375
			// itemRepository.select
516
			// itemRepository.select
Line 384... Line 525...
384
						|| itemStockAllocationMap.containsKey(tagListing.getItemId()))) {
525
						|| itemStockAllocationMap.containsKey(tagListing.getItemId()))) {
385
					iterator.remove();
526
					iterator.remove();
386
					continue;
527
					continue;
387
				}
528
				}
388
			}
529
			}
-
 
530
 
389
			int catalogId = item.getCatalogItemId();
531
			int catalogId = item.getCatalogItemId();
390
 
532
 
391
			CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
533
			CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
392
			if (!catalogListingMap.containsKey(catalogId)) {
534
			if (!catalogListingMap.containsKey(catalogId)) {
393
				catalogListingModel = new CatalogListingModel();
535
				catalogListingModel = new CatalogListingModel();
Line 395... Line 537...
395
				catalogListingModel.setDp(tagListing.getSellingPrice());
537
				catalogListingModel.setDp(tagListing.getSellingPrice());
396
				catalogListingModel.setMop(tagListing.getMop());
538
				catalogListingModel.setMop(tagListing.getMop());
397
				catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
539
				catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
398
				StockAllocationModel stockAllocationModel = itemStockAllocationMap.get(item.getCatalogItemId());
540
				StockAllocationModel stockAllocationModel = itemStockAllocationMap.get(item.getCatalogItemId());
399
				int stockAllocationQuantity = stockAllocationModel == null ? 0 : stockAllocationModel.getQuantity();
541
				int stockAllocationQuantity = stockAllocationModel == null ? 0 : stockAllocationModel.getQuantity();
-
 
542
				if (plannedDetailMap != null) {
-
 
543
 
-
 
544
					Integer quantity = plannedDetailMap.get(catalogId);
-
 
545
					if (quantity != null) {
-
 
546
						catalogListingModel.setAllocatedQuantity(quantity);
-
 
547
					} else {
-
 
548
 
-
 
549
						catalogListingModel.setAllocatedQuantity(stockAllocationQuantity);
-
 
550
					}
-
 
551
				} else {
400
				catalogListingModel.setAllocatedQuantity(stockAllocationQuantity);
552
					catalogListingModel.setAllocatedQuantity(stockAllocationQuantity);
-
 
553
				}
-
 
554
				if (last15DaysMap != null) {
-
 
555
					Integer last15DaysSale = last15DaysMap.get(catalogId);
-
 
556
 
-
 
557
					if (last15DaysSale != null) {
-
 
558
						catalogListingModel.setLast15DaysSale(last15DaysSale);
-
 
559
					} else {
-
 
560
						catalogListingModel.setLast15DaysSale(0);
-
 
561
					}
-
 
562
				} else {
-
 
563
					catalogListingModel.setLast15DaysSale(0);
-
 
564
				}
-
 
565
 
401
				catalogListingModel.setToBeOrdered(stockAllocationQuantity);
566
				catalogListingModel.setToBeOrdered(stockAllocationQuantity);
402
				catalogListingModel.setBrand(item.getBrand());
567
				catalogListingModel.setBrand(item.getBrand());
403
				if (item.getCategoryId() == 10006) {
568
				if (item.getCategoryId() == 10006) {
404
					catalogListingModel.setCategoryId(item.getCategoryId());
569
					catalogListingModel.setCategoryId(item.getCategoryId());
405
				}
570
				}
-
 
571
 
-
 
572
				FocusedModel fm = focusedModelMap.get(catalogId);
-
 
573
				if (fm != null) {
-
 
574
					catalogListingModel.setRecommendedQty(fm.getRecommendedQty());
-
 
575
					catalogListingModel.setMinimumQty(fm.getMinimumQty());
-
 
576
 
-
 
577
				} else {
-
 
578
					catalogListingModel.setRecommendedQty(0);
-
 
579
					catalogListingModel.setMinimumQty(0);
-
 
580
				}
-
 
581
 
406
				catalogListingMap.put(catalogId, catalogListingModel);
582
				catalogListingMap.put(catalogId, catalogListingModel);
-
 
583
 
407
			}
584
			}
408
 
585
 
409
			ItemIdAvailability itemIdAvailability = itemCisMap.get(tagListing.getItemId());
586
			ItemIdAvailability itemIdAvailability = itemCisMap.get(tagListing.getItemId());
410
			int itemAvailability = itemIdAvailability == null ? 0 : itemIdAvailability.getAvailability();
587
			int itemAvailability = itemIdAvailability == null ? 0 : itemIdAvailability.getAvailability();
411
			catalogListingModel.setStockInHand(catalogListingModel.getStockInHand() + itemAvailability);
588
			catalogListingModel.setStockInHand(catalogListingModel.getStockInHand() + itemAvailability);
Line 417... Line 594...
417
			if (catalogListingModel.getAllocatedQuantity() > 0) {
594
			if (catalogListingModel.getAllocatedQuantity() > 0) {
418
				toBeOrdered = Math.max(catalogListingModel.getToBeOrdered() - inTransitQty - itemAvailability, 0);
595
				toBeOrdered = Math.max(catalogListingModel.getToBeOrdered() - inTransitQty - itemAvailability, 0);
419
				catalogListingModel.setToBeOrdered(toBeOrdered);
596
				catalogListingModel.setToBeOrdered(toBeOrdered);
420
			}
597
			}
421
		}
598
		}
422
		
599
 
423
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers();
600
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers();
424
		if (fofoId > 0) {
601
		if (fofoId > 0) {
425
			CustomRetailer customRetailer = customRetailersMap.get(fofoId);
602
			CustomRetailer customRetailer = customRetailersMap.get(fofoId);
426
			model.addAttribute("retailerName",
603
			model.addAttribute("retailerName",
427
					customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
604
					customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
Line 432... Line 609...
432
			model.addAttribute("counterSize", counterSize.toString());
609
			model.addAttribute("counterSize", counterSize.toString());
433
		}
610
		}
434
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
611
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
435
 
612
 
436
		List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
613
		List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
-
 
614
		List<CatalogListingModel> catalogModel = catalogModelList.stream()
-
 
615
				.filter(x -> !(x.getBrand().equals("Live Demo"))).collect(Collectors.toList());
437
 
616
 
-
 
617
		LOGGER.info("item" + catalogModelList);
438
		Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getToBeOrdered,
618
		Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getMinimumQty,
439
				Comparator.reverseOrder());
619
				Comparator.reverseOrder());
440
		model.addAttribute("catalogTagListings",
620
		LOGGER.info("monthlyPlanned" + monthlyPlanned);
441
				catalogModelList.stream().sorted(firstCmp).collect(Collectors.toList()));
621
		model.addAttribute("catalogTagListings", catalogModel.stream().sorted(firstCmp).collect(Collectors.toList()));
442
		model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
622
		model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
443
		model.addAttribute("customRetailers", customRetailers);
623
		model.addAttribute("customRetailers", customRetailers);
444
		model.addAttribute("totalAmount", totalAmount);
624
		model.addAttribute("totalAmount", totalAmount);
-
 
625
		model.addAttribute("monthlyPlanned", monthlyPlanned);
445
		model.addAttribute("totalPcs", totalPcs);
626
		model.addAttribute("totalPcs", totalPcs);
446
		return "open-indent";
627
		return "open-indent";
447
	}
628
	}
448
 
629
 
449
	private List<Order> filterValidOrders(List<Order> lastOrdersList) {
630
	private List<Order> filterValidOrders(List<Order> lastOrdersList) {
Line 612... Line 793...
612
			LOGGER.error("Unexpected exception", e);
793
			LOGGER.error("Unexpected exception", e);
613
		}
794
		}
614
		return sum;
795
		return sum;
615
	}
796
	}
616
 
797
 
-
 
798
	@RequestMapping(value = "/getFocusedModel", method = RequestMethod.GET)
-
 
799
	public String getFocusedModel(HttpServletRequest request,
-
 
800
			@RequestParam(name = "offset", defaultValue = "0") int offset,
-
 
801
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
-
 
802
			throws ProfitMandiBusinessException {
-
 
803
		List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
-
 
804
 
-
 
805
		Map<Integer, Item> itemMap = this.getItemByCatalogId(focusedModels);
-
 
806
 
-
 
807
		model.addAttribute("focusedModels", focusedModels);
-
 
808
		model.addAttribute("itemMap", itemMap);
-
 
809
 
-
 
810
		return "focused_model";
-
 
811
	}
-
 
812
 
-
 
813
	private Map<Integer, Item> getItemByCatalogId(List<FocusedModel> focusedModels) {
-
 
814
		Map<Integer, Item> itemMap = new HashMap<>();
-
 
815
		for (FocusedModel focusedModel : focusedModels) {
-
 
816
			List<Item> items = itemRepository.selectAllByCatalogItemId(focusedModel.getCatalogId());
-
 
817
			itemMap.put(items.get(0).getCatalogItemId(), items.get(0));
-
 
818
		}
-
 
819
 
-
 
820
		return itemMap;
-
 
821
	}
-
 
822
 
-
 
823
	@RequestMapping(value = "/focusedModel", method = RequestMethod.POST)
-
 
824
	public String focusedModel(HttpServletRequest request, @RequestParam int catalogId, @RequestParam int recommended,
-
 
825
			@RequestParam int minimumQty, Model model) throws ProfitMandiBusinessException {
-
 
826
 
-
 
827
		FocusedModel fm = new FocusedModel();
-
 
828
		fm.setCatalogId(catalogId);
-
 
829
		fm.setMinimumQty(minimumQty);
-
 
830
		fm.setRecommendedQty(recommended);
-
 
831
		fm.setCreatedTimestamp(LocalDateTime.now());
-
 
832
		focusedModelRepository.persist(fm);
-
 
833
		return "focused_model";
-
 
834
	}
-
 
835
 
-
 
836
	@RequestMapping(value = "/removeItem", method = RequestMethod.DELETE)
-
 
837
	public String removeFocusedModelItem(HttpServletRequest request,
-
 
838
			@RequestParam(name = "catalogId", defaultValue = "0") int catalogId, Model model) throws Exception {
-
 
839
 
-
 
840
		focusedModelRepository.deleteById(catalogId);
-
 
841
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
842
		return "response";
-
 
843
	}
617
}
844
}
618
845