Rev 23944 | Rev 24077 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import java.io.IOException;import java.net.URISyntaxException;import java.util.List;import javax.servlet.http.HttpServletRequest;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Controller;import org.springframework.transaction.annotation.Transactional;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.dao.entity.fofo.FofoStore;import com.spice.profitmandi.dao.entity.transaction.Order;import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;import com.spice.profitmandi.dao.repository.fofo.PurchaseReturnItemRepository;import com.spice.profitmandi.dao.repository.transaction.OrderRepository;import com.spice.profitmandi.service.authentication.RoleManager;import com.spice.profitmandi.service.inventory.InventoryService;import com.spice.profitmandi.service.transaction.TransactionService;import com.spice.profitmandi.service.wallet.WalletService;import com.spice.profitmandi.web.model.LoginDetails;import com.spice.profitmandi.web.util.CookiesProcessor;@Controller@Transactional(rollbackFor = Throwable.class)public class DashboardController {@Value("${web.api.host}")private String webApiHost;@Value("${web.api.port}")private int webApiPort;@Autowiredprivate CookiesProcessor cookiesProcessor;@Autowiredprivate RoleManager roleManager;@Autowiredprivate FofoStoreRepository fofoStoreRepository;@Autowiredprivate WalletService walletService;@Autowiredprivate InventoryService inventoryService;@Autowiredprivate OrderRepository orderRepository;@Autowiredprivate PurchaseReturnItemRepository purchaseReturnItemRepository;/** @Autowired private ScanRepository scanRepository;*/@Autowiredprivate TransactionService transactionService;private static final Logger LOGGER = LogManager.getLogger(DashboardController.class);@RequestMapping(value = "/dashboard", method = RequestMethod.GET)public String dashboard(HttpServletRequest request, Model model)throws ProfitMandiBusinessException, URISyntaxException, IOException {// LOGGER.info("scanRepository.selectScansByInventoryItemId(1)",// scanRepository.selectScansByInventoryItemId(1));LOGGER.info("In Dashboard");LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);FofoStore fofoStore = null;try {fofoStore = fofoStoreRepository.selectByRetailerId(loginDetails.getFofoId());} catch (ProfitMandiBusinessException e) {LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());}float walletAmount = 0;float inStockAmount = 0;float unbilledStockAmount = 0;float grnPendingStockAmount = 0;float shortPercentage = 100;float totalInvestedAmount = 0;float minimumInvestment = 0;float returnedStockInTransit=0;if (roleManager.isAdmin(loginDetails.getRoleIds())) {model.addAttribute("showAlert", false);} else if (roleManager.isPartner(loginDetails.getRoleIds())) {walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());for (Order unBilledOrder : unbilledOrders) {unbilledStockAmount += unBilledOrder.getTotalAmount();}List<Order> grnPendingOrders = orderRepository.selectPendingGrnOrders(loginDetails.getFofoId());for (Order grnPendingOrder : grnPendingOrders) {grnPendingStockAmount += grnPendingOrder.getTotalAmount();}totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;shortPercentage = ((fofoStore.getMinimumInvestment() - totalInvestedAmount)/ fofoStore.getMinimumInvestment()) * 100;model.addAttribute("showAlert", shortPercentage > 10);minimumInvestment = fofoStore.getMinimumInvestment();//debitNoteRepository.se}model.addAttribute("walletAmount", walletAmount);model.addAttribute("inStockAmount", inStockAmount);model.addAttribute("unbilledStockAmount", unbilledStockAmount);model.addAttribute("grnPendingStockAmount", grnPendingStockAmount);model.addAttribute("shortPercentage", shortPercentage);model.addAttribute("totalInvestedAmount", totalInvestedAmount);model.addAttribute("minimumInvestmentAmount", minimumInvestment);model.addAttribute("returnedStockInTransit", returnedStockInTransit);model.addAttribute("fofoStore", fofoStore);model.addAttribute("walletAmount");model.addAttribute("appContextPath", request.getContextPath());model.addAttribute("isAdmin", roleManager.isAdmin(loginDetails.getRoleIds()));model.addAttribute("webApiHost", webApiHost);model.addAttribute("webApiPort", webApiPort);// LOGGER.info("loginDetails.getFofoId()"+loginDetails.getFofoId());// inventoryService.prebookingAvailabilitySendMessage(loginDetails.getFofoId());return "dashboard";}@RequestMapping(value = "/contactUs", method = RequestMethod.GET)public String contactUs(HttpServletRequest request, Model model) throws Throwable {model.addAttribute("appContextPath", request.getContextPath());return "contact-us";}/** private List<PaymentOption> getPaymentOptions(int fofoId){ List<Integer>* paymentOptionIds =* fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(fofoId);* if(paymentOptionIds.isEmpty()){ return new ArrayList<>(); } return* paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds)); }*/}