Exemple #1
0
        /// <summary>
        /// get production price sheet by rfq
        /// </summary>
        /// <param name="rfqId"></param>
        /// <returns></returns>
        public PriceSheet GetProductionPriceSheetBrRfq(Guid rfqId)
        {
            var priceSheet = new PriceSheet();

            try
            {
                priceSheet = _db.PriceSheet.FirstOrDefault(x => x.RfqId == rfqId && x.IsProduction);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error getting production price sheet: {0} ", ex.ToString());
            }

            return(priceSheet);
        }
Exemple #2
0
        /// <summary>
        /// get price sheet by project
        /// </summary>
        /// <param name="projectId"></param>
        /// <returns></returns>
        public PriceSheet GetPriceSheetByProject(Guid projectId)
        {
            var priceSheet = new PriceSheet();

            try
            {
                priceSheet = _db.PriceSheet.FirstOrDefault(x => x.ProjectId == projectId);
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error getting price sheet: {0} ", ex.ToString());
            }

            return(priceSheet);
        }
Exemple #3
0
        /// <summary>
        /// get price sheet by number
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public PriceSheet GetPriceSheet(string number)
        {
            var priceSheet = new PriceSheet();

            try
            {
                priceSheet = _db.PriceSheet.FirstOrDefault(x => x.Number.Replace(" ", string.Empty).ToLower() == number.Replace(" ", string.Empty).ToLower());
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Error getting price sheet: {0} ", ex.ToString());
            }

            return(priceSheet);
        }
Exemple #4
0
        public JsonResult Edit(PriceSheetViewModel priceSheet)
        {
            var operationResult = new OperationResult();

            PriceSheet priceSheetToUpdate = new PriceSheet();

            var priceSheetId = priceSheet.PriceSheetId;

            priceSheetToUpdate = new PriceSheetConverter().ConvertToDomain(priceSheet);

            operationResult = _priceSheetRepository.UpdatePriceSheet(priceSheetToUpdate);

            if (operationResult.Success)
            {
                if (priceSheet.CostDetailList != null && priceSheet.CostDetailList.Count > 0)
                {
                    foreach (var costDetail in priceSheet.CostDetailList)
                    {
                        var priceDetail = priceSheet.PriceDetailList.FirstOrDefault(x => x.ProjectPartId == costDetail.ProjectPartId);

                        var tempPart = _projectPartRepository.GetProjectPart(costDetail.ProjectPartId);
                        {
                            tempPart.Weight       = costDetail.Weight;
                            tempPart.AnnualUsage  = (int)costDetail.AnnualUsage;
                            tempPart.Cost         = costDetail.Cost;
                            tempPart.PatternCost  = costDetail.PatternCost;
                            tempPart.FixtureCost  = costDetail.FixtureCost;
                            tempPart.PriceSheetId = priceSheetId;
                            tempPart.Price        = priceDetail.Price;
                            tempPart.PatternPrice = priceDetail.PatternPrice;
                            tempPart.FixturePrice = priceDetail.FixturePrice;
                        }

                        operationResult = _projectPartRepository.UpdateProjectPart(tempPart);
                    }
                }

                if (priceSheetToUpdate.IsProduction)
                {
                    operationResult = EditPriceSheetParts(priceSheetToUpdate.PriceSheetId);
                }

                operationResult.ReferenceId = priceSheetId;
            }

            return(Json(operationResult, JsonRequestBehavior.AllowGet));
        }
