Subversion Repositories SmartDukaan

Rev

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

Rev 36399 Rev 36518
Line 267... Line 267...
267
                }
267
                }
268
            }
268
            }
269
 
269
 
270
            LOGGER.info("finalBidStatus: {}",finalBidStatus);
270
            LOGGER.info("finalBidStatus: {}",finalBidStatus);
271
            if (finalBidStatus.equals(ProfitMandiConstants.BID_ENUM.CLOSED)) {
271
            if (finalBidStatus.equals(ProfitMandiConstants.BID_ENUM.CLOSED)) {
272
                // Check if this is the first PO for this partner (before creating the new transaction)
272
                // First PO if: no transactions at all, OR all previous first-PO approvals were REJECTED
273
                boolean isFirstPO = !transactionRepository.hasTransactionsByRetailerId(fofoId);
273
                boolean isFirstPO = !transactionRepository.hasTransactionsByRetailerId(fofoId)
-
 
274
                        || transactionApprovalRepository.allFirstPoRejectedByRetailerId(fofoId);
274
 
275
 
-
 
276
                if (isFirstPO) {
-
 
277
                    // Block if a first PO is already pending approval
-
 
278
                    if (transactionApprovalRepository.hasPendingFirstPoByRetailerId(fofoId)) {
-
 
279
                        throw new ProfitMandiBusinessException(
-
 
280
                                "First PO is pending approval",
-
 
281
                                fofoId,
-
 
282
                                "First PO is already pending approval. Please wait for approval or rejection before creating another order.");
-
 
283
                    }
-
 
284
 
275
                // Block first PO if FULL_STOCK_PAYMENT is not done (for LOI-flow partners only)
285
                    // Block first PO if FULL_STOCK_PAYMENT is not done (for LOI-flow partners only)
276
                if (isFirstPO && fofoStore != null && !fofoStore.isInternal() && fofoStore.getCode() != null) {
286
                    if (fofoStore != null && !fofoStore.isInternal() && fofoStore.getCode() != null) {
277
                    com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel pob =
287
                        com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel pob =
278
                            partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
288
                                partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
279
                    if (pob != null) {
289
                        if (pob != null) {
280
                        StoreTimelinetb fspEntry = storeTimelinetbRepository.selectByOnboardingIdAndEvent(
290
                            StoreTimelinetb fspEntry = storeTimelinetbRepository.selectByOnboardingIdAndEvent(
281
                                pob.getId(), StoreTimeline.FULL_STOCK_PAYMENT);
291
                                    pob.getId(), StoreTimeline.FULL_STOCK_PAYMENT);
282
                        if (fspEntry == null) {
292
                            if (fspEntry == null) {
283
                            LOGGER.warn("PO creation blocked for fofoId={}, onboardingId={}: FULL_STOCK_PAYMENT not done", fofoId, pob.getId());
293
                                LOGGER.warn("PO creation blocked for fofoId={}, onboardingId={}: FULL_STOCK_PAYMENT not done", fofoId, pob.getId());
284
                            throw new ProfitMandiBusinessException(
294
                                throw new ProfitMandiBusinessException(
285
                                    "Full Stock Payment is required before creating PO",
295
                                        "Full Stock Payment is required before creating PO",
286
                                    fofoStore.getCode(),
296
                                        fofoStore.getCode(),
287
                                    "Full Stock Payment must be completed before first PO can be created");
297
                                        "Full Stock Payment must be completed before first PO can be created");
-
 
298
                            }
288
                        }
299
                        }
289
                    }
300
                    }
290
                }
301
                }
291
 
302
 
292
                LOGGER.info("totalPayableAmount - {}", totalPayableAmount);
303
                LOGGER.info("totalPayableAmount - {}", totalPayableAmount);
Line 319... Line 330...
319
                    try {
330
                    try {
320
                        sendFirstPOApprovalEmail(fofoStore, transactionId, totalPayableAmount, creatorId);
331
                        sendFirstPOApprovalEmail(fofoStore, transactionId, totalPayableAmount, creatorId);
321
                    } catch (Exception e) {
332
                    } catch (Exception e) {
322
                        LOGGER.error("Failed to send first PO approval email for fofoId: " + fofoId, e);
333
                        LOGGER.error("Failed to send first PO approval email for fofoId: " + fofoId, e);
323
                    }
334
                    }
324
                    // Track PO_CREATION on timeline for first PO
335
                    // Track PO_CREATION on timeline for first PO (direct call like BILLING — bypasses BLOCKER_MAP
-
 
336
                    // since the PO is actually being created, the timeline must record it)
325
                    try {
337
                    try {
326
                        if (fofoStore != null && fofoStore.getCode() != null) {
338
                        if (fofoStore != null && fofoStore.getCode() != null) {
327
                            com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel pob =
339
                            com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel pob =
328
                                    partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
340
                                    partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
329
                            if (pob != null) {
341
                            if (pob != null) {
330
                                storeTimelineTatService.onPoCreationComplete(pob.getId());
342
                                storeTimelineTatService.createStoreTimelinetb(pob.getId(), StoreTimeline.PO_CREATION);
331
                            }
343
                            }
332
                        }
344
                        }
333
                    } catch (Exception e) {
345
                    } catch (Exception e) {
334
                        LOGGER.error("Failed to track PO_CREATION timeline for fofoId: " + fofoId, e);
346
                        LOGGER.error("Failed to track PO_CREATION timeline for fofoId: " + fofoId, e);
335
                    }
347
                    }