Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21577 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
22486 ashik.ali 3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.InputStream;
21577 ashik.ali 6
import java.util.List;
21654 ashik.ali 7
import java.util.Map;
21577 ashik.ali 8
 
9
import javax.servlet.http.HttpServletRequest;
21987 kshitij.so 10
import javax.servlet.http.HttpServletResponse;
21577 ashik.ali 11
 
23568 govind 12
import org.apache.logging.log4j.Logger;
13
import org.apache.logging.log4j.LogManager;
21577 ashik.ali 14
import org.springframework.beans.factory.annotation.Autowired;
23784 ashik.ali 15
import org.springframework.beans.factory.annotation.Qualifier;
21987 kshitij.so 16
import org.springframework.beans.factory.annotation.Value;
22486 ashik.ali 17
import org.springframework.core.io.InputStreamResource;
18
import org.springframework.http.HttpHeaders;
19
import org.springframework.http.HttpStatus;
22472 ashik.ali 20
import org.springframework.http.ResponseEntity;
21577 ashik.ali 21
import org.springframework.stereotype.Controller;
21654 ashik.ali 22
import org.springframework.transaction.annotation.Transactional;
21577 ashik.ali 23
import org.springframework.ui.Model;
22472 ashik.ali 24
import org.springframework.web.bind.annotation.RequestBody;
21577 ashik.ali 25
import org.springframework.web.bind.annotation.RequestMapping;
22472 ashik.ali 26
import org.springframework.web.bind.annotation.RequestMethod;
21577 ashik.ali 27
import org.springframework.web.bind.annotation.RequestParam;
28
 
21987 kshitij.so 29
import com.google.gson.Gson;
21577 ashik.ali 30
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
21612 ashik.ali 31
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
22472 ashik.ali 32
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
21577 ashik.ali 33
import com.spice.profitmandi.common.model.ProfitMandiConstants;
22472 ashik.ali 34
import com.spice.profitmandi.common.util.ExcelUtils;
21987 kshitij.so 35
import com.spice.profitmandi.common.util.Utils;
22927 ashik.ali 36
import com.spice.profitmandi.service.inventory.InventoryService;
22139 amit.gupta 37
import com.spice.profitmandi.web.model.LoginDetails;
22069 ashik.ali 38
import com.spice.profitmandi.web.util.CookiesProcessor;
21577 ashik.ali 39
 
