Пример #1
0
        internal static ConcessionLetterVm GetDeliveryNoteInfo(int hbId, string langCode)
        {
            ConcessionLetterVm concLetterVm = new ConcessionLetterVm();
            OperationsEntities db           = new OperationsEntities();
            var hbView = db.HouseBillViews.Where(x => x.HouseBillId == hbId).Select(x => new
            {
                x.CarrierNameEn,
                x.FromPort,
                x.MBL,
                x.GrossWeight,
                x.CBM,
                x.ConsigneeNameEn,
                x.ToPort,
                x.CarrierType,
                x.NumberOfPackages,
                x.OperationId,
                x.VesselName,
                x.ArriveDate,
                x.HouseBL,
                x.GoodsDescription
            }).FirstOrDefault();

            int operId = hbView.OperationId;

            concLetterVm.CarrierName      = hbView.CarrierNameEn;
            concLetterVm.FromPort         = hbView.FromPort;
            concLetterVm.MBL              = hbView.MBL;
            concLetterVm.GrossWeight      = hbView.GrossWeight.Value;
            concLetterVm.CBM              = hbView.CBM.Value;
            concLetterVm.ConsigneeName    = hbView.ConsigneeNameEn;
            concLetterVm.Containers       = OperationHelper.GetContainersSummary(operId);
            concLetterVm.NumberOfPackages = hbView.NumberOfPackages.Value;
            concLetterVm.ToPort           = hbView.ToPort;
            concLetterVm.VesselName       = hbView.VesselName;
            concLetterVm.ArriveDate       = hbView.ArriveDate;
            concLetterVm.HouseBL          = hbView.HouseBL;
            concLetterVm.GoodsDescription = hbView.GoodsDescription;

            var containerList = db.OperationContainers.Where(x => x.OperationId == operId).Select(x => x.ContainerNumber).ToArray();

            concLetterVm.ContainerNumber = string.Join(" - ", containerList);

            concLetterVm.StaticLabels = CommonHelper.GetStaticLabels((int)StaticTextForScreenEnum.DeliveryNote, langCode);

            return(concLetterVm);
        }
