Subversion Repositories SmartDukaan

Rev

Rev 24288 | Rev 24315 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24288 Rev 24312
Line 5... Line 5...
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;
9
import java.time.temporal.WeekFields;
10
import java.util.Collection;
10
import java.util.ArrayList;
11
import java.util.List;
11
import java.util.List;
12
import java.util.stream.Collectors;
-
 
13
 
12
 
14
import javax.servlet.http.HttpServletRequest;
13
import javax.servlet.http.HttpServletRequest;
15
 
14
 
16
import org.apache.commons.lang3.StringUtils;
-
 
17
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.Logger;
16
import org.apache.logging.log4j.Logger;
19
import org.apache.solr.common.util.Utils;
-
 
20
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Autowired;
21
import org.springframework.beans.factory.annotation.Value;
18
import org.springframework.beans.factory.annotation.Value;
22
import org.springframework.stereotype.Controller;
19
import org.springframework.stereotype.Controller;
23
import org.springframework.transaction.annotation.Transactional;
20
import org.springframework.transaction.annotation.Transactional;
24
import org.springframework.ui.Model;
21
import org.springframework.ui.Model;
Line 26... Line 23...
26
import org.springframework.web.bind.annotation.RequestMethod;
23
import org.springframework.web.bind.annotation.RequestMethod;
27
import org.springframework.web.bind.annotation.RequestParam;
24
import org.springframework.web.bind.annotation.RequestParam;
28
 
25
 
29
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
26
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
30
import com.spice.profitmandi.common.model.ProfitMandiConstants;
27
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
28
import com.spice.profitmandi.common.util.FormattingUtils;
31
import com.spice.profitmandi.dao.entity.dtr.NotificationData;
29
import com.spice.profitmandi.dao.entity.dtr.NotificationData;
32
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
30
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
33
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
31
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
34
import com.spice.profitmandi.dao.entity.transaction.Order;
32
import com.spice.profitmandi.dao.entity.transaction.Order;
35
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
33
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
Line 45... Line 43...
45
import com.spice.profitmandi.service.wallet.WalletService;
43
import com.spice.profitmandi.service.wallet.WalletService;
46
import com.spice.profitmandi.web.model.LoginDetails;
44
import com.spice.profitmandi.web.model.LoginDetails;
47
import com.spice.profitmandi.web.util.CookiesProcessor;
45
import com.spice.profitmandi.web.util.CookiesProcessor;
48
import com.spice.profitmandi.web.util.MVCResponseSender;
46
import com.spice.profitmandi.web.util.MVCResponseSender;
49
 
47
 
-
 
48
import be.ceau.chart.BarChart;
-
 
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
 
50
@Controller
58
@Controller
51
@Transactional(rollbackFor = Throwable.class)
59
@Transactional(rollbackFor = Throwable.class)
52
public class DashboardController {
60
public class DashboardController {
53
 
61
 
54
	@Value("${web.api.host}")
62
	@Value("${web.api.host}")
Line 107... Line 115...
107
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
115
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
108
 
116
 
109
	private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
117
	private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);
110
 
118
 
111
	@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
119
	@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
112
	public String dashboard(HttpServletRequest request,@RequestParam(name = "offset", defaultValue = "0") int offset,
120
	public String dashboard(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
113
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
121
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
114
			throws ProfitMandiBusinessException, URISyntaxException, IOException {
122
			throws ProfitMandiBusinessException, URISyntaxException, IOException {
115
		// LOGGER.info("scanRepository.selectScansByInventoryItemId(1)",
123
		// LOGGER.info("scanRepository.selectScansByInventoryItemId(1)",
116
		// scanRepository.selectScansByInventoryItemId(1));
124
		// scanRepository.selectScansByInventoryItemId(1));
117
		LOGGER.info("In Dashboard");
125
		LOGGER.info("In Dashboard");
Line 129... Line 137...
129
		float unbilledStockAmount = 0;
137
		float unbilledStockAmount = 0;
130
		float grnPendingStockAmount = 0;
138
		float grnPendingStockAmount = 0;
131
		float shortPercentage = 100;
139
		float shortPercentage = 100;
132
		float totalInvestedAmount = 0;
140
		float totalInvestedAmount = 0;
133
		float minimumInvestment = 0;
141
		float minimumInvestment = 0;
134
		float returnedStockInTransit=0;
142
		float returnedStockInTransit = 0;
135
		float sale=0;
143
		float sale = 0;
136
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
144
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
137
			model.addAttribute("showAlert", false);
145
			model.addAttribute("showAlert", false);
138
			model.addAttribute("sale", sale);
146
			model.addAttribute("sale", sale);
139
			List<NotificationData> notificationData = null;
147
			List<NotificationData> notificationData = null;
140
			long size = 0;
148
			long size = 0;
Line 174... Line 182...
174
 
182
 
175
			}
183
			}
176
		} else if (roleManager.isPartner(loginDetails.getRoleIds())) {
184
		} else if (roleManager.isPartner(loginDetails.getRoleIds())) {
177
			walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
185
			walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();
178
			inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
186
			inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());
179
			
187
 
180
			List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
188
			List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());
181
			for (Order unBilledOrder : unbilledOrders) {
189
			for (Order unBilledOrder : unbilledOrders) {
182
				unbilledStockAmount += unBilledOrder.getTotalAmount();
190
				unbilledStockAmount += unBilledOrder.getTotalAmount();
183
			}
191
			}
184
 
192
 
Line 231... Line 239...
231
 
239
 
232
			}
240
			}
233
		}
241
		}
234
		LocalDate endDate = LocalDate.now().minusDays(1);
242
		LocalDate endDate = LocalDate.now().minusDays(1);
