| 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;
|
| 24105 |
govind |
31 |
import org.springframework.web.bind.annotation.PutMapping;
|
| 21612 |
ashik.ali |
32 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
33 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
34 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21689 |
ashik.ali |
35 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21612 |
ashik.ali |
36 |
|
| 23203 |
ashik.ali |
37 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
| 21612 |
ashik.ali |
38 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21985 |
kshitij.so |
39 |
import com.spice.profitmandi.common.model.CartFofo;
|
| 22860 |
ashik.ali |
40 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
| 23654 |
amit.gupta |
41 |
import com.spice.profitmandi.common.model.CreditNotePdfModel;
|
| 23584 |
ashik.ali |
42 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
| 23638 |
amit.gupta |
43 |
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
|
| 24105 |
govind |
44 |
import com.spice.profitmandi.common.model.PaymentOptionTransactionModel;
|
| 22660 |
ashik.ali |
45 |
import com.spice.profitmandi.common.model.PdfModel;
|
| 22581 |
ashik.ali |
46 |
import com.spice.profitmandi.common.model.PriceModel;
|
| 21612 |
ashik.ali |
47 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21689 |
ashik.ali |
48 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 23638 |
amit.gupta |
49 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 22244 |
ashik.ali |
50 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 23638 |
amit.gupta |
51 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 22217 |
ashik.ali |
52 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
| 23343 |
ashik.ali |
53 |
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
|
| 23548 |
ashik.ali |
54 |
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
|
| 21728 |
ashik.ali |
55 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
|
|
56 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 23654 |
amit.gupta |
57 |
import com.spice.profitmandi.dao.entity.fofo.CustomerCreditNote;
|
|
|
58 |
import com.spice.profitmandi.dao.entity.fofo.CustomerReturnItem;
|
| 23638 |
amit.gupta |
59 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| 22927 |
ashik.ali |
60 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 22860 |
ashik.ali |
61 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 21728 |
ashik.ali |
62 |
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
|
| 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;
|
| 22860 |
ashik.ali |
73 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 21728 |
ashik.ali |
74 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 23366 |
ashik.ali |
75 |
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
|
| 21728 |
ashik.ali |
76 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 24440 |
amit.gupta |
77 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 23298 |
ashik.ali |
78 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 23798 |
amit.gupta |
79 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 24440 |
amit.gupta |
80 |
import com.spice.profitmandi.service.integrations.zest.MobileInsurancePlan;
|
|
|
81 |
import com.spice.profitmandi.service.integrations.zest.ZestService;
|
| 23366 |
ashik.ali |
82 |
import com.spice.profitmandi.service.order.OrderService;
|
| 22069 |
ashik.ali |
83 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 22139 |
amit.gupta |
84 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 22069 |
ashik.ali |
85 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 24105 |
govind |
86 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 21612 |
ashik.ali |
87 |
|
|
|
88 |
@Controller
|
| 23973 |
govind |
89 |
@Transactional(rollbackFor = Throwable.class)
|
| 21612 |
ashik.ali |
90 |
public class OrderController {
|
|
|
91 |
|
| 23568 |
govind |
92 |
private static final Logger LOGGER = LogManager.getLogger(OrderController.class);
|
| 21985 |
kshitij.so |
93 |
|
| 21612 |
ashik.ali |
94 |
@Autowired
|
| 22860 |
ashik.ali |
95 |
private CustomerRepository customerRepository;
|
| 23973 |
govind |
96 |
|
| 23821 |
amit.gupta |
97 |
private boolean accessoriesDeals = true;
|
| 21985 |
kshitij.so |
98 |
|
| 21612 |
ashik.ali |
99 |
@Autowired
|
| 23786 |
amit.gupta |
100 |
private RoleManager roleManager;
|
| 23973 |
govind |
101 |
|
| 23786 |
amit.gupta |
102 |
@Autowired
|
| 23654 |
amit.gupta |
103 |
private CustomerReturnItemRepository customerReturnItemRepository;
|
| 23973 |
govind |
104 |
|
| 23654 |
amit.gupta |
105 |
@Autowired
|
| 23638 |
amit.gupta |
106 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 21985 |
kshitij.so |
107 |
|
| 21612 |
ashik.ali |
108 |
@Autowired
|
| 22860 |
ashik.ali |
109 |
private PaymentOptionRepository paymentOptionRepository;
|
| 24440 |
amit.gupta |
110 |
|
|
|
111 |
@Autowired
|
|
|
112 |
private StateRepository stateRepository;
|
| 23973 |
govind |
113 |
|
| 23638 |
amit.gupta |
114 |
@Autowired
|
|
|
115 |
private ItemRepository itemRepository;
|
| 21985 |
kshitij.so |
116 |
|
| 21680 |
ashik.ali |
117 |
@Autowired
|
| 24105 |
govind |
118 |
private MVCResponseSender mvcResponseSender;
|
| 24440 |
amit.gupta |
119 |
|
|
|
120 |
@Autowired
|
|
|
121 |
private ZestService zestService;
|
| 24105 |
govind |
122 |
|
|
|
123 |
@Autowired
|
| 22860 |
ashik.ali |
124 |
private FofoOrderRepository fofoOrderRepository;
|
| 21985 |
kshitij.so |
125 |
|
| 21680 |
ashik.ali |
126 |
@Autowired
|
| 22860 |
ashik.ali |
127 |
private CustomerAddressRepository customerAddressRepository;
|
| 23973 |
govind |
128 |
|
| 22217 |
ashik.ali |
129 |
@Autowired
|
| 22860 |
ashik.ali |
130 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 23973 |
govind |
131 |
|
| 23343 |
ashik.ali |
132 |
@Autowired
|
|
|
133 |
private InsuranceProviderRepository insuranceProviderRepository;
|
| 21985 |
kshitij.so |
134 |
|
| 21896 |
ashik.ali |
135 |
@Autowired
|
| 22860 |
ashik.ali |
136 |
private CookiesProcessor cookiesProcessor;
|
| 23973 |
govind |
137 |
|
| 22069 |
ashik.ali |
138 |
@Autowired
|
| 22860 |
ashik.ali |
139 |
private PricingService pricingService;
|
| 23973 |
govind |
140 |
|
| 22354 |
ashik.ali |
141 |
@Autowired
|
| 22860 |
ashik.ali |
142 |
private OrderService orderService;
|
| 23973 |
govind |
143 |
|
| 23298 |
ashik.ali |
144 |
@Autowired
|
|
|
145 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 23973 |
govind |
146 |
|
| 22354 |
ashik.ali |
147 |
@Autowired
|
| 23298 |
ashik.ali |
148 |
private AddressRepository addressRepository;
|
| 23973 |
govind |
149 |
|
| 23298 |
ashik.ali |
150 |
@Autowired
|
| 23548 |
ashik.ali |
151 |
private PaymentOptionTransactionRepository fofoOrderPaymentOptionRepository;
|
| 23973 |
govind |
152 |
|
| 23366 |
ashik.ali |
153 |
@Autowired
|
|
|
154 |
private FofoPartnerPaymentOptionRepository fofoPartnerPaymentOptionRepository;
|
| 23973 |
govind |
155 |
|
| 23419 |
ashik.ali |
156 |
@Autowired
|
| 22860 |
ashik.ali |
157 |
private ResponseSender<?> responseSender;
|
| 23973 |
govind |
158 |
|
| 21985 |
kshitij.so |
159 |
@RequestMapping(value = "/order")
|
| 23973 |
govind |
160 |
public String orderIndex(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model)
|
|
|
161 |
throws ProfitMandiBusinessException {
|
|
|
162 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
163 |
;
|
|
|
164 |
|
| 23298 |
ashik.ali |
165 |
int addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(loginDetails.getFofoId());
|
|
|
166 |
Address address = addressRepository.selectById(addressId);
|
| 23973 |
govind |
167 |
|
| 22860 |
ashik.ali |
168 |
List<CartFofo> cartItems = orderService.cartCheckout(cartData);
|
|
|
169 |
Set<Integer> itemIds = new HashSet<>();
|
| 23973 |
govind |
170 |
for (CartFofo cartFofo : cartItems) {
|
| 22860 |
ashik.ali |
171 |
itemIds.add(cartFofo.getItemId());
|
| 21985 |
kshitij.so |
172 |
}
|
| 23973 |
govind |
173 |
Map<Integer, PriceModel> mopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds,
|
|
|
174 |
loginDetails.getFofoId());
|
|
|
175 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository
|
|
|
176 |
.selectPaymentOptionIdsByFofoId(loginDetails.getFofoId());
|
| 23366 |
ashik.ali |
177 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds));
|
| 22860 |
ashik.ali |
178 |
LOGGER.info("mopPriceMap {}", mopPriceMap);
|
| 24440 |
amit.gupta |
179 |
model.addAttribute("stateNames", stateRepository.selectAll().stream().map(x->x.getName()).collect(Collectors.toList()));
|
| 23298 |
ashik.ali |
180 |
model.addAttribute("retailerStateName", address.getState());
|
| 24440 |
amit.gupta |
181 |
model.addAttribute("cartItems", cartItems);
|
| 22860 |
ashik.ali |
182 |
model.addAttribute("mopPriceMap", mopPriceMap);
|
| 23366 |
ashik.ali |
183 |
model.addAttribute("paymentOptions", paymentOptions);
|
| 23821 |
amit.gupta |
184 |
model.addAttribute("accessoriesDeals", accessoriesDeals);
|
| 22860 |
ashik.ali |
185 |
return "order-index";
|
| 21985 |
kshitij.so |
186 |
}
|
| 23973 |
govind |
187 |
|
| 24440 |
amit.gupta |
188 |
@RequestMapping(value = "/checkplans", method = RequestMethod.GET)
|
|
|
189 |
public String getInsurancePrices(HttpServletRequest request,
|
|
|
190 |
@RequestParam float price, Model model) throws ProfitMandiBusinessException {
|
| 22244 |
ashik.ali |
191 |
LOGGER.info("Request received at url : {}", request.getRequestURI());
|
| 24440 |
amit.gupta |
192 |
|
|
|
193 |
try {
|
|
|
194 |
String response = mvcResponseSender.createResponseString(this.getPlans(price));
|
|
|
195 |
model.addAttribute("response", response);
|
|
|
196 |
} catch (Exception e) {
|
|
|
197 |
// TODO Auto-generated catch block
|
|
|
198 |
e.printStackTrace();
|
|
|
199 |
throw new ProfitMandiBusinessException("Plans", "Plans API", "Error formatting insurance plans");
|
|
|
200 |
}
|
|
|
201 |
|
|
|
202 |
return "response";
|
| 22244 |
ashik.ali |
203 |
}
|
| 23973 |
govind |
204 |
|
| 21985 |
kshitij.so |
205 |
@RequestMapping(value = "/get-order", method = RequestMethod.GET)
|
| 23973 |
govind |
206 |
public String getOrder(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId,
|
|
|
207 |
Model model) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
208 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
209 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 23638 |
amit.gupta |
210 |
List<FofoOrderItem> fofoLineItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 22927 |
ashik.ali |
211 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 23973 |
govind |
212 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
| 22927 |
ashik.ali |
213 |
customerAddress.setPhoneNumber(customer.getMobileNumber());
|
| 23973 |
govind |
214 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
215 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
216 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
|
|
217 |
.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
|
|
|
218 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
219 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23343 |
ashik.ali |
220 |
this.addInsuranceProvider(insurancePolicies);
|
| 24087 |
amit.gupta |
221 |
|
| 22927 |
ashik.ali |
222 |
model.addAttribute("fofoOrder", fofoOrder);
|
|
|
223 |
model.addAttribute("fofoLineItems", fofoLineItems);
|
|
|
224 |
model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
|
|
|
225 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
| 23548 |
ashik.ali |
226 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
| 23366 |
ashik.ali |
227 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
| 22927 |
ashik.ali |
228 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
229 |
return "order-details";
|
| 21985 |
kshitij.so |
230 |
}
|
| 23973 |
govind |
231 |
|
|
|
232 |
private Map<Integer, InsuranceProvider> toInsuranceProviderIdInsuranceProvider(
|
|
|
233 |
List<InsuranceProvider> insuranceProviders) {
|
| 23343 |
ashik.ali |
234 |
Map<Integer, InsuranceProvider> insuranceProviderIdInsuranceProviderMap = new HashMap<>();
|
| 23973 |
govind |
235 |
for (InsuranceProvider insuranceProvider : insuranceProviders) {
|
| 23343 |
ashik.ali |
236 |
insuranceProviderIdInsuranceProviderMap.put(insuranceProvider.getId(), insuranceProvider);
|
|
|
237 |
}
|
|
|
238 |
return insuranceProviderIdInsuranceProviderMap;
|
|
|
239 |
}
|
| 23973 |
govind |
240 |
|
|
|
241 |
private void addInsuranceProvider(List<InsurancePolicy> insurancePolicies) {
|
|
|
242 |
if (insurancePolicies.isEmpty()) {
|
| 23343 |
ashik.ali |
243 |
return;
|
|
|
244 |
}
|
|
|
245 |
Set<Integer> insuranceProviderIds = new HashSet<>();
|
| 23973 |
govind |
246 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| 23343 |
ashik.ali |
247 |
insuranceProviderIds.add(insurancePolicy.getProviderId());
|
|
|
248 |
}
|
|
|
249 |
LOGGER.info("insuranceProviderIds {}", insuranceProviderIds);
|
|
|
250 |
List<InsuranceProvider> insuranceProviders = insuranceProviderRepository.selectByIds(insuranceProviderIds);
|
| 23973 |
govind |
251 |
Map<Integer, InsuranceProvider> insuranceProviderIdInsuranceProviderMap = this
|
|
|
252 |
.toInsuranceProviderIdInsuranceProvider(insuranceProviders);
|
|
|
253 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
|
|
254 |
insurancePolicy
|
|
|
255 |
.setInsuranceProvider(insuranceProviderIdInsuranceProviderMap.get(insurancePolicy.getProviderId()));
|
| 23343 |
ashik.ali |
256 |
}
|
|
|
257 |
}
|
| 23973 |
govind |
258 |
|
| 22244 |
ashik.ali |
259 |
@RequestMapping(value = "/saleDetails", method = RequestMethod.GET)
|
| 23973 |
govind |
260 |
public String getSaleDetails(HttpServletRequest request,
|
|
|
261 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws Exception {
|
| 22927 |
ashik.ali |
262 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
263 |
|
| 22927 |
ashik.ali |
264 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 23654 |
amit.gupta |
265 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 22927 |
ashik.ali |
266 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 23973 |
govind |
267 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
268 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
269 |
|
|
|
270 |
// Added Migration info as we lost it.
|
|
|
271 |
if (paymentOptionTransactions == null || paymentOptionTransactions.size() == 0) {
|
| 23952 |
amit.gupta |
272 |
PaymentOptionTransaction pot = new PaymentOptionTransaction();
|
|
|
273 |
pot.setAmount(fofoOrder.getTotalAmount());
|
|
|
274 |
pot.setCreateTimestamp(fofoOrder.getCreateTimestamp());
|
| 23973 |
govind |
275 |
// Mark it paid through cash
|
| 23952 |
amit.gupta |
276 |
pot.setPaymentOptionId(1);
|
|
|
277 |
pot.setReferenceType(PaymentOptionReferenceType.ORDER);
|
|
|
278 |
fofoOrderPaymentOptionRepository.persist(pot);
|
|
|
279 |
paymentOptionTransactions.add(pot);
|
|
|
280 |
LOGGER.info("Added to get invoice");
|
|
|
281 |
}
|
| 23973 |
govind |
282 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
|
|
283 |
.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
|
|
|
284 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
285 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23343 |
ashik.ali |
286 |
this.addInsuranceProvider(insurancePolicies);
|
| 23973 |
govind |
287 |
Map<Integer, Item> itemsMap = fofoOrderItems.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> {
|
| 23638 |
amit.gupta |
288 |
try {
|
|
|
289 |
return itemRepository.selectById(x.getItemId());
|
|
|
290 |
} catch (ProfitMandiBusinessException e) {
|
|
|
291 |
// TODO Auto-generated catch block
|
|
|
292 |
return null;
|
|
|
293 |
}
|
|
|
294 |
}));
|
| 23973 |
govind |
295 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdLineItemMap = fofoOrderItems.stream()
|
|
|
296 |
.collect(Collectors.toMap(FofoOrderItem::getId, FofoOrderItem::getFofoLineItems));
|
| 23654 |
amit.gupta |
297 |
|
| 23973 |
govind |
298 |
Map<Integer, List<CustomerReturnItem>> foiIdCustomerReturnInventoryItemsMap = fofoOrderItems.stream()
|
|
|
299 |
.collect(Collectors.toMap(foi -> foi.getId(),
|
|
|
300 |
foi -> customerReturnItemRepository.selectAllByOrderItemId(foi.getId())));
|
| 23654 |
amit.gupta |
301 |
|
|
|
302 |
Map<Integer, Integer> inventoryItemBilledQtyMap = new HashMap<>();
|
| 23973 |
govind |
303 |
|
|
|
304 |
for (FofoOrderItem foi : fofoOrderItems) {
|
|
|
305 |
for (FofoLineItem fli : foi.getFofoLineItems()) {
|
| 23654 |
amit.gupta |
306 |
inventoryItemBilledQtyMap.put(fli.getInventoryItemId(), fli.getQuantity());
|
|
|
307 |
}
|
| 23973 |
govind |
308 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository
|
|
|
309 |
.selectAllByOrderItemId(foi.getId());
|
| 24094 |
amit.gupta |
310 |
this.markDoa(fofoOrder, foi);
|
| 23973 |
govind |
311 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
|
|
312 |
inventoryItemBilledQtyMap.put(customerReturnItem.getInventoryItemId(),
|
|
|
313 |
inventoryItemBilledQtyMap.get(customerReturnItem.getInventoryItemId()) - 1);
|
| 23654 |
amit.gupta |
314 |
}
|
|
|
315 |
}
|
| 23973 |
govind |
316 |
|
| 23654 |
amit.gupta |
317 |
LOGGER.info("fofoOrderItemIdLineItemMap {}", fofoOrderItemIdLineItemMap);
|
| 22927 |
ashik.ali |
318 |
model.addAttribute("fofoOrder", fofoOrder);
|
| 23638 |
amit.gupta |
319 |
model.addAttribute("itemsMap", itemsMap);
|
| 23654 |
amit.gupta |
320 |
model.addAttribute("fofoOrderItemIdLineItemsMap", StringUtils.toString(fofoOrderItemIdLineItemMap));
|
| 23973 |
govind |
321 |
model.addAttribute("foiIdCustomerReturnInventoryItemsMap",
|
|
|
322 |
StringUtils.toString(foiIdCustomerReturnInventoryItemsMap));
|
| 23654 |
amit.gupta |
323 |
model.addAttribute("fofoOrderItems", fofoOrderItems);
|
|
|
324 |
model.addAttribute("inventoryItemBilledQtyMap", StringUtils.toString(inventoryItemBilledQtyMap));
|
| 22927 |
ashik.ali |
325 |
model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
|
|
|
326 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
| 23548 |
ashik.ali |
327 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
| 23366 |
ashik.ali |
328 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
| 22927 |
ashik.ali |
329 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
| 23638 |
amit.gupta |
330 |
model.addAttribute("markDefective", this.markDefective(fofoOrder));
|
| 22927 |
ashik.ali |
331 |
return "sale-details";
|
| 22244 |
ashik.ali |
332 |
}
|
| 23973 |
govind |
333 |
|
| 24094 |
amit.gupta |
334 |
private void markDoa(FofoOrder fofoOrder, FofoOrderItem foi) {
|
|
|
335 |
if (foi.getBrand().equals("Nokia") && foi.getCost() < 4990) {
|
|
|
336 |
foi.setDoa(true);
|
|
|
337 |
}
|
|
|
338 |
LocalDateTime buyDate = fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS);
|
|
|
339 |
LocalDateTime curDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
|
|
340 |
if (buyDate.isAfter(curDate.minusDays(45))) {
|
|
|
341 |
foi.setDoa(true);
|
|
|
342 |
} else
|
|
|
343 |
foi.setDoa(
|
|
|
344 |
foi.getBrand().equals("Nokia") && foi.getCost() < 4990 && buyDate.isAfter(curDate.minusYears(1)));
|
| 23638 |
amit.gupta |
345 |
}
|
| 23973 |
govind |
346 |
|
| 23638 |
amit.gupta |
347 |
private boolean markDefective(FofoOrder fofoOrder) {
|
| 23973 |
govind |
348 |
return fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS).plusDays(180)
|
|
|
349 |
.isAfter(LocalDateTime.now().truncatedTo(ChronoUnit.DAYS));
|
|
|
350 |
|
| 23638 |
amit.gupta |
351 |
}
|
| 23973 |
govind |
352 |
|
| 23584 |
ashik.ali |
353 |
@RequestMapping(value = "/getSearchOrder")
|
| 23973 |
govind |
354 |
public String getSearchOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 23584 |
ashik.ali |
355 |
return "search-order";
|
|
|
356 |
}
|
| 23973 |
govind |
357 |
|
| 23584 |
ashik.ali |
358 |
@RequestMapping(value = "/customerDetails", method = RequestMethod.PUT)
|
| 23973 |
govind |
359 |
public String updateCustomerDetails(HttpServletRequest request, @RequestBody CustomCustomer customCustomer,
|
|
|
360 |
@RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER) String invoiceNumber, Model model)
|
| 24281 |
amit.gupta |
361 |
throws Exception {
|
| 23973 |
govind |
362 |
|
| 23584 |
ashik.ali |
363 |
orderService.updateCustomerDetails(customCustomer, invoiceNumber);
|
|
|
364 |
return this.getSearchOrderDetails(request, invoiceNumber, model);
|
|
|
365 |
}
|
| 23973 |
govind |
366 |
|
| 23584 |
ashik.ali |
367 |
@RequestMapping(value = "/searchOrderDetails", method = RequestMethod.GET)
|
| 23973 |
govind |
368 |
public String getSearchOrderDetails(HttpServletRequest request,
|
|
|
369 |
@RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER) String invoiceNumber, Model model)
|
| 24281 |
amit.gupta |
370 |
throws Exception {
|
| 23973 |
govind |
371 |
|
| 23584 |
ashik.ali |
372 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 24271 |
amit.gupta |
373 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 23584 |
ashik.ali |
374 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
375 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 24105 |
govind |
376 |
List<Integer> fofoPartnerPaymentOptions = fofoPartnerPaymentOptionRepository
|
|
|
377 |
.selectPaymentOptionIdsByFofoId(fofoOrder.getFofoId());
|
| 24276 |
amit.gupta |
378 |
|
|
|
379 |
Map<Integer, Item> itemsMap = fofoOrderItems.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> {
|
|
|
380 |
try {
|
|
|
381 |
return itemRepository.selectById(x.getItemId());
|
|
|
382 |
} catch (ProfitMandiBusinessException e) {
|
|
|
383 |
// TODO Auto-generated catch block
|
|
|
384 |
return null;
|
|
|
385 |
}
|
|
|
386 |
}));
|
| 24105 |
govind |
387 |
LOGGER.info("fofoPartnerPaymentOptions" + fofoPartnerPaymentOptions);
|
| 23973 |
govind |
388 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
389 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
| 24105 |
govind |
390 |
LOGGER.info("paymentOptionTransactions" + paymentOptionTransactions);
|
| 23973 |
govind |
391 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
| 24105 |
govind |
392 |
.paymentOptionIdPaymentOptionMapUsingPaymentOptions(fofoPartnerPaymentOptions);
|
|
|
393 |
Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = this
|
|
|
394 |
.paymentOptionIdPaymentOptionTransactionMap(paymentOptionTransactions);
|
|
|
395 |
LOGGER.info("paymentOptionIdPaymentOptionTransactionMap" + paymentOptionIdPaymentOptionTransactionMap.keySet());
|
| 23973 |
govind |
396 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
397 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23584 |
ashik.ali |
398 |
this.addInsuranceProvider(insurancePolicies);
|
|
|
399 |
model.addAttribute("fofoOrder", fofoOrder);
|
| 24271 |
amit.gupta |
400 |
for(FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
|
|
401 |
fofoOrderItem.setDoa(true);
|
|
|
402 |
}
|
| 24281 |
amit.gupta |
403 |
|
|
|
404 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdLineItemMap = fofoOrderItems.stream()
|
|
|
405 |
.collect(Collectors.toMap(FofoOrderItem::getId, FofoOrderItem::getFofoLineItems));
|
|
|
406 |
|
|
|
407 |
Map<Integer, List<CustomerReturnItem>> foiIdCustomerReturnInventoryItemsMap = fofoOrderItems.stream()
|
|
|
408 |
.collect(Collectors.toMap(foi -> foi.getId(),
|
|
|
409 |
foi -> customerReturnItemRepository.selectAllByOrderItemId(foi.getId())));
|
|
|
410 |
|
|
|
411 |
Map<Integer, Integer> inventoryItemBilledQtyMap = new HashMap<>();
|
|
|
412 |
|
|
|
413 |
for (FofoOrderItem foi : fofoOrderItems) {
|
|
|
414 |
for (FofoLineItem fli : foi.getFofoLineItems()) {
|
|
|
415 |
inventoryItemBilledQtyMap.put(fli.getInventoryItemId(), fli.getQuantity());
|
|
|
416 |
}
|
|
|
417 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository
|
|
|
418 |
.selectAllByOrderItemId(foi.getId());
|
|
|
419 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
|
|
420 |
inventoryItemBilledQtyMap.put(customerReturnItem.getInventoryItemId(),
|
|
|
421 |
inventoryItemBilledQtyMap.get(customerReturnItem.getInventoryItemId()) - 1);
|
|
|
422 |
}
|
|
|
423 |
}
|
|
|
424 |
model.addAttribute("foiIdCustomerReturnInventoryItemsMap",
|
|
|
425 |
StringUtils.toString(foiIdCustomerReturnInventoryItemsMap));
|
| 24271 |
amit.gupta |
426 |
model.addAttribute("fofoOrderItems", fofoOrderItems);
|
| 24281 |
amit.gupta |
427 |
model.addAttribute("inventoryItemBilledQtyMap", StringUtils.toString(inventoryItemBilledQtyMap));
|
|
|
428 |
model.addAttribute("fofoOrderItemIdLineItemsMap", StringUtils.toString(fofoOrderItemIdLineItemMap));
|
| 24276 |
amit.gupta |
429 |
model.addAttribute("itemsMap", itemsMap);
|
| 24271 |
amit.gupta |
430 |
model.addAttribute("markDefective", true);
|
| 23584 |
ashik.ali |
431 |
model.addAttribute("customer", customer);
|
|
|
432 |
model.addAttribute("customerAddress", customerAddress);
|
|
|
433 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
|
|
434 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
| 24105 |
govind |
435 |
model.addAttribute("paymentOptionIdPaymentOptionTransactionMap", paymentOptionIdPaymentOptionTransactionMap);
|
| 23584 |
ashik.ali |
436 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
| 24105 |
govind |
437 |
model.addAttribute("fofoPartnerPaymentOptions", fofoPartnerPaymentOptions);
|
|
|
438 |
model.addAttribute("totalNumberOfPaymentOptionId", fofoPartnerPaymentOptions.size());
|
| 24440 |
amit.gupta |
439 |
model.addAttribute("stateNames", stateRepository.selectAll().stream().map(x->x.getName()).collect(Collectors.toList()));
|
| 23584 |
ashik.ali |
440 |
return "search-order-details";
|
|
|
441 |
}
|
| 23973 |
govind |
442 |
|
|
|
443 |
private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap(
|
|
|
444 |
List<PaymentOptionTransaction> paymentOptionTransactions) {
|
| 23366 |
ashik.ali |
445 |
Set<Integer> paymentOptionIds = new HashSet<>();
|
| 23973 |
govind |
446 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
| 23548 |
ashik.ali |
447 |
paymentOptionIds.add(paymentOptionTransaction.getPaymentOptionId());
|
| 23366 |
ashik.ali |
448 |
}
|
|
|
449 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByIds(paymentOptionIds);
|
|
|
450 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = new HashMap<>();
|
| 23973 |
govind |
451 |
for (PaymentOption paymentOption : paymentOptions) {
|
| 23366 |
ashik.ali |
452 |
paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
|
|
|
453 |
}
|
|
|
454 |
return paymentOptionIdPaymentOptionMap;
|
|
|
455 |
}
|
| 23973 |
govind |
456 |
|
| 24105 |
govind |
457 |
private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMapUsingPaymentOptions(
|
|
|
458 |
List<Integer> fofoPartnerPaymentOptions) {
|
|
|
459 |
List<PaymentOption> paymentOptions = paymentOptionRepository
|
|
|
460 |
.selectByIds(new HashSet<>(fofoPartnerPaymentOptions));
|
|
|
461 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = new HashMap<>();
|
|
|
462 |
for (PaymentOption paymentOption : paymentOptions) {
|
|
|
463 |
paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
|
|
|
464 |
}
|
|
|
465 |
return paymentOptionIdPaymentOptionMap;
|
|
|
466 |
}
|
|
|
467 |
|
|
|
468 |
private Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap(
|
|
|
469 |
List<PaymentOptionTransaction> paymentOptionTransactions) {
|
|
|
470 |
Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = new HashMap<>();
|
|
|
471 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
|
|
472 |
paymentOptionIdPaymentOptionTransactionMap.put(paymentOptionTransaction.getPaymentOptionId(),
|
|
|
473 |
paymentOptionTransaction);
|
|
|
474 |
}
|
|
|
475 |
return paymentOptionIdPaymentOptionTransactionMap;
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
|
|
|
479 |
|
| 21985 |
kshitij.so |
480 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
| 23973 |
govind |
481 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest,
|
|
|
482 |
Model model) throws ProfitMandiBusinessException {
|
| 22064 |
ashik.ali |
483 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), createOrderRequest);
|
| 22927 |
ashik.ali |
484 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
485 |
|
| 23823 |
amit.gupta |
486 |
int fofoOrderId = orderService.createOrder(createOrderRequest, fofoDetails.getFofoId(), accessoriesDeals);
|
| 22280 |
ashik.ali |
487 |
LOGGER.info("Order has been created successfully...");
|
| 23973 |
govind |
488 |
return "redirect:/get-order/?orderId=" + fofoOrderId;
|
| 21612 |
ashik.ali |
489 |
}
|
| 23973 |
govind |
490 |
|
| 23638 |
amit.gupta |
491 |
@RequestMapping(value = "/order/bad_return", method = RequestMethod.POST)
|
| 23973 |
govind |
492 |
public ResponseEntity<?> badReturn(HttpServletRequest request, @RequestBody FoiBadReturnRequest foiBadReturnRequest,
|
|
|
493 |
Model model) throws ProfitMandiBusinessException {
|
| 23638 |
amit.gupta |
494 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), foiBadReturnRequest);
|
|
|
495 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 24282 |
amit.gupta |
496 |
CustomerCreditNote custmoerCreditNote;
|
|
|
497 |
if(roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
|
|
498 |
FofoOrderItem foi = fofoOrderItemRepository.selectById(foiBadReturnRequest.getFofoOrderItemId());
|
|
|
499 |
FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
|
|
|
500 |
custmoerCreditNote = orderService.badReturn(fo.getFofoId(), foiBadReturnRequest);
|
|
|
501 |
} else {
|
|
|
502 |
custmoerCreditNote = orderService.badReturn(fofoDetails.getFofoId(), foiBadReturnRequest);
|
|
|
503 |
}
|
| 23654 |
amit.gupta |
504 |
return responseSender.ok(custmoerCreditNote.getId());
|
| 23638 |
amit.gupta |
505 |
}
|
| 21985 |
kshitij.so |
506 |
|
| 21689 |
ashik.ali |
507 |
@RequestMapping(value = "/generateInvoice")
|
| 23973 |
govind |
508 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
|
|
509 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
|
|
510 |
LOGGER.info("Request received at url {} with params [{}={}] ", request.getRequestURI(),
|
|
|
511 |
ProfitMandiConstants.ORDER_ID, orderId);
|
| 22139 |
amit.gupta |
512 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23594 |
ashik.ali |
513 |
PdfModel pdfModel = null;
|
| 23973 |
govind |
514 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 23594 |
ashik.ali |
515 |
pdfModel = orderService.getInvoicePdfModel(orderId);
|
| 23973 |
govind |
516 |
} else {
|
| 23594 |
ashik.ali |
517 |
pdfModel = orderService.getInvoicePdfModel(fofoDetails.getFofoId(), orderId);
|
|
|
518 |
}
|
| 21689 |
ashik.ali |
519 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
520 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
|
|
521 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 23973 |
govind |
522 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
523 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
524 |
headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
|
|
525 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
526 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
527 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
528 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 21689 |
ashik.ali |
529 |
}
|
| 23973 |
govind |
530 |
|
| 22244 |
ashik.ali |
531 |
@RequestMapping(value = "/saleHistory")
|
| 23973 |
govind |
532 |
public String saleHistory(HttpServletRequest request,
|
|
|
533 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
534 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
535 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
536 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
537 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
538 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
539 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
540 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
541 |
|
|
|
542 |
Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue,
|
|
|
543 |
startTime, endTime, offset, limit);
|
| 23203 |
ashik.ali |
544 |
model.addAllAttributes(map);
|
| 23973 |
govind |
545 |
|
| 22244 |
ashik.ali |
546 |
return "sale-history";
|
|
|
547 |
}
|
| 23973 |
govind |
548 |
|
|
|
549 |
@RequestMapping(value = "/credit-note/{creditNoteId}")
|
|
|
550 |
public ResponseEntity<?> downloadCreditNote(HttpServletRequest request, @PathVariable int creditNoteId)
|
|
|
551 |
throws ProfitMandiBusinessException {
|
| 23654 |
amit.gupta |
552 |
CreditNotePdfModel creditNotePdfModel = orderService.getCreditNotePdfModel(creditNoteId);
|
|
|
553 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
554 |
PdfUtils.generateAndWriteCustomerCreditNotes(Arrays.asList(creditNotePdfModel), byteArrayOutputStream);
|
|
|
555 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 23973 |
govind |
556 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
557 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
558 |
headers.set("Content-disposition",
|
|
|
559 |
"inline; filename=invoice-" + creditNotePdfModel.getCreditNoteNumber() + ".pdf");
|
|
|
560 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
561 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
562 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
563 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 23654 |
amit.gupta |
564 |
}
|
| 23973 |
govind |
565 |
|
| 22291 |
ashik.ali |
566 |
@RequestMapping(value = "/getPaginatedSaleHistory")
|
| 23973 |
govind |
567 |
public String getSaleHistoryPaginated(HttpServletRequest request,
|
|
|
568 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
569 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
570 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
571 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
572 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
573 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
574 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
575 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
576 |
Map<String, Object> map = orderService.getSaleHistoryPaginated(loginDetails.getFofoId(), searchType,
|
|
|
577 |
searchValue, startTime, endTime, offset, limit);
|
| 23203 |
ashik.ali |
578 |
model.addAllAttributes(map);
|
| 23973 |
govind |
579 |
|
| 22291 |
ashik.ali |
580 |
return "sale-history-paginated";
|
|
|
581 |
}
|
|
|
582 |
|
| 24105 |
govind |
583 |
@PutMapping(value = "/updatePaymentTransaction")
|
|
|
584 |
public String updateTransactionDetails(HttpServletRequest request, @RequestParam String referenceType,
|
|
|
585 |
@RequestParam int fofoId, @RequestParam int referenceId,
|
|
|
586 |
@RequestBody List<PaymentOptionTransactionModel> paymentOptionTransactionModels, Model model)
|
|
|
587 |
throws Exception {
|
|
|
588 |
float amount = 0;
|
|
|
589 |
LOGGER.info(paymentOptionTransactionModels);
|
|
|
590 |
|
|
|
591 |
for (PaymentOptionTransactionModel paymentOptionTransactionModel : paymentOptionTransactionModels) {
|
|
|
592 |
amount = amount + paymentOptionTransactionModel.getAmount();
|
|
|
593 |
}
|
|
|
594 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoId, referenceId);
|
|
|
595 |
LOGGER.info("FofoOrder amount" + fofoOrder.getTotalAmount() + "amount" + amount);
|
|
|
596 |
if (amount == fofoOrder.getTotalAmount()) {
|
|
|
597 |
if (paymentOptionTransactionModels.size() > 0) {
|
|
|
598 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
599 |
.selectByReferenceIdAndType(referenceId, PaymentOptionReferenceType.ORDER);
|
|
|
600 |
Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = this
|
|
|
601 |
.paymentOptionIdPaymentOptionTransactionMap(paymentOptionTransactions);
|
|
|
602 |
LOGGER.info("paymentOptionIdPaymentOptionTransactionMap"
|
|
|
603 |
+ paymentOptionIdPaymentOptionTransactionMap.keySet());
|
|
|
604 |
for (PaymentOptionTransactionModel paymentOptionTransactionModel : paymentOptionTransactionModels) {
|
|
|
605 |
if (paymentOptionIdPaymentOptionTransactionMap
|
|
|
606 |
.containsKey(paymentOptionTransactionModel.getPaymentOptionId())) {
|
|
|
607 |
|
|
|
608 |
PaymentOptionTransaction paymentOptionTransaction = paymentOptionIdPaymentOptionTransactionMap
|
|
|
609 |
.get(paymentOptionTransactionModel.getPaymentOptionId());
|
|
|
610 |
|
|
|
611 |
if (paymentOptionTransactionModel.getAmount() == 0) {
|
|
|
612 |
fofoOrderPaymentOptionRepository.delete(paymentOptionTransaction);
|
|
|
613 |
LOGGER.info("deleted successfully");
|
|
|
614 |
} else {
|
|
|
615 |
|
|
|
616 |
paymentOptionTransaction.setAmount(paymentOptionTransactionModel.getAmount());
|
|
|
617 |
fofoOrderPaymentOptionRepository.persist(paymentOptionTransaction);
|
|
|
618 |
LOGGER.info("updated successfully");
|
|
|
619 |
|
|
|
620 |
}
|
|
|
621 |
} else {
|
|
|
622 |
if (paymentOptionTransactionModel.getAmount() > 0) {
|
|
|
623 |
PaymentOptionTransaction paymentOptionTransaction = new PaymentOptionTransaction();
|
|
|
624 |
paymentOptionTransaction.setReferenceId(referenceId);
|
|
|
625 |
paymentOptionTransaction.setReferenceType(PaymentOptionReferenceType.ORDER);
|
|
|
626 |
paymentOptionTransaction
|
|
|
627 |
.setPaymentOptionId(paymentOptionTransactionModel.getPaymentOptionId());
|
|
|
628 |
paymentOptionTransaction.setAmount(paymentOptionTransactionModel.getAmount());
|
|
|
629 |
paymentOptionTransaction.setFofoId(fofoId);
|
| 24167 |
amit.gupta |
630 |
paymentOptionTransaction.setCreateTimestamp(fofoOrder.getCreateTimestamp());
|
| 24105 |
govind |
631 |
fofoOrderPaymentOptionRepository.persist(paymentOptionTransaction);
|
|
|
632 |
LOGGER.info("inserted successfully");
|
|
|
633 |
}
|
|
|
634 |
}
|
|
|
635 |
|
|
|
636 |
}
|
|
|
637 |
|
|
|
638 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
639 |
}
|
|
|
640 |
} else {
|
|
|
641 |
throw new ProfitMandiBusinessException("Amount", amount, "Sum of amount is not equal to total amount");
|
|
|
642 |
}
|
|
|
643 |
|
|
|
644 |
return "response";
|
|
|
645 |
}
|
| 24440 |
amit.gupta |
646 |
|
|
|
647 |
|
|
|
648 |
|
|
|
649 |
private Map<String, List<MobileInsurancePlan>> getPlans(float sellingPrice) throws ProfitMandiBusinessException {
|
|
|
650 |
Map<String, List<MobileInsurancePlan>> productDurationPlans = zestService.getAllPlansByProductAndDuration();
|
|
|
651 |
Map<String, List<MobileInsurancePlan>> returnPlans = new HashMap<>();
|
|
|
652 |
productDurationPlans.entrySet().stream().forEach(m -> {
|
|
|
653 |
returnPlans.put(m.getKey(), m.getValue().stream().filter(x -> {
|
|
|
654 |
return Float.parseFloat(x.getMaxPrice()) >= sellingPrice
|
|
|
655 |
&& Float.parseFloat(x.getMinPrice()) <= sellingPrice;
|
|
|
656 |
}).collect(Collectors.toList()));
|
|
|
657 |
});
|
|
|
658 |
return returnPlans;
|
|
|
659 |
}
|
| 21612 |
ashik.ali |
660 |
}
|