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