235
		LocalDate weekStartDate = endDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
243
		LocalDate weekStartDate = endDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
236
		LocalDate startDate = weekStartDate.minusWeeks(3);
244
		LocalDate startDate = weekStartDate.minusWeeks(5);
237
		List<PartnerDailyInvestment> dailyInvestments = partnerDailyInvestmentRepository.selectAll(loginDetails.getFofoId(), startDate, endDate);
245
		List<PartnerDailyInvestment> partnerInvestments = partnerDailyInvestmentRepository
238
		Collection<Integer> investmentMaintained = dailyInvestments.stream().collect(Collectors.groupingBy(
-
 
239
				x->x.getDate().get(WeekFields.ISO.weekOfYear()), 
-
 
240
				Collectors.summingInt(x1-> {return x1.isComplete()?1:0;})
246
				.selectAll(loginDetails.getFofoId(), startDate, endDate);
241
		)).values();
-
 
242
		
247
 
243
		model.addAttribute("investmentMaintained", Utils.toJSONString(investmentMaintained));
248
		model.addAttribute("investmentChart", this.getInvestmentChartData(partnerInvestments));
244
		model.addAttribute("sale", sale);
249
		model.addAttribute("sale", sale);
245
		model.addAttribute("walletAmount", walletAmount);
250
		model.addAttribute("walletAmount", walletAmount);
246
		model.addAttribute("inStockAmount", inStockAmount);
251
		model.addAttribute("inStockAmount", inStockAmount);
247
		model.addAttribute("unbilledStockAmount", unbilledStockAmount);
252
		model.addAttribute("unbilledStockAmount", unbilledStockAmount);
248
		model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
253
		model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);
Line 266... Line 271...
266
		// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
271
		// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());
267
		// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
272
		// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());
268
		return "dashboard";
273
		return "dashboard";
269
	}
274
	}
270
 
275
 
-
 
276
	private String getInvestmentChartData(List<PartnerDailyInvestment> partnerInvestments) {
-
 
277
 
-
 
278
		List<List<Integer>> walletStackList = new ArrayList<>();
-
 
279
		List<List<Integer>> inStockStackList = new ArrayList<>();
-
 
280
		List<List<Integer>> salesStackList = new ArrayList<>();
-
 
281
		List<List<Integer>> grnPendingStackList = new ArrayList<>();
-
 
282
		List<List<Integer>> billingPendingStackList = new ArrayList<>();
-
 
283
		List<List<Integer>> inTransitStackList = new ArrayList<>();
-
 
284
		List<List<LocalDate>> datesList = new ArrayList<>();
-
 
285
 
-
 
286
		int currentWeekOfYear = 0;
-
 
287
		for (PartnerDailyInvestment pdi : partnerInvestments) {
-
 
288
			List<Integer> walletStack = null;
-
 
289
			List<Integer> inStockStack = null;
-
 
290
			List<Integer> salesStack = null;
-
 
291
			List<Integer> grnPendingStack = null;
-
 
292
			List<Integer> billingPendingStack = null;
-
 
293
			List<Integer> inTransitStack = null;
-
 
294
			List<LocalDate> dates = null;
-
 
295
			int weekOfYear = pdi.getDate().get(WeekFields.ISO.weekOfYear());
-
 
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());
-
 
313
			inStockStack.add((int)pdi.getInStockAmount());
-
 
314
			salesStack.add((int)pdi.getSalesAmount());
-
 
315
			grnPendingStack.add((int)pdi.getGrnPendingAmount());
-
 
316
			billingPendingStack.add((int)pdi.getUnbilledAmount());
-
 
317
			inTransitStack.add((int)pdi.getReturnInTransitAmount());
-
 
318
			datesList.add(dates);
-
 
319
			
-
 
320
		}
-
 
321
		
-
 
322
		int counter = 0;
-
 
323
		BarData barData = new BarData();
-
 
324
		while(counter < walletStackList.size()) {
-
 
325
			barData
-
 
326
			.addDataset(new BarDataset().setData(walletStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("Wallet"))
-
 
327
			.addDataset(new BarDataset().setData(inStockStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("In Stock"))
-
 
328
			.addDataset(new BarDataset().setData(salesStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("Sales"))
-
 
329
			.addDataset(new BarDataset().setData(grnPendingStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("Grn Pending"))
-
 
330
			.addDataset(new BarDataset().setData(billingPendingStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("Billing Pending"))
-
 
331
			.addDataset(new BarDataset().setData(inTransitStackList.get(counter).stream().mapToInt(i -> i).toArray()).setLabel("In Transit"));
-
 
332
			counter++;
-
 
333
		}
-
 
334
		BarOptions barOptions = new BarOptions()
-
 
335
				.setTitle(new Title().setText("Daily Investment Summary"))
-
 
336
				.setScales(new BarScale().addxAxes(new XAxis<LinearTicks>().setStacked(true))
-
 
337
										 .addyAxes(new YAxis<LinearTicks>().setStacked(true))
-
 
338
										 );
-
 
339
						
-
 
340
		BarChart barChart = new BarChart(barData, barOptions);
-
 
341
		return barChart.toJson();
-
 
342
	}
-
 
343
 
271
	// This method is currently hardcoded to faciliate watches sold as gift.
344
	// This method is currently hardcoded to faciliate watches sold as gift.
272
	private boolean hasGift(int fofoId) {
345
	private boolean hasGift(int fofoId) {
273
		try {
346
		try {
274
			return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
347
			return currentInventorySnapshotRepository.selectByItemIdAndFofoId(ProfitMandiConstants.GIFT_ID, fofoId)
275
					.getAvailability() > 0;
348
					.getAvailability() > 0;