| 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 |
|
|
|
142 |
|
| 23419 |
ashik.ali |
143 |
@Autowired
|
| 22860 |
ashik.ali |
144 |
private ResponseSender<?> responseSender;
|
| 23973 |
govind |
145 |
|
| 21985 |
kshitij.so |
146 |
@RequestMapping(value = "/order")
|
| 23973 |
govind |
147 |
public String orderIndex(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model)
|
|
|
148 |
throws ProfitMandiBusinessException {
|
|
|
149 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
150 |
;
|
|
|
151 |
|
| 23298 |
ashik.ali |
152 |
int addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(loginDetails.getFofoId());
|
|
|
153 |
Address address = addressRepository.selectById(addressId);
|
| 23973 |
govind |
154 |
|
| 22860 |
ashik.ali |
155 |
List<CartFofo> cartItems = orderService.cartCheckout(cartData);
|
|
|
156 |
Set<Integer> itemIds = new HashSet<>();
|
| 23973 |
govind |
157 |
for (CartFofo cartFofo : cartItems) {
|
| 22860 |
ashik.ali |
158 |
itemIds.add(cartFofo.getItemId());
|
| 21985 |
kshitij.so |
159 |
}
|
| 23973 |
govind |
160 |
Map<Integer, PriceModel> mopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds,
|
|
|
161 |
loginDetails.getFofoId());
|
|
|
162 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository
|
|
|
163 |
.selectPaymentOptionIdsByFofoId(loginDetails.getFofoId());
|
| 23366 |
ashik.ali |
164 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds));
|
| 22860 |
ashik.ali |
165 |
LOGGER.info("mopPriceMap {}", mopPriceMap);
|
| 23298 |
ashik.ali |
166 |
model.addAttribute("stateNames", Utils.getAllStateNames());
|
|
|
167 |
model.addAttribute("retailerStateName", address.getState());
|
| 22860 |
ashik.ali |
168 |
model.addAttribute("cartObj", cartItems);
|
|
|
169 |
model.addAttribute("mopPriceMap", mopPriceMap);
|
| 23366 |
ashik.ali |
170 |
model.addAttribute("paymentOptions", paymentOptions);
|
| 23821 |
amit.gupta |
171 |
model.addAttribute("accessoriesDeals", accessoriesDeals);
|
| 22860 |
ashik.ali |
172 |
return "order-index";
|
| 21985 |
kshitij.so |
173 |
}
|
| 23973 |
govind |
174 |
|
| 22244 |
ashik.ali |
175 |
@RequestMapping(value = "/insurancePrices", method = RequestMethod.GET)
|
| 23973 |
govind |
176 |
public ResponseEntity<?> getInsurancePrices(HttpServletRequest request,
|
|
|
177 |
@RequestParam(name = ProfitMandiConstants.PRICE) float price) throws ProfitMandiBusinessException {
|
| 22244 |
ashik.ali |
178 |
LOGGER.info("Request received at url : {}", request.getRequestURI());
|
| 22927 |
ashik.ali |
179 |
Set<Float> prices = new HashSet<>();
|
|
|
180 |
prices.add(price);
|
|
|
181 |
return responseSender.ok(pricingService.getInsurancePrices(prices, ProfitMandiConstants.GADGET_COPS));
|
| 22244 |
ashik.ali |
182 |
}
|
| 23973 |
govind |
183 |
|
| 21985 |
kshitij.so |
184 |
@RequestMapping(value = "/get-order", method = RequestMethod.GET)
|
| 23973 |
govind |
185 |
public String getOrder(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId,
|
|
|
186 |
Model model) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
187 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
188 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 23638 |
amit.gupta |
189 |
List<FofoOrderItem> fofoLineItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 22927 |
ashik.ali |
190 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 23973 |
govind |
191 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
| 22927 |
ashik.ali |
192 |
customerAddress.setPhoneNumber(customer.getMobileNumber());
|
| 23973 |
govind |
193 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
194 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
195 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
|
|
196 |
.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
|
|
|
197 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
198 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23343 |
ashik.ali |
199 |
this.addInsuranceProvider(insurancePolicies);
|
| 24087 |
amit.gupta |
200 |
|
| 22927 |
ashik.ali |
201 |
model.addAttribute("fofoOrder", fofoOrder);
|
|
|
202 |
model.addAttribute("fofoLineItems", fofoLineItems);
|
|
|
203 |
model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
|
|
|
204 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
| 23548 |
ashik.ali |
205 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
| 23366 |
ashik.ali |
206 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
| 22927 |
ashik.ali |
207 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
208 |
return "order-details";
|
| 21985 |
kshitij.so |
209 |
}
|
| 23973 |
govind |
210 |
|
|
|
211 |
private Map<Integer, InsuranceProvider> toInsuranceProviderIdInsuranceProvider(
|
|
|
212 |
List<InsuranceProvider> insuranceProviders) {
|
| 23343 |
ashik.ali |
213 |
Map<Integer, InsuranceProvider> insuranceProviderIdInsuranceProviderMap = new HashMap<>();
|
| 23973 |
govind |
214 |
for (InsuranceProvider insuranceProvider : insuranceProviders) {
|
| 23343 |
ashik.ali |
215 |
insuranceProviderIdInsuranceProviderMap.put(insuranceProvider.getId(), insuranceProvider);
|
|
|
216 |
}
|
|
|
217 |
return insuranceProviderIdInsuranceProviderMap;
|
|
|
218 |
}
|
| 23973 |
govind |
219 |
|
|
|
220 |
private void addInsuranceProvider(List<InsurancePolicy> insurancePolicies) {
|
|
|
221 |
if (insurancePolicies.isEmpty()) {
|
| 23343 |
ashik.ali |
222 |
return;
|
|
|
223 |
}
|
|
|
224 |
Set<Integer> insuranceProviderIds = new HashSet<>();
|
| 23973 |
govind |
225 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| 23343 |
ashik.ali |
226 |
insuranceProviderIds.add(insurancePolicy.getProviderId());
|
|
|
227 |
}
|
|
|
228 |
LOGGER.info("insuranceProviderIds {}", insuranceProviderIds);
|
|
|
229 |
List<InsuranceProvider> insuranceProviders = insuranceProviderRepository.selectByIds(insuranceProviderIds);
|
| 23973 |
govind |
230 |
Map<Integer, InsuranceProvider> insuranceProviderIdInsuranceProviderMap = this
|
|
|
231 |
.toInsuranceProviderIdInsuranceProvider(insuranceProviders);
|
|
|
232 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
|
|
233 |
insurancePolicy
|
|
|
234 |
.setInsuranceProvider(insuranceProviderIdInsuranceProviderMap.get(insurancePolicy.getProviderId()));
|
| 23343 |
ashik.ali |
235 |
}
|
|
|
236 |
}
|
| 23973 |
govind |
237 |
|
| 22244 |
ashik.ali |
238 |
@RequestMapping(value = "/saleDetails", method = RequestMethod.GET)
|
| 23973 |
govind |
239 |
public String getSaleDetails(HttpServletRequest request,
|
|
|
240 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws Exception {
|
| 22927 |
ashik.ali |
241 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
242 |
|
| 22927 |
ashik.ali |
243 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 23654 |
amit.gupta |
244 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 22927 |
ashik.ali |
245 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 23973 |
govind |
246 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
247 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
248 |
|
|
|
249 |
// Added Migration info as we lost it.
|
|
|
250 |
if (paymentOptionTransactions == null || paymentOptionTransactions.size() == 0) {
|
| 23952 |
amit.gupta |
251 |
PaymentOptionTransaction pot = new PaymentOptionTransaction();
|
|
|
252 |
pot.setAmount(fofoOrder.getTotalAmount());
|
|
|
253 |
pot.setCreateTimestamp(fofoOrder.getCreateTimestamp());
|
| 23973 |
govind |
254 |
// Mark it paid through cash
|
| 23952 |
amit.gupta |
255 |
pot.setPaymentOptionId(1);
|
|
|
256 |
pot.setReferenceType(PaymentOptionReferenceType.ORDER);
|
|
|
257 |
fofoOrderPaymentOptionRepository.persist(pot);
|
|
|
258 |
paymentOptionTransactions.add(pot);
|
|
|
259 |
LOGGER.info("Added to get invoice");
|
|
|
260 |
}
|
| 23973 |
govind |
261 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
|
|
262 |
.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
|
|
|
263 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
264 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23343 |
ashik.ali |
265 |
this.addInsuranceProvider(insurancePolicies);
|
| 23973 |
govind |
266 |
Map<Integer, Item> itemsMap = fofoOrderItems.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> {
|
| 23638 |
amit.gupta |
267 |
try {
|
|
|
268 |
return itemRepository.selectById(x.getItemId());
|
|
|
269 |
} catch (ProfitMandiBusinessException e) {
|
|
|
270 |
// TODO Auto-generated catch block
|
|
|
271 |
return null;
|
|
|
272 |
}
|
|
|
273 |
}));
|
| 23973 |
govind |
274 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdLineItemMap = fofoOrderItems.stream()
|
|
|
275 |
.collect(Collectors.toMap(FofoOrderItem::getId, FofoOrderItem::getFofoLineItems));
|
| 23654 |
amit.gupta |
276 |
|
| 23973 |
govind |
277 |
Map<Integer, List<CustomerReturnItem>> foiIdCustomerReturnInventoryItemsMap = fofoOrderItems.stream()
|
|
|
278 |
.collect(Collectors.toMap(foi -> foi.getId(),
|
|
|
279 |
foi -> customerReturnItemRepository.selectAllByOrderItemId(foi.getId())));
|
| 23654 |
amit.gupta |
280 |
|
|
|
281 |
Map<Integer, Integer> inventoryItemBilledQtyMap = new HashMap<>();
|
| 23973 |
govind |
282 |
|
|
|
283 |
for (FofoOrderItem foi : fofoOrderItems) {
|
|
|
284 |
for (FofoLineItem fli : foi.getFofoLineItems()) {
|
| 23654 |
amit.gupta |
285 |
inventoryItemBilledQtyMap.put(fli.getInventoryItemId(), fli.getQuantity());
|
|
|
286 |
}
|
| 23973 |
govind |
287 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository
|
|
|
288 |
.selectAllByOrderItemId(foi.getId());
|
|
|
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("markDoa", this.markDoa(fofoOrder));
|
|
|
309 |
model.addAttribute("markDefective", this.markDefective(fofoOrder));
|
| 22927 |
ashik.ali |
310 |
return "sale-details";
|
| 22244 |
ashik.ali |
311 |
}
|
| 23973 |
govind |
312 |
|
| 23638 |
amit.gupta |
313 |
private boolean markDoa(FofoOrder fofoOrder) {
|
| 23973 |
govind |
314 |
return fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS).plusDays(90)
|
|
|
315 |
.isAfter(LocalDateTime.now().truncatedTo(ChronoUnit.DAYS));
|
| 23638 |
amit.gupta |
316 |
}
|
| 23973 |
govind |
317 |
|
| 23638 |
amit.gupta |
318 |
private boolean markDefective(FofoOrder fofoOrder) {
|
| 23973 |
govind |
319 |
return fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS).plusDays(180)
|
|
|
320 |
.isAfter(LocalDateTime.now().truncatedTo(ChronoUnit.DAYS));
|
|
|
321 |
|
| 23638 |
amit.gupta |
322 |
}
|
| 23973 |
govind |
323 |
|
| 23584 |
ashik.ali |
324 |
@RequestMapping(value = "/getSearchOrder")
|
| 23973 |
govind |
325 |
public String getSearchOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 23584 |
ashik.ali |
326 |
return "search-order";
|
|
|
327 |
}
|
| 23973 |
govind |
328 |
|
| 23584 |
ashik.ali |
329 |
@RequestMapping(value = "/customerDetails", method = RequestMethod.PUT)
|
| 23973 |
govind |
330 |
public String updateCustomerDetails(HttpServletRequest request, @RequestBody CustomCustomer customCustomer,
|
|
|
331 |
@RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER) String invoiceNumber, Model model)
|
|
|
332 |
throws ProfitMandiBusinessException {
|
|
|
333 |
|
| 23584 |
ashik.ali |
334 |
orderService.updateCustomerDetails(customCustomer, invoiceNumber);
|
| 23973 |
govind |
335 |
|
| 23584 |
ashik.ali |
336 |
return this.getSearchOrderDetails(request, invoiceNumber, model);
|
|
|
337 |
}
|
| 23973 |
govind |
338 |
|
| 23584 |
ashik.ali |
339 |
@RequestMapping(value = "/searchOrderDetails", method = RequestMethod.GET)
|
| 23973 |
govind |
340 |
public String getSearchOrderDetails(HttpServletRequest request,
|
|
|
341 |
@RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER) String invoiceNumber, Model model)
|
|
|
342 |
throws ProfitMandiBusinessException {
|
|
|
343 |
|
| 23584 |
ashik.ali |
344 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 23638 |
amit.gupta |
345 |
List<FofoOrderItem> fofoLineItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 23584 |
ashik.ali |
346 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
347 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 23973 |
govind |
348 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
349 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
350 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
|
|
351 |
.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
|
|
|
352 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
353 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23584 |
ashik.ali |
354 |
this.addInsuranceProvider(insurancePolicies);
|
|
|
355 |
model.addAttribute("fofoOrder", fofoOrder);
|
|
|
356 |
model.addAttribute("fofoLineItems", fofoLineItems);
|
|
|
357 |
model.addAttribute("customer", customer);
|
|
|
358 |
model.addAttribute("customerAddress", customerAddress);
|
|
|
359 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
|
|
360 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
|
|
361 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
362 |
model.addAttribute("stateNames", Utils.getAllStateNames());
|
|
|
363 |
return "search-order-details";
|
|
|
364 |
}
|
| 23973 |
govind |
365 |
|
|
|
366 |
private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap(
|
|
|
367 |
List<PaymentOptionTransaction> paymentOptionTransactions) {
|
| 23366 |
ashik.ali |
368 |
Set<Integer> paymentOptionIds = new HashSet<>();
|
| 23973 |
govind |
369 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
| 23548 |
ashik.ali |
370 |
paymentOptionIds.add(paymentOptionTransaction.getPaymentOptionId());
|
| 23366 |
ashik.ali |
371 |
}
|
|
|
372 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByIds(paymentOptionIds);
|
|
|
373 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = new HashMap<>();
|
| 23973 |
govind |
374 |
for (PaymentOption paymentOption : paymentOptions) {
|
| 23366 |
ashik.ali |
375 |
paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
|
|
|
376 |
}
|
|
|
377 |
return paymentOptionIdPaymentOptionMap;
|
|
|
378 |
}
|
| 23973 |
govind |
379 |
|
| 21985 |
kshitij.so |
380 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
| 23973 |
govind |
381 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest,
|
|
|
382 |
Model model) throws ProfitMandiBusinessException {
|
| 22064 |
ashik.ali |
383 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), createOrderRequest);
|
| 22927 |
ashik.ali |
384 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
385 |
|
| 23823 |
amit.gupta |
386 |
int fofoOrderId = orderService.createOrder(createOrderRequest, fofoDetails.getFofoId(), accessoriesDeals);
|
| 22280 |
ashik.ali |
387 |
LOGGER.info("Order has been created successfully...");
|
| 23973 |
govind |
388 |
return "redirect:/get-order/?orderId=" + fofoOrderId;
|
| 21612 |
ashik.ali |
389 |
}
|
| 23973 |
govind |
390 |
|
| 23638 |
amit.gupta |
391 |
@RequestMapping(value = "/order/bad_return", method = RequestMethod.POST)
|
| 23973 |
govind |
392 |
public ResponseEntity<?> badReturn(HttpServletRequest request, @RequestBody FoiBadReturnRequest foiBadReturnRequest,
|
|
|
393 |
Model model) throws ProfitMandiBusinessException {
|
| 23638 |
amit.gupta |
394 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), foiBadReturnRequest);
|
|
|
395 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23654 |
amit.gupta |
396 |
CustomerCreditNote custmoerCreditNote = orderService.badReturn(fofoDetails.getFofoId(), foiBadReturnRequest);
|
|
|
397 |
return responseSender.ok(custmoerCreditNote.getId());
|
| 23638 |
amit.gupta |
398 |
}
|
| 21985 |
kshitij.so |
399 |
|
| 21689 |
ashik.ali |
400 |
@RequestMapping(value = "/generateInvoice")
|
| 23973 |
govind |
401 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
|
|
402 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
|
|
403 |
LOGGER.info("Request received at url {} with params [{}={}] ", request.getRequestURI(),
|
|
|
404 |
ProfitMandiConstants.ORDER_ID, orderId);
|
| 22139 |
amit.gupta |
405 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23594 |
ashik.ali |
406 |
PdfModel pdfModel = null;
|
| 23973 |
govind |
407 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 23594 |
ashik.ali |
408 |
pdfModel = orderService.getInvoicePdfModel(orderId);
|
| 23973 |
govind |
409 |
} else {
|
| 23594 |
ashik.ali |
410 |
pdfModel = orderService.getInvoicePdfModel(fofoDetails.getFofoId(), orderId);
|
|
|
411 |
}
|
| 21689 |
ashik.ali |
412 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
413 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
|
|
414 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 23973 |
govind |
415 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
416 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
417 |
headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
|
|
418 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
419 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
420 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
421 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 21689 |
ashik.ali |
422 |
}
|
| 23973 |
govind |
423 |
|
| 22244 |
ashik.ali |
424 |
@RequestMapping(value = "/saleHistory")
|
| 23973 |
govind |
425 |
public String saleHistory(HttpServletRequest request,
|
|
|
426 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
427 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
428 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
429 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
430 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
431 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
432 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
433 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
434 |
|
|
|
435 |
Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue,
|
|
|
436 |
startTime, endTime, offset, limit);
|
| 23203 |
ashik.ali |
437 |
model.addAllAttributes(map);
|
| 23973 |
govind |
438 |
|
| 22244 |
ashik.ali |
439 |
return "sale-history";
|
|
|
440 |
}
|
| 23973 |
govind |
441 |
|
|
|
442 |
@RequestMapping(value = "/credit-note/{creditNoteId}")
|
|
|
443 |
public ResponseEntity<?> downloadCreditNote(HttpServletRequest request, @PathVariable int creditNoteId)
|
|
|
444 |
throws ProfitMandiBusinessException {
|
| 23654 |
amit.gupta |
445 |
CreditNotePdfModel creditNotePdfModel = orderService.getCreditNotePdfModel(creditNoteId);
|
|
|
446 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
447 |
PdfUtils.generateAndWriteCustomerCreditNotes(Arrays.asList(creditNotePdfModel), byteArrayOutputStream);
|
|
|
448 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 23973 |
govind |
449 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
450 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
451 |
headers.set("Content-disposition",
|
|
|
452 |
"inline; filename=invoice-" + creditNotePdfModel.getCreditNoteNumber() + ".pdf");
|
|
|
453 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
454 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
455 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
456 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 23654 |
amit.gupta |
457 |
}
|
| 23973 |
govind |
458 |
|
| 22291 |
ashik.ali |
459 |
@RequestMapping(value = "/getPaginatedSaleHistory")
|
| 23973 |
govind |
460 |
public String getSaleHistoryPaginated(HttpServletRequest request,
|
|
|
461 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
462 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
463 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
464 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
465 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
466 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
467 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
468 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
469 |
Map<String, Object> map = orderService.getSaleHistoryPaginated(loginDetails.getFofoId(), searchType,
|
|
|
470 |
searchValue, startTime, endTime, offset, limit);
|
| 23203 |
ashik.ali |
471 |
model.addAllAttributes(map);
|
| 23973 |
govind |
472 |
|
| 22291 |
ashik.ali |
473 |
return "sale-history-paginated";
|
|
|
474 |
}
|
|
|
475 |
|
| 21612 |
ashik.ali |
476 |
}
|