Subversion Repositories SmartDukaan

Rev

Rev 31007 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.service;

import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
import com.spice.profitmandi.common.model.CustomAddress;
import com.spice.profitmandi.common.model.CustomRetailer;
import com.spice.profitmandi.dao.entity.transaction.*;
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
import com.spice.profitmandi.dao.repository.transaction.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SellerServiceImpl implements SellerService {

        @Autowired
        OrganisationRepository organisationRepository;

        @Autowired
        SellerRepository sellerRepository;

        @Autowired
        SellerWarehouseRepository sellerWarehouseRepository;

        @Autowired
        StateRepository stateRepository;

        @Autowired
        WarehouseAddressMappingRepository warehouseAddressMappingRepository;

        @Autowired
        WarehouseAddressMasterRepository warehouseAddressMasterRepository;

        public CustomRetailer convertToSeller(String sellerPrefix) throws ProfitMandiBusinessException {
                SellerWarehouse sellerWarehouse = sellerWarehouseRepository.selectByPrefix(sellerPrefix);
                Seller sellerInfo = sellerRepository.selectById(sellerWarehouse.getSellerId());
                Organisation organisation = organisationRepository.selectById(sellerInfo.getOrganisationId());
                CustomRetailer customRetailer = new CustomRetailer();
                customRetailer.setBusinessName(organisation.getName());
                customRetailer.setGstNumber(sellerInfo.getGstin());
                WarehouseAddressMapping warehouseAddressMapping = warehouseAddressMappingRepository.selectByWarehouseId(sellerWarehouse.getWarehouseId());
                WarehouseAddressMaster warehouseAddressMaster = warehouseAddressMasterRepository.selectById(warehouseAddressMapping.getAddressId());

                CustomAddress customAddress = new CustomAddress();
                try {
                        customAddress.setState(stateRepository.selectById(warehouseAddressMaster.getStateId()).getName());
                } catch (Exception e) {
                        throw new ProfitMandiBusinessException("Warehouse Address State", warehouseAddressMaster.getStateId(),
                                        "Problem while fetching state");
                }
                customAddress.setCity(warehouseAddressMaster.getAddress());
                customAddress.setPinCode(warehouseAddressMaster.getPin());
                customAddress.setPhoneNumber(warehouseAddressMaster.getContacNumber());
                customAddress.setName(organisation.getName());

                customRetailer.setAddress(customAddress);

                return customRetailer;
        }
}