private static double GetTareWeight(CaseSize customCaseSize, OmsLabelType labelType, OrderDetail orderDetail) { decimal tareWeight; switch (labelType) { // abs in case when value in db has negative sign case OmsLabelType.Bag: tareWeight = GetBagTareWeight(customCaseSize, orderDetail); break; case OmsLabelType.Box: tareWeight = GetBoxTareWeight(customCaseSize, orderDetail); break; default: tareWeight = 0; break; } return((double)tareWeight); }
public static CaseSize ToCaseSize(this TareWeightViewModel tareWeightViewModel) { var caseSize = new CaseSize() { Name = tareWeightViewModel.Name, Id = tareWeightViewModel.Id, CustomerTypeId = (tareWeightViewModel.CustomerType.Id == 0)? (OmsCustomerType?)null: tareWeightViewModel.CustomerType.Id, CaseTypeId = tareWeightViewModel.CaseType.Id, CreateDateTime = DateTime.Today, IsActive = true, TareWeight = tareWeightViewModel.TareWeight_ }; return(caseSize); }
private static decimal GetBagTareWeight(CaseSize selectedСaseSizeEntity, OrderDetail orderDetail) { if (selectedСaseSizeEntity != null) { return(Math.Abs(selectedСaseSizeEntity.TareWeight)); } else { var customerProductData = orderDetail.Product.CustomerProductData.FirstOrDefault(x => x.CustomerId == orderDetail.Order.CustomerId); if (customerProductData != null && orderDetail.Product != null && orderDetail.Product.CustomerProductData != null && orderDetail.Product.CustomerProductData.Any(x => x.CustomerId == orderDetail.Order.CustomerId)) { if (customerProductData.BagSizeId.HasValue) { return(customerProductData.BagSizeEntity.TareWeight); } } } return (Math.Abs(orderDetail.Product.BagSizeEntity.TareWeight)); }
private static decimal GetBoxTareWeight(CaseSize selectedСaseSizeEntity, OrderDetail orderDetail) { // abs in case when value in db has negative sign if (selectedСaseSizeEntity != null) { return(Math.Abs(selectedСaseSizeEntity.TareWeight)); } else { var customerProductData = orderDetail.Product.CustomerProductData.FirstOrDefault(x => x.CustomerId == orderDetail.Order.CustomerId); if (customerProductData != null && orderDetail.Product != null && orderDetail.Product.CustomerProductData != null && orderDetail.Product.CustomerProductData.Any(x => x.CustomerId == orderDetail.Order.CustomerId)) { if (customerProductData.BoxSizeId.HasValue) { return(customerProductData.BoxSizeEntity.TareWeight); } } } return (Math.Abs(orderDetail.Product.BoxSizeEntity != null ? orderDetail.Product.BoxSizeEntity.TareWeight : 0)); }
public void ProduceCustomBagLabels(List <OrderDetail> orderDetails, double poundWeight, OmsLabelType labelType, DateTime?processDate, QualityGrade qualityGrade, AnimalLabelsViewModel animalLabel = null, CaseSize customCaseSize = null) { if (!orderDetails.Any()) { return; } var model = GetLabelLayoutViewModel(poundWeight, orderDetails.First(), labelType, false, qualityGrade, animalLabel, customCaseSize); foreach (var orderDetail in orderDetails) { ProduceLabel(labelType, model, orderDetail, true, processDate); } }
public void ProduceLabel(int orderDetailId, double poundWeight, OmsLabelType labelType, int quantity = 1, DateTime?processDate = null, QualityGrade qualityGrade = null, AnimalLabelsViewModel animalLabel = null, CaseSize customCaseSize = null) { var context = new OmsContext(); _orderDetailRepository = new OrderDetailRepository(context); var orderDetail = _orderDetailRepository.GetLabelInfo(orderDetailId); var model = GetLabelLayoutViewModel(poundWeight, orderDetail, labelType, false, qualityGrade, animalLabel, customCaseSize); for (var i = 0; i < quantity; i++) { ProduceLabel(labelType, model, orderDetail, false, processDate); } context.Dispose(); }
private LabelOutputViewModel GetLabelLayoutViewModel(double poundWeight, OrderDetail orderDetail, OmsLabelType labelType, bool needSetSerialNumber = true, QualityGrade qualityGrade = null, AnimalLabelsViewModel animalLabel = null, CaseSize customCaseSize = null) { var model = new LabelOutputViewModel(); model.PoundWeight = GetNetPoundWeight(poundWeight, labelType, orderDetail); model.KilogramWeight = GetCorrectKilogramWeight(model.PoundWeight); var order = orderDetail.Order; var product = orderDetail.Product; var customer = order.Customer; var productData = GetCustomerProductData(product, order); model.CustomerStateCode = orderDetail.CustomerLocation.StateCode; model.CustomerAddress1 = orderDetail.CustomerLocation.Address1; model.CustomerAddress2 = orderDetail.CustomerLocation.Address2; model.CustomerCity = orderDetail.CustomerLocation.City; model.CustomerEmail = orderDetail.CustomerLocation.Email; model.CustomerFax = orderDetail.CustomerLocation.Fax; model.CustomerZipCode = orderDetail.CustomerLocation.ZipCode; model.CustomerPhone = orderDetail.CustomerLocation.Phone; model.CustomerName = orderDetail.CustomerLocation.Name; model.OrderDetailId = orderDetail.Id; model.Type = labelType; model.ItemCode = product.Upc; model.LotNumber = GetLotNumber(order.Id); model.Description = product.EnglishDescription; model.ProcessDate = order.ProcessDate ?? DateTime.Today; model.SlaughterDate = order.SlaughterDate ?? DateTime.Today; model.BestBeforeDate = order.BestBeforeDate ?? DateTime.Today.AddDays(45); model.SpeciesBugPath = GetSpeciesBugPath(product); model.LogoPath = GetLogoPath(customer); model.BornInRegionName = order.BornRegion.With(x => x.Name); model.RaisedInRegionName = order.RaisedRegion.With(x => x.Name); model.ProductOfRegionName = order.ProductOfRegion.With(x => x.Name); model.SlaughteredInRegionName = order.SlaughteredRegion.With(x => x.Name); model.DistributedBy = customer.DistributedBy; model.LabelFile = SetLabelFile(labelType, customer, false); model.GermanDescription = product.GermanDescription; model.FrenchDescription = product.FrenchDescription; model.ItalianDescription = product.ItalianDescription; model.SwedishDescription = product.SwedishDescription; model.Organic = GetOrganicPath(animalLabel != null && animalLabel.IsOrganic); model.SerialNumber = (needSetSerialNumber) ? GetSerialNumber() : null; model.JulianProductionDate = DateTime.Now.DayOfYear.ToString(CultureInfo.InvariantCulture).PadLeft(3, '0'); model.VarCustomerJobValue = order.AdditionalInfoOnLabel; model.AnimalName = animalLabel != null ? animalLabel.Name : ""; model.Species = (animalLabel != null && animalLabel.Species != null) ? animalLabel.Species.Name : ""; model.NutritionDescription = product.NutritionDescription; model.NutritionServingSize = product.NutritionServingSize; model.NutritionServingContainer = product.NutritionServingContainer; model.NutritionCalories = product.NutritionCalories; model.NutritionCaloriesFat = product.NutritionCaloriesFat; model.NutritionTotalFat = product.NutritionTotalFat; model.NutritionSatFat = product.NutritionSatFat; model.NutritionTransFat = product.NutritionTransFat; model.NutritionPolyFat = product.NutritionPolyFat; model.NutritionMonoFat = product.NutritionMonoFat; model.NutritionCholesterol = product.NutritionCholesterol; model.NutritionSodium = product.NutritionSodium; model.NutritionCarbs = product.NutritionCarbs; model.NutritionProtein = product.NutritionProtein; model.NutritionVitA = product.NutritionVitA; model.NutritionVitC = product.NutritionVitC; model.NutritionCalcium = product.NutritionCalcium; model.NutritionIron = product.NutritionIron; model.PackedFor = customer.Name; model.Refrigeration = order.Refrigeration.Return(x => x.Name); model.Trim = product.TrimCut.Return(x => x.Name); model.GradeName = qualityGrade != null? qualityGrade.Name: ""; model.CustomerProductCode = productData == null || productData.ProductCode == null ? product.Code : productData.ProductCode; model.PricePerPound = productData == null || productData.PricePerPound == null ? product.PricePerPound : productData.PricePerPound; model.Price = model.PricePerPound != null ? model.PricePerPound.Value *Convert.ToDecimal(model.PoundWeight) : (decimal?)null; model.Gtin = productData == null || productData.Gtin == null ? product.Gtin : productData.Gtin.Value; model.VarCustomerProductValue = productData == null || productData.ProductDescription == null ? null : productData.ProductDescription; model.Customer = customer.Name; model.CustomerPO = order.POCustomer; model.Printer = SettingsManager.Current.Printer; model.WeighedDate = DateTime.Now; // todo (alexm): should be checked model.TareWeight = labelType == OmsLabelType.Box? GetBoxTareWeight(customCaseSize, orderDetail) : GetBagTareWeight(customCaseSize, orderDetail); return(model); }
public static double GetNetPoundWeight(double poundWeight, OmsLabelType labelType, OrderDetail orderDetail, CaseSize customCase = null) { var tareWeight = GetTareWeight(customCase, labelType, orderDetail); poundWeight -= tareWeight; return(poundWeight < 1000 ? poundWeight : Math.Round(poundWeight, MidpointRounding.AwayFromZero)); }
public static double GetGrossPoundWeight(double poundWeight, OmsLabelType labelType, OrderDetail orderDetail, CaseSize customCase = null) { return(poundWeight + GetTareWeight(customCase, labelType, orderDetail)); }
private void InitializeViewModel(int selectedOrderId) { var order = _orderRepository.Get(selectedOrderId); CustomerType = order.Customer.CustomerType.Id; var coldWeightEntry = order.ColdWeightEntries.FirstOrDefault(); if (coldWeightEntry != null) { var boxes_ = new BindingList <CaseSize>(); var bags = new BindingList <CaseSize>(); foreach (var orderDetail in order.OrderDetail) { CaseSize bag = orderDetail.Product.BagSizeEntity; CaseSize box = orderDetail.Product.BoxSizeEntity; var customerProductData = orderDetail.Product.CustomerProductData.FirstOrDefault(x => x.CustomerId == order.CustomerId); if (customerProductData != null && orderDetail.Product != null && orderDetail.Product.CustomerProductData != null && orderDetail.Product.CustomerProductData.Any(x => x.CustomerId == order.CustomerId)) { if (customerProductData.BagSizeId.HasValue) { bag = customerProductData.BagSizeEntity; } if (customerProductData.BoxSizeId.HasValue) { box = customerProductData.BoxSizeEntity; } } bags.Add(bag); boxes_.Add(box); } var coldWeightId = coldWeightEntry.Id; BagsTab.Visibility = order.BagEnable ? Visibility.Visible : Visibility.Collapsed; _viewModel.IsCustomOwner = order.Customer.CustomerTypeId == OmsCustomerType.Custom; if (_viewModel.IsCustomOwner) { _viewModel.CustomBagGridViewModel = new CustomBagGridViewModel() { AnimalNumbers = _labelService.GetAnimalNumbers(selectedOrderId), BagsTareWeights = new BindingList <CaseSize>(bags.Distinct().ToList()) }; _viewModel.CustomBoxGridViewModel = new CustomBoxGridViewModel() { BoxesCustomList = _labelService.GetBoxesCustomList(selectedOrderId), BoxesTareWeights = new BindingList <CaseSize>(boxes_.Distinct().ToList()) }; _viewModel.CustomTrayGridViewModel = new CustomBoxGridViewModel() { BoxesCustomList = _labelService.GetTraysCustomList(selectedOrderId), BoxesTareWeights = new BindingList <CaseSize>(boxes_.Distinct().ToList()) }; } else { _viewModel.UnitListViewModel = new UnitListViewModel(); var qualities = _qualityGradeRepository.GetAll().ToList().Select(x => new QualityGrade() { Name = x.Name, Id = x.Id }).ToList(); var animalLabels = _animalLabelRepository.GetAll().ToList(); var animalNames = animalLabels.Where( x => x.ColdWeightEntryDetails.ToList().Select(v => v.ColdWeightEntry.Id).Contains(coldWeightId)) .ToList() .Select(x => new AnimalLabelsViewModel() { Name = x.Name, IsOrganic = x.IsOrganic, Id = x.Id, Species = new SpeciesViewModel() { Name = x.Species.Name } }); _viewModel.UnitListViewModel.QualityGrades = new BindingList <QualityGrade>(qualities); _viewModel.UnitListViewModel.AnimalLabels = new BindingList <AnimalLabelsViewModel>(animalNames.ToList()); var labelGridItems = _labelService.GetLabelGridItems(selectedOrderId, !order.BagEnable); _viewModel.UnitListViewModel.BoxesList = new BindingList <LabelGridItem>(labelGridItems.Item1.OrderBy(x => x.ProductId).ToList()); foreach (var item in _viewModel.UnitListViewModel.BoxesList) { item.ItemColumn = _viewModel.UnitListViewModel.BoxesList.IndexOf(item); } //_viewModel.UnitListViewModel.TraysList = // new BindingList<LabelGridItem>(labelGridItems.Item3.OrderBy(x => x.ProductId).ToList()); //foreach (var item in _viewModel.UnitListViewModel.TraysList) //{ // item.ItemColumn = _viewModel.UnitListViewModel.TraysList.IndexOf(item); //} if (order.BagEnable) { _viewModel.UnitListViewModel.BagsList = new BindingList <LabelGridItem>(labelGridItems.Item2.OrderBy(x => x.ProductId).ToList()); } _viewModel.UnitListViewModel.BoxesTareWeights = new BindingList <CaseSize>(boxes_.Distinct().ToList()); _viewModel.UnitListViewModel.BagsTareWeights = new BindingList <CaseSize>(bags.Distinct().ToList()); } } if (!order.BagEnable) { BoxTab.IsSelected = true; } BtnEditLabels.IsEnabled = !_viewModel.IsCustomOwner; GridBags.Visibility = GetVisibility(!_viewModel.IsCustomOwner); GridBoxes.Visibility = GetVisibility(!_viewModel.IsCustomOwner); GridTray.Visibility = GetVisibility(!_viewModel.IsCustomOwner); GridCustomBags.Visibility = GetVisibility(_viewModel.IsCustomOwner); GridCustomBoxes.Visibility = GetVisibility(_viewModel.IsCustomOwner); GridCustomTray.Visibility = GetVisibility(_viewModel.IsCustomOwner); _viewModel.SpecialInstructions = order.SpecialInstructions; _viewModel.CustomerComments = order.CustomerComments; _viewModel.CombosSource = GetCombosSource(order); _viewModel.OffalsSource = GetOffalsSource(order); _viewModel.OrderSummary = GetOrderSummary(selectedOrderId); _viewModel.ProcessDate = order.ProcessDate; DisplayScaleOutput(string.Empty); }