Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
23784 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
23883 ashik.ali 3
import java.util.ArrayList;
23784 ashik.ali 4
import java.util.HashMap;
5
import java.util.HashSet;
6
import java.util.List;
7
import java.util.Map;
8
import java.util.Set;
9
 
10
import javax.servlet.http.HttpServletRequest;
11
 
12
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.Logger;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.beans.factory.annotation.Qualifier;
16
import org.springframework.stereotype.Controller;
17
import org.springframework.transaction.annotation.Transactional;
18
import org.springframework.ui.Model;
19
import org.springframework.web.bind.annotation.RequestBody;
20
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestMethod;
22
import org.springframework.web.bind.annotation.RequestParam;
23
 
24
import com.spice.profitmandi.common.enumuration.ItemType;
25
import com.spice.profitmandi.common.enumuration.ScanType;
26
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
27
import com.spice.profitmandi.common.model.CreateItemRequest;
23883 ashik.ali 28
import com.spice.profitmandi.common.model.InstructionItemRequest;
23784 ashik.ali 29
import com.spice.profitmandi.common.model.ProfitMandiConstants;
30
import com.spice.profitmandi.common.model.ScanInItemRequest;
23883 ashik.ali 31
import com.spice.profitmandi.common.model.ScanInPartnerItemRequest;
23784 ashik.ali 32
import com.spice.profitmandi.common.model.ScanOutItemRequest;
23883 ashik.ali 33
import com.spice.profitmandi.common.model.ScanOutPartnerItemRequest;
23784 ashik.ali 34
import com.spice.profitmandi.dao.entity.nonbillable.AdminCurrentInventorySnapshot;
35
import com.spice.profitmandi.dao.entity.nonbillable.AdminDeliveryNote;
23883 ashik.ali 36
import com.spice.profitmandi.dao.entity.nonbillable.InstructionItem;
37
import com.spice.profitmandi.dao.entity.nonbillable.InstructionItemDetail;
23784 ashik.ali 38
import com.spice.profitmandi.dao.entity.nonbillable.Item;
39
import com.spice.profitmandi.dao.entity.nonbillable.PartnerCurrentInventorySnapshot;
23883 ashik.ali 40
import com.spice.profitmandi.dao.entity.nonbillable.ScanOutPartnerItem;
23784 ashik.ali 41
import com.spice.profitmandi.dao.entity.nonbillable.Vendor;
42
import com.spice.profitmandi.dao.entity.nonbillable.Warehouse;
23883 ashik.ali 43
import com.spice.profitmandi.dao.entity.user.Address;
23984 govind 44
import com.spice.profitmandi.dao.enumuration.dtr.RoleType;
23883 ashik.ali 45
import com.spice.profitmandi.dao.enumuration.nonbillable.InstructionItemStatus;
46
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
23984 govind 47
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
23784 ashik.ali 48
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
23984 govind 49
import com.spice.profitmandi.dao.repository.dtr.UserRoleRepository;
23784 ashik.ali 50
import com.spice.profitmandi.dao.repository.nonbillable.AdminCurrentInventorySnapshotRepository;
23883 ashik.ali 51
import com.spice.profitmandi.dao.repository.nonbillable.AdminDeliveryNoteDetailRepository;
23784 ashik.ali 52
import com.spice.profitmandi.dao.repository.nonbillable.AdminDeliveryNoteRepository;
53
import com.spice.profitmandi.dao.repository.nonbillable.AdminInventoryItemRepository;
23883 ashik.ali 54
import com.spice.profitmandi.dao.repository.nonbillable.InstructionItemDetailRepository;
55
import com.spice.profitmandi.dao.repository.nonbillable.InstructionItemRepository;
23784 ashik.ali 56
import com.spice.profitmandi.dao.repository.nonbillable.ItemRepository;
57
import com.spice.profitmandi.dao.repository.nonbillable.PartnerCurrentInventorySnapshotRepository;
23883 ashik.ali 58
import com.spice.profitmandi.dao.repository.nonbillable.PartnerInventoryItemRepository;
59
import com.spice.profitmandi.dao.repository.nonbillable.ScanOutPartnerItemRepository;
23784 ashik.ali 60
import com.spice.profitmandi.dao.repository.nonbillable.UserWarehouseRepository;
61
import com.spice.profitmandi.dao.repository.nonbillable.VendorRepository;
62
import com.spice.profitmandi.dao.repository.nonbillable.WarehouseRepository;
23883 ashik.ali 63
import com.spice.profitmandi.dao.repository.user.AddressRepository;
23784 ashik.ali 64
import com.spice.profitmandi.service.nonbillable.InventoryService;
65
import com.spice.profitmandi.service.user.RetailerService;
23984 govind 66
import com.spice.profitmandi.service.user.UserService;
23784 ashik.ali 67
import com.spice.profitmandi.web.model.LoginDetails;
68
import com.spice.profitmandi.web.util.CookiesProcessor;
69
 
