コード例 #1
0
        // GET: FSPrice/Details/5
        public ActionResult Calculate()
        {
            // empty batches object to fill soon
            //var batches = new List<DTO.BatchDTO>();
            //var VM = new List<DTO.BatchEditVM>();
            // dear service can i have the batches please
            var Allbatches = db.GetPBBatches();
            var unChanged  = Allbatches.Where(b => b.Comment == null);
            List <ImportModel.Batch> updateList = new List <ImportModel.Batch>();

            foreach (var b in unChanged)
            {
                // lets build a model we can edit
                /// get price datavar
                ///
                if (b.Id == 6854)
                {
                    var found = true;
                }
                int?         WholeSalePrice = b.WholesalePrice;
                PriceItemDTO batchWithPrice = PriceService.GetUnitPrice(b.FormSize, b.FormSizeCode);
                if (batchWithPrice == null)
                {
                    //DTO.BatchEditVM vm = new DTO.BatchEditVM();
                    //vm.BatchId = b.Id;
                    //vm.Sku = b.Sku;
                    //vm.Name = b.Name;
                    //vm.FormSize = b.FormSize;
                    //vm.FormSizeCode = b.FormSizeCode;
                    //vm.formType = "Dont Know";
                    //vm.PriceRule = "No Price Band";
                    //vm.maxPrice = 0;
                    //vm.minPrice = Convert.ToInt32(b.WholesalePrice)/100;
                    //VM.Add(vm);
                    //    var max = batchWithPrice.MaxUnitValue * 100;
                    //    var min = batchWithPrice.MinUnitValue * 100;
                    //    if (b.Price < min)
                    //    {
                    //        WholeSalePrice = Convert.ToInt32(min) + b.Price;

                    //    }
                    //    if (b.Price > max)
                    //    {
                    //        WholeSalePrice = Convert.ToInt32(max) + b.Price;
                    //    }
                    //ImportService.DTO.BatchPriceDTO newPrice = new ImportService.DTO.BatchPriceDTO();
                    //newPrice.BatchId = b.Id;
                    //newPrice.Price = Convert.ToInt32(WholeSalePrice);
                }
                else
                {
                    // nothing yet
                    var newPrice = PriceService.CalCapPrice(b);
                    b.WholesalePrice = Convert.ToInt32(newPrice);
                    updateList.Add(b);
                }
            }
            db.BatchUpdate(updateList);
            return(RedirectToAction("Index"));
        }
コード例 #2
0
        /// <summary>
        /// Calculates the proposed sale unit sale price dependant upon form - size
        /// </summary>
        /// <param name="batch"></param>
        /// <returns>Proposed unit Sale Price</returns>
        private static decimal CalCapPrice(ImportModel.Pannebakker batch)
        {
            // pb buy price
            var y = batch.Price;
            // base sales price
            var x = (batch.Price / 0.55m);

            PriceItemDTO price = PriceService.GetUnitPrice(batch.FormSize, batch.FormSizeCode);

            if (price != null)
            {
                var max = Convert.ToDecimal(price.MaxUnitValue * 100);
                var min = Convert.ToDecimal(price.MinUnitValue * 100);
                if (x < min)
                {
                    return(min + y);
                }
                if (x > max)
                {
                    return(max + y);
                }
            }
            else
            {
                return(0);
            }
            return(y);
        }
コード例 #3
0
        public IActionResult PutPriceItem(int id, PriceItemDTO priceItemDTO)
        {
            if (id != priceItemDTO.ProductId)
            {
                return(BadRequest());
            }

            DishSize priceItem = _mapper.Map <DishSize>(priceItemDTO);

            _priceItemRepository.Update(priceItem);


            try
            {
                _priceItemRepository.Save();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PriceItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #4
0
 public ActionResult <DishDTO> PostDish(PriceItemDTO priceItemDTO)
 {
     _priceItemRepository.Insert(_mapper.Map <DishSize>(priceItemDTO));
     _priceItemRepository.Save();
     return(CreatedAtAction("GetDish", new { id = priceItemDTO.ProductId }, priceItemDTO));
 }
コード例 #5
0
        public IEnumerable <FormSizePriceItem> PostPrices(IEnumerable <BatchQuoteItem> items)
        {
            // get all the batched in this quote
            //List<Batch> results = GetBatches(items);

            // this is the list I am going to send back
            List <FormSizePriceItem> outList = new List <FormSizePriceItem>();

            /// build output list
            foreach (var item in items)
            {
                // thisPriceItem will hold the result of the form based price calculation
                FormPriceRules.PriceItemDTO thisPriceItem = new PriceItemDTO();

                // result is the Item we are going to add to the list and sendback to Rob
                var result = new FormSizePriceItem();

                // batchid is the one i was given - going to be the same as the one passed in
                result.BatchId = item.BatchId;

                // my starting price is the one i was given so seach for it by id
                //result.PriceIn = items.First(i => i.BatchId == item.BatchId).PriceIn;
                result.PriceIn = item.PriceIn;

                //CHECK IF CUSTOM BATCH
                if (item.BatchId == 0 || item.BatchId == null)
                {
                    //If true then just return the original price because its not going to change
                    result.PriceOut = result.PriceIn;
                }
                else
                {
                    var batchToGetDetailsFrom = db.Batches.FirstOrDefault(x => x.Id == item.BatchId);

                    if (batchToGetDetailsFrom == null)
                    {
                        result.PriceOut = result.PriceIn;
                    }
                    else
                    {
                        // calculate the formsize price max and min the client uses int 1234 the calculator uses doubles
                        thisPriceItem = FormPriceRules.PriceService.GetUnitPrice(batchToGetDetailsFrom.FormSize, batchToGetDetailsFrom.FormSizeCode);
                        int max           = Convert.ToInt32(thisPriceItem.MaxUnitValue * 100);
                        int min           = Convert.ToInt32(thisPriceItem.MinUnitValue * 100);
                        int purchasePrice = Convert.ToInt32(batchToGetDetailsFrom.BuyPrice);

                        // now we can calculate the bandwidth values
                        int MaxPrice = purchasePrice + max;
                        int MinPrice = purchasePrice + min;

                        // default is to just return what i was given
                        result.PriceOut = result.PriceIn;

                        /// if the quantiyDiscountPrice <= purchase price + MinPrice
                        /// then return purchace + min profit
                        if (result.PriceIn <= MinPrice)
                        {
                            result.PriceOut = MinPrice;
                        }

                        //if the quantityDiscountPrice >= purchase price + max value
                        // then purchace + max profit
                        if (result.PriceIn >= MaxPrice)
                        {
                            result.PriceOut = MaxPrice;
                        }

                        result.Description = thisPriceItem.RuleNumber + " was applied to " + thisPriceItem.PlantType + " with a max of " + thisPriceItem.MaxUnitValue + " a min of " + thisPriceItem.MinUnitValue + " Description " + thisPriceItem.Description;
                    }
                }

                outList.Add(result);
            }

            return(outList);
        }