| 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;
|
| 22217 |
ashik.ali |
6 |
import java.time.DateTimeException;
|
|
|
7 |
import java.time.LocalDate;
|
| 22244 |
ashik.ali |
8 |
import java.time.LocalDateTime;
|
| 21680 |
ashik.ali |
9 |
import java.util.ArrayList;
|
| 21985 |
kshitij.so |
10 |
import java.util.Collection;
|
| 21680 |
ashik.ali |
11 |
import java.util.HashMap;
|
| 21612 |
ashik.ali |
12 |
import java.util.HashSet;
|
| 21985 |
kshitij.so |
13 |
import java.util.Iterator;
|
| 21680 |
ashik.ali |
14 |
import java.util.List;
|
|
|
15 |
import java.util.Map;
|
| 21612 |
ashik.ali |
16 |
import java.util.Set;
|
|
|
17 |
|
|
|
18 |
import javax.servlet.http.HttpServletRequest;
|
| 21689 |
ashik.ali |
19 |
import javax.servlet.http.HttpServletResponse;
|
| 21612 |
ashik.ali |
20 |
|
| 21985 |
kshitij.so |
21 |
import org.json.JSONObject;
|
| 21612 |
ashik.ali |
22 |
import org.slf4j.Logger;
|
|
|
23 |
import org.slf4j.LoggerFactory;
|
|
|
24 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21689 |
ashik.ali |
25 |
import org.springframework.core.io.InputStreamResource;
|
|
|
26 |
import org.springframework.http.HttpHeaders;
|
|
|
27 |
import org.springframework.http.HttpStatus;
|
|
|
28 |
import org.springframework.http.MediaType;
|
|
|
29 |
import org.springframework.http.ResponseEntity;
|
| 21612 |
ashik.ali |
30 |
import org.springframework.stereotype.Controller;
|
| 22064 |
ashik.ali |
31 |
import org.springframework.transaction.annotation.Transactional;
|
| 21985 |
kshitij.so |
32 |
import org.springframework.ui.Model;
|
| 21612 |
ashik.ali |
33 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
34 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
35 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21689 |
ashik.ali |
36 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21612 |
ashik.ali |
37 |
|
|
|
38 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21985 |
kshitij.so |
39 |
import com.spice.profitmandi.common.model.CartFofo;
|
| 21680 |
ashik.ali |
40 |
import com.spice.profitmandi.common.model.CustomAddress;
|
| 21689 |
ashik.ali |
41 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
|
|
42 |
import com.spice.profitmandi.common.model.CustomFofoLineItem;
|
|
|
43 |
import com.spice.profitmandi.common.model.CustomFofoOrderItem;
|
| 22217 |
ashik.ali |
44 |
import com.spice.profitmandi.common.model.CustomInsurancePolicy;
|
| 21689 |
ashik.ali |
45 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 22217 |
ashik.ali |
46 |
import com.spice.profitmandi.common.model.GadgetCopsInsuranceModel;
|
| 21896 |
ashik.ali |
47 |
import com.spice.profitmandi.common.model.GstRate;
|
| 21689 |
ashik.ali |
48 |
import com.spice.profitmandi.common.model.PdfModel;
|
| 21612 |
ashik.ali |
49 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22217 |
ashik.ali |
50 |
import com.spice.profitmandi.common.model.SerialNumberDetail;
|
|
|
51 |
import com.spice.profitmandi.common.util.InsuranceUtils;
|
| 21689 |
ashik.ali |
52 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 21680 |
ashik.ali |
53 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 21896 |
ashik.ali |
54 |
import com.spice.profitmandi.common.util.Utils;
|
| 22244 |
ashik.ali |
55 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 21728 |
ashik.ali |
56 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 22217 |
ashik.ali |
57 |
import com.spice.profitmandi.dao.entity.dtr.GadgetCopsInsuranceCalc;
|
|
|
58 |
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
|
|
|
59 |
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
|
|
|
60 |
import com.spice.profitmandi.dao.entity.dtr.PolicyNumberGenerationSequence;
|
| 21728 |
ashik.ali |
61 |
import com.spice.profitmandi.dao.entity.dtr.Retailer;
|
|
|
62 |
import com.spice.profitmandi.dao.entity.dtr.User;
|
|
|
63 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
|
|
64 |
import com.spice.profitmandi.dao.entity.fofo.Customer;
|
|
|
65 |
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
|
| 21896 |
ashik.ali |
66 |
import com.spice.profitmandi.dao.entity.fofo.FofoItemId;
|
| 21728 |
ashik.ali |
67 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
|
|
|
68 |
import com.spice.profitmandi.dao.entity.fofo.FofoLineItemSerialNumber;
|
|
|
69 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
|
|
70 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
|
|
71 |
import com.spice.profitmandi.dao.entity.fofo.InvoiceNumberGenerationSequence;
|
|
|
72 |
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
|
|
|
73 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
|
|
74 |
import com.spice.profitmandi.dao.entity.user.Address;
|
|
|
75 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 21883 |
kshitij.so |
76 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 22217 |
ashik.ali |
77 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
|
|
78 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
|
|
79 |
import com.spice.profitmandi.dao.repository.dtr.PolicyNumberGenerationSequenceRepository;
|
| 21728 |
ashik.ali |
80 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
|
|
81 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
|
|
82 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
83 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
|
|
84 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
|
|
85 |
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
|
|
|
86 |
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
|
|
|
87 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
|
|
88 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemSerialNumberRepository;
|
|
|
89 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
|
|
90 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
|
|
91 |
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
|
|
|
92 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
|
|
93 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
|
|
94 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
|
|
95 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 22069 |
ashik.ali |
96 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 22139 |
amit.gupta |
97 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 21612 |
ashik.ali |
98 |
import com.spice.profitmandi.web.request.CreateOrderRequest;
|
|
|
99 |
import com.spice.profitmandi.web.request.CustomPaymentOption;
|
| 21680 |
ashik.ali |
100 |
import com.spice.profitmandi.web.response.ItemIdQuantityAvailability;
|
|
|
101 |
import com.spice.profitmandi.web.response.Quantity;
|
| 22069 |
ashik.ali |
102 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 21612 |
ashik.ali |
103 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
104 |
|
| 21985 |
kshitij.so |
105 |
import in.shop2020.model.v1.catalog.ItemType;
|
|
|
106 |
|
| 21612 |
ashik.ali |
107 |
@Controller
|
| 22037 |
amit.gupta |
108 |
@Transactional(rollbackFor=Throwable.class)
|
| 21612 |
ashik.ali |
109 |
public class OrderController {
|
|
|
110 |
|
|
|
111 |
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
| 21985 |
kshitij.so |
112 |
|
| 21612 |
ashik.ali |
113 |
@Autowired
|
|
|
114 |
OrderRepository orderRepository;
|
| 21985 |
kshitij.so |
115 |
|
| 21612 |
ashik.ali |
116 |
@Autowired
|
|
|
117 |
InventoryItemRepository inventoryItemRepository;
|
| 21985 |
kshitij.so |
118 |
|
| 21612 |
ashik.ali |
119 |
@Autowired
|
| 21680 |
ashik.ali |
120 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 21985 |
kshitij.so |
121 |
|
| 21680 |
ashik.ali |
122 |
@Autowired
|
|
|
123 |
InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
|
| 21985 |
kshitij.so |
124 |
|
| 21680 |
ashik.ali |
125 |
@Autowired
|
|
|
126 |
CustomerRepository customerRepository;
|
| 21985 |
kshitij.so |
127 |
|
| 21680 |
ashik.ali |
128 |
@Autowired
|
|
|
129 |
AddressRepository addressRepository;
|
| 21985 |
kshitij.so |
130 |
|
| 21680 |
ashik.ali |
131 |
@Autowired
|
|
|
132 |
FofoLineItemSerialNumberRepository fofoLineItemSerialNumberRepository;
|
| 21985 |
kshitij.so |
133 |
|
| 21680 |
ashik.ali |
134 |
@Autowired
|
|
|
135 |
FofoLineItemRepository fofoLineItemRepository;
|
| 21985 |
kshitij.so |
136 |
|
| 21680 |
ashik.ali |
137 |
@Autowired
|
|
|
138 |
PaymentOptionRepository paymentOptionRepository;
|
| 21985 |
kshitij.so |
139 |
|
| 21680 |
ashik.ali |
140 |
@Autowired
|
|
|
141 |
ScanRecordRepository scanRecordRepository;
|
| 21985 |
kshitij.so |
142 |
|
| 21680 |
ashik.ali |
143 |
@Autowired
|
|
|
144 |
FofoOrderRepository fofoOrderRepository;
|
| 21985 |
kshitij.so |
145 |
|
| 21680 |
ashik.ali |
146 |
@Autowired
|
| 21689 |
ashik.ali |
147 |
RetailerRepository retailerRepository;
|
| 21985 |
kshitij.so |
148 |
|
| 21689 |
ashik.ali |
149 |
@Autowired
|
|
|
150 |
UserRepository userRepository;
|
| 21985 |
kshitij.so |
151 |
|
| 21689 |
ashik.ali |
152 |
@Autowired
|
|
|
153 |
UserAccountRepository userAccountRepository;
|
| 21985 |
kshitij.so |
154 |
|
| 21689 |
ashik.ali |
155 |
@Autowired
|
|
|
156 |
RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 21985 |
kshitij.so |
157 |
|
| 21689 |
ashik.ali |
158 |
@Autowired
|
| 21711 |
ashik.ali |
159 |
CustomerAddressRepository customerAddressRepository;
|
| 21985 |
kshitij.so |
160 |
|
| 21711 |
ashik.ali |
161 |
@Autowired
|
| 21896 |
ashik.ali |
162 |
ItemRepository itemRepository;
|
| 22217 |
ashik.ali |
163 |
|
|
|
164 |
@Autowired
|
|
|
165 |
InsuranceProviderRepository insuranceProviderRepository;
|
|
|
166 |
|
|
|
167 |
@Autowired
|
|
|
168 |
InsurancePolicyRepository insurancePolicyRepository;
|
|
|
169 |
|
|
|
170 |
@Autowired
|
|
|
171 |
PolicyNumberGenerationSequenceRepository policyNumberGenerationSequenceRepository;
|
| 21985 |
kshitij.so |
172 |
|
| 21896 |
ashik.ali |
173 |
@Autowired
|
| 21612 |
ashik.ali |
174 |
MVCResponseSender mvcResponseSender;
|
| 21985 |
kshitij.so |
175 |
|
| 21612 |
ashik.ali |
176 |
@Autowired
|
| 22069 |
ashik.ali |
177 |
CookiesProcessor cookiesProcessor;
|
|
|
178 |
|
|
|
179 |
@Autowired
|
|
|
180 |
PricingService pricingService;
|
| 22244 |
ashik.ali |
181 |
|
|
|
182 |
|
|
|
183 |
@Autowired
|
|
|
184 |
ResponseSender<?> responseSender;
|
| 21985 |
kshitij.so |
185 |
|
|
|
186 |
@RequestMapping(value = "/order")
|
|
|
187 |
public String orderIndex(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
| 22244 |
ashik.ali |
188 |
LoginDetails loginDetails = null;
|
| 21985 |
kshitij.so |
189 |
try {
|
| 22244 |
ashik.ali |
190 |
loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 21985 |
kshitij.so |
191 |
} catch (ProfitMandiBusinessException e) {
|
|
|
192 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
193 |
return "response";
|
|
|
194 |
}
|
| 22275 |
ashik.ali |
195 |
try{
|
|
|
196 |
JSONObject cartObject = new JSONObject(cartData);
|
|
|
197 |
Iterator<?> keys = cartObject.keys();
|
|
|
198 |
|
|
|
199 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
200 |
List<CartFofo> cartItems = new ArrayList<CartFofo>();
|
|
|
201 |
|
|
|
202 |
while( keys.hasNext() ) {
|
|
|
203 |
String key = (String)keys.next();
|
|
|
204 |
if ( cartObject.get(key) instanceof JSONObject ) {
|
|
|
205 |
System.out.println(cartObject.get(key));
|
|
|
206 |
}
|
|
|
207 |
CartFofo cf = new CartFofo();
|
|
|
208 |
cf.setItemId(cartObject.getJSONObject(key).getInt("itemId"));
|
|
|
209 |
cf.setQuantity(cartObject.getJSONObject(key).getInt("quantity"));
|
|
|
210 |
|
|
|
211 |
if (cf.getQuantity() <= 0){
|
|
|
212 |
continue;
|
|
|
213 |
}
|
|
|
214 |
cartItems.add(cf);
|
|
|
215 |
itemIds.add(cartObject.getJSONObject(key).getInt("itemId"));
|
| 21985 |
kshitij.so |
216 |
}
|
| 22275 |
ashik.ali |
217 |
Map<Integer, Item> itemMap = new HashMap<Integer, Item>();
|
|
|
218 |
if (itemIds.size() > 0){
|
|
|
219 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
|
|
220 |
for (Item i : items){
|
|
|
221 |
itemMap.put(i.getId(), i);
|
|
|
222 |
}
|
|
|
223 |
|
| 21985 |
kshitij.so |
224 |
}
|
| 22275 |
ashik.ali |
225 |
for (CartFofo cf : cartItems){
|
|
|
226 |
Item i = itemMap.get(cf.getItemId());
|
|
|
227 |
if (i == null){
|
|
|
228 |
continue;
|
|
|
229 |
}
|
|
|
230 |
cf.setDisplayName(getValidName(i.getBrand())+" "+getValidName(i.getModelName())+" "+getValidName(i.getModelNumber())+" "+getValidName(i.getColor()).replaceAll("\\s+", " "));
|
|
|
231 |
cf.setItemType(i.getType());
|
| 21985 |
kshitij.so |
232 |
}
|
| 22275 |
ashik.ali |
233 |
Map<Integer, Float> mopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, loginDetails.getFofoId());
|
|
|
234 |
LOGGER.info("mopPriceMap {}", mopPriceMap);
|
|
|
235 |
model.addAttribute("cartObj", cartItems);
|
|
|
236 |
model.addAttribute("mopPriceMap", mopPriceMap);
|
|
|
237 |
return "order-index";
|
|
|
238 |
}catch (Exception e) {
|
|
|
239 |
LOGGER.error("Unable to Prepare cart to place order...", e);
|
|
|
240 |
return "error";
|
| 21985 |
kshitij.so |
241 |
}
|
|
|
242 |
}
|
|
|
243 |
|
|
|
244 |
private String getValidName(String name){
|
|
|
245 |
return name!=null?name:"";
|
|
|
246 |
}
|
| 21612 |
ashik.ali |
247 |
|
| 22244 |
ashik.ali |
248 |
@RequestMapping(value = "/insurancePrices", method = RequestMethod.GET)
|
|
|
249 |
public ResponseEntity<?> getInsurancePrices(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PRICE) float price){
|
|
|
250 |
LOGGER.info("Request received at url : {}", request.getRequestURI());
|
|
|
251 |
try{
|
|
|
252 |
Set<Float> prices = new HashSet<>();
|
|
|
253 |
prices.add(price);
|
|
|
254 |
return responseSender.ok(pricingService.getInsurancePrices(prices, ProfitMandiConstants.GADGET_COPS));
|
|
|
255 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
256 |
return responseSender.notFound(profitMandiBusinessException);
|
|
|
257 |
}
|
|
|
258 |
}
|
|
|
259 |
|
|
|
260 |
|
| 21985 |
kshitij.so |
261 |
@RequestMapping(value = "/get-order", method = RequestMethod.GET)
|
| 22244 |
ashik.ali |
262 |
public String getOrder(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws ProfitMandiBusinessException, Exception{
|
| 22139 |
amit.gupta |
263 |
LoginDetails fofoDetails;
|
| 21985 |
kshitij.so |
264 |
try {
|
| 22069 |
ashik.ali |
265 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21985 |
kshitij.so |
266 |
} catch (ProfitMandiBusinessException e) {
|
|
|
267 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
268 |
return "response";
|
|
|
269 |
}
|
|
|
270 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 22098 |
kshitij.so |
271 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
272 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
273 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByOrderId(fofoOrder.getId());
|
| 22244 |
ashik.ali |
274 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByInvoiceNumber(fofoOrder.getInvoiceNumber());
|
| 22098 |
kshitij.so |
275 |
model.addAttribute("fofoOrder", fofoOrder);
|
|
|
276 |
model.addAttribute("fofoLineItems", fofoLineItems);
|
|
|
277 |
model.addAttribute("customerBillingAddress", getBillingAddress(customerAddress));
|
|
|
278 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
|
|
279 |
model.addAttribute("paymentOptions", paymentOptions);
|
| 22244 |
ashik.ali |
280 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
| 22098 |
kshitij.so |
281 |
return "order-details";
|
| 21985 |
kshitij.so |
282 |
}
|
| 22244 |
ashik.ali |
283 |
|
|
|
284 |
|
|
|
285 |
@RequestMapping(value = "/saleDetails", method = RequestMethod.GET)
|
|
|
286 |
public String getSaleDetails(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws ProfitMandiBusinessException, Exception{
|
|
|
287 |
LoginDetails fofoDetails;
|
|
|
288 |
try {
|
|
|
289 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
290 |
} catch (ProfitMandiBusinessException e) {
|
|
|
291 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
292 |
return "response";
|
|
|
293 |
}
|
|
|
294 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
|
|
295 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
|
|
|
296 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
|
|
297 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByOrderId(fofoOrder.getId());
|
|
|
298 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByInvoiceNumber(fofoOrder.getInvoiceNumber());
|
|
|
299 |
model.addAttribute("fofoOrder", fofoOrder);
|
|
|
300 |
model.addAttribute("fofoLineItems", fofoLineItems);
|
|
|
301 |
model.addAttribute("customerBillingAddress", getBillingAddress(customerAddress));
|
|
|
302 |
model.addAttribute("customerBillingAddressObj", customerAddress);
|
|
|
303 |
model.addAttribute("paymentOptions", paymentOptions);
|
|
|
304 |
model.addAttribute("insurancePolicies", insurancePolicies);
|
|
|
305 |
return "sale-details";
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
|
| 21985 |
kshitij.so |
309 |
|
| 22098 |
kshitij.so |
310 |
private String getBillingAddress(CustomerAddress customerAddress) {
|
|
|
311 |
String address = "";
|
|
|
312 |
if ((customerAddress.getLine1() != null) && (!customerAddress.getLine1().isEmpty())) {
|
|
|
313 |
address = address + customerAddress.getLine1();
|
|
|
314 |
address = address + ", ";
|
|
|
315 |
}
|
|
|
316 |
|
|
|
317 |
if ((customerAddress.getLine2() != null) && (!customerAddress.getLine2().isEmpty())) {
|
|
|
318 |
address = address + customerAddress.getLine2();
|
|
|
319 |
address = address + ", ";
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
if ((customerAddress.getLandmark() != null) && (!customerAddress.getLandmark().isEmpty())) {
|
|
|
323 |
address = address + customerAddress.getLandmark();
|
|
|
324 |
address = address + ", ";
|
|
|
325 |
}
|
|
|
326 |
|
|
|
327 |
if ((customerAddress.getCity() != null) && (!customerAddress.getCity().isEmpty())) {
|
|
|
328 |
address = address + customerAddress.getCity();
|
|
|
329 |
address = address + ", ";
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
if ((customerAddress.getState() != null) && (!customerAddress.getState().isEmpty())) {
|
|
|
333 |
address = address + customerAddress.getState();
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
if ((customerAddress.getPinCode() != null) && (!customerAddress.getPinCode().isEmpty())) {
|
|
|
337 |
address = address + "- " + customerAddress.getPinCode();
|
|
|
338 |
}
|
|
|
339 |
|
|
|
340 |
return address;
|
|
|
341 |
}
|
|
|
342 |
|
| 21985 |
kshitij.so |
343 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
|
|
344 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest, Model model) throws Throwable{
|
| 22064 |
ashik.ali |
345 |
LOGGER.info("request at uri {} body {}", request.getRequestURI(), createOrderRequest);
|
| 22139 |
amit.gupta |
346 |
LoginDetails fofoDetails;
|
| 21985 |
kshitij.so |
347 |
try {
|
| 22069 |
ashik.ali |
348 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21985 |
kshitij.so |
349 |
} catch (ProfitMandiBusinessException e) {
|
|
|
350 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
351 |
return "response";
|
|
|
352 |
}
|
| 22244 |
ashik.ali |
353 |
try{
|
|
|
354 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
355 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); //this is for error
|
|
|
356 |
Map<Integer, CustomFofoLineItem> customFofoLineItemMap = new HashMap<>();
|
|
|
357 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); //this is for pricing error
|
|
|
358 |
float totalAmount = 0;
|
|
|
359 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
|
|
360 |
itemIds.add(customFofoLineItem.getItemId());
|
|
|
361 |
if(!customFofoLineItem.getSerialNumberDetails().isEmpty() && customFofoLineItem.getQuantity() != customFofoLineItem.getSerialNumberDetails().size()){
|
|
|
362 |
itemIdQuantity.put(customFofoLineItem.getItemId(), customFofoLineItem.getQuantity());
|
|
|
363 |
}
|
|
|
364 |
if(!(customFofoLineItem.getSellingPrice() > 0)){
|
|
|
365 |
lineItemPrice.put(customFofoLineItem.getItemId(), customFofoLineItem.getSellingPrice());
|
|
|
366 |
}else{
|
|
|
367 |
totalAmount = totalAmount + customFofoLineItem.getSellingPrice() * customFofoLineItem.getQuantity();
|
|
|
368 |
for(SerialNumberDetail serialNumberDetail : customFofoLineItem.getSerialNumberDetails()){
|
|
|
369 |
if(serialNumberDetail.isInsurance() && serialNumberDetail.getAmount() > 0){
|
|
|
370 |
totalAmount = totalAmount + serialNumberDetail.getAmount();
|
|
|
371 |
}
|
| 22217 |
ashik.ali |
372 |
}
|
|
|
373 |
}
|
| 22244 |
ashik.ali |
374 |
customFofoLineItemMap.put(customFofoLineItem.getItemId(), customFofoLineItem);
|
| 21680 |
ashik.ali |
375 |
}
|
| 22244 |
ashik.ali |
376 |
if(!itemIdQuantity.isEmpty()){
|
|
|
377 |
// if item quantity does not match with given serialnumbers size
|
|
|
378 |
LOGGER.error("itemId's quantity should be equal to given serialnumber size {} ", itemIdQuantity);
|
| 22253 |
ashik.ali |
379 |
throw new ProfitMandiBusinessException("itemIdQuantity", itemIdQuantity, "");
|
|
|
380 |
//return "error";
|
| 21896 |
ashik.ali |
381 |
}
|
| 22244 |
ashik.ali |
382 |
try{
|
|
|
383 |
this.validatePaymentOptionsAndTotalAmount(createOrderRequest.getPaymentOptions(), totalAmount);
|
|
|
384 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
385 |
LOGGER.error("Error occured while validating payment options : ", profitMandiBusinessException);
|
| 22253 |
ashik.ali |
386 |
throw profitMandiBusinessException;
|
| 21896 |
ashik.ali |
387 |
}
|
| 22244 |
ashik.ali |
388 |
if(!lineItemPrice.isEmpty()){
|
|
|
389 |
// given fofo line item price must be greater than zero
|
|
|
390 |
LOGGER.error("requested itemId's selling price must greater than 0");
|
| 22253 |
ashik.ali |
391 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PRICE, lineItemPrice, "");
|
| 21985 |
kshitij.so |
392 |
}
|
| 22244 |
ashik.ali |
393 |
|
|
|
394 |
List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.selectByFofoItemIds(fofoDetails.getFofoId(), itemIds);
|
|
|
395 |
if(itemIds.size() != currentInventorySnapshots.size()){
|
|
|
396 |
// error
|
|
|
397 |
}
|
|
|
398 |
List<ItemIdQuantityAvailability> itemIdQuantityAvailabilities = new ArrayList<>(); //this is for error
|
|
|
399 |
LOGGER.info("currentInventorySnapshots "+currentInventorySnapshots);
|
|
|
400 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots){
|
|
|
401 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(currentInventorySnapshot.getId().getItemId());
|
|
|
402 |
LOGGER.info("customFofoLineItem "+customFofoLineItem);
|
|
|
403 |
if(customFofoLineItem.getQuantity() > currentInventorySnapshot.getAvailability()){
|
|
|
404 |
ItemIdQuantityAvailability itemIdQuantityAvailability = new ItemIdQuantityAvailability();
|
|
|
405 |
itemIdQuantityAvailability.setItemId(customFofoLineItem.getItemId());
|
|
|
406 |
Quantity quantity = new Quantity();
|
|
|
407 |
quantity.setAvailable(currentInventorySnapshot.getAvailability());
|
|
|
408 |
quantity.setRequested(customFofoLineItem.getQuantity());
|
|
|
409 |
itemIdQuantityAvailability.setQuantity(quantity);
|
|
|
410 |
itemIdQuantityAvailabilities.add(itemIdQuantityAvailability);
|
| 21680 |
ashik.ali |
411 |
}
|
| 22244 |
ashik.ali |
412 |
|
| 21680 |
ashik.ali |
413 |
}
|
| 22244 |
ashik.ali |
414 |
|
|
|
415 |
|
|
|
416 |
|
|
|
417 |
if(!itemIdQuantityAvailabilities.isEmpty()){
|
|
|
418 |
// itemIdQuantity request is not valid
|
|
|
419 |
LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
|
| 22253 |
ashik.ali |
420 |
throw new ProfitMandiBusinessException("itemIdQuantityAvailabilities", itemIdQuantityAvailabilities, "");
|
| 22244 |
ashik.ali |
421 |
}
|
|
|
422 |
|
|
|
423 |
|
|
|
424 |
|
|
|
425 |
// Set<Integer> invalidItemIdSerialNumbers = new HashSet<>();
|
|
|
426 |
// Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>();
|
|
|
427 |
// List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoDetails.getFofoId(), itemIds); //change it
|
|
|
428 |
//
|
|
|
429 |
// Map<Integer, Float> itemIdPriceDropAmount = new HashMap<>();
|
|
|
430 |
//
|
|
|
431 |
// for(InventoryItem inventoryItem : inventoryItems){
|
|
|
432 |
// CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(inventoryItem.getItemId());
|
|
|
433 |
// if(customFofoLineItem.getSerialNumbers().isEmpty()){
|
|
|
434 |
// if(!(inventoryItem.getSerialNumber() == null && inventoryItem.getSerialNumber().equals(""))){
|
|
|
435 |
// invalidItemIdSerialNumbers.add(inventoryItem.getItemId());
|
|
|
436 |
// }
|
|
|
437 |
// }
|
|
|
438 |
// if(!customFofoLineItem.getSerialNumbers().isEmpty()){
|
|
|
439 |
// if(!customFofoLineItem.getSerialNumbers().contains(inventoryItem.getSerialNumber())){
|
|
|
440 |
// if(!itemIdSerialNumbers.containsKey(customFofoLineItem.getItemId())){
|
|
|
441 |
// Set<String> serialNumbers = new HashSet<>();
|
|
|
442 |
// serialNumbers.add(inventoryItem.getSerialNumber());
|
|
|
443 |
// itemIdSerialNumbers.put(customFofoLineItem.getItemId(), serialNumbers);
|
|
|
444 |
// }else{
|
|
|
445 |
// itemIdSerialNumbers.get(customFofoLineItem.getItemId()).add(inventoryItem.getSerialNumber());
|
|
|
446 |
// }
|
|
|
447 |
// }
|
|
|
448 |
// itemIdPriceDropAmount.put(inventoryItem.getItemId(), inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount());
|
|
|
449 |
// }
|
|
|
450 |
|
|
|
451 |
Map<Integer, Item> itemMap = new HashMap<Integer, Item>();
|
|
|
452 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
|
|
453 |
for (Item i : items){
|
|
|
454 |
itemMap.put(i.getId(), i);
|
|
|
455 |
}
|
|
|
456 |
|
|
|
457 |
Set<Integer> nonSerializedItemIds = new HashSet<>();
|
|
|
458 |
Set<String> serialNumbers = new HashSet<>();
|
|
|
459 |
Map<String, Float> insuranceSerialNumberItemPrice = new HashMap<>();
|
|
|
460 |
Map<String, Float> insuranceSerialNumberSaleAmount = new HashMap<>();
|
|
|
461 |
Map<String, String> serialNumberModelName = new HashMap<>();
|
|
|
462 |
Map<String, String> serialNumberBrand = new HashMap<>();
|
|
|
463 |
Collection<CustomFofoLineItem> lineItemsValues = customFofoLineItemMap.values();
|
|
|
464 |
for (CustomFofoLineItem cli : lineItemsValues){
|
|
|
465 |
|
|
|
466 |
Item item = itemMap.get(cli.getItemId());
|
|
|
467 |
if (item.getType().equals(ItemType.SERIALIZED)){
|
|
|
468 |
for (SerialNumberDetail serialNumberDetail : cli.getSerialNumberDetails()){
|
|
|
469 |
serialNumbers.add(serialNumberDetail.getSerialNumber());
|
|
|
470 |
if(serialNumberDetail.isInsurance()){
|
|
|
471 |
insuranceSerialNumberItemPrice.put(serialNumberDetail.getSerialNumber(), cli.getSellingPrice());
|
|
|
472 |
insuranceSerialNumberSaleAmount.put(serialNumberDetail.getSerialNumber(), serialNumberDetail.getAmount());
|
|
|
473 |
serialNumberModelName.put(serialNumberDetail.getSerialNumber(), item.getModelName());
|
|
|
474 |
serialNumberBrand.put(serialNumberDetail.getSerialNumber(), item.getBrand());
|
|
|
475 |
}
|
| 21985 |
kshitij.so |
476 |
}
|
|
|
477 |
}
|
| 22244 |
ashik.ali |
478 |
else{
|
|
|
479 |
nonSerializedItemIds.add(cli.getItemId());
|
| 21985 |
kshitij.so |
480 |
}
|
| 22244 |
ashik.ali |
481 |
|
| 21985 |
kshitij.so |
482 |
}
|
| 22244 |
ashik.ali |
483 |
|
|
|
484 |
|
|
|
485 |
Map<Integer, List<InventoryItem>> serializedInventoryItemMap = new HashMap<Integer, List<InventoryItem>>();
|
|
|
486 |
Map<Integer, List<InventoryItem>> nonSerializedInventoryItemMap = new HashMap<Integer, List<InventoryItem>>();
|
|
|
487 |
Map<Integer, List<Float>> itemIdPriceDropAmount = new HashMap<>();
|
|
|
488 |
|
|
|
489 |
if (!serialNumbers.isEmpty()){
|
|
|
490 |
List<InventoryItem> serializedInventoryItems = inventoryItemRepository.selectByFofoIdSerialNumbers(fofoDetails.getFofoId(), serialNumbers);
|
|
|
491 |
LOGGER.info("serializedInventoryItems {}", serializedInventoryItems);
|
|
|
492 |
for (InventoryItem it : serializedInventoryItems){
|
|
|
493 |
if (it.getGoodQuantity() == 1){
|
|
|
494 |
if (serializedInventoryItemMap.containsKey(it.getItemId())){
|
|
|
495 |
serializedInventoryItemMap.get(it.getItemId()).add(it);
|
|
|
496 |
itemIdPriceDropAmount.get(it.getItemId()).
|
|
|
497 |
add(it.getUnitPrice() - (it.getPriceDropAmount()==null?0:it.getPriceDropAmount()));
|
|
|
498 |
}
|
|
|
499 |
else{
|
|
|
500 |
ArrayList<InventoryItem> tmp = new ArrayList<InventoryItem>();
|
|
|
501 |
tmp.add(it);
|
|
|
502 |
serializedInventoryItemMap.put(it.getItemId(), tmp);
|
|
|
503 |
ArrayList<Float> priceDropAmouts = new ArrayList<>();
|
|
|
504 |
priceDropAmouts.add(it.getUnitPrice() - (it.getPriceDropAmount()==null?0:it.getPriceDropAmount()));
|
|
|
505 |
itemIdPriceDropAmount.put(it.getItemId(), priceDropAmouts);
|
|
|
506 |
}
|
|
|
507 |
}
|
| 21985 |
kshitij.so |
508 |
}
|
|
|
509 |
}
|
| 22244 |
ashik.ali |
510 |
|
|
|
511 |
if (!nonSerializedItemIds.isEmpty()){
|
|
|
512 |
List<InventoryItem> nonSerializedInventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoDetails.getFofoId(), nonSerializedItemIds);
|
|
|
513 |
for (InventoryItem it : nonSerializedInventoryItems){
|
|
|
514 |
if (it.getGoodQuantity() > 0){
|
|
|
515 |
if (nonSerializedInventoryItemMap.containsKey(it.getItemId())){
|
|
|
516 |
nonSerializedInventoryItemMap.get(it.getItemId()).add(it);
|
|
|
517 |
}
|
|
|
518 |
else{
|
|
|
519 |
ArrayList<InventoryItem> tmp = new ArrayList<InventoryItem>();
|
|
|
520 |
tmp.add(it);
|
|
|
521 |
nonSerializedInventoryItemMap.put(it.getItemId(), tmp);
|
|
|
522 |
}
|
|
|
523 |
}
|
| 21985 |
kshitij.so |
524 |
}
|
|
|
525 |
}
|
| 22244 |
ashik.ali |
526 |
|
|
|
527 |
List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
|
|
|
528 |
List<Integer> itemIdSerialNumbers = new ArrayList<Integer>();
|
|
|
529 |
|
|
|
530 |
for (Item i : items){
|
|
|
531 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(i.getId());
|
|
|
532 |
if (i.getType().equals(ItemType.SERIALIZED)){
|
|
|
533 |
if (customFofoLineItem ==null || customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
|
|
534 |
invalidItemIdSerialNumbers.add(i.getId());
|
| 21985 |
kshitij.so |
535 |
}
|
|
|
536 |
}
|
| 22244 |
ashik.ali |
537 |
else{
|
|
|
538 |
if (customFofoLineItem == null || !customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
|
|
539 |
itemIdSerialNumbers.add(i.getId());
|
|
|
540 |
}
|
| 21985 |
kshitij.so |
541 |
}
|
|
|
542 |
}
|
| 22244 |
ashik.ali |
543 |
|
|
|
544 |
if(!invalidItemIdSerialNumbers.isEmpty()){
|
|
|
545 |
LOGGER.error("Invalid itemId's serialNumbers {}", invalidItemIdSerialNumbers);
|
|
|
546 |
// itemId's are serialized you are saying these are not serialized
|
| 22253 |
ashik.ali |
547 |
throw new ProfitMandiBusinessException("invalidItemIdSerialNumbers", invalidItemIdSerialNumbers, "");
|
| 22069 |
ashik.ali |
548 |
}
|
| 22244 |
ashik.ali |
549 |
|
|
|
550 |
if(!itemIdSerialNumbers.isEmpty()){
|
|
|
551 |
LOGGER.error("Invalid itemId's serialNumbers {}", itemIdSerialNumbers);
|
|
|
552 |
// itemId's are non serialized you are saying these are serialized
|
| 22253 |
ashik.ali |
553 |
throw new ProfitMandiBusinessException("itemIdSerialNumbers", itemIdSerialNumbers, "");
|
| 21985 |
kshitij.so |
554 |
}
|
| 22244 |
ashik.ali |
555 |
|
|
|
556 |
if(items.size() != itemIds.size()){
|
|
|
557 |
LOGGER.error("Requested ItemIds not found in catalog");
|
|
|
558 |
// invalid itemIds
|
| 22253 |
ashik.ali |
559 |
throw new ProfitMandiBusinessException("invalidItemIds", "", "");
|
| 21985 |
kshitij.so |
560 |
}
|
| 22244 |
ashik.ali |
561 |
|
|
|
562 |
Map<Integer, List<InventoryItem>> inventoryItemsToBill = new HashMap<Integer,List<InventoryItem>>();
|
|
|
563 |
Map<Integer, Integer> inventoryItemQuantityUsed = new HashMap<>(); //to keep track of inventoryitem quanity used for scan records insertion
|
|
|
564 |
|
|
|
565 |
LOGGER.info("itemMap keys {}", itemMap.keySet());
|
|
|
566 |
//Lets reduce quantity and decide what inventory items to use.
|
|
|
567 |
for (Item i : items){
|
|
|
568 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(i.getId());
|
|
|
569 |
if (i.getType().equals(ItemType.SERIALIZED)){
|
|
|
570 |
//TODO:handle null
|
|
|
571 |
if (serializedInventoryItemMap.get(i.getId()) == null || customFofoLineItem.getSerialNumberDetails().size() != serializedInventoryItemMap.get(i.getId()).size()){
|
|
|
572 |
//not enough serial numbers
|
|
|
573 |
//LOGGER.info("serialNumbers {}", serialNumbers);
|
|
|
574 |
LOGGER.info("serializedInventoryItemMap {}", serializedInventoryItemMap);
|
|
|
575 |
LOGGER.info("itemId {}", i.getId());
|
|
|
576 |
LOGGER.error("not enough serial numbers");
|
| 22253 |
ashik.ali |
577 |
throw new ProfitMandiBusinessException("notEnoughSerialNumbers", "", "");
|
| 22244 |
ashik.ali |
578 |
}
|
|
|
579 |
List<InventoryItem> inventoryItemsSerializedserialized = serializedInventoryItemMap.get(i.getId());
|
|
|
580 |
for (InventoryItem it : inventoryItemsSerializedserialized){
|
|
|
581 |
it.setGoodQuantity(0);
|
|
|
582 |
inventoryItemQuantityUsed.put(it.getId(), 1);
|
|
|
583 |
}
|
|
|
584 |
inventoryItemsToBill.put(i.getId(), inventoryItemsSerializedserialized);
|
| 21680 |
ashik.ali |
585 |
}
|
| 22244 |
ashik.ali |
586 |
else{
|
|
|
587 |
List<InventoryItem> inventoryItemsNonSerialized = nonSerializedInventoryItemMap.get(i.getId());
|
|
|
588 |
int quantityToBill = customFofoLineItem.getQuantity();
|
|
|
589 |
int totalLeft = quantityToBill;
|
|
|
590 |
List<InventoryItem> inventoryItemsNonSerializedUsed = new ArrayList<InventoryItem>();
|
|
|
591 |
if (inventoryItemsNonSerialized!=null){
|
|
|
592 |
for (InventoryItem it : inventoryItemsNonSerialized){
|
|
|
593 |
if (totalLeft > 0){
|
|
|
594 |
int toUse = Math.min(totalLeft, it.getGoodQuantity());
|
|
|
595 |
inventoryItemQuantityUsed.put(it.getId(), toUse);
|
|
|
596 |
it.setGoodQuantity(it.getGoodQuantity() - toUse);
|
|
|
597 |
totalLeft = totalLeft - toUse;
|
|
|
598 |
inventoryItemsNonSerializedUsed.add(it);
|
|
|
599 |
}
|
|
|
600 |
}
|
|
|
601 |
}
|
|
|
602 |
|
|
|
603 |
if (totalLeft > 0){
|
|
|
604 |
//not enough quanity for non-serialized
|
|
|
605 |
System.out.println("not enough quanity for non-serialized");
|
| 22253 |
ashik.ali |
606 |
throw new ProfitMandiBusinessException("notEnoughQuantityForNonSerialized", "", "");
|
| 22244 |
ashik.ali |
607 |
}
|
|
|
608 |
inventoryItemsToBill.put(i.getId(), inventoryItemsNonSerializedUsed);
|
| 21896 |
ashik.ali |
609 |
}
|
|
|
610 |
}
|
| 22217 |
ashik.ali |
611 |
|
| 22244 |
ashik.ali |
612 |
// mop price validation
|
|
|
613 |
Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
|
| 22250 |
ashik.ali |
614 |
Map<Integer, Float> itemIdMopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, fofoDetails.getFofoId());
|
| 22244 |
ashik.ali |
615 |
for(Map.Entry<Integer, Float> entry : itemIdMopPriceMap.entrySet()){
|
|
|
616 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(entry.getKey());
|
| 22253 |
ashik.ali |
617 |
if(entry.getValue() < Float.MAX_VALUE && customFofoLineItem.getSellingPrice() < entry.getValue()){
|
| 22244 |
ashik.ali |
618 |
invalidMopItemIdPriceMap.put(entry.getKey(), customFofoLineItem.getSellingPrice());
|
| 22217 |
ashik.ali |
619 |
}
|
|
|
620 |
}
|
|
|
621 |
|
| 22244 |
ashik.ali |
622 |
if(!invalidMopItemIdPriceMap.isEmpty()){
|
|
|
623 |
LOGGER.error("Invalid itemIds selling prices{} should be greater than mop prices {}", invalidMopItemIdPriceMap, itemIdMopPriceMap);
|
| 22253 |
ashik.ali |
624 |
throw new ProfitMandiBusinessException("invalidMopItemIdPrice", invalidMopItemIdPriceMap, "");
|
| 22217 |
ashik.ali |
625 |
}
|
| 22244 |
ashik.ali |
626 |
|
|
|
627 |
InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
|
|
|
628 |
try{
|
|
|
629 |
invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoDetails.getFofoId());
|
|
|
630 |
invoiceNumberGenerationSequence.setSequence(invoiceNumberGenerationSequence.getSequence() + 1);
|
|
|
631 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
|
|
632 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
633 |
invoiceNumberGenerationSequence = new InvoiceNumberGenerationSequence();
|
|
|
634 |
invoiceNumberGenerationSequence.setFofoId(fofoDetails.getFofoId());
|
|
|
635 |
invoiceNumberGenerationSequence.setPrefix("INVOICE");
|
|
|
636 |
invoiceNumberGenerationSequence.setSequence(1);
|
|
|
637 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
|
|
638 |
}
|
|
|
639 |
|
|
|
640 |
CustomCustomer customCustomer = createOrderRequest.getCustomer();
|
|
|
641 |
|
|
|
642 |
if(!StringUtils.isValidEmailAddress(customCustomer.getEmailId())){
|
|
|
643 |
LOGGER.error("invalid customer emailId {} ", customCustomer.getEmailId());
|
| 22253 |
ashik.ali |
644 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, customCustomer.getEmailId(), "");
|
| 22217 |
ashik.ali |
645 |
}
|
| 22244 |
ashik.ali |
646 |
|
|
|
647 |
if(!StringUtils.isValidMobile(customCustomer.getMobileNumber())){
|
|
|
648 |
LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
|
| 22253 |
ashik.ali |
649 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.MOBILE_NUMBER, customCustomer.getMobileNumber(), "");
|
| 22244 |
ashik.ali |
650 |
}
|
| 22217 |
ashik.ali |
651 |
|
| 22244 |
ashik.ali |
652 |
boolean insurance = false;
|
|
|
653 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
|
|
654 |
for(SerialNumberDetail serialNumberDetail : customFofoLineItem.getSerialNumberDetails()){
|
|
|
655 |
if(serialNumberDetail.getAmount() > 0){
|
|
|
656 |
insurance = true;
|
|
|
657 |
break;
|
|
|
658 |
}
|
|
|
659 |
}
|
|
|
660 |
}
|
|
|
661 |
LOGGER.info("insurance [{}] processing ....", insurance);
|
| 22217 |
ashik.ali |
662 |
|
| 22244 |
ashik.ali |
663 |
LocalDate customerDateOfBirth = null;
|
|
|
664 |
if(insurance){
|
| 22217 |
ashik.ali |
665 |
try{
|
| 22244 |
ashik.ali |
666 |
customerDateOfBirth = StringUtils.toDate(createOrderRequest.getCustomerDateOfBirth());
|
|
|
667 |
}catch(DateTimeException dateTimeException){
|
|
|
668 |
LOGGER.error("Unable to parse dateOfBirth", dateTimeException);
|
| 22253 |
ashik.ali |
669 |
throw new ProfitMandiBusinessException("dateOfBirth", createOrderRequest.getCustomerDateOfBirth(), "");
|
| 22217 |
ashik.ali |
670 |
}
|
|
|
671 |
}
|
| 22244 |
ashik.ali |
672 |
|
|
|
673 |
Customer customer = null;
|
|
|
674 |
try{
|
|
|
675 |
customer = customerRepository.selectByMobileNumber(customCustomer.getMobileNumber());
|
|
|
676 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
677 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
|
|
678 |
customer = new Customer();
|
|
|
679 |
customer.setFirstName(customCustomer.getFirstName());
|
|
|
680 |
customer.setLastName(customCustomer.getLastName());
|
|
|
681 |
customer.setEmailId(customCustomer.getEmailId());
|
|
|
682 |
customer.setMobileNumber(customCustomer.getMobileNumber());
|
|
|
683 |
customerRepository.persist(customer);
|
|
|
684 |
}
|
|
|
685 |
//TODO:Check if createOrderRequest contains addressId
|
|
|
686 |
CustomerAddress customerAddress = this.createCustomerAddress(customCustomer.getAddress());
|
|
|
687 |
customerAddress.setCustomerId(customer.getId());
|
|
|
688 |
customerAddressRepository.persist(customerAddress);
|
|
|
689 |
|
|
|
690 |
FofoOrder fofoOrder = new FofoOrder();
|
|
|
691 |
fofoOrder.setCustomerId(customer.getId());
|
|
|
692 |
fofoOrder.setFofoId(fofoDetails.getFofoId());
|
|
|
693 |
fofoOrder.setInvoiceNumber(invoiceNumberGenerationSequence.getPrefix() + invoiceNumberGenerationSequence.getSequence());
|
|
|
694 |
fofoOrder.setTotalAmount(totalAmount);
|
|
|
695 |
fofoOrder.setCustomerAddressId(customerAddress.getId());
|
|
|
696 |
fofoOrderRepository.persist(fofoOrder);
|
|
|
697 |
|
|
|
698 |
for(CustomPaymentOption customPaymentOption : createOrderRequest.getPaymentOptions()){
|
|
|
699 |
PaymentOption paymentOption = new PaymentOption();
|
|
|
700 |
paymentOption.setOrderId(fofoOrder.getId());
|
|
|
701 |
paymentOption.setAmount(customPaymentOption.getAmount());
|
|
|
702 |
paymentOption.setType(customPaymentOption.getType());
|
|
|
703 |
paymentOptionRepository.persist(paymentOption);
|
|
|
704 |
}
|
|
|
705 |
|
|
|
706 |
Address retailerAddress = addressRepository.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoDetails.getFofoId()));
|
|
|
707 |
Map<String, GstRate> gstRateMap = null;
|
|
|
708 |
if(retailerAddress.getState().equals(customerAddress.getState())){
|
|
|
709 |
gstRateMap = Utils.getGstRates(retailerAddress.getState());
|
|
|
710 |
}else{
|
|
|
711 |
LOGGER.info("inter gstRate = true");
|
|
|
712 |
gstRateMap = Utils.getInterGstRates();
|
|
|
713 |
}
|
|
|
714 |
LOGGER.info("gstRateMap {}", gstRateMap);
|
|
|
715 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
|
|
716 |
FofoLineItem fofoLineItem = new FofoLineItem();
|
|
|
717 |
fofoLineItem.setItemId(customFofoLineItem.getItemId());
|
|
|
718 |
fofoLineItem.setQuantity(customFofoLineItem.getQuantity());
|
|
|
719 |
fofoLineItem.setSellingPrice(customFofoLineItem.getSellingPrice());
|
|
|
720 |
fofoLineItem.setOrderId(fofoOrder.getId());
|
|
|
721 |
fofoLineItem.setDp(customFofoLineItem.getSellingPrice());
|
|
|
722 |
Item item = itemMap.get(customFofoLineItem.getItemId());
|
|
|
723 |
GstRate gstRate = gstRateMap.get(item.getHsnCode());
|
|
|
724 |
fofoLineItem.setIgstRate(gstRate.getIgstRate());
|
|
|
725 |
fofoLineItem.setCgstRate(gstRate.getCgstRate());
|
|
|
726 |
fofoLineItem.setSgstRate(gstRate.getSgstRate());
|
|
|
727 |
fofoLineItem.setHsnCode(gstRate.getHsnCode());
|
|
|
728 |
List<Float> priceDropAmounts = itemIdPriceDropAmount.get(customFofoLineItem.getItemId());
|
|
|
729 |
float cost = 0;
|
|
|
730 |
if (priceDropAmounts!=null){
|
|
|
731 |
for (Float pda : priceDropAmounts){
|
|
|
732 |
cost = cost + pda;
|
|
|
733 |
}
|
|
|
734 |
}
|
|
|
735 |
else{
|
|
|
736 |
cost = customFofoLineItem.getSellingPrice()* customFofoLineItem.getQuantity();
|
|
|
737 |
}
|
|
|
738 |
fofoLineItem.setCost(cost);
|
|
|
739 |
fofoLineItem.setBrand(item.getBrand());
|
|
|
740 |
fofoLineItem.setModelName(item.getModelName());
|
|
|
741 |
fofoLineItem.setModelNumber(item.getModelNumber());
|
|
|
742 |
fofoLineItem.setColor(item.getColor());
|
|
|
743 |
fofoLineItemRepository.persist(fofoLineItem);
|
|
|
744 |
LOGGER.info("\n\n");
|
|
|
745 |
if(!customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
|
|
746 |
for(SerialNumberDetail serialNumberDetail : customFofoLineItem.getSerialNumberDetails()){
|
|
|
747 |
FofoLineItemSerialNumber fofoLineItemSerialNumber = new FofoLineItemSerialNumber();
|
|
|
748 |
fofoLineItemSerialNumber.setFofoLineItemId(fofoLineItem.getId());
|
|
|
749 |
fofoLineItemSerialNumber.setSerialNumber(serialNumberDetail.getSerialNumber());
|
|
|
750 |
fofoLineItemSerialNumberRepository.persist(fofoLineItemSerialNumber);
|
|
|
751 |
}
|
|
|
752 |
}
|
|
|
753 |
|
|
|
754 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots){
|
|
|
755 |
FofoItemId fofoItemId = new FofoItemId();
|
|
|
756 |
fofoItemId.setFofoId(fofoDetails.getFofoId());
|
|
|
757 |
fofoItemId.setItemId(fofoLineItem.getItemId());
|
|
|
758 |
if(currentInventorySnapshot.getId().equals(fofoItemId)){
|
|
|
759 |
currentInventorySnapshotRepository.updateAvailabilityByFofoItemId(fofoItemId, currentInventorySnapshot.getAvailability() - customFofoLineItem.getQuantity());
|
|
|
760 |
}
|
|
|
761 |
}
|
|
|
762 |
List<InventoryItem> inventoryItems = inventoryItemsToBill.get(fofoLineItem.getItemId());
|
|
|
763 |
for(InventoryItem inventoryItem : inventoryItems){
|
|
|
764 |
inventoryItem.setLastScanType(ScanType.SALE);
|
| 22253 |
ashik.ali |
765 |
inventoryItemRepository.persist(inventoryItem);
|
|
|
766 |
ScanRecord scanRecord = new ScanRecord();
|
| 22244 |
ashik.ali |
767 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
|
|
768 |
scanRecord.setFofoId(fofoDetails.getFofoId());
|
|
|
769 |
//correct this
|
|
|
770 |
scanRecord.setQuantity(inventoryItemQuantityUsed.get(inventoryItem.getId()));
|
|
|
771 |
scanRecord.setType(ScanType.SALE);
|
| 22253 |
ashik.ali |
772 |
scanRecordRepository.persist(scanRecord);
|
| 22244 |
ashik.ali |
773 |
}
|
|
|
774 |
}
|
|
|
775 |
|
|
|
776 |
// insurance calculation is insurance flag is enabled
|
|
|
777 |
if(!insuranceSerialNumberItemPrice.isEmpty()){
|
|
|
778 |
LOGGER.info("Processing for insurence for serialNumbers");
|
|
|
779 |
Map<Float, GadgetCopsInsuranceCalc> insurancePricesMap = pricingService.getInsurancePrices(new HashSet<>(insuranceSerialNumberItemPrice.values()), ProfitMandiConstants.GADGET_COPS);
|
|
|
780 |
InsuranceProvider insuranceProvider = insuranceProviderRepository.selectByName(ProfitMandiConstants.GADGET_COPS);
|
|
|
781 |
|
|
|
782 |
|
|
|
783 |
Map<Float, Float> invalidInsurancePurchaseSaleAmount = new HashMap<>();
|
|
|
784 |
Map<Float, Float> invalidInsuranceSalePurchaseAmount = new HashMap<>();
|
|
|
785 |
for(Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()){
|
|
|
786 |
if(insuranceSerialNumberSaleAmount.get(entry.getKey()) < insurancePricesMap.get(entry.getValue()).getDealerPrice()){
|
|
|
787 |
invalidInsurancePurchaseSaleAmount.put(insurancePricesMap.get(entry.getValue()).getDealerPrice(), insuranceSerialNumberSaleAmount.get(entry.getKey()));
|
|
|
788 |
}
|
|
|
789 |
|
|
|
790 |
if(insuranceSerialNumberSaleAmount.get(entry.getKey()) > insurancePricesMap.get(entry.getValue()).getSellingPrice()){
|
|
|
791 |
invalidInsuranceSalePurchaseAmount.put(insuranceSerialNumberSaleAmount.get(entry.getKey()), insurancePricesMap.get(entry.getValue()).getDealerPrice());
|
|
|
792 |
}
|
|
|
793 |
}
|
|
|
794 |
|
|
|
795 |
// insurance sale amount can not be lesser than insurance purchase amount
|
|
|
796 |
if(!invalidInsurancePurchaseSaleAmount.isEmpty()){
|
|
|
797 |
LOGGER.error("Invalid Insurance prices [{}], insurance sale amount can not be lesser than insurance purchase amount", invalidInsurancePurchaseSaleAmount);
|
|
|
798 |
return "error";
|
|
|
799 |
}
|
|
|
800 |
|
|
|
801 |
if(!invalidInsuranceSalePurchaseAmount.isEmpty()){
|
|
|
802 |
LOGGER.error("Invalid Insurance prices [{}], insurance sale amount can not be greater than than insurance max amount", invalidInsuranceSalePurchaseAmount);
|
|
|
803 |
return "error";
|
|
|
804 |
}
|
|
|
805 |
|
|
|
806 |
|
|
|
807 |
for(Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()){
|
|
|
808 |
PolicyNumberGenerationSequence policyNumberGenerationSequence = null;
|
|
|
809 |
try{
|
|
|
810 |
policyNumberGenerationSequence = policyNumberGenerationSequenceRepository.select();
|
|
|
811 |
policyNumberGenerationSequence.setSequence(policyNumberGenerationSequence.getSequence() + 1);
|
|
|
812 |
policyNumberGenerationSequenceRepository.persist(policyNumberGenerationSequence);
|
|
|
813 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
814 |
policyNumberGenerationSequence = new PolicyNumberGenerationSequence();
|
|
|
815 |
policyNumberGenerationSequence.setSequence(1);
|
|
|
816 |
policyNumberGenerationSequenceRepository.persist(policyNumberGenerationSequence);
|
|
|
817 |
}
|
|
|
818 |
|
|
|
819 |
InsurancePolicy insurancePolicy = new InsurancePolicy();
|
|
|
820 |
insurancePolicy.setInvoiceNumber(invoiceNumberGenerationSequence.getPrefix() + invoiceNumberGenerationSequence.getSequence());
|
|
|
821 |
insurancePolicy.setRetailerId(fofoDetails.getFofoId());
|
|
|
822 |
insurancePolicy.setPurchaseAmount(insurancePricesMap.get(entry.getValue()).getDealerPrice());
|
|
|
823 |
insurancePolicy.setSaleAmount(insuranceSerialNumberSaleAmount.get(entry.getKey()));
|
|
|
824 |
insurancePolicy.setSellingPrice(entry.getValue());
|
|
|
825 |
insurancePolicy.setSerialNumber(entry.getKey());
|
|
|
826 |
insurancePolicy.setModelName(serialNumberModelName.get(entry.getKey()));
|
|
|
827 |
insurancePolicy.setBrand(serialNumberBrand.get(entry.getKey()));
|
|
|
828 |
insurancePolicy.setPolicyNumber(StringUtils.generatePolicyNumber(ProfitMandiConstants.POLICY_NUMBER_PREFIX, policyNumberGenerationSequence.getSequence()));
|
|
|
829 |
insurancePolicy.setProviderId(insuranceProvider.getId());
|
|
|
830 |
insurancePolicy.setCustomerFirstName(customer.getFirstName());
|
|
|
831 |
insurancePolicy.setCustomerLastName(customer.getLastName());
|
|
|
832 |
insurancePolicy.setCustomerMobileNumber(customer.getMobileNumber());
|
|
|
833 |
insurancePolicy.setCustomerEmailId(customer.getEmailId());
|
|
|
834 |
insurancePolicy.setCustomerDateOfBirth(customerDateOfBirth);
|
|
|
835 |
insurancePolicy.setCustomerAddress1(customerAddress.getLine1());
|
|
|
836 |
insurancePolicy.setCustomerAddress2(customerAddress.getLine2());
|
|
|
837 |
insurancePolicy.setCustomerCity(customerAddress.getCity());
|
|
|
838 |
insurancePolicy.setCustomerPinCode(customerAddress.getPinCode());
|
|
|
839 |
insurancePolicy.setCustomerState(customerAddress.getState());
|
|
|
840 |
|
|
|
841 |
GadgetCopsInsuranceModel gadgetCopsInsuranceModel = new GadgetCopsInsuranceModel();
|
|
|
842 |
gadgetCopsInsuranceModel.setBrand(serialNumberBrand.get(entry.getKey()));
|
|
|
843 |
gadgetCopsInsuranceModel.setModelName(serialNumberModelName.get(entry.getKey()));
|
|
|
844 |
gadgetCopsInsuranceModel.setSerialNumber(entry.getKey());
|
|
|
845 |
gadgetCopsInsuranceModel.setCustomerFirstName(customer.getFirstName());
|
|
|
846 |
gadgetCopsInsuranceModel.setCustomerLastName(customer.getLastName());
|
|
|
847 |
gadgetCopsInsuranceModel.setCustomerDateOfBirth(customerDateOfBirth);
|
|
|
848 |
gadgetCopsInsuranceModel.setCustomerMobileNumber(customer.getMobileNumber());
|
|
|
849 |
gadgetCopsInsuranceModel.setCustomerEmailId(customer.getEmailId());
|
|
|
850 |
gadgetCopsInsuranceModel.setCustomerAddress1(customerAddress.getLine1());
|
|
|
851 |
gadgetCopsInsuranceModel.setCustomerAddress2(customerAddress.getLine2());
|
|
|
852 |
gadgetCopsInsuranceModel.setCustomerCity(customerAddress.getCity());
|
|
|
853 |
gadgetCopsInsuranceModel.setCustomerPinCode(customerAddress.getPinCode());
|
|
|
854 |
gadgetCopsInsuranceModel.setCustomerState(customerAddress.getState());
|
|
|
855 |
gadgetCopsInsuranceModel.setPrice(insurancePolicy.getSellingPrice());
|
|
|
856 |
gadgetCopsInsuranceModel.setInvoiceNumber(insurancePolicy.getInvoiceNumber());
|
|
|
857 |
gadgetCopsInsuranceModel.setPolicyNumber(insurancePolicy.getPolicyNumber());
|
|
|
858 |
|
|
|
859 |
try{
|
|
|
860 |
InsuranceUtils.submitToGadgetCops(gadgetCopsInsuranceModel);
|
|
|
861 |
insurancePolicy.setPosted(true);
|
|
|
862 |
}catch (ProfitMandiBusinessException profitMandiBusinessException) {
|
|
|
863 |
LOGGER.info("Unable to submit insurance policy details to {}", insuranceProvider.getName(), profitMandiBusinessException);
|
|
|
864 |
}
|
|
|
865 |
insurancePolicyRepository.persist(insurancePolicy);
|
|
|
866 |
}
|
|
|
867 |
}
|
|
|
868 |
LOGGER.info("Order has been created successfully...");
|
|
|
869 |
return "redirect:/get-order/?orderId="+fofoOrder.getId();
|
|
|
870 |
}catch (Exception e) {
|
|
|
871 |
LOGGER.error("Unable to create order : ", e);
|
|
|
872 |
return "error";
|
| 22217 |
ashik.ali |
873 |
}
|
| 21612 |
ashik.ali |
874 |
}
|
| 21985 |
kshitij.so |
875 |
|
| 21711 |
ashik.ali |
876 |
private CustomerAddress createCustomerAddress(CustomAddress customAddress){
|
|
|
877 |
CustomerAddress customerAddress = new CustomerAddress();
|
|
|
878 |
customerAddress.setName(customAddress.getName());
|
|
|
879 |
customerAddress.setLine1(customAddress.getLine1());
|
|
|
880 |
customerAddress.setLine2(customAddress.getLine2());
|
|
|
881 |
customerAddress.setLandmark(customAddress.getLandmark());
|
|
|
882 |
customerAddress.setCity(customAddress.getCity());
|
|
|
883 |
customerAddress.setPinCode(customAddress.getPinCode());
|
|
|
884 |
customerAddress.setState(customAddress.getState());
|
|
|
885 |
customerAddress.setCountry(customAddress.getCountry());
|
|
|
886 |
customerAddress.setPhoneNumber(customAddress.getPhoneNumber());
|
|
|
887 |
return customerAddress;
|
| 21680 |
ashik.ali |
888 |
}
|
| 21985 |
kshitij.so |
889 |
|
| 21689 |
ashik.ali |
890 |
private CustomAddress createCustomAddress(Address address){
|
|
|
891 |
CustomAddress customAddress = new CustomAddress();
|
|
|
892 |
customAddress.setName(address.getName());
|
|
|
893 |
customAddress.setLine1(address.getLine1());
|
|
|
894 |
customAddress.setLine2(address.getLine2());
|
|
|
895 |
customAddress.setLandmark(address.getLandmark());
|
|
|
896 |
customAddress.setCity(address.getCity());
|
|
|
897 |
customAddress.setPinCode(address.getPinCode());
|
|
|
898 |
customAddress.setState(address.getState());
|
|
|
899 |
customAddress.setCountry(address.getCountry());
|
|
|
900 |
customAddress.setPhoneNumber(address.getPhoneNumber());
|
|
|
901 |
return customAddress;
|
| 21680 |
ashik.ali |
902 |
}
|
| 21985 |
kshitij.so |
903 |
|
| 21711 |
ashik.ali |
904 |
private CustomAddress createCustomAddress(CustomerAddress customerAddress){
|
|
|
905 |
CustomAddress customAddress = new CustomAddress();
|
|
|
906 |
customAddress.setName(customerAddress.getName());
|
|
|
907 |
customAddress.setLine1(customerAddress.getLine1());
|
|
|
908 |
customAddress.setLine2(customerAddress.getLine2());
|
|
|
909 |
customAddress.setLandmark(customerAddress.getLandmark());
|
|
|
910 |
customAddress.setCity(customerAddress.getCity());
|
|
|
911 |
customAddress.setPinCode(customerAddress.getPinCode());
|
|
|
912 |
customAddress.setState(customerAddress.getState());
|
|
|
913 |
customAddress.setCountry(customerAddress.getCountry());
|
|
|
914 |
customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
|
|
|
915 |
return customAddress;
|
|
|
916 |
}
|
| 21985 |
kshitij.so |
917 |
|
| 21680 |
ashik.ali |
918 |
private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
|
| 21612 |
ashik.ali |
919 |
{
|
|
|
920 |
float calculatedAmount = 0;
|
|
|
921 |
Set<String> paymentOptionTypes = new HashSet<>();
|
|
|
922 |
for(CustomPaymentOption customPaymentOption : customPaymentOptions){
|
| 21680 |
ashik.ali |
923 |
if(paymentOptionTypes.contains(customPaymentOption.getType().name())){
|
| 21612 |
ashik.ali |
924 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_TYPE, customPaymentOption.getType().name(), "");
|
| 21680 |
ashik.ali |
925 |
}else{
|
|
|
926 |
paymentOptionTypes.add(customPaymentOption.getType().name());
|
|
|
927 |
calculatedAmount = calculatedAmount + customPaymentOption.getAmount();
|
| 21612 |
ashik.ali |
928 |
}
|
|
|
929 |
}
|
|
|
930 |
if(calculatedAmount != totalAmount){
|
| 22244 |
ashik.ali |
931 |
LOGGER.error("PaymentOptionCalculatedAmount [{}] != TotalAmount [{}]", calculatedAmount, totalAmount);
|
| 21612 |
ashik.ali |
932 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "");
|
|
|
933 |
}
|
|
|
934 |
}
|
| 21985 |
kshitij.so |
935 |
|
|
|
936 |
|
| 21689 |
ashik.ali |
937 |
@RequestMapping(value = "/generateInvoice")
|
| 21896 |
ashik.ali |
938 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws Throwable{
|
| 22064 |
ashik.ali |
939 |
LOGGER.info("Request received at url {} with params [{}={}] ", request.getRequestURI(), ProfitMandiConstants.ORDER_ID, orderId);
|
| 22139 |
amit.gupta |
940 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 22217 |
ashik.ali |
941 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 22026 |
ashik.ali |
942 |
|
| 21689 |
ashik.ali |
943 |
PdfModel pdfModel = new PdfModel();
|
|
|
944 |
pdfModel.setAuther("profitmandi");
|
|
|
945 |
pdfModel.setTitle("Retailer Invoice");
|
| 22217 |
ashik.ali |
946 |
|
|
|
947 |
// insurance calculation
|
|
|
948 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByInvoiceNumber(fofoOrder.getInvoiceNumber());
|
|
|
949 |
Set<CustomInsurancePolicy> customInsurancePolicies = new HashSet<>();
|
|
|
950 |
final float totalInsuranceTaxRate = 18;
|
|
|
951 |
for(InsurancePolicy insurancePolicy : insurancePolicies){
|
|
|
952 |
float taxableInsurancePrice = insurancePolicy.getSaleAmount() / (1 + totalInsuranceTaxRate / 100);
|
|
|
953 |
CustomInsurancePolicy customInsurancePolicy = new CustomInsurancePolicy();
|
| 22244 |
ashik.ali |
954 |
customInsurancePolicy.setDescription(insurancePolicy.getInsuranceProvider().getName() + " Protection (" + insurancePolicy.getSerialNumber() + ")");
|
| 22217 |
ashik.ali |
955 |
customInsurancePolicy.setHsnCode("");
|
|
|
956 |
customInsurancePolicy.setRate(taxableInsurancePrice);
|
|
|
957 |
customInsurancePolicy.setIgstRate(18);
|
|
|
958 |
customInsurancePolicy.setIgstAmount(taxableInsurancePrice * 18 /100);
|
|
|
959 |
customInsurancePolicy.setCgstRate(18);
|
|
|
960 |
customInsurancePolicy.setCgstAmount(taxableInsurancePrice * 9 /100);
|
|
|
961 |
customInsurancePolicy.setSgstRate(9);
|
|
|
962 |
customInsurancePolicy.setSgstAmount(taxableInsurancePrice * 9 /100);
|
|
|
963 |
customInsurancePolicies.add(customInsurancePolicy);
|
|
|
964 |
}
|
|
|
965 |
pdfModel.setInsurancePolicies(customInsurancePolicies);
|
| 21689 |
ashik.ali |
966 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
|
|
967 |
CustomCustomer customCustomer = new CustomCustomer();
|
| 22217 |
ashik.ali |
968 |
customCustomer.setFirstName(customer.getFirstName());
|
|
|
969 |
customCustomer.setLastName(customer.getLastName());
|
| 21689 |
ashik.ali |
970 |
customCustomer.setEmailId(customer.getEmailId());
|
|
|
971 |
customCustomer.setMobileNumber(customer.getMobileNumber());
|
| 21711 |
ashik.ali |
972 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 21689 |
ashik.ali |
973 |
customCustomer.setAddress(this.createCustomAddress(customerAddress));
|
|
|
974 |
pdfModel.setCustomer(customCustomer);
|
|
|
975 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
| 22244 |
ashik.ali |
976 |
pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
|
| 22026 |
ashik.ali |
977 |
|
| 21689 |
ashik.ali |
978 |
Retailer retailer = retailerRepository.selectById(fofoDetails.getFofoId());
|
|
|
979 |
User user = userRepository.selectById(userAccountRepository.selectUserIdByRetailerId(retailer.getId()));
|
|
|
980 |
CustomRetailer customRetailer = new CustomRetailer();
|
|
|
981 |
customRetailer.setBusinessName(retailer.getName());
|
|
|
982 |
customRetailer.setMobileNumber(user.getMobileNumber());
|
|
|
983 |
customRetailer.setTinNumber(retailer.getNumber());
|
|
|
984 |
Address retailerAddress = addressRepository.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId()));
|
|
|
985 |
customRetailer.setAddress(this.createCustomAddress(retailerAddress));
|
|
|
986 |
pdfModel.setRetailer(customRetailer);
|
|
|
987 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
|
| 22026 |
ashik.ali |
988 |
|
| 21689 |
ashik.ali |
989 |
Set<CustomFofoOrderItem> customerFofoOrderItems = new HashSet<>();
|
|
|
990 |
for(FofoLineItem fofoLineItem : fofoLineItems){
|
|
|
991 |
CustomFofoOrderItem customFofoOrderItem = new CustomFofoOrderItem();
|
| 22026 |
ashik.ali |
992 |
float totalTaxRate = fofoLineItem.getIgstRate() + fofoLineItem.getSgstRate() + fofoLineItem.getCgstRate();
|
|
|
993 |
float taxableSellingPrice = fofoLineItem.getSellingPrice() / (1 + totalTaxRate / 100);
|
|
|
994 |
|
|
|
995 |
customFofoOrderItem.setAmount(fofoLineItem.getQuantity() * taxableSellingPrice);
|
| 21689 |
ashik.ali |
996 |
customFofoOrderItem.setDescription(fofoLineItem.getBrand() + " " + fofoLineItem.getModelName() + " " + fofoLineItem.getModelNumber() + " " + fofoLineItem.getColor());
|
| 22026 |
ashik.ali |
997 |
customFofoOrderItem.setRate(taxableSellingPrice);
|
| 21689 |
ashik.ali |
998 |
customFofoOrderItem.setQuantity(fofoLineItem.getQuantity());
|
| 22026 |
ashik.ali |
999 |
float igstAmount = (customFofoOrderItem.getAmount() * fofoLineItem.getIgstRate()) / 100;
|
|
|
1000 |
float cgstAmount = (customFofoOrderItem.getAmount() * fofoLineItem.getCgstRate()) / 100;
|
|
|
1001 |
float sgstAmount = (customFofoOrderItem.getAmount() * fofoLineItem.getSgstRate()) / 100;
|
| 21896 |
ashik.ali |
1002 |
customFofoOrderItem.setIgstRate(fofoLineItem.getIgstRate());
|
| 22026 |
ashik.ali |
1003 |
customFofoOrderItem.setIgstAmount(igstAmount);
|
|
|
1004 |
customFofoOrderItem.setCgstRate(fofoLineItem.getCgstRate());
|
|
|
1005 |
customFofoOrderItem.setCgstAmount(cgstAmount);
|
|
|
1006 |
customFofoOrderItem.setSgstRate(fofoLineItem.getSgstRate());
|
|
|
1007 |
customFofoOrderItem.setSgstAmount(sgstAmount);
|
| 21896 |
ashik.ali |
1008 |
customFofoOrderItem.setHsnCode(fofoLineItem.getHsnCode());
|
| 21689 |
ashik.ali |
1009 |
customFofoOrderItem.setSerialNumbers(String.join(", ",this.toSerialNumbers(fofoLineItem.getFofoLineItemSerialNumbers())));
|
|
|
1010 |
customerFofoOrderItems.add(customFofoOrderItem);
|
|
|
1011 |
}
|
|
|
1012 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
|
|
1013 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
1014 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
|
|
1015 |
//final MediaType mediaType=MediaType.parseMediaType(profilePhotoModel.getContentType().getValue());
|
|
|
1016 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 22026 |
ashik.ali |
1017 |
final HttpHeaders headers=new HttpHeaders();
|
|
|
1018 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
| 22099 |
kshitij.so |
1019 |
headers.set("Content-disposition", "inline; filename=invoice-" + fofoOrder.getInvoiceNumber() + ".pdf");
|
| 22026 |
ashik.ali |
1020 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
1021 |
final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
1022 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
|
|
1023 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 21689 |
ashik.ali |
1024 |
}
|
| 21985 |
kshitij.so |
1025 |
|
| 21689 |
ashik.ali |
1026 |
private Set<String> toSerialNumbers(Set<FofoLineItemSerialNumber> fofoLineItemSerialNumbers){
|
|
|
1027 |
Set<String> serialNumbers = new HashSet<>(fofoLineItemSerialNumbers.size());
|
|
|
1028 |
for(FofoLineItemSerialNumber fofoLineItemSerialNumber : fofoLineItemSerialNumbers){
|
|
|
1029 |
serialNumbers.add(fofoLineItemSerialNumber.getSerialNumber());
|
|
|
1030 |
}
|
|
|
1031 |
return serialNumbers;
|
|
|
1032 |
}
|
| 22244 |
ashik.ali |
1033 |
|
|
|
1034 |
@RequestMapping(value = "/saleHistory")
|
|
|
1035 |
public String saleHistory(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, @RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER, defaultValue = "") String invoiceNumber, @RequestParam(name = "searchType",defaultValue="") String searchType, Model model) throws Exception{
|
|
|
1036 |
LoginDetails loginDetails = null;
|
|
|
1037 |
try {
|
|
|
1038 |
loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1039 |
} catch (ProfitMandiBusinessException e) {
|
|
|
1040 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
1041 |
return "response";
|
|
|
1042 |
}
|
|
|
1043 |
|
|
|
1044 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
1045 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
|
|
1046 |
long countItems = 0;
|
|
|
1047 |
List<FofoOrder> fofoOrders = new ArrayList<>();
|
|
|
1048 |
if(searchType.equalsIgnoreCase("purchaseReference") && !invoiceNumber.isEmpty()){
|
|
|
1049 |
try {
|
|
|
1050 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndInvoiceNumber(loginDetails.getFofoId(), invoiceNumber);
|
|
|
1051 |
fofoOrders.add(fofoOrder);
|
|
|
1052 |
} catch (ProfitMandiBusinessException e) {
|
|
|
1053 |
LOGGER.info("Sale history not found : ", e);
|
|
|
1054 |
}
|
|
|
1055 |
}else{
|
|
|
1056 |
fofoOrders = fofoOrderRepository.selectByFofoId(loginDetails.getFofoId(),startDateTime, endDateTime, offset, limit);
|
|
|
1057 |
countItems = fofoOrderRepository.selectCount(loginDetails.getFofoId(), startDateTime, endDateTime, invoiceNumber, searchType);
|
|
|
1058 |
}
|
|
|
1059 |
|
|
|
1060 |
model.addAttribute("saleHistories", fofoOrders);
|
|
|
1061 |
model.addAttribute("start",offset+1);
|
|
|
1062 |
model.addAttribute("size",countItems);
|
|
|
1063 |
model.addAttribute("searchType",searchType);
|
|
|
1064 |
model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
|
|
|
1065 |
model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
|
|
|
1066 |
if (fofoOrders.size() < limit){
|
|
|
1067 |
model.addAttribute("end",offset + fofoOrders.size());
|
|
|
1068 |
}
|
|
|
1069 |
else{
|
|
|
1070 |
model.addAttribute("end",offset+limit);
|
|
|
1071 |
}
|
|
|
1072 |
|
|
|
1073 |
return "sale-history";
|
|
|
1074 |
}
|
| 21985 |
kshitij.so |
1075 |
|
| 21612 |
ashik.ali |
1076 |
}
|