| 23405 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 25736 |
tejbeer |
3 |
import com.mongodb.DBObject;
|
| 30046 |
tejbeer |
4 |
import com.spice.profitmandi.common.enumuration.ActivationType;
|
| 23785 |
amit.gupta |
5 |
import com.spice.profitmandi.common.enumuration.CounterSize;
|
| 26846 |
tejbeer |
6 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 23405 |
amit.gupta |
7 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30017 |
amit.gupta |
8 |
import com.spice.profitmandi.common.model.*;
|
| 24231 |
amit.gupta |
9 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 25721 |
tejbeer |
10 |
import com.spice.profitmandi.common.util.Utils;
|
|
|
11 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
| 26721 |
tejbeer |
12 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 30003 |
tejbeer |
13 |
import com.spice.profitmandi.dao.entity.catalog.Category;
|
| 25721 |
tejbeer |
14 |
import com.spice.profitmandi.dao.entity.catalog.FocusedModel;
|
| 23785 |
amit.gupta |
15 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 23405 |
amit.gupta |
16 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 27088 |
tejbeer |
17 |
import com.spice.profitmandi.dao.entity.cs.Region;
|
| 30017 |
amit.gupta |
18 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
| 30664 |
amit.gupta |
19 |
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
|
| 30003 |
tejbeer |
20 |
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
|
| 23796 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 26846 |
tejbeer |
22 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 23796 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.entity.user.User;
|
| 30017 |
amit.gupta |
24 |
import com.spice.profitmandi.dao.entity.warehouse.BrandRegionMapping;
|
| 26978 |
tejbeer |
25 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 30003 |
tejbeer |
26 |
import com.spice.profitmandi.dao.model.FofoReportingModel;
|
|
|
27 |
import com.spice.profitmandi.dao.model.InStockAccessoriesTvFofoIdModel;
|
|
|
28 |
import com.spice.profitmandi.dao.model.InStockBrandFofoIdModel;
|
| 26721 |
tejbeer |
29 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 30003 |
tejbeer |
30 |
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
|
| 25721 |
tejbeer |
31 |
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
|
| 23405 |
amit.gupta |
32 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
|
|
33 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 31663 |
amit.gupta |
34 |
import com.spice.profitmandi.dao.repository.cs.*;
|
| 30044 |
tejbeer |
35 |
import com.spice.profitmandi.dao.repository.dtr.BrandLimitRepository;
|
| 23779 |
amit.gupta |
36 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 25736 |
tejbeer |
37 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 26846 |
tejbeer |
38 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 30017 |
amit.gupta |
39 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
| 30664 |
amit.gupta |
40 |
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
|
| 27768 |
tejbeer |
41 |
import com.spice.profitmandi.dao.repository.inventory.SaholicInventoryCISRepository;
|
| 30017 |
amit.gupta |
42 |
import com.spice.profitmandi.dao.repository.inventory.WarehouseRepository;
|
| 23796 |
amit.gupta |
43 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
|
|
44 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
|
|
45 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 30017 |
amit.gupta |
46 |
import com.spice.profitmandi.dao.repository.warehouse.BrandRegionMappingRepository;
|
| 26846 |
tejbeer |
47 |
import com.spice.profitmandi.service.NotificationService;
|
| 23798 |
amit.gupta |
48 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 25736 |
tejbeer |
49 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 27768 |
tejbeer |
50 |
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
|
| 23779 |
amit.gupta |
51 |
import com.spice.profitmandi.service.inventory.StockAllocationService;
|
|
|
52 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 25547 |
amit.gupta |
53 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23796 |
amit.gupta |
54 |
import com.spice.profitmandi.thrift.clients.PaymentClient;
|
|
|
55 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
|
|
56 |
import com.spice.profitmandi.thrift.clients.UserClient;
|
| 23405 |
amit.gupta |
57 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
58 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
59 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 23796 |
amit.gupta |
60 |
import in.shop2020.logistics.PickUpType;
|
| 30017 |
amit.gupta |
61 |
import in.shop2020.model.v1.order.*;
|
| 23796 |
amit.gupta |
62 |
import in.shop2020.model.v1.user.ItemPriceQuantity;
|
|
|
63 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
|
|
64 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
|
|
65 |
import in.shop2020.payments.Attribute;
|
|
|
66 |
import in.shop2020.payments.PaymentException;
|
|
|
67 |
import in.shop2020.payments.PaymentStatus;
|
| 30017 |
amit.gupta |
68 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
|
|
69 |
import org.apache.logging.log4j.LogManager;
|
|
|
70 |
import org.apache.logging.log4j.Logger;
|
|
|
71 |
import org.apache.thrift.TException;
|
|
|
72 |
import org.json.JSONArray;
|
|
|
73 |
import org.json.JSONObject;
|
|
|
74 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
75 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
76 |
import org.springframework.http.HttpHeaders;
|
|
|
77 |
import org.springframework.http.HttpStatus;
|
|
|
78 |
import org.springframework.http.ResponseEntity;
|
|
|
79 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
80 |
import org.springframework.stereotype.Controller;
|
|
|
81 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
82 |
import org.springframework.ui.Model;
|
|
|
83 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
84 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
85 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
86 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 23796 |
amit.gupta |
87 |
|
| 30017 |
amit.gupta |
88 |
import javax.servlet.http.HttpServletRequest;
|
|
|
89 |
import java.time.LocalDate;
|
|
|
90 |
import java.time.LocalDateTime;
|
|
|
91 |
import java.time.LocalTime;
|
|
|
92 |
import java.util.*;
|
|
|
93 |
import java.util.Map.Entry;
|
|
|
94 |
import java.util.function.Function;
|
|
|
95 |
import java.util.stream.Collectors;
|
|
|
96 |
|
| 23405 |
amit.gupta |
97 |
@Controller
|
|
|
98 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
99 |
public class IndentController {
|
|
|
100 |
|
| 23568 |
govind |
101 |
private static final Logger LOGGER = LogManager.getLogger(IndentController.class);
|
| 23796 |
amit.gupta |
102 |
private static final int WALLET_GATEWAY_ID = 8;
|
| 24406 |
amit.gupta |
103 |
private static final Set<Integer> defaultTags = new HashSet<Integer>(Arrays.asList(4));
|
| 23405 |
amit.gupta |
104 |
|
| 24231 |
amit.gupta |
105 |
private final List<OrderStatus> partnerPendingOrderList = Arrays.asList(OrderStatus.ACCEPTED,
|
|
|
106 |
OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH,
|
|
|
107 |
OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.SHIPPED_TO_LOGST,
|
|
|
108 |
OrderStatus.REACHED_DESTINATION_CITY);
|
| 25721 |
tejbeer |
109 |
|
| 26951 |
amit.gupta |
110 |
private static final int PLANNING_OPEN_DAY = 20;
|
|
|
111 |
private static final int PLANNING_CLOSE_DAY = 1;
|
|
|
112 |
|
| 30017 |
amit.gupta |
113 |
private static final String PO_TITLE_STRING = "Alert - Stock Arriving at SD Warehouse";
|
|
|
114 |
|
| 25547 |
amit.gupta |
115 |
@Autowired
|
|
|
116 |
WalletService walletService;
|
| 24231 |
amit.gupta |
117 |
|
| 23405 |
amit.gupta |
118 |
@Autowired
|
| 30017 |
amit.gupta |
119 |
BrandRegionMappingRepository brandRegionMappingRepository;
|
|
|
120 |
|
|
|
121 |
@Autowired
|
| 25721 |
tejbeer |
122 |
private JavaMailSender googleMailSender;
|
|
|
123 |
|
|
|
124 |
@Autowired
|
| 23405 |
amit.gupta |
125 |
private CookiesProcessor cookiesProcessor;
|
| 24231 |
amit.gupta |
126 |
|
| 23796 |
amit.gupta |
127 |
@Autowired
|
|
|
128 |
private UserWalletRepository userWalletRepository;
|
| 23785 |
amit.gupta |
129 |
|
| 23779 |
amit.gupta |
130 |
@Autowired
|
| 23796 |
amit.gupta |
131 |
private UserRepository userRepository;
|
|
|
132 |
|
|
|
133 |
@Autowired
|
| 23779 |
amit.gupta |
134 |
FofoStoreRepository fofoStoreRepository;
|
| 23405 |
amit.gupta |
135 |
|
|
|
136 |
@Autowired
|
| 23796 |
amit.gupta |
137 |
private OrderRepository orderRepository;
|
|
|
138 |
|
|
|
139 |
@Autowired
|
| 26846 |
tejbeer |
140 |
private UserAccountRepository userAccountRepository;
|
|
|
141 |
|
|
|
142 |
@Autowired
|
| 23405 |
amit.gupta |
143 |
private ItemRepository itemRepository;
|
|
|
144 |
|
|
|
145 |
@Autowired
|
| 23779 |
amit.gupta |
146 |
private StockAllocationService stockAllocationService;
|
|
|
147 |
|
|
|
148 |
@Autowired
|
|
|
149 |
private RetailerService retailerService;
|
| 23405 |
amit.gupta |
150 |
|
|
|
151 |
@Autowired
|
|
|
152 |
private TagListingRepository tagListingRepository;
|
|
|
153 |
|
|
|
154 |
@Autowired
|
|
|
155 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
156 |
|
|
|
157 |
@Autowired
|
| 23796 |
amit.gupta |
158 |
private PurchaseRepository purchaseRepository;
|
|
|
159 |
|
|
|
160 |
@Autowired
|
| 23405 |
amit.gupta |
161 |
private MVCResponseSender mvcResponseSender;
|
|
|
162 |
|
| 23785 |
amit.gupta |
163 |
@Autowired
|
| 25721 |
tejbeer |
164 |
private FocusedModelRepository focusedModelRepository;
|
|
|
165 |
|
|
|
166 |
@Autowired
|
|
|
167 |
private MonthlyPlannedRepository monthlyPlannedRepository;
|
|
|
168 |
|
|
|
169 |
@Autowired
|
|
|
170 |
private FofoOrderRepository fofoOrderRepository;
|
| 25732 |
tejbeer |
171 |
|
| 25721 |
tejbeer |
172 |
@Autowired
|
| 25732 |
tejbeer |
173 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
|
|
174 |
|
|
|
175 |
@Autowired
|
| 25721 |
tejbeer |
176 |
private PlannedDetailRepository plannedDetailRepository;
|
| 25732 |
tejbeer |
177 |
|
| 25721 |
tejbeer |
178 |
@Autowired
|
| 23785 |
amit.gupta |
179 |
RoleManager roleManager;
|
| 23405 |
amit.gupta |
180 |
|
| 25721 |
tejbeer |
181 |
@Autowired
|
| 27081 |
tejbeer |
182 |
PartnerTypeChangeRepository partnerTypeChangeRepository;
|
|
|
183 |
|
|
|
184 |
@Autowired
|
| 25736 |
tejbeer |
185 |
private Mongo mongoClient;
|
|
|
186 |
|
|
|
187 |
@Autowired
|
|
|
188 |
private InventoryService inventoryService;
|
|
|
189 |
|
|
|
190 |
@Autowired
|
| 31663 |
amit.gupta |
191 |
private CsService1 csService1;
|
|
|
192 |
|
|
|
193 |
@Autowired
|
| 26721 |
tejbeer |
194 |
private CsService csService;
|
| 25721 |
tejbeer |
195 |
|
| 26721 |
tejbeer |
196 |
@Autowired
|
|
|
197 |
private AuthRepository authRepository;
|
| 26846 |
tejbeer |
198 |
@Autowired
|
| 30017 |
amit.gupta |
199 |
WarehouseRepository warehouseRepository;
|
| 26846 |
tejbeer |
200 |
@Autowired
|
| 30017 |
amit.gupta |
201 |
private SuggestedPoRepository suggestedPoRepository;
|
| 26846 |
tejbeer |
202 |
|
|
|
203 |
@Autowired
|
|
|
204 |
private NotificationService notificationService;
|
|
|
205 |
|
| 27088 |
tejbeer |
206 |
@Autowired
|
|
|
207 |
private RegionRepository regionRepository;
|
|
|
208 |
|
|
|
209 |
@Autowired
|
|
|
210 |
private PartnerRegionRepository partnerRegionRepository;
|
|
|
211 |
|
| 27768 |
tejbeer |
212 |
@Autowired
|
|
|
213 |
private SaholicInventoryCISRepository saholicInventoryCISRepository;
|
|
|
214 |
|
|
|
215 |
@Autowired
|
|
|
216 |
private SaholicInventoryService saholicInventoryService;
|
|
|
217 |
|
| 30003 |
tejbeer |
218 |
@Autowired
|
|
|
219 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 30017 |
amit.gupta |
220 |
@Autowired
|
|
|
221 |
private SuggestedPoDetailRepository suggestedPoDetailRepository;
|
| 30003 |
tejbeer |
222 |
|
| 30664 |
amit.gupta |
223 |
@Autowired
|
|
|
224 |
SaholicCISTableRepository saholicCISTableRepository;
|
|
|
225 |
|
| 23779 |
amit.gupta |
226 |
@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
|
| 25721 |
tejbeer |
227 |
public String saveOpenIndent(HttpServletRequest request, Model model, @RequestParam int catalogId,
|
| 31317 |
tejbeer |
228 |
@RequestParam int itemQty, @RequestParam int fofoId) throws Exception {
|
| 27088 |
tejbeer |
229 |
if (fofoId == 0) {
|
|
|
230 |
|
|
|
231 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
232 |
fofoId = loginDetails.getFofoId();
|
|
|
233 |
|
| 26990 |
tejbeer |
234 |
}
|
| 27088 |
tejbeer |
235 |
|
| 26082 |
tejbeer |
236 |
LocalDate currentMonthDate = LocalDate.now();
|
|
|
237 |
MonthlyPlanned monthlyPlanned = null;
|
| 25721 |
tejbeer |
238 |
|
| 26951 |
amit.gupta |
239 |
if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(PLANNING_OPEN_DAY))) {
|
| 26082 |
tejbeer |
240 |
currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
|
| 26978 |
tejbeer |
241 |
monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
|
|
|
242 |
LOGGER.info("monthlyPlanned" + monthlyPlanned);
|
|
|
243 |
saveMonthlyPlanned(monthlyPlanned, fofoId, currentMonthDate, catalogId, itemQty);
|
| 26082 |
tejbeer |
244 |
}
|
| 31238 |
amit.gupta |
245 |
model.addAttribute("response1", mvcResponseSender.createResponseString(false));
|
| 26082 |
tejbeer |
246 |
return "response";
|
|
|
247 |
}
|
|
|
248 |
|
|
|
249 |
private void saveMonthlyPlanned(MonthlyPlanned monthlyPlanned, int fofoId, LocalDate currentMonthDate,
|
| 31317 |
tejbeer |
250 |
int catalogId, int itemQty) {
|
| 25721 |
tejbeer |
251 |
if (monthlyPlanned == null) {
|
|
|
252 |
monthlyPlanned = new MonthlyPlanned();
|
| 26082 |
tejbeer |
253 |
monthlyPlanned.setFofoId(fofoId);
|
|
|
254 |
monthlyPlanned.setYearMonth(currentMonthDate);
|
| 25721 |
tejbeer |
255 |
monthlyPlannedRepository.persist(monthlyPlanned);
|
|
|
256 |
PlannedDetail pd = new PlannedDetail();
|
|
|
257 |
pd.setCatalogId(catalogId);
|
|
|
258 |
pd.setPlannedId(monthlyPlanned.getId());
|
|
|
259 |
pd.setQuantity(itemQty);
|
|
|
260 |
pd.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
261 |
plannedDetailRepository.persist(pd);
|
|
|
262 |
|
| 23786 |
amit.gupta |
263 |
} else {
|
| 25721 |
tejbeer |
264 |
PlannedDetail plannedDetail = plannedDetailRepository.selectByPlannedIdCatalogId(monthlyPlanned.getId(),
|
|
|
265 |
catalogId);
|
|
|
266 |
if (plannedDetail == null) {
|
|
|
267 |
plannedDetail = new PlannedDetail();
|
|
|
268 |
plannedDetail.setCatalogId(catalogId);
|
|
|
269 |
plannedDetail.setPlannedId(monthlyPlanned.getId());
|
|
|
270 |
plannedDetail.setQuantity(itemQty);
|
|
|
271 |
plannedDetail.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
272 |
plannedDetailRepository.persist(plannedDetail);
|
|
|
273 |
} else if (itemQty == 0) {
|
|
|
274 |
plannedDetailRepository.delete(plannedDetail);
|
|
|
275 |
|
|
|
276 |
} else {
|
|
|
277 |
plannedDetail.setCatalogId(catalogId);
|
|
|
278 |
plannedDetail.setQuantity(itemQty);
|
|
|
279 |
plannedDetail.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
280 |
}
|
|
|
281 |
|
| 23785 |
amit.gupta |
282 |
}
|
| 25721 |
tejbeer |
283 |
|
|
|
284 |
}
|
|
|
285 |
|
|
|
286 |
@RequestMapping(value = "/open-indent/confirm", method = RequestMethod.POST)
|
| 26748 |
tejbeer |
287 |
public String confirmOpenIndent(HttpServletRequest request,
|
| 31317 |
tejbeer |
288 |
@RequestParam(required = false, defaultValue = "0") int fofoId, Model model) throws Exception {
|
| 26748 |
tejbeer |
289 |
|
|
|
290 |
if (fofoId == 0) {
|
|
|
291 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
292 |
fofoId = loginDetails.getFofoId();
|
|
|
293 |
}
|
| 25721 |
tejbeer |
294 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
| 26748 |
tejbeer |
295 |
|
| 26951 |
amit.gupta |
296 |
LocalDate currentDate = LocalDate.now();
|
|
|
297 |
LocalDate planningMonthDate = null;
|
| 26082 |
tejbeer |
298 |
MonthlyPlanned monthlyPlanned = null;
|
| 26951 |
amit.gupta |
299 |
if (currentDate.isAfter(currentDate.withDayOfMonth(PLANNING_OPEN_DAY))) {
|
|
|
300 |
planningMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
|
|
|
301 |
monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, planningMonthDate);
|
| 25721 |
tejbeer |
302 |
|
| 26082 |
tejbeer |
303 |
confirmMonthlyPlanned(monthlyPlanned, customRetailer, fofoId);
|
|
|
304 |
}
|
| 31238 |
amit.gupta |
305 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 26082 |
tejbeer |
306 |
|
|
|
307 |
return "response";
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
private void confirmMonthlyPlanned(MonthlyPlanned monthlyPlanned, CustomRetailer customRetailer, int fofoId)
|
|
|
311 |
throws Exception {
|
| 25721 |
tejbeer |
312 |
List<PlannedDetail> plannedDetails = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId());
|
|
|
313 |
|
|
|
314 |
List<PlannedModel> plannedModel = new ArrayList<>();
|
|
|
315 |
for (PlannedDetail plannedDetail : plannedDetails) {
|
|
|
316 |
|
|
|
317 |
List<Item> items = itemRepository.selectAllByCatalogItemId(plannedDetail.getCatalogId());
|
|
|
318 |
String itemDesription = items.get(0).getItemDescriptionNoColor();
|
|
|
319 |
PlannedModel pm = new PlannedModel();
|
|
|
320 |
pm.setItemDescription(itemDesription);
|
|
|
321 |
pm.setStoreName(customRetailer.getBusinessName());
|
|
|
322 |
pm.setQty(plannedDetail.getQuantity());
|
| 26082 |
tejbeer |
323 |
pm.setFofoId(fofoId);
|
| 25721 |
tejbeer |
324 |
plannedModel.add(pm);
|
|
|
325 |
LOGGER.info("plannedModel" + plannedModel);
|
|
|
326 |
|
| 23785 |
amit.gupta |
327 |
}
|
| 26978 |
tejbeer |
328 |
List<String> ccemails = new ArrayList<>();
|
|
|
329 |
LOGGER.info("ccemails" + ccemails);
|
|
|
330 |
Map<EscalationType, String> emailEsclationType = csService.getAuthUserAndEsclationTypeByPartnerId(fofoId);
|
|
|
331 |
LOGGER.info("emailEsclationType" + emailEsclationType);
|
| 31636 |
tejbeer |
332 |
if (emailEsclationType.get(EscalationType.L1) != null) {
|
|
|
333 |
ccemails.add(emailEsclationType.get(EscalationType.L1));
|
|
|
334 |
}
|
|
|
335 |
|
|
|
336 |
if (emailEsclationType.get(EscalationType.L2) != null) {
|
|
|
337 |
|
|
|
338 |
ccemails.add(emailEsclationType.get(EscalationType.L2));
|
|
|
339 |
}
|
| 26978 |
tejbeer |
340 |
LOGGER.info("ccemails" + ccemails);
|
|
|
341 |
List<String> bccemails = new ArrayList<>();
|
|
|
342 |
bccemails.add(emailEsclationType.get(EscalationType.L3));
|
|
|
343 |
LOGGER.info("bccemails" + bccemails);
|
| 25721 |
tejbeer |
344 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
345 |
Arrays.asList("Partner Id", "Partner Name", "Model Name", "Qty"),
|
|
|
346 |
plannedModel.stream()
|
|
|
347 |
.map(x -> Arrays.asList(x.getFofoId(), x.getStoreName(), x.getItemDescription(), x.getQty()))
|
|
|
348 |
.collect(Collectors.toList()));
|
|
|
349 |
LOGGER.info("baos" + baos);
|
| 31317 |
tejbeer |
350 |
Utils.sendMailWithAttachments(googleMailSender, new String[] { customRetailer.getEmail() },
|
| 26978 |
tejbeer |
351 |
ccemails.toArray(new String[ccemails.size()]), bccemails.toArray(new String[bccemails.size()]),
|
| 25721 |
tejbeer |
352 |
"Planned Indent", "PFA",
|
| 31317 |
tejbeer |
353 |
new Attachment[] { new Attachment("PlannedIndent.csv", new ByteArrayResource(baos.toByteArray())), });
|
| 25721 |
tejbeer |
354 |
|
| 23405 |
amit.gupta |
355 |
}
|
|
|
356 |
|
| 24231 |
amit.gupta |
357 |
@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
|
|
|
358 |
public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
|
| 31317 |
tejbeer |
359 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
|
|
360 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
|
| 25702 |
amit.gupta |
361 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
362 |
Set<Integer> roleIds = loginDetails.getRoleIds();
|
| 24231 |
amit.gupta |
363 |
LOGGER.info("Counter size is {}", counterSize);
|
|
|
364 |
LOGGER.info("Fofo Id is {}", fofoId);
|
| 30426 |
tejbeer |
365 |
|
| 25721 |
tejbeer |
366 |
if (roleManager.isAdmin(roleIds) || loginDetails.getFofoId() == fofoId) {
|
| 24231 |
amit.gupta |
367 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
|
|
368 |
.collect(Collectors.toList());
|
| 30426 |
tejbeer |
369 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
370 |
Map<Integer, CustomRetailer> crm = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
371 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
372 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 24232 |
amit.gupta |
373 |
List<StockAllocationModel> stockAllocationList = stockAllocationService.getStockAllocation(counterSize,
|
|
|
374 |
true);
|
|
|
375 |
Map<Integer, Integer> modelStockAllocationMap = stockAllocationList.stream()
|
|
|
376 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
|
| 23405 |
amit.gupta |
377 |
|
| 24232 |
amit.gupta |
378 |
Map<String, Integer> catalogUserQtyMap = new HashMap<>();
|
| 25702 |
amit.gupta |
379 |
currentInventorySnapshotRepository.selectByFofoId(fofoId).stream().forEach(x -> {
|
| 24232 |
amit.gupta |
380 |
int retailerId = x.getFofoId();
|
|
|
381 |
int catalogId;
|
|
|
382 |
try {
|
|
|
383 |
catalogId = itemRepository.selectById(x.getItemId()).getCatalogItemId();
|
|
|
384 |
String key = catalogId + "-" + retailerId;
|
|
|
385 |
if (!catalogUserQtyMap.containsKey(key)) {
|
|
|
386 |
catalogUserQtyMap.put(key, 0);
|
|
|
387 |
}
|
|
|
388 |
catalogUserQtyMap.put(key, catalogUserQtyMap.get(key) + x.getAvailability());
|
|
|
389 |
} catch (ProfitMandiBusinessException e) {
|
|
|
390 |
// TODO Auto-generated catch block
|
|
|
391 |
throw new RuntimeException(e);
|
| 24231 |
amit.gupta |
392 |
}
|
|
|
393 |
});
|
| 23779 |
amit.gupta |
394 |
|
| 24231 |
amit.gupta |
395 |
List<Order> inTransitOrders = orderRepository.selectOrders(fofoIds, partnerPendingOrderList);
|
| 24232 |
amit.gupta |
396 |
Map<String, Integer> catalogUserInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> {
|
|
|
397 |
try {
|
|
|
398 |
return itemRepository.selectById(x.getLineItem().getItemId()).getCatalogItemId() + "-"
|
|
|
399 |
+ x.getRetailerId();
|
|
|
400 |
} catch (ProfitMandiBusinessException e) {
|
|
|
401 |
// TODO Auto-generated catch block
|
|
|
402 |
return "";
|
|
|
403 |
}
|
|
|
404 |
}, Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
| 23779 |
amit.gupta |
405 |
|
| 24232 |
amit.gupta |
406 |
Map<String, CatalogListingModel> catalogListingMap = new HashMap<>();
|
|
|
407 |
|
|
|
408 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
|
|
409 |
Iterator<TagListing> iterator = tagListings.iterator();
|
| 24231 |
amit.gupta |
410 |
while (iterator.hasNext()) {
|
|
|
411 |
TagListing tagListing = iterator.next();
|
|
|
412 |
Item item = itemRepository.selectById(tagListing.getItemId());
|
| 24232 |
amit.gupta |
413 |
int catalogId = item.getCatalogItemId();
|
| 24231 |
amit.gupta |
414 |
if (item.getCategoryId() != 10006) {
|
|
|
415 |
continue;
|
|
|
416 |
}
|
| 23779 |
amit.gupta |
417 |
|
| 24232 |
amit.gupta |
418 |
int catalogStockAllocationQuantity = modelStockAllocationMap.containsKey(catalogId)
|
|
|
419 |
? modelStockAllocationMap.get(catalogId)
|
|
|
420 |
: 0;
|
|
|
421 |
for (int retailerId : fofoIds) {
|
|
|
422 |
String key = catalogId + "-" + retailerId;
|
|
|
423 |
if (catalogListingMap.containsKey(key)) {
|
|
|
424 |
continue;
|
| 24231 |
amit.gupta |
425 |
}
|
| 24232 |
amit.gupta |
426 |
int catalogInTransit = catalogUserInTransit.containsKey(key) ? catalogUserInTransit.get(key) : 0;
|
|
|
427 |
int catalogInStock = catalogUserQtyMap.containsKey(key) ? catalogUserQtyMap.get(key) : 0;
|
|
|
428 |
if (catalogInTransit + catalogInStock == 0 && catalogStockAllocationQuantity == 0) {
|
|
|
429 |
continue;
|
|
|
430 |
}
|
|
|
431 |
CatalogListingModel catalogListingModel = new CatalogListingModel();
|
|
|
432 |
catalogListingModel.setFofoId(retailerId);
|
|
|
433 |
catalogListingModel.setModelName(item.getModelName());
|
|
|
434 |
catalogListingModel.setModelNumber(item.getModelNumber());
|
|
|
435 |
catalogListingModel.setCatalogId(catalogId);
|
|
|
436 |
catalogListingModel.setDp(tagListing.getSellingPrice());
|
|
|
437 |
catalogListingModel.setMop(tagListing.getMop());
|
|
|
438 |
catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
|
|
|
439 |
catalogListingModel.setAllocatedQuantity(catalogStockAllocationQuantity);
|
|
|
440 |
catalogListingModel.setInTransitQuantity(catalogInTransit);
|
|
|
441 |
catalogListingModel
|
|
|
442 |
.setToBeOrdered(catalogStockAllocationQuantity - catalogInTransit - catalogInStock);
|
| 24233 |
amit.gupta |
443 |
catalogListingModel.setStockInHand(catalogInStock);
|
| 24232 |
amit.gupta |
444 |
catalogListingModel.setBrand(item.getBrand());
|
|
|
445 |
catalogListingModel.setModelName(item.getModelName());
|
|
|
446 |
catalogListingModel.setModelNumber(item.getModelNumber());
|
|
|
447 |
catalogListingModel.setCategoryId(item.getCategoryId());
|
|
|
448 |
catalogListingMap.put(key, catalogListingModel);
|
| 23405 |
amit.gupta |
449 |
}
|
|
|
450 |
}
|
| 25853 |
amit.gupta |
451 |
List<List<?>> listOfRows = new ArrayList<>();
|
| 24231 |
amit.gupta |
452 |
for (CatalogListingModel clm : catalogListingMap.values()) {
|
| 30426 |
tejbeer |
453 |
CustomRetailer cr = crm.get(clm.getFofoId());
|
| 24349 |
amit.gupta |
454 |
listOfRows.add(Arrays.asList(cr.getPartnerId(), cr.getBusinessName(), clm.getCatalogId(),
|
|
|
455 |
clm.getBrand(), clm.getModelName(), clm.getModelNumber(), clm.getDp(), clm.getMop(),
|
|
|
456 |
clm.getAllocatedQuantity(), clm.getInTransitQuantity(), clm.getStockInHand(),
|
|
|
457 |
clm.getToBeOrdered()));
|
| 24231 |
amit.gupta |
458 |
}
|
| 24349 |
amit.gupta |
459 |
ByteArrayOutputStream baos = FileUtil
|
|
|
460 |
.getCSVByteStream(
|
|
|
461 |
Arrays.asList("StoreId", "StoreName", "Catalog Id", "Brand", "Model Name", "Model Number",
|
|
|
462 |
"DP", "MOP", "Allocated Quantity", "In Transit", "Stock In hand", "Shortage"),
|
|
|
463 |
listOfRows);
|
| 24231 |
amit.gupta |
464 |
HttpHeaders headers = new HttpHeaders();
|
|
|
465 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
466 |
headers.set("Content-disposition", "inline; filename=retailer-allocation.csv");
|
| 24232 |
amit.gupta |
467 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(baos.toByteArray()), headers,
|
|
|
468 |
HttpStatus.OK);
|
| 23405 |
amit.gupta |
469 |
}
|
| 24231 |
amit.gupta |
470 |
return null;
|
| 24232 |
amit.gupta |
471 |
|
| 23405 |
amit.gupta |
472 |
}
|
|
|
473 |
|
| 24349 |
amit.gupta |
474 |
@RequestMapping(value = "/itemsByCatalogId")
|
|
|
475 |
public String getItemsByCatalogId(HttpServletRequest request, Model model,
|
| 31317 |
tejbeer |
476 |
@RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
|
| 25378 |
tejbeer |
477 |
throws ProfitMandiBusinessException {
|
| 24410 |
amit.gupta |
478 |
if (catalogId == 0) {
|
|
|
479 |
catalogId = itemRepository.selectById(itemId).getCatalogItemId();
|
|
|
480 |
}
|
| 24349 |
amit.gupta |
481 |
List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
|
| 24414 |
amit.gupta |
482 |
LOGGER.info("Items {}", items);
|
| 25378 |
tejbeer |
483 |
Map<Integer, String> itemsColorMap = items.stream().filter(x -> x.getColorNatural().startsWith("f_"))
|
|
|
484 |
.collect(Collectors.toMap(Item::getId, Item::getColor));
|
| 24413 |
amit.gupta |
485 |
Map<Integer, TagListing> tagsMap = tagListingRepository
|
|
|
486 |
.selectByItemIdsAndTagIds(items.stream().map(x -> x.getId()).collect(Collectors.toSet()), defaultTags)
|
| 25378 |
tejbeer |
487 |
.stream().collect(Collectors.toMap(TagListing::getItemId, x -> x));
|
| 24414 |
amit.gupta |
488 |
LOGGER.info("Items color map {}", itemsColorMap);
|
| 24349 |
amit.gupta |
489 |
JSONArray response = new JSONArray();
|
| 24413 |
amit.gupta |
490 |
itemsColorMap.keySet().stream().forEach(x -> {
|
| 25378 |
tejbeer |
491 |
response.put(new JSONObject().put("color", itemsColorMap.get(x)).put("id", x).put("active",
|
|
|
492 |
tagsMap.get(x) == null ? false : tagsMap.get(x).isActive()));
|
| 24349 |
amit.gupta |
493 |
});
|
| 31238 |
amit.gupta |
494 |
model.addAttribute("response1", response.toString());
|
| 24349 |
amit.gupta |
495 |
return "response";
|
| 24410 |
amit.gupta |
496 |
|
| 24349 |
amit.gupta |
497 |
}
|
|
|
498 |
|
| 28055 |
tejbeer |
499 |
@RequestMapping(value = "/hotdealsitemsByCatalogId")
|
|
|
500 |
public String getHotdealsitemsByCatalogId(HttpServletRequest request, Model model,
|
| 31317 |
tejbeer |
501 |
@RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
|
| 28055 |
tejbeer |
502 |
throws ProfitMandiBusinessException {
|
|
|
503 |
if (catalogId == 0) {
|
|
|
504 |
catalogId = itemRepository.selectById(itemId).getCatalogItemId();
|
|
|
505 |
}
|
|
|
506 |
List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
|
|
|
507 |
LOGGER.info("Items {}", items);
|
|
|
508 |
Map<Integer, String> itemsColorMap = items.stream().filter(x -> x.getColorNatural().startsWith("f_"))
|
|
|
509 |
.collect(Collectors.toMap(Item::getId, Item::getColor));
|
|
|
510 |
Map<Integer, TagListing> tagsMap = tagListingRepository
|
|
|
511 |
.selectByItemIdsAndTagIds(items.stream().map(x -> x.getId()).collect(Collectors.toSet()), defaultTags)
|
|
|
512 |
.stream().collect(Collectors.toMap(TagListing::getItemId, x -> x));
|
|
|
513 |
LOGGER.info("Items color map {}", itemsColorMap);
|
|
|
514 |
JSONArray response = new JSONArray();
|
|
|
515 |
itemsColorMap.keySet().stream().forEach(x -> {
|
|
|
516 |
response.put(new JSONObject().put("color", itemsColorMap.get(x)).put("id", x).put("hotDeals",
|
|
|
517 |
tagsMap.get(x) == null ? false : tagsMap.get(x).isHotDeals()));
|
|
|
518 |
});
|
| 31238 |
amit.gupta |
519 |
model.addAttribute("response1", response.toString());
|
| 28055 |
tejbeer |
520 |
return "response";
|
|
|
521 |
|
|
|
522 |
}
|
|
|
523 |
|
| 30664 |
amit.gupta |
524 |
private List<Order> filterValidOrders(List<Order> lastOrdersList) {
|
|
|
525 |
int orderRemovedCount = 0;
|
|
|
526 |
Iterator<Order> orderIterator = lastOrdersList.iterator();
|
|
|
527 |
while (orderIterator.hasNext()) {
|
|
|
528 |
Order o = orderIterator.next();
|
|
|
529 |
if (o.getInvoiceNumber() != null) {
|
|
|
530 |
try {
|
|
|
531 |
purchaseRepository.selectByPurchaseReferenceAndFofoId(o.getInvoiceNumber(), o.getRetailerId());
|
|
|
532 |
orderIterator.remove();
|
|
|
533 |
orderRemovedCount++;
|
|
|
534 |
} catch (Exception e) {
|
|
|
535 |
|
|
|
536 |
}
|
|
|
537 |
}
|
|
|
538 |
}
|
|
|
539 |
LOGGER.info("Order removed count is {}", orderRemovedCount);
|
|
|
540 |
return lastOrdersList;
|
|
|
541 |
}
|
|
|
542 |
|
| 31317 |
tejbeer |
543 |
// Clean up the saholic cis table
|
| 30664 |
amit.gupta |
544 |
@RequestMapping(value = "/indent/confirm-pause", method = RequestMethod.POST)
|
| 30668 |
amit.gupta |
545 |
public String updateTagListing(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
|
| 30664 |
amit.gupta |
546 |
throws Exception {
|
|
|
547 |
JSONArray jsonArray = new JSONArray(jsonArrayString);
|
|
|
548 |
for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
549 |
JSONObject obj = jsonArray.getJSONObject(i);
|
|
|
550 |
|
|
|
551 |
TagListing tl = tagListingRepository.selectByItemId(obj.getInt("id"));
|
|
|
552 |
if (tl == null) {
|
|
|
553 |
continue;
|
|
|
554 |
} else {
|
|
|
555 |
tl.setActive(obj.getBoolean("active"));
|
| 30668 |
amit.gupta |
556 |
if (!tl.isActive()) {
|
| 31317 |
tejbeer |
557 |
saholicCISTableRepository.selectAllByItemId(tl.getItemId()).stream()
|
|
|
558 |
.forEach(x -> saholicCISTableRepository.delete(x));
|
| 30668 |
amit.gupta |
559 |
}
|
| 30664 |
amit.gupta |
560 |
}
|
|
|
561 |
}
|
| 31238 |
amit.gupta |
562 |
model.addAttribute("response1", true);
|
| 30664 |
amit.gupta |
563 |
return "response";
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
@RequestMapping(value = "/indent/confirm-hotdeals-pause", method = RequestMethod.POST)
|
|
|
567 |
public String hotdealUpdate(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
|
|
|
568 |
throws Exception {
|
|
|
569 |
JSONArray jsonArray = new JSONArray(jsonArrayString);
|
|
|
570 |
for (int i = 0; i < jsonArray.length(); i++) {
|
|
|
571 |
JSONObject obj = jsonArray.getJSONObject(i);
|
|
|
572 |
|
|
|
573 |
TagListing tl = tagListingRepository.selectByItemId(obj.getInt("id"));
|
|
|
574 |
if (tl == null) {
|
|
|
575 |
continue;
|
|
|
576 |
} else {
|
|
|
577 |
tl.setHotDeals(obj.getBoolean("hotDeals"));
|
|
|
578 |
tagListingRepository.persist(tl);
|
|
|
579 |
}
|
|
|
580 |
}
|
| 31238 |
amit.gupta |
581 |
model.addAttribute("response1", true);
|
| 30664 |
amit.gupta |
582 |
return "response";
|
|
|
583 |
}
|
|
|
584 |
|
|
|
585 |
@RequestMapping(value = "/indent/create-po", method = RequestMethod.POST)
|
|
|
586 |
public String raisePO(HttpServletRequest request, Model model) throws Exception {
|
|
|
587 |
boolean success = false;
|
|
|
588 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
589 |
int fofoId = loginDetails.getFofoId();
|
|
|
590 |
List<ItemPriceQuantity> itemQuantities = this.getItemQuantities(fofoId);
|
|
|
591 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
|
|
592 |
Client userClient = new UserClient().getClient();
|
|
|
593 |
double totalAmount = itemQuantities.stream().mapToDouble(x -> x.getQty() * x.getPrice()).sum();
|
|
|
594 |
|
|
|
595 |
if (totalAmount > 0) {
|
|
|
596 |
userClient.addItemPricingToCart(customRetailer.getCartId(), itemQuantities);
|
|
|
597 |
User user = userRepository.selectById(loginDetails.getFofoId());
|
|
|
598 |
userClient = new UserClient().getClient();
|
|
|
599 |
LOGGER.info("Setting wallet amount in cart");
|
|
|
600 |
long transactionId = userClient.createOrders(user.getActiveCartId(), "", 0, "", 0, loginDetails.getFofoId(),
|
|
|
601 |
7890, OrderSource.WEBSITE.getValue(), true);
|
|
|
602 |
LOGGER.info("Creating wallet payment for transactionId - {}", transactionId);
|
|
|
603 |
createPayment(user, totalAmount, transactionId);
|
|
|
604 |
TransactionService.Client transactionClient = new TransactionClient().getClient();
|
|
|
605 |
transactionClient.changeTransactionStatus(transactionId, TransactionStatus.AUTHORIZED,
|
|
|
606 |
"Payment received for the order", PickUpType.RUNNER.getValue(), OrderType.B2B, OrderSource.WEBSITE);
|
|
|
607 |
transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
|
|
|
608 |
"Paid fully through wallet", PickUpType.RUNNER.getValue(), OrderType.B2B, OrderSource.WEBSITE);
|
|
|
609 |
LOGGER.info("Successfully created transaction: " + transactionId + " for amount: " + totalAmount);
|
|
|
610 |
transactionClient = new TransactionClient().getClient();
|
|
|
611 |
transactionClient.markOrderForRegisteredGstInvoice(Collections.singletonList(Long.valueOf(transactionId)));
|
|
|
612 |
try {
|
|
|
613 |
transactionClient.enqueueTransactionInfoEmail(transactionId);
|
|
|
614 |
} catch (Exception e1) {
|
|
|
615 |
e1.printStackTrace();
|
|
|
616 |
LOGGER.error("Unable to update status of transaction. Thrift Exception:", e1);
|
|
|
617 |
}
|
|
|
618 |
resetCart(transactionClient.getTransaction(transactionId));
|
|
|
619 |
}
|
| 31238 |
amit.gupta |
620 |
model.addAttribute("response1", mvcResponseSender.createResponseString(success));
|
| 30664 |
amit.gupta |
621 |
return "response";
|
|
|
622 |
}
|
|
|
623 |
|
|
|
624 |
private void createPayment(User user, double totalAmount, long transactionId)
|
|
|
625 |
throws NumberFormatException, PaymentException, TException {
|
|
|
626 |
List<Attribute> paymentAttributes = new ArrayList<Attribute>();
|
|
|
627 |
in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
|
|
|
628 |
paymentAttributes.add(new Attribute("payMethod", "7890"));
|
|
|
629 |
long paymentId = paymentClient.createPayment(user.getId(), totalAmount, WALLET_GATEWAY_ID, transactionId,
|
|
|
630 |
false);
|
|
|
631 |
paymentClient.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null,
|
|
|
632 |
PaymentStatus.SUCCESS, null, paymentAttributes);
|
|
|
633 |
}
|
|
|
634 |
|
| 23405 |
amit.gupta |
635 |
@RequestMapping(value = "/indent/loadIndent")
|
| 23785 |
amit.gupta |
636 |
public String loadOpenIndent(HttpServletRequest request, Model model,
|
| 31317 |
tejbeer |
637 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
|
|
638 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
|
| 25702 |
amit.gupta |
639 |
|
|
|
640 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
641 |
Set<Integer> roleIds = loginDetails.getRoleIds();
|
| 23785 |
amit.gupta |
642 |
LOGGER.info("Counter size is {}", counterSize);
|
|
|
643 |
LOGGER.info("Fofo Id is {}", fofoId);
|
| 25736 |
tejbeer |
644 |
boolean isAdmin = roleManager.isAdmin(roleIds);
|
| 25796 |
tejbeer |
645 |
|
| 25797 |
tejbeer |
646 |
List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
647 |
.collect(Collectors.toList());
|
|
|
648 |
|
| 25796 |
tejbeer |
649 |
Map<String, Object> equalsMap = new HashMap<>();
|
|
|
650 |
equalsMap.put("categoryId", 10006);
|
| 25797 |
tejbeer |
651 |
equalsMap.put("brand", brands);
|
| 25796 |
tejbeer |
652 |
Map<String, List<?>> notEqualsMap = new HashMap<>();
|
|
|
653 |
|
|
|
654 |
Map<String, List<?>> notEqualsJoinMap = new HashMap<>();
|
|
|
655 |
Map<Integer, Integer> currentStockMap;
|
|
|
656 |
|
| 25721 |
tejbeer |
657 |
if (!isAdmin && fofoId == 0) {
|
| 23786 |
amit.gupta |
658 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
| 25796 |
tejbeer |
659 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
|
|
660 |
equalsStockJoinMap.put("fofoId", fofoId);
|
|
|
661 |
currentStockMap = itemRepository
|
| 25800 |
tejbeer |
662 |
.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
|
|
|
663 |
equalsStockJoinMap, notEqualsJoinMap, "availability")
|
| 25796 |
tejbeer |
664 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
| 25797 |
tejbeer |
665 |
LOGGER.info("currentStock");
|
| 23786 |
amit.gupta |
666 |
} else {
|
|
|
667 |
if (fofoId == 0) {
|
| 25796 |
tejbeer |
668 |
|
|
|
669 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
|
|
670 |
equalsStockJoinMap.put("fofoId", fofoId);
|
|
|
671 |
|
|
|
672 |
currentStockMap = itemRepository
|
| 25800 |
tejbeer |
673 |
.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
|
| 25796 |
tejbeer |
674 |
equalsStockJoinMap, notEqualsJoinMap, "availability")
|
|
|
675 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
676 |
|
| 23779 |
amit.gupta |
677 |
} else {
|
| 25796 |
tejbeer |
678 |
|
|
|
679 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
|
|
680 |
equalsStockJoinMap.put("fofoId", fofoId);
|
|
|
681 |
|
|
|
682 |
currentStockMap = itemRepository
|
| 25800 |
tejbeer |
683 |
.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
|
| 25796 |
tejbeer |
684 |
equalsStockJoinMap, notEqualsJoinMap, "availability")
|
|
|
685 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
686 |
|
| 23405 |
amit.gupta |
687 |
}
|
| 23786 |
amit.gupta |
688 |
}
|
| 25796 |
tejbeer |
689 |
|
|
|
690 |
LOGGER.info("currentStock" + currentStockMap);
|
| 25797 |
tejbeer |
691 |
|
| 23796 |
amit.gupta |
692 |
Map<Integer, Integer> itemsInTransit = null;
|
| 23855 |
amit.gupta |
693 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
| 25702 |
amit.gupta |
694 |
if (!isAdmin) {
|
| 23786 |
amit.gupta |
695 |
tagListings = new ArrayList<>(tagListings);
|
| 28055 |
tejbeer |
696 |
List<Order> inTransitOrders = orderRepository.selectPendingGrnOrder(fofoId,
|
|
|
697 |
OrderRepository.validOrderStatusList);
|
| 23796 |
amit.gupta |
698 |
inTransitOrders = this.filterValidOrders(inTransitOrders);
|
|
|
699 |
itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
700 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
701 |
} else {
|
|
|
702 |
itemsInTransit = new HashMap<>();
|
| 23786 |
amit.gupta |
703 |
}
|
| 25797 |
tejbeer |
704 |
|
| 23796 |
amit.gupta |
705 |
int totalPcs = 0;
|
| 25797 |
tejbeer |
706 |
|
| 23796 |
amit.gupta |
707 |
float totalAmount = 0;
|
| 24231 |
amit.gupta |
708 |
Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
|
| 27088 |
tejbeer |
709 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
|
|
|
710 |
.collect(Collectors.toList());
|
| 25796 |
tejbeer |
711 |
|
| 27088 |
tejbeer |
712 |
LOGGER.info("regionIds" + regionIds);
|
|
|
713 |
Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAllByRegionIds(regionIds).stream()
|
|
|
714 |
.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
|
|
|
715 |
LOGGER.info("focusedModelMap" + focusedModelMap);
|
| 26956 |
amit.gupta |
716 |
LocalDate planningMonthDate = null;
|
| 26082 |
tejbeer |
717 |
MonthlyPlanned monthlyPlanned = null;
|
| 26176 |
tejbeer |
718 |
List<Integer> fofoOrderIds = null;
|
| 26082 |
tejbeer |
719 |
LOGGER.info("localDate" + LocalDate.now());
|
| 26951 |
amit.gupta |
720 |
if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(PLANNING_OPEN_DAY))) {
|
| 26956 |
amit.gupta |
721 |
planningMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
|
|
|
722 |
monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, planningMonthDate);
|
| 26082 |
tejbeer |
723 |
LOGGER.info("monthlyPlanned2" + monthlyPlanned);
|
| 26176 |
tejbeer |
724 |
fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
|
| 31317 |
tejbeer |
725 |
LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
|
| 26176 |
tejbeer |
726 |
.collect(Collectors.toList());
|
| 26082 |
tejbeer |
727 |
|
|
|
728 |
model.addAttribute("planningMonth", LocalDate.now().plusMonths(1).getMonth());
|
| 26951 |
amit.gupta |
729 |
} else {
|
| 26956 |
amit.gupta |
730 |
planningMonthDate = LocalDate.now().withDayOfMonth(1);
|
| 26176 |
tejbeer |
731 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 26956 |
amit.gupta |
732 |
monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, planningMonthDate);
|
|
|
733 |
model.addAttribute("planningMonth", planningMonthDate.getMonth());
|
| 26176 |
tejbeer |
734 |
model.addAttribute("mtd", true);
|
| 26131 |
tejbeer |
735 |
model.addAttribute("freezed", true);
|
| 26176 |
tejbeer |
736 |
fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
|
| 31317 |
tejbeer |
737 |
curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX)).stream().map(x -> x.getId())
|
| 26176 |
tejbeer |
738 |
.collect(Collectors.toList());
|
| 26082 |
tejbeer |
739 |
LOGGER.info("monthlyPlanned1" + monthlyPlanned);
|
| 26978 |
tejbeer |
740 |
}
|
| 26082 |
tejbeer |
741 |
|
| 25721 |
tejbeer |
742 |
Map<Integer, Integer> plannedDetailMap = null;
|
|
|
743 |
if (monthlyPlanned != null) {
|
|
|
744 |
plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
|
|
|
745 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
|
|
|
746 |
|
|
|
747 |
}
|
| 25797 |
tejbeer |
748 |
LOGGER.info("plannedDetailMap" + plannedDetailMap);
|
| 26176 |
tejbeer |
749 |
|
| 25796 |
tejbeer |
750 |
LOGGER.info("fofoOrderIds" + fofoOrderIds);
|
|
|
751 |
Map<String, Object> equalsJoinMap = new HashMap<>();
|
| 26618 |
tejbeer |
752 |
|
| 25796 |
tejbeer |
753 |
equalsJoinMap.put("orderId", fofoOrderIds);
|
| 26618 |
tejbeer |
754 |
Map<Integer, Integer> last15daysMap = null;
|
| 26748 |
tejbeer |
755 |
if (fofoOrderIds != null && !fofoOrderIds.isEmpty()) {
|
| 24231 |
amit.gupta |
756 |
|
| 26618 |
tejbeer |
757 |
last15daysMap = itemRepository
|
|
|
758 |
.selectItems(FofoOrderItem.class, "id", "itemId", equalsMap, notEqualsMap, equalsJoinMap,
|
|
|
759 |
notEqualsJoinMap, "quantity")
|
|
|
760 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
761 |
}
|
| 25796 |
tejbeer |
762 |
LOGGER.info("last15daysMap" + last15daysMap);
|
| 25721 |
tejbeer |
763 |
|
| 25796 |
tejbeer |
764 |
Map<Integer, TagListing> taglistingMap = tagListings.stream()
|
|
|
765 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
|
|
766 |
List<Item> items = itemRepository.selectByIds(taglistingMap.keySet());
|
|
|
767 |
Map<Integer, List<Item>> catalogIdItemMap = items.stream().collect(
|
|
|
768 |
Collectors.groupingBy(x -> x.getCatalogItemId(), Collectors.mapping(y -> y, Collectors.toList())));
|
| 25797 |
tejbeer |
769 |
LOGGER.info("catalogIdItemMap");
|
| 24231 |
amit.gupta |
770 |
|
| 25796 |
tejbeer |
771 |
Map<String, Object> equalsItemJoinMap = new HashMap<>();
|
| 25797 |
tejbeer |
772 |
equalsItemJoinMap.put("active", 1);
|
| 28897 |
amit.gupta |
773 |
List<IntegerIdAggregateValue> tagListingCatalogIds = itemRepository.selectItems(TagListing.class, "id",
|
| 25800 |
tejbeer |
774 |
"itemId", equalsMap, notEqualsMap, equalsItemJoinMap, notEqualsJoinMap, "tagId");
|
| 25797 |
tejbeer |
775 |
LOGGER.info("tagListingCatalogIds");
|
| 28897 |
amit.gupta |
776 |
for (IntegerIdAggregateValue catalogIdAggregateValue : tagListingCatalogIds) {
|
| 25796 |
tejbeer |
777 |
int catalogId = catalogIdAggregateValue.getCatalogId();
|
|
|
778 |
Item item = catalogIdItemMap.get(catalogId).get(0);
|
|
|
779 |
TagListing tagListing = taglistingMap.get(item.getId());
|
| 24231 |
amit.gupta |
780 |
CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
|
|
|
781 |
if (!catalogListingMap.containsKey(catalogId)) {
|
|
|
782 |
catalogListingModel = new CatalogListingModel();
|
|
|
783 |
catalogListingModel.setCatalogId(catalogId);
|
|
|
784 |
catalogListingModel.setDp(tagListing.getSellingPrice());
|
|
|
785 |
catalogListingModel.setMop(tagListing.getMop());
|
|
|
786 |
catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
|
| 25721 |
tejbeer |
787 |
if (plannedDetailMap != null) {
|
|
|
788 |
|
|
|
789 |
Integer quantity = plannedDetailMap.get(catalogId);
|
|
|
790 |
if (quantity != null) {
|
|
|
791 |
catalogListingModel.setAllocatedQuantity(quantity);
|
|
|
792 |
}
|
|
|
793 |
}
|
|
|
794 |
|
| 25796 |
tejbeer |
795 |
if (last15daysMap != null) {
|
|
|
796 |
Integer last15DaysSale = last15daysMap.get(catalogId);
|
|
|
797 |
|
| 25721 |
tejbeer |
798 |
if (last15DaysSale != null) {
|
|
|
799 |
catalogListingModel.setLast15DaysSale(last15DaysSale);
|
|
|
800 |
} else {
|
|
|
801 |
catalogListingModel.setLast15DaysSale(0);
|
|
|
802 |
}
|
|
|
803 |
} else {
|
|
|
804 |
catalogListingModel.setLast15DaysSale(0);
|
|
|
805 |
}
|
|
|
806 |
|
| 24231 |
amit.gupta |
807 |
catalogListingModel.setBrand(item.getBrand());
|
|
|
808 |
if (item.getCategoryId() == 10006) {
|
|
|
809 |
catalogListingModel.setCategoryId(item.getCategoryId());
|
|
|
810 |
}
|
| 25721 |
tejbeer |
811 |
|
|
|
812 |
FocusedModel fm = focusedModelMap.get(catalogId);
|
|
|
813 |
if (fm != null) {
|
|
|
814 |
catalogListingModel.setRecommendedQty(fm.getRecommendedQty());
|
|
|
815 |
catalogListingModel.setMinimumQty(fm.getMinimumQty());
|
|
|
816 |
|
|
|
817 |
} else {
|
|
|
818 |
catalogListingModel.setRecommendedQty(0);
|
|
|
819 |
catalogListingModel.setMinimumQty(0);
|
|
|
820 |
}
|
|
|
821 |
|
| 24231 |
amit.gupta |
822 |
catalogListingMap.put(catalogId, catalogListingModel);
|
| 25721 |
tejbeer |
823 |
|
| 24231 |
amit.gupta |
824 |
}
|
| 25736 |
tejbeer |
825 |
int itemAvailability = 0;
|
| 25796 |
tejbeer |
826 |
if (currentStockMap != null) {
|
|
|
827 |
Integer qty = currentStockMap.get(catalogId);
|
| 25736 |
tejbeer |
828 |
itemAvailability = qty == null ? 0 : qty;
|
|
|
829 |
catalogListingModel.setStockInHand(itemAvailability);
|
|
|
830 |
} else {
|
|
|
831 |
catalogListingModel.setStockInHand(0);
|
|
|
832 |
}
|
| 24231 |
amit.gupta |
833 |
Integer inTransitQuantity = itemsInTransit.get(item.getId());
|
|
|
834 |
int inTransitQty = (inTransitQuantity == null ? 0 : inTransitQuantity);
|
|
|
835 |
catalogListingModel.setInTransitQuantity(catalogListingModel.getInTransitQuantity() + inTransitQty);
|
| 26179 |
tejbeer |
836 |
if (plannedDetailMap != null) {
|
| 26177 |
tejbeer |
837 |
if (plannedDetailMap.get(catalogId) != null) {
|
| 24231 |
amit.gupta |
838 |
|
| 26177 |
tejbeer |
839 |
int remaining = plannedDetailMap.get(catalogId) - catalogListingModel.getLast15DaysSale()
|
|
|
840 |
+ catalogListingModel.getStockInHand() + catalogListingModel.getInTransitQuantity();
|
|
|
841 |
LOGGER.info("remaning" + remaining);
|
| 26176 |
tejbeer |
842 |
|
| 26177 |
tejbeer |
843 |
if (remaining != 0) {
|
|
|
844 |
catalogListingModel.setRemaining(remaining);
|
|
|
845 |
} else {
|
|
|
846 |
catalogListingModel.setRemaining(0);
|
|
|
847 |
}
|
| 26176 |
tejbeer |
848 |
}
|
|
|
849 |
}
|
| 23786 |
amit.gupta |
850 |
}
|
| 25721 |
tejbeer |
851 |
|
| 26963 |
amit.gupta |
852 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(false);
|
| 23786 |
amit.gupta |
853 |
if (fofoId > 0) {
|
|
|
854 |
CustomRetailer customRetailer = customRetailersMap.get(fofoId);
|
|
|
855 |
model.addAttribute("retailerName",
|
|
|
856 |
customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
|
|
|
857 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
858 |
model.addAttribute("retailerId", customRetailer.getPartnerId());
|
|
|
859 |
model.addAttribute("counterSize", fs.getCounterSize().toString());
|
| 23779 |
amit.gupta |
860 |
} else {
|
| 23786 |
amit.gupta |
861 |
model.addAttribute("counterSize", counterSize.toString());
|
| 23405 |
amit.gupta |
862 |
}
|
| 23786 |
amit.gupta |
863 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
| 25702 |
amit.gupta |
864 |
|
|
|
865 |
List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
|
|
|
866 |
|
| 25721 |
tejbeer |
867 |
Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getMinimumQty,
|
| 24231 |
amit.gupta |
868 |
Comparator.reverseOrder());
|
| 25721 |
tejbeer |
869 |
LOGGER.info("monthlyPlanned" + monthlyPlanned);
|
| 25796 |
tejbeer |
870 |
model.addAttribute("catalogTagListings",
|
|
|
871 |
catalogModelList.stream().sorted(firstCmp).collect(Collectors.toList()));
|
| 25702 |
amit.gupta |
872 |
model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
|
| 26177 |
tejbeer |
873 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
|
| 26956 |
amit.gupta |
874 |
model.addAttribute("previousPlanningMonth", planningMonthDate.minusMonths(1).getMonth());
|
|
|
875 |
model.addAttribute("currentPlanningMonth", planningMonthDate.getMonth());
|
| 26131 |
tejbeer |
876 |
|
| 23786 |
amit.gupta |
877 |
model.addAttribute("customRetailers", customRetailers);
|
| 23796 |
amit.gupta |
878 |
model.addAttribute("totalAmount", totalAmount);
|
| 25721 |
tejbeer |
879 |
model.addAttribute("monthlyPlanned", monthlyPlanned);
|
| 23796 |
amit.gupta |
880 |
model.addAttribute("totalPcs", totalPcs);
|
| 23786 |
amit.gupta |
881 |
return "open-indent";
|
| 25796 |
tejbeer |
882 |
|
| 23405 |
amit.gupta |
883 |
}
|
| 23796 |
amit.gupta |
884 |
|
| 30664 |
amit.gupta |
885 |
private long resetCart(Transaction transaction) {
|
|
|
886 |
long sum = 0;
|
|
|
887 |
Map<Long, Double> items = new HashMap<Long, Double>();
|
|
|
888 |
for (in.shop2020.model.v1.order.Order order : transaction.getOrders()) {
|
|
|
889 |
sum += order.getGvAmount();
|
|
|
890 |
for (LineItem lineitem : order.getLineitems()) {
|
|
|
891 |
Long itemId = lineitem.getItem_id();
|
|
|
892 |
Double quantity = items.get(itemId);
|
|
|
893 |
if (quantity == null) {
|
|
|
894 |
quantity = lineitem.getQuantity();
|
|
|
895 |
} else {
|
|
|
896 |
quantity = quantity + lineitem.getQuantity();
|
| 30017 |
amit.gupta |
897 |
}
|
| 30664 |
amit.gupta |
898 |
items.put(itemId, quantity);
|
| 30017 |
amit.gupta |
899 |
}
|
|
|
900 |
}
|
|
|
901 |
|
| 30664 |
amit.gupta |
902 |
LOGGER.debug("Items to reset in cart are: " + items);
|
| 30017 |
amit.gupta |
903 |
|
| 30664 |
amit.gupta |
904 |
try {
|
|
|
905 |
Client userClient = new UserClient().getClient();
|
|
|
906 |
userClient.resetCart(transaction.getShoppingCartid(), items);
|
|
|
907 |
} catch (TException e) {
|
|
|
908 |
LOGGER.error("Error while updating information in payment database.", e);
|
|
|
909 |
} catch (ShoppingCartException e) {
|
|
|
910 |
LOGGER.error("Error while reseting the cart in cart database.", e);
|
|
|
911 |
} catch (Exception e) {
|
|
|
912 |
LOGGER.error("Unexpected exception", e);
|
| 30017 |
amit.gupta |
913 |
}
|
| 30664 |
amit.gupta |
914 |
return sum;
|
| 30017 |
amit.gupta |
915 |
}
|
|
|
916 |
|
| 30664 |
amit.gupta |
917 |
private List<ItemPriceQuantity> getItemQuantities(int fofoId) throws ProfitMandiBusinessException {
|
|
|
918 |
List<ItemPriceQuantity> itemQuantities = new ArrayList<>();
|
|
|
919 |
/*
|
|
|
920 |
* Map<Integer, ItemIdAvailability> itemCisMap = null; List<ItemIdAvailability>
|
|
|
921 |
* currentInventorySnapshots = currentInventorySnapshotRepository
|
|
|
922 |
* .selectItemsStock(fofoId); itemCisMap =
|
|
|
923 |
* currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
|
|
|
924 |
* .collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
|
|
925 |
* List<StockAllocationModel> stockAllocationList =
|
|
|
926 |
* stockAllocationService.getStockAllocation(fofoId, true);
|
|
|
927 |
*
|
|
|
928 |
* Map<Integer, StockAllocationModel> itemStockAllocationMap =
|
|
|
929 |
* stockAllocationList.stream() .collect(Collectors.toMap(x -> x.catalogId(), x
|
|
|
930 |
* -> x)); Map<Integer, Integer> itemsInTransit = null;
|
|
|
931 |
* LOGGER.info("Item Stock Allocation Model Map {}", itemStockAllocationMap);
|
|
|
932 |
* List<TagListing> tagListings = tagListingRepository.selectAll(false);
|
|
|
933 |
* List<Order> inTransitOrders = orderRepository.selectOrders(fofoId,
|
|
|
934 |
* validOrderStatusList); inTransitOrders =
|
|
|
935 |
* this.filterValidOrders(inTransitOrders); itemsInTransit =
|
|
|
936 |
* inTransitOrders.stream().collect(Collectors.groupingBy(x ->
|
|
|
937 |
* x.getLineItem().getItemId(), Collectors.summingInt(x ->
|
|
|
938 |
* x.getLineItem().getQuantity())));
|
|
|
939 |
*
|
|
|
940 |
* Iterator<TagListing> iterator = tagListings.iterator();
|
|
|
941 |
*
|
|
|
942 |
* int toBeOrdered = 0; while (iterator.hasNext()) { TagListing tagListing =
|
|
|
943 |
* iterator.next(); LOGGER.info(" tagListing.setAllocatedQuantity {}",
|
|
|
944 |
* tagListing.getAllocatedQuantity()); if
|
|
|
945 |
* (!itemCisMap.containsKey(tagListing.getItemId()) &&
|
|
|
946 |
* !itemStockAllocationMap.containsKey(tagListing.getItemId())) {
|
|
|
947 |
* iterator.remove(); continue; } ItemIdAvailability itemIdAvailability =
|
|
|
948 |
* itemCisMap.get(tagListing.getItemId());
|
|
|
949 |
* tagListing.setStockInHand(itemIdAvailability == null ? 0 :
|
|
|
950 |
* itemIdAvailability.getAvailability()); StockAllocationModel
|
|
|
951 |
* stockAllocationModel = itemStockAllocationMap.get(tagListing.getItemId());
|
|
|
952 |
*
|
|
|
953 |
* if (itemsInTransit.containsKey(tagListing.getItemId())) {
|
|
|
954 |
* tagListing.setInTransitQuantity(itemsInTransit.get(tagListing.getItemId()));
|
|
|
955 |
* } else { tagListing.setInTransitQuantity(0); } if (stockAllocationModel !=
|
|
|
956 |
* null) { tagListing.setAllocatedQuantity(stockAllocationModel.getQuantity());
|
|
|
957 |
* toBeOrdered = Math.max(tagListing.getAllocatedQuantity() -
|
|
|
958 |
* tagListing.getInTransitQuantity() - tagListing.getStockInHand(), 0); if
|
|
|
959 |
* (toBeOrdered > 0) { ItemPriceQuantity ipq = new ItemPriceQuantity();
|
|
|
960 |
* ipq.setItemId(tagListing.getItemId()); ipq.setQty((long) toBeOrdered);
|
|
|
961 |
* ipq.setPrice(tagListing.getSellingPrice()); itemQuantities.add(ipq); } } }
|
|
|
962 |
*/
|
|
|
963 |
return itemQuantities;
|
| 30017 |
amit.gupta |
964 |
|
|
|
965 |
}
|
|
|
966 |
|
| 26131 |
tejbeer |
967 |
@RequestMapping(value = "/indent/loadIndentPreviousMonth")
|
|
|
968 |
public String previousMonthLoadOpenIndent(HttpServletRequest request, Model model,
|
| 31317 |
tejbeer |
969 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
|
|
970 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
|
| 26956 |
amit.gupta |
971 |
LocalDate planMonthStart = null;
|
|
|
972 |
if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(PLANNING_OPEN_DAY))) {
|
|
|
973 |
planMonthStart = LocalDate.now().plusMonths(1).withDayOfMonth(1);
|
|
|
974 |
} else {
|
|
|
975 |
planMonthStart = LocalDate.now().withDayOfMonth(1);
|
|
|
976 |
}
|
| 26131 |
tejbeer |
977 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
978 |
Set<Integer> roleIds = loginDetails.getRoleIds();
|
|
|
979 |
LOGGER.info("Counter size is {}", counterSize);
|
|
|
980 |
LOGGER.info("Fofo Id is {}", fofoId);
|
|
|
981 |
boolean isAdmin = roleManager.isAdmin(roleIds);
|
|
|
982 |
|
|
|
983 |
List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
984 |
.collect(Collectors.toList());
|
|
|
985 |
|
|
|
986 |
Map<String, Object> equalsMap = new HashMap<>();
|
|
|
987 |
equalsMap.put("categoryId", 10006);
|
|
|
988 |
equalsMap.put("brand", brands);
|
|
|
989 |
Map<String, List<?>> notEqualsMap = new HashMap<>();
|
|
|
990 |
|
|
|
991 |
Map<String, List<?>> notEqualsJoinMap = new HashMap<>();
|
|
|
992 |
Map<Integer, Integer> currentStockMap;
|
|
|
993 |
|
|
|
994 |
if (!isAdmin && fofoId == 0) {
|
|
|
995 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
|
|
996 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
|
|
997 |
equalsStockJoinMap.put("fofoId", fofoId);
|
|
|
998 |
currentStockMap = itemRepository
|
|
|
999 |
.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
|
|
|
1000 |
equalsStockJoinMap, notEqualsJoinMap, "availability")
|
|
|
1001 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
1002 |
LOGGER.info("currentStock");
|
|
|
1003 |
} else {
|
|
|
1004 |
if (fofoId == 0) {
|
|
|
1005 |
|
|
|
1006 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
|
|
1007 |
equalsStockJoinMap.put("fofoId", fofoId);
|
|
|
1008 |
|
|
|
1009 |
currentStockMap = itemRepository
|
|
|
1010 |
.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
|
|
|
1011 |
equalsStockJoinMap, notEqualsJoinMap, "availability")
|
|
|
1012 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
1013 |
|
|
|
1014 |
} else {
|
|
|
1015 |
|
|
|
1016 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
|
|
1017 |
equalsStockJoinMap.put("fofoId", fofoId);
|
|
|
1018 |
|
|
|
1019 |
currentStockMap = itemRepository
|
|
|
1020 |
.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
|
|
|
1021 |
equalsStockJoinMap, notEqualsJoinMap, "availability")
|
|
|
1022 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
1023 |
|
|
|
1024 |
}
|
|
|
1025 |
}
|
|
|
1026 |
|
|
|
1027 |
LOGGER.info("currentStock" + currentStockMap);
|
|
|
1028 |
|
|
|
1029 |
Map<Integer, Integer> itemsInTransit = null;
|
|
|
1030 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
|
|
1031 |
if (!isAdmin) {
|
|
|
1032 |
tagListings = new ArrayList<>(tagListings);
|
| 28055 |
tejbeer |
1033 |
List<Order> inTransitOrders = orderRepository.selectPendingGrnOrder(fofoId,
|
|
|
1034 |
OrderRepository.validOrderStatusList);
|
| 26131 |
tejbeer |
1035 |
inTransitOrders = this.filterValidOrders(inTransitOrders);
|
|
|
1036 |
itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
1037 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
1038 |
} else {
|
|
|
1039 |
itemsInTransit = new HashMap<>();
|
|
|
1040 |
}
|
|
|
1041 |
|
|
|
1042 |
int totalPcs = 0;
|
|
|
1043 |
|
|
|
1044 |
float totalAmount = 0;
|
|
|
1045 |
Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
|
|
|
1046 |
|
| 27088 |
tejbeer |
1047 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
|
|
|
1048 |
.collect(Collectors.toList());
|
| 26131 |
tejbeer |
1049 |
|
| 27088 |
tejbeer |
1050 |
Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAllByRegionIds(regionIds).stream()
|
|
|
1051 |
.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
|
|
|
1052 |
|
| 26978 |
tejbeer |
1053 |
MonthlyPlanned monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId,
|
|
|
1054 |
planMonthStart.minusMonths(1));
|
| 26956 |
amit.gupta |
1055 |
model.addAttribute("planningMonth", planMonthStart.minusMonths(1).getMonth());
|
|
|
1056 |
model.addAttribute("previousPlanningMonth", planMonthStart.minusMonths(1).getMonth());
|
|
|
1057 |
model.addAttribute("currentPlanningMonth", planMonthStart.getMonth());
|
| 26131 |
tejbeer |
1058 |
|
|
|
1059 |
Map<Integer, Integer> plannedDetailMap = null;
|
|
|
1060 |
if (monthlyPlanned != null) {
|
|
|
1061 |
plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
|
|
|
1062 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
|
|
|
1063 |
|
|
|
1064 |
}
|
|
|
1065 |
|
|
|
1066 |
LOGGER.info("plannedDetailMap" + plannedDetailMap);
|
|
|
1067 |
List<Integer> fofoOrderIds = fofoOrderRepository
|
|
|
1068 |
.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
|
| 26978 |
tejbeer |
1069 |
planMonthStart.minusMonths(1).atStartOfDay(), planMonthStart.atStartOfDay())
|
| 26131 |
tejbeer |
1070 |
.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 26721 |
tejbeer |
1071 |
|
| 26131 |
tejbeer |
1072 |
LOGGER.info("fofoOrderIds" + fofoOrderIds);
|
|
|
1073 |
Map<String, Object> equalsJoinMap = new HashMap<>();
|
|
|
1074 |
equalsJoinMap.put("orderId", fofoOrderIds);
|
| 26721 |
tejbeer |
1075 |
Map<Integer, Integer> lastMonthSaleMap = null;
|
|
|
1076 |
if (!fofoOrderIds.isEmpty()) {
|
|
|
1077 |
lastMonthSaleMap = itemRepository
|
|
|
1078 |
.selectItems(FofoOrderItem.class, "id", "itemId", equalsMap, notEqualsMap, equalsJoinMap,
|
|
|
1079 |
notEqualsJoinMap, "quantity")
|
|
|
1080 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
1081 |
}
|
| 26131 |
tejbeer |
1082 |
LOGGER.info("lastMonthSaleMap" + lastMonthSaleMap);
|
|
|
1083 |
|
|
|
1084 |
Map<Integer, TagListing> taglistingMap = tagListings.stream()
|
|
|
1085 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
|
|
1086 |
List<Item> items = itemRepository.selectByIds(taglistingMap.keySet());
|
|
|
1087 |
Map<Integer, List<Item>> catalogIdItemMap = items.stream().collect(
|
|
|
1088 |
Collectors.groupingBy(x -> x.getCatalogItemId(), Collectors.mapping(y -> y, Collectors.toList())));
|
|
|
1089 |
LOGGER.info("catalogIdItemMap");
|
|
|
1090 |
|
|
|
1091 |
Map<String, Object> equalsItemJoinMap = new HashMap<>();
|
|
|
1092 |
equalsItemJoinMap.put("active", 1);
|
| 28897 |
amit.gupta |
1093 |
List<IntegerIdAggregateValue> tagListingCatalogIds = itemRepository.selectItems(TagListing.class, "id",
|
| 26131 |
tejbeer |
1094 |
"itemId", equalsMap, notEqualsMap, equalsItemJoinMap, notEqualsJoinMap, "tagId");
|
|
|
1095 |
LOGGER.info("tagListingCatalogIds");
|
| 28897 |
amit.gupta |
1096 |
for (IntegerIdAggregateValue catalogIdAggregateValue : tagListingCatalogIds) {
|
| 26131 |
tejbeer |
1097 |
int catalogId = catalogIdAggregateValue.getCatalogId();
|
|
|
1098 |
Item item = catalogIdItemMap.get(catalogId).get(0);
|
|
|
1099 |
TagListing tagListing = taglistingMap.get(item.getId());
|
|
|
1100 |
CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
|
|
|
1101 |
if (!catalogListingMap.containsKey(catalogId)) {
|
|
|
1102 |
catalogListingModel = new CatalogListingModel();
|
|
|
1103 |
catalogListingModel.setCatalogId(catalogId);
|
|
|
1104 |
catalogListingModel.setDp(tagListing.getSellingPrice());
|
|
|
1105 |
catalogListingModel.setMop(tagListing.getMop());
|
|
|
1106 |
catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
|
|
|
1107 |
if (plannedDetailMap != null) {
|
|
|
1108 |
|
|
|
1109 |
Integer quantity = plannedDetailMap.get(catalogId);
|
|
|
1110 |
if (quantity != null) {
|
|
|
1111 |
catalogListingModel.setAllocatedQuantity(quantity);
|
|
|
1112 |
}
|
|
|
1113 |
}
|
|
|
1114 |
|
|
|
1115 |
if (lastMonthSaleMap != null) {
|
|
|
1116 |
Integer lastMonthSale = lastMonthSaleMap.get(catalogId);
|
|
|
1117 |
|
|
|
1118 |
if (lastMonthSale != null) {
|
|
|
1119 |
catalogListingModel.setLastMonthSaleMap(lastMonthSale);
|
|
|
1120 |
} else {
|
|
|
1121 |
catalogListingModel.setLastMonthSaleMap(0);
|
|
|
1122 |
}
|
|
|
1123 |
} else {
|
|
|
1124 |
catalogListingModel.setLast15DaysSale(0);
|
|
|
1125 |
}
|
|
|
1126 |
|
|
|
1127 |
catalogListingModel.setBrand(item.getBrand());
|
|
|
1128 |
if (item.getCategoryId() == 10006) {
|
|
|
1129 |
catalogListingModel.setCategoryId(item.getCategoryId());
|
|
|
1130 |
}
|
|
|
1131 |
|
|
|
1132 |
FocusedModel fm = focusedModelMap.get(catalogId);
|
|
|
1133 |
if (fm != null) {
|
|
|
1134 |
catalogListingModel.setRecommendedQty(fm.getRecommendedQty());
|
|
|
1135 |
catalogListingModel.setMinimumQty(fm.getMinimumQty());
|
|
|
1136 |
|
|
|
1137 |
} else {
|
|
|
1138 |
catalogListingModel.setRecommendedQty(0);
|
|
|
1139 |
catalogListingModel.setMinimumQty(0);
|
|
|
1140 |
}
|
|
|
1141 |
|
|
|
1142 |
catalogListingMap.put(catalogId, catalogListingModel);
|
|
|
1143 |
|
|
|
1144 |
}
|
|
|
1145 |
int itemAvailability = 0;
|
|
|
1146 |
if (currentStockMap != null) {
|
|
|
1147 |
Integer qty = currentStockMap.get(catalogId);
|
|
|
1148 |
itemAvailability = qty == null ? 0 : qty;
|
|
|
1149 |
catalogListingModel.setStockInHand(itemAvailability);
|
|
|
1150 |
} else {
|
|
|
1151 |
catalogListingModel.setStockInHand(0);
|
|
|
1152 |
}
|
|
|
1153 |
Integer inTransitQuantity = itemsInTransit.get(item.getId());
|
|
|
1154 |
int inTransitQty = (inTransitQuantity == null ? 0 : inTransitQuantity);
|
|
|
1155 |
catalogListingModel.setInTransitQuantity(catalogListingModel.getInTransitQuantity() + inTransitQty);
|
|
|
1156 |
|
|
|
1157 |
}
|
|
|
1158 |
|
| 26963 |
amit.gupta |
1159 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(false);
|
| 26131 |
tejbeer |
1160 |
if (fofoId > 0) {
|
|
|
1161 |
CustomRetailer customRetailer = customRetailersMap.get(fofoId);
|
|
|
1162 |
model.addAttribute("retailerName",
|
|
|
1163 |
customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
|
|
|
1164 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
1165 |
model.addAttribute("retailerId", customRetailer.getPartnerId());
|
|
|
1166 |
model.addAttribute("counterSize", fs.getCounterSize().toString());
|
|
|
1167 |
} else {
|
|
|
1168 |
model.addAttribute("counterSize", counterSize.toString());
|
|
|
1169 |
}
|
|
|
1170 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
|
|
1171 |
|
|
|
1172 |
List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
|
|
|
1173 |
|
|
|
1174 |
Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getMinimumQty,
|
|
|
1175 |
Comparator.reverseOrder());
|
|
|
1176 |
LOGGER.info("monthlyPlanned" + monthlyPlanned);
|
|
|
1177 |
model.addAttribute("catalogTagListings",
|
|
|
1178 |
catalogModelList.stream().sorted(firstCmp).collect(Collectors.toList()));
|
|
|
1179 |
model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
|
|
|
1180 |
model.addAttribute("previousMonth", true);
|
|
|
1181 |
model.addAttribute("freezed", true);
|
| 26177 |
tejbeer |
1182 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
|
| 26131 |
tejbeer |
1183 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
1184 |
model.addAttribute("totalAmount", totalAmount);
|
|
|
1185 |
model.addAttribute("monthlyPlanned", monthlyPlanned);
|
|
|
1186 |
model.addAttribute("totalPcs", totalPcs);
|
|
|
1187 |
return "open-indent";
|
|
|
1188 |
|
|
|
1189 |
}
|
|
|
1190 |
|
| 30664 |
amit.gupta |
1191 |
private Map<Integer, Item> getItemByCatalogId(List<FocusedModel> focusedModels) {
|
|
|
1192 |
Map<Integer, Item> itemMap = new HashMap<>();
|
|
|
1193 |
for (FocusedModel focusedModel : focusedModels) {
|
|
|
1194 |
List<Item> items = itemRepository.selectAllByCatalogItemId(focusedModel.getCatalogId());
|
|
|
1195 |
itemMap.put(items.get(0).getCatalogItemId(), items.get(0));
|
| 23796 |
amit.gupta |
1196 |
}
|
|
|
1197 |
|
| 30664 |
amit.gupta |
1198 |
return itemMap;
|
|
|
1199 |
}
|
| 25378 |
tejbeer |
1200 |
|
| 30664 |
amit.gupta |
1201 |
private Map<Integer, Region> getRegionByRegionId(List<FocusedModel> focusedModels) {
|
|
|
1202 |
Map<Integer, Region> regionMap = new HashMap<>();
|
|
|
1203 |
for (FocusedModel focusedModel : focusedModels) {
|
|
|
1204 |
Region region = regionRepository.selectById(focusedModel.getRegionId());
|
|
|
1205 |
regionMap.put(region.getId(), region);
|
| 24406 |
amit.gupta |
1206 |
}
|
| 24231 |
amit.gupta |
1207 |
|
| 30664 |
amit.gupta |
1208 |
return regionMap;
|
| 23796 |
amit.gupta |
1209 |
}
|
| 24231 |
amit.gupta |
1210 |
|
| 25721 |
tejbeer |
1211 |
@RequestMapping(value = "/getFocusedModel", method = RequestMethod.GET)
|
|
|
1212 |
public String getFocusedModel(HttpServletRequest request,
|
| 31317 |
tejbeer |
1213 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
1214 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
| 25721 |
tejbeer |
1215 |
throws ProfitMandiBusinessException {
|
| 25736 |
tejbeer |
1216 |
|
|
|
1217 |
long size = 0;
|
| 25721 |
tejbeer |
1218 |
List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
|
| 27081 |
tejbeer |
1219 |
|
| 25736 |
tejbeer |
1220 |
size = focusedModelRepository.selectAllCount();
|
|
|
1221 |
if (!focusedModels.isEmpty()) {
|
|
|
1222 |
Map<Integer, Item> itemMap = this.getItemByCatalogId(focusedModels);
|
| 27088 |
tejbeer |
1223 |
Map<Integer, Region> regionMap = this.getRegionByRegionId(focusedModels);
|
| 25721 |
tejbeer |
1224 |
|
| 27088 |
tejbeer |
1225 |
LOGGER.info("regionMap" + regionMap);
|
| 25736 |
tejbeer |
1226 |
model.addAttribute("focusedModels", focusedModels);
|
|
|
1227 |
model.addAttribute("itemMap", itemMap);
|
| 27088 |
tejbeer |
1228 |
model.addAttribute("regionMap", regionMap);
|
| 25736 |
tejbeer |
1229 |
model.addAttribute("start", offset + 1);
|
|
|
1230 |
model.addAttribute("size", size);
|
|
|
1231 |
model.addAttribute("url", "/getPaginatedFocusedModel");
|
|
|
1232 |
|
|
|
1233 |
if (focusedModels.size() < limit) {
|
|
|
1234 |
model.addAttribute("end", offset + focusedModels.size());
|
|
|
1235 |
} else {
|
|
|
1236 |
model.addAttribute("end", offset + limit);
|
|
|
1237 |
}
|
|
|
1238 |
} else {
|
|
|
1239 |
|
|
|
1240 |
model.addAttribute("walletRequest", focusedModels);
|
|
|
1241 |
model.addAttribute("size", size);
|
|
|
1242 |
|
|
|
1243 |
}
|
|
|
1244 |
|
| 27088 |
tejbeer |
1245 |
List<Region> regions = regionRepository.selectAll();
|
| 27081 |
tejbeer |
1246 |
|
| 27088 |
tejbeer |
1247 |
model.addAttribute("regions", regions);
|
|
|
1248 |
|
| 25721 |
tejbeer |
1249 |
return "focused_model";
|
|
|
1250 |
}
|
|
|
1251 |
|
| 25736 |
tejbeer |
1252 |
@RequestMapping(value = "/getPaginatedFocusedModel", method = RequestMethod.GET)
|
|
|
1253 |
public String getPaginatedFocusedModel(HttpServletRequest request,
|
| 31317 |
tejbeer |
1254 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
1255 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
| 25736 |
tejbeer |
1256 |
throws ProfitMandiBusinessException {
|
|
|
1257 |
LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
|
|
|
1258 |
List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
|
|
|
1259 |
|
|
|
1260 |
if (!focusedModels.isEmpty()) {
|
|
|
1261 |
Map<Integer, Item> itemMap = this.getItemByCatalogId(focusedModels);
|
| 27088 |
tejbeer |
1262 |
Map<Integer, Region> regionMap = this.getRegionByRegionId(focusedModels);
|
| 25736 |
tejbeer |
1263 |
model.addAttribute("focusedModels", focusedModels);
|
|
|
1264 |
model.addAttribute("itemMap", itemMap);
|
| 27088 |
tejbeer |
1265 |
model.addAttribute("regionMap", regionMap);
|
| 25736 |
tejbeer |
1266 |
model.addAttribute("url", "/getPaginatedFocusedModel");
|
|
|
1267 |
} else {
|
|
|
1268 |
model.addAttribute("focusedModels", focusedModels);
|
|
|
1269 |
|
|
|
1270 |
}
|
| 27081 |
tejbeer |
1271 |
|
| 27088 |
tejbeer |
1272 |
List<Region> regions = regionRepository.selectAll();
|
|
|
1273 |
|
|
|
1274 |
model.addAttribute("regions", regions);
|
| 25736 |
tejbeer |
1275 |
return "focused-model-paginated";
|
|
|
1276 |
}
|
|
|
1277 |
|
| 25798 |
tejbeer |
1278 |
private List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
|
|
|
1279 |
Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
|
| 25736 |
tejbeer |
1280 |
|
| 25798 |
tejbeer |
1281 |
List<DBObject> mobileBrands = mongoClient.getMongoBrands(fofoId, "", 3);
|
|
|
1282 |
List<BrandStockPrice> brandStockPrices = new ArrayList<>();
|
|
|
1283 |
|
|
|
1284 |
mobileBrands.stream().forEach(x -> {
|
|
|
1285 |
String brand = (String) x.get("name");
|
|
|
1286 |
if (brandStockPricesMap.containsKey(brand)) {
|
|
|
1287 |
BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
|
|
|
1288 |
brandStockPrice.setBrandUrl((String) x.get("url"));
|
|
|
1289 |
brandStockPrice.setRank(((Double) x.get("rank")).intValue());
|
|
|
1290 |
brandStockPrices.add(brandStockPrice);
|
|
|
1291 |
}
|
|
|
1292 |
});
|
|
|
1293 |
|
|
|
1294 |
return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted((x, y) -> x.getRank() - y.getRank())
|
|
|
1295 |
.collect(Collectors.toList());
|
|
|
1296 |
}
|
|
|
1297 |
|
| 26721 |
tejbeer |
1298 |
@RequestMapping(value = "/getPartnerAllocation")
|
|
|
1299 |
public String getPartnerAllocation(HttpServletRequest request, Model model) throws Exception {
|
|
|
1300 |
|
|
|
1301 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1302 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1303 |
|
|
|
1304 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
1305 |
|
|
|
1306 |
List<Integer> fofoIds = pp.get(authUser.getId());
|
|
|
1307 |
|
| 30426 |
tejbeer |
1308 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
1309 |
Map<Integer, CustomRetailer> crm = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null)
|
|
|
1310 |
.collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 26721 |
tejbeer |
1311 |
Map<Integer, FofoStore> fofoStoreMap = fofoStoreRepository.selectByRetailerIds(fofoIds).stream()
|
|
|
1312 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1313 |
|
| 30426 |
tejbeer |
1314 |
model.addAttribute("customRetailersMap", crm);
|
| 26721 |
tejbeer |
1315 |
model.addAttribute("fofoStoreMap", fofoStoreMap);
|
|
|
1316 |
return "partners_allocation";
|
|
|
1317 |
|
|
|
1318 |
}
|
|
|
1319 |
|
| 26846 |
tejbeer |
1320 |
@RequestMapping(value = "/partnerPendingOrder")
|
|
|
1321 |
public String partnerPendingOrder(HttpServletRequest request, Model model) throws Exception {
|
|
|
1322 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1323 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1324 |
|
|
|
1325 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
1326 |
|
|
|
1327 |
List<Integer> fofoIds = pp.get(authUser.getId());
|
| 30426 |
tejbeer |
1328 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
1329 |
Map<Integer, CustomRetailer> crm = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null)
|
|
|
1330 |
.collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 26846 |
tejbeer |
1331 |
|
| 30426 |
tejbeer |
1332 |
model.addAttribute("customRetailersMap", crm);
|
| 26846 |
tejbeer |
1333 |
|
|
|
1334 |
return "partner-po";
|
|
|
1335 |
|
|
|
1336 |
}
|
|
|
1337 |
|
| 30664 |
amit.gupta |
1338 |
@RequestMapping(value = "/focusedModel", method = RequestMethod.POST)
|
|
|
1339 |
public String focusedModel(HttpServletRequest request, @RequestParam int catalogId,
|
| 31317 |
tejbeer |
1340 |
@RequestParam(name = "recommended", defaultValue = "0") int recommended,
|
|
|
1341 |
@RequestParam(name = "minimumQty", defaultValue = "0") int minimumQty,
|
|
|
1342 |
@RequestParam(name = "obvrecommend", defaultValue = "0") int obvrecommend,
|
|
|
1343 |
@RequestParam(name = "obvminimum", defaultValue = "0") int obvminimum, @RequestParam int regionId,
|
|
|
1344 |
Model model) throws ProfitMandiBusinessException {
|
| 30664 |
amit.gupta |
1345 |
|
|
|
1346 |
FocusedModel fm = new FocusedModel();
|
|
|
1347 |
fm.setCatalogId(catalogId);
|
|
|
1348 |
fm.setMinimumQty(minimumQty);
|
|
|
1349 |
fm.setRecommendedQty(recommended);
|
|
|
1350 |
fm.setRegionId(regionId);
|
|
|
1351 |
fm.setObsRecommendedQty(obvrecommend);
|
|
|
1352 |
fm.setObsMinimumQty(obvminimum);
|
|
|
1353 |
fm.setCreatedTimestamp(LocalDateTime.now());
|
|
|
1354 |
focusedModelRepository.persist(fm);
|
|
|
1355 |
return "focused_model";
|
|
|
1356 |
}
|
|
|
1357 |
|
| 30017 |
amit.gupta |
1358 |
@RequestMapping(value = "/removeItem", method = RequestMethod.DELETE)
|
|
|
1359 |
public String removeFocusedModelItem(HttpServletRequest request,
|
| 31317 |
tejbeer |
1360 |
@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
|
| 30017 |
amit.gupta |
1361 |
|
|
|
1362 |
focusedModelRepository.deleteById(id);
|
| 31238 |
amit.gupta |
1363 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 30017 |
amit.gupta |
1364 |
return "response";
|
|
|
1365 |
}
|
|
|
1366 |
|
| 26846 |
tejbeer |
1367 |
@RequestMapping(value = "/getPartnerloadContent")
|
|
|
1368 |
public String getPartnerloadContent(HttpServletRequest request, Model model,
|
| 31317 |
tejbeer |
1369 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
|
|
1370 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
|
| 26846 |
tejbeer |
1371 |
|
|
|
1372 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1373 |
Set<Integer> roleIds = loginDetails.getRoleIds();
|
|
|
1374 |
LOGGER.info("Counter size is {}", counterSize);
|
|
|
1375 |
LOGGER.info("Fofo Id is {}", fofoId);
|
|
|
1376 |
boolean isAdmin = roleManager.isAdmin(roleIds);
|
|
|
1377 |
|
|
|
1378 |
List<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
|
|
1379 |
.collect(Collectors.toList());
|
|
|
1380 |
|
|
|
1381 |
Map<String, Object> equalsMap = new HashMap<>();
|
|
|
1382 |
equalsMap.put("categoryId", 10006);
|
|
|
1383 |
equalsMap.put("brand", brands);
|
|
|
1384 |
Map<String, List<?>> notEqualsMap = new HashMap<>();
|
|
|
1385 |
|
|
|
1386 |
Map<String, List<?>> notEqualsJoinMap = new HashMap<>();
|
|
|
1387 |
Map<Integer, Integer> currentStockMap;
|
|
|
1388 |
|
|
|
1389 |
if (!isAdmin && fofoId == 0) {
|
|
|
1390 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
|
|
1391 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
|
|
1392 |
equalsStockJoinMap.put("fofoId", fofoId);
|
|
|
1393 |
currentStockMap = itemRepository
|
|
|
1394 |
.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
|
|
|
1395 |
equalsStockJoinMap, notEqualsJoinMap, "availability")
|
|
|
1396 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
1397 |
LOGGER.info("currentStock");
|
|
|
1398 |
} else {
|
|
|
1399 |
if (fofoId == 0) {
|
|
|
1400 |
|
|
|
1401 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
|
|
1402 |
equalsStockJoinMap.put("fofoId", fofoId);
|
|
|
1403 |
|
|
|
1404 |
currentStockMap = itemRepository
|
|
|
1405 |
.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
|
|
|
1406 |
equalsStockJoinMap, notEqualsJoinMap, "availability")
|
|
|
1407 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
1408 |
|
|
|
1409 |
} else {
|
|
|
1410 |
|
|
|
1411 |
Map<String, Object> equalsStockJoinMap = new HashMap<>();
|
|
|
1412 |
equalsStockJoinMap.put("fofoId", fofoId);
|
|
|
1413 |
|
|
|
1414 |
currentStockMap = itemRepository
|
|
|
1415 |
.selectItems(CurrentInventorySnapshot.class, "id", "itemId", equalsMap, notEqualsMap,
|
|
|
1416 |
equalsStockJoinMap, notEqualsJoinMap, "availability")
|
|
|
1417 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
1418 |
|
|
|
1419 |
}
|
|
|
1420 |
}
|
|
|
1421 |
|
| 27768 |
tejbeer |
1422 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 26846 |
tejbeer |
1423 |
LOGGER.info("currentStock" + currentStockMap);
|
|
|
1424 |
|
|
|
1425 |
Map<Integer, Integer> itemsInTransit = null;
|
|
|
1426 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
|
|
1427 |
if (!isAdmin) {
|
|
|
1428 |
tagListings = new ArrayList<>(tagListings);
|
| 28055 |
tejbeer |
1429 |
List<Order> inTransitOrders = orderRepository.selectPendingGrnOrder(fofoId,
|
|
|
1430 |
OrderRepository.validOrderStatusList);
|
| 26846 |
tejbeer |
1431 |
inTransitOrders = this.filterValidOrders(inTransitOrders);
|
|
|
1432 |
itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
1433 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
1434 |
} else {
|
|
|
1435 |
itemsInTransit = new HashMap<>();
|
|
|
1436 |
}
|
|
|
1437 |
|
|
|
1438 |
int totalPcs = 0;
|
|
|
1439 |
|
|
|
1440 |
float totalAmount = 0;
|
|
|
1441 |
Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
|
|
|
1442 |
|
| 27088 |
tejbeer |
1443 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
|
|
|
1444 |
.collect(Collectors.toList());
|
| 26846 |
tejbeer |
1445 |
|
| 27088 |
tejbeer |
1446 |
Map<Integer, FocusedModel> focusedModelMap = focusedModelRepository.selectAllByRegionIds(regionIds).stream()
|
|
|
1447 |
.collect(Collectors.toMap(FocusedModel::getCatalogId, Function.identity()));
|
|
|
1448 |
|
| 26846 |
tejbeer |
1449 |
LocalDate currentMonthDate = LocalDate.now();
|
|
|
1450 |
MonthlyPlanned monthlyPlanned = null;
|
|
|
1451 |
List<Integer> fofoOrderIds = null;
|
|
|
1452 |
LOGGER.info("localDate" + LocalDate.now());
|
| 26951 |
amit.gupta |
1453 |
if (LocalDate.now().isAfter(LocalDate.now().withDayOfMonth(PLANNING_OPEN_DAY))) {
|
| 26846 |
tejbeer |
1454 |
currentMonthDate = LocalDate.now().plusMonths(1).withDayOfMonth(1);
|
|
|
1455 |
monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
|
|
|
1456 |
LOGGER.info("monthlyPlanned2" + monthlyPlanned);
|
|
|
1457 |
fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
|
| 31317 |
tejbeer |
1458 |
LocalDateTime.now().minusDays(15), LocalDateTime.now()).stream().map(x -> x.getId())
|
| 26846 |
tejbeer |
1459 |
.collect(Collectors.toList());
|
|
|
1460 |
|
|
|
1461 |
model.addAttribute("planningMonth", LocalDate.now().plusMonths(1).getMonth());
|
| 26951 |
amit.gupta |
1462 |
} else {
|
| 26846 |
tejbeer |
1463 |
currentMonthDate = LocalDate.now().withDayOfMonth(1);
|
|
|
1464 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
1465 |
monthlyPlanned = monthlyPlannedRepository.selectByFofoIdYearMonth(fofoId, currentMonthDate);
|
|
|
1466 |
model.addAttribute("planningMonth", currentMonthDate.getMonth());
|
|
|
1467 |
model.addAttribute("mtd", true);
|
|
|
1468 |
model.addAttribute("freezed", true);
|
|
|
1469 |
fofoOrderIds = fofoOrderRepository.selectByFofoIdBetweenCreatedTimeStamp(loginDetails.getFofoId(),
|
| 31317 |
tejbeer |
1470 |
curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX)).stream().map(x -> x.getId())
|
| 26846 |
tejbeer |
1471 |
.collect(Collectors.toList());
|
|
|
1472 |
LOGGER.info("monthlyPlanned1" + monthlyPlanned);
|
|
|
1473 |
}
|
|
|
1474 |
|
|
|
1475 |
Map<Integer, Integer> plannedDetailMap = null;
|
|
|
1476 |
if (monthlyPlanned != null) {
|
|
|
1477 |
plannedDetailMap = plannedDetailRepository.selectByPlannedId(monthlyPlanned.getId()).stream()
|
|
|
1478 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
|
|
|
1479 |
|
|
|
1480 |
}
|
|
|
1481 |
LOGGER.info("plannedDetailMap" + plannedDetailMap);
|
|
|
1482 |
|
|
|
1483 |
LOGGER.info("fofoOrderIds" + fofoOrderIds);
|
|
|
1484 |
Map<String, Object> equalsJoinMap = new HashMap<>();
|
|
|
1485 |
|
|
|
1486 |
equalsJoinMap.put("orderId", fofoOrderIds);
|
|
|
1487 |
Map<Integer, Integer> last15daysMap = null;
|
|
|
1488 |
if (fofoOrderIds != null && !fofoOrderIds.isEmpty()) {
|
|
|
1489 |
|
|
|
1490 |
last15daysMap = itemRepository
|
|
|
1491 |
.selectItems(FofoOrderItem.class, "id", "itemId", equalsMap, notEqualsMap, equalsJoinMap,
|
|
|
1492 |
notEqualsJoinMap, "quantity")
|
|
|
1493 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> (int) x.getAggregateValue()));
|
|
|
1494 |
}
|
|
|
1495 |
LOGGER.info("last15daysMap" + last15daysMap);
|
|
|
1496 |
|
|
|
1497 |
Map<Integer, TagListing> taglistingMap = tagListings.stream()
|
|
|
1498 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
|
|
1499 |
List<Item> items = itemRepository.selectByIds(taglistingMap.keySet());
|
|
|
1500 |
Map<Integer, List<Item>> catalogIdItemMap = items.stream().collect(
|
|
|
1501 |
Collectors.groupingBy(x -> x.getCatalogItemId(), Collectors.mapping(y -> y, Collectors.toList())));
|
|
|
1502 |
LOGGER.info("catalogIdItemMap");
|
|
|
1503 |
|
|
|
1504 |
Map<String, Object> equalsItemJoinMap = new HashMap<>();
|
|
|
1505 |
equalsItemJoinMap.put("active", 1);
|
| 28897 |
amit.gupta |
1506 |
List<IntegerIdAggregateValue> tagListingCatalogIds = itemRepository.selectItems(TagListing.class, "id",
|
| 26846 |
tejbeer |
1507 |
"itemId", equalsMap, notEqualsMap, equalsItemJoinMap, notEqualsJoinMap, "tagId");
|
| 27768 |
tejbeer |
1508 |
Map<Integer, Integer> ourStockAvailability = new HashMap<>();
|
|
|
1509 |
|
|
|
1510 |
Map<Integer, List<Integer>> catalogItemIdMap = itemRepository
|
|
|
1511 |
.selectAllByCatalogIds(new HashSet<>(
|
|
|
1512 |
tagListingCatalogIds.stream().map(x -> x.getCatalogId()).collect(Collectors.toList())))
|
|
|
1513 |
.stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1514 |
Collectors.mapping(y -> y.getId(), Collectors.toList())));
|
|
|
1515 |
for (Entry<Integer, List<Integer>> catalogItem : catalogItemIdMap.entrySet()) {
|
|
|
1516 |
List<Integer> itemIds = catalogItem.getValue();
|
|
|
1517 |
int availability = 0;
|
|
|
1518 |
for (Integer itemId : itemIds) {
|
| 31317 |
tejbeer |
1519 |
List<SaholicCISTable> saholicCISTableList = saholicCISTableRepository.selectByItemWarehouse(itemId,
|
|
|
1520 |
fofoStore.getWarehouseId());
|
| 30664 |
amit.gupta |
1521 |
if (saholicCISTableList != null) {
|
| 31317 |
tejbeer |
1522 |
availability += saholicCISTableList.stream()
|
|
|
1523 |
.collect(Collectors.summingInt(x -> x.getAvailability()));
|
| 27768 |
tejbeer |
1524 |
}
|
|
|
1525 |
}
|
|
|
1526 |
Integer catalogItemId = catalogItem.getKey();
|
|
|
1527 |
ourStockAvailability.put(catalogItemId, availability);
|
|
|
1528 |
}
|
|
|
1529 |
LOGGER.info("ourStockAvailability" + ourStockAvailability);
|
|
|
1530 |
|
| 28897 |
amit.gupta |
1531 |
for (IntegerIdAggregateValue catalogIdAggregateValue : tagListingCatalogIds) {
|
| 26846 |
tejbeer |
1532 |
int catalogId = catalogIdAggregateValue.getCatalogId();
|
|
|
1533 |
Item item = catalogIdItemMap.get(catalogId).get(0);
|
|
|
1534 |
TagListing tagListing = taglistingMap.get(item.getId());
|
|
|
1535 |
CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
|
|
|
1536 |
if (!catalogListingMap.containsKey(catalogId)) {
|
|
|
1537 |
catalogListingModel = new CatalogListingModel();
|
|
|
1538 |
catalogListingModel.setCatalogId(catalogId);
|
|
|
1539 |
catalogListingModel.setDp(tagListing.getSellingPrice());
|
|
|
1540 |
catalogListingModel.setMop(tagListing.getMop());
|
|
|
1541 |
catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
|
|
|
1542 |
if (plannedDetailMap != null) {
|
|
|
1543 |
|
|
|
1544 |
Integer quantity = plannedDetailMap.get(catalogId);
|
|
|
1545 |
if (quantity != null) {
|
|
|
1546 |
catalogListingModel.setAllocatedQuantity(quantity);
|
|
|
1547 |
}
|
|
|
1548 |
}
|
|
|
1549 |
|
|
|
1550 |
if (last15daysMap != null) {
|
|
|
1551 |
Integer last15DaysSale = last15daysMap.get(catalogId);
|
|
|
1552 |
|
|
|
1553 |
if (last15DaysSale != null) {
|
|
|
1554 |
catalogListingModel.setLast15DaysSale(last15DaysSale);
|
|
|
1555 |
} else {
|
|
|
1556 |
catalogListingModel.setLast15DaysSale(0);
|
|
|
1557 |
}
|
|
|
1558 |
} else {
|
|
|
1559 |
catalogListingModel.setLast15DaysSale(0);
|
|
|
1560 |
}
|
|
|
1561 |
|
|
|
1562 |
catalogListingModel.setBrand(item.getBrand());
|
|
|
1563 |
if (item.getCategoryId() == 10006) {
|
|
|
1564 |
catalogListingModel.setCategoryId(item.getCategoryId());
|
|
|
1565 |
}
|
|
|
1566 |
|
| 27768 |
tejbeer |
1567 |
Integer ourStock = ourStockAvailability.get(catalogId);
|
|
|
1568 |
LOGGER.info("catalogId" + catalogId);
|
|
|
1569 |
|
|
|
1570 |
LOGGER.info("ourStock" + ourStock);
|
|
|
1571 |
if (ourStock != null) {
|
|
|
1572 |
catalogListingModel.setOurStockQty(ourStock);
|
|
|
1573 |
}
|
|
|
1574 |
|
| 26846 |
tejbeer |
1575 |
FocusedModel fm = focusedModelMap.get(catalogId);
|
|
|
1576 |
if (fm != null) {
|
|
|
1577 |
catalogListingModel.setRecommendedQty(fm.getRecommendedQty());
|
|
|
1578 |
catalogListingModel.setMinimumQty(fm.getMinimumQty());
|
| 29667 |
tejbeer |
1579 |
catalogListingModel.setObsRecommendedQty(fm.getObsRecommendedQty());
|
|
|
1580 |
catalogListingModel.setObsMinimumQty(fm.getObsMinimumQty());
|
| 26846 |
tejbeer |
1581 |
|
|
|
1582 |
} else {
|
|
|
1583 |
catalogListingModel.setRecommendedQty(0);
|
|
|
1584 |
catalogListingModel.setMinimumQty(0);
|
| 29667 |
tejbeer |
1585 |
|
|
|
1586 |
catalogListingModel.setObsRecommendedQty(0);
|
|
|
1587 |
catalogListingModel.setObsMinimumQty(0);
|
|
|
1588 |
|
| 26846 |
tejbeer |
1589 |
}
|
|
|
1590 |
|
|
|
1591 |
catalogListingMap.put(catalogId, catalogListingModel);
|
|
|
1592 |
|
|
|
1593 |
}
|
|
|
1594 |
int itemAvailability = 0;
|
|
|
1595 |
if (currentStockMap != null) {
|
|
|
1596 |
Integer qty = currentStockMap.get(catalogId);
|
|
|
1597 |
itemAvailability = qty == null ? 0 : qty;
|
|
|
1598 |
catalogListingModel.setStockInHand(itemAvailability);
|
|
|
1599 |
} else {
|
|
|
1600 |
catalogListingModel.setStockInHand(0);
|
|
|
1601 |
}
|
|
|
1602 |
Integer inTransitQuantity = itemsInTransit.get(item.getId());
|
|
|
1603 |
int inTransitQty = (inTransitQuantity == null ? 0 : inTransitQuantity);
|
|
|
1604 |
catalogListingModel.setInTransitQuantity(catalogListingModel.getInTransitQuantity() + inTransitQty);
|
|
|
1605 |
if (plannedDetailMap != null) {
|
|
|
1606 |
if (plannedDetailMap.get(catalogId) != null) {
|
|
|
1607 |
|
|
|
1608 |
int remaining = plannedDetailMap.get(catalogId) - catalogListingModel.getLast15DaysSale()
|
|
|
1609 |
+ catalogListingModel.getStockInHand() + catalogListingModel.getInTransitQuantity();
|
|
|
1610 |
LOGGER.info("remaning" + remaining);
|
|
|
1611 |
|
|
|
1612 |
if (remaining != 0) {
|
|
|
1613 |
catalogListingModel.setRemaining(remaining);
|
|
|
1614 |
} else {
|
|
|
1615 |
catalogListingModel.setRemaining(0);
|
|
|
1616 |
}
|
|
|
1617 |
}
|
|
|
1618 |
}
|
|
|
1619 |
}
|
|
|
1620 |
|
| 26963 |
amit.gupta |
1621 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(false);
|
| 26846 |
tejbeer |
1622 |
if (fofoId > 0) {
|
|
|
1623 |
CustomRetailer customRetailer = customRetailersMap.get(fofoId);
|
|
|
1624 |
model.addAttribute("retailerName",
|
|
|
1625 |
customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
|
|
|
1626 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
1627 |
model.addAttribute("retailerId", customRetailer.getPartnerId());
|
|
|
1628 |
model.addAttribute("counterSize", fs.getCounterSize().toString());
|
|
|
1629 |
} else {
|
|
|
1630 |
model.addAttribute("counterSize", counterSize.toString());
|
|
|
1631 |
}
|
|
|
1632 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
|
|
1633 |
|
|
|
1634 |
List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
|
|
|
1635 |
|
|
|
1636 |
Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getMinimumQty,
|
|
|
1637 |
Comparator.reverseOrder());
|
|
|
1638 |
LOGGER.info("monthlyPlanned" + monthlyPlanned);
|
|
|
1639 |
model.addAttribute("catalogTagListings",
|
|
|
1640 |
catalogModelList.stream().sorted(firstCmp).collect(Collectors.toList()));
|
|
|
1641 |
model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
|
| 27768 |
tejbeer |
1642 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(fofoId));
|
| 26846 |
tejbeer |
1643 |
model.addAttribute("previousPlanningMonth", LocalDate.now().minusMonths(1).getMonth());
|
|
|
1644 |
model.addAttribute("currentPlanningMonth", LocalDate.now().getMonth());
|
|
|
1645 |
|
|
|
1646 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
1647 |
model.addAttribute("totalAmount", totalAmount);
|
|
|
1648 |
model.addAttribute("monthlyPlanned", monthlyPlanned);
|
|
|
1649 |
model.addAttribute("totalPcs", totalPcs);
|
|
|
1650 |
|
|
|
1651 |
UserWallet userWallet = walletService.getUserWallet(fofoId);
|
|
|
1652 |
|
|
|
1653 |
model.addAttribute("userWallet", userWallet);
|
|
|
1654 |
|
|
|
1655 |
return "create-partner-po";
|
|
|
1656 |
|
|
|
1657 |
}
|
|
|
1658 |
|
|
|
1659 |
@RequestMapping(value = "/selectItemColor", method = RequestMethod.GET)
|
|
|
1660 |
public String selectItemColor(HttpServletRequest request, @RequestParam int catalogId, Model model)
|
|
|
1661 |
throws Exception {
|
|
|
1662 |
|
|
|
1663 |
List<Item> selecteditems = itemRepository.selectAllByCatalogItemId(catalogId);
|
|
|
1664 |
|
|
|
1665 |
List<Item> items = new ArrayList<>();
|
|
|
1666 |
for (Item item : selecteditems) {
|
|
|
1667 |
|
|
|
1668 |
TagListing tagListing = tagListingRepository.selectByItemId(item.getId(), true);
|
|
|
1669 |
|
|
|
1670 |
if (tagListing != null) {
|
|
|
1671 |
items.add(item);
|
|
|
1672 |
}
|
|
|
1673 |
|
|
|
1674 |
}
|
|
|
1675 |
model.addAttribute("items", items);
|
|
|
1676 |
LOGGER.info("itemIdAndColorMap" + items);
|
|
|
1677 |
return "select-item-color";
|
|
|
1678 |
}
|
|
|
1679 |
|
| 30003 |
tejbeer |
1680 |
List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com",
|
| 30564 |
tejbeer |
1681 |
"niranjan.kala@smartdukaan.com", "amit.gupta@smartdukaan.com", "tejbeer.kaur@smartdukaan.com");
|
| 30003 |
tejbeer |
1682 |
|
|
|
1683 |
@Autowired
|
|
|
1684 |
private PositionRepository positionRepository;
|
|
|
1685 |
|
|
|
1686 |
@Autowired
|
|
|
1687 |
private PartnerTypeChangeService partnerTypeChangeService;
|
|
|
1688 |
|
|
|
1689 |
@Autowired
|
|
|
1690 |
private com.spice.profitmandi.service.transaction.TransactionService transactionService;
|
|
|
1691 |
|
|
|
1692 |
@Autowired
|
|
|
1693 |
private CategoryRepository categoryRepository;
|
|
|
1694 |
|
| 30044 |
tejbeer |
1695 |
@Autowired
|
|
|
1696 |
private BrandLimitRepository brandLimitRepository;
|
|
|
1697 |
|
| 31663 |
amit.gupta |
1698 |
@Autowired
|
|
|
1699 |
//This is alternate proxy to auth to enable Spring Caching
|
|
|
1700 |
private CsService1 authService1;
|
|
|
1701 |
|
| 30003 |
tejbeer |
1702 |
private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING,
|
|
|
1703 |
OrderStatus.ACCEPTED);
|
|
|
1704 |
|
|
|
1705 |
public static final Map<String, Double> Brand_Amount_Limit = new HashMap<>();
|
|
|
1706 |
|
|
|
1707 |
static {
|
| 30044 |
tejbeer |
1708 |
|
| 30003 |
tejbeer |
1709 |
Brand_Amount_Limit.put("accessories", 10000.00);
|
|
|
1710 |
Brand_Amount_Limit.put("TV", 27000.00);
|
|
|
1711 |
}
|
|
|
1712 |
|
|
|
1713 |
@RequestMapping(value = "/getPartnersBrandWiseDetail", method = RequestMethod.GET)
|
|
|
1714 |
public String getPartnersBrandWiseDetail(HttpServletRequest request, Model model) throws Exception {
|
|
|
1715 |
|
|
|
1716 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1717 |
String email = loginDetails.getEmailId();
|
|
|
1718 |
|
|
|
1719 |
List<String> brands = Arrays.asList("Vivo", "Samsung", "Oppo", "Tecno", "Itel", "OnePlus", "Lava", "Realme",
|
|
|
1720 |
"Xiaomi", "Nokia");
|
|
|
1721 |
|
|
|
1722 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
| 31663 |
amit.gupta |
1723 |
Set<Integer> fofoIds = csService1.getAuthFofoIds(email, true);
|
| 30003 |
tejbeer |
1724 |
|
|
|
1725 |
Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
|
|
|
1726 |
|
| 30024 |
tejbeer |
1727 |
Map<Integer, Map<String, Double>> fofoIdBrandAmountMap = new HashMap<>();
|
| 30003 |
tejbeer |
1728 |
|
|
|
1729 |
Map<Integer, InStockAccessoriesTvFofoIdModel> inStockAccessTv = new HashMap<>();
|
|
|
1730 |
Map<Integer, InStockAccessoriesTvFofoIdModel> pendingIndentAccessTv = new HashMap<>();
|
|
|
1731 |
Map<Integer, InStockAccessoriesTvFofoIdModel> grnPendingAccessTvOrders = new HashMap<>();
|
| 30426 |
tejbeer |
1732 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 30003 |
tejbeer |
1733 |
Map<Integer, CustomRetailer> customRetailers = new HashMap<>();
|
|
|
1734 |
Map<Integer, PartnerType> fofoIdPartnerTypeMap = new HashMap<>();
|
|
|
1735 |
|
| 31694 |
amit.gupta |
1736 |
if (fofoIds != null && fofoIds.size() > 0) {
|
| 30003 |
tejbeer |
1737 |
List<Integer> fofoIdList = new ArrayList<>(fofoIds);
|
|
|
1738 |
|
| 30046 |
tejbeer |
1739 |
Map<Integer, ActivationType> partnerActivationType = fofoStoreRepository.selectByRetailerIds(fofoIdList)
|
|
|
1740 |
.stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getActivationType()));
|
|
|
1741 |
|
|
|
1742 |
model.addAttribute("partnerActivationType", partnerActivationType);
|
|
|
1743 |
model.addAttribute("activationTypes", ActivationType.values());
|
|
|
1744 |
|
| 30003 |
tejbeer |
1745 |
Map<Integer, FofoReportingModel> partnerSalesHeadersMap = csService.getPartnerIdSalesHeaders();
|
|
|
1746 |
|
|
|
1747 |
model.addAttribute("partnerSalesHeadersMap", partnerSalesHeadersMap);
|
| 30044 |
tejbeer |
1748 |
|
|
|
1749 |
Map<Integer, Map<String, Float>> partnerBrandLimitMap = brandLimitRepository.selectAllPartnerBrandLimit()
|
|
|
1750 |
.stream().collect(Collectors.groupingBy(x -> x.getFofoId(),
|
|
|
1751 |
Collectors.toMap(x -> x.getBrand(), x -> x.getBrandLimit())));
|
|
|
1752 |
|
|
|
1753 |
model.addAttribute("partnerBrandLimitMap", partnerBrandLimitMap);
|
| 30426 |
tejbeer |
1754 |
customRetailers = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null)
|
|
|
1755 |
.collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 30024 |
tejbeer |
1756 |
Map<Integer, Map<String, Double>> inStockBrandModel = new HashMap<>();
|
|
|
1757 |
Map<Integer, Map<String, Double>> pendingIndent = new HashMap<>();
|
|
|
1758 |
Map<Integer, Map<String, Double>> grnPendingOrders = new HashMap<>();
|
| 30003 |
tejbeer |
1759 |
|
| 30024 |
tejbeer |
1760 |
// mobile
|
| 30003 |
tejbeer |
1761 |
inStockBrandModel = currentInventorySnapshotRepository.selectSumInStockMobiletabletGroupByBrand(fofoIdList)
|
|
|
1762 |
.stream()
|
|
|
1763 |
.collect(Collectors.groupingBy(InStockBrandFofoIdModel::getFofoId,
|
|
|
1764 |
Collectors.groupingBy(InStockBrandFofoIdModel::getBrand,
|
|
|
1765 |
Collectors.summingDouble(InStockBrandFofoIdModel::getAmount))));
|
|
|
1766 |
|
|
|
1767 |
pendingIndent = transactionService.getInTransitOrders(fofoIdList).stream()
|
| 30024 |
tejbeer |
1768 |
.filter(x -> x.getLineItem().getItem().getCategoryId() == ProfitMandiConstants.MOBILE_CATEGORY_ID)
|
| 30003 |
tejbeer |
1769 |
.collect(Collectors.groupingBy(x -> x.getRetailerId(),
|
|
|
1770 |
Collectors.groupingBy(y -> y.getLineItem().getBrand(),
|
|
|
1771 |
Collectors.summingDouble(y -> (double) y.getTotalAmount()))));
|
|
|
1772 |
|
|
|
1773 |
grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoIdList).stream()
|
| 30024 |
tejbeer |
1774 |
.filter(x -> x.getLineItem().getItem().getCategoryId() == ProfitMandiConstants.MOBILE_CATEGORY_ID)
|
| 30003 |
tejbeer |
1775 |
.collect(Collectors.groupingBy(x -> x.getRetailerId(),
|
|
|
1776 |
Collectors.groupingBy(y -> y.getLineItem().getBrand(),
|
|
|
1777 |
Collectors.summingDouble(y -> (double) y.getTotalAmount()))));
|
|
|
1778 |
|
| 30024 |
tejbeer |
1779 |
// accessories
|
| 30003 |
tejbeer |
1780 |
inStockAccessTv = currentInventorySnapshotRepository.selectSumInStockAccessoriesAndTv(fofoIdList).stream()
|
|
|
1781 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
1782 |
|
|
|
1783 |
pendingIndentAccessTv = orderRepository.selectAllPendingIndentAccessoriesTvGroupByFofoId(fofoIdList)
|
|
|
1784 |
.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
1785 |
|
|
|
1786 |
grnPendingAccessTvOrders = orderRepository.selectAllGrnPendingAccessoriesTvGroupByFofoId(fofoIdList)
|
|
|
1787 |
.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
1788 |
|
| 30024 |
tejbeer |
1789 |
for (Entry<Integer, CustomRetailer> customRetailer : customRetailers.entrySet()) {
|
|
|
1790 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(customRetailer.getKey(),
|
|
|
1791 |
LocalDate.now());
|
|
|
1792 |
fofoIdPartnerTypeMap.put(customRetailer.getKey(), partnerType);
|
|
|
1793 |
|
|
|
1794 |
Map<String, Double> stockBrand = inStockBrandModel.get(customRetailer.getKey());
|
|
|
1795 |
Map<String, Double> pendingIndentBrand = pendingIndent.get(customRetailer.getKey());
|
|
|
1796 |
Map<String, Double> grnBrand = grnPendingOrders.get(customRetailer.getKey());
|
|
|
1797 |
double totalAmount = 0;
|
|
|
1798 |
|
|
|
1799 |
Map<String, Double> brandAmountMap = new HashMap<>();
|
|
|
1800 |
for (String brand : brands) {
|
|
|
1801 |
|
|
|
1802 |
double stockValue = 0;
|
|
|
1803 |
double pendingValue = 0;
|
|
|
1804 |
double grnValue = 0;
|
|
|
1805 |
if (stockBrand != null) {
|
|
|
1806 |
|
|
|
1807 |
if (stockBrand.get(brand) != null) {
|
|
|
1808 |
stockValue = stockBrand.get(brand);
|
|
|
1809 |
}
|
|
|
1810 |
}
|
|
|
1811 |
|
|
|
1812 |
if (pendingIndentBrand != null) {
|
|
|
1813 |
if (pendingIndentBrand.get(brand) != null) {
|
|
|
1814 |
pendingValue = pendingIndentBrand.get(brand);
|
|
|
1815 |
}
|
|
|
1816 |
}
|
|
|
1817 |
|
|
|
1818 |
if (grnBrand != null) {
|
|
|
1819 |
if (grnBrand.get(brand) != null) {
|
|
|
1820 |
grnValue = grnBrand.get(brand);
|
|
|
1821 |
}
|
|
|
1822 |
}
|
|
|
1823 |
|
|
|
1824 |
totalAmount = stockValue + pendingValue + grnValue;
|
|
|
1825 |
|
|
|
1826 |
brandAmountMap.put(brand, totalAmount);
|
|
|
1827 |
|
|
|
1828 |
}
|
|
|
1829 |
|
|
|
1830 |
fofoIdBrandAmountMap.put(customRetailer.getKey(), brandAmountMap);
|
|
|
1831 |
|
|
|
1832 |
}
|
|
|
1833 |
|
|
|
1834 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
|
|
|
1835 |
.selectAll(new ArrayList<>(fofoIdList), LocalDate.now().minusDays(1));
|
|
|
1836 |
if (!partnerDailyInvestments.isEmpty()) {
|
|
|
1837 |
partnerDailyInvestmentMap = partnerDailyInvestments.stream()
|
|
|
1838 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
1839 |
}
|
|
|
1840 |
|
| 30003 |
tejbeer |
1841 |
}
|
|
|
1842 |
|
|
|
1843 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
1844 |
|
| 30024 |
tejbeer |
1845 |
LOGGER.info("fofoIdBrandAmountMap" + fofoIdBrandAmountMap);
|
| 30003 |
tejbeer |
1846 |
|
|
|
1847 |
model.addAttribute("partnerDailyInvestmentMap", partnerDailyInvestmentMap);
|
|
|
1848 |
|
|
|
1849 |
model.addAttribute("brands", brands);
|
|
|
1850 |
|
|
|
1851 |
model.addAttribute("brandAmountLimit", Brand_Amount_Limit);
|
| 30024 |
tejbeer |
1852 |
model.addAttribute("fofoIdBrandAmountMap", fofoIdBrandAmountMap);
|
| 30003 |
tejbeer |
1853 |
|
|
|
1854 |
model.addAttribute("inStockAccessTv", inStockAccessTv);
|
|
|
1855 |
model.addAttribute("pendingIndentAccessTv", pendingIndentAccessTv);
|
|
|
1856 |
model.addAttribute("grnPendingAccessTvOrders", grnPendingAccessTvOrders);
|
|
|
1857 |
model.addAttribute("fofoIdPartnerTypeMap", fofoIdPartnerTypeMap);
|
|
|
1858 |
return "partner-brandwise-detail";
|
|
|
1859 |
}
|
|
|
1860 |
|
| 30046 |
tejbeer |
1861 |
@RequestMapping(value = "/changeActivationType", method = RequestMethod.POST)
|
|
|
1862 |
public String changeActivationType(HttpServletRequest request, @RequestParam String code,
|
| 31317 |
tejbeer |
1863 |
@RequestParam ActivationType activationType, Model model) throws Exception {
|
| 30046 |
tejbeer |
1864 |
|
|
|
1865 |
FofoStore fofoStore = fofoStoreRepository.selectByStoreCode(code);
|
|
|
1866 |
|
|
|
1867 |
fofoStore.setActivationType(activationType);
|
|
|
1868 |
|
| 31238 |
amit.gupta |
1869 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 30046 |
tejbeer |
1870 |
return "response";
|
|
|
1871 |
|
|
|
1872 |
}
|
|
|
1873 |
|
| 30017 |
amit.gupta |
1874 |
@RequestMapping(value = "/createPo", method = RequestMethod.POST)
|
|
|
1875 |
public String createPo(HttpServletRequest request, @RequestBody SuggestedPoModel monthlyPoModel, Model model)
|
|
|
1876 |
throws Exception {
|
|
|
1877 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1878 |
SuggestedPo mp = new SuggestedPo();
|
|
|
1879 |
mp.setFofoId(monthlyPoModel.getFofoId());
|
|
|
1880 |
mp.setCreateTimestamp(LocalDateTime.now());
|
|
|
1881 |
mp.setStatus("open");
|
|
|
1882 |
mp.setAuthId(loginDetails.getEmailId());
|
|
|
1883 |
suggestedPoRepository.persist(mp);
|
|
|
1884 |
|
|
|
1885 |
for (SuggestedPoIdModel poId : monthlyPoModel.getPoIds()) {
|
|
|
1886 |
SuggestedPoDetail mpd = new SuggestedPoDetail();
|
|
|
1887 |
mpd.setItemId(poId.getItemId());
|
|
|
1888 |
mpd.setQuantity(poId.getQty());
|
|
|
1889 |
mpd.setUpdatedTimestamp(LocalDateTime.now());
|
|
|
1890 |
mpd.setPoId(mp.getId());
|
|
|
1891 |
suggestedPoDetailRepository.persist(mpd);
|
|
|
1892 |
}
|
|
|
1893 |
|
|
|
1894 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
1895 |
sendNotificationModel.setCampaignName("Alert");
|
|
|
1896 |
sendNotificationModel.setMessage("Suggested Po");
|
|
|
1897 |
sendNotificationModel.setType("url");
|
|
|
1898 |
sendNotificationModel.setTitle("Alert");
|
|
|
1899 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/partnerPo/" + mp.getId());
|
|
|
1900 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
|
|
|
1901 |
sendNotificationModel.setMessageType(MessageType.notification);
|
|
|
1902 |
int userId = userAccountRepository.selectUserIdByRetailerId(monthlyPoModel.getFofoId());
|
|
|
1903 |
|
|
|
1904 |
sendNotificationModel.setUserIds(Arrays.asList(userId));
|
|
|
1905 |
notificationService.sendNotification(sendNotificationModel);
|
| 31238 |
amit.gupta |
1906 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 30017 |
amit.gupta |
1907 |
|
|
|
1908 |
return "response";
|
|
|
1909 |
}
|
|
|
1910 |
|
| 30003 |
tejbeer |
1911 |
@RequestMapping(value = "/getPartnerShortageStock", method = RequestMethod.GET)
|
|
|
1912 |
public String getPartnerShortageStock(HttpServletRequest request,
|
| 31317 |
tejbeer |
1913 |
@RequestParam(required = false, defaultValue = "") String brand, @RequestParam int fofoId, Model model)
|
| 30003 |
tejbeer |
1914 |
throws Exception {
|
|
|
1915 |
|
|
|
1916 |
Map<Integer, Map<Integer, List<SaholicPOItem>>> warehousePoItemAvailabilityMap = saholicInventoryService
|
|
|
1917 |
.getSaholicPOItems();
|
|
|
1918 |
|
|
|
1919 |
List<FocusedModelShortageModel> focusedModelShortageList = new ArrayList<>();
|
|
|
1920 |
CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
|
|
|
1921 |
Map<Integer, Integer> processingOrderMap = null;
|
|
|
1922 |
Map<Integer, Integer> catalogIdAndQtyMap = null;
|
|
|
1923 |
Map<Integer, Integer> grnPendingOrdersMap = null;
|
|
|
1924 |
|
| 30044 |
tejbeer |
1925 |
List<PartnerStockDescriptionModel> inStocks = new ArrayList<>();
|
|
|
1926 |
|
|
|
1927 |
List<PartnerStockDescriptionModel> grnPendings = new ArrayList<>();
|
|
|
1928 |
|
|
|
1929 |
List<PartnerStockDescriptionModel> pendingIndents = new ArrayList<>();
|
|
|
1930 |
|
| 30003 |
tejbeer |
1931 |
Map<Integer, Integer> currentInventorySnapshot = currentInventorySnapshotRepository.selectByFofoId(fofoId)
|
|
|
1932 |
.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
|
|
|
1933 |
|
|
|
1934 |
if (!currentInventorySnapshot.isEmpty()) {
|
| 30044 |
tejbeer |
1935 |
if (!brand.equals("undefined") && !brand.equals("accessories") && !brand.equals("TV")) {
|
|
|
1936 |
catalogIdAndQtyMap = itemRepository.selectByIds(currentInventorySnapshot.keySet()).stream()
|
|
|
1937 |
.filter(x -> x.getBrand().equals(brand))
|
|
|
1938 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1939 |
Collectors.summingInt(x -> currentInventorySnapshot.get(x.getId()))));
|
| 30003 |
tejbeer |
1940 |
|
| 30044 |
tejbeer |
1941 |
} else {
|
|
|
1942 |
catalogIdAndQtyMap = itemRepository.selectByIds(currentInventorySnapshot.keySet()).stream()
|
|
|
1943 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1944 |
Collectors.summingInt(x -> currentInventorySnapshot.get(x.getId()))));
|
|
|
1945 |
}
|
|
|
1946 |
inStocks.addAll(getBrandItemwiseDescription(brand, catalogIdAndQtyMap));
|
| 30003 |
tejbeer |
1947 |
}
|
|
|
1948 |
|
|
|
1949 |
Map<Integer, Integer> grnPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
|
|
|
1950 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
1951 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
1952 |
if (!grnPendingOrders.isEmpty()) {
|
|
|
1953 |
|
| 30044 |
tejbeer |
1954 |
if (!brand.equals("undefined") && !brand.equals("accessories") && !brand.equals("TV")) {
|
|
|
1955 |
grnPendingOrdersMap = itemRepository.selectByIds(grnPendingOrders.keySet()).stream()
|
|
|
1956 |
.filter(x -> x.getBrand().equals(brand))
|
|
|
1957 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1958 |
Collectors.summingInt(x -> grnPendingOrders.get(x.getId()))));
|
|
|
1959 |
|
|
|
1960 |
} else {
|
|
|
1961 |
grnPendingOrdersMap = itemRepository.selectByIds(grnPendingOrders.keySet()).stream()
|
|
|
1962 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1963 |
Collectors.summingInt(x -> grnPendingOrders.get(x.getId()))));
|
|
|
1964 |
}
|
|
|
1965 |
grnPendings.addAll(getBrandItemwiseDescription(brand, grnPendingOrdersMap));
|
|
|
1966 |
|
| 30003 |
tejbeer |
1967 |
}
|
|
|
1968 |
|
|
|
1969 |
Map<Integer, Integer> processingOrder = orderRepository.selectOrders(fofoId, orderStatusList).stream()
|
|
|
1970 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
1971 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
1972 |
if (!processingOrder.isEmpty()) {
|
| 30044 |
tejbeer |
1973 |
if (!brand.equals("undefined") && !brand.equals("accessories") && !brand.equals("TV")) {
|
|
|
1974 |
processingOrderMap = itemRepository.selectByIds(processingOrder.keySet()).stream()
|
|
|
1975 |
.filter(x -> x.getBrand().equals(brand)).collect(Collectors.groupingBy(
|
|
|
1976 |
x -> x.getCatalogItemId(), Collectors.summingInt(x -> processingOrder.get(x.getId()))));
|
| 30003 |
tejbeer |
1977 |
|
| 30044 |
tejbeer |
1978 |
} else {
|
|
|
1979 |
processingOrderMap = itemRepository.selectByIds(processingOrder.keySet()).stream()
|
|
|
1980 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId(),
|
|
|
1981 |
Collectors.summingInt(x -> processingOrder.get(x.getId()))));
|
|
|
1982 |
}
|
|
|
1983 |
pendingIndents.addAll(getBrandItemwiseDescription(brand, processingOrderMap));
|
|
|
1984 |
|
| 30003 |
tejbeer |
1985 |
}
|
|
|
1986 |
|
|
|
1987 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
|
|
|
1988 |
.collect(Collectors.toList());
|
|
|
1989 |
LOGGER.info("regionIds" + regionIds);
|
|
|
1990 |
if (regionIds.size() == 0) {
|
|
|
1991 |
LOGGER.info("No region found for partner {}", fofoId);
|
|
|
1992 |
|
|
|
1993 |
}
|
|
|
1994 |
Map<Integer, Optional<Integer>> focusedCatalogIdAndQtyMap = focusedModelRepository
|
|
|
1995 |
.selectAllByRegionIds(regionIds).stream().collect(Collectors.groupingBy(FocusedModel::getCatalogId,
|
|
|
1996 |
Collectors.mapping(FocusedModel::getObsMinimumQty, Collectors.maxBy(Integer::compareTo))));
|
|
|
1997 |
|
|
|
1998 |
for (Map.Entry<Integer, Optional<Integer>> entry : focusedCatalogIdAndQtyMap.entrySet()) {
|
|
|
1999 |
List<Item> items = itemRepository.selectAllByCatalogItemId(entry.getKey());
|
|
|
2000 |
|
|
|
2001 |
if (brand.equals("undefined") || items.get(0).getBrand().equals(brand)) {
|
|
|
2002 |
|
|
|
2003 |
FocusedModelShortageModel fm = this.getFocusedModelShortage(entry.getValue().get(), entry.getKey(),
|
| 31317 |
tejbeer |
2004 |
processingOrderMap, grnPendingOrdersMap, catalogIdAndQtyMap, fofoId,
|
|
|
2005 |
warehousePoItemAvailabilityMap, items, customRetailer);
|
| 30003 |
tejbeer |
2006 |
|
|
|
2007 |
focusedModelShortageList.add(fm);
|
|
|
2008 |
} else if (brand.equals("accessories")) {
|
|
|
2009 |
|
|
|
2010 |
if (items.get(0).getCategoryId() != ProfitMandiConstants.MOBILE_CATEGORY_ID) {
|
|
|
2011 |
if (items.get(0).getCategoryId() != 0) {
|
|
|
2012 |
Category category = categoryRepository.selectById(items.get(0).getCategoryId());
|
|
|
2013 |
|
|
|
2014 |
if (category.getParentCategoryId() == 10011) {
|
|
|
2015 |
FocusedModelShortageModel fm = this.getFocusedModelShortage(entry.getValue().get(),
|
| 31317 |
tejbeer |
2016 |
entry.getKey(), processingOrderMap, grnPendingOrdersMap, catalogIdAndQtyMap, fofoId,
|
|
|
2017 |
warehousePoItemAvailabilityMap, items, customRetailer);
|
| 30003 |
tejbeer |
2018 |
|
|
|
2019 |
focusedModelShortageList.add(fm);
|
|
|
2020 |
|
|
|
2021 |
}
|
|
|
2022 |
}
|
|
|
2023 |
|
|
|
2024 |
}
|
|
|
2025 |
|
|
|
2026 |
} else if (brand.equals("TV")) {
|
|
|
2027 |
|
|
|
2028 |
if (items.get(0).getCategoryId() != ProfitMandiConstants.MOBILE_CATEGORY_ID) {
|
|
|
2029 |
LOGGER.info("items.get(0).getCategoryId()" + items.get(0).getCategoryId());
|
|
|
2030 |
if (items.get(0).getCategoryId() != 0) {
|
|
|
2031 |
|
|
|
2032 |
Category category = categoryRepository.selectById(items.get(0).getCategoryId());
|
|
|
2033 |
|
|
|
2034 |
if (category.getParentCategoryId() == 14200) {
|
|
|
2035 |
FocusedModelShortageModel fm = this.getFocusedModelShortage(entry.getValue().get(),
|
|
|
2036 |
entry.getKey(), processingOrderMap, grnPendingOrdersMap, catalogIdAndQtyMap, fofoId,
|
| 31317 |
tejbeer |
2037 |
warehousePoItemAvailabilityMap, items, customRetailer);
|
| 30003 |
tejbeer |
2038 |
|
|
|
2039 |
focusedModelShortageList.add(fm);
|
|
|
2040 |
|
|
|
2041 |
}
|
|
|
2042 |
}
|
|
|
2043 |
|
|
|
2044 |
}
|
|
|
2045 |
|
|
|
2046 |
}
|
|
|
2047 |
|
|
|
2048 |
}
|
|
|
2049 |
|
|
|
2050 |
LOGGER.info("focusedModelShortageList" + focusedModelShortageList);
|
|
|
2051 |
|
|
|
2052 |
model.addAttribute("focusedModelShortageList", focusedModelShortageList);
|
|
|
2053 |
|
| 30044 |
tejbeer |
2054 |
model.addAttribute("inStocks", inStocks);
|
|
|
2055 |
|
|
|
2056 |
model.addAttribute("grnPendings", grnPendings);
|
|
|
2057 |
|
|
|
2058 |
model.addAttribute("pendingIndents", pendingIndents);
|
|
|
2059 |
|
| 30003 |
tejbeer |
2060 |
model.addAttribute("customRetailer", customRetailer);
|
| 30044 |
tejbeer |
2061 |
|
|
|
2062 |
model.addAttribute("brand", brand);
|
|
|
2063 |
|
|
|
2064 |
if (brand.equals("undefined")) {
|
|
|
2065 |
|
|
|
2066 |
Map<String, List<FocusedModelShortageModel>> focusedModelShortageBrandMap = focusedModelShortageList
|
|
|
2067 |
.stream().collect(Collectors.groupingBy(x -> x.getBrandName()));
|
|
|
2068 |
|
|
|
2069 |
Map<String, List<PartnerStockDescriptionModel>> inStockBrandMap = inStocks.stream()
|
|
|
2070 |
.collect(Collectors.groupingBy(x -> x.getBrand()));
|
|
|
2071 |
|
|
|
2072 |
LOGGER.info("inStockBrandMap" + inStockBrandMap);
|
|
|
2073 |
|
|
|
2074 |
Map<String, List<PartnerStockDescriptionModel>> grnPendingBrandMap = grnPendings.stream()
|
|
|
2075 |
.collect(Collectors.groupingBy(x -> x.getBrand()));
|
|
|
2076 |
|
|
|
2077 |
LOGGER.info("grnPendingBrandMap" + grnPendingBrandMap);
|
|
|
2078 |
|
|
|
2079 |
Map<String, List<PartnerStockDescriptionModel>> pendingIndentBrandMap = pendingIndents.stream()
|
|
|
2080 |
.collect(Collectors.groupingBy(x -> x.getBrand()));
|
|
|
2081 |
|
|
|
2082 |
LOGGER.info("pendingIndentBrandMap" + pendingIndentBrandMap);
|
|
|
2083 |
|
|
|
2084 |
model.addAttribute("inStockBrandMap", inStockBrandMap);
|
|
|
2085 |
|
|
|
2086 |
model.addAttribute("grnPendingBrandMap", grnPendingBrandMap);
|
|
|
2087 |
|
|
|
2088 |
model.addAttribute("focusedModelShortageBrandMap", focusedModelShortageBrandMap);
|
|
|
2089 |
|
|
|
2090 |
model.addAttribute("pendingIndentBrandMap", pendingIndentBrandMap);
|
|
|
2091 |
|
|
|
2092 |
}
|
| 30003 |
tejbeer |
2093 |
return "partner-stock";
|
|
|
2094 |
|
|
|
2095 |
}
|
|
|
2096 |
|
| 30044 |
tejbeer |
2097 |
private List<PartnerStockDescriptionModel> getBrandItemwiseDescription(String brand,
|
| 31317 |
tejbeer |
2098 |
Map<Integer, Integer> catalogIdAndQtyMap) throws ProfitMandiBusinessException {
|
| 30044 |
tejbeer |
2099 |
List<PartnerStockDescriptionModel> inStocks = new ArrayList<>();
|
|
|
2100 |
|
|
|
2101 |
for (Entry<Integer, Integer> inStock : catalogIdAndQtyMap.entrySet()) {
|
|
|
2102 |
List<Item> items = itemRepository.selectAllByCatalogItemId(inStock.getKey());
|
|
|
2103 |
|
|
|
2104 |
if (brand.equals("accessories")) {
|
|
|
2105 |
if (items.get(0).getCategoryId() != ProfitMandiConstants.MOBILE_CATEGORY_ID) {
|
|
|
2106 |
|
|
|
2107 |
if (items.get(0).getCategoryId() != 0) {
|
|
|
2108 |
Category category = categoryRepository.selectById(items.get(0).getCategoryId());
|
|
|
2109 |
|
|
|
2110 |
if (category.getParentCategoryId() == 10011) {
|
|
|
2111 |
PartnerStockDescriptionModel psdp = new PartnerStockDescriptionModel();
|
|
|
2112 |
psdp.setBrand(items.get(0).getBrand());
|
|
|
2113 |
psdp.setItemDescription(items.get(0).getBrand() + " " + items.get(0).getModelName() + " "
|
|
|
2114 |
+ items.get(0).getModelNumber());
|
|
|
2115 |
psdp.setQty(inStock.getValue());
|
|
|
2116 |
inStocks.add(psdp);
|
|
|
2117 |
}
|
|
|
2118 |
}
|
|
|
2119 |
|
|
|
2120 |
}
|
|
|
2121 |
|
|
|
2122 |
} else if (brand.equals("TV")) {
|
|
|
2123 |
if (items.get(0).getCategoryId() != ProfitMandiConstants.MOBILE_CATEGORY_ID) {
|
|
|
2124 |
|
|
|
2125 |
if (items.get(0).getCategoryId() != 0) {
|
|
|
2126 |
Category category = categoryRepository.selectById(items.get(0).getCategoryId());
|
|
|
2127 |
|
|
|
2128 |
if (category.getParentCategoryId() == 14200) {
|
|
|
2129 |
PartnerStockDescriptionModel psdp = new PartnerStockDescriptionModel();
|
|
|
2130 |
psdp.setBrand(items.get(0).getBrand());
|
|
|
2131 |
psdp.setItemDescription(items.get(0).getBrand() + " " + items.get(0).getModelName() + " "
|
|
|
2132 |
+ items.get(0).getModelNumber());
|
|
|
2133 |
psdp.setQty(inStock.getValue());
|
|
|
2134 |
inStocks.add(psdp);
|
|
|
2135 |
}
|
|
|
2136 |
}
|
|
|
2137 |
|
|
|
2138 |
}
|
|
|
2139 |
|
|
|
2140 |
} else {
|
|
|
2141 |
PartnerStockDescriptionModel psdp = new PartnerStockDescriptionModel();
|
|
|
2142 |
psdp.setBrand(items.get(0).getBrand());
|
|
|
2143 |
psdp.setItemDescription(items.get(0).getBrand() + " " + items.get(0).getModelName() + " "
|
|
|
2144 |
+ items.get(0).getModelNumber());
|
|
|
2145 |
psdp.setQty(inStock.getValue());
|
|
|
2146 |
inStocks.add(psdp);
|
|
|
2147 |
}
|
|
|
2148 |
|
|
|
2149 |
}
|
|
|
2150 |
|
|
|
2151 |
return inStocks;
|
|
|
2152 |
}
|
|
|
2153 |
|
| 30003 |
tejbeer |
2154 |
private FocusedModelShortageModel getFocusedModelShortage(int qty, int catalogId,
|
| 31317 |
tejbeer |
2155 |
Map<Integer, Integer> processingOrderMap, Map<Integer, Integer> grnPendingOrdersMap,
|
|
|
2156 |
Map<Integer, Integer> catalogIdAndQtyMap, int fofoId,
|
|
|
2157 |
Map<Integer, Map<Integer, List<SaholicPOItem>>> warehousePoItemAvailabilityMap, List<Item> items,
|
|
|
2158 |
CustomRetailer customRetailer) throws ProfitMandiBusinessException {
|
| 30003 |
tejbeer |
2159 |
|
|
|
2160 |
int minQty = qty;
|
|
|
2161 |
int inStockQty = 0;
|
|
|
2162 |
int processingQty = 0;
|
|
|
2163 |
int grnPendingQty = 0;
|
|
|
2164 |
int allColorNetAvailability = 0;
|
|
|
2165 |
int allColorPoAvailability = 0;
|
|
|
2166 |
if (processingOrderMap != null) {
|
|
|
2167 |
processingQty = (processingOrderMap.get(catalogId) == null) ? 0 : processingOrderMap.get(catalogId);
|
|
|
2168 |
|
|
|
2169 |
}
|
|
|
2170 |
if (grnPendingOrdersMap != null) {
|
|
|
2171 |
grnPendingQty = (grnPendingOrdersMap.get(catalogId) == null) ? 0 : grnPendingOrdersMap.get(catalogId);
|
|
|
2172 |
|
|
|
2173 |
}
|
|
|
2174 |
if (catalogIdAndQtyMap != null) {
|
|
|
2175 |
inStockQty = (catalogIdAndQtyMap.get(catalogId) == null) ? 0 : catalogIdAndQtyMap.get(catalogId);
|
|
|
2176 |
|
|
|
2177 |
}
|
|
|
2178 |
|
|
|
2179 |
int grnStockQty = grnPendingQty + inStockQty;
|
|
|
2180 |
int totalQty = processingQty + grnPendingQty + inStockQty;
|
|
|
2181 |
|
|
|
2182 |
int shortageQty = minQty - totalQty;
|
|
|
2183 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
2184 |
|
|
|
2185 |
Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = warehousePoItemAvailabilityMap
|
|
|
2186 |
.get(fofoStore.getWarehouseId());
|
|
|
2187 |
|
|
|
2188 |
for (Item it : items) {
|
| 31317 |
tejbeer |
2189 |
List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(it.getId(),
|
|
|
2190 |
fofoStore.getWarehouseId());
|
| 30003 |
tejbeer |
2191 |
List<SaholicPOItem> poItemAvailability = null;
|
|
|
2192 |
|
|
|
2193 |
if (poItemAvailabilityMap != null) {
|
|
|
2194 |
poItemAvailability = poItemAvailabilityMap.get(it.getId());
|
|
|
2195 |
}
|
|
|
2196 |
if (currentAvailability != null) {
|
|
|
2197 |
allColorNetAvailability += currentAvailability.stream()
|
| 30664 |
amit.gupta |
2198 |
.collect(Collectors.summingInt(SaholicCISTable::getNetAvailability));
|
| 30003 |
tejbeer |
2199 |
}
|
|
|
2200 |
|
|
|
2201 |
if (poItemAvailability != null) {
|
|
|
2202 |
allColorPoAvailability += poItemAvailability.stream()
|
|
|
2203 |
.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty));
|
|
|
2204 |
}
|
|
|
2205 |
|
|
|
2206 |
}
|
|
|
2207 |
|
|
|
2208 |
FocusedModelShortageModel fm = new FocusedModelShortageModel();
|
|
|
2209 |
fm.setFofoId(fofoId);
|
|
|
2210 |
fm.setStoreCode(fofoStore.getCode());
|
|
|
2211 |
fm.setStoreName(customRetailer.getBusinessName());
|
|
|
2212 |
fm.setBrandName(items.get(0).getBrand());
|
|
|
2213 |
fm.setModelName(items.get(0).getModelName());
|
|
|
2214 |
fm.setModelNumber(items.get(0).getModelNumber());
|
|
|
2215 |
fm.setGrnStockQty(grnStockQty);
|
|
|
2216 |
fm.setPendingIndentQty(processingQty);
|
|
|
2217 |
fm.setShortageQty(shortageQty);
|
| 31393 |
amit.gupta |
2218 |
fm.setPoAvailability(allColorPoAvailability);
|
| 30003 |
tejbeer |
2219 |
fm.setItemName(items.get(0).getBrand() + items.get(0).getModelNumber() + items.get(0).getModelName());
|
| 31393 |
amit.gupta |
2220 |
fm.setAvailability(allColorNetAvailability);
|
| 30003 |
tejbeer |
2221 |
return fm;
|
|
|
2222 |
|
|
|
2223 |
}
|
|
|
2224 |
|
| 30017 |
amit.gupta |
2225 |
@RequestMapping(value = "/indent/send-po-notification", method = RequestMethod.GET)
|
|
|
2226 |
public String SendPONotification(HttpServletRequest request, Model model) {
|
|
|
2227 |
model.addAttribute("warehouses", ProfitMandiConstants.WAREHOUSE_MAP);
|
|
|
2228 |
return "send-po-notification";
|
|
|
2229 |
}
|
|
|
2230 |
|
|
|
2231 |
@RequestMapping(value = "/indent/send-po-notification", method = RequestMethod.POST)
|
| 30044 |
tejbeer |
2232 |
public String sendPONotification(HttpServletRequest request, @RequestBody POItemWarehouseModel poItemWarehouseModel,
|
| 31317 |
tejbeer |
2233 |
Model model) throws Exception {
|
| 30017 |
amit.gupta |
2234 |
|
| 30426 |
tejbeer |
2235 |
Map<Integer, Item> selectedCatalogItemMap = itemRepository
|
|
|
2236 |
.selectAllByCatalogIds(new HashSet<>(poItemWarehouseModel.getCatalogIds())).stream()
|
|
|
2237 |
.collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x, (existing, replacement) -> existing));
|
| 30017 |
amit.gupta |
2238 |
|
| 30080 |
amit.gupta |
2239 |
Set<String> brands = selectedCatalogItemMap.values().stream().map(x -> x.getBrand().toLowerCase())
|
| 30044 |
tejbeer |
2240 |
.collect(Collectors.toSet());
|
| 30080 |
amit.gupta |
2241 |
|
| 30017 |
amit.gupta |
2242 |
int warehouseId = poItemWarehouseModel.getWarehouseId();
|
| 30080 |
amit.gupta |
2243 |
for (String brand : brands) {
|
| 30096 |
amit.gupta |
2244 |
List<String> modelNames = selectedCatalogItemMap.entrySet().stream()
|
| 30426 |
tejbeer |
2245 |
.filter(x -> x.getValue().getBrand().toLowerCase().equals(brand))
|
|
|
2246 |
.map(x -> x.getValue().getItemDescriptionNoColor()).collect(Collectors.toList());
|
| 30080 |
amit.gupta |
2247 |
SendNotificationModel sendNotificationModel = new SendNotificationModel();
|
|
|
2248 |
sendNotificationModel.setCampaignName("SendPo");
|
|
|
2249 |
sendNotificationModel.setTitle(String.format(PO_TITLE_STRING));
|
| 30096 |
amit.gupta |
2250 |
sendNotificationModel.setMessage(String.join(", ", modelNames));
|
| 30080 |
amit.gupta |
2251 |
sendNotificationModel.setType("url");
|
|
|
2252 |
sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
|
|
|
2253 |
sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
|
|
|
2254 |
sendNotificationModel.setMessageType(MessageType.notification);
|
| 30017 |
amit.gupta |
2255 |
|
| 30426 |
tejbeer |
2256 |
List<BrandRegionMapping> brandRegionMappings = brandRegionMappingRepository.selectAll().stream()
|
|
|
2257 |
.filter(x -> brand.equals(x.getBrand().toLowerCase()) && x.getFromWarehouseId() == warehouseId
|
|
|
2258 |
&& !x.isAccessory())
|
| 30080 |
amit.gupta |
2259 |
.collect(Collectors.toList());
|
|
|
2260 |
List<Integer> toWarehouseIds = brandRegionMappings.stream().map(x -> x.getToWarehouseId())
|
|
|
2261 |
.collect(Collectors.toList());
|
| 30017 |
amit.gupta |
2262 |
|
| 30080 |
amit.gupta |
2263 |
List<Integer> fofoIds = fofoStoreRepository.selectByWarehouseIds(toWarehouseIds).stream()
|
|
|
2264 |
.filter(x -> !x.isInternal() && x.isActive()).map(x -> x.getId()).collect(Collectors.toList());
|
| 30017 |
amit.gupta |
2265 |
|
| 30080 |
amit.gupta |
2266 |
List<Integer> userIds = userAccountRepository.selectUserIdsByRetailerIds(fofoIds);
|
|
|
2267 |
sendNotificationModel.setUserIds(userIds);
|
|
|
2268 |
notificationService.sendNotification(sendNotificationModel);
|
|
|
2269 |
}
|
| 31238 |
amit.gupta |
2270 |
model.addAttribute("response1", true);
|
| 30017 |
amit.gupta |
2271 |
return "response";
|
|
|
2272 |
}
|
|
|
2273 |
|
| 25721 |
tejbeer |
2274 |
}
|