Subversion Repositories SmartDukaan

Rev

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

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