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