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