| Line 2... |
Line 2... |
| 2 |
|
2 |
|
| 3 |
import java.io.ByteArrayInputStream;
|
3 |
import java.io.ByteArrayInputStream;
|
| 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.Collection;
|
| 7 |
import java.util.HashMap;
|
8 |
import java.util.HashMap;
|
| 8 |
import java.util.HashSet;
|
9 |
import java.util.HashSet;
|
| - |
|
10 |
import java.util.Iterator;
|
| 9 |
import java.util.List;
|
11 |
import java.util.List;
|
| 10 |
import java.util.Map;
|
12 |
import java.util.Map;
|
| 11 |
import java.util.Set;
|
13 |
import java.util.Set;
|
| 12 |
|
14 |
|
| 13 |
import javax.servlet.http.HttpServletRequest;
|
15 |
import javax.servlet.http.HttpServletRequest;
|
| 14 |
import javax.servlet.http.HttpServletResponse;
|
16 |
import javax.servlet.http.HttpServletResponse;
|
| - |
|
17 |
import javax.transaction.Transactional;
|
| 15 |
|
18 |
|
| - |
|
19 |
import org.json.JSONObject;
|
| 16 |
import org.slf4j.Logger;
|
20 |
import org.slf4j.Logger;
|
| 17 |
import org.slf4j.LoggerFactory;
|
21 |
import org.slf4j.LoggerFactory;
|
| 18 |
import org.springframework.beans.factory.annotation.Autowired;
|
22 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 19 |
import org.springframework.core.io.InputStreamResource;
|
23 |
import org.springframework.core.io.InputStreamResource;
|
| 20 |
import org.springframework.http.HttpHeaders;
|
24 |
import org.springframework.http.HttpHeaders;
|
| 21 |
import org.springframework.http.HttpStatus;
|
25 |
import org.springframework.http.HttpStatus;
|
| 22 |
import org.springframework.http.MediaType;
|
26 |
import org.springframework.http.MediaType;
|
| 23 |
import org.springframework.http.ResponseEntity;
|
27 |
import org.springframework.http.ResponseEntity;
|
| 24 |
import org.springframework.stereotype.Controller;
|
28 |
import org.springframework.stereotype.Controller;
|
| 25 |
import org.springframework.transaction.annotation.Transactional;
|
29 |
import org.springframework.ui.Model;
|
| 26 |
import org.springframework.web.bind.annotation.RequestBody;
|
30 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 27 |
import org.springframework.web.bind.annotation.RequestMapping;
|
31 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 28 |
import org.springframework.web.bind.annotation.RequestMethod;
|
32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 29 |
import org.springframework.web.bind.annotation.RequestParam;
|
33 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 30 |
|
34 |
|
| 31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
36 |
import com.spice.profitmandi.common.model.CartFofo;
|
| 32 |
import com.spice.profitmandi.common.model.CustomAddress;
|
37 |
import com.spice.profitmandi.common.model.CustomAddress;
|
| 33 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
38 |
import com.spice.profitmandi.common.model.CustomCustomer;
|
| 34 |
import com.spice.profitmandi.common.model.CustomFofoLineItem;
|
39 |
import com.spice.profitmandi.common.model.CustomFofoLineItem;
|
| 35 |
import com.spice.profitmandi.common.model.CustomFofoOrderItem;
|
40 |
import com.spice.profitmandi.common.model.CustomFofoOrderItem;
|
| 36 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
41 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| Line 70... |
Line 75... |
| 70 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
75 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 71 |
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
|
76 |
import com.spice.profitmandi.dao.repository.fofo.InvoiceNumberGenerationSequenceRepository;
|
| 72 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
77 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 73 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
78 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 74 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
79 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| - |
|
80 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepositoryImpl;
|
| 75 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
81 |
import com.spice.profitmandi.dao.repository.user.AddressRepository;
|
| 76 |
import com.spice.profitmandi.web.model.FofoDetails;
|
82 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| 77 |
import com.spice.profitmandi.web.request.CreateOrderRequest;
|
83 |
import com.spice.profitmandi.web.request.CreateOrderRequest;
|
| 78 |
import com.spice.profitmandi.web.request.CustomPaymentOption;
|
84 |
import com.spice.profitmandi.web.request.CustomPaymentOption;
|
| 79 |
import com.spice.profitmandi.web.response.ItemIdQuantityAvailability;
|
85 |
import com.spice.profitmandi.web.response.ItemIdQuantityAvailability;
|
| 80 |
import com.spice.profitmandi.web.response.Quantity;
|
86 |
import com.spice.profitmandi.web.response.Quantity;
|
| 81 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
87 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
| 82 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
88 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 83 |
|
89 |
|
| - |
|
90 |
import in.shop2020.model.v1.catalog.ItemType;
|
| - |
|
91 |
|
| 84 |
@Controller
|
92 |
@Controller
|
| 85 |
@Transactional(rollbackFor = Throwable.class)
|
93 |
@Transactional
|
| 86 |
public class OrderController {
|
94 |
public class OrderController {
|
| 87 |
|
95 |
|
| 88 |
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
96 |
private static final Logger LOGGER = LoggerFactory.getLogger(OrderController.class);
|
| 89 |
|
97 |
|
| 90 |
@Autowired
|
98 |
@Autowired
|
| 91 |
OrderRepository orderRepository;
|
99 |
OrderRepository orderRepository;
|
| 92 |
|
100 |
|
| 93 |
@Autowired
|
101 |
@Autowired
|
| 94 |
InventoryItemRepository inventoryItemRepository;
|
102 |
InventoryItemRepository inventoryItemRepository;
|
| 95 |
|
103 |
|
| 96 |
@Autowired
|
104 |
@Autowired
|
| 97 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
105 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 98 |
|
106 |
|
| 99 |
@Autowired
|
107 |
@Autowired
|
| 100 |
InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
|
108 |
InvoiceNumberGenerationSequenceRepository invoiceNumberGenerationSequenceRepository;
|
| 101 |
|
109 |
|
| 102 |
@Autowired
|
110 |
@Autowired
|
| 103 |
CustomerRepository customerRepository;
|
111 |
CustomerRepository customerRepository;
|
| 104 |
|
112 |
|
| 105 |
@Autowired
|
113 |
@Autowired
|
| 106 |
AddressRepository addressRepository;
|
114 |
AddressRepository addressRepository;
|
| 107 |
|
115 |
|
| 108 |
@Autowired
|
116 |
@Autowired
|
| 109 |
FofoLineItemSerialNumberRepository fofoLineItemSerialNumberRepository;
|
117 |
FofoLineItemSerialNumberRepository fofoLineItemSerialNumberRepository;
|
| 110 |
|
118 |
|
| 111 |
@Autowired
|
119 |
@Autowired
|
| 112 |
FofoLineItemRepository fofoLineItemRepository;
|
120 |
FofoLineItemRepository fofoLineItemRepository;
|
| 113 |
|
121 |
|
| 114 |
@Autowired
|
122 |
@Autowired
|
| 115 |
PaymentOptionRepository paymentOptionRepository;
|
123 |
PaymentOptionRepository paymentOptionRepository;
|
| 116 |
|
124 |
|
| 117 |
@Autowired
|
125 |
@Autowired
|
| 118 |
ScanRecordRepository scanRecordRepository;
|
126 |
ScanRecordRepository scanRecordRepository;
|
| 119 |
|
127 |
|
| 120 |
@Autowired
|
128 |
@Autowired
|
| 121 |
FofoOrderRepository fofoOrderRepository;
|
129 |
FofoOrderRepository fofoOrderRepository;
|
| 122 |
|
130 |
|
| 123 |
@Autowired
|
131 |
@Autowired
|
| 124 |
RetailerRepository retailerRepository;
|
132 |
RetailerRepository retailerRepository;
|
| 125 |
|
133 |
|
| 126 |
@Autowired
|
134 |
@Autowired
|
| 127 |
UserRepository userRepository;
|
135 |
UserRepository userRepository;
|
| 128 |
|
136 |
|
| 129 |
@Autowired
|
137 |
@Autowired
|
| 130 |
UserAccountRepository userAccountRepository;
|
138 |
UserAccountRepository userAccountRepository;
|
| 131 |
|
139 |
|
| 132 |
@Autowired
|
140 |
@Autowired
|
| 133 |
RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
141 |
RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
|
| 134 |
|
142 |
|
| 135 |
@Autowired
|
143 |
@Autowired
|
| 136 |
CustomerAddressRepository customerAddressRepository;
|
144 |
CustomerAddressRepository customerAddressRepository;
|
| 137 |
|
145 |
|
| 138 |
@Autowired
|
146 |
@Autowired
|
| 139 |
ItemRepository itemRepository;
|
147 |
ItemRepository itemRepository;
|
| 140 |
|
148 |
|
| 141 |
@Autowired
|
149 |
@Autowired
|
| 142 |
MVCResponseSender mvcResponseSender;
|
150 |
MVCResponseSender mvcResponseSender;
|
| 143 |
|
151 |
|
| 144 |
@Autowired
|
152 |
@Autowired
|
| 145 |
CookiesFetcher cookiesFetcher;
|
153 |
CookiesFetcher cookiesFetcher;
|
| - |
|
154 |
|
| - |
|
155 |
@RequestMapping(value = "/order")
|
| - |
|
156 |
public String orderIndex(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
| - |
|
157 |
FofoDetails fofoDetails;
|
| - |
|
158 |
try {
|
| - |
|
159 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| - |
|
160 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
161 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
| - |
|
162 |
return "response";
|
| - |
|
163 |
}
|
| - |
|
164 |
JSONObject cartObject = new JSONObject(cartData);
|
| - |
|
165 |
Iterator<?> keys = cartObject.keys();
|
| - |
|
166 |
|
| - |
|
167 |
Set<Integer> itemIds = new HashSet<>();
|
| - |
|
168 |
List<CartFofo> cartItems = new ArrayList<CartFofo>();
|
| - |
|
169 |
|
| - |
|
170 |
while( keys.hasNext() ) {
|
| - |
|
171 |
String key = (String)keys.next();
|
| - |
|
172 |
if ( cartObject.get(key) instanceof JSONObject ) {
|
| - |
|
173 |
System.out.println(cartObject.get(key));
|
| - |
|
174 |
}
|
| - |
|
175 |
CartFofo cf = new CartFofo();
|
| - |
|
176 |
cf.setItemId(cartObject.getJSONObject(key).getInt("itemId"));
|
| - |
|
177 |
cf.setQuantity(cartObject.getJSONObject(key).getInt("quantity"));
|
| - |
|
178 |
if (cf.getQuantity() <= 0){
|
| - |
|
179 |
continue;
|
| - |
|
180 |
}
|
| - |
|
181 |
cartItems.add(cf);
|
| - |
|
182 |
itemIds.add(cartObject.getJSONObject(key).getInt("itemId"));
|
| - |
|
183 |
}
|
| - |
|
184 |
Map<Integer, Item> itemMap = new HashMap<Integer, Item>();
|
| - |
|
185 |
if (itemIds.size() > 0){
|
| - |
|
186 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
| - |
|
187 |
for (Item i : items){
|
| - |
|
188 |
itemMap.put(i.getId(), i);
|
| - |
|
189 |
}
|
| - |
|
190 |
}
|
| - |
|
191 |
for (CartFofo cf : cartItems){
|
| - |
|
192 |
Item i = itemMap.get(cf.getItemId());
|
| - |
|
193 |
if (i == null){
|
| - |
|
194 |
continue;
|
| - |
|
195 |
}
|
| - |
|
196 |
cf.setDisplayName(getValidName(i.getBrand())+" "+getValidName(i.getModelName())+" "+getValidName(i.getModelNumber())+" "+getValidName(i.getColor()).replaceAll("\\s+", " "));
|
| - |
|
197 |
cf.setItemType(i.getType());
|
| - |
|
198 |
}
|
| - |
|
199 |
model.addAttribute("cartObj", cartItems);
|
| - |
|
200 |
return "order-index";
|
| - |
|
201 |
}
|
| - |
|
202 |
|
| - |
|
203 |
private String getValidName(String name){
|
| - |
|
204 |
return name!=null?name:"";
|
| - |
|
205 |
}
|
| 146 |
|
206 |
|
| - |
|
207 |
@RequestMapping(value = "/get-order", method = RequestMethod.GET)
|
| - |
|
208 |
public String getOrder(HttpServletRequest request, @RequestParam(name = "orderId") int orderId, Model model) throws ProfitMandiBusinessException, Exception{
|
| - |
|
209 |
FofoDetails fofoDetails;
|
| - |
|
210 |
try {
|
| - |
|
211 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| - |
|
212 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
213 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
| - |
|
214 |
return "response";
|
| - |
|
215 |
}
|
| - |
|
216 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| - |
|
217 |
LOGGER.info(fofoOrder.toString());
|
| - |
|
218 |
LOGGER.info(fofoOrder.getCustomer().toString());
|
| - |
|
219 |
LOGGER.info(fofoOrder.getCustomer().getCustomerAddress().toString());
|
| - |
|
220 |
LOGGER.info(fofoOrder.getFofoLineItem().toString());
|
| - |
|
221 |
LOGGER.info(fofoOrder.getFofoLineItem().get(0).getFofoLineItemSerialNumbers().toString());
|
| - |
|
222 |
LOGGER.info(fofoOrder.getPaymentOption().toString());
|
| - |
|
223 |
return null;
|
| - |
|
224 |
}
|
| - |
|
225 |
|
| 147 |
@RequestMapping(value = "/order", method = RequestMethod.POST)
|
226 |
@RequestMapping(value = "/create-order", method = RequestMethod.POST)
|
| 148 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest) throws Throwable{
|
227 |
public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest, Model model) throws Throwable{
|
| 149 |
//FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
228 |
//FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| 150 |
LOGGER.info("/order request {}", createOrderRequest);
|
229 |
LOGGER.info("/order request {}", createOrderRequest);
|
| 151 |
FofoDetails fofoDetails = new FofoDetails();
|
230 |
FofoDetails fofoDetails;
|
| - |
|
231 |
try {
|
| 152 |
fofoDetails.setFofoId(963490);
|
232 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| 153 |
return this.createOrder(createOrderRequest, fofoDetails);
|
233 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
234 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
| - |
|
235 |
return "response";
|
| 154 |
}
|
236 |
}
|
| 155 |
|
- |
|
| 156 |
private String createOrder(CreateOrderRequest createOrderRequest, FofoDetails fofoDetails) throws ProfitMandiBusinessException{
|
- |
|
| 157 |
Set<Integer> itemIds = new HashSet<>();
|
237 |
Set<Integer> itemIds = new HashSet<>();
|
| 158 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); //this is for error
|
238 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); //this is for error
|
| 159 |
Map<Integer, CustomFofoLineItem> customFofoLineItemMap = new HashMap<>();
|
239 |
Map<Integer, CustomFofoLineItem> customFofoLineItemMap = new HashMap<>();
|
| 160 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); //this is for pricing error
|
240 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); //this is for pricing error
|
| 161 |
float totalAmount = 0;
|
241 |
float totalAmount = 0;
|
| Line 185... |
Line 265... |
| 185 |
if(!lineItemPrice.isEmpty()){
|
265 |
if(!lineItemPrice.isEmpty()){
|
| 186 |
// given fofo line item price must be greater than zero
|
266 |
// given fofo line item price must be greater than zero
|
| 187 |
LOGGER.error("requested itemId's selling price must greater than 0");
|
267 |
LOGGER.error("requested itemId's selling price must greater than 0");
|
| 188 |
return "error";
|
268 |
return "error";
|
| 189 |
}
|
269 |
}
|
| 190 |
|
270 |
|
| 191 |
List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.selectByFofoItemIds(fofoDetails.getFofoId(), itemIds);
|
271 |
List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.selectByFofoItemIds(fofoDetails.getFofoId(), itemIds);
|
| 192 |
if(itemIds.size() != currentInventorySnapshots.size()){
|
272 |
if(itemIds.size() != currentInventorySnapshots.size()){
|
| 193 |
// error
|
273 |
// error
|
| 194 |
}
|
274 |
}
|
| 195 |
List<ItemIdQuantityAvailability> itemIdQuantityAvailabilities = new ArrayList<>(); //this is for error
|
275 |
List<ItemIdQuantityAvailability> itemIdQuantityAvailabilities = new ArrayList<>(); //this is for error
|
| - |
|
276 |
LOGGER.info("currentInventorySnapshots "+currentInventorySnapshots);
|
| 196 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots){
|
277 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots){
|
| 197 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(currentInventorySnapshot.getId().getItemId());
|
278 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(currentInventorySnapshot.getId().getItemId());
|
| - |
|
279 |
LOGGER.info("customFofoLineItem "+customFofoLineItem);
|
| 198 |
if(customFofoLineItem.getQuantity() > currentInventorySnapshot.getAvailability()){
|
280 |
if(customFofoLineItem.getQuantity() > currentInventorySnapshot.getAvailability()){
|
| 199 |
ItemIdQuantityAvailability itemIdQuantityAvailability = new ItemIdQuantityAvailability();
|
281 |
ItemIdQuantityAvailability itemIdQuantityAvailability = new ItemIdQuantityAvailability();
|
| 200 |
itemIdQuantityAvailability.setItemId(customFofoLineItem.getItemId());
|
282 |
itemIdQuantityAvailability.setItemId(customFofoLineItem.getItemId());
|
| 201 |
Quantity quantity = new Quantity();
|
283 |
Quantity quantity = new Quantity();
|
| 202 |
quantity.setAvailable(currentInventorySnapshot.getAvailability());
|
284 |
quantity.setAvailable(currentInventorySnapshot.getAvailability());
|
| 203 |
quantity.setRequested(customFofoLineItem.getQuantity());
|
285 |
quantity.setRequested(customFofoLineItem.getQuantity());
|
| 204 |
itemIdQuantityAvailability.setQuantity(quantity);
|
286 |
itemIdQuantityAvailability.setQuantity(quantity);
|
| 205 |
itemIdQuantityAvailabilities.add(itemIdQuantityAvailability);
|
287 |
itemIdQuantityAvailabilities.add(itemIdQuantityAvailability);
|
| 206 |
}
|
288 |
}
|
| 207 |
|
289 |
|
| 208 |
}
|
290 |
}
|
| 209 |
|
291 |
|
| 210 |
|
292 |
|
| 211 |
|
293 |
|
| 212 |
if(!itemIdQuantityAvailabilities.isEmpty()){
|
294 |
if(!itemIdQuantityAvailabilities.isEmpty()){
|
| 213 |
// itemIdQuantity request is not valid
|
295 |
// itemIdQuantity request is not valid
|
| 214 |
LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
|
296 |
LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
|
| 215 |
return "error";
|
297 |
return "error";
|
| 216 |
}
|
298 |
}
|
| 217 |
|
299 |
|
| 218 |
|
300 |
|
| 219 |
|
301 |
|
| 220 |
Set<Integer> invalidItemIdSerialNumbers = new HashSet<>();
|
302 |
// Set<Integer> invalidItemIdSerialNumbers = new HashSet<>();
|
| 221 |
Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>();
|
303 |
// Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>();
|
| 222 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoDetails.getFofoId(), itemIds);
|
304 |
// List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoDetails.getFofoId(), itemIds); //change it
|
| 223 |
|
305 |
//
|
| 224 |
Map<Integer, Float> itemIdPriceDropAmount = new HashMap<>();
|
306 |
// Map<Integer, Float> itemIdPriceDropAmount = new HashMap<>();
|
| 225 |
|
307 |
//
|
| 226 |
for(InventoryItem inventoryItem : inventoryItems){
|
308 |
// for(InventoryItem inventoryItem : inventoryItems){
|
| 227 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(inventoryItem.getItemId());
|
309 |
// CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(inventoryItem.getItemId());
|
| 228 |
if(customFofoLineItem.getSerialNumbers().isEmpty()){
|
310 |
// if(customFofoLineItem.getSerialNumbers().isEmpty()){
|
| 229 |
if(!(inventoryItem.getSerialNumber() == null && inventoryItem.getSerialNumber().equals(""))){
|
311 |
// if(!(inventoryItem.getSerialNumber() == null && inventoryItem.getSerialNumber().equals(""))){
|
| 230 |
invalidItemIdSerialNumbers.add(inventoryItem.getItemId());
|
312 |
// invalidItemIdSerialNumbers.add(inventoryItem.getItemId());
|
| - |
|
313 |
// }
|
| - |
|
314 |
// }
|
| - |
|
315 |
// if(!customFofoLineItem.getSerialNumbers().isEmpty()){
|
| - |
|
316 |
// if(!customFofoLineItem.getSerialNumbers().contains(inventoryItem.getSerialNumber())){
|
| - |
|
317 |
// if(!itemIdSerialNumbers.containsKey(customFofoLineItem.getItemId())){
|
| - |
|
318 |
// Set<String> serialNumbers = new HashSet<>();
|
| - |
|
319 |
// serialNumbers.add(inventoryItem.getSerialNumber());
|
| - |
|
320 |
// itemIdSerialNumbers.put(customFofoLineItem.getItemId(), serialNumbers);
|
| - |
|
321 |
// }else{
|
| - |
|
322 |
// itemIdSerialNumbers.get(customFofoLineItem.getItemId()).add(inventoryItem.getSerialNumber());
|
| - |
|
323 |
// }
|
| - |
|
324 |
// }
|
| - |
|
325 |
// itemIdPriceDropAmount.put(inventoryItem.getItemId(), inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount());
|
| - |
|
326 |
// }
|
| - |
|
327 |
|
| - |
|
328 |
Map<Integer, Item> itemMap = new HashMap<Integer, Item>();
|
| - |
|
329 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
| - |
|
330 |
for (Item i : items){
|
| - |
|
331 |
itemMap.put(i.getId(), i);
|
| - |
|
332 |
}
|
| - |
|
333 |
|
| - |
|
334 |
Set<Integer> nonSerializedItemIds = new HashSet<>();
|
| - |
|
335 |
Set<String> serialNumbers = new HashSet<>();
|
| - |
|
336 |
|
| - |
|
337 |
Collection<CustomFofoLineItem> lineItemsValues = customFofoLineItemMap.values();
|
| - |
|
338 |
for (CustomFofoLineItem cli : lineItemsValues){
|
| - |
|
339 |
|
| - |
|
340 |
Item item = itemMap.get(cli.getItemId());
|
| - |
|
341 |
if (item.getType().equals(ItemType.SERIALIZED)){
|
| - |
|
342 |
for (String s : cli.getSerialNumbers()){
|
| - |
|
343 |
serialNumbers.add(s);
|
| 231 |
}
|
344 |
}
|
| 232 |
}
|
345 |
}
|
| - |
|
346 |
else{
|
| 233 |
if(!customFofoLineItem.getSerialNumbers().isEmpty()){
|
347 |
nonSerializedItemIds.add(cli.getItemId());
|
| - |
|
348 |
}
|
| - |
|
349 |
|
| - |
|
350 |
}
|
| - |
|
351 |
|
| - |
|
352 |
|
| 234 |
if(!customFofoLineItem.getSerialNumbers().contains(inventoryItem.getSerialNumber())){
|
353 |
Map<Integer, List<InventoryItem>> serializedInventoryItemMap = new HashMap<Integer, List<InventoryItem>>();
|
| 235 |
if(!itemIdSerialNumbers.containsKey(customFofoLineItem.getItemId())){
|
354 |
Map<Integer, List<InventoryItem>> nonSerializedInventoryItemMap = new HashMap<Integer, List<InventoryItem>>();
|
| 236 |
Set<String> serialNumbers = new HashSet<>();
|
355 |
Map<Integer, List<Float>> itemIdPriceDropAmount = new HashMap<>();
|
| - |
|
356 |
|
| - |
|
357 |
if (serialNumbers.size() > 0 ){
|
| - |
|
358 |
List<InventoryItem> serializedInventoryItems = inventoryItemRepository.selectByFofoIdSerialNumbers(fofoDetails.getFofoId(), serialNumbers);
|
| - |
|
359 |
for (InventoryItem it : serializedInventoryItems){
|
| - |
|
360 |
if (it.getGoodQuantity() == 1){
|
| 237 |
serialNumbers.add(inventoryItem.getSerialNumber());
|
361 |
if (serializedInventoryItemMap.containsKey(it.getItemId())){
|
| 238 |
itemIdSerialNumbers.put(customFofoLineItem.getItemId(), serialNumbers);
|
362 |
serializedInventoryItemMap.get(it.getItemId()).add(it);
|
| - |
|
363 |
itemIdPriceDropAmount.get(it.getItemId()).add(it.getUnitPrice() - (it.getPriceDropAmount()==null?0:it.getPriceDropAmount()));
|
| - |
|
364 |
}
|
| 239 |
}else{
|
365 |
else{
|
| - |
|
366 |
ArrayList<InventoryItem> tmp = new ArrayList<InventoryItem>();
|
| - |
|
367 |
tmp.add(it);
|
| - |
|
368 |
serializedInventoryItemMap.put(it.getItemId(), tmp);
|
| - |
|
369 |
ArrayList<Float> priceDropAmouts = new ArrayList<>();
|
| - |
|
370 |
priceDropAmouts.add(it.getUnitPrice() - (it.getPriceDropAmount()==null?0:it.getPriceDropAmount()));
|
| 240 |
itemIdSerialNumbers.get(customFofoLineItem.getItemId()).add(inventoryItem.getSerialNumber());
|
371 |
itemIdPriceDropAmount.put(it.getItemId(), priceDropAmouts);
|
| 241 |
}
|
372 |
}
|
| 242 |
}
|
373 |
}
|
| 243 |
}
|
374 |
}
|
| 244 |
itemIdPriceDropAmount.put(inventoryItem.getItemId(), inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount());
|
- |
|
| 245 |
}
|
375 |
}
|
| - |
|
376 |
|
| - |
|
377 |
if (nonSerializedItemIds.size() > 0){
|
| - |
|
378 |
List<InventoryItem> nonSerializedInventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoDetails.getFofoId(), nonSerializedItemIds);
|
| - |
|
379 |
for (InventoryItem it : nonSerializedInventoryItems){
|
| - |
|
380 |
if (it.getGoodQuantity() > 0){
|
| - |
|
381 |
if (nonSerializedInventoryItemMap.containsKey(it.getItemId())){
|
| - |
|
382 |
nonSerializedInventoryItemMap.get(it.getItemId()).add(it);
|
| - |
|
383 |
}
|
| - |
|
384 |
else{
|
| - |
|
385 |
ArrayList<InventoryItem> tmp = new ArrayList<InventoryItem>();
|
| - |
|
386 |
tmp.add(it);
|
| - |
|
387 |
nonSerializedInventoryItemMap.put(it.getItemId(), tmp);
|
| - |
|
388 |
}
|
| - |
|
389 |
}
|
| - |
|
390 |
}
|
| 246 |
|
391 |
}
|
| - |
|
392 |
|
| - |
|
393 |
List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
|
| - |
|
394 |
List<Integer> itemIdSerialNumbers = new ArrayList<Integer>();
|
| - |
|
395 |
|
| - |
|
396 |
for (Item i : items){
|
| - |
|
397 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(i.getId());
|
| - |
|
398 |
if (i.getType().equals(ItemType.SERIALIZED)){
|
| - |
|
399 |
if (customFofoLineItem ==null || customFofoLineItem.getSerialNumbers().size() ==0){
|
| - |
|
400 |
invalidItemIdSerialNumbers.add(i.getId());
|
| - |
|
401 |
}
|
| - |
|
402 |
}
|
| - |
|
403 |
else{
|
| - |
|
404 |
if (customFofoLineItem == null || customFofoLineItem.getSerialNumbers().size() > 0 ){
|
| - |
|
405 |
itemIdSerialNumbers.add(i.getId());
|
| - |
|
406 |
}
|
| - |
|
407 |
}
|
| - |
|
408 |
}
|
| - |
|
409 |
|
| 247 |
if(!invalidItemIdSerialNumbers.isEmpty()){
|
410 |
if(!invalidItemIdSerialNumbers.isEmpty()){
|
| 248 |
LOGGER.error("Invalid itemId's serialNumbers {}", invalidItemIdSerialNumbers);
|
411 |
LOGGER.error("Invalid itemId's serialNumbers {}", invalidItemIdSerialNumbers);
|
| 249 |
// itemId's are serialized you are saying these are not serialized
|
412 |
// itemId's are serialized you are saying these are not serialized
|
| 250 |
return "error";
|
413 |
return "error";
|
| 251 |
}
|
414 |
}
|
| 252 |
|
415 |
|
| 253 |
if(!itemIdSerialNumbers.isEmpty()){
|
416 |
if(!itemIdSerialNumbers.isEmpty()){
|
| 254 |
LOGGER.error("Invalid itemId's serialNumbers {}", itemIdSerialNumbers);
|
417 |
LOGGER.error("Invalid itemId's serialNumbers {}", itemIdSerialNumbers);
|
| 255 |
// itemId's are non serialized you are saying these are serialized
|
418 |
// itemId's are non serialized you are saying these are serialized
|
| 256 |
return "error";
|
419 |
return "error";
|
| 257 |
}
|
420 |
}
|
| 258 |
|
- |
|
| 259 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
- |
|
| 260 |
|
421 |
|
| 261 |
if(items.size() != itemIds.size()){
|
422 |
if(items.size() != itemIds.size()){
|
| 262 |
LOGGER.error("Requested ItemIds not found in catalog");
|
423 |
LOGGER.error("Requested ItemIds not found in catalog");
|
| 263 |
// invalid itemIds
|
424 |
// invalid itemIds
|
| 264 |
return "error";
|
425 |
return "error";
|
| 265 |
}
|
426 |
}
|
| - |
|
427 |
|
| - |
|
428 |
Map<Integer, List<InventoryItem>> inventoryItemsToBill = new HashMap<Integer,List<InventoryItem>>();
|
| - |
|
429 |
Map<Integer, Integer> inventoryItemQuantityUsed = new HashMap<>(); //to keep track of inventoryitem quanity used for scan records insertion
|
| - |
|
430 |
|
| - |
|
431 |
//Lets reduce quantity and decide what inventory items to use.
|
| - |
|
432 |
for (Item i : items){
|
| - |
|
433 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(i.getId());
|
| - |
|
434 |
if (i.getType().equals(ItemType.SERIALIZED)){
|
| - |
|
435 |
//TODO:handle null
|
| - |
|
436 |
if (serializedInventoryItemMap.get(i.getId()) == null || customFofoLineItem.getSerialNumbers().size() != serializedInventoryItemMap.get(i.getId()).size()){
|
| - |
|
437 |
//not enough serial numbers
|
| - |
|
438 |
System.out.println("not enough serial numbers");
|
| - |
|
439 |
return "error";
|
| - |
|
440 |
}
|
| - |
|
441 |
List<InventoryItem> inventoryItemsSerializedserialized = serializedInventoryItemMap.get(i.getId());
|
| - |
|
442 |
for (InventoryItem it : inventoryItemsSerializedserialized){
|
| - |
|
443 |
it.setGoodQuantity(0);
|
| - |
|
444 |
inventoryItemQuantityUsed.put(it.getId(), 1);
|
| - |
|
445 |
}
|
| - |
|
446 |
inventoryItemsToBill.put(i.getId(), inventoryItemsSerializedserialized);
|
| 266 |
|
447 |
}
|
| - |
|
448 |
else{
|
| - |
|
449 |
List<InventoryItem> inventoryItemsNonSerialized = nonSerializedInventoryItemMap.get(i.getId());
|
| - |
|
450 |
int quantityToBill = customFofoLineItem.getQuantity();
|
| - |
|
451 |
int totalLeft = quantityToBill;
|
| - |
|
452 |
List<InventoryItem> inventoryItemsNonSerializedUsed = new ArrayList<InventoryItem>();
|
| - |
|
453 |
if (inventoryItemsNonSerialized!=null){
|
| 267 |
Map<Integer, Item> itemIdDetails = this.toItemMap(items);
|
454 |
for (InventoryItem it : inventoryItemsNonSerialized){
|
| - |
|
455 |
if (totalLeft > 0){
|
| - |
|
456 |
int toUse = Math.min(totalLeft, it.getGoodQuantity());
|
| - |
|
457 |
inventoryItemQuantityUsed.put(it.getId(), toUse);
|
| - |
|
458 |
it.setGoodQuantity(it.getGoodQuantity() - toUse);
|
| - |
|
459 |
totalLeft = totalLeft - toUse;
|
| - |
|
460 |
inventoryItemsNonSerializedUsed.add(it);
|
| - |
|
461 |
}
|
| - |
|
462 |
}
|
| - |
|
463 |
}
|
| - |
|
464 |
|
| - |
|
465 |
if (totalLeft > 0){
|
| - |
|
466 |
//not enough quanity for non-serialized
|
| - |
|
467 |
System.out.println("not enough quanity for non-serialized");
|
| - |
|
468 |
return "error";
|
| - |
|
469 |
}
|
| - |
|
470 |
inventoryItemsToBill.put(i.getId(), inventoryItemsNonSerializedUsed);
|
| - |
|
471 |
}
|
| 268 |
|
472 |
}
|
| - |
|
473 |
|
| 269 |
InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
|
474 |
InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
|
| 270 |
try{
|
475 |
try{
|
| 271 |
invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoDetails.getFofoId());
|
476 |
invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoDetails.getFofoId());
|
| 272 |
invoiceNumberGenerationSequence.setSequence(invoiceNumberGenerationSequence.getSequence() + 1);
|
477 |
invoiceNumberGenerationSequence.setSequence(invoiceNumberGenerationSequence.getSequence() + 1);
|
| 273 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
478 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
| Line 275... |
Line 480... |
| 275 |
invoiceNumberGenerationSequence = new InvoiceNumberGenerationSequence();
|
480 |
invoiceNumberGenerationSequence = new InvoiceNumberGenerationSequence();
|
| 276 |
invoiceNumberGenerationSequence.setFofoId(fofoDetails.getFofoId());
|
481 |
invoiceNumberGenerationSequence.setFofoId(fofoDetails.getFofoId());
|
| 277 |
invoiceNumberGenerationSequence.setPrefix("INVOICE");
|
482 |
invoiceNumberGenerationSequence.setPrefix("INVOICE");
|
| 278 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
483 |
invoiceNumberGenerationSequenceRepository.persist(invoiceNumberGenerationSequence);
|
| 279 |
}
|
484 |
}
|
| 280 |
|
485 |
|
| 281 |
CustomCustomer customCustomer = createOrderRequest.getCustomer();
|
486 |
CustomCustomer customCustomer = createOrderRequest.getCustomer();
|
| 282 |
|
487 |
|
| 283 |
if(!StringUtils.isValidEmailAddress(customCustomer.getEmailId())){
|
488 |
if(!StringUtils.isValidEmailAddress(customCustomer.getEmailId())){
|
| 284 |
LOGGER.error("invalid customer emailId {} ", customCustomer.getEmailId());
|
489 |
LOGGER.error("invalid customer emailId {} ", customCustomer.getEmailId());
|
| 285 |
return "error";
|
490 |
return "error";
|
| 286 |
}
|
491 |
}
|
| 287 |
|
492 |
|
| 288 |
if(!StringUtils.isValidMobile(customCustomer.getMobileNumber())){
|
493 |
if(!StringUtils.isValidMobile(customCustomer.getMobileNumber())){
|
| 289 |
LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
|
494 |
LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
|
| 290 |
return "error";
|
495 |
return "error";
|
| 291 |
}
|
496 |
}
|
| 292 |
|
497 |
|
| 293 |
Customer customer = null;
|
498 |
Customer customer = null;
|
| 294 |
boolean foundCustomer = false;
|
- |
|
| 295 |
if(customCustomer.getCustomerAddressId() > 0){
|
- |
|
| 296 |
try{
|
499 |
try{
|
| 297 |
customer = customerRepository.selectById(customCustomer.getCustomerAddressId());
|
- |
|
| 298 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
- |
|
| 299 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
- |
|
| 300 |
foundCustomer = true;
|
500 |
//TODO:remove email id
|
| 301 |
}
|
- |
|
| 302 |
}else{
|
- |
|
| 303 |
try{
|
- |
|
| 304 |
customer = customerRepository.selectByMobileNumber(customCustomer.getMobileNumber());
|
501 |
customer = customerRepository.selectByMobileNumber(customCustomer.getMobileNumber());
|
| 305 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
502 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 306 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
503 |
LOGGER.error("Error : ", profitMandiBusinessException);
|
| 307 |
foundCustomer = true;
|
- |
|
| 308 |
}
|
- |
|
| 309 |
}
|
- |
|
| 310 |
LOGGER.error("Error occured : {}", foundCustomer);
|
- |
|
| 311 |
if(foundCustomer){
|
- |
|
| 312 |
customer = new Customer();
|
504 |
customer = new Customer();
|
| 313 |
customer.setName(customCustomer.getName());
|
505 |
customer.setName(customCustomer.getName());
|
| 314 |
customer.setEmailId(customCustomer.getEmailId());
|
506 |
customer.setEmailId(customCustomer.getEmailId());
|
| 315 |
customer.setMobileNumber(customCustomer.getMobileNumber());
|
507 |
customer.setMobileNumber(customCustomer.getMobileNumber());
|
| 316 |
customerRepository.persist(customer);
|
508 |
customerRepository.persist(customer);
|
| 317 |
}
|
509 |
}
|
| 318 |
//TODO:Check if createOrderRequest contains addressId
|
510 |
//TODO:Check if createOrderRequest contains addressId
|
| 319 |
CustomerAddress customerAddress = this.createCustomerAddress(customCustomer.getAddress());
|
511 |
CustomerAddress customerAddress = this.createCustomerAddress(customCustomer.getAddress());
|
| 320 |
customerAddress.setCustomerId(customer.getId());
|
512 |
customerAddress.setCustomerId(customer.getId());
|
| 321 |
customerAddressRepository.persist(customerAddress);
|
513 |
customerAddressRepository.persist(customerAddress);
|
| 322 |
|
514 |
|
| 323 |
/*InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = */
|
515 |
/*InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = */
|
| 324 |
|
516 |
|
| 325 |
|
517 |
|
| 326 |
FofoOrder fofoOrder = new FofoOrder();
|
518 |
FofoOrder fofoOrder = new FofoOrder();
|
| 327 |
fofoOrder.setCustomerId(customer.getId());
|
519 |
fofoOrder.setCustomerId(customer.getId());
|
| 328 |
fofoOrder.setFofoId(fofoDetails.getFofoId());
|
520 |
fofoOrder.setFofoId(fofoDetails.getFofoId());
|
| 329 |
fofoOrder.setInvoiceNumber(invoiceNumberGenerationSequence.getPrefix() + invoiceNumberGenerationSequence.getSequence());
|
521 |
fofoOrder.setInvoiceNumber(invoiceNumberGenerationSequence.getPrefix() + invoiceNumberGenerationSequence.getSequence());
|
| 330 |
fofoOrder.setTotalAmount(totalAmount);
|
522 |
fofoOrder.setTotalAmount(totalAmount);
|
| 331 |
fofoOrder.setCustomerAddressId(customerAddress.getId());
|
523 |
fofoOrder.setCustomerAddressId(customerAddress.getId());
|
| 332 |
fofoOrderRepository.persist(fofoOrder);
|
524 |
fofoOrderRepository.persist(fofoOrder);
|
| 333 |
|
525 |
|
| 334 |
for(CustomPaymentOption customPaymentOption : createOrderRequest.getPaymentOptions()){
|
526 |
for(CustomPaymentOption customPaymentOption : createOrderRequest.getPaymentOptions()){
|
| 335 |
PaymentOption paymentOption = new PaymentOption();
|
527 |
PaymentOption paymentOption = new PaymentOption();
|
| 336 |
paymentOption.setOrderId(fofoOrder.getId());
|
528 |
paymentOption.setOrderId(fofoOrder.getId());
|
| 337 |
paymentOption.setAmount(customPaymentOption.getAmount());
|
529 |
paymentOption.setAmount(customPaymentOption.getAmount());
|
| 338 |
paymentOption.setType(customPaymentOption.getType());
|
530 |
paymentOption.setType(customPaymentOption.getType());
|
| 339 |
paymentOptionRepository.persist(paymentOption);
|
531 |
paymentOptionRepository.persist(paymentOption);
|
| 340 |
}
|
532 |
}
|
| 341 |
|
533 |
|
| 342 |
Address retailerAddress = addressRepository.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoDetails.getFofoId()));
|
534 |
Address retailerAddress = addressRepository.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(fofoDetails.getFofoId()));
|
| 343 |
|
535 |
//
|
| 344 |
Map<String, GstRate> gstRateMap = null;
|
- |
|
| 345 |
if(retailerAddress.getState().equals(customerAddress.getState())){
|
- |
|
| 346 |
LOGGER.info("inter gstRate = true");
|
- |
|
| 347 |
gstRateMap = Utils.getInterGstRates();
|
- |
|
| 348 |
}else{
|
- |
|
| 349 |
gstRateMap = Utils.getGstRates(retailerAddress.getState());
|
536 |
Map<String, GstRate> gstRateMap = Utils.getGstRates(retailerAddress.getState());
|
| 350 |
}
|
- |
|
| 351 |
LOGGER.info("gstRateMap {}", gstRateMap);
|
- |
|
| 352 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
537 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
| 353 |
FofoLineItem fofoLineItem = new FofoLineItem();
|
538 |
FofoLineItem fofoLineItem = new FofoLineItem();
|
| 354 |
fofoLineItem.setItemId(customFofoLineItem.getItemId());
|
539 |
fofoLineItem.setItemId(customFofoLineItem.getItemId());
|
| 355 |
fofoLineItem.setQuantity(customFofoLineItem.getQuantity());
|
540 |
fofoLineItem.setQuantity(customFofoLineItem.getQuantity());
|
| 356 |
fofoLineItem.setSellingPrice(customFofoLineItem.getSellingPrice());
|
541 |
fofoLineItem.setSellingPrice(customFofoLineItem.getSellingPrice());
|
| 357 |
fofoLineItem.setOrderId(fofoOrder.getId());
|
542 |
fofoLineItem.setOrderId(fofoOrder.getId());
|
| 358 |
fofoLineItem.setDp(customFofoLineItem.getSellingPrice());
|
543 |
fofoLineItem.setDp(customFofoLineItem.getSellingPrice());
|
| 359 |
Item item = itemIdDetails.get(customFofoLineItem.getItemId());
|
544 |
Item item = itemMap.get(customFofoLineItem.getItemId());
|
| 360 |
GstRate gstRate = gstRateMap.get(item.getHsnCode());
|
545 |
GstRate gstRate = gstRateMap.get(item.getHsnCode());
|
| 361 |
fofoLineItem.setIgstRate(gstRate.getIgstRate());
|
546 |
fofoLineItem.setIgstRate(gstRate.getIgstRate());
|
| 362 |
fofoLineItem.setCgstRate(gstRate.getCgstRate());
|
547 |
fofoLineItem.setCgstRate(gstRate.getCgstRate());
|
| 363 |
fofoLineItem.setSgstRate(gstRate.getSgstRate());
|
548 |
fofoLineItem.setSgstRate(gstRate.getSgstRate());
|
| 364 |
fofoLineItem.setHsnCode(gstRate.getHsnCode());
|
549 |
fofoLineItem.setHsnCode(gstRate.getHsnCode());
|
| 365 |
fofoLineItem.setCost(itemIdPriceDropAmount.get(customFofoLineItem.getItemId()));
|
550 |
List<Float> priceDropAmounts = itemIdPriceDropAmount.get(customFofoLineItem.getItemId());
|
| - |
|
551 |
float cost = 0;
|
| - |
|
552 |
if (priceDropAmounts!=null){
|
| - |
|
553 |
for (Float pda : priceDropAmounts){
|
| - |
|
554 |
cost = cost + pda;
|
| - |
|
555 |
}
|
| - |
|
556 |
}
|
| - |
|
557 |
else{
|
| - |
|
558 |
cost = customFofoLineItem.getSellingPrice()* customFofoLineItem.getQuantity();
|
| - |
|
559 |
}
|
| - |
|
560 |
fofoLineItem.setCost(cost);
|
| 366 |
fofoLineItem.setBrand(item.getBrand());
|
561 |
fofoLineItem.setBrand(item.getBrand());
|
| 367 |
fofoLineItem.setModelName(item.getModelName());
|
562 |
fofoLineItem.setModelName(item.getModelName());
|
| 368 |
fofoLineItem.setModelNumber(item.getModelNumber());
|
563 |
fofoLineItem.setModelNumber(item.getModelNumber());
|
| 369 |
fofoLineItem.setColor(item.getColor());
|
564 |
fofoLineItem.setColor(item.getColor());
|
| 370 |
fofoLineItemRepository.persist(fofoLineItem);
|
565 |
fofoLineItemRepository.persist(fofoLineItem);
|
| Line 375... |
Line 570... |
| 375 |
fofoLineItemSerialNumber.setFofoLineItemId(fofoLineItem.getId());
|
570 |
fofoLineItemSerialNumber.setFofoLineItemId(fofoLineItem.getId());
|
| 376 |
fofoLineItemSerialNumber.setSerialNumber(serialNumber);
|
571 |
fofoLineItemSerialNumber.setSerialNumber(serialNumber);
|
| 377 |
fofoLineItemSerialNumberRepository.persist(fofoLineItemSerialNumber);
|
572 |
fofoLineItemSerialNumberRepository.persist(fofoLineItemSerialNumber);
|
| 378 |
}
|
573 |
}
|
| 379 |
}
|
574 |
}
|
| 380 |
|
575 |
|
| 381 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots){
|
576 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots){
|
| 382 |
FofoItemId fofoItemId = new FofoItemId();
|
577 |
FofoItemId fofoItemId = new FofoItemId();
|
| 383 |
fofoItemId.setFofoId(fofoDetails.getFofoId());
|
578 |
fofoItemId.setFofoId(fofoDetails.getFofoId());
|
| 384 |
fofoItemId.setItemId(fofoLineItem.getItemId());
|
579 |
fofoItemId.setItemId(fofoLineItem.getItemId());
|
| 385 |
if(currentInventorySnapshot.getId().equals(fofoItemId)){
|
580 |
if(currentInventorySnapshot.getId().equals(fofoItemId)){
|
| 386 |
currentInventorySnapshotRepository.updateAvailabilityByFofoItemId(fofoItemId, currentInventorySnapshot.getAvailability() - customFofoLineItem.getQuantity());
|
581 |
currentInventorySnapshotRepository.updateAvailabilityByFofoItemId(fofoItemId, currentInventorySnapshot.getAvailability() - customFofoLineItem.getQuantity());
|
| 387 |
}
|
582 |
}
|
| 388 |
}
|
583 |
}
|
| - |
|
584 |
List<InventoryItem> inventoryItems = inventoryItemsToBill.get(fofoLineItem.getItemId());
|
| 389 |
for(InventoryItem inventoryItem : inventoryItems){
|
585 |
for(InventoryItem inventoryItem : inventoryItems){
|
| 390 |
if(inventoryItem.getItemId() == fofoLineItem.getItemId()){
|
- |
|
| 391 |
if(inventoryItem.getSerialNumber() == null || inventoryItem.getSerialNumber().isEmpty()){
|
- |
|
| 392 |
if(fofoLineItem.getQuantity() > 0)
|
- |
|
| 393 |
if(fofoLineItem.getQuantity() <= inventoryItem.getGoodQuantity()){
|
- |
|
| 394 |
inventoryItem.setGoodQuantity(inventoryItem.getGoodQuantity() - fofoLineItem.getQuantity());
|
- |
|
| 395 |
inventoryItem.setLastScanType(ScanType.SALE);
|
586 |
inventoryItem.setLastScanType(ScanType.SALE);
|
| 396 |
inventoryItemRepository.persist(inventoryItem);
|
587 |
inventoryItemRepository.persist(inventoryItem);
|
| 397 |
ScanRecord scanRecord = new ScanRecord();
|
588 |
ScanRecord scanRecord = new ScanRecord();
|
| 398 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
589 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
| 399 |
scanRecord.setFofoId(fofoDetails.getFofoId());
|
590 |
scanRecord.setFofoId(fofoDetails.getFofoId());
|
| 400 |
scanRecord.setQuantity(fofoLineItem.getQuantity());
|
- |
|
| 401 |
scanRecord.setType(ScanType.SALE);
|
- |
|
| 402 |
scanRecordRepository.persist(scanRecord);
|
- |
|
| 403 |
}else{
|
591 |
//correct this
|
| 404 |
int availableGoodQuantity = inventoryItem.getGoodQuantity();
|
- |
|
| 405 |
inventoryItem.setGoodQuantity(0);
|
- |
|
| 406 |
fofoLineItem.setQuantity(fofoLineItem.getQuantity() - availableGoodQuantity);
|
- |
|
| 407 |
inventoryItem.setLastScanType(ScanType.SALE);
|
- |
|
| 408 |
inventoryItemRepository.persist(inventoryItem);
|
- |
|
| 409 |
ScanRecord scanRecord = new ScanRecord();
|
- |
|
| 410 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
- |
|
| 411 |
scanRecord.setFofoId(fofoDetails.getFofoId());
|
- |
|
| 412 |
scanRecord.setQuantity(availableGoodQuantity);
|
- |
|
| 413 |
scanRecord.setType(ScanType.SALE);
|
- |
|
| 414 |
scanRecordRepository.persist(scanRecord);
|
- |
|
| 415 |
}
|
- |
|
| 416 |
}else{
|
- |
|
| 417 |
inventoryItem.setGoodQuantity(0);
|
- |
|
| 418 |
inventoryItem.setLastScanType(ScanType.SALE);
|
- |
|
| 419 |
inventoryItemRepository.persist(inventoryItem);
|
- |
|
| 420 |
ScanRecord scanRecord = new ScanRecord();
|
- |
|
| 421 |
scanRecord.setInventoryItemId(inventoryItem.getId());
|
592 |
scanRecord.setQuantity(inventoryItemQuantityUsed.get(inventoryItem.getId()));
|
| 422 |
scanRecord.setFofoId(fofoDetails.getFofoId());
|
- |
|
| 423 |
scanRecord.setQuantity(1);
|
- |
|
| 424 |
scanRecord.setType(ScanType.SALE);
|
593 |
scanRecord.setType(ScanType.SALE);
|
| 425 |
scanRecordRepository.persist(scanRecord);
|
594 |
scanRecordRepository.persist(scanRecord);
|
| 426 |
}
|
- |
|
| 427 |
}
|
595 |
}
|
| 428 |
}
|
- |
|
| 429 |
}
|
596 |
}
|
| 430 |
return null;
|
597 |
return null;
|
| 431 |
}
|
598 |
}
|
| 432 |
|
599 |
|
| 433 |
|
600 |
|
| 434 |
private Map<Integer, Item> toItemMap(List<Item> items){
|
601 |
private Map<Integer, Item> toItemMap(List<Item> items){
|
| 435 |
Map<Integer, Item> map = new HashMap<>();
|
602 |
Map<Integer, Item> map = new HashMap<>();
|
| 436 |
for(Item item : items){
|
603 |
for(Item item : items){
|
| 437 |
map.put(item.getId(), item);
|
604 |
map.put(item.getId(), item);
|
| 438 |
}
|
605 |
}
|
| 439 |
return map;
|
606 |
return map;
|
| 440 |
}
|
607 |
}
|
| 441 |
|
608 |
|
| 442 |
/*private Address createAddress(CustomAddress customAddress){
|
609 |
/*private Address createAddress(CustomAddress customAddress){
|
| 443 |
Address address = new Address();
|
610 |
Address address = new Address();
|
| 444 |
address.setName(customAddress.getName());
|
611 |
address.setName(customAddress.getName());
|
| 445 |
address.setLine1(customAddress.getLine1());
|
612 |
address.setLine1(customAddress.getLine1());
|
| 446 |
address.setLine2(customAddress.getLine2());
|
613 |
address.setLine2(customAddress.getLine2());
|
| Line 451... |
Line 618... |
| 451 |
address.setCountry(customAddress.getCountry());
|
618 |
address.setCountry(customAddress.getCountry());
|
| 452 |
address.setPhoneNumber(customAddress.getPhoneNumber());
|
619 |
address.setPhoneNumber(customAddress.getPhoneNumber());
|
| 453 |
address.setEnabled(true);
|
620 |
address.setEnabled(true);
|
| 454 |
return address;
|
621 |
return address;
|
| 455 |
}*/
|
622 |
}*/
|
| 456 |
|
623 |
|
| 457 |
private CustomerAddress createCustomerAddress(CustomAddress customAddress){
|
624 |
private CustomerAddress createCustomerAddress(CustomAddress customAddress){
|
| 458 |
CustomerAddress customerAddress = new CustomerAddress();
|
625 |
CustomerAddress customerAddress = new CustomerAddress();
|
| 459 |
customerAddress.setName(customAddress.getName());
|
626 |
customerAddress.setName(customAddress.getName());
|
| 460 |
customerAddress.setLine1(customAddress.getLine1());
|
627 |
customerAddress.setLine1(customAddress.getLine1());
|
| 461 |
customerAddress.setLine2(customAddress.getLine2());
|
628 |
customerAddress.setLine2(customAddress.getLine2());
|
| Line 465... |
Line 632... |
| 465 |
customerAddress.setState(customAddress.getState());
|
632 |
customerAddress.setState(customAddress.getState());
|
| 466 |
customerAddress.setCountry(customAddress.getCountry());
|
633 |
customerAddress.setCountry(customAddress.getCountry());
|
| 467 |
customerAddress.setPhoneNumber(customAddress.getPhoneNumber());
|
634 |
customerAddress.setPhoneNumber(customAddress.getPhoneNumber());
|
| 468 |
return customerAddress;
|
635 |
return customerAddress;
|
| 469 |
}
|
636 |
}
|
| 470 |
|
637 |
|
| 471 |
private CustomAddress createCustomAddress(Address address){
|
638 |
private CustomAddress createCustomAddress(Address address){
|
| 472 |
CustomAddress customAddress = new CustomAddress();
|
639 |
CustomAddress customAddress = new CustomAddress();
|
| 473 |
customAddress.setName(address.getName());
|
640 |
customAddress.setName(address.getName());
|
| 474 |
customAddress.setLine1(address.getLine1());
|
641 |
customAddress.setLine1(address.getLine1());
|
| 475 |
customAddress.setLine2(address.getLine2());
|
642 |
customAddress.setLine2(address.getLine2());
|
| Line 479... |
Line 646... |
| 479 |
customAddress.setState(address.getState());
|
646 |
customAddress.setState(address.getState());
|
| 480 |
customAddress.setCountry(address.getCountry());
|
647 |
customAddress.setCountry(address.getCountry());
|
| 481 |
customAddress.setPhoneNumber(address.getPhoneNumber());
|
648 |
customAddress.setPhoneNumber(address.getPhoneNumber());
|
| 482 |
return customAddress;
|
649 |
return customAddress;
|
| 483 |
}
|
650 |
}
|
| 484 |
|
651 |
|
| 485 |
private CustomAddress createCustomAddress(CustomerAddress customerAddress){
|
652 |
private CustomAddress createCustomAddress(CustomerAddress customerAddress){
|
| 486 |
CustomAddress customAddress = new CustomAddress();
|
653 |
CustomAddress customAddress = new CustomAddress();
|
| 487 |
customAddress.setName(customerAddress.getName());
|
654 |
customAddress.setName(customerAddress.getName());
|
| 488 |
customAddress.setLine1(customerAddress.getLine1());
|
655 |
customAddress.setLine1(customerAddress.getLine1());
|
| 489 |
customAddress.setLine2(customerAddress.getLine2());
|
656 |
customAddress.setLine2(customerAddress.getLine2());
|
| Line 493... |
Line 660... |
| 493 |
customAddress.setState(customerAddress.getState());
|
660 |
customAddress.setState(customerAddress.getState());
|
| 494 |
customAddress.setCountry(customerAddress.getCountry());
|
661 |
customAddress.setCountry(customerAddress.getCountry());
|
| 495 |
customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
|
662 |
customAddress.setPhoneNumber(customerAddress.getPhoneNumber());
|
| 496 |
return customAddress;
|
663 |
return customAddress;
|
| 497 |
}
|
664 |
}
|
| 498 |
|
665 |
|
| 499 |
private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
|
666 |
private void validatePaymentOptionsAndTotalAmount(Set<CustomPaymentOption> customPaymentOptions, float totalAmount) throws ProfitMandiBusinessException
|
| 500 |
{
|
667 |
{
|
| 501 |
float calculatedAmount = 0;
|
668 |
float calculatedAmount = 0;
|
| 502 |
Set<String> paymentOptionTypes = new HashSet<>();
|
669 |
Set<String> paymentOptionTypes = new HashSet<>();
|
| 503 |
for(CustomPaymentOption customPaymentOption : customPaymentOptions){
|
670 |
for(CustomPaymentOption customPaymentOption : customPaymentOptions){
|
| Line 510... |
Line 677... |
| 510 |
}
|
677 |
}
|
| 511 |
if(calculatedAmount != totalAmount){
|
678 |
if(calculatedAmount != totalAmount){
|
| 512 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "");
|
679 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.PAYMENT_OPTION_CALCULATED_AMOUNT, calculatedAmount, "");
|
| 513 |
}
|
680 |
}
|
| 514 |
}
|
681 |
}
|
| 515 |
|
682 |
|
| 516 |
|
683 |
|
| 517 |
@RequestMapping(value = "/generateInvoice")
|
684 |
@RequestMapping(value = "/generateInvoice")
|
| 518 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws Throwable{
|
685 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId) throws Throwable{
|
| 519 |
LOGGER.info("Request received at url {} with params {} ", request.getRequestURI(), request.getParameterMap());
|
686 |
LOGGER.info("Request received at url {} with params {} ", request.getRequestURI(), request.getParameterMap());
|
| 520 |
//FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
687 |
FofoDetails fofoDetails;
|
| 521 |
|
688 |
try {
|
| 522 |
FofoDetails fofoDetails = new FofoDetails();
|
689 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| 523 |
fofoDetails.setFofoId(963490);
|
690 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
691 |
return null;
|
| - |
|
692 |
}
|
| 524 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
693 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(fofoDetails.getFofoId(), orderId);
|
| 525 |
PdfModel pdfModel = new PdfModel();
|
694 |
PdfModel pdfModel = new PdfModel();
|
| 526 |
pdfModel.setAuther("profitmandi");
|
695 |
pdfModel.setAuther("profitmandi");
|
| 527 |
pdfModel.setTitle("Retailer Invoice");
|
696 |
pdfModel.setTitle("Retailer Invoice");
|
| 528 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
697 |
Customer customer = customerRepository.selectById(fofoOrder.getCustomerId());
|
| Line 533... |
Line 702... |
| 533 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
702 |
CustomerAddress customerAddress = customerAddressRepository.selectById(fofoOrder.getCustomerAddressId());
|
| 534 |
customCustomer.setAddress(this.createCustomAddress(customerAddress));
|
703 |
customCustomer.setAddress(this.createCustomAddress(customerAddress));
|
| 535 |
pdfModel.setCustomer(customCustomer);
|
704 |
pdfModel.setCustomer(customCustomer);
|
| 536 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
705 |
pdfModel.setInvoiceNumber(fofoOrder.getInvoiceNumber());
|
| 537 |
pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
|
706 |
pdfModel.setTotalAmount(fofoOrder.getTotalAmount());
|
| 538 |
|
707 |
|
| 539 |
Retailer retailer = retailerRepository.selectById(fofoDetails.getFofoId());
|
708 |
Retailer retailer = retailerRepository.selectById(fofoDetails.getFofoId());
|
| 540 |
User user = userRepository.selectById(userAccountRepository.selectUserIdByRetailerId(retailer.getId()));
|
709 |
User user = userRepository.selectById(userAccountRepository.selectUserIdByRetailerId(retailer.getId()));
|
| 541 |
CustomRetailer customRetailer = new CustomRetailer();
|
710 |
CustomRetailer customRetailer = new CustomRetailer();
|
| 542 |
customRetailer.setBusinessName(retailer.getName());
|
711 |
customRetailer.setBusinessName(retailer.getName());
|
| 543 |
customRetailer.setMobileNumber(user.getMobileNumber());
|
712 |
customRetailer.setMobileNumber(user.getMobileNumber());
|
| 544 |
customRetailer.setTinNumber(retailer.getNumber());
|
713 |
customRetailer.setTinNumber(retailer.getNumber());
|
| 545 |
Address retailerAddress = addressRepository.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId()));
|
714 |
Address retailerAddress = addressRepository.selectById(retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailer.getId()));
|
| 546 |
customRetailer.setAddress(this.createCustomAddress(retailerAddress));
|
715 |
customRetailer.setAddress(this.createCustomAddress(retailerAddress));
|
| 547 |
pdfModel.setRetailer(customRetailer);
|
716 |
pdfModel.setRetailer(customRetailer);
|
| 548 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
|
717 |
List<FofoLineItem> fofoLineItems = fofoLineItemRepository.selectByOrderId(fofoOrder.getId());
|
| 549 |
|
718 |
|
| 550 |
Set<CustomFofoOrderItem> customerFofoOrderItems = new HashSet<>();
|
719 |
Set<CustomFofoOrderItem> customerFofoOrderItems = new HashSet<>();
|
| 551 |
for(FofoLineItem fofoLineItem : fofoLineItems){
|
720 |
for(FofoLineItem fofoLineItem : fofoLineItems){
|
| 552 |
CustomFofoOrderItem customFofoOrderItem = new CustomFofoOrderItem();
|
721 |
CustomFofoOrderItem customFofoOrderItem = new CustomFofoOrderItem();
|
| 553 |
customFofoOrderItem.setAmount(fofoLineItem.getQuantity() * fofoLineItem.getSellingPrice());
|
722 |
customFofoOrderItem.setAmount(fofoLineItem.getQuantity() * fofoLineItem.getSellingPrice());
|
| 554 |
customFofoOrderItem.setDescription(fofoLineItem.getBrand() + " " + fofoLineItem.getModelName() + " " + fofoLineItem.getModelNumber() + " " + fofoLineItem.getColor());
|
723 |
customFofoOrderItem.setDescription(fofoLineItem.getBrand() + " " + fofoLineItem.getModelName() + " " + fofoLineItem.getModelNumber() + " " + fofoLineItem.getColor());
|
| 555 |
float totalTaxRate = fofoLineItem.getIgstRate() + fofoLineItem.getSgstRate() + fofoLineItem.getCgstRate();
|
- |
|
| 556 |
float taxableAmount = customFofoOrderItem.getAmount() / (1 + (totalTaxRate / 100));
|
- |
|
| 557 |
//float itemTotal = customFofoOrderItem.getAmount() + taxableAmount;
|
724 |
float itemTotal = customFofoOrderItem.getAmount();
|
| 558 |
//LOGGER.info("totalTaxRate ={}, taxableAmount ={}, itemTotal ={}", totalTaxRate, taxableAmount, itemTotal);
|
- |
|
| 559 |
customFofoOrderItem.setRate(fofoLineItem.getSellingPrice());
|
725 |
customFofoOrderItem.setRate(fofoLineItem.getSellingPrice());
|
| 560 |
customFofoOrderItem.setQuantity(fofoLineItem.getQuantity());
|
726 |
customFofoOrderItem.setQuantity(fofoLineItem.getQuantity());
|
| 561 |
float igstAmount = (taxableAmount * fofoLineItem.getIgstRate()) / 100;
|
- |
|
| 562 |
float cgstAmount = (taxableAmount * fofoLineItem.getCgstRate()) / 100;
|
- |
|
| 563 |
float sgstAmount = (taxableAmount * fofoLineItem.getSgstRate()) / 100;
|
- |
|
| 564 |
LOGGER.info("igst [{},{}], cgst [{},{}], sgst[{},{}]", fofoLineItem.getIgstRate(), igstAmount, fofoLineItem.getCgstRate(), cgstAmount, fofoLineItem.getSgstRate(), sgstAmount);
|
- |
|
| 565 |
customFofoOrderItem.setIgstRate(fofoLineItem.getIgstRate());
|
727 |
customFofoOrderItem.setIgstRate(fofoLineItem.getIgstRate());
|
| 566 |
customFofoOrderItem.setIgstAmount(igstAmount);
|
- |
|
| 567 |
customFofoOrderItem.setCgstRate(fofoLineItem.getCgstRate());
|
728 |
customFofoOrderItem.setCgstRate(fofoLineItem.getIgstRate());
|
| 568 |
customFofoOrderItem.setCgstAmount(cgstAmount);
|
- |
|
| 569 |
customFofoOrderItem.setSgstRate(fofoLineItem.getSgstRate());
|
729 |
customFofoOrderItem.setSgstRate(fofoLineItem.getIgstRate());
|
| 570 |
customFofoOrderItem.setSgstAmount(sgstAmount);
|
- |
|
| 571 |
customFofoOrderItem.setHsnCode(fofoLineItem.getHsnCode());
|
730 |
customFofoOrderItem.setHsnCode(fofoLineItem.getHsnCode());
|
| 572 |
customFofoOrderItem.setItemTotal(customFofoOrderItem.getAmount() + igstAmount + cgstAmount + sgstAmount);
|
731 |
customFofoOrderItem.setItemTotal(itemTotal);
|
| 573 |
customFofoOrderItem.setSerialNumbers(String.join(", ",this.toSerialNumbers(fofoLineItem.getFofoLineItemSerialNumbers())));
|
732 |
customFofoOrderItem.setSerialNumbers(String.join(", ",this.toSerialNumbers(fofoLineItem.getFofoLineItemSerialNumbers())));
|
| 574 |
customerFofoOrderItems.add(customFofoOrderItem);
|
733 |
customerFofoOrderItems.add(customFofoOrderItem);
|
| 575 |
//pdfModel.setTotalAmount(pdfModel.getTotalAmount() + customFofoOrderItem.getItemTotal());
|
- |
|
| 576 |
}
|
734 |
}
|
| 577 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
735 |
pdfModel.setOrderItems(customerFofoOrderItems);
|
| 578 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
736 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 579 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
737 |
PdfUtils.generateAndWrite(pdfModel, byteArrayOutputStream);
|
| 580 |
//final MediaType mediaType=MediaType.parseMediaType(profilePhotoModel.getContentType().getValue());
|
738 |
//final MediaType mediaType=MediaType.parseMediaType(profilePhotoModel.getContentType().getValue());
|
| 581 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
739 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
| 582 |
final HttpHeaders headers=new HttpHeaders();
|
740 |
final HttpHeaders headers=new HttpHeaders();
|
| 583 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
741 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
| 584 |
headers.set("Content-Disposition", "Order-"+orderId);
|
742 |
//headers.set("Content-Disposition", "Order-pdf-"+custom);
|
| 585 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
743 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
| 586 |
final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
744 |
final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
| 587 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
745 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
| 588 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
746 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 589 |
}
|
747 |
}
|
| 590 |
|
748 |
|
| 591 |
private Set<String> toSerialNumbers(Set<FofoLineItemSerialNumber> fofoLineItemSerialNumbers){
|
749 |
private Set<String> toSerialNumbers(Set<FofoLineItemSerialNumber> fofoLineItemSerialNumbers){
|
| 592 |
Set<String> serialNumbers = new HashSet<>(fofoLineItemSerialNumbers.size());
|
750 |
Set<String> serialNumbers = new HashSet<>(fofoLineItemSerialNumbers.size());
|
| 593 |
for(FofoLineItemSerialNumber fofoLineItemSerialNumber : fofoLineItemSerialNumbers){
|
751 |
for(FofoLineItemSerialNumber fofoLineItemSerialNumber : fofoLineItemSerialNumbers){
|
| 594 |
serialNumbers.add(fofoLineItemSerialNumber.getSerialNumber());
|
752 |
serialNumbers.add(fofoLineItemSerialNumber.getSerialNumber());
|
| 595 |
}
|
753 |
}
|
| 596 |
return serialNumbers;
|
754 |
return serialNumbers;
|
| 597 |
}
|
755 |
}
|
| 598 |
|
756 |
|
| 599 |
|
757 |
|
| 600 |
}
|
758 |
}
|