Exemple #5
0
        /// <summary>
        /// convert price sheet to view model
        /// </summary>
        /// <param name="priceSheet"></param>
        /// <returns></returns>
        public PriceSheetViewModel ConvertToView(PriceSheet priceSheet)
        {
            PriceSheetViewModel model = new PriceSheetViewModel();

            var _projectRepository          = new ProjectRepository();
            var _rfqRepository              = new RfqRepository();
            var _countryRepository          = new CountryRepository();
            var _foundryDynamicsRepository  = new FoundryDynamicsRepository();
            var _customerDynamicsRepository = new CustomerDynamicsRepository();
            var _priceSheetRepository       = new PriceSheetRepository();
            var _quoteRepository            = new QuoteRepository();

            var project          = _projectRepository.GetProject(priceSheet.ProjectId);
            var rfq              = _rfqRepository.GetRfq(priceSheet.RfqId);
            var country          = _countryRepository.GetCountry((rfq != null) ? rfq.CountryId : Guid.Empty);
            var dynamicsFoundry  = _foundryDynamicsRepository.GetFoundry((rfq != null) ? rfq.FoundryId : string.Empty);
            var dynamicsCustomer = _customerDynamicsRepository.GetCustomer((rfq != null) ? rfq.CustomerId : string.Empty);

            model.PriceSheetId        = priceSheet.PriceSheetId;
            model.Number              = (!string.IsNullOrEmpty(priceSheet.Number)) ? priceSheet.Number : "N/A";
            model.RfqId               = priceSheet.RfqId;
            model.ProjectMargin       = priceSheet.ProjectMargin;
            model.ProjectName         = (project != null && !string.IsNullOrEmpty(project.Name)) ? project.Name : "N/A";
            model.RfqNumber           = (rfq != null && !string.IsNullOrEmpty(rfq.Number)) ? rfq.Number : "N/A";
            model.Country             = (country != null && !string.IsNullOrEmpty(country.Name)) ? country.Name : "N/A";
            model.Foundry             = (dynamicsFoundry != null && !string.IsNullOrEmpty(dynamicsFoundry.VENDSHNM)) ? dynamicsFoundry.VENDSHNM : "N/A";
            model.Customer            = (dynamicsCustomer != null && !string.IsNullOrEmpty(dynamicsCustomer.SHRTNAME)) ? dynamicsCustomer.SHRTNAME : "N/A";
            model.WAF                 = priceSheet.WAF;
            model.AnnualContainer     = priceSheet.AnnualContainer;
            model.AnnualDollars       = priceSheet.AnnualDollars;
            model.AnnualMargin        = priceSheet.AnnualMargin;
            model.AnnualWeight        = priceSheet.AnnualWeight;
            model.DollarContainer     = priceSheet.DollarContainer;
            model.InsuranceDivisor    = priceSheet.InsuranceDivisor;
            model.InsuranceDuty       = priceSheet.InsuranceDuty;
            model.InsuranceFreight    = priceSheet.InsuranceFreight;
            model.InsurancePercentage = priceSheet.InsurancePercentage;
            model.InsurancePremium    = priceSheet.InsurancePremium;
            model.ToolingMargin       = priceSheet.ToolingMargin;
            model.FixtureMargin       = priceSheet.FixtureMargin;
            model.DueDate             = priceSheet.ModifiedDate;
            model.PriceSheetType      = priceSheet.IsQuote ? "Quote" : priceSheet.IsProduction ? "Production" : "N/A";
            model.TotalWeight         = priceSheet.AnnualWeight;

            model.PriceSheetParts = new List <PriceSheetPartViewModel>();
            model.CostDetailList  = new List <PriceSheetCostDetailViewModel>();
            model.PriceDetailList = new List <PriceSheetPriceDetailViewModel>();

            var priceSheetParts = _priceSheetRepository.GetPriceSheetParts(priceSheet.PriceSheetId).ToList();

            if (priceSheetParts != null && priceSheetParts.Count > 0)
            {
                foreach (var priceSheetPart in priceSheetParts)
                {
                    PriceSheetPartViewModel priceSheetPartModel = new PriceSheetPartViewModel();
                    if (priceSheet.IsQuote)
                    {
                        priceSheetPartModel = new PriceSheetPartConverter().ConvertToProjectPartView(priceSheetPart);
                    }
                    else if (priceSheet.IsProduction)
                    {
                        priceSheetPartModel = new PriceSheetPartConverter().ConvertToPartView(priceSheetPart);
                    }
                    model.PriceSheetParts.Add(priceSheetPartModel);

                    PriceSheetCostDetailViewModel costDetail = new PriceSheetPartConverter().ConvertToCostView(priceSheetPart);
                    model.CostDetailList.Add(costDetail);
                    var priceDetail = new PriceSheetPartConverter().ConvertToPriceView(priceSheetPart);
                    model.PriceDetailList.Add(priceDetail);

                    model.TotalAnnualCost  += costDetail.AnnualCost;
                    model.TotalAnnualPrice += priceDetail.AnnualPrice;

                    model.PriceSheetParts = model.PriceSheetParts.OrderBy(y => y.PartNumber).ToList();
                    var margin = (model.TotalAnnualPrice - model.TotalAnnualCost) / model.TotalAnnualPrice * 100;
                    model.OverallMargin = margin.ToString("#.##") + '%';
                }
            }

            model.BucketList = _priceSheetRepository.GetPriceSheetBuckets().Where(x => x.PriceSheetId == priceSheet.PriceSheetId).ToList();

            var quotes = _quoteRepository.GetQuotes();

            if (quotes != null && quotes.Count > 0)
            {
                foreach (var quote in quotes)
                {
                    if (quote.PriceSheetId == priceSheet.PriceSheetId)
                    {
                        model.NoEdit = true;
                        break;
                    }
                }
            }

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

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

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

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

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

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

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

            return(model);
        }
