Example #1
0
        /// <summary>
        /// convert price sheet part to price sheet part price detail view model
        /// </summary>
        /// <param name="part"></param>
        /// <returns></returns>
        public PriceSheetPriceDetailViewModel ConvertToPriceView(PriceSheetPart part)
        {
            PriceSheetPriceDetailViewModel model = new PriceSheetPriceDetailViewModel();

            var _projectPartRepository = new ProjectPartRepository();

            var projectPart = _projectPartRepository.GetProjectPart(part.ProjectPartId);

            model.PriceSheetPartId = part.PriceSheetPartId;
            model.PartNumber       = (projectPart != null) ? projectPart.Number : "N/A";
            model.Weight           = (projectPart != null) ? projectPart.Weight : 0;
            model.AnnualUsage      = part.AnnualUsage;
            model.RawPrice         = part.RawPrice;
            model.AnnualRawPrice   = part.AnnualRawPrice;
            model.PNumber          = part.PNumberPrice;
            model.MachinePrice     = part.MachinePrice;
            model.FOBPrice         = part.FOBPrice;
            model.AddOn            = part.AddOnPrice;
            model.Surcharge        = part.SurchargePrice;
            model.Duty             = part.DutyCost;
            model.Price            = part.Price;
            model.AnnualPrice      = part.AnnualPrice;
            model.FixturePrice     = part.FixturePrice;
            model.PatternPrice     = part.PatternPrice;
            model.ProjectPartId    = part.ProjectPartId ?? Guid.Empty;

            if (_projectPartRepository != null)
            {
                _projectPartRepository.Dispose();
                _projectPartRepository = null;
            }

            return(model);
        }
