Subversion Repositories SmartDukaan

Rev

Rev 37119 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37119 Rev 37143
Line 180... Line 180...
180
                throw new ProfitMandiBusinessException("Item Quantity", "", "Should be greater than 0");
180
                throw new ProfitMandiBusinessException("Item Quantity", "", "Should be greater than 0");
181
            }
181
            }
182
 
182
 
183
            // Batch-fetch per-fofo data once (instead of per-item)
183
            // Batch-fetch per-fofo data once (instead of per-item)
184
            FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
184
            FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
185
            List<String> partnerIneligibleBrands = brandsService.partnerIneligibleBrands(fofoId);
-
 
186
 
185
 
187
            // Batch-fetch items and tag listings for all items in this fofo's order (2 queries instead of 2N)
186
            // Batch-fetch items and tag listings for all items in this fofo's order (2 queries instead of 2N)
188
            Set<Integer> allItemIds = fofoBulkOrderModels.stream().map(BulkOrderModel::getItemId).collect(Collectors.toSet());
187
            Set<Integer> allItemIds = fofoBulkOrderModels.stream().map(BulkOrderModel::getItemId).collect(Collectors.toSet());
189
            Map<Integer, TagListing> tagListingMap = tagListingRepository.selectByItemIds(allItemIds);
188
            Map<Integer, TagListing> tagListingMap = tagListingRepository.selectByItemIds(allItemIds);
190
            Map<Integer, Item> itemMap = itemRepository.selectByIds(allItemIds).stream()
189
            Map<Integer, Item> itemMap = itemRepository.selectByIds(allItemIds).stream()
191
                    .collect(Collectors.toMap(Item::getId, item -> item));
190
                    .collect(Collectors.toMap(Item::getId, item -> item));
192
 
191
 
-
 
192
            if (!fofoStore.isInternal()) {
-
 
193
                List<String> orderBrands = itemMap.values().stream().map(Item::getBrand).distinct()
-
 
194
                        .collect(Collectors.toList());
-
 
195
                brandsService.validateOrderableBrands(fofoId, orderBrands);
-
 
196
            }
-
 
197
 
193
            List<CartItem> cartItems = new ArrayList<>();
198
            List<CartItem> cartItems = new ArrayList<>();
194
            double totalPayableAmount = 0;
199
            double totalPayableAmount = 0;
195
            BigDecimal totalPayableAmountBD = new BigDecimal(0);
200
            BigDecimal totalPayableAmountBD = new BigDecimal(0);
196
            for (BulkOrderModel fofoBulkOrderModel : fofoBulkOrderModels) {
201
            for (BulkOrderModel fofoBulkOrderModel : fofoBulkOrderModels) {
197
                CartItem cartItem = new CartItem();
202
                CartItem cartItem = new CartItem();
Line 204... Line 209...
204
                }
209
                }
205
                Item item = itemMap.get(fofoBulkOrderModel.getItemId());
210
                Item item = itemMap.get(fofoBulkOrderModel.getItemId());
206
                if (item == null) {
211
                if (item == null) {
207
                    throw new ProfitMandiBusinessException("Item not found", fofoBulkOrderModel.getItemId(), "Item does not exist: " + fofoBulkOrderModel.getItemId());
212
                    throw new ProfitMandiBusinessException("Item not found", fofoBulkOrderModel.getItemId(), "Item does not exist: " + fofoBulkOrderModel.getItemId());
208
                }
213
                }
209
                if (!fofoStore.isInternal()) {
-
 
210
                    if (partnerIneligibleBrands.contains(item.getBrand())) {
-
 
211
                        throw new ProfitMandiBusinessException("Brand is not allowed", "Brand ( " + item.getBrand() + ") is not allowed for this partner", "");
-
 
212
                    }
-
 
213
                }
-
 
214
 
-
 
215
                double itemSellingPrice = tagListing.getSellingPrice();
214
                double itemSellingPrice = tagListing.getSellingPrice();
216
                boolean isActualPrice = fofoBulkOrderModel.getItemPrice() == itemSellingPrice;
215
                boolean isActualPrice = fofoBulkOrderModel.getItemPrice() == itemSellingPrice;
217
                boolean isPriceZero = fofoBulkOrderModel.getItemPrice() == 0d;
216
                boolean isPriceZero = fofoBulkOrderModel.getItemPrice() == 0d;
218
                double customSellingPrice = fofoBulkOrderModel.getItemPrice();
217
                double customSellingPrice = fofoBulkOrderModel.getItemPrice();
219
                int itemId = cartItem.getItemId();
218
                int itemId = cartItem.getItemId();