70
@Controller
71
@Transactional
72
public class ItemController {
23984 govind 73
 
23784 ashik.ali 74
	private static final Logger LOGGER = LogManager.getLogger(ItemController.class);
23984 govind 75
 
23784 ashik.ali 76
	@Autowired
77
	@Qualifier("nonbillableItemRepository")
78
	private ItemRepository itemRepository;
23984 govind 79
 
23784 ashik.ali 80
	@Autowired
81
	@Qualifier("nonbillableInventoryService")
82
	private InventoryService inventoryService;
83
	@Autowired
23984 govind 84
	private RoleRepository roleRepository;
85
	@Autowired
86
	private UserService userService;
87
	@Autowired
23784 ashik.ali 88
	private AdminCurrentInventorySnapshotRepository adminCurrentInventorySnapshotRepository;
23984 govind 89
 
23784 ashik.ali 90
	@Autowired
91
	private AdminInventoryItemRepository adminInventoryItemRepository;
23984 govind 92
 
23784 ashik.ali 93
	@Autowired
94
	private PartnerCurrentInventorySnapshotRepository partnerCurrentInventorySnapshotRepository;
23984 govind 95
 
23784 ashik.ali 96
	@Autowired
97
	private VendorRepository vendorRepository;
23984 govind 98
 
23784 ashik.ali 99
	@Autowired
100
	private WarehouseRepository warehouseRepository;
23984 govind 101
 
23784 ashik.ali 102
	@Autowired
103
	private RetailerService retailerService;
23984 govind 104
 
23784 ashik.ali 105
	@Autowired
106
	@Qualifier(value = "userRepository")
107
	private UserRepository userRepository;
108
	@Autowired
23984 govind 109
	private UserRoleRepository userRoleRepository;
110
	@Autowired
23784 ashik.ali 111
	private UserWarehouseRepository userWarehouseRepository;
23984 govind 112
 
23784 ashik.ali 113
	@Autowired
114
	private AdminDeliveryNoteRepository adminDeliveryNoteRepository;
23883 ashik.ali 115
 
116
	@Autowired
23984 govind 117
	private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
23883 ashik.ali 118
 
119
	@Autowired
23984 govind 120
	private AddressRepository addressRepository;
23883 ashik.ali 121
 
122
	@Autowired
23984 govind 123
	private PartnerInventoryItemRepository partnerInventoryItemRepository;
23883 ashik.ali 124
 
125
	@Autowired
23984 govind 126
	private ScanOutPartnerItemRepository scanOutPartnerItemRepository;
127
 
23784 ashik.ali 128
	@Autowired
23883 ashik.ali 129
	private InstructionItemRepository instructionItemRepository;
23984 govind 130
 
23784 ashik.ali 131
	@Autowired
23883 ashik.ali 132
	private InstructionItemDetailRepository instructionItemDetailRepository;
23984 govind 133
 
23883 ashik.ali 134
	@Autowired
135
	private AdminDeliveryNoteDetailRepository adminDeliveryNoteDetailRepository;
23984 govind 136
 
23883 ashik.ali 137
	@Autowired
23784 ashik.ali 138
	private CookiesProcessor cookiesProcessor;
23984 govind 139
 
140
	private Map<Integer, String> itemsToVendorIdNameMap(List<Item> items) {
23784 ashik.ali 141
		Map<Integer, String> vendorIdNameMap = new HashMap<>();
23984 govind 142
		if (items.isEmpty()) {
23784 ashik.ali 143
			return vendorIdNameMap;
144
		}
145
		Set<Integer> vendorIds = new HashSet<>();
23984 govind 146
		for (Item item : items) {
23784 ashik.ali 147
			vendorIds.add(item.getVendorId());
148
		}
23984 govind 149
 
23784 ashik.ali 150
		List<Vendor> vendors = vendorRepository.selectByIds(vendorIds);
23984 govind 151
		for (Vendor vendor : vendors) {
23784 ashik.ali 152
			vendorIdNameMap.put(vendor.getId(), vendor.getName());
153
		}
154
		return vendorIdNameMap;
155
	}
23984 govind 156
 
157
	private Map<Integer, String> adminCurrentInventorySnapshotsToItemIdDescriptionMap(
158
			List<AdminCurrentInventorySnapshot> currentInventorySnapshots) {
159
		if (currentInventorySnapshots.isEmpty()) {
23784 ashik.ali 160
			return new HashMap<>();
161
		}
162
		Set<Integer> itemIds = new HashSet<>();
23984 govind 163
		for (AdminCurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots) {
23784 ashik.ali 164
			itemIds.add(currentInventorySnapshot.getItemId());
165
		}
166
		return itemIdDescriptionMap(itemIds);
167
	}
23984 govind 168
 
169
	private Map<Integer, String> adminCurrentInventorySnapshotsToItemIdTypeMap(
170
			List<AdminCurrentInventorySnapshot> currentInventorySnapshots) {
171
		if (currentInventorySnapshots.isEmpty()) {
23784 ashik.ali 172
			return new HashMap<>();
173
		}
174
		Set<Integer> itemIds = new HashSet<>();
23984 govind 175
		for (AdminCurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots) {
23784 ashik.ali 176
			itemIds.add(currentInventorySnapshot.getItemId());
177
		}
178
		return itemIdTypeMap(itemIds);
179
	}
23984 govind 180
 
181
	private Map<Integer, String> partnerCurrentInventorySnapshotsToItemIdDescriptionMap(
182
			List<PartnerCurrentInventorySnapshot> partnerCurrentInventorySnapshots) {
183
		if (partnerCurrentInventorySnapshots.isEmpty()) {
23784 ashik.ali 184
			return new HashMap<>();
185
		}
186
		Set<Integer> itemIds = new HashSet<>();
23984 govind 187
		for (PartnerCurrentInventorySnapshot partnerCurrentInventorySnapshot : partnerCurrentInventorySnapshots) {
23784 ashik.ali 188
			itemIds.add(partnerCurrentInventorySnapshot.getItemId());
189
		}
190
		return itemIdDescriptionMap(itemIds);
191
	}
23984 govind 192
 
193
	/*
194
	 * private Map<Integer, String>
195
	 * adminDeliveryNotesToItemIdDescriptionMap(List<AdminDeliveryNote>
196
	 * adminDeliveryNotes){ if(adminDeliveryNotes.isEmpty()) { return new
197
	 * HashMap<>(); } Set<Integer> itemIds = new HashSet<>(); for(AdminDeliveryNote
198
	 * adminDeliveryNote : adminDeliveryNotes) {
199
	 * itemIds.add(adminDeliveryNote.getItemId()); } return
200
	 * itemIdDescriptionMap(itemIds); }
201
	 */
202
 
203
	private Map<Integer, String> scanOutPartnerItemsToItemIdDescriptionMap(
204
			List<ScanOutPartnerItem> scanOutPartnerItems) {
205
		if (scanOutPartnerItems.isEmpty()) {
23784 ashik.ali 206
			return new HashMap<>();
207
		}
208
		Set<Integer> itemIds = new HashSet<>();
23984 govind 209
		for (ScanOutPartnerItem scanOutPartnerItem : scanOutPartnerItems) {
210
			itemIds.add(scanOutPartnerItem.getItemId());
23784 ashik.ali 211
		}
212
		return itemIdDescriptionMap(itemIds);
23984 govind 213
	}
23883 ashik.ali 214
 
23984 govind 215
	private Map<Integer, String> itemIdDescriptionMap(Set<Integer> itemIds) {
23784 ashik.ali 216
		Map<Integer, String> itemIdDescriptionMap = new HashMap<>();
217
		List<Item> items = itemRepository.selectByIds(itemIds);
23984 govind 218
		for (Item item : items) {
23784 ashik.ali 219
			itemIdDescriptionMap.put(item.getId(), item.getBrand() + " " + item.getDescription());
220
		}
221
		return itemIdDescriptionMap;
222
	}
23984 govind 223
 
224
	private Map<Integer, String> itemIdTypeMap(Set<Integer> itemIds) {
23784 ashik.ali 225
		Map<Integer, String> itemIdTypeMap = new HashMap<>();
226
		List<Item> items = itemRepository.selectByIds(itemIds);
23984 govind 227
		for (Item item : items) {
23784 ashik.ali 228
			itemIdTypeMap.put(item.getId(), item.getType().toString());
229
		}
230
		return itemIdTypeMap;
231
	}
23984 govind 232
 
233
	private Map<Integer, String> warehouseIdNameMap(List<Warehouse> warehouses) {
23784 ashik.ali 234
		Map<Integer, String> warehouseIdNameMap = new HashMap<>();
23984 govind 235
		for (Warehouse warehouse : warehouses) {
23784 ashik.ali 236
			warehouseIdNameMap.put(warehouse.getId(), warehouse.getName());
237
		}
238
		return warehouseIdNameMap;
239
	}
23984 govind 240
 
241
	private Set<Integer> instructionItemsToWarehouseIds(List<InstructionItem> instructionItems) {
23883 ashik.ali 242
		Set<Integer> warehouseIds = new HashSet<>();
23984 govind 243
		for (InstructionItem instructionItem : instructionItems) {
23883 ashik.ali 244
			warehouseIds.add(instructionItem.getWarehouseId());
245
		}
246
		return warehouseIds;
247
	}
23984 govind 248
 
249
	private Set<Integer> instructionItemsToFofoIds(List<InstructionItem> instructionItems) {
23883 ashik.ali 250
		Set<Integer> fofoIds = new HashSet<>();
23984 govind 251
		for (InstructionItem instructionItem : instructionItems) {
23883 ashik.ali 252
			fofoIds.add(instructionItem.getFofoId());
253
		}
254
		return fofoIds;
255
	}
23984 govind 256
 
257
	private Set<Integer> instructionItemsToInstructionItemIds(List<InstructionItem> instructionItems) {
23883 ashik.ali 258
		Set<Integer> instructionItemIds = new HashSet<>();
23984 govind 259
		for (InstructionItem instructionItem : instructionItems) {
23883 ashik.ali 260
			instructionItemIds.add(instructionItem.getId());
261
		}
262
		return instructionItemIds;
263
	}
23984 govind 264
 
265
	private Map<Integer, Integer> instructionItemDetailsToItemIdQuantityMap(
266
			List<InstructionItemDetail> instructionItemDetails) {
23883 ashik.ali 267
		Map<Integer, Integer> itemIdQuantityMap = new HashMap<>();
23984 govind 268
		for (InstructionItemDetail instructionItemDetail : instructionItemDetails) {
269
			if (!itemIdQuantityMap.containsKey(instructionItemDetail.getItemId())) {
23883 ashik.ali 270
				itemIdQuantityMap.put(instructionItemDetail.getItemId(), instructionItemDetail.getQuantity());
23984 govind 271
			} else {
272
				itemIdQuantityMap.put(instructionItemDetail.getItemId(),
273
						itemIdQuantityMap.get(instructionItemDetail.getItemId()) + instructionItemDetail.getQuantity());
23883 ashik.ali 274
			}
275
		}
276
		return itemIdQuantityMap;
277
	}
23984 govind 278
 
279
	private Map<Integer, List<InstructionItemDetail>> instructionItemsToInstructionItemIdInstructionItemDetailsMap(
280
			List<InstructionItemDetail> instructionItemDetails) {
281
		// Set<Integer> instructionItemIds =
282
		// this.instructionItemsToInstructionItemIds(instructionItems);
283
		// List<InstructionItemDetail> instructionItemDetails =
284
		// instructionItemDetailRepository.selectByInstructionItemIds(instructionItemIds);
23883 ashik.ali 285
		Map<Integer, List<InstructionItemDetail>> instructionIdInstructionItemDetailMap = new HashMap<>();
23984 govind 286
		for (InstructionItemDetail instructionItemDetail : instructionItemDetails) {
287
			if (!instructionIdInstructionItemDetailMap.containsKey(instructionItemDetail.getInstructionItemId())) {
23883 ashik.ali 288
				List<InstructionItemDetail> instructionItemDetailsList = new ArrayList<>();
289
				instructionItemDetailsList.add(instructionItemDetail);
23984 govind 290
				instructionIdInstructionItemDetailMap.put(instructionItemDetail.getInstructionItemId(),
291
						instructionItemDetailsList);
292
			} else {
293
				instructionIdInstructionItemDetailMap.get(instructionItemDetail.getInstructionItemId())
294
						.add(instructionItemDetail);
23883 ashik.ali 295
			}
296
		}
297
		return instructionIdInstructionItemDetailMap;
298
	}
23984 govind 299
 
300
	private Set<Integer> instructionItemDetailsToItemIds(List<InstructionItemDetail> instructionItemDetails) {
23883 ashik.ali 301
		Set<Integer> itemIds = new HashSet<>();
23984 govind 302
		for (InstructionItemDetail instructionItemDetail : instructionItemDetails) {
23883 ashik.ali 303
			itemIds.add(instructionItemDetail.getItemId());
304
		}
305
		return itemIds;
306
	}
23984 govind 307
 
308
	private Set<Integer> adminDeliveryNotesToWarehouseIds(List<AdminDeliveryNote> adminDeliveryNotes) {
23883 ashik.ali 309
		Set<Integer> warehouseIds = new HashSet<>();
23984 govind 310
		for (AdminDeliveryNote adminDeliveryNote : adminDeliveryNotes) {
23883 ashik.ali 311
			warehouseIds.add(adminDeliveryNote.getWarehouseId());
312
		}
313
		return warehouseIds;
314
	}
23984 govind 315
 
316
	private Set<Integer> adminDeliveryNotesToFofoIds(List<AdminDeliveryNote> adminDeliveryNotes) {
23883 ashik.ali 317
		Set<Integer> fofoIds = new HashSet<>();
23984 govind 318
		for (AdminDeliveryNote adminDeliveryNote : adminDeliveryNotes) {
23883 ashik.ali 319
			fofoIds.add(adminDeliveryNote.getFofoId());
320
		}
321
		return fofoIds;
322
	}
23984 govind 323
 
23784 ashik.ali 324
	@RequestMapping(value = "/createItem", method = RequestMethod.GET)
23984 govind 325
	public String createItem(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
326
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
327
			throws ProfitMandiBusinessException {
23784 ashik.ali 328
		LOGGER.info("Request Received at url {}", request.getRequestURI());
329
		List<Item> items = itemRepository.selectAll(offset, limit);
330
		long size = itemRepository.selectAllCount();
331
		Map<Integer, String> vendorIdNameMap = this.itemsToVendorIdNameMap(items);
332
		List<Vendor> vendors = vendorRepository.selectAll();
333
		model.addAttribute("vendors", vendors);
334
		model.addAttribute("items", items);
335
		model.addAttribute("types", ItemType.values());
336
		model.addAttribute("vendorIdNameMap", vendorIdNameMap);
337
		model.addAttribute("start", offset + 1);
338
		model.addAttribute("size", size);
23984 govind 339
		if (items.size() < limit) {
23784 ashik.ali 340
			model.addAttribute("end", offset + items.size());
23984 govind 341
		} else {
23784 ashik.ali 342
			model.addAttribute("end", offset + limit);
343
		}
344
		return "items";
345
	}
23984 govind 346
 
23784 ashik.ali 347
	@RequestMapping(value = "/createItem", method = RequestMethod.POST)
23984 govind 348
	public String createItem(HttpServletRequest request, @RequestBody CreateItemRequest createItemRequest,
349
			@RequestParam(name = "offset", defaultValue = "0") int offset,
350
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
351
			throws ProfitMandiBusinessException {
23784 ashik.ali 352
		LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), createItemRequest);
353
		inventoryService.createItem(createItemRequest);
354
		List<Item> items = itemRepository.selectAll(offset, limit);
355
		Map<Integer, String> vendorIdNameMap = this.itemsToVendorIdNameMap(items);
356
		long size = itemRepository.selectAllCount();
357
		List<Vendor> vendors = vendorRepository.selectAll();
358
		model.addAttribute("vendors", vendors);
359
		model.addAttribute("items", items);
360
		model.addAttribute("types", ItemType.values());
361
		model.addAttribute("vendorIdNameMap", vendorIdNameMap);
362
		model.addAttribute("start", offset + 1);
363
		model.addAttribute("size", size);
23984 govind 364
		if (items.size() < limit) {
23784 ashik.ali 365
			model.addAttribute("end", offset + items.size());
23984 govind 366
		} else {
23784 ashik.ali 367
			model.addAttribute("end", offset + limit);
368
		}
369
		return "items";
370
	}
23984 govind 371
 
23784 ashik.ali 372
	@RequestMapping(value = "/getPaginatedItems", method = RequestMethod.GET)
23984 govind 373
	public String getPaginatedItems(HttpServletRequest request,
374
			@RequestParam(name = "offset", defaultValue = "0") int offset,
375
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
376
			throws ProfitMandiBusinessException {
377
		List<Item> items = itemRepository.selectAll(offset, limit);
23784 ashik.ali 378
		Map<Integer, String> vendorIdNameMap = this.itemsToVendorIdNameMap(items);
379
		List<Vendor> vendors = vendorRepository.selectAll();
380
		model.addAttribute("vendors", vendors);
381
		model.addAttribute("items", items);
382
		model.addAttribute("vendorIdNameMap", vendorIdNameMap);
383
		return "items-paginated";
384
	}
23984 govind 385
 
23784 ashik.ali 386
	@RequestMapping(value = "/scanInItems", method = RequestMethod.POST)
23984 govind 387
	public String scanInItems(HttpServletRequest request, @RequestBody ScanInItemRequest scanInItemRequest,
388
			@RequestParam(name = "offset", defaultValue = "0") int offset,
389
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
390
			throws ProfitMandiBusinessException {
23784 ashik.ali 391
		LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), scanInItemRequest);
392
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23883 ashik.ali 393
		List<Integer> warehouseIds = userWarehouseRepository.selectWarehouseIdsByUserId(loginDetails.getFofoId());
23784 ashik.ali 394
		List<Item> items = itemRepository.selectAll();
395
		inventoryService.scanInItem(scanInItemRequest, loginDetails.getFofoId());
23984 govind 396
		List<AdminCurrentInventorySnapshot> adminCurrentInventorySnapshots = adminCurrentInventorySnapshotRepository
397
				.selectAllByAdminId(loginDetails.getFofoId(), offset, limit);
398
		Map<Integer, String> itemIdDescriptionMap = this
399
				.adminCurrentInventorySnapshotsToItemIdDescriptionMap(adminCurrentInventorySnapshots);
23784 ashik.ali 400
		long size = adminCurrentInventorySnapshotRepository.selectAllCountByAdminId(loginDetails.getFofoId());
23984 govind 401
		if (!warehouseIds.isEmpty()) {
23883 ashik.ali 402
			model.addAttribute("warehouses", warehouseRepository.selectByIds(new HashSet<>(warehouseIds)));
403
		}
23784 ashik.ali 404
		model.addAttribute("items", items);
405
		model.addAttribute("adminCurrentInventorySnapshots", adminCurrentInventorySnapshots);
406
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
407
		model.addAttribute("start", offset + 1);
408
		model.addAttribute("size", size);
23984 govind 409
		if (adminCurrentInventorySnapshots.size() < limit) {
23784 ashik.ali 410
			model.addAttribute("end", offset + adminCurrentInventorySnapshots.size());
23984 govind 411
		} else {
23784 ashik.ali 412
			model.addAttribute("end", offset + limit);
413
		}
414
		return "scan-in-items";
415
	}
23984 govind 416
 
23784 ashik.ali 417
	@RequestMapping(value = "/getScanInItems", method = RequestMethod.GET)
23984 govind 418
	public String getScanInItems(HttpServletRequest request,
419
			@RequestParam(name = "offset", defaultValue = "0") int offset,
420
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
421
			throws ProfitMandiBusinessException {
23784 ashik.ali 422
		LOGGER.info("Request Received at url {}", request.getRequestURI());
423
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23883 ashik.ali 424
		List<Integer> warehouseIds = userWarehouseRepository.selectWarehouseIdsByUserId(loginDetails.getFofoId());
23784 ashik.ali 425
		List<Item> items = itemRepository.selectAll();
23984 govind 426
		List<AdminCurrentInventorySnapshot> adminCurrentInventorySnapshots = adminCurrentInventorySnapshotRepository
427
				.selectAllByAdminId(loginDetails.getFofoId(), offset, limit);
428
		Map<Integer, String> itemIdDescriptionMap = this
429
				.adminCurrentInventorySnapshotsToItemIdDescriptionMap(adminCurrentInventorySnapshots);
23784 ashik.ali 430
		long size = adminCurrentInventorySnapshotRepository.selectAllCountByAdminId(loginDetails.getFofoId());
23984 govind 431
		if (!warehouseIds.isEmpty()) {
23883 ashik.ali 432
			model.addAttribute("warehouses", warehouseRepository.selectByIds(new HashSet<>(warehouseIds)));
433
		}
23784 ashik.ali 434
		model.addAttribute("items", items);
435
		model.addAttribute("adminCurrentInventorySnapshots", adminCurrentInventorySnapshots);
436
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
437
		model.addAttribute("start", offset + 1);
438
		model.addAttribute("size", size);
23984 govind 439
		if (adminCurrentInventorySnapshots.size() < limit) {
23784 ashik.ali 440
			model.addAttribute("end", offset + adminCurrentInventorySnapshots.size());
23984 govind 441
		} else {
23784 ashik.ali 442
			model.addAttribute("end", offset + limit);
443
		}
444
		return "scan-in-items";
445
	}
23984 govind 446
 
23784 ashik.ali 447
	@RequestMapping(value = "/getPaginatedScanInItems", method = RequestMethod.GET)
23984 govind 448
	public String getPaginatedScanInItems(HttpServletRequest request,
449
			@RequestParam(name = "offset", defaultValue = "0") int offset,
450
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
451
			throws ProfitMandiBusinessException {
23784 ashik.ali 452
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23984 govind 453
		List<AdminCurrentInventorySnapshot> adminCurrentInventorySnapshots = adminCurrentInventorySnapshotRepository
454
				.selectAllByAdminId(loginDetails.getFofoId(), offset, limit);
455
		Map<Integer, String> itemIdDescriptionMap = this
456
				.adminCurrentInventorySnapshotsToItemIdDescriptionMap(adminCurrentInventorySnapshots);
23784 ashik.ali 457
		model.addAttribute("adminCurrentInventorySnapshots", adminCurrentInventorySnapshots);
458
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
459
		return "scan-in-items-paginated";
460
	}
23984 govind 461
 
23784 ashik.ali 462
	@RequestMapping(value = "/getScanInPartnerItems", method = RequestMethod.GET)
23984 govind 463
	public String getScanInPartnerItems(HttpServletRequest request,
464
			@RequestParam(name = "offset", defaultValue = "0") int offset,
465
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
466
			throws ProfitMandiBusinessException {
23784 ashik.ali 467
		LOGGER.info("Request Received at url {}", request.getRequestURI());
468
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23984 govind 469
 
470
		// List<Item> items = itemRepository.selectAll();
471
		List<PartnerCurrentInventorySnapshot> partnerCurrentInventorySnapshots = partnerCurrentInventorySnapshotRepository
472
				.selectAllByFofoId(loginDetails.getFofoId(), offset, limit);
473
		Map<Integer, String> itemIdDescriptionMap = this
474
				.partnerCurrentInventorySnapshotsToItemIdDescriptionMap(partnerCurrentInventorySnapshots);
23784 ashik.ali 475
		long size = partnerCurrentInventorySnapshotRepository.selectAllCountByFofoId(loginDetails.getFofoId());
23984 govind 476
		// model.addAttribute("items", items);
23784 ashik.ali 477
		model.addAttribute("partnerCurrentInventorySnapshots", partnerCurrentInventorySnapshots);
478
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
479
		model.addAttribute("start", offset + 1);
480
		model.addAttribute("size", size);
23984 govind 481
		if (partnerCurrentInventorySnapshots.size() < limit) {
23784 ashik.ali 482
			model.addAttribute("end", offset + partnerCurrentInventorySnapshots.size());
23984 govind 483
		} else {
23784 ashik.ali 484
			model.addAttribute("end", offset + limit);
485
		}
486
		return "scan-in-partner-items";
487
	}
23984 govind 488
 
23883 ashik.ali 489
	@RequestMapping(value = "/scanInPartnerItems", method = RequestMethod.POST)
23984 govind 490
	public String getScanInPartnerItems(HttpServletRequest request,
491
			@RequestBody ScanInPartnerItemRequest scanInPartnerItemRequest,
492
			@RequestParam(name = "offset", defaultValue = "0") int offset,
493
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
494
			throws ProfitMandiBusinessException {
23784 ashik.ali 495
		LOGGER.info("Request Received at url {}", request.getRequestURI());
496
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23883 ashik.ali 497
		inventoryService.scanInPartnerItem(scanInPartnerItemRequest, loginDetails.getFofoId());
23984 govind 498
		List<PartnerCurrentInventorySnapshot> partnerCurrentInventorySnapshots = partnerCurrentInventorySnapshotRepository
499
				.selectAllByFofoId(loginDetails.getFofoId(), offset, limit);
500
		Map<Integer, String> itemIdDescriptionMap = this
501
				.partnerCurrentInventorySnapshotsToItemIdDescriptionMap(partnerCurrentInventorySnapshots);
23784 ashik.ali 502
		long size = partnerCurrentInventorySnapshotRepository.selectAllCountByFofoId(loginDetails.getFofoId());
503
		model.addAttribute("partnerCurrentInventorySnapshots", partnerCurrentInventorySnapshots);
504
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
505
		model.addAttribute("start", offset + 1);
506
		model.addAttribute("size", size);
23984 govind 507
		if (partnerCurrentInventorySnapshots.size() < limit) {
23784 ashik.ali 508
			model.addAttribute("end", offset + partnerCurrentInventorySnapshots.size());
23984 govind 509
		} else {
23784 ashik.ali 510
			model.addAttribute("end", offset + limit);
511
		}
512
		return "scan-in-partner-items";
513
	}
23984 govind 514
 
23784 ashik.ali 515
	@RequestMapping(value = "/getPaginatedScanInPartnerItems", method = RequestMethod.GET)
23984 govind 516
	public String getPaginatedScanInPartnerItems(HttpServletRequest request,
517
			@RequestParam(name = "offset", defaultValue = "0") int offset,
518
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
519
			throws ProfitMandiBusinessException {
23784 ashik.ali 520
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23984 govind 521
		List<PartnerCurrentInventorySnapshot> partnerCurrentInventorySnapshots = partnerCurrentInventorySnapshotRepository
522
				.selectAllByFofoId(loginDetails.getFofoId(), offset, limit);
523
		Map<Integer, String> itemIdDescriptionMap = this
524
				.partnerCurrentInventorySnapshotsToItemIdDescriptionMap(partnerCurrentInventorySnapshots);
23784 ashik.ali 525
		model.addAttribute("partnerCurrentInventorySnapshots", partnerCurrentInventorySnapshots);
526
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
527
		return "scan-in-partner-items-paginated";
528
	}
23984 govind 529
 
530
	private Map<Integer, Integer> partnerCurrentInventorySnapshotsItemIdQuantityMap(
531
			List<PartnerCurrentInventorySnapshot> partnerCurrentInventorySnapshots) {
23883 ashik.ali 532
		Map<Integer, Integer> itemIdQuantityMap = new HashMap<>();
23984 govind 533
		for (PartnerCurrentInventorySnapshot partnerCurrentInventorySnapshot : partnerCurrentInventorySnapshots) {
534
			itemIdQuantityMap.put(partnerCurrentInventorySnapshot.getItemId(),
535
					partnerCurrentInventorySnapshot.getAvailability());
23883 ashik.ali 536
		}
537
		return itemIdQuantityMap;
538
	}
539
 
23984 govind 540
	@RequestMapping(value = "/getScanOutPartnerItems", method = RequestMethod.GET)
541
	public String getScanOutPartnerItems(HttpServletRequest request,
542
			@RequestParam(name = "offset", defaultValue = "0") int offset,
543
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
544
			throws ProfitMandiBusinessException {
545
		LOGGER.info("Request Received at url {}", request.getRequestURI());
546
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23883 ashik.ali 547
 
23984 govind 548
		int addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(loginDetails.getFofoId());
549
		Address address = addressRepository.selectById(addressId);
23883 ashik.ali 550
 
23984 govind 551
		List<PartnerCurrentInventorySnapshot> partnerCurrentInventorySnapshots = partnerCurrentInventorySnapshotRepository
552
				.selectByFofoId(loginDetails.getFofoId());
553
		Map<Integer, Integer> itemIdQuantityMap = this
554
				.partnerCurrentInventorySnapshotsItemIdQuantityMap(partnerCurrentInventorySnapshots);
555
		List<Item> items = itemRepository.selectByIds(itemIdQuantityMap.keySet());
556
 
557
		List<ScanOutPartnerItem> scanOutPartnerItems = scanOutPartnerItemRepository
558
				.selectAllByFofoId(loginDetails.getFofoId(), offset, limit);
559
		Map<Integer, String> itemIdDescriptionMap = this.scanOutPartnerItemsToItemIdDescriptionMap(scanOutPartnerItems);
560
		long size = scanOutPartnerItemRepository.selectCountByFofoId(loginDetails.getFofoId());
561
		model.addAttribute("items", items);
562
		// model.addAttribute("stateNames", Utils.getAllStateNames());
563
		model.addAttribute("retailerStateName", address.getState());
564
		model.addAttribute("scanOutPartnerItems", scanOutPartnerItems);
565
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
566
		model.addAttribute("itemIdQuantityMap", itemIdQuantityMap);
567
		model.addAttribute("start", offset + 1);
568
		model.addAttribute("size", size);
569
		if (scanOutPartnerItems.size() < limit) {
570
			model.addAttribute("end", offset + scanOutPartnerItems.size());
571
		} else {
572
			model.addAttribute("end", offset + limit);
573
		}
574
		return "scan-out-partner-items";
575
	}
576
 
577
	@RequestMapping(value = "/instructionItem", method = RequestMethod.POST)
578
	public String instructionItems(HttpServletRequest request,
579
			@RequestBody InstructionItemRequest instructionItemRequest,
580
			@RequestParam(name = "offset", defaultValue = "0") int offset,
581
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
582
			throws ProfitMandiBusinessException {
583
		LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), instructionItemRequest);
584
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
585
		inventoryService.instructionItem(instructionItemRequest, loginDetails.getFofoId());
586
		return this.getInstructionItems(request, offset, limit, model);
587
	}
588
 
589
	@RequestMapping(value = "/getInstructionItems", method = RequestMethod.GET)
590
	public String getInstructionItems(HttpServletRequest request,
591
			@RequestParam(name = "offset", defaultValue = "0") int offset,
592
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
593
			throws ProfitMandiBusinessException {
594
		LOGGER.info("Request Received at url {}", request.getRequestURI());
595
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
596
		List<InstructionItem> instructionItems = instructionItemRepository.selectAllByAdminId(loginDetails.getFofoId(),
597
				offset, limit);
598
		LOGGER.info("instructionItems" + instructionItems);
599
		Set<Integer> instructionItemWarehouseIds = this.instructionItemsToWarehouseIds(instructionItems);
600
		LOGGER.info("instructionItemWarehouseIds" + instructionItemWarehouseIds);
601
		List<Warehouse> warehouses = new ArrayList<>();
602
		if (!instructionItemWarehouseIds.isEmpty()) {
603
 
604
			warehouses = warehouseRepository.selectByIds(instructionItemWarehouseIds);
605
 
606
		}
607
		Map<Integer, String> warehouseIdNameMap = this.warehouseIdNameMap(warehouses);
608
 
609
		List<Integer> warehouseIds = userWarehouseRepository.selectWarehouseIdsByUserId(loginDetails.getFofoId());
610
		if (!warehouseIds.isEmpty()) {
23883 ashik.ali 611
			model.addAttribute("warehouses", warehouseRepository.selectByIds(new HashSet<>(warehouseIds)));
23984 govind 612
			LOGGER.info(warehouseRepository.selectByIds(new HashSet<>(warehouseIds)) + "warehouseIdNameMap");
23883 ashik.ali 613
		}
614
 
23984 govind 615
		List<Integer> userIds = userRoleRepository
616
				.selectUserIdsByRoleId(roleRepository.selectByName(RoleType.FOFO_ADMIN.toString()).getId());
617
		Map<Integer, String> userIdEmailIdMap = userService.getAllUseUserIdEmailIdMap(userIds);
23883 ashik.ali 618
 
23984 govind 619
		model.addAttribute("fofoIdEmailIdMap", userIdEmailIdMap);
620
		long size = instructionItemRepository.selectCountByAdminId(loginDetails.getFofoId());
621
		model.addAttribute("warehouseIdNameMap", warehouseIdNameMap);
622
		model.addAttribute("instructionItems", instructionItems);
623
		model.addAttribute("start", offset + 1);
624
		model.addAttribute("size", size);
625
		if (instructionItems.size() < limit) {
626
			model.addAttribute("end", offset + instructionItems.size());
627
		} else {
628
			model.addAttribute("end", offset + limit);
629
		}
23883 ashik.ali 630
 
23984 govind 631
		return "instruction-items";
632
	}
633
 
634
	@RequestMapping(value = "/getPaginatedInstructionItems", method = RequestMethod.GET)
635
	public String getPaginatedInstructionItems(HttpServletRequest request,
636
			@RequestParam(name = "offset", defaultValue = "0") int offset,
637
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
638
			throws ProfitMandiBusinessException {
639
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
640
		List<InstructionItem> instructionItems = instructionItemRepository.selectAllByAdminId(loginDetails.getFofoId(),
641
				offset, limit);
642
 
643
		Set<Integer> warehouseIds = this.instructionItemsToWarehouseIds(instructionItems);
644
		List<Warehouse> warehouses = warehouseRepository.selectByIds(warehouseIds);
645
		Map<Integer, String> warehouseIdNameMap = this.warehouseIdNameMap(warehouses);
646
 
647
		model.addAttribute("warehouseIdNameMap", warehouseIdNameMap);
648
		model.addAttribute("instructionItems", instructionItems);
649
		return "scan-out-partner-items-paginated";
650
	}
651
 
652
	@RequestMapping(value = "/scanOutPartnerItem", method = RequestMethod.POST)
653
	public String scanOutPartnerItems(HttpServletRequest request,
654
			@RequestBody ScanOutPartnerItemRequest scanOutPartnerItemRequest,
655
			@RequestParam(name = "offset", defaultValue = "0") int offset,
656
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
657
			throws ProfitMandiBusinessException {
658
		LOGGER.info("Request Received at url {}", request.getRequestURI());
659
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
660
		inventoryService.scanOutPartnerItem(scanOutPartnerItemRequest, loginDetails.getFofoId());
661
		return this.scanOutPartnerItems(request, scanOutPartnerItemRequest, offset, limit, model);
662
	}
663
 
664
	@RequestMapping(value = "/getPaginatedScanOutPartnerItems", method = RequestMethod.GET)
665
	public String getPaginatedScanOutPartnerItems(HttpServletRequest request,
666
			@RequestParam(name = "offset", defaultValue = "0") int offset,
667
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
668
			throws ProfitMandiBusinessException {
669
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
670
		List<ScanOutPartnerItem> scanOutPartnerItems = scanOutPartnerItemRepository
671
				.selectAllByFofoId(loginDetails.getFofoId(), offset, limit);
672
		Map<Integer, String> itemIdDescriptionMap = this.scanOutPartnerItemsToItemIdDescriptionMap(scanOutPartnerItems);
673
		model.addAttribute("scanOutPartnerItems", scanOutPartnerItems);
674
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
675
		return "scan-out-partner-items-paginated";
676
	}
677
 
23784 ashik.ali 678
	@RequestMapping(value = "/deliveryNoteDetails", method = RequestMethod.GET)
23984 govind 679
	public String deliveryNoteDetails(HttpServletRequest request,
680
			@RequestParam(name = ProfitMandiConstants.DELIVERY_NOTE_ID) String deliveryNoteId, Model model)
681
			throws ProfitMandiBusinessException {
23784 ashik.ali 682
		LOGGER.info("Request Received at url {}", request.getRequestURI());
683
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23984 govind 684
		AdminDeliveryNote adminDeliveryNote = adminDeliveryNoteRepository
685
				.selectByDeliveryNoteIdAndFofoid(deliveryNoteId, loginDetails.getFofoId());
686
		if (adminDeliveryNote.getCompleteTimestamp() != null) {
687
			throw new ProfitMandiBusinessException(
688
					ProfitMandiConstants.DELIVERY_NOTE_ID + ", " + ProfitMandiConstants.FOFO_ID,
689
					deliveryNoteId + ", " + loginDetails.getFofoId(), "NNBLBL_ITM_1002");
23883 ashik.ali 690
		}
691
		Warehouse warehouse = warehouseRepository.selectId(adminDeliveryNote.getWarehouseId());
23984 govind 692
		List<Integer> instructionItemIds = adminDeliveryNoteDetailRepository
693
				.selectInstructionItemIdsByDeliveryNoteId(deliveryNoteId);
694
		List<InstructionItemDetail> instructionItemDetails = instructionItemDetailRepository
695
				.selectByInstructionItemIds(new HashSet<>(instructionItemIds));
696
		Map<Integer, Integer> itemIdQuantityMap = this
697
				.instructionItemDetailsToItemIdQuantityMap(instructionItemDetails);
23883 ashik.ali 698
		Map<Integer, String> itemIdDescriptionMap = this.itemIdDescriptionMap(itemIdQuantityMap.keySet());
699
		Map<Integer, String> itemIdTypeMap = this.itemIdTypeMap(itemIdQuantityMap.keySet());
700
		model.addAttribute("deliveryNoteId", deliveryNoteId);
701
		model.addAttribute("warehouseName", warehouse.getName());
702
		model.addAttribute("itemIdQuantityMap", itemIdQuantityMap);
703
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
704
		model.addAttribute("itemIdTypeMap", itemIdTypeMap);
705
		return "delivery-note-details";
23784 ashik.ali 706
	}
23984 govind 707
 
23784 ashik.ali 708
	@RequestMapping(value = "/getItemsByWarehouseId", method = RequestMethod.GET)
23984 govind 709
	public String getItemsByWarehouseId(HttpServletRequest request,
710
			@RequestParam(name = ProfitMandiConstants.WAREHOUSE_ID) int warehouseId, Model model)
711
			throws ProfitMandiBusinessException {
23784 ashik.ali 712
		LOGGER.info("Request Received at url {}", request.getRequestURI());
23984 govind 713
		List<AdminCurrentInventorySnapshot> adminCurrentInventorySnapshots = adminCurrentInventorySnapshotRepository
714
				.selectAllAvailableByWarehouseId(warehouseId);
715
		Map<Integer, String> itemIdDescriptionMap = this
716
				.adminCurrentInventorySnapshotsToItemIdDescriptionMap(adminCurrentInventorySnapshots);
717
		Map<Integer, String> itemIdTypeMap = this
718
				.adminCurrentInventorySnapshotsToItemIdTypeMap(adminCurrentInventorySnapshots);
23784 ashik.ali 719
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
720
		model.addAttribute("itemIdTypeMap", itemIdTypeMap);
721
		return "warehouse-items";
722
	}
23984 govind 723
 
23883 ashik.ali 724
	@RequestMapping(value = "/getInstructionItemsByWarehouseId", method = RequestMethod.GET)
23984 govind 725
	public String getInstructionItemsByWarehouseId(HttpServletRequest request,
726
			@RequestParam(name = ProfitMandiConstants.WAREHOUSE_ID) int warehouseId, Model model)
727
			throws ProfitMandiBusinessException {
23883 ashik.ali 728
		LOGGER.info("Request Received at url {}", request.getRequestURI());
23984 govind 729
		List<AdminCurrentInventorySnapshot> adminCurrentInventorySnapshots = adminCurrentInventorySnapshotRepository
730
				.selectAllAvailableByWarehouseId(warehouseId);
731
		Map<Integer, String> itemIdDescriptionMap = this
732
				.adminCurrentInventorySnapshotsToItemIdDescriptionMap(adminCurrentInventorySnapshots);
733
		Map<Integer, String> itemIdTypeMap = this
734
				.adminCurrentInventorySnapshotsToItemIdTypeMap(adminCurrentInventorySnapshots);
23883 ashik.ali 735
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
736
		model.addAttribute("itemIdTypeMap", itemIdTypeMap);
737
		return "warehouse-instruction-items";
738
	}
23984 govind 739
 
23883 ashik.ali 740
	@RequestMapping(value = "/getPendingInstructionItems", method = RequestMethod.GET)
23984 govind 741
	public String getPendingInstructionItems(HttpServletRequest request,
742
			@RequestParam(name = ProfitMandiConstants.WAREHOUSE_ID) int warehouseId,
743
			@RequestParam(name = ProfitMandiConstants.USER_ID) int userId, Model model)
744
			throws ProfitMandiBusinessException {
23883 ashik.ali 745
		LOGGER.info("Request Received at url {}", request.getRequestURI());
746
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23984 govind 747
		List<InstructionItem> instructionItems = instructionItemRepository.selectByAdminIdWarehouseIdUserIdStatus(
748
				loginDetails.getFofoId(), warehouseId, userId, InstructionItemStatus.PENDING);
23883 ashik.ali 749
		Set<Integer> instructionItemIds = this.instructionItemsToInstructionItemIds(instructionItems);
23984 govind 750
		List<InstructionItemDetail> instructionItemDetails = instructionItemDetailRepository
751
				.selectByInstructionItemIds(instructionItemIds);
23883 ashik.ali 752
		Set<Integer> itemIds = this.instructionItemDetailsToItemIds(instructionItemDetails);
23984 govind 753
		Map<Integer, List<InstructionItemDetail>> instructionItemIdInstructionItemDetailsMap = this
754
				.instructionItemsToInstructionItemIdInstructionItemDetailsMap(instructionItemDetails);
23883 ashik.ali 755
		Map<Integer, String> itemIdDescriptionMap = this.itemIdDescriptionMap(itemIds);
756
		Map<Integer, String> itemIdTypeMap = this.itemIdTypeMap(itemIds);
757
		model.addAttribute("instructionItems", instructionItems);
758
		model.addAttribute("instructionItemIdInstructionItemDetailsMap", instructionItemIdInstructionItemDetailsMap);
759
		model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
760
		model.addAttribute("itemIdTypeMap", itemIdTypeMap);
761
		return "pending-instruction-items";
762
	}
23984 govind 763
 
23784 ashik.ali 764
	@RequestMapping(value = "/getScanOutItems", method = RequestMethod.GET)
23984 govind 765
	public String getScanOutItems(HttpServletRequest request,
766
			@RequestParam(name = "offset", defaultValue = "0") int offset,
767
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
768
			throws ProfitMandiBusinessException {
23784 ashik.ali 769
		LOGGER.info("Request Received at url {}", request.getRequestURI());
23984 govind 770
		// List<AdminCurrentInventorySnapshot> adminCurrentInventorySnapshots =
771
		// adminCurrentInventorySnapshotRepository.selectAll();
772
		// Set<Integer> adminIds = this.getAdminIds(adminCurrentInventorySnapshots);
773
		// Map<Integer, String> adminIdEmailIdMap =
774
		// retailerService.getAllFofoRetailerIdEmailIdMap(adminIds);
23883 ashik.ali 775
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23984 govind 776
		List<InstructionItem> instructionItems = instructionItemRepository
777
				.selectByAdminIdStatus(loginDetails.getFofoId(), InstructionItemStatus.PENDING);
778
 
23883 ashik.ali 779
		List<Warehouse> warehouses = new ArrayList<>();
780
		Map<Integer, String> fofoIdEmailIdMap = new HashMap<>();
23984 govind 781
		if (!instructionItems.isEmpty()) {
23883 ashik.ali 782
			Set<Integer> warehouseIds = this.instructionItemsToWarehouseIds(instructionItems);
783
			warehouses = warehouseRepository.selectByIds(warehouseIds);
784
			Set<Integer> fofoIds = this.instructionItemsToFofoIds(instructionItems);
785
			fofoIdEmailIdMap = retailerService.getAllFofoRetailerIdEmailIdMap(fofoIds);
786
		}
23984 govind 787
 
23784 ashik.ali 788
		List<AdminDeliveryNote> adminDeliveryNotes = adminDeliveryNoteRepository.selectAll(offset, limit);
23984 govind 789
		Map<Integer, String> warehouseIdNameMap = new HashMap<>();
790
		if (!adminDeliveryNotes.isEmpty()) {
791
			List<Warehouse> adminDeliveryNoteWarehouses = warehouseRepository
792
					.selectByIds(this.adminDeliveryNotesToWarehouseIds(adminDeliveryNotes));
23883 ashik.ali 793
			warehouseIdNameMap = this.warehouseIdNameMap(adminDeliveryNoteWarehouses);
23984 govind 794
			fofoIdEmailIdMap = retailerService
795
					.getAllFofoRetailerIdEmailIdMap(this.adminDeliveryNotesToFofoIds(adminDeliveryNotes));
23883 ashik.ali 796
		}
23784 ashik.ali 797
		long size = adminDeliveryNoteRepository.selectAllCount();
23984 govind 798
		// model.addAttribute("adminIdEmailIdMap", adminIdEmailIdMap);
23784 ashik.ali 799
		model.addAttribute("adminDeliveryNotes", adminDeliveryNotes);
23883 ashik.ali 800
		model.addAttribute("warehouses", warehouses);
23784 ashik.ali 801
		model.addAttribute("warehouseIdNameMap", warehouseIdNameMap);
802
		model.addAttribute("fofoIdEmailIdMap", fofoIdEmailIdMap);
803
		model.addAttribute("start", offset + 1);
804
		model.addAttribute("size", size);
23984 govind 805
		if (adminDeliveryNotes.size() < limit) {
23784 ashik.ali 806
			model.addAttribute("end", offset + adminDeliveryNotes.size());
23984 govind 807
		} else {
23784 ashik.ali 808
			model.addAttribute("end", offset + limit);
809
		}
810
		return "scan-out-items";
811
	}
23984 govind 812
 
23784 ashik.ali 813
	@RequestMapping(value = "/scanOutItems", method = RequestMethod.POST)
23984 govind 814
	public String scanOutItems(HttpServletRequest request, @RequestBody ScanOutItemRequest scanOutItemRequest,
815
			@RequestParam(name = "offset", defaultValue = "0") int offset,
816
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
817
			throws ProfitMandiBusinessException {
23784 ashik.ali 818
		LOGGER.info("Request Received at url {} with body {}", request.getRequestURI(), scanOutItemRequest);
23883 ashik.ali 819
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
820
		inventoryService.scanOutItem(scanOutItemRequest, loginDetails.getFofoId());
821
		return this.getScanOutItems(request, offset, limit, model);
23784 ashik.ali 822
	}
23984 govind 823
 
23784 ashik.ali 824
	@RequestMapping(value = "/getPaginatedScanOutItems", method = RequestMethod.GET)
23984 govind 825
	public String getPaginatedScanOutItems(HttpServletRequest request,
826
			@RequestParam(name = "offset", defaultValue = "0") int offset,
827
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
828
			throws ProfitMandiBusinessException {
23784 ashik.ali 829
		LOGGER.info("Request Received at url {}", request.getRequestURI());
23984 govind 830
		/*
831
		 * List<Warehouse> warehouses = warehouseRepository.selectAll();
832
		 * List<AdminDeliveryNote> adminDeliveryNotes =
833
		 * adminDeliveryNoteRepository.selectAll(offset, limit); Map<Integer, String>
834
		 * itemIdDescriptionMap =
835
		 * this.adminDeliveryNotesToItemIdDescriptionMap(adminDeliveryNotes);
836
		 * Map<Integer, String> warehouseIdNameMap =
837
		 * this.warehouseIdNameMap(warehouses); Map<Integer, String> fofoIdEmailIdMap =
838
		 * retailerService.getAllFofoRetailerIdEmailIdMap();
839
		 * model.addAttribute("adminDeliveryNotes", adminDeliveryNotes);
840
		 * model.addAttribute("warehouseIdNameMap", warehouseIdNameMap);
841
		 * model.addAttribute("fofoIdEmailIdMap", fofoIdEmailIdMap);
842
		 * model.addAttribute("itemIdDescriptionMap", itemIdDescriptionMap);
843
		 */
23784 ashik.ali 844
		return "scan-out-items-paginated";
845
	}
23984 govind 846
 
23883 ashik.ali 847
	@RequestMapping(value = "/getSerialNumbersByItemIdWarehouseId", method = RequestMethod.GET)
23984 govind 848
	public String getSerialNumbersByItemIdWarehouseId(HttpServletRequest request,
849
			@RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId,
850
			@RequestParam(name = ProfitMandiConstants.WAREHOUSE_ID) int warehouseId, Model model)
851
			throws ProfitMandiBusinessException {
852
		List<String> itemSerialNumbers = adminInventoryItemRepository
853
				.selectSerialNumbersByWarehouseIdItemIdScanType(warehouseId, itemId, ScanType.IN);
23784 ashik.ali 854
		model.addAttribute("itemSerialNumbers", itemSerialNumbers);
855
		return "item-serial-numbers";
856
	}
23883 ashik.ali 857
 
23984 govind 858
	@RequestMapping(value = "/getSerialNumbersByItemId", method = RequestMethod.GET)
859
	public String getSerialNumbersByItemId(HttpServletRequest request,
860
			@RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model)
861
			throws ProfitMandiBusinessException {
862
		List<String> itemSerialNumbers = partnerInventoryItemRepository.selectSerialNumbersByItemIdScanType(itemId,
863
				ScanType.IN);
864
		model.addAttribute("itemSerialNumbers", itemSerialNumbers);
865
		return "item-serial-numbers-single";
866
	}
867
 
23784 ashik.ali 868
}