public ActionResult ShipmentAnalysisReport(Guid bolId) { var operationResult = new OperationResult(); MemoryStream ms = new MemoryStream(); var _billOfLadingRepository = new BillOfLadingRepository(); try { ms = ReportingManager.CreateShipmentAnalysisReport(bolId); if (ms != null) { var existingBillOfLading = _billOfLadingRepository.GetBillOfLading(bolId); existingBillOfLading.HasBeenAnalyzed = true; operationResult = _billOfLadingRepository.UpdateBillOfLading(existingBillOfLading); } } catch (Exception ex) { operationResult.Message = "Error occured during Shipment Analysis"; logger.ErrorFormat("Error occured during Shipment Analysis: {0} ", ex.ToString()); this.AddNotification(operationResult.Message, NotificationType.ERROR); } return(new FileStreamResult(ms, "application/pdf")); }
/// <summary> /// convert shipment to view model /// </summary> /// <param name="shipment"></param> /// <returns></returns> public ShipmentViewModel ConvertToView(Shipment shipment) { ShipmentViewModel model = new ShipmentViewModel(); var _vesselRepository = new VesselRepository(); var _portRepository = new PortRepository(); var _bolRepository = new BillOfLadingRepository(); var vessel = _vesselRepository.GetVessel(shipment.VesselId); var port = _portRepository.GetPort(shipment.PortId); var bols = _bolRepository.GetBillOfLadings().Where(x => x.ShipmentId == shipment.ShipmentId).ToList(); model.ShipmentId = shipment.ShipmentId; model.CarrierId = shipment.CarrierId; model.VesselId = shipment.VesselId; model.PortId = shipment.PortId; model.DepartureDate = shipment.DepartureDate; model.EstArrivalDate = (shipment.EstArrivalDate != null) ? shipment.EstArrivalDate : DateTime.MinValue; model.ShipmentNotes = (!string.IsNullOrEmpty(shipment.Notes)) ? shipment.Notes : "N/A"; model.VesselName = (vessel != null && !string.IsNullOrEmpty(vessel.Name)) ? vessel.Name : "N/A"; model.PortName = (port != null && !string.IsNullOrEmpty(port.Name)) ? port.Name : "N/A"; model.DepartureDateStr = shipment.DepartureDate.ToShortDateString(); model.EstArrivalDateStr = (shipment.EstArrivalDate != null) ? shipment.EstArrivalDate.Value.ToShortDateString() : "N/A"; model.IsComplete = shipment.IsComplete; model.CompletedDate = (shipment.CompletedDate != null) ? shipment.CompletedDate : DateTime.MinValue; model.CompletedDateStr = (shipment.CompletedDate != null) ? shipment.CompletedDate.Value.ToShortDateString() : "N/A"; model.CreatedDate = (shipment.CreatedDate != null) ? shipment.CreatedDate : DateTime.MinValue; if (bols != null && bols.Count > 0) { model.BillsOfLading = new List <BillOfLadingViewModel>(); foreach (var bol in bols) { BillOfLadingViewModel convertedModel = new BillOfLadingConverter().ConvertToView(bol); model.BillsOfLading.Add(convertedModel); } } if (_vesselRepository != null) { _vesselRepository.Dispose(); _vesselRepository = null; } if (_portRepository != null) { _portRepository.Dispose(); _portRepository = null; } if (_bolRepository != null) { _bolRepository.Dispose(); _bolRepository = null; } return(model); }
/// <summary> /// convert bol to view model /// </summary> /// <param name="bol"></param> /// <returns></returns> public BillOfLadingViewModel ConvertToView(BillOfLading bol) { BillOfLadingViewModel model = new BillOfLadingViewModel(); var _bolRepository = new BillOfLadingRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _foundryInvoiceRepository = new FoundryInvoiceRepository(); var _containerRepository = new ContainerRepository(); var _foundryOrderRepository = new FoundryOrderRepository(); var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(bol.FoundryId); var foundryInvoice = _foundryInvoiceRepository.GetFoundryInvoiceByBillOfLading(bol.BillOfLadingId); var containers = _containerRepository.GetContainers().Where(x => x.BillOfLadingId == bol.BillOfLadingId).ToList(); model.BillOfLadingId = bol.BillOfLadingId; model.ShipmentId = bol.ShipmentId; model.FoundryId = bol.FoundryId; model.BolNumber = (!string.IsNullOrEmpty(bol.Number)) ? bol.Number : "N/A"; model.BolDate = bol.BolDate; model.BolDateStr = (bol.BolDate != null) ? bol.BolDate.ToShortDateString() : "N/A"; model.FoundryName = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.Description = (!string.IsNullOrEmpty(bol.Description)) ? bol.Description : "N/A"; model.HasLcl = bol.HasLcl; model.HasDoorMove = bol.HasDoorMove; model.HasArrivalNotice = bol.HasArrivalNotice; model.HasOriginalDocuments = bol.HasOriginalDocuments; model.PalletCount = bol.PalletCount; model.GrossWeight = bol.GrossWeight; model.NetWeight = bol.NetWeight; model.BolNotes = (!string.IsNullOrEmpty(bol.Notes)) ? bol.Notes : "N/A"; model.WireInstructions = (!string.IsNullOrEmpty(bol.WireInstructions)) ? bol.WireInstructions : "N/A"; model.CustomsNumber = (!string.IsNullOrEmpty(bol.CustomsNumber)) ? bol.CustomsNumber : "N/A"; model.IsCustomsLiquidated = bol.IsCustomsLiquidated; model.FoundryInvoiceId = (foundryInvoice != null) ? foundryInvoice.FoundryInvoiceId : Guid.Empty; model.BillOfLadingId = (foundryInvoice != null) ? foundryInvoice.FoundryInvoiceId : Guid.Empty; model.InvoiceNumber = (foundryInvoice != null && !string.IsNullOrEmpty(foundryInvoice.Number)) ? foundryInvoice.Number : "N/A"; model.InvoiceTotal = (foundryInvoice != null) ? foundryInvoice.Amount : 0.00m; model.ScheduledDate = (foundryInvoice != null && foundryInvoice.ScheduledPaymentDate != null) ? foundryInvoice.ScheduledPaymentDate : DateTime.MinValue; model.ScheduledDateStr = (foundryInvoice != null && foundryInvoice.ScheduledPaymentDate != null) ? foundryInvoice.ScheduledPaymentDate.Value.ToShortDateString() : "N/A"; model.ActualDate = (foundryInvoice != null && foundryInvoice.ActualPaymentDate != null) ? foundryInvoice.ActualPaymentDate : DateTime.MinValue; model.ActualDateStr = (foundryInvoice != null && foundryInvoice.ActualPaymentDate != null) ? foundryInvoice.ActualPaymentDate.Value.ToShortDateString() : "N/A"; model.InvoiceNotes = (foundryInvoice != null && !string.IsNullOrEmpty(foundryInvoice.Notes)) ? foundryInvoice.Notes : "N/A"; model.HasBeenAnalyzed = bol.HasBeenAnalyzed; if (containers != null && containers.Count > 0) { model.Containers = new List <ContainerViewModel>(); foreach (var container in containers) { ContainerViewModel convertedModel = new ContainerConverter().ConvertToView(container); model.Containers.Add(convertedModel); } model.ContainerParts = new List <ContainerPartViewModel>(); model.Pallets = new List <PalletViewModel>(); model.PurchaseOrders = new List <FoundryOrderViewModel>(); foreach (var container in model.Containers) { if (container.ContainerParts != null) { foreach (var containerPart in container.ContainerParts) { model.ContainerParts.Add(containerPart); model.Pallets.Add(new PalletViewModel() { PalletNumber = containerPart.PalletNumber }); var foundryOrder = _foundryOrderRepository.GetFoundryOrder(containerPart.FoundryOrderId); if (foundryOrder != null) { FoundryOrderViewModel convertedModel = new FoundryOrderConverter().ConvertToView(foundryOrder); model.PurchaseOrders.Add(convertedModel); } } } } if (model.PurchaseOrders != null && model.PurchaseOrders.Count > 0) { model.PurchaseOrders = model.PurchaseOrders.GroupBy(x => x.FoundryOrderId).Select(y => y.First()).ToList(); } if (model.Pallets != null && model.Pallets.Count > 0) { model.Pallets = model.Pallets.Distinct().ToList(); } } model.FoundryInvoice = new FoundryInvoiceConverter().ConvertToView(foundryInvoice); if (_bolRepository != null) { _bolRepository.Dispose(); _bolRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_foundryInvoiceRepository != null) { _foundryInvoiceRepository.Dispose(); _foundryInvoiceRepository = null; } if (_containerRepository != null) { _containerRepository.Dispose(); _containerRepository = null; } if (_foundryOrderRepository != null) { _foundryOrderRepository.Dispose(); _foundryOrderRepository = null; } return(model); }
/// <summary> /// convert foundry order to view model /// </summary> /// <param name="order"></param> /// <returns></returns> public FoundryOrderViewModel ConvertToView(FoundryOrder order) { FoundryOrderViewModel model = new FoundryOrderViewModel(); var _projectRepository = new ProjectRepository(); var _customerDynamicsRepository = new CustomerDynamicsRepository(); var _customerAddressDynamicsRepository = new CustomerAddressDynamicsRepository(); var _stateRepository = new StateRepository(); var _foundryDynamicsRepository = new FoundryDynamicsRepository(); var _siteDynamicsRepository = new SiteDynamicsRepository(); var _orderTermRepository = new OrderTermRepository(); var _billOfLadingRepository = new BillOfLadingRepository(); var _customerOrderRepository = new CustomerOrderRepository(); var _foundryOrderRepository = new FoundryOrderRepository(); var project = _projectRepository.GetProject(order.ProjectId); var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(order.CustomerId); var dynamicsCustomerAddress = _customerAddressDynamicsRepository.GetCustomerAddress(order.CustomerAddressId); var state = _stateRepository.GetState((dynamicsCustomerAddress != null && !string.IsNullOrEmpty(dynamicsCustomerAddress.STATE)) ? dynamicsCustomerAddress.STATE : string.Empty); var stateName = (state != null && !string.IsNullOrEmpty(state.Name)) ? ", " + state.Name : string.Empty; var dynamicsFoundry = _foundryDynamicsRepository.GetFoundry(order.FoundryId); var dynamicsSite = _siteDynamicsRepository.GetSite((dynamicsCustomerAddress != null && !string.IsNullOrEmpty(dynamicsCustomerAddress.LOCNCODE)) ? dynamicsCustomerAddress.LOCNCODE : string.Empty); var orderTerm = _orderTermRepository.GetOrderTerm(order.ShipmentTermsId); var billOfLading = _billOfLadingRepository.GetBillOfLadings().FirstOrDefault(x => x.FoundryId.Replace(" ", string.Empty).ToLower() == order.FoundryId.Replace(" ", string.Empty).ToLower()); var parts = _foundryOrderRepository.GetFoundryOrderParts().Where(x => x.FoundryOrderId == order.FoundryOrderId).ToList(); model.FoundryOrderId = order.FoundryOrderId; model.BillOfLadingId = (billOfLading != null) ? billOfLading.BillOfLadingId : Guid.Empty; model.OrderNumber = (!string.IsNullOrEmpty(order.Number)) ? order.Number : "N/A"; model.CustomerId = order.CustomerId; model.CustomerName = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A"; model.CustomerAddressId = order.CustomerAddressId; model.CustomerAddress = (dynamicsCustomerAddress != null) ? dynamicsCustomerAddress.ADDRESS1 + " " + dynamicsCustomerAddress.CITY + ", " + stateName : "N/A"; model.ProjectId = order.ProjectId; model.ProjectName = (project != null) ? project.Name : "N/A"; model.FoundryId = order.FoundryId; model.FoundryName = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A"; model.OrderNotes = (!string.IsNullOrEmpty(order.Notes)) ? order.Notes : "N/A"; model.ShipmentTermsId = order.ShipmentTermsId; model.ShipmentTerms = (orderTerm != null) ? orderTerm.Description : "N/A"; model.OrderDate = order.OrderDate; model.PODate = (order.OrderDate != null) ? order.OrderDate : DateTime.MinValue; model.PODateStr = (order.OrderDate != null) ? order.OrderDate.ToShortDateString() : "N/A"; model.DueDate = (order.DueDate != null) ? order.DueDate : DateTime.MinValue; model.DueDateStr = (order.DueDate != null) ? order.DueDate.Value.ToShortDateString() : "N/A"; model.PortDate = (order.PortDate != null) ? order.PortDate : DateTime.MinValue; model.PortDateStr = (order.PortDate != null) ? order.PortDate.Value.ToShortDateString() : "N/A"; model.ShipDate = (order.ShipDate != null) ? order.ShipDate : DateTime.MinValue; model.ShipDateStr = (order.ShipDate != null) ? order.ShipDate.Value.ToShortDateString() : "N/A"; model.EstArrivalDate = (order.EstArrivalDate != null) ? order.EstArrivalDate : DateTime.MinValue; model.EstArrivalDateStr = (order.EstArrivalDate != null) ? order.EstArrivalDate.Value.ToShortDateString() : "N/A"; model.ShipVia = (!string.IsNullOrEmpty(order.ShipVia)) ? order.ShipVia : "N/A"; model.TransitDays = order.TransitDays; model.SiteId = order.SiteId; model.SiteDescription = (dynamicsSite != null && !string.IsNullOrEmpty(dynamicsSite.LOCNDSCR)) ? dynamicsSite.LOCNDSCR : "N/A"; model.IsOpen = order.IsOpen ? true : false; model.IsConfirmed = order.IsConfirmed; model.ConfirmedDate = (order.ConfirmedDate != null) ? order.ConfirmedDate : DateTime.MinValue; model.ConfirmedDateStr = (order.ConfirmedDate != null) ? order.ConfirmedDate.Value.ToShortDateString() : "N/A"; model.IsHold = order.IsHold; model.HoldExpirationDate = (order.HoldExpirationDate != null) ? order.HoldExpirationDate : DateTime.MinValue; model.HoldExpirationDateStr = (order.HoldExpirationDate != null) ? order.HoldExpirationDate.Value.ToShortDateString() : "N/A"; model.HoldNotes = (!string.IsNullOrEmpty(order.HoldNotes)) ? order.HoldNotes : "N/A"; model.IsCanceled = order.IsCanceled; model.CanceledDate = (order.CanceledDate != null) ? order.CanceledDate : DateTime.MinValue; model.CanceledDateStr = (order.CanceledDate != null) ? order.CanceledDate.Value.ToShortDateString() : "N/A"; model.CancelNotes = (!string.IsNullOrEmpty(order.CancelNotes)) ? order.CancelNotes : "N/A"; model.IsComplete = order.IsComplete; model.CompletedDate = (order.CompletedDate != null) ? order.CompletedDate : DateTime.MinValue; model.CompletedDateStr = (order.CompletedDate != null) ? order.CompletedDate.Value.ToShortDateString() : "N/A"; model.Status = order.IsOpen ? "Open" : order.IsCanceled ? "Canceled" : order.IsComplete ? "Completed" : order.IsHold ? "On Hold" : "N/A"; model.IsSample = order.IsSample; model.IsTooling = order.IsTooling; model.IsProduction = order.IsProduction; model.OrderTypeDescription = order.IsSample ? "Sample" : order.IsTooling ? "Tooling" : order.IsProduction ? "Production" : "N/A"; if (parts != null && parts.Count > 0) { var foundryOrderParts = new List <FoundryOrderPartViewModel>(); var totalPrice = 0.00m; foreach (var part in parts) { FoundryOrderPartViewModel foundryOrderPart = new FoundryOrderPartViewModel(); if (model.OrderTypeDescription.Equals("Sample") || model.OrderTypeDescription.Equals("Tooling")) { foundryOrderPart = new FoundryOrderPartConverter().ConvertToProjectPartView(part); } else { foundryOrderPart = new FoundryOrderPartConverter().ConvertToPartView(part); } foundryOrderParts.Add(foundryOrderPart); totalPrice += (foundryOrderPart.Price * foundryOrderPart.FoundryOrderQuantity); } model.TotalPrice = Math.Round(totalPrice, 2); model.FoundryOrderParts = foundryOrderParts; } if (_projectRepository != null) { _projectRepository.Dispose(); _projectRepository = null; } if (_customerDynamicsRepository != null) { _customerDynamicsRepository.Dispose(); _customerDynamicsRepository = null; } if (_customerAddressDynamicsRepository != null) { _customerAddressDynamicsRepository.Dispose(); _customerAddressDynamicsRepository = null; } if (_stateRepository != null) { _stateRepository.Dispose(); _stateRepository = null; } if (_foundryDynamicsRepository != null) { _foundryDynamicsRepository.Dispose(); _foundryDynamicsRepository = null; } if (_siteDynamicsRepository != null) { _siteDynamicsRepository.Dispose(); _siteDynamicsRepository = null; } if (_orderTermRepository != null) { _orderTermRepository.Dispose(); _orderTermRepository = null; } if (_billOfLadingRepository != null) { _billOfLadingRepository.Dispose(); _billOfLadingRepository = null; } if (_customerOrderRepository != null) { _customerOrderRepository.Dispose(); _customerOrderRepository = null; } if (_foundryOrderRepository != null) { _foundryOrderRepository.Dispose(); _foundryOrderRepository = null; } return(model); }