Subversion Repositories SmartDukaan

Rev

Rev 33108 | Rev 33126 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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