Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
31007 amit.gupta 1
package com.spice.profitmandi.service;
2
 
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.common.model.CustomAddress;
5
import com.spice.profitmandi.common.model.CustomRetailer;
6
import com.spice.profitmandi.dao.entity.transaction.*;
7
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
8
import com.spice.profitmandi.dao.repository.transaction.*;
9
import org.springframework.beans.factory.annotation.Autowired;
10
import org.springframework.stereotype.Component;
11
 
12
@Component
13
public class SellerServiceImpl implements SellerService {
14
 
15
	@Autowired
16
	OrganisationRepository organisationRepository;
17
 
18
	@Autowired
19
	SellerRepository sellerRepository;
20
 
21
	@Autowired
22
	SellerWarehouseRepository sellerWarehouseRepository;
23
 
24
	@Autowired
25
	StateRepository stateRepository;
26
 
27
	@Autowired
32383 amit.gupta 28
	WarehouseAddressMappingRepository warehouseAddressMappingRepository;
31007 amit.gupta 29
 
30
	@Autowired
32383 amit.gupta 31
	WarehouseAddressMasterRepository warehouseAddressMasterRepository;
31007 amit.gupta 32
 
33
	public CustomRetailer convertToSeller(String sellerPrefix) throws ProfitMandiBusinessException {
34
		SellerWarehouse sellerWarehouse = sellerWarehouseRepository.selectByPrefix(sellerPrefix);
35
		Seller sellerInfo = sellerRepository.selectById(sellerWarehouse.getSellerId());
36
		Organisation organisation = organisationRepository.selectById(sellerInfo.getOrganisationId());
37
		CustomRetailer customRetailer = new CustomRetailer();
38
		customRetailer.setBusinessName(organisation.getName());
39
		customRetailer.setGstNumber(sellerInfo.getGstin());
32383 amit.gupta 40
		WarehouseAddressMapping warehouseAddressMapping = warehouseAddressMappingRepository.selectByWarehouseId(sellerWarehouse.getWarehouseId());
41
		WarehouseAddressMaster warehouseAddressMaster = warehouseAddressMasterRepository.selectById(warehouseAddressMapping.getAddressId());
31007 amit.gupta 42
 
43
		CustomAddress customAddress = new CustomAddress();
44
		try {
45
			customAddress.setState(stateRepository.selectById(warehouseAddressMaster.getStateId()).getName());
46
		} catch (Exception e) {
47
			throw new ProfitMandiBusinessException("Warehouse Address State", warehouseAddressMaster.getStateId(),
48
					"Problem while fetching state");
49
		}
50
		customAddress.setCity(warehouseAddressMaster.getAddress());
51
		customAddress.setPinCode(warehouseAddressMaster.getPin());
52
		customAddress.setPhoneNumber(warehouseAddressMaster.getContacNumber());
53
		customAddress.setName(organisation.getName());
54
 
55
		customRetailer.setAddress(customAddress);
56
 
57
		return customRetailer;
58
	}
59
}