| 21577 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 21654 |
ashik.ali |
3 |
import java.time.LocalDateTime;
|
| 21987 |
kshitij.so |
4 |
import java.util.ArrayList;
|
| 21654 |
ashik.ali |
5 |
import java.util.HashMap;
|
| 21612 |
ashik.ali |
6 |
import java.util.HashSet;
|
| 21987 |
kshitij.so |
7 |
import java.util.Iterator;
|
| 21577 |
ashik.ali |
8 |
import java.util.List;
|
| 21654 |
ashik.ali |
9 |
import java.util.Map;
|
| 21612 |
ashik.ali |
10 |
import java.util.Set;
|
| 21577 |
ashik.ali |
11 |
|
|
|
12 |
import javax.servlet.http.HttpServletRequest;
|
| 21987 |
kshitij.so |
13 |
import javax.servlet.http.HttpServletResponse;
|
| 21577 |
ashik.ali |
14 |
|
| 21987 |
kshitij.so |
15 |
import org.json.JSONObject;
|
| 21577 |
ashik.ali |
16 |
import org.slf4j.Logger;
|
|
|
17 |
import org.slf4j.LoggerFactory;
|
|
|
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21987 |
kshitij.so |
19 |
import org.springframework.beans.factory.annotation.Value;
|
| 21577 |
ashik.ali |
20 |
import org.springframework.stereotype.Controller;
|
| 21654 |
ashik.ali |
21 |
import org.springframework.transaction.annotation.Transactional;
|
| 21577 |
ashik.ali |
22 |
import org.springframework.ui.Model;
|
|
|
23 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
24 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
25 |
|
| 21987 |
kshitij.so |
26 |
import com.google.gson.Gson;
|
| 21577 |
ashik.ali |
27 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21987 |
kshitij.so |
28 |
import com.spice.profitmandi.common.model.CartFofo;
|
| 21612 |
ashik.ali |
29 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 21577 |
ashik.ali |
30 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21654 |
ashik.ali |
31 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 21987 |
kshitij.so |
32 |
import com.spice.profitmandi.common.util.Utils;
|
| 21728 |
ashik.ali |
33 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 21987 |
kshitij.so |
34 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
| 21728 |
ashik.ali |
35 |
import com.spice.profitmandi.dao.entity.fofo.FofoItemId;
|
|
|
36 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
|
|
37 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
|
|
38 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
|
|
39 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
|
|
40 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
|
|
41 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
|
|
42 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
|
|
43 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
|
|
44 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 22139 |
amit.gupta |
45 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 21987 |
kshitij.so |
46 |
import com.spice.profitmandi.web.response.ValidateCart;
|
| 22069 |
ashik.ali |
47 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 21577 |
ashik.ali |
48 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
49 |
|
|
|
50 |
@Controller
|
| 22037 |
amit.gupta |
51 |
@Transactional(rollbackFor=Throwable.class)
|
| 21577 |
ashik.ali |
52 |
public class InventoryController {
|
| 21987 |
kshitij.so |
53 |
|
| 21577 |
ashik.ali |
54 |
private static final Logger LOGGER = LoggerFactory.getLogger(InventoryController.class);
|
| 21987 |
kshitij.so |
55 |
|
| 21577 |
ashik.ali |
56 |
@Autowired
|
|
|
57 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 21987 |
kshitij.so |
58 |
|
| 21577 |
ashik.ali |
59 |
@Autowired
|
| 21636 |
ashik.ali |
60 |
InventoryItemRepository inventoryItemRepository;
|
| 21987 |
kshitij.so |
61 |
|
| 21636 |
ashik.ali |
62 |
@Autowired
|
| 21654 |
ashik.ali |
63 |
PurchaseRepository purchaseRepository;
|
| 21987 |
kshitij.so |
64 |
|
| 21654 |
ashik.ali |
65 |
@Autowired
|
|
|
66 |
ItemRepository itemRepository;
|
| 21987 |
kshitij.so |
67 |
|
| 21654 |
ashik.ali |
68 |
@Autowired
|
|
|
69 |
OrderRepository orderRepository;
|
| 21987 |
kshitij.so |
70 |
|
| 21654 |
ashik.ali |
71 |
@Autowired
|
| 21577 |
ashik.ali |
72 |
MVCResponseSender mvcResponseSender;
|
| 21987 |
kshitij.so |
73 |
|
| 21577 |
ashik.ali |
74 |
@Autowired
|
| 22069 |
ashik.ali |
75 |
CookiesProcessor cookiesProcessor;
|
| 21577 |
ashik.ali |
76 |
|
| 21987 |
kshitij.so |
77 |
@Value("${saholic.api.host}")
|
|
|
78 |
private String host;
|
|
|
79 |
@Value("${saholic.api.port}")
|
|
|
80 |
private int port;
|
|
|
81 |
@Value("${saholic.api.webapp}")
|
|
|
82 |
private String webapp;
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
@RequestMapping(value = "/getCurrentInventorySnapshot")
|
|
|
86 |
public String getCurrentAvailability(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit , @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm ,Model model) throws Exception{
|
| 22139 |
amit.gupta |
87 |
LoginDetails fofoDetails;
|
| 21577 |
ashik.ali |
88 |
try {
|
| 22069 |
ashik.ali |
89 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21577 |
ashik.ali |
90 |
} catch (ProfitMandiBusinessException e) {
|
| 21581 |
ashik.ali |
91 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
92 |
return "response";
|
| 21577 |
ashik.ali |
93 |
}
|
| 21987 |
kshitij.so |
94 |
List<CurrentInventorySnapshot> currentInventorySnapshot = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
95 |
long countItems = currentInventorySnapshotRepository.getCurrentInventorySnapshotCount(fofoDetails.getFofoId(), searchTerm);
|
|
|
96 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshot);
|
|
|
97 |
model.addAttribute("start",offset+1);
|
|
|
98 |
model.addAttribute("size",countItems);
|
|
|
99 |
model.addAttribute("searchTerm",searchTerm);
|
|
|
100 |
if (currentInventorySnapshot.size() < limit){
|
|
|
101 |
model.addAttribute("end",offset+currentInventorySnapshot.size());
|
|
|
102 |
}
|
|
|
103 |
else{
|
|
|
104 |
model.addAttribute("end",offset+limit);
|
|
|
105 |
}
|
|
|
106 |
return "inventory-snapshot";
|
| 21612 |
ashik.ali |
107 |
}
|
| 21987 |
kshitij.so |
108 |
|
|
|
109 |
@RequestMapping(value = "/getBadInventorySnapshot")
|
|
|
110 |
public String getBadAvailability(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit , @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm ,Model model) throws Exception{
|
| 22139 |
amit.gupta |
111 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
112 |
try {
|
| 22069 |
ashik.ali |
113 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
114 |
} catch (ProfitMandiBusinessException e) {
|
|
|
115 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
116 |
return "response";
|
|
|
117 |
}
|
|
|
118 |
model.addAttribute("badInventorySnapshot",new ArrayList<>());
|
|
|
119 |
model.addAttribute("searchTerm",searchTerm);
|
|
|
120 |
return "bad-inventory-snapshot";
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
@RequestMapping(value = "/getPaginatedCurrentInventorySnapshot")
|
|
|
124 |
public String getCurrentAvailabilityPaginated(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm , Model model) throws Exception{
|
| 22139 |
amit.gupta |
125 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
126 |
try {
|
| 22069 |
ashik.ali |
127 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
128 |
} catch (ProfitMandiBusinessException e) {
|
|
|
129 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
130 |
return "response";
|
|
|
131 |
}
|
|
|
132 |
List<CurrentInventorySnapshot> currentInventorySnapshot = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
133 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshot);
|
|
|
134 |
return "inventory-snapshot-paginated";
|
|
|
135 |
}
|
| 21612 |
ashik.ali |
136 |
|
| 21987 |
kshitij.so |
137 |
@RequestMapping(value = "/getCatalog")
|
|
|
138 |
public String getCatalog(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit , @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm ,Model model) throws Exception{
|
| 22139 |
amit.gupta |
139 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
140 |
try {
|
| 22069 |
ashik.ali |
141 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
142 |
} catch (ProfitMandiBusinessException e) {
|
|
|
143 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
144 |
return "response";
|
|
|
145 |
}
|
|
|
146 |
List<CurrentInventorySnapshot> currentInventorySnapshot = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
147 |
long countItems = currentInventorySnapshotRepository.getCurrentInventorySnapshotCount(fofoDetails.getFofoId(), searchTerm);
|
|
|
148 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshot);
|
|
|
149 |
model.addAttribute("start",offset+1);
|
|
|
150 |
model.addAttribute("size",countItems);
|
|
|
151 |
model.addAttribute("searchTerm",searchTerm);
|
|
|
152 |
if (currentInventorySnapshot.size() < limit){
|
|
|
153 |
model.addAttribute("end",offset+currentInventorySnapshot.size());
|
|
|
154 |
}
|
|
|
155 |
else{
|
|
|
156 |
model.addAttribute("end",offset+limit);
|
|
|
157 |
}
|
|
|
158 |
return "catalog";
|
|
|
159 |
}
|
|
|
160 |
|
|
|
161 |
@RequestMapping(value = "/getPaginatedCatalog")
|
|
|
162 |
public String getCatalogPaginated(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm , Model model) throws Exception{
|
| 22139 |
amit.gupta |
163 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
164 |
try {
|
| 22069 |
ashik.ali |
165 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
166 |
} catch (ProfitMandiBusinessException e) {
|
|
|
167 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
168 |
return "response";
|
|
|
169 |
}
|
|
|
170 |
List<CurrentInventorySnapshot> currentInventorySnapshot = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
171 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshot);
|
|
|
172 |
return "catalog-paginated";
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
|
| 21612 |
ashik.ali |
177 |
private Set<CustomCurrentInventorySnapshot> getCustomCurrentInventorySnapshots(List<Object[]> rows){
|
|
|
178 |
Set<CustomCurrentInventorySnapshot> currentInventorySnapshots = new HashSet<>();
|
|
|
179 |
for(Object[] row : rows){
|
|
|
180 |
currentInventorySnapshots.add(this.createCustomCurrentInventorySnapshop(row));
|
| 21577 |
ashik.ali |
181 |
}
|
| 21612 |
ashik.ali |
182 |
return currentInventorySnapshots;
|
| 21577 |
ashik.ali |
183 |
}
|
|
|
184 |
|
| 21987 |
kshitij.so |
185 |
private String getVaildName(String name){
|
|
|
186 |
return name!=null?name:"";
|
|
|
187 |
}
|
|
|
188 |
|
| 21612 |
ashik.ali |
189 |
private CustomCurrentInventorySnapshot createCustomCurrentInventorySnapshop(Object[] row)
|
|
|
190 |
{
|
|
|
191 |
CustomCurrentInventorySnapshot currentInventorySnapshot = new CustomCurrentInventorySnapshot();
|
|
|
192 |
currentInventorySnapshot.setItemId((Integer)row[0]);
|
|
|
193 |
currentInventorySnapshot.setAvailability((Integer)row[1]);
|
|
|
194 |
currentInventorySnapshot.setBrand((String)row[2]);
|
|
|
195 |
currentInventorySnapshot.setModelName((String)row[3]);
|
|
|
196 |
currentInventorySnapshot.setModelNumber((String)row[4]);
|
|
|
197 |
currentInventorySnapshot.setColor((String)row[5]);
|
| 21987 |
kshitij.so |
198 |
currentInventorySnapshot.setCatalogItemId((Integer)row[6]);
|
|
|
199 |
currentInventorySnapshot.setDisplayName((getVaildName((String)row[2])+" "+getVaildName((String)row[3])+" "+getVaildName((String)row[4])+" "+getVaildName((String)row[5])).replaceAll("\\s+", " "));
|
|
|
200 |
currentInventorySnapshot.setIconUrl(Utils.getIconUrl(currentInventorySnapshot.getCatalogItemId(), host, port, webapp));
|
| 21612 |
ashik.ali |
201 |
return currentInventorySnapshot;
|
|
|
202 |
}
|
| 21577 |
ashik.ali |
203 |
@RequestMapping(value = "/checkItemAvailability")
|
| 21987 |
kshitij.so |
204 |
public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model) throws Exception{
|
| 22139 |
amit.gupta |
205 |
LoginDetails fofoDetails;
|
| 21577 |
ashik.ali |
206 |
try {
|
| 22069 |
ashik.ali |
207 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21577 |
ashik.ali |
208 |
} catch (ProfitMandiBusinessException e) {
|
| 21581 |
ashik.ali |
209 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
210 |
return "response";
|
| 21577 |
ashik.ali |
211 |
}
|
|
|
212 |
try{
|
|
|
213 |
FofoItemId fofoItemId = new FofoItemId();
|
|
|
214 |
fofoItemId.setFofoId(fofoDetails.getFofoId());
|
|
|
215 |
fofoItemId.setItemId(itemId);
|
| 21612 |
ashik.ali |
216 |
Object[] row = currentInventorySnapshotRepository.selectCustomByFofoItemId(fofoItemId);
|
| 21987 |
kshitij.so |
217 |
model.addAttribute("currentInventorySnapshot", new Gson().toJson(this.createCustomCurrentInventorySnapshop(row)));
|
|
|
218 |
return "current-item-availability";
|
| 21577 |
ashik.ali |
219 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 21581 |
ashik.ali |
220 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
|
|
|
221 |
return "response";
|
| 21577 |
ashik.ali |
222 |
}
|
|
|
223 |
}
|
|
|
224 |
|
| 21987 |
kshitij.so |
225 |
@RequestMapping(value = "/cart")
|
|
|
226 |
public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
| 22139 |
amit.gupta |
227 |
LoginDetails fofoDetails;
|
| 21654 |
ashik.ali |
228 |
try {
|
| 22069 |
ashik.ali |
229 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21654 |
ashik.ali |
230 |
} catch (ProfitMandiBusinessException e) {
|
|
|
231 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
232 |
return "response";
|
| 21636 |
ashik.ali |
233 |
}
|
| 21657 |
ashik.ali |
234 |
|
| 21987 |
kshitij.so |
235 |
JSONObject cartObject = new JSONObject(cartData);
|
|
|
236 |
Iterator<?> keys = cartObject.keys();
|
|
|
237 |
|
|
|
238 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
239 |
List<CartFofo> cartItems = new ArrayList<CartFofo>();
|
|
|
240 |
|
|
|
241 |
while( keys.hasNext() ) {
|
|
|
242 |
String key = (String)keys.next();
|
|
|
243 |
if ( cartObject.get(key) instanceof JSONObject ) {
|
|
|
244 |
System.out.println(cartObject.get(key));
|
|
|
245 |
}
|
|
|
246 |
CartFofo cf = new CartFofo();
|
|
|
247 |
cf.setItemId(cartObject.getJSONObject(key).getInt("itemId"));
|
|
|
248 |
cf.setQuantity(cartObject.getJSONObject(key).getInt("quantity"));
|
|
|
249 |
cf.setDisplayName(cartObject.getJSONObject(key).getString("displayName"));
|
|
|
250 |
cf.setIconUrl(cartObject.getJSONObject(key).getString("iconUrl"));
|
|
|
251 |
cf.setAvailability(0);
|
|
|
252 |
cartItems.add(cf);
|
|
|
253 |
itemIds.add(cartObject.getJSONObject(key).getInt("itemId"));
|
|
|
254 |
}
|
|
|
255 |
if (itemIds.size() > 0){
|
|
|
256 |
List<CurrentInventorySnapshot> cisList = currentInventorySnapshotRepository.selectByFofoItemIds(fofoDetails.getFofoId(), itemIds);
|
|
|
257 |
for (CurrentInventorySnapshot cis: cisList ){
|
|
|
258 |
for (CartFofo cartItem : cartItems){
|
|
|
259 |
if (cartItem.getItemId() == cis.getItem().getId()){
|
|
|
260 |
cartItem.setAvailability(cis.getAvailability());
|
|
|
261 |
}
|
|
|
262 |
}
|
|
|
263 |
}
|
|
|
264 |
for (CartFofo cartItem : cartItems){
|
|
|
265 |
if (cartItem.getAvailability() < cartItem.getQuantity() && cartItem.getAvailability()!=0){
|
|
|
266 |
cartItem.setQuantity(cartItem.getAvailability());
|
|
|
267 |
cartItem.setMessage("Item quantity changed.Less stock available");
|
|
|
268 |
}
|
|
|
269 |
if (cartItem.getAvailability() == 0){
|
|
|
270 |
cartItem.setQuantity(0);
|
|
|
271 |
cartItem.setMessage("You don't have stock for this item");
|
|
|
272 |
}
|
|
|
273 |
}
|
|
|
274 |
}
|
|
|
275 |
model.addAttribute("cartObj", cartItems);
|
|
|
276 |
return "cart";
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
@RequestMapping(value = "/validate-cart")
|
|
|
280 |
public String validateCart(HttpServletRequest request, HttpServletResponse response,@RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
| 22139 |
amit.gupta |
281 |
LoginDetails fofoDetails = null;
|
| 21987 |
kshitij.so |
282 |
try {
|
| 22069 |
ashik.ali |
283 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
284 |
} catch (ProfitMandiBusinessException e) {
|
|
|
285 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
286 |
return "response";
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
JSONObject cartObject = new JSONObject(cartData);
|
|
|
290 |
Iterator<?> keys = cartObject.keys();
|
|
|
291 |
|
|
|
292 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
293 |
List<CartFofo> cartItems = new ArrayList<CartFofo>();
|
|
|
294 |
|
|
|
295 |
if (cartObject.keySet().size() == 0){
|
|
|
296 |
model.addAttribute("validateCartResponse",new Gson().toJson(new ValidateCart("POST", "/cart", false, cartData)));
|
|
|
297 |
return "validate-cart";
|
|
|
298 |
}
|
|
|
299 |
|
|
|
300 |
while( keys.hasNext() ) {
|
|
|
301 |
String key = (String)keys.next();
|
|
|
302 |
if ( cartObject.get(key) instanceof JSONObject ) {
|
|
|
303 |
System.out.println(cartObject.get(key));
|
|
|
304 |
}
|
|
|
305 |
CartFofo cf = new CartFofo();
|
|
|
306 |
cf.setItemId(cartObject.getJSONObject(key).getInt("itemId"));
|
|
|
307 |
cf.setQuantity(cartObject.getJSONObject(key).getInt("quantity"));
|
|
|
308 |
cf.setDisplayName(cartObject.getJSONObject(key).getString("displayName"));
|
|
|
309 |
cf.setIconUrl(cartObject.getJSONObject(key).getString("iconUrl"));
|
|
|
310 |
cf.setAvailability(0);
|
|
|
311 |
cartItems.add(cf);
|
|
|
312 |
itemIds.add(cartObject.getJSONObject(key).getInt("itemId"));
|
|
|
313 |
}
|
|
|
314 |
if (itemIds.size() > 0){
|
|
|
315 |
List<CurrentInventorySnapshot> cisList = currentInventorySnapshotRepository.selectByFofoItemIds(fofoDetails.getFofoId(), itemIds);
|
|
|
316 |
for (CurrentInventorySnapshot cis: cisList ){
|
|
|
317 |
for (CartFofo cartItem : cartItems){
|
|
|
318 |
if (cartItem.getItemId() == cis.getItem().getId()){
|
|
|
319 |
cartItem.setAvailability(cis.getAvailability());
|
|
|
320 |
}
|
|
|
321 |
}
|
|
|
322 |
}
|
|
|
323 |
for (CartFofo cartItem : cartItems){
|
|
|
324 |
if (cartItem.getAvailability() < cartItem.getQuantity()){
|
|
|
325 |
model.addAttribute("validateCartResponse",new Gson().toJson(new ValidateCart("POST", "/cart", false, cartData)));
|
|
|
326 |
return "validate-cart";
|
|
|
327 |
}
|
|
|
328 |
}
|
|
|
329 |
}
|
|
|
330 |
else{
|
|
|
331 |
model.addAttribute("validateCartResponse",new Gson().toJson(new ValidateCart("POST", "/cart", false, cartData)));
|
|
|
332 |
return "validate-cart";
|
|
|
333 |
}
|
|
|
334 |
model.addAttribute("validateCartResponse",new Gson().toJson(new ValidateCart("POST", "/order", true, cartData)));
|
|
|
335 |
return "validate-cart";
|
|
|
336 |
}
|
|
|
337 |
|
|
|
338 |
@RequestMapping(value = "/grnHistory")
|
|
|
339 |
public String grnHistoryByFofoId(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE,defaultValue="") String purchaseReference, @RequestParam(name = "searchType",defaultValue="") String searchType,Model model) throws Exception{
|
| 22139 |
amit.gupta |
340 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
341 |
try {
|
| 22069 |
ashik.ali |
342 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
343 |
} catch (ProfitMandiBusinessException e) {
|
|
|
344 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
345 |
return "response";
|
|
|
346 |
}
|
|
|
347 |
|
| 21654 |
ashik.ali |
348 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
349 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
|
|
350 |
|
| 21987 |
kshitij.so |
351 |
List<Purchase> grnHistory = new ArrayList<Purchase>();
|
|
|
352 |
long countItems = 0;
|
|
|
353 |
if (searchType.equalsIgnoreCase("purchaseReference") && purchaseReference.trim().length() > 0){
|
|
|
354 |
try{
|
|
|
355 |
Purchase purchase = purchaseRepository.selectByPurchaseReference(purchaseReference);
|
|
|
356 |
grnHistory.add(purchase);
|
|
|
357 |
countItems = 1;
|
|
|
358 |
}
|
|
|
359 |
catch(Exception | ProfitMandiBusinessException e){
|
|
|
360 |
LOGGER.info("Unable to get purchase reference "+purchaseReference);
|
|
|
361 |
}
|
|
|
362 |
}
|
|
|
363 |
else{
|
|
|
364 |
grnHistory = purchaseRepository.selectByFofoId(fofoDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
|
|
|
365 |
countItems = purchaseRepository.getPurchaseCount(fofoDetails.getFofoId(), startDateTime, endDateTime, purchaseReference, searchType);
|
|
|
366 |
}
|
|
|
367 |
model.addAttribute("grnHistories", grnHistory);
|
|
|
368 |
model.addAttribute("start",offset+1);
|
|
|
369 |
model.addAttribute("size",countItems);
|
|
|
370 |
model.addAttribute("searchType",searchType);
|
|
|
371 |
model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
|
|
|
372 |
model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
|
|
|
373 |
if (grnHistory.size() < limit){
|
|
|
374 |
model.addAttribute("end",offset+grnHistory.size());
|
|
|
375 |
}
|
|
|
376 |
else{
|
|
|
377 |
model.addAttribute("end",offset+limit);
|
|
|
378 |
}
|
|
|
379 |
return "grn-history";
|
| 21636 |
ashik.ali |
380 |
}
|
| 21987 |
kshitij.so |
381 |
|
|
|
382 |
@RequestMapping(value = "/getPaginatedGrnHistory")
|
|
|
383 |
public String getGrnHistoryPaginated(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE,defaultValue="") String purchaseReference, @RequestParam(name = "searchType",defaultValue="") String searchType,Model model) throws Exception{
|
| 22139 |
amit.gupta |
384 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
385 |
try {
|
| 22069 |
ashik.ali |
386 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
387 |
} catch (ProfitMandiBusinessException e) {
|
|
|
388 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
389 |
return "response";
|
|
|
390 |
}
|
|
|
391 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
392 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
|
|
393 |
|
|
|
394 |
List<Purchase> grnHistory = purchaseRepository.selectByFofoId(fofoDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
|
|
|
395 |
model.addAttribute("grnHistories", grnHistory);
|
|
|
396 |
return "grn-history-paginated";
|
|
|
397 |
}
|
|
|
398 |
|
| 21654 |
ashik.ali |
399 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
|
|
|
400 |
public String grnHistoryByPurchaseId(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model) throws Exception{
|
| 22139 |
amit.gupta |
401 |
LoginDetails fofoDetails;
|
| 21636 |
ashik.ali |
402 |
try {
|
| 22069 |
ashik.ali |
403 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21636 |
ashik.ali |
404 |
} catch (ProfitMandiBusinessException e) {
|
|
|
405 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
406 |
return "response";
|
|
|
407 |
}
|
| 21654 |
ashik.ali |
408 |
Purchase purchase = null;
|
|
|
409 |
try {
|
|
|
410 |
purchase = purchaseRepository.selectById(purchaseId);
|
|
|
411 |
} catch (ProfitMandiBusinessException e) {
|
| 21987 |
kshitij.so |
412 |
|
| 21654 |
ashik.ali |
413 |
}
|
| 21987 |
kshitij.so |
414 |
model.addAttribute("grnDetails", this.grnHistoryDetails(purchase, fofoDetails.getFofoId()));
|
|
|
415 |
model.addAttribute("purchaseId",purchase.getId());
|
|
|
416 |
model.addAttribute("purchaseReference",purchase.getPurchaseReference());
|
|
|
417 |
return "grn-details";
|
| 21636 |
ashik.ali |
418 |
}
|
| 21987 |
kshitij.so |
419 |
|
| 21654 |
ashik.ali |
420 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
|
|
|
421 |
public String grnHistoryByPurchaseReference(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model) throws Exception{
|
| 22139 |
amit.gupta |
422 |
LoginDetails fofoDetails;
|
| 21654 |
ashik.ali |
423 |
try {
|
| 22069 |
ashik.ali |
424 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21654 |
ashik.ali |
425 |
} catch (ProfitMandiBusinessException e) {
|
|
|
426 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
427 |
return "response";
|
|
|
428 |
}
|
|
|
429 |
Purchase purchase = null;
|
|
|
430 |
try {
|
|
|
431 |
purchase = purchaseRepository.selectByPurchaseReference(purchaseReference);
|
|
|
432 |
} catch (ProfitMandiBusinessException e) {
|
| 21987 |
kshitij.so |
433 |
|
| 21654 |
ashik.ali |
434 |
}
|
| 21987 |
kshitij.so |
435 |
model.addAttribute("grnDetails", this.grnHistoryDetails(purchase, fofoDetails.getFofoId()));
|
|
|
436 |
model.addAttribute("purchaseId",purchase.getId());
|
|
|
437 |
model.addAttribute("purchaseReference",purchase.getPurchaseReference());
|
|
|
438 |
return "grn-details";
|
| 21654 |
ashik.ali |
439 |
}
|
| 21987 |
kshitij.so |
440 |
|
| 21654 |
ashik.ali |
441 |
private Map<Integer, Map<String, Object>> grnHistoryDetails(Purchase purchase, int fofoId){
|
|
|
442 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
443 |
Set<Item> inventoryItemDetails = new HashSet<>();
|
|
|
444 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchase.getId());
|
|
|
445 |
for(InventoryItem inventoryItem : inventoryItems){
|
|
|
446 |
inventoryItemDetails.add(inventoryItem.getItem());
|
|
|
447 |
itemIds.add(inventoryItem.getItemId());
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
Map<Integer, Map<String, Object>> grnHistoryDetails = new HashMap<>();
|
|
|
451 |
this.createGrnHistoryDetails(grnHistoryDetails, inventoryItems);
|
| 21987 |
kshitij.so |
452 |
Map<Integer, Map<String, Object>> completedItemDetails = this.toMap(inventoryItemDetails, purchase);
|
|
|
453 |
|
| 21654 |
ashik.ali |
454 |
this.writeItemDetailstoGrnHistories(grnHistoryDetails, completedItemDetails);
|
| 21987 |
kshitij.so |
455 |
|
| 21654 |
ashik.ali |
456 |
if(!purchase.isCompleted()){
|
| 21680 |
ashik.ali |
457 |
List<Order> orders = orderRepository.selectByInvoiceNumberRetailerIdNotItemIds(purchase.getPurchaseReference(), fofoId, itemIds);
|
| 21654 |
ashik.ali |
458 |
for(Order order : orders){
|
|
|
459 |
LineItem lineItem = order.getLineItem();
|
|
|
460 |
//orderItemDetails.add(lineItem.getItem());
|
|
|
461 |
Item item = lineItem.getItem();
|
|
|
462 |
if(!grnHistoryDetails.containsKey(item.getId())){
|
|
|
463 |
Map<String, Object> grnHistoryDetail = new HashMap<>();
|
|
|
464 |
grnHistoryDetail.put(ProfitMandiConstants.QUANTITY, lineItem.getQuantity());
|
|
|
465 |
grnHistoryDetail.put(ProfitMandiConstants.BRAND, item.getBrand());
|
|
|
466 |
grnHistoryDetail.put(ProfitMandiConstants.MODEL_NAME, item.getModelName());
|
|
|
467 |
grnHistoryDetail.put(ProfitMandiConstants.MODEL_NUMBER, item.getModelNumber());
|
|
|
468 |
grnHistoryDetail.put(ProfitMandiConstants.COLOR, item.getColor());
|
| 21987 |
kshitij.so |
469 |
grnHistoryDetail.put(ProfitMandiConstants.CATALOG_ITEM_ID, item.getCatalogItemId());
|
|
|
470 |
grnHistoryDetail.put("iconUrl",Utils.getIconUrl(item.getCatalogItemId(), host, port, webapp));
|
| 21654 |
ashik.ali |
471 |
grnHistoryDetail.put(ProfitMandiConstants.COMPLETED, false);
|
| 21987 |
kshitij.so |
472 |
grnHistoryDetail.put("purchaseReference", purchase.getPurchaseReference());
|
| 21654 |
ashik.ali |
473 |
if(lineItem.getSerialNumber() == null || lineItem.getSerialNumber().equals("")){
|
|
|
474 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, false);
|
|
|
475 |
}else{
|
|
|
476 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, true);
|
|
|
477 |
Set<String> serialNumbers = new HashSet<>();
|
|
|
478 |
serialNumbers.add(lineItem.getSerialNumber());
|
|
|
479 |
grnHistoryDetail.put(ProfitMandiConstants.SERIAL_NUMBERS, serialNumbers);
|
|
|
480 |
}
|
|
|
481 |
grnHistoryDetails.put(item.getId(), grnHistoryDetail);
|
|
|
482 |
}else{
|
|
|
483 |
Map<String, Object> grnHistoryDetail = grnHistoryDetails.get(item.getId());
|
|
|
484 |
if((boolean)grnHistoryDetail.get(ProfitMandiConstants.SERIALIZED)){
|
|
|
485 |
@SuppressWarnings("unchecked")
|
|
|
486 |
Set<String> serialNumbers = (Set<String>)grnHistoryDetail.get(ProfitMandiConstants.SERIAL_NUMBERS);
|
| 21987 |
kshitij.so |
487 |
serialNumbers.add(lineItem.getSerialNumber());
|
| 21654 |
ashik.ali |
488 |
}
|
|
|
489 |
}
|
|
|
490 |
}
|
|
|
491 |
}
|
|
|
492 |
return grnHistoryDetails;
|
|
|
493 |
}
|
| 21987 |
kshitij.so |
494 |
|
| 21654 |
ashik.ali |
495 |
private void writeItemDetailstoGrnHistories(Map<Integer, Map<String, Object>> grnHistoryDetails, Map<Integer, Map<String, Object>> itemDetails){
|
|
|
496 |
for(int key : grnHistoryDetails.keySet()){
|
|
|
497 |
Map<String, Object> grnHistoryDetail = grnHistoryDetails.get(key);
|
|
|
498 |
grnHistoryDetail.putAll(itemDetails.get(key));
|
|
|
499 |
}
|
|
|
500 |
}
|
| 21987 |
kshitij.so |
501 |
|
|
|
502 |
private Map<Integer, Map<String, Object>> toMap(Set<Item> items, Purchase purchase){
|
| 21654 |
ashik.ali |
503 |
Map<Integer, Map<String, Object>> map = new HashMap<>();
|
|
|
504 |
for(Item item : items){
|
|
|
505 |
Map<String, Object> detailMap = new HashMap<>();
|
|
|
506 |
detailMap.put(ProfitMandiConstants.BRAND, item.getBrand());
|
|
|
507 |
detailMap.put(ProfitMandiConstants.MODEL_NAME, item.getModelName());
|
|
|
508 |
detailMap.put(ProfitMandiConstants.MODEL_NUMBER, item.getModelNumber());
|
|
|
509 |
detailMap.put(ProfitMandiConstants.COLOR, item.getColor());
|
| 21987 |
kshitij.so |
510 |
detailMap.put(ProfitMandiConstants.CATALOG_ITEM_ID, item.getCatalogItemId());
|
|
|
511 |
detailMap.put("iconUrl",Utils.getIconUrl(item.getCatalogItemId(), host, port, webapp));
|
|
|
512 |
detailMap.put("purchaseReference", purchase.getPurchaseReference());
|
| 21654 |
ashik.ali |
513 |
map.put(item.getId(), detailMap);
|
|
|
514 |
}
|
|
|
515 |
return map;
|
|
|
516 |
}
|
| 21987 |
kshitij.so |
517 |
|
| 21654 |
ashik.ali |
518 |
private void createGrnHistoryDetails(Map<Integer, Map<String, Object>> grnHistoryDetails, List<InventoryItem> inventoryItems){
|
|
|
519 |
//Map<Integer, Map<String, Object>> grnHistoryDetails = new HashMap<>();
|
|
|
520 |
for(InventoryItem inventoryItem : inventoryItems){
|
|
|
521 |
if(!grnHistoryDetails.containsKey(inventoryItem.getItemId())){
|
|
|
522 |
Map<String, Object> grnHistoryDetail = new HashMap<>();
|
|
|
523 |
grnHistoryDetail.put(ProfitMandiConstants.QUANTITY, inventoryItem.getInitialQuantity());
|
|
|
524 |
grnHistoryDetail.put(ProfitMandiConstants.COMPLETED, true);
|
|
|
525 |
if(inventoryItem.getSerialNumber() == null || inventoryItem.getSerialNumber().equals("")){
|
|
|
526 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, false);
|
|
|
527 |
}else{
|
|
|
528 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, true);
|
|
|
529 |
Set<String> serialNumbers = new HashSet<>();
|
|
|
530 |
serialNumbers.add(inventoryItem.getSerialNumber());
|
|
|
531 |
grnHistoryDetail.put(ProfitMandiConstants.SERIAL_NUMBERS, serialNumbers);
|
| 22244 |
ashik.ali |
532 |
grnHistoryDetail.put("formattedSerialNumbers", String.join(", ", serialNumbers));
|
| 21654 |
ashik.ali |
533 |
}
|
|
|
534 |
grnHistoryDetails.put(inventoryItem.getItemId(), grnHistoryDetail);
|
|
|
535 |
//itemIds.add(inventoryItem.getItemId());
|
|
|
536 |
}else{
|
|
|
537 |
Map<String, Object> grnHistoryDetail = grnHistoryDetails.get(inventoryItem.getItemId());
|
|
|
538 |
if((boolean)grnHistoryDetail.get(ProfitMandiConstants.SERIALIZED)){
|
|
|
539 |
@SuppressWarnings("unchecked")
|
|
|
540 |
Set<String> serialNumbers = (Set<String>)grnHistoryDetail.get(ProfitMandiConstants.SERIAL_NUMBERS);
|
|
|
541 |
LOGGER.info("serialNumbers {}", serialNumbers);
|
| 21987 |
kshitij.so |
542 |
serialNumbers.add(inventoryItem.getSerialNumber());
|
| 22244 |
ashik.ali |
543 |
grnHistoryDetail.put("formattedSerialNumbers", String.join(", ", serialNumbers));
|
| 21654 |
ashik.ali |
544 |
grnHistoryDetail.put(ProfitMandiConstants.QUANTITY, (int)grnHistoryDetail.get(ProfitMandiConstants.QUANTITY) + inventoryItem.getInitialQuantity());
|
|
|
545 |
}
|
|
|
546 |
}
|
| 21987 |
kshitij.so |
547 |
|
| 21654 |
ashik.ali |
548 |
}
|
|
|
549 |
//return null;
|
|
|
550 |
}
|
| 21987 |
kshitij.so |
551 |
|
| 21654 |
ashik.ali |
552 |
public List<Item> getItemsByItemIds(Set<Integer> itemIds){
|
|
|
553 |
return null;
|
|
|
554 |
}
|
| 21987 |
kshitij.so |
555 |
|
| 21577 |
ashik.ali |
556 |
}
|