Subversion Repositories SmartDukaan

Rev

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

Rev 23848 Rev 23884
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.IOException;
3
import java.io.IOException;
4
import java.net.URISyntaxException;
4
import java.net.URISyntaxException;
-
 
5
import java.util.List;
5
 
6
 
6
import javax.servlet.http.HttpServletRequest;
7
import javax.servlet.http.HttpServletRequest;
7
 
8
 
8
import org.apache.logging.log4j.LogManager;
9
import org.apache.logging.log4j.LogManager;
9
import org.apache.logging.log4j.Logger;
10
import org.apache.logging.log4j.Logger;
Line 15... Line 16...
15
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMethod;
17
import org.springframework.web.bind.annotation.RequestMethod;
17
 
18
 
18
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
20
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
21
import com.spice.profitmandi.dao.entity.transaction.Order;
20
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
22
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
-
 
23
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
21
import com.spice.profitmandi.service.authentication.RoleManager;
24
import com.spice.profitmandi.service.authentication.RoleManager;
-
 
25
import com.spice.profitmandi.service.inventory.InventoryService;
-
 
26
import com.spice.profitmandi.service.transaction.TransactionService;
-
 
27
import com.spice.profitmandi.service.wallet.WalletService;
-
 
28
import com.spice.profitmandi.warehouse.dao.repository.ScanRepository;
22
import com.spice.profitmandi.web.model.LoginDetails;
29
import com.spice.profitmandi.web.model.LoginDetails;
23
import com.spice.profitmandi.web.util.CookiesProcessor;
30
import com.spice.profitmandi.web.util.CookiesProcessor;
24
 
31
 
25
@Controller
32
@Controller
26
@Transactional(rollbackFor = Throwable.class)
33
@Transactional(rollbackFor = Throwable.class)
Line 38... Line 45...
38
	@Autowired
45
	@Autowired
39
	private RoleManager roleManager;
46
	private RoleManager roleManager;
40
	
47
	
41
	@Autowired
48
	@Autowired
42
	private FofoStoreRepository fofoStoreRepository;
49
	private FofoStoreRepository fofoStoreRepository;
-
 
50
 
-
 
51
	@Autowired
-
 
52
	private WalletService walletService;
-
 
53
	
-
 
54
	@Autowired
-
 
55
	private InventoryService inventoryService;
-
 
56
	
-
 
57
	@Autowired
-
 
58
	private OrderRepository orderRepository;
-
 
59
 
-
 
60
	@Autowired
-
 
61
	private ScanRepository scanRepository;
-
 
62
	
-
 
63
	@Autowired
-
 
64
	private TransactionService transactionService;
43
	
65
	
44
	private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
66
	private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
45
	
67
	
46
	@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
68
	@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
47
	public String dashboard(HttpServletRequest request, Model model) throws ProfitMandiBusinessException, URISyntaxException, IOException{
69
	public String dashboard(HttpServletRequest request, Model model) throws ProfitMandiBusinessException, URISyntaxException, IOException{
-
 
70
		//LOGGER.info("scanRepository.selectScansByInventoryItemId(1)", scanRepository.selectScansByInventoryItemId(1));
-
 
71
		LOGGER.info("In Dashboard");
48
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
72
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
49
		
73
		
50
		FofoStore fofoStore = null;
74
		FofoStore fofoStore = null;
51
		try {
75
		try {
52
			fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
76
			fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
53
		} catch (ProfitMandiBusinessException e) {
77
		} catch (ProfitMandiBusinessException e) {
54
			LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
78
			LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
55
		}
79
		}
-
 
80
		if(roleManager.isPartner(loginDetails.getRoleIds())) {
-
 
81
			float walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
-
 
82
			float inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
-
 
83
 
-
 
84
			float unbilledStockAmount = 0;
-
 
85
			List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
-
 
86
			for(Order unBilledOrder : unbilledOrders) {
-
 
87
				unbilledStockAmount += unBilledOrder.getTotalAmount();
-
 
88
			}
-
 
89
 
-
 
90
			float grnPendingStockAmount = 0;
-
 
91
			List<Order> grnPendingOrders = transactionService.getGrnPendingOrders(loginDetails.getFofoId());
-
 
92
			for(Order grnPendingOrder : grnPendingOrders) {
-
 
93
				grnPendingStockAmount += grnPendingOrder.getTotalAmount();
-
 
94
			}
-
 
95
			LOGGER.info("walletAmount is {}, inStockAmount is {}, unbilledStockAmount is {}, grnPendingStockAmount is {}",
-
 
96
					walletAmount, inStockAmount, unbilledStockAmount, grnPendingStockAmount);
-
 
97
			float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
-
 
98
			LOGGER.info("Total Amount in System is {}", totalInvestedAmount);
-
 
99
			LOGGER.info("Store minimum investment is {}", fofoStore.getMinimumInvestment());
-
 
100
			LOGGER.info("Investment Currently Short by {}%", ((fofoStore.getMinimumInvestment() - totalInvestedAmount)/fofoStore.getMinimumInvestment())*100);
-
 
101
		}
56
		model.addAttribute("fofoStore", fofoStore);
102
		model.addAttribute("fofoStore", fofoStore);
57
		model.addAttribute("appContextPath", request.getContextPath());
103
		model.addAttribute("appContextPath", request.getContextPath());
58
		model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
104
		model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
59
		model.addAttribute("webApiHost", webApiHost);
105
		model.addAttribute("webApiHost", webApiHost);
60
		model.addAttribute("webApiPort", webApiPort);
106
		model.addAttribute("webApiPort", webApiPort);