Subversion Repositories SmartDukaan

Rev

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

Rev 23918 Rev 23923
Line 29... Line 29...
29
import com.spice.profitmandi.web.util.CookiesProcessor;
29
import com.spice.profitmandi.web.util.CookiesProcessor;
30
 
30
 
31
@Controller
31
@Controller
32
@Transactional(rollbackFor = Throwable.class)
32
@Transactional(rollbackFor = Throwable.class)
33
public class DashboardController {
33
public class DashboardController {
34
	
34
 
35
	@Value("${web.api.host}")
35
	@Value("${web.api.host}")
36
	private String webApiHost;
36
	private String webApiHost;
37
	
37
 
38
	@Value("${web.api.port}")
38
	@Value("${web.api.port}")
39
	private int webApiPort;
39
	private int webApiPort;
40
 
40
 
41
	@Autowired
41
	@Autowired
42
	private CookiesProcessor cookiesProcessor;
42
	private CookiesProcessor cookiesProcessor;
43
	
43
 
44
	@Autowired
44
	@Autowired
45
	private RoleManager roleManager;
45
	private RoleManager roleManager;
46
	
46
 
47
	@Autowired
47
	@Autowired
48
	private FofoStoreRepository fofoStoreRepository;
48
	private FofoStoreRepository fofoStoreRepository;
49
 
49
 
50
	@Autowired
50
	@Autowired
51
	private WalletService walletService;
51
	private WalletService walletService;
52
	
52
 
53
	@Autowired
53
	@Autowired
54
	private InventoryService inventoryService;
54
	private InventoryService inventoryService;
55
	
55
 
56
	@Autowired
56
	@Autowired
57
	private OrderRepository orderRepository;
57
	private OrderRepository orderRepository;
58
 
58
 
59
	/*@Autowired
59
	/*
60
	private ScanRepository scanRepository;*/
60
	 * @Autowired private ScanRepository scanRepository;
-
 
61
	 */
61
	
62
 
62
	@Autowired
63
	@Autowired
63
	private TransactionService transactionService;
64
	private TransactionService transactionService;
64
	
65
 
65
	private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
66
	private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
66
	
67
 
67
	@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
68
	@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
-
 
69
	public String dashboard(HttpServletRequest request, Model model)
68
	public String dashboard(HttpServletRequest request, Model model) throws ProfitMandiBusinessException, URISyntaxException, IOException{
70
			throws ProfitMandiBusinessException, URISyntaxException, IOException {
69
		//LOGGER.info("scanRepository.selectScansByInventoryItemId(1)", scanRepository.selectScansByInventoryItemId(1));
71
		// LOGGER.info("scanRepository.selectScansByInventoryItemId(1)",
-
 
72
		// scanRepository.selectScansByInventoryItemId(1));
70
		LOGGER.info("In Dashboard");
73
		LOGGER.info("In Dashboard");
71
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
74
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
72
		
75
 
73
		FofoStore fofoStore = null;
76
		FofoStore fofoStore = null;
74
		try {
77
		try {
75
			fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
78
			fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
76
		} catch (ProfitMandiBusinessException e) {
79
		} catch (ProfitMandiBusinessException e) {
77
			LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
80
			LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
78
		}
81
		}
79
		if(roleManager.isPartner(loginDetails.getRoleIds())) {
-
 
80
			float walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
-
 
81
			float inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
-
 
82
 
82
 
-
 
83
		float walletAmount = 0;
-
 
84
		float inStockAmount = 0;
83
			float unbilledStockAmount = 0;
85
		float unbilledStockAmount = 0;
-
 
86
		float grnPendingStockAmount = 0;
-
 
87
		float shortPercentage = 100;
-
 
88
		float totalInvestedAmount = 0;
-
 
89
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
-
 
90
			model.addAttribute("showAlert", false);
-
 
91
		} else if (roleManager.isPartner(loginDetails.getRoleIds())) {
-
 
92
			walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
-
 
93
			inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
-
 
94
 
84
			List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
95
			List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
85
			for(Order unBilledOrder : unbilledOrders) {
96
			for (Order unBilledOrder : unbilledOrders) {
86
				unbilledStockAmount += unBilledOrder.getTotalAmount();
97
				unbilledStockAmount += unBilledOrder.getTotalAmount();
87
			}
98
			}
88
 
99
 
89
			float grnPendingStockAmount = 0;
-
 
90
			List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(loginDetails.getFofoId());
100
			List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(loginDetails.getFofoId());
91
			for(Order grnPendingOrder : grnPendingOrders) {
101
			for (Order grnPendingOrder : grnPendingOrders) {
92
				grnPendingStockAmount += grnPendingOrder.getTotalAmount();
102
				grnPendingStockAmount += grnPendingOrder.getTotalAmount();
93
			}
103
			}
94
			LOGGER.info("walletAmount is {}, inStockAmount is {}, unbilledStockAmount is {}, grnPendingStockAmount is {}",
-
 
95
					walletAmount, inStockAmount, unbilledStockAmount, grnPendingStockAmount);
-
 
96
			float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
104
			totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
97
			LOGGER.info("Total Amount in System is {}", totalInvestedAmount);
-
 
98
			float shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)/fofoStore.getMinimumInvestment())*100;
105
			shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)
99
			LOGGER.info("Store minimum investment is {}", fofoStore.getMinimumInvestment());
106
					/ fofoStore.getMinimumInvestment()) * 100;
100
			LOGGER.info("Investment Currently Short by {}%", shortPercentage);
-
 
101
			model.addAttribute("walletAmount", walletAmount);
-
 
102
			model.addAttribute("inStockAmount", inStockAmount);
-
 
103
			model.addAttribute("unbilledStockAmount", unbilledStockAmount);
-
 
104
			model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
-
 
105
			model.addAttribute("shortPercentage", shortPercentage);
107
			model.addAttribute("showAlert", shortPercentage < 90);
106
			model.addAttribute("totalInvestedAmount", totalInvestedAmount);
-
 
107
			model.addAttribute("minimumInvestmentAmount", fofoStore.getMinimumInvestment());
-
 
108
			model.addAttribute("showAlert", true);
-
 
109
		}
