Subversion Repositories SmartDukaan

Rev

Rev 33102 | Rev 33116 | 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(),
396
					FormattingUtils.format(walletSummary.getBusinessTimestamp())));
397
 
398
		}
399
 
400
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
401
				.getCSVByteStream(Arrays.asList("Id", "Code", "Name", "Email", "Phone", "Amount", "Refundable_amount",
402
						"Reference", "Reference_type", "Business_timestamp", "Description"), rows);
403
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, partnerName + " Wallet Statement Report");
404
 
405
		return responseEntity;
406
 
407
	}
408
 
409
	@RequestMapping(value = "/walletSummaryFetchReportByDate", method = RequestMethod.GET)
410
	public String getwalletSummaryFetchReport(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
411
											  @RequestParam(required = false) LocalDate startDate,
412
											  @RequestParam(required = false) LocalDate endDate)
413
			throws Exception {
414
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
415
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
416
		if (startDate == null) {
417
			startDate = LocalDate.now().minusDays(30);
418
		}
419
		endDate = LocalDate.now();
420
		model.addAttribute("startDate", startDate);
421
		model.addAttribute("endDate", endDate);
422
		model.addAttribute("isAdmin", isAdmin);
423
		if (isAdmin) {
424
			if (fofoId == 0) {
425
				//No need to send any data
426
				model.addAttribute("walletSummartList", new ArrayList<>());
427
 
428
				return "wallet-summary-report";
429
			} else {
430
				List<WalletSummaryReportModel> walletSummartList = fofoOrderRepository
431
						.selectWalletSummaryReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
432
				model.addAttribute("walletSummartList", walletSummartList);
433
 
434
				return "wallet-summary-report";
435
			}
436
 
437
		} else {
438
 
439
 
440
			FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
441
			List<WalletSummaryReportModel> walletSummartList = fofoOrderRepository
442
					.selectWalletSummaryReport(loginDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
443
			//LOGGER.info("walletSummartList {}", walletSummartList);
444
 
445
			model.addAttribute("walletSummartList", walletSummartList);
446
 
447
			return "wallet-summary-report";
448
		}
449
	}
450
 
451
	@RequestMapping(value = "/walletSummaryReport", method = RequestMethod.GET)
452
	public String getWalletSummaryReport(HttpServletRequest request, Model model) throws Exception {
453
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
454
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
455
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
456
		LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
457
 
458
		List<WalletSummaryReportModel> walletSummartList = fofoOrderRepository
459
				.selectWalletSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
460
		LOGGER.info("walletSummartList {}", walletSummartList);
461
 
462
		model.addAttribute("startDate", currentDate.minusDays(30).toLocalDate());
463
		model.addAttribute("endDate", LocalDate.now());
464
		model.addAttribute("walletSummartList", walletSummartList);
465
		model.addAttribute("isAdmin", isAdmin);
466
 
467
		return "wallet-summary-report";
468
	}
469
 
470
	@RequestMapping(value = "/pendingIndentReport", method = RequestMethod.GET)
471
	public String getPendingIndentReport(HttpServletRequest request, Model model) throws Exception {
472
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
473
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
474
 
475
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
476
		LocalDateTime currentStartMonth = currentDate.minusMonths(2).toLocalDate().atStartOfDay();
477
 
478
		List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
479
				.selectPendingIndentReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
480
		LOGGER.info("pendingIndentReports {}", pendingIndentReports);
481
 
482
		model.addAttribute("startDate", currentDate.minusMonths(2).toLocalDate());
483
		model.addAttribute("endDate", LocalDate.now());
484
		model.addAttribute("pendingIndentReports", pendingIndentReports);
485
		model.addAttribute("isAdmin", isAdmin);
486
 
487
 
488
		return "pending-indent-report";
489
	}
490
 
491
	@RequestMapping(value = "/pendingIndentFetchReportByDate", method = RequestMethod.GET)
492
	public String getpendingIndentFetchReport(
493
			HttpServletRequest request,
494
			@RequestParam(defaultValue = "0") int fofoId,
495
			@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
496
			@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate,
497
			Model model
498
	) throws Exception {
499
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
500
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
501
		if (startDate == null) {
502
			startDate = LocalDate.now().minusDays(30);
503
			endDate = LocalDate.now();
504
		}
505
		model.addAttribute("startDate", startDate);
506
		model.addAttribute("endDate", endDate);
507
		model.addAttribute("isAdmin", isAdmin);
508
		if (isAdmin) {
509
			if (fofoId == 0) {
510
				model.addAttribute("pendingIndentReports", new ArrayList<>());
511
				return "pending-indent-report";
512
			} else {
513
				List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
514
						.selectPendingIndentReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
515
				model.addAttribute("pendingIndentReports", pendingIndentReports);
516
				return "pending-indent-report";
517
			}
518
		} else {
519
			LocalDateTime currentDate = LocalDate.now().atStartOfDay();
520
			List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
521
					.selectPendingIndentReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
522
			model.addAttribute("pendingIndentReports", pendingIndentReports);
523
			return "pending-indent-report";
524
 
525
		}
526
	}
527
 
528
 
529
	@RequestMapping(value = "/pendingIndentReportDownload", method = RequestMethod.GET)
530
	public ResponseEntity<?> getPendingIndentReportDownload(HttpServletRequest request,
33108 tejus.loha 531
															@RequestParam(defaultValue = "0") int fofoId,
33102 tejus.loha 532
															@RequestParam(name = "startDate") LocalDate startDate,
533
															@RequestParam(name = "endDate") LocalDate endDate, Model model)
534
			throws Exception {
535
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
536
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
537
        /*LocalDateTime currentDate = LocalDate.now().atStartOfDay();
538
        LocalDateTime currentStartMonth = currentDate.minusMonths(2).toLocalDate().atStartOfDay();*/
539
		List<PendingIndentReportModel> pendingIndentReports = null;
540
		List<List<?>> rows = new ArrayList<>();
541
		if (isAdmin) {
33108 tejus.loha 542
			if (fofoId == 0)
543
				pendingIndentReports = new ArrayList<>();
544
			else
545
				pendingIndentReports = fofoOrderRepository
33102 tejus.loha 546
					.selectPendingIndentReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
547
		} else {
548
			pendingIndentReports = fofoOrderRepository
549
					.selectPendingIndentReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
550
 
551
		}
552
		LOGGER.info("pendingIndentReports {}", pendingIndentReports);
553
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
554
 
555
		for (PendingIndentReportModel pir : pendingIndentReports) {
556
 
557
			rows.add(Arrays.asList(pir.getTransactionId(), pir.getOrderId(),
558
					pir.getCreatTimestamp().format(dateTimeFormatter), pir.getItemId(), pir.getBrand(),
559
					pir.getModelName(), pir.getModelNumber(), pir.getColor(), pir.getQuantity(), pir.getUnitPrice(),
560
					pir.getWalletAmount(), pir.getStatus(), pir.getInvoiceNumber(),
561
					pir.getBillingTimestamp() == null ? "" : pir.getBillingTimestamp().format(dateTimeFormatter)));
562
 
563
		}
564
 
565
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList(
566
				"Transaction Id", "Order Id", "Created_At", "Item_Id", "Brand", "Model Name", "Model Number", "Color",
567
				"Quantity", "Unit Price", "Wallet Deduction", "Status", "Invoice Number", "Billing Timestamp"), rows);
568
 
569
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Order Status Summary Report");
570
 
571
		return responseEntity;
572
	}
