public bool InsertCost(TShirtCostRecord cost) { //cost.CostRevision = 0; cost.DateCreated = DateTime.UtcNow; try { _costRepository.Create(cost); return(true); } catch { return(false); } }
public ActionResult Edit() { TShirtCostRecord cost = _costService.GetCost(cultureSearch); if (cost == null) { return(View("Edit")); } else { AdminCostViewModel costViewModel = new AdminCostViewModel { AdditionalScreenCosts = cost.AdditionalScreenCosts.ToString(), DTGPrintPrice = cost.DTGPrintPrice.ToString(), FirstScreenCost = cost.FirstScreenCost.ToString(), InkCost = cost.InkCost.ToString(), LabourCost = cost.LabourCost.ToString(), LabourTimePerColourPerPrint = cost.LabourTimePerColourPerPrint, LabourTimePerSidePrintedPerPrint = cost.LabourTimePerSidePrintedPerPrint, PercentageMarkUpRequired = cost.PercentageMarkUpRequired.ToString(), PrintsPerLitre = cost.PrintsPerLitre, SalesGoal = cost.SalesGoal, MaxColors = cost.MaxColors, MinimumTarget = cost.MinimumTarget }; return(View("Edit", costViewModel)); } }
public bool UpdateCost(TShirtCostRecord cost) { int new_revisision = cost.CostRevision + 1; TShirtCostRecord tshirt = new TShirtCostRecord() { AdditionalScreenCosts = cost.AdditionalScreenCosts, CostCulture = cost.CostCulture, CostRevision = new_revisision, DateCreated = DateTime.UtcNow, DTGPrintPrice = cost.DTGPrintPrice, FirstScreenCost = cost.FirstScreenCost, InkCost = cost.InkCost, LabourCost = cost.LabourCost, LabourTimePerColourPerPrint = cost.LabourTimePerColourPerPrint, LabourTimePerSidePrintedPerPrint = cost.LabourTimePerSidePrintedPerPrint, MaxColors = cost.MaxColors, PercentageMarkUpRequired = cost.PercentageMarkUpRequired, PrintsPerLitre = cost.PrintsPerLitre, SalesGoal = cost.SalesGoal }; return(InsertCost(tshirt)); }
public ActionResult Save(AdminCostViewModel costViewModel) { costViewModel = ReplaceAllCost(costViewModel); bool dontUpdate = false; float flo; try { flo = Convert.ToSingle(costViewModel.AdditionalScreenCosts, new CultureInfo("en-US")); } catch { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Additional Screen Costs\"")); dontUpdate = true; } try { flo = Convert.ToSingle(costViewModel.DTGPrintPrice, new CultureInfo("en-US")); } catch { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"DTG print price\"")); dontUpdate = true; } try { flo = Convert.ToSingle(costViewModel.FirstScreenCost, new CultureInfo("en-US")); } catch { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"1st Screen Cost\"")); dontUpdate = true; } try { flo = Convert.ToSingle(costViewModel.InkCost, new CultureInfo("en-US")); } catch { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Ink Cost\"")); dontUpdate = true; } try { flo = Convert.ToSingle(costViewModel.LabourCost, new CultureInfo("en-US")); } catch { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Labour Cost\"")); dontUpdate = true; } if (costViewModel.LabourTimePerColourPerPrint == 0) { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Labour time per colour per print\"")); dontUpdate = true; } if (costViewModel.LabourTimePerSidePrintedPerPrint == 0) { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Labour time per side printed per print\"")); dontUpdate = true; } try { flo = Convert.ToSingle(costViewModel.PercentageMarkUpRequired, new CultureInfo("en-US")); } catch { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Percentage Mark-Up required\"")); dontUpdate = true; } if (costViewModel.PrintsPerLitre == 0) { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("Incorrect entries in the box \"Prints per litre\"")); dontUpdate = true; } if (dontUpdate) { return(this.RedirectToAction("Edit")); } TShirtCostRecord cost = _costService.GetCost(cultureSearch); if (cost == null) { TShirtCostRecord newCost = new TShirtCostRecord { AdditionalScreenCosts = Convert.ToSingle(costViewModel.AdditionalScreenCosts, new CultureInfo("en-US")), DTGPrintPrice = Convert.ToSingle(costViewModel.DTGPrintPrice, new CultureInfo("en-US")), FirstScreenCost = Convert.ToSingle(costViewModel.FirstScreenCost, new CultureInfo("en-US")), InkCost = Convert.ToSingle(costViewModel.InkCost, new CultureInfo("en-US")), LabourCost = Convert.ToSingle(costViewModel.LabourCost, new CultureInfo("en-US")), LabourTimePerColourPerPrint = costViewModel.LabourTimePerColourPerPrint, LabourTimePerSidePrintedPerPrint = costViewModel.LabourTimePerSidePrintedPerPrint, PercentageMarkUpRequired = Convert.ToSingle(costViewModel.PercentageMarkUpRequired, new CultureInfo("en-US")), PrintsPerLitre = costViewModel.PrintsPerLitre, SalesGoal = costViewModel.SalesGoal, MaxColors = costViewModel.MaxColors, CostCulture = cultureSearch, MinimumTarget = costViewModel.MinimumTarget }; if (_costService.InsertCost(newCost)) { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Information, T("Data update was successfully")); } else { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("When you try to update the data error occurred. Please, try again later!")); } } else { var ncost = new TShirtCostRecord() { AdditionalScreenCosts = Convert.ToSingle(costViewModel.AdditionalScreenCosts, new CultureInfo("en-US")), DTGPrintPrice = Convert.ToSingle(costViewModel.DTGPrintPrice, new CultureInfo("en-US")), FirstScreenCost = Convert.ToSingle(costViewModel.FirstScreenCost, new CultureInfo("en-US")), InkCost = Convert.ToSingle(costViewModel.InkCost, new CultureInfo("en-US")), CostCulture = "en-MY", LabourCost = Convert.ToSingle(costViewModel.LabourCost, new CultureInfo("en-US")), LabourTimePerColourPerPrint = costViewModel.LabourTimePerColourPerPrint, LabourTimePerSidePrintedPerPrint = costViewModel.LabourTimePerSidePrintedPerPrint, PercentageMarkUpRequired = Convert.ToSingle(costViewModel.PercentageMarkUpRequired, new CultureInfo("en-US")), PrintsPerLitre = costViewModel.PrintsPerLitre, SalesGoal = costViewModel.SalesGoal, MaxColors = costViewModel.MaxColors, CostRevision = cost.CostRevision + 1, MinimumTarget = costViewModel.MinimumTarget }; //cost.AdditionalScreenCosts = Convert.ToSingle(costViewModel.AdditionalScreenCosts, new CultureInfo("en-US")); //cost.DTGPrintPrice = Convert.ToSingle(costViewModel.DTGPrintPrice, new CultureInfo("en-US")); //cost.FirstScreenCost = Convert.ToSingle(costViewModel.FirstScreenCost, new CultureInfo("en-US")); //cost.InkCost = Convert.ToSingle(costViewModel.InkCost, new CultureInfo("en-US")); //cost.LabourCost = Convert.ToSingle(costViewModel.LabourCost, new CultureInfo("en-US")); //cost.LabourTimePerColourPerPrint = costViewModel.LabourTimePerColourPerPrint; //cost.LabourTimePerSidePrintedPerPrint = costViewModel.LabourTimePerSidePrintedPerPrint; //cost.PercentageMarkUpRequired = Convert.ToSingle(costViewModel.PercentageMarkUpRequired, new CultureInfo("en-US")); //cost.PrintsPerLitre = costViewModel.PrintsPerLitre; //cost.SalesGoal = costViewModel.SalesGoal; //cost.MaxColors = costViewModel.MaxColors; if (_costService.InsertCost(ncost)) { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Information, T("Data update was successfully")); } else { Services.Notifier.Add(Orchard.UI.Notify.NotifyType.Error, T("When you try to update the data error occurred. Please, try again later!")); } } return(this.RedirectToAction("Index")); }
public float CalculateVersion2(int campaignID, int productID, int soldcount) { var culture = _workContextAccessor.GetContext().CurrentCulture.Trim(); //TShirtCostRecord cost = _costService.GetCost(culture); var campaign = _campaignService.GetCampaignById(campaignID); var product = campaign.Products.Where(aa => aa.Id == productID).First(); if (soldcount >= campaign.ProductCountGoal) { return((float)product.BaseCost); } int CntBackColor = campaign.CntBackColor; int CntFrontColor = campaign.CntFrontColor; if (CntBackColor == 0 && CntFrontColor == 0) { CntFrontColor = 1; } else { CntBackColor = campaign.CntBackColor; // == 0 ? 1 : campaign.CntBackColor; CntFrontColor = campaign.CntFrontColor; // == 0 ? 1 : campaign.CntFrontColor; } TShirtCostRecord cost = (campaign.TShirtCostRecord != null) ? campaign.TShirtCostRecord : _costService.GetCost(culture); //var additionalScreenCosts = cost.AdditionalScreenCosts; //var costOfMaterial = product.ProductRecord.BaseCost; //var dTGPrintPrice = cost.DTGPrintPrice; //var firstScreenCost = cost.FirstScreenCost; //var inkCost = cost.InkCost; //var labourCost = cost.LabourCost; //var labourTimePerColourPerPrint = cost.LabourTimePerColourPerPrint; //var labourTimePerSidePrintedPerPrint = cost.LabourTimePerSidePrintedPerPrint; //var percentageMarkUpRequired = cost.PercentageMarkUpRequired / 100; //var printsPerLitre = cost.PrintsPerLitre; //var count = soldcount; double B3 = cost.FirstScreenCost; //1st Screen Cost (RM) double B4 = cost.AdditionalScreenCosts; //Additional Screen Costs (RM) double B5 = cost.InkCost; //Ink Cost (RM per litre per colour) double B6 = cost.PrintsPerLitre; //Prints per litre double B7 = cost.LabourCost; //Labour Cost (RM per hr) double B8 = cost.LabourTimePerColourPerPrint; //Labour time per colour per print (seconds) double B9 = cost.LabourTimePerSidePrintedPerPrint; //Labour time per side printed per print (seconds) double B10 = (product.CostOfMaterial == 0) ? product.ProductRecord.BaseCost : product.CostOfMaterial; //Cost of material/ t-shirt (RM each) double B11 = cost.PercentageMarkUpRequired / 100; //Percentage Mark-Up required double B12 = cost.DTGPrintPrice; //DTG print price (RM) double B14 = CntFrontColor; //Number of colours (front) double B15 = CntBackColor; //Number of colours (back) double B16 = soldcount; //Quantity var x = Math.Min(B10 + B12, (B3 * Math.Min(B14, 1) + B4 * Math.Max(0, B14 - 1) + B3 * Math.Min(B15, 1) + B4 * Math.Max(0, B15 - 1) + B7 * B8 / 3600 * B16 * (B14 + B15) + B5 / B6 * B16 * (B14 + B15) + B7 * (B9 / 3600) * ((B14 > 0 ? 1 : 0) + (B15 > 0 ? 1 : 0)) * B16 + B10 * B16) / B16) * (1 + B11); return((float)x); }
private float CalculateBaseCost(int campaignID, int productID, int soldcount) { culture = _workContextAccessor.GetContext().CurrentCulture.Trim(); //TShirtCostRecord cost = _costService.GetCost(culture); var campaign = _campaignService.GetCampaignById(campaignID); var product = campaign.Products.Where(aa => aa.Id == productID).First(); if (soldcount >= campaign.ProductCountGoal) { return((float)product.BaseCost); } int CntBackColor = campaign.CntBackColor; int CntFrontColor = campaign.CntFrontColor; if (CntBackColor == 0 && CntFrontColor == 0) { CntFrontColor = 1; } else { CntBackColor = campaign.CntBackColor; // == 0 ? 1 : campaign.CntBackColor; CntFrontColor = campaign.CntFrontColor; // == 0 ? 1 : campaign.CntFrontColor; } TShirtCostRecord cost = (campaign.TShirtCostRecord != null) ? campaign.TShirtCostRecord : _costService.GetCost(culture); var additionalScreenCosts = cost.AdditionalScreenCosts; var costOfMaterial = product.ProductRecord.BaseCost; var dTGPrintPrice = cost.DTGPrintPrice; var firstScreenCost = cost.FirstScreenCost; var inkCost = cost.InkCost; var labourCost = cost.LabourCost; var labourTimePerColourPerPrint = cost.LabourTimePerColourPerPrint; var labourTimePerSidePrintedPerPrint = cost.LabourTimePerSidePrintedPerPrint; var percentageMarkUpRequired = cost.PercentageMarkUpRequired / 100; var printsPerLitre = cost.PrintsPerLitre; var count = soldcount; var argument1 = 1 + percentageMarkUpRequired; var argument2 = CntBackColor > 0 ? CntBackColor : 0; var argument3 = CntFrontColor > 0 ? CntFrontColor : 0; var argument4 = (float)labourTimePerSidePrintedPerPrint / 3600; var argument5 = CntBackColor + CntFrontColor; var argument6 = costOfMaterial + dTGPrintPrice; var argument7 = Math.Min(CntFrontColor, 1); var argument8 = Math.Max(0, CntFrontColor - 1); var argument9 = Math.Min(CntBackColor, 1); var argument10 = Math.Max(0, CntBackColor - 1); var argument11 = costOfMaterial * count; var argument12 = count * argument5; var argument13 = labourCost * labourTimePerColourPerPrint / 3600 * argument12; var argument14 = inkCost / printsPerLitre * argument12; var argument15_1 = argument3 + argument2; var argument15 = labourCost * argument4 * argument15_1 * count; var function1 = argument7 + argument9; var function2 = firstScreenCost * function1; var function3 = argument8 + argument10; var function4 = additionalScreenCosts * function3; var function5 = function2 + function4 + argument13 + argument14 + argument15 + argument11; var function6 = function5 / count; var function7 = argument6 > function6 ? function6 : argument6; var result = function7 * argument1; return((float)result); }