Exemple #6
0
        /// <summary>
        /// convert price sheet view model to domain
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public PriceSheet ConvertToDomain(PriceSheetViewModel model)
        {
            var _rfqRepository = new RfqRepository();

            var rfq = _rfqRepository.GetRfq(model.RfqId);

            var priceSheet = new PriceSheet();

            priceSheet.PriceSheetId        = model.PriceSheetId;
            priceSheet.Number              = model.Number;
            priceSheet.WAF                 = model.WAF;
            priceSheet.ProjectMargin       = model.ProjectMargin;
            priceSheet.AnnualDollars       = model.AnnualDollars;
            priceSheet.AnnualMargin        = model.AnnualMargin;
            priceSheet.AnnualWeight        = model.AnnualWeight;
            priceSheet.AnnualContainer     = model.AnnualContainer;
            priceSheet.DollarContainer     = model.DollarContainer;
            priceSheet.InsuranceFreight    = model.InsuranceFreight;
            priceSheet.InsurancePercentage = model.InsurancePercentage;
            priceSheet.InsuranceDuty       = model.InsuranceDuty;
            priceSheet.InsuranceDivisor    = model.InsuranceDivisor;
            priceSheet.InsurancePremium    = model.InsurancePremium;
            priceSheet.ToolingMargin       = model.ToolingMargin;
            priceSheet.FixtureMargin       = model.FixtureMargin;
            priceSheet.IsQuote             = model.IsQuote;
            priceSheet.IsProduction        = model.IsProduction;
            priceSheet.RfqId               = model.RfqId;
            priceSheet.ProjectId           = (rfq != null) ? rfq.ProjectId : (Guid?)null;
            priceSheet.PriceSheetBuckets   = model.BucketList;

            if (model.CostDetailList != null && model.CostDetailList.Count > 0)
            {
                priceSheet.PriceSheetParts = new List <PriceSheetPart>();

                foreach (var costDetail in model.CostDetailList)
                {
                    var priceSheetPart = new PriceSheetPart();

                    priceSheetPart.PriceSheetPartId  = costDetail.PriceSheetPartId;
                    priceSheetPart.PriceSheetId      = model.PriceSheetId;
                    priceSheetPart.AddOnCost         = costDetail.AddOn;
                    priceSheetPart.AnnualCost        = costDetail.AnnualCost;
                    priceSheetPart.AnnualRawCost     = costDetail.AnnualRawCost;
                    priceSheetPart.AnnualUsage       = costDetail.AnnualUsage;
                    priceSheetPart.AvailableQuantity = (int)costDetail.AnnualUsage;
                    priceSheetPart.Cost          = costDetail.Cost;
                    priceSheetPart.DutyCost      = costDetail.Duty;
                    priceSheetPart.FixtureCost   = costDetail.FixtureCost;
                    priceSheetPart.FOBCost       = costDetail.FOBCost;
                    priceSheetPart.MachineCost   = costDetail.MachineCost;
                    priceSheetPart.PatternCost   = costDetail.PatternCost;
                    priceSheetPart.PNumberCost   = costDetail.PNumber;
                    priceSheetPart.ProjectPartId = costDetail.ProjectPartId;
                    priceSheetPart.PartId        = null;
                    priceSheetPart.RawCost       = costDetail.RawCost;
                    priceSheetPart.SurchargeCost = costDetail.Surcharge;
                    priceSheetPart.IsQuote       = model.IsQuote;
                    priceSheetPart.IsProduction  = model.IsProduction;

                    var priceDetail = model.PriceDetailList.FirstOrDefault(x => x.ProjectPartId == costDetail.ProjectPartId);
                    if (priceDetail != null)
                    {
                        priceSheetPart.AddOnPrice     = priceDetail.AddOn;
                        priceSheetPart.AnnualPrice    = priceDetail.AnnualPrice;
                        priceSheetPart.AnnualRawPrice = priceDetail.AnnualRawPrice;
                        priceSheetPart.DutyPrice      = priceDetail.Duty;
                        priceSheetPart.FixturePrice   = priceDetail.FixturePrice;
                        priceSheetPart.FOBPrice       = priceDetail.FOBPrice;
                        priceSheetPart.MachinePrice   = priceDetail.MachinePrice;
                        priceSheetPart.PatternPrice   = priceDetail.PatternPrice;
                        priceSheetPart.PNumberPrice   = priceDetail.PNumber;
                        priceSheetPart.Price          = priceDetail.Price;
                        priceSheetPart.RawPrice       = priceDetail.RawPrice;
                        priceSheetPart.SurchargePrice = priceDetail.Surcharge;
                    }

                    priceSheet.PriceSheetParts.Add(priceSheetPart);
                }
            }

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

            return(priceSheet);
        }