573
 
574
	@RequestMapping(value = "/schemePayoutReport", method = RequestMethod.GET)
575
	public String getschemePayoutReport(HttpServletRequest request, Model model,
576
										@RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
577
			throws ProfitMandiBusinessException {
578
 
579
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
580
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
581
		if (startDate == null) {
582
			startDate = LocalDate.now().minusDays(30);
583
			endDate = LocalDate.now();
584
		}
585
		model.addAttribute("startDate", startDate);
586
		model.addAttribute("endDate", endDate);
587
		model.addAttribute("isAdmin", isAdmin);
588
		//LOGGER.info("schemePayoutReports {}", schemePayoutReports);
589
		List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
590
				.selectSchemePayoutReport(loginDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
591
		model.addAttribute("schemePayoutReports", schemePayoutReports);
592
		return "scheme-payout-report";
593
 
594
	}
595
 
596
	@RequestMapping(value = "/schemePayoutFetchReportByDate", method = RequestMethod.GET)
597
	public String getschemePayoutFetchReportByDate(
598
			HttpServletRequest request,
599
			Model model,
600
			@RequestParam(defaultValue = "0") int fofoId,
601
			@RequestParam(required = false) LocalDate startDate,
602
			@RequestParam(required = false) LocalDate endDate)
603
			throws ProfitMandiBusinessException {
604
		//LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
605
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
606
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
607
		if (startDate == null) {
608
			startDate = LocalDate.now().minusDays(30);
609
			endDate = LocalDate.now();
610
		}
611
		model.addAttribute("startDate", startDate);
612
		model.addAttribute("endDate", endDate);
613
		model.addAttribute("isAdmin", isAdmin);
614
 
615
		LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
616
		if (isAdmin) {
617
			if (fofoId == 0) {
618
				//No need to pull any data
619
				model.addAttribute("schemePayoutReports", new ArrayList<>());
620
				return "scheme-payout-report";
621
 
622
			} else {
623
				List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
624
						.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
625
 
626
				model.addAttribute("schemePayoutReports", schemePayoutReports);
627
				return "scheme-payout-report";
628
			}
629
		} else {
630
			fofoId = loginDetails.getFofoId();
631
 
632
			List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
633
					.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
634
 
635
			model.addAttribute("schemePayoutReports", schemePayoutReports);
636
			return "scheme-payout-report";
637
		}
638
 
639
	}
640
 
641
	@RequestMapping(value = "/offerPayoutReport", method = RequestMethod.GET)
642
	public String getOfferPayoutReport(HttpServletRequest request, Model model, @RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate) throws Exception {
643
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
644
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
645
 
646
		if (startDate == null) {
647
			startDate = LocalDate.now().minusDays(30);
648
			endDate = LocalDate.now();
649
		}
650
		model.addAttribute("startDate", startDate);
651
		model.addAttribute("endDate", endDate);
652
 
653
 
654
		List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
655
				.selectOfferPayoutDumpReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
656
		LOGGER.info("offerPayoutDumpReports {}", offerPayoutDumpReports);
657
 
658
		model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
659
		model.addAttribute("isAdmin", isAdmin);
660
 
661
		return "offer-payout-dump-report";
662
	}
663
 
664
	@RequestMapping(value = "/offerPayoutFetchReportByDate", method = RequestMethod.GET)
665
	public String getofferPayoutFetchReportByDate(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
666
												  @RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
667
			throws ProfitMandiBusinessException {
668
 
669
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
670
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
671
		if (startDate == null) {
672
			startDate = LocalDate.now().minusDays(30);
673
			endDate = LocalDate.now();
674
		}
675
		model.addAttribute("startDate", startDate);
676
		model.addAttribute("endDate", endDate);
677
		model.addAttribute("isAdmin", isAdmin);
678
		LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
679
		if (isAdmin) {
680
			if (fofoId == 0) {
681
				//No need to pull any data
682
				model.addAttribute("offerPayoutReports", new ArrayList<>());
683
				return "offer-payout-dump-report";
684
 
685
			} else {
686
				List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
687
						.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
688
 
689
				model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
690
 
691
 
692
				return "offer-payout-dump-report";
693
 
694
			}
695
		} else {
696
			fofoId = loginDetails.getFofoId();
697
			List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
698
					.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
699
 
700
			model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
701
 
702
 
703
			return "offer-payout-dump-report";
704
		}
705
	}
706
 
707
 
708
	@RequestMapping(value = "/selectPartnerBillingSummaryReport", method = RequestMethod.GET)
709
	public String getselectPartnerBillingSummaryReport(HttpServletRequest request, Model model) throws Exception {
710
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
711
 
712
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
713
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
714
 
715
		List<PartnerBillingSummaryModel> partnerBillingSummaryReports = fofoOrderRepository
716
				.selectPartnerBillingSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
717
 
718
		model.addAttribute("startDate", currentDate.minusMonths(3).toLocalDate());
719
		model.addAttribute("endDate", LocalDate.now());
720
		model.addAttribute("partnerBillingSummaryReports", partnerBillingSummaryReports);
721
 
722
		return "partner-billing-summary-report";
723
	}
724
 
725
	@RequestMapping(value = "/priceDropReport", method = RequestMethod.GET)
726
	public String getSelectPriceDropReport(HttpServletRequest request, @RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
727
										   @RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model) throws Exception {
728
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
729
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
730
		if (startDate == null) {
731
			startDate = LocalDate.now().minusDays(30);
732
			endDate = LocalDate.now();
733
		}
734
		model.addAttribute("startDate", startDate);
735
		model.addAttribute("endDate", endDate);
736
		model.addAttribute("isAdmin", isAdmin);
737
		List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoDetails.getFofoId(),
738
				startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
739
		model.addAttribute("priceDropReports", priceDropReports);
740
 
741
		return "price-drop-report";
742
	}
743
 
744
	@RequestMapping(value = "/priceDropFetchReportByDate", method = RequestMethod.GET)
745
	public String getpriceDropFetchReportByDate(HttpServletRequest request,
746
												@RequestParam(defaultValue = "0") int fofoId,
747
												@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
748
												@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
749
			throws Exception {
750
 
751
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
752
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
753
		if (startDate == null) {
754
			startDate = LocalDate.now().minusDays(30);
755
			endDate = LocalDate.now();
756
		}
757
		model.addAttribute("startDate", startDate);
758
		model.addAttribute("endDate", endDate);
759
		model.addAttribute("isAdmin", isAdmin);
760
		if (isAdmin) {
761
			if (fofoId == 0) {
762
				model.addAttribute("priceDropReports", new ArrayList<>());
763
				return "price-drop-report";
764
			} else {
765
				List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoId,
766
						startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
767
				model.addAttribute("priceDropReports", priceDropReports);
768
				return "price-drop-report";
769
			}
770
 
771
		} else {
772
			List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoDetails.getFofoId(),
773
					startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
774
			model.addAttribute("priceDropReports", priceDropReports);
775
			return "price-drop-report";
776
		}
777
	}
778
 
779
 
780
	@RequestMapping(value = "/downloadPriceDropReport", method = RequestMethod.GET)
781
	public ResponseEntity<?> getSelectDownloadPriceDropReport(HttpServletRequest request,
33108 tejus.loha 782
															  @RequestParam(defaultValue = "0") int fofoId,
33102 tejus.loha 783
															  @RequestParam(name = "startDate") LocalDate startDate,
784
															  @RequestParam(name = "endDate") LocalDate endDate, Model model)
785
			throws Exception {
786
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
787
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
788
		List<List<?>> rows = new ArrayList<>();
789
		List<PriceDropReportModel> priceDropReports = null;
790
		if (isAdmin) {
33108 tejus.loha 791
			if (fofoId == 0)
792
				priceDropReports = new ArrayList<>();
793
			else
794
				priceDropReports = orderRepository.selectPriceDropReport(fofoId,
33102 tejus.loha 795
					startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
796
		} else {
797
			fofoId = fofoDetails.getFofoId();
798
			priceDropReports = orderRepository.selectPriceDropReport(fofoId,
799
					startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
800
		}
801
		for (PriceDropReportModel pdr : priceDropReports) {
802
 
803
			rows.add(Arrays.asList(pdr.getCode(), pdr.getId(), pdr.getBrand(), pdr.getModelName(), pdr.getModelNumber(),
804
					pdr.getAffectedOn(), pdr.getAmount(), pdr.getPartnerPayout(), pdr.getImei(), pdr.getStatus(),
805
					pdr.getUpdateTimestamp(), pdr.getRejectionReason()));
806
 
807
		}
808
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
809
				.getCSVByteStream(Arrays.asList("code", "Price_Drop_Id", "brand", "model_name", "model_number",
810
						"affected_on", "amount", "partner_payout", "Imei", "status", "processed_on", "Reason"), rows);
811
 
812
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "price drop report");
813
 
814
		return responseEntity;
815
 
816
	}
817
 
818
	@RequestMapping(value = "/downloadPartnerBillingSummaryReport", method = RequestMethod.GET)
819
	public ResponseEntity<?> getdownloadPartnerBillingSummaryReport(HttpServletRequest request,
820
																	@RequestParam(name = "startDate") LocalDate startDate,
821
																	@RequestParam(name = "endDate") LocalDate endDate, Model model)
822
			throws Exception {
823
 
824
		List<List<?>> rows = new ArrayList<>();
825
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
826
 
827
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
828
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
829
 
830
		List<PartnerBillingSummaryModel> partnerBillingSummaryReports = fofoOrderRepository
831
				.selectPartnerBillingSummaryReport(fofoDetails.getFofoId(), startDate.atStartOfDay(),
832
						endDate.atTime(LocalTime.MAX));
833
 
834
		for (PartnerBillingSummaryModel pbsr : partnerBillingSummaryReports) {
835
 
836
			rows.add(Arrays.asList(pbsr.getId(),
837
					FormattingUtils.format(pbsr.getCreateTimestamp()),
838
					FormattingUtils.format(pbsr.getBillingTimestamp()),
839
					FormattingUtils.format(pbsr.getDeliveryTimestamp()),
840
					FormattingUtils.format(pbsr.getPartnerGrnTimestamp()),
841
					pbsr.getTransactionId(),
842
					pbsr.getLogisticsTransactionId(), pbsr.getAirwayBillNumber(), pbsr.getStatusSubGroup(),
843
					pbsr.getStatusName(), pbsr.getRetailerId(), pbsr.getRetailerName(), pbsr.getItemId(),
844
					pbsr.getBrand(), pbsr.getModelName(), pbsr.getModelNumber(), pbsr.getColor(), pbsr.getUnitPrice(),
845
					pbsr.getQuantity(), pbsr.getTotalPrice(), pbsr.getInvoiceNumber(), pbsr.getSellerName(), pbsr.getGstNumber(), pbsr.getHsnCode(), pbsr.getIgstRate(),
846
					pbsr.getCgstRate(), pbsr.getSgstRate()));
847
 
848
		}
849
 
850
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("OrderId",
851
				"Created On", "Billed On", "Delivered On", "Grned On", "Transaction_id", "master_order_id",
852
				"airwaybill_no", "statusSubGroupp", "statusName", "customer_id", "customer_name", "Item_Id", "brand",
853
				"model_name", "model_number", "color", "selling_price", "Quantity", "total_price", "invoice_number",
854
				"seller_name", "gst_number", "hsn_code", "igstrate", "cgstrate", "sgstrate"), rows);
855
 
856
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Billing Statement Report");
857
 
858
		return responseEntity;
859
 
860
 
861
	}
862
 
863
	@RequestMapping(value = "/invoiceSchemeOutSummaryReport", method = RequestMethod.GET)
864
	public String getInvoiceSchemeOutSummaryReport(HttpServletRequest request, Model model) throws Exception {
865
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
866
 
867
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
868
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
869
 
870
		List<FocoSchemeOutReportModel> focoSchemeOutReports = fofoOrderRepository
871
				.selectInvoiceSchemeOutSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
872
		LOGGER.info("focoSchemeOutReportModel {}", focoSchemeOutReports);
873
 
874
		model.addAttribute("startDate", currentDate.minusMonths(3).toLocalDate());
875
		model.addAttribute("endDate", LocalDate.now());
876
		model.addAttribute("focoSchemeOutReports", focoSchemeOutReports);
877
 
878
		return "invoicewise-scheme-out-report";
879
	}
880
 
881
	@RequestMapping(value = "/downloadInvoiceSchemeOutSummaryReport", method = RequestMethod.GET)
882
	public ResponseEntity<?> getDownloadInvoiceSchemeOutSummaryReport(HttpServletRequest request, Model model)
883
			throws Exception {
884
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
885
 
886
		List<List<?>> rows = new ArrayList<>();
887
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
888
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
889
 
890
		List<FocoSchemeOutReportModel> focoSchemeOutReports = fofoOrderRepository
891
				.selectInvoiceSchemeOutSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
892
		LOGGER.info("focoSchemeOutReportModel {}", focoSchemeOutReports);
893
 
894
		for (FocoSchemeOutReportModel fsor : focoSchemeOutReports) {
895
			rows.add(Arrays.asList(fsor.getInvoiceNumber(), fsor.getQuantity(), fsor.getBrand(), fsor.getModelName(),
896
					fsor.getModelNumber(), fsor.getColor(), fsor.getAmount()));
897
 
898
		}
899
 
900
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
901
				Arrays.asList("InvoiceNumber", "Quantity", "Brand", "Model Name", "Model Number", "Color", "Amount"),
902
				rows);
903
 
904
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows,
905
				"invoice wise scheme out Summary Report");
906
 
907
		return responseEntity;
908
	}
909
 
910
	@RequestMapping(value = "/schemePayoutReportDownload", method = RequestMethod.GET)
911
	public ResponseEntity<?> getSchemePayoutReportDownload(HttpServletRequest request,
33108 tejus.loha 912
														   @RequestParam(defaultValue = "0") int fofoId,
33102 tejus.loha 913
														   @RequestParam(name = "startDate") LocalDate startDate,
914
														   @RequestParam(name = "endDate") LocalDate endDate, Model model)
915
			throws Exception {
916
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
917
 
918
		List<List<?>> rows = new ArrayList<>();
919
 
920
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
921
 
922
		List<SchemePayoutReportModel> schemePayoutReports = null;
923
		if (isAdmin) {
33108 tejus.loha 924
			if (fofoId == 0)
925
				schemePayoutReports = new ArrayList<>();
926
			else
927
				schemePayoutReports = fofoOrderRepository
33102 tejus.loha 928
					.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
929
		} else {
930
			fofoId = fofoDetails.getFofoId();
931
			schemePayoutReports = fofoOrderRepository
932
					.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
933
		}
934
		LOGGER.info("schemePayoutReports {}", schemePayoutReports);
935
 
936
		for (SchemePayoutReportModel spr : schemePayoutReports) {
937
 
938
			rows.add(Arrays.asList(spr.getId(), spr.getSerialNumber(), spr.getBrand(), spr.getModelName(),
939
					spr.getModelNumber(), spr.getColor(), spr.getSchemeInDp(), spr.getSchemeOutDp(), spr.getSchemeId(),
940
					spr.getName(), spr.getType(), spr.getAmountType(), spr.getPurchaseReference(),
941
					spr.getInvoiceNumber(), spr.getSioAmount(), spr.getStatus(), spr.getStatusDescription(),
942
					spr.getCreateTimestamp(), spr.getRolledBackTimestamp()));
943
 
944
		}
945
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("Item_Id",
946
				"serial_number", "Brand", "Model Name", "Model Number", "Color", "Scheme_IN_DP", "Scheme_out_dp",
947
				"Scheme_Id", "Name", "Type", "amount", "Purchase_Invoice", "SALE_INOVOICE", "Amount", "status",
948
				"description", "create_timestamp", "rolled_back_timestamp"), rows);
949
 
950
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Scheme Payout Summary Report");
951
 
952
		return responseEntity;
953
	}
954
 
955
 
956
	@RequestMapping(value = "/offerPayoutDumpReportDownload", method = RequestMethod.GET)
957
	public ResponseEntity<?> getOfferPayoutDumpReportDownload(HttpServletRequest request,
33108 tejus.loha 958
															  @RequestParam(defaultValue = "0") int fofoId,
33102 tejus.loha 959
															  @RequestParam(name = "startDate") LocalDate startDate,
960
															  @RequestParam(name = "endDate") LocalDate endDate, Model model)
961
			throws Exception {
962
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
963
		List<List<?>> rows = new ArrayList<>();
964
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
965
		List<OfferPayoutDumpReportModel> offerPayoutReports = null;
966
		if (isAdmin) {
33108 tejus.loha 967
			if (fofoId == 0)
968
				offerPayoutReports = new ArrayList<>();
969
			else
970
				offerPayoutReports = fofoOrderRepository
33102 tejus.loha 971
					.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
972
		} else {
973
			fofoId = fofoDetails.getFofoId();
974
			offerPayoutReports = fofoOrderRepository
975
					.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
976
		}
977
 
978
 
979
		for (OfferPayoutDumpReportModel opdr : offerPayoutReports) {
980
 
981
			rows.add(Arrays.asList(opdr.getId(), opdr.getBrand(), opdr.getModelName(),
982
					opdr.getModelNumber(), opdr.getColor(), opdr.getSerialNumber(), opdr.getOfferId(),
983
					opdr.getName(), opdr.getType(),
984
					opdr.getSlabAmount(), opdr.getAmount(), opdr.getDescription(),
985
					opdr.getCreateTimestamp(), opdr.getRejectTimestamp()));
986
 
987
		}
988
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("Id",
989
				"Brand", "Model Name", "Model Number", "Color", "Serial number",
990
				"Offer Id", "Name", "Type", "Slab Amount", "Amount",
991
				"Description", "Credited On", "Rejected On"), rows);
992
 
993
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Offer Payout Summary Report");
994
 
995
		return responseEntity;
996
	}
