Subversion Repositories SmartDukaan

Rev

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

Rev 37102 Rev 37151
Line 868... Line 868...
868
            fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
868
            fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
869
            fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
869
            fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
870
            fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
870
            fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
871
            fofoStore.setFofoType(updateRetailerRequest.getFofoType());
871
            fofoStore.setFofoType(updateRetailerRequest.getFofoType());
872
            fofoStore.setGstNumber(updateRetailerRequest.getGstNumber());
872
            fofoStore.setGstNumber(updateRetailerRequest.getGstNumber());
-
 
873
 
-
 
874
            // The store already exists but its code may never have reached the onboarding
-
 
875
            // panel (e.g. verification approved while another dtr user held the partner's
-
 
876
            // mobile, so the approval-time linker resolved the wrong account). Re-saving the
-
 
877
            // form previously did nothing for the panel because linking only ran on NEW
-
 
878
            // store creation. Link here too; the method is a no-op if the panel already
-
 
879
            // has a code.
-
 
880
            this.linkStoreCodeToOnboardingPanel(fofoStore, updateRetailerRequest.getUserMobileNumber(), retailerId);
873
        } else {
881
        } else {
874
            int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
882
            int retailerAddressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
875
            Address retailerAddress = addressRepository.selectById(retailerAddressId);
883
            Address retailerAddress = addressRepository.selectById(retailerAddressId);
876
 
884
 
877
            // StateInfo stateInfo = null;
885
            // StateInfo stateInfo = null;
Line 925... Line 933...
925
            fofoStore.setActivationType(ActivationType.ACTIVE);
933
            fofoStore.setActivationType(ActivationType.ACTIVE);
926
            fofoStore.setGstNumber(updateRetailerRequest.getGstNumber());
934
            fofoStore.setGstNumber(updateRetailerRequest.getGstNumber());
927
            fofoStore.setOutletName(retailerAddress.getName());
935
            fofoStore.setOutletName(retailerAddress.getName());
928
            fofoStoreRepository.persist(fofoStore);
936
            fofoStoreRepository.persist(fofoStore);
929
 
937
 
930
            // Link store code to onboarding panel (only for NEW store creation)
938
            // Link store code to onboarding panel
931
            try {
-
 
932
                PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository.selectByPhoneNumber(
-
 
933
                        Long.parseLong(retailerAddress.getPhoneNumber()));
939
            this.linkStoreCodeToOnboardingPanel(fofoStore, retailerAddress.getPhoneNumber(), retailerId);
934
                if (pobp != null) {
-
 
935
                    PartnerVerificationpanel pvp = partnerOnboardingVerificationRepository
-
 
936
                            .selectByOnboardingId(pobp.getId());
-
 
937
                    if (pvp != null && PartnerVerificationApprovalStatus.YES.equals(pvp.getApproval())) {
-
 
938
                        pobp.setCode(fofoStore.getCode());
-
 
939
                        storeTimelineTatService.onCodeCreated(pobp.getId());
-
 
940
                        PartnerVerificationCheckboxes cb = partnerOnboardingVerificationRepository
-
 
941
                                .selectVerifiCheckboxByOnboardingId(pobp.getId());
-
 
942
                        if (cb == null) {
-
 
943
                            cb = new PartnerVerificationCheckboxes();
-
 
944
                            cb.setOnboardingId(pobp.getId());
-
 
945
                            partnerOnboardingVerificationRepository.persist(cb);
-
 
946
                        }
-
 
947
                    }
-
 
948
                }
-
 
949
            } catch (Exception e) {
-
 
950
                LOGGER.error("Error linking store code to onboarding for retailerId: {}", retailerId, e);
-
 
951
            }
-
 
952
 
940
 
953
            PincodePartner pincodePartner = pincodePartnerRepository.selectPartnerByPincode(retailerAddress.getPinCode(), fofoStore.getId());
941
            PincodePartner pincodePartner = pincodePartnerRepository.selectPartnerByPincode(retailerAddress.getPinCode(), fofoStore.getId());
954
            if (pincodePartner == null) {
942
            if (pincodePartner == null) {
955
                PincodePartner pinPartner = new PincodePartner();
943
                PincodePartner pinPartner = new PincodePartner();
956
                pinPartner.setFofoId(fofoStore.getId());
944
                pinPartner.setFofoId(fofoStore.getId());
Line 965... Line 953...
965
        }
953
        }
966
 
954
 
967
        return fofoStore;
955
        return fofoStore;
968
    }
