| 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;
|
| 24880 |
govind |
31 |
import org.springframework.web.bind.annotation.GetMapping;
|
| 23654 |
amit.gupta |
32 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 24105 |
govind |
33 |
import org.springframework.web.bind.annotation.PutMapping;
|
| 21612 |
ashik.ali |
34 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
35 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
36 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21689 |
ashik.ali |
37 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21612 |
ashik.ali |
38 |
|
| 26817 |
amit.gupta |
39 |
import com.google.gson.Gson;
|
| 23203 |
ashik.ali |
40 |
import com.spice.profitmandi.common.enumuration.SearchType;
|
| 21612 |
ashik.ali |
41 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21985 |
kshitij.so |
42 |
import com.spice.profitmandi.common.model.CartFofo;
|
| 22860 |
ashik.ali |
43 |
import com.spice.profitmandi.common.model.CreateOrderRequest;
|
| 23654 |
amit.gupta |
44 |
import com.spice.profitmandi.common.model.CreditNotePdfModel;
|
| 23584 |
ashik.ali |
45 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
| 26647 |
tejbeer |
46 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 27861 |
tejbeer |
47 |
import com.spice.profitmandi.common.model.FofoItemIdAmountModel;
|
| 23638 |
amit.gupta |
48 |
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
|
| 27861 |
tejbeer |
49 |
import com.spice.profitmandi.common.model.PartnerOptionsAndItemAmountModel;
|
| 24105 |
govind |
50 |
import com.spice.profitmandi.common.model.PaymentOptionTransactionModel;
|
| 22660 |
ashik.ali |
51 |
import com.spice.profitmandi.common.model.PdfModel;
|
| 22581 |
ashik.ali |
52 |
import com.spice.profitmandi.common.model.PriceModel;
|
| 21612 |
ashik.ali |
53 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21689 |
ashik.ali |
54 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 23638 |
amit.gupta |
55 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 22244 |
ashik.ali |
56 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 23638 |
amit.gupta |
57 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 27861 |
tejbeer |
58 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 22217 |
ashik.ali |
59 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
| 23343 |
ashik.ali |
60 |
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
|
| 23548 |
ashik.ali |
61 |
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
|
| 26647 |
tejbeer |
62 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
| 21728 |
ashik.ali |
63 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
|
|
64 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 23654 |
amit.gupta |
65 |
import com.spice.profitmandi.dao.entity.fofo.CustomerCreditNote;
|
|
|
66 |
import com.spice.profitmandi.dao.entity.fofo.CustomerReturnItem;
|
| 23638 |
amit.gupta |
67 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
| 22927 |
ashik.ali |
68 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 22860 |
ashik.ali |
69 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 21728 |
ashik.ali |
70 |
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
|
| 26647 |
tejbeer |
71 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrder;
|
|
|
72 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
|
| 23298 |
ashik.ali |
73 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 23548 |
ashik.ali |
74 |
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
|
| 27046 |
tejbeer |
75 |
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
|
| 23638 |
amit.gupta |
76 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 27861 |
tejbeer |
77 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 26647 |
tejbeer |
78 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 22217 |
ashik.ali |
79 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
| 23343 |
ashik.ali |
80 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
| 23638 |
amit.gupta |
81 |
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
|
| 23298 |
ashik.ali |
82 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 26647 |
tejbeer |
83 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 21728 |
ashik.ali |
84 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
|
|
85 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
| 23650 |
amit.gupta |
86 |
import com.spice.profitmandi.dao.repository.fofo.CustomerReturnItemRepository;
|
| 22860 |
ashik.ali |
87 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 21728 |
ashik.ali |
88 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 23366 |
ashik.ali |
89 |
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
|
| 21728 |
ashik.ali |
90 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 26647 |
tejbeer |
91 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
|
|
|
92 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderRepository;
|
| 24440 |
amit.gupta |
93 |
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
|
| 23298 |
ashik.ali |
94 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 23798 |
amit.gupta |
95 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 25726 |
amit.gupta |
96 |
import com.spice.profitmandi.service.integrations.zest.InsuranceService;
|
| 24440 |
amit.gupta |
97 |
import com.spice.profitmandi.service.integrations.zest.MobileInsurancePlan;
|
| 23366 |
ashik.ali |
98 |
import com.spice.profitmandi.service.order.OrderService;
|
| 22069 |
ashik.ali |
99 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 26647 |
tejbeer |
100 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22139 |
amit.gupta |
101 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 22069 |
ashik.ali |
102 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 24105 |
govind |
103 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 21612 |
ashik.ali |
104 |
|
|
|
105 |
@Controller
|
| 23973 |
govind |
106 |
@Transactional(rollbackFor = Throwable.class)
|
| 21612 |
ashik.ali |
107 |
public class OrderController {
|
|
|
108 |
|
| 23568 |
govind |
109 |
private static final Logger LOGGER = LogManager.getLogger(OrderController.class);
|
| 21985 |
kshitij.so |
110 |
|
| 21612 |
ashik.ali |
111 |
@Autowired
|
| 22860 |
ashik.ali |
112 |
private CustomerRepository customerRepository;
|
| 23973 |
govind |
113 |
|
| 23821 |
amit.gupta |
114 |
private boolean accessoriesDeals = true;
|
| 21985 |
kshitij.so |
115 |
|
| 21612 |
ashik.ali |
116 |
@Autowired
|
| 23786 |
amit.gupta |
117 |
private RoleManager roleManager;
|
| 23973 |
govind |
118 |
|
| 23786 |
amit.gupta |
119 |
@Autowired
|
| 26817 |
amit.gupta |
120 |
private Gson gson;
|
| 27046 |
tejbeer |
121 |
|
| 26817 |
amit.gupta |
122 |
@Autowired
|
| 23654 |
amit.gupta |
123 |
private CustomerReturnItemRepository customerReturnItemRepository;
|
| 23973 |
govind |
124 |
|
| 23654 |
amit.gupta |
125 |
@Autowired
|
| 23638 |
amit.gupta |
126 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| 21985 |
kshitij.so |
127 |
|
| 21612 |
ashik.ali |
128 |
@Autowired
|
| 22860 |
ashik.ali |
129 |
private PaymentOptionRepository paymentOptionRepository;
|
| 24844 |
amit.gupta |
130 |
|
| 24440 |
amit.gupta |
131 |
@Autowired
|
|
|
132 |
private StateRepository stateRepository;
|
| 23973 |
govind |
133 |
|
| 23638 |
amit.gupta |
134 |
@Autowired
|
|
|
135 |
private ItemRepository itemRepository;
|
| 21985 |
kshitij.so |
136 |
|
| 21680 |
ashik.ali |
137 |
@Autowired
|
| 24105 |
govind |
138 |
private MVCResponseSender mvcResponseSender;
|
| 24844 |
amit.gupta |
139 |
|
| 24440 |
amit.gupta |
140 |
@Autowired
|
| 25726 |
amit.gupta |
141 |
private InsuranceService insuranceService;
|
| 24105 |
govind |
142 |
|
|
|
143 |
@Autowired
|
| 22860 |
ashik.ali |
144 |
private FofoOrderRepository fofoOrderRepository;
|
| 21985 |
kshitij.so |
145 |
|
| 21680 |
ashik.ali |
146 |
@Autowired
|
| 22860 |
ashik.ali |
147 |
private CustomerAddressRepository customerAddressRepository;
|
| 23973 |
govind |
148 |
|
| 22217 |
ashik.ali |
149 |
@Autowired
|
| 22860 |
ashik.ali |
150 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 23973 |
govind |
151 |
|
| 23343 |
ashik.ali |
152 |
@Autowired
|
|
|
153 |
private InsuranceProviderRepository insuranceProviderRepository;
|
| 21985 |
kshitij.so |
154 |
|
| 21896 |
ashik.ali |
155 |
@Autowired
|
| 22860 |
ashik.ali |
156 |
private CookiesProcessor cookiesProcessor;
|
| 23973 |
govind |
157 |
|
| 22069 |
ashik.ali |
158 |
@Autowired
|
| 22860 |
ashik.ali |
159 |
private PricingService pricingService;
|
| 23973 |
govind |
160 |
|
| 22354 |
ashik.ali |
161 |
@Autowired
|
| 22860 |
ashik.ali |
162 |
private OrderService orderService;
|
| 23973 |
govind |
163 |
|
| 23298 |
ashik.ali |
164 |
@Autowired
|
|
|
165 |
private RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 23973 |
govind |
166 |
|
| 22354 |
ashik.ali |
167 |
@Autowired
|
| 23298 |
ashik.ali |
168 |
private AddressRepository addressRepository;
|
| 23973 |
govind |
169 |
|
| 23298 |
ashik.ali |
170 |
@Autowired
|
| 23548 |
ashik.ali |
171 |
private PaymentOptionTransactionRepository fofoOrderPaymentOptionRepository;
|
| 23973 |
govind |
172 |
|
| 23366 |
ashik.ali |
173 |
@Autowired
|
|
|
174 |
private FofoPartnerPaymentOptionRepository fofoPartnerPaymentOptionRepository;
|
| 23973 |
govind |
175 |
|
| 23419 |
ashik.ali |
176 |
@Autowired
|
| 22860 |
ashik.ali |
177 |
private ResponseSender<?> responseSender;
|
| 23973 |
govind |
178 |
|
| 26647 |
tejbeer |
179 |
@Autowired
|
|
|
180 |
private PendingOrderRepository pendingOrderRepository;
|
|
|
181 |
|
|
|
182 |
@Autowired
|
|
|
183 |
private PendingOrderItemRepository pendingOrderItemRepository;
|
|
|
184 |
|
|
|
185 |
@Autowired
|
|
|
186 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
187 |
|
|
|
188 |
@Autowired
|
|
|
189 |
private RetailerService retailerService;
|
|
|
190 |
|
|
|
191 |
@Autowired
|
|
|
192 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
193 |
|
| 27861 |
tejbeer |
194 |
@Autowired
|
|
|
195 |
private TagListingRepository tagListingRepository;
|
|
|
196 |
|
| 21985 |
kshitij.so |
197 |
@RequestMapping(value = "/order")
|
| 23973 |
govind |
198 |
public String orderIndex(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model)
|
|
|
199 |
throws ProfitMandiBusinessException {
|
|
|
200 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
201 |
;
|
|
|
202 |
|
| 23298 |
ashik.ali |
203 |
int addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(loginDetails.getFofoId());
|
|
|
204 |
Address address = addressRepository.selectById(addressId);
|
| 23973 |
govind |
205 |
|
| 22860 |
ashik.ali |
206 |
List<CartFofo> cartItems = orderService.cartCheckout(cartData);
|
|
|
207 |
Set<Integer> itemIds = new HashSet<>();
|
| 23973 |
govind |
208 |
for (CartFofo cartFofo : cartItems) {
|
| 22860 |
ashik.ali |
209 |
itemIds.add(cartFofo.getItemId());
|
| 21985 |
kshitij.so |
210 |
}
|
| 23973 |
govind |
211 |
Map<Integer, PriceModel> mopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds,
|
|
|
212 |
loginDetails.getFofoId());
|
|
|
213 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository
|
|
|
214 |
.selectPaymentOptionIdsByFofoId(loginDetails.getFofoId());
|
| 23366 |
ashik.ali |
215 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds));
|
| 22860 |
ashik.ali |
216 |
LOGGER.info("mopPriceMap {}", mopPriceMap);
|
| 24844 |
amit.gupta |
217 |
model.addAttribute("stateNames",
|
|
|
218 |
stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList()));
|
| 23298 |
ashik.ali |
219 |
model.addAttribute("retailerStateName", address.getState());
|
| 24440 |
amit.gupta |
220 |
model.addAttribute("cartItems", cartItems);
|
| 22860 |
ashik.ali |
221 |
model.addAttribute("mopPriceMap", mopPriceMap);
|
| 23366 |
ashik.ali |
222 |
model.addAttribute("paymentOptions", paymentOptions);
|
| 23821 |
amit.gupta |
223 |
model.addAttribute("accessoriesDeals", accessoriesDeals);
|
| 22860 |
ashik.ali |
224 |
return "order-index";
|
| 21985 |
kshitij.so |
225 |
}
|
| 23973 |
govind |
226 |
|
| 24440 |
amit.gupta |
227 |
@RequestMapping(value = "/checkplans", method = RequestMethod.GET)
|
| 25726 |
amit.gupta |
228 |
public String getInsurancePrices(HttpServletRequest request, @RequestParam float price, Model model,
|
|
|
229 |
@RequestParam int itemId) throws ProfitMandiBusinessException {
|
| 22244 |
ashik.ali |
230 |
LOGGER.info("Request received at url : {}", request.getRequestURI());
|
| 24844 |
amit.gupta |
231 |
|
| 24440 |
amit.gupta |
232 |
try {
|
| 25726 |
amit.gupta |
233 |
String response = mvcResponseSender.createResponseString(this.getPlans(price, itemId));
|
| 24440 |
amit.gupta |
234 |
model.addAttribute("response", response);
|
|
|
235 |
} catch (Exception e) {
|
|
|
236 |
// TODO Auto-generated catch block
|
|
|
237 |
e.printStackTrace();
|
|
|
238 |
throw new ProfitMandiBusinessException("Plans", "Plans API", "Error formatting insurance plans");
|
|
|
239 |
}
|
| 24844 |
amit.gupta |
240 |
|
| 24440 |
amit.gupta |
241 |
return "response";
|
| 22244 |
ashik.ali |
242 |
}
|
| 23973 |
govind |
243 |
|
| 21985 |
kshitij.so |
244 |
@RequestMapping(value = "/get-order", method = RequestMethod.GET)
|
| 23973 |
govind |
245 |
public String getOrder(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId,
|
|
|
246 |
Model model) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
247 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
248 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 23638 |
amit.gupta |
249 |
List<FofoOrderItem> fofoLineItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 22927 |
ashik.ali |
250 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 23973 |
govind |
251 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
| 22927 |
ashik.ali |
252 |
customerAddress.setPhoneNumber(customer.getMobileNumber());
|
| 23973 |
govind |
253 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
254 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
255 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
|
|
256 |
.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
|
|
|
257 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
258 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23343 |
ashik.ali |
259 |
this.addInsuranceProvider(insurancePolicies);
|
| 24087 |
amit.gupta |
260 |
|
| 22927 |
ashik.ali |
261 |
model.addAttribute("fofoOrder", fofoOrder);
|
|
|
262 |
model.addAttribute("fofoLineItems", fofoLineItems);
|
|
|
263 |
model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
|
|
|
264 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
| 23548 |
ashik.ali |
265 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
| 23366 |
ashik.ali |
266 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
| 22927 |
ashik.ali |
267 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
268 |
return "order-details";
|
| 21985 |
kshitij.so |
269 |
}
|
| 23973 |
govind |
270 |
|
|
|
271 |
private Map<Integer, InsuranceProvider> toInsuranceProviderIdInsuranceProvider(
|
|
|
272 |
List<InsuranceProvider> insuranceProviders) {
|
| 23343 |
ashik.ali |
273 |
Map<Integer, InsuranceProvider> insuranceProviderIdInsuranceProviderMap = new HashMap<>();
|
| 23973 |
govind |
274 |
for (InsuranceProvider insuranceProvider : insuranceProviders) {
|
| 23343 |
ashik.ali |
275 |
insuranceProviderIdInsuranceProviderMap.put(insuranceProvider.getId(), insuranceProvider);
|
|
|
276 |
}
|
|
|
277 |
return insuranceProviderIdInsuranceProviderMap;
|
|
|
278 |
}
|
| 23973 |
govind |
279 |
|
|
|
280 |
private void addInsuranceProvider(List<InsurancePolicy> insurancePolicies) {
|
|
|
281 |
if (insurancePolicies.isEmpty()) {
|
| 23343 |
ashik.ali |
282 |
return;
|
|
|
283 |
}
|
|
|
284 |
Set<Integer> insuranceProviderIds = new HashSet<>();
|
| 23973 |
govind |
285 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| 23343 |
ashik.ali |
286 |
insuranceProviderIds.add(insurancePolicy.getProviderId());
|
|
|
287 |
}
|
|
|
288 |
LOGGER.info("insuranceProviderIds {}", insuranceProviderIds);
|
|
|
289 |
List<InsuranceProvider> insuranceProviders = insuranceProviderRepository.selectByIds(insuranceProviderIds);
|
| 23973 |
govind |
290 |
Map<Integer, InsuranceProvider> insuranceProviderIdInsuranceProviderMap = this
|
|
|
291 |
.toInsuranceProviderIdInsuranceProvider(insuranceProviders);
|
|
|
292 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
|
|
293 |
insurancePolicy
|
|
|
294 |
.setInsuranceProvider(insuranceProviderIdInsuranceProviderMap.get(insurancePolicy.getProviderId()));
|
| 23343 |
ashik.ali |
295 |
}
|
|
|
296 |
}
|
| 23973 |
govind |
297 |
|
| 22244 |
ashik.ali |
298 |
@RequestMapping(value = "/saleDetails", method = RequestMethod.GET)
|
| 23973 |
govind |
299 |
public String getSaleDetails(HttpServletRequest request,
|
|
|
300 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws Exception {
|
| 22927 |
ashik.ali |
301 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 25562 |
amit.gupta |
302 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
| 22927 |
ashik.ali |
303 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 23654 |
amit.gupta |
304 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 22927 |
ashik.ali |
305 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 23973 |
govind |
306 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
307 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
|
|
308 |
|
|
|
309 |
// Added Migration info as we lost it.
|
|
|
310 |
if (paymentOptionTransactions == null || paymentOptionTransactions.size() == 0) {
|
| 23952 |
amit.gupta |
311 |
PaymentOptionTransaction pot = new PaymentOptionTransaction();
|
|
|
312 |
pot.setAmount(fofoOrder.getTotalAmount());
|
|
|
313 |
pot.setCreateTimestamp(fofoOrder.getCreateTimestamp());
|
| 23973 |
govind |
314 |
// Mark it paid through cash
|
| 23952 |
amit.gupta |
315 |
pot.setPaymentOptionId(1);
|
|
|
316 |
pot.setReferenceType(PaymentOptionReferenceType.ORDER);
|
|
|
317 |
fofoOrderPaymentOptionRepository.persist(pot);
|
|
|
318 |
paymentOptionTransactions.add(pot);
|
|
|
319 |
LOGGER.info("Added to get invoice");
|
|
|
320 |
}
|
| 23973 |
govind |
321 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
|
|
322 |
.paymentOptionIdPaymentOptionMap(paymentOptionTransactions);
|
|
|
323 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
324 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23343 |
ashik.ali |
325 |
this.addInsuranceProvider(insurancePolicies);
|
| 23973 |
govind |
326 |
Map<Integer, Item> itemsMap = fofoOrderItems.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> {
|
| 23638 |
amit.gupta |
327 |
try {
|
|
|
328 |
return itemRepository.selectById(x.getItemId());
|
|
|
329 |
} catch (ProfitMandiBusinessException e) {
|
|
|
330 |
// TODO Auto-generated catch block
|
|
|
331 |
return null;
|
|
|
332 |
}
|
|
|
333 |
}));
|
| 23973 |
govind |
334 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdLineItemMap = fofoOrderItems.stream()
|
|
|
335 |
.collect(Collectors.toMap(FofoOrderItem::getId, FofoOrderItem::getFofoLineItems));
|
| 23654 |
amit.gupta |
336 |
|
| 23973 |
govind |
337 |
Map<Integer, List<CustomerReturnItem>> foiIdCustomerReturnInventoryItemsMap = fofoOrderItems.stream()
|
|
|
338 |
.collect(Collectors.toMap(foi -> foi.getId(),
|
|
|
339 |
foi -> customerReturnItemRepository.selectAllByOrderItemId(foi.getId())));
|
| 23654 |
amit.gupta |
340 |
|
|
|
341 |
Map<Integer, Integer> inventoryItemBilledQtyMap = new HashMap<>();
|
| 23973 |
govind |
342 |
|
|
|
343 |
for (FofoOrderItem foi : fofoOrderItems) {
|
|
|
344 |
for (FofoLineItem fli : foi.getFofoLineItems()) {
|
| 23654 |
amit.gupta |
345 |
inventoryItemBilledQtyMap.put(fli.getInventoryItemId(), fli.getQuantity());
|
|
|
346 |
}
|
| 23973 |
govind |
347 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository
|
|
|
348 |
.selectAllByOrderItemId(foi.getId());
|
| 25562 |
amit.gupta |
349 |
this.markDoa(fofoOrder, foi, isAdmin);
|
| 23973 |
govind |
350 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
|
|
351 |
inventoryItemBilledQtyMap.put(customerReturnItem.getInventoryItemId(),
|
|
|
352 |
inventoryItemBilledQtyMap.get(customerReturnItem.getInventoryItemId()) - 1);
|
| 23654 |
amit.gupta |
353 |
}
|
|
|
354 |
}
|
| 23973 |
govind |
355 |
|
| 23654 |
amit.gupta |
356 |
LOGGER.info("fofoOrderItemIdLineItemMap {}", fofoOrderItemIdLineItemMap);
|
| 22927 |
ashik.ali |
357 |
model.addAttribute("fofoOrder", fofoOrder);
|
| 23638 |
amit.gupta |
358 |
model.addAttribute("itemsMap", itemsMap);
|
| 23654 |
amit.gupta |
359 |
model.addAttribute("fofoOrderItemIdLineItemsMap", StringUtils.toString(fofoOrderItemIdLineItemMap));
|
| 23973 |
govind |
360 |
model.addAttribute("foiIdCustomerReturnInventoryItemsMap",
|
|
|
361 |
StringUtils.toString(foiIdCustomerReturnInventoryItemsMap));
|
| 23654 |
amit.gupta |
362 |
model.addAttribute("fofoOrderItems", fofoOrderItems);
|
|
|
363 |
model.addAttribute("inventoryItemBilledQtyMap", StringUtils.toString(inventoryItemBilledQtyMap));
|
| 22927 |
ashik.ali |
364 |
model.addAttribute("customerBillingAddress", orderService.getBillingAddress(customerAddress));
|
|
|
365 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
| 23548 |
ashik.ali |
366 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
| 23366 |
ashik.ali |
367 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
| 22927 |
ashik.ali |
368 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
| 23638 |
amit.gupta |
369 |
model.addAttribute("markDefective", this.markDefective(fofoOrder));
|
| 22927 |
ashik.ali |
370 |
return "sale-details";
|
| 22244 |
ashik.ali |
371 |
}
|
| 23973 |
govind |
372 |
|
| 25562 |
amit.gupta |
373 |
private void markDoa(FofoOrder fofoOrder, FofoOrderItem foi, boolean isAdmin) {
|
| 25606 |
tejbeer |
374 |
if (isAdmin) {
|
| 24094 |
amit.gupta |
375 |
foi.setDoa(true);
|
| 25562 |
amit.gupta |
376 |
return;
|
| 24094 |
amit.gupta |
377 |
}
|
| 28263 |
amit.gupta |
378 |
boolean isImei = foi.getFofoLineItems().stream().anyMatch(x->x.getSerialNumber().equals("863903054378477"));
|
| 24094 |
amit.gupta |
379 |
LocalDateTime buyDate = fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS);
|
|
|
380 |
LocalDateTime curDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
| 28263 |
amit.gupta |
381 |
if (buyDate.isAfter(curDate.minusDays(45)) || isImei) {
|
| 24094 |
amit.gupta |
382 |
foi.setDoa(true);
|
|
|
383 |
} else
|
|
|
384 |
foi.setDoa(
|
|
|
385 |
foi.getBrand().equals("Nokia") && foi.getCost() < 4990 && buyDate.isAfter(curDate.minusYears(1)));
|
| 23638 |
amit.gupta |
386 |
}
|
| 23973 |
govind |
387 |
|
| 23638 |
amit.gupta |
388 |
private boolean markDefective(FofoOrder fofoOrder) {
|
| 23973 |
govind |
389 |
return fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS).plusDays(180)
|
|
|
390 |
.isAfter(LocalDateTime.now().truncatedTo(ChronoUnit.DAYS));
|
|
|
391 |
|
| 23638 |
amit.gupta |
392 |
}
|
| 23973 |
govind |
393 |
|
| 23584 |
ashik.ali |
394 |
@RequestMapping(value = "/getSearchOrder")
|
| 23973 |
govind |
395 |
public String getSearchOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 23584 |
ashik.ali |
396 |
return "search-order";
|
|
|
397 |
}
|
| 23973 |
govind |
398 |
|
| 27819 |
tejbeer |
399 |
@RequestMapping(value = "/getInvoiceSearchOrder")
|
|
|
400 |
public String getInvoiceSearchOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
401 |
return "invoices-cancel";
|
|
|
402 |
}
|
|
|
403 |
|
| 23584 |
ashik.ali |
404 |
@RequestMapping(value = "/customerDetails", method = RequestMethod.PUT)
|
| 23973 |
govind |
405 |
public String updateCustomerDetails(HttpServletRequest request, @RequestBody CustomCustomer customCustomer,
|
|
|
406 |
@RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER) String invoiceNumber, Model model)
|
| 24281 |
amit.gupta |
407 |
throws Exception {
|
| 23973 |
govind |
408 |
|
| 23584 |
ashik.ali |
409 |
orderService.updateCustomerDetails(customCustomer, invoiceNumber);
|
|
|
410 |
return this.getSearchOrderDetails(request, invoiceNumber, model);
|
|
|
411 |
}
|
| 23973 |
govind |
412 |
|
| 23584 |
ashik.ali |
413 |
@RequestMapping(value = "/searchOrderDetails", method = RequestMethod.GET)
|
| 23973 |
govind |
414 |
public String getSearchOrderDetails(HttpServletRequest request,
|
|
|
415 |
@RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER) String invoiceNumber, Model model)
|
| 24281 |
amit.gupta |
416 |
throws Exception {
|
| 23973 |
govind |
417 |
|
| 23584 |
ashik.ali |
418 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 24271 |
amit.gupta |
419 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 23584 |
ashik.ali |
420 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
421 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 24105 |
govind |
422 |
List<Integer> fofoPartnerPaymentOptions = fofoPartnerPaymentOptionRepository
|
|
|
423 |
.selectPaymentOptionIdsByFofoId(fofoOrder.getFofoId());
|
| 24276 |
amit.gupta |
424 |
Map<Integer, Item> itemsMap = fofoOrderItems.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> {
|
|
|
425 |
try {
|
|
|
426 |
return itemRepository.selectById(x.getItemId());
|
|
|
427 |
} catch (ProfitMandiBusinessException e) {
|
|
|
428 |
// TODO Auto-generated catch block
|
|
|
429 |
return null;
|
|
|
430 |
}
|
|
|
431 |
}));
|
| 24105 |
govind |
432 |
LOGGER.info("fofoPartnerPaymentOptions" + fofoPartnerPaymentOptions);
|
| 23973 |
govind |
433 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
434 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
| 24105 |
govind |
435 |
LOGGER.info("paymentOptionTransactions" + paymentOptionTransactions);
|
| 23973 |
govind |
436 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
| 24105 |
govind |
437 |
.paymentOptionIdPaymentOptionMapUsingPaymentOptions(fofoPartnerPaymentOptions);
|
|
|
438 |
Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = this
|
|
|
439 |
.paymentOptionIdPaymentOptionTransactionMap(paymentOptionTransactions);
|
|
|
440 |
LOGGER.info("paymentOptionIdPaymentOptionTransactionMap" + paymentOptionIdPaymentOptionTransactionMap.keySet());
|
| 23973 |
govind |
441 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
442 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23584 |
ashik.ali |
443 |
this.addInsuranceProvider(insurancePolicies);
|
|
|
444 |
model.addAttribute("fofoOrder", fofoOrder);
|
| 24844 |
amit.gupta |
445 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
| 24271 |
amit.gupta |
446 |
fofoOrderItem.setDoa(true);
|
|
|
447 |
}
|
| 24844 |
amit.gupta |
448 |
|
| 24281 |
amit.gupta |
449 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdLineItemMap = fofoOrderItems.stream()
|
|
|
450 |
.collect(Collectors.toMap(FofoOrderItem::getId, FofoOrderItem::getFofoLineItems));
|
|
|
451 |
|
|
|
452 |
Map<Integer, List<CustomerReturnItem>> foiIdCustomerReturnInventoryItemsMap = fofoOrderItems.stream()
|
|
|
453 |
.collect(Collectors.toMap(foi -> foi.getId(),
|
|
|
454 |
foi -> customerReturnItemRepository.selectAllByOrderItemId(foi.getId())));
|
|
|
455 |
|
|
|
456 |
Map<Integer, Integer> inventoryItemBilledQtyMap = new HashMap<>();
|
|
|
457 |
|
|
|
458 |
for (FofoOrderItem foi : fofoOrderItems) {
|
|
|
459 |
for (FofoLineItem fli : foi.getFofoLineItems()) {
|
|
|
460 |
inventoryItemBilledQtyMap.put(fli.getInventoryItemId(), fli.getQuantity());
|
|
|
461 |
}
|
|
|
462 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository
|
|
|
463 |
.selectAllByOrderItemId(foi.getId());
|
|
|
464 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
|
|
465 |
inventoryItemBilledQtyMap.put(customerReturnItem.getInventoryItemId(),
|
|
|
466 |
inventoryItemBilledQtyMap.get(customerReturnItem.getInventoryItemId()) - 1);
|
|
|
467 |
}
|
|
|
468 |
}
|
|
|
469 |
model.addAttribute("foiIdCustomerReturnInventoryItemsMap",
|
|
|
470 |
StringUtils.toString(foiIdCustomerReturnInventoryItemsMap));
|
| 24271 |
amit.gupta |
471 |
model.addAttribute("fofoOrderItems", fofoOrderItems);
|
| 24281 |
amit.gupta |
472 |
model.addAttribute("inventoryItemBilledQtyMap", StringUtils.toString(inventoryItemBilledQtyMap));
|
|
|
473 |
model.addAttribute("fofoOrderItemIdLineItemsMap", StringUtils.toString(fofoOrderItemIdLineItemMap));
|
| 24276 |
amit.gupta |
474 |
model.addAttribute("itemsMap", itemsMap);
|
| 24271 |
amit.gupta |
475 |
model.addAttribute("markDefective", true);
|
| 23584 |
ashik.ali |
476 |
model.addAttribute("customer", customer);
|
|
|
477 |
model.addAttribute("customerAddress", customerAddress);
|
|
|
478 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
|
|
479 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
| 24105 |
govind |
480 |
model.addAttribute("paymentOptionIdPaymentOptionTransactionMap", paymentOptionIdPaymentOptionTransactionMap);
|
| 23584 |
ashik.ali |
481 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
| 24105 |
govind |
482 |
model.addAttribute("fofoPartnerPaymentOptions", fofoPartnerPaymentOptions);
|
|
|
483 |
model.addAttribute("totalNumberOfPaymentOptionId", fofoPartnerPaymentOptions.size());
|
| 24844 |
amit.gupta |
484 |
model.addAttribute("stateNames",
|
|
|
485 |
stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList()));
|
| 23584 |
ashik.ali |
486 |
return "search-order-details";
|
|
|
487 |
}
|
| 23973 |
govind |
488 |
|
|
|
489 |
private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap(
|
|
|
490 |
List<PaymentOptionTransaction> paymentOptionTransactions) {
|
| 23366 |
ashik.ali |
491 |
Set<Integer> paymentOptionIds = new HashSet<>();
|
| 23973 |
govind |
492 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
| 23548 |
ashik.ali |
493 |
paymentOptionIds.add(paymentOptionTransaction.getPaymentOptionId());
|
| 23366 |
ashik.ali |
494 |
}
|
|
|
495 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByIds(paymentOptionIds);
|
|
|
496 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = new HashMap<>();
|
| 23973 |
govind |
497 |
for (PaymentOption paymentOption : paymentOptions) {
|
| 23366 |
ashik.ali |
498 |
paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
|
|
|
499 |
}
|
|
|
500 |
return paymentOptionIdPaymentOptionMap;
|
|
|
501 |
}
|
| 23973 |
govind |
502 |
|
| 24105 |
govind |
503 |
private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMapUsingPaymentOptions(
|
|
|
504 |
List<Integer> fofoPartnerPaymentOptions) {
|
|
|
505 |
List<PaymentOption> paymentOptions = paymentOptionRepository
|
|
|
506 |
.selectByIds(new HashSet<>(fofoPartnerPaymentOptions));
|
|
|
507 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = new HashMap<>();
|
|
|
508 |
for (PaymentOption paymentOption : paymentOptions) {
|
|
|
509 |
paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
|
|
|
510 |
}
|
|
|
511 |
return paymentOptionIdPaymentOptionMap;
|
|
|
512 |
}
|
|
|
513 |
|
|
|
514 |
private Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap(
|
|
|
515 |
List<PaymentOptionTransaction> paymentOptionTransactions) {
|
|
|
516 |
Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = new HashMap<>();
|
|
|
517 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
|
|
518 |
paymentOptionIdPaymentOptionTransactionMap.put(paymentOptionTransaction.getPaymentOptionId(),
|
|
|
519 |
paymentOptionTransaction);
|
|
|
520 |
}
|
|
|
521 |
return paymentOptionIdPaymentOptionTransactionMap;
|
|
|
522 |
}
|
|
|
523 |
|
| 21985 |
kshitij.so |
524 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
| 23973 |
govind |
525 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest,
|
|
|
526 |
Model model) throws ProfitMandiBusinessException {
|
| 26647 |
tejbeer |
527 |
// throw new ProfitMandiBusinessException("Billing is on hold temporarily",
|
|
|
528 |
// "Billing is on hold temporarily", "Billing is on hold temporarily");
|
| 26531 |
amit.gupta |
529 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), createOrderRequest);
|
| 22927 |
ashik.ali |
530 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
531 |
|
| 23823 |
amit.gupta |
532 |
int fofoOrderId = orderService.createOrder(createOrderRequest, fofoDetails.getFofoId(), accessoriesDeals);
|
| 22280 |
ashik.ali |
533 |
LOGGER.info("Order has been created successfully...");
|
| 26531 |
amit.gupta |
534 |
return "redirect:/get-order/?orderId=" + fofoOrderId;
|
| 21612 |
ashik.ali |
535 |
}
|
| 23973 |
govind |
536 |
|
| 23638 |
amit.gupta |
537 |
@RequestMapping(value = "/order/bad_return", method = RequestMethod.POST)
|
| 23973 |
govind |
538 |
public ResponseEntity<?> badReturn(HttpServletRequest request, @RequestBody FoiBadReturnRequest foiBadReturnRequest,
|
|
|
539 |
Model model) throws ProfitMandiBusinessException {
|
| 23638 |
amit.gupta |
540 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), foiBadReturnRequest);
|
|
|
541 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 24282 |
amit.gupta |
542 |
CustomerCreditNote custmoerCreditNote;
|
| 24844 |
amit.gupta |
543 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 24282 |
amit.gupta |
544 |
FofoOrderItem foi = fofoOrderItemRepository.selectById(foiBadReturnRequest.getFofoOrderItemId());
|
|
|
545 |
FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
|
|
|
546 |
custmoerCreditNote = orderService.badReturn(fo.getFofoId(), foiBadReturnRequest);
|
|
|
547 |
} else {
|
|
|
548 |
custmoerCreditNote = orderService.badReturn(fofoDetails.getFofoId(), foiBadReturnRequest);
|
|
|
549 |
}
|
| 23654 |
amit.gupta |
550 |
return responseSender.ok(custmoerCreditNote.getId());
|
| 23638 |
amit.gupta |
551 |
}
|
| 21985 |
kshitij.so |
552 |
|
| 21689 |
ashik.ali |
553 |
@RequestMapping(value = "/generateInvoice")
|
| 23973 |
govind |
554 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
|
|
555 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
|
|
556 |
LOGGER.info("Request received at url {} with params [{}={}] ", request.getRequestURI(),
|
|
|
557 |
ProfitMandiConstants.ORDER_ID, orderId);
|
| 22139 |
amit.gupta |
558 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23594 |
ashik.ali |
559 |
PdfModel pdfModel = null;
|
| 23973 |
govind |
560 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 23594 |
ashik.ali |
561 |
pdfModel = orderService.getInvoicePdfModel(orderId);
|
| 23973 |
govind |
562 |
} else {
|
| 23594 |
ashik.ali |
563 |
pdfModel = orderService.getInvoicePdfModel(fofoDetails.getFofoId(), orderId);
|
|
|
564 |
}
|
| 21689 |
ashik.ali |
565 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 24844 |
amit.gupta |
566 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
| 21689 |
ashik.ali |
567 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 23973 |
govind |
568 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
569 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
570 |
headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
|
|
571 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
572 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
573 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
574 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 21689 |
ashik.ali |
575 |
}
|
| 23973 |
govind |
576 |
|
| 24844 |
amit.gupta |
577 |
@RequestMapping(value = "/generateInvoices")
|
|
|
578 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
|
|
579 |
@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, @RequestParam int partnerId)
|
|
|
580 |
throws ProfitMandiBusinessException {
|
|
|
581 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
582 |
List<PdfModel> pdfModels = new ArrayList<>();
|
|
|
583 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
|
|
584 |
List<Integer> orderIds = fofoOrderRepository.selectByFofoId(partnerId, startDate, endDate, 0, 0).stream()
|
|
|
585 |
.map(x -> x.getId()).collect(Collectors.toList());
|
|
|
586 |
for (int orderId : orderIds) {
|
|
|
587 |
pdfModels.add(orderService.getInvoicePdfModel(orderId));
|
|
|
588 |
}
|
|
|
589 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
590 |
PdfUtils.generateAndWrite(pdfModels, byteArrayOutputStream);
|
|
|
591 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
|
|
592 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
593 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
594 |
headers.set("Content-disposition", "inline; filename=invoice-" + partnerId + ".pdf");
|
|
|
595 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
596 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
597 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
598 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
599 |
} else {
|
|
|
600 |
throw new ProfitMandiBusinessException("Auth", fofoDetails.getEmailId(), "Unauthorised access");
|
|
|
601 |
}
|
|
|
602 |
}
|
|
|
603 |
|
| 22244 |
ashik.ali |
604 |
@RequestMapping(value = "/saleHistory")
|
| 23973 |
govind |
605 |
public String saleHistory(HttpServletRequest request,
|
|
|
606 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
607 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
608 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
609 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
610 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
611 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
612 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
613 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
614 |
|
|
|
615 |
Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue,
|
|
|
616 |
startTime, endTime, offset, limit);
|
| 23203 |
ashik.ali |
617 |
model.addAllAttributes(map);
|
| 22244 |
ashik.ali |
618 |
return "sale-history";
|
|
|
619 |
}
|
| 23973 |
govind |
620 |
|
| 25092 |
amit.gupta |
621 |
@RequestMapping(value = "/downloadInvoices")
|
|
|
622 |
public ResponseEntity<?> downloadInvoices(HttpServletRequest request,
|
|
|
623 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
624 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
625 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
626 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
627 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
628 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
629 |
throws ProfitMandiBusinessException {
|
|
|
630 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
631 |
|
|
|
632 |
Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue,
|
|
|
633 |
startTime, endTime, offset, 100);
|
| 25562 |
amit.gupta |
634 |
List<FofoOrder> fofoOrders = (List<FofoOrder>) map.get("saleHistories");
|
| 25092 |
amit.gupta |
635 |
|
| 25562 |
amit.gupta |
636 |
if (fofoOrders.size() == 0) {
|
| 25092 |
amit.gupta |
637 |
throw new ProfitMandiBusinessException("Search criteria", "", "No orders found for criteria");
|
|
|
638 |
}
|
|
|
639 |
|
| 25093 |
amit.gupta |
640 |
final HttpHeaders headers = new HttpHeaders();
|
| 25092 |
amit.gupta |
641 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
642 |
headers.set("Content-disposition", "inline; filename=invoices.pdf");
|
|
|
643 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
644 |
List<PdfModel> pdfModels = new ArrayList<>();
|
| 25562 |
amit.gupta |
645 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 25092 |
amit.gupta |
646 |
try {
|
|
|
647 |
pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId()));
|
| 25606 |
tejbeer |
648 |
} catch (Exception e) {
|
|
|
649 |
LOGGER.info("could not create invoice for {}, invoice number {}", fofoOrder.getId(),
|
|
|
650 |
fofoOrder.getInvoiceNumber());
|
| 25092 |
amit.gupta |
651 |
}
|
|
|
652 |
}
|
|
|
653 |
PdfUtils.generateAndWrite(pdfModels, byteArrayOutputStream);
|
|
|
654 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
655 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
656 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
657 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
658 |
}
|
|
|
659 |
|
| 23973 |
govind |
660 |
@RequestMapping(value = "/credit-note/{creditNoteId}")
|
|
|
661 |
public ResponseEntity<?> downloadCreditNote(HttpServletRequest request, @PathVariable int creditNoteId)
|
|
|
662 |
throws ProfitMandiBusinessException {
|
| 23654 |
amit.gupta |
663 |
CreditNotePdfModel creditNotePdfModel = orderService.getCreditNotePdfModel(creditNoteId);
|
|
|
664 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
665 |
PdfUtils.generateAndWriteCustomerCreditNotes(Arrays.asList(creditNotePdfModel), byteArrayOutputStream);
|
|
|
666 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 23973 |
govind |
667 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
668 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
669 |
headers.set("Content-disposition",
|
|
|
670 |
"inline; filename=invoice-" + creditNotePdfModel.getCreditNoteNumber() + ".pdf");
|
|
|
671 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
672 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
673 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
674 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 23654 |
amit.gupta |
675 |
}
|
| 23973 |
govind |
676 |
|
| 22291 |
ashik.ali |
677 |
@RequestMapping(value = "/getPaginatedSaleHistory")
|
| 23973 |
govind |
678 |
public String getSaleHistoryPaginated(HttpServletRequest request,
|
|
|
679 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
680 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
681 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
682 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
683 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
684 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
685 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
686 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
687 |
Map<String, Object> map = orderService.getSaleHistoryPaginated(loginDetails.getFofoId(), searchType,
|
|
|
688 |
searchValue, startTime, endTime, offset, limit);
|
| 23203 |
ashik.ali |
689 |
model.addAllAttributes(map);
|
| 22291 |
ashik.ali |
690 |
return "sale-history-paginated";
|
|
|
691 |
}
|
|
|
692 |
|
| 24105 |
govind |
693 |
@PutMapping(value = "/updatePaymentTransaction")
|
|
|
694 |
public String updateTransactionDetails(HttpServletRequest request, @RequestParam String referenceType,
|
|
|
695 |
@RequestParam int fofoId, @RequestParam int referenceId,
|
| 27861 |
tejbeer |
696 |
@RequestBody PartnerOptionsAndItemAmountModel partnerOptionsAndItemAmountModel,
|
| 28055 |
tejbeer |
697 |
@RequestParam float totalAmount, Model model) throws Exception {
|
| 27861 |
tejbeer |
698 |
|
|
|
699 |
List<PaymentOptionTransactionModel> paymentOptionTransactionModels = partnerOptionsAndItemAmountModel
|
|
|
700 |
.getPaymentOptionTransactionModel();
|
| 24105 |
govind |
701 |
LOGGER.info(paymentOptionTransactionModels);
|
| 27861 |
tejbeer |
702 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoId, referenceId);
|
|
|
703 |
LOGGER.info("sdssd" + fofoOrder);
|
|
|
704 |
fofoOrder.setTotalAmount(totalAmount);
|
|
|
705 |
List<FofoItemIdAmountModel> fofoItemIdAmountModel = partnerOptionsAndItemAmountModel.getItemAmountModel();
|
|
|
706 |
for (FofoItemIdAmountModel fim : fofoItemIdAmountModel) {
|
|
|
707 |
LOGGER.info("fim" + fim.getFofoItemId());
|
| 28190 |
tejbeer |
708 |
|
| 28189 |
tejbeer |
709 |
LOGGER.info("fimAmount" + fim.getAmount());
|
| 27861 |
tejbeer |
710 |
Item item = itemRepository.selectById(fim.getItemId());
|
|
|
711 |
TagListing tagListing = tagListingRepository.selectByItemId(item.getId());
|
|
|
712 |
FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectById(fim.getFofoItemId());
|
| 28188 |
tejbeer |
713 |
LOGGER.info("category" + item.getCategoryId());
|
|
|
714 |
if (item.getCategoryId() == ProfitMandiConstants.MOBILE_CATEGORY_ID) {
|
| 28190 |
tejbeer |
715 |
if (fofoOrderItem.getMop() <= fim.getAmount()) {
|
| 27861 |
tejbeer |
716 |
|
| 28131 |
tejbeer |
717 |
if (fim.getAmount() <= tagListing.getMrp()) {
|
| 27861 |
tejbeer |
718 |
fofoOrderItem.setSellingPrice(fim.getAmount());
|
|
|
719 |
} else {
|
|
|
720 |
throw new ProfitMandiBusinessException("Amount", fim.getAmount(),
|
|
|
721 |
"Sum of amount is not less than to MRP");
|
|
|
722 |
}
|
|
|
723 |
|
|
|
724 |
LOGGER.info("fofoOrderItem2" + fofoOrderItem);
|
|
|
725 |
|
| 28190 |
tejbeer |
726 |
} else {
|
|
|
727 |
// TODO below mop condition need to added added
|
|
|
728 |
fofoOrderItem.setSellingPrice(fim.getAmount());
|
| 27861 |
tejbeer |
729 |
}
|
|
|
730 |
|
|
|
731 |
} else {
|
|
|
732 |
fofoOrderItem.setSellingPrice(fim.getAmount());
|
|
|
733 |
LOGGER.info("fofoOrderItem1" + fofoOrderItem);
|
|
|
734 |
|
|
|
735 |
}
|
|
|
736 |
LOGGER.info("fofoOrderItem" + fofoOrderItem);
|
|
|
737 |
|
| 24105 |
govind |
738 |
}
|
|
|
739 |
|
| 27861 |
tejbeer |
740 |
/*
|
|
|
741 |
* for (PaymentOptionTransactionModel paymentOptionTransactionModel :
|
|
|
742 |
* paymentOptionTransactionModels) { amount = amount +
|
|
|
743 |
* paymentOptionTransactionModel.getAmount(); } LOGGER.info("FofoOrder amount" +
|
|
|
744 |
* fofoOrder.getTotalAmount() + "amount" + amount); if (amount ==
|
|
|
745 |
* fofoOrder.getTotalAmount()) {
|
|
|
746 |
*/
|
|
|
747 |
if (paymentOptionTransactionModels.size() > 0) {
|
|
|
748 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
749 |
.selectByReferenceIdAndType(referenceId, PaymentOptionReferenceType.ORDER);
|
|
|
750 |
Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = this
|
|
|
751 |
.paymentOptionIdPaymentOptionTransactionMap(paymentOptionTransactions);
|
|
|
752 |
LOGGER.info(
|
|
|
753 |
"paymentOptionIdPaymentOptionTransactionMap" + paymentOptionIdPaymentOptionTransactionMap.keySet());
|
|
|
754 |
for (PaymentOptionTransactionModel paymentOptionTransactionModel : paymentOptionTransactionModels) {
|
|
|
755 |
if (paymentOptionIdPaymentOptionTransactionMap
|
|
|
756 |
.containsKey(paymentOptionTransactionModel.getPaymentOptionId())) {
|
| 24105 |
govind |
757 |
|
| 27861 |
tejbeer |
758 |
PaymentOptionTransaction paymentOptionTransaction = paymentOptionIdPaymentOptionTransactionMap
|
|
|
759 |
.get(paymentOptionTransactionModel.getPaymentOptionId());
|
| 24105 |
govind |
760 |
|
| 27861 |
tejbeer |
761 |
if (paymentOptionTransactionModel.getAmount() == 0) {
|
|
|
762 |
fofoOrderPaymentOptionRepository.delete(paymentOptionTransaction);
|
|
|
763 |
LOGGER.info("deleted successfully");
|
|
|
764 |
} else {
|
| 24105 |
govind |
765 |
|
| 27861 |
tejbeer |
766 |
paymentOptionTransaction.setAmount(paymentOptionTransactionModel.getAmount());
|
|
|
767 |
fofoOrderPaymentOptionRepository.persist(paymentOptionTransaction);
|
|
|
768 |
LOGGER.info("updated successfully");
|
|
|
769 |
|
| 24105 |
govind |
770 |
}
|
| 27861 |
tejbeer |
771 |
} else {
|
|
|
772 |
if (paymentOptionTransactionModel.getAmount() > 0) {
|
|
|
773 |
PaymentOptionTransaction paymentOptionTransaction = new PaymentOptionTransaction();
|
|
|
774 |
paymentOptionTransaction.setReferenceId(referenceId);
|
|
|
775 |
paymentOptionTransaction.setReferenceType(PaymentOptionReferenceType.ORDER);
|
|
|
776 |
paymentOptionTransaction.setPaymentOptionId(paymentOptionTransactionModel.getPaymentOptionId());
|
|
|
777 |
paymentOptionTransaction.setAmount(paymentOptionTransactionModel.getAmount());
|
|
|
778 |
paymentOptionTransaction.setFofoId(fofoId);
|
|
|
779 |
paymentOptionTransaction.setCreateTimestamp(fofoOrder.getCreateTimestamp());
|
|
|
780 |
fofoOrderPaymentOptionRepository.persist(paymentOptionTransaction);
|
|
|
781 |
LOGGER.info("inserted successfully");
|
|
|
782 |
}
|
| 24105 |
govind |
783 |
}
|
|
|
784 |
|
|
|
785 |
}
|
| 27861 |
tejbeer |
786 |
|
|
|
787 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 24105 |
govind |
788 |
}
|
| 27861 |
tejbeer |
789 |
/*
|
|
|
790 |
* else
|
|
|
791 |
*
|
|
|
792 |
* { throw new ProfitMandiBusinessException("Amount", amount,
|
|
|
793 |
* "Sum of amount is not equal to total amount"); }
|
|
|
794 |
*/
|
| 24105 |
govind |
795 |
|
|
|
796 |
return "response";
|
| 27861 |
tejbeer |
797 |
|
| 24105 |
govind |
798 |
}
|
| 24440 |
amit.gupta |
799 |
|
| 25726 |
amit.gupta |
800 |
private Map<String, List<MobileInsurancePlan>> getPlans(float sellingPrice, int itemId)
|
|
|
801 |
throws ProfitMandiBusinessException {
|
|
|
802 |
try {
|
|
|
803 |
Map<String, List<MobileInsurancePlan>> productDurationPlans = insuranceService.getAllPlans(itemId,
|
|
|
804 |
sellingPrice);
|
|
|
805 |
return productDurationPlans;
|
|
|
806 |
} catch (Exception e) {
|
|
|
807 |
e.printStackTrace();
|
|
|
808 |
throw new ProfitMandiBusinessException("Fetch Insurance Plans", "Insurance",
|
| 26647 |
tejbeer |
809 |
"Could not fetch insurance Plans");
|
| 25726 |
amit.gupta |
810 |
}
|
|
|
811 |
|
| 24440 |
amit.gupta |
812 |
}
|
| 24880 |
govind |
813 |
|
|
|
814 |
@GetMapping("/insuranceDetails")
|
|
|
815 |
public String getInsuranceDetails(HttpServletRequest request,
|
|
|
816 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
817 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
818 |
throws ProfitMandiBusinessException {
|
|
|
819 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
820 |
long size = 0;
|
|
|
821 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerId(loginDetails.getFofoId(),
|
|
|
822 |
offset, limit);
|
|
|
823 |
size = insurancePolicyRepository.selectCountByRetailerId(loginDetails.getFofoId());
|
|
|
824 |
Map<Integer, String> providerPolicyNameAndIdMap = insuranceProviderRepository
|
|
|
825 |
.selectByIds(insurancePolicies.stream().map(x -> x.getProviderId()).collect(Collectors.toSet()))
|
|
|
826 |
.stream().collect(Collectors.toMap(InsuranceProvider::getId, InsuranceProvider::getName));
|
|
|
827 |
if (size < limit) {
|
|
|
828 |
model.addAttribute("end", offset + size);
|
|
|
829 |
} else {
|
|
|
830 |
model.addAttribute("end", offset + limit);
|
|
|
831 |
}
|
|
|
832 |
model.addAttribute("start", offset + 1);
|
|
|
833 |
model.addAttribute("size", size);
|
|
|
834 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
835 |
model.addAttribute("providerPolicyNameAndIdMap", providerPolicyNameAndIdMap);
|
|
|
836 |
return "insurance-details";
|
|
|
837 |
}
|
| 25092 |
amit.gupta |
838 |
|
| 24880 |
govind |
839 |
@GetMapping("/insuranceDetailsPaginated")
|
|
|
840 |
public String getInsuranceDetailsPaginated(HttpServletRequest request,
|
|
|
841 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
842 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
843 |
throws ProfitMandiBusinessException {
|
|
|
844 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
845 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerId(loginDetails.getFofoId(),
|
|
|
846 |
offset, limit);
|
|
|
847 |
Map<Integer, String> providerPolicyNameAndIdMap = insuranceProviderRepository
|
|
|
848 |
.selectByIds(insurancePolicies.stream().map(x -> x.getProviderId()).collect(Collectors.toSet()))
|
|
|
849 |
.stream().collect(Collectors.toMap(InsuranceProvider::getId, InsuranceProvider::getName));
|
|
|
850 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
851 |
model.addAttribute("providerPolicyNameAndIdMap", providerPolicyNameAndIdMap);
|
|
|
852 |
return "insurance-details-paginated";
|
|
|
853 |
}
|
| 26647 |
tejbeer |
854 |
|
|
|
855 |
@GetMapping("/pendingOrders")
|
| 26663 |
tejbeer |
856 |
public String getPendingOrders(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 26647 |
tejbeer |
857 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
858 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
859 |
List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
|
|
|
860 |
.collect(Collectors.toList());
|
|
|
861 |
|
| 27046 |
tejbeer |
862 |
if (isAdmin) {
|
| 26817 |
amit.gupta |
863 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
864 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
865 |
}
|
|
|
866 |
List<PendingOrder> pendingOrders = null;
|
| 26647 |
tejbeer |
867 |
if (isAdmin) {
|
| 27046 |
tejbeer |
868 |
pendingOrders = pendingOrderRepository.selectAllByStatus(OrderStatus.PENDING);
|
| 26647 |
tejbeer |
869 |
} else {
|
| 27046 |
tejbeer |
870 |
pendingOrders = pendingOrderRepository.selectByFofoId(loginDetails.getFofoId(), OrderStatus.PENDING);
|
| 26647 |
tejbeer |
871 |
}
|
| 27046 |
tejbeer |
872 |
|
|
|
873 |
if (!pendingOrders.isEmpty()) {
|
|
|
874 |
List<Integer> customerIds = pendingOrders.stream().map(x -> x.getCustomerId()).collect(Collectors.toList());
|
|
|
875 |
|
|
|
876 |
Map<Integer, Customer> customersMap = customerRepository.selectAllByIds(customerIds).stream()
|
|
|
877 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
878 |
pendingOrders.stream().forEach(x -> {
|
|
|
879 |
x.setCustomer(customersMap.get(x.getCustomerId()));
|
|
|
880 |
});
|
|
|
881 |
|
|
|
882 |
}
|
|
|
883 |
|
| 26817 |
amit.gupta |
884 |
model.addAttribute("pendingOrder", pendingOrders);
|
|
|
885 |
model.addAttribute("isAdmin", isAdmin);
|
| 26647 |
tejbeer |
886 |
return "pending_fofo_order";
|
|
|
887 |
}
|
|
|
888 |
|
|
|
889 |
@GetMapping("/getPendingOrderItem")
|
|
|
890 |
public String getPendingOrderItem(HttpServletRequest request, @RequestParam int orderId, Model model)
|
|
|
891 |
throws ProfitMandiBusinessException {
|
|
|
892 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
893 |
Map<Integer, Item> itemMap = new HashMap<>();
|
|
|
894 |
Map<Integer, CurrentInventorySnapshot> inventoryMap = new HashMap<>();
|
| 26817 |
amit.gupta |
895 |
PendingOrder pendingPO = pendingOrderRepository.selectById(orderId);
|
|
|
896 |
Customer customer = customerRepository.selectById(pendingPO.getCustomerId());
|
| 26647 |
tejbeer |
897 |
List<PendingOrderItem> pendingOrderItems = pendingOrderItemRepository.selectByOrderId(orderId);
|
|
|
898 |
for (PendingOrderItem pendingOrderItem : pendingOrderItems) {
|
|
|
899 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
900 |
CurrentInventorySnapshot cis = currentInventorySnapshotRepository
|
|
|
901 |
.selectByItemAndFofoId(pendingOrderItem.getItemId(), loginDetails.getFofoId());
|
|
|
902 |
itemMap.put(pendingOrderItem.getItemId(), item);
|
|
|
903 |
LOGGER.info("cis" + cis);
|
|
|
904 |
inventoryMap.put(pendingOrderItem.getItemId(), cis);
|
|
|
905 |
}
|
|
|
906 |
|
|
|
907 |
LOGGER.info("inventoryMap" + inventoryMap);
|
|
|
908 |
model.addAttribute("pendingOrderItems", pendingOrderItems);
|
|
|
909 |
model.addAttribute("itemMap", itemMap);
|
|
|
910 |
model.addAttribute("inventoryMap", inventoryMap);
|
| 26817 |
amit.gupta |
911 |
model.addAttribute("pendingPO", gson.toJson(pendingPO));
|
|
|
912 |
model.addAttribute("pendingPOCustomer", gson.toJson(customer));
|
| 26721 |
tejbeer |
913 |
model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 26647 |
tejbeer |
914 |
return "pending-order-item";
|
|
|
915 |
}
|
| 26721 |
tejbeer |
916 |
|
|
|
917 |
@RequestMapping(value = "/cancelPendingOrder", method = RequestMethod.POST)
|
|
|
918 |
public String cancelPendingOrder(HttpServletRequest request, @RequestParam int id, Model model) throws Exception {
|
| 27046 |
tejbeer |
919 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26721 |
tejbeer |
920 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(id);
|
|
|
921 |
|
|
|
922 |
List<PendingOrderItem> pendingOrderItem = pendingOrderItemRepository.selectByOrderId(id);
|
|
|
923 |
for (PendingOrderItem poi : pendingOrderItem) {
|
| 27046 |
tejbeer |
924 |
poi.setStatus(OrderStatus.CANCELLED);
|
|
|
925 |
poi.setStatusDescription(loginDetails.getEmailId());
|
| 26721 |
tejbeer |
926 |
}
|
| 27046 |
tejbeer |
927 |
pendingOrder.setStatus(OrderStatus.CLOSED);
|
| 26721 |
tejbeer |
928 |
|
|
|
929 |
pendingOrderRepository.persist(pendingOrder);
|
|
|
930 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
931 |
|
|
|
932 |
return "response";
|
|
|
933 |
}
|
|
|
934 |
|
|
|
935 |
@RequestMapping(value = "/cancelPendingOrderItem", method = RequestMethod.POST)
|
|
|
936 |
public String cancelPendingOrderItem(HttpServletRequest request, @RequestParam int id, Model model)
|
|
|
937 |
throws Exception {
|
| 27046 |
tejbeer |
938 |
|
|
|
939 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26721 |
tejbeer |
940 |
PendingOrderItem pendingOrderItem = pendingOrderItemRepository.selectById(id);
|
|
|
941 |
|
| 27046 |
tejbeer |
942 |
pendingOrderItem.setStatus(OrderStatus.CANCELLED);
|
|
|
943 |
pendingOrderItem.setStatusDescription(loginDetails.getEmailId());
|
| 27057 |
tejbeer |
944 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(pendingOrderItem.getOrderId());
|
| 26721 |
tejbeer |
945 |
|
| 27046 |
tejbeer |
946 |
List<OrderStatus> status = pendingOrderItemRepository.selectByOrderId(pendingOrderItem.getOrderId()).stream()
|
| 26721 |
tejbeer |
947 |
.map(x -> x.getStatus()).collect(Collectors.toList());
|
|
|
948 |
|
| 27046 |
tejbeer |
949 |
if (!status.contains(OrderStatus.PENDING)) {
|
|
|
950 |
pendingOrder.setStatus(OrderStatus.CLOSED);
|
| 26721 |
tejbeer |
951 |
}
|
|
|
952 |
pendingOrderItemRepository.persist(pendingOrderItem);
|
|
|
953 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
954 |
|
|
|
955 |
return "response";
|
|
|
956 |
}
|
| 27046 |
tejbeer |
957 |
|
| 27819 |
tejbeer |
958 |
@RequestMapping(value = "/cancelOrderByInvoice", method = RequestMethod.POST)
|
|
|
959 |
public String cancelOrder(HttpServletRequest request, @RequestParam List<String> invoiceNumbers, Model model)
|
|
|
960 |
throws Exception {
|
|
|
961 |
orderService.cancelOrder(invoiceNumbers);
|
|
|
962 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
963 |
|
|
|
964 |
return "response";
|
|
|
965 |
}
|
|
|
966 |
|
| 21612 |
ashik.ali |
967 |
}
|