Subversion Repositories SmartDukaan

Rev

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

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