public JsonResult GetPartsForPriceSheet(Guid rfqId, bool includeRaw, bool includeMachined) { var model = new PriceSheetPartViewModel(); var parts = new List <PriceSheetPartViewModel>(); var tempParts = _projectPartRepository.GetProjectParts().Where(x => x.RfqId == rfqId).OrderBy(x => x.Number).ToList(); if (tempParts != null && tempParts.Count > 0) { foreach (var tempPart in tempParts) { if (tempPart.IsRaw && includeRaw) { PriceSheetPartViewModel costPart = new PriceSheetPartConverter().ConvertToCostView(tempPart); parts.Add(costPart); } else if (tempPart.IsMachined && includeMachined) { PriceSheetPartViewModel costPart = new PriceSheetPartConverter().ConvertToCostView(tempPart); parts.Add(costPart); } } } model.OrderParts = parts.OrderBy(x => x.PartNumber).ToList(); return(Json(model, JsonRequestBehavior.AllowGet)); }
/// <summary> /// convert price sheet part to view model for quote price sheet /// </summary> /// <param name="part"></param> /// <returns></returns> public PriceSheetPartViewModel ConvertToProjectPartView(PriceSheetPart part) { PriceSheetPartViewModel model = new PriceSheetPartViewModel(); var _projectPartRepository = new ProjectPartRepository(); var _priceSheetRepository = new PriceSheetRepository(); var priceSheet = _priceSheetRepository.GetPriceSheet(part.PriceSheetId); var projectPart = _projectPartRepository.GetProjectPart(part.ProjectPartId); model.ProjectPartId = part.ProjectPartId ?? Guid.Empty; model.PriceSheetPartId = part.PriceSheetPartId; model.PriceSheetId = part.PriceSheetId; model.PriceSheetNumber = (priceSheet != null) ? priceSheet.Number : "N/A"; model.PartNumber = (projectPart != null) ? projectPart.Number : "N/A"; model.PartDescription = (projectPart != null) ? projectPart.Description : "N/A"; model.AvailableQuantity = part.AvailableQuantity; model.CustomerOrderQuantity = part.AvailableQuantity; model.UnitPrice = part.Price; model.UnitCost = part.Cost; if (_projectPartRepository != null) { _projectPartRepository.Dispose(); _projectPartRepository = null; } if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } return(model); }
/// <summary> /// convert project part to price sheet part cost view model /// </summary> /// <param name="part"></param> /// <returns></returns> public PriceSheetPartViewModel ConvertToCostView(ProjectPart part) { PriceSheetPartViewModel model = new PriceSheetPartViewModel(); model.AnnualUsage = Decimal.ToInt32(part.AnnualUsage); model.PartNumber = part.Number; model.Weight = part.Weight; model.ProjectPartId = part.ProjectPartId; return(model); }
/// <summary> /// convert price sheet part to view model for production price sheet /// </summary> /// <param name="part"></param> /// <returns></returns> public PriceSheetPartViewModel ConvertToPartView(PriceSheetPart part) { PriceSheetPartViewModel model = new PriceSheetPartViewModel(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _priceSheetRepository = new PriceSheetRepository(); var _projectPartRepository = new ProjectPartRepository(); var priceSheet = _priceSheetRepository.GetPriceSheet(part.PriceSheetId); var projectPart = _projectPartRepository.GetProjectPart(part.ProjectPartId); var tempPart = _partRepository.GetPart((projectPart != null) ? projectPart.PartId : null); var dynamicsPart = _dynamicsPartRepository.GetPartMaster((tempPart != null) ? tempPart.Number : null); model.ProjectPartId = part.ProjectPartId ?? Guid.Empty; model.PartId = (tempPart != null) ? tempPart.PartId : Guid.Empty; model.PriceSheetPartId = part.PriceSheetPartId; model.PriceSheetId = part.PriceSheetId; model.PriceSheetNumber = (priceSheet != null) ? priceSheet.Number : "N/A"; model.PartNumber = (tempPart != null) ? tempPart.Number : "N/A"; model.PartDescription = (dynamicsPart != null && !string.IsNullOrEmpty(dynamicsPart.ITEMDESC)) ? dynamicsPart.ITEMDESC : "N/A"; model.AvailableQuantity = part.AvailableQuantity; model.CustomerOrderQuantity = part.AvailableQuantity; model.UnitPrice = part.Price; model.UnitCost = part.Cost; if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } return(model); }
/// <summary> /// convert price sheet to view model /// </summary> /// <param name="priceSheet"></param> /// <returns></returns> public PriceSheetViewModel ConvertToView(PriceSheet priceSheet) { PriceSheetViewModel model = new PriceSheetViewModel(); var _projectRepository = new ProjectRepository(); var _rfqRepository = new RfqRepository(); var _countryRepository = new CountryRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _priceSheetRepository = new PriceSheetRepository(); var _quoteRepository = new QuoteRepository(); var project = _projectRepository.GetProject(priceSheet.ProjectId); var rfq = _rfqRepository.GetRfq(priceSheet.RfqId); var country = _countryRepository.GetCountry((rfq != null) ? rfq.CountryId : Guid.Empty); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry((rfq != null) ? rfq.FoundryId : string.Empty); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer((rfq != null) ? rfq.CustomerId : string.Empty); model.PriceSheetId = priceSheet.PriceSheetId; model.Number = (!string.IsNullOrEmpty(priceSheet.Number)) ? priceSheet.Number : "N/A"; model.RfqId = priceSheet.RfqId; model.ProjectMargin = priceSheet.ProjectMargin; model.ProjectName = (project != null && !string.IsNullOrEmpty(project.Name)) ? project.Name : "N/A"; model.RfqNumber = (rfq != null && !string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A"; model.Country = (country != null && !string.IsNullOrEmpty(country.Name)) ? country.Name : "N/A"; model.Foundry = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.Customer = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.WAF = priceSheet.WAF; model.AnnualContainer = priceSheet.AnnualContainer; model.AnnualDollars = priceSheet.AnnualDollars; model.AnnualMargin = priceSheet.AnnualMargin; model.AnnualWeight = priceSheet.AnnualWeight; model.DollarContainer = priceSheet.DollarContainer; model.InsuranceDivisor = priceSheet.InsuranceDivisor; model.InsuranceDuty = priceSheet.InsuranceDuty; model.InsuranceFreight = priceSheet.InsuranceFreight; model.InsurancePercentage = priceSheet.InsurancePercentage; model.InsurancePremium = priceSheet.InsurancePremium; model.ToolingMargin = priceSheet.ToolingMargin; model.FixtureMargin = priceSheet.FixtureMargin; model.DueDate = priceSheet.ModifiedDate; model.PriceSheetType = priceSheet.IsQuote ? "Quote" : priceSheet.IsProduction ? "Production" : "N/A"; model.TotalWeight = priceSheet.AnnualWeight; model.PriceSheetParts = new List <PriceSheetPartViewModel>(); model.CostDetailList = new List <PriceSheetCostDetailViewModel>(); model.PriceDetailList = new List <PriceSheetPriceDetailViewModel>(); var priceSheetParts = _priceSheetRepository.GetPriceSheetParts(priceSheet.PriceSheetId).ToList(); if (priceSheetParts != null && priceSheetParts.Count > 0) { foreach (var priceSheetPart in priceSheetParts) { PriceSheetPartViewModel priceSheetPartModel = new PriceSheetPartViewModel(); if (priceSheet.IsQuote) { priceSheetPartModel = new PriceSheetPartConverter().ConvertToProjectPartView(priceSheetPart); } else if (priceSheet.IsProduction) { priceSheetPartModel = new PriceSheetPartConverter().ConvertToPartView(priceSheetPart); } model.PriceSheetParts.Add(priceSheetPartModel); PriceSheetCostDetailViewModel costDetail = new PriceSheetPartConverter().ConvertToCostView(priceSheetPart); model.CostDetailList.Add(costDetail); var priceDetail = new PriceSheetPartConverter().ConvertToPriceView(priceSheetPart); model.PriceDetailList.Add(priceDetail); model.TotalAnnualCost += costDetail.AnnualCost; model.TotalAnnualPrice += priceDetail.AnnualPrice; model.PriceSheetParts = model.PriceSheetParts.OrderBy(y => y.PartNumber).ToList(); var margin = (model.TotalAnnualPrice - model.TotalAnnualCost) / model.TotalAnnualPrice * 100; model.OverallMargin = margin.ToString("#.##") + '%'; } } model.BucketList = _priceSheetRepository.GetPriceSheetBuckets().Where(x => x.PriceSheetId == priceSheet.PriceSheetId).ToList(); var quotes = _quoteRepository.GetQuotes(); if (quotes != null && quotes.Count > 0) { foreach (var quote in quotes) { if (quote.PriceSheetId == priceSheet.PriceSheetId) { model.NoEdit = true; break; } } } if (_projectRepository != null) { _projectRepository.Dispose(); _projectRepository = null; } if (_rfqRepository != null) { _rfqRepository.Dispose(); _rfqRepository = null; } if (_countryRepository != null) { _countryRepository.Dispose(); _countryRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } if (_quoteRepository != null) { _quoteRepository.Dispose(); _quoteRepository = null; } return(model); }