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