| Line 4... |
Line 4... |
| 4 |
import java.net.URISyntaxException;
|
4 |
import java.net.URISyntaxException;
|
| 5 |
import java.time.DayOfWeek;
|
5 |
import java.time.DayOfWeek;
|
| 6 |
import java.time.LocalDate;
|
6 |
import java.time.LocalDate;
|
| 7 |
import java.time.LocalDateTime;
|
7 |
import java.time.LocalDateTime;
|
| 8 |
import java.time.temporal.TemporalAdjusters;
|
8 |
import java.time.temporal.TemporalAdjusters;
|
| 9 |
import java.time.temporal.WeekFields;
|
- |
|
| 10 |
import java.util.ArrayList;
|
- |
|
| 11 |
import java.util.List;
|
9 |
import java.util.List;
|
| 12 |
|
10 |
|
| 13 |
import javax.servlet.http.HttpServletRequest;
|
11 |
import javax.servlet.http.HttpServletRequest;
|
| 14 |
|
12 |
|
| 15 |
import org.apache.logging.log4j.LogManager;
|
13 |
import org.apache.logging.log4j.LogManager;
|
| 16 |
import org.apache.logging.log4j.Logger;
|
14 |
import org.apache.logging.log4j.Logger;
|
| - |
|
15 |
import org.json.JSONArray;
|
| - |
|
16 |
import org.json.JSONObject;
|
| 17 |
import org.springframework.beans.factory.annotation.Autowired;
|
17 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 18 |
import org.springframework.beans.factory.annotation.Value;
|
18 |
import org.springframework.beans.factory.annotation.Value;
|
| 19 |
import org.springframework.stereotype.Controller;
|
19 |
import org.springframework.stereotype.Controller;
|
| 20 |
import org.springframework.transaction.annotation.Transactional;
|
20 |
import org.springframework.transaction.annotation.Transactional;
|
| 21 |
import org.springframework.ui.Model;
|
21 |
import org.springframework.ui.Model;
|
| Line 31... |
Line 31... |
| 31 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
31 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 32 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
32 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 33 |
import com.spice.profitmandi.dao.repository.dtr.NotificationPanelRepository;
|
33 |
import com.spice.profitmandi.dao.repository.dtr.NotificationPanelRepository;
|
| 34 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
34 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 35 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
35 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 36 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;
|
- |
|
| 37 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
36 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 38 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
37 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 39 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
38 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 40 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
- |
|
| 41 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
39 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 42 |
import com.spice.profitmandi.service.wallet.WalletService;
|
40 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 43 |
import com.spice.profitmandi.web.model.LoginDetails;
|
41 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 44 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
42 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 45 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
43 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 46 |
|
44 |
|
| 47 |
import be.ceau.chart.BarChart;
|
- |
|
| 48 |
import be.ceau.chart.color.Color;
|
- |
|
| 49 |
import be.ceau.chart.data.BarData;
|
- |
|
| 50 |
import be.ceau.chart.dataset.BarDataset;
|
- |
|
| 51 |
import be.ceau.chart.options.BarOptions;
|
- |
|
| 52 |
import be.ceau.chart.options.Title;
|
- |
|
| 53 |
import be.ceau.chart.options.scales.BarScale;
|
- |
|
| 54 |
import be.ceau.chart.options.scales.XAxis;
|
- |
|
| 55 |
import be.ceau.chart.options.scales.YAxis;
|
- |
|
| 56 |
import be.ceau.chart.options.ticks.LinearTicks;
|
- |
|
| 57 |
|
- |
|
| 58 |
@Controller
|
45 |
@Controller
|
| 59 |
@Transactional(rollbackFor = Throwable.class)
|
46 |
@Transactional(rollbackFor = Throwable.class)
|
| 60 |
public class DashboardController {
|
47 |
public class DashboardController {
|
| 61 |
|
48 |
|
| - |
|
49 |
private static final String IN_TRANSIT_STACK = "inTransitStack";
|
| - |
|
50 |
|
| - |
|
51 |
private static final String BILLING_PENDING_STACK = "billingPendingStack";
|
| - |
|
52 |
|
| - |
|
53 |
private static final String GRN_PENDING_STACK = "grnPendingStack";
|
| - |
|
54 |
|
| - |
|
55 |
private static final String SALES_STACK = "salesStack";
|
| - |
|
56 |
|
| - |
|
57 |
private static final String IN_STOCK_STACK = "inStockStack";
|
| - |
|
58 |
|
| - |
|
59 |
private static final String WALLET_STACK = "walletStack";
|
| - |
|
60 |
|
| 62 |
@Value("${web.api.host}")
|
61 |
@Value("${web.api.host}")
|
| 63 |
private String webApiHost;
|
62 |
private String webApiHost;
|
| 64 |
|
63 |
|
| 65 |
@Value("${web.api.scheme}")
|
64 |
@Value("${web.api.scheme}")
|
| 66 |
private String webApiScheme;
|
65 |
private String webApiScheme;
|
| Line 84... |
Line 83... |
| 84 |
private WalletService walletService;
|
83 |
private WalletService walletService;
|
| 85 |
|
84 |
|
| 86 |
@Autowired
|
85 |
@Autowired
|
| 87 |
private InventoryService inventoryService;
|
86 |
private InventoryService inventoryService;
|
| 88 |
|
87 |
|
| 89 |
@Autowired
|
- |
|
| 90 |
private TargetSlabService targetSlabService;
|
- |
|
| 91 |
|
88 |
|
| 92 |
@Autowired
|
89 |
@Autowired
|
| 93 |
private OrderRepository orderRepository;
|
90 |
private OrderRepository orderRepository;
|
| 94 |
|
91 |
|
| 95 |
@Autowired
|
- |
|
| 96 |
private PurchaseReturnItemRepository purchaseReturnItemRepository;
|
- |
|
| 97 |
|
92 |
|
| 98 |
@Autowired
|
93 |
@Autowired
|
| 99 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
94 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 100 |
|
95 |
|
| 101 |
/*
|
96 |
/*
|
| Line 272... |
Line 267... |
| 272 |
// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
|
267 |
// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
|
| 273 |
return "dashboard";
|
268 |
return "dashboard";
|
| 274 |
}
|
269 |
}
|
| 275 |
|
270 |
|
| 276 |
private String getInvestmentChartData(List<PartnerDailyInvestment> partnerInvestments) {
|
271 |
private String getInvestmentChartData(List<PartnerDailyInvestment> partnerInvestments) {
|
| - |
|
272 |
|
| 277 |
|
273 |
|
| 278 |
List<List<Integer>> walletStackList = new ArrayList<>();
|
274 |
JSONObject scale = new JSONObject().put("scaleLabel", new JSONObject().put("scaleLabel", "Amount in Rs"));
|
| 279 |
List<List<Integer>> inStockStackList = new ArrayList<>();
|
275 |
JSONObject titleObject = new JSONObject()
|
| 280 |
List<List<Integer>> salesStackList = new ArrayList<>();
|
276 |
.put("display", true)
|
| 281 |
List<List<Integer>> grnPendingStackList = new ArrayList<>();
|
277 |
.put("text", "Investment Overview").put("display", true);
|
| 282 |
List<List<Integer>> billingPendingStackList = new ArrayList<>();
|
- |
|
| 283 |
List<List<Integer>> inTransitStackList = new ArrayList<>();
|
- |
|
| - |
|
278 |
|
| 284 |
List<List<LocalDate>> datesList = new ArrayList<>();
|
279 |
JSONObject barData = new JSONObject();
|
| 285 |
|
280 |
|
| 286 |
int currentWeekOfYear = 0;
|
281 |
JSONObject walletStack = new JSONObject().put("label", "Wallet").put("backgroundColor","rgba(255, 99, 132, 0.2)")
|
| 287 |
List<Integer> walletStack = null;
|
282 |
.put("label", "Wallet").put("stack", WALLET_STACK).put("data", new JSONArray());
|
| - |
|
283 |
JSONObject inStockStack = new JSONObject().put("label", "In Stock").put("backgroundColor","rgba(54, 162, 235, 0.2)")
|
| 288 |
List<Integer> inStockStack = null;
|
284 |
.put("label", "In Stock").put("stack", IN_STOCK_STACK).put("data", new JSONArray());
|
| - |
|
285 |
JSONObject salesStack = new JSONObject().put("label", "Sales").put("backgroundColor","rgba(255, 206, 86, 0.2)")
|
| 289 |
List<Integer> salesStack = null;
|
286 |
.put("label", "Sales").put("stack", SALES_STACK).put("data", new JSONArray());
|
| - |
|
287 |
JSONObject grnPendingStack = new JSONObject().put("label", "Grn Pending").put("backgroundColor","rgba(75, 192, 192, 0.2)")
|
| 290 |
List<Integer> grnPendingStack = null;
|
288 |
.put("label", "Grn Pending").put("stack", GRN_PENDING_STACK).put("data", new JSONArray());
|
| - |
|
289 |
JSONObject billingPendingStack = new JSONObject().put("label", "Billing Pending").put("backgroundColor","rgba(153, 102, 255, 0.2)")
|
| 291 |
List<Integer> billingPendingStack = null;
|
290 |
.put("label", "Billing Pending").put("stack", BILLING_PENDING_STACK).put("data", new JSONArray());
|
| - |
|
291 |
JSONObject inTransitStack = new JSONObject().put("label", "In Transit").put("backgroundColor","rgba(255, 159, 64, 0.2)")
|
| 292 |
List<Integer> inTransitStack = null;
|
292 |
.put("label", "Returned").put("stack", IN_TRANSIT_STACK).put("data", new JSONArray());
|
| - |
|
293 |
|
| 293 |
List<LocalDate> dates = null;
|
294 |
JSONArray dateLabels = new JSONArray();
|
| - |
|
295 |
|
| 294 |
for (PartnerDailyInvestment pdi : partnerInvestments) {
|
296 |
for (PartnerDailyInvestment pdi : partnerInvestments) {
|
| 295 |
int weekOfYear = pdi.getDate().get(WeekFields.ISO.weekOfYear());
|
297 |
dateLabels = dateLabels.put(pdi.getDate().toString());
|
| 296 |
if (weekOfYear != currentWeekOfYear) {
|
- |
|
| 297 |
walletStack = new ArrayList<>();
|
- |
|
| 298 |
inStockStack = new ArrayList<>();
|
- |
|
| 299 |
salesStack = new ArrayList<>();
|
- |
|
| 300 |
grnPendingStack = new ArrayList<>();
|
- |
|
| 301 |
billingPendingStack = new ArrayList<>();
|
- |
|
| 302 |
inTransitStack = new ArrayList<>();
|
- |
|
| 303 |
dates = new ArrayList<>();
|
- |
|
| 304 |
currentWeekOfYear = weekOfYear;
|
- |
|
| 305 |
walletStackList.add(walletStack);
|
- |
|
| 306 |
inStockStackList.add(inStockStack);
|
- |
|
| 307 |
salesStackList.add(salesStack);
|
- |
|
| 308 |
grnPendingStackList.add(grnPendingStack);
|
- |
|
| 309 |
billingPendingStackList.add(billingPendingStack);
|
- |
|
| 310 |
inTransitStackList.add(inTransitStack);
|
- |
|
| 311 |
}
|
- |
|
| 312 |
walletStack.add((int)pdi.getWalletAmount());
|
298 |
walletStack.getJSONArray("data").put((int)pdi.getWalletAmount());
|
| 313 |
inStockStack.add((int)pdi.getInStockAmount());
|
299 |
inStockStack.getJSONArray("data").put((int)pdi.getInStockAmount());
|
| 314 |
salesStack.add((int)pdi.getSalesAmount());
|
300 |
salesStack.getJSONArray("data").put((int)pdi.getSalesAmount());
|
| 315 |
grnPendingStack.add((int)pdi.getGrnPendingAmount());
|
301 |
grnPendingStack.getJSONArray("data").put((int)pdi.getUnbilledAmount());
|
| 316 |
billingPendingStack.add((int)pdi.getUnbilledAmount());
|
302 |
billingPendingStack.getJSONArray("data").put((int)pdi.getGrnPendingAmount());
|
| 317 |
inTransitStack.add((int)pdi.getReturnInTransitAmount());
|
303 |
inTransitStack.getJSONArray("data").put((int)pdi.getReturnInTransitAmount());
|
| 318 |
datesList.add(dates);
|
- |
|
| 319 |
|
- |
|
| 320 |
}
|
304 |
}
|
| 321 |
|
305 |
|
| 322 |
int counter = 0;
|
- |
|
| 323 |
BarData barData = new BarData();
|
306 |
JSONArray barDataSetsArray = new JSONArray().put(walletStack).put(inStockStack)
|
| 324 |
while(counter < walletStackList.size()) {
|
307 |
.put(salesStack).put(grnPendingStack).put(billingPendingStack).put(inTransitStack);
|
| 325 |
barData
|
- |
|
| 326 |
.addDataset(new BarDataset().setData(walletStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("Wallet").addBackgroundColor(Color.BLUE))
|
308 |
barData.put("labels", dateLabels).put("datasets", barDataSetsArray);
|
| 327 |
.addDataset(new BarDataset().setData(inStockStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("In Stock").addBackgroundColor(Color.LIGHT_BLUE))
|
- |
|
| 328 |
.addDataset(new BarDataset().setData(salesStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("Sales").addBackgroundColor(Color.YELLOW))
|
309 |
scale.put("yAxes", new JSONArray().put(new JSONObject().put("stacked", true)))
|
| 329 |
.addDataset(new BarDataset().setData(grnPendingStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("Grn Pending").addBackgroundColor(Color.LIGHT_YELLOW))
|
- |
|
| 330 |
.addDataset(new BarDataset().setData(billingPendingStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("Billing Pending").addBackgroundColor(Color.GREEN))
|
- |
|
| 331 |
.addDataset(new BarDataset().setData(inTransitStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("In Transit").addBackgroundColor(Color.GREEN_YELLOW));
|
310 |
.put("xAxes", new JSONArray().put(new JSONObject().put("stacked", true)));
|
| 332 |
counter++;
|
- |
|
| 333 |
}
|
311 |
|
| 334 |
BarOptions barOptions = new BarOptions()
|
312 |
JSONObject barOptions = new JSONObject()
|
| 335 |
.setTitle(new Title().setDisplay(true).setText("Daily Investment Summary"))
|
313 |
.put("title", titleObject).put("responsive", true)
|
| 336 |
.setResponsive(true)
|
314 |
.put("scales", scale)
|
| 337 |
|
- |
|
| 338 |
.setScales(new BarScale().addxAxes(new XAxis<LinearTicks>().setStacked(true))
|
315 |
.put("tooltips", new JSONObject().put("mode", "index").put("intersect", false));
|
| 339 |
.addyAxes(new YAxis<LinearTicks>().setStacked(true))
|
- |
|
| 340 |
);
|
- |
|
| 341 |
|
316 |
|
| 342 |
BarChart barChart = new BarChart(barData, barOptions);
|
317 |
JSONObject chartJSOn = new JSONObject().put("type", "bar").put("data", barData).put("options", barOptions);
|
| 343 |
return barChart.toJson();
|
318 |
return chartJSOn.toString();
|
| 344 |
}
|
319 |
}
|
| 345 |
|
320 |
|
| 346 |
// This method is currently hardcoded to faciliate watches sold as gift.
|
321 |
// This method is currently hardcoded to faciliate watches sold as gift.
|
| 347 |
private boolean hasGift(int fofoId) {
|
322 |
private boolean hasGift(int fofoId) {
|
| 348 |
try {
|
323 |
try {
|
| Line 357... |
Line 332... |
| 357 |
public String getPaginatedNotificationData(HttpServletRequest request,
|
332 |
public String getPaginatedNotificationData(HttpServletRequest request,
|
| 358 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
333 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
| 359 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
|
334 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
|
| 360 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
335 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 361 |
|
336 |
|
| 362 |
FofoStore fofoStore = null;
|
- |
|
| 363 |
try {
|
- |
|
| 364 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
- |
|
| 365 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 366 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
- |
|
| 367 |
}
|
- |
|
| 368 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
337 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 369 |
List<NotificationData> notificationData = null;
|
338 |
List<NotificationData> notificationData = null;
|
| 370 |
|
339 |
|
| 371 |
notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
|
340 |
notificationData = notificationPanelRepository.selectAllNotificationData(offset, limit);
|
| 372 |
|
341 |
|