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