Subversion Repositories SmartDukaan

Rev

Rev 33874 | Rev 33880 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33874 Rev 33878
Line 5054... Line 5054...
5054
            int fofoId = entry.getKey();
5054
            int fofoId = entry.getKey();
5055
            List<PartnerOpeningStockByTodayModel> partnerStockList = entry.getValue();
5055
            List<PartnerOpeningStockByTodayModel> partnerStockList = entry.getValue();
5056
 
5056
 
5057
            for (PartnerOpeningStockByTodayModel partnerStock : partnerStockList) {
5057
            for (PartnerOpeningStockByTodayModel partnerStock : partnerStockList) {
5058
                int catalogId = partnerStock.getCatalogId();
5058
                int catalogId = partnerStock.getCatalogId();
5059
                int openingQtyFromModel = partnerStock.getOpeningQty();
5059
                int stockQty = partnerStock.getOpeningQty();
5060
                LocalDate openingDate = partnerStock.getOpeningDate();
5060
                LocalDate openingDate = partnerStock.getOpeningDate();
5061
 
5061
 
5062
                // Check if an entry already exists in the FofoOpeningStock table
5062
                // Check if an entry already exists in the FofoOpeningStock table
5063
                FofoOpeningStock existingStock = fofoOpeningStockRepository.findByFofoIdAndCatalogId(fofoId, catalogId);
5063
                FofoOpeningStock existingStock = fofoOpeningStockRepository.findByFofoIdAndCatalogId(fofoId, catalogId);
5064
 
5064
 
5065
                if (existingStock != null) {
5065
                if (existingStock != null) {
5066
 
5066
 
5067
                    if (existingStock.getOpeningQty() < openingQtyFromModel) {
5067
                    if (existingStock.getOpeningQty() < stockQty) {
5068
 
-
 
5069
                        existingStock.setOpeningQty(openingQtyFromModel);
5068
                        existingStock.setOpeningQty(stockQty);
5070
                        existingStock.setCurrentQty(openingQtyFromModel);
5069
                        existingStock.setCurrentQty(stockQty);
5071
                        existingStock.setOpeningDate(openingDate);
5070
                        existingStock.setOpeningDate(openingDate);
5072
                        LOGGER.info("if condition exist {}");
5071
                        LOGGER.info("if condition exist {}");
-
 
5072
                    }else if(existingStock.getCurrentQty() >= existingStock.getOpeningQty()){
-
 
5073
                            existingStock.setOpeningQty(existingStock.getCurrentQty());
-
 
5074
                            existingStock.setOpeningDate(LocalDate.now());
-
 
5075
                    } else if (existingStock.getOpeningDate().isBefore(LocalDate.now().minusDays(7))) {
-
 
5076
                        int averageQty = Math.round((existingStock.getCurrentQty() + existingStock.getOpeningQty()) / 2.0f);
-
 
5077
 
-
 
5078
                        if (averageQty == 1 && existingStock.getOpeningQty() == 1 && existingStock.getCurrentQty() == 0) {
-
 
5079
                            // Delete the existing stock entry from the table
-
 
5080
                            fofoOpeningStockRepository.delete(existingStock);
-
 
5081
                            LOGGER.info("Deleted record with fofoId: {}, catalogId: {} because averageQty, openingQty, and currentQty meet deletion criteria", fofoId, catalogId);
-
 
5082
                        } else {
-
 
5083
                            // Update the existing stock with the new average quantity
-
 
5084
                            existingStock.setOpeningQty(averageQty);
-
 
5085
                            existingStock.setOpeningDate(LocalDate.now());
-
 
5086
                            LOGGER.info("Updated due to date being older than 7 days with average quantity: {}", averageQty);
-
 
5087
                        }
5073
                    }
5088
                    }
5074
                } else {
5089
                } else {
5075
                    LOGGER.info("else condition exist");
5090
                    LOGGER.info("else condition exist");
5076
                    FofoOpeningStock newStock = new FofoOpeningStock();
5091
                    FofoOpeningStock newStock = new FofoOpeningStock();
5077
                    newStock.setFofoId(fofoId);
5092
                    newStock.setFofoId(fofoId);
5078
                    newStock.setCatalogId(catalogId);
5093
                    newStock.setCatalogId(catalogId);
5079
                    newStock.setOpeningQty(openingQtyFromModel);
5094
                    newStock.setOpeningQty(stockQty);
5080
                    newStock.setCurrentQty(openingQtyFromModel);
5095
                    newStock.setCurrentQty(stockQty);
5081
                    newStock.setOpeningDate(openingDate);
5096
                    newStock.setOpeningDate(openingDate);
5082
                    fofoOpeningStockRepository.persist(newStock);
5097
                    fofoOpeningStockRepository.persist(newStock);
5083
 
5098
 
5084
                }
5099
                }
5085
            }
5100
            }