/// <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); }
/// <summary> /// Turn 30% into a decimal by dividing 30 by 100, which is 0.3. // Minus 0.3 from 1 to get 0.7. // Divide the price the good cost you by 0.7. // The number that you receive is how much you need to sell the item for to get a 30% profit margin. /// </summary> /// <param name="batch"></param> /// <param name="MarginIn"></param> /// <returns></returns> public static Result CalMarginPrice(ImportModel.Pannebakker batch, decimal MarginIn) { // Divide the number you wish to increase by 100 to find 1 % of it. var Onepc = batch.Price / 100; //Multiply 1 % by your chosen percentage. var increase = Onepc * MarginIn; // Add this number to your original number. var newPrice = batch.Price + increase; //var margin = MarginIn / 100; //// Divide the number you wish to increase by 100 //var PcValue = 1 - margin; //// Multiply 1% by your chosen percentage //var newPrice = batch.Price / PcValue; var result = new Result { price = 0, rule = "" }; // Add this number to your original number result.price = newPrice; result.rule = "Simple margin of " + MarginIn.ToString() + " applied"; return(result); }
/// <returns>Proposed unit Sale Price</returns> public static Result CalCapPrice(ImportModel.Pannebakker batch) { //decimal margin = MarginIn / 100; // pb buy price var y = batch.Price; // base sales price var x = (batch.Price / 0.55m); var result = new Result { price = 0, rule = "" }; ServiceLayer.PriceItemDTO price = PriceService.GetUnitPrice(batch.FormSize, batch.FormSizeCode); if (price != null) { result.rule = price.RuleNumber.ToString(); var max = Convert.ToDecimal(price.MaxUnitValue * 100); var min = Convert.ToDecimal(price.MinUnitValue * 100); if (x < min) { result.price = min + y; return(result); } if (x > max) { result.price = max + y; return(result); } } else { result.price = 0; return(result); } result.price = y; return(result); }
public ActionResult UpLoad() { List <ImportModel.rawImport> recordsIn = new List <ImportModel.rawImport>(); List <ImportModel.Pannebakker> existingRecords = new List <ImportModel.Pannebakker>(); List <ImportModel.rawImport> newRecords = new List <ImportModel.rawImport>(); try { recordsIn = ReadInputFile(); // existingRecords = db.GetPannebakkers().ToList(); // newRecords = recordsIn.Union(existingRecords).ToList(); // newRecords = existingRecords.Union(recordsIn, new DTO.PbComparer()).ToList(); } catch (Exception ex) { ViewBag.Error = ex.InnerException.Message; return(View("version")); } try { #region import ///// empty the import tables // db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Pannebakker]"); db.EmptyImport(); /// insert into raw import and remove any duplicates just in case // db.BulkInsert<Pannebakker>(newRecords); db.BulkInsertIntoImport(recordsIn); db.RemoveDuplicateImport(); #endregion import // merge import into PB and clean form sizes //AddBatch(records); db.MergeImportToPB(); db.cleanPBForms(); db.cleanForms(); db.RemoveDuplicatePB(); // so PB table sould now be solid and ready // remove any duplicates from PB and Batch // may not be needed but just in case // db.RemoveDuplicateBatch(); // clean all old PB's from batch as we are going to provide a new lot. // worried about this moving frowards if quotes use batch ids from PB's i am removing //db.RemovePBFromBatch(); var allPB = db.GetPannebakkers().ToList(); // db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Pannebakker]"); List <ImportModel.Pannebakker> newBatches = new List <ImportModel.Pannebakker>(); foreach (var b in allPB) { ImportModel.Pannebakker newB = new ImportModel.Pannebakker(); decimal price = CalCapPrice(b); if (price != 0) { newB.WholesalePrice = Convert.ToInt32(price); } else { newB.WholesalePrice = Convert.ToInt32(b.Price); } newB.Price = b.Price; newB.FormSize = b.FormSize; newB.Location = "PB"; newB.Name = b.Name; newB.Sku = b.Sku; newB.WholesalePrice = Convert.ToInt32(price); newB.FormSizeCode = b.FormSizeCode; if (price != b.Price) { newB.Comment = "Price Modified from " + b.Price + " to " + newB.WholesalePrice; } if (price == b.Price) { newB.Comment = "Price Not Modified"; } if (price == 0) { newB.Comment = null; } newBatches.Add(newB); } //IEnumerable<ImportModel.Batch> newBatches = allPB.Select(batch => new ImportModel.Batch //{ // Active = true, // AllocatedQuantity = 0, // BuyPrice = CalCapPrice(batch), // Comment = "", // FormSize = batch.FormSize, // ImageExists = false, // GrowingQuantity = 0, // Location = "PB", // Name = batch.Name, // Sku = batch.Sku, // Quantity = 5000, // WholesalePrice = 0, // DateStamp = DateTime.Now, //}); db.EmptyPB(); db.BulkInsertIntoPB(newBatches); db.MergePbToBatch(); ViewBag.Title = "done"; Response.Write("<script>console.log('Data has been saved to db');</script>"); return(View("uploadDone")); //return RedirectToAction("Index"); } catch (Exception ex) { ViewBag.Error = ex.InnerException.Message; return(View("shit")); } }
public ActionResult CalculateBasePrice(decimal margin, decimal import) { decimal test = 0; test = margin; try { var allPB = db.GetPannebakkers().ToList(); // db.Database.ExecuteSqlCommand("TRUNCATE TABLE [Pannebakker]"); #region update import value var pbSupplier = db.GetSupplierByAccount("PO21"); pbSupplier.ImportOffSet = Convert.ToDouble(import); db.UpdateSupplier(pbSupplier); #endregion List <ImportModel.Pannebakker> newBatches = new List <ImportModel.Pannebakker>(); foreach (var b in allPB) { if (b.BatchId == 5313) { var fred = 1; } ImportModel.Pannebakker newB = new ImportModel.Pannebakker(); CalcData.Result result = CalcData.CalMarginPrice(b, margin); decimal price = result.price; if (price != 0) { newB.WholesalePrice = Convert.ToInt32(price); } else { newB.WholesalePrice = Convert.ToInt32(b.Price); } newB.Price = b.Price; newB.FormSize = b.FormSize; newB.Location = "PB"; newB.Name = b.Name; newB.Sku = b.Sku; newB.WholesalePrice = Convert.ToInt32(price); newB.FormSizeCode = b.FormSizeCode; newB.FromDate = b.FromDate; if (price != b.Price) { newB.Comment = "Using Rule " + result.rule + "Price Modified from " + b.Price + " to " + newB.WholesalePrice; } if (price == b.Price) { newB.Comment = "Using Rule " + result.rule + " Price Not Modified"; } if (price == 0) { newB.Comment = null; } newBatches.Add(newB); } db.EmptyPB(); db.BulkInsertIntoPB(newBatches); return(View()); //return RedirectToAction("Index"); } catch (Exception ex) { ViewBag.Error = ex.InnerException.Message; return(View("shit")); } }