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