| Line 5158... |
Line 5158... |
| 5158 |
@Autowired
|
5158 |
@Autowired
|
| 5159 |
private SmartCartService smartCartService;
|
5159 |
private SmartCartService smartCartService;
|
| 5160 |
|
5160 |
|
| 5161 |
public void createOpeningStockPartyWise() throws Exception {
|
5161 |
public void createOpeningStockPartyWise() throws Exception {
|
| 5162 |
// Get all partner stock data
|
5162 |
// Get all partner stock data
|
| 5163 |
Map<Integer, List<PartnerOpeningStockByTodayModel>> partnerOpeningStockByTodayMap = currentInventorySnapshotRepository.getAllPartnerTodayStock();
|
5163 |
Map<Integer, List<PartnerOpeningStockByTodayModel>> partnerOpeningStockByTodayInStockMap = currentInventorySnapshotRepository.getAllPartnerTodayInstock();
|
| - |
|
5164 |
Map<Integer, List<PartnerOpeningStockByTodayModel>> partnerOpeningStockByTodayGrnPending = currentInventorySnapshotRepository.getAllPartnerTodayGrnPending();
|
| - |
|
5165 |
|
| - |
|
5166 |
Map<Integer, List<PartnerOpeningStockByTodayModel>> partnerOpeningStockByTodayMap =
|
| - |
|
5167 |
new HashMap<>();
|
| - |
|
5168 |
|
| - |
|
5169 |
// STEP 1: Copy in-stock data
|
| - |
|
5170 |
partnerOpeningStockByTodayInStockMap.forEach((fofoId, list) ->
|
| - |
|
5171 |
partnerOpeningStockByTodayMap.put(
|
| - |
|
5172 |
fofoId,
|
| - |
|
5173 |
new ArrayList<>(list) // deep list copy
|
| - |
|
5174 |
)
|
| - |
|
5175 |
);
|
| - |
|
5176 |
|
| - |
|
5177 |
// STEP 2: Merge GRN pending using streams
|
| - |
|
5178 |
partnerOpeningStockByTodayGrnPending.forEach((fofoId, grnList) -> {
|
| - |
|
5179 |
|
| - |
|
5180 |
// If FOFO missing → simply insert GRN list (deep copy)
|
| - |
|
5181 |
partnerOpeningStockByTodayMap
|
| - |
|
5182 |
.computeIfAbsent(fofoId, x -> new ArrayList<>())
|
| - |
|
5183 |
.addAll(
|
| - |
|
5184 |
grnList.stream()
|
| - |
|
5185 |
.map(g -> new PartnerOpeningStockByTodayModel(
|
| - |
|
5186 |
g.getFofoId(),
|
| - |
|
5187 |
g.getCatalogId(),
|
| - |
|
5188 |
g.getModelNumber(),
|
| - |
|
5189 |
g.getOpeningQty()
|
| - |
|
5190 |
))
|
| - |
|
5191 |
.collect(Collectors.toList())
|
| - |
|
5192 |
);
|
| - |
|
5193 |
});
|
| - |
|
5194 |
|
| - |
|
5195 |
// STEP 3: Now merge duplicates per catalogId using grouping
|
| - |
|
5196 |
partnerOpeningStockByTodayMap.replaceAll((fofoId, list) ->
|
| - |
|
5197 |
list.stream()
|
| - |
|
5198 |
.collect(Collectors.toMap(
|
| - |
|
5199 |
PartnerOpeningStockByTodayModel::getCatalogId,
|
| - |
|
5200 |
m -> new PartnerOpeningStockByTodayModel(
|
| - |
|
5201 |
m.getFofoId(),
|
| - |
|
5202 |
m.getCatalogId(),
|
| - |
|
5203 |
m.getModelNumber(),
|
| - |
|
5204 |
m.getOpeningQty()
|
| - |
|
5205 |
),
|
| - |
|
5206 |
// merge function: sum openingQty
|
| - |
|
5207 |
(m1, m2) -> {
|
| - |
|
5208 |
m1.setOpeningQty(m1.getOpeningQty() + m2.getOpeningQty());
|
| - |
|
5209 |
return m1;
|
| - |
|
5210 |
}
|
| - |
|
5211 |
))
|
| - |
|
5212 |
.values()
|
| - |
|
5213 |
.stream()
|
| - |
|
5214 |
.collect(Collectors.toList())
|
| - |
|
5215 |
);
|
| - |
|
5216 |
|
| - |
|
5217 |
|
| - |
|
5218 |
|
| - |
|
5219 |
|
| - |
|
5220 |
|
| 5164 |
Map<Integer, Map<Integer, Integer>> activatedButNotBilledCatalogQtyMap = smartCartService.activatedButNotBilledCatalogQtyMap();
|
5221 |
Map<Integer, Map<Integer, Integer>> activatedButNotBilledCatalogQtyMap = smartCartService.activatedButNotBilledCatalogQtyMap();
|
| 5165 |
LOGGER.info("PartnerOpeningStockByTodayModel {}", partnerOpeningStockByTodayMap);
|
5222 |
LOGGER.info("PartnerOpeningStockByTodayModel {}", partnerOpeningStockByTodayMap);
|
| 5166 |
for (Map.Entry<Integer, List<PartnerOpeningStockByTodayModel>> entry : partnerOpeningStockByTodayMap.entrySet()) {
|
5223 |
for (Map.Entry<Integer, List<PartnerOpeningStockByTodayModel>> entry : partnerOpeningStockByTodayMap.entrySet()) {
|
| 5167 |
int fofoId = entry.getKey();
|
5224 |
int fofoId = entry.getKey();
|
| 5168 |
List<PartnerOpeningStockByTodayModel> partnerStockList = entry.getValue();
|
5225 |
List<PartnerOpeningStockByTodayModel> partnerStockList = entry.getValue();
|
| Line 5175... |
Line 5232... |
| 5175 |
int stockCurrentQty = partnerStock.getOpeningQty();
|
5232 |
int stockCurrentQty = partnerStock.getOpeningQty();
|
| 5176 |
LocalDate openingDate = partnerStock.getOpeningDate();
|
5233 |
LocalDate openingDate = partnerStock.getOpeningDate();
|
| 5177 |
|
5234 |
|
| 5178 |
int soldButNotBilledQty = activatedButNotBilledQtyMap.getOrDefault(catalogId, 0);
|
5235 |
int soldButNotBilledQty = activatedButNotBilledQtyMap.getOrDefault(catalogId, 0);
|
| 5179 |
|
5236 |
|
| - |
|
5237 |
if(catalogId ==1025656 && fofoId == 175140232 ){
|
| - |
|
5238 |
LOGGER.info("catalogId {}",catalogId);
|
| - |
|
5239 |
LOGGER.info("fofoId {}",fofoId);
|
| - |
|
5240 |
LOGGER.info("soldButNotBilledQty {}",soldButNotBilledQty);
|
| - |
|
5241 |
LOGGER.info("stockCurrentQty {}",stockCurrentQty);
|
| - |
|
5242 |
}
|
| - |
|
5243 |
|
| 5180 |
// Subtract soldQty from partnerCurrentQty
|
5244 |
// Subtract soldQty from partnerCurrentQty
|
| 5181 |
int partnerCurrentQty = Math.max(stockCurrentQty - soldButNotBilledQty, 0); // Ensure it doesn't go negative
|
5245 |
int partnerCurrentQty = Math.max(stockCurrentQty - soldButNotBilledQty, 0); // Ensure it doesn't go negative
|
| 5182 |
|
5246 |
|
| 5183 |
|
5247 |
|
| 5184 |
// Check if an entry already exists in the FofoOpeningStock table
|
5248 |
// Check if an entry already exists in the FofoOpeningStock table
|