997
 
998
 
999
	@GetMapping("/getAllOnlineOrder")
1000
	public String getAllOrders(HttpServletRequest request, @RequestParam(required = false) LocalDate date, Model model)
1001
			throws ProfitMandiBusinessException {
1002
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1003
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
1004
		if (date == null) {
1005
			date = LocalDate.now().minusDays(3);
1006
		}
1007
 
1008
		LOGGER.info("date" + date);
1009
		List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
1010
				.collect(Collectors.toList());
1011
 
1012
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
1013
 
1014
		Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> customRetailerMap.get(x))
1015
				.filter(x -> x != null).collect(Collectors.toList()).stream()
1016
				.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
1017
 
1018
		model.addAttribute("customRetailersMap", customRetailersMap);
1019
 
1020
		List<PendingOrderItem> pendingOrderItem = null;
1021
 
1022
		pendingOrderItem = pendingOrderItemRepository.selectAll(date.atStartOfDay(), LocalDateTime.now());
1023
 
1024
		Map<String, Object> map = pendingOrderService.getItemOrders(pendingOrderItem, 0);
1025
 
1026
		model.addAttribute("pendingOrderItem", map.get("pendingOrderItem"));
1027
		model.addAttribute("partnerInventoryMap", map.get("partnerInventoryMap"));
