Subversion Repositories SmartDukaan

Rev

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

Rev 33092 Rev 33102
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import com.spice.profitmandi.common.enumuration.ReporticoProject;
3
import com.spice.profitmandi.common.enumuration.ReporticoProject;
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
5
import com.spice.profitmandi.common.model.CustomRetailer;
5
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
6
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
6
import com.spice.profitmandi.common.services.ReporticoService;
7
import com.spice.profitmandi.common.services.ReporticoService;
7
import com.spice.profitmandi.common.util.FileUtil;
8
import com.spice.profitmandi.common.util.FileUtil;
-
 
9
import com.spice.profitmandi.common.util.FormattingUtils;
8
import com.spice.profitmandi.dao.entity.auth.AuthUser;
10
import com.spice.profitmandi.dao.entity.auth.AuthUser;
9
import com.spice.profitmandi.dao.model.CollectionSummary;
11
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
12
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
-
 
13
import com.spice.profitmandi.dao.model.*;
10
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
14
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
11
import com.spice.profitmandi.dao.repository.cs.CsService;
15
import com.spice.profitmandi.dao.repository.cs.CsService;
12
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
16
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
13
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
17
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
-
 
18
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
-
 
19
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
-
 
20
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
14
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
21
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
15
import com.spice.profitmandi.service.authentication.RoleManager;
22
import com.spice.profitmandi.service.authentication.RoleManager;
16
import com.spice.profitmandi.service.order.OrderService;
23
import com.spice.profitmandi.service.order.OrderService;
-
 
24
import com.spice.profitmandi.service.user.RetailerService;
17
import com.spice.profitmandi.web.model.LoginDetails;
25
import com.spice.profitmandi.web.model.LoginDetails;
18
import com.spice.profitmandi.web.util.CookiesProcessor;
26
import com.spice.profitmandi.web.util.CookiesProcessor;
19
import org.apache.http.HttpResponse;
27
import org.apache.http.HttpResponse;
20
import org.apache.logging.log4j.LogManager;
28
import org.apache.logging.log4j.LogManager;
21
import org.apache.logging.log4j.Logger;
29
import org.apache.logging.log4j.Logger;
Line 34... Line 42...
34
import java.time.LocalDate;
42
import java.time.LocalDate;
35
import java.time.LocalDateTime;
43
import java.time.LocalDateTime;
36
import java.time.LocalTime;
44
import java.time.LocalTime;
37
import java.time.format.DateTimeFormatter;
45
import java.time.format.DateTimeFormatter;
38
import java.util.*;
46
import java.util.*;
-
 
47
import java.util.stream.Collectors;
39
 
48
 
40
@Controller
49
@Controller
41
@Transactional(rollbackFor = Throwable.class)
50
@Transactional(rollbackFor = Throwable.class)
42
public class ReportsController {
51
public class ReportsController {
43
 
-
 
-
 
52
	private static final Logger LOGGER = LogManager.getLogger(OrderController.class);
44
	@Autowired
53
	@Autowired
45
	private RoleRepository roleRepository;
54
	private RoleRepository roleRepository;
46
 
55
 
47
	@Autowired
56
	@Autowired
-
 
57
	private FofoOrderRepository fofoOrderRepository;
-
 
58
 
-
 
59
	@Autowired
-
 
60
	private RetailerService retailerService;
-
 
61
 
-
 
62
	@Autowired
-
 
63
	private PendingOrderItemRepository pendingOrderItemRepository;
-
 
64
 
-
 
65
	@Autowired
-
 
66
	private PendingOrderService pendingOrderService;
-
 
67
 
-
 
68
	@Autowired
48
	private CookiesProcessor cookiesProcessor;
69
	private CookiesProcessor cookiesProcessor;
49
	
-
 
50
	@Autowired
70
	@Autowired
51
	private FofoStoreRepository fofoStoreRepository;
71
	private FofoStoreRepository fofoStoreRepository;
52
 
72
 
53
	@Autowired
73
	@Autowired
54
	private ReporticoService reporticoService;
74
	private ReporticoService reporticoService;
55
 
75
 
56
	@Autowired
76
	@Autowired
57
	private OrderRepository orderRepository;
77
	private OrderRepository orderRepository;
58
	@Autowired
78
	@Autowired
59
	private RoleManager roleManager;
79
	private RoleManager roleManager;
60
	
-
 
61
	@Autowired
80
	@Autowired
62
	private OrderService  orderService;
81
	private OrderService orderService;
63
 
82
 
64
	@Autowired
83
	@Autowired
65
	private CsService csService;
84
	private CsService csService;
66
 
85
 
67
	@Autowired
86
	@Autowired
Line 69... Line 88...
69
 
88
 
70
	private static final Logger Logger = LogManager.getLogger(OrderController.class);
89
	private static final Logger Logger = LogManager.getLogger(OrderController.class);
71
 
90
 
72
	@RequestMapping(value = "/reports/{projectName}/{fileName}")
91
	@RequestMapping(value = "/reports/{projectName}/{fileName}")
73
	public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
92
	public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
74
			@PathVariable ReporticoProject projectName, @RequestBody(required = false) Map<String, String> paramsMap)
93
										 @PathVariable ReporticoProject projectName, @RequestBody(required = false) Map<String, String> paramsMap)
75
			throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
94
			throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
76
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
95
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
77
		HttpResponse response;
96
		HttpResponse response;
78
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
97
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
79
 
98
 
Line 109... Line 128...
109
		headers.setContentLength(response.getEntity().getContentLength());
128
		headers.setContentLength(response.getEntity().getContentLength());
110
		return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
129
		return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
111
	}
130
	}
112
 
131
 
113
	private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
132
	private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
114
			Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
133
											Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
115
		return reporticoService.getReportFile(projectName, fileName, reportParams);
134
		return reporticoService.getReportFile(projectName, fileName, reportParams);
116
	}
135
	}
117
	
136
 
118
	@RequestMapping(value = "/collectionSummary", method = RequestMethod.GET)
137
	@RequestMapping(value = "/collectionSummary", method = RequestMethod.GET)
119
	public String getCollectionSummary(HttpServletRequest request,
138
	public String getCollectionSummary(HttpServletRequest request,
120
			Model model) throws ProfitMandiBusinessException {
139
									   Model model) throws ProfitMandiBusinessException {
121
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
140
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
122
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
141
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
123
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
142
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
124
		LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
143
		LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
125
		
-
 
126
		List<CollectionSummary> collectionSummaryList =orderRepository.selectCollectionSummary(fofoDetails.getFofoId(),currentStartMonth, currentDate);
144
		List<CollectionSummary> collectionSummaryList = orderRepository.selectCollectionSummary(fofoDetails.getFofoId(), currentStartMonth, currentDate);
127
		
-
 
128
		Logger.info("CollectionSummaryList {}", collectionSummaryList);
145
		Logger.info("CollectionSummaryList {}", collectionSummaryList);
129
		
-
 
130
		model.addAttribute("startDate",currentDate.minusDays(30).toLocalDate());
146
		model.addAttribute("startDate", currentDate.minusDays(30).toLocalDate());
131
		model.addAttribute("endDate", LocalDate.now());
147
		model.addAttribute("endDate", LocalDate.now());
132
		model.addAttribute("collectionSummaryList", collectionSummaryList);
148
		model.addAttribute("collectionSummaryList", collectionSummaryList);
133
		model.addAttribute("isAdmin", isAdmin);
149
		model.addAttribute("isAdmin", isAdmin);
134
		return "partner-collection-summary";
150
		return "partner-collection-summary";
135
	}
151
	}