Example #2
0
        /// <summary>
        /// convert foundry order part to project part view model
        /// </summary>
        /// <param name="foundryOrderPart"></param>
        /// <returns></returns>
        public FoundryOrderPartViewModel ConvertToProjectPartView(FoundryOrderPart foundryOrderPart)
        {
            FoundryOrderPartViewModel model = new FoundryOrderPartViewModel();

            var _foundryOrderRepository    = new FoundryOrderRepository();
            var _customerOrderRepository   = new CustomerOrderRepository();
            var _projectPartRepository     = new ProjectPartRepository();
            var _dynamicsReceiptRepository = new ReceiptDynamicsRepository();

            var customerOrderPart = _customerOrderRepository.GetCustomerOrderPart(foundryOrderPart.CustomerOrderPartId);
            var projectPart       = _projectPartRepository.GetProjectPart(foundryOrderPart.ProjectPartId);
            var customerOrder     = _customerOrderRepository.GetCustomerOrder((customerOrderPart != null) ? customerOrderPart.CustomerOrderId : Guid.Empty);

            model.FoundryOrderPartId   = foundryOrderPart.FoundryOrderPartId;
            model.CustomerOrderPartId  = foundryOrderPart.CustomerOrderPartId;
            model.FoundryOrderId       = foundryOrderPart.FoundryOrderId;
            model.ProjectPartId        = foundryOrderPart.ProjectPartId;
            model.CustomerOrderId      = (customerOrderPart != null) ? customerOrderPart.CustomerOrderId : Guid.Empty;
            model.AvailableQuantity    = (customerOrderPart != null) ? customerOrderPart.AvailableQuantity : 0;
            model.FoundryOrderQuantity = foundryOrderPart.Quantity;
            model.PartNumber           = (projectPart != null && !string.IsNullOrEmpty(projectPart.Number)) ? projectPart.Number : "N/A";
            model.PartDescription      = (projectPart != null && !string.IsNullOrEmpty(projectPart.Description)) ? projectPart.Description : "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.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 (_foundryOrderRepository != null)
            {
                _foundryOrderRepository.Dispose();
                _foundryOrderRepository = null;
            }
            if (_customerOrderRepository != null)
            {
                _customerOrderRepository.Dispose();
                _customerOrderRepository = null;
            }
            if (_projectPartRepository != null)
            {
                _projectPartRepository.Dispose();
                _projectPartRepository = null;
            }
            if (_dynamicsReceiptRepository != null)
            {
                _dynamicsReceiptRepository.Dispose();
                _dynamicsReceiptRepository = null;
            }

            return(model);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <summary>
        /// convert rfq to quote view model
        /// </summary>
        /// <param name="rfq"></param>
        /// <returns></returns>
        public QuoteViewModel ConvertToView(Rfq rfq)
        {
            QuoteViewModel model = new QuoteViewModel();

            var _priceSheetRepository       = new PriceSheetRepository();
            var _projectPartRepository      = new ProjectPartRepository();
            var _customerDynamicsRepository = new CustomerDynamicsRepository();

            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer(rfq.CustomerId);
            var priceSheet       = _priceSheetRepository.GetPriceSheets().FirstOrDefault(x => x.RfqId == rfq.RfqId && x.IsQuote);
            var projectParts     = _projectPartRepository.GetProjectParts().Where(x => x.PriceSheetId == ((priceSheet != null) ? priceSheet.PriceSheetId : Guid.Empty));

            model.ProjectId     = rfq.ProjectId;
            model.RfqId         = rfq.RfqId;
            model.RfqNumber     = rfq.Number;
            model.ContactName   = rfq.ContactName;
            model.CustomerId    = rfq.CustomerId;
            model.CustomerName  = (dynamicsCustomer != null) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.MaterialId    = rfq.MaterialId;
            model.CoatingTypeId = rfq.CoatingTypeId;
            model.IsMachined    = rfq.IsMachined;
            model.Machining     = rfq.IsMachined ? "Included" : "Not Included";
            model.PriceSheetId  = (priceSheet != null) ? priceSheet.PriceSheetId : Guid.Empty;
            model.Date          = DateTime.Now.ToShortDateString();
            model.QuoteDateStr  = DateTime.Now.ToShortDateString();

            if (projectParts != null && projectParts.Count() > 0)
            {
                model.MaterialId = projectParts.FirstOrDefault().MaterialId;

                model.QuoteParts = new List <QuotePartViewModel>();
                foreach (var projectPart in projectParts)
                {
                    var quotePartModel = new QuotePartConverter().ConvertToView(projectPart);
                    model.QuoteParts.Add(quotePartModel);
                }
            }

            if (_priceSheetRepository != null)
            {
                _priceSheetRepository.Dispose();
                _priceSheetRepository = null;
            }
            if (_projectPartRepository != null)
            {
                _projectPartRepository.Dispose();
                _projectPartRepository = null;
            }

            if (_customerDynamicsRepository != null)
            {
                _customerDynamicsRepository.Dispose();
                _customerDynamicsRepository = null;
            }

            return(model);
        }
Example #5
0
        /// <summary>
        /// convert customer order part to project part view model
        /// </summary>
        /// <param name="customerOrderPart"></param>
        /// <returns></returns>
        public CustomerOrderPartViewModel ConvertToProjectPartView(CustomerOrderPart customerOrderPart)
        {
            CustomerOrderPartViewModel model = new CustomerOrderPartViewModel();

            var _priceSheetRepository    = new PriceSheetRepository();
            var _projectPartRepository   = new ProjectPartRepository();
            var _customerOrderRepository = new CustomerOrderRepository();
            var _foundryOrderRepository  = new FoundryOrderRepository();

            var priceSheetPart   = _priceSheetRepository.GetPriceSheetPart(customerOrderPart.PriceSheetPartId);
            var projectPart      = _projectPartRepository.GetProjectPart((customerOrderPart.ProjectPartId != null) ? customerOrderPart.ProjectPartId : Guid.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.CustomerOrderPartId   = customerOrderPart.CustomerOrderPartId;
            model.CustomerOrderId       = customerOrderPart.CustomerOrderId;
            model.PONumber              = (!string.IsNullOrEmpty(customerOrder.PONumber)) ? customerOrder.PONumber : "N/A";
            model.ProjectPartId         = customerOrderPart.ProjectPartId;
            model.PriceSheetPartId      = customerOrderPart.PriceSheetPartId;
            model.PriceSheetId          = (priceSheet != null) ? priceSheet.PriceSheetId : Guid.Empty;
            model.AvailableQuantity     = customerOrderPart.AvailableQuantity;
            model.CustomerOrderQuantity = customerOrderPart.Quantity;
            model.PartNumber            = (projectPart != null && !string.IsNullOrEmpty(projectPart.Number)) ? projectPart.Number : "N/A";
            model.PartDescription       = (projectPart != null && !string.IsNullOrEmpty(projectPart.Description)) ? projectPart.Description : "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.ReceiptQuantity       = receivedQuantity;
            model.Cost  = customerOrderPart.Cost;
            model.Price = customerOrderPart.Price;

            if (_priceSheetRepository != null)
            {
                _priceSheetRepository.Dispose();
                _priceSheetRepository = null;
            }

            if (_projectPartRepository != null)
            {
                _projectPartRepository.Dispose();
                _projectPartRepository = null;
            }

            if (_customerOrderRepository != null)
            {
                _customerOrderRepository.Dispose();
                _customerOrderRepository = null;
            }

            return(model);
        }
Example #6
0
        /// <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);
        }
Example #7
0
        /// <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);
        }