1028
		model.addAttribute("date", date);
1029
		model.addAttribute("isAdmin", isAdmin);
1030
		return "online-all-order-item";
1031
	}
1032
 
1033
 
23822 amit.gupta 1034
	@RequestMapping(value = "/reports", method = RequestMethod.GET)
28106 amit.gupta 1035
	public String reports(HttpServletRequest httpServletRequest, Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
28137 amit.gupta 1036
		//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(httpServletRequest);
28106 amit.gupta 1037
		Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap = ReporticoProject.reporticoProjectMap;
28137 amit.gupta 1038
		/*if(fofoStoreRepository.getWarehousePartnerMap().get(7720).stream().filter(x->x.getId()==loginDetails.getFofoId()).count() > 0) {
28106 amit.gupta 1039
			Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap1 = new HashMap<ReporticoProject, List<ReporticoUrlInfo>>();
1040
			returnMap1.put(ReporticoProject.FOCO, returnMap.get(ReporticoProject.FOCO));
1041
			returnMap1.put(ReporticoProject.FOCOR, returnMap.get(ReporticoProject.FOCOR).stream().skip(1).collect(Collectors.toList()));
28107 amit.gupta 1042
			returnMap = returnMap1;
28137 amit.gupta 1043
		}*/
28107 amit.gupta 1044
		model.addAttribute("reporticoProjectMap", returnMap);
23637 amit.gupta 1045
		return "reports";
1046
	}
23612 amit.gupta 1047
}