| Line 42... |
Line 42... |
| 42 |
import com.spice.profitmandi.common.model.ItemIdAvailability;
|
42 |
import com.spice.profitmandi.common.model.ItemIdAvailability;
|
| 43 |
import com.spice.profitmandi.common.model.StockAllocationModel;
|
43 |
import com.spice.profitmandi.common.model.StockAllocationModel;
|
| 44 |
import com.spice.profitmandi.common.util.FileUtil;
|
44 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 45 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
45 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 46 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
46 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 47 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
- |
|
| 48 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
47 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 49 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
48 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 50 |
import com.spice.profitmandi.dao.entity.user.User;
|
49 |
import com.spice.profitmandi.dao.entity.user.User;
|
| 51 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
50 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 52 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
51 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| Line 168... |
Line 167... |
| 168 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
|
167 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
|
| 169 |
Set<Integer> roleIds = cookiesProcessor.getCookiesObject(request).getRoleIds();
|
168 |
Set<Integer> roleIds = cookiesProcessor.getCookiesObject(request).getRoleIds();
|
| 170 |
LOGGER.info("Counter size is {}", counterSize);
|
169 |
LOGGER.info("Counter size is {}", counterSize);
|
| 171 |
LOGGER.info("Fofo Id is {}", fofoId);
|
170 |
LOGGER.info("Fofo Id is {}", fofoId);
|
| 172 |
if (roleManager.isAdmin(roleIds)) {
|
171 |
if (roleManager.isAdmin(roleIds)) {
|
| 173 |
List<StockAllocationModel> stockAllocationList = stockAllocationService.getStockAllocation(counterSize,
|
- |
|
| 174 |
true);
|
- |
|
| 175 |
Map<Integer, StockAllocationModel> modelStockAllocationMap = stockAllocationList.stream()
|
- |
|
| 176 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
|
- |
|
| 177 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
172 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
| 178 |
.collect(Collectors.toList());
|
173 |
.collect(Collectors.toList());
|
| 179 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
174 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
| 180 |
|
175 |
|
| 181 |
Map<String, CatalogListingModel> catalogListingMap = new HashMap<>();
|
176 |
List<StockAllocationModel> stockAllocationList = stockAllocationService.getStockAllocation(counterSize,
|
| 182 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
177 |
true);
|
| 183 |
Iterator<TagListing> iterator = tagListings.iterator();
|
178 |
Map<Integer, Integer> modelStockAllocationMap = stockAllocationList.stream()
|
| 184 |
Map<Integer, List<CurrentInventorySnapshot>> itemListSnapshot = new HashMap<>();
|
179 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
|
| 185 |
|
180 |
|
| - |
|
181 |
Map<String, Integer> catalogUserQtyMap = new HashMap<>();
|
| 186 |
currentInventorySnapshotRepository.selectAll(Optional.of(true)).stream().forEach(x -> {
|
182 |
currentInventorySnapshotRepository.selectAll(Optional.of(true)).stream().forEach(x -> {
|
| - |
|
183 |
int retailerId = x.getFofoId();
|
| - |
|
184 |
int catalogId;
|
| - |
|
185 |
try {
|
| - |
|
186 |
catalogId = itemRepository.selectById(x.getItemId()).getCatalogItemId();
|
| - |
|
187 |
String key = catalogId + "-" + retailerId;
|
| 187 |
if (!itemListSnapshot.containsKey(x.getItemId())) {
|
188 |
if (!catalogUserQtyMap.containsKey(key)) {
|
| - |
|
189 |
catalogUserQtyMap.put(key, 0);
|
| - |
|
190 |
}
|
| 188 |
itemListSnapshot.put(x.getItemId(), new ArrayList<>());
|
191 |
catalogUserQtyMap.put(key, catalogUserQtyMap.get(key) + x.getAvailability());
|
| - |
|
192 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
193 |
// TODO Auto-generated catch block
|
| - |
|
194 |
throw new RuntimeException(e);
|
| 189 |
}
|
195 |
}
|
| 190 |
itemListSnapshot.get(x.getItemId()).add(x);
|
- |
|
| 191 |
});
|
196 |
});
|
| 192 |
|
197 |
|
| 193 |
List<Order> inTransitOrders = orderRepository.selectOrders(fofoIds, partnerPendingOrderList);
|
198 |
List<Order> inTransitOrders = orderRepository.selectOrders(fofoIds, partnerPendingOrderList);
|
| 194 |
Map<String, Integer> itemsInTransit = inTransitOrders.stream()
|
199 |
Map<String, Integer> catalogUserInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> {
|
| - |
|
200 |
try {
|
| - |
|
201 |
return itemRepository.selectById(x.getLineItem().getItemId()).getCatalogItemId() + "-"
|
| 195 |
.collect(Collectors.groupingBy(
|
202 |
+ x.getRetailerId();
|
| 196 |
x -> new String(x.getLineItem().getItemId() + "-" + x.getRetailerId()),
|
203 |
} catch (ProfitMandiBusinessException e) {
|
| - |
|
204 |
// TODO Auto-generated catch block
|
| - |
|
205 |
return "";
|
| - |
|
206 |
}
|
| 197 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
207 |
}, Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
| 198 |
|
208 |
|
| - |
|
209 |
Map<String, CatalogListingModel> catalogListingMap = new HashMap<>();
|
| - |
|
210 |
|
| - |
|
211 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
| - |
|
212 |
Iterator<TagListing> iterator = tagListings.iterator();
|
| 199 |
while (iterator.hasNext()) {
|
213 |
while (iterator.hasNext()) {
|
| 200 |
TagListing tagListing = iterator.next();
|
214 |
TagListing tagListing = iterator.next();
|
| 201 |
Item item = itemRepository.selectById(tagListing.getItemId());
|
215 |
Item item = itemRepository.selectById(tagListing.getItemId());
|
| - |
|
216 |
int catalogId = item.getCatalogItemId();
|
| 202 |
if (item.getCategoryId() != 10006) {
|
217 |
if (item.getCategoryId() != 10006) {
|
| 203 |
continue;
|
218 |
continue;
|
| 204 |
}
|
219 |
}
|
| 205 |
int catalogId = item.getCatalogItemId();
|
- |
|
| - |
|
220 |
|
| 206 |
if ((modelStockAllocationMap.containsKey(catalogId)
|
221 |
int catalogStockAllocationQuantity = modelStockAllocationMap.containsKey(catalogId)
|
| 207 |
&& modelStockAllocationMap.get(catalogId).getQuantity() > 0)
|
222 |
? modelStockAllocationMap.get(catalogId)
|
| 208 |
|| itemListSnapshot.containsKey(item.getId())) {
|
- |
|
| 209 |
List<CurrentInventorySnapshot> cisList = itemListSnapshot.get(item.getId());
|
- |
|
| 210 |
if (cisList != null) {
|
- |
|
| 211 |
for (CurrentInventorySnapshot cis : cisList) {
|
- |
|
| 212 |
if (!catalogListingMap.containsKey(catalogId + "-" + cis.getFofoId())) {
|
- |
|
| 213 |
CatalogListingModel catalogListingModel = new CatalogListingModel();
|
- |
|
| 214 |
catalogListingModel.setFofoId(cis.getFofoId());
|
- |
|
| 215 |
catalogListingModel.setModelName(item.getModelName());
|
- |
|
| 216 |
catalogListingModel.setModelNumber(item.getModelNumber());
|
- |
|
| 217 |
catalogListingModel.setCatalogId(catalogId);
|
- |
|
| 218 |
catalogListingModel.setDp(tagListing.getSellingPrice());
|
- |
|
| 219 |
catalogListingModel.setMop(tagListing.getMop());
|
- |
|
| 220 |
catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
|
- |
|
| 221 |
StockAllocationModel stockAllocationModel = modelStockAllocationMap.get(item.getCatalogItemId());
|
- |
|
| 222 |
int stockAllocationQuantity = stockAllocationModel == null ? 0
|
- |
|
| 223 |
: stockAllocationModel.getQuantity();
|
- |
|
| 224 |
catalogListingModel.setAllocatedQuantity(stockAllocationQuantity);
|
- |
|
| 225 |
catalogListingModel.setToBeOrdered(stockAllocationQuantity);
|
- |
|
| 226 |
catalogListingModel.setBrand(item.getBrand());
|
- |
|
| 227 |
if (item.getCategoryId() == 10006) {
|
- |
|
| 228 |
catalogListingModel.setCategoryId(item.getCategoryId());
|
- |
|
| 229 |
}
|
223 |
: 0;
|
| 230 |
catalogListingMap.put(catalogId + "-" + cis.getFofoId(), catalogListingModel);
|
- |
|
| 231 |
}
|
- |
|
| 232 |
CatalogListingModel catalogListingModel = catalogListingMap
|
224 |
for (int retailerId : fofoIds) {
|
| 233 |
.get(catalogId + "-" + cis.getFofoId());
|
225 |
String key = catalogId + "-" + retailerId;
|
| 234 |
|
- |
|
| 235 |
int itemAvailability = cis.getAvailability();
|
- |
|
| 236 |
catalogListingModel.setStockInHand(catalogListingModel.getStockInHand() + itemAvailability);
|
- |
|
| 237 |
|
- |
|
| 238 |
Integer inTransitQuantity = itemsInTransit.get(item.getId() + "-" + cis.getFofoId());
|
- |
|
| 239 |
int inTransitQty = (inTransitQuantity == null ? 0 : inTransitQuantity);
|
- |
|
| 240 |
catalogListingModel
|
- |
|
| 241 |
.setInTransitQuantity(catalogListingModel.getInTransitQuantity() + inTransitQty);
|
- |
|
| 242 |
|
- |
|
| 243 |
if (catalogListingModel.getAllocatedQuantity() > 0) {
|
226 |
if (catalogListingMap.containsKey(key)) {
|
| 244 |
int toBeOrdered = Math
|
- |
|
| 245 |
.max(catalogListingModel.getToBeOrdered() - inTransitQty - itemAvailability, 0);
|
- |
|
| 246 |
catalogListingModel.setToBeOrdered(toBeOrdered);
|
- |
|
| 247 |
}
|
227 |
continue;
|
| 248 |
}
|
- |
|
| 249 |
}
|
228 |
}
|
| - |
|
229 |
int catalogInTransit = catalogUserInTransit.containsKey(key) ? catalogUserInTransit.get(key) : 0;
|
| - |
|
230 |
int catalogInStock = catalogUserQtyMap.containsKey(key) ? catalogUserQtyMap.get(key) : 0;
|
| - |
|
231 |
if (catalogInTransit + catalogInStock == 0 && catalogStockAllocationQuantity == 0) {
|
| - |
|
232 |
continue;
|
| - |
|
233 |
}
|
| - |
|
234 |
CatalogListingModel catalogListingModel = new CatalogListingModel();
|
| - |
|
235 |
catalogListingModel.setFofoId(retailerId);
|
| - |
|
236 |
catalogListingModel.setModelName(item.getModelName());
|
| - |
|
237 |
catalogListingModel.setModelNumber(item.getModelNumber());
|
| - |
|
238 |
catalogListingModel.setCatalogId(catalogId);
|
| - |
|
239 |
catalogListingModel.setDp(tagListing.getSellingPrice());
|
| - |
|
240 |
catalogListingModel.setMop(tagListing.getMop());
|
| - |
|
241 |
catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
|
| - |
|
242 |
catalogListingModel.setAllocatedQuantity(catalogStockAllocationQuantity);
|
| - |
|
243 |
catalogListingModel.setInTransitQuantity(catalogInTransit);
|
| - |
|
244 |
catalogListingModel
|
| - |
|
245 |
.setToBeOrdered(catalogStockAllocationQuantity - catalogInTransit - catalogInStock);
|
| - |
|
246 |
catalogListingModel.setBrand(item.getBrand());
|
| - |
|
247 |
catalogListingModel.setModelName(item.getModelName());
|
| - |
|
248 |
catalogListingModel.setModelNumber(item.getModelNumber());
|
| - |
|
249 |
catalogListingModel.setCategoryId(item.getCategoryId());
|
| - |
|
250 |
catalogListingMap.put(key, catalogListingModel);
|
| 250 |
}
|
251 |
}
|
| 251 |
}
|
252 |
}
|
| 252 |
List<List<Object>> listOfRows = new ArrayList<>();
|
253 |
List<List<Object>> listOfRows = new ArrayList<>();
|
| 253 |
for (CatalogListingModel clm : catalogListingMap.values()) {
|
254 |
for (CatalogListingModel clm : catalogListingMap.values()) {
|
| 254 |
CustomRetailer cr = customRetailersMap.get(clm.getFofoId());
|
255 |
CustomRetailer cr = customRetailersMap.get(clm.getFofoId());
|
| 255 |
listOfRows
|
256 |
listOfRows
|
| 256 |
.add(Arrays.asList(cr.getPartnerId(), cr.getBusinessName(), clm.getBrand(), clm.getCatalogId(),
|
257 |
.add(Arrays.asList(cr.getPartnerId(), cr.getBusinessName(), clm.getBrand(), clm.getCatalogId(),
|
| 257 |
clm.getItemDescription(), clm.getDp(), clm.getMop(), clm.getAllocatedQuantity(),
|
258 |
clm.getItemDescription(), clm.getDp(), clm.getMop(), clm.getAllocatedQuantity(),
|
| 258 |
clm.getInTransitQuantity(), clm.getStockInHand(), clm.getToBeOrdered()));
|
259 |
clm.getInTransitQuantity(), clm.getStockInHand(), clm.getToBeOrdered()));
|
| 259 |
}
|
260 |
}
|
| 260 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("StoreId", "StoreName", "Catalog Id", "Brand", "Model", "DP", "MOP",
|
261 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("StoreId", "StoreName", "Catalog Id",
|
| 261 |
"Allocated Quantity", "In Transit", "Stock In hand", "Shortage"), listOfRows);
|
262 |
"Brand", "Model", "DP", "MOP", "Allocated Quantity", "In Transit", "Stock In hand", "Shortage"),
|
| - |
|
263 |
listOfRows);
|
| 262 |
HttpHeaders headers = new HttpHeaders();
|
264 |
HttpHeaders headers = new HttpHeaders();
|
| 263 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
265 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
| 264 |
headers.set("Content-disposition", "inline; filename=retailer-allocation.csv");
|
266 |
headers.set("Content-disposition", "inline; filename=retailer-allocation.csv");
|
| 265 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(baos.toByteArray()), headers, HttpStatus.OK);
|
267 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(baos.toByteArray()), headers,
|
| - |
|
268 |
HttpStatus.OK);
|
| 266 |
}
|
269 |
}
|
| 267 |
return null;
|
270 |
return null;
|
| - |
|
271 |
|
| 268 |
}
|
272 |
}
|
| 269 |
|
273 |
|
| 270 |
@RequestMapping(value = "/indent/loadIndent")
|
274 |
@RequestMapping(value = "/indent/loadIndent")
|
| 271 |
public String loadOpenIndent(HttpServletRequest request, Model model,
|
275 |
public String loadOpenIndent(HttpServletRequest request, Model model,
|
| 272 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
276 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
| Line 335... |
Line 339... |
| 335 |
iterator.remove();
|
339 |
iterator.remove();
|
| 336 |
continue;
|
340 |
continue;
|
| 337 |
}
|
341 |
}
|
| 338 |
} else {
|
342 |
} else {
|
| 339 |
if (!(itemCisMap.containsKey(tagListing.getItemId())
|
343 |
if (!(itemCisMap.containsKey(tagListing.getItemId())
|
| 340 |
|| itemStockAllocationMap.containsKey(tagListing.getItemId()))
|
344 |
|| itemStockAllocationMap.containsKey(tagListing.getItemId()))) {
|
| 341 |
) {
|
- |
|
| 342 |
iterator.remove();
|
345 |
iterator.remove();
|
| 343 |
continue;
|
346 |
continue;
|
| 344 |
}
|
347 |
}
|
| 345 |
}
|
348 |
}
|
| 346 |
int catalogId = item.getCatalogItemId();
|
349 |
int catalogId = item.getCatalogItemId();
|