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