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