| 21615 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 23568 |
govind |
3 |
import java.io.IOException;
|
|
|
4 |
import java.net.URISyntaxException;
|
| 23884 |
amit.gupta |
5 |
import java.util.List;
|
| 23568 |
govind |
6 |
|
| 22086 |
amit.gupta |
7 |
import javax.servlet.http.HttpServletRequest;
|
|
|
8 |
|
| 23786 |
amit.gupta |
9 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
10 |
import org.apache.logging.log4j.Logger;
|
| 22481 |
ashik.ali |
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23379 |
ashik.ali |
12 |
import org.springframework.beans.factory.annotation.Value;
|
| 21615 |
kshitij.so |
13 |
import org.springframework.stereotype.Controller;
|
| 22481 |
ashik.ali |
14 |
import org.springframework.transaction.annotation.Transactional;
|
| 22073 |
ashik.ali |
15 |
import org.springframework.ui.Model;
|
| 21615 |
kshitij.so |
16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
18 |
|
| 22481 |
ashik.ali |
19 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 22654 |
ashik.ali |
20 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 23884 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 22481 |
ashik.ali |
22 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23884 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 23844 |
amit.gupta |
24 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23884 |
amit.gupta |
25 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
|
|
26 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
27 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 22481 |
ashik.ali |
28 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
29 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
30 |
|
| 21615 |
kshitij.so |
31 |
@Controller
|
| 22481 |
ashik.ali |
32 |
@Transactional(rollbackFor = Throwable.class)
|
| 21615 |
kshitij.so |
33 |
public class DashboardController {
|
| 23379 |
ashik.ali |
34 |
|
|
|
35 |
@Value("${web.api.host}")
|
|
|
36 |
private String webApiHost;
|
|
|
37 |
|
|
|
38 |
@Value("${web.api.port}")
|
|
|
39 |
private int webApiPort;
|
| 21615 |
kshitij.so |
40 |
|
| 22481 |
ashik.ali |
41 |
@Autowired
|
| 22927 |
ashik.ali |
42 |
private CookiesProcessor cookiesProcessor;
|
| 23784 |
ashik.ali |
43 |
|
| 23568 |
govind |
44 |
@Autowired
|
| 23786 |
amit.gupta |
45 |
private RoleManager roleManager;
|
| 23784 |
ashik.ali |
46 |
|
| 23838 |
ashik.ali |
47 |
@Autowired
|
|
|
48 |
private FofoStoreRepository fofoStoreRepository;
|
| 23884 |
amit.gupta |
49 |
|
|
|
50 |
@Autowired
|
|
|
51 |
private WalletService walletService;
|
| 23838 |
ashik.ali |
52 |
|
| 23884 |
amit.gupta |
53 |
@Autowired
|
|
|
54 |
private InventoryService inventoryService;
|
|
|
55 |
|
|
|
56 |
@Autowired
|
|
|
57 |
private OrderRepository orderRepository;
|
|
|
58 |
|
| 23887 |
amit.gupta |
59 |
/*@Autowired
|
|
|
60 |
private ScanRepository scanRepository;*/
|
| 23884 |
amit.gupta |
61 |
|
|
|
62 |
@Autowired
|
|
|
63 |
private TransactionService transactionService;
|
|
|
64 |
|
| 23568 |
govind |
65 |
private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
|
| 21615 |
kshitij.so |
66 |
|
|
|
67 |
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
|
| 23568 |
govind |
68 |
public String dashboard(HttpServletRequest request, Model model) throws ProfitMandiBusinessException, URISyntaxException, IOException{
|
| 23884 |
amit.gupta |
69 |
//LOGGER.info("scanRepository.selectScansByInventoryItemId(1)", scanRepository.selectScansByInventoryItemId(1));
|
|
|
70 |
LOGGER.info("In Dashboard");
|
| 22927 |
ashik.ali |
71 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 22481 |
ashik.ali |
72 |
|
|
|
73 |
FofoStore fofoStore = null;
|
|
|
74 |
try {
|
| 22927 |
ashik.ali |
75 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
| 22481 |
ashik.ali |
76 |
} catch (ProfitMandiBusinessException e) {
|
| 22927 |
ashik.ali |
77 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
| 22481 |
ashik.ali |
78 |
}
|
| 23884 |
amit.gupta |
79 |
if(roleManager.isPartner(loginDetails.getRoleIds())) {
|
|
|
80 |
float walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
|
|
|
81 |
float inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
|
|
|
82 |
|
|
|
83 |
float unbilledStockAmount = 0;
|
|
|
84 |
List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
|
|
|
85 |
for(Order unBilledOrder : unbilledOrders) {
|
|
|
86 |
unbilledStockAmount += unBilledOrder.getTotalAmount();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
float grnPendingStockAmount = 0;
|
| 23904 |
amit.gupta |
90 |
List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(loginDetails.getFofoId());
|
| 23884 |
amit.gupta |
91 |
for(Order grnPendingOrder : grnPendingOrders) {
|
|
|
92 |
grnPendingStockAmount += grnPendingOrder.getTotalAmount();
|
|
|
93 |
}
|
|
|
94 |
LOGGER.info("walletAmount is {}, inStockAmount is {}, unbilledStockAmount is {}, grnPendingStockAmount is {}",
|
|
|
95 |
walletAmount, inStockAmount, unbilledStockAmount, grnPendingStockAmount);
|
|
|
96 |
float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
|
|
|
97 |
LOGGER.info("Total Amount in System is {}", totalInvestedAmount);
|
| 23918 |
amit.gupta |
98 |
float shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)/fofoStore.getMinimumInvestment())*100;
|
| 23884 |
amit.gupta |
99 |
LOGGER.info("Store minimum investment is {}", fofoStore.getMinimumInvestment());
|
| 23918 |
amit.gupta |
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);
|
|
|
106 |
model.addAttribute("totalInvestedAmount", totalInvestedAmount);
|
|
|
107 |
model.addAttribute("minimumInvestmentAmount", fofoStore.getMinimumInvestment());
|
|
|
108 |
model.addAttribute("showAlert", true);
|
| 23884 |
amit.gupta |
109 |
}
|
| 23848 |
ashik.ali |
110 |
model.addAttribute("fofoStore", fofoStore);
|
| 23918 |
amit.gupta |
111 |
model.addAttribute("walletAmount");
|
| 22086 |
amit.gupta |
112 |
model.addAttribute("appContextPath", request.getContextPath());
|
| 23796 |
amit.gupta |
113 |
model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23379 |
ashik.ali |
114 |
model.addAttribute("webApiHost", webApiHost);
|
|
|
115 |
model.addAttribute("webApiPort", webApiPort);
|
| 23568 |
govind |
116 |
//LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
|
|
|
117 |
//inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
|
| 21615 |
kshitij.so |
118 |
return "dashboard";
|
|
|
119 |
}
|
|
|
120 |
|
| 22860 |
ashik.ali |
121 |
|
| 22354 |
ashik.ali |
122 |
@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
123 |
public String contactUs(HttpServletRequest request, Model model) throws Throwable{
|
| 22354 |
ashik.ali |
124 |
model.addAttribute("appContextPath", request.getContextPath());
|
|
|
125 |
return "contact-us";
|
|
|
126 |
}
|
|
|
127 |
|
| 23366 |
ashik.ali |
128 |
/*private List<PaymentOption> getPaymentOptions(int fofoId){
|
|
|
129 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
|
|
|
130 |
if(paymentOptionIds.isEmpty()){
|
|
|
131 |
return new ArrayList<>();
|
|
|
132 |
}
|
|
|
133 |
return paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds));
|
|
|
134 |
}*/
|
|
|
135 |
|
|
|
136 |
|
| 21615 |
kshitij.so |
137 |
}
|