| 21615 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 25221 |
amit.gupta |
3 |
import java.text.DecimalFormat;
|
| 24288 |
amit.gupta |
4 |
import java.time.LocalDate;
|
| 24276 |
amit.gupta |
5 |
import java.time.LocalDateTime;
|
| 24880 |
govind |
6 |
import java.time.LocalTime;
|
| 24339 |
amit.gupta |
7 |
import java.util.ArrayList;
|
| 25136 |
amit.gupta |
8 |
import java.util.LinkedHashMap;
|
| 23884 |
amit.gupta |
9 |
import java.util.List;
|
| 24880 |
govind |
10 |
import java.util.Map;
|
|
|
11 |
import java.util.stream.Collectors;
|
| 23568 |
govind |
12 |
|
| 22086 |
amit.gupta |
13 |
import javax.servlet.http.HttpServletRequest;
|
| 25221 |
amit.gupta |
14 |
import javax.transaction.Transactional;
|
| 22086 |
amit.gupta |
15 |
|
| 23786 |
amit.gupta |
16 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
17 |
import org.apache.logging.log4j.Logger;
|
| 22481 |
ashik.ali |
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23379 |
ashik.ali |
19 |
import org.springframework.beans.factory.annotation.Value;
|
| 21615 |
kshitij.so |
20 |
import org.springframework.stereotype.Controller;
|
| 22073 |
ashik.ali |
21 |
import org.springframework.ui.Model;
|
| 21615 |
kshitij.so |
22 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
23 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
24 |
|
| 24996 |
amit.gupta |
25 |
import com.mongodb.DBObject;
|
| 22481 |
ashik.ali |
26 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24996 |
amit.gupta |
27 |
import com.spice.profitmandi.common.model.BrandStockPrice;
|
| 24203 |
amit.gupta |
28 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 24880 |
govind |
29 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 22654 |
ashik.ali |
30 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 24288 |
amit.gupta |
31 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| 25214 |
amit.gupta |
32 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTarget;
|
|
|
33 |
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
|
| 24880 |
govind |
34 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 22481 |
ashik.ali |
35 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24880 |
govind |
36 |
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
|
|
|
37 |
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
|
| 24996 |
amit.gupta |
38 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 24098 |
tejbeer |
39 |
import com.spice.profitmandi.dao.repository.dtr.NotificationPanelRepository;
|
| 24880 |
govind |
40 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 24203 |
amit.gupta |
41 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 24880 |
govind |
42 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 24288 |
amit.gupta |
43 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 25214 |
amit.gupta |
44 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTargetRepository;
|
|
|
45 |
import com.spice.profitmandi.dao.repository.fofo.TargetSlabRepository;
|
| 24336 |
amit.gupta |
46 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 23844 |
amit.gupta |
47 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23884 |
amit.gupta |
48 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 25214 |
amit.gupta |
49 |
import com.spice.profitmandi.service.slab.TargetSlabService;
|
| 23884 |
amit.gupta |
50 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 22481 |
ashik.ali |
51 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
52 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 24263 |
tejbeer |
53 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 22481 |
ashik.ali |
54 |
|
| 21615 |
kshitij.so |
55 |
@Controller
|
| 25222 |
amit.gupta |
56 |
@Transactional(rollbackOn = Throwable.class)
|
| 21615 |
kshitij.so |
57 |
public class DashboardController {
|
| 23923 |
amit.gupta |
58 |
|
| 23379 |
ashik.ali |
59 |
@Value("${web.api.host}")
|
|
|
60 |
private String webApiHost;
|
| 23923 |
amit.gupta |
61 |
|
| 24072 |
amit.gupta |
62 |
@Value("${web.api.scheme}")
|
|
|
63 |
private String webApiScheme;
|
| 24288 |
amit.gupta |
64 |
|
| 24078 |
amit.gupta |
65 |
@Value("${web.api.root}")
|
|
|
66 |
private String webApiRoot;
|
|
|
67 |
|
| 23379 |
ashik.ali |
68 |
@Value("${web.api.port}")
|
|
|
69 |
private int webApiPort;
|
| 21615 |
kshitij.so |
70 |
|
| 22481 |
ashik.ali |
71 |
@Autowired
|
| 22927 |
ashik.ali |
72 |
private CookiesProcessor cookiesProcessor;
|
| 23923 |
amit.gupta |
73 |
|
| 23568 |
govind |
74 |
@Autowired
|
| 24880 |
govind |
75 |
private ItemRepository itemRepository;
|
|
|
76 |
|
|
|
77 |
@Autowired
|
| 25214 |
amit.gupta |
78 |
private TargetSlabService targetSlabService;
|
|
|
79 |
|
|
|
80 |
@Autowired
|
|
|
81 |
private PartnerTargetRepository partnerTargetRepository;
|
|
|
82 |
|
|
|
83 |
@Autowired
|
|
|
84 |
private TargetSlabRepository targetSlabRepository;
|
|
|
85 |
|
|
|
86 |
@Autowired
|
| 23786 |
amit.gupta |
87 |
private RoleManager roleManager;
|
| 23923 |
amit.gupta |
88 |
|
| 23838 |
ashik.ali |
89 |
@Autowired
|
|
|
90 |
private FofoStoreRepository fofoStoreRepository;
|
| 23884 |
amit.gupta |
91 |
|
|
|
92 |
@Autowired
|
| 24880 |
govind |
93 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| 23923 |
amit.gupta |
94 |
|
| 23884 |
amit.gupta |
95 |
@Autowired
|
| 24880 |
govind |
96 |
private PartnerInvestmentService partnerInvestmentService;
|
| 24288 |
amit.gupta |
97 |
|
| 23884 |
amit.gupta |
98 |
@Autowired
|
| 24880 |
govind |
99 |
private InsurancePolicyRepository insurancePolicyRepository;
|
| 23923 |
amit.gupta |
100 |
/*
|
|
|
101 |
* @Autowired private ScanRepository scanRepository;
|
|
|
102 |
*/
|
| 24880 |
govind |
103 |
@Autowired
|
|
|
104 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
| 23923 |
amit.gupta |
105 |
|
| 23884 |
amit.gupta |
106 |
@Autowired
|
|
|
107 |
private TransactionService transactionService;
|
| 25136 |
amit.gupta |
108 |
|
| 24996 |
amit.gupta |
109 |
@Autowired
|
|
|
110 |
private InventoryService inventoryService;
|
| 24263 |
tejbeer |
111 |
|
| 24098 |
tejbeer |
112 |
@Autowired
|
| 24263 |
tejbeer |
113 |
private MVCResponseSender mvcResponseSender;
|
|
|
114 |
|
|
|
115 |
@Autowired
|
| 24098 |
tejbeer |
116 |
private NotificationPanelRepository notificationPanelRepository;
|
| 23923 |
amit.gupta |
117 |
|
| 24203 |
amit.gupta |
118 |
@Autowired
|
|
|
119 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
120 |
|
| 24880 |
govind |
121 |
@Autowired
|
|
|
122 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
|
|
123 |
|
|
|
124 |
@Autowired
|
|
|
125 |
private InsuranceProviderRepository insuranceProviderRepository;
|
| 25136 |
amit.gupta |
126 |
|
| 24996 |
amit.gupta |
127 |
@Autowired
|
|
|
128 |
private Mongo mongoClient;
|
| 24880 |
govind |
129 |
|
| 23568 |
govind |
130 |
private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
|
| 23923 |
amit.gupta |
131 |
|
| 25136 |
amit.gupta |
132 |
@RequestMapping(value = "/12dashboard34", method = RequestMethod.GET)
|
| 25140 |
amit.gupta |
133 |
public String dashboard1(HttpServletRequest request, Model model) throws Exception {
|
| 25136 |
amit.gupta |
134 |
LOGGER.info("In Dashboard1");
|
|
|
135 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 25179 |
amit.gupta |
136 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
137 |
model.addAttribute("isAdmin", isAdmin);
|
| 25180 |
amit.gupta |
138 |
if (!isAdmin) {
|
| 25179 |
amit.gupta |
139 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
|
|
|
140 |
model.addAttribute("salesMap", this.getSales(loginDetails.getFofoId()));
|
|
|
141 |
model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
|
|
|
142 |
return "dashboard1";
|
|
|
143 |
}
|
| 25136 |
amit.gupta |
144 |
return "dashboard1";
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
private Map<String, Object> getInvestments(int fofoId) throws Exception {
|
|
|
148 |
Map<String, Object> investments = new LinkedHashMap<>();
|
|
|
149 |
PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 1);
|
|
|
150 |
LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1);
|
|
|
151 |
LocalDate yesterDate = LocalDate.now().minusDays(1);
|
|
|
152 |
PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
|
|
|
153 |
if (yesterdayInvestment == null) {
|
|
|
154 |
yesterdayInvestment = new PartnerDailyInvestment();
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId,
|
|
|
158 |
currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
|
|
|
159 |
|
| 25140 |
amit.gupta |
160 |
long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10)
|
| 25136 |
amit.gupta |
161 |
.collect(Collectors.counting());
|
| 25140 |
amit.gupta |
162 |
investments.put("today", investment.getTotalInvestment());
|
|
|
163 |
investments.put("investment", investment);
|
|
|
164 |
investments.put("inStock", investment.getInStockAmount());
|
| 25182 |
amit.gupta |
165 |
investments.put("minimum", investment.getMinInvestmentString());
|
| 25140 |
amit.gupta |
166 |
investments.put("short", investment.getShortPercentage());
|
|
|
167 |
investments.put("okDays", okInvestmentDays);
|
| 25136 |
amit.gupta |
168 |
return investments;
|
|
|
169 |
}
|
|
|
170 |
|
| 25221 |
amit.gupta |
171 |
private Map<String, Object> getSales(int fofoId) {
|
|
|
172 |
Map<String, Object> salesMap = new LinkedHashMap<>();
|
| 25140 |
amit.gupta |
173 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 25214 |
amit.gupta |
174 |
int monthLength = LocalDate.now().lengthOfMonth();
|
| 25140 |
amit.gupta |
175 |
List<FofoOrderItem> fofoOrderItems = fofoOrderItemRepository.selectBetweenCreatedTime(fofoId, curDate,
|
|
|
176 |
curDate.with(LocalTime.MAX));
|
|
|
177 |
List<FofoOrderItem> mtdFofoOrderItems = fofoOrderItemRepository.selectBetweenCreatedTime(fofoId,
|
|
|
178 |
curDate.withDayOfMonth(1), curDate.with(LocalTime.MAX));
|
|
|
179 |
double todaySale = fofoOrderItems.stream()
|
|
|
180 |
.collect(Collectors.summingDouble(x -> x.getSellingPrice() * x.getQuantity()));
|
|
|
181 |
double mtdSale = mtdFofoOrderItems.stream()
|
|
|
182 |
.collect(Collectors.summingDouble(x -> x.getSellingPrice() * x.getQuantity()));
|
| 25214 |
amit.gupta |
183 |
|
|
|
184 |
List<PartnerTargetDetails> partnerTargetDetails = partnerTargetRepository
|
|
|
185 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now());
|
| 25372 |
tejbeer |
186 |
if(partnerTargetDetails.isEmpty()) {
|
|
|
187 |
partnerTargetDetails = partnerTargetRepository
|
|
|
188 |
.selectAllGeEqAndLeEqStartDateAndEndDate(LocalDateTime.now().minusMonths(1));
|
|
|
189 |
}
|
| 25214 |
amit.gupta |
190 |
|
|
|
191 |
List<Integer> targetIds = partnerTargetRepository
|
|
|
192 |
.selectAllPartnerTargetForPartner(fofoId,
|
|
|
193 |
partnerTargetDetails.stream().map(x -> x.getId()).collect(Collectors.toList()))
|
|
|
194 |
.stream().map(x -> x.getTargetId()).collect(Collectors.toList());
|
|
|
195 |
if (targetIds.size() > 0) {
|
|
|
196 |
PartnerTarget target = partnerTargetRepository.selectAllPartnerTargetForPartner(fofoId, targetIds).get(0);
|
|
|
197 |
double targetValue = (double)target.getTargetValue();
|
|
|
198 |
int remainingDays = monthLength - curDate.getDayOfMonth() + 1;
|
|
|
199 |
//Should not consider today's sale while evaluating today's target.
|
| 25221 |
amit.gupta |
200 |
double todayTargetValue = Math.round((targetValue - (mtdSale-todaySale))/remainingDays);
|
|
|
201 |
DecimalFormat df = new DecimalFormat("#.##");
|
|
|
202 |
String targetValueString = df.format(targetValue/100000) + "Lac";
|
| 25214 |
amit.gupta |
203 |
salesMap.put("todayTarget", todayTargetValue);
|
| 25223 |
amit.gupta |
204 |
salesMap.put("monthTarget", targetValueString);
|
| 25214 |
amit.gupta |
205 |
} else {
|
|
|
206 |
salesMap.put("todayTarget", 0d);
|
|
|
207 |
salesMap.put("monthTarget", 0d);
|
|
|
208 |
|
|
|
209 |
}
|
| 25140 |
amit.gupta |
210 |
salesMap.put("todaySale", todaySale);
|
|
|
211 |
salesMap.put("mtdSale", mtdSale);
|
| 25136 |
amit.gupta |
212 |
return salesMap;
|
|
|
213 |
}
|
|
|
214 |
|
| 25152 |
amit.gupta |
215 |
private List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
|
| 25140 |
amit.gupta |
216 |
Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
|
| 25175 |
amit.gupta |
217 |
|
| 25140 |
amit.gupta |
218 |
List<DBObject> mobileBrands = mongoClient.getMongoBrands(fofoId, "", 3);
|
| 25136 |
amit.gupta |
219 |
List<BrandStockPrice> brandStockPrices = new ArrayList<>();
|
| 25156 |
amit.gupta |
220 |
|
| 25140 |
amit.gupta |
221 |
mobileBrands.stream().forEach(x -> {
|
|
|
222 |
String brand = (String) x.get("name");
|
|
|
223 |
if (brandStockPricesMap.containsKey(brand)) {
|
|
|
224 |
BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
|
|
|
225 |
brandStockPrice.setBrandUrl((String) x.get("url"));
|
|
|
226 |
brandStockPrice.setRank(((Double) x.get("rank")).intValue());
|
|
|
227 |
brandStockPrices.add(brandStockPrice);
|
|
|
228 |
}
|
|
|
229 |
});
|
|
|
230 |
|
| 25175 |
amit.gupta |
231 |
return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted((x, y) -> x.getRank() - y.getRank())
|
|
|
232 |
.collect(Collectors.toList());
|
| 25136 |
amit.gupta |
233 |
}
|
|
|
234 |
|
| 21615 |
kshitij.so |
235 |
@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
|
| 25156 |
amit.gupta |
236 |
public String dashboard(HttpServletRequest request, Model model) throws Exception {
|
| 25140 |
amit.gupta |
237 |
|
| 22927 |
ashik.ali |
238 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 25180 |
amit.gupta |
239 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
240 |
model.addAttribute("isAdmin", isAdmin);
|
| 23923 |
amit.gupta |
241 |
|
| 22481 |
ashik.ali |
242 |
FofoStore fofoStore = null;
|
| 25274 |
amit.gupta |
243 |
model.addAttribute("webApiHost", webApiHost);
|
|
|
244 |
model.addAttribute("webApiPort", webApiPort);
|
|
|
245 |
model.addAttribute("webApiScheme", webApiScheme);
|
|
|
246 |
model.addAttribute("webApiRoot", webApiRoot);
|
| 25183 |
amit.gupta |
247 |
if (isAdmin) {
|
| 25180 |
amit.gupta |
248 |
return "dashboard1";
|
|
|
249 |
} else {
|
|
|
250 |
try {
|
|
|
251 |
fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());
|
|
|
252 |
model.addAttribute("fofoStore", fofoStore);
|
|
|
253 |
model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
|
|
|
254 |
model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
|
|
|
255 |
|
|
|
256 |
model.addAttribute("brandStockPrices", this.getBrandStockPrices(loginDetails.getFofoId()));
|
|
|
257 |
model.addAttribute("salesMap", this.getSales(loginDetails.getFofoId()));
|
|
|
258 |
model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
|
|
|
259 |
model.addAttribute("isInvestmentOk",
|
| 25276 |
amit.gupta |
260 |
partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(), 10, ProfitMandiConstants.CUTOFF_INVESTMENT));
|
| 25180 |
amit.gupta |
261 |
} catch (ProfitMandiBusinessException e) {
|
|
|
262 |
LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
|
|
|
263 |
|
|
|
264 |
}
|
| 22481 |
ashik.ali |
265 |
}
|
| 25197 |
amit.gupta |
266 |
model.addAttribute("monthDays", LocalDate.now().minusDays(1).lengthOfMonth());
|
|
|
267 |
model.addAttribute("dayOfMonth", LocalDate.now().minusDays(1).getDayOfMonth());
|
| 25140 |
amit.gupta |
268 |
return "dashboard1";
|
| 21615 |
kshitij.so |
269 |
}
|
| 23923 |
amit.gupta |
270 |
|
| 24288 |
amit.gupta |
271 |
// This method is currently hardcoded to faciliate watches sold as gift.
|
| 24203 |
amit.gupta |
272 |
private boolean hasGift(int fofoId) {
|
|
|
273 |
try {
|
| 24288 |
amit.gupta |
274 |
return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
|
|
|
275 |
.getAvailability() > 0;
|
| 24203 |
amit.gupta |
276 |
} catch (ProfitMandiBusinessException e) {
|
|
|
277 |
return false;
|
|
|
278 |
}
|
|
|
279 |
}
|
| 24288 |
amit.gupta |
280 |
|
| 22354 |
ashik.ali |
281 |
@RequestMapping(value = "/contactUs", method = RequestMethod.GET)
|
| 23923 |
amit.gupta |
282 |
public String contactUs(HttpServletRequest request, Model model) throws Throwable {
|
| 22354 |
ashik.ali |
283 |
model.addAttribute("appContextPath", request.getContextPath());
|
|
|
284 |
return "contact-us";
|
|
|
285 |
}
|
| 23923 |
amit.gupta |
286 |
|
| 21615 |
kshitij.so |
287 |
}
|