| Line 115... |
Line 115... |
| 115 |
FofoOpeningStock fofoOpeningStock = fofoOpeningStockRepository.findByFofoIdAndCatalogId(fofoId,catalogId);
|
115 |
FofoOpeningStock fofoOpeningStock = fofoOpeningStockRepository.findByFofoIdAndCatalogId(fofoId,catalogId);
|
| 116 |
if(fofoOpeningStock !=null){
|
116 |
if(fofoOpeningStock !=null){
|
| 117 |
int updatedQty = fofoOpeningStock.getCurrentQty() - quantity;
|
117 |
int updatedQty = fofoOpeningStock.getCurrentQty() - quantity;
|
| 118 |
fofoOpeningStock.setCurrentQty(updatedQty);
|
118 |
fofoOpeningStock.setCurrentQty(updatedQty);
|
| 119 |
}
|
119 |
}
|
| - |
|
120 |
}
|
| - |
|
121 |
|
| - |
|
122 |
@Override
|
| - |
|
123 |
public void minusOpeningStockBatch(Map<Integer, Integer> itemIdQuantityMap, int fofoId) throws ProfitMandiBusinessException {
|
| - |
|
124 |
if (itemIdQuantityMap == null || itemIdQuantityMap.isEmpty()) {
|
| - |
|
125 |
return;
|
| - |
|
126 |
}
|
| - |
|
127 |
|
| - |
|
128 |
// Batch fetch all items - 1 DB call instead of N
|
| - |
|
129 |
List<Item> items = itemRepository.selectByIds(itemIdQuantityMap.keySet());
|
| 120 |
|
130 |
|
| - |
|
131 |
// Build itemId -> catalogId map
|
| - |
|
132 |
Map<Integer, Integer> itemToCatalogMap = items.stream()
|
| - |
|
133 |
.collect(Collectors.toMap(Item::getId, Item::getCatalogItemId));
|
| 121 |
|
134 |
|
| - |
|
135 |
// Get unique catalogIds and build catalogId -> quantity map
|
| - |
|
136 |
Map<Integer, Integer> catalogQuantityMap = new HashMap<>();
|
| - |
|
137 |
for (Map.Entry<Integer, Integer> entry : itemIdQuantityMap.entrySet()) {
|
| - |
|
138 |
Integer catalogId = itemToCatalogMap.get(entry.getKey());
|
| - |
|
139 |
if (catalogId != null) {
|
| - |
|
140 |
catalogQuantityMap.merge(catalogId, entry.getValue(), Integer::sum);
|
| - |
|
141 |
}
|
| - |
|
142 |
}
|
| - |
|
143 |
|
| - |
|
144 |
// Batch fetch all FofoOpeningStock records - 1 DB call instead of N
|
| - |
|
145 |
List<FofoOpeningStock> openingStocks = fofoOpeningStockRepository.findByFofoIdAndCatalogIds(
|
| - |
|
146 |
fofoId, catalogQuantityMap.keySet());
|
| - |
|
147 |
|
| - |
|
148 |
// Update each opening stock
|
| - |
|
149 |
for (FofoOpeningStock openingStock : openingStocks) {
|
| - |
|
150 |
Integer quantityToSubtract = catalogQuantityMap.get(openingStock.getCatalogId());
|
| - |
|
151 |
if (quantityToSubtract != null) {
|
| - |
|
152 |
openingStock.setCurrentQty(openingStock.getCurrentQty() - quantityToSubtract);
|
| - |
|
153 |
}
|
| - |
|
154 |
}
|
| 122 |
}
|
155 |
}
|
| 123 |
|
156 |
|
| 124 |
@Override
|
157 |
@Override
|
| 125 |
public Set<Integer> getAllItemIdsForSmartCartOfPartner(int fofoId) throws ProfitMandiBusinessException {
|
158 |
public Set<Integer> getAllItemIdsForSmartCartOfPartner(int fofoId) throws ProfitMandiBusinessException {
|
| 126 |
LocalDateTime todayDate = LocalDate.now().atStartOfDay();
|
159 |
LocalDateTime todayDate = LocalDate.now().atStartOfDay();
|