| 21612 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 21689 |
ashik.ali |
3 |
import java.io.ByteArrayInputStream;
|
|
|
4 |
import java.io.ByteArrayOutputStream;
|
|
|
5 |
import java.io.InputStream;
|
| 21612 |
ashik.ali |
6 |
import java.util.HashSet;
|
| 21680 |
ashik.ali |
7 |
import java.util.List;
|
|
|
8 |
import java.util.Map;
|
| 21612 |
ashik.ali |
9 |
import java.util.Set;
|
|
|
10 |
|
|
|
11 |
import javax.servlet.http.HttpServletRequest;
|
| 21689 |
ashik.ali |
12 |
import javax.servlet.http.HttpServletResponse;
|
| 21612 |
ashik.ali |
13 |
|
|
|
14 |
import org.slf4j.Logger;
|
|
|
15 |
import org.slf4j.LoggerFactory;
|
|
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21689 |
ashik.ali |
17 |
import org.springframework.core.io.InputStreamResource;
|
|
|
18 |
import org.springframework.http.HttpHeaders;
|
|
|
19 |
import org.springframework.http.HttpStatus;
|
|
|
20 |
import org.springframework.http.MediaType;
|
|
|
21 |
import org.springframework.http.ResponseEntity;
|
| 21612 |
ashik.ali |
22 |
import org.springframework.stereotype.Controller;
|
| 22064 |
ashik.ali |
23 |
import org.springframework.transaction.annotation.Transactional;
|
| 21985 |
kshitij.so |
24 |
import org.springframework.ui.Model;
|
| 21612 |
ashik.ali |
25 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
26 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
27 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21689 |
ashik.ali |
28 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21612 |
ashik.ali |
29 |
|
| 23203 |
ashik.ali |
30 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
| 21612 |
ashik.ali |
31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21985 |
kshitij.so |
32 |
import com.spice.profitmandi.common.model.CartFofo;
|
| 22860 |
ashik.ali |
33 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
| 22660 |
ashik.ali |
34 |
import com.spice.profitmandi.common.model.PdfModel;
|
| 22581 |
ashik.ali |
35 |
import com.spice.profitmandi.common.model.PriceModel;
|
| 21612 |
ashik.ali |
36 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21689 |
ashik.ali |
37 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 22244 |
ashik.ali |
38 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 22217 |
ashik.ali |
39 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
| 21728 |
ashik.ali |
40 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
|
|
41 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 22927 |
ashik.ali |
42 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 22860 |
ashik.ali |
43 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 21728 |
ashik.ali |
44 |
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
|
| 22217 |
ashik.ali |
45 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
| 21728 |
ashik.ali |
46 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
|
|
47 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
| 22860 |
ashik.ali |
48 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 21728 |
ashik.ali |
49 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
|
|
50 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 22927 |
ashik.ali |
51 |
import com.spice.profitmandi.service.inventory.OrderService;
|
| 22069 |
ashik.ali |
52 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 22139 |
amit.gupta |
53 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 22069 |
ashik.ali |
54 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 21612 |
ashik.ali |
55 |
|
|
|
56 |
@Controller
|
| 22037 |
amit.gupta |
57 |
@Transactional(rollbackFor=Throwable.class)
|
| 21612 |
ashik.ali |
58 |
public class OrderController {
|
|
|
59 |
|
|
|
60 |
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
| 21985 |
kshitij.so |
61 |
|
| 21612 |
ashik.ali |
62 |
@Autowired
|
| 22860 |
ashik.ali |
63 |
private CustomerRepository customerRepository;
|
| 21985 |
kshitij.so |
64 |
|
| 21612 |
ashik.ali |
65 |
@Autowired
|
| 22860 |
ashik.ali |
66 |
private FofoOrderItemRepository fofoLineItemRepository;
|
| 21985 |
kshitij.so |
67 |
|
| 21612 |
ashik.ali |
68 |
@Autowired
|
| 22860 |
ashik.ali |
69 |
private PaymentOptionRepository paymentOptionRepository;
|
| 21985 |
kshitij.so |
70 |
|
| 21680 |
ashik.ali |
71 |
@Autowired
|
| 22860 |
ashik.ali |
72 |
private FofoOrderRepository fofoOrderRepository;
|
| 21985 |
kshitij.so |
73 |
|
| 21680 |
ashik.ali |
74 |
@Autowired
|
| 22860 |
ashik.ali |
75 |
private CustomerAddressRepository customerAddressRepository;
|
| 22217 |
ashik.ali |
76 |
|
|
|
77 |
@Autowired
|
| 22860 |
ashik.ali |
78 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 21985 |
kshitij.so |
79 |
|
| 21896 |
ashik.ali |
80 |
@Autowired
|
| 22860 |
ashik.ali |
81 |
private CookiesProcessor cookiesProcessor;
|
| 22069 |
ashik.ali |
82 |
|
|
|
83 |
@Autowired
|
| 22860 |
ashik.ali |
84 |
private PricingService pricingService;
|
| 22244 |
ashik.ali |
85 |
|
| 22354 |
ashik.ali |
86 |
@Autowired
|
| 22860 |
ashik.ali |
87 |
private OrderService orderService;
|
| 22244 |
ashik.ali |
88 |
|
| 22354 |
ashik.ali |
89 |
|
|
|
90 |
@Autowired
|
| 22860 |
ashik.ali |
91 |
private ResponseSender<?> responseSender;
|
| 22689 |
amit.gupta |
92 |
|
| 21985 |
kshitij.so |
93 |
@RequestMapping(value = "/order")
|
| 22927 |
ashik.ali |
94 |
public String orderIndex(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException{
|
|
|
95 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);;
|
|
|
96 |
|
| 22860 |
ashik.ali |
97 |
List<CartFofo> cartItems = orderService.cartCheckout(cartData);
|
|
|
98 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
99 |
for(CartFofo cartFofo : cartItems){
|
|
|
100 |
itemIds.add(cartFofo.getItemId());
|
| 21985 |
kshitij.so |
101 |
}
|
| 22860 |
ashik.ali |
102 |
Map<Integer, PriceModel> mopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, loginDetails.getFofoId());
|
|
|
103 |
LOGGER.info("mopPriceMap {}", mopPriceMap);
|
|
|
104 |
model.addAttribute("cartObj", cartItems);
|
|
|
105 |
model.addAttribute("mopPriceMap", mopPriceMap);
|
|
|
106 |
return "order-index";
|
| 21985 |
kshitij.so |
107 |
}
|
| 22660 |
ashik.ali |
108 |
|
| 21612 |
ashik.ali |
109 |
|
| 22244 |
ashik.ali |
110 |
@RequestMapping(value = "/insurancePrices", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
111 |
public ResponseEntity<?> getInsurancePrices(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PRICE) float price) throws ProfitMandiBusinessException{
|
| 22244 |
ashik.ali |
112 |
LOGGER.info("Request received at url : {}", request.getRequestURI());
|
| 22927 |
ashik.ali |
113 |
Set<Float> prices = new HashSet<>();
|
|
|
114 |
prices.add(price);
|
|
|
115 |
return responseSender.ok(pricingService.getInsurancePrices(prices, ProfitMandiConstants.GADGET_COPS));
|
| 22244 |
ashik.ali |
116 |
}
|
|
|
117 |
|
|
|
118 |
|
| 21985 |
kshitij.so |
119 |
@RequestMapping(value = "/get-order", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
120 |
public String getOrder(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws ProfitMandiBusinessException{
|
|
|
121 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
122 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
|
|
123 |
List<FofoOrderItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
124 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
125 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
126 |
customerAddress.setPhoneNumber(customer.getMobileNumber());
|
|
|
127 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByOrderId(fofoOrder.getId());
|
|
|
128 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
|
|
129 |
model.addAttribute("fofoOrder", fofoOrder);
|
|
|
130 |
model.addAttribute("fofoLineItems", fofoLineItems);
|
|
|
131 |
model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
|
|
|
132 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
|
|
133 |
model.addAttribute("paymentOptions", paymentOptions);
|
|
|
134 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
135 |
return "order-details";
|
| 21985 |
kshitij.so |
136 |
}
|
| 22244 |
ashik.ali |
137 |
|
|
|
138 |
|
|
|
139 |
@RequestMapping(value = "/saleDetails", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
140 |
public String getSaleDetails(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws ProfitMandiBusinessException{
|
|
|
141 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
142 |
|
|
|
143 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
|
|
144 |
List<FofoOrderItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
145 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
146 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByOrderId(fofoOrder.getId());
|
|
|
147 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
|
|
148 |
model.addAttribute("fofoOrder", fofoOrder);
|
|
|
149 |
model.addAttribute("fofoLineItems", fofoLineItems);
|
|
|
150 |
model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
|
|
|
151 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
|
|
152 |
model.addAttribute("paymentOptions", paymentOptions);
|
|
|
153 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
154 |
return "sale-details";
|
| 22244 |
ashik.ali |
155 |
}
|
|
|
156 |
|
| 21985 |
kshitij.so |
157 |
|
|
|
158 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
| 22927 |
ashik.ali |
159 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest, Model model) throws ProfitMandiBusinessException{
|
| 22064 |
ashik.ali |
160 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), createOrderRequest);
|
| 22927 |
ashik.ali |
161 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
162 |
|
| 22860 |
ashik.ali |
163 |
int fofoOrderId = orderService.createOrder(createOrderRequest, fofoDetails.getFofoId());
|
| 22280 |
ashik.ali |
164 |
LOGGER.info("Order has been created successfully...");
|
| 22860 |
ashik.ali |
165 |
return "redirect:/get-order/?orderId="+fofoOrderId;
|
| 21612 |
ashik.ali |
166 |
}
|
| 21985 |
kshitij.so |
167 |
|
|
|
168 |
|
| 21689 |
ashik.ali |
169 |
@RequestMapping(value = "/generateInvoice")
|
| 22927 |
ashik.ali |
170 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException{
|
| 22064 |
ashik.ali |
171 |
LOGGER.info("Request received at url {} with params [{}={}] ", request.getRequestURI(), ProfitMandiConstants.ORDER_ID, orderId);
|
| 22139 |
amit.gupta |
172 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 22860 |
ashik.ali |
173 |
|
|
|
174 |
PdfModel pdfModel = orderService.getInvoicePdfModel(fofoDetails.getFofoId(), orderId);
|
| 22026 |
ashik.ali |
175 |
|
| 21689 |
ashik.ali |
176 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
177 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
|
|
178 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 22026 |
ashik.ali |
179 |
final HttpHeaders headers=new HttpHeaders();
|
|
|
180 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
| 22860 |
ashik.ali |
181 |
headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
| 22026 |
ashik.ali |
182 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
183 |
final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
184 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
|
|
185 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 21689 |
ashik.ali |
186 |
}
|
| 22244 |
ashik.ali |
187 |
|
|
|
188 |
@RequestMapping(value = "/saleHistory")
|
| 23203 |
ashik.ali |
189 |
public String saleHistory(HttpServletRequest request, @RequestParam(name = "searchValue", defaultValue = "") String searchValue, @RequestParam(name = "searchType", defaultValue="") SearchType searchType, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
| 22927 |
ashik.ali |
190 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22244 |
ashik.ali |
191 |
|
| 23203 |
ashik.ali |
192 |
Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue, startTimeString, endTimeString, offset, limit);
|
|
|
193 |
model.addAllAttributes(map);
|
| 22244 |
ashik.ali |
194 |
|
|
|
195 |
return "sale-history";
|
|
|
196 |
}
|
| 22291 |
ashik.ali |
197 |
|
|
|
198 |
|
|
|
199 |
@RequestMapping(value = "/getPaginatedSaleHistory")
|
| 23203 |
ashik.ali |
200 |
public String getSaleHistoryPaginated(HttpServletRequest request, @RequestParam(name = "searchValue", defaultValue="") String searchValue, @RequestParam(name = "searchType", defaultValue = "") SearchType searchType, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, Model model) throws ProfitMandiBusinessException{
|
| 22927 |
ashik.ali |
201 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
202 |
|
| 23203 |
ashik.ali |
203 |
Map<String, Object> map = orderService.getSaleHistoryPaginated(loginDetails.getFofoId(), searchType, searchValue, startTimeString, endTimeString, offset, limit);
|
|
|
204 |
model.addAllAttributes(map);
|
|
|
205 |
|
| 22291 |
ashik.ali |
206 |
return "sale-history-paginated";
|
|
|
207 |
}
|
|
|
208 |
|
| 21612 |
ashik.ali |
209 |
}
|