| Line 20... |
Line 20... |
| 20 |
import com.spice.profitmandi.common.util.Utils;
|
20 |
import com.spice.profitmandi.common.util.Utils;
|
| 21 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
21 |
import com.spice.profitmandi.common.util.Utils.Attachment;
|
| 22 |
import com.spice.profitmandi.common.web.client.RestClient;
|
22 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 23 |
import com.spice.profitmandi.dao.Interface.Campaign;
|
23 |
import com.spice.profitmandi.dao.Interface.Campaign;
|
| 24 |
import com.spice.profitmandi.dao.cart.CartService;
|
24 |
import com.spice.profitmandi.dao.cart.CartService;
|
| - |
|
25 |
import com.spice.profitmandi.dao.cart.SmartCartService;
|
| 25 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
26 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 26 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
|
27 |
import com.spice.profitmandi.dao.entity.auth.PartnerCollectionRemark;
|
| 27 |
import com.spice.profitmandi.dao.entity.catalog.*;
|
28 |
import com.spice.profitmandi.dao.entity.catalog.*;
|
| 28 |
import com.spice.profitmandi.dao.entity.cs.NonSdBuying;
|
29 |
import com.spice.profitmandi.dao.entity.cs.NonSdBuying;
|
| 29 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
30 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| Line 4753... |
Line 4754... |
| 4753 |
return message;
|
4754 |
return message;
|
| 4754 |
}
|
4755 |
}
|
| 4755 |
|
4756 |
|
| 4756 |
@Autowired
|
4757 |
@Autowired
|
| 4757 |
private FofoOpeningStockRepository fofoOpeningStockRepository;
|
4758 |
private FofoOpeningStockRepository fofoOpeningStockRepository;
|
| - |
|
4759 |
@Autowired
|
| - |
|
4760 |
private SmartCartService smartCartService;
|
| 4758 |
|
4761 |
|
| 4759 |
public void createOpeningStockPartyWise() throws Exception {
|
4762 |
public void createOpeningStockPartyWise() throws Exception {
|
| 4760 |
// Get all partner stock data
|
4763 |
// Get all partner stock data
|
| 4761 |
Map<Integer, List<PartnerOpeningStockByTodayModel>> partnerOpeningStockByTodayMap = currentInventorySnapshotRepository.getAllPartnerTodayStock();
|
4764 |
Map<Integer, List<PartnerOpeningStockByTodayModel>> partnerOpeningStockByTodayMap = currentInventorySnapshotRepository.getAllPartnerTodayStock();
|
| - |
|
4765 |
Map<Integer, Map<Integer, Integer>> activatedButNotBilledCatalogQtyMap = smartCartService.activatedButNotBilledCatalogQtyMap();
|
| 4762 |
LOGGER.info("PartnerOpeningStockByTodayModel {}",partnerOpeningStockByTodayMap);
|
4766 |
LOGGER.info("PartnerOpeningStockByTodayModel {}",partnerOpeningStockByTodayMap);
|
| 4763 |
for (Map.Entry<Integer, List<PartnerOpeningStockByTodayModel>> entry : partnerOpeningStockByTodayMap.entrySet()) {
|
4767 |
for (Map.Entry<Integer, List<PartnerOpeningStockByTodayModel>> entry : partnerOpeningStockByTodayMap.entrySet()) {
|
| 4764 |
int fofoId = entry.getKey();
|
4768 |
int fofoId = entry.getKey();
|
| 4765 |
List<PartnerOpeningStockByTodayModel> partnerStockList = entry.getValue();
|
4769 |
List<PartnerOpeningStockByTodayModel> partnerStockList = entry.getValue();
|
| - |
|
4770 |
// Get the sold (activated-but-not-billed) quantity for this fofo and catalog
|
| - |
|
4771 |
Map<Integer, Integer> activatedButNotBilledQtyMap = activatedButNotBilledCatalogQtyMap.getOrDefault(fofoId, Collections.emptyMap());
|
| 4766 |
|
4772 |
|
| 4767 |
// if stock is vaialble in snapshot
|
4773 |
// if stock is avaialble in snapshot
|
| 4768 |
for (PartnerOpeningStockByTodayModel partnerStock : partnerStockList) {
|
4774 |
for (PartnerOpeningStockByTodayModel partnerStock : partnerStockList) {
|
| 4769 |
int catalogId = partnerStock.getCatalogId();
|
4775 |
int catalogId = partnerStock.getCatalogId();
|
| 4770 |
int partnerCurrentQty = partnerStock.getOpeningQty();
|
4776 |
int stockCurrentQty = partnerStock.getOpeningQty();
|
| 4771 |
LocalDate openingDate = partnerStock.getOpeningDate();
|
4777 |
LocalDate openingDate = partnerStock.getOpeningDate();
|
| 4772 |
|
4778 |
|
| - |
|
4779 |
int soldButNotBilledQty = activatedButNotBilledQtyMap.getOrDefault(catalogId, 0);
|
| - |
|
4780 |
|
| - |
|
4781 |
// Subtract soldQty from partnerCurrentQty
|
| - |
|
4782 |
int partnerCurrentQty = Math.max(stockCurrentQty - soldButNotBilledQty, 0); // Ensure it doesn't go negative
|
| - |
|
4783 |
|
| - |
|
4784 |
|
| 4773 |
// Check if an entry already exists in the FofoOpeningStock table
|
4785 |
// Check if an entry already exists in the FofoOpeningStock table
|
| 4774 |
FofoOpeningStock existingStock = fofoOpeningStockRepository.findByFofoIdAndCatalogId(fofoId, catalogId);
|
4786 |
FofoOpeningStock existingStock = fofoOpeningStockRepository.findByFofoIdAndCatalogId(fofoId, catalogId);
|
| 4775 |
|
4787 |
|
| 4776 |
|
4788 |
|
| 4777 |
if (existingStock != null) {
|
4789 |
if (existingStock != null) {
|