Example #1
0
        public async Task <CommercialsGetRes> GetCommercials([FromBody] CommercialsGetReq request)
        {
            var response = new CommercialsGetRes();

            try
            {
                if (!string.IsNullOrEmpty(request.QRFID))
                {
                    response = _commercialsRepository.GetCommercials(request);
                    response.ResponseStatus.Status       = "Success";
                    response.ResponseStatus.ErrorMessage = response != null ? "" : "No Records Found.";
                }
                else
                {
                    response.ResponseStatus.Status       = "Failure";
                    response.ResponseStatus.ErrorMessage = "QRFId can not be Null/Zero.";
                }
            }
            catch (Exception ex)
            {
                response.ResponseStatus.Status       = "Failure";
                response.ResponseStatus.ErrorMessage = "An Error Occurs :- " + ex.Message;
            }

            return(response);
        }
Example #2
0
        public async Task <CommercialsGetRes> GetCommercials(CommercialsGetReq commercialsGetReq, string ticket)
        {
            CommercialsGetRes commercialsGetRes = new CommercialsGetRes();

            commercialsGetRes = await serviceProxy.PostData(_configuration.GetValue <string>("ServiceCommercials:GetCommercials"), commercialsGetReq, typeof(CommercialsGetRes), ticket);

            return(commercialsGetRes);
        }
        public IActionResult GetCommercialsData(string QRFID, string EnquiryPipeline = "", long filterByDeparture = 0, long filterByPaxSlab = 0)
        {
            CommercialsViewModel model = new CommercialsViewModel();

            model.MenuViewModel.QRFID           = QRFID;
            model.MenuViewModel.EnquiryPipeline = EnquiryPipeline;
            #region Dropdown Binding
            //NewQuoteViewModel modelQuote = new NewQuoteViewModel();
            //bool GetStatus = false;
            //SalesQuoteLibrary quoteLibrary = new SalesQuoteLibrary(_configuration);
            //if (Convert.ToInt32(QRFId) > 0)
            //{
            //    modelQuote.QRFID = QRFID;
            //    GetStatus = quoteLibrary.GetQRFPaxSlabDetails(_configuration, token, ref modelQuote);
            //}

            //SalesProviders objSalesProvider = new SalesProviders(_configuration);
            //DepartureDateGetRequest objDepartureDatesReq = new DepartureDateGetRequest() { QRF_Id = QRFId, date = (DateTime?)null };
            //DepartureDateGetResponse objDepartureDatesRes = objSalesProvider.GetDepartureDatesForQRFId(objDepartureDatesReq, token).Result;
            //model.PaxSlabList = (modelQuote.mdlQuotePaxRangeViewModel.QuotePaxSlabDetails).Select(a => new AttributeValues { AttributeValue_Id = a.PaxSlabId.ToString(), Value = a.PaxSlabFrom + "-" + a.PaxSlabTo }).ToList();
            //model.DepartureDatesList = (objDepartureDatesRes.DepartureDates).Select(a => new AttributeValues { AttributeValue_Id = a.Departure_Id.ToString(), Value = Convert.ToDateTime(a.Date).ToString("dd MMM yy") }).ToList();
            ////long defaultPaxSlabId = Convert.ToInt32(model.PaxSlabList[0].AttributeValue_Id);

            QRFDepartureDateGetReq objDepartureDatesReq = new QRFDepartureDateGetReq()
            {
                QRFID = QRFID, date = (DateTime?)null
            };
            QRFDepartureDateGetRes objDepartureDatesRes = coProviders.GetDepartureDatesForCostingByQRF_Id(objDepartureDatesReq, token).Result;
            QRFPaxSlabGetReq       objPaxSlabReq        = new QRFPaxSlabGetReq()
            {
                QRFID = QRFID
            };
            QRFPaxGetResponse objPaxSlabRes = coProviders.GetPaxSlabDetailsForCostingByQRF_Id(objPaxSlabReq, token).Result;
            model.PaxSlabList = (objPaxSlabRes.PaxSlabDetails.QRFPaxSlabs).Select(a => new AttributeValues {
                AttributeValue_Id = a.PaxSlab_Id.ToString(), Value = a.From + "-" + a.To
            }).ToList();
            model.DepartureDatesList = (objDepartureDatesRes.DepartureDates).Select(a => new AttributeValues {
                AttributeValue_Id = a.Departure_Id.ToString(), Value = Convert.ToDateTime(a.Date).ToString("dd MMM yy")
            }).ToList();

            model.CurrentDate = DateTime.Now.ToString("dd MMM yyyy");

            string username = "";
            IRequestCookieCollection objCookies = HttpContext.Request.Cookies;
            username       = HttpContext.Request.Cookies["UserName"] ?? ckUserName;
            model.UserName = username;
            #endregion

            #region Get Commercial data
            CommercialsGetRes response = new CommercialsGetRes();
            CommercialsGetReq request  = new CommercialsGetReq();
            request.QRFID       = QRFID;
            request.DepartureId = filterByDeparture == 0 ? objDepartureDatesRes.DepartureDates[0].Departure_Id : filterByDeparture;
            request.PaxSlabId   = filterByPaxSlab == 0 ? objPaxSlabRes.PaxSlabDetails.QRFPaxSlabs[0].PaxSlab_Id : filterByPaxSlab;

            response                  = coProviders.GetCommercials(request, token).Result;
            model.QRFID               = response.QRFID;
            model.QRFPriceId          = response.QRFPriceId;
            model.PercentSoldOptional = response.PercentSoldOptional;

            model.BareBoneList    = response.BareBoneList;
            model.QRFExhangeRates = response.QRFExhangeRates;

            string PositionType = "";
            foreach (var item in response.PositionIncluded)
            {
                if (item.PositionType != PositionType)
                {
                    model.PositionIncluded.Add(new mQRFPositionTotalCost
                    {
                        QRFCostForPositionID = "",
                        PositionType         = item.PositionType,
                        ProductName          = "",
                        TotalBuyPrice        = response.PositionIncluded.Where(a => a.PositionType == item.PositionType).Sum(a => a.TotalBuyPrice),
                        TotalSellPrice       = response.PositionIncluded.Where(a => a.PositionType == item.PositionType).Sum(a => a.TotalSellPrice),
                        ProfitPercentage     = response.PositionIncluded.Where(a => a.PositionType == item.PositionType && a.ProfitPercentage > 0).Count() > 0 ?
                                               (response.PositionIncluded.Where(a => a.PositionType == item.PositionType).Sum(a => a.ProfitPercentage)
                                                / response.PositionIncluded.Where(a => a.PositionType == item.PositionType && a.ProfitPercentage > 0).Count()) : 0,
                        ProfitAmount = response.PositionIncluded.Where(a => a.PositionType == item.PositionType).Sum(a => a.ProfitAmount),
                        BuyCurrency  = item.BuyCurrency,
                        QRFCurrency  = item.QRFCurrency
                    });
                }
                model.PositionIncluded.Add(new mQRFPositionTotalCost
                {
                    QRFCostForPositionID = item.QRFCostForPositionID,
                    PositionType         = item.PositionType,
                    PositionId           = item.PositionId,
                    ProductName          = item.ProductName,
                    TotalBuyPrice        = item.TotalBuyPrice,
                    TotalSellPrice       = item.TotalSellPrice,
                    ProfitAmount         = item.ProfitAmount,
                    ProfitPercentage     = item.ProfitPercentage,
                    BuyCurrency          = item.BuyCurrency,
                    QRFCurrency          = item.QRFCurrency
                });
                PositionType = item.PositionType;
            }

            foreach (var item in response.PositionSupplement)
            {
                model.PositionSupplement.Add(new mQRFPositionTotalCost
                {
                    QRFCostForPositionID = item.QRFCostForPositionID,
                    PositionType         = item.PositionType,
                    PositionId           = item.PositionId,
                    ProductName          = item.ProductName,
                    TotalBuyPrice        = item.TotalBuyPrice,
                    TotalSellPrice       = item.TotalSellPrice,
                    ProfitAmount         = item.ProfitAmount,
                    ProfitPercentage     = item.ProfitPercentage,
                    BuyCurrency          = item.BuyCurrency,
                    QRFCurrency          = item.QRFCurrency
                });
            }

            foreach (var item in response.PositionOptional)
            {
                model.PositionOptional.Add(new mQRFPositionTotalCost
                {
                    QRFCostForPositionID = item.QRFCostForPositionID,
                    PositionType         = item.PositionType,
                    PositionId           = item.PositionId,
                    ProductName          = item.ProductName,
                    TotalBuyPrice        = item.TotalBuyPrice,
                    TotalSellPrice       = item.TotalSellPrice,
                    ProfitAmount         = item.ProfitAmount,
                    ProfitPercentage     = item.ProfitPercentage,
                    BuyCurrency          = item.BuyCurrency,
                    QRFCurrency          = item.QRFCurrency
                });
            }

            model.DepartureDate = filterByDeparture;
            model.PaxSlab       = filterByPaxSlab;

            #endregion

            if (model.PositionSupplement.Count > 0)
            {
                ViewBag.QRFCurrency = model.PositionSupplement[0].QRFCurrency;
            }
            if (model.PositionOptional.Count > 0)
            {
                ViewBag.QRFCurrency = model.PositionOptional[0].QRFCurrency;
            }
            if (model.PositionIncluded.Count > 0)
            {
                ViewBag.QRFCurrency = model.PositionIncluded[0].QRFCurrency;
            }

            ViewBag.IsAllowToAppRej = false;
            if (model.MenuViewModel.EnquiryPipeline == "Costing Approval Pipeline")
            {
                if (UserRoles.Contains("Product Accountant"))
                {
                    ViewBag.IsAllowToAppRej = true;
                }
            }

            return(PartialView("_Commercials", model));
        }
        public CommercialsGetRes GetCommercials(CommercialsGetReq request)
        {
            CommercialsGetRes response = new CommercialsGetRes();

            var QRFPrice = _MongoContext.mQRFPrice.AsQueryable().Where(a => a.QRFID == request.QRFID && a.IsCurrentVersion).OrderByDescending(b => b.VersionId).FirstOrDefault();

            response.QRFID               = QRFPrice.QRFID;
            response.QRFPriceId          = QRFPrice.QRFPrice_Id;
            response.PercentSoldOptional = QRFPrice.PercentSoldOptional;

            var PositionsList = _MongoContext.mQRFPositionTotalCost.AsQueryable().Where(a => a.QRFPrice_Id == QRFPrice.QRFPrice_Id && a.Departure_Id == request.DepartureId && a.PaxSlab_Id == request.PaxSlabId).ToList();

            _genericRepository.getExchangeRateForPosition(ref PositionsList);

            #region Bare Bone data
            double vCostPrice         = 0;
            double vSellPrice         = 0;
            double vProfit            = 0;
            double vProfitPercent     = 0;
            string vCostPriceCurrency = "";
            string vSellPriceCurrency = "";

            var PositionForHotel = PositionsList.Where(a => a.PositionType.ToLower() == "hotel" || a.PositionType.ToLower() == "overnight ferry").ToList();
            vCostPrice         = PositionForHotel.Sum(a => a.TotalBuyPrice);
            vSellPrice         = PositionForHotel.Sum(a => a.TotalSellPrice);
            vProfit            = PositionForHotel.Sum(a => a.ProfitAmount);
            vProfitPercent     = PositionForHotel.Sum(a => a.ProfitPercentage) / PositionForHotel.Count;
            vCostPriceCurrency = PositionForHotel.Count > 0 ? PositionForHotel[0].BuyCurrency : null;
            vSellPriceCurrency = PositionForHotel.Count > 0 ? PositionForHotel[0].QRFCurrency : null;

            response.BareBoneList.Add(new CommercialsData
            {
                ProductType   = "Hotel",
                CostPrice     = vCostPrice,
                SellPrice     = vSellPrice,
                ProfitLoss    = vProfit,
                ProfitPercent = vProfitPercent,
                BuyCurrency   = vCostPriceCurrency,
                SellCurrency  = vSellPriceCurrency
            });

            var PositionForTransportation = PositionsList.Where(a => a.PositionType.ToLower() == "ldc" || a.PositionType.ToLower() == "coach" || a.PositionType.ToLower() == "private transfer" ||
                                                                a.PositionType.ToLower() == "scheduled transfer" || a.PositionType.ToLower() == "ferry passenger" || a.PositionType.ToLower() == "ferry transfer" || a.PositionType.ToLower() == "train").ToList();
            vCostPrice         = PositionForTransportation.Sum(a => a.TotalBuyPrice);
            vSellPrice         = PositionForTransportation.Sum(a => a.TotalSellPrice);
            vProfit            = PositionForTransportation.Sum(a => a.ProfitAmount);
            vProfitPercent     = PositionForTransportation.Sum(a => a.ProfitPercentage) / PositionForTransportation.Count;
            vCostPriceCurrency = PositionForTransportation.Count > 0 ? PositionForTransportation[0].BuyCurrency : null;
            vSellPriceCurrency = PositionForTransportation.Count > 0 ? PositionForTransportation[0].QRFCurrency : null;

            response.BareBoneList.Add(new CommercialsData
            {
                ProductType   = "Transportation",
                CostPrice     = vCostPrice,
                SellPrice     = vSellPrice,
                ProfitLoss    = vProfit,
                ProfitPercent = vProfitPercent,
                BuyCurrency   = vCostPriceCurrency,
                SellCurrency  = vSellPriceCurrency
            });

            var PositionForActivities = PositionsList.Where(a => a.PositionType.ToLower() == "attractions" || a.PositionType.ToLower() == "sightseeing - citytour").ToList();
            vCostPrice         = PositionForActivities.Sum(a => a.TotalBuyPrice);
            vSellPrice         = PositionForActivities.Sum(a => a.TotalSellPrice);
            vProfit            = PositionForActivities.Sum(a => a.ProfitAmount);
            vProfitPercent     = PositionForActivities.Sum(a => a.ProfitPercentage) / PositionForActivities.Count;
            vCostPriceCurrency = PositionForActivities.Count > 0 ? PositionForActivities[0].BuyCurrency : null;
            vSellPriceCurrency = PositionForActivities.Count > 0 ? PositionForActivities[0].QRFCurrency : null;

            response.BareBoneList.Add(new CommercialsData
            {
                ProductType   = "Activities",
                CostPrice     = vCostPrice,
                SellPrice     = vSellPrice,
                ProfitLoss    = vProfit,
                ProfitPercent = vProfitPercent,
                BuyCurrency   = vCostPriceCurrency,
                SellCurrency  = vSellPriceCurrency
            });

            var PositionForMeal = PositionsList.Where(a => a.PositionType.ToLower() == "meal").ToList();
            vCostPrice         = PositionForMeal.Sum(a => a.TotalBuyPrice);
            vSellPrice         = PositionForMeal.Sum(a => a.TotalSellPrice);
            vProfit            = PositionForMeal.Sum(a => a.ProfitAmount);
            vProfitPercent     = PositionForMeal.Sum(a => a.ProfitPercentage) / PositionForMeal.Count;
            vCostPriceCurrency = PositionForMeal.Count > 0 ? PositionForMeal[0].BuyCurrency : null;
            vSellPriceCurrency = PositionForMeal.Count > 0 ? PositionForMeal[0].QRFCurrency : null;

            response.BareBoneList.Add(new CommercialsData
            {
                ProductType   = "Meals",
                CostPrice     = vCostPrice,
                SellPrice     = vSellPrice,
                ProfitLoss    = vProfit,
                ProfitPercent = vProfitPercent,
                BuyCurrency   = vCostPriceCurrency,
                SellCurrency  = vSellPriceCurrency
            });

            var PositionForOthers = PositionsList.Where(a => !(a.PositionType.ToLower() == "ldc" || a.PositionType.ToLower() == "coach" || a.PositionType.ToLower() == "private transfer" ||
                                                               a.PositionType.ToLower() == "scheduled transfer" || a.PositionType.ToLower() == "ferry passenger" || a.PositionType.ToLower() == "ferry transfer" || a.PositionType.ToLower() == "train" ||
                                                               a.PositionType.ToLower() == "hotel" || a.PositionType.ToLower() == "overnight ferry" || a.PositionType.ToLower() == "attractions" || a.PositionType.ToLower() == "sightseeing - citytour" || a.PositionType.ToLower() == "meal")).ToList();
            vCostPrice         = PositionForOthers.Sum(a => a.TotalBuyPrice);
            vSellPrice         = PositionForOthers.Sum(a => a.TotalSellPrice);
            vProfit            = PositionForOthers.Sum(a => a.ProfitAmount);
            vProfitPercent     = PositionForOthers.Sum(a => a.ProfitPercentage) / PositionForOthers.Count;
            vCostPriceCurrency = PositionForOthers.Count > 0 ? PositionForOthers[0].BuyCurrency : null;
            vSellPriceCurrency = PositionForOthers.Count > 0 ? PositionForOthers[0].QRFCurrency : null;

            response.BareBoneList.Add(new CommercialsData
            {
                ProductType   = "Others",
                CostPrice     = vCostPrice,
                SellPrice     = vSellPrice,
                ProfitLoss    = vProfit,
                ProfitPercent = vProfitPercent,
                BuyCurrency   = vCostPriceCurrency,
                SellCurrency  = vSellPriceCurrency
            });
            #endregion

            response.PositionIncluded   = PositionsList.Where(a => a.PositionKeepAs.ToUpper() == "INCLUDED").OrderBy(b => b.PositionType).ThenBy(c => c.ProductName).ToList();
            response.PositionSupplement = PositionsList.Where(a => a.PositionKeepAs.ToUpper() == "SUPPLEMENT").OrderBy(b => b.ProductName).ToList();
            response.PositionOptional   = PositionsList.Where(a => a.PositionKeepAs.ToUpper() == "OPTIONAL").OrderBy(b => b.ProductName).ToList();

            response.QRFExhangeRates = _MongoContext.mQRFPrice.AsQueryable().Where(a => a.QRFPrice_Id == QRFPrice.QRFPrice_Id).Select(b => b.QRFExchangeRates).FirstOrDefault();

            return(response);
        }