| 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;
|
| 23638 |
amit.gupta |
6 |
import java.time.LocalDateTime;
|
|
|
7 |
import java.time.temporal.ChronoUnit;
|
| 23654 |
amit.gupta |
8 |
import java.util.Arrays;
|
| 23343 |
ashik.ali |
9 |
import java.util.HashMap;
|
| 21612 |
ashik.ali |
10 |
import java.util.HashSet;
|
| 21680 |
ashik.ali |
11 |
import java.util.List;
|
|
|
12 |
import java.util.Map;
|
| 21612 |
ashik.ali |
13 |
import java.util.Set;
|
| 23638 |
amit.gupta |
14 |
import java.util.stream.Collectors;
|
| 21612 |
ashik.ali |
15 |
|
|
|
16 |
import javax.servlet.http.HttpServletRequest;
|
| 21689 |
ashik.ali |
17 |
import javax.servlet.http.HttpServletResponse;
|
| 21612 |
ashik.ali |
18 |
|
| 23638 |
amit.gupta |
19 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
20 |
import org.apache.logging.log4j.Logger;
|
| 21612 |
ashik.ali |
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21689 |
ashik.ali |
22 |
import org.springframework.core.io.InputStreamResource;
|
|
|
23 |
import org.springframework.http.HttpHeaders;
|
|
|
24 |
import org.springframework.http.HttpStatus;
|
|
|
25 |
import org.springframework.http.MediaType;
|
|
|
26 |
import org.springframework.http.ResponseEntity;
|
| 21612 |
ashik.ali |
27 |
import org.springframework.stereotype.Controller;
|
| 22064 |
ashik.ali |
28 |
import org.springframework.transaction.annotation.Transactional;
|
| 21985 |
kshitij.so |
29 |
import org.springframework.ui.Model;
|
| 23654 |
amit.gupta |
30 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 21612 |
ashik.ali |
31 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
32 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
33 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21689 |
ashik.ali |
34 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21612 |
ashik.ali |
35 |
|
| 23203 |
ashik.ali |
36 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
| 21612 |
ashik.ali |
37 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21985 |
kshitij.so |
38 |
import com.spice.profitmandi.common.model.CartFofo;
|
| 22860 |
ashik.ali |
39 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
| 23654 |
amit.gupta |
40 |
import com.spice.profitmandi.common.model.CreditNotePdfModel;
|
| 23584 |
ashik.ali |
41 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
| 23638 |
amit.gupta |
42 |
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
|
| 22660 |
ashik.ali |
43 |
import com.spice.profitmandi.common.model.PdfModel;
|
| 22581 |
ashik.ali |
44 |
import com.spice.profitmandi.common.model.PriceModel;
|
| 21612 |
ashik.ali |
45 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21689 |
ashik.ali |
46 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 23638 |
amit.gupta |
47 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 23298 |
ashik.ali |
48 |
import com.spice.profitmandi.common.util.Utils;
|
| 22244 |
ashik.ali |
49 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 23638 |
amit.gupta |
50 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 22217 |
ashik.ali |
51 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
| 23343 |
ashik.ali |
52 |
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
|
| 23548 |
ashik.ali |
53 |
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
|
| 21728 |
ashik.ali |
54 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
|
|
55 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 23654 |
amit.gupta |
56 |
import com.spice.profitmandi.dao.entity.fofo.CustomerCreditNote;
|
|
|
57 |
import com.spice.profitmandi.dao.entity.fofo.CustomerReturnItem;
|
| 23638 |
amit.gupta |
58 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| 22927 |
ashik.ali |
59 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 22860 |
ashik.ali |
60 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 21728 |
ashik.ali |
61 |
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
|
| 23419 |
ashik.ali |
62 |
import com.spice.profitmandi.dao.entity.fofo.PrebookingOrderItem;
|
| 23298 |
ashik.ali |
63 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 23548 |
ashik.ali |
64 |
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
|
| 23638 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 22217 |
ashik.ali |
66 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
| 23343 |
ashik.ali |
67 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
| 23638 |
amit.gupta |
68 |
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
|
| 23298 |
ashik.ali |
69 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 21728 |
ashik.ali |
70 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
|
|
71 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
| 23650 |
amit.gupta |
72 |
import com.spice.profitmandi.dao.repository.fofo.CustomerReturnItemRepository;
|
| 23638 |
amit.gupta |
73 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
| 22860 |
ashik.ali |
74 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 21728 |
ashik.ali |
75 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 23366 |
ashik.ali |
76 |
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
|
| 21728 |
ashik.ali |
77 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 23419 |
ashik.ali |
78 |
import com.spice.profitmandi.dao.repository.fofo.PrebookingOrderItemRepository;
|
| 23298 |
ashik.ali |
79 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 23798 |
amit.gupta |
80 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23366 |
ashik.ali |
81 |
import com.spice.profitmandi.service.order.OrderService;
|
| 22069 |
ashik.ali |
82 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 22139 |
amit.gupta |
83 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 22069 |
ashik.ali |
84 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 21612 |
ashik.ali |
85 |
|
|
|
86 |
@Controller
|
| 23973 |
govind |
87 |
@Transactional(rollbackFor = Throwable.class)
|
| 21612 |
ashik.ali |
88 |
public class OrderController {
|
|
|
89 |
|
| 23568 |
govind |
90 |
private static final Logger LOGGER = LogManager.getLogger(OrderController.class);
|
| 21985 |
kshitij.so |
91 |
|
| 21612 |
ashik.ali |
92 |
@Autowired
|
| 22860 |
ashik.ali |
93 |
private CustomerRepository customerRepository;
|
| 23973 |
govind |
94 |
|
| 23821 |
amit.gupta |
95 |
private boolean accessoriesDeals = true;
|
| 21985 |
kshitij.so |
96 |
|
| 21612 |
ashik.ali |
97 |
@Autowired
|
| 23786 |
amit.gupta |
98 |
private RoleManager roleManager;
|
| 23973 |
govind |
99 |
|
| 23786 |
amit.gupta |
100 |
@Autowired
|
| 23654 |
amit.gupta |
101 |
private CustomerReturnItemRepository customerReturnItemRepository;
|
| 23973 |
govind |
102 |
|
| 23654 |
amit.gupta |
103 |
@Autowired
|
| 23638 |
amit.gupta |
104 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 21985 |
kshitij.so |
105 |
|
| 21612 |
ashik.ali |
106 |
@Autowired
|
| 22860 |
ashik.ali |
107 |
private PaymentOptionRepository paymentOptionRepository;
|
| 23973 |
govind |
108 |
|
| 23638 |
amit.gupta |
109 |
@Autowired
|
|
|
110 |
private ItemRepository itemRepository;
|
| 21985 |
kshitij.so |
111 |
|
| 21680 |
ashik.ali |
112 |
@Autowired
|
| 22860 |
ashik.ali |
113 |
private FofoOrderRepository fofoOrderRepository;
|
| 21985 |
kshitij.so |
114 |
|
| 21680 |
ashik.ali |
115 |
@Autowired
|
| 22860 |
ashik.ali |
116 |
private CustomerAddressRepository customerAddressRepository;
|
| 23973 |
govind |
117 |
|
| 22217 |
ashik.ali |
118 |
@Autowired
|
| 22860 |
ashik.ali |
119 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 23973 |
govind |
120 |
|
| 23343 |
ashik.ali |
121 |
@Autowired
|
|
|
122 |
private InsuranceProviderRepository insuranceProviderRepository;
|
| 21985 |
kshitij.so |
123 |
|
| 21896 |
ashik.ali |
124 |
@Autowired
|
| 22860 |
ashik.ali |
125 |
private CookiesProcessor cookiesProcessor;
|
| 23973 |
govind |
126 |
|
| 22069 |
ashik.ali |
127 |
@Autowired
|
| 22860 |
ashik.ali |
128 |
private PricingService pricingService;
|
| 23973 |
govind |
129 |
|
| 22354 |
ashik.ali |
130 |
@Autowired
|
| 22860 |
ashik.ali |
131 |
private OrderService orderService;
|
| 23973 |
govind |
132 |
|
| 23298 |
ashik.ali |
133 |
@Autowired
|
|
|
134 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 23973 |
govind |
135 |
|
| 22354 |
ashik.ali |
136 |
@Autowired
|
| 23298 |
ashik.ali |
137 |
private AddressRepository addressRepository;
|
| 23973 |
govind |
138 |
|
| 23298 |
ashik.ali |
139 |
@Autowired
|
| 23548 |
ashik.ali |
140 |
private PaymentOptionTransactionRepository fofoOrderPaymentOptionRepository;
|
| 23973 |
govind |
141 |
|
| 23366 |
ashik.ali |
142 |
@Autowired
|
|
|
143 |
private FofoPartnerPaymentOptionRepository fofoPartnerPaymentOptionRepository;
|
| 23973 |
govind |
144 |
|
| 23366 |
ashik.ali |
145 |
@Autowired
|
| 23419 |
ashik.ali |
146 |
private PrebookingOrderItemRepository prebookingOrderItemRepository;
|
| 23973 |
govind |
147 |
|
| 23419 |
ashik.ali |
148 |
@Autowired
|
| 22860 |
ashik.ali |
149 |
private ResponseSender<?> responseSender;
|
| 23973 |
govind |
150 |
|
| 21985 |
kshitij.so |
151 |
@RequestMapping(value = "/order")
|
| 23973 |
govind |
152 |
public String orderIndex(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model)
|
|
|
153 |
throws ProfitMandiBusinessException {
|
|
|
154 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
155 |
;
|
|
|
156 |
|
| 23298 |
ashik.ali |
157 |
int addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(loginDetails.getFofoId());
|
|
|
158 |
Address address = addressRepository.selectById(addressId);
|
| 23973 |
govind |
159 |
|
| 22860 |
ashik.ali |
160 |
List<CartFofo> cartItems = orderService.cartCheckout(cartData);
|
|
|
161 |
Set<Integer> itemIds = new HashSet<>();
|
| 23973 |
govind |
162 |
for (CartFofo cartFofo : cartItems) {
|
| 22860 |
ashik.ali |
163 |
itemIds.add(cartFofo.getItemId());
|
| 21985 |
kshitij.so |
164 |
}
|
| 23973 |
govind |
165 |
Map<Integer, PriceModel> mopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds,
|
|
|
166 |
loginDetails.getFofoId());
|
|
|
167 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository
|
|
|
168 |
.selectPaymentOptionIdsByFofoId(loginDetails.getFofoId());
|
| 23366 |
ashik.ali |
169 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds));
|
| 22860 |
ashik.ali |
170 |
LOGGER.info("mopPriceMap {}", mopPriceMap);
|
| 23298 |
ashik.ali |
171 |
model.addAttribute("stateNames", Utils.getAllStateNames());
|
|
|
172 |
model.addAttribute("retailerStateName", address.getState());
|
| 22860 |
ashik.ali |
173 |
model.addAttribute("cartObj", cartItems);
|
|
|
174 |
model.addAttribute("mopPriceMap", mopPriceMap);
|
| 23366 |
ashik.ali |
175 |
model.addAttribute("paymentOptions", paymentOptions);
|
| 23821 |
amit.gupta |
176 |
model.addAttribute("accessoriesDeals", accessoriesDeals);
|
| 22860 |
ashik.ali |
177 |
return "order-index";
|
| 21985 |
kshitij.so |
178 |
}
|
| 23973 |
govind |
179 |
|
| 22244 |
ashik.ali |
180 |
@RequestMapping(value = "/insurancePrices", method = RequestMethod.GET)
|
| 23973 |
govind |
181 |
public ResponseEntity<?> getInsurancePrices(HttpServletRequest request,
|
|
|
182 |
@RequestParam(name = ProfitMandiConstants.PRICE) float price) throws ProfitMandiBusinessException {
|
| 22244 |
ashik.ali |
183 |
LOGGER.info("Request received at url : {}", request.getRequestURI());
|
| 22927 |
ashik.ali |
184 |
Set<Float> prices = new HashSet<>();
|
|
|
185 |
prices.add(price);
|
|
|
186 |
return responseSender.ok(pricingService.getInsurancePrices(prices, ProfitMandiConstants.GADGET_COPS));
|
| 22244 |
ashik.ali |
187 |
}
|
| 23973 |
govind |
188 |
|
| 21985 |
kshitij.so |
189 |
@RequestMapping(value = "/get-order", method = RequestMethod.GET)
|
| 23973 |
govind |
190 |
public String getOrder(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId,
|
|
|
191 |
Model model) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
192 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
193 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 23638 |
amit.gupta |
194 |
List<FofoOrderItem> fofoLineItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 22927 |
ashik.ali |
195 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 23973 |
govind |
196 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
| 22927 |
ashik.ali |
197 |
customerAddress.setPhoneNumber(customer.getMobileNumber());
|
| 23973 |
govind |
198 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
199 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
200 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
|
|
201 |
.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
|
|
|
202 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
203 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23343 |
ashik.ali |
204 |
this.addInsuranceProvider(insurancePolicies);
|
| 23419 |
ashik.ali |
205 |
List<PrebookingOrderItem> prebookingOrderItems = prebookingOrderItemRepository.selectByOrderId(orderId);
|
| 23973 |
govind |
206 |
Map<Integer, PrebookingOrderItem> itemIdPrebookingOrderItemMap = this
|
|
|
207 |
.prebookingOrderItemToItemIdPrebookingOrderItem(prebookingOrderItems);
|
| 22927 |
ashik.ali |
208 |
model.addAttribute("fofoOrder", fofoOrder);
|
|
|
209 |
model.addAttribute("fofoLineItems", fofoLineItems);
|
|
|
210 |
model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
|
|
|
211 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
| 23548 |
ashik.ali |
212 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
| 23366 |
ashik.ali |
213 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
| 22927 |
ashik.ali |
214 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
| 23419 |
ashik.ali |
215 |
model.addAttribute("itemIdPrebookingOrderItemMap", itemIdPrebookingOrderItemMap);
|
| 22927 |
ashik.ali |
216 |
return "order-details";
|
| 21985 |
kshitij.so |
217 |
}
|
| 23973 |
govind |
218 |
|
| 23419 |
ashik.ali |
219 |
@RequestMapping(value = "/generateOtp", method = RequestMethod.POST)
|
| 23973 |
govind |
220 |
public ResponseEntity<?> generateOtp(@RequestBody Map<Integer, Float> itemIdAdvanceAmount,
|
|
|
221 |
@RequestParam(name = ProfitMandiConstants.CUSTOMER_EMAIL_ID) String customerEmailId,
|
|
|
222 |
@RequestParam(name = ProfitMandiConstants.CUSTOMER_MOBILE_NUMBER) String customerMobileNumber)
|
|
|
223 |
throws ProfitMandiBusinessException {
|
|
|
224 |
|
|
|
225 |
int response = orderService.generatePrebookingOrdersOtp(customerEmailId, customerMobileNumber,
|
|
|
226 |
itemIdAdvanceAmount);
|
|
|
227 |
|
| 23419 |
ashik.ali |
228 |
return responseSender.ok(response);
|
|
|
229 |
}
|
| 23973 |
govind |
230 |
|
| 23419 |
ashik.ali |
231 |
@RequestMapping(value = "/validateOtp", method = RequestMethod.GET)
|
| 23973 |
govind |
232 |
public ResponseEntity<?> validateOtp(
|
|
|
233 |
@RequestParam(name = ProfitMandiConstants.CUSTOMER_EMAIL_ID) String customerEmailId,
|
| 23419 |
ashik.ali |
234 |
@RequestParam(name = ProfitMandiConstants.CUSTOMER_MOBILE_NUMBER) String customerMobileNumber,
|
|
|
235 |
@RequestParam("otpId") int otpId, @RequestParam("otpValue") String otpValue)
|
| 23973 |
govind |
236 |
throws ProfitMandiBusinessException {
|
|
|
237 |
|
| 23419 |
ashik.ali |
238 |
String responseString = orderService.validateOtp(customerEmailId, customerMobileNumber, otpId, otpValue);
|
| 23973 |
govind |
239 |
|
| 23419 |
ashik.ali |
240 |
return responseSender.ok(responseString);
|
|
|
241 |
}
|
| 23973 |
govind |
242 |
|
|
|
243 |
private Map<Integer, InsuranceProvider> toInsuranceProviderIdInsuranceProvider(
|
|
|
244 |
List<InsuranceProvider> insuranceProviders) {
|
| 23343 |
ashik.ali |
245 |
Map<Integer, InsuranceProvider> insuranceProviderIdInsuranceProviderMap = new HashMap<>();
|
| 23973 |
govind |
246 |
for (InsuranceProvider insuranceProvider : insuranceProviders) {
|
| 23343 |
ashik.ali |
247 |
insuranceProviderIdInsuranceProviderMap.put(insuranceProvider.getId(), insuranceProvider);
|
|
|
248 |
}
|
|
|
249 |
return insuranceProviderIdInsuranceProviderMap;
|
|
|
250 |
}
|
| 23973 |
govind |
251 |
|
|
|
252 |
private void addInsuranceProvider(List<InsurancePolicy> insurancePolicies) {
|
|
|
253 |
if (insurancePolicies.isEmpty()) {
|
| 23343 |
ashik.ali |
254 |
return;
|
|
|
255 |
}
|
|
|
256 |
Set<Integer> insuranceProviderIds = new HashSet<>();
|
| 23973 |
govind |
257 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| 23343 |
ashik.ali |
258 |
insuranceProviderIds.add(insurancePolicy.getProviderId());
|
|
|
259 |
}
|
|
|
260 |
LOGGER.info("insuranceProviderIds {}", insuranceProviderIds);
|
|
|
261 |
List<InsuranceProvider> insuranceProviders = insuranceProviderRepository.selectByIds(insuranceProviderIds);
|
| 23973 |
govind |
262 |
Map<Integer, InsuranceProvider> insuranceProviderIdInsuranceProviderMap = this
|
|
|
263 |
.toInsuranceProviderIdInsuranceProvider(insuranceProviders);
|
|
|
264 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
|
|
265 |
insurancePolicy
|
|
|
266 |
.setInsuranceProvider(insuranceProviderIdInsuranceProviderMap.get(insurancePolicy.getProviderId()));
|
| 23343 |
ashik.ali |
267 |
}
|
|
|
268 |
}
|
| 23973 |
govind |
269 |
|
| 22244 |
ashik.ali |
270 |
@RequestMapping(value = "/saleDetails", method = RequestMethod.GET)
|
| 23973 |
govind |
271 |
public String getSaleDetails(HttpServletRequest request,
|
|
|
272 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws Exception {
|
| 22927 |
ashik.ali |
273 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
274 |
|
| 22927 |
ashik.ali |
275 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 23654 |
amit.gupta |
276 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 22927 |
ashik.ali |
277 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 23973 |
govind |
278 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
279 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
280 |
|
|
|
281 |
// Added Migration info as we lost it.
|
|
|
282 |
if (paymentOptionTransactions == null || paymentOptionTransactions.size() == 0) {
|
| 23952 |
amit.gupta |
283 |
PaymentOptionTransaction pot = new PaymentOptionTransaction();
|
|
|
284 |
pot.setAmount(fofoOrder.getTotalAmount());
|
|
|
285 |
pot.setCreateTimestamp(fofoOrder.getCreateTimestamp());
|
| 23973 |
govind |
286 |
// Mark it paid through cash
|
| 23952 |
amit.gupta |
287 |
pot.setPaymentOptionId(1);
|
|
|
288 |
pot.setReferenceType(PaymentOptionReferenceType.ORDER);
|
|
|
289 |
fofoOrderPaymentOptionRepository.persist(pot);
|
|
|
290 |
paymentOptionTransactions.add(pot);
|
|
|
291 |
LOGGER.info("Added to get invoice");
|
|
|
292 |
}
|
| 23973 |
govind |
293 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
|
|
294 |
.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
|
|
|
295 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
296 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23343 |
ashik.ali |
297 |
this.addInsuranceProvider(insurancePolicies);
|
| 23419 |
ashik.ali |
298 |
List<PrebookingOrderItem> prebookingOrderItems = prebookingOrderItemRepository.selectByOrderId(orderId);
|
| 23973 |
govind |
299 |
Map<Integer, PrebookingOrderItem> itemIdPrebookingOrderItemMap = this
|
|
|
300 |
.prebookingOrderItemToItemIdPrebookingOrderItem(prebookingOrderItems);
|
|
|
301 |
Map<Integer, Item> itemsMap = fofoOrderItems.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> {
|
| 23638 |
amit.gupta |
302 |
try {
|
|
|
303 |
return itemRepository.selectById(x.getItemId());
|
|
|
304 |
} catch (ProfitMandiBusinessException e) {
|
|
|
305 |
// TODO Auto-generated catch block
|
|
|
306 |
return null;
|
|
|
307 |
}
|
|
|
308 |
}));
|
| 23973 |
govind |
309 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdLineItemMap = fofoOrderItems.stream()
|
|
|
310 |
.collect(Collectors.toMap(FofoOrderItem::getId, FofoOrderItem::getFofoLineItems));
|
| 23654 |
amit.gupta |
311 |
|
| 23973 |
govind |
312 |
Map<Integer, List<CustomerReturnItem>> foiIdCustomerReturnInventoryItemsMap = fofoOrderItems.stream()
|
|
|
313 |
.collect(Collectors.toMap(foi -> foi.getId(),
|
|
|
314 |
foi -> customerReturnItemRepository.selectAllByOrderItemId(foi.getId())));
|
| 23654 |
amit.gupta |
315 |
|
|
|
316 |
Map<Integer, Integer> inventoryItemBilledQtyMap = new HashMap<>();
|
| 23973 |
govind |
317 |
|
|
|
318 |
for (FofoOrderItem foi : fofoOrderItems) {
|
|
|
319 |
for (FofoLineItem fli : foi.getFofoLineItems()) {
|
| 23654 |
amit.gupta |
320 |
inventoryItemBilledQtyMap.put(fli.getInventoryItemId(), fli.getQuantity());
|
|
|
321 |
}
|
| 23973 |
govind |
322 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository
|
|
|
323 |
.selectAllByOrderItemId(foi.getId());
|
|
|
324 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
|
|
325 |
inventoryItemBilledQtyMap.put(customerReturnItem.getInventoryItemId(),
|
|
|
326 |
inventoryItemBilledQtyMap.get(customerReturnItem.getInventoryItemId()) - 1);
|
| 23654 |
amit.gupta |
327 |
}
|
|
|
328 |
}
|
| 23973 |
govind |
329 |
|
| 23654 |
amit.gupta |
330 |
LOGGER.info("fofoOrderItemIdLineItemMap {}", fofoOrderItemIdLineItemMap);
|
| 22927 |
ashik.ali |
331 |
model.addAttribute("fofoOrder", fofoOrder);
|
| 23638 |
amit.gupta |
332 |
model.addAttribute("itemsMap", itemsMap);
|
| 23654 |
amit.gupta |
333 |
model.addAttribute("fofoOrderItemIdLineItemsMap", StringUtils.toString(fofoOrderItemIdLineItemMap));
|
| 23973 |
govind |
334 |
model.addAttribute("foiIdCustomerReturnInventoryItemsMap",
|
|
|
335 |
StringUtils.toString(foiIdCustomerReturnInventoryItemsMap));
|
| 23654 |
amit.gupta |
336 |
model.addAttribute("fofoOrderItems", fofoOrderItems);
|
|
|
337 |
model.addAttribute("inventoryItemBilledQtyMap", StringUtils.toString(inventoryItemBilledQtyMap));
|
| 22927 |
ashik.ali |
338 |
model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
|
|
|
339 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
| 23548 |
ashik.ali |
340 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
| 23366 |
ashik.ali |
341 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
| 22927 |
ashik.ali |
342 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
| 23419 |
ashik.ali |
343 |
model.addAttribute("itemIdPrebookingOrderItemMap", itemIdPrebookingOrderItemMap);
|
| 23638 |
amit.gupta |
344 |
model.addAttribute("markDoa", this.markDoa(fofoOrder));
|
|
|
345 |
model.addAttribute("markDefective", this.markDefective(fofoOrder));
|
| 22927 |
ashik.ali |
346 |
return "sale-details";
|
| 22244 |
ashik.ali |
347 |
}
|
| 23973 |
govind |
348 |
|
| 23638 |
amit.gupta |
349 |
private boolean markDoa(FofoOrder fofoOrder) {
|
| 23973 |
govind |
350 |
return fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS).plusDays(90)
|
|
|
351 |
.isAfter(LocalDateTime.now().truncatedTo(ChronoUnit.DAYS));
|
| 23638 |
amit.gupta |
352 |
}
|
| 23973 |
govind |
353 |
|
| 23638 |
amit.gupta |
354 |
private boolean markDefective(FofoOrder fofoOrder) {
|
| 23973 |
govind |
355 |
return fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS).plusDays(180)
|
|
|
356 |
.isAfter(LocalDateTime.now().truncatedTo(ChronoUnit.DAYS));
|
|
|
357 |
|
| 23638 |
amit.gupta |
358 |
}
|
| 23973 |
govind |
359 |
|
| 23584 |
ashik.ali |
360 |
@RequestMapping(value = "/getSearchOrder")
|
| 23973 |
govind |
361 |
public String getSearchOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 23584 |
ashik.ali |
362 |
return "search-order";
|
|
|
363 |
}
|
| 23973 |
govind |
364 |
|
| 23584 |
ashik.ali |
365 |
@RequestMapping(value = "/customerDetails", method = RequestMethod.PUT)
|
| 23973 |
govind |
366 |
public String updateCustomerDetails(HttpServletRequest request, @RequestBody CustomCustomer customCustomer,
|
|
|
367 |
@RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER) String invoiceNumber, Model model)
|
|
|
368 |
throws ProfitMandiBusinessException {
|
|
|
369 |
|
| 23584 |
ashik.ali |
370 |
orderService.updateCustomerDetails(customCustomer, invoiceNumber);
|
| 23973 |
govind |
371 |
|
| 23584 |
ashik.ali |
372 |
return this.getSearchOrderDetails(request, invoiceNumber, model);
|
|
|
373 |
}
|
| 23973 |
govind |
374 |
|
| 23584 |
ashik.ali |
375 |
@RequestMapping(value = "/searchOrderDetails", method = RequestMethod.GET)
|
| 23973 |
govind |
376 |
public String getSearchOrderDetails(HttpServletRequest request,
|
|
|
377 |
@RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER) String invoiceNumber, Model model)
|
|
|
378 |
throws ProfitMandiBusinessException {
|
|
|
379 |
|
| 23584 |
ashik.ali |
380 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 23638 |
amit.gupta |
381 |
List<FofoOrderItem> fofoLineItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 23584 |
ashik.ali |
382 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
383 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 23973 |
govind |
384 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
385 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
386 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
|
|
387 |
.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
|
|
|
388 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
389 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23584 |
ashik.ali |
390 |
this.addInsuranceProvider(insurancePolicies);
|
| 23973 |
govind |
391 |
List<PrebookingOrderItem> prebookingOrderItems = prebookingOrderItemRepository
|
|
|
392 |
.selectByOrderId(fofoOrder.getId());
|
|
|
393 |
Map<Integer, PrebookingOrderItem> itemIdPrebookingOrderItemMap = this
|
|
|
394 |
.prebookingOrderItemToItemIdPrebookingOrderItem(prebookingOrderItems);
|
| 23584 |
ashik.ali |
395 |
model.addAttribute("fofoOrder", fofoOrder);
|
|
|
396 |
model.addAttribute("fofoLineItems", fofoLineItems);
|
|
|
397 |
model.addAttribute("customer", customer);
|
|
|
398 |
model.addAttribute("customerAddress", customerAddress);
|
|
|
399 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
|
|
400 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
|
|
401 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
402 |
model.addAttribute("itemIdPrebookingOrderItemMap", itemIdPrebookingOrderItemMap);
|
|
|
403 |
model.addAttribute("stateNames", Utils.getAllStateNames());
|
|
|
404 |
return "search-order-details";
|
|
|
405 |
}
|
| 23973 |
govind |
406 |
|
|
|
407 |
private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap(
|
|
|
408 |
List<PaymentOptionTransaction> paymentOptionTransactions) {
|
| 23366 |
ashik.ali |
409 |
Set<Integer> paymentOptionIds = new HashSet<>();
|
| 23973 |
govind |
410 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
| 23548 |
ashik.ali |
411 |
paymentOptionIds.add(paymentOptionTransaction.getPaymentOptionId());
|
| 23366 |
ashik.ali |
412 |
}
|
|
|
413 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByIds(paymentOptionIds);
|
|
|
414 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = new HashMap<>();
|
| 23973 |
govind |
415 |
for (PaymentOption paymentOption : paymentOptions) {
|
| 23366 |
ashik.ali |
416 |
paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
|
|
|
417 |
}
|
|
|
418 |
return paymentOptionIdPaymentOptionMap;
|
|
|
419 |
}
|
| 23973 |
govind |
420 |
|
|
|
421 |
private Map<Integer, PrebookingOrderItem> prebookingOrderItemToItemIdPrebookingOrderItem(
|
|
|
422 |
List<PrebookingOrderItem> prebookingOrderItems) {
|
| 23419 |
ashik.ali |
423 |
Map<Integer, PrebookingOrderItem> itemIdPrebookingOrderItem = new HashMap<>();
|
| 23973 |
govind |
424 |
for (PrebookingOrderItem prebookingOrderItem : prebookingOrderItems) {
|
| 23419 |
ashik.ali |
425 |
itemIdPrebookingOrderItem.put(prebookingOrderItem.getItemId(), prebookingOrderItem);
|
|
|
426 |
}
|
|
|
427 |
return itemIdPrebookingOrderItem;
|
|
|
428 |
}
|
| 21985 |
kshitij.so |
429 |
|
|
|
430 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
| 23973 |
govind |
431 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest,
|
|
|
432 |
Model model) throws ProfitMandiBusinessException {
|
| 22064 |
ashik.ali |
433 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), createOrderRequest);
|
| 22927 |
ashik.ali |
434 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
435 |
|
| 23823 |
amit.gupta |
436 |
int fofoOrderId = orderService.createOrder(createOrderRequest, fofoDetails.getFofoId(), accessoriesDeals);
|
| 22280 |
ashik.ali |
437 |
LOGGER.info("Order has been created successfully...");
|
| 23973 |
govind |
438 |
return "redirect:/get-order/?orderId=" + fofoOrderId;
|
| 21612 |
ashik.ali |
439 |
}
|
| 23973 |
govind |
440 |
|
| 23638 |
amit.gupta |
441 |
@RequestMapping(value = "/order/bad_return", method = RequestMethod.POST)
|
| 23973 |
govind |
442 |
public ResponseEntity<?> badReturn(HttpServletRequest request, @RequestBody FoiBadReturnRequest foiBadReturnRequest,
|
|
|
443 |
Model model) throws ProfitMandiBusinessException {
|
| 23638 |
amit.gupta |
444 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), foiBadReturnRequest);
|
|
|
445 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23654 |
amit.gupta |
446 |
CustomerCreditNote custmoerCreditNote = orderService.badReturn(fofoDetails.getFofoId(), foiBadReturnRequest);
|
|
|
447 |
return responseSender.ok(custmoerCreditNote.getId());
|
| 23638 |
amit.gupta |
448 |
}
|
| 21985 |
kshitij.so |
449 |
|
| 21689 |
ashik.ali |
450 |
@RequestMapping(value = "/generateInvoice")
|
| 23973 |
govind |
451 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
|
|
452 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
|
|
453 |
LOGGER.info("Request received at url {} with params [{}={}] ", request.getRequestURI(),
|
|
|
454 |
ProfitMandiConstants.ORDER_ID, orderId);
|
| 22139 |
amit.gupta |
455 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23594 |
ashik.ali |
456 |
PdfModel pdfModel = null;
|
| 23973 |
govind |
457 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 23594 |
ashik.ali |
458 |
pdfModel = orderService.getInvoicePdfModel(orderId);
|
| 23973 |
govind |
459 |
} else {
|
| 23594 |
ashik.ali |
460 |
pdfModel = orderService.getInvoicePdfModel(fofoDetails.getFofoId(), orderId);
|
|
|
461 |
}
|
| 21689 |
ashik.ali |
462 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
463 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
|
|
464 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 23973 |
govind |
465 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
466 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
467 |
headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
|
|
468 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
469 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
470 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
471 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 21689 |
ashik.ali |
472 |
}
|
| 23973 |
govind |
473 |
|
| 22244 |
ashik.ali |
474 |
@RequestMapping(value = "/saleHistory")
|
| 23973 |
govind |
475 |
public String saleHistory(HttpServletRequest request,
|
|
|
476 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
477 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
478 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
479 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
480 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
481 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
482 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
483 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
484 |
|
|
|
485 |
Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue,
|
|
|
486 |
startTime, endTime, offset, limit);
|
| 23203 |
ashik.ali |
487 |
model.addAllAttributes(map);
|
| 23973 |
govind |
488 |
|
| 22244 |
ashik.ali |
489 |
return "sale-history";
|
|
|
490 |
}
|
| 23973 |
govind |
491 |
|
|
|
492 |
@RequestMapping(value = "/credit-note/{creditNoteId}")
|
|
|
493 |
public ResponseEntity<?> downloadCreditNote(HttpServletRequest request, @PathVariable int creditNoteId)
|
|
|
494 |
throws ProfitMandiBusinessException {
|
| 23654 |
amit.gupta |
495 |
CreditNotePdfModel creditNotePdfModel = orderService.getCreditNotePdfModel(creditNoteId);
|
|
|
496 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
497 |
PdfUtils.generateAndWriteCustomerCreditNotes(Arrays.asList(creditNotePdfModel), byteArrayOutputStream);
|
|
|
498 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 23973 |
govind |
499 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
500 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
501 |
headers.set("Content-disposition",
|
|
|
502 |
"inline; filename=invoice-" + creditNotePdfModel.getCreditNoteNumber() + ".pdf");
|
|
|
503 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
504 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
505 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
506 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 23654 |
amit.gupta |
507 |
}
|
| 23973 |
govind |
508 |
|
| 22291 |
ashik.ali |
509 |
@RequestMapping(value = "/getPaginatedSaleHistory")
|
| 23973 |
govind |
510 |
public String getSaleHistoryPaginated(HttpServletRequest request,
|
|
|
511 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
512 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
513 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
514 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
515 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
516 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
517 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
518 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
519 |
Map<String, Object> map = orderService.getSaleHistoryPaginated(loginDetails.getFofoId(), searchType,
|
|
|
520 |
searchValue, startTime, endTime, offset, limit);
|
| 23203 |
ashik.ali |
521 |
model.addAllAttributes(map);
|
| 23973 |
govind |
522 |
|
| 22291 |
ashik.ali |
523 |
return "sale-history-paginated";
|
|
|
524 |
}
|
|
|
525 |
|
| 21612 |
ashik.ali |
526 |
}
|