/// <summary> /// Get house bill .. in case of no house bills .. will fill its view model from operation data /// </summary> /// <param name="operationId"> int Operation Id </param> /// <param name="oprOrderFrom">byte Order From</param> /// <returns></returns> public ActionResult GetHbContent(int operationId, byte oprOrderFrom, int hbId = 0) { #region Check Rights bool hasRights; if (oprOrderFrom == 1) //Check export rights { if (hbId == 0) { hasRights = AdminHelper.CheckUserAction(ScreenEnum.ExportHB, ActionEnum.Add); } else { hasRights = AdminHelper.CheckUserAction(ScreenEnum.ExportHB, ActionEnum.Edit); } } else { if (hbId == 0) { hasRights = AdminHelper.CheckUserAction(ScreenEnum.ImportHB, ActionEnum.Add); } else { hasRights = AdminHelper.CheckUserAction(ScreenEnum.ImportHB, ActionEnum.Edit); } } if (!hasRights) { return(PartialView("~/Views/Shared/_UnAuthorized.cshtml")); } #endregion HouseBillVm houseBillVm = HouseBillHelper.GetHbContent(operationId, oprOrderFrom, hbId); ViewBag.ShipperList = ListCommonHelper.GetShipperList(); ViewBag.ConsigneeList = ListCommonHelper.GetConsigneeList(); ViewBag.IncotermLib = ListCommonHelper.GetIncotermLibList(); ViewBag.Containers = ListCommonHelper.GetContainerList(); ViewBag.PackageList = ListCommonHelper.GetPackageTypeList(); ViewData["PortList"] = ListCommonHelper.GetPortsGrouped(); ViewData["CurrencyList"] = ListCommonHelper.GetCurrencyList(); ViewBag.AgentList = ListCommonHelper.GetAgentList(); ViewBag.OperationVm = OperationHelper.GetOperationInfo(operationId); ViewBag.OperContainers = OperationHelper.GetOperationContainers(operationId); ViewBag.SelectedHbCon = HouseBillHelper.GetHousContainerByHouseID(hbId); ViewBag.NotifierList = ListCommonHelper.GetNotifierList(0); return(PartialView("~/Views/Operation/_HouseBill.cshtml", houseBillVm)); }
internal static string AddEditHouseBill(HouseBillVm houseBillVm) { string isSaved = "true"; int houseBillId = houseBillVm.HouseBillId; OperationsEntities db = new OperationsEntities(); HouseBill houseBillDb; if (houseBillId == 0) { houseBillDb = new HouseBill(); } else { houseBillDb = db.HouseBills.Where(x => x.HouseBillId == houseBillId).FirstOrDefault(); } Mapper.CreateMap <HouseBillVm, HouseBill>().IgnoreAllNonExisting(); Mapper.Map(houseBillVm, houseBillDb); if (houseBillId == 0) { db.HouseBills.Add(houseBillDb); int operationId = houseBillDb.OperationId; Operation operationObj = db.Operations.Where(x => x.OperationId == operationId).FirstOrDefault(); operationObj.StatusId = 2; } try { db.SaveChanges(); isSaved = "true_" + houseBillDb.HouseBillId; } catch (DbEntityValidationException e) { isSaved = "false " + e.InnerException.InnerException; } catch (Exception e) { isSaved = "false " + e.InnerException.InnerException; } return(isSaved); }
internal static HouseBillVm GetHbContent(int operationId, byte oprOrderFrom, int hbId = 0) { OperationsEntities db = new OperationsEntities(); HouseBillVm houseBillVm = new HouseBillVm(oprOrderFrom); HouseBill houseBillDb = null; //if(hbId == 0) // add new house bill // houseBillDb = db.HouseBills.Where(x => x.OperationId == operationId).FirstOrDefault(); if (hbId != 0) // add new house bill { houseBillDb = db.HouseBills.Where(x => x.HouseBillId == hbId).FirstOrDefault(); } if (houseBillDb == null) { Operation operationDb = db.Operations.Where(x => x.OperationId == operationId).FirstOrDefault(); Mapper.CreateMap <Operation, HouseBillVm>() .ForMember(x => x.OperationDate, y => y.Ignore()) .ForMember(x => x.CreateBy, y => y.Ignore()) .ForMember(x => x.CreateDate, y => y.Ignore()) .ForMember(x => x.StatusId, y => y.Ignore()) .ForMember(x => x.CollectedFreightCost, y => y.MapFrom(s => s.FreightCostAmount)) .ForMember(x => x.CollectedThcCost, y => y.MapFrom(s => s.ThcCostAmount)) .ForMember(x => x.OperationMinDate, y => y.MapFrom(s => s.OperationDate)); Mapper.Map(operationDb, houseBillVm); //Check if has another HBLs get only the remaining amounts decimal nw = 0, gw = 0, cbm = 0, freightCost = 0, thcCost = 0; int packagesNum = 0; int hbCount = GetHBCount(operationId); if (hbCount > 0) { var pervSum = db.HouseBills.Where(x => x.OperationId == operationId) .Select(x => new { x.OperationId, x.NetWeight, x.GrossWeight, x.CBM, x.NumberOfPackages, x.CollectedFreightCost, x.CollectedThcCost }) .GroupBy(s => s.OperationId) .Select(g => new { nw = g.Sum(x => x.NetWeight), gw = g.Sum(x => x.GrossWeight), cbm = g.Sum(x => x.CBM), packagesNum = g.Sum(x => x.NumberOfPackages), freightCost = g.Sum(x => x.CollectedFreightCost), thcCost = g.Sum(x => x.CollectedThcCost) }).FirstOrDefault(); if (operationDb.NetWeight != null) { nw = operationDb.NetWeight.Value - pervSum.nw.Value; } if (operationDb.GrossWeight != null) { gw = operationDb.GrossWeight.Value - pervSum.gw.Value; } if (operationDb.CBM != null) { cbm = operationDb.CBM.Value - pervSum.cbm.Value; } if (operationDb.NumberOfPackages != null) { packagesNum = operationDb.NumberOfPackages.Value - pervSum.packagesNum.Value; } if (operationDb.FreightCostAmount != null) { freightCost = operationDb.FreightCostAmount.Value - pervSum.freightCost.Value; } if (operationDb.ThcCostAmount != null) { thcCost = operationDb.ThcCostAmount.Value - pervSum.thcCost.Value; } houseBillVm.NetWeight = nw; houseBillVm.GrossWeight = gw; houseBillVm.CBM = cbm; houseBillVm.NumberOfPackages = packagesNum; houseBillVm.CollectedFreightCost = freightCost; houseBillVm.CollectedThcCost = thcCost; } } else { Mapper.CreateMap <HouseBill, HouseBillVm>().IgnoreAllNonExisting(); Mapper.Map(houseBillDb, houseBillVm); //get departure and arrive date var operObj = db.Operations .Where(x => x.OperationId == operationId) .Select(x => new { x.DateOfDeparture, x.ArriveDate, x.OperationDate }).FirstOrDefault(); houseBillVm.DateOfDeparture = operObj.DateOfDeparture; houseBillVm.ArriveDate = operObj.ArriveDate; houseBillVm.OperationMinDate = operObj.OperationDate; } return(houseBillVm); }
/// <summary> /// The post action to save House Bill data /// </summary> /// <param name="houseBillVm">House Bill view model object</param> /// <returns>string "true" or "false + error message"</returns> public ActionResult AddEditHouseBill(HouseBillVm houseBillVm) { string isSaved = HouseBillHelper.AddEditHouseBill(houseBillVm); return(Json(isSaved)); }