-
 
152
 
136
	@RequestMapping(value = "/collectionSummaryFetchReportByDate", method = RequestMethod.GET)
153
	@RequestMapping(value = "/collectionSummaryFetchReportByDate", method = RequestMethod.GET)
137
	public String getcollectionSummaryFetchReport(HttpServletRequest request,
154
	public String getcollectionSummaryFetchReport(HttpServletRequest request,
138
												  @RequestParam(defaultValue = "0") int fofoId,
155
												  @RequestParam(defaultValue = "0") int fofoId,
139
											 @RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
156
												  @RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
140
											 @RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
157
												  @RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
141
			throws Exception {
158
			throws Exception {
142
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
159
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
143
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
160
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
144
		if (isAdmin) {
161
		if (isAdmin) {
145
			startDate = LocalDate.now().minusDays(30);
162
			startDate = LocalDate.now().minusDays(30);
146
			endDate = LocalDate.now();
163
			endDate = LocalDate.now();
147
		}
164
		}
148
		model.addAttribute("startDate",startDate);
165
		model.addAttribute("startDate", startDate);
149
		model.addAttribute("endDate", endDate);
166
		model.addAttribute("endDate", endDate);
150
		model.addAttribute("isAdmin", isAdmin);
167
		model.addAttribute("isAdmin", isAdmin);
151
 
168
 
152
 
169
 
153
		if (isAdmin) {
170
		if (isAdmin) {
Line 168... Line 185...
168
			model.addAttribute("collectionSummaryList", collectionSummaryList);
185
			model.addAttribute("collectionSummaryList", collectionSummaryList);
169
			return "partner-collection-summary";
186
			return "partner-collection-summary";
170
 
187
 
171
		}
188
		}
172
	}
189
	}
173
	
190
 
174
	@RequestMapping(value = "/downloadCollectionSummary", method = RequestMethod.GET)
191
	@RequestMapping(value = "/downloadCollectionSummary", method = RequestMethod.GET)
175
	public ResponseEntity<?>  getDownloadCollectionSummary(HttpServletRequest request,
192
	public ResponseEntity<?> getDownloadCollectionSummary(HttpServletRequest request,
-
 
193
														  @RequestParam int fofoId,
176
			@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
194
														  @RequestParam(name = "startDate") LocalDate startDate,
177
			@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate,Model model) throws Exception {
195
														  @RequestParam(name = "endDate") LocalDate endDate, Model model) throws Exception {
178
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
196
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
179
		List<List<?>> rows = new ArrayList<>();
197
		List<List<?>> rows = new ArrayList<>();
180
 
-
 
-
 
198
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
199
		List<CollectionSummary> collectionSummaryList = null;
-
 
200
		if (isAdmin) {
-
 
201
			collectionSummaryList = orderRepository.selectCollectionSummary(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
181
		
202
		} else {
-
 
203
			fofoId = fofoDetails.getFofoId();
182
		List<CollectionSummary> collectionSummaryList =orderRepository.selectCollectionSummary(fofoDetails.getFofoId(),startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
204
			collectionSummaryList = orderRepository.selectCollectionSummary(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
183
		
205
		}
184
		Logger.info("CollectionSummaryList {}", collectionSummaryList);
206
		Logger.info("CollectionSummaryList {}", collectionSummaryList);
185
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
207
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
186
		
-
 
187
		for( CollectionSummary cs : collectionSummaryList) {
208
		for (CollectionSummary cs : collectionSummaryList) {
188
			
-
 
189
			rows.add(Arrays.asList(cs.getDate().format(
209
			rows.add(Arrays.asList(cs.getDate().format(
190
					dateTimeFormatter), cs.getReferenceType(),cs.getCash(),cs.getPinelabs(),cs.getBajajFinserv(),cs.getHomeCredit(),cs.getPaytm(),
210
							dateTimeFormatter), cs.getReferenceType(), cs.getCash(), cs.getPinelabs(), cs.getBajajFinserv(), cs.getHomeCredit(), cs.getPaytm(),
191
					cs.getCapitalFirst(),cs.getZestMoney(),cs.getSamsungSure(),cs.getTotalAmount()));
211
					cs.getCapitalFirst(), cs.getZestMoney(), cs.getSamsungSure(), cs.getTotalAmount()));
192
			
-
 
193
			
-
 
194
		}
212
		}
195
		
-
 
196
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
213
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
197
				.getCSVByteStream(Arrays.asList("Date", "Reference Type", "Cash","Pinelabs", "Bajaj Finservice", "Home Credit", "Paymt",
214
				.getCSVByteStream(Arrays.asList("Date", "Reference Type", "Cash", "Pinelabs", "Bajaj Finservice", "Home Credit", "Paymt",
198
						"Capital First", "Zest Money", "Samsung Sure", "Total Amount"), rows);
215
						"Capital First", "Zest Money", "Samsung Sure", "Total Amount"), rows);
-
 
216
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Collection Summary Report");
-
 
217
 
-
 
218
		return responseEntity;
-
 
219
	}
-
 
220
 
-
 
221
	@RequestMapping(value = "/franchiseeSalesReport", method = RequestMethod.GET)
-
 
222
	public String getFranchiseeSalesReport(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
-
 
223
										   @RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
-
 
224
			throws ProfitMandiBusinessException {
-
 
225
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
226
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
-
 
227
		if (startDate == null) {
-
 
228
			startDate = LocalDate.now().minusDays(30);
-
 
229
 
-
 
230
		}
-
 
231
		endDate = LocalDate.now();
-
 
232
		model.addAttribute("startDate", startDate);
-
 
233
		model.addAttribute("endDate", endDate);
-
 
234
		model.addAttribute("isAdmin", isAdmin);
-
 
235
		LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
-
 
236
		if (isAdmin) {
-
 
237
			if (fofoId == 0) {
-
 
238
				//No need to pull any data
-
 
239
				model.addAttribute("focoSaleReportList", new ArrayList<>());
-
 
240
				return "foco-sale-report";
-
 
241
 
-
 
242
			}
-
 
243
		} else {
-
 
244
			fofoId = loginDetails.getFofoId();
-
 
245
		}
-
 
246
 
-
 
247
 
-
 
248
		FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
249
 
-
 
250
		List<FocoSaleReportModel> focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoId, fs.getCode(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
251
		model.addAttribute("focoSaleReportList", focoSaleReportList);
-
 
252
		return "foco-sale-report";
-
 
253
	}
-
 
254
 
-
 
255
	@RequestMapping(value = "/franchiseeSalesFetchReportByDate", method = RequestMethod.GET)
-
 
256
	public String getfranchiseeSalesFetchReport(HttpServletRequest request, Model model,
-
 
257
												@RequestParam(defaultValue = "0") int fofoId,
-
 
258
												@RequestParam(required = false) LocalDate startDate,
-
 
259
												@RequestParam(required = false) LocalDate endDate)
-
 
260
			throws Exception {
-
 
261
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
262
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
-
 
263
		if (startDate == null) {
-
 
264
 
-
 
265
			startDate = LocalDate.now().minusDays(30);
-
 
266
			endDate = LocalDate.now();
-
 
267
		}
-
 
268
		model.addAttribute("startDate", startDate);
-
 
269
		model.addAttribute("endDate", endDate);
-
 
270
		model.addAttribute("isAdmin", isAdmin);
-
 
271
 
-
 
272
		// List<List<?>> rows = new ArrayList<>();
-
 
273
 
-
 
274
		LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
-
 
275
		if (isAdmin) {
-
 
276
			if (fofoId == 0) {
-
 
277
				//no need any data
-
 
278
				model.addAttribute("focoSaleReportList", new ArrayList<>());
-
 
279
				return "foco-sale-report";
-
 
280
			}
-
 
281
		} else {
-
 
282
			fofoId = loginDetails.getFofoId();
-
 
283
		}
-
 
284
		FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
285
		List<FocoSaleReportModel> focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoId, fs.getCode(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
286
		model.addAttribute("focoSaleReportList", focoSaleReportList);
-
 
287
		return "foco-sale-report";
-
 
288
	}
-
 
289
 
-
 
290
 
-
 
291
	@RequestMapping(value = "/downloadFranchiseeSales", method = RequestMethod.GET)
-
 
292
	public ResponseEntity<?> getdownloadFranchiseeSales(HttpServletRequest request,
-
 
293
														@RequestParam int fofoId,
-
 
294
														@RequestParam(name = "startDate") LocalDate startDate,
-
 
295
														@RequestParam(name = "endDate") LocalDate endDate,
-
 
296
														Model model)
-
 
297
			throws Exception {
-
 
298
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
299
 
-
 
300
		List<List<?>> rows = new ArrayList<>();
-
 
301
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
302
		List<FocoSaleReportModel> focoSaleReportList = null;
-
 
303
		FofoStore fs = null;
-
 
304
		if (isAdmin) {
-
 
305
			fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
306
			focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoId,
-
 
307
					fs.getCode(), startDate.atStartOfDay(), endDate.atStartOfDay());
-
 
308
 
-
 
309
		} else {
-
 
310
			fofoId = fofoDetails.getFofoId();
-
 
311
			fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
312
 
-
 
313
			focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoDetails.getFofoId(),
-
 
314
					fs.getCode(), startDate.atStartOfDay(), endDate.atStartOfDay());
-
 
315
		}
-
 
316
		LOGGER.info("FocoSaleReportList {}", focoSaleReportList);
-
 
317
		String partnerName = null;
-
 
318
		for (FocoSaleReportModel fsr : focoSaleReportList) {
-
 
319
			partnerName = fsr.getName();
-
 
320
			rows.add(Arrays.asList(fsr.getCode(), fsr.getName(), fsr.getCity(), fsr.getState(), fsr.getRegion(),
-
 
321
					fsr.getItemId(), fsr.getBrand(), fsr.getModelName(), fsr.getModelNumber(), fsr.getColor(),
-
 
322
					fsr.getQuantity(), fsr.getDp(), fsr.getSellingPrice(), fsr.getMop(), fsr.getSerialNumber(),
-
 
323
					FormattingUtils.format(fsr.getCreateDate()), fsr.getCustomerName(), fsr.getCustomerPhone(),
-
 
324
					fsr.getCustomerCity(), fsr.getCustomerPincode(), fsr.getInvoiceNumber(), fsr.getPurchaseReference(),
-
 
325
					fsr.getCustomerGstNumber(), FormattingUtils.format(fsr.getCancelledTimestamp()),
-
 
326
					FormattingUtils.format(fsr.getGrnCompleteDate()), fsr.getHygieneRating(), fsr.getRating(),
-
 
327
					fsr.getStatus(), fsr.getRemark(), FormattingUtils.format(fsr.getCreatedTimestamp()),
-
 
328
					FormattingUtils.format(fsr.getDisposedTimestamp()),
-
 
329
					FormattingUtils.format(fsr.getNextTimestamp()),
-
 
330
					FormattingUtils.format(fsr.getActivationTimestamp()),
-
 
331
					FormattingUtils.format(fsr.getActivationTimestamp()), fsr.getLabel()));
-
 
332
 
-
 
333
		}
-
 
334
 
-
 
335
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
-
 
336
				Arrays.asList("Code", "Name", "City", "State", "Region", "Item Id", "Brand", "Model Name",
-
 
337
						"Model Number", "Color", "Quantity", "Dp", "Selling_Price", "mop", "Serial Number",
-
 
338
						"Create Date", "Customer Name", "Customer Phone", "Customer City", " Customer Pincode",
-
 
339
						"Invoice  Number", "Purchase Reference", "Customer Gst Number", " Cancelled Timestamp",
-
 
340
						"GRN Complete Date", "Hygiene Rating", "Rating", "Status", "Remark", "Created Timestamp",
-
 
341
						"Disposed Timestamp", " Next Timestamp", "Activation Timestamp", "Create Timestamp", "Label"),
-
 
342
				rows);
-
 
343
 
-
 
344
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, partnerName + " Franchisee Sales Report");
-
 
345
 
-
 
346
		return responseEntity;
-
 
347
 
-
 
348
	}
-
 
349
 
-
 
350
	@RequestMapping(value = "/downloadWalletSummaryReport", method = RequestMethod.GET)
-
 
351
	public ResponseEntity<?> getDownloadWalletSummaryReport(HttpServletRequest request,
-
 
352
															@RequestParam(defaultValue = "0", name = "fofoId") int fofoId,
-
 
353
															@RequestParam(name = "startDate") LocalDate startDate,
-
 
354
															@RequestParam(name = "endDate") LocalDate endDate, Model model)
-
 
355
			throws Exception {
-
 
356
 
-
 
357
		List<List<?>> rows = new ArrayList<>();
-
 
358
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
359
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
360
		List<WalletSummaryReportModel> walletSummartList = null;
-
 
361
		if (isAdmin) {
-
 
362
			walletSummartList = fofoOrderRepository.selectWalletSummaryReport(
-
 
363
					fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
364
		} else {
-
 
365
 
-
 
366
			walletSummartList = fofoOrderRepository.selectWalletSummaryReport(
-
 
367
					fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
199
		
368
		}
-
 
369
		LOGGER.info("walletSummartList {}", fofoId);
-
 
370
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
-
 
371
		String partnerName = null;
-
 
372
 
-
 
373
		for (WalletSummaryReportModel walletSummary : walletSummartList) {
-
 
374
			partnerName = walletSummary.getName();
-
 
375
 
-
 
376
			rows.add(Arrays.asList(
-
 
377
					walletSummary.getId(),
-
 
378
					walletSummary.getCode(),
-
 
379
					walletSummary.getName(),
-
 
380
					walletSummary.getEmail(),
-
 
381
					walletSummary.getPhone(),
-
 
382
					walletSummary.getAmount(),
-
 
383
					walletSummary.getRefundableAmount(),
-
 
384
					walletSummary.getReference(),
-
 
385
					walletSummary.getReferenceType(),
-
 
386
					FormattingUtils.format(walletSummary.getBusinessTimestamp())));
-
 
387
 
-
 
388
		}
-
 
389
 
-
 
390
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
391
				.getCSVByteStream(Arrays.asList("Id", "Code", "Name", "Email", "Phone", "Amount", "Refundable_amount",
-
 
392
						"Reference", "Reference_type", "Business_timestamp", "Description"), rows);
-
 
393
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, partnerName + " Wallet Statement Report");
-
 
394
 
-
 
395
		return responseEntity;
-
 
396
 
-
 
397
	}
-
 
398
 
-
 
399
	@RequestMapping(value = "/walletSummaryFetchReportByDate", method = RequestMethod.GET)
-
 
400
	public String getwalletSummaryFetchReport(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
-
 
401
											  @RequestParam(required = false) LocalDate startDate,
-
 
402
											  @RequestParam(required = false) LocalDate endDate)
-
 
403
			throws Exception {
-
 
404
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
405
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
-
 
406
		if (startDate == null) {
-
 
407
			startDate = LocalDate.now().minusDays(30);
-
 
408
		}
-
 
409
		endDate = LocalDate.now();
-
 
410
		model.addAttribute("startDate", startDate);
-
 
411
		model.addAttribute("endDate", endDate);
-
 
412
		model.addAttribute("isAdmin", isAdmin);
-
 
413
		if (isAdmin) {
-
 
414
			if (fofoId == 0) {
-
 
415
				//No need to send any data
-
 
416
				model.addAttribute("walletSummartList", new ArrayList<>());
-
 
417
 
-
 
418
				return "wallet-summary-report";
-
 
419
			} else {
-
 
420
				List<WalletSummaryReportModel> walletSummartList = fofoOrderRepository
-
 
421
						.selectWalletSummaryReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
422
				model.addAttribute("walletSummartList", walletSummartList);
-
 
423
 
-
 
424
				return "wallet-summary-report";
-
 
425
			}
-
 
426
 
-
 
427
		} else {
-
 
428
 
-
 
429
 
-
 
430
			FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
431
			List<WalletSummaryReportModel> walletSummartList = fofoOrderRepository
-
 
432
					.selectWalletSummaryReport(loginDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
433
			//LOGGER.info("walletSummartList {}", walletSummartList);
-
 
434
 
-
 
435
			model.addAttribute("walletSummartList", walletSummartList);
-
 
436
 
-
 
437
			return "wallet-summary-report";
-
 
438
		}
-
 
439
	}
-
 
440
 
-
 
441
	@RequestMapping(value = "/walletSummaryReport", method = RequestMethod.GET)
-
 
442
	public String getWalletSummaryReport(HttpServletRequest request, Model model) throws Exception {
-
 
443
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
444
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
445
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
446
		LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
-
 
447
 
-
 
448
		List<WalletSummaryReportModel> walletSummartList = fofoOrderRepository
-
 
449
				.selectWalletSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
-
 
450
		LOGGER.info("walletSummartList {}", walletSummartList);
-
 
451
 
-
 
452
		model.addAttribute("startDate", currentDate.minusDays(30).toLocalDate());
-
 
453
		model.addAttribute("endDate", LocalDate.now());
-
 
454
		model.addAttribute("walletSummartList", walletSummartList);
-
 
455
		model.addAttribute("isAdmin", isAdmin);
-
 
456
 
-
 
457
		return "wallet-summary-report";
-
 
458
	}
-
 
459
 
-
 
460
	@RequestMapping(value = "/pendingIndentReport", method = RequestMethod.GET)
-
 
461
	public String getPendingIndentReport(HttpServletRequest request, Model model) throws Exception {
-
 
462
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
463
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
464
 
-
 
465
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
466
		LocalDateTime currentStartMonth = currentDate.minusMonths(2).toLocalDate().atStartOfDay();
-
 
467
 
-
 
468
		List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
-
 
469
				.selectPendingIndentReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
-
 
470
		LOGGER.info("pendingIndentReports {}", pendingIndentReports);
-
 
471
 
-
 
472
		model.addAttribute("startDate", currentDate.minusMonths(2).toLocalDate());
-
 
473
		model.addAttribute("endDate", LocalDate.now());
-
 
474
		model.addAttribute("pendingIndentReports", pendingIndentReports);
-
 
475
		model.addAttribute("isAdmin", isAdmin);
-
 
476
 
-
 
477
 
-
 
478
		return "pending-indent-report";
-
 
479
	}
-
 
480
 
-
 
481
	@RequestMapping(value = "/pendingIndentFetchReportByDate", method = RequestMethod.GET)
-
 
482
	public String getpendingIndentFetchReport(
-
 
483
			HttpServletRequest request,
-
 
484
			@RequestParam(defaultValue = "0") int fofoId,
-
 
485
			@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
-
 
486
			@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate,
-
 
487
			Model model
-
 
488
	) throws Exception {
-
 
489
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
490
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
491
		if (startDate == null) {
-
 
492
			startDate = LocalDate.now().minusDays(30);
-
 
493
			endDate = LocalDate.now();
-
 
494
		}
-
 
495
		model.addAttribute("startDate", startDate);
-
 
496
		model.addAttribute("endDate", endDate);
-
 
497
		model.addAttribute("isAdmin", isAdmin);
-
 
498
		if (isAdmin) {
-
 
499
			if (fofoId == 0) {
-
 
500
				model.addAttribute("pendingIndentReports", new ArrayList<>());
-
 
501
				return "pending-indent-report";
-
 
502
			} else {
-
 
503
				List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
-
 
504
						.selectPendingIndentReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
505
				model.addAttribute("pendingIndentReports", pendingIndentReports);
-
 
506
				return "pending-indent-report";
-
 
507
			}
-
 
508
		} else {
-
 
509
			LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
510
			List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
-
 
511
					.selectPendingIndentReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
512
			model.addAttribute("pendingIndentReports", pendingIndentReports);
-
 
513
			return "pending-indent-report";
-
 
514
 
-
 
515
		}
-
 
516
	}
-
 
517
 
-
 
518
 
-
 
519
	@RequestMapping(value = "/pendingIndentReportDownload", method = RequestMethod.GET)
-
 
520
	public ResponseEntity<?> getPendingIndentReportDownload(HttpServletRequest request,
-
 
521
															@RequestParam int fofoId,
-
 
522
															@RequestParam(name = "startDate") LocalDate startDate,
-
 
523
															@RequestParam(name = "endDate") LocalDate endDate, Model model)
-
 
524
			throws Exception {
-
 
525
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
526
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
527
        /*LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
528
        LocalDateTime currentStartMonth = currentDate.minusMonths(2).toLocalDate().atStartOfDay();*/
-
 
529
		List<PendingIndentReportModel> pendingIndentReports = null;
-
 
530
		List<List<?>> rows = new ArrayList<>();
-
 
531
		if (isAdmin) {
-
 
532
			pendingIndentReports = fofoOrderRepository
-
 
533
					.selectPendingIndentReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
534
		} else {
-
 
535
			pendingIndentReports = fofoOrderRepository
-
 
536
					.selectPendingIndentReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
537
 
-
 
538
		}
-
 
539
		LOGGER.info("pendingIndentReports {}", pendingIndentReports);
-
 
540
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
-
 
541
 
-
 
542
		for (PendingIndentReportModel pir : pendingIndentReports) {
-
 
543
 
-
 
544
			rows.add(Arrays.asList(pir.getTransactionId(), pir.getOrderId(),
-
 
545
					pir.getCreatTimestamp().format(dateTimeFormatter), pir.getItemId(), pir.getBrand(),
-
 
546
					pir.getModelName(), pir.getModelNumber(), pir.getColor(), pir.getQuantity(), pir.getUnitPrice(),
-
 
547
					pir.getWalletAmount(), pir.getStatus(), pir.getInvoiceNumber(),
-
 
548
					pir.getBillingTimestamp() == null ? "" : pir.getBillingTimestamp().format(dateTimeFormatter)));
-
 
549
 
-
 
550
		}
-
 
551
 
-
 
552
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList(
-
 
553
				"Transaction Id", "Order Id", "Created_At", "Item_Id", "Brand", "Model Name", "Model Number", "Color",
-
 
554
				"Quantity", "Unit Price", "Wallet Deduction", "Status", "Invoice Number", "Billing Timestamp"), rows);
-
 
555
 
-
 
556
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Order Status Summary Report");
-
 
557
 
-
 
558
		return responseEntity;
-
 
559
	}
-
 
560
 
-
 
561
	@RequestMapping(value = "/schemePayoutReport", method = RequestMethod.GET)
-
 
562
	public String getschemePayoutReport(HttpServletRequest request, Model model,
-
 
563
										@RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
-
 
564
			throws ProfitMandiBusinessException {
-
 
565
 
-
 
566
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
567
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
-
 
568
		if (startDate == null) {
-
 
569
			startDate = LocalDate.now().minusDays(30);
-
 
570
			endDate = LocalDate.now();
-
 
571
		}
-
 
572
		model.addAttribute("startDate", startDate);
-
 
573
		model.addAttribute("endDate", endDate);
-
 
574
		model.addAttribute("isAdmin", isAdmin);
-
 
575
		//LOGGER.info("schemePayoutReports {}", schemePayoutReports);
-
 
576
		List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
-
 
577
				.selectSchemePayoutReport(loginDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
578
		model.addAttribute("schemePayoutReports", schemePayoutReports);
-
 
579
		return "scheme-payout-report";
-
 
580
 
-
 
581
	}
-
 
582
 
-
 
583
	@RequestMapping(value = "/schemePayoutFetchReportByDate", method = RequestMethod.GET)
-
 
584
	public String getschemePayoutFetchReportByDate(
-
 
585
			HttpServletRequest request,
-
 
586
			Model model,
-
 
587
			@RequestParam(defaultValue = "0") int fofoId,
-
 
588
			@RequestParam(required = false) LocalDate startDate,
-
 
589
			@RequestParam(required = false) LocalDate endDate)
-
 
590
			throws ProfitMandiBusinessException {
-
 
591
		//LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
592
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
593
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
-
 
594
		if (startDate == null) {
-
 
595
			startDate = LocalDate.now().minusDays(30);
-
 
596
			endDate = LocalDate.now();
-
 
597
		}
-
 
598
		model.addAttribute("startDate", startDate);
-
 
599
		model.addAttribute("endDate", endDate);
-
 
600
		model.addAttribute("isAdmin", isAdmin);
-
 
601
 
-
 
602
		LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
-
 
603
		if (isAdmin) {
-
 
604
			if (fofoId == 0) {
-
 
605
				//No need to pull any data
-
 
606
				model.addAttribute("schemePayoutReports", new ArrayList<>());
-
 
607
				return "scheme-payout-report";
-
 
608
 
-
 
609
			} else {
-
 
610
				List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
-
 
611
						.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
612
 
-
 
613
				model.addAttribute("schemePayoutReports", schemePayoutReports);
-
 
614
				return "scheme-payout-report";
-
 
615
			}
-
 
616
		} else {
-
 
617
			fofoId = loginDetails.getFofoId();
-
 
618
 
-
 
619
			List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
-
 
620
					.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
621
 
-
 
622
			model.addAttribute("schemePayoutReports", schemePayoutReports);
-
 
623
			return "scheme-payout-report";
-
 
624
		}
-
 
625
 
-
 
626
	}
-
 
627
 
-
 
628
	@RequestMapping(value = "/offerPayoutReport", method = RequestMethod.GET)
-
 
629
	public String getOfferPayoutReport(HttpServletRequest request, Model model, @RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate) throws Exception {
-
 
630
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
631
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
632
 
-
 
633
		if (startDate == null) {
-
 
634
			startDate = LocalDate.now().minusDays(30);
-
 
635
			endDate = LocalDate.now();
-
 
636
		}
-
 
637
		model.addAttribute("startDate", startDate);
-
 
638
		model.addAttribute("endDate", endDate);
-
 
639
 
-
 
640
 
-
 
641
		List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
-
 
642
				.selectOfferPayoutDumpReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
643
		LOGGER.info("offerPayoutDumpReports {}", offerPayoutDumpReports);
-
 
644
 
-
 
645
		model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
-
 
646
		model.addAttribute("isAdmin", isAdmin);
-
 
647
 
-
 
648
		return "offer-payout-dump-report";
-
 
649
	}
-
 
650
 
-
 
651
	@RequestMapping(value = "/offerPayoutFetchReportByDate", method = RequestMethod.GET)
-
 
652
	public String getofferPayoutFetchReportByDate(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
-
 
653
												  @RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
-
 
654
			throws ProfitMandiBusinessException {
-
 
655
 
-
 
656
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
657
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
-
 
658
		if (startDate == null) {
-
 
659
			startDate = LocalDate.now().minusDays(30);
-
 
660
			endDate = LocalDate.now();
-
 
661
		}
-
 
662
		model.addAttribute("startDate", startDate);
-
 
663
		model.addAttribute("endDate", endDate);
-
 
664
		model.addAttribute("isAdmin", isAdmin);
-
 
665
		LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
-
 
666
		if (isAdmin) {
-
 
667
			if (fofoId == 0) {
-
 
668
				//No need to pull any data
-
 
669
				model.addAttribute("offerPayoutReports", new ArrayList<>());
-
 
670
				return "offer-payout-dump-report";
-
 
671
 
-
 
672
			} else {
-
 
673
				List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
-
 
674
						.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
675
 
-
 
676
				model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
-
 
677
 
-
 
678
 
-
 
679
				return "offer-payout-dump-report";
-
 
680
 
-
 
681
			}
-
 
682
		} else {
-
 
683
			fofoId = loginDetails.getFofoId();
-
 
684
			List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
-
 
685
					.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
686
 
-
 
687
			model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
-
 
688
 
-
 
689
 
-
 
690
			return "offer-payout-dump-report";
-
 
691
		}
-
 
692
	}
-
 
693
 
-
 
694
 
-
 
695
	@RequestMapping(value = "/selectPartnerBillingSummaryReport", method = RequestMethod.GET)
-
 
696
	public String getselectPartnerBillingSummaryReport(HttpServletRequest request, Model model) throws Exception {
-
 
697
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
698
 
-
 
699
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
700
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
701
 
-
 
702
		List<PartnerBillingSummaryModel> partnerBillingSummaryReports = fofoOrderRepository
-
 
703
				.selectPartnerBillingSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
-
 
704
 
-
 
705
		model.addAttribute("startDate", currentDate.minusMonths(3).toLocalDate());
-
 
706
		model.addAttribute("endDate", LocalDate.now());
-
 
707
		model.addAttribute("partnerBillingSummaryReports", partnerBillingSummaryReports);
-
 
708
 
-
 
709
		return "partner-billing-summary-report";
-
 
710
	}
-
 
711
 
-
 
712
	@RequestMapping(value = "/priceDropReport", method = RequestMethod.GET)
-
 
713
	public String getSelectPriceDropReport(HttpServletRequest request, @RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
-
 
714
										   @RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model) throws Exception {
-
 
715
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
716
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
717
		if (startDate == null) {
-
 
718
			startDate = LocalDate.now().minusDays(30);
-
 
719
			endDate = LocalDate.now();
-
 
720
		}
-
 
721
		model.addAttribute("startDate", startDate);
-
 
722
		model.addAttribute("endDate", endDate);
-
 
723
		model.addAttribute("isAdmin", isAdmin);
-
 
724
		List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoDetails.getFofoId(),
-
 
725
				startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
726
		model.addAttribute("priceDropReports", priceDropReports);
-
 
727
 
-
 
728
		return "price-drop-report";
-
 
729
	}
-
 
730
 
-
 
731
	@RequestMapping(value = "/priceDropFetchReportByDate", method = RequestMethod.GET)
-
 
732
	public String getpriceDropFetchReportByDate(HttpServletRequest request,
-
 
733
												@RequestParam(defaultValue = "0") int fofoId,
-
 
734
												@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
-
 
735
												@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
-
 
736
			throws Exception {
-
 
737
 
-
 
738
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
739
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
740
		if (startDate == null) {
-
 
741
			startDate = LocalDate.now().minusDays(30);
-
 
742
			endDate = LocalDate.now();
-
 
743
		}
-
 
744
		model.addAttribute("startDate", startDate);
-
 
745
		model.addAttribute("endDate", endDate);
-
 
746
		model.addAttribute("isAdmin", isAdmin);
-
 
747
		if (isAdmin) {
-
 
748
			if (fofoId == 0) {
-
 
749
				model.addAttribute("priceDropReports", new ArrayList<>());
-
 
750
				return "price-drop-report";
-
 
751
			} else {
-
 
752
				List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoId,
-
 
753
						startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
754
				model.addAttribute("priceDropReports", priceDropReports);
-
 
755
				return "price-drop-report";
-
 
756
			}
-
 
757
 
-
 
758
		} else {
-
 
759
			List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoDetails.getFofoId(),
-
 
760
					startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
761
			model.addAttribute("priceDropReports", priceDropReports);
-
 
762
			return "price-drop-report";
-
 
763
		}
-
 
764
	}
-
 
765
 
-
 
766
 
-
 
767
	@RequestMapping(value = "/downloadPriceDropReport", method = RequestMethod.GET)
-
 
768
	public ResponseEntity<?> getSelectDownloadPriceDropReport(HttpServletRequest request,
-
 
769
															  @RequestParam() int fofoId,
-
 
770
															  @RequestParam(name = "startDate") LocalDate startDate,
-
 
771
															  @RequestParam(name = "endDate") LocalDate endDate, Model model)
-
 
772
			throws Exception {
-
 
773
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
774
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
775
		List<List<?>> rows = new ArrayList<>();
-
 
776
		List<PriceDropReportModel> priceDropReports = null;
-
 
777
		if (isAdmin) {
-
 
778
			priceDropReports = orderRepository.selectPriceDropReport(fofoId,
-
 
779
					startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
780
		} else {
-
 
781
			fofoId = fofoDetails.getFofoId();
-
 
782
			priceDropReports = orderRepository.selectPriceDropReport(fofoId,
-
 
783
					startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
784
		}
-
 
785
		for (PriceDropReportModel pdr : priceDropReports) {
-
 
786
 
-
 
787
			rows.add(Arrays.asList(pdr.getCode(), pdr.getId(), pdr.getBrand(), pdr.getModelName(), pdr.getModelNumber(),
-
 
788
					pdr.getAffectedOn(), pdr.getAmount(), pdr.getPartnerPayout(), pdr.getImei(), pdr.getStatus(),
-
 
789
					pdr.getUpdateTimestamp(), pdr.getRejectionReason()));
-
 
790
 
-
 
791
		}
-
 
792
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
793
				.getCSVByteStream(Arrays.asList("code", "Price_Drop_Id", "brand", "model_name", "model_number",
-
 
794
						"affected_on", "amount", "partner_payout", "Imei", "status", "processed_on", "Reason"), rows);
-
 
795
 
-
 
796
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "price drop report");
-
 
797
 
-
 
798
		return responseEntity;
-
 
799
 
-
 
800
	}
-
 
801
 
-
 
802
	@RequestMapping(value = "/downloadPartnerBillingSummaryReport", method = RequestMethod.GET)
-
 
803
	public ResponseEntity<?> getdownloadPartnerBillingSummaryReport(HttpServletRequest request,
-
 
804
																	@RequestParam(name = "startDate") LocalDate startDate,
-
 
805
																	@RequestParam(name = "endDate") LocalDate endDate, Model model)
-
 
806
			throws Exception {
-
 
807
 
-
 
808
		List<List<?>> rows = new ArrayList<>();
-
 
809
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
810
 
-
 
811
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
812
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
813
 
-
 
814
		List<PartnerBillingSummaryModel> partnerBillingSummaryReports = fofoOrderRepository
-
 
815
				.selectPartnerBillingSummaryReport(fofoDetails.getFofoId(), startDate.atStartOfDay(),
-
 
816
						endDate.atTime(LocalTime.MAX));
-
 
817
 
-
 
818
		for (PartnerBillingSummaryModel pbsr : partnerBillingSummaryReports) {
-
 
819
 
-
 
820
			rows.add(Arrays.asList(pbsr.getId(),
-
 
821
					FormattingUtils.format(pbsr.getCreateTimestamp()),
-
 
822
					FormattingUtils.format(pbsr.getBillingTimestamp()),
-
 
823
					FormattingUtils.format(pbsr.getDeliveryTimestamp()),
-
 
824
					FormattingUtils.format(pbsr.getPartnerGrnTimestamp()),
-
 
825
					pbsr.getTransactionId(),
-
 
826
					pbsr.getLogisticsTransactionId(), pbsr.getAirwayBillNumber(), pbsr.getStatusSubGroup(),
-
 
827
					pbsr.getStatusName(), pbsr.getRetailerId(), pbsr.getRetailerName(), pbsr.getItemId(),
-
 
828
					pbsr.getBrand(), pbsr.getModelName(), pbsr.getModelNumber(), pbsr.getColor(), pbsr.getUnitPrice(),
-
 
829
					pbsr.getQuantity(), pbsr.getTotalPrice(), pbsr.getInvoiceNumber(), pbsr.getSellerName(), pbsr.getGstNumber(), pbsr.getHsnCode(), pbsr.getIgstRate(),
-
 
830
					pbsr.getCgstRate(), pbsr.getSgstRate()));
-
 
831
 
-
 
832
		}
-
 
833
 
-
 
834
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("OrderId",
-
 
835
				"Created On", "Billed On", "Delivered On", "Grned On", "Transaction_id", "master_order_id",
-
 
836
				"airwaybill_no", "statusSubGroupp", "statusName", "customer_id", "customer_name", "Item_Id", "brand",
-
 
837
				"model_name", "model_number", "color", "selling_price", "Quantity", "total_price", "invoice_number",
-
 
838
				"seller_name", "gst_number", "hsn_code", "igstrate", "cgstrate", "sgstrate"), rows);
-
 
839
 
-
 
840
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Billing Statement Report");
-
 
841
 
-
 
842
		return responseEntity;
-
 
843
 
-
 
844
 
-
 
845
	}
-
 
846
 
-
 
847
	@RequestMapping(value = "/invoiceSchemeOutSummaryReport", method = RequestMethod.GET)
-
 
848
	public String getInvoiceSchemeOutSummaryReport(HttpServletRequest request, Model model) throws Exception {
-
 
849
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
850
 
-
 
851
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
852
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
853
 
-
 
854
		List<FocoSchemeOutReportModel> focoSchemeOutReports = fofoOrderRepository
-
 
855
				.selectInvoiceSchemeOutSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
-
 
856
		LOGGER.info("focoSchemeOutReportModel {}", focoSchemeOutReports);
-
 
857
 
-
 
858
		model.addAttribute("startDate", currentDate.minusMonths(3).toLocalDate());
-
 
859
		model.addAttribute("endDate", LocalDate.now());
-
 
860
		model.addAttribute("focoSchemeOutReports", focoSchemeOutReports);
-
 
861
 
-
 
862
		return "invoicewise-scheme-out-report";
-
 
863
	}
-
 
864
 
-
 
865
	@RequestMapping(value = "/downloadInvoiceSchemeOutSummaryReport", method = RequestMethod.GET)
-
 
866
	public ResponseEntity<?> getDownloadInvoiceSchemeOutSummaryReport(HttpServletRequest request, Model model)
-
 
867
			throws Exception {
-
 
868
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
869
 
-
 
870
		List<List<?>> rows = new ArrayList<>();
-
 
871
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
872
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
873
 
-
 
874
		List<FocoSchemeOutReportModel> focoSchemeOutReports = fofoOrderRepository
-
 
875
				.selectInvoiceSchemeOutSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
-
 
876
		LOGGER.info("focoSchemeOutReportModel {}", focoSchemeOutReports);
-
 
877
 
-
 
878
		for (FocoSchemeOutReportModel fsor : focoSchemeOutReports) {
-
 
879
			rows.add(Arrays.asList(fsor.getInvoiceNumber(), fsor.getQuantity(), fsor.getBrand(), fsor.getModelName(),
-
 
880
					fsor.getModelNumber(), fsor.getColor(), fsor.getAmount()));
-
 
881
 
-
 
882
		}
-
 
883
 
-
 
884
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
-
 
885
				Arrays.asList("InvoiceNumber", "Quantity", "Brand", "Model Name", "Model Number", "Color", "Amount"),
-
 
886
				rows);
-
 
887
 
-
 
888
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows,
-
 
889
				"invoice wise scheme out Summary Report");
-
 
890
 
-
 
891
		return responseEntity;
-
 
892
	}
-
 
893
 
-
 
894
	@RequestMapping(value = "/schemePayoutReportDownload", method = RequestMethod.GET)
-
 
895
	public ResponseEntity<?> getSchemePayoutReportDownload(HttpServletRequest request,
-
 
896
														   @RequestParam int fofoId,
-
 
897
														   @RequestParam(name = "startDate") LocalDate startDate,
-
 
898
														   @RequestParam(name = "endDate") LocalDate endDate, Model model)
-
 
899
			throws Exception {
-
 
900
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
901
 
-
 
902
		List<List<?>> rows = new ArrayList<>();
-
 
903
 
-
 
904
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
905
 
-
 
906
		List<SchemePayoutReportModel> schemePayoutReports = null;
-
 
907
		if (isAdmin) {
-
 
908
			schemePayoutReports = fofoOrderRepository
-
 
909
					.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
910
		} else {
-
 
911
			fofoId = fofoDetails.getFofoId();
-
 
912
			schemePayoutReports = fofoOrderRepository
-
 
913
					.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
914
		}
-
 
915
		LOGGER.info("schemePayoutReports {}", schemePayoutReports);
-
 
916
 
-
 
917
		for (SchemePayoutReportModel spr : schemePayoutReports) {
-
 
918
 
-
 
919
			rows.add(Arrays.asList(spr.getId(), spr.getSerialNumber(), spr.getBrand(), spr.getModelName(),
-
 
920
					spr.getModelNumber(), spr.getColor(), spr.getSchemeInDp(), spr.getSchemeOutDp(), spr.getSchemeId(),
-
 
921
					spr.getName(), spr.getType(), spr.getAmountType(), spr.getPurchaseReference(),
-
 
922
					spr.getInvoiceNumber(), spr.getSioAmount(), spr.getStatus(), spr.getStatusDescription(),
-
 
923
					spr.getCreateTimestamp(), spr.getRolledBackTimestamp()));
-
 
924
 
-
 
925
		}
-
 
926
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("Item_Id",
-
 
927
				"serial_number", "Brand", "Model Name", "Model Number", "Color", "Scheme_IN_DP", "Scheme_out_dp",
-
 
928
				"Scheme_Id", "Name", "Type", "amount", "Purchase_Invoice", "SALE_INOVOICE", "Amount", "status",
-
 
929
				"description", "create_timestamp", "rolled_back_timestamp"), rows);
-
 
930
 
200
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows,"Collection Summary Report");
931
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Scheme Payout Summary Report");
201
 
932
 
202
		
-
 
203
		return responseEntity;
933
		return responseEntity;
204
	}
934
	}
-
 
935
 
-
 
936
 
-
 
937
	@RequestMapping(value = "/offerPayoutDumpReportDownload", method = RequestMethod.GET)
-
 
938
	public ResponseEntity<?> getOfferPayoutDumpReportDownload(HttpServletRequest request,
-
 
939
															  @RequestParam int fofoId,
-
 
940
															  @RequestParam(name = "startDate") LocalDate startDate,
-
 
941
															  @RequestParam(name = "endDate") LocalDate endDate, Model model)
-
 
942
			throws Exception {
-
 
943
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
944
		List<List<?>> rows = new ArrayList<>();
-
 
945
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
-
 
946
		List<OfferPayoutDumpReportModel> offerPayoutReports = null;
-
 
947
		if (isAdmin) {
-
 
948
			offerPayoutReports = fofoOrderRepository
-
 
949
					.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
950
		} else {
-
 
951
			fofoId = fofoDetails.getFofoId();
-
 
952
			offerPayoutReports = fofoOrderRepository
-
 
953
					.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
-
 
954
		}
-
 
955
 
-
 
956
 
-
 
957
		for (OfferPayoutDumpReportModel opdr : offerPayoutReports) {
-
 
958
 
-
 
959
			rows.add(Arrays.asList(opdr.getId(), opdr.getBrand(), opdr.getModelName(),
-
 
960
					opdr.getModelNumber(), opdr.getColor(), opdr.getSerialNumber(), opdr.getOfferId(),
-
 
961
					opdr.getName(), opdr.getType(),
-
 
962
					opdr.getSlabAmount(), opdr.getAmount(), opdr.getDescription(),
-
 
963
					opdr.getCreateTimestamp(), opdr.getRejectTimestamp()));
-
 
964
 
-
 
965
		}
-
 
966
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("Id",
-
 
967
				"Brand", "Model Name", "Model Number", "Color", "Serial number",
-
 
968
				"Offer Id", "Name", "Type", "Slab Amount", "Amount",
-
 
969
				"Description", "Credited On", "Rejected On"), rows);
-
 
970
 
-
 
971
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Offer Payout Summary Report");
-
 
972
 
-
 
973
		return responseEntity;
205
	
974
	}
-
 
975
 
-
 
976
 
-
 
977
	@GetMapping("/getAllOnlineOrder")
-
 
978
	public String getAllOrders(HttpServletRequest request, @RequestParam(required = false) LocalDate date, Model model)
-
 
979
			throws ProfitMandiBusinessException {
-
 
980
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
981
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
-
 
982
		if (date == null) {
-
 
983
			date = LocalDate.now().minusDays(3);
-
 
984
		}
-
 
985
 
-
 
986
		LOGGER.info("date" + date);
-
 
987
		List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
-
 
988
				.collect(Collectors.toList());
-
 
989
 
-
 
990
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
-
 
991
 
-
 
992
		Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> customRetailerMap.get(x))
-
 
993
				.filter(x -> x != null).collect(Collectors.toList()).stream()
-
 
994
				.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
-
 
995
 
-
 
996
		model.addAttribute("customRetailersMap", customRetailersMap);
-
 
997
 
-
 
998
		List<PendingOrderItem> pendingOrderItem = null;
-
 
999
 
-
 
1000
		pendingOrderItem = pendingOrderItemRepository.selectAll(date.atStartOfDay(), LocalDateTime.now());
-
 
1001
 
-
 
1002
		Map<String, Object> map = pendingOrderService.getItemOrders(pendingOrderItem, 0);
206
	
1003
 
-
 
1004
		model.addAttribute("pendingOrderItem", map.get("pendingOrderItem"));
-
 
1005
		model.addAttribute("partnerInventoryMap", map.get("partnerInventoryMap"));
-
 
1006
		model.addAttribute("date", date);
-
 
1007
		model.addAttribute("isAdmin", isAdmin);
-
 
1008
		return "online-all-order-item";
207
	
1009
	}
208
 
1010
 
209
 
1011
 
210
	@RequestMapping(value = "/reports", method = RequestMethod.GET)
1012
	@RequestMapping(value = "/reports", method = RequestMethod.GET)
211
	public String reports(HttpServletRequest httpServletRequest, Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
1013
	public String reports(HttpServletRequest httpServletRequest, Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
212
		
-
 
213
		//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(httpServletRequest);
1014
		//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(httpServletRequest);
214
		Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap = ReporticoProject.reporticoProjectMap;
1015
		Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap = ReporticoProject.reporticoProjectMap;
215
		/*if(fofoStoreRepository.getWarehousePartnerMap().get(7720).stream().filter(x->x.getId()==loginDetails.getFofoId()).count() > 0) {
1016
		/*if(fofoStoreRepository.getWarehousePartnerMap().get(7720).stream().filter(x->x.getId()==loginDetails.getFofoId()).count() > 0) {
216
			Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap1 = new HashMap<ReporticoProject, List<ReporticoUrlInfo>>();
1017
			Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap1 = new HashMap<ReporticoProject, List<ReporticoUrlInfo>>();
217
			returnMap1.put(ReporticoProject.FOCO, returnMap.get(ReporticoProject.FOCO));
1018
			returnMap1.put(ReporticoProject.FOCO, returnMap.get(ReporticoProject.FOCO));
218
			returnMap1.put(ReporticoProject.FOCOR, returnMap.get(ReporticoProject.FOCOR).stream().skip(1).collect(Collectors.toList()));
1019
			returnMap1.put(ReporticoProject.FOCOR, returnMap.get(ReporticoProject.FOCOR).stream().skip(1).collect(Collectors.toList()));
219
			returnMap = returnMap1;
1020
			returnMap = returnMap1;
220
		}*/
1021
		}*/
221
		model.addAttribute("reporticoProjectMap", returnMap);
1022
		model.addAttribute("reporticoProjectMap", returnMap);
222
		
-
 
223
		return "reports";
1023
		return "reports";
224
	}
1024
	}
225
}
1025
}