| 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 {
|
| 23923 |
amit.gupta |
34 |
|
| 23379 |
ashik.ali |
35 |
@Value("${web.api.host}")
|
|
|
36 |
private String webApiHost;
|
| 23923 |
amit.gupta |
37 |
|
| 23379 |
ashik.ali |
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;
|
| 23923 |
amit.gupta |
43 |
|
| 23568 |
govind |
44 |
@Autowired
|
| 23786 |
amit.gupta |
45 |
private RoleManager roleManager;
|
| 23923 |
amit.gupta |
46 |
|
| 23838 |
ashik.ali |
47 |
@Autowired
|
|
|
48 |
private FofoStoreRepository fofoStoreRepository;
|
| 23884 |
amit.gupta |
49 |
|
|
|
50 |
@Autowired
|
|
|
51 |
private WalletService walletService;
|
| 23923 |
amit.gupta |
52 |
|
| 23884 |
amit.gupta |
53 |
@Autowired
|
|
|
54 |
private InventoryService inventoryService;
|
| 23923 |
amit.gupta |
55 |
|
| 23884 |
amit.gupta |
56 |
@Autowired
|
|
|
57 |
private OrderRepository orderRepository;
|
|
|
58 |
|
| 23923 |
amit.gupta |
59 |
/*
|
|
|
60 |
* @Autowired private ScanRepository scanRepository;
|
|
|
61 |
*/
|
|
|
62 |
|
| 23884 |
amit.gupta |
63 |
@Autowired
|
|
|
64 |
private TransactionService transactionService;
|
| 23923 |
amit.gupta |
65 |
|
| 23568 |
govind |
66 |
private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
|
| 23923 |
amit.gupta |
67 |
|
| 21615 |
kshitij.so |
68 |
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
|
| 23923 |
amit.gupta |
69 |
public String dashboard(HttpServletRequest request, Model model)
|
|
|
70 |
throws ProfitMandiBusinessException, URISyntaxException, IOException {
|
|
|
71 |
// LOGGER.info("scanRepository.selectScansByInventoryItemId(1)",
|
|
|
72 |
// scanRepository.selectScansByInventoryItemId(1));
|
| 23884 |
amit.gupta |
73 |
LOGGER.info("In Dashboard");
|
| 22927 |
ashik.ali |
74 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23923 |
amit.gupta |
75 |
|
| 22481 |
ashik.ali |
76 |
FofoStore fofoStore = null;
|
|
|
77 |
try {
|
| 22927 |
ashik.ali |
78 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
| 22481 |
ashik.ali |
79 |
} catch (ProfitMandiBusinessException e) {
|
| 22927 |
ashik.ali |
80 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
| 22481 |
ashik.ali |
81 |
}
|
| 23884 |
amit.gupta |
82 |
|
| 23923 |
amit.gupta |
83 |
float walletAmount = 0;
|
|
|
84 |
float inStockAmount = 0;
|
|
|
85 |
float unbilledStockAmount = 0;
|
|
|
86 |
float grnPendingStockAmount = 0;
|
|
|
87 |
float shortPercentage = 100;
|
|
|
88 |
float totalInvestedAmount = 0;
|
| 23936 |
tejbeer |
89 |
float minimumInvestment = 0;
|
| 23923 |
amit.gupta |
90 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
91 |
model.addAttribute("showAlert", false);
|
|
|
92 |
} else if (roleManager.isPartner(loginDetails.getRoleIds())) {
|
|
|
93 |
walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
|
|
|
94 |
inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
|
|
|
95 |
|
| 23884 |
amit.gupta |
96 |
List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
|
| 23923 |
amit.gupta |
97 |
for (Order unBilledOrder : unbilledOrders) {
|
| 23884 |
amit.gupta |
98 |
unbilledStockAmount += unBilledOrder.getTotalAmount();
|
|
|
99 |
}
|
|
|
100 |
|
| 23904 |
amit.gupta |
101 |
List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(loginDetails.getFofoId());
|
| 23923 |
amit.gupta |
102 |
for (Order grnPendingOrder : grnPendingOrders) {
|
| 23884 |
amit.gupta |
103 |
grnPendingStockAmount += grnPendingOrder.getTotalAmount();
|
|
|
104 |
}
|
| 23923 |
amit.gupta |
105 |
totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
|
|
|
106 |
shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)
|
|
|
107 |
/ fofoStore.getMinimumInvestment()) * 100;
|
| 23944 |
amit.gupta |
108 |
model.addAttribute("showAlert", shortPercentage > 10);
|
| 23936 |
tejbeer |
109 |
minimumInvestment = fofoStore.getMinimumInvestment();
|
| 23884 |
amit.gupta |
110 |
}
|
| 23923 |
amit.gupta |
111 |
model.addAttribute("walletAmount", walletAmount);
|
|
|
112 |
model.addAttribute("inStockAmount", inStockAmount);
|
|
|
113 |
model.addAttribute("unbilledStockAmount", unbilledStockAmount);
|
|
|
114 |
model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
|
|
|
115 |
model.addAttribute("shortPercentage", shortPercentage);
|
|
|
116 |
model.addAttribute("totalInvestedAmount", totalInvestedAmount);
|
| 23936 |
tejbeer |
117 |
model.addAttribute("minimumInvestmentAmount", minimumInvestment);
|
| 23923 |
amit.gupta |
118 |
|
| 23848 |
ashik.ali |
119 |
model.addAttribute("fofoStore", fofoStore);
|
| 23918 |
amit.gupta |
120 |
model.addAttribute("walletAmount");
|
| 22086 |
amit.gupta |
121 |
model.addAttribute("appContextPath", request.getContextPath());
|
| 23796 |
amit.gupta |
122 |
model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23379 |
ashik.ali |
123 |
model.addAttribute("webApiHost", webApiHost);
|
|
|
124 |
model.addAttribute("webApiPort", webApiPort);
|
| 23923 |
amit.gupta |
125 |
// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
|
|
|
126 |
// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
|
| 21615 |
kshitij.so |
127 |
return "dashboard";
|
|
|
128 |
}
|
| 23923 |
amit.gupta |
129 |
|
| 22354 |
ashik.ali |
130 |
@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
|
| 23923 |
amit.gupta |
131 |
public String contactUs(HttpServletRequest request, Model model) throws Throwable {
|
| 22354 |
ashik.ali |
132 |
model.addAttribute("appContextPath", request.getContextPath());
|
|
|
133 |
return "contact-us";
|
|
|
134 |
}
|
| 23923 |
amit.gupta |
135 |
|
|
|
136 |
/*
|
|
|
137 |
* private List<PaymentOption> getPaymentOptions(int fofoId){ List<Integer>
|
|
|
138 |
* paymentOptionIds =
|
|
|
139 |
* fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
|
|
|
140 |
* if(paymentOptionIds.isEmpty()){ return new ArrayList<>(); } return
|
|
|
141 |
* paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds)); }
|
|
|
142 |
*/
|
|
|
143 |
|
| 21615 |
kshitij.so |
144 |
}
|