Пример #2
0
        public static TruckingOrderDetailVm GetTruckingOrderDetailInfo(int truckingOrderId)
        {
            TruckingOrderDetailVm trkoVmObj = new TruckingOrderDetailVm(truckingOrderId);
            EasyFreightEntities   db        = new EasyFreightEntities();

            int truckDetailCount = db.TruckingOrderDetails.Where(x => x.TruckingOrderId == truckingOrderId).Count();

            OperationsEntities db1 = new OperationsEntities();
            var truckViewObj       = db1.TruckingOrdersViews.Where(x => x.TruckingOrderId == truckingOrderId).FirstOrDefault();

            Mapper.CreateMap <TruckingOrdersView, TruckingOrderDetailVm>().IgnoreAllNonExisting();

            Mapper.Map(truckViewObj, trkoVmObj);

            trkoVmObj.ClientName        = truckViewObj.OrderFrom == 1 ? truckViewObj.ShipperNameEn : truckViewObj.ConsigneeNameEn;
            trkoVmObj.ContainersSummary = OperationHelper.GetContainersSummary(trkoVmObj.OperationId);

            List <TruckingOrderCost> truckCostList = db.TruckingOrderCosts.Where(x => x.TruckingOrderId == truckingOrderId).ToList();
            TruckingCostVm           truckingCostObj;

            if (truckCostList.Count() == 0)
            {
                truckingCostObj = new TruckingCostVm(trkoVmObj.TruckingOrderId);
                trkoVmObj.TruckingOrderCosts.Add(truckingCostObj);
            }
            else
            {
                Mapper.CreateMap <TruckingOrderCost, TruckingCostVm>().IgnoreAllNonExisting();
                trkoVmObj.TotalCostNet     = Math.Round(truckCostList.Sum(x => x.TruckingCostNet), 2);
                trkoVmObj.TotalCostSelling = Math.Round(truckCostList.Sum(x => x.TruckingCostSelling), 2);
                foreach (var cost in truckCostList)
                {
                    truckingCostObj = new TruckingCostVm();
                    Mapper.Map(cost, truckingCostObj);
                    truckingCostObj.TruckingCostSelling = Math.Round(truckingCostObj.TruckingCostSelling.Value, 2);
                    truckingCostObj.TruckingCostNet     = Math.Round(truckingCostObj.TruckingCostNet.Value, 2);
                    truckingCostObj.TruckingCostName    = cost.TruckingCostLib.TruckingCostName;
                    truckingCostObj.CurrencySign        = cost.Currency.CurrencySign;

                    trkoVmObj.TruckingOrderCosts.Add(truckingCostObj);
                }
            }

            List <OperationContainerVm> operationContainerList = OperationHelper.GetOperationContainers(trkoVmObj.OperationId);

            if (operationContainerList.Count() > 0)
            {
                //kamal
                int truckHouseId = db.TruckingOrders.Where(x => x.TruckingOrderId == truckingOrderId).Select(a => a.HouseBillId.Value).FirstOrDefault();
                List <HouseContainerVm> hcVmList = HouseBillHelper.GetHousContainerByHouseID(truckHouseId);
                if (hcVmList.Count > 0)
                {
                    foreach (var opcont in operationContainerList)
                    {
                        foreach (var item in hcVmList)
                        {
                            if (item.OperConId == opcont.OperConId)
                            {
                                trkoVmObj.OperationContainers.Add(opcont);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var opcont in operationContainerList)
                    {
                        trkoVmObj.OperationContainers.Add(opcont);
                    }
                }
            }

            trkoVmObj.HbDate = db1.HouseBills
                               .Where(x => x.HouseBillId == truckViewObj.HouseBillId).FirstOrDefault().OperationDate.Value;

            //Get code generated if first insert
            if (truckDetailCount == 0)
            {
                trkoVmObj.TruckingOrderCode = AdminHelper.GeneratePrefixCode(PrefixForEnum.TruckingOrder, false);
            }

            return(trkoVmObj);
        }
Пример #3
0
        /// <summary>
        /// Get complete operation cost .. if has many HB .. will get the sum foreach on
        /// The will contains operation, trucking, custom clearance cost
        /// </summary>
        /// <param name="operationId">operation Id</param>
        /// <returns>OperationCostAccMainVm</returns>
        public static OperationCostAccMainVm GetOperationCost(int operationId, int hbId = 0, string langCode = "en")
        {
            OperationCostAccMainVm operCostMainVm;
            OperationsEntities     db = new OperationsEntities();

            if (hbId == 0)
            {
                operCostMainVm = db.OperationViews
                                 .Where(x => x.OperationId == operationId)
                                 .Select(x => new OperationCostAccMainVm
                {
                    BookingNumber = x.BookingNumber,
                    CarrierName   = x.CarrierNameEn,
                    FromPort      = x.FromPort,
                    ConsigneeName = x.ConsigneeNameEn,
                    MBL           = x.MBL,
                    OperationCode = x.OperationCode,
                    OperationId   = x.OperationId,
                    ShipperName   = x.ShipperNameEn,
                    ToPort        = x.ToPort,
                    VesselName    = x.VesselName,
                    AgentName     = x.AgentNameEn,
                    OrderFrom     = x.OrderFrom == 1 ? "Export" : "Import"
                }).FirstOrDefault();

                var hbList = db.HouseBills.Where(x => x.OperationId == operationId).Select(x => x.HouseBL).ToArray();
                operCostMainVm.HouseBL = string.Join(" , ", hbList);
            }
            else
            {
                operCostMainVm = db.HouseBillViews
                                 .Where(x => x.HouseBillId == hbId)
                                 .Select(x => new OperationCostAccMainVm
                {
                    BookingNumber = x.BookingNumber,
                    CarrierName   = x.CarrierNameEn,
                    FromPort      = x.FromPort,
                    ConsigneeName = x.CarrierNameEn,
                    MBL           = x.MBL,
                    OperationCode = x.OperationCode,
                    OperationId   = x.OperationId,
                    ShipperName   = x.ShipperNameEn,
                    ToPort        = x.ToPort,
                    VesselName    = x.VesselName,
                    AgentName     = x.AgentNameEn,
                    OrderFrom     = x.OrderFrom == 1 ? "Export" : "Import",
                    HouseBL       = x.HouseBL
                }).FirstOrDefault();
            }


            operCostMainVm.ContainerSummary = OperationHelper.GetContainersSummary(operCostMainVm.OperationId);

            dynamic operCostList;

            //Get operationcost
            if (hbId == 0)
            {
                operCostList = db.OperationCosts.Include("OperationCostLib").Include("Currency")
                               .Where(x => x.OperationId == operationId)
                               .GroupBy(g => new
                {
                    g.OperationCostLib.OperCostNameEn,
                    g.Currency.CurrencySign,
                    g.IsAgentCost,
                    g.CurrencyId,
                    g.OperCostLibId,
                    g.CurrencyIdSelling,
                    g.HouseBillId,
                    sellingCurrSign = g.Currency1.CurrencySign
                })
                               .Select(g => new
                {
                    OperCostNameEn       = g.Key.OperCostNameEn,
                    OperationCostNet     = g.Sum(x => x.OperationCostNet),
                    OperationCostSelling = g.Sum(x => x.OperationCostSelling),
                    CurrencySign         = g.Key.CurrencySign,
                    IsAgentCost          = g.Key.IsAgentCost,
                    CurrencyId           = g.Key.CurrencyId,
                    OperCostId           = g.Key.OperCostLibId,
                    CurrencyIdSelling    = g.Key.CurrencyIdSelling,
                    HouseBillId          = g.Key.HouseBillId,
                    CurrencySignSelling  = g.Key.sellingCurrSign
                })
                               .ToList();
            }
            else
            {
                //Will not get agent cost .. check with operation
                operCostList = db.OperationCosts.Include("OperationCostLibs")
                               .Include("Currency")
                               .Include("Currency1")
                               .Where(x => x.HouseBillId == hbId && x.IsAgentCost == false)
                               .Select(g => new
                {
                    OperCostNameEn       = g.OperationCostLib.OperCostNameEn,
                    OperationCostNet     = g.OperationCostNet,
                    OperationCostSelling = g.OperationCostSelling,
                    CurrencySign         = g.Currency.CurrencySign,
                    IsAgentCost          = g.IsAgentCost,
                    CurrencyId           = g.CurrencyId,
                    OperCostId           = g.OperCostId,
                    CurrencyIdSelling    = g.CurrencyIdSelling,
                    CurrencySignSelling  = g.Currency1.CurrencySign,
                    HouseBillId          = g.HouseBillId
                })
                               .ToList();
            }

            OperationCostAccVm operCostAccVm;
            int i = 1;

            foreach (var item in operCostList)
            {
                operCostAccVm                     = new OperationCostAccVm();
                operCostAccVm.Id                  = i;
                operCostAccVm.CostName            = item.OperCostNameEn;
                operCostAccVm.CurrencySign        = item.CurrencySign;
                operCostAccVm.IsAgent             = item.IsAgentCost;
                operCostAccVm.NetRate             = Math.Round(item.OperationCostNet, 2);
                operCostAccVm.SellingRate         = Math.Round(item.OperationCostSelling, 2);
                operCostAccVm.CurrencyId          = item.CurrencyId;
                operCostAccVm.FkType              = Convert.ToByte(CostType.OperationCost);
                operCostAccVm.CostFkId            = item.OperCostId;
                operCostAccVm.CurrencyIdSelling   = item.CurrencyIdSelling;
                operCostAccVm.CurrencySignSelling = item.CurrencySignSelling;
                operCostAccVm.HouseBillId         = item.HouseBillId;

                i = i + 1;
                operCostMainVm.OperationCostAccVms.Add(operCostAccVm);
            }

            //Get trucking cost
            dynamic truckingCost;

            if (hbId == 0)
            {
                EasyFreightEntities db1 = new EasyFreightEntities();
                truckingCost = db1.TruckingOrderCosts.Include("TruckingCostLibs").Include("Currency")
                               .Where(x => x.TruckingOrderDetail.TruckingOrder.OperationId == operationId)
                               .GroupBy(g => new { g.TruckingCostLib.TruckingCostName, g.Currency.CurrencySign, g.CurrencyId, g.TruckingCostId })
                               .Select(g => new
                {
                    NetRate             = g.Sum(x => x.TruckingCostNet),
                    SellingRate         = g.Sum(x => x.TruckingCostSelling),
                    CostName            = g.Key.TruckingCostName,
                    CurrencySign        = g.Key.CurrencySign,
                    CurrencyId          = g.Key.CurrencyId,
                    TruckingOrderCostId = g.Key.TruckingCostId
                }).ToList();
            }
            else
            {
                EasyFreightEntities db1 = new EasyFreightEntities();
                truckingCost = db1.TruckingOrderCosts.Include("TruckingCostLibs").Include("Currency")
                               .Where(x => x.TruckingOrderDetail.TruckingOrder.HouseBillId == hbId)
                               .Select(g => new
                {
                    NetRate             = g.TruckingCostNet,
                    SellingRate         = g.TruckingCostSelling,
                    CostName            = g.TruckingCostLib.TruckingCostName,
                    CurrencySign        = g.Currency.CurrencySign,
                    CurrencyId          = g.CurrencyId,
                    TruckingOrderCostId = g.TruckingOrderCostId
                }).ToList();
            }


            foreach (var item in truckingCost)
            {
                operCostAccVm                     = new OperationCostAccVm();
                operCostAccVm.Id                  = i;
                operCostAccVm.CostName            = item.CostName;
                operCostAccVm.CurrencySign        = item.CurrencySign;
                operCostAccVm.NetRate             = Math.Round(item.NetRate, 2);
                operCostAccVm.SellingRate         = Math.Round(item.SellingRate, 2);
                operCostAccVm.CurrencyId          = item.CurrencyId;
                operCostAccVm.FkType              = Convert.ToByte(CostType.TruckingCost);
                operCostAccVm.CostFkId            = item.TruckingOrderCostId;
                operCostAccVm.CurrencyIdSelling   = item.CurrencyId;
                operCostAccVm.CurrencySignSelling = item.CurrencySign;
                i = i + 1;
                operCostMainVm.OperationCostAccVms.Add(operCostAccVm);
            }

            //Get CC cost
            dynamic ccCost;

            if (hbId == 0)
            {
                ccCost = db.CustomClearanceDetails.Include("CustomClearanceCostLibs").Include("Currency")
                         .Where(x => x.CustomClearanceOrder.OperationId == operationId)
                         .GroupBy(g => new { g.CustomClearanceCostLib.CostNameEn, g.Currency.CurrencySign, g.CurrencyId, g.CCCostId })
                         .Select(g => new
                {
                    NetRate      = g.Sum(x => x.CCCostNet),
                    SellingRate  = g.Sum(x => x.CCCostSelling),
                    CostName     = g.Key.CostNameEn,
                    CurrencySign = g.Key.CurrencySign,
                    CurrencyId   = g.Key.CurrencyId,
                    CCDetailsId  = g.Key.CCCostId
                });
            }
            else
            {
                ccCost = db.CustomClearanceDetails.Include("CustomClearanceCostLibs").Include("Currency")
                         .Where(x => x.CustomClearanceOrder.HouseBillId == hbId)
                         .Select(g => new
                {
                    NetRate      = g.CCCostNet,
                    SellingRate  = g.CCCostSelling,
                    CostName     = g.CustomClearanceCostLib.CostNameEn,
                    CurrencySign = g.Currency.CurrencySign,
                    CurrencyId   = g.CurrencyId,
                    CCDetailsId  = g.CCDetailsId
                });
            }


            foreach (var item in ccCost)
            {
                operCostAccVm                     = new OperationCostAccVm();
                operCostAccVm.Id                  = i;
                operCostAccVm.CostName            = item.CostName;
                operCostAccVm.CurrencySign        = item.CurrencySign;
                operCostAccVm.NetRate             = Math.Round(item.NetRate, 2);
                operCostAccVm.SellingRate         = Math.Round(item.SellingRate, 2);
                operCostAccVm.CurrencyId          = item.CurrencyId;
                operCostAccVm.FkType              = Convert.ToByte(CostType.CCCost);
                operCostAccVm.CostFkId            = item.CCDetailsId;
                operCostAccVm.CurrencyIdSelling   = item.CurrencyId;
                operCostAccVm.CurrencySignSelling = item.CurrencySign;
                i = i + 1;
                operCostMainVm.OperationCostAccVms.Add(operCostAccVm);
            }

            //Totals
            var totalList = operCostMainVm.OperationCostAccVms.GroupBy(g => new { g.CurrencySign })
                            .Select(g => new
            {
                CurrencySign = g.Key.CurrencySign,
                TotalNetRate = g.Sum(x => x.NetRate),
                CurrencyId   = g.Where(x => x.CurrencySign == g.Key.CurrencySign).FirstOrDefault().CurrencyId
            }).ToList();

            var totalListSelling = operCostMainVm.OperationCostAccVms.GroupBy(g => g.CurrencySignSelling)
                                   .Select(g => new
            {
                CurrencySign     = g.Key,
                TotalSellingRate = g.Sum(x => x.SellingRate),
                TotalAgentRate   = g.Where(x => x.IsAgent).Sum(x => x.SellingRate),
                CurrencyId       = g.Where(x => x.CurrencySignSelling == g.Key).FirstOrDefault().CurrencyIdSelling
            }).ToList();

            Dictionary <int, string> usedCurrency = new Dictionary <int, string>();

            usedCurrency = totalList.Select(c => new { key = c.CurrencyId, value = c.CurrencySign }).Distinct().ToDictionary(x => x.key, x => x.value);
            foreach (var item in totalListSelling)
            {
                if (!usedCurrency.ContainsKey(item.CurrencyId))
                {
                    usedCurrency.Add(item.CurrencyId, item.CurrencySign);
                }
            }
            // usedCurrency.(totalListSelling.Select(c => c.CurrencyId).Distinct().ToList());
            //usedCurrency = usedCurrency.Distinct().ToList();


            OperationCostTotalAccVm _operTotalsVm;

            foreach (var item in usedCurrency)
            {
                var sellingItem = totalListSelling.Where(x => x.CurrencyId == item.Key).FirstOrDefault();
                var netItem     = totalList.Where(x => x.CurrencyId == item.Key).FirstOrDefault();

                _operTotalsVm = new OperationCostTotalAccVm();
                _operTotalsVm.CurrencySign     = netItem == null ? item.Value : netItem.CurrencySign;
                _operTotalsVm.TotalNetRate     = netItem == null ? 0 : netItem.TotalNetRate;
                _operTotalsVm.TotalSellingRate = sellingItem == null ? 0 : sellingItem.TotalSellingRate;
                _operTotalsVm.TotalAgentRate   = sellingItem == null ? 0 : sellingItem.TotalAgentRate;
                _operTotalsVm.CurrencyId       = netItem == null ? item.Key : netItem.CurrencyId;

                operCostMainVm.OperationCostTotalAccVms.Add(_operTotalsVm);
            }


            //OperationCostTotalAccVm operTotalsVm;
            //int currId;
            //foreach (var item in totalList)
            //{
            //    currId = item.CurrencyId;
            //    var sellingItem = totalListSelling.Where(x => x.CurrencyId == currId).FirstOrDefault();
            //    operTotalsVm = new OperationCostTotalAccVm();
            //    operTotalsVm.CurrencySign = item.CurrencySign;
            //    operTotalsVm.TotalNetRate = item.TotalNetRate;
            //    operTotalsVm.TotalSellingRate = sellingItem == null ? 0 : sellingItem.TotalSellingRate;
            //    operTotalsVm.TotalAgentRate = sellingItem  == null ? 0 : sellingItem.TotalAgentRate;
            //    operTotalsVm.CurrencyId = item.CurrencyId;

            //    operCostMainVm.OperationCostTotalAccVms.Add(operTotalsVm);
            //}

            return(operCostMainVm);
        }