Rev 23848 | Rev 23887 | 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.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.warehouse.dao.repository.ScanRepository;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 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());}if(roleManager.isPartner(loginDetails.getRoleIds())) {float walletAmount = walletService.getUserWallet(loginDetails.getFofoId()).getAmount();float inStockAmount = inventoryService.getTotalAmountInStock(loginDetails.getFofoId());float unbilledStockAmount = 0;List<Order> unbilledOrders = transactionService.getInTransitOrders(loginDetails.getFofoId());for(Order unBilledOrder : unbilledOrders) {unbilledStockAmount += unBilledOrder.getTotalAmount();}float grnPendingStockAmount = 0;List<Order> grnPendingOrders = transactionService.getGrnPendingOrders(loginDetails.getFofoId());for(Order grnPendingOrder : grnPendingOrders) {grnPendingStockAmount += grnPendingOrder.getTotalAmount();}LOGGER.info("walletAmount is {}, inStockAmount is {}, unbilledStockAmount is {}, grnPendingStockAmount is {}",walletAmount, inStockAmount, unbilledStockAmount, grnPendingStockAmount);float totalInvestedAmount = walletAmount + inStockAmount + unbilledStockAmount + grnPendingStockAmount;LOGGER.info("Total Amount in System is {}", totalInvestedAmount);LOGGER.info("Store minimum investment is {}", fofoStore.getMinimumInvestment());LOGGER.info("Investment Currently Short by {}%", ((fofoStore.getMinimumInvestment() - totalInvestedAmount)/fofoStore.getMinimumInvestment())*100);}model.addAttribute("fofoStore", fofoStore);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));}*/}