Subversion Repositories SmartDukaan

Rev

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

Rev 22927 Rev 23020
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
-
 
3
import java.io.ByteArrayInputStream;
-
 
4
import java.io.ByteArrayOutputStream;
-
 
5
import java.io.InputStream;
-
 
6
import java.time.LocalDateTime;
3
import java.util.List;
7
import java.util.List;
-
 
8
import java.util.Map;
4
 
9
 
5
import javax.servlet.http.HttpServletRequest;
10
import javax.servlet.http.HttpServletRequest;
6
 
11
 
7
import org.slf4j.Logger;
12
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
13
import org.slf4j.LoggerFactory;
9
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.beans.factory.annotation.Autowired;
-
 
15
import org.springframework.core.io.InputStreamResource;
-
 
16
import org.springframework.http.HttpHeaders;
-
 
17
import org.springframework.http.HttpStatus;
-
 
18
import org.springframework.http.ResponseEntity;
10
import org.springframework.stereotype.Controller;
19
import org.springframework.stereotype.Controller;
11
import org.springframework.transaction.annotation.Transactional;
20
import org.springframework.transaction.annotation.Transactional;
12
import org.springframework.ui.Model;
21
import org.springframework.ui.Model;
13
import org.springframework.web.bind.annotation.RequestBody;
22
import org.springframework.web.bind.annotation.RequestBody;
14
import org.springframework.web.bind.annotation.RequestMapping;
23
import org.springframework.web.bind.annotation.RequestMapping;
15
import org.springframework.web.bind.annotation.RequestMethod;
24
import org.springframework.web.bind.annotation.RequestMethod;
16
import org.springframework.web.bind.annotation.RequestParam;
25
import org.springframework.web.bind.annotation.RequestParam;
17
 
26
 
-
 
27
import com.spice.profitmandi.common.enumuration.DateTimePattern;
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
28
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.model.CreateSchemeRequest;
29
import com.spice.profitmandi.common.model.CreateSchemeRequest;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
30
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
31
import com.spice.profitmandi.common.model.SchemeModel;
-
 
32
import com.spice.profitmandi.common.util.ExcelUtils;
-
 
33
import com.spice.profitmandi.common.util.StringUtils;
21
import com.spice.profitmandi.dao.entity.catalog.Scheme;
34
import com.spice.profitmandi.dao.entity.catalog.Scheme;
22
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
35
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
-
 
36
import com.spice.profitmandi.service.inventory.InventoryService;
23
import com.spice.profitmandi.service.scheme.SchemeService;
37
import com.spice.profitmandi.service.scheme.SchemeService;
24
import com.spice.profitmandi.web.model.LoginDetails;
38
import com.spice.profitmandi.web.model.LoginDetails;
25
import com.spice.profitmandi.web.util.CookiesProcessor;
39
import com.spice.profitmandi.web.util.CookiesProcessor;
26
 
40
 
27
@Controller
41
@Controller
Line 36... Line 50...
36
	@Autowired
50
	@Autowired
37
	private SchemeRepository schemeRepository;
51
	private SchemeRepository schemeRepository;
38
 
52
 
39
	@Autowired
53
	@Autowired
40
	private CookiesProcessor cookiesProcessor;
54
	private CookiesProcessor cookiesProcessor;
-
 
55
	
-
 
56
	@Autowired
-
 
57
	private InventoryService inventoryService;
41
 
58
 
42
	@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
59
	@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
43
	public String createScheme(HttpServletRequest request, Model model){
60
	public String createScheme(HttpServletRequest request, Model model){
-
 
61
		//Map<Integer, String> itemIdItemDescriptionMap = inventoryService.getAllItemIdItemDescriptionMap();
-
 
62
		//model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
-
 
63
		model.addAttribute("brands", inventoryService.getAllBrands());
44
		return "create-scheme";
64
		return "create-scheme";
45
	}
65
	}
46
	
66
	
-
 
67
	@RequestMapping(value = "/getItemsByBrand", method = RequestMethod.GET)
-
 
68
	public String getItemsByBrand(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.BRAND) String brand, Model model){
-
 
69
		Map<Integer, String> itemIdItemDescriptionMap = inventoryService.getAllItemIdItemDescriptionMap(brand);
-
 
70
		model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
-
 
71
		//model.addAttribute("brands", inventoryService.getAllBrands());
-
 
72
		return "items-description";
-
 
73
	}
-
 
74
	
-
 
75
	
47
	@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
76
	@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
48
	public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model)  throws ProfitMandiBusinessException{
77
	public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model)  throws ProfitMandiBusinessException{
49
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
78
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
50
		LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
79
		LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
51
		schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
80
		schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
Line 87... Line 116...
87
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
116
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
88
		model.addAttribute("schemes", schemes);
117
		model.addAttribute("schemes", schemes);
89
		return "schemes-paginated";
118
		return "schemes-paginated";
90
	}
119
	}
91
	
120
	
-
 
121
	@RequestMapping(value = "/schemes/downloadPage", method = RequestMethod.GET)
-
 
122
	public String downloadPage(HttpServletRequest request, Model model){
-
 
123
		return "schemes-download";
-
 
124
	}
-
 
125
	
-
 
126
	@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
-
 
127
	public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_DATE_TIME) String startDateTimeString, @RequestParam(name = ProfitMandiConstants.END_DATE_TIME) String endDateTimeString, Model model) throws ProfitMandiBusinessException{
-
 
128
		LocalDateTime startDateTime = StringUtils.toDateTime(startDateTimeString, DateTimePattern.DD_MM_YYYY_T_HH_MM_SS);
-
 
129
		LocalDateTime endDateTime = StringUtils.toDateTime(endDateTimeString, DateTimePattern.DD_MM_YYYY_T_HH_MM_SS);
-
 
130
		
-
 
131
		List<SchemeModel> schemeModels = schemeService.getAllSchemeModels(startDateTime, endDateTime);
-
 
132
		
-
 
133
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-
 
134
		ExcelUtils.writeSchemeModels(schemeModels, byteArrayOutputStream);
-
 
135
		
-
 
136
		final HttpHeaders headers=new HttpHeaders();
-
 
137
        headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
-
 
138
		headers.set("Content-disposition", "inline; filename=SchemesReport.xlsx");
-
 
139
        headers.setContentLength(byteArrayOutputStream.toByteArray().length);
-
 
140
        final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
-
 
141
        final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
-
 
142
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
-
 
143
		
-
 
144
		//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
-
 
145
	}
-
 
146
	
92
	@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
147
	@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
93
	public String getSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)  throws ProfitMandiBusinessException{
148
	public String getSchemeById(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)  throws ProfitMandiBusinessException{
94
		Scheme scheme = schemeService.getSchemeById(schemeId);
149
		Scheme scheme = schemeService.getSchemeById(schemeId);
95
		model.addAttribute("scheme", scheme);
150
		model.addAttribute("scheme", scheme);
96
		return "scheme-details";
151
		return "scheme-details";