108
		}
-
 
109
		model.addAttribute("walletAmount", walletAmount);
-
 
110
		model.addAttribute("inStockAmount", inStockAmount);
-
 
111
		model.addAttribute("unbilledStockAmount", unbilledStockAmount);
-
 
112
		model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
-
 
113
		model.addAttribute("shortPercentage", shortPercentage);
-
 
114
		model.addAttribute("totalInvestedAmount", totalInvestedAmount);
-
 
115
		model.addAttribute("minimumInvestmentAmount", fofoStore.getMinimumInvestment());
-
 
116
 
110
		model.addAttribute("fofoStore", fofoStore);
117
		model.addAttribute("fofoStore", fofoStore);
111
		model.addAttribute("walletAmount");
118
		model.addAttribute("walletAmount");
112
		model.addAttribute("appContextPath", request.getContextPath());
119
		model.addAttribute("appContextPath", request.getContextPath());
113
		model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
120
		model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
114
		model.addAttribute("webApiHost", webApiHost);
121
		model.addAttribute("webApiHost", webApiHost);
115
		model.addAttribute("webApiPort", webApiPort);
122
		model.addAttribute("webApiPort", webApiPort);
116
		//LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
123
		// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
117
		//inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
124
		// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
118
		return "dashboard";
125
		return "dashboard";
119
	}
126
	}
120
	
-
 
121
	
127
 
122
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
128
	@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
123
	public String contactUs(HttpServletRequest request, Model model) throws Throwable{
129
	public String contactUs(HttpServletRequest request, Model model) throws Throwable {
124
		model.addAttribute("appContextPath", request.getContextPath());
130
		model.addAttribute("appContextPath", request.getContextPath());
125
		return "contact-us";
131
		return "contact-us";
126
	}
132
	}
127
	
133
 
-
 
134
	/*
128
	/*private List<PaymentOption> getPaymentOptions(int fofoId){
135
	 * private List<PaymentOption> getPaymentOptions(int fofoId){ List<Integer>
-
 
136
	 * paymentOptionIds =
129
		List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
137
	 * fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
130
		if(paymentOptionIds.isEmpty()){
138
	 * if(paymentOptionIds.isEmpty()){ return new ArrayList<>(); } return
131
			return new ArrayList<>();
-
 
132
		}
-
 
133
		return paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds));
139
	 * paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds)); }
134
	}*/
140
	 */
135
	
-
 
136
	
141
 
137
}
142
}