Subversion Repositories SmartDukaan

Rev

Rev 23111 | Rev 23373 | 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());
105
		customCurrentInventorySnapshot.setIconUrl(Utils.getIconUrl(customCurrentInventorySnapshot.getCatalogItemId(), host, port, webapp));
106
		model.addAttribute("currentInventorySnapshot", new Gson().toJson(customCurrentInventorySnapshot));
107
		return "current-item-availability";
108
 
21577 ashik.ali 109
	}
110
 
23192 ashik.ali 111
	@RequestMapping(value = "/cart", method = RequestMethod.POST)
22927 ashik.ali 112
	public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException{
113
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
21657 ashik.ali 114
 
22927 ashik.ali 115
		Map<String, Object> map = inventoryService.addToCart(cartData, loginDetails.getFofoId());
116
		model.addAllAttributes(map);
21987 kshitij.so 117
		return "cart";
118
	}
119
 
23192 ashik.ali 120
	@RequestMapping(value = "/validate-cart", method = RequestMethod.POST)
22927 ashik.ali 121
	public String validateCart(HttpServletRequest request, HttpServletResponse response,@RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException{
122
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
21987 kshitij.so 123
 
22927 ashik.ali 124
		Map<String, Object> map = inventoryService.validateCart(cartData, loginDetails.getFofoId());
125
		model.addAllAttributes(map);
21987 kshitij.so 126
		return "validate-cart";
127
	}
128
 
129
	@RequestMapping(value = "/grnHistory")
22927 ashik.ali 130
	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{
131
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
132
		Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTimeString, endTimeString, offset, limit, purchaseReference, searchType);
133
		model.addAllAttributes(map);
21987 kshitij.so 134
		return "grn-history";
21636 ashik.ali 135
	}
21987 kshitij.so 136
 
137
	@RequestMapping(value = "/getPaginatedGrnHistory")
22927 ashik.ali 138
	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{
139
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
140
		Map<String, Object> map = inventoryService.getPaginatedGrnHistory(loginDetails.getFofoId(), startTimeString, endTimeString, offset, limit);
141
		model.addAllAttributes(map);
21987 kshitij.so 142
		return "grn-history-paginated";
143
	}
144
 
21654 ashik.ali 145
	@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
22927 ashik.ali 146
	public String grnHistoryByPurchaseId(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model) throws ProfitMandiBusinessException{
147
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
148
		Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseId, host, port, webapp);
149
		model.addAllAttributes(map);
21987 kshitij.so 150
		return "grn-details";
21636 ashik.ali 151
	}
21987 kshitij.so 152
 
21654 ashik.ali 153
	@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
22927 ashik.ali 154
	public String grnHistoryByPurchaseReference(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model) throws ProfitMandiBusinessException{
155
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
156
		Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseReference, host, port, webapp);
157
		model.addAllAttributes(map);
21987 kshitij.so 158
		return "grn-details";
21654 ashik.ali 159
	}
22472 ashik.ali 160
 
161
	@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
22927 ashik.ali 162
	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{
163
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
164
		Map<String, Object> map = inventoryService.getPaginatedItemAgingByInterval(loginDetails.getFofoId(), intervals, searchContent, offset, limit);
165
		model.addAllAttributes(map);
22523 ashik.ali 166
		return "item-aging";
167
	}
168
 
169
	@RequestMapping(value = "/downloadInventoryItemAgingByInterval", method = RequestMethod.POST)
22927 ashik.ali 170
	public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals, Model model) throws ProfitMandiBusinessException{
171
		LOGGER.info("Request received at url{} with body {}", request.getRequestURI(), intervals);
172
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
173
 
174
		List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryService.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
175
 
22486 ashik.ali 176
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
177
		ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
178
 
179
		final HttpHeaders headers=new HttpHeaders();
180
		//private static final String CONTENT_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
181
        headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
182
        //headers.set("Content-Type", "application/vnd.ms-excel");
183
		headers.set("Content-disposition", "inline; filename=InventoryItemAging.xlsx");
184
        headers.setContentLength(byteArrayOutputStream.toByteArray().length);
185
        final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
186
        final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
187
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
188
 
189
		//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
22472 ashik.ali 190
	}
21987 kshitij.so 191
 
21577 ashik.ali 192
}