40
@Controller
22037 amit.gupta 41
@Transactional(rollbackFor=Throwable.class)
21577 ashik.ali 42
public class InventoryController {
21987 kshitij.so 43
 
23568 govind 44
	private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
21987 kshitij.so 45
 
21577 ashik.ali 46
	@Autowired
22927 ashik.ali 47
	private CookiesProcessor cookiesProcessor;
21577 ashik.ali 48
 
22354 ashik.ali 49
	@Autowired
23784 ashik.ali 50
	@Qualifier("fofoInventoryService")
22927 ashik.ali 51
	private InventoryService inventoryService;
23786 amit.gupta 52
 
21987 kshitij.so 53
	@Value("${saholic.api.host}")
54
	private String host;
23786 amit.gupta 55
 
21987 kshitij.so 56
	@Value("${saholic.api.port}")
57
	private int port;
23786 amit.gupta 58
 
21987 kshitij.so 59
	@Value("${saholic.api.webapp}")
60
	private String webapp;
61
 
23786 amit.gupta 62
	@RequestMapping(value = "/getCurrentInventorySnapshot")
63
	public String getCurrentAvailability(HttpServletRequest request,
64
			@RequestParam(name = "offset", defaultValue = "0") int offset,
65
			@RequestParam(name = "limit", defaultValue = "10") int limit,
66
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, 
67
			Model model)
68
			throws ProfitMandiBusinessException {
22927 ashik.ali 69
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 70
		Map<String, Object> map = inventoryService.getCurrentInventorySnapshot(loginDetails.getFofoId(), offset, limit,
71
				searchTerm);
22927 ashik.ali 72
		model.addAllAttributes(map);
21987 kshitij.so 73
		return "inventory-snapshot";
21612 ashik.ali 74
	}
21987 kshitij.so 75
 
23786 amit.gupta 76
	@RequestMapping(value = "/getBadInventorySnapshot")
77
	public String getBadAvailability(HttpServletRequest request,
78
			@RequestParam(name = "offset", defaultValue = "0") int offset,
79
			@RequestParam(name = "limit", defaultValue = "10") int limit,
80
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
81
			throws ProfitMandiBusinessException {
22927 ashik.ali 82
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 83
		Map<String, Object> map = inventoryService.getBadInventorySnapshot(loginDetails.getFofoId(), offset, limit,
84
				searchTerm);
22927 ashik.ali 85
		model.addAllAttributes(map);
21987 kshitij.so 86
		return "bad-inventory-snapshot";
87
	}
88
 
23786 amit.gupta 89
	@RequestMapping(value = "/getPaginatedCurrentInventorySnapshot")
90
	public String getPaginatedCurrentInventorySnapshot(HttpServletRequest request,
91
			@RequestParam(name = "offset", defaultValue = "0") int offset,
92
			@RequestParam(name = "limit", defaultValue = "10") int limit,
93
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
94
			throws ProfitMandiBusinessException {
22927 ashik.ali 95
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 96
		Map<String, Object> map = inventoryService.getPaginatedCurrentInventorySnapshot(loginDetails.getFofoId(),
97
				offset, limit, searchTerm);
22927 ashik.ali 98
		model.addAllAttributes(map);
21987 kshitij.so 99
		return "inventory-snapshot-paginated";
100
	}
23786 amit.gupta 101
 
102
	@RequestMapping(value = "/getCatalog")
103
	public String getCatalog(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
104
			@RequestParam(name = "limit", defaultValue = "10") int limit,
105
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
106
			throws ProfitMandiBusinessException {
22927 ashik.ali 107
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
108
		Map<String, Object> map = inventoryService.getCatalog(loginDetails.getFofoId(), offset, limit, searchTerm);
109
		model.addAllAttributes(map);
21987 kshitij.so 110
		return "catalog";
111
	}
23786 amit.gupta 112
 
113
	@RequestMapping(value = "/getPaginatedCatalog")
114
	public String getCatalogPaginated(HttpServletRequest request,
115
			@RequestParam(name = "offset", defaultValue = "0") int offset,
116
			@RequestParam(name = "limit", defaultValue = "10") int limit,
117
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
118
			throws ProfitMandiBusinessException {
22927 ashik.ali 119
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 120
		Map<String, Object> map = inventoryService.getPaginatedCatalog(loginDetails.getFofoId(), offset, limit,
121
				searchTerm);
22927 ashik.ali 122
		model.addAllAttributes(map);
21987 kshitij.so 123
		return "catalog-paginated";
124
	}
125
 
23786 amit.gupta 126
	@RequestMapping(value = "/checkItemAvailability")
127
	public String getItemAvailability(HttpServletRequest request,
128
			@RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model)
129
			throws ProfitMandiBusinessException {
22927 ashik.ali 130
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 131
		CustomCurrentInventorySnapshot customCurrentInventorySnapshot = inventoryService.checkItemAvailability(itemId,
132
				loginDetails.getFofoId());
133
		customCurrentInventorySnapshot
134
				.setIconUrl(Utils.getIconUrl(customCurrentInventorySnapshot.getCatalogItemId(), host, port, webapp));
22927 ashik.ali 135
		model.addAttribute("currentInventorySnapshot", new Gson().toJson(customCurrentInventorySnapshot));
136
		return "current-item-availability";
23786 amit.gupta 137
 
21577 ashik.ali 138
	}
23786 amit.gupta 139
 
23192 ashik.ali 140
	@RequestMapping(value = "/cart", method = RequestMethod.POST)
23786 amit.gupta 141
	public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model)
142
			throws ProfitMandiBusinessException {
22927 ashik.ali 143
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 144
 
22927 ashik.ali 145
		Map<String, Object> map = inventoryService.addToCart(cartData, loginDetails.getFofoId());
146
		model.addAllAttributes(map);
21987 kshitij.so 147
		return "cart";
148
	}
23786 amit.gupta 149
 
23192 ashik.ali 150
	@RequestMapping(value = "/validate-cart", method = RequestMethod.POST)
23786 amit.gupta 151
	public String validateCart(HttpServletRequest request, HttpServletResponse response,
152
			@RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException {
22927 ashik.ali 153
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 154
 
22927 ashik.ali 155
		Map<String, Object> map = inventoryService.validateCart(cartData, loginDetails.getFofoId());
156
		model.addAllAttributes(map);
21987 kshitij.so 157
		return "validate-cart";
158
	}
159
 
23786 amit.gupta 160
	@RequestMapping(value = "/grnHistory")
161
	public String getGrnHistory(HttpServletRequest request,
162
			@RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString,
163
			@RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString,
164
			@RequestParam(name = "offset", defaultValue = "0") int offset,
165
			@RequestParam(name = "limit", defaultValue = "10") int limit,
166
			@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
167
			@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
168
			throws ProfitMandiBusinessException {
22927 ashik.ali 169
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 170
		Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTimeString,
171
				endTimeString, offset, limit, purchaseReference, searchType);
22927 ashik.ali 172
		model.addAllAttributes(map);
21987 kshitij.so 173
		return "grn-history";
21636 ashik.ali 174
	}
21987 kshitij.so 175
 
23786 amit.gupta 176
	@RequestMapping(value = "/getPaginatedGrnHistory")
177
	public String getPaginatedGrnHistory(HttpServletRequest request,
178
			@RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString,
179
			@RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString,
180
			@RequestParam(name = "offset", defaultValue = "0") int offset,
181
			@RequestParam(name = "limit", defaultValue = "10") int limit,
182
			@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
183
			@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
184
			throws ProfitMandiBusinessException {
22927 ashik.ali 185
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 186
		Map<String, Object> map = inventoryService.getPaginatedGrnHistory(loginDetails.getFofoId(), startTimeString,
187
				endTimeString, offset, limit);
22927 ashik.ali 188
		model.addAllAttributes(map);
21987 kshitij.so 189
		return "grn-history-paginated";
190
	}
191
 
23786 amit.gupta 192
	@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
193
	public String grnHistoryByPurchaseId(HttpServletRequest request,
194
			@RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model)
195
			throws ProfitMandiBusinessException {
22927 ashik.ali 196
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 197
		Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseId, host, port,
198
				webapp);
22927 ashik.ali 199
		model.addAllAttributes(map);
21987 kshitij.so 200
		return "grn-details";
21636 ashik.ali 201
	}
21987 kshitij.so 202
 
23786 amit.gupta 203
	@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
204
	public String grnHistoryByPurchaseReference(HttpServletRequest request,
205
			@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model)
206
			throws ProfitMandiBusinessException {
22927 ashik.ali 207
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 208
		Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseReference,
209
				host, port, webapp);
22927 ashik.ali 210
		model.addAllAttributes(map);
21987 kshitij.so 211
		return "grn-details";
21654 ashik.ali 212
	}
23786 amit.gupta 213
 
22472 ashik.ali 214
	@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
23786 amit.gupta 215
	public String getInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals,
216
			Model model, @RequestParam(name = "searchContent", defaultValue = "") String searchContent,
217
			@RequestParam(name = "offset", defaultValue = "0") int offset,
218
			@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {
22927 ashik.ali 219
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 220
		Map<String, Object> map = inventoryService.getPaginatedItemAgingByInterval(loginDetails.getFofoId(), intervals,
221
				searchContent, offset, limit);
22927 ashik.ali 222
		model.addAllAttributes(map);
22523 ashik.ali 223
		return "item-aging";
224
	}
23786 amit.gupta 225
 
22523 ashik.ali 226
	@RequestMapping(value = "/downloadInventoryItemAgingByInterval", method = RequestMethod.POST)
23786 amit.gupta 227
	public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
228
			@RequestBody List<Integer> intervals, Model model) throws ProfitMandiBusinessException {
22927 ashik.ali 229
		LOGGER.info("Request received at url{} with body {}", request.getRequestURI(), intervals);
230
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
23786 amit.gupta 231
 
232
		List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryService
233
				.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
234
 
22486 ashik.ali 235
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
236
		ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
23786 amit.gupta 237
 
238
		final HttpHeaders headers = new HttpHeaders();
239
		// private static final String CONTENT_TYPE_XLSX =
240
		// "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
241
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
242
		// headers.set("Content-Type", "application/vnd.ms-excel");
22486 ashik.ali 243
		headers.set("Content-disposition", "inline; filename=InventoryItemAging.xlsx");
23786 amit.gupta 244
		headers.setContentLength(byteArrayOutputStream.toByteArray().length);
245
		final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
246
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
247
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
248
 
249
		// return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
22472 ashik.ali 250
	}
21987 kshitij.so 251
 
21577 ashik.ali 252
}