| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.ByteArrayInputStream;
|
- |
|
| 4 |
import java.io.ByteArrayOutputStream;
|
- |
|
| 5 |
import java.io.InputStream;
|
- |
|
| 6 |
import java.time.LocalDate;
|
- |
|
| 7 |
import java.time.LocalDateTime;
|
- |
|
| 8 |
import java.time.format.DateTimeFormatter;
|
- |
|
| 9 |
import java.time.temporal.ChronoUnit;
|
- |
|
| 10 |
import java.util.ArrayList;
|
- |
|
| 11 |
import java.util.Arrays;
|
- |
|
| 12 |
import java.util.HashMap;
|
- |
|
| 13 |
import java.util.HashSet;
|
- |
|
| 14 |
import java.util.List;
|
- |
|
| 15 |
import java.util.Map;
|
- |
|
| 16 |
import java.util.Set;
|
- |
|
| 17 |
import java.util.stream.Collectors;
|
- |
|
| 18 |
|
- |
|
| 19 |
import javax.servlet.http.HttpServletRequest;
|
- |
|
| 20 |
import javax.servlet.http.HttpServletResponse;
|
- |
|
| 21 |
|
- |
|
| 22 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 23 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 24 |
import org.json.JSONObject;
|
- |
|
| 25 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 26 |
import org.springframework.core.io.InputStreamResource;
|
- |
|
| 27 |
import org.springframework.http.HttpHeaders;
|
- |
|
| 28 |
import org.springframework.http.HttpStatus;
|
- |
|
| 29 |
import org.springframework.http.MediaType;
|
- |
|
| 30 |
import org.springframework.http.ResponseEntity;
|
- |
|
| 31 |
import org.springframework.stereotype.Controller;
|
- |
|
| 32 |
import org.springframework.transaction.annotation.Transactional;
|
- |
|
| 33 |
import org.springframework.ui.Model;
|
- |
|
| 34 |
import org.springframework.web.bind.annotation.GetMapping;
|
- |
|
| 35 |
import org.springframework.web.bind.annotation.PathVariable;
|
- |
|
| 36 |
import org.springframework.web.bind.annotation.PutMapping;
|
- |
|
| 37 |
import org.springframework.web.bind.annotation.RequestBody;
|
- |
|
| 38 |
import org.springframework.web.bind.annotation.RequestMapping;
|
- |
|
| 39 |
import org.springframework.web.bind.annotation.RequestMethod;
|
- |
|
| 40 |
import org.springframework.web.bind.annotation.RequestParam;
|
- |
|
| 41 |
|
- |
|
| 42 |
import com.google.gson.Gson;
|
3 |
import com.google.gson.Gson;
|
| 43 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
4 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
| 44 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 45 |
import com.spice.profitmandi.common.model.CartFofo;
|
6 |
import com.spice.profitmandi.common.model.*;
|
| 46 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
- |
|
| 47 |
import com.spice.profitmandi.common.model.CreditNotePdfModel;
|
- |
|
| 48 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
- |
|
| 49 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
- |
|
| 50 |
import com.spice.profitmandi.common.model.FofoItemIdAmountModel;
|
- |
|
| 51 |
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
|
- |
|
| 52 |
import com.spice.profitmandi.common.model.PartnerOptionsAndItemAmountModel;
|
- |
|
| 53 |
import com.spice.profitmandi.common.model.PaymentOptionTransactionModel;
|
- |
|
| 54 |
import com.spice.profitmandi.common.model.PdfModel;
|
- |
|
| 55 |
import com.spice.profitmandi.common.model.PriceModel;
|
- |
|
| 56 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
- |
|
| 57 |
import com.spice.profitmandi.common.solr.SolrService;
|
7 |
import com.spice.profitmandi.common.solr.SolrService;
|
| 58 |
import com.spice.profitmandi.common.util.FileUtil;
|
8 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 59 |
import com.spice.profitmandi.common.util.PdfUtils;
|
9 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 60 |
import com.spice.profitmandi.common.util.StringUtils;
|
10 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 61 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
11 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 62 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
12 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 63 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
13 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 64 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
14 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
| 65 |
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
|
15 |
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
|
| 66 |
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
|
16 |
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
|
| 67 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
- |
|
| 68 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
- |
|
| 69 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
- |
|
| 70 |
import com.spice.profitmandi.dao.entity.fofo.CustomerCreditNote;
|
- |
|
| 71 |
import com.spice.profitmandi.dao.entity.fofo.CustomerReturnItem;
|
- |
|
| 72 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
- |
|
| 73 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
- |
|
| 74 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
- |
|
| 75 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
- |
|
| 76 |
import com.spice.profitmandi.dao.entity.fofo.Mou;
|
17 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 77 |
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
|
- |
|
| 78 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrder;
|
- |
|
| 79 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
|
- |
|
| 80 |
import com.spice.profitmandi.dao.entity.user.Address;
|
18 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 81 |
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
|
19 |
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
|
| 82 |
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
|
20 |
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
|
| 83 |
import com.spice.profitmandi.dao.model.FocoSaleReportModel;
|
21 |
import com.spice.profitmandi.dao.model.*;
|
| 84 |
import com.spice.profitmandi.dao.model.FocoSchemeOutReportModel;
|
- |
|
| 85 |
import com.spice.profitmandi.dao.model.PartnerBillingSummaryModel;
|
- |
|
| 86 |
import com.spice.profitmandi.dao.model.PendingIndentReportModel;
|
- |
|
| 87 |
import com.spice.profitmandi.dao.model.PriceDropReportModel;
|
- |
|
| 88 |
import com.spice.profitmandi.dao.model.SchemePayoutReportModel;
|
- |
|
| 89 |
import com.spice.profitmandi.dao.model.WalletSummaryReportModel;
|
- |
|
| 90 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
22 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 91 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
23 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 92 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
24 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 93 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
- |
|
| 94 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
- |
|
| 95 |
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
|
- |
|
| 96 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
- |
|
| 97 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
- |
|
| 98 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
- |
|
| 99 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
- |
|
| 100 |
import com.spice.profitmandi.dao.repository.fofo.CustomerReturnItemRepository;
|
- |
|
| 101 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
- |
|
| 102 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
- |
|
| 103 |
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
|
- |
|
| 104 |
import com.spice.profitmandi.dao.repository.fofo.MouRepository;
|
25 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 105 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
- |
|
| 106 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
|
- |
|
| 107 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderRepository;
|
- |
|
| 108 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
|
- |
|
| 109 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
26 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 110 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
27 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 111 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
28 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 112 |
import com.spice.profitmandi.service.EmailService;
|
29 |
import com.spice.profitmandi.service.EmailService;
|
| 113 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
30 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| Line 654... |
Line 571... |
| 654 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
571 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
| 655 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
572 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
| 656 |
LOGGER.info("Request received at url {} with params [{}={}] ", request.getRequestURI(),
|
573 |
LOGGER.info("Request received at url {} with params [{}={}] ", request.getRequestURI(),
|
| 657 |
ProfitMandiConstants.ORDER_ID, orderId);
|
574 |
ProfitMandiConstants.ORDER_ID, orderId);
|
| 658 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
575 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 659 |
PdfModel pdfModel = null;
|
576 |
InvoicePdfModel pdfModel = null;
|
| 660 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
577 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 661 |
pdfModel = orderService.getInvoicePdfModel(orderId);
|
578 |
pdfModel = orderService.getInvoicePdfModel(orderId);
|
| 662 |
} else {
|
579 |
} else {
|
| 663 |
pdfModel = orderService.getInvoicePdfModel(fofoDetails.getFofoId(), orderId);
|
580 |
pdfModel = orderService.getInvoicePdfModel(fofoDetails.getFofoId(), orderId);
|
| 664 |
}
|
581 |
}
|
| Line 677... |
Line 594... |
| 677 |
@RequestMapping(value = "/generateInvoices")
|
594 |
@RequestMapping(value = "/generateInvoices")
|
| 678 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
595 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
| 679 |
@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, @RequestParam int partnerId)
|
596 |
@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, @RequestParam int partnerId)
|
| 680 |
throws ProfitMandiBusinessException {
|
597 |
throws ProfitMandiBusinessException {
|
| 681 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
598 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 682 |
List<PdfModel> pdfModels = new ArrayList<>();
|
599 |
List<InvoicePdfModel> pdfModels = new ArrayList<>();
|
| 683 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
600 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 684 |
List<Integer> orderIds = fofoOrderRepository.selectByFofoId(partnerId, startDate, endDate, 0, 0).stream()
|
601 |
List<Integer> orderIds = fofoOrderRepository.selectByFofoId(partnerId, startDate, endDate, 0, 0).stream()
|
| 685 |
.map(x -> x.getId()).collect(Collectors.toList());
|
602 |
.map(x -> x.getId()).collect(Collectors.toList());
|
| 686 |
for (int orderId : orderIds) {
|
603 |
for (int orderId : orderIds) {
|
| 687 |
pdfModels.add(orderService.getInvoicePdfModel(orderId));
|
604 |
pdfModels.add(orderService.getInvoicePdfModel(orderId));
|
| Line 739... |
Line 656... |
| 739 |
|
656 |
|
| 740 |
final HttpHeaders headers = new HttpHeaders();
|
657 |
final HttpHeaders headers = new HttpHeaders();
|
| 741 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
658 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
| 742 |
headers.set("Content-disposition", "inline; filename=invoices.pdf");
|
659 |
headers.set("Content-disposition", "inline; filename=invoices.pdf");
|
| 743 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
660 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 744 |
List<PdfModel> pdfModels = new ArrayList<>();
|
661 |
List<InvoicePdfModel> pdfModels = new ArrayList<>();
|
| 745 |
for (FofoOrder fofoOrder : fofoOrders) {
|
662 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 746 |
try {
|
663 |
try {
|
| 747 |
pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId()));
|
664 |
pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId()));
|
| 748 |
} catch (Exception e) {
|
665 |
} catch (Exception e) {
|
| 749 |
LOGGER.info("could not create invoice for {}, invoice number {}", fofoOrder.getId(),
|
666 |
LOGGER.info("could not create invoice for {}, invoice number {}", fofoOrder.getId(),
|