| 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 |
}
|
|
|
378 |
LocalDateTime buyDate = fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS);
|
|
|
379 |
LocalDateTime curDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
|
|
380 |
if (buyDate.isAfter(curDate.minusDays(45))) {
|
|
|
381 |
foi.setDoa(true);
|
|
|
382 |
} else
|
|
|
383 |
foi.setDoa(
|
|
|
384 |
foi.getBrand().equals("Nokia") && foi.getCost() < 4990 && buyDate.isAfter(curDate.minusYears(1)));
|
| 23638 |
amit.gupta |
385 |
}
|
| 23973 |
govind |
386 |
|
| 23638 |
amit.gupta |
387 |
private boolean markDefective(FofoOrder fofoOrder) {
|
| 23973 |
govind |
388 |
return fofoOrder.getCreateTimestamp().truncatedTo(ChronoUnit.DAYS).plusDays(180)
|
|
|
389 |
.isAfter(LocalDateTime.now().truncatedTo(ChronoUnit.DAYS));
|
|
|
390 |
|
| 23638 |
amit.gupta |
391 |
}
|
| 23973 |
govind |
392 |
|
| 23584 |
ashik.ali |
393 |
@RequestMapping(value = "/getSearchOrder")
|
| 23973 |
govind |
394 |
public String getSearchOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 23584 |
ashik.ali |
395 |
return "search-order";
|
|
|
396 |
}
|
| 23973 |
govind |
397 |
|
| 27819 |
tejbeer |
398 |
@RequestMapping(value = "/getInvoiceSearchOrder")
|
|
|
399 |
public String getInvoiceSearchOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
400 |
return "invoices-cancel";
|
|
|
401 |
}
|
|
|
402 |
|
| 23584 |
ashik.ali |
403 |
@RequestMapping(value = "/customerDetails", method = RequestMethod.PUT)
|
| 23973 |
govind |
404 |
public String updateCustomerDetails(HttpServletRequest request, @RequestBody CustomCustomer customCustomer,
|
|
|
405 |
@RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER) String invoiceNumber, Model model)
|
| 24281 |
amit.gupta |
406 |
throws Exception {
|
| 23973 |
govind |
407 |
|
| 23584 |
ashik.ali |
408 |
orderService.updateCustomerDetails(customCustomer, invoiceNumber);
|
|
|
409 |
return this.getSearchOrderDetails(request, invoiceNumber, model);
|
|
|
410 |
}
|
| 23973 |
govind |
411 |
|
| 23584 |
ashik.ali |
412 |
@RequestMapping(value = "/searchOrderDetails", method = RequestMethod.GET)
|
| 23973 |
govind |
413 |
public String getSearchOrderDetails(HttpServletRequest request,
|
|
|
414 |
@RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER) String invoiceNumber, Model model)
|
| 24281 |
amit.gupta |
415 |
throws Exception {
|
| 23973 |
govind |
416 |
|
| 23584 |
ashik.ali |
417 |
FofoOrder fofoOrder = fofoOrderRepository.selectByInvoiceNumber(invoiceNumber);
|
| 24271 |
amit.gupta |
418 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectByOrderId(fofoOrder.getId());
|
| 23584 |
ashik.ali |
419 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
420 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 24105 |
govind |
421 |
List<Integer> fofoPartnerPaymentOptions = fofoPartnerPaymentOptionRepository
|
|
|
422 |
.selectPaymentOptionIdsByFofoId(fofoOrder.getFofoId());
|
| 24276 |
amit.gupta |
423 |
Map<Integer, Item> itemsMap = fofoOrderItems.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> {
|
|
|
424 |
try {
|
|
|
425 |
return itemRepository.selectById(x.getItemId());
|
|
|
426 |
} catch (ProfitMandiBusinessException e) {
|
|
|
427 |
// TODO Auto-generated catch block
|
|
|
428 |
return null;
|
|
|
429 |
}
|
|
|
430 |
}));
|
| 24105 |
govind |
431 |
LOGGER.info("fofoPartnerPaymentOptions" + fofoPartnerPaymentOptions);
|
| 23973 |
govind |
432 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
433 |
.selectByReferenceIdAndType(fofoOrder.getId(), PaymentOptionReferenceType.ORDER);
|
| 24105 |
govind |
434 |
LOGGER.info("paymentOptionTransactions" + paymentOptionTransactions);
|
| 23973 |
govind |
435 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = this
|
| 24105 |
govind |
436 |
.paymentOptionIdPaymentOptionMapUsingPaymentOptions(fofoPartnerPaymentOptions);
|
|
|
437 |
Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = this
|
|
|
438 |
.paymentOptionIdPaymentOptionTransactionMap(paymentOptionTransactions);
|
|
|
439 |
LOGGER.info("paymentOptionIdPaymentOptionTransactionMap" + paymentOptionIdPaymentOptionTransactionMap.keySet());
|
| 23973 |
govind |
440 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository
|
|
|
441 |
.selectByRetailerIdInvoiceNumber(fofoOrder.getFofoId(), fofoOrder.getInvoiceNumber());
|
| 23584 |
ashik.ali |
442 |
this.addInsuranceProvider(insurancePolicies);
|
|
|
443 |
model.addAttribute("fofoOrder", fofoOrder);
|
| 24844 |
amit.gupta |
444 |
for (FofoOrderItem fofoOrderItem : fofoOrderItems) {
|
| 24271 |
amit.gupta |
445 |
fofoOrderItem.setDoa(true);
|
|
|
446 |
}
|
| 24844 |
amit.gupta |
447 |
|
| 24281 |
amit.gupta |
448 |
Map<Integer, Set<FofoLineItem>> fofoOrderItemIdLineItemMap = fofoOrderItems.stream()
|
|
|
449 |
.collect(Collectors.toMap(FofoOrderItem::getId, FofoOrderItem::getFofoLineItems));
|
|
|
450 |
|
|
|
451 |
Map<Integer, List<CustomerReturnItem>> foiIdCustomerReturnInventoryItemsMap = fofoOrderItems.stream()
|
|
|
452 |
.collect(Collectors.toMap(foi -> foi.getId(),
|
|
|
453 |
foi -> customerReturnItemRepository.selectAllByOrderItemId(foi.getId())));
|
|
|
454 |
|
|
|
455 |
Map<Integer, Integer> inventoryItemBilledQtyMap = new HashMap<>();
|
|
|
456 |
|
|
|
457 |
for (FofoOrderItem foi : fofoOrderItems) {
|
|
|
458 |
for (FofoLineItem fli : foi.getFofoLineItems()) {
|
|
|
459 |
inventoryItemBilledQtyMap.put(fli.getInventoryItemId(), fli.getQuantity());
|
|
|
460 |
}
|
|
|
461 |
List<CustomerReturnItem> customerReturnItems = customerReturnItemRepository
|
|
|
462 |
.selectAllByOrderItemId(foi.getId());
|
|
|
463 |
for (CustomerReturnItem customerReturnItem : customerReturnItems) {
|
|
|
464 |
inventoryItemBilledQtyMap.put(customerReturnItem.getInventoryItemId(),
|
|
|
465 |
inventoryItemBilledQtyMap.get(customerReturnItem.getInventoryItemId()) - 1);
|
|
|
466 |
}
|
|
|
467 |
}
|
|
|
468 |
model.addAttribute("foiIdCustomerReturnInventoryItemsMap",
|
|
|
469 |
StringUtils.toString(foiIdCustomerReturnInventoryItemsMap));
|
| 24271 |
amit.gupta |
470 |
model.addAttribute("fofoOrderItems", fofoOrderItems);
|
| 24281 |
amit.gupta |
471 |
model.addAttribute("inventoryItemBilledQtyMap", StringUtils.toString(inventoryItemBilledQtyMap));
|
|
|
472 |
model.addAttribute("fofoOrderItemIdLineItemsMap", StringUtils.toString(fofoOrderItemIdLineItemMap));
|
| 24276 |
amit.gupta |
473 |
model.addAttribute("itemsMap", itemsMap);
|
| 24271 |
amit.gupta |
474 |
model.addAttribute("markDefective", true);
|
| 23584 |
ashik.ali |
475 |
model.addAttribute("customer", customer);
|
|
|
476 |
model.addAttribute("customerAddress", customerAddress);
|
|
|
477 |
model.addAttribute("paymentOptionTransactions", paymentOptionTransactions);
|
|
|
478 |
model.addAttribute("paymentOptionIdPaymentOptionMap", paymentOptionIdPaymentOptionMap);
|
| 24105 |
govind |
479 |
model.addAttribute("paymentOptionIdPaymentOptionTransactionMap", paymentOptionIdPaymentOptionTransactionMap);
|
| 23584 |
ashik.ali |
480 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
| 24105 |
govind |
481 |
model.addAttribute("fofoPartnerPaymentOptions", fofoPartnerPaymentOptions);
|
|
|
482 |
model.addAttribute("totalNumberOfPaymentOptionId", fofoPartnerPaymentOptions.size());
|
| 24844 |
amit.gupta |
483 |
model.addAttribute("stateNames",
|
|
|
484 |
stateRepository.selectAll().stream().map(x -> x.getName()).collect(Collectors.toList()));
|
| 23584 |
ashik.ali |
485 |
return "search-order-details";
|
|
|
486 |
}
|
| 23973 |
govind |
487 |
|
|
|
488 |
private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap(
|
|
|
489 |
List<PaymentOptionTransaction> paymentOptionTransactions) {
|
| 23366 |
ashik.ali |
490 |
Set<Integer> paymentOptionIds = new HashSet<>();
|
| 23973 |
govind |
491 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
| 23548 |
ashik.ali |
492 |
paymentOptionIds.add(paymentOptionTransaction.getPaymentOptionId());
|
| 23366 |
ashik.ali |
493 |
}
|
|
|
494 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByIds(paymentOptionIds);
|
|
|
495 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = new HashMap<>();
|
| 23973 |
govind |
496 |
for (PaymentOption paymentOption : paymentOptions) {
|
| 23366 |
ashik.ali |
497 |
paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
|
|
|
498 |
}
|
|
|
499 |
return paymentOptionIdPaymentOptionMap;
|
|
|
500 |
}
|
| 23973 |
govind |
501 |
|
| 24105 |
govind |
502 |
private Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMapUsingPaymentOptions(
|
|
|
503 |
List<Integer> fofoPartnerPaymentOptions) {
|
|
|
504 |
List<PaymentOption> paymentOptions = paymentOptionRepository
|
|
|
505 |
.selectByIds(new HashSet<>(fofoPartnerPaymentOptions));
|
|
|
506 |
Map<Integer, PaymentOption> paymentOptionIdPaymentOptionMap = new HashMap<>();
|
|
|
507 |
for (PaymentOption paymentOption : paymentOptions) {
|
|
|
508 |
paymentOptionIdPaymentOptionMap.put(paymentOption.getId(), paymentOption);
|
|
|
509 |
}
|
|
|
510 |
return paymentOptionIdPaymentOptionMap;
|
|
|
511 |
}
|
|
|
512 |
|
|
|
513 |
private Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap(
|
|
|
514 |
List<PaymentOptionTransaction> paymentOptionTransactions) {
|
|
|
515 |
Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = new HashMap<>();
|
|
|
516 |
for (PaymentOptionTransaction paymentOptionTransaction : paymentOptionTransactions) {
|
|
|
517 |
paymentOptionIdPaymentOptionTransactionMap.put(paymentOptionTransaction.getPaymentOptionId(),
|
|
|
518 |
paymentOptionTransaction);
|
|
|
519 |
}
|
|
|
520 |
return paymentOptionIdPaymentOptionTransactionMap;
|
|
|
521 |
}
|
|
|
522 |
|
| 21985 |
kshitij.so |
523 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
| 23973 |
govind |
524 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest,
|
|
|
525 |
Model model) throws ProfitMandiBusinessException {
|
| 26647 |
tejbeer |
526 |
// throw new ProfitMandiBusinessException("Billing is on hold temporarily",
|
|
|
527 |
// "Billing is on hold temporarily", "Billing is on hold temporarily");
|
| 26531 |
amit.gupta |
528 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), createOrderRequest);
|
| 22927 |
ashik.ali |
529 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
530 |
|
| 23823 |
amit.gupta |
531 |
int fofoOrderId = orderService.createOrder(createOrderRequest, fofoDetails.getFofoId(), accessoriesDeals);
|
| 22280 |
ashik.ali |
532 |
LOGGER.info("Order has been created successfully...");
|
| 26531 |
amit.gupta |
533 |
return "redirect:/get-order/?orderId=" + fofoOrderId;
|
| 21612 |
ashik.ali |
534 |
}
|
| 23973 |
govind |
535 |
|
| 23638 |
amit.gupta |
536 |
@RequestMapping(value = "/order/bad_return", method = RequestMethod.POST)
|
| 23973 |
govind |
537 |
public ResponseEntity<?> badReturn(HttpServletRequest request, @RequestBody FoiBadReturnRequest foiBadReturnRequest,
|
|
|
538 |
Model model) throws ProfitMandiBusinessException {
|
| 23638 |
amit.gupta |
539 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), foiBadReturnRequest);
|
|
|
540 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 24282 |
amit.gupta |
541 |
CustomerCreditNote custmoerCreditNote;
|
| 24844 |
amit.gupta |
542 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 24282 |
amit.gupta |
543 |
FofoOrderItem foi = fofoOrderItemRepository.selectById(foiBadReturnRequest.getFofoOrderItemId());
|
|
|
544 |
FofoOrder fo = fofoOrderRepository.selectByOrderId(foi.getOrderId());
|
|
|
545 |
custmoerCreditNote = orderService.badReturn(fo.getFofoId(), foiBadReturnRequest);
|
|
|
546 |
} else {
|
|
|
547 |
custmoerCreditNote = orderService.badReturn(fofoDetails.getFofoId(), foiBadReturnRequest);
|
|
|
548 |
}
|
| 23654 |
amit.gupta |
549 |
return responseSender.ok(custmoerCreditNote.getId());
|
| 23638 |
amit.gupta |
550 |
}
|
| 21985 |
kshitij.so |
551 |
|
| 21689 |
ashik.ali |
552 |
@RequestMapping(value = "/generateInvoice")
|
| 23973 |
govind |
553 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
|
|
554 |
@RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws ProfitMandiBusinessException {
|
|
|
555 |
LOGGER.info("Request received at url {} with params [{}={}] ", request.getRequestURI(),
|
|
|
556 |
ProfitMandiConstants.ORDER_ID, orderId);
|
| 22139 |
amit.gupta |
557 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23594 |
ashik.ali |
558 |
PdfModel pdfModel = null;
|
| 23973 |
govind |
559 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 23594 |
ashik.ali |
560 |
pdfModel = orderService.getInvoicePdfModel(orderId);
|
| 23973 |
govind |
561 |
} else {
|
| 23594 |
ashik.ali |
562 |
pdfModel = orderService.getInvoicePdfModel(fofoDetails.getFofoId(), orderId);
|
|
|
563 |
}
|
| 21689 |
ashik.ali |
564 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 24844 |
amit.gupta |
565 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
| 21689 |
ashik.ali |
566 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 23973 |
govind |
567 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
568 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
569 |
headers.set("Content-disposition", "inline; filename=invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
|
|
570 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
571 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
572 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
573 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 21689 |
ashik.ali |
574 |
}
|
| 23973 |
govind |
575 |
|
| 24844 |
amit.gupta |
576 |
@RequestMapping(value = "/generateInvoices")
|
|
|
577 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
|
|
578 |
@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, @RequestParam int partnerId)
|
|
|
579 |
throws ProfitMandiBusinessException {
|
|
|
580 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
581 |
List<PdfModel> pdfModels = new ArrayList<>();
|
|
|
582 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
|
|
583 |
List<Integer> orderIds = fofoOrderRepository.selectByFofoId(partnerId, startDate, endDate, 0, 0).stream()
|
|
|
584 |
.map(x -> x.getId()).collect(Collectors.toList());
|
|
|
585 |
for (int orderId : orderIds) {
|
|
|
586 |
pdfModels.add(orderService.getInvoicePdfModel(orderId));
|
|
|
587 |
}
|
|
|
588 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
589 |
PdfUtils.generateAndWrite(pdfModels, byteArrayOutputStream);
|
|
|
590 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
|
|
591 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
592 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
593 |
headers.set("Content-disposition", "inline; filename=invoice-" + partnerId + ".pdf");
|
|
|
594 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
595 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
596 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
597 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
598 |
} else {
|
|
|
599 |
throw new ProfitMandiBusinessException("Auth", fofoDetails.getEmailId(), "Unauthorised access");
|
|
|
600 |
}
|
|
|
601 |
}
|
|
|
602 |
|
| 22244 |
ashik.ali |
603 |
@RequestMapping(value = "/saleHistory")
|
| 23973 |
govind |
604 |
public String saleHistory(HttpServletRequest request,
|
|
|
605 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
606 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
607 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
608 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
609 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
610 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
611 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
612 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
613 |
|
|
|
614 |
Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue,
|
|
|
615 |
startTime, endTime, offset, limit);
|
| 23203 |
ashik.ali |
616 |
model.addAllAttributes(map);
|
| 22244 |
ashik.ali |
617 |
return "sale-history";
|
|
|
618 |
}
|
| 23973 |
govind |
619 |
|
| 25092 |
amit.gupta |
620 |
@RequestMapping(value = "/downloadInvoices")
|
|
|
621 |
public ResponseEntity<?> downloadInvoices(HttpServletRequest request,
|
|
|
622 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
623 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
624 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
625 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
626 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
627 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
628 |
throws ProfitMandiBusinessException {
|
|
|
629 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
630 |
|
|
|
631 |
Map<String, Object> map = orderService.getSaleHistory(loginDetails.getFofoId(), searchType, searchValue,
|
|
|
632 |
startTime, endTime, offset, 100);
|
| 25562 |
amit.gupta |
633 |
List<FofoOrder> fofoOrders = (List<FofoOrder>) map.get("saleHistories");
|
| 25092 |
amit.gupta |
634 |
|
| 25562 |
amit.gupta |
635 |
if (fofoOrders.size() == 0) {
|
| 25092 |
amit.gupta |
636 |
throw new ProfitMandiBusinessException("Search criteria", "", "No orders found for criteria");
|
|
|
637 |
}
|
|
|
638 |
|
| 25093 |
amit.gupta |
639 |
final HttpHeaders headers = new HttpHeaders();
|
| 25092 |
amit.gupta |
640 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
641 |
headers.set("Content-disposition", "inline; filename=invoices.pdf");
|
|
|
642 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
643 |
List<PdfModel> pdfModels = new ArrayList<>();
|
| 25562 |
amit.gupta |
644 |
for (FofoOrder fofoOrder : fofoOrders) {
|
| 25092 |
amit.gupta |
645 |
try {
|
|
|
646 |
pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId()));
|
| 25606 |
tejbeer |
647 |
} catch (Exception e) {
|
|
|
648 |
LOGGER.info("could not create invoice for {}, invoice number {}", fofoOrder.getId(),
|
|
|
649 |
fofoOrder.getInvoiceNumber());
|
| 25092 |
amit.gupta |
650 |
}
|
|
|
651 |
}
|
|
|
652 |
PdfUtils.generateAndWrite(pdfModels, byteArrayOutputStream);
|
|
|
653 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
654 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
655 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
656 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
657 |
}
|
|
|
658 |
|
| 23973 |
govind |
659 |
@RequestMapping(value = "/credit-note/{creditNoteId}")
|
|
|
660 |
public ResponseEntity<?> downloadCreditNote(HttpServletRequest request, @PathVariable int creditNoteId)
|
|
|
661 |
throws ProfitMandiBusinessException {
|
| 23654 |
amit.gupta |
662 |
CreditNotePdfModel creditNotePdfModel = orderService.getCreditNotePdfModel(creditNoteId);
|
|
|
663 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
664 |
PdfUtils.generateAndWriteCustomerCreditNotes(Arrays.asList(creditNotePdfModel), byteArrayOutputStream);
|
|
|
665 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 23973 |
govind |
666 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
667 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
668 |
headers.set("Content-disposition",
|
|
|
669 |
"inline; filename=invoice-" + creditNotePdfModel.getCreditNoteNumber() + ".pdf");
|
|
|
670 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
671 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
672 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
673 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 23654 |
amit.gupta |
674 |
}
|
| 23973 |
govind |
675 |
|
| 22291 |
ashik.ali |
676 |
@RequestMapping(value = "/getPaginatedSaleHistory")
|
| 23973 |
govind |
677 |
public String getSaleHistoryPaginated(HttpServletRequest request,
|
|
|
678 |
@RequestParam(name = "searchValue", defaultValue = "") String searchValue,
|
|
|
679 |
@RequestParam(name = "searchType", defaultValue = "") SearchType searchType,
|
|
|
680 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
681 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
682 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
683 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
684 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
685 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23973 |
govind |
686 |
Map<String, Object> map = orderService.getSaleHistoryPaginated(loginDetails.getFofoId(), searchType,
|
|
|
687 |
searchValue, startTime, endTime, offset, limit);
|
| 23203 |
ashik.ali |
688 |
model.addAllAttributes(map);
|
| 22291 |
ashik.ali |
689 |
return "sale-history-paginated";
|
|
|
690 |
}
|
|
|
691 |
|
| 24105 |
govind |
692 |
@PutMapping(value = "/updatePaymentTransaction")
|
|
|
693 |
public String updateTransactionDetails(HttpServletRequest request, @RequestParam String referenceType,
|
|
|
694 |
@RequestParam int fofoId, @RequestParam int referenceId,
|
| 27861 |
tejbeer |
695 |
@RequestBody PartnerOptionsAndItemAmountModel partnerOptionsAndItemAmountModel,
|
| 28055 |
tejbeer |
696 |
@RequestParam float totalAmount, Model model) throws Exception {
|
| 27861 |
tejbeer |
697 |
|
|
|
698 |
List<PaymentOptionTransactionModel> paymentOptionTransactionModels = partnerOptionsAndItemAmountModel
|
|
|
699 |
.getPaymentOptionTransactionModel();
|
| 24105 |
govind |
700 |
LOGGER.info(paymentOptionTransactionModels);
|
| 27861 |
tejbeer |
701 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoId, referenceId);
|
|
|
702 |
LOGGER.info("sdssd" + fofoOrder);
|
|
|
703 |
fofoOrder.setTotalAmount(totalAmount);
|
|
|
704 |
List<FofoItemIdAmountModel> fofoItemIdAmountModel = partnerOptionsAndItemAmountModel.getItemAmountModel();
|
|
|
705 |
for (FofoItemIdAmountModel fim : fofoItemIdAmountModel) {
|
|
|
706 |
LOGGER.info("fim" + fim.getFofoItemId());
|
|
|
707 |
Item item = itemRepository.selectById(fim.getItemId());
|
|
|
708 |
TagListing tagListing = tagListingRepository.selectByItemId(item.getId());
|
|
|
709 |
FofoOrderItem fofoOrderItem = fofoOrderItemRepository.selectById(fim.getFofoItemId());
|
| 28188 |
tejbeer |
710 |
LOGGER.info("category" + item.getCategoryId());
|
|
|
711 |
if (item.getCategoryId() == ProfitMandiConstants.MOBILE_CATEGORY_ID) {
|
| 27861 |
tejbeer |
712 |
if (fofoOrderItem.getMop() >= fim.getAmount()) {
|
|
|
713 |
|
| 28131 |
tejbeer |
714 |
if (fim.getAmount() <= tagListing.getMrp()) {
|
| 27861 |
tejbeer |
715 |
fofoOrderItem.setSellingPrice(fim.getAmount());
|
|
|
716 |
} else {
|
|
|
717 |
throw new ProfitMandiBusinessException("Amount", fim.getAmount(),
|
|
|
718 |
"Sum of amount is not less than to MRP");
|
|
|
719 |
}
|
|
|
720 |
|
|
|
721 |
LOGGER.info("fofoOrderItem2" + fofoOrderItem);
|
|
|
722 |
|
|
|
723 |
}
|
|
|
724 |
|
|
|
725 |
} else {
|
|
|
726 |
fofoOrderItem.setSellingPrice(fim.getAmount());
|
|
|
727 |
LOGGER.info("fofoOrderItem1" + fofoOrderItem);
|
|
|
728 |
|
|
|
729 |
}
|
|
|
730 |
LOGGER.info("fofoOrderItem" + fofoOrderItem);
|
|
|
731 |
|
| 24105 |
govind |
732 |
}
|
|
|
733 |
|
| 27861 |
tejbeer |
734 |
/*
|
|
|
735 |
* for (PaymentOptionTransactionModel paymentOptionTransactionModel :
|
|
|
736 |
* paymentOptionTransactionModels) { amount = amount +
|
|
|
737 |
* paymentOptionTransactionModel.getAmount(); } LOGGER.info("FofoOrder amount" +
|
|
|
738 |
* fofoOrder.getTotalAmount() + "amount" + amount); if (amount ==
|
|
|
739 |
* fofoOrder.getTotalAmount()) {
|
|
|
740 |
*/
|
|
|
741 |
if (paymentOptionTransactionModels.size() > 0) {
|
|
|
742 |
List<PaymentOptionTransaction> paymentOptionTransactions = fofoOrderPaymentOptionRepository
|
|
|
743 |
.selectByReferenceIdAndType(referenceId, PaymentOptionReferenceType.ORDER);
|
|
|
744 |
Map<Integer, PaymentOptionTransaction> paymentOptionIdPaymentOptionTransactionMap = this
|
|
|
745 |
.paymentOptionIdPaymentOptionTransactionMap(paymentOptionTransactions);
|
|
|
746 |
LOGGER.info(
|
|
|
747 |
"paymentOptionIdPaymentOptionTransactionMap" + paymentOptionIdPaymentOptionTransactionMap.keySet());
|
|
|
748 |
for (PaymentOptionTransactionModel paymentOptionTransactionModel : paymentOptionTransactionModels) {
|
|
|
749 |
if (paymentOptionIdPaymentOptionTransactionMap
|
|
|
750 |
.containsKey(paymentOptionTransactionModel.getPaymentOptionId())) {
|
| 24105 |
govind |
751 |
|
| 27861 |
tejbeer |
752 |
PaymentOptionTransaction paymentOptionTransaction = paymentOptionIdPaymentOptionTransactionMap
|
|
|
753 |
.get(paymentOptionTransactionModel.getPaymentOptionId());
|
| 24105 |
govind |
754 |
|
| 27861 |
tejbeer |
755 |
if (paymentOptionTransactionModel.getAmount() == 0) {
|
|
|
756 |
fofoOrderPaymentOptionRepository.delete(paymentOptionTransaction);
|
|
|
757 |
LOGGER.info("deleted successfully");
|
|
|
758 |
} else {
|
| 24105 |
govind |
759 |
|
| 27861 |
tejbeer |
760 |
paymentOptionTransaction.setAmount(paymentOptionTransactionModel.getAmount());
|
|
|
761 |
fofoOrderPaymentOptionRepository.persist(paymentOptionTransaction);
|
|
|
762 |
LOGGER.info("updated successfully");
|
|
|
763 |
|
| 24105 |
govind |
764 |
}
|
| 27861 |
tejbeer |
765 |
} else {
|
|
|
766 |
if (paymentOptionTransactionModel.getAmount() > 0) {
|
|
|
767 |
PaymentOptionTransaction paymentOptionTransaction = new PaymentOptionTransaction();
|
|
|
768 |
paymentOptionTransaction.setReferenceId(referenceId);
|
|
|
769 |
paymentOptionTransaction.setReferenceType(PaymentOptionReferenceType.ORDER);
|
|
|
770 |
paymentOptionTransaction.setPaymentOptionId(paymentOptionTransactionModel.getPaymentOptionId());
|
|
|
771 |
paymentOptionTransaction.setAmount(paymentOptionTransactionModel.getAmount());
|
|
|
772 |
paymentOptionTransaction.setFofoId(fofoId);
|
|
|
773 |
paymentOptionTransaction.setCreateTimestamp(fofoOrder.getCreateTimestamp());
|
|
|
774 |
fofoOrderPaymentOptionRepository.persist(paymentOptionTransaction);
|
|
|
775 |
LOGGER.info("inserted successfully");
|
|
|
776 |
}
|
| 24105 |
govind |
777 |
}
|
|
|
778 |
|
|
|
779 |
}
|
| 27861 |
tejbeer |
780 |
|
|
|
781 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 24105 |
govind |
782 |
}
|
| 27861 |
tejbeer |
783 |
/*
|
|
|
784 |
* else
|
|
|
785 |
*
|
|
|
786 |
* { throw new ProfitMandiBusinessException("Amount", amount,
|
|
|
787 |
* "Sum of amount is not equal to total amount"); }
|
|
|
788 |
*/
|
| 24105 |
govind |
789 |
|
|
|
790 |
return "response";
|
| 27861 |
tejbeer |
791 |
|
| 24105 |
govind |
792 |
}
|
| 24440 |
amit.gupta |
793 |
|
| 25726 |
amit.gupta |
794 |
private Map<String, List<MobileInsurancePlan>> getPlans(float sellingPrice, int itemId)
|
|
|
795 |
throws ProfitMandiBusinessException {
|
|
|
796 |
try {
|
|
|
797 |
Map<String, List<MobileInsurancePlan>> productDurationPlans = insuranceService.getAllPlans(itemId,
|
|
|
798 |
sellingPrice);
|
|
|
799 |
return productDurationPlans;
|
|
|
800 |
} catch (Exception e) {
|
|
|
801 |
e.printStackTrace();
|
|
|
802 |
throw new ProfitMandiBusinessException("Fetch Insurance Plans", "Insurance",
|
| 26647 |
tejbeer |
803 |
"Could not fetch insurance Plans");
|
| 25726 |
amit.gupta |
804 |
}
|
|
|
805 |
|
| 24440 |
amit.gupta |
806 |
}
|
| 24880 |
govind |
807 |
|
|
|
808 |
@GetMapping("/insuranceDetails")
|
|
|
809 |
public String getInsuranceDetails(HttpServletRequest request,
|
|
|
810 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
811 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
812 |
throws ProfitMandiBusinessException {
|
|
|
813 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
814 |
long size = 0;
|
|
|
815 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerId(loginDetails.getFofoId(),
|
|
|
816 |
offset, limit);
|
|
|
817 |
size = insurancePolicyRepository.selectCountByRetailerId(loginDetails.getFofoId());
|
|
|
818 |
Map<Integer, String> providerPolicyNameAndIdMap = insuranceProviderRepository
|
|
|
819 |
.selectByIds(insurancePolicies.stream().map(x -> x.getProviderId()).collect(Collectors.toSet()))
|
|
|
820 |
.stream().collect(Collectors.toMap(InsuranceProvider::getId, InsuranceProvider::getName));
|
|
|
821 |
if (size < limit) {
|
|
|
822 |
model.addAttribute("end", offset + size);
|
|
|
823 |
} else {
|
|
|
824 |
model.addAttribute("end", offset + limit);
|
|
|
825 |
}
|
|
|
826 |
model.addAttribute("start", offset + 1);
|
|
|
827 |
model.addAttribute("size", size);
|
|
|
828 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
829 |
model.addAttribute("providerPolicyNameAndIdMap", providerPolicyNameAndIdMap);
|
|
|
830 |
return "insurance-details";
|
|
|
831 |
}
|
| 25092 |
amit.gupta |
832 |
|
| 24880 |
govind |
833 |
@GetMapping("/insuranceDetailsPaginated")
|
|
|
834 |
public String getInsuranceDetailsPaginated(HttpServletRequest request,
|
|
|
835 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
836 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
837 |
throws ProfitMandiBusinessException {
|
|
|
838 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
839 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerId(loginDetails.getFofoId(),
|
|
|
840 |
offset, limit);
|
|
|
841 |
Map<Integer, String> providerPolicyNameAndIdMap = insuranceProviderRepository
|
|
|
842 |
.selectByIds(insurancePolicies.stream().map(x -> x.getProviderId()).collect(Collectors.toSet()))
|
|
|
843 |
.stream().collect(Collectors.toMap(InsuranceProvider::getId, InsuranceProvider::getName));
|
|
|
844 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
845 |
model.addAttribute("providerPolicyNameAndIdMap", providerPolicyNameAndIdMap);
|
|
|
846 |
return "insurance-details-paginated";
|
|
|
847 |
}
|
| 26647 |
tejbeer |
848 |
|
|
|
849 |
@GetMapping("/pendingOrders")
|
| 26663 |
tejbeer |
850 |
public String getPendingOrders(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 26647 |
tejbeer |
851 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
852 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
853 |
List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
|
|
|
854 |
.collect(Collectors.toList());
|
|
|
855 |
|
| 27046 |
tejbeer |
856 |
if (isAdmin) {
|
| 26817 |
amit.gupta |
857 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
858 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
859 |
}
|
|
|
860 |
List<PendingOrder> pendingOrders = null;
|
| 26647 |
tejbeer |
861 |
if (isAdmin) {
|
| 27046 |
tejbeer |
862 |
pendingOrders = pendingOrderRepository.selectAllByStatus(OrderStatus.PENDING);
|
| 26647 |
tejbeer |
863 |
} else {
|
| 27046 |
tejbeer |
864 |
pendingOrders = pendingOrderRepository.selectByFofoId(loginDetails.getFofoId(), OrderStatus.PENDING);
|
| 26647 |
tejbeer |
865 |
}
|
| 27046 |
tejbeer |
866 |
|
|
|
867 |
if (!pendingOrders.isEmpty()) {
|
|
|
868 |
List<Integer> customerIds = pendingOrders.stream().map(x -> x.getCustomerId()).collect(Collectors.toList());
|
|
|
869 |
|
|
|
870 |
Map<Integer, Customer> customersMap = customerRepository.selectAllByIds(customerIds).stream()
|
|
|
871 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
872 |
pendingOrders.stream().forEach(x -> {
|
|
|
873 |
x.setCustomer(customersMap.get(x.getCustomerId()));
|
|
|
874 |
});
|
|
|
875 |
|
|
|
876 |
}
|
|
|
877 |
|
| 26817 |
amit.gupta |
878 |
model.addAttribute("pendingOrder", pendingOrders);
|
|
|
879 |
model.addAttribute("isAdmin", isAdmin);
|
| 26647 |
tejbeer |
880 |
return "pending_fofo_order";
|
|
|
881 |
}
|
|
|
882 |
|
|
|
883 |
@GetMapping("/getPendingOrderItem")
|
|
|
884 |
public String getPendingOrderItem(HttpServletRequest request, @RequestParam int orderId, Model model)
|
|
|
885 |
throws ProfitMandiBusinessException {
|
|
|
886 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
887 |
Map<Integer, Item> itemMap = new HashMap<>();
|
|
|
888 |
Map<Integer, CurrentInventorySnapshot> inventoryMap = new HashMap<>();
|
| 26817 |
amit.gupta |
889 |
PendingOrder pendingPO = pendingOrderRepository.selectById(orderId);
|
|
|
890 |
Customer customer = customerRepository.selectById(pendingPO.getCustomerId());
|
| 26647 |
tejbeer |
891 |
List<PendingOrderItem> pendingOrderItems = pendingOrderItemRepository.selectByOrderId(orderId);
|
|
|
892 |
for (PendingOrderItem pendingOrderItem : pendingOrderItems) {
|
|
|
893 |
Item item = itemRepository.selectById(pendingOrderItem.getItemId());
|
|
|
894 |
CurrentInventorySnapshot cis = currentInventorySnapshotRepository
|
|
|
895 |
.selectByItemAndFofoId(pendingOrderItem.getItemId(), loginDetails.getFofoId());
|
|
|
896 |
itemMap.put(pendingOrderItem.getItemId(), item);
|
|
|
897 |
LOGGER.info("cis" + cis);
|
|
|
898 |
inventoryMap.put(pendingOrderItem.getItemId(), cis);
|
|
|
899 |
}
|
|
|
900 |
|
|
|
901 |
LOGGER.info("inventoryMap" + inventoryMap);
|
|
|
902 |
model.addAttribute("pendingOrderItems", pendingOrderItems);
|
|
|
903 |
model.addAttribute("itemMap", itemMap);
|
|
|
904 |
model.addAttribute("inventoryMap", inventoryMap);
|
| 26817 |
amit.gupta |
905 |
model.addAttribute("pendingPO", gson.toJson(pendingPO));
|
|
|
906 |
model.addAttribute("pendingPOCustomer", gson.toJson(customer));
|
| 26721 |
tejbeer |
907 |
model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 26647 |
tejbeer |
908 |
return "pending-order-item";
|
|
|
909 |
}
|
| 26721 |
tejbeer |
910 |
|
|
|
911 |
@RequestMapping(value = "/cancelPendingOrder", method = RequestMethod.POST)
|
|
|
912 |
public String cancelPendingOrder(HttpServletRequest request, @RequestParam int id, Model model) throws Exception {
|
| 27046 |
tejbeer |
913 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26721 |
tejbeer |
914 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(id);
|
|
|
915 |
|
|
|
916 |
List<PendingOrderItem> pendingOrderItem = pendingOrderItemRepository.selectByOrderId(id);
|
|
|
917 |
for (PendingOrderItem poi : pendingOrderItem) {
|
| 27046 |
tejbeer |
918 |
poi.setStatus(OrderStatus.CANCELLED);
|
|
|
919 |
poi.setStatusDescription(loginDetails.getEmailId());
|
| 26721 |
tejbeer |
920 |
}
|
| 27046 |
tejbeer |
921 |
pendingOrder.setStatus(OrderStatus.CLOSED);
|
| 26721 |
tejbeer |
922 |
|
|
|
923 |
pendingOrderRepository.persist(pendingOrder);
|
|
|
924 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
925 |
|
|
|
926 |
return "response";
|
|
|
927 |
}
|
|
|
928 |
|
|
|
929 |
@RequestMapping(value = "/cancelPendingOrderItem", method = RequestMethod.POST)
|
|
|
930 |
public String cancelPendingOrderItem(HttpServletRequest request, @RequestParam int id, Model model)
|
|
|
931 |
throws Exception {
|
| 27046 |
tejbeer |
932 |
|
|
|
933 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 26721 |
tejbeer |
934 |
PendingOrderItem pendingOrderItem = pendingOrderItemRepository.selectById(id);
|
|
|
935 |
|
| 27046 |
tejbeer |
936 |
pendingOrderItem.setStatus(OrderStatus.CANCELLED);
|
|
|
937 |
pendingOrderItem.setStatusDescription(loginDetails.getEmailId());
|
| 27057 |
tejbeer |
938 |
PendingOrder pendingOrder = pendingOrderRepository.selectById(pendingOrderItem.getOrderId());
|
| 26721 |
tejbeer |
939 |
|
| 27046 |
tejbeer |
940 |
List<OrderStatus> status = pendingOrderItemRepository.selectByOrderId(pendingOrderItem.getOrderId()).stream()
|
| 26721 |
tejbeer |
941 |
.map(x -> x.getStatus()).collect(Collectors.toList());
|
|
|
942 |
|
| 27046 |
tejbeer |
943 |
if (!status.contains(OrderStatus.PENDING)) {
|
|
|
944 |
pendingOrder.setStatus(OrderStatus.CLOSED);
|
| 26721 |
tejbeer |
945 |
}
|
|
|
946 |
pendingOrderItemRepository.persist(pendingOrderItem);
|
|
|
947 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
948 |
|
|
|
949 |
return "response";
|
|
|
950 |
}
|
| 27046 |
tejbeer |
951 |
|
| 27819 |
tejbeer |
952 |
@RequestMapping(value = "/cancelOrderByInvoice", method = RequestMethod.POST)
|
|
|
953 |
public String cancelOrder(HttpServletRequest request, @RequestParam List<String> invoiceNumbers, Model model)
|
|
|
954 |
throws Exception {
|
|
|
955 |
orderService.cancelOrder(invoiceNumbers);
|
|
|
956 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
957 |
|
|
|
958 |
return "response";
|
|
|
959 |
}
|
|
|
960 |
|
| 21612 |
ashik.ali |
961 |
}
|