956
    }
969
 
957
 
-
 
958
    /**
-
 
959
     * Copies an existing fofo_store code onto the partner_onboarding_panel row for the
-
 
960
     * given mobile number, provided verification is approved and the panel does not
-
 
961
     * already hold a code. Called for BOTH new and existing stores: the approval-time
-
 
962
     * linker in PartnerOnBoardingPanelController can miss (e.g. kyc=0, or a legacy dtr
-
 
963
     * user squatting on the partner's mobile made selectByMobileNumber resolve the
-
 
964
     * wrong account), and before this method existed a form re-save silently skipped
-
 
965
     * linking whenever the store already existed. Best-effort: never fails the save.
-
 
966
     */
-
 
967
    private void linkStoreCodeToOnboardingPanel(FofoStore fofoStore, String phoneNumber, int retailerId) {
-
 
968
        if (fofoStore == null || fofoStore.getCode() == null || fofoStore.getCode().isEmpty()
-
 
969
                || phoneNumber == null || phoneNumber.isEmpty()) {
-
 
970
            return;
-
 
971
        }
-
 
972
        try {
-
 
973
            PartnerOnBoardingPanel pobp = partnerOnBoardingPanelRepository.selectByPhoneNumber(
-
 
974
                    Long.parseLong(phoneNumber));
-
 
975
            if (pobp == null) {
-
 
976
                return;
-
 
977
            }
-
 
978
            // Never overwrite: multi-store / GST-change onboardings keep their own codes.
-
 
979
            if (pobp.getCode() != null && !pobp.getCode().isEmpty()) {
-
 
980
                return;
-
 
981
            }
-
 
982
            PartnerVerificationpanel pvp = partnerOnboardingVerificationRepository
-
 
983
                    .selectByOnboardingId(pobp.getId());
-
 
984
            if (pvp != null && PartnerVerificationApprovalStatus.YES.equals(pvp.getApproval())) {
-
 
985
                pobp.setCode(fofoStore.getCode());
-
 
986
                storeTimelineTatService.onCodeCreated(pobp.getId());
-
 
987
                PartnerVerificationCheckboxes cb = partnerOnboardingVerificationRepository
-
 
988
                        .selectVerifiCheckboxByOnboardingId(pobp.getId());
-
 
989
                if (cb == null) {
-
 
990
                    cb = new PartnerVerificationCheckboxes();
-
 
991
                    cb.setOnboardingId(pobp.getId());
-
 
992
                    partnerOnboardingVerificationRepository.persist(cb);
-
 
993
                }
-
 
994
                LOGGER.info("Linked store code {} to onboardingId {} for retailerId {}",
-
 
995
                        fofoStore.getCode(), pobp.getId(), retailerId);
-
 
996
            }
-
 
997
        } catch (Exception e) {
-
 
998
            LOGGER.error("Error linking store code to onboarding for retailerId: {}", retailerId, e);
-
 
999
        }
-
 
1000
    }
-
 
1001
 
970
    @Override
1002
    @Override
971
    public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String
1003
    public FofoStore createFofoStoreCodeByUserId(int userId, String districtName, String
972
            stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
1004
            stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
973
        User user = userRepository.selectById(userId);
1005
        User user = userRepository.selectById(userId);
974
        // = userAccountRepository.selectRetailerIdByUserId(user.getId());
1006
        // = userAccountRepository.selectRetailerIdByUserId(user.getId());