Subversion Repositories SmartDukaan

Rev

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