Exemple #7
0
        /// <summary>
        /// update price sheet
        /// </summary>
        /// <param name="priceSheet"></param>
        /// <returns></returns>
        public OperationResult UpdatePriceSheet(PriceSheet priceSheet)
        {
            var operationResult = new OperationResult();

            var existingPriceSheet = GetPriceSheet(priceSheet.PriceSheetId);

            if (existingPriceSheet != null)
            {
                logger.Debug("PriceSheet is being updated.");

                try
                {
                    _db.PriceSheet.Attach(existingPriceSheet);

                    _db.Entry(existingPriceSheet).CurrentValues.SetValues(priceSheet);

                    _db.SaveChanges();

                    var existingBuckets = GetPriceSheetBuckets().Where(x => x.PriceSheetId == priceSheet.PriceSheetId).ToList();

                    if (priceSheet.PriceSheetBuckets != null && priceSheet.PriceSheetBuckets.Count > 0)
                    {
                        foreach (var bucket in priceSheet.PriceSheetBuckets)
                        {
                            var existingBucket = _db.PriceSheetBucket.FirstOrDefault(x => x.PriceSheetBucketId == bucket.PriceSheetBucketId);

                            if (existingBucket != null)
                            {
                                _db.PriceSheetBucket.Attach(existingBucket);

                                existingBucket.IsAddOn     = bucket.IsAddOn;
                                existingBucket.IsDuty      = bucket.IsDuty;
                                existingBucket.IsSurcharge = bucket.IsSurcharge;
                                existingBucket.Margin      = bucket.Margin;
                                existingBucket.Name        = bucket.Name;
                                existingBucket.PNumber     = bucket.PNumber;
                                existingBucket.SellValue   = bucket.SellValue;
                                existingBucket.Value       = bucket.Value;
                            }
                            else
                            {
                                bucket.PriceSheetId = priceSheet.PriceSheetId;

                                _db.PriceSheetBucket.Add(bucket);

                                existingPriceSheet.PriceSheetBuckets.Add(bucket);
                            }

                            _db.SaveChanges();
                        }
                    }

                    if (existingBuckets != null && existingBuckets.Count > 0)
                    {
                        foreach (var bucket in existingBuckets)
                        {
                            var existingBucket = priceSheet.PriceSheetBuckets.FirstOrDefault(x => x.PriceSheetBucketId == bucket.PriceSheetBucketId);

                            if (existingBucket == null)
                            {
                                _db.PriceSheetBucket.Attach(bucket);

                                _db.PriceSheetBucket.Remove(bucket);

                                existingPriceSheet.PriceSheetBuckets.Remove(existingBucket);

                                _db.SaveChanges();
                            }
                        }
                    }

                    var existingParts = GetPriceSheetParts(priceSheet.PriceSheetId);

                    if (priceSheet.PriceSheetParts != null && priceSheet.PriceSheetParts.Count > 0)
                    {
                        foreach (var part in priceSheet.PriceSheetParts)
                        {
                            var existingPart = _db.PriceSheetPart.FirstOrDefault(x => x.PriceSheetPartId == part.PriceSheetPartId);

                            if (existingPart != null)
                            {
                                _db.PriceSheetPart.Attach(existingPart);

                                existingPart.AvailableQuantity = part.AvailableQuantity;
                                existingPart.AnnualUsage       = part.AnnualUsage;
                                existingPart.RawCost           = part.RawCost;
                                existingPart.RawPrice          = part.RawPrice;
                                existingPart.AnnualRawCost     = part.AnnualRawCost;
                                existingPart.AnnualRawPrice    = part.AnnualRawPrice;
                                existingPart.PNumberCost       = part.PNumberCost;
                                existingPart.PNumberPrice      = part.PNumberPrice;
                                existingPart.MachineCost       = part.MachineCost;
                                existingPart.MachinePrice      = part.MachinePrice;
                                existingPart.FOBCost           = part.FOBCost;
                                existingPart.FOBPrice          = part.FOBPrice;
                                existingPart.AddOnCost         = part.AddOnCost;
                                existingPart.AddOnPrice        = part.AddOnPrice;
                                existingPart.SurchargeCost     = part.SurchargeCost;
                                existingPart.SurchargePrice    = part.SurchargePrice;
                                existingPart.DutyCost          = part.DutyCost;
                                existingPart.DutyPrice         = part.DutyPrice;
                                existingPart.Cost         = part.Cost;
                                existingPart.Price        = part.Price;
                                existingPart.AnnualCost   = part.AnnualCost;
                                existingPart.AnnualPrice  = part.AnnualPrice;
                                existingPart.FixtureCost  = part.FixtureCost;
                                existingPart.FixturePrice = part.FixturePrice;
                                existingPart.PatternCost  = part.PatternCost;
                                existingPart.PatternPrice = part.PatternPrice;
                            }
                            else
                            {
                                part.PriceSheetId = priceSheet.PriceSheetId;

                                _db.PriceSheetPart.Add(part);

                                existingPriceSheet.PriceSheetParts.Add(part);
                            }

                            _db.SaveChanges();
                        }
                    }

                    if (existingParts != null && existingParts.Count > 0)
                    {
                        foreach (var part in existingParts)
                        {
                            var existingPart = priceSheet.PriceSheetParts.FirstOrDefault(x => x.PriceSheetPartId == part.PriceSheetPartId);

                            if (existingPart == null)
                            {
                                _db.PriceSheetPart.Attach(part);

                                _db.PriceSheetPart.Remove(part);

                                _db.SaveChanges();
                            }
                        }
                    }

                    operationResult.Success = true;
                    operationResult.Message = "Success";
                }
                catch (Exception ex)
                {
                    operationResult.Success = false;
                    operationResult.Message = "Error";
                    logger.ErrorFormat("Error while updating priceSheet: { 0} ", ex.ToString());
                }
            }
            else
            {
                operationResult.Success = false;
                operationResult.Message = "Unable to find selected priceSheet.";
            }
            return(operationResult);
        }