Subversion Repositories SmartDukaan

Rev

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

Rev 37822 Rev 37845
Line 1... Line 1...
1
package com.spice.profitmandi.service.user;
1
package com.spice.profitmandi.service.user;
2
 
2
 
-
 
3
import com.spice.profitmandi.dao.enumuration.warehouse.WarehouseStatus;
-
 
4
import com.spice.profitmandi.service.warehouse.BillingWarehouseService;
-
 
5
 
3
import com.fasterxml.jackson.databind.ObjectMapper;
6
import com.fasterxml.jackson.databind.ObjectMapper;
4
import com.google.common.hash.Hashing;
7
import com.google.common.hash.Hashing;
5
import com.google.gson.Gson;
8
import com.google.gson.Gson;
6
import com.spice.profitmandi.common.enumuration.ActivationType;
9
import com.spice.profitmandi.common.enumuration.ActivationType;
7
import com.spice.profitmandi.common.enumuration.FofoType;
10
import com.spice.profitmandi.common.enumuration.FofoType;
Line 53... Line 56...
53
import java.util.stream.Stream;
56
import java.util.stream.Stream;
54
 
57
 
55
@Component
58
@Component
56
public class RetailerServiceImpl implements RetailerService {
59
public class RetailerServiceImpl implements RetailerService {
57
 
60
 
-
 
61
    @Autowired
-
 
62
    private BillingWarehouseService billingWarehouseService;
-
 
63
 
-
 
64
 
58
    private static final Logger LOGGER = LogManager.getLogger(RetailerServiceImpl.class);
65
    private static final Logger LOGGER = LogManager.getLogger(RetailerServiceImpl.class);
59
    private static final String[] TRIAL_CODE_CREATION_AUDIENCE = new String[]{"amit.gupta@smartdukaan.com"};
66
    private static final String[] TRIAL_CODE_CREATION_AUDIENCE = new String[]{"amit.gupta@smartdukaan.com"};
60
    //private static final String [] TRIAL_CODE_CREATION_AUDIENCE = new String[]{};
67
    //private static final String [] TRIAL_CODE_CREATION_AUDIENCE = new String[]{};
61
 
68
 
62
    @Autowired
69
    @Autowired
Line 886... Line 893...
886
        Function<Role, String> roleToNameFunction = role -> String.valueOf(role.getName());
893
        Function<Role, String> roleToNameFunction = role -> String.valueOf(role.getName());
887
        Set<String> userRoleStrings = roles.stream().map(roleToNameFunction).collect(Collectors.toSet());
894
        Set<String> userRoleStrings = roles.stream().map(roleToNameFunction).collect(Collectors.toSet());
888
        return String.join(", ", userRoleStrings);
895
        return String.join(", ", userRoleStrings);
889
    }
896
    }
890
 
897
 
-
 
898
    // A store's warehouse is where its orders are allocated, so only an ACTIVE one may be newly assigned; a store
-
 
899
    // already on a suspended warehouse can still be saved without moving it.
-
 
900
    private void requireAssignableWarehouse(int warehouseId, Integer previousWarehouseId)
-
 
901
            throws ProfitMandiBusinessException {
-
 
902
        if (previousWarehouseId != null && previousWarehouseId == warehouseId) {
-
 
903
            return;
-
 
904
        }
-
 
905
        WarehouseStatus status = billingWarehouseService.getStatus(warehouseId);
-
 
906
        if (status != WarehouseStatus.ACTIVE) {
-
 
907
            throw new ProfitMandiBusinessException("warehouseId", warehouseId, "Warehouse "
-
 
908
                    + billingWarehouseService.getName(warehouseId, String.valueOf(warehouseId)) + " is "
-
 
909
                    + (status == null ? "not a billing warehouse" : status.name().toLowerCase())
-
 
910
                    + " - partner stores can only be assigned to an active warehouse");
-
 
911
        }
-
 
912
    }
-
 
913
 
891
    private FofoStore createFofoStoreCodeByRetailerId(int retailerId, String districtName, String
914
    private FofoStore createFofoStoreCodeByRetailerId(int retailerId, String districtName, String
892
            stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
915
            stateName, UpdateRetailerRequest updateRetailerRequest) throws ProfitMandiBusinessException {
893
        FofoStore fofoStore = null;
916
        FofoStore fofoStore = null;
894
        try {
917
        try {
895
            fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
918
            fofoStore = fofoStoreRepository.selectByRetailerId(retailerId);
Line 903... Line 926...
903
            int previousWarehouseId = fofoStore.getWarehouseId();
926
            int previousWarehouseId = fofoStore.getWarehouseId();
904
            FofoType previousFofoType = fofoStore.getFofoType();
927
            FofoType previousFofoType = fofoStore.getFofoType();
905
            fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
928
            fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
906
            fofoStore.setAstId(updateRetailerRequest.getAstId());
929
            fofoStore.setAstId(updateRetailerRequest.getAstId());
907
            fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
930
            fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
-
 
931
            this.requireAssignableWarehouse(updateRetailerRequest.getWarehouseId(), previousWarehouseId);
908
            fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
932
            fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
909
            fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
933
            fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
910
            fofoStore.setFofoType(updateRetailerRequest.getFofoType());
934
            fofoStore.setFofoType(updateRetailerRequest.getFofoType());
911
            fofoStore.setGstNumber(updateRetailerRequest.getGstNumber());
935
            fofoStore.setGstNumber(updateRetailerRequest.getGstNumber());
912
 
936
 
Line 945... Line 969...
945
            fofoStore.setId(retailerId);
969
            fofoStore.setId(retailerId);
946
            fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
970
            fofoStore.setCounterSize(updateRetailerRequest.getCountersize());
947
            fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
971
            fofoStore.setMinimumInvestment(updateRetailerRequest.getMinInvestment());
948
 
972
 
949
            fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
973
            fofoStore.setCounterPotential(updateRetailerRequest.getCounterPotential());
-
 
974
            this.requireAssignableWarehouse(updateRetailerRequest.getWarehouseId(), null);
950
            fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
975
            fofoStore.setWarehouseId(updateRetailerRequest.getWarehouseId());
951
 
976
 
952
            //Check for Trial users here
977
            //Check for Trial users here
953
            int nextStoreCodeInt = fofoStoreRepository.selectLatestStore().getCodeInt() + 1;
978
            int nextStoreCodeInt = fofoStoreRepository.selectLatestStore().getCodeInt() + 1;
954
 
979