Example #8
0
        /// <summary>
        /// convert project part to part model for Create part
        /// </summary>
        /// <param name="projectPart"></param>
        /// <returns></returns>
        public Part ConvertToCreatePart(ProjectPart projectPart)
        {
            Part part = new Part();

            var _projectPartRepository = new ProjectPartRepository();

            var projectPartDrawings = _projectPartRepository.GetProjectPartDrawings(projectPart.ProjectPartId);
            var projectPartLayouts  = _projectPartRepository.GetProjectPartLayouts(projectPart.ProjectPartId);

            part.PartId                  = projectPart.PartId ?? Guid.Empty;
            part.Number                  = projectPart.Number;
            part.AccountCode             = projectPart.AccountCode;
            part.CustomerId              = projectPart.CustomerId;
            part.CustomerAddressId       = projectPart.CustomerAddressId;
            part.FoundryId               = projectPart.FoundryId;
            part.SubFoundryId            = projectPart.SubFoundryId;
            part.HtsNumberId             = projectPart.HtsNumberId;
            part.MaterialId              = projectPart.MaterialId;
            part.MaterialSpecificationId = projectPart.MaterialSpecificationId;
            part.PartStatusId            = projectPart.PartStatusId;
            part.PartTypeId              = projectPart.PartTypeId;
            part.ShipmentTermId          = projectPart.ShipmentTermId;
            part.PaymentTermId           = projectPart.PaymentTermId;
            part.SurchargeId             = projectPart.SurchargeId;
            part.SiteId                  = projectPart.SiteId;
            part.DestinationId           = projectPart.DestinationId;
            part.CoatingTypeId           = projectPart.CoatingTypeId;
            part.PatternMaterialId       = projectPart.PatternMaterialId;
            part.IsRaw              = projectPart.IsRaw;
            part.IsMachined         = projectPart.IsMachined;
            part.PalletQuantity     = projectPart.PalletQuantity;
            part.AdditionalCost     = projectPart.AdditionalCost;
            part.FixtureDate        = projectPart.FixtureDate;
            part.FixtureCost        = projectPart.FixtureCost;
            part.FixturePrice       = projectPart.FixturePrice;
            part.PatternDate        = projectPart.PatternDate;
            part.PatternCost        = projectPart.PatternCost;
            part.PatternPrice       = projectPart.PatternPrice;
            part.IsFamilyPattern    = projectPart.IsFamilyPattern;
            part.FoundryOrderId     = projectPart.FoundryOrderId;
            part.ToolingDescription = projectPart.ToolingDescription;
            part.Notes              = projectPart.Notes;
            part.AnnualUsage        = projectPart.AnnualUsage;
            part.IsActive           = true;

            if (projectPartDrawings != null && projectPartDrawings.Count > 0)
            {
                part.PartDrawings = new List <PartDrawing>();
                foreach (var projectPartDrawing in projectPartDrawings)
                {
                    var partDrawing = new PartDrawingConverter().ConvertToDomain(projectPartDrawing);
                    part.PartDrawings.Add(partDrawing);
                }
            }

            if (projectPartLayouts != null && projectPartLayouts.Count > 0)
            {
                part.PartLayouts = new List <PartLayout>();
                foreach (var projectPartLayout in projectPartLayouts)
                {
                    var partLayout = new PartLayoutConverter().ConvertToDomain(projectPartLayout);
                    part.PartLayouts.Add(partLayout);
                }
            }

            if (_projectPartRepository != null)
            {
                _projectPartRepository.Dispose();
                _projectPartRepository = null;
            }

            return(part);
        }
Example #9
0
        /// <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);
        }
