/// <summary> /// convert price sheet to list model /// </summary> /// <param name="priceSheet"></param> /// <returns></returns> public PriceSheetListModel ConvertToListView(PriceSheet priceSheet) { PriceSheetListModel model = new PriceSheetListModel(); var _rfqRepository = new RfqRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var rfq = _rfqRepository.GetRfq(priceSheet.RfqId); 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.Date = (priceSheet.CreatedDate != null) ? priceSheet.CreatedDate : DateTime.MinValue; model.DateStr = (priceSheet.CreatedDate != null) ? priceSheet.CreatedDate.Value.ToShortDateString() : "N/A"; model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.RfqNumber = (rfq != null && !string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A"; model.ProjectMargin = priceSheet.ProjectMargin; model.WAF = priceSheet.WAF; model.Status = priceSheet.IsQuote ? "Quote" : priceSheet.IsProduction ? "Production" : "N/A"; model.CreatedDate = (priceSheet.CreatedDate != null) ? priceSheet.CreatedDate : DateTime.MinValue; if (_rfqRepository != null) { _rfqRepository.Dispose(); _rfqRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } return(model); }
/// <summary> /// convert project to list model /// </summary> /// <param name="project"></param> /// <returns></returns> public ProjectViewModel ConvertToListView(Project project) { ProjectViewModel model = new ProjectViewModel(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _rfqRepository = new RfqRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(project.CustomerId); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(project.FoundryId); model.ProjectId = project.ProjectId; model.ProjectName = (!string.IsNullOrEmpty(project.Name)) ? project.Name : "N/A"; model.CustomerId = project.CustomerId; model.FoundryId = project.FoundryId; model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.FoundryName = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.CreatedDate = (project.CreatedDate != null) ? project.CreatedDate : DateTime.MinValue; model.CreatedDateStr = (project.CreatedDate != null) ? project.CreatedDate.Value.ToShortDateString() : "N/A"; model.CreatedBy = project.CreatedBy; model.IsOpen = project.IsOpen; model.IsHold = project.IsHold; model.HoldNotes = project.HoldNotes; model.HoldExpirationDate = (project.HoldExpirationDate != null) ? project.HoldExpirationDate : DateTime.MinValue; model.HoldExpirationDateStr = (project.HoldExpirationDate != null) ? project.HoldExpirationDate.Value.ToShortDateString() : "N/A"; model.IsCanceled = project.IsCanceled; model.CanceledDate = (project.CanceledDate != null) ? project.CanceledDate : DateTime.MinValue;; model.CanceledDateStr = (project.CanceledDate != null) ? project.CanceledDate.Value.ToString("M/dd/yyyy") : "N/A"; model.IsComplete = project.IsComplete; model.CompletedDate = (project.CompletedDate != null) ? project.CompletedDate : DateTime.MinValue; model.CompletedDateStr = (project.CompletedDate != null) ? project.CompletedDate.Value.ToString("M/dd/yyyy") : "N/A"; model.Status = project.IsOpen ? "Open" : project.IsCanceled ? "Canceled" : project.IsComplete ? "Completed" : project.IsHold ? "On Hold" : "N/A"; if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_rfqRepository != null) { _rfqRepository.Dispose(); _rfqRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } return(model); }
/// <summary> /// convert quote to list model /// </summary> /// <param name="quote"></param> /// <returns></returns> public QuoteViewModel ConvertToListView(Quote quote) { QuoteViewModel model = new QuoteViewModel(); var _rfqRepository = new RfqRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var rfq = _rfqRepository.GetRfq(quote.RfqId); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(quote.CustomerId); model.QuoteId = quote.QuoteId; model.QuoteNumber = (!string.IsNullOrEmpty(quote.Number)) ? quote.Number : "N/A"; model.QuoteDate = quote.QuoteDate; model.QuoteDateStr = quote.QuoteDate.ToShortDateString(); model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.RfqNumber = (rfq != null && !string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A"; model.IsOpen = quote.IsOpen; model.IsHold = quote.IsHold; model.IsCanceled = quote.IsCanceled; model.Status = quote.IsOpen ? "Open" : quote.IsCanceled ? "Canceled" : quote.IsHold ? "On Hold" : "N/A"; model.CreatedDate = quote.CreatedDate; model.HoldNotes = quote.HoldNotes; model.HoldExpirationDate = quote.HoldExpirationDate; if (_rfqRepository != null) { _rfqRepository.Dispose(); _rfqRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = 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); }
/// <summary> /// convert price sheet view model to domain /// </summary> /// <param name="model"></param> /// <returns></returns> public PriceSheet ConvertToDomain(PriceSheetViewModel model) { var _rfqRepository = new RfqRepository(); var rfq = _rfqRepository.GetRfq(model.RfqId); var priceSheet = new PriceSheet(); priceSheet.PriceSheetId = model.PriceSheetId; priceSheet.Number = model.Number; priceSheet.WAF = model.WAF; priceSheet.ProjectMargin = model.ProjectMargin; priceSheet.AnnualDollars = model.AnnualDollars; priceSheet.AnnualMargin = model.AnnualMargin; priceSheet.AnnualWeight = model.AnnualWeight; priceSheet.AnnualContainer = model.AnnualContainer; priceSheet.DollarContainer = model.DollarContainer; priceSheet.InsuranceFreight = model.InsuranceFreight; priceSheet.InsurancePercentage = model.InsurancePercentage; priceSheet.InsuranceDuty = model.InsuranceDuty; priceSheet.InsuranceDivisor = model.InsuranceDivisor; priceSheet.InsurancePremium = model.InsurancePremium; priceSheet.ToolingMargin = model.ToolingMargin; priceSheet.FixtureMargin = model.FixtureMargin; priceSheet.IsQuote = model.IsQuote; priceSheet.IsProduction = model.IsProduction; priceSheet.RfqId = model.RfqId; priceSheet.ProjectId = (rfq != null) ? rfq.ProjectId : (Guid?)null; priceSheet.PriceSheetBuckets = model.BucketList; if (model.CostDetailList != null && model.CostDetailList.Count > 0) { priceSheet.PriceSheetParts = new List <PriceSheetPart>(); foreach (var costDetail in model.CostDetailList) { var priceSheetPart = new PriceSheetPart(); priceSheetPart.PriceSheetPartId = costDetail.PriceSheetPartId; priceSheetPart.PriceSheetId = model.PriceSheetId; priceSheetPart.AddOnCost = costDetail.AddOn; priceSheetPart.AnnualCost = costDetail.AnnualCost; priceSheetPart.AnnualRawCost = costDetail.AnnualRawCost; priceSheetPart.AnnualUsage = costDetail.AnnualUsage; priceSheetPart.AvailableQuantity = (int)costDetail.AnnualUsage; priceSheetPart.Cost = costDetail.Cost; priceSheetPart.DutyCost = costDetail.Duty; priceSheetPart.FixtureCost = costDetail.FixtureCost; priceSheetPart.FOBCost = costDetail.FOBCost; priceSheetPart.MachineCost = costDetail.MachineCost; priceSheetPart.PatternCost = costDetail.PatternCost; priceSheetPart.PNumberCost = costDetail.PNumber; priceSheetPart.ProjectPartId = costDetail.ProjectPartId; priceSheetPart.PartId = null; priceSheetPart.RawCost = costDetail.RawCost; priceSheetPart.SurchargeCost = costDetail.Surcharge; priceSheetPart.IsQuote = model.IsQuote; priceSheetPart.IsProduction = model.IsProduction; var priceDetail = model.PriceDetailList.FirstOrDefault(x => x.ProjectPartId == costDetail.ProjectPartId); if (priceDetail != null) { priceSheetPart.AddOnPrice = priceDetail.AddOn; priceSheetPart.AnnualPrice = priceDetail.AnnualPrice; priceSheetPart.AnnualRawPrice = priceDetail.AnnualRawPrice; priceSheetPart.DutyPrice = priceDetail.Duty; priceSheetPart.FixturePrice = priceDetail.FixturePrice; priceSheetPart.FOBPrice = priceDetail.FOBPrice; priceSheetPart.MachinePrice = priceDetail.MachinePrice; priceSheetPart.PatternPrice = priceDetail.PatternPrice; priceSheetPart.PNumberPrice = priceDetail.PNumber; priceSheetPart.Price = priceDetail.Price; priceSheetPart.RawPrice = priceDetail.RawPrice; priceSheetPart.SurchargePrice = priceDetail.Surcharge; } priceSheet.PriceSheetParts.Add(priceSheetPart); } } if (_rfqRepository != null) { _rfqRepository.Dispose(); _rfqRepository = null; } return(priceSheet); }
/// <summary> /// convert quote to view model /// </summary> /// <param name="quote"></param> /// <returns></returns> public QuoteViewModel ConvertToView(Quote quote) { QuoteViewModel model = new QuoteViewModel(); var _rfqRepository = new RfqRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _customerAddressDynamicsRepository = new CustomerAddressDynamicsRepository(); var _stateRepository = new StateRepository(); var _shipmentTermRepository = new ShipmentTermRepository(); var _paymentTermRepository = new PaymentTermRepository(); var _materialRepository = new MaterialRepository(); var _coatingTypeRepository = new CoatingTypeRepository(); var _htsNumberRepository = new HtsNumberRepository(); var _projectReposiotry = new ProjectPartRepository(); var rfq = _rfqRepository.GetRfq(quote.RfqId); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(quote.CustomerId); var dynamicsCustomerAddress = _customerAddressDynamicsRepository.GetCustomerAddress(quote.CustomerAddressId); var state = _stateRepository.GetState((dynamicsCustomerAddress != null && !string.IsNullOrEmpty(dynamicsCustomerAddress.STATE)) ? dynamicsCustomerAddress.STATE : string.Empty); var stateName = (state != null) ? ", " + state.Name : string.Empty; var shipmentTerm = _shipmentTermRepository.GetShipmentTerm(quote.ShipmentTermId); var paymentTerm = _paymentTermRepository.GetPaymentTerm(quote.PaymentTermId); var material = _materialRepository.GetMaterial(quote.MaterialId); var coatingType = _coatingTypeRepository.GetCoatingType(quote.CoatingTypeId); var htsNumber = _htsNumberRepository.GetHtsNumber(quote.HtsNumberId); var quoteParts = _projectReposiotry.GetProjectParts().Where(x => x.QuoteId == quote.QuoteId).ToList(); model.QuoteId = quote.QuoteId; model.RfqId = quote.RfqId; model.PriceSheetId = quote.PriceSheetId; model.ProjectId = quote.ProjectId; model.QuoteNumber = (!string.IsNullOrEmpty(quote.Number)) ? quote.Number : "N/A"; model.QuoteDate = quote.QuoteDate; model.QuoteDateStr = quote.QuoteDate.ToShortDateString(); model.RfqNumber = (rfq != null && !string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A"; model.Validity = quote.Validity; model.ContactName = (!string.IsNullOrEmpty(quote.ContactName)) ? quote.ContactName : "N/A"; model.CustomerId = quote.CustomerId; model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.CustomerAddressId = quote.CustomerAddressId; model.CustomerAddress = (dynamicsCustomerAddress != null) ? dynamicsCustomerAddress.ADDRESS1 + " " + dynamicsCustomerAddress.CITY + stateName : "N/A"; model.ContactCopy = (!string.IsNullOrEmpty(quote.ContactCopy)) ? quote.ContactCopy : "N/A"; model.ShipmentTermId = quote.ShipmentTermId; model.ShipmentTermDescription = (shipmentTerm != null && !string.IsNullOrEmpty(shipmentTerm.Description)) ? shipmentTerm.Description : "N/A"; model.PaymentTermId = quote.PaymentTermId; model.PaymentTermDescription = (paymentTerm != null && !string.IsNullOrEmpty(paymentTerm.Description)) ? paymentTerm.Description : "N/A"; model.MinimumShipment = (!string.IsNullOrEmpty(quote.MinimumShipment)) ? quote.MinimumShipment : "N/A"; model.ToolingTermDescription = (!string.IsNullOrEmpty(quote.ToolingTermDescription)) ? quote.ToolingTermDescription : "N/A"; model.SampleLeadTime = (!string.IsNullOrEmpty(quote.SampleLeadTime)) ? quote.SampleLeadTime : "N/A"; model.ProductionLeadTime = (!string.IsNullOrEmpty(quote.ProductionLeadTime)) ? quote.ProductionLeadTime : "N/A"; model.MaterialId = quote.MaterialId; model.MaterialDescription = (material != null && !string.IsNullOrEmpty(material.Description)) ? material.Description : "N/A"; model.CoatingTypeId = quote.CoatingTypeId; model.CoatingTypeDescription = (coatingType != null && !string.IsNullOrEmpty(coatingType.Description)) ? coatingType.Description : "N/A"; model.HtsNumberId = quote.HtsNumberId; model.HtsNumberDescription = (htsNumber != null && !string.IsNullOrEmpty(htsNumber.Description)) ? htsNumber.Description + "(" + (htsNumber.DutyRate * 100).ToString() + "%)" : "N/A"; model.IsMachined = quote.IsMachined; model.Notes = quote.Notes; model.IsOpen = quote.IsOpen; model.IsHold = quote.IsHold; model.HoldExpirationDate = (quote.HoldExpirationDate != null) ? quote.HoldExpirationDate : DateTime.MinValue; model.HoldExpirationDateStr = (quote.HoldExpirationDate != null) ? quote.HoldExpirationDate.Value.ToShortDateString() : null; model.HoldNotes = (!string.IsNullOrEmpty(quote.HoldNotes)) ? quote.HoldNotes : "N/A"; model.IsCanceled = quote.IsCanceled; model.CanceledDate = (quote.CanceledDate != null) ? quote.CanceledDate : DateTime.MinValue; model.CanceledDateStr = (quote.CanceledDate != null) ? quote.CanceledDate.Value.ToShortDateString() : null; model.CancelNotes = (!string.IsNullOrEmpty(quote.CancelNotes)) ? quote.CancelNotes : "N/A"; model.Status = quote.IsOpen ? "Open" : quote.IsCanceled ? "Canceled" : quote.IsHold ? "On Hold" : "N/A"; model.Machining = quote.IsMachined == true ? "Included" : "Not Included"; if (quoteParts != null) { model.QuoteParts = new List <QuotePartViewModel>(); foreach (var quotePart in quoteParts) { var quotePartModel = new QuotePartConverter().ConvertToView(quotePart); model.QuoteParts.Add(quotePartModel); } } if (_rfqRepository != null) { _rfqRepository.Dispose(); _rfqRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_customerAddressDynamicsRepository != null) { _customerAddressDynamicsRepository.Dispose(); _customerAddressDynamicsRepository = null; } if (_stateRepository != null) { _stateRepository.Dispose(); _stateRepository = null; } if (_shipmentTermRepository != null) { _shipmentTermRepository.Dispose(); _shipmentTermRepository = null; } if (_paymentTermRepository != null) { _paymentTermRepository.Dispose(); _paymentTermRepository = null; } if (_materialRepository != null) { _materialRepository.Dispose(); _materialRepository = null; } if (_coatingTypeRepository != null) { _coatingTypeRepository.Dispose(); _coatingTypeRepository = null; } if (_htsNumberRepository != null) { _htsNumberRepository.Dispose(); _htsNumberRepository = null; } if (_projectReposiotry != null) { _projectReposiotry.Dispose(); _projectReposiotry = null; } return(model); }