| 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;
|
| 24098 |
tejbeer |
18 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21615 |
kshitij.so |
19 |
|
| 22481 |
ashik.ali |
20 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24098 |
tejbeer |
21 |
import com.spice.profitmandi.dao.entity.dtr.NotificationData;
|
| 22654 |
ashik.ali |
22 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 23884 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 22481 |
ashik.ali |
24 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24098 |
tejbeer |
25 |
import com.spice.profitmandi.dao.repository.dtr.NotificationPanelRepository;
|
| 23951 |
amit.gupta |
26 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
|
| 23884 |
amit.gupta |
27 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 23844 |
amit.gupta |
28 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23884 |
amit.gupta |
29 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
|
|
30 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
31 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 22481 |
ashik.ali |
32 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
33 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
34 |
|
| 21615 |
kshitij.so |
35 |
@Controller
|
| 22481 |
ashik.ali |
36 |
@Transactional(rollbackFor = Throwable.class)
|
| 21615 |
kshitij.so |
37 |
public class DashboardController {
|
| 23923 |
amit.gupta |
38 |
|
| 23379 |
ashik.ali |
39 |
@Value("${web.api.host}")
|
|
|
40 |
private String webApiHost;
|
| 23923 |
amit.gupta |
41 |
|
| 24072 |
amit.gupta |
42 |
@Value("${web.api.scheme}")
|
|
|
43 |
private String webApiScheme;
|
|
|
44 |
|
| 24078 |
amit.gupta |
45 |
@Value("${web.api.root}")
|
|
|
46 |
private String webApiRoot;
|
|
|
47 |
|
| 23379 |
ashik.ali |
48 |
@Value("${web.api.port}")
|
|
|
49 |
private int webApiPort;
|
| 21615 |
kshitij.so |
50 |
|
| 24077 |
amit.gupta |
51 |
|
| 22481 |
ashik.ali |
52 |
@Autowired
|
| 22927 |
ashik.ali |
53 |
private CookiesProcessor cookiesProcessor;
|
| 23923 |
amit.gupta |
54 |
|
| 23568 |
govind |
55 |
@Autowired
|
| 23786 |
amit.gupta |
56 |
private RoleManager roleManager;
|
| 23923 |
amit.gupta |
57 |
|
| 23838 |
ashik.ali |
58 |
@Autowired
|
|
|
59 |
private FofoStoreRepository fofoStoreRepository;
|
| 23884 |
amit.gupta |
60 |
|
|
|
61 |
@Autowired
|
|
|
62 |
private WalletService walletService;
|
| 23923 |
amit.gupta |
63 |
|
| 23884 |
amit.gupta |
64 |
@Autowired
|
|
|
65 |
private InventoryService inventoryService;
|
| 23923 |
amit.gupta |
66 |
|
| 23884 |
amit.gupta |
67 |
@Autowired
|
|
|
68 |
private OrderRepository orderRepository;
|
| 23951 |
amit.gupta |
69 |
|
|
|
70 |
@Autowired
|
|
|
71 |
private PurchaseReturnItemRepository purchaseReturnItemRepository;
|
| 24098 |
tejbeer |
72 |
|
| 23923 |
amit.gupta |
73 |
/*
|
|
|
74 |
* @Autowired private ScanRepository scanRepository;
|
|
|
75 |
*/
|
|
|
76 |
|
| 23884 |
amit.gupta |
77 |
@Autowired
|
|
|
78 |
private TransactionService transactionService;
|
| 24098 |
tejbeer |
79 |
|
|
|
80 |
@Autowired
|
|
|
81 |
private NotificationPanelRepository notificationPanelRepository;
|
| 23923 |
amit.gupta |
82 |
|
| 23568 |
govind |
83 |
private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
|
| 23923 |
amit.gupta |
84 |
|
| 21615 |
kshitij.so |
85 |
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
|
| 24098 |
tejbeer |
86 |
public String dashboard(HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
87 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
| 23923 |
amit.gupta |
88 |
throws ProfitMandiBusinessException, URISyntaxException, IOException {
|
|
|
89 |
// LOGGER.info("scanRepository.selectScansByInventoryItemId(1)",
|
|
|
90 |
// scanRepository.selectScansByInventoryItemId(1));
|
| 23884 |
amit.gupta |
91 |
LOGGER.info("In Dashboard");
|
| 22927 |
ashik.ali |
92 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23923 |
amit.gupta |
93 |
|
| 22481 |
ashik.ali |
94 |
FofoStore fofoStore = null;
|
|
|
95 |
try {
|
| 22927 |
ashik.ali |
96 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
| 22481 |
ashik.ali |
97 |
} catch (ProfitMandiBusinessException e) {
|
| 22927 |
ashik.ali |
98 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
| 22481 |
ashik.ali |
99 |
}
|
| 23884 |
amit.gupta |
100 |
|
| 23923 |
amit.gupta |
101 |
float walletAmount = 0;
|
|
|
102 |
float inStockAmount = 0;
|
|
|
103 |
float unbilledStockAmount = 0;
|
|
|
104 |
float grnPendingStockAmount = 0;
|
|
|
105 |
float shortPercentage = 100;
|
|
|
106 |
float totalInvestedAmount = 0;
|
| 23936 |
tejbeer |
107 |
float minimumInvestment = 0;
|
| 23951 |
amit.gupta |
108 |
float returnedStockInTransit=0;
|
| 23923 |
amit.gupta |
109 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
110 |
model.addAttribute("showAlert", false);
|
|
|
111 |
} else if (roleManager.isPartner(loginDetails.getRoleIds())) {
|
|
|
112 |
walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
|
|
|
113 |
inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
|
|
|
114 |
|
| 23884 |
amit.gupta |
115 |
List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
|
| 23923 |
amit.gupta |
116 |
for (Order unBilledOrder : unbilledOrders) {
|
| 23884 |
amit.gupta |
117 |
unbilledStockAmount += unBilledOrder.getTotalAmount();
|
|
|
118 |
}
|
|
|
119 |
|
| 23904 |
amit.gupta |
120 |
List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(loginDetails.getFofoId());
|
| 23923 |
amit.gupta |
121 |
for (Order grnPendingOrder : grnPendingOrders) {
|
| 23884 |
amit.gupta |
122 |
grnPendingStockAmount += grnPendingOrder.getTotalAmount();
|
|
|
123 |
}
|
| 23923 |
amit.gupta |
124 |
totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;
|
|
|
125 |
shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)
|
|
|
126 |
/ fofoStore.getMinimumInvestment()) * 100;
|
| 23944 |
amit.gupta |
127 |
model.addAttribute("showAlert", shortPercentage > 10);
|
| 23936 |
tejbeer |
128 |
minimumInvestment = fofoStore.getMinimumInvestment();
|
| 23951 |
amit.gupta |
129 |
|
|
|
130 |
//debitNoteRepository.se
|
| 23884 |
amit.gupta |
131 |
}
|
| 23923 |
amit.gupta |
132 |
model.addAttribute("walletAmount", walletAmount);
|
|
|
133 |
model.addAttribute("inStockAmount", inStockAmount);
|
|
|
134 |
model.addAttribute("unbilledStockAmount", unbilledStockAmount);
|
|
|
135 |
model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
|
|
|
136 |
model.addAttribute("shortPercentage", shortPercentage);
|
|
|
137 |
model.addAttribute("totalInvestedAmount", totalInvestedAmount);
|
| 23936 |
tejbeer |
138 |
model.addAttribute("minimumInvestmentAmount", minimumInvestment);
|
| 23951 |
amit.gupta |
139 |
model.addAttribute("returnedStockInTransit", returnedStockInTransit);
|
| 23923 |
amit.gupta |
140 |
|
| 23848 |
ashik.ali |
141 |
model.addAttribute("fofoStore", fofoStore);
|
| 23918 |
amit.gupta |
142 |
model.addAttribute("walletAmount");
|
| 22086 |
amit.gupta |
143 |
model.addAttribute("appContextPath", request.getContextPath());
|
| 23796 |
amit.gupta |
144 |
model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 23379 |
ashik.ali |
145 |
model.addAttribute("webApiHost", webApiHost);
|
|
|
146 |
model.addAttribute("webApiPort", webApiPort);
|
| 24072 |
amit.gupta |
147 |
model.addAttribute("webApiScheme", webApiScheme);
|
| 24077 |
amit.gupta |
148 |
model.addAttribute("webApiRoot", webApiRoot);
|
| 24098 |
tejbeer |
149 |
|
|
|
150 |
List<NotificationData> notificationData = null;
|
|
|
151 |
long size = 0;
|
|
|
152 |
|
|
|
153 |
notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
|
|
|
154 |
size = notificationPanelRepository.selectAllCount();
|
|
|
155 |
LOGGER.info("notification_data {}", notificationData);
|
|
|
156 |
|
|
|
157 |
LOGGER.info("notification_data {}",size);
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
if (!notificationData.isEmpty()) {
|
|
|
161 |
|
|
|
162 |
model.addAttribute("notificationData",notificationData);
|
|
|
163 |
LOGGER.info("notificationdata", notificationData);
|
|
|
164 |
model.addAttribute("start", offset + 1);
|
|
|
165 |
model.addAttribute("size", size);
|
|
|
166 |
model.addAttribute("url", "/getPaginatedNotificationData");
|
|
|
167 |
|
|
|
168 |
LOGGER.info("start {}",offset+1);
|
|
|
169 |
LOGGER.info("SIZE {}",size);
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
|
173 |
if (notificationData.size() < limit) {
|
|
|
174 |
model.addAttribute("end", offset + notificationData.size());
|
|
|
175 |
LOGGER.info("SIZE2 {}", offset + notificationData.size());
|
|
|
176 |
} else {
|
|
|
177 |
model.addAttribute("end", offset + limit);
|
|
|
178 |
|
|
|
179 |
LOGGER.info("end {}",size);
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
} else {
|
|
|
186 |
|
|
|
187 |
model.addAttribute("notificationData", notificationData);
|
|
|
188 |
model.addAttribute("size", size);
|
|
|
189 |
LOGGER.info("sizeOriginal {}",size);
|
|
|
190 |
|
|
|
191 |
}
|
| 23923 |
amit.gupta |
192 |
// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
|
|
|
193 |
// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
|
| 21615 |
kshitij.so |
194 |
return "dashboard";
|
|
|
195 |
}
|
| 23923 |
amit.gupta |
196 |
|
| 24098 |
tejbeer |
197 |
|
|
|
198 |
@RequestMapping(value = "/getPaginatedNotificationData", method = RequestMethod.GET)
|
|
|
199 |
public String getPaginatedNotificationData(HttpServletRequest request,
|
|
|
200 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
201 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
|
|
|
202 |
List<NotificationData> notificationData = null;
|
|
|
203 |
|
|
|
204 |
notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
|
|
|
205 |
|
|
|
206 |
LOGGER.info("notification_data {}", notificationData);
|
|
|
207 |
|
|
|
208 |
|
|
|
209 |
if (!notificationData.isEmpty()) {
|
|
|
210 |
|
|
|
211 |
model.addAttribute("notificationData",notificationData);
|
|
|
212 |
model.addAttribute("url", "/getPaginatedNotificationData");
|
|
|
213 |
|
|
|
214 |
} else {
|
|
|
215 |
model.addAttribute("notificationData", notificationData);
|
|
|
216 |
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
return "dashboard-paginated";
|
|
|
220 |
}
|
| 22354 |
ashik.ali |
221 |
@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
|
| 23923 |
amit.gupta |
222 |
public String contactUs(HttpServletRequest request, Model model) throws Throwable {
|
| 22354 |
ashik.ali |
223 |
model.addAttribute("appContextPath", request.getContextPath());
|
|
|
224 |
return "contact-us";
|
|
|
225 |
}
|
| 23923 |
amit.gupta |
226 |
|
|
|
227 |
/*
|
|
|
228 |
* private List<PaymentOption> getPaymentOptions(int fofoId){ List<Integer>
|
|
|
229 |
* paymentOptionIds =
|
|
|
230 |
* fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);
|
|
|
231 |
* if(paymentOptionIds.isEmpty()){ return new ArrayList<>(); } return
|
|
|
232 |
* paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds)); }
|
|
|
233 |
*/
|
|
|
234 |
|
| 21615 |
kshitij.so |
235 |
}
|