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