Example #10
0
        /// <summary>
        /// convert rfq to view model
        /// </summary>
        /// <param name="rfq"></param>
        /// <returns></returns>
        public RfqViewModel ConvertToView(Rfq rfq)
        {
            RfqViewModel model = new RfqViewModel();

            var _projectRepository               = new ProjectRepository();
            var _customerDynamicsRepository      = new CustomerDynamicsRepository();
            var _salespersonDynamicsRepository   = new SalespersonDynamicsRepository();
            var _foundryDynamicsRepository       = new FoundryDynamicsRepository();
            var _countryRepository               = new CountryRepository();
            var _shipmentTermRepository          = new ShipmentTermRepository();
            var _coatingTypeRepository           = new CoatingTypeRepository();
            var _specificationMaterialRepository = new SpecificationMaterialRepository();
            var _priceSheetRepository            = new PriceSheetRepository();
            var _projectPartRepository           = new ProjectPartRepository();

            var project               = _projectRepository.GetProject(rfq.ProjectId);
            var dynamicsCustomer      = _customerDynamicsRepository.GetCustomer(rfq.CustomerId);
            var dyanmicsSalesperson   = _salespersonDynamicsRepository.GetSalesperson((dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SLPRSNID)) ? dynamicsCustomer.SLPRSNID : string.Empty);
            var dynamicsFoundry       = _foundryDynamicsRepository.GetFoundry(rfq.FoundryId);
            var country               = _countryRepository.GetCountry(rfq.CountryId);
            var shipmentTerm          = _shipmentTermRepository.GetShipmentTerm(rfq.ShipmentTermId);
            var coatingType           = _coatingTypeRepository.GetCoatingType(rfq.CoatingTypeId);
            var specificationMaterial = _specificationMaterialRepository.GetSpecificationMaterial(rfq.SpecificationMaterialId);
            var quotePriceSheet       = _priceSheetRepository.GetQuotePriceSheetByRfq(rfq.RfqId);
            var productionPriceSheet  = _priceSheetRepository.GetProductionPriceSheetBrRfq(rfq.RfqId);

            model.RfqId                            = rfq.RfqId;
            model.ProjectId                        = rfq.ProjectId;
            model.ProjectName                      = (project != null && !string.IsNullOrEmpty(project.Name)) ? project.Name : "N/A";
            model.RfqNumber                        = (!string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A";
            model.RfqDate                          = rfq.RfqDate;
            model.RfqDateStr                       = rfq.RfqDate.ToShortDateString();
            model.CustomerId                       = rfq.CustomerId;
            model.CustomerName                     = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.FoundryId                        = rfq.FoundryId;
            model.FoundryName                      = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A";
            model.CountryId                        = rfq.CountryId;
            model.SalespersonId                    = rfq.SalespersonId;
            model.SalespersonName                  = (dyanmicsSalesperson != null) ? dyanmicsSalesperson.SLPRSNFN + " " + dyanmicsSalesperson.SPRSNSLN : "N/A";
            model.CoatingTypeId                    = rfq.CoatingTypeId;
            model.SpecificationMaterialId          = rfq.SpecificationMaterialId;
            model.ContactName                      = rfq.ContactName;
            model.CountryName                      = (country != null && !string.IsNullOrEmpty(country.Name)) ? country.Name : "N/A";
            model.Attention                        = (!string.IsNullOrEmpty(rfq.Attention)) ? rfq.Attention : "N/A";
            model.PrintsSent                       = (rfq.PrintsSent != null) ? rfq.PrintsSent.Value.ToShortDateString() : "N/A";
            model.SentVia                          = rfq.SentVia;
            model.ShipmentTermDescription          = (shipmentTerm != null) ? shipmentTerm.Description : "N/A";
            model.IsMachined                       = rfq.IsMachined;
            model.Packaging                        = rfq.Packaging;
            model.NumberOfSamples                  = rfq.NumberOfSamples;
            model.Details                          = (!string.IsNullOrEmpty(rfq.Attention)) ? rfq.Details : "N/A";
            model.CoatingType                      = (coatingType != null && !string.IsNullOrEmpty(coatingType.Description)) ? coatingType.Description : "N/A";
            model.CoatingTypeId                    = rfq.CoatingTypeId;
            model.SpecificationMaterialId          = rfq.SpecificationMaterialId;
            model.SpecificationMaterialDescription = (specificationMaterial != null && !string.IsNullOrEmpty(specificationMaterial.Description)) ? specificationMaterial.Description : "N/A";
            model.ISIRRequired                     = rfq.ISIRRequired;
            model.SampleCastingAvailable           = rfq.SampleCastingAvailable;
            model.MetalCertAvailable               = rfq.MetalCertAvailable;
            model.CMTRRequired                     = rfq.CMTRRequired;
            model.GaugingRequired                  = rfq.GaugingRequired;
            model.TestBarsRequired                 = rfq.TestBarsRequired;
            model.Notes                            = (!string.IsNullOrEmpty(rfq.Notes)) ? rfq.Notes : "N/A";
            model.IsOpen                           = rfq.IsOpen;
            model.IsHold                           = rfq.IsHold;
            model.HoldExpirationDate               = (rfq.HoldExpirationDate != null) ? rfq.HoldExpirationDate : DateTime.MinValue;
            model.HoldExpirationDateStr            = (rfq.HoldExpirationDate != null) ? rfq.HoldExpirationDate.Value.ToShortDateString() : "N/A";
            model.HoldNotes                        = (!string.IsNullOrEmpty(rfq.HoldNotes)) ? rfq.HoldNotes : "N/A";
            model.IsCanceled                       = rfq.IsCanceled;
            model.CanceledDate                     = (rfq.CanceledDate != null) ? rfq.CanceledDate : DateTime.MinValue;
            model.CanceledDateStr                  = (rfq.CanceledDate != null) ? rfq.CanceledDate.Value.ToShortDateString() : "N/A";
            model.Status                           = rfq.IsOpen ? "Open" : rfq.IsCanceled ? "Canceled" : rfq.IsHold ? "On Hold" : "N/A";
            model.QuotePriceSheetId                = (quotePriceSheet != null) ? quotePriceSheet.PriceSheetId : Guid.Empty;
            model.QuotePriceSheet                  = (quotePriceSheet != null) ? quotePriceSheet.Number : "N/A";
            model.ProductionPriceSheet             = (productionPriceSheet != null) ? productionPriceSheet.Number : "N/A";
            model.MaterialId                       = rfq.MaterialId;
            model.ShipmentTermId                   = rfq.ShipmentTermId;
            model.CancelNotes                      = (!string.IsNullOrEmpty(rfq.CancelNotes)) ? rfq.CancelNotes : "N/A";
            model.HasPriceSheet                    = (quotePriceSheet != null || productionPriceSheet != null) ? true : false;

            model.RfqParts = new List <RfqPartViewModel>();
            var rfqParts = _projectPartRepository.GetProjectParts().Where(x => x.RfqId == rfq.RfqId).ToList();

            foreach (var rfqPart in rfqParts)
            {
                var rfqPartModel = new RfqPartConverter().ConvertToView(rfqPart);
                model.RfqParts.Add(rfqPartModel);
            }

            if (_projectRepository != null)
            {
                _projectRepository.Dispose();
                _projectRepository = null;
            }

            if (_customerDynamicsRepository != null)
            {
                _customerDynamicsRepository.Dispose();
                _customerDynamicsRepository = null;
            }
            if (_salespersonDynamicsRepository != null)
            {
                _salespersonDynamicsRepository.Dispose();
                _salespersonDynamicsRepository = null;
            }

            if (_foundryDynamicsRepository != null)
            {
                _foundryDynamicsRepository.Dispose();
                _foundryDynamicsRepository = null;
            }
            if (_countryRepository != null)
            {
                _countryRepository.Dispose();
                _countryRepository = null;
            }
            if (_shipmentTermRepository != null)
            {
                _shipmentTermRepository.Dispose();
                _shipmentTermRepository = null;
            }
            if (_coatingTypeRepository != null)
            {
                _coatingTypeRepository.Dispose();
                _coatingTypeRepository = null;
            }
            if (_specificationMaterialRepository != null)
            {
                _specificationMaterialRepository.Dispose();
                _specificationMaterialRepository = null;
            }
            if (_priceSheetRepository != null)
            {
                _priceSheetRepository.Dispose();
                _priceSheetRepository = null;
            }
            if (_projectPartRepository != null)
            {
                _projectPartRepository.Dispose();
                _projectPartRepository = null;
            }

            return(model);
        }