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