| Line 4... |
Line 4... |
| 4 |
import java.io.ByteArrayOutputStream;
|
4 |
import java.io.ByteArrayOutputStream;
|
| 5 |
import java.io.InputStream;
|
5 |
import java.io.InputStream;
|
| 6 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 7 |
import java.util.HashMap;
|
7 |
import java.util.HashMap;
|
| 8 |
import java.util.HashSet;
|
8 |
import java.util.HashSet;
|
| - |
|
9 |
import java.util.Iterator;
|
| 9 |
import java.util.List;
|
10 |
import java.util.List;
|
| 10 |
import java.util.Map;
|
11 |
import java.util.Map;
|
| 11 |
import java.util.Set;
|
12 |
import java.util.Set;
|
| 12 |
|
13 |
|
| 13 |
import javax.servlet.http.HttpServletRequest;
|
14 |
import javax.servlet.http.HttpServletRequest;
|
| 14 |
import javax.servlet.http.HttpServletResponse;
|
15 |
import javax.servlet.http.HttpServletResponse;
|
| 15 |
import javax.transaction.Transactional;
|
16 |
import javax.transaction.Transactional;
|
| 16 |
|
17 |
|
| - |
|
18 |
import org.json.JSONObject;
|
| 17 |
import org.slf4j.Logger;
|
19 |
import org.slf4j.Logger;
|
| 18 |
import org.slf4j.LoggerFactory;
|
20 |
import org.slf4j.LoggerFactory;
|
| 19 |
import org.springframework.beans.factory.annotation.Autowired;
|
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 20 |
import org.springframework.core.io.InputStreamResource;
|
22 |
import org.springframework.core.io.InputStreamResource;
|
| 21 |
import org.springframework.http.HttpHeaders;
|
23 |
import org.springframework.http.HttpHeaders;
|
| 22 |
import org.springframework.http.HttpStatus;
|
24 |
import org.springframework.http.HttpStatus;
|
| 23 |
import org.springframework.http.MediaType;
|
25 |
import org.springframework.http.MediaType;
|
| 24 |
import org.springframework.http.ResponseEntity;
|
26 |
import org.springframework.http.ResponseEntity;
|
| 25 |
import org.springframework.stereotype.Controller;
|
27 |
import org.springframework.stereotype.Controller;
|
| - |
|
28 |
import org.springframework.ui.Model;
|
| 26 |
import org.springframework.web.bind.annotation.RequestBody;
|
29 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 27 |
import org.springframework.web.bind.annotation.RequestMapping;
|
30 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 28 |
import org.springframework.web.bind.annotation.RequestMethod;
|
31 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 29 |
import org.springframework.web.bind.annotation.RequestParam;
|
32 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 30 |
|
33 |
|
| 31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
34 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
35 |
import com.spice.profitmandi.common.model.CartFofo;
|
| 32 |
import com.spice.profitmandi.common.model.CustomAddress;
|
36 |
import com.spice.profitmandi.common.model.CustomAddress;
|
| 33 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
37 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
| 34 |
import com.spice.profitmandi.common.model.CustomFofoLineItem;
|
38 |
import com.spice.profitmandi.common.model.CustomFofoLineItem;
|
| 35 |
import com.spice.profitmandi.common.model.CustomFofoOrderItem;
|
39 |
import com.spice.profitmandi.common.model.CustomFofoOrderItem;
|
| 36 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
40 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| Line 53... |
Line 57... |
| 53 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
57 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 54 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
58 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
| 55 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
59 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 56 |
import com.spice.profitmandi.dao.entity.user.Address;
|
60 |
import com.spice.profitmandi.dao.entity.user.Address;
|
| 57 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
61 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| - |
|
62 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 58 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
63 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
|
| 59 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
64 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 60 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
65 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 61 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
66 |
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
|
| 62 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
67 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| Line 82... |
Line 87... |
| 82 |
@Controller
|
87 |
@Controller
|
| 83 |
@Transactional
|
88 |
@Transactional
|
| 84 |
public class OrderController {
|
89 |
public class OrderController {
|
| 85 |
|
90 |
|
| 86 |
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
91 |
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
| 87 |
|
92 |
|
| 88 |
@Autowired
|
93 |
@Autowired
|
| 89 |
OrderRepository orderRepository;
|
94 |
OrderRepository orderRepository;
|
| 90 |
|
95 |
|
| 91 |
@Autowired
|
96 |
@Autowired
|
| 92 |
InventoryItemRepository inventoryItemRepository;
|
97 |
InventoryItemRepository inventoryItemRepository;
|
| 93 |
|
98 |
|
| 94 |
@Autowired
|
99 |
@Autowired
|
| 95 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
100 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 96 |
|
101 |
|
| 97 |
@Autowired
|
102 |
@Autowired
|
| 98 |
InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
|
103 |
InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
|
| 99 |
|
104 |
|
| 100 |
@Autowired
|
105 |
@Autowired
|
| 101 |
CustomerRepository customerRepository;
|
106 |
CustomerRepository customerRepository;
|
| 102 |
|
107 |
|
| 103 |
@Autowired
|
108 |
@Autowired
|
| 104 |
AddressRepository addressRepository;
|
109 |
AddressRepository addressRepository;
|
| 105 |
|
110 |
|
| 106 |
@Autowired
|
111 |
@Autowired
|
| 107 |
FofoLineItemSerialNumberRepository fofoLineItemSerialNumberRepository;
|
112 |
FofoLineItemSerialNumberRepository fofoLineItemSerialNumberRepository;
|
| 108 |
|
113 |
|
| 109 |
@Autowired
|
114 |
@Autowired
|
| 110 |
FofoLineItemRepository fofoLineItemRepository;
|
115 |
FofoLineItemRepository fofoLineItemRepository;
|
| 111 |
|
116 |
|
| 112 |
@Autowired
|
117 |
@Autowired
|
| 113 |
PaymentOptionRepository paymentOptionRepository;
|
118 |
PaymentOptionRepository paymentOptionRepository;
|
| 114 |
|
119 |
|
| 115 |
@Autowired
|
120 |
@Autowired
|
| 116 |
ScanRecordRepository scanRecordRepository;
|
121 |
ScanRecordRepository scanRecordRepository;
|
| 117 |
|
122 |
|
| 118 |
@Autowired
|
123 |
@Autowired
|
| 119 |
FofoOrderRepository fofoOrderRepository;
|
124 |
FofoOrderRepository fofoOrderRepository;
|
| 120 |
|
125 |
|
| 121 |
@Autowired
|
126 |
@Autowired
|
| 122 |
RetailerRepository retailerRepository;
|
127 |
RetailerRepository retailerRepository;
|
| 123 |
|
128 |
|
| 124 |
@Autowired
|
129 |
@Autowired
|
| 125 |
UserRepository userRepository;
|
130 |
UserRepository userRepository;
|
| 126 |
|
131 |
|
| 127 |
@Autowired
|
132 |
@Autowired
|
| 128 |
UserAccountRepository userAccountRepository;
|
133 |
UserAccountRepository userAccountRepository;
|
| - |
|
134 |
|
| - |
|
135 |
@Autowired
|
| - |
|
136 |
ItemRepository itemRepository;
|
| 129 |
|
137 |
|
| 130 |
@Autowired
|
138 |
@Autowired
|
| 131 |
RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
139 |
RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 132 |
|
140 |
|
| 133 |
@Autowired
|
141 |
@Autowired
|
| 134 |
CustomerAddressRepository customerAddressRepository;
|
142 |
CustomerAddressRepository customerAddressRepository;
|
| 135 |
|
143 |
|
| 136 |
@Autowired
|
144 |
@Autowired
|
| 137 |
MVCResponseSender mvcResponseSender;
|
145 |
MVCResponseSender mvcResponseSender;
|
| 138 |
|
146 |
|
| 139 |
@Autowired
|
147 |
@Autowired
|
| 140 |
CookiesFetcher cookiesFetcher;
|
148 |
CookiesFetcher cookiesFetcher;
|
| - |
|
149 |
|
| - |
|
150 |
@RequestMapping(value = "/order")
|
| - |
|
151 |
public String orderIndex(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
| - |
|
152 |
FofoDetails fofoDetails;
|
| - |
|
153 |
try {
|
| - |
|
154 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| - |
|
155 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
156 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
| - |
|
157 |
return "response";
|
| - |
|
158 |
}
|
| - |
|
159 |
JSONObject cartObject = new JSONObject(cartData);
|
| - |
|
160 |
Iterator<?> keys = cartObject.keys();
|
| - |
|
161 |
|
| - |
|
162 |
Set<Integer> itemIds = new HashSet<>();
|
| - |
|
163 |
List<CartFofo> cartItems = new ArrayList<CartFofo>();
|
| - |
|
164 |
|
| - |
|
165 |
while( keys.hasNext() ) {
|
| - |
|
166 |
String key = (String)keys.next();
|
| - |
|
167 |
if ( cartObject.get(key) instanceof JSONObject ) {
|
| - |
|
168 |
System.out.println(cartObject.get(key));
|
| - |
|
169 |
}
|
| - |
|
170 |
CartFofo cf = new CartFofo();
|
| - |
|
171 |
cf.setItemId(cartObject.getJSONObject(key).getInt("itemId"));
|
| - |
|
172 |
cf.setQuantity(cartObject.getJSONObject(key).getInt("quantity"));
|
| - |
|
173 |
cartItems.add(cf);
|
| - |
|
174 |
itemIds.add(cartObject.getJSONObject(key).getInt("itemId"));
|
| - |
|
175 |
}
|
| - |
|
176 |
Map<Integer, Item> itemMap = new HashMap<Integer, Item>();
|
| - |
|
177 |
if (itemIds.size() > 0){
|
| - |
|
178 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
| - |
|
179 |
for (Item i : items){
|
| - |
|
180 |
itemMap.put(i.getId(), i);
|
| - |
|
181 |
}
|
| - |
|
182 |
}
|
| - |
|
183 |
for (CartFofo cf : cartItems){
|
| - |
|
184 |
Item i = itemMap.get(cf.getItemId());
|
| - |
|
185 |
if (i == null){
|
| - |
|
186 |
continue;
|
| - |
|
187 |
}
|
| - |
|
188 |
cf.setDisplayName(getValidName(i.getBrand())+" "+getValidName(i.getModelName())+" "+getValidName(i.getModelNumber())+" "+getValidName(i.getColor()).replaceAll("\\s+", " "));
|
| - |
|
189 |
cf.setItemType(i.getType());
|
| - |
|
190 |
}
|
| - |
|
191 |
model.addAttribute("cartObj", cartItems);
|
| - |
|
192 |
return "order-index";
|
| - |
|
193 |
}
|
| 141 |
|
194 |
|
| - |
|
195 |
private String getValidName(String name){
|
| - |
|
196 |
return name!=null?name:"";
|
| - |
|
197 |
}
|
| - |
|
198 |
|
| 142 |
@RequestMapping(value = "/order", method = RequestMethod.POST)
|
199 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
| 143 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest) throws Throwable{
|
200 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest, Model model) throws Throwable{
|
| 144 |
//FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
201 |
//FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| 145 |
LOGGER.info("/order request {}", createOrderRequest);
|
202 |
LOGGER.info("/order request {}", createOrderRequest);
|
| 146 |
FofoDetails fofoDetails = new FofoDetails();
|
203 |
FofoDetails fofoDetails = new FofoDetails();
|
| 147 |
fofoDetails.setFofoId(963490);
|
204 |
fofoDetails.setFofoId(963490);
|
| 148 |
Set<CustomFofoLineItem> fofoLineItems = createOrderRequest.getFofoLineItems();
|
205 |
Set<CustomFofoLineItem> fofoLineItems = createOrderRequest.getFofoLineItems();
|
| Line 177... |
Line 234... |
| 177 |
quantity.setAvailable(currentInventorySnapshot.getAvailability());
|
234 |
quantity.setAvailable(currentInventorySnapshot.getAvailability());
|
| 178 |
quantity.setRequested(fofoLineItem.getQuantity());
|
235 |
quantity.setRequested(fofoLineItem.getQuantity());
|
| 179 |
itemIdQuantityAvailability.setQuantity(quantity);
|
236 |
itemIdQuantityAvailability.setQuantity(quantity);
|
| 180 |
itemIdQuantityAvailabilities.add(itemIdQuantityAvailability);
|
237 |
itemIdQuantityAvailabilities.add(itemIdQuantityAvailability);
|
| 181 |
}
|
238 |
}
|
| 182 |
}
|
- |
|
| 183 |
if(!(fofoLineItem.getSellingPrice() > 0)){
|
239 |
if(!(fofoLineItem.getSellingPrice() > 0)){
|
| 184 |
lineItemPrice.put(fofoLineItem.getItemId(), fofoLineItem.getSellingPrice());
|
240 |
lineItemPrice.put(fofoLineItem.getItemId(), fofoLineItem.getSellingPrice());
|
| 185 |
}else{
|
241 |
}else{
|
| 186 |
totalAmount = totalAmount + fofoLineItem.getSellingPrice() * fofoLineItem.getQuantity();
|
242 |
totalAmount = totalAmount + fofoLineItem.getSellingPrice() * fofoLineItem.getQuantity();
|
| - |
|
243 |
}
|
| 187 |
}
|
244 |
}
|
| 188 |
}
|
245 |
}
|
| 189 |
}
|
246 |
}
|
| 190 |
|
247 |
|
| 191 |
try{
|
248 |
try{
|
| 192 |
this.validatePaymentOptionsAndTotalAmount(createOrderRequest.getPaymentOptions(), totalAmount);
|
249 |
this.validatePaymentOptionsAndTotalAmount(createOrderRequest.getPaymentOptions(), totalAmount);
|
| 193 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
250 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 194 |
LOGGER.error("Error occured while validating payment options : ", profitMandiBusinessException);
|
251 |
LOGGER.error("Error occured while validating payment options : ", profitMandiBusinessException);
|
| 195 |
return "error";
|
252 |
return "error";
|
| 196 |
}
|
253 |
}
|
| 197 |
|
254 |
|
| 198 |
if(!itemIdQuantityAvailabilities.isEmpty()){
|
255 |
if(!itemIdQuantityAvailabilities.isEmpty()){
|
| 199 |
// itemIdQuantity request is not valid
|
256 |
// itemIdQuantity request is not valid
|
| 200 |
LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
|
257 |
LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
|
| 201 |
return "error";
|
258 |
return "error";
|
| 202 |
}
|
259 |
}
|
| 203 |
|
260 |
|
| 204 |
if(!lineItemPrice.isEmpty()){
|
261 |
if(!lineItemPrice.isEmpty()){
|
| 205 |
// given fofo line item price must be greater than zero
|
262 |
// given fofo line item price must be greater than zero
|
| 206 |
LOGGER.error("requested itemId's selling price must greater thant 0");
|
263 |
LOGGER.error("requested itemId's selling price must greater thant 0");
|
| 207 |
return "error";
|
264 |
return "error";
|
| 208 |
}
|
265 |
}
|
| 209 |
|
266 |
|
| 210 |
Set<Integer> invalidItemIdSerialNumbers = new HashSet<>();
|
267 |
Set<Integer> invalidItemIdSerialNumbers = new HashSet<>();
|
| 211 |
Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>();
|
268 |
Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>();
|
| 212 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoDetails.getFofoId(), itemIds);
|
269 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoDetails.getFofoId(), itemIds);
|
| 213 |
if(inventoryItems.isEmpty()){
|
270 |
if(inventoryItems.isEmpty()){
|
| 214 |
// invalid item ids
|
271 |
// invalid item ids
|
| 215 |
LOGGER.error("Requested itemId's are not available in inventoryItem");
|
272 |
LOGGER.error("Requested itemId's are not available in inventoryItem");
|
| 216 |
return "error";
|
273 |
return "error";
|
| 217 |
}
|
274 |
}
|
| 218 |
|
275 |
|
| 219 |
Map<Integer, Float> itemIdPriceDropAmount = new HashMap<>();
|
276 |
Map<Integer, Float> itemIdPriceDropAmount = new HashMap<>();
|
| 220 |
|
277 |
|
| 221 |
for(InventoryItem inventoryItem : inventoryItems){
|
278 |
for(InventoryItem inventoryItem : inventoryItems){
|
| 222 |
for(CustomFofoLineItem fofoLineItem : fofoLineItems){
|
279 |
for(CustomFofoLineItem fofoLineItem : fofoLineItems){
|
| 223 |
if(inventoryItem.getItemId() == fofoLineItem.getItemId()){
|
280 |
if(inventoryItem.getItemId() == fofoLineItem.getItemId()){
|
| 224 |
if(fofoLineItem.getSerialNumbers().isEmpty()){
|
281 |
if(fofoLineItem.getSerialNumbers().isEmpty()){
|
| 225 |
if(!(inventoryItem.getSerialNumber() == null && inventoryItem.getSerialNumber().equals(""))){
|
282 |
if(!(inventoryItem.getSerialNumber() == null && inventoryItem.getSerialNumber().equals(""))){
|
| Line 239... |
Line 296... |
| 239 |
}
|
296 |
}
|
| 240 |
itemIdPriceDropAmount.put(inventoryItem.getItemId(), inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount());
|
297 |
itemIdPriceDropAmount.put(inventoryItem.getItemId(), inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount());
|
| 241 |
}
|
298 |
}
|
| 242 |
}
|
299 |
}
|
| 243 |
}
|
300 |
}
|
| 244 |
|
301 |
|
| 245 |
if(!invalidItemIdSerialNumbers.isEmpty()){
|
302 |
if(!invalidItemIdSerialNumbers.isEmpty()){
|
| 246 |
LOGGER.error("Invalid itemId's serialNumbers {}", invalidItemIdSerialNumbers);
|
303 |
LOGGER.error("Invalid itemId's serialNumbers {}", invalidItemIdSerialNumbers);
|
| 247 |
// itemId's are serialized you are saying these are not serialized
|
304 |
// itemId's are serialized you are saying these are not serialized
|
| 248 |
return "error";
|
305 |
return "error";
|
| 249 |
}
|
306 |
}
|
| 250 |
|
307 |
|
| 251 |
if(!itemIdSerialNumbers.isEmpty()){
|
308 |
if(!itemIdSerialNumbers.isEmpty()){
|
| 252 |
LOGGER.error("Invalid itemId's serialNumbers {}", itemIdSerialNumbers);
|
309 |
LOGGER.error("Invalid itemId's serialNumbers {}", itemIdSerialNumbers);
|
| 253 |
// itemId's are non serialized you are saying these are serialized
|
310 |
// itemId's are non serialized you are saying these are serialized
|
| 254 |
return "error";
|
311 |
return "error";
|
| 255 |
}
|
312 |
}
|
| Line 262... |
Line 319... |
| 262 |
invoiceNumberGenerationSequence = new InvoiceNumberGenerationSequence();
|
319 |
invoiceNumberGenerationSequence = new InvoiceNumberGenerationSequence();
|
| 263 |
invoiceNumberGenerationSequence.setFofoId(fofoDetails.getFofoId());
|
320 |
invoiceNumberGenerationSequence.setFofoId(fofoDetails.getFofoId());
|
| 264 |
invoiceNumberGenerationSequence.setPrefix("INVOICE");
|
321 |
invoiceNumberGenerationSequence.setPrefix("INVOICE");
|
| 265 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
322 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
| 266 |
}
|
323 |
}
|
| 267 |
|
324 |
|
| 268 |
CustomCustomer customCustomer = createOrderRequest.getCustomer();
|
325 |
CustomCustomer customCustomer = createOrderRequest.getCustomer();
|
| 269 |
|
326 |
|
| 270 |
if(!StringUtils.isValidEmailAddress(customCustomer.getEmailId())){
|
327 |
if(!StringUtils.isValidEmailAddress(customCustomer.getEmailId())){
|
| 271 |
LOGGER.error("invalid customer emailId {} ", customCustomer.getEmailId());
|
328 |
LOGGER.error("invalid customer emailId {} ", customCustomer.getEmailId());
|
| 272 |
return "error";
|
329 |
return "error";
|
| 273 |
}
|
330 |
}
|
| 274 |
|
331 |
|
| 275 |
if(!StringUtils.isValidMobile(customCustomer.getMobileNumber())){
|
332 |
if(!StringUtils.isValidMobile(customCustomer.getMobileNumber())){
|
| 276 |
LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
|
333 |
LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
|
| 277 |
return "error";
|
334 |
return "error";
|
| 278 |
}
|
335 |
}
|
| 279 |
|
336 |
|
| 280 |
Customer customer = null;
|
337 |
Customer customer = null;
|
| 281 |
try{
|
338 |
try{
|
| 282 |
customer = customerRepository.selectByEmailIdAndMobileNumber(customCustomer.getEmailId(), customCustomer.getMobileNumber());
|
339 |
customer = customerRepository.selectByEmailIdAndMobileNumber(customCustomer.getEmailId(), customCustomer.getMobileNumber());
|
| 283 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
340 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 284 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
341 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
| 285 |
customer = new Customer();
|
342 |
customer = new Customer();
|
| 286 |
customCustomer.setName(customCustomer.getName());
|
343 |
customer.setName(customCustomer.getName());
|
| 287 |
customer.setEmailId(customCustomer.getEmailId());
|
344 |
customer.setEmailId(customCustomer.getEmailId());
|
| 288 |
customer.setMobileNumber(customCustomer.getMobileNumber());
|
345 |
customer.setMobileNumber(customCustomer.getMobileNumber());
|
| 289 |
customerRepository.persist(customer);
|
346 |
customerRepository.persist(customer);
|
| 290 |
}
|
347 |
}
|
| 291 |
CustomerAddress customerAddress = this.createCustomerAddress(customCustomer.getAddress());
|
348 |
CustomerAddress customerAddress = this.createCustomerAddress(customCustomer.getAddress());
|
| 292 |
customerAddress.setCustomerId(customer.getId());
|
349 |
customerAddress.setCustomerId(customer.getId());
|
| 293 |
customerAddressRepository.persist(customerAddress);
|
350 |
customerAddressRepository.persist(customerAddress);
|
| 294 |
|
351 |
|
| 295 |
/*InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = */
|
352 |
/*InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = */
|
| 296 |
|
353 |
|
| 297 |
|
354 |
|
| 298 |
FofoOrder fofoOrder = new FofoOrder();
|
355 |
FofoOrder fofoOrder = new FofoOrder();
|
| 299 |
fofoOrder.setCustomerId(customer.getId());
|
356 |
fofoOrder.setCustomerId(customer.getId());
|
| 300 |
fofoOrder.setFofoId(fofoDetails.getFofoId());
|
357 |
fofoOrder.setFofoId(fofoDetails.getFofoId());
|
| 301 |
fofoOrder.setInvoiceNumber(invoiceNumberGenerationSequence.getPrefix() + invoiceNumberGenerationSequence.getSequence());
|
358 |
fofoOrder.setInvoiceNumber(invoiceNumberGenerationSequence.getPrefix() + invoiceNumberGenerationSequence.getSequence());
|
| 302 |
fofoOrder.setTotalAmount(totalAmount);
|
359 |
fofoOrder.setTotalAmount(totalAmount);
|
| 303 |
fofoOrderRepository.persist(fofoOrder);
|
360 |
fofoOrderRepository.persist(fofoOrder);
|
| 304 |
|
361 |
|
| 305 |
for(CustomPaymentOption customPaymentOption : createOrderRequest.getPaymentOptions()){
|
362 |
for(CustomPaymentOption customPaymentOption : createOrderRequest.getPaymentOptions()){
|
| 306 |
PaymentOption paymentOption = new PaymentOption();
|
363 |
PaymentOption paymentOption = new PaymentOption();
|
| 307 |
paymentOption.setOrderId(fofoOrder.getId());
|
364 |
paymentOption.setOrderId(fofoOrder.getId());
|
| 308 |
paymentOption.setAmount(customPaymentOption.getAmount());
|
365 |
paymentOption.setAmount(customPaymentOption.getAmount());
|
| 309 |
paymentOption.setType(customPaymentOption.getType());
|
366 |
paymentOption.setType(customPaymentOption.getType());
|
| 310 |
paymentOptionRepository.persist(paymentOption);
|
367 |
paymentOptionRepository.persist(paymentOption);
|
| 311 |
}
|
368 |
}
|
| - |
|
369 |
|
| - |
|
370 |
// List<Order> orders = orderRepository.selectByRetailerIdItemIds(fofoDetails.getFofoId(), itemIds);
|
| - |
|
371 |
//
|
| - |
|
372 |
// Set<Item> items = new HashSet<>(itemIds.size());
|
| - |
|
373 |
// for(Order order : orders){
|
| - |
|
374 |
// LineItem lineItem = order.getLineItem();
|
| - |
|
375 |
// items.add(lineItem.getItem());
|
| - |
|
376 |
// }
|
| - |
|
377 |
//
|
| - |
|
378 |
// if(items.size() != itemIds.size()){
|
| - |
|
379 |
// LOGGER.error("Requested ItemIds not found in catalog");
|
| - |
|
380 |
// // invalid itemIds
|
| - |
|
381 |
// return "error";
|
| - |
|
382 |
// }
|
| 312 |
|
383 |
|
| 313 |
List<Order> orders = orderRepository.selectByRetailerIdItemIds(fofoDetails.getFofoId(), itemIds);
|
- |
|
| 314 |
|
- |
|
| 315 |
Set<Item> items = new HashSet<>(itemIds.size());
|
384 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
| 316 |
for(Order order : orders){
|
- |
|
| 317 |
LineItem lineItem = order.getLineItem();
|
- |
|
| 318 |
items.add(lineItem.getItem());
|
- |
|
| 319 |
}
|
- |
|
| 320 |
|
- |
|
| 321 |
if(items.size() != itemIds.size()){
|
- |
|
| 322 |
LOGGER.error("Requested ItemIds not found in catalog");
|
- |
|
| 323 |
// invalid itemIds
|
- |
|
| 324 |
return "error";
|
- |
|
| 325 |
}
|
- |
|
| 326 |
|
385 |
|
| 327 |
Map<Integer, Map<String, String>> itemIdDetails = this.toMap(items);
|
386 |
Map<Integer, Map<String, String>> itemIdDetails = this.toMap(items);
|
| 328 |
|
387 |
|
| 329 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
388 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
| 330 |
FofoLineItem fofoLineItem = new FofoLineItem();
|
389 |
FofoLineItem fofoLineItem = new FofoLineItem();
|
| 331 |
fofoLineItem.setItemId(customFofoLineItem.getItemId());
|
390 |
fofoLineItem.setItemId(customFofoLineItem.getItemId());
|
| 332 |
fofoLineItem.setQuantity(customFofoLineItem.getQuantity());
|
391 |
fofoLineItem.setQuantity(customFofoLineItem.getQuantity());
|
| 333 |
fofoLineItem.setSellingPrice(customFofoLineItem.getSellingPrice());
|
392 |
fofoLineItem.setSellingPrice(customFofoLineItem.getSellingPrice());
|
| Line 349... |
Line 408... |
| 349 |
fofoLineItemSerialNumber.setFofoLineItemId(fofoLineItem.getId());
|
408 |
fofoLineItemSerialNumber.setFofoLineItemId(fofoLineItem.getId());
|
| 350 |
fofoLineItemSerialNumber.setSerialNumber(serialNumber);
|
409 |
fofoLineItemSerialNumber.setSerialNumber(serialNumber);
|
| 351 |
fofoLineItemSerialNumberRepository.persist(fofoLineItemSerialNumber);
|
410 |
fofoLineItemSerialNumberRepository.persist(fofoLineItemSerialNumber);
|
| 352 |
}
|
411 |
}
|
| 353 |
}
|
412 |
}
|
| 354 |
|
413 |
|
| 355 |
|
414 |
|
| 356 |
|
415 |
|
| 357 |
|
416 |
|
| 358 |
for(InventoryItem inventoryItem : inventoryItems){
|
417 |
for(InventoryItem inventoryItem : inventoryItems){
|
| 359 |
if(inventoryItem.getItemId() == fofoLineItem.getItemId()){
|
418 |
if(inventoryItem.getItemId() == fofoLineItem.getItemId()){
|
| 360 |
if(inventoryItem.getSerialNumber() == null || inventoryItem.getSerialNumber().isEmpty()){
|
419 |
if(inventoryItem.getSerialNumber() == null || inventoryItem.getSerialNumber().isEmpty()){
|
| 361 |
if(fofoLineItem.getQuantity() > 0)
|
420 |
if(fofoLineItem.getQuantity() > 0)
|
| 362 |
if(fofoLineItem.getQuantity() <= inventoryItem.getGoodQuantity()){
|
421 |
if(fofoLineItem.getQuantity() <= inventoryItem.getGoodQuantity()){
|
| 363 |
inventoryItem.setGoodQuantity(inventoryItem.getGoodQuantity() - fofoLineItem.getQuantity());
|
422 |
inventoryItem.setGoodQuantity(inventoryItem.getGoodQuantity() - fofoLineItem.getQuantity());
|
| 364 |
inventoryItem.setLastScanType(ScanType.SALE);
|
423 |
inventoryItem.setLastScanType(ScanType.SALE);
|
| 365 |
inventoryItemRepository.persist(inventoryItem);
|
424 |
inventoryItemRepository.persist(inventoryItem);
|
| 366 |
ScanRecord scanRecord = new ScanRecord();
|
425 |
ScanRecord scanRecord = new ScanRecord();
|
| 367 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
426 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
| 368 |
scanRecord.setFofoId(fofoDetails.getFofoId());
|
427 |
scanRecord.setFofoId(fofoDetails.getFofoId());
|
| 369 |
scanRecord.setQuantity(fofoLineItem.getQuantity());
|
428 |
scanRecord.setQuantity(fofoLineItem.getQuantity());
|
| 370 |
scanRecord.setType(ScanType.SALE);
|
429 |
scanRecord.setType(ScanType.SALE);
|
| 371 |
scanRecordRepository.persist(scanRecord);
|
430 |
scanRecordRepository.persist(scanRecord);
|
| 372 |
}else{
|
431 |
}else{
|
| 373 |
int availableGoodQuantity = inventoryItem.getGoodQuantity();
|
432 |
int availableGoodQuantity = inventoryItem.getGoodQuantity();
|
| 374 |
inventoryItem.setGoodQuantity(0);
|
433 |
inventoryItem.setGoodQuantity(0);
|
| 375 |
fofoLineItem.setQuantity(fofoLineItem.getQuantity() - availableGoodQuantity);
|
434 |
fofoLineItem.setQuantity(fofoLineItem.getQuantity() - availableGoodQuantity);
|
| 376 |
inventoryItem.setLastScanType(ScanType.SALE);
|
435 |
inventoryItem.setLastScanType(ScanType.SALE);
|
| 377 |
inventoryItemRepository.persist(inventoryItem);
|
436 |
inventoryItemRepository.persist(inventoryItem);
|
| 378 |
ScanRecord scanRecord = new ScanRecord();
|
437 |
ScanRecord scanRecord = new ScanRecord();
|
| 379 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
438 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
| 380 |
scanRecord.setFofoId(fofoDetails.getFofoId());
|
439 |
scanRecord.setFofoId(fofoDetails.getFofoId());
|
| 381 |
scanRecord.setQuantity(availableGoodQuantity);
|
440 |
scanRecord.setQuantity(availableGoodQuantity);
|
| 382 |
scanRecord.setType(ScanType.SALE);
|
441 |
scanRecord.setType(ScanType.SALE);
|
| 383 |
scanRecordRepository.persist(scanRecord);
|
442 |
scanRecordRepository.persist(scanRecord);
|
| 384 |
}
|
443 |
}
|
| 385 |
}else{
|
444 |
}else{
|
| 386 |
inventoryItem.setGoodQuantity(0);
|
445 |
inventoryItem.setGoodQuantity(0);
|
| 387 |
inventoryItem.setLastScanType(ScanType.SALE);
|
446 |
inventoryItem.setLastScanType(ScanType.SALE);
|
| 388 |
inventoryItemRepository.persist(inventoryItem);
|
447 |
inventoryItemRepository.persist(inventoryItem);
|
| 389 |
ScanRecord scanRecord = new ScanRecord();
|
448 |
ScanRecord scanRecord = new ScanRecord();
|
| Line 393... |
Line 452... |
| 393 |
scanRecord.setType(ScanType.SALE);
|
452 |
scanRecord.setType(ScanType.SALE);
|
| 394 |
scanRecordRepository.persist(scanRecord);
|
453 |
scanRecordRepository.persist(scanRecord);
|
| 395 |
}
|
454 |
}
|
| 396 |
}
|
455 |
}
|
| 397 |
}
|
456 |
}
|
| 398 |
|
457 |
|
| - |
|
458 |
//current inventory not updating
|
| - |
|
459 |
//logic is flawed - check flow and handle error properly without persisiting
|
| - |
|
460 |
//jugaad kaam @ ashik ali
|
| - |
|
461 |
|
| 399 |
}
|
462 |
}
|
| 400 |
return null;
|
463 |
return null;
|
| 401 |
}
|
464 |
}
|
| 402 |
|
465 |
|
| 403 |
|
466 |
|
| 404 |
private Map<Integer, Map<String, String>> toMap(Set<Item> items){
|
467 |
private Map<Integer, Map<String, String>> toMap(List<Item> items){
|
| 405 |
Map<Integer, Map<String, String>> map = new HashMap<>();
|
468 |
Map<Integer, Map<String, String>> map = new HashMap<>();
|
| 406 |
for(Item item : items){
|
469 |
for(Item item : items){
|
| 407 |
Map<String, String> detailMap = new HashMap<>();
|
470 |
Map<String, String> detailMap = new HashMap<>();
|
| 408 |
detailMap.put(ProfitMandiConstants.BRAND, item.getBrand());
|
471 |
detailMap.put(ProfitMandiConstants.BRAND, item.getBrand());
|
| 409 |
detailMap.put(ProfitMandiConstants.MODEL_NAME, item.getModelName());
|
472 |
detailMap.put(ProfitMandiConstants.MODEL_NAME, item.getModelName());
|
| Line 411... |
Line 474... |
| 411 |
detailMap.put(ProfitMandiConstants.COLOR, item.getColor());
|
474 |
detailMap.put(ProfitMandiConstants.COLOR, item.getColor());
|
| 412 |
map.put(item.getId(), detailMap);
|
475 |
map.put(item.getId(), detailMap);
|
| 413 |
}
|
476 |
}
|
| 414 |
return map;
|
477 |
return map;
|
| 415 |
}
|
478 |
}
|
| 416 |
|
479 |
|
| 417 |
/*private Address createAddress(CustomAddress customAddress){
|
480 |
/*private Address createAddress(CustomAddress customAddress){
|
| 418 |
Address address = new Address();
|
481 |
Address address = new Address();
|
| 419 |
address.setName(customAddress.getName());
|
482 |
address.setName(customAddress.getName());
|
| 420 |
address.setLine1(customAddress.getLine1());
|
483 |
address.setLine1(customAddress.getLine1());
|
| 421 |
address.setLine2(customAddress.getLine2());
|
484 |
address.setLine2(customAddress.getLine2());
|
| Line 426... |
Line 489... |
| 426 |
address.setCountry(customAddress.getCountry());
|
489 |
address.setCountry(customAddress.getCountry());
|
| 427 |
address.setPhoneNumber(customAddress.getPhoneNumber());
|
490 |
address.setPhoneNumber(customAddress.getPhoneNumber());
|
| 428 |
address.setEnabled(true);
|
491 |
address.setEnabled(true);
|
| 429 |
return address;
|
492 |
return address;
|
| 430 |
}*/
|
493 |
}*/
|
| 431 |
|
494 |
|
| 432 |
private CustomerAddress createCustomerAddress(CustomAddress customAddress){
|
495 |
private CustomerAddress createCustomerAddress(CustomAddress customAddress){
|
| 433 |
CustomerAddress customerAddress = new CustomerAddress();
|
496 |
CustomerAddress customerAddress = new CustomerAddress();
|
| 434 |
customerAddress.setName(customAddress.getName());
|
497 |
customerAddress.setName(customAddress.getName());
|
| 435 |
customerAddress.setLine1(customAddress.getLine1());
|
498 |
customerAddress.setLine1(customAddress.getLine1());
|
| 436 |
customerAddress.setLine2(customAddress.getLine2());
|
499 |
customerAddress.setLine2(customAddress.getLine2());
|
| Line 440... |
Line 503... |
| 440 |
customerAddress.setState(customAddress.getState());
|
503 |
customerAddress.setState(customAddress.getState());
|
| 441 |
customerAddress.setCountry(customAddress.getCountry());
|
504 |
customerAddress.setCountry(customAddress.getCountry());
|
| 442 |
customerAddress.setPhoneNumber(customAddress.getPhoneNumber());
|
505 |
customerAddress.setPhoneNumber(customAddress.getPhoneNumber());
|
| 443 |
return customerAddress;
|
506 |
return customerAddress;
|
| 444 |
}
|
507 |
}
|
| 445 |
|
508 |
|
| 446 |
private CustomAddress createCustomAddress(Address address){
|
509 |
private CustomAddress createCustomAddress(Address address){
|
| 447 |
CustomAddress customAddress = new CustomAddress();
|
510 |
CustomAddress customAddress = new CustomAddress();
|
| 448 |
customAddress.setName(address.getName());
|
511 |
customAddress.setName(address.getName());
|
| 449 |
customAddress.setLine1(address.getLine1());
|
512 |
customAddress.setLine1(address.getLine1());
|
| 450 |
customAddress.setLine2(address.getLine2());
|
513 |
customAddress.setLine2(address.getLine2());
|
| Line 454... |
Line 517... |
| 454 |
customAddress.setState(address.getState());
|
517 |
customAddress.setState(address.getState());
|
| 455 |
customAddress.setCountry(address.getCountry());
|
518 |
customAddress.setCountry(address.getCountry());
|
| 456 |
customAddress.setPhoneNumber(address.getPhoneNumber());
|
519 |
customAddress.setPhoneNumber(address.getPhoneNumber());
|
| 457 |
return customAddress;
|
520 |
return customAddress;
|
| 458 |
}
|
521 |
}
|
| 459 |
|
522 |
|
| 460 |
private CustomAddress createCustomAddress(CustomerAddress customerAddress){
|
523 |
private CustomAddress createCustomAddress(CustomerAddress customerAddress){
|
| 461 |
CustomAddress customAddress = new CustomAddress();
|
524 |
CustomAddress customAddress = new CustomAddress();
|
| 462 |
customAddress.setName(customerAddress.getName());
|
525 |
customAddress.setName(customerAddress.getName());
|
| 463 |
customAddress.setLine1(customerAddress.getLine1());
|
526 |
customAddress.setLine1(customerAddress.getLine1());
|
| 464 |
customAddress.setLine2(customerAddress.getLine2());
|
527 |
customAddress.setLine2(customerAddress.getLine2());
|
| Line 468... |
Line 531... |
| 468 |
customAddress.setState(customerAddress.getState());
|
531 |
customAddress.setState(customerAddress.getState());
|
| 469 |
customAddress.setCountry(customerAddress.getCountry());
|
532 |
customAddress.setCountry(customerAddress.getCountry());
|
| 470 |
customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
|
533 |
customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
|
| 471 |
return customAddress;
|
534 |
return customAddress;
|
| 472 |
}
|
535 |
}
|
| 473 |
|
536 |
|
| 474 |
private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
|
537 |
private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
|
| 475 |
{
|
538 |
{
|
| 476 |
float calculatedAmount = 0;
|
539 |
float calculatedAmount = 0;
|
| 477 |
Set<String> paymentOptionTypes = new HashSet<>();
|
540 |
Set<String> paymentOptionTypes = new HashSet<>();
|
| 478 |
for(CustomPaymentOption customPaymentOption : customPaymentOptions){
|
541 |
for(CustomPaymentOption customPaymentOption : customPaymentOptions){
|
| Line 481... |
Line 544... |
| 481 |
}else{
|
544 |
}else{
|
| 482 |
paymentOptionTypes.add(customPaymentOption.getType().name());
|
545 |
paymentOptionTypes.add(customPaymentOption.getType().name());
|
| 483 |
calculatedAmount = calculatedAmount + customPaymentOption.getAmount();
|
546 |
calculatedAmount = calculatedAmount + customPaymentOption.getAmount();
|
| 484 |
}
|
547 |
}
|
| 485 |
}
|
548 |
}
|
| - |
|
549 |
|
| - |
|
550 |
LOGGER.info("calculatedAmount "+calculatedAmount);
|
| - |
|
551 |
LOGGER.info("totalAmount "+totalAmount);
|
| - |
|
552 |
|
| 486 |
if(calculatedAmount != totalAmount){
|
553 |
if(calculatedAmount != totalAmount){
|
| 487 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "");
|
554 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "");
|
| 488 |
}
|
555 |
}
|
| 489 |
}
|
556 |
}
|
| 490 |
|
557 |
|
| 491 |
|
558 |
|
| 492 |
@RequestMapping(value = "/generateInvoice")
|
559 |
@RequestMapping(value = "/generateInvoice")
|
| 493 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws Throwable{
|
560 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws Throwable{
|
| 494 |
LOGGER.info("Request received at url {} with params {} ", request.getRequestURI(), request.getParameterMap());
|
561 |
LOGGER.info("Request received at url {} with params {} ", request.getRequestURI(), request.getParameterMap());
|
| 495 |
//FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
562 |
//FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| 496 |
|
563 |
|
| 497 |
FofoDetails fofoDetails = new FofoDetails();
|
564 |
FofoDetails fofoDetails = new FofoDetails();
|
| 498 |
fofoDetails.setFofoId(963490);
|
565 |
fofoDetails.setFofoId(963490);
|
| 499 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
566 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 500 |
PdfModel pdfModel = new PdfModel();
|
567 |
PdfModel pdfModel = new PdfModel();
|
| 501 |
pdfModel.setAuther("profitmandi");
|
568 |
pdfModel.setAuther("profitmandi");
|
| Line 508... |
Line 575... |
| 508 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
575 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 509 |
customCustomer.setAddress(this.createCustomAddress(customerAddress));
|
576 |
customCustomer.setAddress(this.createCustomAddress(customerAddress));
|
| 510 |
pdfModel.setCustomer(customCustomer);
|
577 |
pdfModel.setCustomer(customCustomer);
|
| 511 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
578 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
| 512 |
pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
|
579 |
pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
|
| 513 |
|
580 |
|
| 514 |
Retailer retailer = retailerRepository.selectById(fofoDetails.getFofoId());
|
581 |
Retailer retailer = retailerRepository.selectById(fofoDetails.getFofoId());
|
| 515 |
User user = userRepository.selectById(userAccountRepository.selectUserIdByRetailerId(retailer.getId()));
|
582 |
User user = userRepository.selectById(userAccountRepository.selectUserIdByRetailerId(retailer.getId()));
|
| 516 |
CustomRetailer customRetailer = new CustomRetailer();
|
583 |
CustomRetailer customRetailer = new CustomRetailer();
|
| 517 |
customRetailer.setBusinessName(retailer.getName());
|
584 |
customRetailer.setBusinessName(retailer.getName());
|
| 518 |
customRetailer.setMobileNumber(user.getMobileNumber());
|
585 |
customRetailer.setMobileNumber(user.getMobileNumber());
|
| 519 |
customRetailer.setTinNumber(retailer.getNumber());
|
586 |
customRetailer.setTinNumber(retailer.getNumber());
|
| 520 |
Address retailerAddress = addressRepository.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId()));
|
587 |
Address retailerAddress = addressRepository.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId()));
|
| 521 |
customRetailer.setAddress(this.createCustomAddress(retailerAddress));
|
588 |
customRetailer.setAddress(this.createCustomAddress(retailerAddress));
|
| 522 |
pdfModel.setRetailer(customRetailer);
|
589 |
pdfModel.setRetailer(customRetailer);
|
| 523 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
|
590 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
|
| 524 |
|
591 |
|
| 525 |
Set<CustomFofoOrderItem> customerFofoOrderItems = new HashSet<>();
|
592 |
Set<CustomFofoOrderItem> customerFofoOrderItems = new HashSet<>();
|
| 526 |
for(FofoLineItem fofoLineItem : fofoLineItems){
|
593 |
for(FofoLineItem fofoLineItem : fofoLineItems){
|
| 527 |
CustomFofoOrderItem customFofoOrderItem = new CustomFofoOrderItem();
|
594 |
CustomFofoOrderItem customFofoOrderItem = new CustomFofoOrderItem();
|
| 528 |
customFofoOrderItem.setAmount(fofoLineItem.getQuantity() * fofoLineItem.getSellingPrice());
|
595 |
customFofoOrderItem.setAmount(fofoLineItem.getQuantity() * fofoLineItem.getSellingPrice());
|
| 529 |
customFofoOrderItem.setDescription(fofoLineItem.getBrand() + " " + fofoLineItem.getModelName() + " " + fofoLineItem.getModelNumber() + " " + fofoLineItem.getColor());
|
596 |
customFofoOrderItem.setDescription(fofoLineItem.getBrand() + " " + fofoLineItem.getModelName() + " " + fofoLineItem.getModelNumber() + " " + fofoLineItem.getColor());
|
| Line 539... |
Line 606... |
| 539 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
606 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
| 540 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
607 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 541 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
608 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
| 542 |
//final MediaType mediaType=MediaType.parseMediaType(profilePhotoModel.getContentType().getValue());
|
609 |
//final MediaType mediaType=MediaType.parseMediaType(profilePhotoModel.getContentType().getValue());
|
| 543 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
610 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 544 |
final HttpHeaders headers=new HttpHeaders();
|
611 |
final HttpHeaders headers=new HttpHeaders();
|
| 545 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
612 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
| 546 |
//headers.set("Content-Disposition", "retailerInvoice.pdf");
|
613 |
//headers.set("Content-Disposition", "retailerInvoice.pdf");
|
| 547 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
614 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
| 548 |
final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
615 |
final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
| 549 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
616 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
| 550 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
617 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 551 |
}
|
618 |
}
|
| 552 |
|
619 |
|
| 553 |
private Set<String> toSerialNumbers(Set<FofoLineItemSerialNumber> fofoLineItemSerialNumbers){
|
620 |
private Set<String> toSerialNumbers(Set<FofoLineItemSerialNumber> fofoLineItemSerialNumbers){
|
| 554 |
Set<String> serialNumbers = new HashSet<>(fofoLineItemSerialNumbers.size());
|
621 |
Set<String> serialNumbers = new HashSet<>(fofoLineItemSerialNumbers.size());
|
| 555 |
for(FofoLineItemSerialNumber fofoLineItemSerialNumber : fofoLineItemSerialNumbers){
|
622 |
for(FofoLineItemSerialNumber fofoLineItemSerialNumber : fofoLineItemSerialNumbers){
|
| 556 |
serialNumbers.add(fofoLineItemSerialNumber.getSerialNumber());
|
623 |
serialNumbers.add(fofoLineItemSerialNumber.getSerialNumber());
|
| 557 |
}
|
624 |
}
|