Subversion Repositories SmartDukaan

Rev

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

Rev 36936 Rev 37091
Line 124... Line 124...
124
    com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
124
    com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
125
 
125
 
126
    @Autowired
126
    @Autowired
127
    com.spice.profitmandi.dao.repository.user.StoreTimelinetbRepository storeTimelinetbRepository;
127
    com.spice.profitmandi.dao.repository.user.StoreTimelinetbRepository storeTimelinetbRepository;
128
 
128
 
-
 
129
    @Autowired
-
 
130
    com.spice.profitmandi.service.catalog.ComboService comboService;
-
 
131
 
-
 
132
    @Autowired
-
 
133
    com.spice.profitmandi.dao.repository.cs.PositionRepository positionRepository;
-
 
134
 
129
 
135
 
130
    public void parseBulkOrders(MultipartFile file, int creatorId) throws Exception {
136
    public void parseBulkOrders(MultipartFile file, int creatorId) throws Exception {
131
        XSSFWorkbook myWorkBook = new XSSFWorkbook(file.getInputStream());
137
        XSSFWorkbook myWorkBook = new XSSFWorkbook(file.getInputStream());
132
 
138
 
133
        myWorkBook.setMissingCellPolicy(Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
139
        myWorkBook.setMissingCellPolicy(Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
Line 151... Line 157...
151
 
157
 
152
    public ProfitMandiConstants.BID_ENUM generatePurchaseOrder(List<BulkOrderModel> bulkOrderModels, int creatorId, ProfitMandiConstants.PO_TYPE type, ProfitMandiConstants.BID_CRON_ENUM scheduleType) throws Exception {
158
    public ProfitMandiConstants.BID_ENUM generatePurchaseOrder(List<BulkOrderModel> bulkOrderModels, int creatorId, ProfitMandiConstants.PO_TYPE type, ProfitMandiConstants.BID_CRON_ENUM scheduleType) throws Exception {
153
        Map<Integer, List<BulkOrderModel>> fofoBulkOrdersMap = bulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getFofoId()));
159
        Map<Integer, List<BulkOrderModel>> fofoBulkOrdersMap = bulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getFofoId()));
154
        boolean approvalRequired = false;
160
        boolean approvalRequired = false;
155
        ProfitMandiConstants.BID_ENUM finalBidStatus = ProfitMandiConstants.BID_ENUM.CLOSED;
161
        ProfitMandiConstants.BID_ENUM finalBidStatus = ProfitMandiConstants.BID_ENUM.CLOSED;
-
 
162
        // Combo enforcement is gated to RBM/SALES creators only (creatorId is constant for the whole file).
-
 
163
        boolean enforceCombo = isRbmOrSalesCreator(creatorId);
156
        for (Map.Entry<Integer, List<BulkOrderModel>> fofoBulkOrderEntry : fofoBulkOrdersMap.entrySet()) {
164
        for (Map.Entry<Integer, List<BulkOrderModel>> fofoBulkOrderEntry : fofoBulkOrdersMap.entrySet()) {
157
            int fofoId = fofoBulkOrderEntry.getKey();
165
            int fofoId = fofoBulkOrderEntry.getKey();
158
            List<BulkOrderModel> fofoBulkOrderModels = fofoBulkOrderEntry.getValue();
166
            List<BulkOrderModel> fofoBulkOrderModels = fofoBulkOrderEntry.getValue();
159
            Map<Integer, Long> orderItemCountMap = fofoBulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getItemId(), Collectors.counting()));
167
            Map<Integer, Long> orderItemCountMap = fofoBulkOrderModels.stream().collect(Collectors.groupingBy(x -> x.getItemId(), Collectors.counting()));
160
 
168
 
Line 247... Line 255...
247
                        //throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Cancelling the BID");
255
                        //throw new ProfitMandiBusinessException("Skipping order due to insufficient balance for id - ", fofoId, " ,Cancelling the BID");
248
                    }
256
                    }
249
                }
257
                }
250
            }
258
            }
251
            UserCart userCart = cartService.setCartItems(fofoId, cartItems);
259
            UserCart userCart = cartService.setCartItems(fofoId, cartItems);
-
 
260
            // RBM/SALES bulk orders must satisfy combo requirements: if a combo main is present without its
-
 
261
            // required sides, validateCombo throws "Missing required Qty for Combo" (restrict-only; never injects a side).
-
 
262
            if (enforceCombo) {
-
 
263
                comboService.validateCombo(userCart);
-
 
264
            }
252
            // createtransactionInternally set the value in transaction table
265
            // createtransactionInternally set the value in transaction table
253
 
266
 
254
            double creditAmountRequired = totalPayableAmount - walletAmount;
267
            double creditAmountRequired = totalPayableAmount - walletAmount;
255
            int loanId = 0;
268
            int loanId = 0;
256
            try {
269
            try {
Line 363... Line 376...
363
 
376
 
364
        }
377
        }
365
        return finalBidStatus;
378
        return finalBidStatus;
366
    }
379
    }
367
 
380
 
-
 
381
    /** True if the bulk-order creator holds an RBM or SALES position — the only creators combo enforcement applies to. Fail-open (returns false) if positions can't be resolved. */
-
 
382
    private boolean isRbmOrSalesCreator(int creatorId) {
-
 
383
        try {
-
 
384
            return positionRepository.selectPositionByAuthId(creatorId).stream()
-
 
385
                    .anyMatch(p -> p.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_RBM
-
 
386
                            || p.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES);
-
 
387
        } catch (Exception e) {
-
 
388
            LOGGER.warn("Combo-enforce gate: could not resolve positions for creator {} - {}", creatorId, e.getMessage());
-
 
389
            return false;
-
 
390
        }
-
 
391
    }
-
 
392
 
368
    public void createApproval(int transactionId, boolean firstPo) {
393
    public void createApproval(int transactionId, boolean firstPo) {
369
        TransactionApproval transactionApproval = new TransactionApproval();
394
        TransactionApproval transactionApproval = new TransactionApproval();
370
        transactionApproval.setId(transactionId);
395
        transactionApproval.setId(transactionId);
371
        transactionApproval.setStatus(TransactionApprovalStatus.PENDING);
396
        transactionApproval.setStatus(TransactionApprovalStatus.PENDING);
372
        transactionApproval.setFirstPo(firstPo);
397
        transactionApproval.setFirstPo(firstPo);