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