Subversion Repositories SmartDukaan

Rev

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

Rev 22927 Rev 23203
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;
3
import java.io.ByteArrayInputStream;
4
import java.io.ByteArrayOutputStream;
4
import java.io.ByteArrayOutputStream;
5
import java.io.InputStream;
5
import java.io.InputStream;
6
import java.time.LocalDateTime;
-
 
7
import java.util.ArrayList;
-
 
8
import java.util.HashSet;
6
import java.util.HashSet;
9
import java.util.List;
7
import java.util.List;
10
import java.util.Map;
8
import java.util.Map;
11
import java.util.Set;
9
import java.util.Set;
12
 
10
 
Line 27... Line 25...
27
import org.springframework.web.bind.annotation.RequestBody;
25
import org.springframework.web.bind.annotation.RequestBody;
28
import org.springframework.web.bind.annotation.RequestMapping;
26
import org.springframework.web.bind.annotation.RequestMapping;
29
import org.springframework.web.bind.annotation.RequestMethod;
27
import org.springframework.web.bind.annotation.RequestMethod;
30
import org.springframework.web.bind.annotation.RequestParam;
28
import org.springframework.web.bind.annotation.RequestParam;
31
 
29
 
-
 
30
import com.spice.profitmandi.common.enumuration.SearchType;
32
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
31
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
33
import com.spice.profitmandi.common.model.CartFofo;
32
import com.spice.profitmandi.common.model.CartFofo;
34
import com.spice.profitmandi.common.model.CreateOrderRequest;
33
import com.spice.profitmandi.common.model.CreateOrderRequest;
35
import com.spice.profitmandi.common.model.PdfModel;
34
import com.spice.profitmandi.common.model.PdfModel;
36
import com.spice.profitmandi.common.model.PriceModel;
35
import com.spice.profitmandi.common.model.PriceModel;
37
import com.spice.profitmandi.common.model.ProfitMandiConstants;
36
import com.spice.profitmandi.common.model.ProfitMandiConstants;
38
import com.spice.profitmandi.common.util.PdfUtils;
37
import com.spice.profitmandi.common.util.PdfUtils;
39
import com.spice.profitmandi.common.util.StringUtils;
-
 
40
import com.spice.profitmandi.common.web.util.ResponseSender;
38
import com.spice.profitmandi.common.web.util.ResponseSender;
41
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
39
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
42
import com.spice.profitmandi.dao.entity.fofo.Customer;
40
import com.spice.profitmandi.dao.entity.fofo.Customer;
43
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
41
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
44
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
42
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
Line 186... Line 184...
186
        final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
184
        final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
187
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
185
        return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
188
	}
186
	}
189
	
187
	
190
	@RequestMapping(value = "/saleHistory")
188
	@RequestMapping(value = "/saleHistory")
191
	public String saleHistory(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.INVOICE_NUMBER, defaultValue = "") String invoiceNumber, @RequestParam(name = "searchType",defaultValue="") String searchType, Model model) throws ProfitMandiBusinessException{
189
	public String saleHistory(HttpServletRequest request, @RequestParam(name = "searchValue", defaultValue = "") String searchValue, @RequestParam(name = "searchType", defaultValue="") SearchType searchType, @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, Model model) throws ProfitMandiBusinessException{
192
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
190
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
193
		
191
		
194
		LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
-
 
195
		LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
-
 
196
		long countItems = 0;
-
 
197
		List<FofoOrder> fofoOrders = new ArrayList<>();
-
 
198
		if(searchType.equalsIgnoreCase(ProfitMandiConstants.INVOICE_NUMBER) && !invoiceNumber.isEmpty()){
-
 
199
			try {
-
 
200
				FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndInvoiceNumber(loginDetails.getFofoId(), invoiceNumber);
-
 
201
				fofoOrders.add(fofoOrder);
-
 
202
			} catch (ProfitMandiBusinessException e) {
-
 
203
				LOGGER.info("Sale history not found : ", e);
-
 
204
			}
-
 
205
		}else{
-
 
206
			fofoOrders = fofoOrderRepository.selectByFofoId(loginDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
192
		Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue, startTimeString, endTimeString, offset, limit);
207
			countItems = fofoOrderRepository.selectCount(loginDetails.getFofoId(), startDateTime, endDateTime, invoiceNumber, searchType);
-
 
208
		}
-
 
209
		
-
 
210
		model.addAttribute("saleHistories", fofoOrders);
-
 
211
		model.addAttribute("start", offset + 1);
-
 
212
		model.addAttribute("size", countItems);
193
		model.addAllAttributes(map);
213
		model.addAttribute("searchType", searchType);
-
 
214
		model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
-
 
215
		model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
-
 
216
		if (fofoOrders.size() < limit){
-
 
217
			model.addAttribute("end", offset + fofoOrders.size());
-
 
218
		}
-
 
219
		else{
-
 
220
			model.addAttribute("end", offset + limit);
-
 
221
		}
-
 
222
		
194
		
223
		return "sale-history";
195
		return "sale-history";
224
	}
196
	}
225
	
197
	
226
	
198
	
227
	@RequestMapping(value = "/getPaginatedSaleHistory")
199
	@RequestMapping(value = "/getPaginatedSaleHistory")
228
	public String getSaleHistoryPaginated(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.INVOICE_NUMBER, defaultValue="") String invoiceNumber, @RequestParam(name = "searchType", defaultValue = "") String searchType, Model model) throws ProfitMandiBusinessException{
200
	public String getSaleHistoryPaginated(HttpServletRequest request, @RequestParam(name = "searchValue", defaultValue="") String searchValue, @RequestParam(name = "searchType", defaultValue = "") SearchType searchType, @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, Model model) throws ProfitMandiBusinessException{
229
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
201
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
230
		
202
		
231
		LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
203
		Map<String, Object> map = orderService.getSaleHistoryPaginated(loginDetails.getFofoId(), searchType, searchValue, startTimeString, endTimeString, offset, limit);
232
		LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
204
		model.addAllAttributes(map);
233
 
205
		
234
		List<FofoOrder> saleHistories = fofoOrderRepository.selectByFofoId(loginDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
-
 
235
		model.addAttribute("saleHistories", saleHistories);
-
 
236
		return "sale-history-paginated";
206
		return "sale-history-paginated";
237
	}
207
	}
238
 
208
 
239
}
209
}