| 21577 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 22486 |
ashik.ali |
3 |
import java.io.ByteArrayInputStream;
|
|
|
4 |
import java.io.ByteArrayOutputStream;
|
|
|
5 |
import java.io.InputStream;
|
| 23886 |
amit.gupta |
6 |
import java.time.LocalDateTime;
|
| 24465 |
tejbeer |
7 |
import java.util.ArrayList;
|
| 24917 |
tejbeer |
8 |
import java.util.HashMap;
|
| 24465 |
tejbeer |
9 |
import java.util.HashSet;
|
| 24917 |
tejbeer |
10 |
import java.util.Iterator;
|
| 21577 |
ashik.ali |
11 |
import java.util.List;
|
| 21654 |
ashik.ali |
12 |
import java.util.Map;
|
| 24917 |
tejbeer |
13 |
import java.util.Optional;
|
| 24465 |
tejbeer |
14 |
import java.util.Set;
|
|
|
15 |
import java.util.stream.Collectors;
|
| 21577 |
ashik.ali |
16 |
|
|
|
17 |
import javax.servlet.http.HttpServletRequest;
|
| 21987 |
kshitij.so |
18 |
import javax.servlet.http.HttpServletResponse;
|
| 21577 |
ashik.ali |
19 |
|
| 23886 |
amit.gupta |
20 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
21 |
import org.apache.logging.log4j.Logger;
|
| 24739 |
tejbeer |
22 |
import org.apache.thrift.TException;
|
| 24465 |
tejbeer |
23 |
import org.json.JSONObject;
|
| 21577 |
ashik.ali |
24 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23784 |
ashik.ali |
25 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 21987 |
kshitij.so |
26 |
import org.springframework.beans.factory.annotation.Value;
|
| 22486 |
ashik.ali |
27 |
import org.springframework.core.io.InputStreamResource;
|
|
|
28 |
import org.springframework.http.HttpHeaders;
|
|
|
29 |
import org.springframework.http.HttpStatus;
|
| 25140 |
amit.gupta |
30 |
import org.springframework.http.MediaType;
|
| 22472 |
ashik.ali |
31 |
import org.springframework.http.ResponseEntity;
|
| 24917 |
tejbeer |
32 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 21577 |
ashik.ali |
33 |
import org.springframework.stereotype.Controller;
|
| 21654 |
ashik.ali |
34 |
import org.springframework.transaction.annotation.Transactional;
|
| 21577 |
ashik.ali |
35 |
import org.springframework.ui.Model;
|
| 22472 |
ashik.ali |
36 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21577 |
ashik.ali |
37 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 22472 |
ashik.ali |
38 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21577 |
ashik.ali |
39 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
40 |
|
| 21987 |
kshitij.so |
41 |
import com.google.gson.Gson;
|
| 25698 |
tejbeer |
42 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 21577 |
ashik.ali |
43 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21612 |
ashik.ali |
44 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 24106 |
tejbeer |
45 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 22472 |
ashik.ali |
46 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
| 24106 |
tejbeer |
47 |
import com.spice.profitmandi.common.model.ItemFeatureDataModel;
|
| 24917 |
tejbeer |
48 |
import com.spice.profitmandi.common.model.NotifyItemIdModel;
|
|
|
49 |
import com.spice.profitmandi.common.model.NotifyOrderIdModel;
|
|
|
50 |
import com.spice.profitmandi.common.model.NotifyOrderModel;
|
| 25640 |
tejbeer |
51 |
import com.spice.profitmandi.common.model.OrderCancellationModel;
|
| 25140 |
amit.gupta |
52 |
import com.spice.profitmandi.common.model.PdfModel;
|
| 21577 |
ashik.ali |
53 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 25851 |
amit.gupta |
54 |
import com.spice.profitmandi.common.model.SendNotificationModel;
|
| 22472 |
ashik.ali |
55 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 25140 |
amit.gupta |
56 |
import com.spice.profitmandi.common.util.PdfUtils;
|
| 24123 |
tejbeer |
57 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 24950 |
tejbeer |
58 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 24106 |
tejbeer |
59 |
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
|
| 25371 |
tejbeer |
60 |
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
|
|
|
61 |
import com.spice.profitmandi.dao.entity.dtr.PushNotifications;
|
|
|
62 |
import com.spice.profitmandi.dao.entity.dtr.UserCampaign;
|
| 25140 |
amit.gupta |
63 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 24917 |
tejbeer |
64 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24465 |
tejbeer |
65 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
|
|
66 |
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
|
| 24917 |
tejbeer |
67 |
import com.spice.profitmandi.dao.entity.transaction.NotifyColorChange;
|
| 25066 |
tejbeer |
68 |
import com.spice.profitmandi.dao.entity.transaction.NotifyMessage;
|
| 24917 |
tejbeer |
69 |
import com.spice.profitmandi.dao.entity.transaction.NotifyOrder;
|
| 24739 |
tejbeer |
70 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 25371 |
tejbeer |
71 |
import com.spice.profitmandi.dao.entity.user.Device;
|
|
|
72 |
import com.spice.profitmandi.dao.model.SimpleCampaign;
|
|
|
73 |
import com.spice.profitmandi.dao.model.SimpleCampaignParams;
|
|
|
74 |
import com.spice.profitmandi.dao.repository.catalog.DeviceRepository;
|
| 24123 |
tejbeer |
75 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 24950 |
tejbeer |
76 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 24106 |
tejbeer |
77 |
import com.spice.profitmandi.dao.repository.catalog.TagRankingRepository;
|
| 24465 |
tejbeer |
78 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 25371 |
tejbeer |
79 |
import com.spice.profitmandi.dao.repository.dtr.NotificationCampaignRepository;
|
|
|
80 |
import com.spice.profitmandi.dao.repository.dtr.PushNotificationRepository;
|
| 24917 |
tejbeer |
81 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 25371 |
tejbeer |
82 |
import com.spice.profitmandi.dao.repository.dtr.UserCampaignRepository;
|
| 24203 |
amit.gupta |
83 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 24465 |
tejbeer |
84 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
|
|
85 |
import com.spice.profitmandi.dao.repository.fofo.LiveDemoBillingRespository;
|
| 24917 |
tejbeer |
86 |
import com.spice.profitmandi.dao.repository.inventory.NotifyStatus;
|
|
|
87 |
import com.spice.profitmandi.dao.repository.transaction.NotifyColorChangeRepository;
|
|
|
88 |
import com.spice.profitmandi.dao.repository.transaction.NotifyItemRepository;
|
| 25066 |
tejbeer |
89 |
import com.spice.profitmandi.dao.repository.transaction.NotifyMessageRepository;
|
| 24917 |
tejbeer |
90 |
import com.spice.profitmandi.dao.repository.transaction.NotifyOrderRespository;
|
| 24658 |
tejbeer |
91 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 25851 |
amit.gupta |
92 |
import com.spice.profitmandi.service.NotificationService;
|
| 22927 |
ashik.ali |
93 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 24465 |
tejbeer |
94 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22139 |
amit.gupta |
95 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 22069 |
ashik.ali |
96 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 24106 |
tejbeer |
97 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 21577 |
ashik.ali |
98 |
|
| 24658 |
tejbeer |
99 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 24739 |
tejbeer |
100 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 24658 |
tejbeer |
101 |
|
| 21577 |
ashik.ali |
102 |
@Controller
|
| 24123 |
tejbeer |
103 |
@Transactional(rollbackFor = Throwable.class)
|
| 21577 |
ashik.ali |
104 |
public class InventoryController {
|
| 21987 |
kshitij.so |
105 |
|
| 23568 |
govind |
106 |
private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
|
| 21987 |
kshitij.so |
107 |
|
| 21577 |
ashik.ali |
108 |
@Autowired
|
| 22927 |
ashik.ali |
109 |
private CookiesProcessor cookiesProcessor;
|
| 24123 |
tejbeer |
110 |
|
| 22354 |
ashik.ali |
111 |
@Autowired
|
| 23784 |
ashik.ali |
112 |
@Qualifier("fofoInventoryService")
|
| 22927 |
ashik.ali |
113 |
private InventoryService inventoryService;
|
| 24465 |
tejbeer |
114 |
|
| 24203 |
amit.gupta |
115 |
@Autowired
|
| 24950 |
tejbeer |
116 |
TagListingRepository tagListingRepository;
|
|
|
117 |
|
|
|
118 |
@Autowired
|
| 24203 |
amit.gupta |
119 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 24123 |
tejbeer |
120 |
|
| 24106 |
tejbeer |
121 |
@Autowired
|
|
|
122 |
private TagRankingRepository tagRankingRepository;
|
| 24123 |
tejbeer |
123 |
|
| 24106 |
tejbeer |
124 |
@Autowired
|
| 24465 |
tejbeer |
125 |
private InventoryItemRepository inventoryItemRepository;
|
|
|
126 |
|
|
|
127 |
@Autowired
|
|
|
128 |
private LiveDemoBillingRespository liveDemoBillingRespository;
|
|
|
129 |
|
|
|
130 |
@Autowired
|
| 24123 |
tejbeer |
131 |
private ItemRepository itemRepository;
|
|
|
132 |
|
|
|
133 |
@Autowired
|
| 24465 |
tejbeer |
134 |
private RetailerService retailerService;
|
|
|
135 |
|
|
|
136 |
@Autowired
|
| 24106 |
tejbeer |
137 |
private MVCResponseSender mvcResponseSender;
|
| 24123 |
tejbeer |
138 |
|
| 24465 |
tejbeer |
139 |
@Autowired
|
|
|
140 |
FofoStoreRepository fofoStoreRepository;
|
|
|
141 |
|
| 24658 |
tejbeer |
142 |
@Autowired
|
|
|
143 |
private OrderRepository orderRepository;
|
|
|
144 |
|
| 24739 |
tejbeer |
145 |
@Autowired
|
| 24917 |
tejbeer |
146 |
private NotifyItemRepository notifyItemRepository;
|
| 24739 |
tejbeer |
147 |
|
| 24917 |
tejbeer |
148 |
@Autowired
|
|
|
149 |
private NotifyColorChangeRepository notifyColorChangeRepository;
|
|
|
150 |
|
|
|
151 |
@Autowired
|
|
|
152 |
private NotifyOrderRespository notifyOrderRespository;
|
|
|
153 |
|
|
|
154 |
@Autowired
|
| 25851 |
amit.gupta |
155 |
private NotificationService notificationService;
|
|
|
156 |
|
|
|
157 |
@Autowired
|
| 25066 |
tejbeer |
158 |
private NotifyMessageRepository notifyMessageRepository;
|
|
|
159 |
|
|
|
160 |
@Autowired
|
| 24917 |
tejbeer |
161 |
private UserAccountRepository userAccountRepository;
|
|
|
162 |
|
| 21987 |
kshitij.so |
163 |
@Value("${saholic.api.host}")
|
|
|
164 |
private String host;
|
| 23786 |
amit.gupta |
165 |
|
| 21987 |
kshitij.so |
166 |
@Value("${saholic.api.port}")
|
|
|
167 |
private int port;
|
| 23786 |
amit.gupta |
168 |
|
| 21987 |
kshitij.so |
169 |
@Value("${saholic.api.webapp}")
|
|
|
170 |
private String webapp;
|
|
|
171 |
|
| 24917 |
tejbeer |
172 |
@Autowired
|
|
|
173 |
JavaMailSender mailSender;
|
|
|
174 |
|
|
|
175 |
@Autowired
|
| 25371 |
tejbeer |
176 |
private NotificationCampaignRepository notificationCampaignRepository;
|
|
|
177 |
|
|
|
178 |
@Autowired
|
|
|
179 |
private DeviceRepository deviceRepository;
|
|
|
180 |
|
|
|
181 |
@Autowired
|
|
|
182 |
private PushNotificationRepository pushNotificationRepository;
|
|
|
183 |
|
|
|
184 |
@Autowired
|
|
|
185 |
private UserCampaignRepository userCampaignRepository;
|
|
|
186 |
|
|
|
187 |
@Autowired
|
|
|
188 |
private Gson gson;
|
|
|
189 |
|
| 23786 |
amit.gupta |
190 |
@RequestMapping(value = "/getCurrentInventorySnapshot")
|
|
|
191 |
public String getCurrentAvailability(HttpServletRequest request,
|
|
|
192 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
193 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
| 24123 |
tejbeer |
194 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
| 23786 |
amit.gupta |
195 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
196 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
197 |
Map<String, Object> map = inventoryService.getCurrentInventorySnapshot(loginDetails.getFofoId(), offset, limit,
|
|
|
198 |
searchTerm);
|
| 22927 |
ashik.ali |
199 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
200 |
return "inventory-snapshot";
|
| 21612 |
ashik.ali |
201 |
}
|
| 21987 |
kshitij.so |
202 |
|
| 23786 |
amit.gupta |
203 |
@RequestMapping(value = "/getBadInventorySnapshot")
|
|
|
204 |
public String getBadAvailability(HttpServletRequest request,
|
|
|
205 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
206 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
207 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
208 |
throws ProfitMandiBusinessException {
|
| 24123 |
tejbeer |
209 |
if (searchTerm == null) {
|
|
|
210 |
searchTerm = "";
|
| 24052 |
amit.gupta |
211 |
}
|
| 22927 |
ashik.ali |
212 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
213 |
Map<String, Object> map = inventoryService.getBadInventorySnapshot(loginDetails.getFofoId(), offset, limit,
|
|
|
214 |
searchTerm);
|
| 22927 |
ashik.ali |
215 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
216 |
return "bad-inventory-snapshot";
|
|
|
217 |
}
|
|
|
218 |
|
| 23786 |
amit.gupta |
219 |
@RequestMapping(value = "/getPaginatedCurrentInventorySnapshot")
|
|
|
220 |
public String getPaginatedCurrentInventorySnapshot(HttpServletRequest request,
|
|
|
221 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
222 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
223 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
224 |
throws ProfitMandiBusinessException {
|
| 24123 |
tejbeer |
225 |
if (searchTerm == null) {
|
|
|
226 |
searchTerm = "";
|
| 24052 |
amit.gupta |
227 |
}
|
| 22927 |
ashik.ali |
228 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
229 |
Map<String, Object> map = inventoryService.getPaginatedCurrentInventorySnapshot(loginDetails.getFofoId(),
|
|
|
230 |
offset, limit, searchTerm);
|
| 22927 |
ashik.ali |
231 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
232 |
return "inventory-snapshot-paginated";
|
|
|
233 |
}
|
| 23786 |
amit.gupta |
234 |
|
|
|
235 |
@RequestMapping(value = "/getCatalog")
|
|
|
236 |
public String getCatalog(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
237 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
238 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
239 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
240 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
241 |
if (searchTerm == null) {
|
|
|
242 |
searchTerm = "";
|
| 24052 |
amit.gupta |
243 |
}
|
| 24739 |
tejbeer |
244 |
|
| 22927 |
ashik.ali |
245 |
Map<String, Object> map = inventoryService.getCatalog(loginDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
246 |
model.addAllAttributes(map);
|
| 24203 |
amit.gupta |
247 |
model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
|
| 24658 |
tejbeer |
248 |
|
| 21987 |
kshitij.so |
249 |
return "catalog";
|
|
|
250 |
}
|
| 23786 |
amit.gupta |
251 |
|
| 24465 |
tejbeer |
252 |
// This method is currently hardcoded to faciliate watches sold as gift.
|
| 24203 |
amit.gupta |
253 |
private boolean hasGift(int fofoId) {
|
|
|
254 |
try {
|
| 24465 |
tejbeer |
255 |
return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
|
|
|
256 |
.getAvailability() > 0;
|
| 24203 |
amit.gupta |
257 |
} catch (ProfitMandiBusinessException e) {
|
|
|
258 |
return false;
|
|
|
259 |
}
|
|
|
260 |
}
|
|
|
261 |
|
| 23786 |
amit.gupta |
262 |
@RequestMapping(value = "/getPaginatedCatalog")
|
|
|
263 |
public String getCatalogPaginated(HttpServletRequest request,
|
|
|
264 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
265 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
266 |
@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
|
|
|
267 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
268 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
269 |
if (searchTerm == null) {
|
|
|
270 |
searchTerm = "";
|
| 24052 |
amit.gupta |
271 |
}
|
| 23786 |
amit.gupta |
272 |
Map<String, Object> map = inventoryService.getPaginatedCatalog(loginDetails.getFofoId(), offset, limit,
|
|
|
273 |
searchTerm);
|
| 22927 |
ashik.ali |
274 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
275 |
return "catalog-paginated";
|
|
|
276 |
}
|
|
|
277 |
|
| 23786 |
amit.gupta |
278 |
@RequestMapping(value = "/checkItemAvailability")
|
|
|
279 |
public String getItemAvailability(HttpServletRequest request,
|
|
|
280 |
@RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model)
|
|
|
281 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
282 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
283 |
CustomCurrentInventorySnapshot customCurrentInventorySnapshot = inventoryService.checkItemAvailability(itemId,
|
|
|
284 |
loginDetails.getFofoId());
|
| 25812 |
amit.gupta |
285 |
/*
|
|
|
286 |
* customCurrentInventorySnapshot
|
|
|
287 |
* .setIconUrl(Utils.getIconUrl(customCurrentInventorySnapshot.getCatalogItemId(
|
|
|
288 |
* ), host, port, webapp));
|
|
|
289 |
*/
|
| 22927 |
ashik.ali |
290 |
model.addAttribute("currentInventorySnapshot", new Gson().toJson(customCurrentInventorySnapshot));
|
|
|
291 |
return "current-item-availability";
|
| 23786 |
amit.gupta |
292 |
|
| 21577 |
ashik.ali |
293 |
}
|
| 23786 |
amit.gupta |
294 |
|
| 23192 |
ashik.ali |
295 |
@RequestMapping(value = "/cart", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
296 |
public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model)
|
|
|
297 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
298 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
299 |
|
| 22927 |
ashik.ali |
300 |
Map<String, Object> map = inventoryService.addToCart(cartData, loginDetails.getFofoId());
|
|
|
301 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
302 |
return "cart";
|
|
|
303 |
}
|
| 23786 |
amit.gupta |
304 |
|
| 23192 |
ashik.ali |
305 |
@RequestMapping(value = "/validate-cart", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
306 |
public String validateCart(HttpServletRequest request, HttpServletResponse response,
|
|
|
307 |
@RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
308 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
309 |
|
| 22927 |
ashik.ali |
310 |
Map<String, Object> map = inventoryService.validateCart(cartData, loginDetails.getFofoId());
|
|
|
311 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
312 |
return "validate-cart";
|
|
|
313 |
}
|
|
|
314 |
|
| 23786 |
amit.gupta |
315 |
@RequestMapping(value = "/grnHistory")
|
| 24123 |
tejbeer |
316 |
public String getGrnHistory(HttpServletRequest request, @RequestParam(required = false) LocalDateTime startTime,
|
| 23886 |
amit.gupta |
317 |
@RequestParam(required = false) LocalDateTime endTime,
|
| 23786 |
amit.gupta |
318 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
319 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
320 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
|
|
|
321 |
@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
|
|
|
322 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
323 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
324 |
Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTime, endTime, offset,
|
|
|
325 |
limit, purchaseReference, searchType);
|
| 22927 |
ashik.ali |
326 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
327 |
return "grn-history";
|
| 21636 |
ashik.ali |
328 |
}
|
| 21987 |
kshitij.so |
329 |
|
| 25140 |
amit.gupta |
330 |
@RequestMapping(value = "/downloadPurchaseInvoices")
|
|
|
331 |
public ResponseEntity<?> downloadPurchaseInvoices(HttpServletRequest request,
|
|
|
332 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
333 |
@RequestParam(required = false) LocalDateTime endTime,
|
|
|
334 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
335 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
336 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
|
|
|
337 |
@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
|
|
|
338 |
throws ProfitMandiBusinessException {
|
|
|
339 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
340 |
Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTime, endTime, offset,
|
|
|
341 |
limit, purchaseReference, searchType);
|
|
|
342 |
|
|
|
343 |
List<FofoOrder> fofoOrders = (List<FofoOrder>) map.get("saleHistories");
|
|
|
344 |
|
|
|
345 |
if (fofoOrders.size() == 0) {
|
|
|
346 |
throw new ProfitMandiBusinessException("Search criteria", "", "No orders found for criteria");
|
|
|
347 |
}
|
|
|
348 |
|
|
|
349 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
350 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
|
|
351 |
headers.set("Content-disposition", "inline; filename=invoices.pdf");
|
|
|
352 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
353 |
List<PdfModel> pdfModels = new ArrayList<>();
|
| 25371 |
tejbeer |
354 |
/*
|
|
|
355 |
* for (FofoOrder fofoOrder : fofoOrders) { try {
|
|
|
356 |
* pdfModels.add(orderService.getInvoicePdfModel(fofoOrder.getId())); } catch
|
|
|
357 |
* (Exception e) {
|
|
|
358 |
* LOGGER.info("could not create invoice for {}, invoice number {}",
|
|
|
359 |
* fofoOrder.getId(), fofoOrder.getInvoiceNumber()); } }
|
|
|
360 |
*/
|
| 25140 |
amit.gupta |
361 |
PdfUtils.generateAndWrite(pdfModels, byteArrayOutputStream);
|
|
|
362 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
363 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
364 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
365 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
366 |
}
|
|
|
367 |
|
| 23786 |
amit.gupta |
368 |
@RequestMapping(value = "/getPaginatedGrnHistory")
|
|
|
369 |
public String getPaginatedGrnHistory(HttpServletRequest request,
|
| 23886 |
amit.gupta |
370 |
@RequestParam(required = false) LocalDateTime startTime,
|
|
|
371 |
@RequestParam(required = false) LocalDateTime endTime,
|
| 23786 |
amit.gupta |
372 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
373 |
@RequestParam(name = "limit", defaultValue = "10") int limit,
|
|
|
374 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE, defaultValue = "") String purchaseReference,
|
|
|
375 |
@RequestParam(name = "searchType", defaultValue = "") String searchType, Model model)
|
|
|
376 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
377 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 24123 |
tejbeer |
378 |
Map<String, Object> map = inventoryService.getPaginatedGrnHistory(loginDetails.getFofoId(), startTime, endTime,
|
|
|
379 |
offset, limit);
|
| 22927 |
ashik.ali |
380 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
381 |
return "grn-history-paginated";
|
|
|
382 |
}
|
|
|
383 |
|
| 23786 |
amit.gupta |
384 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
|
|
|
385 |
public String grnHistoryByPurchaseId(HttpServletRequest request,
|
|
|
386 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model)
|
|
|
387 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
388 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
389 |
Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseId, host, port,
|
|
|
390 |
webapp);
|
| 22927 |
ashik.ali |
391 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
392 |
return "grn-details";
|
| 21636 |
ashik.ali |
393 |
}
|
| 21987 |
kshitij.so |
394 |
|
| 23786 |
amit.gupta |
395 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
|
|
|
396 |
public String grnHistoryByPurchaseReference(HttpServletRequest request,
|
|
|
397 |
@RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model)
|
|
|
398 |
throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
399 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
400 |
Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseReference,
|
|
|
401 |
host, port, webapp);
|
| 22927 |
ashik.ali |
402 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
403 |
return "grn-details";
|
| 21654 |
ashik.ali |
404 |
}
|
| 23786 |
amit.gupta |
405 |
|
| 22472 |
ashik.ali |
406 |
@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
407 |
public String getInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals,
|
|
|
408 |
Model model, @RequestParam(name = "searchContent", defaultValue = "") String searchContent,
|
|
|
409 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
410 |
@RequestParam(name = "limit", defaultValue = "10") int limit) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
411 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
412 |
Map<String, Object> map = inventoryService.getPaginatedItemAgingByInterval(loginDetails.getFofoId(), intervals,
|
|
|
413 |
searchContent, offset, limit);
|
| 22927 |
ashik.ali |
414 |
model.addAllAttributes(map);
|
| 22523 |
ashik.ali |
415 |
return "item-aging";
|
|
|
416 |
}
|
| 23786 |
amit.gupta |
417 |
|
| 22523 |
ashik.ali |
418 |
@RequestMapping(value = "/downloadInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 23786 |
amit.gupta |
419 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
|
|
|
420 |
@RequestBody List<Integer> intervals, Model model) throws ProfitMandiBusinessException {
|
| 22927 |
ashik.ali |
421 |
LOGGER.info("Request received at url{} with body {}", request.getRequestURI(), intervals);
|
|
|
422 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 23786 |
amit.gupta |
423 |
|
|
|
424 |
List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryService
|
|
|
425 |
.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
|
|
|
426 |
|
| 22486 |
ashik.ali |
427 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
428 |
ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
|
| 23786 |
amit.gupta |
429 |
|
|
|
430 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
431 |
// private static final String CONTENT_TYPE_XLSX =
|
|
|
432 |
// "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
433 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
434 |
// headers.set("Content-Type", "application/vnd.ms-excel");
|
| 22486 |
ashik.ali |
435 |
headers.set("Content-disposition", "inline; filename=InventoryItemAging.xlsx");
|
| 23786 |
amit.gupta |
436 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
437 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
438 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
|
|
439 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
440 |
|
| 24123 |
tejbeer |
441 |
// return
|
|
|
442 |
// responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 22472 |
ashik.ali |
443 |
}
|
| 24123 |
tejbeer |
444 |
|
| 24106 |
tejbeer |
445 |
@RequestMapping(value = "/featurePanel", method = RequestMethod.GET)
|
| 25371 |
tejbeer |
446 |
public String FeaturePanel(HttpServletRequest request, Model model) throws Exception {
|
| 21987 |
kshitij.so |
447 |
|
| 24106 |
tejbeer |
448 |
List<TagRanking> tagRanking = null;
|
| 25362 |
tejbeer |
449 |
tagRanking = tagRankingRepository.getAllTagRanking();
|
| 24106 |
tejbeer |
450 |
LOGGER.info("tagRanking" + tagRanking);
|
|
|
451 |
if (!tagRanking.isEmpty()) {
|
| 25371 |
tejbeer |
452 |
Set<Integer> catalogIds = tagRanking.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 24798 |
tejbeer |
453 |
List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
|
|
|
454 |
Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
|
|
|
455 |
x -> x.getItemDescription(), (description1, description2) -> description1));
|
|
|
456 |
|
|
|
457 |
LOGGER.info("catalogDescription" + catalogDescription);
|
| 24465 |
tejbeer |
458 |
model.addAttribute("tagRanking", tagRanking);
|
| 24798 |
tejbeer |
459 |
model.addAttribute("catalogDescription", catalogDescription);
|
| 24106 |
tejbeer |
460 |
|
|
|
461 |
} else {
|
|
|
462 |
model.addAttribute("tagRanking", tagRanking);
|
| 25362 |
tejbeer |
463 |
|
| 24106 |
tejbeer |
464 |
}
|
|
|
465 |
|
|
|
466 |
return "feature";
|
|
|
467 |
|
|
|
468 |
}
|
| 24123 |
tejbeer |
469 |
|
| 24106 |
tejbeer |
470 |
@RequestMapping(value = "/itemfeature", method = RequestMethod.POST)
|
| 24123 |
tejbeer |
471 |
public String Itemfeature(HttpServletRequest request, @RequestBody ItemFeatureDataModel itemFeatureDatatModel,
|
|
|
472 |
Model model) throws Exception {
|
| 25371 |
tejbeer |
473 |
TagRanking tagRanking = tagRankingRepository.selectBycatalogItemId(itemFeatureDatatModel.getCatalogItemId());
|
|
|
474 |
LOGGER.info("tagRanking" + tagRanking);
|
|
|
475 |
if (tagRanking == null) {
|
|
|
476 |
tagRanking = new TagRanking();
|
|
|
477 |
tagRanking.setCatalogItemId(itemFeatureDatatModel.getCatalogItemId());
|
| 25363 |
tejbeer |
478 |
}
|
| 24106 |
tejbeer |
479 |
tagRanking.setFeature(itemFeatureDatatModel.getFeature());
|
| 25363 |
tejbeer |
480 |
tagRanking.setRankPoints(itemFeatureDatatModel.getRankPoints());
|
| 25371 |
tejbeer |
481 |
|
| 24123 |
tejbeer |
482 |
tagRankingRepository.persist(tagRanking);
|
| 24106 |
tejbeer |
483 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
484 |
return "response";
|
|
|
485 |
}
|
|
|
486 |
|
| 24798 |
tejbeer |
487 |
@RequestMapping(value = "/removeFeature", method = RequestMethod.DELETE)
|
|
|
488 |
public String removeTagRankingEnteries(HttpServletRequest request,
|
|
|
489 |
@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
|
| 24917 |
tejbeer |
490 |
|
| 24798 |
tejbeer |
491 |
tagRankingRepository.deleteById(id);
|
|
|
492 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
493 |
return "response";
|
|
|
494 |
}
|
|
|
495 |
|
| 24465 |
tejbeer |
496 |
@RequestMapping(value = "/getDemolistbyfofoId", method = RequestMethod.GET)
|
|
|
497 |
public String DemoListbyFofoId(HttpServletRequest request,
|
|
|
498 |
@RequestParam(required = false, defaultValue = "0") int fofoId, Model model) throws Exception {
|
|
|
499 |
|
|
|
500 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
|
|
501 |
.collect(Collectors.toList());
|
|
|
502 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
503 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
|
|
504 |
List<String> serailNumberList = liveDemoBillingRespository.selectAllSerialNumber();
|
|
|
505 |
LOGGER.info("serailNumberList" + serailNumberList);
|
|
|
506 |
List<InventoryItem> inventoryItem = null;
|
|
|
507 |
List<InventoryItem> inventoryItem1 = new ArrayList<>();
|
|
|
508 |
if (fofoId > 0) {
|
|
|
509 |
List<Item> items = itemRepository.selectAllByBrand("Live Demo");
|
|
|
510 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
511 |
for (Item Item : items) {
|
|
|
512 |
itemIds.add(Item.getId());
|
|
|
513 |
}
|
|
|
514 |
inventoryItem = inventoryItemRepository.selectByFofoIdItemIds(fofoId, itemIds);
|
|
|
515 |
|
|
|
516 |
Set<String> serial = new HashSet<>();
|
|
|
517 |
for (InventoryItem invItem : inventoryItem) {
|
| 24658 |
tejbeer |
518 |
if (!serailNumberList.contains(invItem.getSerialNumber())) {
|
| 24465 |
tejbeer |
519 |
inventoryItem1.add(invItem);
|
| 25371 |
tejbeer |
520 |
|
| 24465 |
tejbeer |
521 |
}
|
|
|
522 |
|
|
|
523 |
}
|
|
|
524 |
|
|
|
525 |
LOGGER.info("inventoyItem" + inventoryItem1);
|
|
|
526 |
model.addAttribute("customRetailers", customRetailers);
|
| 25371 |
tejbeer |
527 |
|
| 24465 |
tejbeer |
528 |
model.addAttribute("liveDemo", inventoryItem1);
|
|
|
529 |
CustomRetailer fofoIdsAndRetailerName = retailerService.getFofoRetailer(fofoId);
|
|
|
530 |
|
|
|
531 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
|
|
532 |
|
|
|
533 |
}
|
|
|
534 |
|
|
|
535 |
else {
|
|
|
536 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
537 |
model.addAttribute("liveDemo", inventoryItem1);
|
|
|
538 |
}
|
|
|
539 |
|
|
|
540 |
return "live_demo_billing";
|
|
|
541 |
|
|
|
542 |
}
|
|
|
543 |
|
|
|
544 |
@RequestMapping(value = "/enableliveDemoSerailNumber", method = RequestMethod.POST)
|
|
|
545 |
public String EnableliveDemoSerailNumber(HttpServletRequest request, @RequestParam String serial_number,
|
|
|
546 |
Model model) throws Exception {
|
|
|
547 |
|
|
|
548 |
LiveDemoSerialNumber liveDemoSerialNumber = new LiveDemoSerialNumber();
|
|
|
549 |
liveDemoSerialNumber.setSerialNumber(serial_number);
|
|
|
550 |
|
|
|
551 |
liveDemoBillingRespository.persist(liveDemoSerialNumber);
|
|
|
552 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
553 |
return "response";
|
|
|
554 |
}
|
|
|
555 |
|
| 24739 |
tejbeer |
556 |
@RequestMapping(value = "/getInProcessOrder", method = RequestMethod.GET)
|
|
|
557 |
public String getInProcessOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
558 |
|
|
|
559 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
| 25067 |
tejbeer |
560 |
.selectAllOrder(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 24917 |
tejbeer |
561 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
562 |
List<Integer> orderIds = new ArrayList<>();
|
|
|
563 |
if (!inProcessorder.isEmpty()) {
|
|
|
564 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessorder) {
|
|
|
565 |
retailerIds.add(order.getRetailerId());
|
|
|
566 |
orderIds.add(order.getId());
|
| 24739 |
tejbeer |
567 |
|
| 24917 |
tejbeer |
568 |
}
|
| 24739 |
tejbeer |
569 |
|
| 25640 |
tejbeer |
570 |
List<NotifyOrder> notify = notifyOrderRespository.selectByorderIds(orderIds);
|
|
|
571 |
for (NotifyOrder notifyOrder : notify) {
|
| 25449 |
tejbeer |
572 |
|
| 25640 |
tejbeer |
573 |
Order orderdetail = orderRepository.selectById(notifyOrder.getOrderId());
|
| 25449 |
tejbeer |
574 |
if (!orderdetail.getStatus().equals(OrderStatus.SUBMITTED_FOR_PROCESSING)) {
|
| 25640 |
tejbeer |
575 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
| 25449 |
tejbeer |
576 |
}
|
| 25640 |
tejbeer |
577 |
}
|
| 24950 |
tejbeer |
578 |
|
| 24917 |
tejbeer |
579 |
Map<Integer, Optional<NotifyOrder>> notifyOrders = notifyOrderRespository.selectByorderIds(orderIds)
|
|
|
580 |
.stream().collect(Collectors.groupingBy(NotifyOrder::getOrderId,
|
|
|
581 |
Collectors.maxBy((x1, x2) -> x1.getId() - x2.getId())));
|
| 24950 |
tejbeer |
582 |
|
| 24917 |
tejbeer |
583 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
|
|
584 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
|
|
585 |
List<com.spice.profitmandi.dao.entity.transaction.Order> pendingPaymentorder = orderRepository
|
|
|
586 |
.selectAllOrderDatesBetweenByStatus(LocalDateTime.now().minusDays(30), LocalDateTime.now(),
|
|
|
587 |
OrderStatus.PAYMENT_PENDING);
|
|
|
588 |
List<com.spice.profitmandi.dao.entity.transaction.Order> failedPaymentorder = orderRepository
|
|
|
589 |
.selectAllOrderDatesBetweenByStatus(LocalDateTime.now().minusDays(30), LocalDateTime.now(),
|
|
|
590 |
OrderStatus.PAYMENT_FAILED);
|
|
|
591 |
pendingPaymentorder.addAll(failedPaymentorder);
|
|
|
592 |
|
|
|
593 |
model.addAttribute("inProcessorder", inProcessorder);
|
|
|
594 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
|
|
595 |
model.addAttribute("pendingPaymentorder", pendingPaymentorder);
|
|
|
596 |
model.addAttribute("latestNotifyOrders", notifyOrders);
|
|
|
597 |
} else {
|
|
|
598 |
model.addAttribute("inProcessorder", inProcessorder);
|
|
|
599 |
}
|
| 24739 |
tejbeer |
600 |
return "review_order";
|
|
|
601 |
}
|
|
|
602 |
|
|
|
603 |
@RequestMapping(value = "/getKeepInTabOrder", method = RequestMethod.GET)
|
|
|
604 |
public String getKeepInTabOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
|
|
605 |
|
|
|
606 |
List<com.spice.profitmandi.dao.entity.transaction.Order> keepatab = orderRepository
|
|
|
607 |
.selectAllOrder(OrderStatus.KEEP_A_TAB);
|
|
|
608 |
|
|
|
609 |
model.addAttribute("keepatab", keepatab);
|
|
|
610 |
|
|
|
611 |
return "keep-a-tab";
|
|
|
612 |
}
|
|
|
613 |
|
|
|
614 |
@RequestMapping(value = "/closeOrder", method = RequestMethod.POST)
|
|
|
615 |
public String closeOrder(HttpServletRequest request, @RequestParam int orderId, Model model) throws Exception {
|
| 24798 |
tejbeer |
616 |
|
| 24739 |
tejbeer |
617 |
Order order = orderRepository.selectById(orderId);
|
| 24798 |
tejbeer |
618 |
if (order != null) {
|
| 24739 |
tejbeer |
619 |
order.setStatus(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
|
| 24798 |
tejbeer |
620 |
|
| 24739 |
tejbeer |
621 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
622 |
|
| 24798 |
tejbeer |
623 |
} else {
|
| 24739 |
tejbeer |
624 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
625 |
|
|
|
626 |
}
|
|
|
627 |
return "response";
|
| 24658 |
tejbeer |
628 |
}
|
|
|
629 |
|
| 25640 |
tejbeer |
630 |
@RequestMapping(value = "/getcancelOrderItems", method = RequestMethod.GET)
|
|
|
631 |
public String getcancelOrderItems(HttpServletRequest request, @RequestParam int itemId, Model model)
|
|
|
632 |
throws Exception {
|
|
|
633 |
|
|
|
634 |
List<Order> inProcessselectedOrder = orderRepository.selectByItemIdOrderStatus(itemId,
|
|
|
635 |
OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
636 |
|
|
|
637 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
638 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessselectedOrder) {
|
|
|
639 |
retailerIds.add(order.getRetailerId());
|
|
|
640 |
|
|
|
641 |
}
|
|
|
642 |
|
|
|
643 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
|
|
644 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
|
|
645 |
|
|
|
646 |
model.addAttribute("inProcessCancelOrder", inProcessselectedOrder);
|
|
|
647 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
|
|
648 |
|
|
|
649 |
return "cancel-order-modal";
|
|
|
650 |
}
|
|
|
651 |
|
| 24739 |
tejbeer |
652 |
@RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
|
| 25640 |
tejbeer |
653 |
public String cancelOrder(HttpServletRequest request, @RequestBody OrderCancellationModel orderCancellationModel,
|
|
|
654 |
Model model) throws Exception {
|
| 24739 |
tejbeer |
655 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 25640 |
tejbeer |
656 |
LOGGER.info("orderId" + orderCancellationModel.getOrderIds());
|
|
|
657 |
|
| 24739 |
tejbeer |
658 |
try {
|
| 25699 |
tejbeer |
659 |
// List<Order> orders =
|
|
|
660 |
// orderRepository.selectByOrderIds(orderCancellationModel.getOrderIds());
|
| 25640 |
tejbeer |
661 |
|
| 25699 |
tejbeer |
662 |
List<Order> orders = orderRepository.selectByOrderIdsOrdersStatus(orderCancellationModel.getOrderIds(),
|
|
|
663 |
OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
664 |
if (!orders.isEmpty()) {
|
|
|
665 |
for (Order order : orders) {
|
| 25640 |
tejbeer |
666 |
|
| 25699 |
tejbeer |
667 |
orderRepository.refundOrder(order.getId(), loginDetails.getEmailId(),
|
|
|
668 |
orderCancellationModel.getReason(), OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
|
|
|
669 |
List<NotifyOrder> notifyOrders = notifyOrderRespository.selectByOrder(order.getId());
|
|
|
670 |
for (NotifyOrder notifyOrder : notifyOrders) {
|
|
|
671 |
if (notifyOrder.getStatus() == NotifyStatus.pending) {
|
|
|
672 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
|
|
673 |
}
|
| 25449 |
tejbeer |
674 |
}
|
| 25699 |
tejbeer |
675 |
sendCancellationNotificationToPartner(order, orderCancellationModel.getReason());
|
|
|
676 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
677 |
|
| 25640 |
tejbeer |
678 |
}
|
|
|
679 |
}
|
| 24739 |
tejbeer |
680 |
} catch (TransactionServiceException | TException e) {
|
|
|
681 |
model.addAttribute("response", mvcResponseSender.createResponseString(false));
|
|
|
682 |
|
|
|
683 |
}
|
| 25640 |
tejbeer |
684 |
|
| 24739 |
tejbeer |
685 |
return "response";
|
|
|
686 |
}
|
|
|
687 |
|
| 25039 |
amit.gupta |
688 |
private void sendCancellationNotificationToPartner(Order order, String reason) throws Exception {
|
|
|
689 |
Item item = itemRepository.selectById(order.getLineItem().getItemId());
|
| 25383 |
tejbeer |
690 |
|
| 25851 |
amit.gupta |
691 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
692 |
sendNotificationModel.setCampaignName("Order Cancellation");
|
|
|
693 |
sendNotificationModel.setTitle(String.format("Order %s %d(Pcs) cancelled", item.getItemDescription(),
|
| 25140 |
amit.gupta |
694 |
order.getLineItem().getQuantity()));
|
| 25851 |
amit.gupta |
695 |
sendNotificationModel.setType("url");
|
|
|
696 |
sendNotificationModel.setMessage(reason);
|
|
|
697 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/orderDetails");
|
|
|
698 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
699 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
700 |
notificationService.sendNotification(sendNotificationModel);
|
| 25140 |
amit.gupta |
701 |
|
| 25039 |
amit.gupta |
702 |
}
|
|
|
703 |
|
| 24917 |
tejbeer |
704 |
@RequestMapping(value = "/getNotifyItemColor", method = RequestMethod.GET)
|
|
|
705 |
public String getNotifyItemColor(HttpServletRequest request, @RequestParam int catalogItemId,
|
|
|
706 |
@RequestParam int itemId, Model model) throws ProfitMandiBusinessException {
|
|
|
707 |
|
| 24950 |
tejbeer |
708 |
List<Item> availableColorItems = itemRepository.selectAllByCatalogItemId(catalogItemId);
|
|
|
709 |
Iterator<Item> itemsIterator = availableColorItems.iterator();
|
| 24917 |
tejbeer |
710 |
|
| 24950 |
tejbeer |
711 |
while (itemsIterator.hasNext()) {
|
|
|
712 |
Item item = itemsIterator.next();
|
|
|
713 |
TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
|
|
|
714 |
|
|
|
715 |
if (itemTagListing == null) {
|
|
|
716 |
itemsIterator.remove();
|
|
|
717 |
|
|
|
718 |
}
|
|
|
719 |
|
|
|
720 |
else if (!itemTagListing.isActive()) {
|
|
|
721 |
itemsIterator.remove();
|
|
|
722 |
|
|
|
723 |
}
|
|
|
724 |
}
|
|
|
725 |
|
| 24917 |
tejbeer |
726 |
List<Order> inProcessselectedOrder = orderRepository.selectByItemIdOrderStatus(itemId,
|
|
|
727 |
OrderStatus.SUBMITTED_FOR_PROCESSING);
|
|
|
728 |
List<Integer> retailerIds = new ArrayList<>();
|
|
|
729 |
|
|
|
730 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessselectedOrder) {
|
|
|
731 |
retailerIds.add(order.getRetailerId());
|
|
|
732 |
|
|
|
733 |
}
|
|
|
734 |
|
|
|
735 |
Map<Integer, String> storeIdAndFofoIdMap = fofoStoreRepository.selectByRetailerIds(retailerIds).stream()
|
|
|
736 |
.collect(Collectors.toMap(FofoStore::getId, FofoStore::getCode));
|
| 24950 |
tejbeer |
737 |
LOGGER.info("item" + availableColorItems);
|
|
|
738 |
model.addAttribute("item", availableColorItems);
|
| 24917 |
tejbeer |
739 |
model.addAttribute("inProcessselectedOrder", inProcessselectedOrder);
|
|
|
740 |
model.addAttribute("storeIdAndFofoIdMap", storeIdAndFofoIdMap);
|
|
|
741 |
|
|
|
742 |
return "notify-order-modal";
|
|
|
743 |
}
|
|
|
744 |
|
|
|
745 |
@RequestMapping(value = "/notifyOrder", method = RequestMethod.POST)
|
|
|
746 |
public String NotifyOrder(HttpServletRequest request, @RequestBody NotifyOrderModel notifyOrderModel, Model model)
|
|
|
747 |
throws Exception {
|
|
|
748 |
|
|
|
749 |
com.spice.profitmandi.dao.entity.transaction.NotifyItem notifyItem = null;
|
|
|
750 |
List<Integer> orderIds = new ArrayList<>();
|
|
|
751 |
|
|
|
752 |
NotifyColorChange notifytimestamp = new NotifyColorChange();
|
|
|
753 |
notifytimestamp.setCreated(LocalDateTime.now());
|
|
|
754 |
notifyColorChangeRepository.persist(notifytimestamp);
|
| 25066 |
tejbeer |
755 |
NotifyMessage notifyMessage = new NotifyMessage();
|
|
|
756 |
notifyMessage.setNotifyId(notifytimestamp.getId());
|
|
|
757 |
notifyMessage.setNotifyMessages(notifyOrderModel.getMessage());
|
| 25140 |
amit.gupta |
758 |
notifyMessageRepository.persist(notifyMessage);
|
| 24917 |
tejbeer |
759 |
for (NotifyItemIdModel itemid : notifyOrderModel.getItemIds()) {
|
|
|
760 |
|
|
|
761 |
notifyItem = new com.spice.profitmandi.dao.entity.transaction.NotifyItem();
|
|
|
762 |
notifyItem.setItemId(itemid.getItemId());
|
|
|
763 |
notifyItem.setResponseTime(itemid.getResponseTime());
|
|
|
764 |
notifyItem.setProcuredDate(itemid.getProcuredTime());
|
|
|
765 |
notifyItem.setNotifyColorchangeId(notifytimestamp.getId());
|
|
|
766 |
notifyItemRepository.persist(notifyItem);
|
|
|
767 |
LOGGER.info("notifyItem" + notifyItem);
|
|
|
768 |
}
|
|
|
769 |
for (NotifyOrderIdModel st : notifyOrderModel.getOrderIds()) {
|
|
|
770 |
List<NotifyOrder> existingOrder = notifyOrderRespository.selectByOrder(st.getOrderId());
|
| 24950 |
tejbeer |
771 |
if (!existingOrder.isEmpty()) {
|
| 24917 |
tejbeer |
772 |
LOGGER.info("existingOrder" + existingOrder);
|
| 24950 |
tejbeer |
773 |
for (NotifyOrder notifyOrder : existingOrder) {
|
|
|
774 |
if (NotifyStatus.pending == notifyOrder.getStatus()) {
|
|
|
775 |
notifyOrder.setStatus(NotifyStatus.rejected);
|
|
|
776 |
}
|
| 24917 |
tejbeer |
777 |
}
|
|
|
778 |
}
|
|
|
779 |
NotifyOrder orderStatus = new NotifyOrder();
|
|
|
780 |
orderStatus.setOrderId(st.getOrderId());
|
|
|
781 |
orderStatus.setNotifyId(notifytimestamp.getId());
|
|
|
782 |
orderStatus.setItemId(st.getOlditemId());
|
|
|
783 |
Order id = orderRepository.selectById(st.getOrderId());
|
|
|
784 |
orderStatus.setFofoId(id.getRetailerId());
|
|
|
785 |
orderStatus.setStatus(NotifyStatus.pending);
|
|
|
786 |
notifyOrderRespository.persist(orderStatus);
|
|
|
787 |
|
|
|
788 |
LOGGER.info("itemStatus" + orderStatus);
|
|
|
789 |
orderIds.add(st.getOrderId());
|
|
|
790 |
}
|
|
|
791 |
|
|
|
792 |
LOGGER.info("orderIds" + orderIds);
|
|
|
793 |
List<Order> orders = orderRepository.selectByOrderIds(orderIds);
|
|
|
794 |
for (Order order : orders) {
|
|
|
795 |
LOGGER.info("order" + order.getId());
|
|
|
796 |
|
| 25140 |
amit.gupta |
797 |
NotifyMessage message = notifyMessageRepository.selectByNotifyId(notifytimestamp.getId());
|
|
|
798 |
|
| 25851 |
amit.gupta |
799 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
800 |
sendNotificationModel.setCampaignName("Notify Partner");
|
|
|
801 |
sendNotificationModel.setMessage(message.getNotifyMessages());
|
|
|
802 |
sendNotificationModel.setType("url");
|
|
|
803 |
sendNotificationModel.setTitle("Alert");
|
|
|
804 |
sendNotificationModel.setUrl("http://app.smartdukaan.com/pages/home/notifyOrder");
|
|
|
805 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
806 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
807 |
notificationService.sendNotification(sendNotificationModel);
|
| 25140 |
amit.gupta |
808 |
|
| 24917 |
tejbeer |
809 |
}
|
|
|
810 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
811 |
return "response";
|
|
|
812 |
}
|
|
|
813 |
|
| 25371 |
tejbeer |
814 |
public void pushNotification(int cid, List<Device> devices) {
|
|
|
815 |
for (Device device : devices) {
|
|
|
816 |
PushNotifications pn = new PushNotifications();
|
|
|
817 |
pn.setNotificationCampaignid(cid);
|
|
|
818 |
pn.setDeviceId(device.getId());
|
|
|
819 |
pn.setUserId(device.getUser_id());
|
|
|
820 |
pushNotificationRepository.persist(pn);
|
|
|
821 |
}
|
|
|
822 |
|
|
|
823 |
}
|
|
|
824 |
|
| 24917 |
tejbeer |
825 |
@RequestMapping(value = "/getAllNotifyOrder", method = RequestMethod.GET)
|
|
|
826 |
public String getAllNotifyOrder(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| 24950 |
tejbeer |
827 |
List<NotifyOrder> notifyOrders = null;
|
| 24917 |
tejbeer |
828 |
List<com.spice.profitmandi.dao.entity.transaction.Order> inProcessorder = orderRepository
|
| 25067 |
tejbeer |
829 |
.selectAllOrder(OrderStatus.SUBMITTED_FOR_PROCESSING);
|
| 24950 |
tejbeer |
830 |
|
| 24917 |
tejbeer |
831 |
List<Integer> orderIds = new ArrayList<>();
|
| 24950 |
tejbeer |
832 |
if (!inProcessorder.isEmpty()) {
|
| 24917 |
tejbeer |
833 |
for (com.spice.profitmandi.dao.entity.transaction.Order order : inProcessorder) {
|
| 24950 |
tejbeer |
834 |
|
| 24917 |
tejbeer |
835 |
orderIds.add(order.getId());
|
|
|
836 |
|
| 24950 |
tejbeer |
837 |
}
|
|
|
838 |
notifyOrders = notifyOrderRespository.selectByorderIds(orderIds);
|
|
|
839 |
Set<Integer> oldItemIds = new HashSet<>();
|
|
|
840 |
List<Integer> fofoIds = new ArrayList<>();
|
|
|
841 |
List<Integer> notifyIds = new ArrayList<>();
|
|
|
842 |
if (!notifyOrders.isEmpty()) {
|
|
|
843 |
for (NotifyOrder notifyOrder : notifyOrders) {
|
|
|
844 |
oldItemIds.add(notifyOrder.getItemId());
|
|
|
845 |
fofoIds.add(notifyOrder.getFofoId());
|
|
|
846 |
notifyIds.add(notifyOrder.getNotifyId());
|
| 24917 |
tejbeer |
847 |
}
|
|
|
848 |
|
| 24950 |
tejbeer |
849 |
List<NotifyColorChange> notifyColorChanges = notifyColorChangeRepository.selectByNotifyId(notifyIds);
|
|
|
850 |
Map<Integer, NotifyColorChange> notifyIdNotifyColorMap = this
|
|
|
851 |
.notifyOrdersToNotifyId(notifyColorChanges);
|
|
|
852 |
Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(fofoIds);
|
|
|
853 |
Map<Integer, String> itemdescription = inventoryService.getItemIdDescriptionMap(oldItemIds);
|
| 24917 |
tejbeer |
854 |
|
| 24950 |
tejbeer |
855 |
model.addAttribute("notifyOrders", notifyOrders);
|
|
|
856 |
model.addAttribute("notifyIdNotifyColorMap", notifyIdNotifyColorMap);
|
|
|
857 |
model.addAttribute("itemdescription", itemdescription);
|
|
|
858 |
model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
|
| 24917 |
tejbeer |
859 |
|
| 24950 |
tejbeer |
860 |
} else {
|
|
|
861 |
model.addAttribute("notifyOrders", notifyOrders);
|
|
|
862 |
}
|
| 24917 |
tejbeer |
863 |
} else {
|
|
|
864 |
model.addAttribute("notifyOrders", notifyOrders);
|
| 24950 |
tejbeer |
865 |
}
|
| 24917 |
tejbeer |
866 |
return "notify_order";
|
|
|
867 |
}
|
|
|
868 |
|
|
|
869 |
private Map<Integer, NotifyColorChange> notifyOrdersToNotifyId(List<NotifyColorChange> notifyColorChanges) {
|
|
|
870 |
Map<Integer, NotifyColorChange> notifyIdNotifyColorMap = new HashMap<>();
|
|
|
871 |
for (NotifyColorChange notifyColorChange : notifyColorChanges) {
|
|
|
872 |
notifyIdNotifyColorMap.put(notifyColorChange.getId(), notifyColorChange);
|
|
|
873 |
}
|
|
|
874 |
return notifyIdNotifyColorMap;
|
|
|
875 |
}
|
|
|
876 |
|
|
|
877 |
}
|