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