/// <summary> /// convert containerPart to view model /// </summary> /// <param name="containerPart"></param> /// <returns></returns> public ContainerPartViewModel ConvertToView(ContainerPart containerPart) { ContainerPartViewModel model = new ContainerPartViewModel(); var _containerRepository = new ContainerRepository(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _foundryOrderRepository = new FoundryOrderRepository(); var container = _containerRepository.GetContainer(containerPart.ContainerId); var foundryOrderPart = _foundryOrderRepository.GetFoundryOrderParts().FirstOrDefault(x => x.FoundryOrderPartId == containerPart.FoundryOrderPartId); var part = _partRepository.GetPart((foundryOrderPart != null) ? foundryOrderPart.PartId : Guid.Empty); var dynamicsPart = _dynamicsPartRepository.GetPartMaster(part != null && !string.IsNullOrEmpty(part.Number) ? part.Number : null); var foundryOrder = _foundryOrderRepository.GetFoundryOrder((foundryOrderPart != null) ? foundryOrderPart.FoundryOrderId : Guid.Empty); model.FoundryOrderPartId = containerPart.FoundryOrderPartId; model.ContainerPartId = containerPart.ContainerPartId; model.ContainerId = containerPart.ContainerId; model.PartId = (part != null) ? part.PartId : Guid.Empty; model.ContainerNumber = (container != null) ? container.Number : "N/A"; model.PartNumber = (part != null && !string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A"; model.FoundryOrderId = (foundryOrder != null) ? foundryOrder.FoundryOrderId : Guid.Empty; model.OrderNumber = (foundryOrder != null && !string.IsNullOrEmpty(foundryOrder.Number)) ? foundryOrder.Number : "N/A"; model.PalletNumber = (!string.IsNullOrEmpty(containerPart.PalletNumber)) ? containerPart.PalletNumber : "N/A"; model.Quantity = containerPart.Quantity; model.Weight = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m; model.Cost = foundryOrderPart.Cost; model.Price = foundryOrderPart.Price; model.AvailableQuantity = (foundryOrderPart != null) ? foundryOrderPart.Quantity : 0; model.ShipCode = (foundryOrderPart != null && !string.IsNullOrEmpty(foundryOrderPart.ShipCode)) ? foundryOrderPart.ShipCode : "N/A"; if (_containerRepository != null) { _containerRepository.Dispose(); _containerRepository = null; } if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_foundryOrderRepository != null) { _foundryOrderRepository.Dispose(); _foundryOrderRepository = null; } return(model); }
/// <summary> /// convert part to rfq part view model /// </summary> /// <param name="part"></param> /// <returns></returns> public RfqPartViewModel ConvertToView(Part part) { RfqPartViewModel model = new RfqPartViewModel(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _materialRepository = new MaterialRepository(); var dynamicsPart = _dynamicsPartRepository.GetPartMaster(part.Number); var material = _materialRepository.GetMaterial(part.MaterialId); var partDrawing = _partRepository.GetPartDrawings(part.PartId).FirstOrDefault(x => x.IsLatest); model.PartId = part.PartId; model.PartNumber = (!string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A"; model.PartDescription = (dynamicsPart != null && !string.IsNullOrEmpty(dynamicsPart.ITEMDESC)) ? dynamicsPart.ITEMDESC : "N/A"; model.CustomerId = part.CustomerId; model.FoundryId = part.FoundryId; model.Weight = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m; model.AnnualUsage = part.AnnualUsage; model.IsMachined = part.IsMachined; model.MaterialId = part.MaterialId; model.MaterialDescription = (material != null && !string.IsNullOrEmpty(material.Description)) ? material.Description : "N/A"; model.RevisionNumber = (partDrawing != null && !string.IsNullOrEmpty(partDrawing.RevisionNumber)) ? partDrawing.RevisionNumber : "N/A"; model.PartDrawingId = (partDrawing != null) ? partDrawing.PartDrawingId : Guid.Empty; model.PartTypeId = part.PartTypeId; model.PartStatusId = part.PartStatusId; model.DestinationId = part.DestinationId; model.SurchargeId = part.SurchargeId; model.SubFoundryId = part.SubFoundryId; if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_materialRepository != null) { _materialRepository.Dispose(); _materialRepository = null; } return(model); }
/// <summary> /// convert container part to packlingList part view model /// </summary> /// <param name="containerPart"></param> /// <returns></returns> public PackingListPartViewModel ConvertToView(ContainerPart containerPart) { PackingListPartViewModel model = new PackingListPartViewModel(); var _foundryOrderRepository = new FoundryOrderRepository(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _customerOrderRepository = new CustomerOrderRepository(); var foundryOrderPart = _foundryOrderRepository.GetFoundryOrderPart(containerPart.FoundryOrderPartId); var part = _partRepository.GetPart(foundryOrderPart.PartId); var dynamicsPart = _dynamicsPartRepository.GetPartMaster((part != null) ? part.Number : null); var customerOrderPart = _customerOrderRepository.GetCustomerOrderPart(foundryOrderPart.CustomerOrderPartId); var customerOrder = _customerOrderRepository.GetCustomerOrder(customerOrderPart.CustomerOrderId); model.ShipCode = foundryOrderPart.ShipCode; model.PartNumber = (part != null && !string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A"; model.PartWeight = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m; model.PartQuantity = containerPart.Quantity; model.PalletNumber = (!string.IsNullOrEmpty(containerPart.PalletNumber)) ? containerPart.PalletNumber : "N/A"; model.PONumber = (customerOrder != null && !string.IsNullOrEmpty(customerOrder.PONumber)) ? customerOrder.PONumber : "N/A"; model.PalletQuantity = containerPart.Quantity; model.InvoiceNumber = "Will fill in later"; if (_foundryOrderRepository != null) { _foundryOrderRepository.Dispose(); _foundryOrderRepository = null; } if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_customerOrderRepository != null) { _customerOrderRepository.Dispose(); _customerOrderRepository = null; } return(model); }
/// <summary> /// convert part to quote part view model /// </summary> /// <param name="part"></param> /// <returns></returns> public QuotePartViewModel ConvertToView(Part part) { QuotePartViewModel model = new QuotePartViewModel(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _partStatusRepository = new PartStatusRepository(); var dynamicsPart = _dynamicsPartRepository.GetPartMaster(part.Number); var dynamicsPartCurrency = _dynamicsPartRepository.GetPartCurrency(part.Number); var partStatus = _partStatusRepository.GetPartStatus(part.PartStatusId); var partDrawing = _partRepository.GetPartDrawings(part.PartId).FirstOrDefault(x => x.IsLatest); model.PartId = part.PartId; model.PartNumber = (!string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A"; model.PartDescription = (dynamicsPart != null && !string.IsNullOrEmpty(dynamicsPart.ITEMDESC)) ? dynamicsPart.ITEMDESC : "N/A"; model.CustomerId = part.CustomerId; model.FoundryId = part.FoundryId; model.RevisionNumber = (partDrawing != null && !string.IsNullOrEmpty(partDrawing.RevisionNumber)) ? partDrawing.RevisionNumber : "N/A"; model.Weight = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m; model.AnnualUsage = part.AnnualUsage; model.Price = (dynamicsPartCurrency != null) ? (decimal)dynamicsPartCurrency.LISTPRCE : 0.00m; model.PatternPrice = part.PatternPrice; model.FixturePrice = part.FixturePrice; model.Cost = (dynamicsPart != null) ? (decimal)dynamicsPart.STNDCOST : 0.00m; model.PatternCost = part.PatternCost; model.FixtureCost = part.FixtureCost; model.IsRaw = part.IsRaw; model.IsMachined = part.IsMachined; if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_partStatusRepository != null) { _partStatusRepository.Dispose(); _partStatusRepository = null; } 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 packlingList part to view model /// </summary> /// <param name="packingListPart"></param> /// <returns></returns> public PackingListPartViewModel ConvertToView(PackingListPart packingListPart) { PackingListPartViewModel model = new PackingListPartViewModel(); var _partRepository = new PartRepository(); var _customerOrderRepository = new CustomerOrderRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var part = _partRepository.GetPart(packingListPart.PartNumber); var dynamicsPart = _dynamicsPartRepository.GetPartMaster((part != null) ? part.Number : null); var customerOrder = _customerOrderRepository.GetCustomerOrder(packingListPart.PONumber); model.PackingListPartId = packingListPart.PackingListPartId; model.PackingListId = packingListPart.PackingListId; model.PartId = (part != null) ? part.PartId : Guid.Empty; model.ShipCode = (!string.IsNullOrEmpty(packingListPart.ShipCode)) ? packingListPart.ShipCode : "N/A"; model.PartNumber = (!string.IsNullOrEmpty(packingListPart.PartNumber)) ? packingListPart.PartNumber : "N/A"; model.PartWeight = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m; model.PartQuantity = packingListPart.PalletQuantity; model.PalletNumber = (!string.IsNullOrEmpty(packingListPart.PalletNumber)) ? packingListPart.PalletNumber : "N/A"; model.PalletQuantity = packingListPart.PalletQuantity; model.PalletWeight = packingListPart.PalletWeight; model.PalletTotal = packingListPart.PalletTotal; model.TotalPalletQuantity = packingListPart.TotalPalletQuantity; model.PONumber = (!string.IsNullOrEmpty(packingListPart.PONumber)) ? packingListPart.PONumber : "N/A"; model.CustomerOrderId = (customerOrder != null) ? customerOrder.CustomerOrderId : Guid.Empty; model.InvoiceNumber = (!string.IsNullOrEmpty(packingListPart.InvoiceNumber)) ? packingListPart.InvoiceNumber : "N/A"; if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_customerOrderRepository != null) { _customerOrderRepository.Dispose(); _customerOrderRepository = null; } return(model); }
/// <summary> /// convert part to part inventory list model /// </summary> /// <param name="part"></param> /// <returns></returns> public PartInventoryViewModel ConvertToListView(Part part) { PartInventoryViewModel model = new PartInventoryViewModel(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _foundryOrderRepository = new FoundryOrderRepository(); var _dynamicsReceiptRepository = new ReceiptDynamicsRepository(); var dynamicsPartQty = _dynamicsPartRepository.GetPartQuantityMaster(part.Number); var dynamicsPartStatus = _dynamicsPartRepository.GetItemStatus(part.Number); var dynamicsPartSales = _dynamicsPartRepository.GetItemSales(part.Number); model.PartId = part.PartId; model.PartNumber = part.Number; model.CustomerId = part.CustomerId; model.FoundryId = part.FoundryId; model.QuantityOnHand = (dynamicsPartStatus != null) ? Math.Round(dynamicsPartStatus.Quantity_on_Hand, 2) : 0.00m; model.Cost = (dynamicsPartStatus != null) ? Math.Round(dynamicsPartStatus.Cost, 2) : 0.00m; model.OnOrderQuantity = (dynamicsPartQty != null) ? Math.Round(dynamicsPartQty.QTYONORD, 2) : 0.00m; model.ReceiptDate = (dynamicsPartStatus != null && dynamicsPartStatus.Last_Receipt_Date != null) ? dynamicsPartStatus.Last_Receipt_Date : DateTime.MinValue; model.ReceiptDateStr = (dynamicsPartStatus != null && dynamicsPartStatus.Last_Receipt_Date != null) ? dynamicsPartStatus.Last_Receipt_Date.ToShortDateString() : "N/A"; model.ReceiptQuantity = (dynamicsPartQty != null) ? Math.Round(dynamicsPartQty.LRCPTQTY, 2) : 0.00m; model.SalesDate = (dynamicsPartStatus != null && dynamicsPartStatus.Last_Sale_Date != null) ? dynamicsPartStatus.Last_Sale_Date : DateTime.MinValue; model.SalesDateStr = (dynamicsPartStatus != null && dynamicsPartStatus.Last_Sale_Date != null) ? dynamicsPartStatus.Last_Sale_Date.ToShortDateString() : "N/A"; model.YearToDateSales = (dynamicsPartSales != null) ? Math.Round(dynamicsPartSales.YTD_SALES, 2) : 0.00m; if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } return(model); }
/// <summary> /// convert customer order part to part view model /// </summary> /// <param name="customerOrderPart"></param> /// <returns></returns> public CustomerOrderPartViewModel ConvertToPartView(CustomerOrderPart customerOrderPart) { CustomerOrderPartViewModel model = new CustomerOrderPartViewModel(); var _priceSheetRepository = new PriceSheetRepository(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _customerOrderRepository = new CustomerOrderRepository(); var _foundryOrderRepository = new FoundryOrderRepository(); var priceSheetPart = _priceSheetRepository.GetPriceSheetPart(customerOrderPart.PriceSheetPartId); var part = _partRepository.GetPart((customerOrderPart.PartId != null) ? customerOrderPart.PartId : Guid.Empty); var dynamicsPart = _dynamicsPartRepository.GetPartMaster((part != null) ? part.Number : string.Empty); var priceSheet = _priceSheetRepository.GetPriceSheet((priceSheetPart != null) ? priceSheetPart.PriceSheetId : Guid.Empty); var customerOrder = _customerOrderRepository.GetCustomerOrder(customerOrderPart.CustomerOrderId); var receivedQuantity = _foundryOrderRepository.GetFoundryOrderParts().Where(x => x.CustomerOrderPartId == customerOrderPart.CustomerOrderPartId && x.HasBeenReceived).Select(y => y.ReceiptQuantity).Sum(); model.CustomerOrderId = customerOrderPart.CustomerOrderId; model.CustomerOrderPartId = customerOrderPart.CustomerOrderPartId; model.PONumber = (customerOrder != null && !string.IsNullOrEmpty(customerOrder.PONumber)) ? customerOrder.PONumber : "N/A"; model.PartId = customerOrderPart.PartId; model.PriceSheetPartId = customerOrderPart.PriceSheetPartId; model.PriceSheetId = (priceSheet != null) ? priceSheet.PriceSheetId : Guid.Empty; model.AvailableQuantity = customerOrderPart.AvailableQuantity; model.CustomerOrderQuantity = customerOrderPart.Quantity; model.PartNumber = (part != null && !string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A"; model.PartDescription = (dynamicsPart != null && !string.IsNullOrEmpty(dynamicsPart.ITEMDESC)) ? dynamicsPart.ITEMDESC : "N/A"; model.PriceSheetNumber = (priceSheet != null && !string.IsNullOrEmpty(priceSheet.Number)) ? priceSheet.Number : "N/A"; model.EstArrivalDate = (customerOrderPart.EstArrivalDate != null) ? customerOrderPart.EstArrivalDate : DateTime.MinValue; model.EstArrivalDateStr = (customerOrderPart.EstArrivalDate != null) ? customerOrderPart.EstArrivalDate.Value.ToShortDateString() : "N/A"; model.ShipDate = (customerOrderPart.ShipDate != null) ? customerOrderPart.ShipDate : DateTime.MinValue;; model.ShipDateStr = (customerOrderPart.ShipDate != null) ? customerOrderPart.ShipDate.Value.ToShortDateString() : "N/A"; model.Cost = customerOrderPart.Cost; model.Price = customerOrderPart.Price; model.ReceiptQuantity = receivedQuantity; if (_priceSheetRepository != null) { _priceSheetRepository.Dispose(); _priceSheetRepository = null; } if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_customerOrderRepository != null) { _customerOrderRepository.Dispose(); _customerOrderRepository = null; } return(model); }
/// <summary> /// convert foundry order part to part view model /// </summary> /// <param name="foundryOrderPart"></param> /// <returns></returns> public FoundryOrderPartViewModel ConvertToPartView(FoundryOrderPart foundryOrderPart) { FoundryOrderPartViewModel model = new FoundryOrderPartViewModel(); var _customerOrderPartRepository = new CustomerOrderRepository(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _customerOrderRepository = new CustomerOrderRepository(); var _foundryOrderRepository = new FoundryOrderRepository(); var customerOrderPart = _customerOrderPartRepository.GetCustomerOrderPart(foundryOrderPart.CustomerOrderPartId); var part = _partRepository.GetPart(foundryOrderPart.PartId); var dynamicsPart = _dynamicsPartRepository.GetPartMaster((part != null) ? part.Number : string.Empty); var customerOrder = _customerOrderRepository.GetCustomerOrder((customerOrderPart != null) ? customerOrderPart.CustomerOrderId : Guid.Empty); var foundryOrder = _foundryOrderRepository.GetFoundryOrder(foundryOrderPart.FoundryOrderId); model.FoundryOrderPartId = foundryOrderPart.FoundryOrderPartId; model.CustomerOrderPartId = foundryOrderPart.CustomerOrderPartId; model.CustomerOrderId = (customerOrder != null) ? customerOrder.CustomerOrderId : Guid.Empty; model.PartId = foundryOrderPart.PartId; model.Weight = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m; model.FoundryOrderId = foundryOrderPart.FoundryOrderId; model.OrderNumber = (foundryOrder != null && !string.IsNullOrEmpty(foundryOrder.Number)) ? foundryOrder.Number : "N/A"; model.AvailableQuantity = foundryOrderPart.AvailableQuantity; model.Quantity = foundryOrderPart.Quantity; model.MaxQuantity = foundryOrderPart.Quantity; model.FoundryOrderQuantity = foundryOrderPart.Quantity; model.PartNumber = (part != null && !string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A"; model.PartDescription = (dynamicsPart != null && !string.IsNullOrEmpty(dynamicsPart.ITEMDESC)) ? dynamicsPart.ITEMDESC : "N/A"; model.PONumber = (customerOrder != null && !string.IsNullOrEmpty(customerOrder.PONumber)) ? customerOrder.PONumber : "N/A"; model.ShipCode = (!string.IsNullOrEmpty(foundryOrderPart.ShipCode)) ? foundryOrderPart.ShipCode : "N/A"; model.ShipCodeNotes = (!string.IsNullOrEmpty(foundryOrderPart.ShipCodeNotes)) ? foundryOrderPart.ShipCodeNotes : "N/A"; model.EstArrivalDate = (foundryOrderPart.EstArrivalDate != null) ? foundryOrderPart.EstArrivalDate : DateTime.MinValue; model.EstArrivalDateStr = (foundryOrderPart.EstArrivalDate != null) ? foundryOrderPart.EstArrivalDate.Value.ToShortDateString() : "N/A"; model.ShipDate = (foundryOrderPart.ShipDate != null) ? foundryOrderPart.ShipDate : DateTime.MinValue; model.ShipDateStr = (foundryOrderPart.ShipDate != null) ? foundryOrderPart.ShipDate.Value.ToShortDateString() : "N/A"; model.ReceiptDate = (foundryOrderPart != null && foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate : DateTime.MinValue; model.ReceiptDateStr = (foundryOrderPart != null && foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate.Value.ToShortDateString() : "N/A"; model.Cost = foundryOrderPart.Cost; model.Price = foundryOrderPart.Price; model.IsScheduled = foundryOrderPart.IsScheduled; model.HasBeenReceived = foundryOrderPart.HasBeenReceived; model.ReceiptDate = (foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate : DateTime.MinValue; model.ReceiptDateStr = (foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate.Value.ToShortDateString() : "N/A"; model.ReceiptQuantity = foundryOrderPart.ReceiptQuantity; if (_customerOrderPartRepository != null) { _customerOrderPartRepository.Dispose(); _customerOrderPartRepository = null; } if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_customerOrderRepository != null) { _customerOrderRepository.Dispose(); _customerOrderRepository = null; } if (_foundryOrderRepository != null) { _foundryOrderRepository.Dispose(); _foundryOrderRepository = null; } return(model); }
/// <summary> /// convert rfq part view model to project part /// </summary> /// <param name="model"></param> /// <returns></returns> public ProjectPart ConvertToDomain(RfqPartViewModel model) { ProjectPart projectPart = new ProjectPart(); var _partRepository = new PartRepository(); var _projectPartRepository = new ProjectPartRepository(); var _partStatusRepository = new PartStatusRepository(); var active = _partStatusRepository.GetPartStates().FirstOrDefault(x => x.Description == "Active"); projectPart.ProjectPartId = model.ProjectPartId; projectPart.PartId = model.PartId; projectPart.Number = model.PartNumber; projectPart.AccountCode = null; projectPart.Description = model.PartDescription; projectPart.RevisionNumber = model.RevisionNumber; projectPart.PriceSheetId = null; projectPart.QuoteId = null; projectPart.CustomerId = model.CustomerId; projectPart.CustomerAddressId = null; projectPart.FoundryId = model.FoundryId; projectPart.SubFoundryId = (model.IsNew) ? model.FoundryId : model.SubFoundryId; projectPart.HtsNumberId = null; projectPart.MaterialId = model.MaterialId; projectPart.PartStatusId = (model.IsNew) ? (active != null) ? active.PartStatusId : Guid.Empty : model.PartStatusId; projectPart.PartTypeId = (model.IsNew) ? null : model.PartTypeId; projectPart.ShipmentTermId = null; projectPart.PaymentTermId = null; projectPart.SurchargeId = (model.IsNew) ? null : model.SurchargeId; projectPart.SiteId = null; projectPart.DestinationId = (model.IsNew) ? null : model.DestinationId; projectPart.PatternMaterialId = null; projectPart.IsRaw = model.IsRaw; projectPart.IsMachined = model.IsMachined; projectPart.Weight = model.Weight; projectPart.Cost = 0.00m; projectPart.Price = 0.00m; projectPart.PalletQuantity = 0; projectPart.AdditionalCost = 0.00m; projectPart.AnnualUsage = model.AnnualUsage; projectPart.FixtureDate = null; projectPart.FixtureCost = 0.00m; projectPart.FixturePrice = 0.00m; projectPart.PatternDate = null; projectPart.PatternCost = 0.00m; projectPart.PatternPrice = 0.00m; projectPart.IsFamilyPattern = false; projectPart.Notes = null; projectPart.CustomerOrderId = null; projectPart.FoundryOrderId = null; projectPart.ToolingDescription = null; if (!string.IsNullOrEmpty(model.RevisionNumber) && model.RevisionNumber != "N/A") { projectPart.ProjectPartDrawings = new List <ProjectPartDrawing>(); ProjectPartDrawing projectPartDrawing = new ProjectPartDrawing(); if (model.Drawing != null) { projectPartDrawing.ProjectPartId = model.ProjectPartId; projectPartDrawing.RevisionNumber = model.Drawing.RevisionNumber; projectPartDrawing.Type = model.Drawing.Type; projectPartDrawing.Length = model.Drawing.Length; projectPartDrawing.Content = model.Drawing.Content; projectPartDrawing.IsLatest = model.Drawing.IsLatest; projectPartDrawing.IsMachined = model.Drawing.IsMachined; projectPartDrawing.IsRaw = model.Drawing.IsRaw; projectPartDrawing.IsActive = model.Drawing.IsActive; } else { if (model.PartId != null) { var drawing = _partRepository.GetPartDrawings(model.PartId ?? Guid.Empty).FirstOrDefault(x => x.RevisionNumber == model.RevisionNumber); projectPartDrawing.ProjectPartId = model.ProjectPartId; if (drawing != null) { projectPartDrawing.RevisionNumber = drawing.RevisionNumber; projectPartDrawing.Type = drawing.Type; projectPartDrawing.Length = drawing.Length; projectPartDrawing.Content = drawing.Content; projectPartDrawing.IsLatest = drawing.IsLatest; projectPartDrawing.IsMachined = drawing.IsMachined; projectPartDrawing.IsRaw = drawing.IsRaw; } projectPartDrawing.IsActive = true; } else { var drawing = _projectPartRepository.GetProjectPartDrawings(model.ProjectPartId).FirstOrDefault(x => x.RevisionNumber == model.RevisionNumber); projectPartDrawing.ProjectPartId = model.ProjectPartId; projectPartDrawing.RevisionNumber = drawing.RevisionNumber; projectPartDrawing.Type = drawing.Type; projectPartDrawing.Length = drawing.Length; projectPartDrawing.Content = drawing.Content; projectPartDrawing.IsLatest = drawing.IsLatest; projectPartDrawing.IsMachined = drawing.IsMachined; projectPartDrawing.IsRaw = drawing.IsRaw; projectPartDrawing.IsActive = true; } } projectPart.ProjectPartDrawings.Add(projectPartDrawing); } if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_projectPartRepository != null) { _projectPartRepository.Dispose(); _projectPartRepository = null; } if (_partStatusRepository != null) { _partStatusRepository.Dispose(); _partStatusRepository = null; } return(projectPart); }
/// <summary> /// convert project to view model /// </summary> /// <param name="project"></param> /// <returns></returns> public ProjectViewModel ConvertToView(Project project) { ProjectViewModel model = new ProjectViewModel(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _projectRepository = new ProjectRepository(); var _partRepository = new PartRepository(); 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.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.CustomerContact = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.CNTCPRSN)) ? dynamicsCustomer.CNTCPRSN : "N/A"; model.CustomerContactPhone = FormattingManager.FormatPhone(dynamicsCustomer.PHONE1); model.FoundryId = project.FoundryId; model.FoundryName = (dynamicsFoundry != null) ? dynamicsFoundry.VENDSHNM : "N/A"; model.FoundryContact = (dynamicsFoundry != null) ? dynamicsFoundry.VNDCNTCT : "N/A"; model.FoundryContactPhone = FormattingManager.FormatPhone((dynamicsFoundry != null) ? dynamicsFoundry.PHNUMBR1 : string.Empty); 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.ModifiedDate = (project.ModifiedDate != null) ? project.ModifiedDate : DateTime.MinValue; model.ModifiedDateStr = (project.ModifiedDate != null) ? project.ModifiedDate.Value.ToShortDateString() : "N/A"; model.ModifiedBy = project.ModifiedBy; model.IsOpen = project.IsOpen; model.IsHold = project.IsHold; model.HoldExpirationDate = (project.HoldExpirationDate != null) ? project.HoldExpirationDate : DateTime.MinValue;; model.HoldExpirationDateStr = (project.HoldExpirationDate != null) ? project.HoldExpirationDate.Value.ToShortDateString() : "N/A"; model.HoldNotes = (!string.IsNullOrEmpty(project.HoldNotes)) ? project.HoldNotes : "N/A"; model.IsCanceled = project.IsCanceled; model.CanceledDate = (project.CanceledDate != null) ? project.CanceledDate : DateTime.MinValue; model.CanceledDateStr = (project.CanceledDate != null) ? project.CanceledDate.Value.ToShortDateString() : "N/A"; model.CancelNotes = (!string.IsNullOrEmpty(project.CancelNotes)) ? project.CancelNotes : "N/A"; model.IsComplete = project.IsComplete; model.CompletedDate = (project.CompletedDate != null) ? project.CompletedDate : DateTime.MinValue; model.CompletedDateStr = (project.CompletedDate != null) ? project.CompletedDate.Value.ToShortDateString() : "N/A"; model.Status = project.IsOpen ? "Open" : project.IsCanceled ? "Canceled" : project.IsComplete ? "Completed" : project.IsHold ? "On Hold" : "N/A"; model.Duration = (project.CompletedDate != null) ? (project.CompletedDate - project.CreatedDate).Value.Days : 0; var notes = new List <ProjectNoteViewModel>(); var tempNotes = _projectRepository.GetProjectNotes(project.ProjectId); if (tempNotes != null && tempNotes.Count > 0) { foreach (var tempNote in tempNotes) { ProjectNoteViewModel convertedModel = new ProjectNoteConverter().ConvertToView(tempNote); notes.Add(convertedModel); } } model.ProjectNotes = notes.OrderBy(y => y.CreatedDate).ToList(); var parts = new List <ProjectPartViewModel>(); var tempParts = _partRepository.GetParts().Where(x => x.Projects.Any(y => y.ProjectId == project.ProjectId)).ToList(); if (project.Parts != null && project.Parts.Count > 0) { foreach (var part in project.Parts) { ProjectPartViewModel convertedModel = new ProjectPartConverter().ConvertToListView(part); if (parts.FirstOrDefault(x => x.PartNumber == convertedModel.PartNumber) == null) { parts.Add(convertedModel); } } } if (project.ProjectParts != null && project.ProjectParts.Count > 0) { foreach (var tempPart in project.ProjectParts.Where(x => x.PartId == null)) { ProjectPartViewModel convertedModel = new ProjectPartConverter().ConvertToListView(tempPart); if (parts.FirstOrDefault(x => x.PartNumber == convertedModel.PartNumber) == null) { parts.Add(convertedModel); } } } model.Parts = parts.OrderBy(x => x.PartNumber).ToList(); if (project.Rfqs != null && project.Rfqs.Count > 0) { model.RFQs = new List <RfqViewModel>(); foreach (var rfq in project.Rfqs) { var rfqModel = new RfqConverter().ConvertToListView(rfq); model.RFQs.Add(rfqModel); } } if (project.PriceSheets != null && project.PriceSheets.Count > 0) { model.PriceSheets = new List <PriceSheetListModel>(); decimal profitMargin = 0; foreach (var priceSheet in project.PriceSheets) { var priceSheetModel = new PriceSheetConverter().ConvertToListView(priceSheet); model.PriceSheets.Add(priceSheetModel); profitMargin += priceSheetModel.ProjectMargin; } model.ProjectMargin = (profitMargin / project.PriceSheets.Count).ToString("#.##") + '%'; } if (project.Quotes != null && project.Quotes.Count > 0) { model.Quotes = new List <QuoteViewModel>(); foreach (var quote in project.Quotes) { var quoteModel = new QuoteConverter().ConvertToListView(quote); model.Quotes.Add(quoteModel); } } if (project.CustomerOrders != null && project.CustomerOrders.Count > 0) { model.CustomerOrders = new List <CustomerOrderViewModel>(); foreach (var customerOrder in project.CustomerOrders) { var customerOrderModel = new CustomerOrderConverter().ConvertToListView(customerOrder); model.CustomerOrders.Add(customerOrderModel); } } if (project.FoundryOrders != null && project.FoundryOrders.Count > 0) { model.FoundryOrders = new List <FoundryOrderViewModel>(); foreach (var foundryOrder in project.FoundryOrders) { var foundryOrderModel = new FoundryOrderConverter().ConvertToListView(foundryOrder); model.FoundryOrders.Add(foundryOrderModel); } } if (project.Shipments != null && project.Shipments.Count > 0) { model.Shipments = new List <ShipmentViewModel>(); foreach (var shipment in project.Shipments) { var shipmentModel = new ShipmentConverter().ConvertToView(shipment); model.Shipments.Add(shipmentModel); } } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_projectRepository != null) { _projectRepository.Dispose(); _projectRepository = null; } if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } return(model); }
/// <summary> /// convert container part to warehouse inventory list model /// </summary> /// <param name="containerPart"></param> /// <returns></returns> public WarehouseInventoryViewModel ConvertToListView(ContainerPart containerPart) { WarehouseInventoryViewModel model = new WarehouseInventoryViewModel(); var _foundryOrderRepository = new FoundryOrderRepository(); var _customerOrderRepository = new CustomerOrderRepository(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _containerRepository = new ContainerRepository(); var foundryOrderPart = _foundryOrderRepository.GetFoundryOrderPart(containerPart.FoundryOrderPartId); var customerOrderPart = _customerOrderRepository.GetCustomerOrderPart((foundryOrderPart != null) ? foundryOrderPart.CustomerOrderPartId : Guid.Empty); var part = _partRepository.GetPart((foundryOrderPart != null) ? foundryOrderPart.PartId : Guid.Empty); var dynamicsPart = _dynamicsPartRepository.GetPartMaster((part != null) ? part.Number : string.Empty); var container = _containerRepository.GetContainer(containerPart.ContainerId); model.CustomerId = (part != null) ? part.CustomerId : "N/A"; model.ShipCode = (foundryOrderPart != null) ? foundryOrderPart.ShipCode : "N/A"; model.PartNumber = (part != null && !string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A"; model.PartWeight = (dynamicsPart != null) ? (dynamicsPart.ITEMSHWT / 100.00m) : 0.00m; model.PalletNumber = (!string.IsNullOrEmpty(part.Number)) ? containerPart.PalletNumber : "N/A"; model.PalletQuantity = containerPart.Quantity; model.TotalQuantity = containerPart.Quantity; model.ContainerNumber = (!string.IsNullOrEmpty(part.Number)) ? container.Number : "N/A"; model.PONumber = (customerOrderPart != null && !string.IsNullOrEmpty(customerOrderPart.CustomerOrder.PONumber)) ? customerOrderPart.CustomerOrder.PONumber : "N/A"; model.WarehouseDate = (foundryOrderPart != null) ? foundryOrderPart.ReceiptDate : DateTime.MinValue; model.WarehouseDateStr = (foundryOrderPart != null && foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate.Value.ToShortDateString() : "N/A"; model.SixtyDaysDate = (foundryOrderPart != null && foundryOrderPart.ReceiptDate != null) ? foundryOrderPart.ReceiptDate.Value.AddDays(60) : DateTime.MinValue; model.SixtyDaysDateStr = (model.SixtyDaysDate != null) ? model.SixtyDaysDate.Value.ToShortDateString() : "N/A"; if (_foundryOrderRepository != null) { _foundryOrderRepository.Dispose(); _foundryOrderRepository = null; } if (_customerOrderRepository != null) { _customerOrderRepository.Dispose(); _customerOrderRepository = null; } if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_containerRepository != null) { _containerRepository.Dispose(); _containerRepository = null; } return(model); }
/// <summary> /// convert part to view model /// </summary> /// <param name="part"></param> /// <returns></returns> public PartViewModel ConvertToView(Part part) { PartViewModel model = new PartViewModel(); var _partRepository = new PartRepository(); var _dynamicsPartRepository = new PartDynamicsRepository(); var _projectPartRepository = new ProjectPartRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _htsNumberRepository = new HtsNumberRepository(); var _partTypeRepository = new PartTypeRepository(); var _partStatusRepository = new PartStatusRepository(); var _foundryOrderRepository = new FoundryOrderRepository(); var dynamicsPart = _dynamicsPartRepository.GetPartMaster(part.Number); var dynamicsPartQty = _dynamicsPartRepository.GetPartQuantityMaster(part.Number); var dynamicsPartCurrency = _dynamicsPartRepository.GetPartCurrency(part.Number); var dynamicsPartRollingSales = _dynamicsPartRepository.GetItemRollingSales(part.Number); var foundryOrderPart = _foundryOrderRepository.GetFoundryOrderPartByPart(part.PartId); if (foundryOrderPart != null) { var toolingOrder = _foundryOrderRepository.GetToolingFoundryOrder(foundryOrderPart.FoundryOrderId); model.FoundryOrderId = (toolingOrder != null) ? foundryOrderPart.FoundryOrderId : Guid.Empty; model.ToolingOrderNumber = (toolingOrder != null && !string.IsNullOrEmpty(toolingOrder.Number)) ? toolingOrder.Number : "N/A"; model.ToolingDescription = (!string.IsNullOrEmpty(part.ToolingDescription)) ? part.ToolingDescription : "N/A"; } var latestDrawing = _partRepository.GetPartDrawings(part.PartId).FirstOrDefault(x => x.IsLatest == true); var weight = (dynamicsPart != null) ? Math.Round((dynamicsPart.ITEMSHWT / 100.00m), 2) : 0.00m; var yearlySalesTotal = (dynamicsPartRollingSales != null) ? (dynamicsPartRollingSales.Sales_1_mo_ago + dynamicsPartRollingSales.Sales_2_mo_ago + dynamicsPartRollingSales.Sales_3_mo_ago + dynamicsPartRollingSales.Sales_4_mo_ago + dynamicsPartRollingSales.Sales_5_mo_ago + dynamicsPartRollingSales.Sales_6_mo_ago + dynamicsPartRollingSales.Sales_7_mo_ago + dynamicsPartRollingSales.Sales_8_mo_ago + dynamicsPartRollingSales.Sales_9_mo_ago + dynamicsPartRollingSales.Sales_10_mo_ago + dynamicsPartRollingSales.Sales_11_mo_ago + dynamicsPartRollingSales.Sales_12_mo_ago) : 0.00m; model.ProjectPartId = Guid.Empty; model.PartId = part.PartId; model.PartNumber = (!string.IsNullOrEmpty(part.Number)) ? part.Number : "N/A"; model.AccountCode = (!string.IsNullOrEmpty(part.AccountCode)) ? part.AccountCode : "N/A"; model.PartDescription = (dynamicsPart != null && !string.IsNullOrEmpty(dynamicsPart.ITEMDESC)) ? dynamicsPart.ITEMDESC : "N/A"; model.RevisionNumber = (latestDrawing != null && !string.IsNullOrEmpty(latestDrawing.RevisionNumber)) ? latestDrawing.RevisionNumber : "N/A"; model.CustomerId = part.CustomerId; model.CustomerAddressId = part.CustomerAddressId; model.FoundryId = part.FoundryId; model.SubFoundryId = part.SubFoundryId; model.HtsNumberId = part.HtsNumberId; model.MaterialId = part.MaterialId; model.SpecificationMaterialId = part.MaterialSpecificationId; model.PartStatusId = part.PartStatusId; model.PartTypeId = part.PartTypeId; model.ShipmentTermId = part.ShipmentTermId; model.PaymentTermId = part.PaymentTermId; model.SurchargeId = part.SurchargeId; model.SiteId = part.SiteId; model.DestinationId = part.DestinationId; model.CoatingTypeId = part.CoatingTypeId; model.PatternMaterialId = part.PatternMaterialId; model.IsRaw = part.IsRaw; model.IsMachined = part.IsMachined; model.PalletQuantity = (part.PalletQuantity != 0) ? part.PalletQuantity : 0; model.PalletWeight = (part.PalletQuantity != 0) ? part.PalletQuantity * weight : 0.00m; model.Weight = weight; model.Cost = (dynamicsPart != null && (Math.Round(dynamicsPart.STNDCOST, 2) != 0.00m)) ? Math.Round(dynamicsPart.STNDCOST, 2) : 0.00m; model.Price = (dynamicsPartCurrency != null && (Math.Round(dynamicsPartCurrency.LISTPRCE, 2) != 0.00m)) ? Math.Round(dynamicsPartCurrency.LISTPRCE, 2) : 0.00m; model.AdditionalCost = (part.AdditionalCost != 0.00m) ? part.AdditionalCost : 0.00m; model.YearlySalesTotal = Math.Round(yearlySalesTotal, 2); model.SixtyDaysSalesTotal = (yearlySalesTotal != 0.00m) ? Math.Round((yearlySalesTotal / 6), 2) : 0.00m; model.MonthlySalesTotal = (yearlySalesTotal != 0.00m) ? Math.Round((yearlySalesTotal / 12), 2) : 0.00m; model.AverageDailySales = (yearlySalesTotal != 0.00m) ? Math.Round((yearlySalesTotal / 365), 2) : 0.00m; model.QuantityOnHand = (dynamicsPartQty != null && (Math.Round(dynamicsPartQty.QTYONHND, 2) != 0.00m)) ? Math.Round(dynamicsPartQty.QTYONHND, 2) : 0.00m; model.FixtureDate = (part.FixtureDate != null) ? part.FixtureDate : DateTime.MinValue; model.FixtureDateStr = (part.FixtureDate != null) ? part.FixtureDate.Value.ToShortDateString() : "N/A"; model.FixtureCost = (Math.Round(part.FixtureCost, 2) != 0.00m) ? Math.Round(part.FixtureCost, 2) : 0.00m; model.FixturePrice = (Math.Round(part.FixturePrice, 2) != 0.00m) ? Math.Round(part.FixturePrice, 2) : 0.00m; model.PatternDate = (part.PatternDate != null) ? part.PatternDate : DateTime.MinValue; model.PatternDateStr = (part.PatternDate != null) ? part.PatternDate.Value.ToShortDateString() : "N/A"; model.PatternCost = (Math.Round(part.PatternCost, 2) != 0.00m) ? Math.Round(part.PatternCost, 2) : 0.00m; model.PatternPrice = (Math.Round(part.PatternPrice, 2) != 0.00m) ? Math.Round(part.PatternPrice, 2) : 0.00m; model.IsFamilyPattern = part.IsFamilyPattern; model.Notes = (!string.IsNullOrEmpty(part.Notes)) ? part.Notes : "N/A"; model.AnnualUsage = (part.AnnualUsage != 0) ? part.AnnualUsage : 0; model.IsActive = part.IsActive; model.IsProjectPart = false; var partDrawings = _partRepository.GetPartDrawings(model.PartId ?? Guid.Empty); if (part.PartDrawings != null && part.PartDrawings.Count > 0) { var drawings = new List <DrawingViewModel>(); foreach (var partDrawing in partDrawings) { DrawingViewModel convertedModel = new PartDrawingConverter().ConvertToView(partDrawing); drawings.Add(convertedModel); } model.Drawings = drawings; } var partLayouts = _partRepository.GetPartLayouts(model.PartId ?? Guid.Empty); if (part.PartLayouts != null && part.PartLayouts.Count > 0) { var layouts = new List <LayoutViewModel>(); foreach (var partLayout in partLayouts) { LayoutViewModel convertedModel = new PartLayoutConverter().ConvertToView(partLayout); layouts.Add(convertedModel); } model.Layouts = layouts; } if (_partRepository != null) { _partRepository.Dispose(); _partRepository = null; } if (_dynamicsPartRepository != null) { _dynamicsPartRepository.Dispose(); _dynamicsPartRepository = null; } if (_projectPartRepository != null) { _projectPartRepository.Dispose(); _projectPartRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_htsNumberRepository != null) { _htsNumberRepository.Dispose(); _htsNumberRepository = null; } if (_partTypeRepository != null) { _partTypeRepository.Dispose(); _partTypeRepository = null; } if (_partStatusRepository != null) { _partStatusRepository.Dispose(); _partStatusRepository = null; } if (_foundryOrderRepository != null) { _foundryOrderRepository.Dispose(); _foundryOrderRepository = null; } return(model); }